@codeguide/core 0.0.28 → 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/__tests__/services/usage/usage-service.test.ts +442 -83
- package/codeguide.ts +3 -0
- package/dist/codeguide.d.ts +2 -1
- package/dist/codeguide.js +1 -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 +257 -0
- package/dist/services/codespace/codespace-types.d.ts +192 -12
- package/dist/services/codespace/index.d.ts +1 -1
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +4 -1
- package/dist/services/projects/project-types.d.ts +66 -32
- 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 +150 -26
- 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 +444 -0
- 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 +291 -1
- 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 +337 -0
- package/services/codespace/codespace-types.ts +262 -13
- package/services/codespace/index.ts +16 -1
- package/services/index.ts +2 -0
- package/services/projects/README.md +107 -34
- package/services/projects/project-types.ts +69 -32
- 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 +178 -27
|
@@ -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
|
+
|