Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(model): preserve reasoning effort through Chat translation

Chrisa29518d9cbfc
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
index a98e8389b3..a89ab59bae 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codexProxyHost.test.ts
@@ -711,6 +711,7 @@ describe('chatBridgeCapabilitiesForRoute', () => {
'https://api.deepseek.com/v1',
'deepseek-chat',
);
+ expect(capabilities.reasoningField).toBeUndefined();
expect(capabilities.passthroughFields).not.toContain('n');
expect(capabilities.passthroughFields).not.toContain('logprobs');
expect(capabilities.passthroughFields).not.toContain('top_logprobs');
diff --git a/apps/desktop/src/main/maker-host/codex-proxy-host.ts b/apps/desktop/src/main/maker-host/codex-proxy-host.ts
index 6c8520cd9b..485f2a67aa 100644
--- a/apps/desktop/src/main/maker-host/codex-proxy-host.ts
+++ b/apps/desktop/src/main/maker-host/codex-proxy-host.ts
@@ -854,7 +854,7 @@ const CHAT_BRIDGE_DEFAULT_CAPABILITIES: ChatBridgeCapabilities = {
developerRole: 'system',
parallelToolCalls: true,
maxTokensField: 'max_tokens',
- reasoningField: 'none',
+ // Leave reasoning undeclared so provider policy can fill it; translator defaults to none.
streamUsage: true,
// Responses fields with direct Chat equivalents. Provider-specific unsupported fields can
// be removed later when the model capability catalog becomes more granular.
diff --git a/packages/model-compat/src/chat.ts b/packages/model-compat/src/chat.ts
index 2125cd16e4..0acdf9d54c 100644
--- a/packages/model-compat/src/chat.ts
+++ b/packages/model-compat/src/chat.ts
@@ -1,5 +1,5 @@
import type { ChatBridgeCapabilities } from './cindy/types';
-import { resolveProviderCompatibilityProfile, profileModelListed, type CompatibilityRoute } from './profiles';
+import { resolveProviderCompatibilityProfile, profileModelListed, profileModelValue, type CompatibilityRoute } from './profiles';
/** Convert upstream declarations into the existing bridge's serializer capabilities.
* Cindy's explicit route capabilities stay authoritative; upstream declarations fill gaps.
@@ -9,6 +9,15 @@ export function chatCompatibilityCapabilities(route: CompatibilityRoute, existin
const profile = resolveProviderCompatibilityProfile(route);
if (!profile) return existing;
const baseline: ChatBridgeCapabilities = {};
+ const hasEffortPolicy = profileModelValue(profile.modelReasoningEffortMap, route.model) !== undefined
+ || profile.reasoningEffortMap !== undefined
+ || profileModelListed(profile.thinkingToggleModels, route.model)
+ || profileModelListed(profile.thinkingBudgetModels, route.model)
+ || profile.reasoningWireFormat === 'gateway-object';
+ // Carry the original choice through translation; map it once at the final wire stage.
+ if (hasEffortPolicy && !profileModelListed(profile.noReasoningModels, route.model)) {
+ baseline.reasoningField = 'reasoning_effort';
+ }
if (typeof profile.parallelToolCalls === 'boolean') baseline.parallelToolCalls = profile.parallelToolCalls;
if (profileModelListed(profile.preserveReasoningContentModels, route.model)) baseline.reasoningHistoryField = 'reasoning_content';
if (profileModelListed(profile.requiresReasoningPlaceholderModels ?? profile.preserveReasoningContentModels, route.model)) baseline.toolCallReasoningPlaceholder = true;
diff --git a/packages/responses-chat-bridge/src/__tests__/handler.test.ts b/packages/responses-chat-bridge/src/__tests__/handler.test.ts
index 39518b1d76..ff8f2c2fc9 100644
--- a/packages/responses-chat-bridge/src/__tests__/handler.test.ts
+++ b/packages/responses-chat-bridge/src/__tests__/handler.test.ts
@@ -93,6 +93,44 @@ describe('createResponsesChatHandler', () => {
},
);
+ it.each([
+ { upstreamBase: 'https://api.minimax.io/v1', model: 'MiniMax-M3', effort: 'high', expected: { thinking: { type: 'adaptive' } } },
+ { upstreamBase: 'https://api.minimax.io/v1', model: 'MiniMax-M3', effort: 'none', expected: { thinking: { type: 'disabled' } } },
+ { upstreamBase: 'https://ark.cn-beijing.volces.com/api/v3', model: 'doubao-seed-2-1-pro-260628', effort: 'high', expected: { thinking: { type: 'enabled' } } },
+ { upstreamBase: 'https://api.neuralwatt.com/v1', model: 'qwen3.5-397b', effort: 'high', expected: { thinking_budget: 24576 } },
+ ])('retains $model reasoning until final provider normalization ($effort)', async ({ upstreamBase, model, effort, expected }) => {
+ const fetchImpl = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {
+ const body = JSON.parse(String(init?.body));
+ expect(body).toMatchObject(expected);
+ expect(body).not.toHaveProperty('reasoning_effort');
+ return streamResponse([{ choices: [{ delta: {}, finish_reason: 'stop' }] }]);
+ });
+ const handler = createResponsesChatHandler({ upstreamBase, buildHeaders: async () => ({}), capabilities: { developerRole: 'system' } }, { fetchImpl });
+ const res = new FakeResponse();
+ await handler.handle({ parsedBody: { model, input: 'hello', reasoning: { effort } }, res: res as never });
+ expect(fetchImpl).toHaveBeenCalledOnce();
+ expect(res.status).toBe(200);
+ });
+
+ it.each([
+ { upstreamBase: 'https://api.minimax.io/v1', model: 'MiniMax-M3', capabilities: { reasoningField: 'none' } as ChatBridgeCapabilities },
+ { upstreamBase: 'https://unrelated.example/v1', model: 'MiniMax-M3', capabilities: {} },
+ { upstreamBase: 'https://api.kimi.com/coding/v1', model: 'k3', capabilities: {} },
+ ])('respects explicit disable, unknown endpoints and declared noReasoning: $upstreamBase', async ({ upstreamBase, model, capabilities }) => {
+ const fetchImpl = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {
+ const body = JSON.parse(String(init?.body));
+ expect(body).not.toHaveProperty('reasoning_effort');
+ expect(body).not.toHaveProperty('thinking');
+ expect(body).not.toHaveProperty('thinking_budget');
+ return streamResponse([{ choices: [{ delta: {}, finish_reason: 'stop' }] }]);
+ });
+ const handler = createResponsesChatHandler({ upstreamBase, buildHeaders: async () => ({}), capabilities }, { fetchImpl });
+ const res = new FakeResponse();
+ await handler.handle({ parsedBody: { model, input: 'hello', reasoning: { effort: 'high' } }, res: res as never });
+ expect(fetchImpl).toHaveBeenCalledOnce();
+ expect(res.status).toBe(200);
+ });
+
it('leaves a consecutive system prefix intact when the upstream accepts it', async () => {
const fetchImpl = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {
expect(JSON.parse(String(init?.body)).messages).toEqual([