import { type ReactNode } from "react"; /** The fence language an assistant uses for an interactive answer. */ export declare const INTERACTIVE_ANSWER_FENCE = "opengeni-ui"; /** Bounds that keep an answer readable in a chat column and cheap to draw. */ export declare const INTERACTIVE_ANSWER_LIMITS: { readonly items: 60; readonly fields: 12; readonly text: 600; }; export type InteractiveAnswerValue = string | number | boolean | null; export type InteractiveAnswerField = { key: string; label: string; /** Shown with numbers: a currency sign or symbol before ($ € £), anything else after. */ unit?: string | undefined; /** Which end of a numeric field is better; marks the best option. */ better?: "higher" | "lower" | undefined; /** Offer the field's distinct values as filter chips. */ filter?: boolean | undefined; }; export type InteractiveAnswerItem = { id: string; title: string; subtitle?: string | undefined; description?: string | undefined; /** A short highlight such as "Recommended" or "Cheapest". */ badge?: string | undefined; /** An https link to the option. */ url?: string | undefined; values: Record; }; export type InteractiveAnswerView = "cards" | "table"; export type InteractiveAnswerSpec = { title?: string | undefined; items: InteractiveAnswerItem[]; fields: InteractiveAnswerField[]; /** A numeric field drawn as a bar chart above the options. */ chart?: string | undefined; /** How many options the person may pick and the words of the send button. */ select?: { max: number; action?: string | undefined; } | undefined; view: InteractiveAnswerView; /** Items beyond the limit that were left out. */ omitted: number; }; export type InteractiveAnswerParse = { status: "ok"; spec: InteractiveAnswerSpec; } /** Still streaming: the options that have fully arrived so far (may be none). */ | { status: "partial"; spec: InteractiveAnswerSpec | null; } | { status: "invalid"; reason: "json" | "shape" | "unsupported"; }; /** * Parse a fence body. With `partial`, an unfinished body (the assistant is * still writing it) yields the options that have arrived so far instead of an * error, so the answer grows in place while it streams. * A body that already parses whole is complete even if its closing fence * never arrived (an answer that ended without one), so it can still be picked. */ export declare function parseInteractiveAnswer(source: string, options?: { partial?: boolean | undefined; }): InteractiveAnswerParse; /** * Whether a message ends inside an unclosed code fence, and that fence's body. * Read from the message as written, so renderers that parse a rewritten copy * (softened while streaming, math normalized) still know which fence is open. */ export declare function trailingOpenFence(message: string): string | null; /** * The longest prefix of a streaming JSON text that parses once its open * strings, arrays and objects are closed. Cuts back to the last comma or * opening bracket when the tail is a half-written key or literal. */ export declare function parsePartialJson(source: string): unknown; /** A value as text, with its unit. Booleans use the caller's words for yes and no. */ export declare function formatInteractiveValue(field: InteractiveAnswerField | undefined, value: InteractiveAnswerValue | undefined, words: { yes: string; no: string; empty: string; }, locale?: string): string; /** The ids holding the best value of each field that says which end is better. */ export declare function bestInteractiveItems(spec: Pick, items: readonly InteractiveAnswerItem[]): Map>; /** The distinct values a filter field offers, in the order they first appear. */ export declare function interactiveFilterOptions(field: InteractiveAnswerField, items: readonly InteractiveAnswerItem[]): InteractiveAnswerValue[]; export type InteractiveAnswerSort = { key: string; direction: "asc" | "desc"; } | null; export type InteractiveAnswerState = { selected: string[]; /** The selection the person last sent, so the card can say it was sent. */ sent: string[] | null; view: InteractiveAnswerView | null; sort: InteractiveAnswerSort; /** Field key to the values shown; a field without an entry shows everything. */ filters: Record; }; export declare const EMPTY_INTERACTIVE_ANSWER_STATE: InteractiveAnswerState; /** * For an answer that stopped mid-stream: leave out a last option that had only * its title when the stream ended, so a half-written option doesn't stay on * screen as an empty card. Options with any detail are kept. */ export declare function settleInteractiveAnswer(parsed: InteractiveAnswerParse, state: "complete" | "streaming" | "incomplete"): InteractiveAnswerParse; /** The options shown: filtered, then ordered by the chosen column. */ export declare function visibleInteractiveItems(spec: InteractiveAnswerSpec, state: Pick): InteractiveAnswerItem[]; /** The next order for a column: ascending, descending, then back to the agent's order. */ export declare function nextInteractiveSort(current: InteractiveAnswerSort, key: string, field?: InteractiveAnswerField): InteractiveAnswerSort; /** Toggle one option. A single pick replaces; a full multi-pick ignores new ones. */ export declare function toggleInteractiveSelection(selected: readonly string[], id: string, max: number): string[]; /** The send button's words: the agent's own, or the caller's default. */ export declare function interactiveActionLabel(spec: InteractiveAnswerSpec, fallback: string): string; /** * The message a pick sends, in the person's voice: the action, then the * chosen options by name in the order the agent listed them. */ export declare function interactiveSelectionMessage(spec: InteractiveAnswerSpec, selected: readonly string[], fallbackAction: string, locale?: string): string; /** True when the current pick is exactly what was last sent. */ export declare function interactiveSelectionWasSent(state: InteractiveAnswerState): boolean; /** A short stable key for one answer body, used to remember its state. */ export declare function interactiveAnswerKey(source: string): string; /** * Where an answer's picks, filters and view are remembered. Synchronous * stores (the web's localStorage) restore on first paint; asynchronous ones * (a phone's storage) restore as soon as they answer. */ export type InteractiveAnswerStore = { get: (key: string) => string | null | undefined | Promise; set: (key: string, value: string) => void | Promise; }; export type InteractiveAnswerHost = { /** * Send the person's pick as their next message (the composer's ordinary * Send). Without it, options can still be filtered and compared, but there * is no send button. */ send?: ((text: string) => Promise | boolean | void) | undefined; /** Separates remembered state per conversation (a session id). */ scope?: string | undefined; store?: InteractiveAnswerStore | undefined; /** Picks are read-only, for example in a shared or archived conversation. */ readOnly?: boolean | undefined; }; /** Lets interactive answers in this subtree send picks and remember their state. */ export declare function InteractiveAnswerProvider({ children, ...host }: InteractiveAnswerHost & { children?: ReactNode; }): import("react").FunctionComponentElement>; export declare function useInteractiveAnswerHost(): InteractiveAnswerHost; /** * One answer's interaction state, kept apart from the answer itself (which * never changes once written) and remembered in the host's store. Ids that * no longer exist in the answer are dropped. */ export declare function useInteractiveAnswerState(answerKey: string, validIds: readonly string[] | null): [ InteractiveAnswerState, (update: (state: InteractiveAnswerState) => InteractiveAnswerState) => void ]; /** The browser's localStorage as an answer store, when it is usable. */ export declare function browserInteractiveAnswerStore(): InteractiveAnswerStore | undefined;