mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 10:00:39 +00:00
Add OpenCode Zen provider support
This commit is contained in:
parent
98b25baf4d
commit
97d0189eae
8 changed files with 529 additions and 1 deletions
|
|
@ -27,6 +27,9 @@ interface ModelsDevModel {
|
|||
modalities?: {
|
||||
input?: string[];
|
||||
};
|
||||
provider?: {
|
||||
npm?: string;
|
||||
};
|
||||
}
|
||||
|
||||
const COPILOT_STATIC_HEADERS = {
|
||||
|
|
@ -314,6 +317,57 @@ async function loadModelsDevData(): Promise<Model<any>[]> {
|
|||
}
|
||||
}
|
||||
|
||||
// Process OpenCode Zen models
|
||||
// API mapping based on provider.npm field:
|
||||
// - @ai-sdk/openai → openai-responses
|
||||
// - @ai-sdk/anthropic → anthropic-messages
|
||||
// - @ai-sdk/google → google-generative-ai
|
||||
// - null/undefined/@ai-sdk/openai-compatible → openai-completions
|
||||
if (data.opencode?.models) {
|
||||
for (const [modelId, model] of Object.entries(data.opencode.models)) {
|
||||
const m = model as ModelsDevModel;
|
||||
if (m.tool_call !== true) continue;
|
||||
|
||||
const npm = m.provider?.npm;
|
||||
let api: Api;
|
||||
let baseUrl: string;
|
||||
|
||||
if (npm === "@ai-sdk/openai") {
|
||||
api = "openai-responses";
|
||||
baseUrl = "https://opencode.ai/zen/v1";
|
||||
} else if (npm === "@ai-sdk/anthropic") {
|
||||
api = "anthropic-messages";
|
||||
// Anthropic SDK appends /v1/messages to baseURL
|
||||
baseUrl = "https://opencode.ai/zen";
|
||||
} else if (npm === "@ai-sdk/google") {
|
||||
api = "google-generative-ai";
|
||||
baseUrl = "https://opencode.ai/zen/v1";
|
||||
} else {
|
||||
// null, undefined, or @ai-sdk/openai-compatible
|
||||
api = "openai-completions";
|
||||
baseUrl = "https://opencode.ai/zen/v1";
|
||||
}
|
||||
|
||||
models.push({
|
||||
id: modelId,
|
||||
name: m.name || modelId,
|
||||
api,
|
||||
provider: "opencode",
|
||||
baseUrl,
|
||||
reasoning: m.reasoning === true,
|
||||
input: m.modalities?.input?.includes("image") ? ["text", "image"] : ["text"],
|
||||
cost: {
|
||||
input: m.cost?.input || 0,
|
||||
output: m.cost?.output || 0,
|
||||
cacheRead: m.cost?.cache_read || 0,
|
||||
cacheWrite: m.cost?.cache_write || 0,
|
||||
},
|
||||
contextWindow: m.limit?.context || 4096,
|
||||
maxTokens: m.limit?.output || 4096,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Process GitHub Copilot models
|
||||
if (data["github-copilot"]?.models) {
|
||||
for (const [modelId, model] of Object.entries(data["github-copilot"].models)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue