@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.
Files changed (79) hide show
  1. package/__tests__/services/usage/usage-service.test.ts +442 -83
  2. package/codeguide.ts +3 -0
  3. package/dist/codeguide.d.ts +2 -1
  4. package/dist/codeguide.js +1 -0
  5. package/dist/index.d.ts +4 -3
  6. package/dist/services/base/base-service.d.ts +21 -0
  7. package/dist/services/base/base-service.js +114 -0
  8. package/dist/services/codespace/codespace-service.d.ts +55 -1
  9. package/dist/services/codespace/codespace-service.js +257 -0
  10. package/dist/services/codespace/codespace-types.d.ts +192 -12
  11. package/dist/services/codespace/index.d.ts +1 -1
  12. package/dist/services/index.d.ts +2 -0
  13. package/dist/services/index.js +4 -1
  14. package/dist/services/projects/project-types.d.ts +66 -32
  15. package/dist/services/starter-kits/index.d.ts +2 -0
  16. package/dist/services/starter-kits/index.js +20 -0
  17. package/dist/services/starter-kits/starter-kits-service.d.ts +13 -0
  18. package/dist/services/starter-kits/starter-kits-service.js +27 -0
  19. package/dist/services/starter-kits/starter-kits-types.d.ts +34 -0
  20. package/dist/services/starter-kits/starter-kits-types.js +2 -0
  21. package/dist/services/tasks/task-service.d.ts +2 -1
  22. package/dist/services/tasks/task-service.js +8 -0
  23. package/dist/services/tasks/task-types.d.ts +26 -7
  24. package/dist/services/usage/usage-service.d.ts +5 -2
  25. package/dist/services/usage/usage-service.js +58 -9
  26. package/dist/services/usage/usage-types.d.ts +150 -26
  27. package/docs/.vitepress/README.md +51 -0
  28. package/docs/.vitepress/config.ts +139 -0
  29. package/docs/.vitepress/theme/custom.css +80 -0
  30. package/docs/.vitepress/theme/index.ts +13 -0
  31. package/docs/.vitepress/tsconfig.json +19 -0
  32. package/docs/QUICKSTART.md +77 -0
  33. package/docs/README.md +134 -0
  34. package/docs/README_SETUP.md +46 -0
  35. package/docs/authentication.md +351 -0
  36. package/docs/codeguide-client.md +350 -0
  37. package/docs/codespace-models.md +1004 -0
  38. package/docs/codespace-service.md +444 -0
  39. package/docs/index.md +135 -0
  40. package/docs/package.json +14 -0
  41. package/docs/projects-service.md +688 -0
  42. package/docs/security-keys-service.md +773 -0
  43. package/docs/starter-kits-service.md +249 -0
  44. package/docs/task-service.md +955 -0
  45. package/docs/testsprite_tests/TC001_Homepage_Load_and_Hero_Section_Display.py +70 -0
  46. package/docs/testsprite_tests/TC002_Sidebar_Navigation_ExpandCollapse_Functionality.py +73 -0
  47. package/docs/testsprite_tests/TC003_Full_Text_Local_Search_with_Keyboard_Shortcut.py +90 -0
  48. package/docs/testsprite_tests/TC004_Dark_Mode_Toggle_and_Persistence.py +73 -0
  49. package/docs/testsprite_tests/TC005_Mobile_Responsiveness_and_Touch_Navigation.py +113 -0
  50. package/docs/testsprite_tests/TC006_GitHub_Integration_Edit_this_page_Links.py +73 -0
  51. package/docs/testsprite_tests/TC007_Syntax_Highlighting_and_Code_Copy_Functionality.py +73 -0
  52. package/docs/testsprite_tests/TC008_Auto_Generated_Table_of_Contents_Accuracy.py +73 -0
  53. package/docs/testsprite_tests/TC009_SEO_and_Content_Discoverability_Verification.py +73 -0
  54. package/docs/testsprite_tests/TC010_Accessibility_Compliance_WCAG_AA.py +73 -0
  55. package/docs/testsprite_tests/TC011_Local_Development_Workflow_Build_and_Hot_Reload.py +74 -0
  56. package/docs/testsprite_tests/TC012_Performance_Metrics_Compliance.py +73 -0
  57. package/docs/testsprite_tests/standard_prd.json +122 -0
  58. package/docs/testsprite_tests/testsprite-mcp-test-report.html +2508 -0
  59. package/docs/testsprite_tests/testsprite-mcp-test-report.md +273 -0
  60. package/docs/testsprite_tests/testsprite_frontend_test_plan.json +390 -0
  61. package/docs/usage-service.md +291 -1
  62. package/index.ts +11 -3
  63. package/package.json +16 -2
  64. package/plans/CODESPACE_LOGS_STREAMING_GUIDE.md +320 -0
  65. package/plans/CODESPACE_TASK_LOGS_API_COMPLETE_GUIDE.md +821 -0
  66. package/services/base/base-service.ts +130 -0
  67. package/services/codespace/codespace-service.ts +337 -0
  68. package/services/codespace/codespace-types.ts +262 -13
  69. package/services/codespace/index.ts +16 -1
  70. package/services/index.ts +2 -0
  71. package/services/projects/README.md +107 -34
  72. package/services/projects/project-types.ts +69 -32
  73. package/services/starter-kits/index.ts +2 -0
  74. package/services/starter-kits/starter-kits-service.ts +33 -0
  75. package/services/starter-kits/starter-kits-types.ts +38 -0
  76. package/services/tasks/task-service.ts +10 -0
  77. package/services/tasks/task-types.ts +29 -7
  78. package/services/usage/usage-service.ts +59 -10
  79. package/services/usage/usage-types.ts +178 -27
package/docs/README.md ADDED
@@ -0,0 +1,134 @@
1
+ ---
2
+ layout: home
3
+
4
+ hero:
5
+ name: "@codeguide/core"
6
+ text: "TypeScript SDK"
7
+ tagline: Complete TypeScript SDK for integrating CodeGuide functionality into your applications
8
+ actions:
9
+ - theme: brand
10
+ text: Get Started
11
+ link: /codeguide-client
12
+ - theme: alt
13
+ text: View on GitHub
14
+ link: https://github.com/CodeGuide-dev/codeguide
15
+
16
+ features:
17
+ - title: 🔑 Multiple Authentication Methods
18
+ details: Database API keys, legacy keys, and JWT tokens with automatic fallback
19
+ - title: 📝 Project Management
20
+ details: Create, update, and manage projects programmatically with full CRUD operations
21
+ - title: 🤖 Codespace Tasks
22
+ details: Create and manage AI-powered coding tasks with support for multiple execution modes
23
+ - title: 🎯 Model Management
24
+ details: Query and manage LLM models and providers for your codespace tasks
25
+ - title: 🔐 Security Keys
26
+ details: Securely manage provider API keys and GitHub tokens with encryption
27
+ - title: 🛡️ TypeScript Support
28
+ details: Full type safety and IntelliSense support for all API methods
29
+ ---
30
+
31
+ ## Quick Start
32
+
33
+ ### Installation
34
+
35
+ ```bash
36
+ npm install @codeguide/core
37
+ ```
38
+
39
+ ### Basic Usage
40
+
41
+ ```typescript
42
+ import { CodeGuide } from '@codeguide/core'
43
+
44
+ // Initialize the CodeGuide client
45
+ const codeguide = new CodeGuide({
46
+ baseUrl: 'https://api.codeguide.ai',
47
+ databaseApiKey: 'sk_your_database_api_key', // Recommended
48
+ })
49
+
50
+ // Access services
51
+ const projects = await codeguide.projects.getAllProjects()
52
+ const tasks = await codeguide.codespace.getCodespaceTasksByProject({
53
+ project_id: 'your_project_id'
54
+ })
55
+ ```
56
+
57
+ ## Documentation Structure
58
+
59
+ ### Core Components
60
+
61
+ - **[CodeGuide Client](./codeguide-client.md)** - Main client class and initialization
62
+ - **[Authentication](./authentication.md)** - Authentication methods and configuration
63
+
64
+ ### Services
65
+
66
+ - **[Projects Service](./projects-service.md)** - Project management and repository connections
67
+ - **[Codespace Service](./codespace-service.md)** - AI-powered coding tasks and workflows
68
+ - **[Codespace Models](./codespace-models.md)** - LLM model providers and model management
69
+ - **[Security Keys Service](./security-keys-service.md)** - Provider API keys and GitHub token management
70
+ - **[Usage Service](./usage-service.md)** - Usage tracking and authorization
71
+
72
+ ## Features
73
+
74
+ - 🔑 **Multiple Authentication Methods** - Database API keys, legacy keys, and JWT tokens
75
+ - 📝 **Project Management** - Create, update, and manage projects programmatically
76
+ - 🤖 **Codespace Tasks** - Create and manage AI-powered coding tasks
77
+ - 🎯 **Model Management** - Query and manage LLM models and providers
78
+ - 🔐 **Security Keys** - Securely manage provider API keys and GitHub tokens
79
+ - 📊 **Usage Tracking** - Monitor API usage and credits
80
+ - 🛡️ **TypeScript Support** - Full type safety and IntelliSense
81
+
82
+ ## Getting Started
83
+
84
+ 1. **Install the package**: `npm install @codeguide/core`
85
+ 2. **Get your API key**: Sign up at [codeguide.ai](https://codeguide.ai) to get your API key
86
+ 3. **Initialize the client**: See [CodeGuide Client](./codeguide-client.md) for setup instructions
87
+ 4. **Authenticate**: See [Authentication](./authentication.md) for authentication options
88
+ 5. **Start building**: Explore the service documentation to learn about available features
89
+
90
+ ## Common Use Cases
91
+
92
+ ### Creating a Project
93
+
94
+ ```typescript
95
+ const project = await codeguide.projects.createProject({
96
+ title: 'My New Project',
97
+ description: 'Project description here'
98
+ })
99
+ ```
100
+
101
+ ### Creating a Codespace Task
102
+
103
+ ```typescript
104
+ const task = await codeguide.codespace.createCodespaceTaskV2({
105
+ project_id: project.id,
106
+ task_description: 'Implement user authentication',
107
+ execution_mode: 'implementation'
108
+ })
109
+ ```
110
+
111
+ ### Managing Security Keys
112
+
113
+ ```typescript
114
+ // Store a provider API key
115
+ await codeguide.securityKeys.createProviderAPIKey({
116
+ provider_key: 'openai',
117
+ api_key: 'sk-your-openai-key'
118
+ })
119
+
120
+ // Store a GitHub token
121
+ await codeguide.securityKeys.createGitHubToken({
122
+ github_token: 'ghp_your_github_token'
123
+ })
124
+ ```
125
+
126
+ ## Support
127
+
128
+ - **GitHub**: [CodeGuide Repository](https://github.com/CodeGuide-dev/codeguide)
129
+ - **Issues**: [GitHub Issues](https://github.com/CodeGuide-dev/codeguide/issues)
130
+ - **Documentation**: This documentation site
131
+
132
+ ## License
133
+
134
+ MIT License - see the LICENSE file for details.
@@ -0,0 +1,46 @@
1
+ # VitePress Setup Instructions
2
+
3
+ ## The Issue
4
+
5
+ VitePress is an ESM-only package, but Node.js was trying to load it with CommonJS `require()`. This has been fixed by creating a separate `package.json` in the `docs/` directory with `"type": "module"`.
6
+
7
+ ## Setup Steps
8
+
9
+ 1. **Install dependencies in the docs directory**:
10
+ ```bash
11
+ cd packages/core
12
+ npm run docs:install
13
+ ```
14
+
15
+ Or manually:
16
+ ```bash
17
+ cd packages/core/docs
18
+ npm install
19
+ ```
20
+
21
+ 2. **Start the development server**:
22
+ ```bash
23
+ cd packages/core
24
+ npm run docs:dev
25
+ ```
26
+
27
+ 3. **Open your browser**:
28
+ Navigate to http://localhost:5173
29
+
30
+ ## Available Commands
31
+
32
+ From `packages/core/`:
33
+ - `npm run docs:dev` - Start development server
34
+ - `npm run docs:build` - Build for production
35
+ - `npm run docs:preview` - Preview the built site
36
+ - `npm run docs:install` - Install docs dependencies
37
+
38
+ Or from `packages/core/docs/`:
39
+ - `npm run dev` - Start development server
40
+ - `npm run build` - Build for production
41
+ - `npm run preview` - Preview the built site
42
+
43
+ ## Why Separate package.json?
44
+
45
+ The docs directory has its own `package.json` with `"type": "module"` to ensure VitePress (which is ESM-only) works correctly without affecting the main package's CommonJS setup.
46
+
@@ -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
+