Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions open-sse/translator/response/claude-to-openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export function claudeToOpenAIResponse(chunk, state) {
} else if (block?.type === CLAUDE_BLOCK.THINKING) {
state.inThinkingBlock = true;
state.currentBlockIndex = chunk.index;
results.push(createChunk(state, { content: "<think>" }));
} else if (block?.type === CLAUDE_BLOCK.TOOL_USE) {
const toolCallIndex = state.toolCallIndex++;
// Restore original tool name from mapping (Claude OAuth)
Expand Down Expand Up @@ -94,7 +93,6 @@ export function claudeToOpenAIResponse(chunk, state) {
break;
}
if (state.inThinkingBlock && chunk.index === state.currentBlockIndex) {
results.push(createChunk(state, { content: "</think>" }));
state.inThinkingBlock = false;
}
state.textBlockStarted = false;
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/claude-reasoning-response.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, it, expect } from "vitest";
import { claudeToOpenAIResponse } from "../../open-sse/translator/response/claude-to-openai.js";

function collect(chunks) {
const state = { toolCalls: new Map() };
return chunks.flatMap((chunk) => claudeToOpenAIResponse(chunk, state) || []);
}

describe("Claude reasoning response translation (#2158)", () => {
it("keeps thinking deltas in reasoning_content without leaking think tags into content", () => {
const output = collect([
{ type: "message_start", message: { id: "msg_12345678", model: "claude", usage: {} } },
{ type: "content_block_start", index: 0, content_block: { type: "thinking", thinking: "" } },
{ type: "content_block_delta", index: 0, delta: { type: "thinking_delta", thinking: "private chain" } },
{ type: "content_block_stop", index: 0 },
{ type: "content_block_start", index: 1, content_block: { type: "text", text: "" } },
{ type: "content_block_delta", index: 1, delta: { type: "text_delta", text: "visible answer" } },
{ type: "content_block_stop", index: 1 },
{ type: "message_delta", delta: { stop_reason: "end_turn" }, usage: { input_tokens: 1, output_tokens: 2 } },
]);

const contentDeltas = output.map((chunk) => chunk.choices?.[0]?.delta?.content).filter(Boolean);
const content = contentDeltas.join("");
const reasoning = output.map((chunk) => chunk.choices?.[0]?.delta?.reasoning_content || "").join("");

expect(contentDeltas).toEqual(["visible answer"]);
expect(contentDeltas).not.toContain("<think>");
expect(contentDeltas).not.toContain("</think>");
expect(content).toBe("visible answer");
expect(reasoning).toBe("private chain");
});
});