rowboat/apps/cli/src/application/entities/workflow-event.ts

86 lines
2 KiB
TypeScript
Raw Normal View History

2025-11-07 11:42:10 +05:30
import { z } from "zod";
import { LlmStepStreamEvent } from "./llm-step-event.js";
import { Workflow } from "./workflow.js";
import { Message } from "./message.js";
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-07 11:42:10 +05:30
workflowId: z.string(),
workflow: Workflow,
2025-11-11 12:32:46 +05:30
interactive: z.boolean(),
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"),
stepIndex: z.number(),
2025-11-07 11:42:10 +05:30
stepId: z.string(),
stepType: z.enum(["agent", "function"]),
});
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
stepId: z.string(),
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
stepId: z.string(),
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
stepId: z.string(),
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
stepId: z.string(),
toolName: z.string(),
result: z.any(),
});
2025-11-11 12:32:46 +05:30
export const RunStepEndEvent = BaseRunEvent.extend({
type: z.literal("step-end"),
stepIndex: z.number(),
});
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-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
]);