Skip to content

🀯 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.

✨ feat(opencode-go): align model configs with models.dev API, add DeepSeek V4 Flash/Pro, improve reasoning runtime (#15031)

Hardy5fb1f339a7f6
diff --git a/packages/model-bank/src/aiModels/opencodeCodingPlan.ts b/packages/model-bank/src/aiModels/opencodeCodingPlan.ts
index 16f569e4dfe..def3c499ba0 100644
--- a/packages/model-bank/src/aiModels/opencodeCodingPlan.ts
+++ b/packages/model-bank/src/aiModels/opencodeCodingPlan.ts
@@ -6,42 +6,50 @@ import { type AIChatModelCard } from '../types/aiModel';
const opencodeCodingPlanChatModels: AIChatModelCard[] = [
{
abilities: { functionCall: true, reasoning: true },
- contextWindowTokens: 204_800,
+ contextWindowTokens: 202_752,
description:
- 'GLM-5.1 by Zhipu AI β€” latest generation coding model with enhanced reasoning and tool use capabilities.',
- displayName: 'GLM-5.1',
- enabled: true,
- id: 'glm-5.1',
- maxOutput: 32_000,
+ 'GLM-5 by Zhipu AI β€” high-performance coding model with strong reasoning abilities.',
+ displayName: 'GLM-5',
+ enabled: false,
+ id: 'glm-5',
+ maxOutput: 32_768,
organization: 'Zhipu',
pricing: {
currency: 'USD',
units: [
- { name: 'textInput', rate: 1.4, strategy: 'fixed', unit: 'millionTokens' },
- { name: 'textOutput', rate: 4.4, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput', rate: 1, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 3.2, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.2, strategy: 'fixed', unit: 'millionTokens' },
],
},
- releasedAt: '2026-04-07',
+ releasedAt: '2026-02-11',
+ settings: {
+ extendParams: ['reasoningEffort'],
+ },
type: 'chat',
},
{
abilities: { functionCall: true, reasoning: true },
- contextWindowTokens: 204_800,
+ contextWindowTokens: 202_752,
description:
- 'GLM-5 by Zhipu AI β€” high-performance coding model with strong reasoning abilities.',
- displayName: 'GLM-5',
- enabled: false,
- id: 'glm-5',
- maxOutput: 32_000,
+ 'GLM-5.1 by Zhipu AI β€” latest generation coding model with enhanced reasoning and tool use capabilities.',
+ displayName: 'GLM-5.1',
+ enabled: true,
+ id: 'glm-5.1',
+ maxOutput: 32_768,
organization: 'Zhipu',
pricing: {
currency: 'USD',
units: [
- { name: 'textInput', rate: 1, strategy: 'fixed', unit: 'millionTokens' },
- { name: 'textOutput', rate: 3.2, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput', rate: 1.4, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 4.4, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.26, strategy: 'fixed', unit: 'millionTokens' },
],
},
- releasedAt: '2026-02-11',
+ releasedAt: '2026-04-07',
+ settings: {
+ extendParams: ['reasoningEffort'],
+ },
type: 'chat',
},
{
@@ -52,59 +60,137 @@ const opencodeCodingPlanChatModels: AIChatModelCard[] = [
displayName: 'Kimi K2.5',
enabled: false,
id: 'kimi-k2.5',
- maxOutput: 32_000,
+ maxOutput: 65_536,
organization: 'Moonshot',
pricing: {
currency: 'USD',
units: [
{ name: 'textInput', rate: 0.6, strategy: 'fixed', unit: 'millionTokens' },
{ name: 'textOutput', rate: 3, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.1, strategy: 'fixed', unit: 'millionTokens' },
],
},
releasedAt: '2026-01-27',
+ settings: {
+ extendParams: ['reasoningEffort'],
+ },
type: 'chat',
},
{
abilities: { functionCall: true, reasoning: true, vision: true },
contextWindowTokens: 262_144,
description:
- 'MiMo-V2-Omni by Xiaomi β€” multimodal model supporting text, image, audio, and PDF input.',
- displayName: 'MiMo-V2 Omni',
+ "Kimi K2.6 is Moonshot AI's latest flagship model, delivering significant improvements in coding, agentic tasks, and multimodal understanding. It supports both 'thinking' and 'non-thinking' modes.",
+ displayName: 'Kimi K2.6',
+ enabled: true,
+ id: 'kimi-k2.6',
+ maxOutput: 65_536,
+ organization: 'Moonshot',
+ pricing: {
+ currency: 'USD',
+ units: [
+ { name: 'textInput', rate: 0.95, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 4, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.16, strategy: 'fixed', unit: 'millionTokens' },
+ ],
+ },
+ releasedAt: '2026-04-21',
+ settings: {
+ extendParams: ['reasoningEffort'],
+ },
+ type: 'chat',
+ },
+ {
+ abilities: { functionCall: true, reasoning: true, vision: true },
+ contextWindowTokens: 1_000_000,
+ description:
+ 'MiMo-V2.5 by Xiaomi β€” a leap in agency and multimodality. Native visual and audio understanding with strong agentic performance.',
+ displayName: 'MiMo-V2.5',
enabled: false,
- id: 'mimo-v2-omni',
- maxOutput: 32_000,
+ id: 'mimo-v2.5',
+ maxOutput: 128_000,
organization: 'Xiaomi',
pricing: {
currency: 'USD',
units: [
- { name: 'textInput', rate: 0.4, strategy: 'fixed', unit: 'millionTokens' },
- { name: 'textOutput', rate: 2, strategy: 'fixed', unit: 'millionTokens' },
+ {
+ name: 'textInput',
+ strategy: 'tiered',
+ tiers: [
+ { rate: 0.4, upTo: 256_000 },
+ { rate: 0.8, upTo: 'infinity' },
+ ],
+ unit: 'millionTokens',
+ },
+ {
+ name: 'textOutput',
+ strategy: 'tiered',
+ tiers: [
+ { rate: 2, upTo: 256_000 },
+ { rate: 4, upTo: 'infinity' },
+ ],
+ unit: 'millionTokens',
+ },
+ {
+ name: 'textInput_cacheRead',
+ strategy: 'tiered',
+ tiers: [
+ { rate: 0.08, upTo: 256_000 },
+ { rate: 0.16, upTo: 'infinity' },
+ ],
+ unit: 'millionTokens',
+ },
],
},
- releasedAt: '2026-03-18',
+ releasedAt: '2026-04-22',
settings: {
extendParams: ['reasoningEffort'],
},
type: 'chat',
},
{
- abilities: { functionCall: true, reasoning: true, vision: true },
- contextWindowTokens: 262_144,
+ abilities: { functionCall: true, reasoning: true },
+ contextWindowTokens: 1_048_576,
description:
- 'Qwen3.6-Plus by Alibaba β€” latest Qwen coding model with strong reasoning and vision capabilities.',
- displayName: 'Qwen3.6 Plus',
- enabled: true,
- id: 'qwen3.6-plus',
- maxOutput: 32_000,
- organization: 'Alibaba',
+ 'MiMo-V2.5-Pro by Xiaomi β€” a leap in agentic and long horizon coherence. Significant improvements in agentic performance, software engineering, and tasks spanning 1000+ tool calls.',
+ displayName: 'MiMo-V2.5 Pro',
+ enabled: false,
+ id: 'mimo-v2.5-pro',
+ maxOutput: 128_000,
+ organization: 'Xiaomi',
pricing: {
currency: 'USD',
units: [
- { name: 'textInput', rate: 0.5, strategy: 'fixed', unit: 'millionTokens' },
- { name: 'textOutput', rate: 3, strategy: 'fixed', unit: 'millionTokens' },
+ {
+ name: 'textInput',
+ strategy: 'tiered',
+ tiers: [
+ { rate: 1, upTo: 256_000 },
+ { rate: 2, upTo: 'infinity' },
+ ],
+ unit: 'millionTokens',
+ },
+ {
+ name: 'textOutput',
+ strategy: 'tiered',
+ tiers: [
+ { rate: 3, upTo: 256_000 },
+ { rate: 6, upTo: 'infinity' },
+ ],
+ unit: 'millionTokens',
+ },
+ {
+ name: 'textInput_cacheRead',
+ strategy: 'tiered',
+ tiers: [
+ { rate: 0.2, upTo: 256_000 },
+ { rate: 0.4, upTo: 'infinity' },
+ ],
+ unit: 'millionTokens',
+ },
],
},
- releasedAt: '2026-04-02',
+ releasedAt: '2026-04-22',
settings: {
extendParams: ['reasoningEffort'],
},
@@ -118,16 +204,20 @@ const opencodeCodingPlanChatModels: AIChatModelCard[] = [
displayName: 'MiniMax M2.5',
enabled: false,
id: 'minimax-m2.5',
- maxOutput: 32_000,
+ maxOutput: 65_536,
organization: 'MiniMax',
pricing: {
currency: 'USD',
units: [
{ name: 'textInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },
{ name: 'textOutput', rate: 1.2, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.03, strategy: 'fixed', unit: 'millionTokens' },
],
},
releasedAt: '2026-02-12',
+ settings: {
+ extendParams: ['reasoningBudgetToken32k'],
+ },
type: 'chat',
},
{
@@ -135,37 +225,44 @@ const opencodeCodingPlanChatModels: AIChatModelCard[] = [
contextWindowTokens: 204_800,
description: 'MiniMax M2.7 β€” latest MiniMax coding model with improved reasoning and tool use.',
displayName: 'MiniMax M2.7',
- enabled: true,
+ enabled: false,
id: 'minimax-m2.7',
- maxOutput: 32_000,
+ maxOutput: 131_072,
organization: 'MiniMax',
pricing: {
currency: 'USD',
units: [
{ name: 'textInput', rate: 0.3, strategy: 'fixed', unit: 'millionTokens' },
{ name: 'textOutput', rate: 1.2, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.06, strategy: 'fixed', unit: 'millionTokens' },
],
},
releasedAt: '2026-03-18',
+ settings: {
+ extendParams: ['reasoningBudgetToken32k'],
+ },
type: 'chat',
},
{
- abilities: { functionCall: true, reasoning: true },
- contextWindowTokens: 1_048_576,
- description: 'MiMo-V2-Pro by Xiaomi β€” high-throughput model with 1M token context window.',
- displayName: 'MiMo-V2 Pro',
+ abilities: { functionCall: true, reasoning: true, vision: true },
+ contextWindowTokens: 262_144,
+ description:
+ 'Qwen3.5-Plus by Alibaba β€” cost-effective coding model with vision support for image and video input.',
+ displayName: 'Qwen3.5 Plus',
enabled: false,
- id: 'mimo-v2-pro',
- maxOutput: 32_000,
- organization: 'Xiaomi',
+ id: 'qwen3.5-plus',
+ maxOutput: 65_536,
+ organization: 'Alibaba',
pricing: {
currency: 'USD',
units: [
- { name: 'textInput', rate: 1, strategy: 'fixed', unit: 'millionTokens' },
- { name: 'textOutput', rate: 3, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput', rate: 0.2, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 1.2, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.02, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheWrite', rate: 0.25, strategy: 'fixed', unit: 'millionTokens' },
],
},
- releasedAt: '2026-03-18',
+ releasedAt: '2026-02-16',
settings: {
extendParams: ['reasoningEffort'],
},
@@ -175,25 +272,99 @@ const opencodeCodingPlanChatModels: AIChatModelCard[] = [
abilities: { functionCall: true, reasoning: true, vision: true },
contextWindowTokens: 262_144,
description:
- 'Qwen3.5-Plus by Alibaba β€” cost-effective coding model with vision support for image and video input.',
- displayName: 'Qwen3.5 Plus',
+ 'Qwen3.6-Plus by Alibaba β€” latest Qwen coding model with strong reasoning and vision capabilities.',
+ displayName: 'Qwen3.6 Plus',
enabled: false,
- id: 'qwen3.5-plus',
- maxOutput: 32_000,
+ id: 'qwen3.6-plus',
+ maxOutput: 65_536,
organization: 'Alibaba',
pricing: {
currency: 'USD',
units: [
- { name: 'textInput', rate: 0.2, strategy: 'fixed', unit: 'millionTokens' },
- { name: 'textOutput', rate: 1.2, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput', rate: 0.5, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 3, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.05, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheWrite', rate: 0.625, strategy: 'fixed', unit: 'millionTokens' },
],
},
- releasedAt: '2026-02-16',
+ releasedAt: '2026-04-02',
+ settings: {
+ extendParams: ['reasoningEffort'],
+ },
+ type: 'chat',
+ },
+ {
+ abilities: { functionCall: true, reasoning: true },
+ contextWindowTokens: 1_000_000,
+ description: 'Qwen3.7 Max by Alibaba β€” latest Max variant with 1M context, strong reasoning, and tool use capabilities.',
+ displayName: 'Qwen3.7 Max',
+ enabled: true,
+ id: 'qwen3.7-max',
+ maxOutput: 65_536,
+ organization: 'Alibaba',
+ pricing: {
+ currency: 'USD',
+ units: [
+ { name: 'textInput', rate: 2.5, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 7.5, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.5, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheWrite', rate: 3.125, strategy: 'fixed', unit: 'millionTokens' },
+ ],
+ },
+ releasedAt: '2026-05-21',
settings: {
extendParams: ['reasoningEffort'],
},
type: 'chat',
},
+ {
+ abilities: { functionCall: true, reasoning: true, structuredOutput: true },
+ contextWindowTokens: 1_000_000,
+ description:
+ "DeepSeek V4 Pro is DeepSeek's most capable 1M-context flagship model, supporting both non-thinking and thinking modes for advanced reasoning and tool use.",
+ displayName: 'DeepSeek V4 Pro',
+ enabled: true,
+ id: 'deepseek-v4-pro',
+ maxOutput: 384_000,
+ organization: 'DeepSeek',
+ pricing: {
+ currency: 'USD',
+ units: [
+ { name: 'textInput', rate: 1.74, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 3.48, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.0145, strategy: 'fixed', unit: 'millionTokens' },
+ ],
+ },
+ releasedAt: '2026-04-24',
+ settings: {
+ extendParams: ['deepseekV4ReasoningEffort'],
+ },
+ type: 'chat',
+ },
+ {
+ abilities: { functionCall: true, reasoning: true, structuredOutput: true },
+ contextWindowTokens: 1_000_000,
+ description:
+ "DeepSeek V4 Flash is DeepSeek's fast 1M-context flagship model, supporting both non-thinking and thinking modes with strong agent capabilities.",
+ displayName: 'DeepSeek V4 Flash',
+ enabled: true,
+ id: 'deepseek-v4-flash',
+ maxOutput: 384_000,
+ organization: 'DeepSeek',
+ pricing: {
+ currency: 'USD',
+ units: [
+ { name: 'textInput', rate: 0.14, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textOutput', rate: 0.28, strategy: 'fixed', unit: 'millionTokens' },
+ { name: 'textInput_cacheRead', rate: 0.0028, strategy: 'fixed', unit: 'millionTokens' },
+ ],
+ },
+ releasedAt: '2026-04-24',
+ settings: {
+ extendParams: ['deepseekV4ReasoningEffort'],
+ },
+ type: 'chat',
+ },
];
export default opencodeCodingPlanChatModels;
diff --git a/packages/model-bank/src/modelProviders/opencodeCodingPlan.ts b/packages/model-bank/src/modelProviders/opencodeCodingPlan.ts
index e17f808d74b..ff7180ac70c 100644
--- a/packages/model-bank/src/modelProviders/opencodeCodingPlan.ts
+++ b/packages/model-bank/src/modelProviders/opencodeCodingPlan.ts
@@ -8,7 +8,7 @@ const OpenCodeCodingPlan: ModelProviderCard = {
'OpenCode Go is a $10/month subscription providing reliable access to curated open coding models: GLM, Kimi, MiMo, Qwen, MiniMax.',
disableBrowserRequest: true,
id: 'opencodecodingplan',
- modelList: { showModelFetcher: false },
+ modelList: { showModelFetcher: true },
modelsUrl: 'https://opencode.ai/go',
name: 'OpenCode Go',
settings: {
@@ -17,7 +17,7 @@ const OpenCodeCodingPlan: ModelProviderCard = {
placeholder: 'https://opencode.ai/zen/go/v1',
},
sdkType: 'openai',
- showModelFetcher: false,
+ showModelFetcher: true,
},
url: 'https://opencode.ai/go',
};
diff --git a/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.ts b/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.ts
new file mode 100644
index 00000000000..2eae4f4541d
--- /dev/null
+++ b/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.ts
@@ -0,0 +1,140 @@
+// @vitest-environment node
+import { ModelProvider } from 'model-bank';
+import { describe, expect, it } from 'vitest';
+
+import { LobeOpenCodeCodingPlanAI, sanitizeJsonSchema } from './index';
+
+const provider = ModelProvider.OpenCodeCodingPlan;
+const defaultBaseURL = 'https://opencode.ai/zen/go/v1';
+
+describe('LobeOpenCodeCodingPlanAI', () => {
+ describe('init', () => {
+ it('should correctly initialize with an API key', () => {
+ const instance = new LobeOpenCodeCodingPlanAI({ apiKey: 'test_api_key' });
+ expect(instance).toBeInstanceOf(LobeOpenCodeCodingPlanAI);
+ });
+ });
+});
+
+describe('sanitizeJsonSchema', () => {
+ it('should return non-object values as-is', () => {
+ expect(sanitizeJsonSchema(null)).toBeNull();
+ expect(sanitizeJsonSchema(undefined)).toBeUndefined();
+ expect(sanitizeJsonSchema('string')).toBe('string');
+ expect(sanitizeJsonSchema(42)).toBe(42);
+ });
+
+ it('should remove null from enum arrays', () => {
+ const schema = {
+ type: 'string',
+ enum: ['heartbeat', 'schedule', null],
+ };
+ const result = sanitizeJsonSchema(schema);
+ expect(result.enum).toEqual(['heartbeat', 'schedule']);
+ });
+
+ it('should simplify type: ["string", "null"] to type: "string"', () => {
+ const schema = {
+ type: ['string', 'null'],
+ enum: ['heartbeat', 'schedule', null],
+ };
+ const result = sanitizeJsonSchema(schema);
+ expect(result.type).toBe('string');
+ expect(result.enum).toEqual(['heartbeat', 'schedule']);
+ });
+
+ it('should keep type: ["string", "number"] as array (no null)', () => {
+ const schema = { type: ['string', 'number'] };
+ expect(sanitizeJsonSchema(schema).type).toEqual(['string', 'number']);
+ });
+
+ it('should drop enum key if all values are null', () => {
+ const schema = { type: 'string', enum: [null, null] };
+ const result = sanitizeJsonSchema(schema);
+ expect(result.enum).toBeUndefined();
+ });
+
+ it('should recurse into properties', () => {
+ const schema = {
+ type: 'object',
+ properties: {
+ action: {
+ type: ['string', 'null'],
+ enum: ['create', 'refine', 'consolidate', null],
+ },
+ name: { type: 'string' },
+ },
+ };
+ const result = sanitizeJsonSchema(schema);
+ expect(result.properties.action.enum).toEqual(['create', 'refine', 'consolidate']);
+ expect(result.properties.action.type).toBe('string');
+ expect(result.properties.name).toEqual({ type: 'string' });
+ });
+
+ it('should recurse into allOf/anyOf/oneOf', () => {
+ const schema = {
+ allOf: [
+ { type: 'object', properties: { x: { enum: ['a', null] } } },
+ { type: 'object', properties: { y: { enum: ['b', null] } } },
+ ],
+ anyOf: [
+ { enum: ['c', null] },
+ { type: ['string', 'null'] },
+ ],
+ };
+ const result = sanitizeJsonSchema(schema);
+ expect(result.allOf[0].properties.x.enum).toEqual(['a']);
+ expect(result.allOf[1].properties.y.enum).toEqual(['b']);
+ expect(result.anyOf[0].enum).toEqual(['c']);
+ expect(result.anyOf[1].type).toBe('string');
+ });
+
+ it('should recurse into items and prefixItems', () => {
+ const schema = {
+ type: 'array',
+ items: {
+ type: 'object',
+ properties: { tag: { enum: ['alpha', 'beta', null] } },
+ },
+ prefixItems: [
+ { enum: ['x', null] },
+ { enum: ['y', null] },
+ ],
+ };
+ const result = sanitizeJsonSchema(schema);
+ expect(result.items.properties.tag.enum).toEqual(['alpha', 'beta']);
+ expect(result.prefixItems[0].enum).toEqual(['x']);
+ expect(result.prefixItems[1].enum).toEqual(['y']);
+ });
+
+ it('should handle deeply nested schemas with $defs and if/then/else', () => {
+ const schema = {
+ $defs: {
+ Foo: {
+ type: 'object',
+ properties: { status: { enum: ['ok', 'error', null] } },
+ },
+ },
+ if: { properties: { x: { enum: ['a', null] } } },
+ then: { properties: { y: { type: ['string', 'null'] } } },
+ else: { properties: { z: { enum: ['b', null] } } },
+ };
+ const result = sanitizeJsonSchema(schema);
+ expect(result.$defs.Foo.properties.status.enum).toEqual(['ok', 'error']);
+ expect(result.if.properties.x.enum).toEqual(['a']);
+ expect(result.then.properties.y.type).toBe('string');
+ expect(result.else.properties.z.enum).toEqual(['b']);
+ });
+
+ it('should handle schemas without nullable enums (no-op)', () => {
+ const schema = {
+ type: 'object',
+ properties: {
+ name: { type: 'string' },
+ count: { type: 'integer' },
+ tags: { type: 'array', items: { type: 'string' } },
+ },
+ };
+ expect(sanitizeJsonSchema(schema)).toEqual(schema);
+ });
+});
diff --git a/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts b/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts
index efb04fa95c4..a78a2b5bf61 100644
--- a/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts
+++ b/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts
@@ -1,18 +1,207 @@
import { ModelProvider } from 'model-bank';
+import type OpenAI from 'openai';
+import { createOpenAICompatibleRuntime } from '../../core/openaiCompatibleFactory';
import { createRouterRuntime } from '../../core/RouterRuntime';
import type { CreateRouterRuntimeOptions } from '../../core/RouterRuntime/createRuntime';
+import type { ChatStreamPayload } from '../../types';
import { processMultiProviderModelList } from '../../utils/modelParse';
const GO_BASE_URL = 'https://opencode.ai/zen/go/v1';
-// MiniMax models in Go use @ai-sdk/anthropic (Anthropic Messages API format)
+// MiniMax and Qwen models in Go use @ai-sdk/anthropic (Anthropic Messages API format)
// Endpoint: /go/v1/messages
-const minimaxModels = ['minimax-m2.5', 'minimax-m2.7'];
+const anthropicModels = ['minimax-m2.5', 'minimax-m2.7', 'qwen3.5-plus', 'qwen3.6-plus', 'qwen3.7-max'];
-// Qwen models in Go use @ai-sdk/alibaba which is not in our apiTypes.
-// They fall through to openai-compatible. The Gateway handles format conversion.
-// All other models (GLM, Kimi, MiMo) use @ai-sdk/openai-compatible.
+// Moonshot Kimi thinking toggle models (kimi-k2.N) expose reasoning on the
+// OpenAI-compatible route. Matches the official Moonshot provider's prefix logic.
+const isKimiThinkingToggleModel = (model: string) => model.startsWith('kimi-k2.');
+
+// Models with interleaved reasoning_content (from models.dev opencode-go)
+// that use openai-compatible SDK. All of these need:
+// 1. reason β†’ reasoning_content conversion
+// 2. reasoning_content forced on all assistant messages (fill '' if missing)
+// Ref: https://models.dev/api.json β†’ opencode-go
+const reasoningInterleavedModels = [
+ 'glm-5',
+ 'glm-5.1',
+ 'mimo-v2.5',
+ 'mimo-v2.5-pro',
+ 'mimo-v2-omni',
+ 'mimo-v2-pro',
+ 'qwen3.7-max',
+ 'deepseek-v4-pro',
+ 'deepseek-v4-flash',
+];
+
+const hasValidReasoning = (reasoning: any) =>
+ typeof reasoning?.content === 'string';
+
+const isEmptyContent = (content: any) =>
+ content === '' || content === null || content === undefined;
+
+/**
+ * Recursively remove `null` values from `enum` arrays in a JSON Schema.
+ * The opencode-go backend ("could not translate the enum None") rejects
+ * nullable enums produced by Zod schema `.nullable()` / `.nullish()`.
+ */
+export const sanitizeJsonSchema = (schema: any): any => {
+ if (!schema || typeof schema !== 'object') return schema;
+ if (Array.isArray(schema)) return schema.map(sanitizeJsonSchema);
+
+ const result: any = {};
+ for (const [key, value] of Object.entries(schema)) {
+ if (key === 'enum' && Array.isArray(value)) {
+ const filtered = value.filter((v: any) => v !== null);
+ if (filtered.length > 0) result[key] = filtered;
+ continue;
+ }
+ // For `type: ['string', 'null']` β†’ just `type: 'string'`
+ if (key === 'type' && Array.isArray(value) && value.includes('null') && value.length >= 2) {
+ const nonNullTypes = value.filter((v: any) => v !== 'null' && v !== null);
+ if (nonNullTypes.length === 1) result.type = nonNullTypes[0];
+ else if (nonNullTypes.length > 1) result.type = nonNullTypes;
+ continue;
+ }
+ // Recurse into schema traversals:
+ // properties, additionalProperties, items, prefixItems
+ // allOf, anyOf, oneOf, not
+ // if/then/else
+ // $defs, definitions
+ // contains, unevaluatedItems, unevaluatedProperties
+ if (key === 'properties' || key === '$defs' || key === 'definitions') {
+ const nested: any = {};
+ for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
+ nested[k] = sanitizeJsonSchema(v);
+ }
+ result[key] = nested;
+ } else if (
+ ['allOf', 'anyOf', 'oneOf', 'prefixItems'].includes(key) &&
+ Array.isArray(value)
+ ) {
+ result[key] = value.map(sanitizeJsonSchema);
+ } else if (
+ ['items', 'additionalProperties', 'not', 'contains', 'if', 'then', 'else',
+ 'unevaluatedItems', 'unevaluatedProperties']
+ .includes(key)
+ ) {
+ result[key] = sanitizeJsonSchema(value);
+ } else {
+ result[key] = sanitizeJsonSchema(value);
+ }
+ }
+ return result;
+};
+
+/**
+ * Build OpenAI-compatible payload with reasoning_content handling.
+ *
+ * Applies to all models with interleaved reasoning_content (models.dev opencode-go):
+ * GLM-5/5.1, MiMo-V2.5/Pro, MiMo-V2-Omni/Pro, DeepSeek V4 Flash/Pro, Kimi K2.5/K2.6
+ *
+ * All of these get reason β†’ reasoning_content conversion AND forced
+ * reasoning_content on assistant messages when thinking is not explicitly disabled.
+ */
+const buildOpenAIPayload = (
+ payload: ChatStreamPayload,
+): OpenAI.ChatCompletionCreateParamsStreaming => {
+ const model = payload.model;
+ const isKimi = isKimiThinkingToggleModel(model);
+ const isInterleavedModel = reasoningInterleavedModels.some((m) => model?.includes(m));
+ if (!isKimi && !isInterleavedModel) return payload as any;
+
+ const thinkingExplicitlyDisabled = (payload as any).thinking?.type === 'disabled';
+ const shouldForceAssistantReasoningContent =
+ (isInterleavedModel || isKimi) && !thinkingExplicitlyDisabled;
+
+ const messages = payload.messages.map((message: any) => {
+ const { reasoning, ...rest } = message;
+
+ // Normalize empty content to space for Kimi (matching Moonshot provider)
+ const normalized = isKimi && isEmptyContent(message.content) ? { ...rest, content: ' ' } : rest;
+
+ const reasoningContent =
+ typeof normalized.reasoning_content === 'string'
+ ? normalized.reasoning_content
+ : hasValidReasoning(reasoning)
+ ? reasoning.content
+ : undefined;
+
+ if (message.role === 'assistant' && shouldForceAssistantReasoningContent) {
+ return {
+ ...normalized,
+ reasoning_content: reasoningContent ?? ' ',
+ };
+ }
+
+ if (reasoningContent !== undefined) {
+ return {
+ ...normalized,
+ reasoning_content: reasoningContent,
+ };
+ }
+
+ return normalized;
+ });
+
+ const { reasoning_effort, thinking, ...restPayload } = payload;
+
+ // Sanitize response_format schema for Kimi models only (opencode-go backend
+ // rejects nullable Zod enums from Kimi K2.5/K2.6 with "could not translate the enum None").
+ const response_format =
+ isKimi &&
+ restPayload.response_format &&
+ 'json_schema' in restPayload.response_format &&
+ restPayload.response_format.json_schema?.schema
+ ? {
+ ...restPayload.response_format,
+ json_schema: {
+ ...restPayload.response_format.json_schema,
+ schema: sanitizeJsonSchema(restPayload.response_format.json_schema.schema),
+ },
+ }
+ : restPayload.response_format;
+
+ // Sanitize tool parameters schemas for Kimi models only
+ const tools =
+ isKimi && restPayload.tools
+ ? restPayload.tools.map((tool: any) => ({
+ ...tool,
+ function: {
+ ...tool.function,
+ parameters: tool.function?.parameters
+ ? sanitizeJsonSchema(tool.function.parameters)
+ : tool.function?.parameters,
+ },
+ }))
+ : restPayload.tools;
+
+ return {
+ ...restPayload,
+ messages,
+ response_format,
+ tools,
+ ...(!thinkingExplicitlyDisabled && reasoning_effort ? { reasoning_effort } : {}),
+ ...(thinking?.type === 'enabled' || thinking?.type === 'disabled'
+ ? { thinking: { type: thinking.type } }
+ : {}),
+ stream: payload.stream ?? true,
+ } as OpenAI.ChatCompletionCreateParamsStreaming;
+};
+
+// Dedicated OpenAI-compatible runtime with buildOpenAIPayload baked into the
+// factory closure. RouterRuntime creates instances of this class for all
+// non-MiniMax models, ensuring reasoning_content is properly set on messages.
+const LobeOpenCodeCodingPlanOpenAI = createOpenAICompatibleRuntime({
+ provider: ModelProvider.OpenCodeCodingPlan,
+ baseURL: GO_BASE_URL,
+ chatCompletion: {
+ handlePayload: buildOpenAIPayload,
+ },
+ debug: {
+ chatCompletion: () => process.env.DEBUG_OPENCODE_GO_CHAT_COMPLETION === '1',
+ },
+});
// Anthropic SDK auto-appends /v1/messages to baseURL, so we need to strip trailing /v1
const stripV1 = (url?: string) => url?.replace(/\/v1$/, '');
@@ -22,28 +211,35 @@ export const params = {
chatCompletion: () => process.env.DEBUG_OPENCODE_GO_CHAT_COMPLETION === '1',
},
id: ModelProvider.OpenCodeCodingPlan,
- models: async () => {
- const { opencodecodingplan } = await import('model-bank');
- return processMultiProviderModelList(
- opencodecodingplan.map((m: { id: string }) => ({ id: m.id })),
- 'opencodecodingplan',
- );
+ models: async ({ client }) => {
+ try {
+ const modelsPage = await (client as any).models.list();
+ const modelList = modelsPage.data || [];
+ return processMultiProviderModelList(modelList, 'opencodecodingplan');
+ } catch {
+ const { opencodecodingplan } = await import('model-bank');
+ return processMultiProviderModelList(
+ opencodecodingplan.map((m: { id: string }) => ({ id: m.id })),
+ 'opencodecodingplan',
+ );
+ }
},
routers: (options) => {
const baseURL = options.baseURL || GO_BASE_URL;
return [
- // Anthropic router for MiniMax models (use Anthropic Messages API format)
+ // Anthropic router for MiniMax & Qwen models (use Anthropic Messages API format)
{
apiType: 'anthropic',
- models: minimaxModels,
+ models: anthropicModels,
options: {
...options,
baseURL: stripV1(baseURL),
},
},
- // OpenAI-compatible fallback for all other models (GLM, Kimi, MiMo, Qwen)
+ // OpenAI-compatible fallback for all other models (GLM, Kimi, MiMo, Qwen, DeepSeek)
{
apiType: 'openai',
+ runtime: LobeOpenCodeCodingPlanOpenAI as any,
options: {
...options,
baseURL,