import { b as ChatInteractionStatus } from './contract-KfqJh_au.js';

type JsonRecord = Record<string, unknown>;
interface StreamEvent {
    type: string;
    data?: JsonRecord;
}
declare function asRecord(value: unknown): JsonRecord | undefined;
declare function asString(value: unknown): string | undefined;
declare function resolveToolId(part: JsonRecord): string;
declare function resolveToolName(part: JsonRecord): string;
declare function normalizeTime(value: unknown): JsonRecord | undefined;
declare function normalizeToolEvent(event: StreamEvent): StreamEvent;
declare function normalizePersistedPart(rawPart: JsonRecord): JsonRecord | null;
/** Stream/transcript part key for a promoted (path-bearing) attachment,
 *  keyed on its storage path — re-emitting the same path folds into the same
 *  segment instead of duplicating it. */
declare function attachmentPartKey(path: string): string;
declare function getPartKey(part: JsonRecord): string;
declare function mergePersistedPart(existing: JsonRecord | undefined, incoming: JsonRecord, delta?: string): JsonRecord;
declare const MISSING_TOOL_TERMINAL_ERROR = "Tool did not report a terminal result before the assistant turn completed.";
declare const MISSING_TOOL_TERMINAL_REASON = "missing-tool-terminal";
/** Closes a tool part left `running` when a stream ended abnormally: settles
 *  it as a terminal `error` and stamps `state.metadata.terminalized` so the
 *  synthetic settlement is distinguishable from a real tool failure. Parts
 *  that already settled (and non-tool parts) pass through untouched. */
declare function terminalizeDanglingToolPart(part: JsonRecord): JsonRecord;
declare function terminalizeDanglingToolParts(parts: JsonRecord[]): JsonRecord[];
/** Settles still-pending interaction parts at persist time. The broker
 *  guarantees a resolved question either answered (run unblocked, no cancel
 *  event) or cancelled/timed out (cancel event already updated the part), so
 *  the success path finalizes remaining pendings as `answered` and the
 *  failure/terminalize paths as `expired`. */
declare function finalizePendingInteractionParts(parts: JsonRecord[], outcome: Extract<ChatInteractionStatus, 'answered' | 'expired'>): JsonRecord[];
/** Collapses text-part artifacts of unstable upstream segment identity: the
 *  same text arriving under two keys (id-less delta stream, then an
 *  id-bearing snapshot) folds into two segments, and interleaved empty
 *  segments survive as blank parts. Consecutive identical text parts merge
 *  into one; empty text parts drop when any non-empty text part exists. */
declare function collapseRedundantTextParts(parts: JsonRecord[]): JsonRecord[];
declare function finalizeAssistantParts(partOrder: string[], partMap: Map<string, JsonRecord>, finalText: string): JsonRecord[];
/** Finalizes, then folds each synthetic tool settlement back into `partMap`
 *  and returns just those updates — the shape a streaming loop needs to emit
 *  closing `message.part.updated` frames for tools the stream never settled. */
declare function terminalizeDanglingAssistantToolUpdates(partOrder: string[], partMap: Map<string, JsonRecord>, finalText: string): JsonRecord[];
declare function encodeEvent(encoder: TextEncoder, event: StreamEvent): Uint8Array;

export { type JsonRecord as J, MISSING_TOOL_TERMINAL_ERROR as M, type StreamEvent as S, MISSING_TOOL_TERMINAL_REASON as a, asRecord as b, asString as c, attachmentPartKey as d, collapseRedundantTextParts as e, encodeEvent as f, finalizeAssistantParts as g, finalizePendingInteractionParts as h, getPartKey as i, normalizeTime as j, normalizeToolEvent as k, resolveToolName as l, mergePersistedPart as m, normalizePersistedPart as n, terminalizeDanglingToolPart as o, terminalizeDanglingToolParts as p, resolveToolId as r, terminalizeDanglingAssistantToolUpdates as t };
