fix(sse): keep the reasoning_content echo off DeepSeek's Claude alternate

The placeholder is an OpenAI-chat field. A DeepSeek connection on the
Anthropic-compatible alternate sends Claude messages, where thinking is
carried as content blocks, so skip the injection when the target format
is claude.
This commit is contained in:
Rafa Martins
2026-11-18 21:14:15 -03:00
committed by diegosouzapw
parent c076efc25f
commit b165c0fa05
2 changed files with 39 additions and 5 deletions

View File

@@ -1007,12 +1007,15 @@ export class DefaultExecutor extends BaseExecutor {
// 9router#1480: native Moonshot and DeepSeek providers 400 when a prior assistant turn lacks
// reasoning_content (#20260). Scope to Moonshot/DeepSeek ids, or a registry entry opting in via
// `requiresReasoningContentEcho` (e.g. `bai`'s DeepSeek resale, #13599).
// `requiresReasoningContentEcho` (e.g. `bai`'s DeepSeek resale, #13599). The field is
// OpenAI-chat only: a Claude alternate (DeepSeek's /anthropic endpoint) carries thinking as
// content blocks, so the placeholder stays off that wire.
const reasoningEcho =
this.provider === "kimi" ||
this.provider === "moonshot" ||
this.provider === "deepseek" ||
!!getRegistryEntry(this.provider)?.requiresReasoningContentEcho;
targetFormat !== "claude" &&
(this.provider === "kimi" ||
this.provider === "moonshot" ||
this.provider === "deepseek" ||
!!getRegistryEntry(this.provider)?.requiresReasoningContentEcho);
if (reasoningEcho) {
const outboundModel =
typeof (withDefaults as Record<string, unknown>)?.model === "string"

View File

@@ -96,3 +96,34 @@ test("DefaultExecutor preserves existing authentic reasoning_content on deepseek
assert.ok(assistantTurn);
assert.equal(assistantTurn!.reasoning_content, "Authentic thinking steps here...");
});
test("DefaultExecutor does not inject reasoning_content on the deepseek Claude alternate format", () => {
// A DeepSeek connection on the Anthropic-compatible alternate sends Claude messages:
// thinking travels as content blocks there, so the OpenAI-only field must stay off.
const executor = new DefaultExecutor("deepseek");
const body = {
model: "deepseek-flash",
max_tokens: 1024,
stream: false,
messages: [
{ role: "user", content: [{ type: "text", text: "read a.txt" }] },
{
role: "assistant",
content: [{ type: "tool_use", id: "toolu_1", name: "read_file", input: { path: "a.txt" } }],
},
{
role: "user",
content: [{ type: "tool_result", tool_use_id: "toolu_1", content: "hello" }],
},
],
};
const transformed = executor.transformRequest("deepseek-flash", body, false, {
apiKey: "sk-deepseek-test",
providerSpecificData: { targetFormat: "claude" },
}) as { messages: Array<Record<string, unknown>> };
const assistantTurn = transformed.messages.find((m) => m.role === "assistant");
assert.ok(assistantTurn);
assert.equal(Object.prototype.hasOwnProperty.call(assistantTurn, "reasoning_content"), false);
});