/** * Chat Widget Registry - Extensible widget system for AI-triggered UI. * * Tool calls from the AI are mapped to registered widgets; each widget * provides render() and onAction(). As of the Preact rewrite, `render` * returns a Preact VNode (JSX) instead of an HTML string — the WidgetSlot * component mounts the returned VNode inside the message bubble. */ import type { VNode } from "preact"; export interface WidgetContext { channelId: string; distinctId: string; primaryColor: string; /** @deprecated Use buildEndpointUrl() instead */ apiBase: string; token: string; /** The ID of the message containing this widget */ messageId: string; /** Build a full URL for a given endpoint path, respecting api_host */ buildEndpointUrl(path: string): string; /** * Dispatch an action for this widget. Provided by the WidgetSlot — calls * `definition.onAction(action, data, context)` and, on `{ success: true }`, * marks the widget as submitted in message metadata so the next render * shows the confirmation UI and (where applicable) triggers an AI follow-up. */ dispatch(action: string, data: Record): Promise; } export interface WidgetActionResult { /** Whether the action succeeded — drives metadata-based re-render */ success?: boolean; } export interface ChatWidgetDefinition { /** Unique type identifier, e.g. "collect_email", "schedule_meeting" */ type: string; /** AI tool description (sent to LLM so it knows when to invoke) */ toolDescription: string; /** JSON schema shape for the tool parameters */ parameters: Record; /** * Returns a Preact VNode rendered inline inside the chat bubble. * * The component should call `ctx.dispatch(action, data)` to submit — * WidgetSlot wires that into `onAction` + the controller's submission * pipeline so widgets only need to render their form. */ render(params: Record, context: WidgetContext): VNode; /** Called when the widget form is submitted or button clicked */ onAction(action: string, data: Record, context: WidgetContext): Promise; } export declare class ChatWidgetRegistry { private _widgets; register(definition: ChatWidgetDefinition): void; get(type: string): ChatWidgetDefinition | undefined; getAll(): ChatWidgetDefinition[]; /** * Build tool definitions for the AI from all registered widgets. */ getToolDefinitions(): Record; }>; }