import { type PersistedRunState } from "@automatalabs/workflows"; import type { AgentRunner } from "@automatalabs/shared-types"; import type { ProjectContext } from "./project-registry.js"; import { type WorkflowExecuteToolInput, type WorkflowSetupResponseToolInput } from "./workflow-tool-input.js"; /** Every observation request has a finite transport budget; human input is durable run state. */ export declare const WORKFLOW_REQUEST_BOUND_MS = 45000; /** The server's own ceiling on one preparation (validation, dry run, live probes). */ export declare const WORKFLOW_PREPARATION_BOUND_MS = 120000; export interface WorkflowSetupRequest { id: string; kind: "backend-approval"; title: string; message: string; requestedSchema: { type: "object"; properties: Record; required: string[]; additionalProperties?: false; }; } export type WorkflowSetup = { state: "preparing"; } | { state: "input-required"; request: WorkflowSetupRequest; }; export interface WorkflowSetupRequiredEvent { runId: string; request: WorkflowSetupRequest; } /** * Fired once per setup request, after the run's preparation is durably `input-required`. Process * scope, like the permission broker: preparation is owned by the process executing the run, and * each server instance filters for the runs its own session named. Returns detach. */ export declare function onSetupRequired(listener: (event: WorkflowSetupRequiredEvent) => void): () => void; export declare function canonicalWorkflowJson(value: unknown): string; export declare function boundWorkflowRequest(operation: Promise, ms?: number): Promise; /** * Preparation refused the run before anything was persisted: unreadable source, a script that * fails validation, or no admission capacity. Hosts report it as a tool execution error. */ export declare class WorkflowPreparationRejected extends Error { readonly name = "WorkflowPreparationRejected"; } /** True when preparation stopped because the caller cancelled the request. */ export declare function isPreparationCancelled(error: unknown): boolean; export interface WorkflowPreparationControl { /** Caller cancellation (the MCP request signal). Nothing is persisted once it aborts. */ signal?: AbortSignal; /** Stage progress for the request's progress token, when the client supplied one. */ progress?: (progress: number, total?: number, message?: string) => void; /** * Called synchronously as soon as the run exists (started, or parked in setup) and before any * setup announcement, so the requesting session can register its interest in the run first. */ onAdmitted?: (runId: string) => void; } export type WorkflowPreparationOutcome = { runId: string; setup?: undefined; } /** Validated, but parked in durable setup until the host answers the request. */ | { runId: string; setup: Extract; }; export declare function workflowSetup(state: PersistedRunState | null | undefined): WorkflowSetup | undefined; /** Project-owned driver: it never captures an MCP request or transport beyond one preparation. */ export declare class WorkflowLifecycle { private readonly context; private readonly runner; private readonly driving; private readonly probeRunner; constructor(context: ProjectContext, runner: AgentRunner); /** * Prepare a run inside the caller's request: read the source, validate it (static parse, mock * dry run, live config probes), then either start execution or park the validated run in * durable setup when a declared backend still needs approval. Nothing is persisted before that * point, so a rejection or a cancellation leaves no run behind. */ prepare(input: WorkflowExecuteToolInput, control?: WorkflowPreparationControl): Promise; /** * Read the run's script file back for a continuation. An unchanged or missing file continues * the persisted script. A changed file is a revision: it is validated exactly like a new run * (structure, mocked dry run, routed probes) and may declare only backends the run's admission * already approved, so no continuation can widen what the host accepted at setup. */ prepareRevision(runId: string, persisted: PersistedRunState, control?: Pick): Promise<{ script: string; revised: boolean; }>; recover(runId: string): void; respond(input: WorkflowSetupResponseToolInput): void; private save; private schedule; /** * Continue a parked run after a setup answer: ask for the next unapproved backend, or * re-validate against the current routing state and admit execution on the same run ID. */ private drive; } export declare function workflowLifecycle(context: ProjectContext, runner: AgentRunner): WorkflowLifecycle; //# sourceMappingURL=workflow-lifecycle.d.ts.map