import { type DbExec } from "../../db/client.js"; import type { AgentChatEvent } from "../types.js"; import type { AgentHarnessRunPolicy } from "./types.js"; export declare const APPROVAL_RESOLUTION_CLAIM_LEASE_MS = 60000; export declare const RESOLVED_APPROVAL_LIMIT = 32; export type AgentHarnessSessionStatus = "running" | "idle" | "stopped" | "errored" | "destroyed"; export declare class AgentHarnessSessionConflictError extends Error { constructor(sessionId: string); } export declare function isAgentHarnessSessionConflictError(error: unknown): error is AgentHarnessSessionConflictError; export interface StoredAgentHarnessSession { id: string; harnessName: string; threadId: string; runId?: string | null; providerSessionId?: string | null; runPolicy?: AgentHarnessRunPolicy | null; status: AgentHarnessSessionStatus; resumeState?: unknown; workspaceRef?: string | null; pendingApproval?: unknown; approvalResolutionId?: string | null; approvalResolutionClaimExpiresAt?: number | null; expiryCleanupId?: string | null; resolvedApprovalIds?: string[]; ownerEmail?: string | null; orgId?: string | null; followUpClaimId?: string | null; followUpId?: string | null; followUpPromptPresent?: boolean; followUpMetadata?: unknown; followUpClaimExpiresAt?: number | null; followUpDeadlineAt?: number | null; followUpDispatchedAt?: number | null; followUpOutcome?: "completed" | "not_dispatched" | "unknown" | null; generation: number; createdAt: number; updatedAt: number; stoppedAt?: number | null; } export interface SaveAgentHarnessSessionInput { id: string; harnessName: string; threadId: string; runId?: string | null; providerSessionId?: string | null; runPolicy?: AgentHarnessRunPolicy | null; status?: AgentHarnessSessionStatus; resumeState?: unknown; workspaceRef?: string | null; pendingApproval?: unknown; approvalResolutionId?: string | null; approvalResolutionClaimExpiresAt?: number | null; expiryCleanupId?: string | null; resolvedApprovalIds?: string[]; ownerEmail?: string | null; orgId?: string | null; followUpClaimId?: string | null; followUpId?: string | null; followUpPromptPresent?: boolean; followUpMetadata?: unknown; followUpClaimExpiresAt?: number | null; followUpDeadlineAt?: number | null; followUpDispatchedAt?: number | null; followUpOutcome?: "completed" | "not_dispatched" | "unknown" | null; stoppedAt?: number | null; expectedGeneration?: number; expectedStatus?: AgentHarnessSessionStatus; expectedFollowUpClaimId?: string; requiresActiveFollowUpClaim?: boolean; expectedApprovalResolutionId?: string | null; expectedExpiryCleanupId?: string | null; requiresNoApprovalResolution?: boolean; requiresActiveApprovalResolution?: boolean; existingSession?: StoredAgentHarnessSession | null; } export interface AgentHarnessSessionGenerationFence { expectedApprovalResolutionId?: string | null; requiresNoApprovalResolution?: boolean; requiresActiveApprovalResolution?: boolean; } export interface AgentHarnessFollowUpIntent { followUpId: string; prompt: string; metadata?: Record; claimLeaseMs: number; deadlineDurationMs: number; } export interface StoredAgentHarnessSessionEvent { operationId: string; seq: number; eventAt: number; transcriptOrder: number | null; event: AgentHarnessSessionJournalEvent; } export type AgentHarnessSessionJournalEvent = AgentChatEvent | { type: "user_input"; text: string; }; export declare const agentHarnessSessionsStore: import("../../db/store-registry.js").Store; export declare function ensureAgentHarnessSessionTables(): Promise; export declare function saveAgentHarnessSession(input: SaveAgentHarnessSessionInput): Promise; export declare function updateAgentHarnessSession(id: string, patch: Partial>): Promise; export declare function updateAgentHarnessSessionIfStatus(id: string, expectedStatus: AgentHarnessSessionStatus, patch: Partial>): Promise; export declare function updateAgentHarnessSessionAtGeneration(id: string, expectedStatus: AgentHarnessSessionStatus, expectedGeneration: number, patch: Partial>, expectedFollowUpClaimId?: string, fence?: boolean | AgentHarnessSessionGenerationFence): Promise; export declare function updateAgentHarnessSessionIfFollowUpClaim(id: string, claimId: string, patch: Partial> | ((existing: StoredAgentHarnessSession) => Partial> | Promise>>), options?: { expectedApprovalResolutionId?: string | null; allowCurrentApprovalResolution?: boolean; requiresNoApprovalResolution?: boolean; }): Promise; export declare function claimAgentHarnessSessionFollowUp(id: string, expectedGeneration: number, claimId: string, intent: AgentHarnessFollowUpIntent): Promise; export declare function markAgentHarnessSessionFollowUpDispatched(id: string, expectedGeneration: number, claimId: string): Promise; export declare function renewAgentHarnessSessionFollowUpClaim(id: string, claimId: string, leaseMs: number): Promise; export declare function persistAgentHarnessFollowUpEvent(sessionId: string, followUpId: string, claimId: string, event: AgentChatEvent, eventAt?: number): Promise; export declare function finalizeAgentHarnessSessionFollowUp(input: { sessionId: string; followUpId: string; claimId: string; expectedGeneration: number; expectedApprovalResolutionId: string | null; resumeState: unknown; pendingApproval: unknown; eventAt?: number; }): Promise; export declare function failAgentHarnessSessionFollowUp(input: { sessionId: string; claimId: string; outcome: "not_dispatched" | "unknown"; errorEvent?: Extract; eventAt?: number; }): Promise; export declare function persistAgentHarnessApprovalEvent(sessionId: string, approvalId: string, event: AgentChatEvent, eventAt?: number): Promise; export declare function claimAgentHarnessSessionApprovalResolution(id: string, approvalId: string, expectedStatus: AgentHarnessSessionStatus, expectedGeneration: number, expectedFollowUpClaimId: string | null): Promise; export declare function renewAgentHarnessSessionApprovalResolutionClaim(id: string, approvalId: string): Promise; export declare function finalizeAgentHarnessSessionApprovalResolution(input: { sessionId: string; approvalId: string; expectedStatus: AgentHarnessSessionStatus; expectedGeneration: number; expectedFollowUpClaimId: string | null; pendingApproval: unknown; resumeState: unknown; resolvedApprovalIds: string[]; eventAt?: number; }): Promise; export declare function failAgentHarnessSessionApprovalResolution(input: { sessionId: string; approvalId: string; errorEvent?: Extract; recordResolvedId?: boolean; eventAt?: number; }): Promise; export declare function releaseAgentHarnessSessionApprovalResolutionBeforeDispatch(input: { sessionId: string; approvalId: string; expectedStatus: AgentHarnessSessionStatus; expectedGeneration: number; expectedFollowUpClaimId: string | null; eventAt?: number; }): Promise; export declare function listExpiredAgentHarnessApprovalResolutions(limit?: number): Promise; export declare function reconcileExpiredAgentHarnessApprovalResolution(sessionId: string, approvalId: string, expectedGeneration: number, eventAt?: number): Promise; export declare function listAgentHarnessSessionEvents(sessionId: string): Promise; export declare function reconcileExpiredAgentHarnessFollowUp(sessionId: string, claimId: string, expectedGeneration: number): Promise; export declare function listExpiredAgentHarnessFollowUps(limit?: number): Promise; export declare function startAgentHarnessSessionFollowUpDispatch(id: string, expectedGeneration: number, claimId: string, start: (assertCurrent: (tx: DbExec) => Promise) => T | Promise): Promise<{ session: StoredAgentHarnessSession; started: T; } | null>; export declare function assertAgentHarnessSessionFollowUpClaimCurrent(tx: DbExec, id: string, generation: number, claimId: string): Promise; export declare function startAgentHarnessSessionApprovalDispatch(id: string, expectedStatus: AgentHarnessSessionStatus, expectedGeneration: number, approvalId: string, start: () => T): Promise<{ session: StoredAgentHarnessSession; started: T; } | null>; export declare function startAgentHarnessSessionExpiryCleanup(id: string, expectedStatus: AgentHarnessSessionStatus, expectedGeneration: number, cleanupId: string, start: () => T): Promise<{ session: StoredAgentHarnessSession; started: T; } | null>; export declare function finishAgentHarnessSessionExpiryCleanup(id: string, cleanupId: string, expectedGeneration: number): Promise; export declare function getAgentHarnessSession(id: string): Promise; export declare function getLatestAgentHarnessSessionForThread(threadId: string, harnessName?: string): Promise; export declare function getAgentHarnessSessionByRunId(runId: string): Promise; export declare function listAgentHarnessSessions(options?: { status?: AgentHarnessSessionStatus; threadId?: string; ownerEmail?: string | null; orgId?: string | null; limit?: number; }): Promise; export declare function markAgentHarnessSessionStopped(id: string, status: Extract): Promise; export declare function markAgentHarnessSessionStoppedIfUnclaimed(id: string, expectedStatus: AgentHarnessSessionStatus, expectedGeneration: number, status: Extract): Promise;