import type { AgentMessage } from '@earendil-works/pi-agent-core'; import type { TurnOrigin } from '@xopcai/endpoint-tools-protocol'; import type { AgentSourceContext, SourceContextRefSummary } from '../../agent/source-context/types.js'; export type ReplaceLatestSessionTurnInput = { conversationId: string; targetTurnId: string; expectedTranscriptId?: string; controlVersion?: number; clientMessageId: string; content: string; attachments?: unknown[]; contextRefs?: SourceContextRefSummary[]; contextSnapshots?: AgentSourceContext[]; thinking?: string; origin: TurnOrigin; }; type ExternalTurnReplacement = { input: ReplaceLatestSessionTurnInput & { expectedTranscriptId: string; }; state: 'reserved' | 'rolling_back' | 'native_rolled_back' | 'rolled_back'; }; export declare const activeExternalTurnReplacements: Set; export declare function getExternalTurnReplacement(conversationId: string): ExternalTurnReplacement | undefined; export declare function listActiveExternalTurnReplacementConversations(): string[]; export declare function updateExternalTurnReplacement(transcriptId: string, state?: Exclude): void; export type ReplaceLatestSessionTurnResult = { ok: true; idempotent: boolean; inputId: string; removedMessages: AgentMessage[]; remainingMessages: AgentMessage[]; } | { ok: false; code: 'TARGET_NOT_FOUND' | 'NOT_LATEST' | 'SESSION_BUSY'; }; /** Validate before aborting a run; the transactional mutation validates again. */ export declare function validateLatestSessionTurnTarget(conversationId: string, targetTurnId: string, expectedTranscriptId?: string): { ok: true; } | { ok: false; code: 'TARGET_NOT_FOUND' | 'NOT_LATEST'; }; /** * Replace the latest persisted user turn with a durable queued input. * Transcript deletion and input insertion share one SQLite transaction so a * failed enqueue cannot leave the conversation without the original turn. */ export declare function replaceLatestSessionTurnAndQueueInput(input: ReplaceLatestSessionTurnInput, externalPhase?: 'reserve' | 'complete'): ReplaceLatestSessionTurnResult; export {};