import { StateDatabase } from "../state/database.js"; import type { ControllerStore, EffectReservation, QueueItem, QueueRequeueOptions, WorkflowRecordUpdate, WorkflowReservation } from "./store.js"; import type { ChildWorkflowRecord, ControllerEvent, ControllerQueueClaim, ControllerResource, ControllerResourceRef, ControllerResourceStatus, EffectRecord, JsonObject } from "./types.js"; declare const TURN_INTENT_FACTS_SCHEMA = "pi-workflows.deferred-turn-facts.v1"; export type WorkflowRunLaunchStatus = "queued" | "starting" | "running" | "parked" | "done" | "failed" | "cancelled"; export type WorkflowRunQueueRecord = { runId: string; workflowName: string; workflowSourceRef: string; workflowSource: unknown; initialized: boolean; definitionDigest: string; input: unknown; launchOptions: unknown; status: WorkflowRunLaunchStatus; runnerId: string | null; claimToken: string | null; claimGeneration: number | null; claimExpiresAt: string | null; affinityRunnerId: string | null; originSessionId: string | null; parentRunId: string | null; errorCode: string | null; errorMessage: string | null; createdAt: string; updatedAt: string; startedAt: string | null; finishedAt: string | null; }; export type WorkflowNotificationRecord = { notificationId: string; runId: string; nodeId: string; attemptId: string; notificationIndex: number; targetSessionId: string; kind: "progress" | "final"; content: string; createdAt: string; deliveryClaimExpiresAt: string | null; deliveredAt: string | null; }; export type WorkflowTurnIntentCause = "agentCancelled" | "timedOut" | "failed" | "launchFailed" | "controllerInterrupted" | "claimLost"; export type WorkflowTurnIntentResolution = "workflowPrompt" | "presentation" | "fallback"; export type WorkflowTurnIntentFacts = JsonObject & { schema: typeof TURN_INTENT_FACTS_SCHEMA; workflowName: string; runId: string; observedState: string; cause: WorkflowTurnIntentCause; nodeId: string | null; attemptId: string | null; reason: string | null; handoff: boolean; }; export type WorkflowTurnIntentRecord = { intentId: string; sourceEventId: string; runId: string; workflowRef: string; targetSessionId: string; cause: WorkflowTurnIntentCause; nodeId: string | null; attemptId: string | null; fallbackFacts: WorkflowTurnIntentFacts; requestedAt: string; eligibleAt: string | null; resolvedAt: string | null; resolution: WorkflowTurnIntentResolution | null; resolutionMessageId: string | null; deliveryClaimExpiresAt: string | null; }; export type RunEventRecord = { seq: number; recordedAt: string; runId: string; workflowRef: string; type: string; runnerId: string | null; payload: JsonObject; }; export declare class SqliteControllerStore implements ControllerStore { readonly filePath: string; readonly state: StateDatabase; private readonly ownsState; private readonly projectId; private closed; constructor(filePath?: string, options?: { readOnly?: boolean; projectPath?: string; state?: StateDatabase; }); close(): void; putResource(options: { controller: string; key: string; spec: TSpec; initialStatus: TStatus; now?: string; }): ControllerResource; getResource(ref: ControllerResourceRef): ControllerResource | undefined; getResourceByUid(uid: string): ControllerResource | undefined; listResources(options?: { controller?: string; }): ControllerResource[]; updateStatus(options: { ref: ControllerResourceRef; expectedResourceVersion: number; claim: ControllerQueueClaim; status: ControllerResourceStatus; finalizers?: string[]; now?: string; }): ControllerResource; requestDeletion(ref: ControllerResourceRef, nowValue?: string): ControllerResource; updateFinalizers(options: { ref: ControllerResourceRef; expectedResourceVersion: number; finalizers: string[]; now?: string; }): ControllerResource; deleteResource(ref: ControllerResourceRef, expectedResourceVersion: number, claim: ControllerQueueClaim): boolean; enqueue(ref: ControllerResourceRef, availableAt?: string): void; claimNext(options: { controllers: string[]; ownerId: string; leaseMs: number; now?: string; }): ControllerQueueClaim | undefined; renewClaim(claim: ControllerQueueClaim, leaseMs: number, nowValue?: string): boolean; settleClaim(claim: ControllerQueueClaim, nowValue?: string): boolean; requeueClaim(claim: ControllerQueueClaim, options: QueueRequeueOptions, nowValue?: string): boolean; listQueue(): QueueItem[]; reserveEffect(options: { key: string; resourceUid: string; claim: ControllerQueueClaim; generation: number; kind: string; requestFingerprint: string; now?: string; }): EffectReservation; getEffect(resourceUid: string, key: string): EffectRecord | undefined; updateEffect(options: { resourceUid: string; key: string; claim: ControllerQueueClaim; state: EffectRecord["state"]; externalRef?: string; error?: string; now?: string; }): EffectRecord; listEffects(resourceUid: string): EffectRecord[]; reserveWorkflow(options: { resourceUid: string; claim: ControllerQueueClaim; requestKey: string; workflow: string; inputFingerprint: string; }): WorkflowReservation; getWorkflow(resourceUid: string, requestKey: string): ChildWorkflowRecord | undefined; getWorkflowByRequestId(requestId: string): ChildWorkflowRecord | undefined; updateWorkflow(requestId: string, update: WorkflowRecordUpdate, claim: ControllerQueueClaim): ChildWorkflowRecord; completeWorkflow(requestId: string, update: WorkflowRecordUpdate): ChildWorkflowRecord; listWorkflows(resourceUid: string): ChildWorkflowRecord[]; recordEvent(options: { controller: string; key: string; claim?: ControllerQueueClaim; type: string; payload?: JsonObject; now?: string; }): ControllerEvent; listEvents(options?: { controller?: string; key?: string; limit?: number; }): ControllerEvent[]; reserveWorkflowRun(options: { runId: string; workflowName: string; workflowSourceRef: string; workflowSource: unknown; definitionDigest: string; definitionSnapshot: unknown; input: unknown; launchOptions?: unknown; runnerId: string; originSessionId: string; parentRunId?: string; now?: string; }): WorkflowRunQueueRecord; enqueueWorkflowRun(options: { runId: string; workflowName: string; workflowSourceRef: string; workflowSource: unknown; definitionDigest: string; definitionSnapshot: unknown; input: unknown; launchOptions?: unknown; runnerId: string; claimToken: string; leaseMs: number; originSessionId: string; parentRunId?: string; now?: string; }): WorkflowRunQueueRecord; getWorkflowRun(runId: string): WorkflowRunQueueRecord | undefined; listWorkflowRuns(options?: { statuses?: WorkflowRunLaunchStatus[]; excludeRunIds?: string[]; limit?: number; }): WorkflowRunQueueRecord[]; findSessionReservation(sessionId: string): WorkflowRunQueueRecord | undefined; claimWorkflowRun(options: { runId: string; runnerId: string; claimToken: string; leaseMs: number; now?: string; }): WorkflowRunQueueRecord | undefined; markWorkflowRunRunning(options: { runId: string; claimToken: string; now?: string; }): boolean; claimNextWorkflowRun(options: { runnerId: string; sessionId?: string; claimToken: string; leaseMs: number; now?: string; excludeRunIds?: string[]; }): WorkflowRunQueueRecord | undefined; renewWorkflowRunClaim(options: { runId: string; claimToken: string; leaseMs: number; now?: string; }): boolean; verifyWorkflowRunClaim(options: { runId: string; claimToken: string; now?: string; }): boolean; workflowRunAuthority(runId: string, claimToken: string): { actor: { type: "session" | "host"; id: string; }; ownerType: "session" | "host"; ownerId: string; token: string; generation: number; } | undefined; parkWorkflowRun(options: { runId: string; claimToken: string; now?: string; }): boolean; failWorkflowRun(options: { runId: string; claimToken?: string; errorCode: string; errorMessage: string; now?: string; }): boolean; cancelWorkflowRun(options: { runId: string; claimToken?: string; now?: string; }): boolean; deleteWorkflowRun(options: { runId: string; claimToken: string; }): boolean; completeWorkflowRun(options: { runId: string; claimToken: string; now?: string; }): boolean; repairCanonicalWorkflowSourceRun(): never; claimLegacyWorkflowSourceRun(): never; recordRunEvent(options: { runId: string; workflowRef: string; type: string; payload?: JsonObject; runnerId?: string; now?: string; }): RunEventRecord; listRunEventsAfter(seq: number, options?: { limit?: number; }): RunEventRecord[]; ensureWorkflowTurnIntent(options: { intentId: string; sourceEventId: string; runId: string; workflowRef: string; targetSessionId: string; cause: WorkflowTurnIntentCause; nodeId?: string | null; attemptId?: string | null; fallbackFacts: WorkflowTurnIntentFacts; eligible: boolean; requestedAt?: string; }): WorkflowTurnIntentRecord; getWorkflowTurnIntent(intentId: string): WorkflowTurnIntentRecord | undefined; findPendingWorkflowTurnIntent(options: { runId: string; targetSessionId: string; }): WorkflowTurnIntentRecord | undefined; claimWorkflowTurnIntent(options: { intentId: string; targetSessionId: string; claimToken: string; leaseMs: number; now?: string; }): WorkflowTurnIntentRecord | undefined; claimEligibleWorkflowTurnIntents(options: { targetSessionId: string; claimToken: string; leaseMs: number; now?: string; limit?: number; }): WorkflowTurnIntentRecord[]; makeWorkflowTurnIntentEligible(options: { intentId: string; fallbackFacts: WorkflowTurnIntentFacts; eligibleAt?: string; now?: string; }): boolean; resolveWorkflowTurnIntent(options: { intentId: string; targetSessionId: string; claimToken: string; resolution: WorkflowTurnIntentResolution; messageId?: string; now?: string; }): boolean; releaseWorkflowTurnIntentClaim(options: { intentId: string; targetSessionId: string; claimToken: string; }): boolean; listWorkflowTurnIntents(options?: { runId?: string; targetSessionId?: string; unresolvedOnly?: boolean; limit?: number; }): WorkflowTurnIntentRecord[]; enqueueWorkflowNotification(options: { runId: string; nodeId: string; attemptId: string; notificationIndex: number; targetSessionId: string; kind: "progress" | "final"; content: string; now?: string; }): WorkflowNotificationRecord; claimPendingWorkflowNotifications(options: { targetSessionId: string; claimToken: string; leaseMs: number; now?: string; limit?: number; }): WorkflowNotificationRecord[]; markWorkflowNotificationDelivered(options: { notificationId: string; targetSessionId: string; claimToken: string; now?: string; }): boolean; settleRunEffect(runId: string, effectType: "run.park_queue" | "run.settle_queue"): void; setWorkflowRunOriginSession(runId: string, originSessionId: string): boolean; private ensureProject; private findProject; private requireProjectId; private controllerRow; private requireControllerRow; private requireControllerRowByUid; private requireResource; private mapControllerResource; private finalizers; private replaceFinalizers; private enqueueControllerRow; private queueErrors; private queueVersion; private settleControllerClaim; private assertControllerClaim; private requireLease; private releaseLease; private resourceRevision; private bumpResource; private insertEvent; private effectRow; private requireEffectRow; private mapEffect; private effectKey; private workflowRow; private workflowRowById; private requireWorkflowRow; private mapWorkflow; private workflowRunRow; private requireWorkflowRunRow; private requireWorkflowRun; private mapWorkflowRun; private claimRun; private updateClaimedRunStatus; private releaseRunClaim; private terminalRun; private turnIntent; private requireTurnIntent; private turnIntentRow; private turnIntentBySource; private mapTurnIntent; private claimEffectForTurn; private claimEffect; private verifyEffectToken; private releaseEffectLease; private completeEffect; private insertEffectResource; private notification; private requireNotification; private notificationRows; private notificationRowById; private mapNotification; private assertWritable; } export {};