2025-11-07 11:42:10 +05:30
|
|
|
import { z } from "zod";
|
2025-11-15 01:51:22 +05:30
|
|
|
import { LlmStepStreamEvent } from "./llm-step-events.js";
|
2025-11-07 11:42:10 +05:30
|
|
|
import { Message } from "./message.js";
|
2025-11-15 01:51:22 +05:30
|
|
|
import { Agent } from "./agent.js";
|
2025-11-07 11:42:10 +05:30
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
const BaseRunEvent = z.object({
|
|
|
|
|
ts: z.iso.datetime().optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const RunStartEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("start"),
|
|
|
|
|
runId: z.string(),
|
2025-11-16 18:21:41 +05:30
|
|
|
agent: z.string(),
|
2025-11-07 11:42:10 +05:30
|
|
|
});
|
|
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
export const RunStepStartEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("step-start"),
|
2025-11-07 11:42:10 +05:30
|
|
|
});
|
|
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
export const RunStreamEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("stream-event"),
|
2025-11-07 11:42:10 +05:30
|
|
|
event: LlmStepStreamEvent,
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
export const RunMessageEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("message"),
|
2025-11-07 11:42:10 +05:30
|
|
|
message: Message,
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
export const RunToolInvocationEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("tool-invocation"),
|
2025-11-07 11:42:10 +05:30
|
|
|
toolName: z.string(),
|
|
|
|
|
input: z.string(),
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
export const RunToolResultEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("tool-result"),
|
2025-11-07 11:42:10 +05:30
|
|
|
toolName: z.string(),
|
|
|
|
|
result: z.any(),
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
export const RunStepEndEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("step-end"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const RunEndEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("end"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const RunPauseEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("pause-for-human-input"),
|
|
|
|
|
toolCallId: z.string(),
|
2025-11-18 02:28:49 +05:30
|
|
|
question: z.string(),
|
2025-11-07 11:42:10 +05:30
|
|
|
});
|
|
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
export const RunResumeEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("resume"),
|
2025-11-07 11:42:10 +05:30
|
|
|
});
|
|
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
export const RunErrorEvent = BaseRunEvent.extend({
|
|
|
|
|
type: z.literal("error"),
|
2025-11-07 11:42:10 +05:30
|
|
|
error: z.string(),
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-11 12:32:46 +05:30
|
|
|
export const RunEvent = z.union([
|
|
|
|
|
RunStartEvent,
|
|
|
|
|
RunStepStartEvent,
|
|
|
|
|
RunStreamEvent,
|
|
|
|
|
RunMessageEvent,
|
|
|
|
|
RunToolInvocationEvent,
|
|
|
|
|
RunToolResultEvent,
|
|
|
|
|
RunStepEndEvent,
|
|
|
|
|
RunEndEvent,
|
|
|
|
|
RunPauseEvent,
|
|
|
|
|
RunResumeEvent,
|
|
|
|
|
RunErrorEvent,
|
2025-11-07 11:42:10 +05:30
|
|
|
]);
|