Skip to content

Commit 63f4c97

Browse files
committed
feat: Add environment configuration system and fix version comparison
- Add support for staging and local development environments - Hidden developer commands for environment switching - Environment-aware authentication and API endpoints - Proper semantic version comparison in update system - Comprehensive development documentation and scripts - Version 0.0.2
1 parent 4e6b23d commit 63f4c97

File tree

21 files changed

+1875
-82
lines changed

21 files changed

+1875
-82
lines changed

.goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ builds:
3131
- goos: windows
3232
goarch: arm
3333
ldflags:
34-
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser
34+
- -s -w -X main.buildVersion={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser
3535

3636
archives:
3737
- id: vapi

DEVELOPMENT.md

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# Development Guide
2+
3+
This guide is for developers working on the Vapi CLI or integrating with different Vapi environments.
4+
5+
## Environment Configuration
6+
7+
The Vapi CLI supports multiple environments for development and testing purposes. This functionality is designed to be **hidden from end users** but accessible to developers.
8+
9+
### Available Environments
10+
11+
| Environment | API URL | Dashboard URL | Use Case |
12+
| ------------- | ----------------------------- | ----------------------------------- | ---------------------- |
13+
| `production` | `https://api.vapi.ai` | `https://dashboard.vapi.ai` | Default, end users |
14+
| `staging` | `https://api.staging.vapi.ai` | `https://dashboard.staging.vapi.ai` | Pre-production testing |
15+
| `development` | `http://localhost:3000` | `http://localhost:3001` | Local development |
16+
17+
### Configuration Methods
18+
19+
#### 1. Environment Variables (Recommended for Development)
20+
21+
```bash
22+
# Set environment
23+
export VAPI_ENV=staging
24+
25+
# Or set URLs directly (overrides environment)
26+
export VAPI_API_BASE_URL=http://localhost:3000
27+
export VAPI_DASHBOARD_URL=http://localhost:3001
28+
```
29+
30+
#### 2. CLI Configuration
31+
32+
```bash
33+
# Hidden command for developers
34+
vapi config env staging
35+
36+
# Or set directly
37+
vapi config set environment staging
38+
```
39+
40+
#### 3. Development Script (Easiest)
41+
42+
```bash
43+
# Quick setup for local development
44+
./scripts/dev-env.sh local
45+
46+
# Set up staging environment
47+
./scripts/dev-env.sh setup staging
48+
49+
# Check current status
50+
./scripts/dev-env.sh status
51+
52+
# Reset to production
53+
./scripts/dev-env.sh reset
54+
```
55+
56+
### Priority Order
57+
58+
The CLI determines which environment to use in this order:
59+
60+
1. **Direct URL overrides** (`VAPI_API_BASE_URL`, `VAPI_DASHBOARD_URL`)
61+
2. **Environment variable** (`VAPI_ENV`)
62+
3. **Config file** (`environment` field)
63+
4. **Default** (production)
64+
65+
### Development Workflow
66+
67+
#### Setting Up Local Development
68+
69+
1. **Start your local services:**
70+
71+
```bash
72+
# Start API server on localhost:3000
73+
# Start dashboard on localhost:3001
74+
```
75+
76+
2. **Configure CLI:**
77+
78+
```bash
79+
./scripts/dev-env.sh local
80+
```
81+
82+
3. **Verify setup:**
83+
84+
```bash
85+
vapi version # Should show environment info
86+
vapi config get
87+
```
88+
89+
4. **Test authentication:**
90+
```bash
91+
vapi login # Opens localhost:3001/auth/cli
92+
```
93+
94+
#### Testing Against Staging
95+
96+
```bash
97+
# Switch to staging
98+
export VAPI_ENV=staging
99+
vapi config set environment staging
100+
101+
# Or use the script
102+
./scripts/dev-env.sh setup staging
103+
104+
# Test commands
105+
vapi assistant list
106+
```
107+
108+
#### Switching Back to Production
109+
110+
```bash
111+
./scripts/dev-env.sh reset
112+
# or
113+
unset VAPI_ENV
114+
vapi config set environment production
115+
```
116+
117+
### Environment Detection
118+
119+
The CLI shows environment information when not in production:
120+
121+
```bash
122+
$ vapi version
123+
vapi version 0.0.3
124+
commit: abc123
125+
built at: 2025-01-27
126+
built by: dev
127+
go version: go1.24.4
128+
platform: darwin/arm64
129+
environment: staging # Only shown for non-production
130+
api url: https://api.staging.vapi.ai
131+
```
132+
133+
### For End Users
134+
135+
End users will **never** see environment-related functionality:
136+
137+
- No environment flags in help output
138+
- Commands are hidden (`vapi config env` is hidden)
139+
- Default behavior is always production
140+
- No environment information shown in version (unless non-production)
141+
142+
### Configuration File
143+
144+
The CLI saves configuration to `~/.vapi-cli.yaml`:
145+
146+
```yaml
147+
api_key: "your-api-key"
148+
environment: "staging"
149+
base_url: "https://api.staging.vapi.ai"
150+
dashboard_url: "https://dashboard.staging.vapi.ai"
151+
timeout: 30
152+
```
153+
154+
### Environment Variables Reference
155+
156+
| Variable | Description | Example |
157+
| -------------------- | ---------------------- | ------------------------ |
158+
| `VAPI_ENV` | Environment name | `staging`, `development` |
159+
| `VAPI_API_KEY` | API key | `vapi_abc123...` |
160+
| `VAPI_API_BASE_URL` | Override API URL | `http://localhost:3000` |
161+
| `VAPI_DASHBOARD_URL` | Override dashboard URL | `http://localhost:3001` |
162+
163+
### Testing Authentication Flow
164+
165+
When testing authentication against different environments:
166+
167+
```bash
168+
# Local development
169+
export VAPI_DASHBOARD_URL=http://localhost:3001
170+
vapi login # Opens localhost:3001/auth/cli
171+
172+
# Staging
173+
export VAPI_ENV=staging
174+
vapi login # Opens dashboard.staging.vapi.ai/auth/cli
175+
```
176+
177+
### Troubleshooting
178+
179+
#### Check Current Configuration
180+
181+
```bash
182+
vapi config get # Shows all settings
183+
./scripts/dev-env.sh status # Comprehensive status
184+
```
185+
186+
#### Reset Everything
187+
188+
```bash
189+
./scripts/dev-env.sh reset
190+
rm ~/.vapi-cli.yaml # Nuclear option
191+
```
192+
193+
#### Debug Environment Detection
194+
195+
```bash
196+
# See what environment variables are set
197+
env | grep VAPI
198+
199+
# Check config file
200+
cat ~/.vapi-cli.yaml
201+
```
202+
203+
### Adding New Environments
204+
205+
To add a new environment (e.g., `testing`):
206+
207+
1. Update `pkg/config/config.go`:
208+
209+
```go
210+
"testing": {
211+
Name: "testing",
212+
APIBaseURL: "https://api.testing.vapi.ai",
213+
DashboardURL: "https://dashboard.testing.vapi.ai",
214+
},
215+
```
216+
217+
2. Update scripts and documentation as needed.
218+
219+
### Security Considerations
220+
221+
- Environment switching is intentionally hidden from end users
222+
- API keys are masked in all output
223+
- Local development uses localhost URLs only
224+
- Production is always the default and safest option

Makefile

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,47 @@ install: build
8989
run: build
9090
$(BINARY_PATH)
9191

92-
# Help
92+
# Version management
93+
.PHONY: version version-get version-set version-bump-major version-bump-minor version-bump-patch
94+
version: version-get
95+
96+
version-get:
97+
@./scripts/version.sh get
98+
99+
version-set:
100+
@if [ -z "$(VERSION)" ]; then \
101+
echo "❌ VERSION is required. Usage: make version-set VERSION=1.2.3"; \
102+
exit 1; \
103+
fi
104+
@./scripts/version.sh set $(VERSION)
105+
106+
version-bump-major:
107+
@./scripts/version.sh bump major
108+
109+
version-bump-minor:
110+
@./scripts/version.sh bump minor
111+
112+
version-bump-patch:
113+
@./scripts/version.sh bump patch
114+
115+
# Help target to show available commands
93116
help:
94117
@echo "Available targets:"
95-
@echo " make build - Build the binary"
96-
@echo " make build-all - Build for all platforms"
97-
@echo " make test - Run tests"
98-
@echo " make test-coverage - Run tests with coverage"
99-
@echo " make clean - Clean build artifacts"
100-
@echo " make tidy - Run go mod tidy"
101-
@echo " make deps - Download dependencies"
102-
@echo " make lint - Run linters"
103-
@echo " make install - Install binary to ~/.local/bin"
104-
@echo " make run - Build and run the binary"
118+
@echo " build Build the CLI binary"
119+
@echo " install Install the CLI to ~/.local/bin"
120+
@echo " test Run all tests"
121+
@echo " lint Run linters"
122+
@echo " clean Clean build artifacts"
123+
@echo ""
124+
@echo "Version management:"
125+
@echo " version Show current version"
126+
@echo " version-set Set version (requires VERSION=x.y.z)"
127+
@echo " version-bump-major Bump major version (1.2.3 -> 2.0.0)"
128+
@echo " version-bump-minor Bump minor version (1.2.3 -> 1.3.0)"
129+
@echo " version-bump-patch Bump patch version (1.2.3 -> 1.2.4)"
130+
@echo ""
131+
@echo "Examples:"
132+
@echo " make version-set VERSION=1.2.3"
133+
@echo " make version-bump-patch"
105134

106135
.PHONY: all build build-all test test-coverage clean tidy deps lint install run help

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The official command-line interface for [Vapi](https://vapi.ai) - Voice AI for d
1313
- 🚀 **Framework Support** - React, Vue, Angular, Next.js, Node.js, Python, Go, and more
1414
- 📦 **SDK Installation** - Automatic SDK setup for your project type
1515
- 🎨 **Code Generation** - Generate components, hooks, and examples
16+
- ⬆️ **Auto-Updates** - Keep your CLI up-to-date with the latest features
1617

1718
## Installation
1819

@@ -149,6 +150,20 @@ vapi config set <key> <value>
149150
vapi config list
150151
```
151152

153+
### Staying Updated
154+
155+
Keep your CLI up-to-date with the latest features and bug fixes:
156+
157+
```bash
158+
# Check for available updates
159+
vapi update check
160+
161+
# Update to the latest version
162+
vapi update
163+
```
164+
165+
The CLI will automatically check for updates periodically and notify you when a new version is available.
166+
152167
## Project Structure
153168

154169
```
@@ -264,3 +279,56 @@ MIT License - see [LICENSE](LICENSE) file for details.
264279
---
265280

266281
Built with ❤️ by the Vapi team
282+
283+
## Version Management
284+
285+
The Vapi CLI uses a simple and discoverable version management system:
286+
287+
### Current Version
288+
289+
The current version is stored in the `VERSION` file at the project root. This makes it easy to find and update.
290+
291+
### Managing Versions
292+
293+
#### Using Make (Recommended)
294+
295+
```bash
296+
# Show current version
297+
make version
298+
299+
# Set a specific version
300+
make version-set VERSION=1.2.3
301+
302+
# Bump versions automatically
303+
make version-bump-patch # 1.2.3 -> 1.2.4
304+
make version-bump-minor # 1.2.3 -> 1.3.0
305+
make version-bump-major # 1.2.3 -> 2.0.0
306+
```
307+
308+
#### Using the Script Directly
309+
310+
```bash
311+
# Show current version
312+
./scripts/version.sh get
313+
314+
# Set a specific version
315+
./scripts/version.sh set 1.2.3
316+
317+
# Bump versions
318+
./scripts/version.sh bump patch
319+
./scripts/version.sh bump minor
320+
./scripts/version.sh bump major
321+
```
322+
323+
### How It Works
324+
325+
1. **Development**: The CLI reads the version from the `VERSION` file
326+
2. **Release Builds**: GoReleaser overrides the version using git tags and ldflags
327+
3. **Priority**: Build-time version (from releases) takes priority over the VERSION file
328+
329+
This approach provides:
330+
331+
- ✅ Easy version discovery (just check the `VERSION` file)
332+
- ✅ Automated version bumping with semantic versioning
333+
- ✅ Consistent versioning across development and releases
334+
- ✅ No need to manually edit code files

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.2

0 commit comments

Comments
 (0)