🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(model-runtime): route OpenCode Go Muse Spark through Responses (#19109)
AmAzing-fc48479dd4cb
diff --git a/packages/model-bank/src/aiModels/__tests__/index.test.ts b/packages/model-bank/src/aiModels/__tests__/index.test.tsindex e02f8931051..8cd7265ad12 100644--- a/packages/model-bank/src/aiModels/__tests__/index.test.ts+++ b/packages/model-bank/src/aiModels/__tests__/index.test.ts@@ -123,6 +123,33 @@ describe('OpenAI audio models', () => {});});+describe('OpenCode Go models', () => {+ it('registers the Muse Spark Contributor series', () => {+ const models = LOBE_DEFAULT_MODEL_LIST.filter(+ (model) =>+ model.providerId === ModelProvider.OpenCodeCodingPlan && model.id.startsWith('muse-spark-'),+ );++ expect(models.map(({ id }) => id)).toEqual([+ 'muse-spark-1.2-contributor',+ 'muse-spark-1.3-contributor',+ ]);+ expect(models.find(({ id }) => id === 'muse-spark-1.3-contributor')).toEqual(+ expect.objectContaining({+ abilities: expect.objectContaining({+ functionCall: true,+ reasoning: true,+ structuredOutput: true,+ vision: true,+ }),+ contextWindowTokens: 1_048_576,+ enabled: true,+ maxOutput: 131_072,+ }),+ );+ });+});+describe('Moonshot models', () => {it('advertises Kimi K3 reasoning effort controls', () => {const kimiK3 = LOBE_DEFAULT_MODEL_LIST.find(diff --git a/packages/model-bank/src/aiModels/opencodeCodingPlan.ts b/packages/model-bank/src/aiModels/opencodeCodingPlan.tsindex 248ccf7a028..22d3a2dcc6b 100644--- a/packages/model-bank/src/aiModels/opencodeCodingPlan.ts+++ b/packages/model-bank/src/aiModels/opencodeCodingPlan.ts@@ -237,6 +237,58 @@ const opencodeCodingPlanChatModels: AIChatModelCard[] = [},type: 'chat',},+ {+ abilities: { functionCall: true, reasoning: true, structuredOutput: true, vision: true },+ contextWindowTokens: 1_048_576,+ description:+ 'Muse Spark 1.2 is a coding-focused update to Muse Spark 1.1 with improvements in code generation, complex debugging, codebase understanding, and end-to-end developer workflows.',+ displayName: 'Muse Spark 1.2 Contributor',+ enabled: false,+ family: 'muse',+ generation: 'muse-spark-1.2',+ id: 'muse-spark-1.2-contributor',+ maxOutput: 131_072,+ organization: 'Meta',+ pricing: {+ currency: 'USD',+ units: [+ { name: 'textInput', rate: 0.1, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textOutput', rate: 0.2, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textInput_cacheRead', rate: 0.002, strategy: 'fixed', unit: 'millionTokens' },+ ],+ },+ releasedAt: '2026-08-05',+ settings: {+ extendParams: ['reasoningEffort'],+ },+ type: 'chat',+ },+ {+ abilities: { functionCall: true, reasoning: true, structuredOutput: true, vision: true },+ contextWindowTokens: 1_048_576,+ description:+ 'Muse Spark 1.3 is a multimodal reasoning model from Meta for coding and agentic workflows.',+ displayName: 'Muse Spark 1.3 Contributor',+ enabled: true,+ family: 'muse',+ generation: 'muse-spark-1.3',+ id: 'muse-spark-1.3-contributor',+ maxOutput: 131_072,+ organization: 'Meta',+ pricing: {+ currency: 'USD',+ units: [+ { name: 'textInput', rate: 0.1, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textOutput', rate: 0.2, strategy: 'fixed', unit: 'millionTokens' },+ { name: 'textInput_cacheRead', rate: 0.002, strategy: 'fixed', unit: 'millionTokens' },+ ],+ },+ releasedAt: '2026-09-02',+ settings: {+ extendParams: ['reasoningEffort'],+ },+ type: 'chat',+ },{abilities: { functionCall: true, reasoning: true, vision: true },contextWindowTokens: 262_144,diff --git a/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.ts b/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.tsindex 92c0d8580e9..74128ee216f 100644--- a/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.ts+++ b/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.ts@@ -152,6 +152,139 @@ describe('sanitizeJsonSchema', () => {});});+describe('Muse Spark Responses API routing', () => {+ let chatCreateSpy: Mock;+ let responsesCreateSpy: Mock;++ beforeEach(() => {+ loadModelsMock.mockResolvedValue([]);+ chatCreateSpy = vi+ .spyOn(OpenAI.Chat.Completions.prototype, 'create')+ .mockResolvedValue(new ReadableStream() as any) as unknown as Mock;+ responsesCreateSpy = vi+ .spyOn(OpenAI.Responses.prototype, 'create')+ .mockResolvedValue(new ReadableStream() as any) as unknown as Mock;+ });++ afterEach(() => {+ vi.restoreAllMocks();+ });++ it.each(['muse-spark-1.2-contributor', 'muse-spark-1.3-contributor'])(+ 'routes %s through Responses even when the provider-level default is Chat Completions',+ async (model) => {+ const instance = new LobeOpenCodeCodingPlanAI({ apiKey: 'test' });++ await instance.chat({+ apiMode: 'chatCompletion',+ messages: [{ content: 'Hello', role: 'user' }],+ model,+ });++ expect(responsesCreateSpy).toHaveBeenCalledOnce();+ expect(chatCreateSpy).not.toHaveBeenCalled();+ },+ );++ describe.each(['muse-spark-1.2-contributor', 'muse-spark-1.3-contributor'])(+ '%s structured generation with offline model discovery',+ (model) => {+ it('generates JSON through Responses without an explicit API override', async () => {+ responsesCreateSpy.mockResolvedValue({ output_text: '{"answer":"Hello"}' });+ const instance = new LobeOpenCodeCodingPlanAI({ apiKey: 'test' });++ const result = await instance.generateObject({+ messages: [{ content: 'Hello', role: 'user' }],+ model,+ schema: {+ name: 'answer',+ schema: { properties: { answer: { type: 'string' } }, type: 'object' },+ },+ });++ expect(result).toEqual({ answer: 'Hello' });+ expect(responsesCreateSpy).toHaveBeenCalledOnce();+ expect(chatCreateSpy).not.toHaveBeenCalled();+ });++ it('generates tool calls through Responses without an explicit API override', async () => {+ responsesCreateSpy.mockResolvedValue({+ output: [{ arguments: '{"answer":"Hello"}', name: 'answer', type: 'function_call' }],+ });+ const instance = new LobeOpenCodeCodingPlanAI({ apiKey: 'test' });++ const result = await instance.generateObject({+ messages: [{ content: 'Hello', role: 'user' }],+ model,+ tools: [+ {+ function: {+ name: 'answer',+ parameters: { properties: { answer: { type: 'string' } }, type: 'object' },+ },+ type: 'function',+ },+ ],+ });++ expect(result).toEqual([{ arguments: { answer: 'Hello' }, name: 'answer' }]);+ expect(responsesCreateSpy).toHaveBeenCalledOnce();+ expect(chatCreateSpy).not.toHaveBeenCalled();+ });+ },+ );++ it('keeps other models on Chat Completions for structured generation', async () => {+ chatCreateSpy.mockResolvedValue({+ choices: [{ message: { content: '{"answer":"Hello"}' } }],+ });+ const instance = new LobeOpenCodeCodingPlanAI({ apiKey: 'test' });++ const result = await instance.generateObject({+ messages: [{ content: 'Hello', role: 'user' }],+ model: 'glm-5',+ schema: {+ name: 'answer',+ schema: { properties: { answer: { type: 'string' } }, type: 'object' },+ },+ });++ expect(result).toEqual({ answer: 'Hello' });+ expect(chatCreateSpy).toHaveBeenCalledOnce();+ expect(responsesCreateSpy).not.toHaveBeenCalled();+ });++ it('uses Responses models discovered after runtime initialization', async () => {+ vi.resetModules();+ const { LobeOpenCodeCodingPlanAI: Runtime } = await import('./index');+ const model = 'discovered-responses-model';+ vi.spyOn(global, 'fetch').mockResolvedValueOnce(+ new Response(+ JSON.stringify({+ 'opencode-go': {+ models: { [model]: { id: model, provider: { npm: '@ai-sdk/openai' } } },+ },+ }),+ ),+ );+ responsesCreateSpy.mockResolvedValue({ output_text: '{"answer":"Hello"}' });+ const instance = new Runtime({ apiKey: 'test' });++ const result = await instance.generateObject({+ messages: [{ content: 'Hello', role: 'user' }],+ model,+ schema: {+ name: 'answer',+ schema: { properties: { answer: { type: 'string' } }, type: 'object' },+ },+ });++ expect(result).toEqual({ answer: 'Hello' });+ expect(responsesCreateSpy).toHaveBeenCalledOnce();+ expect(chatCreateSpy).not.toHaveBeenCalled();+ });+});+describe('buildOpenAIPayload Kimi thinking semantics', () => {let instance: InstanceType<typeof LobeOpenCodeCodingPlanAI>;let createSpy: Mock;diff --git a/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts b/packages/model-runtime/src/providers/opencodeCodingPlan/index.tsindex d41b452f95c..f7d5ee5120b 100644--- a/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts+++ b/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts@@ -61,6 +61,7 @@ interface ModelsCache {*/interleavedIds: Set<string>;modelsDev: Record<string, ModelsDevModel>;+ responsesIds: Set<string>;}// Fallback: models that need Anthropic SDK (used when models.dev is unavailable)@@ -81,6 +82,13 @@ const FALLBACK_INTERLEAVED_IDS: ReadonlySet<string> = new Set(['mimo-v2.5-pro',]);+// Fallback: models that require OpenAI's Responses API when models.dev is+// unreachable. Mirrors OpenCode Go's documented endpoint matrix.+const FALLBACK_RESPONSES_IDS: ReadonlySet<string> = new Set([+ 'muse-spark-1.2-contributor',+ 'muse-spark-1.3-contributor',+]);+let cachedModelsData: ModelsCache | null = null;// ============================================================================@@ -90,6 +98,7 @@ let cachedModelsData: ModelsCache | null = null;/*** Fetch models.dev data and derive all per-provider fields from it:* - `anthropicModels` (models whose `provider.npm` is the Anthropic SDK)+ * - `responsesIds` (models whose `provider.npm` is the OpenAI SDK)* - `interleavedIds` (models with `interleaved.field` set, needing* special reasoning_content handling)* - `modelsDev` (raw model map for enrichment)@@ -113,19 +122,25 @@ const fetchModelsDevData = async (): Promise<ModelsCache> => {const anthropicModels = Object.values(models).filter((m) => m.provider?.npm === '@ai-sdk/anthropic').map((m) => m.id);+ const responsesIds = new Set(+ Object.values(models)+ .filter((m) => m.provider?.npm === '@ai-sdk/openai')+ .map((m) => m.id),+ );const interleavedIds = new Set<string>();for (const m of Object.values(models)) {if (m?.interleaved?.field) interleavedIds.add(m.id);}- cachedModelsData = { anthropicModels, interleavedIds, modelsDev: models };+ cachedModelsData = { anthropicModels, interleavedIds, modelsDev: models, responsesIds };return cachedModelsData;} catch {cachedModelsData = {anthropicModels: [],interleavedIds: new Set(),modelsDev: {},+ responsesIds: new Set(),};return cachedModelsData;}@@ -144,6 +159,13 @@ const getInterleavedModelIds = (): ReadonlySet<string> => {return FALLBACK_INTERLEAVED_IDS;};+const getResponsesModelIds = (): ReadonlySet<string> => {+ if (cachedModelsData && cachedModelsData.responsesIds.size > 0) {+ return cachedModelsData.responsesIds;+ }+ return FALLBACK_RESPONSES_IDS;+};+/*** Get anthropic models with self-contained fallback chain:* 1. models.dev (authoritative `provider.npm` field)@@ -307,13 +329,17 @@ export const sanitizeJsonSchema = (schema: any): any => {// ============================================================================/**- * Build OpenAI-compatible payload with reasoning_content handling.- * Applies to models with interleaved reasoning_content and Kimi K2.x models.+ * Select Responses-only models and build OpenAI-compatible payloads with+ * reasoning_content handling for interleaved and Kimi K2.x models.*/const buildOpenAIPayload = (payload: ChatStreamPayload,): OpenAI.ChatCompletionCreateParamsStreaming => {const model = payload.model;+ if (getResponsesModelIds().has(model)) {+ return { ...payload, apiMode: 'responses' } as OpenAI.ChatCompletionCreateParamsStreaming;+ }+const isKimi = isKimiThinkingToggleModel(model);const interleaved = isInterleavedModel(model);@@ -415,6 +441,11 @@ const LobeOpenCodeCodingPlanOpenAI = createOpenAICompatibleRuntime({debug: {chatCompletion: () => process.env.DEBUG_OPENCODE_GO_CHAT_COMPLETION === '1',},+ generateObject: {+ get useResponseModels() {+ return [...getResponsesModelIds()];+ },+ },});// Anthropic SDK auto-appends /v1/messages to baseURL, so strip trailing /v1