import { z } from '#compiled/zod/index.js'; import type { PaginationOptions, ResolveData } from './shared.js'; export declare const EventTypeSchema: z.ZodEnum<{ run_created: "run_created"; run_started: "run_started"; run_completed: "run_completed"; run_failed: "run_failed"; run_cancelled: "run_cancelled"; attr_set: "attr_set"; step_created: "step_created"; step_completed: "step_completed"; step_failed: "step_failed"; step_retrying: "step_retrying"; step_started: "step_started"; hook_created: "hook_created"; hook_received: "hook_received"; hook_disposed: "hook_disposed"; hook_conflict: "hook_conflict"; wait_created: "wait_created"; wait_completed: "wait_completed"; }>; export type EventType = z.infer; declare const RunEventTypeSchema: z.ZodEnum<{ run_created: "run_created"; run_started: "run_started"; run_completed: "run_completed"; run_failed: "run_failed"; run_cancelled: "run_cancelled"; }>; export type RunEventType = z.infer; export declare const RUN_EVENT_TYPES: ("run_created" | "run_started" | "run_completed" | "run_failed" | "run_cancelled")[]; export declare function isRunEventType(eventType: string): eventType is RunEventType; export declare const TerminalRunEventTypeSchema: z.ZodEnum<{ run_completed: "run_completed"; run_failed: "run_failed"; run_cancelled: "run_cancelled"; }>; export type TerminalRunEventType = z.infer; export declare const TERMINAL_RUN_EVENT_TYPES: ("run_completed" | "run_failed" | "run_cancelled")[]; export declare function isTerminalRunEventType(eventType: string): eventType is TerminalRunEventType; declare const StepEventTypeSchema: z.ZodEnum<{ step_created: "step_created"; step_completed: "step_completed"; step_failed: "step_failed"; step_retrying: "step_retrying"; step_started: "step_started"; }>; export type StepEventType = z.infer; export declare const STEP_EVENT_TYPES: ("step_created" | "step_completed" | "step_failed" | "step_retrying" | "step_started")[]; export declare function isStepEventType(eventType: string): eventType is StepEventType; declare const TerminalStepEventTypeSchema: z.ZodEnum<{ step_completed: "step_completed"; step_failed: "step_failed"; }>; export type TerminalStepEventType = z.infer; export declare const TERMINAL_STEP_EVENT_TYPES: ("step_completed" | "step_failed")[]; export declare function isTerminalStepEventType(eventType: string): eventType is TerminalStepEventType; declare const HookLifecycleEventTypeSchema: z.ZodEnum<{ hook_created: "hook_created"; hook_received: "hook_received"; hook_disposed: "hook_disposed"; }>; export type HookLifecycleEventType = z.infer; export declare const HOOK_LIFECYCLE_EVENT_TYPES: ("hook_created" | "hook_received" | "hook_disposed")[]; export declare function isHookLifecycleEventType(eventType: string): eventType is HookLifecycleEventType; declare const HookEventRequiringExistenceTypeSchema: z.ZodEnum<{ hook_received: "hook_received"; hook_disposed: "hook_disposed"; }>; export type HookEventRequiringExistenceType = z.infer; export declare const HOOK_EVENTS_REQUIRING_EXISTENCE: ("hook_received" | "hook_disposed")[]; export declare function isHookEventRequiringExistence(eventType: string): eventType is HookEventRequiringExistenceType; declare const WaitEventTypeSchema: z.ZodEnum<{ wait_created: "wait_created"; wait_completed: "wait_completed"; }>; export type WaitEventType = z.infer; export declare const WAIT_EVENT_TYPES: ("wait_created" | "wait_completed")[]; export declare function isWaitEventType(eventType: string): eventType is WaitEventType; declare const ChildEntityCreationEventTypeSchema: z.ZodEnum<{ step_created: "step_created"; hook_created: "hook_created"; wait_created: "wait_created"; }>; export type ChildEntityCreationEventType = z.infer; export declare const CHILD_ENTITY_CREATION_EVENT_TYPES: ("step_created" | "hook_created" | "wait_created")[]; export declare function isChildEntityCreationEventType(eventType: string): eventType is ChildEntityCreationEventType; /** * Field within eventData that carries the opaque user payload for event types * that have one. V4 worlds split this field into the wire body while keeping * the remaining eventData fields in metadata. */ export declare const EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE: { readonly run_created: "input"; readonly run_started: "input"; readonly run_completed: "output"; readonly run_failed: "error"; readonly step_created: "input"; readonly step_started: "input"; readonly step_completed: "result"; readonly step_failed: "error"; readonly step_retrying: "error"; readonly hook_created: "metadata"; readonly hook_received: "payload"; }; export type EventDataPayloadField = (typeof EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE)[keyof typeof EVENT_DATA_PAYLOAD_FIELD_BY_EVENT_TYPE]; /** * Fields within eventData that hold ref/payload data per event type. * When resolveData is 'none', only these fields are stripped — all other * metadata (stepName, workflowName, etc.) is preserved. */ export declare const EVENT_DATA_REF_FIELDS: Record; export declare function getEventDataRefFields(eventType: string): readonly string[]; export declare function getEventDataPayloadField(eventType: string): EventDataPayloadField | undefined; /** * Strip ref/payload fields from eventData based on resolveData setting. * When resolveData is 'none', removes only large data fields (refs) from * eventData while preserving metadata like stepName, workflowName, etc. */ export declare function stripEventDataRefs(event: Event, resolveData: ResolveData): Event; export declare const BaseEventSchema: z.ZodObject<{ eventType: z.ZodEnum<{ run_created: "run_created"; run_started: "run_started"; run_completed: "run_completed"; run_failed: "run_failed"; run_cancelled: "run_cancelled"; attr_set: "attr_set"; step_created: "step_created"; step_completed: "step_completed"; step_failed: "step_failed"; step_retrying: "step_retrying"; step_started: "step_started"; hook_created: "hook_created"; hook_received: "hook_received"; hook_disposed: "hook_disposed"; hook_conflict: "hook_conflict"; wait_created: "wait_created"; wait_completed: "wait_completed"; }>; correlationId: z.ZodOptional; specVersion: z.ZodOptional; }, z.core.$strip>; /** * Event created when a hook is first invoked. The World implementation * atomically creates both the event and the hook entity. */ export declare const HookCreatedEventSchema: z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_created">; correlationId: z.ZodString; eventData: z.ZodObject<{ token: z.ZodString; tokenRetentionUntil: z.ZodOptional>; metadata: z.ZodOptional>, z.ZodType>]>>; isWebhook: z.ZodOptional; isSystem: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>; declare const HookReceivedEventSchema: z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_received">; correlationId: z.ZodString; eventData: z.ZodObject<{ token: z.ZodOptional; payload: z.ZodUnion>, z.ZodType>]>; }, z.core.$strip>; }, z.core.$strip>; /** * Event created by World implementations when a hook_created request * conflicts with an existing hook token. This event is NOT user-creatable - * it is only returned by the World when a token conflict is detected. * * When the hook consumer sees this event, it should reject any awaited * promises with a HookTokenConflictError. */ declare const HookConflictEventSchema: z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_conflict">; correlationId: z.ZodString; eventData: z.ZodObject<{ token: z.ZodString; conflictingRunId: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>; /** * Event created when a workflow run is first created. The World implementation * atomically creates both the event and the run entity with status 'pending'. */ declare const RunCreatedEventSchema: z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_created">; eventData: z.ZodObject<{ deploymentId: z.ZodString; workflowName: z.ZodString; input: z.ZodUnion>, z.ZodType>]>; executionContext: z.ZodOptional>; attributes: z.ZodOptional>; allowReservedAttributes: z.ZodOptional>; encryptionPublicKey: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>; export declare const CreateEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_created">; eventData: z.ZodObject<{ deploymentId: z.ZodString; workflowName: z.ZodString; input: z.ZodUnion>, z.ZodType>]>; executionContext: z.ZodOptional>; attributes: z.ZodOptional>; allowReservedAttributes: z.ZodOptional>; encryptionPublicKey: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_started">; eventData: z.ZodOptional>, z.ZodType>]>>; deploymentId: z.ZodOptional; workflowName: z.ZodOptional; executionContext: z.ZodOptional>; attributes: z.ZodOptional>; allowReservedAttributes: z.ZodOptional>; encryptionPublicKey: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_completed">; eventData: z.ZodObject<{ output: z.ZodOptional>, z.ZodType>]>>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_failed">; eventData: z.ZodObject<{ error: z.ZodUnion>, z.ZodType>]>; errorCode: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_cancelled">; eventData: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"attr_set">; correlationId: z.ZodOptional; eventData: z.ZodObject<{ changes: z.ZodArray; }, z.core.$strip>>; writer: z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodLiteral<"workflow">; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"step">; stepId: z.ZodString; attempt: z.ZodNumber; }, z.core.$strip>], "type">; allowReservedAttributes: z.ZodOptional>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_created">; correlationId: z.ZodString; eventData: z.ZodObject<{ stepName: z.ZodString; workflowName: z.ZodOptional; input: z.ZodUnion>, z.ZodType>]>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_completed">; correlationId: z.ZodString; eventData: z.ZodObject<{ ttfs: z.ZodOptional; stso: z.ZodOptional; stepCount: z.ZodOptional; eventCount: z.ZodOptional; rsfs: z.ZodOptional; finalSchedulingReplay: z.ZodOptional; optimizations: z.ZodOptional>; stepName: z.ZodOptional; workflowName: z.ZodOptional; result: z.ZodUnion>, z.ZodType>]>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_failed">; correlationId: z.ZodString; eventData: z.ZodObject<{ ttfs: z.ZodOptional; stso: z.ZodOptional; stepCount: z.ZodOptional; eventCount: z.ZodOptional; rsfs: z.ZodOptional; finalSchedulingReplay: z.ZodOptional; optimizations: z.ZodOptional>; stepName: z.ZodOptional; error: z.ZodUnion>, z.ZodType>]>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_retrying">; correlationId: z.ZodString; eventData: z.ZodObject<{ stepName: z.ZodOptional; error: z.ZodUnion>, z.ZodType>]>; retryAfter: z.ZodOptional>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_started">; correlationId: z.ZodString; eventData: z.ZodOptional; attempt: z.ZodOptional; workflowName: z.ZodOptional; input: z.ZodOptional>, z.ZodType>]>>; ownerMessageId: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_created">; correlationId: z.ZodString; eventData: z.ZodObject<{ token: z.ZodString; tokenRetentionUntil: z.ZodOptional>; metadata: z.ZodOptional>, z.ZodType>]>>; isWebhook: z.ZodOptional; isSystem: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_received">; correlationId: z.ZodString; eventData: z.ZodObject<{ token: z.ZodOptional; payload: z.ZodUnion>, z.ZodType>]>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_disposed">; correlationId: z.ZodString; eventData: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"wait_created">; correlationId: z.ZodString; eventData: z.ZodObject<{ resumeAt: z.ZodCoercedDate; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"wait_completed">; correlationId: z.ZodString; eventData: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>], "eventType">; export declare const EventSchema: z.ZodIntersection; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_created">; eventData: z.ZodObject<{ deploymentId: z.ZodString; workflowName: z.ZodString; input: z.ZodUnion>, z.ZodType>]>; executionContext: z.ZodOptional>; attributes: z.ZodOptional>; allowReservedAttributes: z.ZodOptional>; encryptionPublicKey: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_started">; eventData: z.ZodOptional>, z.ZodType>]>>; deploymentId: z.ZodOptional; workflowName: z.ZodOptional; executionContext: z.ZodOptional>; attributes: z.ZodOptional>; allowReservedAttributes: z.ZodOptional>; encryptionPublicKey: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_completed">; eventData: z.ZodObject<{ output: z.ZodOptional>, z.ZodType>]>>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_failed">; eventData: z.ZodObject<{ error: z.ZodUnion>, z.ZodType>]>; errorCode: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ correlationId: z.ZodOptional; specVersion: z.ZodOptional; eventType: z.ZodLiteral<"run_cancelled">; eventData: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"attr_set">; correlationId: z.ZodOptional; eventData: z.ZodObject<{ changes: z.ZodArray; }, z.core.$strip>>; writer: z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodLiteral<"workflow">; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"step">; stepId: z.ZodString; attempt: z.ZodNumber; }, z.core.$strip>], "type">; allowReservedAttributes: z.ZodOptional>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_created">; correlationId: z.ZodString; eventData: z.ZodObject<{ stepName: z.ZodString; workflowName: z.ZodOptional; input: z.ZodUnion>, z.ZodType>]>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_completed">; correlationId: z.ZodString; eventData: z.ZodObject<{ ttfs: z.ZodOptional; stso: z.ZodOptional; stepCount: z.ZodOptional; eventCount: z.ZodOptional; rsfs: z.ZodOptional; finalSchedulingReplay: z.ZodOptional; optimizations: z.ZodOptional>; stepName: z.ZodOptional; workflowName: z.ZodOptional; result: z.ZodUnion>, z.ZodType>]>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_failed">; correlationId: z.ZodString; eventData: z.ZodObject<{ ttfs: z.ZodOptional; stso: z.ZodOptional; stepCount: z.ZodOptional; eventCount: z.ZodOptional; rsfs: z.ZodOptional; finalSchedulingReplay: z.ZodOptional; optimizations: z.ZodOptional>; stepName: z.ZodOptional; error: z.ZodUnion>, z.ZodType>]>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_retrying">; correlationId: z.ZodString; eventData: z.ZodObject<{ stepName: z.ZodOptional; error: z.ZodUnion>, z.ZodType>]>; retryAfter: z.ZodOptional>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"step_started">; correlationId: z.ZodString; eventData: z.ZodOptional; attempt: z.ZodOptional; workflowName: z.ZodOptional; input: z.ZodOptional>, z.ZodType>]>>; ownerMessageId: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_created">; correlationId: z.ZodString; eventData: z.ZodObject<{ token: z.ZodString; tokenRetentionUntil: z.ZodOptional>; metadata: z.ZodOptional>, z.ZodType>]>>; isWebhook: z.ZodOptional; isSystem: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_received">; correlationId: z.ZodString; eventData: z.ZodObject<{ token: z.ZodOptional; payload: z.ZodUnion>, z.ZodType>]>; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_disposed">; correlationId: z.ZodString; eventData: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"hook_conflict">; correlationId: z.ZodString; eventData: z.ZodObject<{ token: z.ZodString; conflictingRunId: z.ZodOptional; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"wait_created">; correlationId: z.ZodString; eventData: z.ZodObject<{ resumeAt: z.ZodCoercedDate; }, z.core.$strip>; }, z.core.$strip>, z.ZodObject<{ specVersion: z.ZodOptional; eventType: z.ZodLiteral<"wait_completed">; correlationId: z.ZodString; eventData: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>], "eventType">, z.ZodObject<{ runId: z.ZodString; eventId: z.ZodString; createdAt: z.ZodCoercedDate; occurredAt: z.ZodOptional>; specVersion: z.ZodOptional; resumeId: z.ZodOptional; }, z.core.$strip>>; export type Event = z.infer; export type EventOfType = Extract; export type EventRequestOfType = Extract; export type HookCreatedEvent = EventOfType<'hook_created'>; export type HookCreatedEventRequest = EventRequestOfType<'hook_created'>; export type HookReceivedEvent = z.infer; export type HookConflictEvent = z.infer; /** * Union of all possible event request types. * @internal Use CreateEventRequest or RunCreatedEventRequest instead. */ export type AnyEventRequest = z.infer; type ChildEntityCreationEventRequest = EventRequestOfType | (EventRequestOfType<'step_started'> & { eventData: { stepName: string; input: unknown; }; }); /** Includes lazy step_started requests that create their step on demand. */ export declare function isChildEntityCreationEvent(event: AnyEventRequest): event is ChildEntityCreationEventRequest; /** * Event request for creating a new workflow run. * Can be used with a client-generated runId or null for server-generated. */ export type RunCreatedEventRequest = z.infer; /** * Event request types that require an existing runId. * This is the common case for all events except run_created. */ export type CreateEventRequest = Exclude; export interface CreateEventParams { v1Compat?: boolean; resolveData?: ResolveData; /** * Lazy hook resume idempotency key. Set only by `resumeHook()` when it * persists a `hook_received` event whose creation must be deduplicated * against a concurrent re-ensure from the queue consumer. The World routes * it to the backend's `(runId, resumeId)` constraint so both writers * converge on exactly one event. Only meaningful for `hook_received`. */ resumeId?: string; /** * Content digest of the serialized resume payload, computed once by * `resumeHook()` and forwarded identically on the direct write and the queue * re-ensure. The World routes it to the backend so both writers record the * same digest on the `(runId, resumeId)` constraint. Only meaningful * alongside {@link resumeId}. */ resumePayloadDigest?: string; /** Request ID (x-vercel-id when on Vercel) for correlating request logs with workflow events. */ requestId?: string; /** * Compute instance whose handler is writing this event (`COMPUTE_INSTANCE_ID` * in @workflow/core). Ambient per-event identity like {@link requestId}, * which distinguishes invocations *within* an instance. Read back via * `AnalyticsEventSchema` / `AnalyticsStepSchema`. */ computeInstanceId?: string; /** * Epoch ms (the ULID time of the latest event the runtime has loaded during * replay). Sent by replay-context creates so the backend can reject the event * when a newer out-of-band event was recorded after this snapshot, enabling * an optimistic-concurrency guard. Omitted by callers without a loaded event * log. * * Backend contract (for World implementers who want to support the guard): * maintain a per-run marker holding the ULID time of the most recent * *externally-originated* event — a `hook_received` or `step_completed` * created **without** a `stateUpdatedAt` (replay-origin events carry one and * must not advance the marker). On a create that carries `stateUpdatedAt`, * reject with 412 when `stateUpdatedAt < marker` (strictly older); an equal * timestamp must pass (anti-livelock, so an up-to-date client is never * rejected). A backend that ignores this field simply disables the guard — * the client falls open and behaves as before. * * A watermark alone cannot see an event *missing at or below* it, which is * the failure that actually corrupts a replay — see {@link stateEventCount} * for the second half of the guard. */ stateUpdatedAt?: number; /** * How many loaded events have a ULID time at or below {@link stateUpdatedAt}. * Since `stateUpdatedAt` is the *maximum* ULID time in the loaded log, this * equals the loaded array's length. Sent **only** together with * `stateUpdatedAt`; a World must ignore a count that arrives without one. * * This closes the hole a watermark cannot: the watermark proves only "no * newer event exists", while a replay corrupts its log by missing an event * at or *below* its own frontier — a concurrent writer commits in the same * ULID millisecond as the client's last loaded event, so the two watermarks * compare equal and the write is accepted against a log that is one event * short. Because correlation IDs are positional ordinals of a single seeded * sequence, that one-event difference renames every entity after it. * * Backend contract (for World implementers who want to support this half): * * - Count **every** created event for the run, including replay-origin ones. * Unlike the watermark, this is not restricted to out-of-band writes: the * race being fenced is one replay against another. * - Reject with 412 when the count of recorded events at ULID time * `<= stateUpdatedAt` is strictly **greater** than `stateEventCount`. * - Compare **at or below** `stateUpdatedAt`, never strictly below (the * missing event routinely shares the client's frontier millisecond) and * never against a total (all the creates of one suspension share one * snapshot, so a total would reject every sibling after the first). * - **One-sided safety is mandatory.** Anything that makes the backend's * count incomplete, uncomputable, or expired must *allow* the write. A * rejection has to imply a real hole, because the client responds to it by * discarding and re-deriving its whole replay. * * See also the millisecond-granularity caveat on `stateUpdatedAt`: the count * is what makes an equal-timestamp snapshot safe to accept. */ stateEventCount?: number; /** * The client's current event-log cursor (advisory). Sent alongside the other * two snapshot fields so a World that rejects the write MAY return the * events the client is missing on the 412 itself, saving the client a * follow-up `events.list`. * * Distinct from {@link sinceCursor}: a World must **not** compute a delta for * this on the accepted path — it exists purely to make a rejection cheaper. * Returning events on a 412 is OPTIONAL, and the returned set must be * provably complete (it must account for the entire discrepancy the * rejection reported) or omitted entirely: a cursor filters by lexicographic * event id while a hole is defined by ULID time, so a naive * "everything after the cursor" delta can silently exclude the very event * the client is missing. A client that receives nothing does the * authoritative full reload, which is always correct. */ stateCursor?: string; /** * Timestamp for when the event occurred on the client side. Worlds that * support this can persist it separately from `createdAt`, which represents * when the backing service accepted or stored the event. */ occurredAt?: Date; /** * Number of consecutive replay divergences resolved by this event write. * * This is request telemetry, not workflow state. Worlds may use it for * metrics and diagnostics, but must not require it for event * materialization or persist it into the event log. */ replayDivergenceCount?: number; /** * Inline-delta optimization (opt-in). When set, the World MAY return, * on the resulting {@link EventResult}, the first page of events written * strictly after this cursor (via `events`/`cursor`/`hasMore`) — the * same page an `events.list({ cursor: sinceCursor, sortOrder: 'asc' })` * call would return immediately after this write. The inline runtime * loop uses this to skip a redundant `events.list` round-trip between * sequential steps: instead of re-reading its own just-written events * (and any events interleaved in-band, such as `hook_received`), it * consumes the authoritative delta the write already had to compute. * * The cursor MUST share `events.list` semantics: the returned `events` * are everything sorted strictly after `sinceCursor`, `cursor` is the * position past the last returned event, and `hasMore` indicates a * further page exists. A World MAY return a single page and set * `hasMore: true` rather than paginating to exhaustion — the runtime * does not consume a truncated delta, it falls back to a full * incremental fetch whenever `hasMore` is true. (For that reason a step * body emitting more in-band events than one page silently bypasses this * fast path, which is correct but forgoes the saved round-trip.) * Returning these fields at all is OPTIONAL — a World that omits them is * fully supported; the runtime falls back to `events.list`. This * preserves the same divergence guarantees as the fetch path because the * delta is computed atomically against the same log the fetch would read. */ sinceCursor?: string; /** * Run-started preload opt-out (advisory). On a `run_started` write a World * MAY preload the run's event log onto the {@link EventResult} * (`events`/`cursor`/`hasMore`) so the runtime can skip its initial * `events.list`. The turbo first invocation backgrounds `run_started` * purely as a write barrier and never reads that preload, so it sets this * to tell the World to skip the wasted list+resolve — trimming the * `run_started` round-trip that the chained first `step_started` waits on. * A World that ignores it (or doesn't preload) remains fully correct: the * runtime falls back to `events.list` whenever it actually needs the log. * Only honored for `run_started`; ignored for other event types. * * Named to match the World boundary, the wire frame meta, and the backend * option end-to-end (cf. {@link sinceCursor}) so the single name greps * across the SDK and the backend. */ skipPreload?: boolean; /** * Replay-log preload opt-in (advisory) — the `hook_received` dual of * {@link skipPreload}. Set only by the queue consumer's idempotent * `hook_received` re-ensure on a lazy hook resume (alongside * {@link resumeId} + {@link resumePayloadDigest}). A World MAY return the * run's current replay event log with the event creation * (`events`/`cursor`/`hasMore`, plus `run` and `maxEvents`) so the runtime * can initialize replay from this one request and skip both the * `run_started` write and the initial `events.list`. * * The runtime trusts a returned preload as replay input ONLY when all of * the following hold — a World that cannot guarantee them should return * its normal {@link EventResult} instead: * * - `events` is the COMPLETE log with `hasMore: false` (the runtime has no * cursor-continuation machinery on this path; a bounded page is * rejected). * - `cursor` is a valid non-null resume point matching `events.list` * semantics (present even on the final page). * - `run` (with `run.startedAt`) and `maxEvents` are present — this * response plays `run_started`'s role, including the event-ceiling * handshake. * - The log contains `run_created`, `run_started`, and the canonical * `hook_received` carrying the requested {@link resumeId}. * - `events` uses the same ascending ordering semantics as `events.list`. * - The log is read atomically/consistently WITH (i.e. no earlier than) * the `hook_received` write, so no concurrently committed event can be * omitted from the replay input. * * Anything less and the runtime observes that no usable replay preload * came back and falls back to the existing `run_started` setup — a World * that ignores the param entirely remains fully correct. Only meaningful * for `hook_received`; ignored for other event types. Producer-side * `resumeHook()` must not set it. */ preloadEvents?: true; } /** * Result of creating an event. Includes the created event and optionally * the entity that was created or updated as a result of the event, with any updates applied to it. * * Note: `event` is optional to support legacy runs where event storage is skipped. */ export interface EventResult { /** The created event (optional for legacy compatibility) */ event?: Event; /** The workflow run entity (for run_* events) */ run?: import('./runs.js').WorkflowRun; /** The step entity (for step_* events) */ step?: import('./steps.js').Step; /** The hook entity (for hook_created events) */ hook?: import('./hooks.js').Hook; /** The wait entity (for wait_created/wait_completed events) */ wait?: import('./waits.js').Wait; /** * Events with data resolved. Three producers populate this: * * - On a `run_started` response: all events up to this point, so the * runtime can skip the initial `events.list` call and reduce TTFB. * - On a step-terminal write (`step_completed` / `step_failed`) when * the caller passed {@link CreateEventParams.sinceCursor}: the delta * of events written strictly after that cursor, so the inline loop * can skip the per-step incremental `events.list` round-trip. * - On a `hook_received` response when the caller passed * {@link CreateEventParams.preloadEvents}: the run's current replay * log through the canonical `hook_received`, so the lazy hook queue * consumer can skip both the `run_started` write and the initial * `events.list`. */ events?: Event[]; /** Pagination cursor for `events`, matching events.list semantics. */ cursor?: string | null; /** Whether additional event pages are available for `events`. */ hasMore?: boolean; /** * Lazy step start: set to `true` only when a `step_started` event with * step-creation data atomically *created* the step on this call (the * caller won the create-claim), as opposed to transitioning a step that * already existed. The owned-inline runtime path uses this as the * exactly-once ownership signal — it runs the step body inline only when * it created the step, so a concurrent handler that lost the create race * (and gets `EntityConflictError`/skipped) never double-executes. Absent * (undefined) on the legacy path and from older servers/worlds, which is * the safe default (treated as "not the lazy creator"). */ stepCreated?: boolean; /** Server-owned max event count for the run (run-lifecycle responses); the runtime enforces it. */ maxEvents?: number; } export interface GetEventParams { resolveData?: ResolveData; } export interface ListEventsParams { runId: string; pagination?: PaginationOptions; resolveData?: ResolveData; } export interface ListEventsByCorrelationIdParams { correlationId: string; /** * The run the correlation id belongs to. A correlation id is unique per * run, not globally: a slot-numbered run counts its own steps and waits, so * `step_…001` names the first step of *every* such run. Naming the run is * what makes the answer that run's events, and it is what makes the * pagination cursor unambiguous — `(runId, eventId)` is a key where an * event id alone is not. */ runId: string; pagination?: PaginationOptions; resolveData?: ResolveData; } export {}; //# sourceMappingURL=events.d.ts.map