From 1819f4196d22b04ee7e2c13521cd4611f4fa7ecd Mon Sep 17 00:00:00 2001 From: Naiyuan Qing <145280634+NevilleQingNY@users.noreply.github.com> Date: Mon, 9 Feb 2026 08:04:13 +0800 Subject: [PATCH] fix(sdk): add AgentErrorEvent to StreamPayload type StreamPayload.event was missing the agent_error event type, causing TypeScript errors in useGatewayChat and useLocalChat where the comparison payload.event.type === "agent_error" had no type overlap. Co-Authored-By: Claude Opus 4.6 --- packages/sdk/src/actions/index.ts | 1 + packages/sdk/src/actions/stream.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/sdk/src/actions/index.ts b/packages/sdk/src/actions/index.ts index c378a6d6..b3ef94e3 100644 --- a/packages/sdk/src/actions/index.ts +++ b/packages/sdk/src/actions/index.ts @@ -38,6 +38,7 @@ export { type CompactionEvent, type CompactionStartEvent, type CompactionEndEvent, + type AgentErrorEvent, type ContentBlock, type TextContent, type ThinkingContent, diff --git a/packages/sdk/src/actions/stream.ts b/packages/sdk/src/actions/stream.ts index c0249353..19aa9482 100644 --- a/packages/sdk/src/actions/stream.ts +++ b/packages/sdk/src/actions/stream.ts @@ -45,16 +45,22 @@ export type CompactionEndEvent = { /** Union of all compaction events */ export type CompactionEvent = CompactionStartEvent | CompactionEndEvent; +/** Emitted when the agent encounters an error (LLM failure, quota exceeded, etc.) */ +export type AgentErrorEvent = { + type: "agent_error"; + error: string; +}; + // --- Stream event types --- /** - * Hub forwards AgentEvent from pi-agent-core and CompactionEvent as-is. - * StreamPayload wraps them with routing metadata. + * Hub forwards AgentEvent from pi-agent-core, CompactionEvent, + * and AgentErrorEvent as-is. StreamPayload wraps them with routing metadata. */ export interface StreamPayload { streamId: string; agentId: string; - event: AgentEvent | CompactionEvent; + event: AgentEvent | CompactionEvent | AgentErrorEvent; } /** Extract thinking/reasoning content from an AgentEvent that carries a message */