import { type AssistantPreviewState } from "./assistant-preview"; import type { RuntimeEvent, ThreadSummaryEvent } from "@agents24/client"; import { type ContextCompression, type ContextWindow } from "@agents24/client/protocol"; import type { AgentChatRunState, ChatMessage, StoredChatThread } from "./model"; export type AgentChatOperation = "attach_run" | "cancel_run" | "delete_thread" | "load_more_threads" | "load_older_turns" | "open_thread" | "refresh_threads" | "resume_hitl" | "set_feedback" | "submit"; export type AgentChatOperationError = { kind: "operation"; operation: AgentChatOperation; cause: unknown; }; export type AgentChatBackgroundError = { kind: "background"; source: "thread_events"; cause: unknown; }; export type AgentChatState = { assistantPreview?: AssistantPreviewState | null; threads: StoredChatThread[]; activeThreadId: string | null; messages: ChatMessage[]; activeRunId: string | null; cursor: number | null; streamingMessageId: string | null; contextWindow: ContextWindow | null; contextCompression: ContextCompression | null; contextCompressionRevision: number; runState: AgentChatRunState; /** Fatal chat initialization/session failures only. */ error: unknown; /** The latest user-visible operation failure. It must not replace the transcript. */ operationError: AgentChatOperationError | null; /** Failure of a non-blocking background synchronization lane. */ backgroundError: AgentChatBackgroundError | null; }; export declare const initialAgentChatState: AgentChatState; export type AgentChatThreadSelectionSnapshot = Pick; export declare function captureAgentChatThreadSelection(state: AgentChatState): AgentChatThreadSelectionSnapshot; export declare function restoreAgentChatThreadSelection(state: AgentChatState, snapshot: AgentChatThreadSelectionSnapshot): AgentChatState; export declare function withAgentChatOperationError(state: AgentChatState, operation: AgentChatOperation, cause: unknown): AgentChatState; export declare function clearAgentChatOperationError(state: AgentChatState, operation?: AgentChatOperation): AgentChatState; export declare function withAgentChatBackgroundError(state: AgentChatState, cause: unknown): AgentChatState; export declare function clearAgentChatBackgroundError(state: AgentChatState): AgentChatState; /** * Reconcile the authoritative first page without dropping a locally-created * active thread before it becomes visible in the server's list projection. */ export declare function reconcileRefreshedThreads(current: StoredChatThread[], incoming: StoredChatThread[], activeThreadId: string | null, concurrentEvents?: readonly ThreadSummaryEvent[]): StoredChatThread[]; export declare function preferNewestThreadSummary(current: StoredChatThread | undefined, incoming: StoredChatThread): StoredChatThread; /** Adopt the server-created thread without reloading the in-memory transcript. */ export declare function adoptStreamingThread(state: AgentChatState, threadId: string): AgentChatState; export type StableChatMessageBase = { id: string; role: "user" | "assistant"; runId?: string | null; }; export type StableAssistantUpsertInput = { baseMessages?: TMessage[]; create: () => TMessage; messageId?: string | null; runId?: string | null; strictMessageId?: boolean; update: (message: TMessage) => TMessage; }; export declare function appendStableStreamingTurn(messages: TMessage[], userMessage: TMessage, assistantMessage: TMessage): TMessage[]; /** Keep mounted display keys while matching only durable IDs and run linkage. */ export declare function preserveMountedMessageIds(canonical: ChatMessage[], current: ChatMessage[]): ChatMessage[]; /** Reconcile a durable timeline without replacing a newer live assistant segment. */ export declare function reconcileThreadTimeline(current: ChatMessage[], canonical: ChatMessage[], activeRunId: string | null, streamingMessageId: string | null): ChatMessage[]; /** Older pages add history without replacing already mounted or live messages. */ export declare function prependThreadTimeline(current: ChatMessage[], older: ChatMessage[]): ChatMessage[]; /** Bind the durable ID and place the queued user before its reply, if already attached. */ export declare function promoteThreadMessage(current: ChatMessage[], message: ChatMessage, runId: string): ChatMessage[]; export declare function upsertStableAssistantMessage(messages: TMessage[], input: StableAssistantUpsertInput): TMessage[]; export declare function applyRuntimeEvent(state: AgentChatState, event: RuntimeEvent): AgentChatState; export declare function applyRuntimeEvents(state: AgentChatState, events: readonly RuntimeEvent[]): AgentChatState; export declare function applyThreadSummaryEvent(threads: StoredChatThread[], event: ThreadSummaryEvent): StoredChatThread[];