@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,1004 @@
|
|
|
1
|
+
# Codespace Models
|
|
2
|
+
|
|
3
|
+
The Codespace Models API provides methods for querying and managing LLM models and providers used in codespace tasks. This documentation covers all model and provider management functionality.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Codespace models are AI models that can be used for code generation and implementation tasks. Each model belongs to a provider (e.g., OpenAI, Anthropic) and supports different execution modes.
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
### Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @codeguide/core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic Initialization
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { CodeGuide } from '@codeguide/core'
|
|
21
|
+
|
|
22
|
+
const codeguide = new CodeGuide({
|
|
23
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
24
|
+
databaseApiKey: 'sk_your_database_api_key',
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// Access codespace models through the codespace service
|
|
28
|
+
const models = await codeguide.codespace.getCodespaceModels()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Concepts
|
|
32
|
+
|
|
33
|
+
### Models
|
|
34
|
+
|
|
35
|
+
A codespace model represents an AI model that can be used for code generation. Models have:
|
|
36
|
+
- **ID**: Unique identifier (UUID)
|
|
37
|
+
- **Name**: Human-readable name
|
|
38
|
+
- **Provider**: The provider that owns the model
|
|
39
|
+
- **Execution Mode**: The type of tasks the model supports
|
|
40
|
+
- **Base URLs**: API endpoints for the model
|
|
41
|
+
|
|
42
|
+
### Providers
|
|
43
|
+
|
|
44
|
+
A provider represents an LLM service provider (e.g., OpenAI, Anthropic). Providers have:
|
|
45
|
+
- **ID**: Unique identifier (UUID)
|
|
46
|
+
- **Name**: Provider name (e.g., "OpenAI", "Anthropic")
|
|
47
|
+
- **Key**: Provider key (e.g., "openai", "anthropic")
|
|
48
|
+
- **Logo**: Provider logo URL
|
|
49
|
+
|
|
50
|
+
### Execution Modes
|
|
51
|
+
|
|
52
|
+
Models support different execution modes:
|
|
53
|
+
- **`implementation`**: Full code implementation
|
|
54
|
+
- **`docs-only`**: Documentation generation only
|
|
55
|
+
- **`opencode`**: Open code execution mode
|
|
56
|
+
- **`claude-code`**: Claude-specific code mode
|
|
57
|
+
|
|
58
|
+
## Methods Overview
|
|
59
|
+
|
|
60
|
+
| Method | Description | Endpoint |
|
|
61
|
+
|--------|-------------|----------|
|
|
62
|
+
| `getCodespaceModels()` | Get all models with optional filtering | `GET /api/codespace-models/models` |
|
|
63
|
+
| `getCodespaceModel()` | Get a specific model by ID | `GET /api/codespace-models/models/{id}` |
|
|
64
|
+
| `getLLMModelProviders()` | Get all providers | `GET /api/codespace-models/providers` |
|
|
65
|
+
| `getLLMModelProvider()` | Get a specific provider by ID | `GET /api/codespace-models/providers/{id}` |
|
|
66
|
+
| `getModelsByProvider()` | Get all models for a provider | `GET /api/codespace-models/providers/{id}/models` |
|
|
67
|
+
|
|
68
|
+
## Detailed Method Documentation
|
|
69
|
+
|
|
70
|
+
### 1. getCodespaceModels()
|
|
71
|
+
|
|
72
|
+
Retrieves all available codespace models with optional filtering by provider or execution mode.
|
|
73
|
+
|
|
74
|
+
#### Signature
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
async getCodespaceModels(query?: GetCodespaceModelsQuery): Promise<GetCodespaceModelsResponse>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Parameters
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
interface GetCodespaceModelsQuery {
|
|
84
|
+
provider_id?: string // Optional: Filter by provider ID
|
|
85
|
+
execution_mode?: string // Optional: Filter by execution mode
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Returns
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
interface GetCodespaceModelsResponse extends Array<CodespaceModelWithProvider> {}
|
|
93
|
+
|
|
94
|
+
interface CodespaceModelWithProvider {
|
|
95
|
+
id: string
|
|
96
|
+
created_at: string
|
|
97
|
+
key?: string
|
|
98
|
+
name?: string
|
|
99
|
+
provider_id?: string
|
|
100
|
+
base_url?: string
|
|
101
|
+
completion_base_url?: string
|
|
102
|
+
execution_mode?: 'opencode' | 'claude-code' | 'docs-only' | 'implementation'
|
|
103
|
+
logo_src?: string
|
|
104
|
+
provider?: LLMModelProviderInDB
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Example
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// Get all models
|
|
112
|
+
const allModels = await codeguide.codespace.getCodespaceModels()
|
|
113
|
+
console.log(`Found ${allModels.length} models`)
|
|
114
|
+
|
|
115
|
+
// Filter by provider
|
|
116
|
+
const openaiModels = await codeguide.codespace.getCodespaceModels({
|
|
117
|
+
provider_id: 'provider_openai_id',
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
// Filter by execution mode
|
|
121
|
+
const implementationModels = await codeguide.codespace.getCodespaceModels({
|
|
122
|
+
execution_mode: 'implementation',
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
// Filter by both
|
|
126
|
+
const filteredModels = await codeguide.codespace.getCodespaceModels({
|
|
127
|
+
provider_id: 'provider_openai_id',
|
|
128
|
+
execution_mode: 'implementation',
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
// Display models
|
|
132
|
+
allModels.forEach(model => {
|
|
133
|
+
console.log(`${model.name} (${model.provider?.name}) - ${model.execution_mode}`)
|
|
134
|
+
})
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 2. getCodespaceModel()
|
|
138
|
+
|
|
139
|
+
Retrieves a specific codespace model by its ID.
|
|
140
|
+
|
|
141
|
+
#### Signature
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
async getCodespaceModel(modelId: string): Promise<GetCodespaceModelResponse>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Parameters
|
|
148
|
+
|
|
149
|
+
- `modelId` (string, required): The UUID of the model
|
|
150
|
+
|
|
151
|
+
#### Returns
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
interface GetCodespaceModelResponse extends CodespaceModelWithProvider {}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### Example
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const model = await codeguide.codespace.getCodespaceModel('model_uuid_here')
|
|
161
|
+
|
|
162
|
+
console.log(`Model: ${model.name}`)
|
|
163
|
+
console.log(`Provider: ${model.provider?.name}`)
|
|
164
|
+
console.log(`Execution Mode: ${model.execution_mode}`)
|
|
165
|
+
console.log(`Base URL: ${model.base_url}`)
|
|
166
|
+
|
|
167
|
+
if (model.completion_base_url) {
|
|
168
|
+
console.log(`Completion URL: ${model.completion_base_url}`)
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 3. getLLMModelProviders()
|
|
173
|
+
|
|
174
|
+
Retrieves all available LLM model providers.
|
|
175
|
+
|
|
176
|
+
#### Signature
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
async getLLMModelProviders(): Promise<GetLLMModelProvidersResponse>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### Returns
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
interface GetLLMModelProvidersResponse extends Array<LLMModelProviderInDB> {}
|
|
186
|
+
|
|
187
|
+
interface LLMModelProviderInDB {
|
|
188
|
+
id: string
|
|
189
|
+
created_at: string
|
|
190
|
+
name?: string
|
|
191
|
+
key?: string
|
|
192
|
+
logo_src?: string
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### Example
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const providers = await codeguide.codespace.getLLMModelProviders()
|
|
200
|
+
|
|
201
|
+
console.log(`Found ${providers.length} providers:`)
|
|
202
|
+
providers.forEach(provider => {
|
|
203
|
+
console.log(`- ${provider.name} (${provider.key})`)
|
|
204
|
+
if (provider.logo_src) {
|
|
205
|
+
console.log(` Logo: ${provider.logo_src}`)
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### 4. getLLMModelProvider()
|
|
211
|
+
|
|
212
|
+
Retrieves a specific LLM model provider by its ID.
|
|
213
|
+
|
|
214
|
+
#### Signature
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
async getLLMModelProvider(providerId: string): Promise<GetLLMModelProviderResponse>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### Parameters
|
|
221
|
+
|
|
222
|
+
- `providerId` (string, required): The UUID of the provider
|
|
223
|
+
|
|
224
|
+
#### Returns
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
interface GetLLMModelProviderResponse extends LLMModelProviderInDB {}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### Example
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
const provider = await codeguide.codespace.getLLMModelProvider('provider_uuid_here')
|
|
234
|
+
|
|
235
|
+
console.log(`Provider: ${provider.name}`)
|
|
236
|
+
console.log(`Key: ${provider.key}`)
|
|
237
|
+
console.log(`Created: ${provider.created_at}`)
|
|
238
|
+
|
|
239
|
+
if (provider.logo_src) {
|
|
240
|
+
console.log(`Logo: ${provider.logo_src}`)
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### 5. getModelsByProvider()
|
|
245
|
+
|
|
246
|
+
Retrieves all models for a specific provider.
|
|
247
|
+
|
|
248
|
+
#### Signature
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
async getModelsByProvider(providerId: string): Promise<GetModelsByProviderResponse>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### Parameters
|
|
255
|
+
|
|
256
|
+
- `providerId` (string, required): The UUID of the provider
|
|
257
|
+
|
|
258
|
+
#### Returns
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
interface GetModelsByProviderResponse extends Array<CodespaceModelInDB> {}
|
|
262
|
+
|
|
263
|
+
interface CodespaceModelInDB {
|
|
264
|
+
id: string
|
|
265
|
+
created_at: string
|
|
266
|
+
key?: string
|
|
267
|
+
name?: string
|
|
268
|
+
provider_id?: string
|
|
269
|
+
base_url?: string
|
|
270
|
+
completion_base_url?: string
|
|
271
|
+
execution_mode?: 'opencode' | 'claude-code' | 'docs-only' | 'implementation'
|
|
272
|
+
logo_src?: string
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
#### Example
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
// First, get the provider ID
|
|
280
|
+
const providers = await codeguide.codespace.getLLMModelProviders()
|
|
281
|
+
const openaiProvider = providers.find(p => p.key === 'openai')
|
|
282
|
+
|
|
283
|
+
if (openaiProvider) {
|
|
284
|
+
// Get all models for OpenAI
|
|
285
|
+
const openaiModels = await codeguide.codespace.getModelsByProvider(openaiProvider.id)
|
|
286
|
+
|
|
287
|
+
console.log(`Found ${openaiModels.length} OpenAI models:`)
|
|
288
|
+
openaiModels.forEach(model => {
|
|
289
|
+
console.log(`- ${model.name}`)
|
|
290
|
+
console.log(` Execution Mode: ${model.execution_mode}`)
|
|
291
|
+
console.log(` Base URL: ${model.base_url}`)
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Complete Examples
|
|
297
|
+
|
|
298
|
+
### Example 1: Discover Available Models
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
import { CodeGuide } from '@codeguide/core'
|
|
302
|
+
|
|
303
|
+
const codeguide = new CodeGuide({
|
|
304
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
305
|
+
databaseApiKey: process.env.CODEGUIDE_API_KEY!,
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
async function discoverModels() {
|
|
309
|
+
try {
|
|
310
|
+
// Get all providers
|
|
311
|
+
const providers = await codeguide.codespace.getLLMModelProviders()
|
|
312
|
+
console.log(`Found ${providers.length} providers\n`)
|
|
313
|
+
|
|
314
|
+
// For each provider, get their models
|
|
315
|
+
for (const provider of providers) {
|
|
316
|
+
console.log(`\n${provider.name} (${provider.key}):`)
|
|
317
|
+
|
|
318
|
+
const models = await codeguide.codespace.getModelsByProvider(provider.id)
|
|
319
|
+
|
|
320
|
+
models.forEach(model => {
|
|
321
|
+
console.log(` - ${model.name}`)
|
|
322
|
+
console.log(` Mode: ${model.execution_mode}`)
|
|
323
|
+
console.log(` ID: ${model.id}`)
|
|
324
|
+
})
|
|
325
|
+
}
|
|
326
|
+
} catch (error) {
|
|
327
|
+
console.error('Error discovering models:', error.message)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
discoverModels()
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Example 2: Find Models by Execution Mode
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
async function findModelsByMode() {
|
|
338
|
+
const executionModes = ['implementation', 'docs-only', 'opencode', 'claude-code']
|
|
339
|
+
|
|
340
|
+
for (const mode of executionModes) {
|
|
341
|
+
console.log(`\nModels supporting ${mode}:`)
|
|
342
|
+
|
|
343
|
+
const models = await codeguide.codespace.getCodespaceModels({
|
|
344
|
+
execution_mode: mode,
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
models.forEach(model => {
|
|
348
|
+
console.log(` - ${model.name} (${model.provider?.name})`)
|
|
349
|
+
})
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Example 3: Model Selection for Task
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
async function selectModelForTask(executionMode: 'implementation' | 'docs-only') {
|
|
358
|
+
// Get all models that support the execution mode
|
|
359
|
+
const availableModels = await codeguide.codespace.getCodespaceModels({
|
|
360
|
+
execution_mode: executionMode,
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
if (availableModels.length === 0) {
|
|
364
|
+
throw new Error(`No models available for ${executionMode} mode`)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Select the first available model (or implement your selection logic)
|
|
368
|
+
const selectedModel = availableModels[0]
|
|
369
|
+
|
|
370
|
+
console.log(`Selected model: ${selectedModel.name}`)
|
|
371
|
+
console.log(`Provider: ${selectedModel.provider?.name}`)
|
|
372
|
+
console.log(`Model ID: ${selectedModel.id}`)
|
|
373
|
+
|
|
374
|
+
return selectedModel
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Use the selected model in a codespace task
|
|
378
|
+
async function createTaskWithSelectedModel() {
|
|
379
|
+
const model = await selectModelForTask('implementation')
|
|
380
|
+
|
|
381
|
+
const task = await codeguide.codespace.createCodespaceTaskV2({
|
|
382
|
+
project_id: 'proj_123456',
|
|
383
|
+
task_description: 'Implement user authentication',
|
|
384
|
+
execution_mode: 'implementation',
|
|
385
|
+
model_name: model.name,
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
console.log(`Task created: ${task.task_id}`)
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Example 4: Provider Information Display
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
async function displayProviderInfo() {
|
|
396
|
+
const providers = await codeguide.codespace.getLLMModelProviders()
|
|
397
|
+
|
|
398
|
+
for (const provider of providers) {
|
|
399
|
+
console.log(`\n${provider.name}`)
|
|
400
|
+
console.log(`Key: ${provider.key}`)
|
|
401
|
+
console.log(`ID: ${provider.id}`)
|
|
402
|
+
|
|
403
|
+
// Get provider details
|
|
404
|
+
const providerDetails = await codeguide.codespace.getLLMModelProvider(provider.id)
|
|
405
|
+
|
|
406
|
+
// Get models for this provider
|
|
407
|
+
const models = await codeguide.codespace.getModelsByProvider(provider.id)
|
|
408
|
+
console.log(`Models: ${models.length}`)
|
|
409
|
+
|
|
410
|
+
models.forEach(model => {
|
|
411
|
+
console.log(` - ${model.name} (${model.execution_mode})`)
|
|
412
|
+
})
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
## Error Handling
|
|
418
|
+
|
|
419
|
+
### Model Not Found
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
try {
|
|
423
|
+
const model = await codeguide.codespace.getCodespaceModel('invalid_id')
|
|
424
|
+
} catch (error) {
|
|
425
|
+
if (error.message.includes('404') || error.message.includes('not found')) {
|
|
426
|
+
console.error('Model not found')
|
|
427
|
+
} else {
|
|
428
|
+
console.error('Error:', error.message)
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### Provider Not Found
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
try {
|
|
437
|
+
const provider = await codeguide.codespace.getLLMModelProvider('invalid_id')
|
|
438
|
+
} catch (error) {
|
|
439
|
+
if (error.message.includes('404') || error.message.includes('not found')) {
|
|
440
|
+
console.error('Provider not found')
|
|
441
|
+
} else {
|
|
442
|
+
console.error('Error:', error.message)
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Authentication Errors
|
|
448
|
+
|
|
449
|
+
```typescript
|
|
450
|
+
try {
|
|
451
|
+
const models = await codeguide.codespace.getCodespaceModels()
|
|
452
|
+
} catch (error) {
|
|
453
|
+
if (error.message.includes('401') || error.message.includes('Authentication')) {
|
|
454
|
+
console.error('Authentication failed. Check your API key.')
|
|
455
|
+
} else {
|
|
456
|
+
console.error('Error:', error.message)
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
## Type Definitions
|
|
462
|
+
|
|
463
|
+
### Complete Type Reference
|
|
464
|
+
|
|
465
|
+
```typescript
|
|
466
|
+
// Model with provider information
|
|
467
|
+
interface CodespaceModelWithProvider {
|
|
468
|
+
id: string
|
|
469
|
+
created_at: string
|
|
470
|
+
key?: string
|
|
471
|
+
name?: string
|
|
472
|
+
provider_id?: string
|
|
473
|
+
base_url?: string
|
|
474
|
+
completion_base_url?: string
|
|
475
|
+
execution_mode?: 'opencode' | 'claude-code' | 'docs-only' | 'implementation'
|
|
476
|
+
logo_src?: string
|
|
477
|
+
provider?: LLMModelProviderInDB
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Model without provider (from getModelsByProvider)
|
|
481
|
+
interface CodespaceModelInDB {
|
|
482
|
+
id: string
|
|
483
|
+
created_at: string
|
|
484
|
+
key?: string
|
|
485
|
+
name?: string
|
|
486
|
+
provider_id?: string
|
|
487
|
+
base_url?: string
|
|
488
|
+
completion_base_url?: string
|
|
489
|
+
execution_mode?: 'opencode' | 'claude-code' | 'docs-only' | 'implementation'
|
|
490
|
+
logo_src?: string
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Provider
|
|
494
|
+
interface LLMModelProviderInDB {
|
|
495
|
+
id: string
|
|
496
|
+
created_at: string
|
|
497
|
+
name?: string
|
|
498
|
+
key?: string
|
|
499
|
+
logo_src?: string
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Query parameters
|
|
503
|
+
interface GetCodespaceModelsQuery {
|
|
504
|
+
provider_id?: string
|
|
505
|
+
execution_mode?: string
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// Response types
|
|
509
|
+
interface GetCodespaceModelsResponse extends Array<CodespaceModelWithProvider> {}
|
|
510
|
+
interface GetCodespaceModelResponse extends CodespaceModelWithProvider {}
|
|
511
|
+
interface GetLLMModelProvidersResponse extends Array<LLMModelProviderInDB> {}
|
|
512
|
+
interface GetLLMModelProviderResponse extends LLMModelProviderInDB {}
|
|
513
|
+
interface GetModelsByProviderResponse extends Array<CodespaceModelInDB> {}
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
## Implementation Guide
|
|
517
|
+
|
|
518
|
+
This section provides step-by-step implementation guides for common use cases when working with codespace models.
|
|
519
|
+
|
|
520
|
+
### Basic Implementation: Getting All Models
|
|
521
|
+
|
|
522
|
+
The simplest way to get all available models:
|
|
523
|
+
|
|
524
|
+
```typescript
|
|
525
|
+
import { CodeGuide } from '@codeguide/core'
|
|
526
|
+
|
|
527
|
+
const codeguide = new CodeGuide({
|
|
528
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
529
|
+
databaseApiKey: process.env.CODEGUIDE_API_KEY!,
|
|
530
|
+
})
|
|
531
|
+
|
|
532
|
+
// Get all available models
|
|
533
|
+
async function getAllModels() {
|
|
534
|
+
try {
|
|
535
|
+
const models = await codeguide.codespace.getCodespaceModels()
|
|
536
|
+
console.log(`Found ${models.length} total models`)
|
|
537
|
+
|
|
538
|
+
// Process each model
|
|
539
|
+
models.forEach(model => {
|
|
540
|
+
console.log(`- ${model.name}`)
|
|
541
|
+
console.log(` Provider: ${model.provider?.name}`)
|
|
542
|
+
console.log(` Execution Mode: ${model.execution_mode}`)
|
|
543
|
+
console.log(` ID: ${model.id}`)
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
return models
|
|
547
|
+
} catch (error) {
|
|
548
|
+
console.error('Failed to get models:', error.message)
|
|
549
|
+
throw error
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
### Implementation: Getting Models with Caching
|
|
555
|
+
|
|
556
|
+
For better performance, implement caching to avoid repeated API calls:
|
|
557
|
+
|
|
558
|
+
```typescript
|
|
559
|
+
class ModelCache {
|
|
560
|
+
private modelsCache: GetCodespaceModelsResponse | null = null
|
|
561
|
+
private providersCache: GetLLMModelProvidersResponse | null = null
|
|
562
|
+
private cacheTimestamp: number = 0
|
|
563
|
+
private cacheTTL: number = 5 * 60 * 1000 // 5 minutes
|
|
564
|
+
|
|
565
|
+
constructor(private codeguide: CodeGuide) {}
|
|
566
|
+
|
|
567
|
+
async getModels(forceRefresh = false): Promise<GetCodespaceModelsResponse> {
|
|
568
|
+
const now = Date.now()
|
|
569
|
+
|
|
570
|
+
if (!forceRefresh && this.modelsCache && (now - this.cacheTimestamp) < this.cacheTTL) {
|
|
571
|
+
return this.modelsCache
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
this.modelsCache = await this.codeguide.codespace.getCodespaceModels()
|
|
575
|
+
this.cacheTimestamp = now
|
|
576
|
+
return this.modelsCache
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
async getProviders(forceRefresh = false): Promise<GetLLMModelProvidersResponse> {
|
|
580
|
+
const now = Date.now()
|
|
581
|
+
|
|
582
|
+
if (!forceRefresh && this.providersCache && (now - this.cacheTimestamp) < this.cacheTTL) {
|
|
583
|
+
return this.providersCache
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
this.providersCache = await this.codeguide.codespace.getLLMModelProviders()
|
|
587
|
+
this.cacheTimestamp = now
|
|
588
|
+
return this.providersCache
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
clearCache() {
|
|
592
|
+
this.modelsCache = null
|
|
593
|
+
this.providersCache = null
|
|
594
|
+
this.cacheTimestamp = 0
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// Usage
|
|
599
|
+
const codeguide = new CodeGuide({
|
|
600
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
601
|
+
databaseApiKey: process.env.CODEGUIDE_API_KEY!,
|
|
602
|
+
})
|
|
603
|
+
|
|
604
|
+
const cache = new ModelCache(codeguide)
|
|
605
|
+
|
|
606
|
+
// First call - fetches from API
|
|
607
|
+
const models1 = await cache.getModels()
|
|
608
|
+
|
|
609
|
+
// Second call within 5 minutes - returns cached data
|
|
610
|
+
const models2 = await cache.getModels()
|
|
611
|
+
|
|
612
|
+
// Force refresh
|
|
613
|
+
const models3 = await cache.getModels(true)
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
### Implementation: Filtering Models by Execution Mode
|
|
617
|
+
|
|
618
|
+
Get models that support a specific execution mode:
|
|
619
|
+
|
|
620
|
+
```typescript
|
|
621
|
+
async function getModelsByExecutionMode(
|
|
622
|
+
executionMode: 'implementation' | 'docs-only' | 'opencode' | 'claude-code'
|
|
623
|
+
) {
|
|
624
|
+
try {
|
|
625
|
+
const models = await codeguide.codespace.getCodespaceModels({
|
|
626
|
+
execution_mode: executionMode,
|
|
627
|
+
})
|
|
628
|
+
|
|
629
|
+
if (models.length === 0) {
|
|
630
|
+
throw new Error(`No models found for execution mode: ${executionMode}`)
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
return models
|
|
634
|
+
} catch (error) {
|
|
635
|
+
console.error(`Error getting models for ${executionMode}:`, error.message)
|
|
636
|
+
throw error
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Usage examples
|
|
641
|
+
const implementationModels = await getModelsByExecutionMode('implementation')
|
|
642
|
+
const docsOnlyModels = await getModelsByExecutionMode('docs-only')
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
### Implementation: Getting Models by Provider
|
|
646
|
+
|
|
647
|
+
Get all models for a specific provider:
|
|
648
|
+
|
|
649
|
+
```typescript
|
|
650
|
+
async function getModelsByProviderKey(providerKey: string) {
|
|
651
|
+
try {
|
|
652
|
+
// First, get all providers to find the one we want
|
|
653
|
+
const providers = await codeguide.codespace.getLLMModelProviders()
|
|
654
|
+
const provider = providers.find(p => p.key === providerKey)
|
|
655
|
+
|
|
656
|
+
if (!provider) {
|
|
657
|
+
throw new Error(`Provider not found: ${providerKey}`)
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// Get all models for this provider
|
|
661
|
+
const models = await codeguide.codespace.getModelsByProvider(provider.id)
|
|
662
|
+
|
|
663
|
+
return {
|
|
664
|
+
provider,
|
|
665
|
+
models,
|
|
666
|
+
}
|
|
667
|
+
} catch (error) {
|
|
668
|
+
console.error(`Error getting models for provider ${providerKey}:`, error.message)
|
|
669
|
+
throw error
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// Usage
|
|
674
|
+
const openaiData = await getModelsByProviderKey('openai')
|
|
675
|
+
console.log(`OpenAI has ${openaiData.models.length} models`)
|
|
676
|
+
openaiData.models.forEach(model => {
|
|
677
|
+
console.log(`- ${model.name} (${model.execution_mode})`)
|
|
678
|
+
})
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
### Implementation: Getting a Specific Model by ID
|
|
682
|
+
|
|
683
|
+
Retrieve detailed information about a specific model:
|
|
684
|
+
|
|
685
|
+
```typescript
|
|
686
|
+
async function getModelDetails(modelId: string) {
|
|
687
|
+
try {
|
|
688
|
+
const model = await codeguide.codespace.getCodespaceModel(modelId)
|
|
689
|
+
|
|
690
|
+
return {
|
|
691
|
+
id: model.id,
|
|
692
|
+
name: model.name,
|
|
693
|
+
provider: model.provider?.name,
|
|
694
|
+
providerKey: model.provider?.key,
|
|
695
|
+
executionMode: model.execution_mode,
|
|
696
|
+
baseUrl: model.base_url,
|
|
697
|
+
completionBaseUrl: model.completion_base_url,
|
|
698
|
+
logo: model.logo_src || model.provider?.logo_src,
|
|
699
|
+
}
|
|
700
|
+
} catch (error) {
|
|
701
|
+
if (error.message.includes('404') || error.message.includes('not found')) {
|
|
702
|
+
throw new Error(`Model with ID ${modelId} not found`)
|
|
703
|
+
}
|
|
704
|
+
throw error
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// Usage
|
|
709
|
+
const modelDetails = await getModelDetails('model_uuid_here')
|
|
710
|
+
console.log('Model Details:', modelDetails)
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
### Implementation: Building a Model Selection Utility
|
|
714
|
+
|
|
715
|
+
Create a utility class for model selection:
|
|
716
|
+
|
|
717
|
+
```typescript
|
|
718
|
+
class ModelSelector {
|
|
719
|
+
constructor(private codeguide: CodeGuide) {}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* Get the best model for a given execution mode
|
|
723
|
+
*/
|
|
724
|
+
async selectBestModel(
|
|
725
|
+
executionMode: 'implementation' | 'docs-only' | 'opencode' | 'claude-code',
|
|
726
|
+
preferredProvider?: string
|
|
727
|
+
) {
|
|
728
|
+
const models = await this.codeguide.codespace.getCodespaceModels({
|
|
729
|
+
execution_mode: executionMode,
|
|
730
|
+
})
|
|
731
|
+
|
|
732
|
+
if (models.length === 0) {
|
|
733
|
+
throw new Error(`No models available for execution mode: ${executionMode}`)
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// If a preferred provider is specified, try to find a model from that provider
|
|
737
|
+
if (preferredProvider) {
|
|
738
|
+
const preferredModel = models.find(
|
|
739
|
+
m => m.provider?.key === preferredProvider
|
|
740
|
+
)
|
|
741
|
+
if (preferredModel) {
|
|
742
|
+
return preferredModel
|
|
743
|
+
}
|
|
744
|
+
console.warn(
|
|
745
|
+
`Preferred provider ${preferredProvider} not available, using fallback`
|
|
746
|
+
)
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// Return the first available model
|
|
750
|
+
return models[0]
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Get all available models grouped by provider
|
|
755
|
+
*/
|
|
756
|
+
async getModelsGroupedByProvider() {
|
|
757
|
+
const providers = await this.codeguide.codespace.getLLMModelProviders()
|
|
758
|
+
const grouped: Record<string, {
|
|
759
|
+
provider: LLMModelProviderInDB
|
|
760
|
+
models: CodespaceModelInDB[]
|
|
761
|
+
}> = {}
|
|
762
|
+
|
|
763
|
+
for (const provider of providers) {
|
|
764
|
+
const models = await this.codeguide.codespace.getModelsByProvider(provider.id)
|
|
765
|
+
grouped[provider.key || provider.id] = {
|
|
766
|
+
provider,
|
|
767
|
+
models,
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
return grouped
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Check if a model supports a specific execution mode
|
|
776
|
+
*/
|
|
777
|
+
async modelSupportsExecutionMode(
|
|
778
|
+
modelId: string,
|
|
779
|
+
executionMode: string
|
|
780
|
+
): Promise<boolean> {
|
|
781
|
+
try {
|
|
782
|
+
const model = await this.codeguide.codespace.getCodespaceModel(modelId)
|
|
783
|
+
return model.execution_mode === executionMode
|
|
784
|
+
} catch (error) {
|
|
785
|
+
return false
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// Usage
|
|
791
|
+
const selector = new ModelSelector(codeguide)
|
|
792
|
+
|
|
793
|
+
// Select best model for implementation tasks
|
|
794
|
+
const bestModel = await selector.selectBestModel('implementation', 'openai')
|
|
795
|
+
console.log(`Selected: ${bestModel.name}`)
|
|
796
|
+
|
|
797
|
+
// Get models grouped by provider
|
|
798
|
+
const grouped = await selector.getModelsGroupedByProvider()
|
|
799
|
+
Object.entries(grouped).forEach(([key, data]) => {
|
|
800
|
+
console.log(`${data.provider.name}: ${data.models.length} models`)
|
|
801
|
+
})
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
### Implementation: Error Handling Pattern
|
|
805
|
+
|
|
806
|
+
Comprehensive error handling for model operations:
|
|
807
|
+
|
|
808
|
+
```typescript
|
|
809
|
+
async function getModelsWithErrorHandling() {
|
|
810
|
+
try {
|
|
811
|
+
const models = await codeguide.codespace.getCodespaceModels()
|
|
812
|
+
return { success: true, data: models, error: null }
|
|
813
|
+
} catch (error: any) {
|
|
814
|
+
// Handle different error types
|
|
815
|
+
if (error.message?.includes('401') || error.message?.includes('Authentication')) {
|
|
816
|
+
return {
|
|
817
|
+
success: false,
|
|
818
|
+
data: null,
|
|
819
|
+
error: {
|
|
820
|
+
type: 'AUTHENTICATION_ERROR',
|
|
821
|
+
message: 'Authentication failed. Please check your API key.',
|
|
822
|
+
originalError: error.message,
|
|
823
|
+
},
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
if (error.message?.includes('403') || error.message?.includes('Permission')) {
|
|
828
|
+
return {
|
|
829
|
+
success: false,
|
|
830
|
+
data: null,
|
|
831
|
+
error: {
|
|
832
|
+
type: 'PERMISSION_ERROR',
|
|
833
|
+
message: 'You do not have permission to access models.',
|
|
834
|
+
originalError: error.message,
|
|
835
|
+
},
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
if (error.message?.includes('429') || error.message?.includes('rate limit')) {
|
|
840
|
+
return {
|
|
841
|
+
success: false,
|
|
842
|
+
data: null,
|
|
843
|
+
error: {
|
|
844
|
+
type: 'RATE_LIMIT_ERROR',
|
|
845
|
+
message: 'Rate limit exceeded. Please try again later.',
|
|
846
|
+
originalError: error.message,
|
|
847
|
+
},
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// Generic error
|
|
852
|
+
return {
|
|
853
|
+
success: false,
|
|
854
|
+
data: null,
|
|
855
|
+
error: {
|
|
856
|
+
type: 'UNKNOWN_ERROR',
|
|
857
|
+
message: 'An unexpected error occurred while fetching models.',
|
|
858
|
+
originalError: error.message,
|
|
859
|
+
},
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// Usage
|
|
865
|
+
const result = await getModelsWithErrorHandling()
|
|
866
|
+
if (result.success) {
|
|
867
|
+
console.log(`Found ${result.data.length} models`)
|
|
868
|
+
} else {
|
|
869
|
+
console.error(`Error: ${result.error.message}`)
|
|
870
|
+
}
|
|
871
|
+
```
|
|
872
|
+
|
|
873
|
+
### Implementation: React Hook Example
|
|
874
|
+
|
|
875
|
+
Example React hook for fetching models:
|
|
876
|
+
|
|
877
|
+
```typescript
|
|
878
|
+
import { useState, useEffect } from 'react'
|
|
879
|
+
import { CodeGuide } from '@codeguide/core'
|
|
880
|
+
|
|
881
|
+
interface UseModelsOptions {
|
|
882
|
+
executionMode?: string
|
|
883
|
+
providerId?: string
|
|
884
|
+
autoFetch?: boolean
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
export function useModels(options: UseModelsOptions = {}) {
|
|
888
|
+
const { executionMode, providerId, autoFetch = true } = options
|
|
889
|
+
const [models, setModels] = useState<GetCodespaceModelsResponse>([])
|
|
890
|
+
const [loading, setLoading] = useState(false)
|
|
891
|
+
const [error, setError] = useState<Error | null>(null)
|
|
892
|
+
|
|
893
|
+
const fetchModels = async () => {
|
|
894
|
+
setLoading(true)
|
|
895
|
+
setError(null)
|
|
896
|
+
|
|
897
|
+
try {
|
|
898
|
+
const codeguide = new CodeGuide({
|
|
899
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
900
|
+
databaseApiKey: process.env.REACT_APP_CODEGUIDE_API_KEY!,
|
|
901
|
+
})
|
|
902
|
+
|
|
903
|
+
const query: GetCodespaceModelsQuery = {}
|
|
904
|
+
if (executionMode) query.execution_mode = executionMode
|
|
905
|
+
if (providerId) query.provider_id = providerId
|
|
906
|
+
|
|
907
|
+
const fetchedModels = await codeguide.codespace.getCodespaceModels(query)
|
|
908
|
+
setModels(fetchedModels)
|
|
909
|
+
} catch (err) {
|
|
910
|
+
setError(err instanceof Error ? err : new Error('Unknown error'))
|
|
911
|
+
} finally {
|
|
912
|
+
setLoading(false)
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
useEffect(() => {
|
|
917
|
+
if (autoFetch) {
|
|
918
|
+
fetchModels()
|
|
919
|
+
}
|
|
920
|
+
}, [executionMode, providerId, autoFetch])
|
|
921
|
+
|
|
922
|
+
return {
|
|
923
|
+
models,
|
|
924
|
+
loading,
|
|
925
|
+
error,
|
|
926
|
+
refetch: fetchModels,
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// Usage in a React component
|
|
931
|
+
function ModelList() {
|
|
932
|
+
const { models, loading, error, refetch } = useModels({
|
|
933
|
+
executionMode: 'implementation',
|
|
934
|
+
})
|
|
935
|
+
|
|
936
|
+
if (loading) return <div>Loading models...</div>
|
|
937
|
+
if (error) return <div>Error: {error.message}</div>
|
|
938
|
+
|
|
939
|
+
return (
|
|
940
|
+
<div>
|
|
941
|
+
<h2>Available Models ({models.length})</h2>
|
|
942
|
+
<button onClick={refetch}>Refresh</button>
|
|
943
|
+
<ul>
|
|
944
|
+
{models.map(model => (
|
|
945
|
+
<li key={model.id}>
|
|
946
|
+
{model.name} - {model.provider?.name} ({model.execution_mode})
|
|
947
|
+
</li>
|
|
948
|
+
))}
|
|
949
|
+
</ul>
|
|
950
|
+
</div>
|
|
951
|
+
)
|
|
952
|
+
}
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
## Best Practices
|
|
956
|
+
|
|
957
|
+
1. **Cache Provider and Model Lists**: Cache provider and model information to reduce API calls
|
|
958
|
+
2. **Filter Server-Side**: Use query parameters to filter models rather than filtering client-side
|
|
959
|
+
3. **Handle Missing Models**: Always check if models are available before creating tasks
|
|
960
|
+
4. **Validate Execution Modes**: Ensure the selected model supports your desired execution mode
|
|
961
|
+
5. **Error Handling**: Implement proper error handling for missing models or providers
|
|
962
|
+
|
|
963
|
+
## Use Cases
|
|
964
|
+
|
|
965
|
+
### Selecting a Model for a Task
|
|
966
|
+
|
|
967
|
+
```typescript
|
|
968
|
+
async function selectAppropriateModel(taskType: 'implementation' | 'docs-only') {
|
|
969
|
+
// Get models that support the task type
|
|
970
|
+
const models = await codeguide.codespace.getCodespaceModels({
|
|
971
|
+
execution_mode: taskType,
|
|
972
|
+
})
|
|
973
|
+
|
|
974
|
+
// Implement your selection logic (e.g., prefer certain providers)
|
|
975
|
+
const preferredProvider = models.find(m => m.provider?.key === 'openai')
|
|
976
|
+
return preferredProvider || models[0]
|
|
977
|
+
}
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
### Building a Model Selector UI
|
|
981
|
+
|
|
982
|
+
```typescript
|
|
983
|
+
async function buildModelSelector() {
|
|
984
|
+
const providers = await codeguide.codespace.getLLMModelProviders()
|
|
985
|
+
const modelMap = new Map()
|
|
986
|
+
|
|
987
|
+
for (const provider of providers) {
|
|
988
|
+
const models = await codeguide.codespace.getModelsByProvider(provider.id)
|
|
989
|
+
modelMap.set(provider.id, {
|
|
990
|
+
provider,
|
|
991
|
+
models,
|
|
992
|
+
})
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
return Array.from(modelMap.values())
|
|
996
|
+
}
|
|
997
|
+
```
|
|
998
|
+
|
|
999
|
+
## Related Documentation
|
|
1000
|
+
|
|
1001
|
+
- [Codespace Service](./codespace-service.md) - Complete codespace task documentation
|
|
1002
|
+
- [Projects Service](./projects-service.md) - Project management
|
|
1003
|
+
- [CodeGuide Client](./codeguide-client.md) - Client initialization
|
|
1004
|
+
|