@codeguide/core 0.0.22 → 0.0.24
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 +176 -292
- package/dist/examples/project-filtering-example.d.ts +2 -0
- package/dist/examples/project-filtering-example.js +89 -0
- package/dist/index.d.ts +2 -2
- package/dist/services/codespace/codespace-service.d.ts +5 -1
- package/dist/services/codespace/codespace-service.js +75 -1
- package/dist/services/codespace/codespace-types.d.ts +48 -0
- package/dist/services/codespace/index.d.ts +1 -1
- package/dist/services/projects/project-service.d.ts +2 -2
- package/dist/services/projects/project-service.js +9 -2
- package/dist/services/projects/project-types.d.ts +16 -0
- package/dist/services/repository-analysis/repository-types.d.ts +14 -1
- package/docs/codespace-service.md +601 -0
- package/examples/project-filtering-example.ts +98 -0
- package/index.ts +9 -1
- package/package.json +1 -1
- package/services/codespace/codespace-service.ts +107 -7
- package/services/codespace/codespace-types.ts +58 -1
- package/services/codespace/index.ts +4 -1
- package/services/projects/README.md +226 -0
- package/services/projects/project-service.ts +11 -2
- package/services/projects/project-types.ts +18 -0
- package/services/repository-analysis/repository-types.ts +15 -1
package/README.md
CHANGED
|
@@ -2,21 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
The core package for CodeGuide with programmatic API access. This package provides TypeScript interfaces and services for integrating CodeGuide functionality into your applications.
|
|
4
4
|
|
|
5
|
+
## Services Overview
|
|
6
|
+
|
|
7
|
+
The `@codeguide/core` package provides a suite of services to interact with the CodeGuide API:
|
|
8
|
+
|
|
9
|
+
- **[ApiKeyEnhancedService](#apikeyenhancedservice)**: Manages API keys with enhanced features.
|
|
10
|
+
- **[ProjectService](#projectservice)**: Handles project creation, retrieval, and management.
|
|
11
|
+
- **[TaskService](#taskservice)**: Organizes and tracks development tasks within projects.
|
|
12
|
+
- **[CodespaceService](#codespaceservice)**: Manages AI-powered coding tasks, from generation to execution.
|
|
13
|
+
- **[GenerationService](#generationservice)**: Provides AI-powered code and document generation.
|
|
14
|
+
- **[RepositoryAnalysisService](#repositoryanalysisservice)**: Analyzes GitHub repositories for insights and documentation.
|
|
15
|
+
- **[ExternalTokenService](#externaltokenservice)**: Securely stores and manages external API tokens (e.g., GitHub, GitLab).
|
|
16
|
+
- **[SubscriptionService](#subscriptionservice)**: Manages user subscriptions and plans.
|
|
17
|
+
- **[UsageService](#usageservice)**: Monitors API usage, credits, and service health.
|
|
18
|
+
- **[CancellationFunnelService](#cancellationfunnelservice)**: Handles the subscription cancellation process.
|
|
19
|
+
|
|
5
20
|
## Features
|
|
6
21
|
|
|
7
|
-
- 🔑 **API Key Management**: Full CRUD operations for API keys
|
|
8
|
-
- 📝 **Project Management**: Create and manage projects programmatically
|
|
9
|
-
- 🎯 **Task Management**: Organize and track development tasks
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- 🔐 **
|
|
14
|
-
-
|
|
22
|
+
- 🔑 **API Key Management**: Full CRUD operations for API keys.
|
|
23
|
+
- 📝 **Project Management**: Create and manage projects programmatically.
|
|
24
|
+
- 🎯 **Task Management**: Organize and track development tasks.
|
|
25
|
+
- 🤖 **Codespace Tasks**: Create and manage AI-powered coding tasks and workflows.
|
|
26
|
+
- 🎨 **Code Generation**: Generate code, documentation, and more with AI assistance.
|
|
27
|
+
- 🔍 **Repository Analysis**: Analyze code repositories for insights.
|
|
28
|
+
- 🔐 **External Token Management**: Securely store and manage external tokens (e.g., GitHub, GitLab).
|
|
29
|
+
- 💳 **Subscription Management**: Programmatically manage user subscriptions.
|
|
30
|
+
- 📊 **Usage Analytics**: Monitor API usage and credits.
|
|
31
|
+
- 🛡️ **TypeScript Support**: Full type safety and IntelliSense.
|
|
32
|
+
- ⚙️ **Multiple Authentication Methods**: Flexible auth options including database API keys, legacy keys, and JWTs.
|
|
15
33
|
|
|
16
34
|
## Installation
|
|
17
35
|
|
|
18
36
|
```bash
|
|
19
|
-
npm install @codeguide/core@0.0.
|
|
37
|
+
npm install @codeguide/core@0.0.23
|
|
20
38
|
```
|
|
21
39
|
|
|
22
40
|
## Quick Start
|
|
@@ -42,40 +60,30 @@ const newKey = await codeguide.apiKeyEnhanced.createApiKey({
|
|
|
42
60
|
console.log(`Created key: ${newKey.data.api_key}`)
|
|
43
61
|
```
|
|
44
62
|
|
|
45
|
-
###
|
|
63
|
+
### Codespace Task Management
|
|
46
64
|
|
|
47
65
|
```typescript
|
|
48
|
-
import {
|
|
49
|
-
CodeGuide,
|
|
50
|
-
ApiKeyListResponse,
|
|
51
|
-
CreateApiKeyRequest
|
|
52
|
-
} from '@codeguide/core'
|
|
66
|
+
import { CodeGuide } from '@codeguide/core'
|
|
53
67
|
|
|
54
68
|
const codeguide = new CodeGuide({
|
|
55
69
|
baseUrl: 'https://api.codeguide.ai',
|
|
56
70
|
databaseApiKey: 'sk_your_database_api_key'
|
|
57
71
|
})
|
|
58
72
|
|
|
59
|
-
//
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Create a new key
|
|
69
|
-
const createRequest: CreateApiKeyRequest = {
|
|
70
|
-
name: 'Production Application'
|
|
71
|
-
}
|
|
72
|
-
const newKey = await codeguide.apiKeyEnhanced.createApiKey(createRequest)
|
|
73
|
+
// Create a new codespace task for implementation
|
|
74
|
+
const codespaceTask = await codeguide.codespace.createCodespaceTaskV2({
|
|
75
|
+
project_id: "your_project_id",
|
|
76
|
+
task_description: "Implement a new feature for real-time notifications",
|
|
77
|
+
execution_mode: "implementation"
|
|
78
|
+
});
|
|
79
|
+
console.log(`Created codespace task: ${codespaceTask.task_id}`);
|
|
73
80
|
|
|
74
|
-
//
|
|
75
|
-
await codeguide.
|
|
81
|
+
// Get task details
|
|
82
|
+
const taskDetails = await codeguide.codespace.getCodespaceTask(codespaceTask.task_id);
|
|
83
|
+
console.log(`Task status: ${taskDetails.data.status}`);
|
|
76
84
|
```
|
|
77
85
|
|
|
78
|
-
###
|
|
86
|
+
### Subscription Management
|
|
79
87
|
|
|
80
88
|
```typescript
|
|
81
89
|
import { CodeGuide } from '@codeguide/core'
|
|
@@ -85,20 +93,16 @@ const codeguide = new CodeGuide({
|
|
|
85
93
|
databaseApiKey: 'sk_your_database_api_key'
|
|
86
94
|
})
|
|
87
95
|
|
|
88
|
-
//
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
description: 'A modern web app built with React'
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
// Get project details
|
|
95
|
-
const projectDetails = await codeguide.projects.getProject(project.id)
|
|
96
|
+
// Get current subscription
|
|
97
|
+
const subscription = await codeguide.subscription.getCurrentSubscription();
|
|
98
|
+
console.log(`Current plan: ${subscription.data.product.name} (${subscription.data.subscription.status})`);
|
|
96
99
|
|
|
97
|
-
//
|
|
98
|
-
const
|
|
100
|
+
// Get all subscriptions (including historical)
|
|
101
|
+
const allSubscriptions = await codeguide.subscription.getAllSubscriptions();
|
|
102
|
+
console.log(`Found ${allSubscriptions.data.length} total subscriptions.`);
|
|
99
103
|
```
|
|
100
104
|
|
|
101
|
-
###
|
|
105
|
+
### External Token Management
|
|
102
106
|
|
|
103
107
|
```typescript
|
|
104
108
|
import { CodeGuide } from '@codeguide/core'
|
|
@@ -108,20 +112,18 @@ const codeguide = new CodeGuide({
|
|
|
108
112
|
databaseApiKey: 'sk_your_database_api_key'
|
|
109
113
|
})
|
|
110
114
|
|
|
111
|
-
//
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
// Store a GitHub token
|
|
116
|
+
const storedToken = await codeguide.externalTokens.storeExternalToken({
|
|
117
|
+
platform: 'github',
|
|
118
|
+
token: 'ghp_your_github_token',
|
|
119
|
+
token_name: 'My Personal GitHub Token',
|
|
120
|
+
token_type: 'personal_access_token'
|
|
121
|
+
});
|
|
122
|
+
console.log(`Stored token with ID: ${storedToken.id}`);
|
|
116
123
|
|
|
117
|
-
//
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
// Update task status
|
|
121
|
-
await codeguide.tasks.updateTask('task-id-123', {
|
|
122
|
-
status: 'in_progress',
|
|
123
|
-
notes: 'Started working on authentication module'
|
|
124
|
-
})
|
|
124
|
+
// List all stored GitHub tokens
|
|
125
|
+
const githubTokens = await codeguide.externalTokens.listTokens({ platform: 'github' });
|
|
126
|
+
console.log(`Found ${githubTokens.tokens.length} GitHub tokens.`);
|
|
125
127
|
```
|
|
126
128
|
|
|
127
129
|
## Authentication
|
|
@@ -130,6 +132,8 @@ The CodeGuide client supports multiple authentication methods with automatic pri
|
|
|
130
132
|
|
|
131
133
|
### 1. Database API Key (Highest Priority)
|
|
132
134
|
|
|
135
|
+
Recommended method. The key must be prefixed with `sk_`.
|
|
136
|
+
|
|
133
137
|
```typescript
|
|
134
138
|
const codeguide = new CodeGuide({
|
|
135
139
|
baseUrl: 'https://api.codeguide.ai',
|
|
@@ -139,6 +143,8 @@ const codeguide = new CodeGuide({
|
|
|
139
143
|
|
|
140
144
|
### 2. Legacy API Key + User ID
|
|
141
145
|
|
|
146
|
+
For backward compatibility.
|
|
147
|
+
|
|
142
148
|
```typescript
|
|
143
149
|
const codeguide = new CodeGuide({
|
|
144
150
|
baseUrl: 'https://api.codeguide.ai',
|
|
@@ -149,6 +155,8 @@ const codeguide = new CodeGuide({
|
|
|
149
155
|
|
|
150
156
|
### 3. Clerk JWT Token
|
|
151
157
|
|
|
158
|
+
For applications using Clerk for authentication.
|
|
159
|
+
|
|
152
160
|
```typescript
|
|
153
161
|
const codeguide = new CodeGuide({
|
|
154
162
|
baseUrl: 'https://api.codeguide.ai',
|
|
@@ -158,13 +166,13 @@ const codeguide = new CodeGuide({
|
|
|
158
166
|
|
|
159
167
|
### Automatic Fallback
|
|
160
168
|
|
|
161
|
-
The client automatically falls back through authentication methods
|
|
169
|
+
The client automatically falls back through authentication methods based on the priority order (1 > 2 > 3).
|
|
162
170
|
|
|
163
171
|
```typescript
|
|
164
172
|
const codeguide = new CodeGuide({
|
|
165
173
|
baseUrl: 'https://api.codeguide.ai',
|
|
166
174
|
databaseApiKey: 'sk_key', // Will try this first
|
|
167
|
-
apiKey: 'legacy_key', // Fallback if database key
|
|
175
|
+
apiKey: 'legacy_key', // Fallback if database key is invalid or missing
|
|
168
176
|
userId: 'user_id', // Required for legacy auth
|
|
169
177
|
jwtToken: 'jwt_token' // Final fallback
|
|
170
178
|
})
|
|
@@ -174,161 +182,147 @@ const codeguide = new CodeGuide({
|
|
|
174
182
|
|
|
175
183
|
### ApiKeyEnhancedService
|
|
176
184
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
185
|
+
- `getAllApiKeys(): Promise<ApiKeyListResponse>`
|
|
186
|
+
- `createApiKey(request: CreateApiKeyRequest): Promise<CreateApiKeyResponse>`
|
|
187
|
+
- `revokeApiKey(apiKeyId: string): Promise<RevokeApiKeyResponse>`
|
|
188
|
+
- `checkApiKeyPermission(): Promise<ApiKeyPermissionResponse>`
|
|
189
|
+
- `getApiKeyById(apiKeyId: string): Promise<ApiKeyResponse>`
|
|
182
190
|
|
|
183
|
-
|
|
191
|
+
### ProjectService
|
|
184
192
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
193
|
+
- `getAllProjects(params?: GetProjectsRequest): Promise<Project[]>`
|
|
194
|
+
- `getPaginatedProjects(params: PaginatedProjectsRequest): Promise<PaginatedProjectsResponse>`
|
|
195
|
+
- `getProjectById(projectId: string): Promise<Project>`
|
|
196
|
+
- `createProject(request: CreateProjectRequest): Promise<Project>`
|
|
197
|
+
- `updateProject(projectId: string, request: UpdateProjectRequest): Promise<Project>`
|
|
198
|
+
- `deleteProject(projectId: string): Promise<{ status: string; message: string }>`
|
|
199
|
+
- `connectRepository(projectId: string, request: ConnectRepositoryRequest): Promise<ConnectRepositoryResponse>`
|
|
190
200
|
|
|
191
|
-
|
|
192
|
-
```typescript
|
|
193
|
-
async createApiKey(request: CreateApiKeyRequest): Promise<CreateApiKeyResponse>
|
|
194
|
-
```
|
|
195
|
-
Create a new API key.
|
|
201
|
+
### TaskService
|
|
196
202
|
|
|
197
|
-
|
|
198
|
-
- `
|
|
203
|
+
- `getAllTaskGroups(): Promise<TaskGroup[]>`
|
|
204
|
+
- `getPaginatedTaskGroups(params: PaginatedTaskGroupsRequest): Promise<PaginatedTaskGroupsResponse>`
|
|
205
|
+
- `createTaskGroup(request: CreateTaskGroupRequest): Promise<TaskGroup>`
|
|
206
|
+
- `getProjectTaskById(taskId: string): Promise<ProjectTask>`
|
|
207
|
+
- `createProjectTask(request: CreateProjectTaskRequest): Promise<ProjectTask>`
|
|
208
|
+
- `updateProjectTask(taskId: string, request: UpdateProjectTaskRequest): Promise<ProjectTask>`
|
|
199
209
|
|
|
200
|
-
|
|
210
|
+
### CodespaceService
|
|
201
211
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
console.log(response.data.api_key) // The new API key
|
|
208
|
-
```
|
|
212
|
+
- `createCodespaceTaskV2(request: CreateCodespaceTaskRequestV2): Promise<CreateCodespaceTaskResponseV2>`
|
|
213
|
+
- `createBackgroundCodespaceTask(request: CreateBackgroundCodespaceTaskRequest): Promise<CreateBackgroundCodespaceTaskResponse>`
|
|
214
|
+
- `getCodespaceTask(codespaceTaskId: string): Promise<GetCodespaceTaskResponse>`
|
|
215
|
+
- `getCodespaceTasksByProject(params: GetCodespaceTasksByProjectRequest): Promise<GetCodespaceTasksByProjectResponse>`
|
|
216
|
+
- `getCodespaceTaskDetailed(codespaceTaskId: string): Promise<CodespaceTaskDetailedResponse>`
|
|
209
217
|
|
|
210
|
-
|
|
211
|
-
```typescript
|
|
212
|
-
async revokeApiKey(apiKeyId: string): Promise<RevokeApiKeyResponse>
|
|
213
|
-
```
|
|
214
|
-
Revoke an API key by ID.
|
|
218
|
+
### GenerationService
|
|
215
219
|
|
|
216
|
-
|
|
217
|
-
- `
|
|
220
|
+
- `refinePrompt(request: RefinePromptRequest): Promise<RefinePromptResponse>`
|
|
221
|
+
- `generateTitle(request: GenerateTitleRequest): Promise<GenerateTitleResponse>`
|
|
222
|
+
- `generatePRD(request: GeneratePRDRequest): Promise<GeneratePRDResponse>`
|
|
223
|
+
- `generateDocument(request: GenerateDocumentRequest): Promise<GenerateDocumentResponse>`
|
|
224
|
+
- `startBackgroundGeneration(request: BackgroundGenerationRequest): Promise<BackgroundGenerationResponse>`
|
|
225
|
+
- `getBackgroundGenerationStatus(jobId: string): Promise<BackgroundGenerationStatusResponse>`
|
|
218
226
|
|
|
219
|
-
|
|
227
|
+
### RepositoryAnalysisService
|
|
220
228
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
Check if the user can create new API keys.
|
|
229
|
+
- `analyzeRepository(request: AnalyzeRepositoryRequest): Promise<AnalyzeRepositoryResponse>`
|
|
230
|
+
- `getAnalysisStatus(taskId: string): Promise<RepositoryAnalysisStatusResponse>`
|
|
231
|
+
- `getAnalysisResult(taskId: string): Promise<RepositoryAnalysisResultResponse>`
|
|
232
|
+
- `listRepositories(skip?: number, limit?: number): Promise<RepositoryListResponse>`
|
|
226
233
|
|
|
227
|
-
|
|
234
|
+
### ExternalTokenService
|
|
228
235
|
|
|
229
|
-
|
|
236
|
+
- `storeExternalToken(request: StoreExternalTokenRequest): Promise<StoreExternalTokenResponse>`
|
|
237
|
+
- `listTokens(query?: ListTokensQuery): Promise<ListTokensResponse>`
|
|
238
|
+
- `getToken(tokenId: string): Promise<GetTokenResponse>`
|
|
239
|
+
- `validateToken(request: ValidateTokenRequest): Promise<ValidateTokenResponse>`
|
|
240
|
+
- `findBestMatch(request: FindBestMatchRequest): Promise<FindBestMatchResponse>`
|
|
241
|
+
- `revokeToken(tokenId: string): Promise<RevokeTokenResponse>`
|
|
230
242
|
|
|
231
|
-
|
|
232
|
-
```typescript
|
|
233
|
-
async createProject(request: CreateProjectRequest): Promise<ProjectResponse>
|
|
234
|
-
```
|
|
235
|
-
Create a new project.
|
|
236
|
-
|
|
237
|
-
#### getProject(projectId)
|
|
238
|
-
```typescript
|
|
239
|
-
async getProject(projectId: string): Promise<ProjectResponse>
|
|
240
|
-
```
|
|
241
|
-
Get project details by ID.
|
|
242
|
-
|
|
243
|
-
#### getAllProjects()
|
|
244
|
-
```typescript
|
|
245
|
-
async getAllProjects(): Promise<ProjectsListResponse>
|
|
246
|
-
```
|
|
247
|
-
Get all projects for the authenticated user.
|
|
243
|
+
### SubscriptionService
|
|
248
244
|
|
|
249
|
-
|
|
245
|
+
- `getCurrentSubscription(): Promise<CurrentSubscriptionResponse>`
|
|
246
|
+
- `getAllSubscriptions(): Promise<UserSubscriptionsResponse>`
|
|
247
|
+
- `cancelSubscription(subscriptionId: string, request: CancelSubscriptionRequest): Promise<CancelSubscriptionResponse>`
|
|
248
|
+
- `getSubscriptionById(subscriptionId: string): Promise<any>`
|
|
250
249
|
|
|
251
|
-
|
|
252
|
-
```typescript
|
|
253
|
-
async generateTasks(request: GenerateTasksRequest): Promise<TasksResponse>
|
|
254
|
-
```
|
|
255
|
-
Generate tasks for a project.
|
|
250
|
+
### UsageService
|
|
256
251
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
Get all tasks for a project.
|
|
252
|
+
- `getCreditBalance(): Promise<CreditBalanceResponse>`
|
|
253
|
+
- `getUsageSummary(params?: UsageSummaryRequest): Promise<UsageSummaryResponse>`
|
|
254
|
+
- `checkCredits(params: CreditCheckRequest): Promise<CreditCheckResponse>`
|
|
255
|
+
- `healthCheck(): Promise<boolean>`
|
|
262
256
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
Update task status and notes.
|
|
257
|
+
### CancellationFunnelService
|
|
258
|
+
- `initiateCancellation(request: CancellationFunnelInitiateRequest): Promise<CancellationFunnelInitiateResponse>`
|
|
259
|
+
- `logSurveyResponse(request: CancellationFunnelSurveyRequest): Promise<CancellationFunnelSurveyResponse>`
|
|
260
|
+
- `getCancellationFunnelStatus(subscriptionId: string): Promise<any>`
|
|
268
261
|
|
|
269
262
|
## Types
|
|
270
263
|
|
|
271
|
-
|
|
264
|
+
The package exports all necessary types for requests and responses.
|
|
265
|
+
|
|
266
|
+
### Core Types
|
|
272
267
|
```typescript
|
|
273
|
-
interface
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
is_active: boolean
|
|
281
|
-
metadata?: Record<string, any>
|
|
268
|
+
interface APIServiceConfig {
|
|
269
|
+
baseUrl: string
|
|
270
|
+
databaseApiKey?: string // Highest priority (sk_...)
|
|
271
|
+
apiKey?: string // Legacy API key
|
|
272
|
+
userId?: string // Required for legacy auth
|
|
273
|
+
jwtToken?: string // Clerk JWT token
|
|
274
|
+
timeout?: number // Default: 3600000 (1 hour)
|
|
282
275
|
}
|
|
283
|
-
```
|
|
284
276
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
data: ApiKey[]
|
|
277
|
+
interface CodeGuideOptions {
|
|
278
|
+
language?: string
|
|
279
|
+
context?: string
|
|
280
|
+
verbose?: boolean
|
|
290
281
|
}
|
|
291
282
|
```
|
|
292
283
|
|
|
293
|
-
###
|
|
284
|
+
### Key Service Types
|
|
294
285
|
```typescript
|
|
295
|
-
|
|
296
|
-
|
|
286
|
+
// projects/project-types.ts
|
|
287
|
+
interface Project {
|
|
288
|
+
id: string
|
|
289
|
+
title: string
|
|
290
|
+
description: string
|
|
291
|
+
project_repositories: ProjectRepository[]
|
|
292
|
+
// ... and more
|
|
297
293
|
}
|
|
298
|
-
```
|
|
299
294
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
id: string
|
|
307
|
-
name: string
|
|
308
|
-
created_at: string
|
|
309
|
-
expires_at?: string
|
|
310
|
-
is_active: boolean
|
|
311
|
-
metadata?: Record<string, any>
|
|
312
|
-
}
|
|
313
|
-
message?: string
|
|
295
|
+
// codespace/codespace-types.ts
|
|
296
|
+
interface CreateCodespaceTaskRequestV2 {
|
|
297
|
+
project_id: string
|
|
298
|
+
task_description: string
|
|
299
|
+
execution_mode?: 'implementation' | 'docs-only'
|
|
300
|
+
// ... and more
|
|
314
301
|
}
|
|
315
|
-
```
|
|
316
302
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
interface
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
303
|
+
// external-tokens/external-tokens-types.ts
|
|
304
|
+
type Platform = 'github' | 'gitlab' | 'bitbucket'
|
|
305
|
+
interface StoreExternalTokenRequest {
|
|
306
|
+
platform: Platform
|
|
307
|
+
token: string
|
|
308
|
+
token_name: string
|
|
309
|
+
token_type: TokenType
|
|
310
|
+
// ... and more
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// types.ts
|
|
314
|
+
interface Subscription {
|
|
315
|
+
id: string
|
|
316
|
+
status: 'active' | 'canceled' | 'trialing' | ...
|
|
317
|
+
// ... and more
|
|
326
318
|
}
|
|
327
319
|
```
|
|
328
320
|
|
|
321
|
+
For a full list of types, please refer to the source files in `services/**/**-types.ts` and `types.ts`.
|
|
322
|
+
|
|
329
323
|
## Error Handling
|
|
330
324
|
|
|
331
|
-
The client provides detailed error information
|
|
325
|
+
The client provides detailed error information for failed API calls. It is recommended to wrap API calls in a `try...catch` block.
|
|
332
326
|
|
|
333
327
|
```typescript
|
|
334
328
|
try {
|
|
@@ -350,6 +344,8 @@ try {
|
|
|
350
344
|
|
|
351
345
|
### Timeout Configuration
|
|
352
346
|
|
|
347
|
+
You can configure the request timeout (in milliseconds). The default is 1 hour.
|
|
348
|
+
|
|
353
349
|
```typescript
|
|
354
350
|
const codeguide = new CodeGuide({
|
|
355
351
|
baseUrl: 'https://api.codeguide.ai',
|
|
@@ -360,6 +356,8 @@ const codeguide = new CodeGuide({
|
|
|
360
356
|
|
|
361
357
|
### Verbose Logging
|
|
362
358
|
|
|
359
|
+
Enable verbose logging to see detailed request and response information in the console.
|
|
360
|
+
|
|
363
361
|
```typescript
|
|
364
362
|
const codeguide = new CodeGuide({
|
|
365
363
|
baseUrl: 'https://api.codeguide.ai',
|
|
@@ -369,120 +367,6 @@ const codeguide = new CodeGuide({
|
|
|
369
367
|
})
|
|
370
368
|
```
|
|
371
369
|
|
|
372
|
-
## Advanced Usage
|
|
373
|
-
|
|
374
|
-
### Custom Headers
|
|
375
|
-
|
|
376
|
-
The BaseService allows you to intercept and modify requests:
|
|
377
|
-
|
|
378
|
-
```typescript
|
|
379
|
-
// Access the underlying axios instance
|
|
380
|
-
const client = codeguide.apiKeyEnhanced.client
|
|
381
|
-
|
|
382
|
-
// Add custom headers
|
|
383
|
-
client.interceptors.request.use(config => {
|
|
384
|
-
config.headers['X-Custom-Header'] = 'value'
|
|
385
|
-
return config
|
|
386
|
-
})
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
### Response Interceptors
|
|
390
|
-
|
|
391
|
-
```typescript
|
|
392
|
-
// Add custom response handling
|
|
393
|
-
client.interceptors.response.use(
|
|
394
|
-
response => response,
|
|
395
|
-
error => {
|
|
396
|
-
// Custom error handling
|
|
397
|
-
console.error('API Error:', error.response?.data)
|
|
398
|
-
return Promise.reject(error)
|
|
399
|
-
}
|
|
400
|
-
)
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
## Examples
|
|
404
|
-
|
|
405
|
-
### Complete API Key Management Flow
|
|
406
|
-
|
|
407
|
-
```typescript
|
|
408
|
-
import { CodeGuide } from '@codeguide/core'
|
|
409
|
-
|
|
410
|
-
async function manageApiKeys() {
|
|
411
|
-
const codeguide = new CodeGuide({
|
|
412
|
-
baseUrl: 'https://api.codeguide.ai',
|
|
413
|
-
databaseApiKey: 'sk_your_key'
|
|
414
|
-
})
|
|
415
|
-
|
|
416
|
-
try {
|
|
417
|
-
// Check permissions
|
|
418
|
-
const permission = await codeguide.apiKeyEnhanced.checkApiKeyPermission()
|
|
419
|
-
if (!permission.data.can_create) {
|
|
420
|
-
console.log('Cannot create new keys:', permission.data.reason)
|
|
421
|
-
return
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// List current keys
|
|
425
|
-
const currentKeys = await codeguide.apiKeyEnhanced.getAllApiKeys()
|
|
426
|
-
console.log(`Current keys: ${currentKeys.data.length}`)
|
|
427
|
-
|
|
428
|
-
// Create new key
|
|
429
|
-
const newKey = await codeguide.apiKeyEnhanced.createApiKey({
|
|
430
|
-
name: 'Production Application'
|
|
431
|
-
})
|
|
432
|
-
console.log('Created key:', newKey.data.api_key)
|
|
433
|
-
|
|
434
|
-
// Revoke old key if needed
|
|
435
|
-
if (currentKeys.data.length > 5) {
|
|
436
|
-
await codeguide.apiKeyEnhanced.revokeApiKey(currentKeys.data[0].id)
|
|
437
|
-
console.log('Revoked oldest key')
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
} catch (error) {
|
|
441
|
-
console.error('API key management failed:', error.message)
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
### Project Setup with Tasks
|
|
447
|
-
|
|
448
|
-
```typescript
|
|
449
|
-
import { CodeGuide } from '@codeguide/core'
|
|
450
|
-
|
|
451
|
-
async function setupProject() {
|
|
452
|
-
const codeguide = new CodeGuide({
|
|
453
|
-
baseUrl: 'https://api.codeguide.ai',
|
|
454
|
-
databaseApiKey: 'sk_your_key'
|
|
455
|
-
})
|
|
456
|
-
|
|
457
|
-
try {
|
|
458
|
-
// Create project
|
|
459
|
-
const project = await codeguide.projects.createProject({
|
|
460
|
-
title: 'E-commerce Platform',
|
|
461
|
-
description: 'Modern e-commerce solution with React and Node.js'
|
|
462
|
-
})
|
|
463
|
-
|
|
464
|
-
// Generate tasks
|
|
465
|
-
const tasks = await codeguide.tasks.generateTasks({
|
|
466
|
-
project_id: project.id,
|
|
467
|
-
context: 'Building a full-stack e-commerce platform'
|
|
468
|
-
})
|
|
469
|
-
|
|
470
|
-
console.log(`Created project with ${tasks.data.length} tasks`)
|
|
471
|
-
|
|
472
|
-
// Start first task
|
|
473
|
-
if (tasks.data.length > 0) {
|
|
474
|
-
await codeguide.tasks.updateTask(tasks.data[0].id, {
|
|
475
|
-
status: 'in_progress',
|
|
476
|
-
notes: 'Starting project setup'
|
|
477
|
-
})
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
} catch (error) {
|
|
481
|
-
console.error('Project setup failed:', error.message)
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
```
|
|
485
|
-
|
|
486
370
|
## Contributing
|
|
487
371
|
|
|
488
372
|
1. Fork the repository
|
|
@@ -500,4 +384,4 @@ async function setupProject() {
|
|
|
500
384
|
|
|
501
385
|
## License
|
|
502
386
|
|
|
503
|
-
MIT License - see
|
|
387
|
+
MIT License - see the LICENSE file for details.
|