actions/action_event.ts view source
Action event that manages the lifecycle of an action through its state machine.
generics
TMethod
stringstringTPhase
TStep
environment
spec
method narrows to TMethod so consumers passing a typed TApi to
create_rpc_client get event.spec.method typed as the union of
their API's method names rather than plain string. The runtime
value comes from lookup_action_spec(method) keyed off the Proxy
get trap, so the narrowing matches the dispatched method.
type ActionSpecUnion & {method: TMethod}
constructor
type new <TMethod extends string = string, TPhase extends ActionEventPhase = "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute", TStep extends ActionEventStep = "initial" | ... 3 more ... | "failed">(environment: ActionEventEnvironment, spec: { ...; } | ... 1 more ... | { ...; }, data: ActionEventDataUnion<...>): ActionEvent<...>
environment
spec
{ method: string; initiator: "frontend" | "backend" | "both"; side_effects: boolean; input: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; output: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; ... 6 more ...; rate_limit?: "both" | ... 2 more ... | undefined; } | { ...; } | { ...; }data
ActionEventDataUnion<TMethod>toJSON
type (): ActionEventDataUnion<TMethod>
ActionEventDataUnion<TMethod>observe
Subscribe a listener fired on every data transition.
type (listener: ActionEventChangeObserver<TMethod>): () => void
listener
called with (new_data, old_data, event) after each mutation
ActionEventChangeObserver<TMethod>() => voidunsubscribe function
set_data
Replace the event's data and notify observers.
type (new_data: ActionEventDataUnion<TMethod>): void
new_data
ActionEventDataUnion<TMethod>voidparse
Parse input data according to the action's schema.
type (): this
thisthis for chaining with handle_async / handle_sync
Error- if called from a step other than `initial`
handle_async
Execute the handler for the current phase.
type (): Promise<void>
Promise<void>Error- if called from a step other than `parsed` (or `failed`,
handle_sync
Execute handler synchronously (only for sync local_call actions).
type (): void
voidError- if the spec is not a sync `local_call`, or if called
transition
Transition to a new phase.
type (phase: "send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute"): void
phase
the next phase to transition into
"send_request" | "receive_request" | "send_response" | "receive_response" | "send_error" | "receive_error" | "send" | "receive" | "execute"voidError- if called from a step other than `handled` (or
is_complete
type (): boolean
booleanupdate_progress
type (progress: unknown): void
progress
unknownvoidset_request
type (request: { [x: string]: unknown; jsonrpc: "2.0"; id: string | number; method: string; params?: { [x: string]: unknown; } | undefined; }): void
request
{ [x: string]: unknown; jsonrpc: "2.0"; id: string | number; method: string; params?: { [x: string]: unknown; } | undefined; }voidset_response
type (response: { [x: string]: unknown; jsonrpc: "2.0"; id: string | number; result: { [x: string]: unknown; }; } | { [x: string]: unknown; jsonrpc: "2.0"; id: string | number | null; error: { [x: string]: unknown; code: -32700 | -32600 | -32601 | -32602 | -32603 | (number & $brand<...>); message: string; data?: unknown; }; }): void
response
{ [x: string]: unknown; jsonrpc: "2.0"; id: string | number; result: { [x: string]: unknown; }; } | { [x: string]: unknown; jsonrpc: "2.0"; id: string | number | null; error: { [x: string]: unknown; code: -32700 | -32600 | -32601 | -32602 | -32603 | (number & $brand<...>); message: string; data?: unknown; }; }voidset_notification
type (notification: { [x: string]: unknown; jsonrpc: "2.0"; method: string; params?: { [x: string]: unknown; } | undefined; }): void
notification
{ [x: string]: unknown; jsonrpc: "2.0"; method: string; params?: { [x: string]: unknown; } | undefined; }void