mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 21:03:56 +00:00
fix(coding-agent): allow model-level baseUrl override in models.json closes #1777
This commit is contained in:
parent
7bd4c45d81
commit
1912f0336b
2 changed files with 42 additions and 3 deletions
|
|
@ -70,6 +70,7 @@ const ModelDefinitionSchema = Type.Object({
|
||||||
id: Type.String({ minLength: 1 }),
|
id: Type.String({ minLength: 1 }),
|
||||||
name: Type.Optional(Type.String({ minLength: 1 })),
|
name: Type.Optional(Type.String({ minLength: 1 })),
|
||||||
api: Type.Optional(Type.String({ minLength: 1 })),
|
api: Type.Optional(Type.String({ minLength: 1 })),
|
||||||
|
baseUrl: Type.Optional(Type.String({ minLength: 1 })),
|
||||||
reasoning: Type.Optional(Type.Boolean()),
|
reasoning: Type.Optional(Type.Boolean()),
|
||||||
input: Type.Optional(Type.Array(Type.Union([Type.Literal("text"), Type.Literal("image")]))),
|
input: Type.Optional(Type.Array(Type.Union([Type.Literal("text"), Type.Literal("image")]))),
|
||||||
cost: Type.Optional(
|
cost: Type.Optional(
|
||||||
|
|
@ -469,15 +470,15 @@ export class ModelRegistry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// baseUrl is validated to exist for providers with models
|
// Provider baseUrl is required when custom models are defined.
|
||||||
// Apply defaults for optional fields
|
// Individual models can override it with modelDef.baseUrl.
|
||||||
const defaultCost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
const defaultCost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
||||||
models.push({
|
models.push({
|
||||||
id: modelDef.id,
|
id: modelDef.id,
|
||||||
name: modelDef.name ?? modelDef.id,
|
name: modelDef.name ?? modelDef.id,
|
||||||
api: api as Api,
|
api: api as Api,
|
||||||
provider: providerName,
|
provider: providerName,
|
||||||
baseUrl: providerConfig.baseUrl!,
|
baseUrl: modelDef.baseUrl ?? providerConfig.baseUrl!,
|
||||||
reasoning: modelDef.reasoning ?? false,
|
reasoning: modelDef.reasoning ?? false,
|
||||||
input: (modelDef.input ?? ["text"]) as ("text" | "image")[],
|
input: (modelDef.input ?? ["text"]) as ("text" | "image")[],
|
||||||
cost: modelDef.cost ?? defaultCost,
|
cost: modelDef.cost ?? defaultCost,
|
||||||
|
|
@ -682,6 +683,7 @@ export interface ProviderConfigInput {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
api?: Api;
|
api?: Api;
|
||||||
|
baseUrl?: string;
|
||||||
reasoning: boolean;
|
reasoning: boolean;
|
||||||
input: ("text" | "image")[];
|
input: ("text" | "image")[];
|
||||||
cost: { input: number; output: number; cacheRead: number; cacheWrite: number };
|
cost: { input: number; output: number; cacheRead: number; cacheWrite: number };
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,43 @@ describe("ModelRegistry", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("model-level baseUrl overrides provider-level baseUrl for custom models", () => {
|
||||||
|
writeRawModelsJson({
|
||||||
|
"opencode-go": {
|
||||||
|
baseUrl: "https://opencode.ai/zen/go/v1",
|
||||||
|
apiKey: "TEST_KEY",
|
||||||
|
models: [
|
||||||
|
{
|
||||||
|
id: "minimax-m2.5",
|
||||||
|
api: "anthropic-messages",
|
||||||
|
baseUrl: "https://opencode.ai/zen/go",
|
||||||
|
reasoning: true,
|
||||||
|
input: ["text"],
|
||||||
|
cost: { input: 0.3, output: 1.2, cacheRead: 0.03, cacheWrite: 0 },
|
||||||
|
contextWindow: 204800,
|
||||||
|
maxTokens: 131072,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "glm-5",
|
||||||
|
api: "openai-completions",
|
||||||
|
reasoning: true,
|
||||||
|
input: ["text"],
|
||||||
|
cost: { input: 1, output: 3.2, cacheRead: 0.2, cacheWrite: 0 },
|
||||||
|
contextWindow: 204800,
|
||||||
|
maxTokens: 131072,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const registry = new ModelRegistry(authStorage, modelsJsonPath);
|
||||||
|
const m25 = registry.find("opencode-go", "minimax-m2.5");
|
||||||
|
const glm5 = registry.find("opencode-go", "glm-5");
|
||||||
|
|
||||||
|
expect(m25?.baseUrl).toBe("https://opencode.ai/zen/go");
|
||||||
|
expect(glm5?.baseUrl).toBe("https://opencode.ai/zen/go/v1");
|
||||||
|
});
|
||||||
|
|
||||||
test("modelOverrides still apply when provider also defines models", () => {
|
test("modelOverrides still apply when provider also defines models", () => {
|
||||||
writeRawModelsJson({
|
writeRawModelsJson({
|
||||||
openrouter: {
|
openrouter: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue