import { type ClientRequest, type ClientResponse } from "../client/protocol.js"; import { type AttemptClock } from "../state/attempt-time.js"; import { StateDatabase } from "../state/database.js"; import { type JsonValue } from "../state/json.js"; import { WorkflowMessageStore, type WorkflowStepReason } from "../state/workflow-messages.js"; import { type InteractiveRequestRecord } from "../workflows/requests.js"; import type { WorkflowRunnerMessage, WorkflowRunnerResponse } from "./workflow-runner-protocol.js"; export type ServerClaim = { serverId: string; token: string; epoch: number; pid: number; processStartIdentity: string; expiresAt: number; }; export type WorkflowServerStatusRecord = { epoch: number; serverId: string | null; pid: number | null; processStartIdentity: string | null; startedAt: string | null; heartbeatAt: string | null; expiresAt: string | null; live: boolean; }; export type WorkflowRunnerLaunchEnvelope = { schema: "pi-workflows.worker-launch.v1"; runId: string; generation: number; runnerEpoch: string; projectPath: string; workflowSource: JsonValue; definitionDigest: string; inputHash: string; protocolVersion: 1; }; export type RunnerOutcome = "exited" | "cancelled" | "timedOut" | "crashed" | "claimLost" | "orphaned"; export type InteractiveSubmissionRecord = { requestId: string; submissionId: string; idempotencyKey: string; outcome: "validating" | "accepted" | "rejected" | "adopted"; payload: JsonValue; receipt: JsonValue | null; submittedAt: string; }; export declare class ServerStateStore { readonly state: StateDatabase; private readonly ownsState; readonly workflowMessages: WorkflowMessageStore; private readonly attemptTime; constructor(databasePath: string, options?: { state?: StateDatabase; readOnly?: boolean; clock?: AttemptClock; }); close(): void; acquireServer(options: { serverId: string; pid: number; processStartIdentity: string; leaseMs: number; now?: number; }): ServerClaim; renewServer(claim: ServerClaim, leaseMs: number, now?: number): ServerClaim; releaseServer(claim: ServerClaim, _now?: number): boolean; serverStatus(now?: number): WorkflowServerStatusRecord; readCommand(request: ClientRequest): ClientResponse | undefined; adoptCommand(request: ClientRequest): ClientResponse | undefined; executeCommand(request: ClientRequest, serverEpoch: number, operation: () => Omit): ClientResponse; recordRunnerStart(envelope: WorkflowRunnerLaunchEnvelope, serverEpoch: number): void; attachRunnerProcess(runnerEpoch: string, pid: number, processStartIdentity: string): void; markRunnerReady(runnerEpoch: string): void; finishRunner(options: { runnerEpoch: string; outcome: RunnerOutcome; exitCode?: number | null; signal?: string | null; diagnostic?: string; }): void; readRunnerMessage(message: WorkflowRunnerMessage): WorkflowRunnerResponse | undefined; recordRunnerMessage(message: WorkflowRunnerMessage, response: WorkflowRunnerResponse): WorkflowRunnerResponse; createInteractiveRequest(options: { requestId: string; runId: string; attemptId: string; targetSessionId: string; kind: InteractiveRequestRecord["kind"]; contract: JsonValue; }): InteractiveRequestRecord; ensureInteractionMessage(request: InteractiveRequestRecord, reason: WorkflowStepReason, now?: number, reminderTurnId?: string): import("../state/workflow-messages.js").WorkflowMessage; resumePendingInteraction(runId: string, now?: number): InteractiveRequestRecord; syncActiveTime(): void; beginInteractionModelTurn(requestId: string): void; endInteractionModelTurn(requestId: string): void; resumeInteractionModelTurn(runId: string): void; markSessionModelTurnsInactive(targetSessionId: string, now?: number): void; recoverInactiveModelTurns(now?: number): void; resumeSessionModelTurns(targetSessionId: string, now?: number): void; getInteraction(requestId: string): InteractiveRequestRecord | undefined; acceptedInteraction(runId: string): { requestId: string; attemptId: string; nodeId: string; submissionId: string; payload: JsonValue; } | undefined; validatingInteraction(runId: string): { requestId: string; attemptId: string; nodeId: string; submissionId: string; payload: JsonValue; } | undefined; readyInteractionRunIds(): string[]; expiredInteractionRuns(): ExpiredInteractionRunRow[]; timedOutInteraction(runId: string): TimedOutInteractionRow | undefined; interactionSubmission(requestId: string, submissionId: string): InteractiveSubmissionRecord | undefined; finishInteractionValidation(options: { requestId: string; submissionId: string; accepted: boolean; receipt: JsonValue; }): InteractiveSubmissionRecord; listPendingInteractions(sessionId: string): InteractiveRequestRecord[]; listPendingDecisionInteractions(): InteractiveRequestRecord[]; submitInteraction(options: { requestId: string; submissionId: string; idempotencyKey: string; expectedRevision: number; payload: JsonValue; accepted: boolean; receipt?: JsonValue; }): { interaction: InteractiveRequestRecord; submissionId: string; outcome: "accepted" | "adopted"; receipt: JsonValue; }; hasInteractionSubmission(requestId: string, idempotencyKey: string): boolean; beginInteractionValidation(options: { requestId: string; submissionId: string; idempotencyKey: string; expectedRevision: number; payload: JsonValue; receipt?: JsonValue; }): { interaction: InteractiveRequestRecord; submissionId: string; outcome: "accepted" | "adopted"; receipt: JsonValue; }; private serverRow; private commandResponse; private interactiveRequest; private requireInteractiveRequest; } type ExpiredInteractionRunRow = { runId: string; targetSessionId: string; }; type TimedOutInteractionRow = { requestId: string; attemptId: string; nodeId: string; }; export {};