import { parseUserTurnDocument, type SecretRequestView, type SessionInputControlCommand } from '@xopcai/gateway-contract'; import type { TurnOrigin } from '@xopcai/endpoint-tools-protocol'; import type { ConnectionWait } from '@xopcai/gateway-contract'; import { type SessionInput } from '../../storage/sqlite/session-input-repository.js'; import type { UserTurnAttachment } from '../user-turn-input.js'; import { type AgentSourceContext, type TurnContextRef } from '../../agent/source-context/types.js'; import { type SessionInputDelivery, type SessionInputState } from '../../storage/sqlite/index.js'; import type { GatewayPrincipal } from '../security/gateway-principal.js'; export type SubmitSessionInput = { controlVersion?: number; expectedTranscriptId?: string; conversationId: string; clientMessageId: string; delivery: SessionInputDelivery; /** False explicitly defers a Personal AI message or requests cooperative steering. */ interrupt?: boolean; content: string; attachments?: UserTurnAttachment[]; contextRefs?: TurnContextRef[]; sourceContexts?: AgentSourceContext[]; thinking?: string; origin: TurnOrigin; }; type ReplaceTurnFailure = { ok: false; code: 'BAD_REQUEST' | 'TARGET_NOT_FOUND' | 'NOT_LATEST' | 'SESSION_BUSY' | 'CONTEXT_UNAVAILABLE' | 'ROLLBACK_FAILED'; message?: string; }; export type ReplaceLatestTurnInput = SubmitSessionInput & { targetTurnId: string; }; export declare class SessionInputCoordinator { private readonly deps; private readonly pendingSubmissions; private readonly resumeAfter; private readonly draining; private readonly submissionTails; private readonly pendingConnectionStops; private readonly activeRunSettlements; constructor(deps: { prioritizeInput?: (input: SubmitSessionInput) => boolean; interrupt?: (conversationId: string, runId: string, reason?: 'connection_cancel' | 'user_stop') => Promise; coalesceWindowMs?: number; onInputReceived?: (conversationId: string) => void; beforeExecute?: (input: SessionInput) => Promise; continueConnection?: (wait: ConnectionWait, idempotencyKey: string) => Promise; cancelConnection?: (wait: ConnectionWait) => void; onSecretRequestsUpdated?: (requests: SecretRequestView[]) => void; sessionExists: (conversationId: string) => Promise; execute: (input: { inputReceivedAtMs?: number; inputIdentity: { inputId: string; clientMessageId: string; }; runId: string; taskRunId?: string; conversationId: string; content: string; attachments?: UserTurnAttachment[]; sourceContexts?: AgentSourceContext[]; thinking?: string; origin: TurnOrigin; }) => Promise<{ status: string; summary: string; }>; prepareAttachments: (conversationId: string, attachments?: UserTurnAttachment[]) => Promise; prepareContexts: (conversationId: string, contextRefs?: TurnContextRef[]) => Promise; steer: (conversationId: string, content: string, runId?: string, options?: { attachments?: UserTurnAttachment[]; sourceContexts?: AgentSourceContext[]; voiceAgentInstruction?: boolean; clientMessageId?: string; userTurnDocument?: NonNullable>; onHandled?: () => void; }) => Promise; emit: (type: string, payload: unknown) => void; }); control(conversationId: string, command: SessionInputControlCommand): Promise; isAcceptingInput(conversationId: string): boolean; snapshot(conversationId: string): SessionInputState; resumeBrowser(conversationId: string, waitId: string, options?: { embeddedBrowserGrantId?: string; }): void; private connectionTarget; prepareInput(input: SubmitSessionInput): Promise<{ payload?: import("../../storage/sqlite/session-input-repository.js").SessionInputPayload | undefined; status: "queued"; requestedDelivery: SessionInputDelivery; effectiveDelivery: "next"; content: string; attachments: UserTurnAttachment[] | undefined; contextRefs: import("../../agent/source-context/types.js").SourceContextRefSummary[]; interruptRequested: boolean; contextSnapshots: AgentSourceContext[]; thinking: string | undefined; origin: { type: "endpoint"; endpointId: string; } | { type: "channel"; channel: string; } | { type: "system"; source: "automation" | "cli" | "task" | "heartbeat" | "internal" | "task_update"; }; }>; dispatchAcceptedInput(conversationId: string, inputId: string): Promise; private prioritizeAcceptedInput; private publish; private runSubmissionExclusive; withSubmission(conversationId: string, operation: () => Promise): Promise; submit(input: SubmitSessionInput): Promise<{ ok: true; effectiveDelivery: SessionInputDelivery; state: SessionInputState; } | { ok: false; code: 'BAD_REQUEST' | 'QUEUE_FULL' | 'CONTEXT_UNAVAILABLE' | 'SESSION_CHANGED'; }>; /** Atomically verify the conversation is idle and submit an input inside the exclusive lock. */ submitIfIdle(input: SubmitSessionInput, getBusyReason: () => Reason | null): Promise<{ ok: true; effectiveDelivery: SessionInputDelivery; state: SessionInputState; sessionInputId?: string; } | { ok: false; code: 'SESSION_BUSY'; skipReason: Reason; } | { ok: false; code: 'BAD_REQUEST' | 'QUEUE_FULL' | 'CONTEXT_UNAVAILABLE' | 'SESSION_CHANGED'; }>; replaceLatestTurn(input: ReplaceLatestTurnInput, beforeReplace: (allowAbort: boolean) => Promise, actor?: GatewayPrincipal): Promise<{ ok: true; effectiveDelivery: 'next'; state: SessionInputState; } | ReplaceTurnFailure>; private cleanupReplacedTurn; /** A lost provider reply leaves rollback uncertain and requires a session reset. */ private recoverExternalReplacement; private submitLocked; deliverDelegatedTaskSteer(conversationId: string, inputId: string): Promise; private steerInput; drain(conversationId: string): Promise; private requestConnectionStop; private completeConnectionCancellation; private executeConnectionControl; update(conversationId: string, id: string, body: { version: number; content?: string; attachments?: UserTurnAttachment[]; contextRefs?: TurnContextRef[]; thinking?: string; position?: number; }): Promise<{ ok: boolean; state: SessionInputState; contextUnavailable?: boolean; }>; remove(conversationId: string, id: string, version: number): { ok: boolean; state: SessionInputState; }; waitForCompletion(conversationId: string, clientMessageId: string): Promise; recover(): void; } export {};