Skip to content

Commit e9ca110

Browse files
authored
Merge pull request ag-ui-protocol#298 from ag-ui-protocol/fix/legacy-error-message-forwarding
fix: expose run error in legacy runtime events
2 parents b573f73 + 7adb8a6 commit e9ca110

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

typescript-sdk/packages/client/src/legacy/convert.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
StateDeltaEvent,
1919
MessagesSnapshotEvent,
2020
ToolCall,
21+
RunErrorEvent,
2122
} from "@ag-ui/core";
2223
import { Observable } from "rxjs";
2324
import {
@@ -36,6 +37,7 @@ import {
3637
LegacyActionExecutionMessage,
3738
LegacyResultMessage,
3839
LegacyActionExecutionResult,
40+
LegacyRunError
3941
} from "./types";
4042
import untruncateJson from "untruncate-json";
4143

@@ -317,9 +319,14 @@ export const convertToLegacyEvents =
317319
];
318320
}
319321
case EventType.RUN_ERROR: {
320-
// legacy protocol does not have an event for errors
321-
console.error("Run error", event);
322-
return [];
322+
const errorEvent = event as RunErrorEvent;
323+
return [
324+
{
325+
type: LegacyRuntimeEventTypes.enum.RunError,
326+
message: errorEvent.message,
327+
code: errorEvent.code,
328+
} as LegacyRunError,
329+
];
323330
}
324331
case EventType.STEP_STARTED: {
325332
const stepStarted = event as StepStartedEvent;

typescript-sdk/packages/client/src/legacy/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ export const LegacyMetaEvent = z.object({
8484
value: z.any(),
8585
});
8686

87+
88+
export const LegacyRunError = z.object({
89+
type: z.literal(LegacyRuntimeEventTypes.enum.RunError),
90+
message: z.string(),
91+
code: z.string().optional(),
92+
});
93+
8794
export const LegacyRuntimeProtocolEvent = z.discriminatedUnion("type", [
8895
LegacyTextMessageStart,
8996
LegacyTextMessageContent,
@@ -94,6 +101,7 @@ export const LegacyRuntimeProtocolEvent = z.discriminatedUnion("type", [
94101
LegacyActionExecutionResult,
95102
LegacyAgentStateMessage,
96103
LegacyMetaEvent,
104+
LegacyRunError,
97105
]);
98106

99107
// Protocol Event type exports
@@ -109,6 +117,7 @@ export type LegacyActionExecutionResult = z.infer<typeof LegacyActionExecutionRe
109117
export type LegacyAgentStateMessage = z.infer<typeof LegacyAgentStateMessage>;
110118
export type LegacyMetaEvent = z.infer<typeof LegacyMetaEvent>;
111119
export type LegacyRuntimeProtocolEvent = z.infer<typeof LegacyRuntimeProtocolEvent>;
120+
export type LegacyRunError = z.infer<typeof LegacyRunError>;
112121

113122
// Message schemas (with kind discriminator)
114123
export const LegacyTextMessageSchema = z.object({

0 commit comments

Comments
 (0)