import { InteractionField, InteractionRequest, InteractionData } from '@tangle-network/agent-interface';

/** Sidecar → client: the agent raised an ask; data = `{ request }`. */
declare const INTERACTION_EVENT: "interaction";
/** Sidecar → client: the ask was withdrawn; data = `{ id, reason? }`. */
declare const INTERACTION_CANCEL_EVENT: "interaction.cancel";
/** An ask was answered; data = `{ id, status }`. In the wire contract so a
 *  server broadcast and a client-local mark share one event name. */
declare const INTERACTION_RESOLVED_EVENT: "interaction.resolved";
declare function isRenderableInteractionKind(kind: string): boolean;
/** Answer/field keys the sidecar will accept: identifier-safe and never a
 *  prototype-pollution vector. */
declare function isSafeInteractionFieldKey(key: string): boolean;
type ChatSelectField = Extract<InteractionField, {
    type: 'select';
}> & {
    allowCustom?: boolean;
};
type ChatInteractionField = Exclude<InteractionField, {
    type: 'select';
}> | ChatSelectField;
/** `InteractionRequest` whose select fields may carry `allowCustom`. */
type InteractionRequestWire = Omit<InteractionRequest, 'answerSpec'> & {
    answerSpec: {
        fields: ChatInteractionField[];
    };
};
type ChatInteractionStatus = 'pending' | 'answered' | 'declined' | 'cancelled' | 'expired';
/** Accepted field selections keyed by answer-spec field name. */
/** Accepted answer values. Select fields historically used `string[]`; the
 * wider scalar union is additive and lets durable stores preserve text,
 * numeric, and boolean answer fields without coercion. */
type InteractionAnswerValue = string | number | boolean | string[];
type InteractionAnswers = Record<string, InteractionAnswerValue>;
type ParseInteractionAnswersResult = {
    succeeded: true;
    value: InteractionAnswers;
} | {
    succeeded: false;
    error: string;
};
/** Strictly validates and copies persisted answer selections. */
declare function parseInteractionAnswers(value: unknown): ParseInteractionAnswersResult;
/** The client/persisted view of one ask. `fields` come verbatim off the wire. */
interface ChatInteraction {
    id: string;
    kind: string;
    title: string;
    body?: string;
    fields: ChatInteractionField[];
    status: ChatInteractionStatus;
    /** Accepted selections, restored with the transcript after reload. */
    answers?: InteractionAnswers;
    /** Set when status came from an `interaction.cancel` (e.g. "timeout"). */
    cancelReason?: string;
}
declare function isTerminalInteractionStatus(status: ChatInteractionStatus): boolean;
/** Statuses only move forward (pending → terminal); a replayed/stale `pending`
 *  must never resurrect a resolved card. */
declare function canTransitionInteractionStatus(from: ChatInteractionStatus, to: ChatInteractionStatus): boolean;
/** Maps an `interaction.cancel` reason to the card's terminal status. */
declare function cancelStatusFor(reason: string | undefined): ChatInteractionStatus;
/** Content identity for duplicate safety nets. Excludes volatile ids/statuses. */
declare function questionInteractionContentSignature(interaction: ChatInteraction): string | null;
declare function dedupeQuestionInteractionsByContent(interactions: ChatInteraction[]): ChatInteraction[];
type ParseInteractionResult = {
    succeeded: true;
    value: InteractionRequestWire;
} | {
    succeeded: false;
    error: string;
};
/** Parses an `interaction` event's data (`{ request }`). Validates the shape
 *  with the agent-interface schema but returns the raw request so a field a
 *  pinned schema predates (`allowCustom`) survives. */
declare function parseInteractionRequest(data: Record<string, unknown> | undefined): ParseInteractionResult;
interface InteractionCancelData {
    id: string;
    reason?: string;
}
declare function parseInteractionCancel(data: Record<string, unknown> | undefined): {
    succeeded: true;
    value: InteractionCancelData;
} | {
    succeeded: false;
    error: string;
};
declare function fieldAcceptsFreeText(field: ChatInteractionField): boolean;
interface ComposerAnswerDelivery {
    interactionId: string;
    field: ChatInteractionField;
}
/** One delivery per pending ask: the first free-text-capable field, else the
 *  first field. Zero-field asks are skipped (nothing to carry the text). */
declare function composerAnswerDeliveries(pending: ChatInteraction[]): ComposerAnswerDelivery[];
/** Shapes composer text into the respond payload for the routed field
 *  (select answers are string arrays on the wire; text answers are strings). */
declare function composerAnswerData(field: ChatInteractionField, text: string): InteractionData;
declare function interactionPartKey(id: string): string;
declare function noticePartKey(id: string): string;
type NoticeKind = 'warning' | 'auto-declined';
/**
 * Persisted-part shapes the codecs below produce — the SAME rows
 * `/chat-store`'s `ChatInteractionPart`/`ChatNoticePart` store, typed at the
 * source so a product pushing them into a `ChatMessagePart[]` transcript needs
 * no cast. Type aliases (not interfaces) on purpose: the implicit index
 * signature keeps them assignable to the `Record<string, unknown>` these
 * codecs previously returned, so existing consumers stay source-compatible.
 */
type InteractionPersistedPart = {
    type: 'interaction';
    id: string;
    kind: string;
    title: string;
    body?: string;
    answerSpec: {
        fields: ChatInteractionField[];
    };
    status: ChatInteractionStatus;
    answers?: InteractionAnswers;
    cancelReason?: string;
};
type NoticePersistedPart = {
    type: 'notice';
    id: string;
    noticeKind: NoticeKind;
    text: string;
};
/** Builds the persisted/streamed `notice` part — a one-line transcript notice
 *  explaining an out-of-band event (warning, auto-declined interaction). */
declare function noticePart(noticeKind: NoticeKind, id: string, text: string): NoticePersistedPart;
/** Reads a wire request into the client's pending `ChatInteraction`. */
declare function interactionFromWireRequest(request: InteractionRequestWire): ChatInteraction;
/** Builds the persisted/streamed `interaction` part from a wire request. */
declare function interactionToPersistedPart(request: InteractionRequestWire, status: ChatInteractionStatus, cancelReason?: string, answers?: InteractionAnswers): InteractionPersistedPart;
/** Stamps accepted values onto matching persisted interaction parts without
 * mutating the caller's transcript or answer maps. */
declare function stampInteractionAnswers(parts: Array<Record<string, unknown>>, answersByInteractionId: Readonly<Record<string, InteractionAnswers>>): Array<Record<string, unknown>>;
/** Reads a persisted/streamed `interaction` part back into a `ChatInteraction`.
 *  Returns null (caller logs) when the part is not one of ours. */
declare function persistedPartToInteraction(part: Record<string, unknown>): ChatInteraction | null;

export { noticePartKey as A, parseInteractionAnswers as B, type ChatInteraction as C, parseInteractionCancel as D, parseInteractionRequest as E, persistedPartToInteraction as F, questionInteractionContentSignature as G, stampInteractionAnswers as H, INTERACTION_CANCEL_EVENT as I, type NoticeKind as N, type ParseInteractionAnswersResult as P, type ChatInteractionField as a, type ChatInteractionStatus as b, type ChatSelectField as c, type ComposerAnswerDelivery as d, INTERACTION_EVENT as e, INTERACTION_RESOLVED_EVENT as f, type InteractionAnswerValue as g, type InteractionAnswers as h, type InteractionCancelData as i, type InteractionPersistedPart as j, type InteractionRequestWire as k, type NoticePersistedPart as l, type ParseInteractionResult as m, canTransitionInteractionStatus as n, cancelStatusFor as o, composerAnswerData as p, composerAnswerDeliveries as q, dedupeQuestionInteractionsByContent as r, fieldAcceptsFreeText as s, interactionFromWireRequest as t, interactionPartKey as u, interactionToPersistedPart as v, isRenderableInteractionKind as w, isSafeInteractionFieldKey as x, isTerminalInteractionStatus as y, noticePart as z };
