fix(ai): ignore unknown anthropic sse events

closes #3708
This commit is contained in:
Mario Zechner
2026-04-25 16:57:03 +02:00
parent 953f89fbe9
commit 3e7ffff184
9 changed files with 99 additions and 13 deletions

View File

@@ -237,6 +237,15 @@ interface SseDecoderState {
raw: string[];
}
const ANTHROPIC_MESSAGE_EVENTS: ReadonlySet<string> = new Set([
"message_start",
"message_delta",
"message_stop",
"content_block_start",
"content_block_delta",
"content_block_stop",
]);
function flushSseEvent(state: SseDecoderState): ServerSentEvent | null {
if (!state.event && state.data.length === 0) {
return null;
@@ -376,14 +385,14 @@ async function* iterateAnthropicEvents(
}
for await (const sse of iterateSseMessages(response.body, signal)) {
if (!sse.event || sse.event === "ping") {
continue;
}
if (sse.event === "error") {
throw new Error(sse.data);
}
if (!ANTHROPIC_MESSAGE_EVENTS.has(sse.event ?? "")) {
continue;
}
try {
yield parseJsonWithRepair<RawMessageStreamEvent>(sse.data);
} catch (error) {