import type { StateDatabase } from "./database.js"; import { type JsonValue } from "./json.js"; export declare const WORKFLOW_MESSAGE_SCHEMA: "pi-workflows.workflow-message.v1"; export declare const WORKFLOW_MESSAGE_CONTENT_SCHEMA: "pi-workflows.workflow-message-content.v1"; export declare const WORKFLOW_TURN_SCHEMA: "pi-workflows.workflow-turn.v1"; export type WorkflowMessageKind = "step" | "decision" | "notification" | "terminal" | "followUp"; export type WorkflowMessageStatus = "pending" | "sent" | "cancelled"; export type WorkflowStepReason = "initial" | "resumed" | "reminder"; export type WorkflowTurnState = "started" | "ended"; export type WorkflowTurnStopReason = "completed" | "aborted" | "error" | "lost"; export type WorkflowMessageContent = { schema: typeof WORKFLOW_MESSAGE_CONTENT_SCHEMA; customType: string; content: string; display: boolean; details: JsonValue; triggerTurn: boolean; }; export type WorkflowMessage = { schema: typeof WORKFLOW_MESSAGE_SCHEMA; workflowMessageId: string; runId: string; targetSessionId: string; kind: WorkflowMessageKind; sourceId: string; contentDigest: string; content: WorkflowMessageContent; order: number; status: WorkflowMessageStatus; piSessionEntryId: string | null; createdAt: string; updatedAt: string; }; export type WorkflowTurn = { schema: typeof WORKFLOW_TURN_SCHEMA; workflowTurnId: string; workflowMessageId: string; runId: string; targetSessionId: string; state: WorkflowTurnState; stopReason: WorkflowTurnStopReason | null; responseSessionEntryId: string | null; startedAt: string; endedAt: string | null; }; export type WorkflowBranchEntry = { workflowMessageId: string; piSessionEntryId: string; }; export type CreateWorkflowMessageOptions = { workflowMessageId?: string; runId: string; targetSessionId: string; kind: WorkflowMessageKind; sourceId: string; idempotencyKey: string; content: WorkflowMessageContent; now?: number; }; /** Durable workflow content that the server requires Pi to add to one origin session. */ export declare class WorkflowMessageStore { readonly state: StateDatabase; constructor(state: StateDatabase); create(options: CreateWorkflowMessageOptions): WorkflowMessage; get(workflowMessageId: string): WorkflowMessage | undefined; require(workflowMessageId: string): WorkflowMessage; listSession(targetSessionId: string): WorkflowMessage[]; listRun(runId: string): WorkflowMessage[]; latestForSource(kind: WorkflowMessageKind, sourceId: string): WorkflowMessage | undefined; cancelPendingForSource(sourceId: string, kind?: WorkflowMessageKind, now?: number): number; adoptBranch(targetSessionId: string, entries: readonly WorkflowBranchEntry[], allowedMessageIds: ReadonlySet, now?: number): WorkflowMessage[]; startTurn(options: { workflowMessageId: string; workflowTurnId?: string; runId: string; targetSessionId: string; now?: number; }): WorkflowTurn; endTurn(options: { workflowMessageId: string; workflowTurnId: string; runId: string; targetSessionId: string; stopReason: WorkflowTurnStopReason; responseSessionEntryId?: string | null; now?: number; }): WorkflowTurn; cancelPendingForRun(runId: string, now?: number, kinds?: readonly WorkflowMessageKind[]): number; getTurn(workflowTurnId: string): WorkflowTurn | undefined; requireTurn(workflowTurnId: string): WorkflowTurn; openTurnForMessage(workflowMessageId: string): WorkflowTurn | undefined; latestTurnForMessage(workflowMessageId: string): WorkflowTurn | undefined; openTurnsForSession(targetSessionId: string): WorkflowTurn[]; private mapMessage; } export declare function workflowMessageIdFor(kind: WorkflowMessageKind, sourceId: string, idempotencyKey: string): string; export declare function isWorkflowMessageContent(value: unknown): value is WorkflowMessageContent;