fix(ai): own Anthropic SSE parsing to avoid SDK JSON.parse hard-failures

Bypass the Anthropic SDK streaming parser entirely. Use
client.messages.create().asResponse() and decode the SSE stream
ourselves with defensive JSON parsing that repairs invalid escape
sequences and control characters inside string literals.

- Switch from SDK .stream() to .asResponse() + pi-owned SSE decoder
- Add repairJson() / parseJsonWithRepair() to json-parse.ts
- Add anthropic-sse-parsing.test.ts regression for malformed tool deltas
- Update github-copilot-anthropic.test.ts mock to match new call path
- Update deprecated claude-3-5-haiku-20241022 refs to claude-haiku-4-5
- Remove stale non-reasoning model test

fixes #3175
This commit is contained in:
Mario Zechner
2026-04-21 23:00:56 +02:00
parent a0a16c7762
commit 4b926a30a2
12 changed files with 430 additions and 124 deletions

View File

@@ -137,7 +137,7 @@ describe("Tool Call Without Result Tests", () => {
});
describe.skipIf(!process.env.ANTHROPIC_API_KEY)("Anthropic Provider", () => {
const model = getModel("anthropic", "claude-3-5-haiku-20241022");
const model = getModel("anthropic", "claude-haiku-4-5");
it("should filter out tool calls without corresponding tool results", { retry: 3, timeout: 30000 }, async () => {
await testToolCallWithoutResult(model);
@@ -229,7 +229,7 @@ describe("Tool Call Without Result Tests", () => {
// =========================================================================
describe("Anthropic OAuth Provider", () => {
const model = getModel("anthropic", "claude-3-5-haiku-20241022");
const model = getModel("anthropic", "claude-haiku-4-5");
it.skipIf(!anthropicOAuthToken)(
"should filter out tool calls without corresponding tool results",