@codeguide/core 0.0.27 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -41
- package/__tests__/services/codespace/codespace-v2.test.ts +29 -18
- package/__tests__/services/usage/usage-service.test.ts +597 -85
- package/codeguide.ts +6 -0
- package/dist/codeguide.d.ts +3 -1
- package/dist/codeguide.js +2 -0
- package/dist/index.d.ts +4 -3
- package/dist/services/base/base-service.d.ts +21 -0
- package/dist/services/base/base-service.js +114 -0
- package/dist/services/codespace/codespace-service.d.ts +55 -1
- package/dist/services/codespace/codespace-service.js +260 -5
- package/dist/services/codespace/codespace-types.d.ts +193 -13
- package/dist/services/codespace/index.d.ts +1 -1
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +7 -1
- package/dist/services/projects/project-types.d.ts +66 -32
- package/dist/services/repository-analysis/repository-types.d.ts +1 -0
- package/dist/services/starter-kits/index.d.ts +2 -0
- package/dist/services/starter-kits/index.js +20 -0
- package/dist/services/starter-kits/starter-kits-service.d.ts +13 -0
- package/dist/services/starter-kits/starter-kits-service.js +27 -0
- package/dist/services/starter-kits/starter-kits-types.d.ts +34 -0
- package/dist/services/starter-kits/starter-kits-types.js +2 -0
- package/dist/services/tasks/task-service.d.ts +2 -1
- package/dist/services/tasks/task-service.js +8 -0
- package/dist/services/tasks/task-types.d.ts +26 -7
- package/dist/services/usage/usage-service.d.ts +5 -2
- package/dist/services/usage/usage-service.js +58 -9
- package/dist/services/usage/usage-types.d.ts +207 -34
- package/dist/services/users/index.d.ts +2 -0
- package/dist/services/users/index.js +20 -0
- package/dist/services/users/user-service.d.ts +12 -0
- package/dist/services/users/user-service.js +17 -0
- package/dist/services/users/user-types.d.ts +55 -0
- package/dist/services/users/user-types.js +2 -0
- package/docs/.vitepress/README.md +51 -0
- package/docs/.vitepress/config.ts +139 -0
- package/docs/.vitepress/theme/custom.css +80 -0
- package/docs/.vitepress/theme/index.ts +13 -0
- package/docs/.vitepress/tsconfig.json +19 -0
- package/docs/QUICKSTART.md +77 -0
- package/docs/README.md +134 -0
- package/docs/README_SETUP.md +46 -0
- package/docs/authentication.md +351 -0
- package/docs/codeguide-client.md +350 -0
- package/docs/codespace-models.md +1004 -0
- package/docs/codespace-service.md +558 -81
- package/docs/index.md +135 -0
- package/docs/package.json +14 -0
- package/docs/projects-service.md +688 -0
- package/docs/security-keys-service.md +773 -0
- package/docs/starter-kits-service.md +249 -0
- package/docs/task-service.md +955 -0
- package/docs/testsprite_tests/TC001_Homepage_Load_and_Hero_Section_Display.py +70 -0
- package/docs/testsprite_tests/TC002_Sidebar_Navigation_ExpandCollapse_Functionality.py +73 -0
- package/docs/testsprite_tests/TC003_Full_Text_Local_Search_with_Keyboard_Shortcut.py +90 -0
- package/docs/testsprite_tests/TC004_Dark_Mode_Toggle_and_Persistence.py +73 -0
- package/docs/testsprite_tests/TC005_Mobile_Responsiveness_and_Touch_Navigation.py +113 -0
- package/docs/testsprite_tests/TC006_GitHub_Integration_Edit_this_page_Links.py +73 -0
- package/docs/testsprite_tests/TC007_Syntax_Highlighting_and_Code_Copy_Functionality.py +73 -0
- package/docs/testsprite_tests/TC008_Auto_Generated_Table_of_Contents_Accuracy.py +73 -0
- package/docs/testsprite_tests/TC009_SEO_and_Content_Discoverability_Verification.py +73 -0
- package/docs/testsprite_tests/TC010_Accessibility_Compliance_WCAG_AA.py +73 -0
- package/docs/testsprite_tests/TC011_Local_Development_Workflow_Build_and_Hot_Reload.py +74 -0
- package/docs/testsprite_tests/TC012_Performance_Metrics_Compliance.py +73 -0
- package/docs/testsprite_tests/standard_prd.json +122 -0
- package/docs/testsprite_tests/testsprite-mcp-test-report.html +2508 -0
- package/docs/testsprite_tests/testsprite-mcp-test-report.md +273 -0
- package/docs/testsprite_tests/testsprite_frontend_test_plan.json +390 -0
- package/docs/usage-service.md +616 -0
- package/index.ts +11 -3
- package/package.json +16 -2
- package/plans/CODESPACE_LOGS_STREAMING_GUIDE.md +320 -0
- package/plans/CODESPACE_TASK_LOGS_API_COMPLETE_GUIDE.md +821 -0
- package/services/base/base-service.ts +130 -0
- package/services/codespace/codespace-service.ts +347 -8
- package/services/codespace/codespace-types.ts +263 -14
- package/services/codespace/index.ts +16 -1
- package/services/index.ts +4 -0
- package/services/projects/README.md +107 -34
- package/services/projects/project-types.ts +69 -32
- package/services/repository-analysis/repository-types.ts +1 -0
- package/services/starter-kits/index.ts +2 -0
- package/services/starter-kits/starter-kits-service.ts +33 -0
- package/services/starter-kits/starter-kits-types.ts +38 -0
- package/services/tasks/task-service.ts +10 -0
- package/services/tasks/task-types.ts +29 -7
- package/services/usage/usage-service.ts +59 -10
- package/services/usage/usage-types.ts +239 -34
- package/services/users/index.ts +2 -0
- package/services/users/user-service.ts +15 -0
- package/services/users/user-types.ts +59 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
# Authentication
|
|
2
|
+
|
|
3
|
+
The CodeGuide client supports multiple authentication methods with automatic priority handling. This guide covers all available authentication options and how they work.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The CodeGuide client automatically selects the best available authentication method based on priority:
|
|
8
|
+
|
|
9
|
+
1. **Database API Key** (Highest Priority) - Recommended
|
|
10
|
+
2. **Legacy API Key + User ID** (Medium Priority) - For backward compatibility
|
|
11
|
+
3. **Clerk JWT Token** (Lowest Priority) - For Clerk-based applications
|
|
12
|
+
|
|
13
|
+
## Authentication Methods
|
|
14
|
+
|
|
15
|
+
### 1. Database API Key (Recommended)
|
|
16
|
+
|
|
17
|
+
The recommended authentication method. Database API keys are prefixed with `sk_` and provide the most secure and flexible authentication.
|
|
18
|
+
|
|
19
|
+
#### Configuration
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { CodeGuide } from '@codeguide/core'
|
|
23
|
+
|
|
24
|
+
const codeguide = new CodeGuide({
|
|
25
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
26
|
+
databaseApiKey: 'sk_your_database_api_key', // Must start with 'sk_'
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### Features
|
|
31
|
+
|
|
32
|
+
- Highest priority authentication method
|
|
33
|
+
- No user ID required
|
|
34
|
+
- Supports all API features
|
|
35
|
+
- Can be scoped and managed through the API
|
|
36
|
+
|
|
37
|
+
#### Getting Your Database API Key
|
|
38
|
+
|
|
39
|
+
1. Sign up at [codeguide.ai](https://codeguide.ai)
|
|
40
|
+
2. Navigate to API Keys section
|
|
41
|
+
3. Create a new API key (format: `sk_...`)
|
|
42
|
+
4. Copy and store securely
|
|
43
|
+
|
|
44
|
+
### 2. Legacy API Key + User ID
|
|
45
|
+
|
|
46
|
+
For backward compatibility with older integrations. Requires both an API key and user ID.
|
|
47
|
+
|
|
48
|
+
#### Configuration
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { CodeGuide } from '@codeguide/core'
|
|
52
|
+
|
|
53
|
+
const codeguide = new CodeGuide({
|
|
54
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
55
|
+
apiKey: 'your_legacy_api_key',
|
|
56
|
+
userId: 'your_user_id', // Required for legacy auth
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Features
|
|
61
|
+
|
|
62
|
+
- Medium priority (used if database API key is not provided)
|
|
63
|
+
- Requires both `apiKey` and `userId`
|
|
64
|
+
- Backward compatible with older integrations
|
|
65
|
+
|
|
66
|
+
### 3. Clerk JWT Token
|
|
67
|
+
|
|
68
|
+
For applications using Clerk for authentication. Pass a valid Clerk JWT token.
|
|
69
|
+
|
|
70
|
+
#### Configuration
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { CodeGuide } from '@codeguide/core'
|
|
74
|
+
|
|
75
|
+
const codeguide = new CodeGuide({
|
|
76
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
77
|
+
jwtToken: 'your_clerk_jwt_token',
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Features
|
|
82
|
+
|
|
83
|
+
- Lowest priority (used if no other auth method is available)
|
|
84
|
+
- Requires valid Clerk JWT token
|
|
85
|
+
- Useful for Clerk-based applications
|
|
86
|
+
|
|
87
|
+
## Automatic Fallback
|
|
88
|
+
|
|
89
|
+
The client automatically falls back through authentication methods based on priority:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const codeguide = new CodeGuide({
|
|
93
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
94
|
+
databaseApiKey: 'sk_key', // Will try this first (Priority 1)
|
|
95
|
+
apiKey: 'legacy_key', // Fallback if database key invalid (Priority 2)
|
|
96
|
+
userId: 'user_id', // Required for legacy auth
|
|
97
|
+
jwtToken: 'jwt_token', // Final fallback (Priority 3)
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Priority Order:**
|
|
102
|
+
1. Database API Key (`databaseApiKey` with `sk_` prefix)
|
|
103
|
+
2. Legacy API Key + User ID (`apiKey` + `userId`)
|
|
104
|
+
3. Clerk JWT Token (`jwtToken`)
|
|
105
|
+
|
|
106
|
+
## Authentication Validation
|
|
107
|
+
|
|
108
|
+
### Check Current Authentication Method
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const authMethod = codeguide.projects.getAuthenticationMethod()
|
|
112
|
+
|
|
113
|
+
if (authMethod) {
|
|
114
|
+
console.log('Auth type:', authMethod.type)
|
|
115
|
+
console.log('Priority:', authMethod.priority)
|
|
116
|
+
console.log('Headers:', authMethod.headers)
|
|
117
|
+
} else {
|
|
118
|
+
console.log('No authentication configured')
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Validate Authentication Configuration
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const validation = codeguide.projects.validateAuthentication()
|
|
126
|
+
|
|
127
|
+
if (validation.success) {
|
|
128
|
+
console.log('Authentication is valid')
|
|
129
|
+
console.log('Method:', validation.method?.type)
|
|
130
|
+
} else {
|
|
131
|
+
console.error('Authentication error:', validation.error)
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Error Handling
|
|
136
|
+
|
|
137
|
+
### Authentication Errors
|
|
138
|
+
|
|
139
|
+
All authentication errors are thrown with descriptive messages:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
try {
|
|
143
|
+
const projects = await codeguide.projects.getAllProjects()
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (error.message.includes('401')) {
|
|
146
|
+
// Authentication failed
|
|
147
|
+
if (error.message.includes('Database API key')) {
|
|
148
|
+
console.error('Invalid database API key')
|
|
149
|
+
} else if (error.message.includes('Legacy API key')) {
|
|
150
|
+
console.error('Invalid legacy API key or user ID')
|
|
151
|
+
} else if (error.message.includes('Clerk JWT')) {
|
|
152
|
+
console.error('Invalid or expired JWT token')
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Common Error Scenarios
|
|
159
|
+
|
|
160
|
+
#### Invalid Database API Key
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// Error: Database API key authentication failed: Invalid, expired, or inactive API key
|
|
164
|
+
const codeguide = new CodeGuide({
|
|
165
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
166
|
+
databaseApiKey: 'sk_invalid_key',
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### Missing User ID for Legacy Auth
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
// Error: Legacy API key authentication requires both apiKey and userId
|
|
174
|
+
const codeguide = new CodeGuide({
|
|
175
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
176
|
+
apiKey: 'legacy_key',
|
|
177
|
+
// userId is missing
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Invalid JWT Token
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Error: Clerk JWT authentication failed: Invalid or expired token
|
|
185
|
+
const codeguide = new CodeGuide({
|
|
186
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
187
|
+
jwtToken: 'expired_token',
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Best Practices
|
|
192
|
+
|
|
193
|
+
### 1. Use Environment Variables
|
|
194
|
+
|
|
195
|
+
Store API keys securely in environment variables:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
import { CodeGuide } from '@codeguide/core'
|
|
199
|
+
|
|
200
|
+
const codeguide = new CodeGuide({
|
|
201
|
+
baseUrl: process.env.CODEGUIDE_API_URL || 'https://api.codeguide.ai',
|
|
202
|
+
databaseApiKey: process.env.CODEGUIDE_API_KEY, // sk_...
|
|
203
|
+
})
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### 2. Prefer Database API Keys
|
|
207
|
+
|
|
208
|
+
Use database API keys (`sk_...`) for new integrations:
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
// ✅ Recommended
|
|
212
|
+
const codeguide = new CodeGuide({
|
|
213
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
214
|
+
databaseApiKey: 'sk_your_key',
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
// ❌ Avoid if possible
|
|
218
|
+
const codeguide = new CodeGuide({
|
|
219
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
220
|
+
apiKey: 'legacy_key',
|
|
221
|
+
userId: 'user_id',
|
|
222
|
+
})
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 3. Handle Authentication Errors Gracefully
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
async function makeRequest() {
|
|
229
|
+
try {
|
|
230
|
+
return await codeguide.projects.getAllProjects()
|
|
231
|
+
} catch (error) {
|
|
232
|
+
if (error.message.includes('401')) {
|
|
233
|
+
// Retry with different auth method or show user-friendly error
|
|
234
|
+
throw new Error('Please check your API credentials')
|
|
235
|
+
}
|
|
236
|
+
throw error
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### 4. Validate Before Making Requests
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
const validation = codeguide.projects.validateAuthentication()
|
|
245
|
+
|
|
246
|
+
if (!validation.success) {
|
|
247
|
+
console.error('Authentication not configured:', validation.error)
|
|
248
|
+
return
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Proceed with API calls
|
|
252
|
+
const projects = await codeguide.projects.getAllProjects()
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### 5. Rotate Keys Regularly
|
|
256
|
+
|
|
257
|
+
Regularly rotate your API keys for security:
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
// Old key
|
|
261
|
+
const oldCodeguide = new CodeGuide({
|
|
262
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
263
|
+
databaseApiKey: 'sk_old_key',
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
// Create new key via API
|
|
267
|
+
const newKey = await oldCodeguide.apiKeyEnhanced.createApiKey({
|
|
268
|
+
name: 'New Production Key',
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
// Update to new key
|
|
272
|
+
const newCodeguide = new CodeGuide({
|
|
273
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
274
|
+
databaseApiKey: newKey.data.api_key,
|
|
275
|
+
})
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Security Considerations
|
|
279
|
+
|
|
280
|
+
### API Key Storage
|
|
281
|
+
|
|
282
|
+
- **Never commit API keys to version control**
|
|
283
|
+
- Use environment variables or secure key management services
|
|
284
|
+
- Rotate keys regularly
|
|
285
|
+
- Use different keys for different environments (dev, staging, production)
|
|
286
|
+
|
|
287
|
+
### Key Scoping
|
|
288
|
+
|
|
289
|
+
Database API keys can be scoped to specific permissions. Create keys with minimal required permissions:
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// Use scoped keys when possible
|
|
293
|
+
const codeguide = new CodeGuide({
|
|
294
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
295
|
+
databaseApiKey: 'sk_readonly_key', // Scoped to read-only operations
|
|
296
|
+
})
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Token Expiration
|
|
300
|
+
|
|
301
|
+
- JWT tokens expire after a set period
|
|
302
|
+
- Implement token refresh logic for Clerk-based applications
|
|
303
|
+
- Handle token expiration errors gracefully
|
|
304
|
+
|
|
305
|
+
## Examples
|
|
306
|
+
|
|
307
|
+
### Basic Setup
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
import { CodeGuide } from '@codeguide/core'
|
|
311
|
+
|
|
312
|
+
const codeguide = new CodeGuide({
|
|
313
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
314
|
+
databaseApiKey: process.env.CODEGUIDE_API_KEY!,
|
|
315
|
+
})
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### With Fallback
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
const codeguide = new CodeGuide({
|
|
322
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
323
|
+
databaseApiKey: process.env.CODEGUIDE_API_KEY,
|
|
324
|
+
// Fallback to legacy auth if database key not available
|
|
325
|
+
apiKey: process.env.LEGACY_API_KEY,
|
|
326
|
+
userId: process.env.USER_ID,
|
|
327
|
+
})
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Clerk Integration
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
import { useAuth } from '@clerk/nextjs'
|
|
334
|
+
|
|
335
|
+
function MyComponent() {
|
|
336
|
+
const { getToken } = useAuth()
|
|
337
|
+
|
|
338
|
+
const codeguide = new CodeGuide({
|
|
339
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
340
|
+
jwtToken: await getToken(),
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
// Use codeguide...
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## Related Documentation
|
|
348
|
+
|
|
349
|
+
- [CodeGuide Client](./codeguide-client.md) - Client initialization and configuration
|
|
350
|
+
- [Security Keys Service](./security-keys-service.md) - Managing provider API keys
|
|
351
|
+
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# CodeGuide Client
|
|
2
|
+
|
|
3
|
+
The `CodeGuide` class is the main entry point for interacting with the CodeGuide API. It provides access to all available services and handles authentication automatically.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The `CodeGuide` class initializes and manages all service instances, providing a unified interface to interact with the CodeGuide API.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @codeguide/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Basic Initialization
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { CodeGuide } from '@codeguide/core'
|
|
19
|
+
|
|
20
|
+
const codeguide = new CodeGuide({
|
|
21
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
22
|
+
databaseApiKey: 'sk_your_database_api_key',
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Constructor
|
|
27
|
+
|
|
28
|
+
### Signature
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
constructor(config: APIServiceConfig, options?: CodeGuideOptions)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Parameters
|
|
35
|
+
|
|
36
|
+
#### config: APIServiceConfig
|
|
37
|
+
|
|
38
|
+
The API service configuration object:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
interface APIServiceConfig {
|
|
42
|
+
baseUrl: string // Required: API base URL
|
|
43
|
+
databaseApiKey?: string // Recommended: Database API key (format: sk_...)
|
|
44
|
+
apiKey?: string // Legacy: Legacy API key
|
|
45
|
+
userId?: string // Legacy: User ID (required with apiKey)
|
|
46
|
+
jwtToken?: string // Alternative: Clerk JWT token
|
|
47
|
+
timeout?: number // Optional: Request timeout in milliseconds (default: 3600000)
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### options: CodeGuideOptions (Optional)
|
|
52
|
+
|
|
53
|
+
Additional options for the CodeGuide client:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
interface CodeGuideOptions {
|
|
57
|
+
language?: string // Default language for requests
|
|
58
|
+
context?: string // Default context for requests
|
|
59
|
+
verbose?: boolean // Enable verbose logging
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Example
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const codeguide = new CodeGuide(
|
|
67
|
+
{
|
|
68
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
69
|
+
databaseApiKey: 'sk_your_database_api_key',
|
|
70
|
+
timeout: 30000,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
language: 'typescript',
|
|
74
|
+
verbose: true,
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Available Services
|
|
80
|
+
|
|
81
|
+
The CodeGuide client provides access to the following services:
|
|
82
|
+
|
|
83
|
+
| Service | Property | Description |
|
|
84
|
+
|---------|----------|-------------|
|
|
85
|
+
| **Projects** | `codeguide.projects` | Project management and repository connections |
|
|
86
|
+
| **Codespace** | `codeguide.codespace` | AI-powered coding tasks and workflows |
|
|
87
|
+
| **Security Keys** | `codeguide.securityKeys` | Provider API keys and GitHub token management |
|
|
88
|
+
| **Usage** | `codeguide.usage` | Usage tracking and authorization |
|
|
89
|
+
| **Generation** | `codeguide.generation` | AI-powered code and document generation |
|
|
90
|
+
| **Repository Analysis** | `codeguide.repositoryAnalysis` | Repository analysis and insights |
|
|
91
|
+
| **Tasks** | `codeguide.tasks` | Task group and project task management |
|
|
92
|
+
| **API Key Enhanced** | `codeguide.apiKeyEnhanced` | Enhanced API key management |
|
|
93
|
+
| **Subscription** | `codeguide.subscription` | Subscription management |
|
|
94
|
+
| **Cancellation Funnel** | `codeguide.cancellationFunnel` | Subscription cancellation process |
|
|
95
|
+
| **External Tokens** | `codeguide.externalTokens` | External token management (GitHub, GitLab, etc.) |
|
|
96
|
+
| **Users** | `codeguide.users` | User management |
|
|
97
|
+
| **Starter Kits** | `codeguide.starterKits` | Retrieve starter kits for bootstrapping projects |
|
|
98
|
+
|
|
99
|
+
## Helper Methods
|
|
100
|
+
|
|
101
|
+
### getGuidance()
|
|
102
|
+
|
|
103
|
+
Convenience method for backward compatibility. Generates guidance from a prompt.
|
|
104
|
+
|
|
105
|
+
#### Signature
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
async getGuidance(prompt: string): Promise<any>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Parameters
|
|
112
|
+
|
|
113
|
+
- `prompt` (string, required): The user prompt
|
|
114
|
+
|
|
115
|
+
#### Returns
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
{
|
|
119
|
+
id: string
|
|
120
|
+
response: string
|
|
121
|
+
timestamp: string
|
|
122
|
+
language?: string
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Example
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const guidance = await codeguide.getGuidance(
|
|
130
|
+
'How do I implement user authentication?'
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
console.log(guidance.response)
|
|
134
|
+
console.log(guidance.timestamp)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### isHealthy()
|
|
138
|
+
|
|
139
|
+
Check if the API service is healthy and accessible.
|
|
140
|
+
|
|
141
|
+
#### Signature
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
async isHealthy(): Promise<boolean>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Returns
|
|
148
|
+
|
|
149
|
+
- `boolean`: `true` if the service is healthy, `false` otherwise
|
|
150
|
+
|
|
151
|
+
#### Example
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const healthy = await codeguide.isHealthy()
|
|
155
|
+
|
|
156
|
+
if (healthy) {
|
|
157
|
+
console.log('API is healthy')
|
|
158
|
+
} else {
|
|
159
|
+
console.log('API is not responding')
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### createTaskGroupWithCodespace()
|
|
164
|
+
|
|
165
|
+
Helper method to create a task group with codespace task integration.
|
|
166
|
+
|
|
167
|
+
#### Signature
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
async createTaskGroupWithCodespace(request: {
|
|
171
|
+
name: string
|
|
172
|
+
description?: string
|
|
173
|
+
project_id: string
|
|
174
|
+
include_codespace_task?: boolean
|
|
175
|
+
project_description?: string
|
|
176
|
+
}): Promise<any>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Parameters
|
|
180
|
+
|
|
181
|
+
- `request.name` (string, required): Task group name
|
|
182
|
+
- `request.description` (string, optional): Task group description
|
|
183
|
+
- `request.project_id` (string, required): Project ID
|
|
184
|
+
- `request.include_codespace_task` (boolean, optional): Include codespace task
|
|
185
|
+
- `request.project_description` (string, optional): Project description
|
|
186
|
+
|
|
187
|
+
#### Example
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
const taskGroup = await codeguide.createTaskGroupWithCodespace({
|
|
191
|
+
name: 'Authentication Implementation',
|
|
192
|
+
description: 'Implement user authentication system',
|
|
193
|
+
project_id: 'proj_123456',
|
|
194
|
+
include_codespace_task: true
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### setOptions()
|
|
199
|
+
|
|
200
|
+
Update the CodeGuide client options.
|
|
201
|
+
|
|
202
|
+
#### Signature
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
setOptions(options: Partial<CodeGuideOptions>): void
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### Parameters
|
|
209
|
+
|
|
210
|
+
- `options` (Partial<CodeGuideOptions>): Options to update
|
|
211
|
+
|
|
212
|
+
#### Example
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
codeguide.setOptions({
|
|
216
|
+
language: 'python',
|
|
217
|
+
verbose: false,
|
|
218
|
+
})
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Configuration
|
|
222
|
+
|
|
223
|
+
### Base URL
|
|
224
|
+
|
|
225
|
+
The `baseUrl` should point to your CodeGuide API endpoint:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
const codeguide = new CodeGuide({
|
|
229
|
+
baseUrl: 'https://api.codeguide.ai', // Production
|
|
230
|
+
// baseUrl: 'https://api.codeguide.dev', // Development
|
|
231
|
+
databaseApiKey: 'sk_your_key',
|
|
232
|
+
})
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Timeout Configuration
|
|
236
|
+
|
|
237
|
+
Configure the request timeout (in milliseconds). The default is 1 hour (3600000ms).
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
const codeguide = new CodeGuide({
|
|
241
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
242
|
+
databaseApiKey: 'sk_your_key',
|
|
243
|
+
timeout: 1800000, // 30 minutes
|
|
244
|
+
})
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Verbose Logging
|
|
248
|
+
|
|
249
|
+
Enable verbose logging to see detailed request and response information:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
const codeguide = new CodeGuide(
|
|
253
|
+
{
|
|
254
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
255
|
+
databaseApiKey: 'sk_your_key',
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
verbose: true, // Enable detailed logging
|
|
259
|
+
}
|
|
260
|
+
)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Complete Example
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { CodeGuide } from '@codeguide/core'
|
|
267
|
+
|
|
268
|
+
// Initialize the client
|
|
269
|
+
const codeguide = new CodeGuide({
|
|
270
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
271
|
+
databaseApiKey: process.env.CODEGUIDE_API_KEY!,
|
|
272
|
+
timeout: 30000,
|
|
273
|
+
}, {
|
|
274
|
+
language: 'typescript',
|
|
275
|
+
verbose: process.env.NODE_ENV === 'development',
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
// Check health
|
|
279
|
+
const isHealthy = await codeguide.isHealthy()
|
|
280
|
+
if (!isHealthy) {
|
|
281
|
+
throw new Error('API is not healthy')
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Get all projects
|
|
285
|
+
const projects = await codeguide.projects.getAllProjects()
|
|
286
|
+
console.log(`Found ${projects.length} projects`)
|
|
287
|
+
|
|
288
|
+
// Create a new project
|
|
289
|
+
const newProject = await codeguide.projects.createProject({
|
|
290
|
+
title: 'My New Project',
|
|
291
|
+
description: 'Project description',
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
// Create a codespace task
|
|
295
|
+
const task = await codeguide.codespace.createCodespaceTaskV2({
|
|
296
|
+
project_id: newProject.id,
|
|
297
|
+
task_description: 'Implement user authentication',
|
|
298
|
+
execution_mode: 'implementation',
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
console.log(`Created task: ${task.task_id}`)
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Error Handling
|
|
305
|
+
|
|
306
|
+
All methods throw errors for various failure conditions. It's recommended to wrap API calls in try-catch blocks:
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
try {
|
|
310
|
+
const projects = await codeguide.projects.getAllProjects()
|
|
311
|
+
} catch (error) {
|
|
312
|
+
if (error.message.includes('401')) {
|
|
313
|
+
console.error('Authentication failed:', error.message)
|
|
314
|
+
} else if (error.message.includes('403')) {
|
|
315
|
+
console.error('Permission denied:', error.message)
|
|
316
|
+
} else if (error.message.includes('429')) {
|
|
317
|
+
console.error('Rate limited:', error.message)
|
|
318
|
+
} else {
|
|
319
|
+
console.error('API error:', error.message)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Type Exports
|
|
325
|
+
|
|
326
|
+
The package exports all necessary types:
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
import type {
|
|
330
|
+
CodeGuide,
|
|
331
|
+
APIServiceConfig,
|
|
332
|
+
CodeGuideOptions,
|
|
333
|
+
} from '@codeguide/core'
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Best Practices
|
|
337
|
+
|
|
338
|
+
1. **Use Environment Variables**: Store API keys in environment variables
|
|
339
|
+
2. **Handle Errors**: Always wrap API calls in try-catch blocks
|
|
340
|
+
3. **Check Health**: Use `isHealthy()` before making critical requests
|
|
341
|
+
4. **Set Appropriate Timeouts**: Adjust timeout based on expected operation duration
|
|
342
|
+
5. **Enable Verbose Logging**: Use verbose mode during development for debugging
|
|
343
|
+
|
|
344
|
+
## Related Documentation
|
|
345
|
+
|
|
346
|
+
- [Authentication](./authentication.md) - Authentication methods and configuration
|
|
347
|
+
- [Projects Service](./projects-service.md) - Project management
|
|
348
|
+
- [Codespace Service](./codespace-service.md) - Codespace tasks
|
|
349
|
+
- [Security Keys Service](./security-keys-service.md) - Security key management
|
|
350
|
+
|