diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index 0fdf26392f6..8360783c60d 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -611,7 +611,7 @@ export namespace Provider { } for (const [modelID, model] of Object.entries(provider.models ?? {})) { - const existingModel = parsed.models[model.id ?? modelID] + const existingModel = parsed.models[modelID] const name = iife(() => { if (model.name) return model.name if (model.id && model.id !== modelID) return modelID diff --git a/packages/opencode/test/provider/provider.test.ts b/packages/opencode/test/provider/provider.test.ts index c6c6924f01f..56ee38c8f0d 100644 --- a/packages/opencode/test/provider/provider.test.ts +++ b/packages/opencode/test/provider/provider.test.ts @@ -447,6 +447,55 @@ test("provider with baseURL from config", async () => { }) }) +test("multiple local ollama models with similar names are all loaded", async () => { + await using tmp = await tmpdir({ + init: async (dir) => { + await Bun.write( + path.join(dir, "opencode.json"), + JSON.stringify({ + $schema: "https://opencode.ai/config.json", + provider: { + ollama: { + npm: "@ai-sdk/openai-compatible", + name: "Ollama", + options: { + baseURL: "http://localhost:11434/v1", + }, + models: { + "devstral-small-2:24b-cloud": { + name: "Devstral Small 2 (Cloud)", + }, + "devstral-small-2:latest": { + name: "Devstral Small 2 (local)", + }, + "devstral-2:123b-cloud": { + name: "Devstral 2 (Cloud)", + }, + }, + }, + }, + }), + ) + }, + }) + await Instance.provide({ + directory: tmp.path, + fn: async () => { + const providers = await Provider.list() + expect(providers["ollama"]).toBeDefined() + expect(providers["ollama"].models).toBeDefined() + + const models = Object.values(providers["ollama"].models) + expect(models.length).toBe(3) + + const modelIds = models.map((m) => m.id).sort() + expect(modelIds).toContain("devstral-small-2:24b-cloud") + expect(modelIds).toContain("devstral-small-2:latest") + expect(modelIds).toContain("devstral-2:123b-cloud") + }, + }) +}) + test("model cost defaults to zero when not specified", async () => { await using tmp = await tmpdir({ init: async (dir) => {