import type { AgentChatMessage, AgentDetails, AgentMetadata, QueuedPrompt } from "../../services/agentService";
import type { AgentStatus } from "../../services/agentStatus";
import type { EditOperation } from "../../../types";
import type { AgentSessionContextWindowState, AgentSessionCostLimitState, AgentSessionState } from "./types";
export interface AgentSessionInitialInput {
    agent?: AgentDetails;
    isLoading?: boolean;
}
export interface AgentSessionSnapshot {
    agent: AgentDetails;
    queuedPrompts?: QueuedPrompt[];
    operationHistory?: EditOperation[];
    metadata?: AgentMetadata | null;
    costLimitExceeded?: AgentSessionCostLimitState | null;
    contextWindowStatus?: AgentSessionContextWindowState | null;
    liveTotals?: AgentSessionState["liveTotals"];
    epoch?: number;
    force?: boolean;
}
export interface AgentSessionUserMessageEcho {
    messageId: string;
    agentId: string;
    content: string;
    timestamp?: string;
    clientMessageId?: string;
    userName?: string;
    messageOrigin?: "user" | "agent" | "trigger";
    sourceAgentName?: string;
    sourceAgent?: {
        name?: string;
    };
    triggerName?: string;
    attachments?: AgentChatMessage["attachments"];
}
export interface AgentSessionToolApprovalResolution {
    messageId: string;
    toolCallId: string;
    approved: boolean;
}
export interface AgentSessionToolApprovalsRequired {
    messageId: string;
    toolCallIds: string[];
}
export interface AgentSessionAssistantContentChunk {
    messageId: string;
    deltaContent?: string | null;
    reasoning?: string | null;
    isIncremental?: boolean;
    previousContentLength?: number;
    totalContentLength?: number;
    createMessage: () => AgentChatMessage;
}
export interface AgentSessionToolCallUpsert {
    targetIndex: number;
    toolCall: NonNullable<AgentChatMessage["toolCalls"]>[number] & {
        dbMessageId?: string;
    };
}
export interface AgentSessionToolCallMessageUpsert {
    messageId: string;
    toolCall: AgentSessionToolCallUpsert["toolCall"];
    createMessage: () => AgentChatMessage;
}
export interface AgentSessionToolResultApply {
    targetIndex: number;
    toolCallId: string;
    fallbackToolCall: NonNullable<AgentChatMessage["toolCalls"]>[number];
}
export interface AgentSessionToolResultMessageApply {
    messageId: string;
    toolCallId: string;
    fallbackToolCall: AgentSessionToolResultApply["fallbackToolCall"];
}
export declare function createInitialAgentSessionState(input?: AgentSessionInitialInput): AgentSessionState;
export declare function normalizeSessionRunId(value: unknown): string | null;
export declare function createOptimisticUserMessage(input: {
    id: string;
    agentId: string;
    content: string;
    createdDate?: string;
    attachments?: AgentChatMessage["attachments"];
}): AgentChatMessage;
export declare function applyAssistantContentChunkToTranscript(transcript: AgentChatMessage[], chunk: AgentSessionAssistantContentChunk): AgentChatMessage[];
export interface ResyncedAssistantContent {
    content: string;
    reasoning: string;
    toolCalls: NonNullable<AgentChatMessage["toolCalls"]>;
}
/**
 * Merge a resynced assistant snapshot into the existing transcript message
 * without ever shrinking what we already have. A resync carries the content
 * buffered on the server at reconnect time; live streaming may have advanced
 * past it, so blindly replacing content/reasoning/toolCalls with the buffered
 * snapshot can truncate newer streamed state. We keep the longer value of each
 * field, mirroring the regression guard in
 * applyAssistantContentChunkToTranscript.
 */
export declare function mergeResyncedAssistantMessage(existing: AgentChatMessage, resync: ResyncedAssistantContent): AgentChatMessage;
export declare function applyHeartbeatMessageToTranscript(transcript: AgentChatMessage[], heartbeatMessage: AgentChatMessage): AgentChatMessage[];
export declare function clearHeartbeatMessagesFromTranscript(transcript: AgentChatMessage[]): AgentChatMessage[];
export declare function completeOpenAssistantMessagesInTranscript(transcript: AgentChatMessage[]): AgentChatMessage[];
export declare function completeOpenStreamingMessagesInTranscript(transcript: AgentChatMessage[]): AgentChatMessage[];
export declare function upsertToolCallInTranscript(transcript: AgentChatMessage[], input: AgentSessionToolCallUpsert): AgentChatMessage[];
export declare function upsertToolCallForMessageInTranscript(transcript: AgentChatMessage[], input: AgentSessionToolCallMessageUpsert): AgentChatMessage[];
export declare function applyToolResultToTranscript(transcript: AgentChatMessage[], input: AgentSessionToolResultApply): {
    transcript: AgentChatMessage[];
    allToolCallsCompleted: boolean;
};
export declare function applyToolResultForMessageInTranscript(transcript: AgentChatMessage[], input: AgentSessionToolResultMessageApply): {
    transcript: AgentChatMessage[];
    allToolCallsCompleted: boolean;
};
export declare function applyToolApprovalsRequiredToTranscript(transcript: AgentChatMessage[], input: AgentSessionToolApprovalsRequired): AgentChatMessage[];
export declare function applyBackendSnapshot(state: AgentSessionState, snapshot: AgentSessionSnapshot): AgentSessionState;
export declare function applySnapshotLoading(state: AgentSessionState): AgentSessionState;
export declare function applySnapshotReady(state: AgentSessionState): AgentSessionState;
export declare function applySnapshotError(state: AgentSessionState, error: string): AgentSessionState;
export declare function addOptimisticUserMessage(state: AgentSessionState, message: AgentChatMessage): AgentSessionState;
export declare function removeOptimisticUserMessage(state: AgentSessionState, messageId: string): AgentSessionState;
/**
 * Collapse transcript entries that share a case-insensitive id, preserving the
 * position of the first occurrence and keeping the richer (longer
 * content+reasoning) copy. The rendered transcript groups consecutive assistant
 * messages and concatenates their bodies, so a duplicate row — e.g. a streamed
 * copy plus a resynced copy whose GUID differs only by casing — would paint the
 * same content twice. mergeMessagesById dedupes on the load path only; this is
 * the equivalent guard for the live transcript. Returns the original array
 * reference when there is nothing to collapse (the common case).
 */
export declare function dedupeTranscriptById(transcript: AgentChatMessage[]): AgentChatMessage[];
export declare function replaceTranscript(state: AgentSessionState, transcript: AgentChatMessage[]): AgentSessionState;
export declare function reconcileServerUserMessage(state: AgentSessionState, echo: AgentSessionUserMessageEcho): AgentSessionState;
export declare function applyServerUserMessageToTranscript(transcript: AgentChatMessage[], echo: AgentSessionUserMessageEcho): AgentChatMessage[];
export declare function applyRunStart(state: AgentSessionState, input?: {
    runId?: unknown;
    agentName?: string;
    profileId?: string;
    profileName?: string;
}): AgentSessionState;
export declare function shouldAcceptRunFrame(state: AgentSessionState, input: {
    runId?: unknown;
    seq?: unknown;
}): boolean;
export declare function acceptRunFrame(state: AgentSessionState, input: {
    runId?: unknown;
    seq?: unknown;
}): AgentSessionState;
export declare function applyRunStatus(state: AgentSessionState, status: AgentStatus, reason?: string | null): AgentSessionState;
export declare function armStopGuard(state: AgentSessionState): AgentSessionState;
export declare function clearStopGuard(state: AgentSessionState): AgentSessionState;
export declare function settleCompletedRun(state: AgentSessionState, input?: {
    finalStatus?: "completed" | "cancelled";
    runId?: unknown;
}): AgentSessionState;
export declare function applyQueuedPromptAdded(state: AgentSessionState, queueEntry: QueuedPrompt): AgentSessionState;
export declare function applyQueuedPromptProcessed(state: AgentSessionState, promptId: string): AgentSessionState;
export declare function replaceQueuedPrompts(state: AgentSessionState, queuedPrompts: QueuedPrompt[]): AgentSessionState;
export declare function applyOperationHistory(state: AgentSessionState, operations: EditOperation[], limit?: number): AgentSessionState;
export declare function replaceOperationHistory(state: AgentSessionState, operationHistory: EditOperation[]): AgentSessionState;
export declare function applyToolApprovalsRequired(state: AgentSessionState, input: AgentSessionToolApprovalsRequired): AgentSessionState;
export declare function applyToolApprovalResolved(state: AgentSessionState, resolution: AgentSessionToolApprovalResolution): AgentSessionState;
export declare function applyToolApprovalResolvedToTranscript(transcript: AgentChatMessage[], resolution: AgentSessionToolApprovalResolution): AgentChatMessage[];
