Skip to content

Commit 38a6d24

Browse files
committed
feat: add CometAPI as a model provider
- Add CometAPI type definitions with support for GPT-5, Claude-4, Gemini-2.5, and other models - Implement CometAPIHandler extending RouterProvider for OpenAI-compatible API - Add CometAPI to provider settings and configuration - Update webview components to support CometAPI provider - Add CometAPI to dynamic providers list for model fetching Implements #7688
1 parent 7935c94 commit 38a6d24

File tree

9 files changed

+382
-1
lines changed

9 files changed

+382
-1
lines changed

packages/types/src/provider-settings.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
export const providerNames = [
3535
"anthropic",
3636
"claude-code",
37+
"cometapi",
3738
"glama",
3839
"openrouter",
3940
"bedrock",
@@ -336,13 +337,20 @@ const vercelAiGatewaySchema = baseProviderSettingsSchema.extend({
336337
vercelAiGatewayModelId: z.string().optional(),
337338
})
338339

340+
const cometApiSchema = baseProviderSettingsSchema.extend({
341+
cometApiBaseUrl: z.string().optional(),
342+
cometApiApiKey: z.string().optional(),
343+
cometApiModelId: z.string().optional(),
344+
})
345+
339346
const defaultSchema = z.object({
340347
apiProvider: z.undefined(),
341348
})
342349

343350
export const providerSettingsSchemaDiscriminated = z.discriminatedUnion("apiProvider", [
344351
anthropicSchema.merge(z.object({ apiProvider: z.literal("anthropic") })),
345352
claudeCodeSchema.merge(z.object({ apiProvider: z.literal("claude-code") })),
353+
cometApiSchema.merge(z.object({ apiProvider: z.literal("cometapi") })),
346354
glamaSchema.merge(z.object({ apiProvider: z.literal("glama") })),
347355
openRouterSchema.merge(z.object({ apiProvider: z.literal("openrouter") })),
348356
bedrockSchema.merge(z.object({ apiProvider: z.literal("bedrock") })),
@@ -384,6 +392,7 @@ export const providerSettingsSchema = z.object({
384392
apiProvider: providerNamesSchema.optional(),
385393
...anthropicSchema.shape,
386394
...claudeCodeSchema.shape,
395+
...cometApiSchema.shape,
387396
...glamaSchema.shape,
388397
...openRouterSchema.shape,
389398
...bedrockSchema.shape,
@@ -418,6 +427,7 @@ export const providerSettingsSchema = z.object({
418427
...qwenCodeSchema.shape,
419428
...rooSchema.shape,
420429
...vercelAiGatewaySchema.shape,
430+
...cometApiSchema.shape,
421431
...codebaseIndexProviderSchema.shape,
422432
})
423433

@@ -448,6 +458,7 @@ export const MODEL_ID_KEYS: Partial<keyof ProviderSettings>[] = [
448458
"ioIntelligenceModelId",
449459
"vercelAiGatewayModelId",
450460
"deepInfraModelId",
461+
"cometApiModelId",
451462
]
452463

453464
export const getModelId = (settings: ProviderSettings): string | undefined => {
@@ -571,6 +582,7 @@ export const MODELS_BY_PROVIDER: Record<
571582
unbound: { id: "unbound", label: "Unbound", models: [] },
572583
deepinfra: { id: "deepinfra", label: "DeepInfra", models: [] },
573584
"vercel-ai-gateway": { id: "vercel-ai-gateway", label: "Vercel AI Gateway", models: [] },
585+
cometapi: { id: "cometapi", label: "CometAPI", models: [] },
574586
}
575587

576588
export const dynamicProviders = [
@@ -582,6 +594,7 @@ export const dynamicProviders = [
582594
"unbound",
583595
"deepinfra",
584596
"vercel-ai-gateway",
597+
"cometapi",
585598
] as const satisfies readonly ProviderName[]
586599

587600
export type DynamicProvider = (typeof dynamicProviders)[number]
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
import type { ModelInfo } from "../model.js"
2+
3+
// Default fallback values for CometAPI when model metadata is not yet loaded.
4+
export const cometApiDefaultModelId = "gpt-5-chat-latest"
5+
6+
export const cometApiDefaultModelInfo: ModelInfo = {
7+
maxTokens: 16384,
8+
contextWindow: 128000,
9+
supportsImages: true,
10+
supportsPromptCache: false,
11+
inputPrice: 2.5,
12+
outputPrice: 10,
13+
description: "GPT-5 Chat Latest model with 128K context window.",
14+
}
15+
16+
// Fallback models for CometAPI when the API is unavailable
17+
export const COMETAPI_MODELS: Record<string, ModelInfo> = {
18+
// GPT series
19+
"gpt-5-chat-latest": {
20+
maxTokens: 16384,
21+
contextWindow: 128000,
22+
supportsImages: true,
23+
supportsPromptCache: false,
24+
inputPrice: 2.5,
25+
outputPrice: 10,
26+
description: "GPT-5 Chat Latest - Most advanced GPT model",
27+
},
28+
"chatgpt-4o-latest": {
29+
maxTokens: 16384,
30+
contextWindow: 128000,
31+
supportsImages: true,
32+
supportsPromptCache: false,
33+
inputPrice: 2.5,
34+
outputPrice: 10,
35+
description: "ChatGPT-4o Latest - Advanced multimodal model",
36+
},
37+
"gpt-5-mini": {
38+
maxTokens: 16384,
39+
contextWindow: 128000,
40+
supportsImages: true,
41+
supportsPromptCache: false,
42+
inputPrice: 0.15,
43+
outputPrice: 0.6,
44+
description: "GPT-5 Mini - Efficient and cost-effective",
45+
},
46+
"gpt-5-nano": {
47+
maxTokens: 8192,
48+
contextWindow: 128000,
49+
supportsImages: false,
50+
supportsPromptCache: false,
51+
inputPrice: 0.075,
52+
outputPrice: 0.3,
53+
description: "GPT-5 Nano - Ultra-efficient for simple tasks",
54+
},
55+
"gpt-4.1-mini": {
56+
maxTokens: 16384,
57+
contextWindow: 128000,
58+
supportsImages: true,
59+
supportsPromptCache: false,
60+
inputPrice: 0.15,
61+
outputPrice: 0.6,
62+
description: "GPT-4.1 Mini - Balanced performance and cost",
63+
},
64+
"gpt-4o-mini": {
65+
maxTokens: 16384,
66+
contextWindow: 128000,
67+
supportsImages: true,
68+
supportsPromptCache: false,
69+
inputPrice: 0.15,
70+
outputPrice: 0.6,
71+
description: "GPT-4o Mini - Efficient multimodal model",
72+
},
73+
74+
// Claude series
75+
"claude-opus-4-1-20250805": {
76+
maxTokens: 8192,
77+
contextWindow: 200000,
78+
supportsImages: true,
79+
supportsPromptCache: true,
80+
inputPrice: 3,
81+
outputPrice: 15,
82+
description: "Claude Opus 4.1 - Most capable Claude model",
83+
},
84+
"claude-sonnet-4-20250514": {
85+
maxTokens: 8192,
86+
contextWindow: 200000,
87+
supportsImages: true,
88+
supportsPromptCache: true,
89+
inputPrice: 1.5,
90+
outputPrice: 7.5,
91+
description: "Claude Sonnet 4 - Balanced Claude model",
92+
},
93+
"claude-3-7-sonnet-latest": {
94+
maxTokens: 8192,
95+
contextWindow: 200000,
96+
supportsImages: true,
97+
supportsPromptCache: true,
98+
inputPrice: 3,
99+
outputPrice: 15,
100+
description: "Claude 3.7 Sonnet - Latest Sonnet version",
101+
},
102+
"claude-3-5-haiku-latest": {
103+
maxTokens: 8192,
104+
contextWindow: 200000,
105+
supportsImages: true,
106+
supportsPromptCache: true,
107+
inputPrice: 0.25,
108+
outputPrice: 1.25,
109+
description: "Claude 3.5 Haiku - Fast and efficient",
110+
},
111+
112+
// Gemini series
113+
"gemini-2.5-pro": {
114+
maxTokens: 8192,
115+
contextWindow: 2097152,
116+
supportsImages: true,
117+
supportsPromptCache: false,
118+
inputPrice: 1.25,
119+
outputPrice: 5,
120+
description: "Gemini 2.5 Pro - Google's most capable model",
121+
},
122+
"gemini-2.5-flash": {
123+
maxTokens: 8192,
124+
contextWindow: 1048576,
125+
supportsImages: true,
126+
supportsPromptCache: false,
127+
inputPrice: 0.075,
128+
outputPrice: 0.3,
129+
description: "Gemini 2.5 Flash - Fast and efficient",
130+
},
131+
"gemini-2.0-flash": {
132+
maxTokens: 8192,
133+
contextWindow: 1048576,
134+
supportsImages: true,
135+
supportsPromptCache: false,
136+
inputPrice: 0.075,
137+
outputPrice: 0.3,
138+
description: "Gemini 2.0 Flash - Previous generation flash model",
139+
},
140+
141+
// DeepSeek series
142+
"deepseek-v3.1": {
143+
maxTokens: 8192,
144+
contextWindow: 128000,
145+
supportsImages: false,
146+
supportsPromptCache: false,
147+
inputPrice: 0.14,
148+
outputPrice: 0.28,
149+
description: "DeepSeek V3.1 - Advanced reasoning model",
150+
},
151+
"deepseek-r1-0528": {
152+
maxTokens: 8192,
153+
contextWindow: 128000,
154+
supportsImages: false,
155+
supportsPromptCache: false,
156+
supportsReasoningEffort: true,
157+
inputPrice: 0.55,
158+
outputPrice: 2.19,
159+
description: "DeepSeek R1 - Reasoning-focused model",
160+
},
161+
"deepseek-reasoner": {
162+
maxTokens: 8192,
163+
contextWindow: 128000,
164+
supportsImages: false,
165+
supportsPromptCache: false,
166+
supportsReasoningEffort: true,
167+
inputPrice: 0.55,
168+
outputPrice: 2.19,
169+
description: "DeepSeek Reasoner - Advanced reasoning capabilities",
170+
},
171+
172+
// Other popular models
173+
"grok-4-0709": {
174+
maxTokens: 8192,
175+
contextWindow: 128000,
176+
supportsImages: true,
177+
supportsPromptCache: false,
178+
inputPrice: 5,
179+
outputPrice: 15,
180+
description: "Grok 4 - xAI's advanced model",
181+
},
182+
"qwen3-30b-a3b": {
183+
maxTokens: 8192,
184+
contextWindow: 32768,
185+
supportsImages: false,
186+
supportsPromptCache: false,
187+
inputPrice: 0.5,
188+
outputPrice: 1.5,
189+
description: "Qwen3 30B - Alibaba's large language model",
190+
},
191+
"qwen3-coder-plus-2025-07-22": {
192+
maxTokens: 8192,
193+
contextWindow: 32768,
194+
supportsImages: false,
195+
supportsPromptCache: false,
196+
inputPrice: 0.5,
197+
outputPrice: 1.5,
198+
description: "Qwen3 Coder Plus - Specialized for coding tasks",
199+
},
200+
}

packages/types/src/providers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from "./bedrock.js"
33
export * from "./cerebras.js"
44
export * from "./chutes.js"
55
export * from "./claude-code.js"
6+
export * from "./cometapi.js"
67
export * from "./deepseek.js"
78
export * from "./doubao.js"
89
export * from "./featherless.js"

src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
AnthropicHandler,
1010
AwsBedrockHandler,
1111
CerebrasHandler,
12+
CometAPIHandler,
1213
OpenRouterHandler,
1314
VertexHandler,
1415
AnthropicVertexHandler,
@@ -95,6 +96,8 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
9596
return new AnthropicHandler(options)
9697
case "claude-code":
9798
return new ClaudeCodeHandler(options)
99+
case "cometapi":
100+
return new CometAPIHandler(options)
98101
case "glama":
99102
return new GlamaHandler(options)
100103
case "openrouter":

0 commit comments

Comments
 (0)