/** * Kernel Event Types * * Discriminated union of all events emitted by the workflow kernel. * Each event carries a string literal `type` discriminant, a `timestamp`, * and a `workflowRunId` that scopes the event to a specific run. * * This file contains ONLY types -- no runtime code. */ /** Emitted when a new workflow run record is created. */ interface WorkflowCreatedEvent { readonly type: "workflow:created"; readonly timestamp: Date; readonly workflowRunId: string; readonly workflowId: string; } /** Emitted when a workflow run begins execution. */ interface WorkflowStartedEvent { readonly type: "workflow:started"; readonly timestamp: Date; readonly workflowRunId: string; } /** Emitted when a workflow run finishes successfully. */ interface WorkflowCompletedEvent { readonly type: "workflow:completed"; readonly timestamp: Date; readonly workflowRunId: string; readonly duration?: number; readonly totalCost?: number; readonly totalTokens?: number; readonly output?: unknown; } /** Emitted when a workflow run terminates due to an unrecoverable error. */ interface WorkflowFailedEvent { readonly type: "workflow:failed"; readonly timestamp: Date; readonly workflowRunId: string; readonly error: string; } /** Emitted when a workflow run is cancelled by an external request. */ interface WorkflowCancelledEvent { readonly type: "workflow:cancelled"; readonly timestamp: Date; readonly workflowRunId: string; readonly reason?: string; } /** Emitted when a workflow run suspends, waiting on an external signal. */ interface WorkflowSuspendedEvent { readonly type: "workflow:suspended"; readonly timestamp: Date; readonly workflowRunId: string; readonly stageId: string; } /** Emitted when a stage begins execution. */ interface StageStartedEvent { readonly type: "stage:started"; readonly timestamp: Date; readonly workflowRunId: string; readonly stageId: string; readonly stageName: string; readonly stageNumber: number; } /** Emitted when a stage completes successfully. */ interface StageCompletedEvent { readonly type: "stage:completed"; readonly timestamp: Date; readonly workflowRunId: string; readonly stageId: string; readonly stageName: string; readonly duration: number; } /** Emitted when a stage suspends, awaiting a future poll. */ interface StageSuspendedEvent { readonly type: "stage:suspended"; readonly timestamp: Date; readonly workflowRunId: string; readonly stageId: string; readonly stageName: string; readonly nextPollAt: Date; } /** Emitted when a stage fails with an error. */ interface StageFailedEvent { readonly type: "stage:failed"; readonly timestamp: Date; readonly workflowRunId: string; readonly stageId: string; readonly stageName: string; readonly error: string; } /** Emitted to report incremental progress within a stage. */ interface StageProgressEvent { readonly type: "stage:progress"; readonly timestamp: Date; readonly workflowRunId: string; readonly stageId: string; readonly progress: number; readonly message: string; readonly details?: Record; } /** * Emitted when an annotation is written with `emitEvent: true`. Lets * plugins and external systems react to provenance writes in real time * (audit pipelines, SIEM, live dashboards) without polling * `kernel.annotations.list`. * * Off by default — annotations are primarily a queryable provenance * surface, not an event stream. Most consumers won't need this. */ interface AnnotationCreatedEvent { readonly type: "annotation:created"; readonly timestamp: Date; readonly workflowRunId: string; readonly key: string; readonly value: unknown; readonly scope: string; readonly scopeId?: string; readonly attempt?: number; readonly actorKind?: string; readonly actorId?: string; readonly actorVersion?: string; } /** Discriminated union of every kernel event. */ type KernelEvent = WorkflowCreatedEvent | WorkflowStartedEvent | WorkflowCompletedEvent | WorkflowFailedEvent | WorkflowCancelledEvent | WorkflowSuspendedEvent | StageStartedEvent | StageCompletedEvent | StageSuspendedEvent | StageFailedEvent | StageProgressEvent | AnnotationCreatedEvent; /** String literal union of all kernel event type discriminants. */ type KernelEventType = KernelEvent["type"]; export type { KernelEvent as K, StageCompletedEvent as S, WorkflowCancelledEvent as W, KernelEventType as a, StageFailedEvent as b, StageProgressEvent as c, StageStartedEvent as d, StageSuspendedEvent as e, WorkflowCompletedEvent as f, WorkflowCreatedEvent as g, WorkflowFailedEvent as h, WorkflowStartedEvent as i, WorkflowSuspendedEvent as j };