fix(translator): shape Anthropic non-stream responses from forced-streaming providers

The non-streaming Anthropic path leaked OpenAI chat.completion bodies to
Claude clients when the upstream provider forces streaming (forced
SSE->JSON path): parseSSEToOpenAIResponse yields choices[] which Claude
Code cannot parse. Convert to Claude Messages shape for sourceFormat
CLAUDE in sseToJsonHandler.

Shared toClaudeMessageShape/openAICompletionToClaudeMessage moved to
translator/concerns/claudeShape.js to avoid circular import between
nonStreamingHandler and sseToJsonHandler. 5 new tests: sse-to-json
reassembly + Claude guard, plus existing anthropic-nonstream-shape
updated to import from the concern.
This commit is contained in:
asepharyana
2026-09-23 15:36:24 +07:00
parent b239b2a8a9
commit 3de32a10f3
5 changed files with 139 additions and 67 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
const { stripEosSentinel } = await import("../../open-sse/translator/concerns/eosStrip.js");
const { toClaudeMessageShape } = await import("../../open-sse/handlers/chatCore/nonStreamingHandler.js");
const { toClaudeMessageShape } = await import("../../open-sse/translator/concerns/claudeShape.js");
// An OpenAI-shape body as returned by a claude-transport executor (opencode/
// big-pickle): no type:"message", choices[] present. This is what an Anthropic