Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion typescript-sdk/packages/client/src/legacy/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
StateDeltaEvent,
MessagesSnapshotEvent,
ToolCall,
RunErrorEvent,
} from "@ag-ui/core";
import { Observable } from "rxjs";
import {
Expand All @@ -36,6 +37,7 @@ import {
LegacyActionExecutionMessage,
LegacyResultMessage,
LegacyActionExecutionResult,
LegacyRunError
} from "./types";
import untruncateJson from "untruncate-json";

Expand Down Expand Up @@ -319,7 +321,14 @@ export const convertToLegacyEvents =
case EventType.RUN_ERROR: {
// legacy protocol does not have an event for errors
console.error("Run error", event);
return [];
const errorEvent = event as RunErrorEvent;
return [
{
type: LegacyRuntimeEventTypes.enum.RunError,
message: errorEvent.message,
code: errorEvent.code,
} as LegacyRunError,
];
}
case EventType.STEP_STARTED: {
const stepStarted = event as StepStartedEvent;
Expand Down
9 changes: 9 additions & 0 deletions typescript-sdk/packages/client/src/legacy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ export const LegacyMetaEvent = z.object({
value: z.any(),
});


export const LegacyRunError = z.object({
type: z.literal(LegacyRuntimeEventTypes.enum.RunError),
message: z.string(),
code: z.string().optional(),
});

export const LegacyRuntimeProtocolEvent = z.discriminatedUnion("type", [
LegacyTextMessageStart,
LegacyTextMessageContent,
Expand All @@ -94,6 +101,7 @@ export const LegacyRuntimeProtocolEvent = z.discriminatedUnion("type", [
LegacyActionExecutionResult,
LegacyAgentStateMessage,
LegacyMetaEvent,
LegacyRunError,
]);

// Protocol Event type exports
Expand All @@ -109,6 +117,7 @@ export type LegacyActionExecutionResult = z.infer<typeof LegacyActionExecutionRe
export type LegacyAgentStateMessage = z.infer<typeof LegacyAgentStateMessage>;
export type LegacyMetaEvent = z.infer<typeof LegacyMetaEvent>;
export type LegacyRuntimeProtocolEvent = z.infer<typeof LegacyRuntimeProtocolEvent>;
export type LegacyRunError = z.infer<typeof LegacyRunError>;

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