@codeguide/core 0.0.22 → 0.0.23
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/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 +3 -1
- package/dist/services/codespace/codespace-service.js +26 -1
- package/dist/services/codespace/codespace-types.d.ts +33 -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 +49 -7
- package/services/codespace/codespace-types.ts +41 -1
- package/services/codespace/index.ts +1 -0
- 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
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
# Codespace Service Documentation
|
|
2
|
+
|
|
3
|
+
This guide covers how to use the Codespace Service methods through the CodeGuide service for managing AI-powered coding tasks and workflows.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Setup](#setup)
|
|
8
|
+
- [Authentication](#authentication)
|
|
9
|
+
- [Methods Overview](#methods-overview)
|
|
10
|
+
- [Detailed Method Documentation](#detailed-method-documentation)
|
|
11
|
+
- [Error Handling](#error-handling)
|
|
12
|
+
- [Examples](#examples)
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
### Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @codeguide/core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Basic Initialization
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { CodeGuide } from '@codeguide/core'
|
|
26
|
+
|
|
27
|
+
// Initialize the CodeGuide service
|
|
28
|
+
const codeguide = new CodeGuide({
|
|
29
|
+
baseUrl: 'https://api.codeguide.dev',
|
|
30
|
+
databaseApiKey: 'sk_your_database_api_key_here', // Recommended
|
|
31
|
+
// Alternative authentication methods:
|
|
32
|
+
// apiKey: 'your_legacy_api_key',
|
|
33
|
+
// jwtToken: 'your_clerk_jwt_token',
|
|
34
|
+
timeout: 30000
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// Access the codespace service
|
|
38
|
+
const codespace = codeguide.codespace
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Configuration Options
|
|
42
|
+
|
|
43
|
+
The `APIServiceConfig` interface accepts:
|
|
44
|
+
|
|
45
|
+
- `baseUrl` (required): API base URL
|
|
46
|
+
- `databaseApiKey`: Database API key (format: `sk_...`) - **Highest priority**
|
|
47
|
+
- `apiKey`: Legacy API key - **Medium priority**
|
|
48
|
+
- `jwtToken`: Clerk JWT token - **Lowest priority**
|
|
49
|
+
- `timeout`: Request timeout in milliseconds (optional)
|
|
50
|
+
|
|
51
|
+
## Authentication
|
|
52
|
+
|
|
53
|
+
The service supports multiple authentication methods with automatic priority handling:
|
|
54
|
+
|
|
55
|
+
1. **Database API Key** (recommended): `sk_...` format
|
|
56
|
+
2. **Legacy API Key**: Older API key format
|
|
57
|
+
3. **Clerk JWT Token**: JWT-based authentication
|
|
58
|
+
|
|
59
|
+
The service will automatically use the highest priority authentication method available.
|
|
60
|
+
|
|
61
|
+
## Methods Overview
|
|
62
|
+
|
|
63
|
+
The Codespace Service provides the following methods:
|
|
64
|
+
|
|
65
|
+
| Method | Description | Endpoint |
|
|
66
|
+
|--------|-------------|----------|
|
|
67
|
+
| `generateTaskTitle()` | Generate a title from task description | `POST /codespace/generate-task-title` |
|
|
68
|
+
| `createCodespaceTaskV2()` | Create a new codespace task | `POST /codespace/task` |
|
|
69
|
+
| `createBackgroundCodespaceTask()` | Create task in background | `POST /codespace/task/background` |
|
|
70
|
+
| `getCodespaceTask()` | Get task by ID | `GET /codespace/task/{id}` |
|
|
71
|
+
| `getCodespaceTasksByProject()` | Get tasks for a project | `GET /codespace/tasks/project/{id}` |
|
|
72
|
+
| `getCodespaceTaskDetailed()` | Get detailed task info | `GET /codespace/task/{id}/detailed` |
|
|
73
|
+
| `getProjectTasksByCodespace()` | Get project tasks by codespace | `GET /project-tasks/by-codespace/{id}` |
|
|
74
|
+
|
|
75
|
+
## Detailed Method Documentation
|
|
76
|
+
|
|
77
|
+
### 1. generateTaskTitle()
|
|
78
|
+
|
|
79
|
+
Generates a concise title from a detailed task description using AI or fallback logic.
|
|
80
|
+
|
|
81
|
+
#### Signature
|
|
82
|
+
```typescript
|
|
83
|
+
async generateTaskTitle(request: GenerateTaskTitleRequest): Promise<GenerateTaskTitleResponse>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### Parameters
|
|
87
|
+
- `request.task_description` (string, required): The full task description to generate title from
|
|
88
|
+
|
|
89
|
+
#### Response
|
|
90
|
+
```typescript
|
|
91
|
+
interface GenerateTaskTitleResponse {
|
|
92
|
+
success: boolean
|
|
93
|
+
title: string
|
|
94
|
+
message: string
|
|
95
|
+
fallback_used: boolean // true if AI generation failed and fallback was used
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Example
|
|
100
|
+
```typescript
|
|
101
|
+
const response = await codespace.generateTaskTitle({
|
|
102
|
+
task_description: "Create a user authentication system with login, registration, and password reset functionality using JWT tokens and bcrypt for password hashing"
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
console.log(response.title) // "User Authentication System"
|
|
106
|
+
console.log(response.fallback_used) // false if AI generated, true if fallback used
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 2. createCodespaceTaskV2()
|
|
110
|
+
|
|
111
|
+
Creates a new codespace task with complete workflow including PRD generation, task creation, and Claude Code integration.
|
|
112
|
+
|
|
113
|
+
#### Signature
|
|
114
|
+
```typescript
|
|
115
|
+
async createCodespaceTaskV2(request: CreateCodespaceTaskRequestV2): Promise<CreateCodespaceTaskResponseV2>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Parameters
|
|
119
|
+
```typescript
|
|
120
|
+
interface CreateCodespaceTaskRequestV2 {
|
|
121
|
+
project_id: string // Required
|
|
122
|
+
task_description: string // Required
|
|
123
|
+
project_repository_id?: string // Optional
|
|
124
|
+
title?: string // Optional
|
|
125
|
+
branch?: string // Optional
|
|
126
|
+
working_branch?: string // Optional
|
|
127
|
+
base_branch?: string // Optional (default: "main")
|
|
128
|
+
docs_url?: string // Optional
|
|
129
|
+
model_api_keys?: ModelApiKey[] // Optional
|
|
130
|
+
github_token?: string // Optional
|
|
131
|
+
codespace_task_id?: string // Optional (for continuation)
|
|
132
|
+
execution_mode?: 'implementation' | 'docs-only' // Optional (default: "implementation")
|
|
133
|
+
model_name?: string // Optional
|
|
134
|
+
starter_kit_repo?: string // Optional
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface ModelApiKey {
|
|
138
|
+
model_name: string
|
|
139
|
+
api_key: string
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Response
|
|
144
|
+
```typescript
|
|
145
|
+
interface CreateCodespaceTaskResponseV2 {
|
|
146
|
+
success: boolean
|
|
147
|
+
task_id: string
|
|
148
|
+
message: string
|
|
149
|
+
status?: string
|
|
150
|
+
created_at?: string
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### Example
|
|
155
|
+
```typescript
|
|
156
|
+
const response = await codespace.createCodespaceTaskV2({
|
|
157
|
+
project_id: "proj_123456",
|
|
158
|
+
task_description: "Add user profile page with avatar upload and bio editing",
|
|
159
|
+
execution_mode: "implementation",
|
|
160
|
+
model_api_keys: [
|
|
161
|
+
{
|
|
162
|
+
model_name: "claude-3-sonnet",
|
|
163
|
+
api_key: "your_api_key_here"
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
github_token: "ghp_your_github_token"
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
console.log(`Task created with ID: ${response.task_id}`)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 3. createBackgroundCodespaceTask()
|
|
173
|
+
|
|
174
|
+
Creates a codespace task that runs in the background, returning immediately with task details while work continues.
|
|
175
|
+
|
|
176
|
+
#### Signature
|
|
177
|
+
```typescript
|
|
178
|
+
async createBackgroundCodespaceTask(request: CreateBackgroundCodespaceTaskRequest): Promise<CreateBackgroundCodespaceTaskResponse>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Parameters
|
|
182
|
+
Same as `createCodespaceTaskV2()` - extends `CreateCodespaceTaskRequestV2`
|
|
183
|
+
|
|
184
|
+
#### Response
|
|
185
|
+
```typescript
|
|
186
|
+
interface CreateBackgroundCodespaceTaskResponse {
|
|
187
|
+
success: boolean
|
|
188
|
+
task_id: string
|
|
189
|
+
job_id: string // Background job ID for status checking
|
|
190
|
+
status: string
|
|
191
|
+
message: string
|
|
192
|
+
repository_connected: boolean
|
|
193
|
+
mode: 'documentation' | 'implementation'
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Example
|
|
198
|
+
```typescript
|
|
199
|
+
const response = await codespace.createBackgroundCodespaceTask({
|
|
200
|
+
project_id: "proj_123456",
|
|
201
|
+
task_description: "Implement real-time chat functionality",
|
|
202
|
+
execution_mode: "implementation"
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
console.log(`Background task started: ${response.job_id}`)
|
|
206
|
+
// Later check status with the job_id
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### 4. getCodespaceTask()
|
|
210
|
+
|
|
211
|
+
Retrieves a codespace task by its ID with full details.
|
|
212
|
+
|
|
213
|
+
#### Signature
|
|
214
|
+
```typescript
|
|
215
|
+
async getCodespaceTask(codespaceTaskId: string): Promise<GetCodespaceTaskResponse>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### Parameters
|
|
219
|
+
- `codespaceTaskId` (string, required): The ID of the codespace task to retrieve
|
|
220
|
+
|
|
221
|
+
#### Response
|
|
222
|
+
```typescript
|
|
223
|
+
interface GetCodespaceTaskResponse {
|
|
224
|
+
status: string
|
|
225
|
+
data: CodespaceTaskData
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface CodespaceTaskData {
|
|
229
|
+
id: string
|
|
230
|
+
codespace_task_id: string | null
|
|
231
|
+
project_id: string
|
|
232
|
+
project_repository_id: string
|
|
233
|
+
user_id: string
|
|
234
|
+
status: string
|
|
235
|
+
progress: string
|
|
236
|
+
created_at: string
|
|
237
|
+
updated_at: string
|
|
238
|
+
completed_at: string | null
|
|
239
|
+
title: string
|
|
240
|
+
task_description: string
|
|
241
|
+
base_branch: string
|
|
242
|
+
working_branch: string
|
|
243
|
+
github_token_hash: string | null
|
|
244
|
+
pull_request_url: string | null
|
|
245
|
+
pull_request_number: number | null
|
|
246
|
+
work_started_at: string | null
|
|
247
|
+
work_completed_at: string | null
|
|
248
|
+
estimated_completion_time: string | null
|
|
249
|
+
ai_implementation_plan: string | null
|
|
250
|
+
metadata: any
|
|
251
|
+
model_id: string | null
|
|
252
|
+
execution_mode: string
|
|
253
|
+
context_data: any
|
|
254
|
+
final_report_popup_state: string
|
|
255
|
+
technical_document: TechnicalDocument | null
|
|
256
|
+
model: any
|
|
257
|
+
task_models: any[]
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
#### Example
|
|
262
|
+
```typescript
|
|
263
|
+
const response = await codespace.getCodespaceTask("task_789012")
|
|
264
|
+
const task = response.data
|
|
265
|
+
|
|
266
|
+
console.log(`Task: ${task.title}`)
|
|
267
|
+
console.log(`Status: ${task.status}`)
|
|
268
|
+
console.log(`Progress: ${task.progress}`)
|
|
269
|
+
console.log(`Created: ${task.created_at}`)
|
|
270
|
+
|
|
271
|
+
if (task.pull_request_url) {
|
|
272
|
+
console.log(`PR: ${task.pull_request_url}`)
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### 5. getCodespaceTasksByProject()
|
|
277
|
+
|
|
278
|
+
Retrieves all codespace tasks for a specific project with filtering and pagination support.
|
|
279
|
+
|
|
280
|
+
#### Signature
|
|
281
|
+
```typescript
|
|
282
|
+
async getCodespaceTasksByProject(params: GetCodespaceTasksByProjectRequest): Promise<GetCodespaceTasksByProjectResponse>
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
#### Parameters
|
|
286
|
+
```typescript
|
|
287
|
+
interface GetCodespaceTasksByProjectRequest {
|
|
288
|
+
project_id: string // Required
|
|
289
|
+
status?: 'completed' | 'failed' | 'in_progress' | 'created' | 'cancelled'
|
|
290
|
+
limit?: number // Optional (default: 50)
|
|
291
|
+
offset?: number // Optional (default: 0)
|
|
292
|
+
sort_by?: string // Optional (default: "created_at")
|
|
293
|
+
sort_order?: 'asc' | 'desc' // Optional (default: "desc")
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### Response
|
|
298
|
+
```typescript
|
|
299
|
+
interface GetCodespaceTasksByProjectResponse {
|
|
300
|
+
status: string
|
|
301
|
+
data: CodespaceTaskData[]
|
|
302
|
+
total_count: number
|
|
303
|
+
message: string
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
#### Example
|
|
308
|
+
```typescript
|
|
309
|
+
// Get all completed tasks for a project
|
|
310
|
+
const response = await codespace.getCodespaceTasksByProject({
|
|
311
|
+
project_id: "proj_123456",
|
|
312
|
+
status: "completed",
|
|
313
|
+
limit: 20,
|
|
314
|
+
sort_order: "desc"
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
console.log(`Found ${response.total_count} completed tasks`)
|
|
318
|
+
response.data.forEach(task => {
|
|
319
|
+
console.log(`- ${task.title} (${task.status})`)
|
|
320
|
+
})
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### 6. getCodespaceTaskDetailed()
|
|
324
|
+
|
|
325
|
+
Retrieves comprehensive codespace task details including related project data, repository information, and usage statistics.
|
|
326
|
+
|
|
327
|
+
#### Signature
|
|
328
|
+
```typescript
|
|
329
|
+
async getCodespaceTaskDetailed(codespaceTaskId: string): Promise<CodespaceTaskDetailedResponse>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### Parameters
|
|
333
|
+
- `codespaceTaskId` (string, required): The ID of the codespace task to retrieve detailed information for
|
|
334
|
+
|
|
335
|
+
#### Response
|
|
336
|
+
```typescript
|
|
337
|
+
interface CodespaceTaskDetailedResponse {
|
|
338
|
+
status: string
|
|
339
|
+
data: {
|
|
340
|
+
task: CodespaceTaskData
|
|
341
|
+
project: any // Project data structure
|
|
342
|
+
repository: any // Repository data structure
|
|
343
|
+
usage_summary: any // Usage statistics
|
|
344
|
+
}
|
|
345
|
+
message: string
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
#### Example
|
|
350
|
+
```typescript
|
|
351
|
+
const response = await codespace.getCodespaceTaskDetailed("task_789012")
|
|
352
|
+
const { task, project, repository, usage_summary } = response.data
|
|
353
|
+
|
|
354
|
+
console.log(`Task: ${task.title}`)
|
|
355
|
+
console.log(`Project: ${project.name}`)
|
|
356
|
+
console.log(`Repository: ${repository.repo_url}`)
|
|
357
|
+
console.log(`Usage: ${usage_summary.total_requests} requests`)
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### 7. getProjectTasksByCodespace()
|
|
361
|
+
|
|
362
|
+
Retrieves project tasks associated with a specific codespace task.
|
|
363
|
+
|
|
364
|
+
#### Signature
|
|
365
|
+
```typescript
|
|
366
|
+
async getProjectTasksByCodespace(codespaceTaskId: string): Promise<GetProjectTasksByCodespaceResponse>
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
#### Parameters
|
|
370
|
+
- `codespaceTaskId` (string, required): The ID of the codespace task
|
|
371
|
+
|
|
372
|
+
#### Response
|
|
373
|
+
```typescript
|
|
374
|
+
interface GetProjectTasksByCodespaceResponse {
|
|
375
|
+
status: string
|
|
376
|
+
data: any[] // Array of project task objects
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
#### Example
|
|
381
|
+
```typescript
|
|
382
|
+
const response = await codespace.getProjectTasksByCodespace("task_789012")
|
|
383
|
+
|
|
384
|
+
console.log(`Found ${response.data.length} related project tasks`)
|
|
385
|
+
response.data.forEach(projectTask => {
|
|
386
|
+
console.log(`- ${projectTask.name} (${projectTask.status})`)
|
|
387
|
+
})
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## Error Handling
|
|
391
|
+
|
|
392
|
+
All methods throw errors for various failure conditions. Common error types include:
|
|
393
|
+
|
|
394
|
+
### Validation Errors
|
|
395
|
+
```typescript
|
|
396
|
+
try {
|
|
397
|
+
await codespace.createCodespaceTaskV2({})
|
|
398
|
+
} catch (error) {
|
|
399
|
+
console.error(error.message) // "project_id is required"
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### Network/Server Errors
|
|
404
|
+
```typescript
|
|
405
|
+
try {
|
|
406
|
+
await codespace.getCodespaceTask("invalid_id")
|
|
407
|
+
} catch (error) {
|
|
408
|
+
if (error.response?.status === 404) {
|
|
409
|
+
console.error("Task not found")
|
|
410
|
+
} else if (error.response?.status === 401) {
|
|
411
|
+
console.error("Unauthorized - check your API credentials")
|
|
412
|
+
} else {
|
|
413
|
+
console.error("Network error:", error.message)
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Timeout Errors
|
|
419
|
+
```typescript
|
|
420
|
+
try {
|
|
421
|
+
await codespace.createCodespaceTaskV2(largeRequest)
|
|
422
|
+
} catch (error) {
|
|
423
|
+
if (error.code === 'ECONNABORTED') {
|
|
424
|
+
console.error("Request timed out. Consider using background task creation.")
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## Complete Examples
|
|
430
|
+
|
|
431
|
+
### Example 1: Complete Task Workflow
|
|
432
|
+
|
|
433
|
+
```typescript
|
|
434
|
+
import { CodeGuide } from '@codeguide/core'
|
|
435
|
+
|
|
436
|
+
const codeguide = new CodeGuide({
|
|
437
|
+
baseUrl: 'https://api.codeguide.dev',
|
|
438
|
+
databaseApiKey: process.env.CODEGUIDE_API_KEY
|
|
439
|
+
})
|
|
440
|
+
|
|
441
|
+
async function completeTaskWorkflow() {
|
|
442
|
+
try {
|
|
443
|
+
// 1. Generate a title from description
|
|
444
|
+
const titleResponse = await codeguide.codespace.generateTaskTitle({
|
|
445
|
+
task_description: "Implement a REST API for user management with CRUD operations, validation, and authentication middleware"
|
|
446
|
+
})
|
|
447
|
+
|
|
448
|
+
console.log(`Generated title: ${titleResponse.title}`)
|
|
449
|
+
|
|
450
|
+
// 2. Create the task
|
|
451
|
+
const taskResponse = await codeguide.codespace.createCodespaceTaskV2({
|
|
452
|
+
project_id: "proj_123456",
|
|
453
|
+
task_description: "Implement a REST API for user management with CRUD operations, validation, and authentication middleware",
|
|
454
|
+
title: titleResponse.title,
|
|
455
|
+
execution_mode: "implementation",
|
|
456
|
+
model_api_keys: [
|
|
457
|
+
{
|
|
458
|
+
model_name: "claude-3-sonnet",
|
|
459
|
+
api_key: process.env.CLAUDE_API_KEY
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
console.log(`Task created: ${taskResponse.task_id}`)
|
|
465
|
+
|
|
466
|
+
// 3. Monitor task progress
|
|
467
|
+
const checkProgress = async () => {
|
|
468
|
+
const task = await codeguide.codespace.getCodespaceTask(taskResponse.task_id)
|
|
469
|
+
console.log(`Status: ${task.data.status} - Progress: ${task.data.progress}`)
|
|
470
|
+
|
|
471
|
+
if (task.data.status === 'completed') {
|
|
472
|
+
console.log(`Task completed! PR: ${task.data.pull_request_url}`)
|
|
473
|
+
return
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// Check again in 30 seconds
|
|
477
|
+
setTimeout(checkProgress, 30000)
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
checkProgress()
|
|
481
|
+
|
|
482
|
+
} catch (error) {
|
|
483
|
+
console.error("Workflow failed:", error.message)
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
completeTaskWorkflow()
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### Example 2: Background Task Processing
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
async function backgroundTaskExample() {
|
|
494
|
+
try {
|
|
495
|
+
// Create background task
|
|
496
|
+
const response = await codeguide.codespace.createBackgroundCodespaceTask({
|
|
497
|
+
project_id: "proj_123456",
|
|
498
|
+
task_description: "Add comprehensive test suite for existing authentication module",
|
|
499
|
+
execution_mode: "implementation"
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
console.log(`Background task started: ${response.job_id}`)
|
|
503
|
+
|
|
504
|
+
// Poll for completion (in real app, use webhooks or proper job queue)
|
|
505
|
+
const pollStatus = async () => {
|
|
506
|
+
try {
|
|
507
|
+
const task = await codeguide.codespace.getCodespaceTask(response.task_id)
|
|
508
|
+
|
|
509
|
+
console.log(`Status: ${task.data.status}`)
|
|
510
|
+
|
|
511
|
+
if (['completed', 'failed'].includes(task.data.status)) {
|
|
512
|
+
console.log(`Task ${task.data.status === 'completed' ? 'completed successfully' : 'failed'}`)
|
|
513
|
+
return
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
setTimeout(pollStatus, 10000) // Poll every 10 seconds
|
|
517
|
+
} catch (error) {
|
|
518
|
+
console.error("Error checking status:", error.message)
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
pollStatus()
|
|
523
|
+
|
|
524
|
+
} catch (error) {
|
|
525
|
+
console.error("Background task creation failed:", error.message)
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Example 3: Project Task Management
|
|
531
|
+
|
|
532
|
+
```typescript
|
|
533
|
+
async function projectTaskManagement() {
|
|
534
|
+
const projectId = "proj_123456"
|
|
535
|
+
|
|
536
|
+
try {
|
|
537
|
+
// Get all tasks for the project
|
|
538
|
+
const tasksResponse = await codeguide.codespace.getCodespaceTasksByProject({
|
|
539
|
+
project_id: projectId,
|
|
540
|
+
limit: 100,
|
|
541
|
+
sort_order: "desc"
|
|
542
|
+
})
|
|
543
|
+
|
|
544
|
+
console.log(`Project has ${tasksResponse.total_count} total tasks`)
|
|
545
|
+
|
|
546
|
+
// Group tasks by status
|
|
547
|
+
const tasksByStatus = tasksResponse.data.reduce((acc, task) => {
|
|
548
|
+
acc[task.status] = (acc[task.status] || 0) + 1
|
|
549
|
+
return acc
|
|
550
|
+
}, {})
|
|
551
|
+
|
|
552
|
+
console.log("Tasks by status:", tasksByStatus)
|
|
553
|
+
|
|
554
|
+
// Get detailed info for the most recent task
|
|
555
|
+
if (tasksResponse.data.length > 0) {
|
|
556
|
+
const latestTask = tasksResponse.data[0]
|
|
557
|
+
const detailedResponse = await codeguide.codespace.getCodespaceTaskDetailed(latestTask.id)
|
|
558
|
+
|
|
559
|
+
console.log(`Latest task: ${detailedResponse.data.task.title}`)
|
|
560
|
+
console.log(`Project: ${detailedResponse.data.project.name}`)
|
|
561
|
+
console.log(`Repository: ${detailedResponse.data.repository?.repo_url || 'No repository'}`)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
} catch (error) {
|
|
565
|
+
console.error("Project task management failed:", error.message)
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
## Best Practices
|
|
571
|
+
|
|
572
|
+
1. **Use Background Tasks** for long-running operations to avoid timeouts
|
|
573
|
+
2. **Implement Proper Error Handling** with try-catch blocks and status code checking
|
|
574
|
+
3. **Cache Task Data** when possible to reduce API calls
|
|
575
|
+
4. **Use Webhooks** in production for real-time task status updates
|
|
576
|
+
5. **Validate Input** before making API calls to avoid unnecessary requests
|
|
577
|
+
6. **Handle Timeouts** appropriately and implement retry logic when needed
|
|
578
|
+
7. **Use Specific Query Parameters** for filtering and pagination to improve performance
|
|
579
|
+
|
|
580
|
+
## Type Exports
|
|
581
|
+
|
|
582
|
+
The package exports the following types for TypeScript users:
|
|
583
|
+
|
|
584
|
+
```typescript
|
|
585
|
+
import type {
|
|
586
|
+
CreateCodespaceTaskRequest,
|
|
587
|
+
CreateCodespaceTaskResponse,
|
|
588
|
+
CreateBackgroundCodespaceTaskRequest,
|
|
589
|
+
CreateBackgroundCodespaceTaskResponse,
|
|
590
|
+
ModelApiKey,
|
|
591
|
+
GetCodespaceTaskResponse,
|
|
592
|
+
CodespaceTaskData,
|
|
593
|
+
TechnicalDocument,
|
|
594
|
+
GetProjectTasksByCodespaceResponse,
|
|
595
|
+
GetCodespaceTasksByProjectRequest,
|
|
596
|
+
GetCodespaceTasksByProjectResponse,
|
|
597
|
+
CodespaceTaskDetailedResponse
|
|
598
|
+
} from '@codeguide/core'
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
For more information, visit the [API documentation](https://docs.codeguide.dev) or check the [GitHub repository](https://github.com/codeguide/cli).
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CodeGuide, GetProjectsRequest, PaginatedProjectsRequest, Project } from '../index'
|
|
2
|
+
|
|
3
|
+
// Example usage of the new has_repository filtering functionality
|
|
4
|
+
async function demonstrateProjectFiltering() {
|
|
5
|
+
const codeGuide = new CodeGuide({
|
|
6
|
+
baseUrl: 'https://api.example.com',
|
|
7
|
+
apiKey: 'your-api-key'
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
console.log('=== Project Filtering Examples ===\n')
|
|
11
|
+
|
|
12
|
+
// Example 1: Get all projects with repositories
|
|
13
|
+
console.log('1. Getting all projects with repositories:')
|
|
14
|
+
try {
|
|
15
|
+
const projectsWithRepos = await codeGuide.projects.getAllProjects({
|
|
16
|
+
has_repository: true
|
|
17
|
+
})
|
|
18
|
+
console.log(`Found ${projectsWithRepos.length} projects with repositories`)
|
|
19
|
+
projectsWithRepos.forEach((project: Project) => {
|
|
20
|
+
console.log(`- ${project.title} (${project.project_repositories.length} repositories)`)
|
|
21
|
+
})
|
|
22
|
+
} catch (error: any) {
|
|
23
|
+
console.log('Error:', error.message)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
console.log('\n')
|
|
27
|
+
|
|
28
|
+
// Example 2: Get all projects without repositories
|
|
29
|
+
console.log('2. Getting all projects without repositories:')
|
|
30
|
+
try {
|
|
31
|
+
const projectsWithoutRepos = await codeGuide.projects.getAllProjects({
|
|
32
|
+
has_repository: false
|
|
33
|
+
})
|
|
34
|
+
console.log(`Found ${projectsWithoutRepos.length} projects without repositories`)
|
|
35
|
+
projectsWithoutRepos.forEach((project: Project) => {
|
|
36
|
+
console.log(`- ${project.title}`)
|
|
37
|
+
})
|
|
38
|
+
} catch (error: any) {
|
|
39
|
+
console.log('Error:', error.message)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('\n')
|
|
43
|
+
|
|
44
|
+
// Example 3: Paginated projects with repository filter
|
|
45
|
+
console.log('3. Getting paginated projects with repositories:')
|
|
46
|
+
try {
|
|
47
|
+
const paginatedRequest: PaginatedProjectsRequest = {
|
|
48
|
+
page: 1,
|
|
49
|
+
page_size: 10,
|
|
50
|
+
has_repository: true,
|
|
51
|
+
status: 'active'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const paginatedResponse = await codeGuide.projects.getPaginatedProjects(paginatedRequest)
|
|
55
|
+
console.log(`Page ${paginatedResponse.pagination.page} of ${paginatedResponse.pagination.total_pages}`)
|
|
56
|
+
console.log(`Total projects with repositories: ${paginatedResponse.pagination.total}`)
|
|
57
|
+
console.log(`Showing ${paginatedResponse.data.length} projects:`)
|
|
58
|
+
|
|
59
|
+
paginatedResponse.data.forEach((project: Project) => {
|
|
60
|
+
console.log(`- ${project.title}`)
|
|
61
|
+
project.project_repositories.forEach((repo: any) => {
|
|
62
|
+
console.log(` Repository: ${repo.repo_url} (${repo.branch})`)
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
} catch (error: any) {
|
|
66
|
+
console.log('Error:', error.message)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log('\n')
|
|
70
|
+
|
|
71
|
+
// Example 4: Combining filters
|
|
72
|
+
console.log('4. Combining multiple filters:')
|
|
73
|
+
try {
|
|
74
|
+
const combinedFilters: PaginatedProjectsRequest = {
|
|
75
|
+
page: 1,
|
|
76
|
+
page_size: 5,
|
|
77
|
+
has_repository: false,
|
|
78
|
+
search_query: 'web',
|
|
79
|
+
sort_by_date: 'desc'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const filteredProjects = await codeGuide.projects.getPaginatedProjects(combinedFilters)
|
|
83
|
+
console.log(`Found ${filteredProjects.pagination.total} projects matching filters:`)
|
|
84
|
+
filteredProjects.data.forEach((project: Project) => {
|
|
85
|
+
console.log(`- ${project.title} (Updated: ${project.updated_at})`)
|
|
86
|
+
})
|
|
87
|
+
} catch (error: any) {
|
|
88
|
+
console.log('Error:', error.message)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Export for use in tests or other modules
|
|
93
|
+
export { demonstrateProjectFiltering }
|
|
94
|
+
|
|
95
|
+
// Run example if this file is executed directly
|
|
96
|
+
if (require.main === module) {
|
|
97
|
+
demonstrateProjectFiltering().catch(console.error)
|
|
98
|
+
}
|