/************************** * Workflow Client * * High-level API for interacting with workflows **************************/ import type { PendingApproval, PendingEventWait, RunFilter, WorkflowDefinition, WorkflowRun, WorkflowStatus } from "../types.js"; import { type WorkflowBackend } from "../backends/types.js"; import { type WorkflowRunEventObservation } from "../events.js"; import { WorkflowExecutor, type WorkflowExecutorConfig, type WorkflowHandle } from "../executor/workflow-executor.js"; import { ApprovalManager, type ApprovalManagerConfig } from "../runtime/approval-manager.js"; import { EventWaitManager, type EventWaitManagerConfig, type PublishEventOutcome } from "../runtime/event-wait-manager.js"; export type { PublishEventOutcome }; import type { Workflow } from "../dsl/workflow.js"; /** Configuration used by workflow client. */ export interface WorkflowClientConfig { /** Backend for persistence (default: MemoryBackend) */ backend?: WorkflowBackend; /** Executor configuration */ executor?: Partial; /** Approval manager configuration */ approval?: Partial; /** Event wait manager configuration */ eventWait?: Partial>; /** Enable debug logging */ debug?: boolean; } /** Supported observation stream or an explicit unsupported-backend result. */ export type WorkflowRunEventsResult = ({ supported: true; } & WorkflowRunEventObservation) | { supported: false; reason: "unsupported"; }; /** Implement workflow client. */ export declare class WorkflowClient { private backend; private executor; private approvalManager; private eventWaitManager; private debug; /** Wait-node configs from registered definitions, keyed "::". */ private waitNodeConfigs; /** Registered response schemas keyed by a durable definition-path identity. */ private responseSchemas; constructor(config?: WorkflowClientConfig); private createEventWaitFromPersistedInput; private createApprovalFromPersistedInput; register(workflow: Workflow | WorkflowDefinition): void; /** * Index every wait node under its runtime node id and registered-definition path. * * `responseSchema` is a live object and cannot be persisted on an approval. * Persisting the definition-path identity lets a later process recover the * exact registered schema even when a parent wait and a static sub-workflow * wait share a runtime node id. Each static wait gets a definition-local config * clone that carries its own path through execution, so one reused config * object cannot overwrite another path. The node-id index remains the * compatibility fallback for approvals created before definition-path * identities existed. * Static sub-workflows are indexed under the registering workflow's id * because their approvals belong to the parent run. * * A workflow or loop whose `steps` is a function is not walked: the node list * depends on runtime input/iteration state, so no schema can be recovered * from the definition after a process restart. During execution, the exact * runtime config supplies expiry, approvers, and response validation. */ private indexWaitNodeConfigs; registerAll(workflows: Array): void; start(workflowId: string, input: TInput, options?: { runId?: string; }): Promise>; resume(runId: string, expectedWorkerId?: string): Promise; retry(runId: string): Promise; cancel(runId: string): Promise; /** Read a run, including the approvals it is currently waiting on. */ getRun(runId: string): Promise; listRuns(filter?: RunFilter): Promise; getRunsByStatus(status: WorkflowStatus | WorkflowStatus[], limit?: number): Promise; getRunsForWorkflow(workflowId: string, limit?: number): Promise; getPendingApprovals(runId: string): Promise; approve(runId: string, approvalId: string, approver: string, comment?: string, data?: unknown): Promise; reject(runId: string, approvalId: string, approver: string, comment?: string, data?: unknown): Promise; /** * Deliver an event to one run, releasing any `waitForEvent` node parked on * that name. * * The event is buffered durably for the run first, so publishing before the * node parks is safe: the wait consumes it as soon as it exists. The outcome * says which of the four things happened, because "no wait was released" * covers cases a caller has to react to differently: `"delivered"`, * `"buffered"`, `"run-terminal"` (the run is over and the event was * discarded), or `"delivery-failed"` (a wait matched, delivery failed, and * both were rolled back so `retryEventDelivery` can retry the same envelope * without appending a duplicate). * * Rejects when the run's mailbox is full of events no wait has claimed, in * preference to dropping one of them. */ publishEvent(runId: string, eventName: string, payload?: unknown): Promise; /** * Retry the oldest buffered event with this name after `publishEvent` * returned `"delivery-failed"`, without appending a second envelope. * Resolves with whether that exact buffered envelope was delivered. */ retryEventDelivery(runId: string, eventName: string): Promise; /** Read the event waits a run is currently parked on. */ getPendingEventWaits(runId: string): Promise; listAllPendingApprovals(filter?: { workflowId?: string; approver?: string; }): Promise>; /** Open an ordered event observation, or report unsupported custom backends explicitly. */ observeRunEvents(runId: string, options?: { signal?: AbortSignal; }): Promise; getBackend(): WorkflowBackend; getExecutor(): WorkflowExecutor; getApprovalManager(): ApprovalManager; getEventWaitManager(): EventWaitManager; destroy(): Promise; } /** Create workflow client. */ export declare function createWorkflowClient(config?: WorkflowClientConfig): WorkflowClient; //# sourceMappingURL=workflow-client.d.ts.map