From 1267718f194cf9658e19c0d1517db3f2539279ff Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Sun, 23 Aug 2026 13:35:11 -0500 Subject: [PATCH] fix(ai): handle anthropic error events and ping frames - return Effect.fail for error events so stream properly fails instead of returning bare AIError - add ping to SSE allowlist to explicitly handle keepalive frames (matches SDK continue behavior) --- packages/ai/src/protocols/anthropic-messages.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/ai/src/protocols/anthropic-messages.ts b/packages/ai/src/protocols/anthropic-messages.ts index ed5087f5164a..894d2d282d7a 100644 --- a/packages/ai/src/protocols/anthropic-messages.ts +++ b/packages/ai/src/protocols/anthropic-messages.ts @@ -41,6 +41,7 @@ const SSE_EVENTS = new Set([ "content_block_start", "content_block_delta", "content_block_stop", + "ping", "error", ]) export const framing = Framing.sseEvents(SSE_EVENTS) @@ -1004,11 +1005,13 @@ const providerErrorMessage = (event: AnthropicEvent): string => { } const onError = (event: AnthropicEvent) => - new AIError({ - module: ADAPTER, - method: "stream", - reason: classifyProviderFailure({ message: providerErrorMessage(event), code: event.error?.type }), - }) + Effect.fail( + new AIError({ + module: ADAPTER, + method: "stream", + reason: classifyProviderFailure({ message: providerErrorMessage(event), code: event.error?.type }), + }), + ) const step = (state: ParserState, event: AnthropicEvent) => { if (event.type === "message_start") return Effect.succeed(onMessageStart(state, event))