import { ContractInput, ContractOutput, NeutralSchema } from "./contract.mjs"; import { CanonicalConvexBounds, IdempotencyInvocation, IdempotencyPreparation } from "./idempotency.mjs"; import { FunctionReference, FunctionType, FunctionVisibility } from "convex/server"; import { WorkflowCtx } from "@convex-dev/workflow"; //#region src/modules/contracts/workflow.d.ts export declare class WorkflowBindingError extends Error { readonly _tag = "WorkflowBindingError"; constructor(message: string); } export interface WorkflowExecution { readonly version: 1; readonly operation: string; readonly operationVersion: string; readonly contractVersion: string; readonly bindingVersion: string; /** Host-issued business-run identity. Recovery preserves it. */ readonly run: string; /** Opaque host capability; never caller-supplied principal or tenant authority. */ readonly capability: string; /** Logical occurrence, distinct for each repeated loop step. */ readonly occurrence: string; readonly args: Args; } export type WorkflowStepArguments = { execution: WorkflowExecution; }; /** Strict plain, versioned transport. Validity does not confer authority; the host resolves capability anew. */ export declare function workflowExecution(value: WorkflowExecution): WorkflowExecution; export declare function workflowExecution(value: unknown): WorkflowExecution; export interface WorkflowBinding { readonly kind: Kind; readonly operation: string; readonly operationVersion: string; readonly contractVersion: string; readonly bindingVersion: string; readonly args: Args; readonly result: Result; readonly reference: FunctionReference, FunctionVisibility, WorkflowStepArguments>>, NoInfer>>; /** Host explicitly lists deployed descriptor versions whose semantics remain compatible. */ readonly compatibleVersions?: readonly { operationVersion: string; contractVersion: string; bindingVersion: string; }[]; } /** Both phantom reference args and results must match the explicit wire contracts. */ export declare function workflowBinding(binding: WorkflowBinding): WorkflowBinding; export type WorkflowStepOptions = { name?: string; retry?: NonNullable[0]['retry']>; } & ({ inline?: false; runAt?: number; runAfter?: number; } | { inline: true; runAt?: never; runAfter?: never; }); /** A structural seam allows invocation-scoped native WorkflowCtx without creating another durability runtime. */ export interface WorkflowStepRunner { runQuery?: (reference: FunctionReference<'query', FunctionVisibility>, args: WorkflowStepArguments, options?: WorkflowStepOptions) => Promise; runMutation?: (reference: FunctionReference<'mutation', FunctionVisibility>, args: WorkflowStepArguments, options?: WorkflowStepOptions) => Promise; runAction?: (reference: FunctionReference<'action', FunctionVisibility>, args: WorkflowStepArguments, options?: WorkflowStepOptions) => Promise; } export declare function runWorkflowStep(step: WorkflowCtx | WorkflowStepRunner, binding: WorkflowBinding, input: WorkflowExecution>, options?: WorkflowStepOptions): Promise>; export declare function workflowDecode(schema: S, value: unknown): Promise>; type Ordinary = A | PromiseLike; /** This helper belongs inside a registered native function, never in the replaying workflow handler. */ export declare function workflowAttempt(configuration: { authorize: (execution: WorkflowExecution) => Ordinary; execute: (execution: WorkflowExecution, authority: Authority) => Ordinary; }): (input: WorkflowExecution) => Promise; export type WorkflowOutcome = { readonly version: 1; readonly kind: 'succeeded'; readonly value: Result; } | { readonly version: 1; readonly kind: 'failed'; readonly error: Failure; }; declare const protectedMutation: unique symbol; export interface ReceiptProtectedWorkflowMutation { readonly [protectedMutation]: { args: Args; result: Result; }; readonly handler: (execution: WorkflowExecution) => Promise; } export interface WorkflowReceiptAdapter { readonly replayResult: S; readonly prepare: (invocation: IdempotencyInvocation) => Promise>>; } /** Host registers this handler as the inner native mutation. All callbacks share its transaction. */ export declare function receiptWorkflowMutation(configuration: { authorize: (execution: WorkflowExecution) => Ordinary; receipt: (authority: Authority) => WorkflowReceiptAdapter; invocation: (execution: WorkflowExecution, authority: Authority) => IdempotencyInvocation; execute: (execution: WorkflowExecution, authority: Authority) => Ordinary>; }): ReceiptProtectedWorkflowMutation>; export declare function workflowReceiptInvocation(execution: WorkflowExecution, options: { scope: string; fingerprintPolicy: string; bounds: CanonicalConvexBounds; }): IdempotencyInvocation; type TerminalMode = { kind: 'mutation'; /** Assertion supplied only after host native rollback/journaling acceptance. */ atomicJournalProof: 'host-verified'; } | { kind: 'action'; protectedMutation: ReceiptProtectedWorkflowMutation; }; /** The native inner mutation rejection must cross its transaction boundary before terminal mapping. */ export declare function terminalWorkflowAttempt(configuration: TerminalMode & { authorize: (execution: WorkflowExecution) => Ordinary; invokeMutation: (execution: WorkflowExecution, authority: Authority) => Promise>; terminal: (error: unknown) => Ordinary | undefined>; result: Result; failure: Failure; }): (input: WorkflowExecution) => Promise, ContractOutput>>; export type WorkflowNativeStatus = 'running' | 'succeeded' | 'failed' | 'canceled'; export interface WorkflowHostState { readonly generation: number; readonly status: WorkflowNativeStatus; readonly nativeStatus: WorkflowNativeStatus; readonly outcome?: WorkflowOutcome; } export interface WorkflowHostUpdate { readonly generation: number; readonly nativeStatus: WorkflowNativeStatus; readonly outcome?: WorkflowOutcome; } export type WorkflowTransition = { readonly kind: 'applied' | 'ignored'; readonly state: WorkflowHostState; }; /** Call within a host transaction or compare-and-set. A late operation failure refines host success; cancellation and terminal native status stay fenced. */ export declare function workflowTransition(current: WorkflowHostState, update: WorkflowHostUpdate): WorkflowTransition; export declare function workflowCancel(current: WorkflowHostState, expectedGeneration: number): WorkflowTransition; /** Host calls after an authorized native restart. Receipt identity remains run plus occurrence. */ export declare function workflowRestart(current: WorkflowHostState): WorkflowHostState; /** Host closures capture the trusted run, secured storage and manager. `write` must enforce expected generation atomically. */ export declare function workflowStatusBindings(configuration: { authorize: () => Ordinary; read: () => Ordinary>; write: (expectedGeneration: number, state: WorkflowHostState) => Ordinary; nativeStatus: () => Ordinary; receiptOutcome: () => Ordinary | undefined>; /** Host calls the manager in the same transaction as its guarded state write. */ cancelNative: () => Ordinary; restartNative: () => Ordinary; }): { callback(expectedGeneration: number, nativeStatus: WorkflowNativeStatus, outcome?: WorkflowOutcome): Promise>; reconcile(expectedGeneration: number): Promise>; cancel(expectedGeneration: number): Promise>; restart(expectedGeneration: number): Promise<{ kind: 'ignored'; state: WorkflowHostState; } | { kind: 'applied'; state: WorkflowHostState; }>; }; //#endregion //# sourceMappingURL=workflow.d.mts.map