import * as React from 'react'; import { TrilletRoomDetails } from '../server.js'; import { T as Transcript } from '../TranscriptManager-Bh-JJm_m.js'; /** * Built-in widget copy per language. * * Every visitor-facing string the widget renders on its own lives here, so a site in * German, French or Italian gets a fully localised widget without setting a dozen * text attributes. Explicit text attributes and the saved dashboard design still win * over these defaults (see configFromElement). */ declare const WIDGET_LANGUAGES: readonly ["en", "de", "fr", "it"]; type WidgetLanguage = (typeof WIDGET_LANGUAGES)[number]; interface WidgetCopy { startCallText: string; startChatText: string; endCallText: string; endChatText: string; endConversationText: string; messageText: string; callLabel: string; chatLabel: string; switchToTextText: string; switchToVoiceText: string; listeningText: string; speakingText: string; expandText: string; collapseText: string; recaptchaText: string; inputPlaceholder: string; askAnything: string; /** `{name}` is replaced with the agent or brand name. */ askNamed: string; chooseModePrompt: string; talkToUs: string; connecting: string; online: string; callEnded: string; chatEnded: string; startNewChat: string; /** Always-reachable reset action, live or ended — distinct from "end call". */ startOver: string; backToChat: string; /** `{name}` is replaced with the agent or brand name. */ chatWithNamed: string; chat: string; send: string; close: string; typing: string; muteMic: string; unmuteMic: string; terms: string; termsTitle: string; termsAccept: string; termsDecline: string; feedbackQuestion: string; feedbackThanks: string; errorNotEnabled: string; errorUnavailable: string; errorTooMany: string; errorGeneric: string; feedbackGood: string; feedbackBad: string; openChat: string; minimize: string; typeInstead: string; showConversation: string; talkInstead: string; /** Pre-call dynamic-variables form. */ continueText: string; fieldRequired: string; } type WidgetVariant = 'compact' | 'expanded'; type WidgetVariantInput = WidgetVariant | 'tiny' | 'full'; type WidgetMode = 'voice' | 'text' | 'both'; type WidgetPlacement = 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right'; type WidgetTheme = 'light' | 'dark'; /** * The design saved in the Trillet dashboard (Widget designer), served by * GET /v1/api/web-call/public/widget-config. Every key is optional; HTML attributes * on the element always win over these, so an existing embed keeps rendering exactly * as written. */ type AvatarStyle = 'orb' | 'image' | 'initials'; interface RemoteWidgetConfig { avatarStyle?: AvatarStyle | null; orbColor1?: string | null; orbColor2?: string | null; backgroundColor?: string | null; textColor?: string | null; buttonTextColor?: string | null; termsText?: string | null; feedback?: 'none' | 'end' | null; mode?: WidgetMode; placement?: WidgetPlacement; variant?: WidgetVariant; theme?: WidgetTheme; brandColor?: string | null; brandName?: string | null; brandLogo?: string | null; avatar?: string | null; title?: string | null; launcherText?: string | null; greeting?: string | null; inputPlaceholder?: string | null; startCallText?: string | null; messageText?: string | null; suggestedPrompts?: string[]; /** Widget UI language (en | de | fr | it). Absent: the host page's . */ language?: string | null; /** * Variables collected before a call starts, as the dashboard saves them: 'preset' * entries carry a fixed value, 'prompt' entries are asked of the visitor. This is * what GET /web-call/public/widget-config serves inside `widget`; the widget splits * it locally (see splitDynamicVariableDefs). * * Note these are public: the config endpoint is unauthenticated, so a preset value * is readable by anyone and must never hold a secret. */ dynamicVariables?: DynamicVariableDef[]; } /** A visitor-facing "ask user" dynamic variable, collected before a call starts. */ interface DynamicVariablePrompt { key: string; label?: string; placeholder?: string; required?: boolean; } interface WidgetBrand { logo?: string; primaryColor?: string; name?: string; } /** * Resolved, typed widget configuration. The custom element builds this from HTML * attributes; the React wrapper builds it from props. */ interface WidgetConfig { agentId: string; signedUrlEndpoint?: string; workspaceId?: string; /** API host override (whitelabel API domain, or a local backend in development). */ apiBase?: string; /** Load the dashboard design on mount (default true; `remote-config="false"` opts out). */ remoteConfig: boolean; agentName?: string; callFlowName?: string; workspaceName?: string; /** 'orb' (animated gradient, default), 'image' (avatar URL) or 'initials'. */ avatarStyle?: AvatarStyle; avatar?: string; /** Legacy single accent/orb color; alias of orbColor1. */ orbColor?: string; /** Gradient orb color 1 (convai `avatar-orb-color-1`). */ orbColor1?: string; /** Gradient orb color 2 (convai `avatar-orb-color-2`). */ orbColor2?: string; variant: WidgetVariant; placement: WidgetPlacement; dismissible: boolean; /** Resolved UI language and its built-in copy (see ./i18n). */ language: WidgetLanguage; copy: WidgetCopy; actionText?: string; startCallText: string; endCallText: string; messageText: string; /** Mode "both" launcher: the two halves of the Call | Chat button. */ callLabel: string; chatLabel: string; switchToTextText: string; switchToVoiceText: string; listeningText: string; speakingText: string; expandText: string; collapseText: string; recaptchaText: string; /** Short line shown next to the closed launcher, and under the chat header. */ greeting?: string; inputPlaceholder: string; /** Tap-to-send starter questions, shown until the visitor sends a message. */ suggestedPrompts: string[]; theme: WidgetTheme; /** Colour overrides on top of the theme. Button colour is brand.primaryColor. */ backgroundColor?: string; textColor?: string; buttonTextColor?: string; /** Markdown the visitor must accept before their first conversation. */ termsText?: string; /** 'end': ask for a thumbs up/down when a conversation ends. */ feedback: 'none' | 'end'; mode: WidgetMode; variables?: Record; /** * Fixed values for "preset" dynamic variables, sent with every conversation. Not a * place for secrets: they reach the browser and are readable by the visitor. */ dynamicVariablePresets: Record; /** "Ask user" dynamic variables; the widget renders a form for these before a call starts. */ dynamicVariablePrompts: DynamicVariablePrompt[]; maxCallDuration?: number; /** * Optional Google reCAPTCHA v2 site key. When set, the widget renders a checkbox the * visitor solves once per session before the first conversation starts. * * BYO and client-only: the solved token is never sent to Trillet and never verified, * so this is UI friction, not bot protection. See ./recaptcha.ts. For a real gate, * use the core SDK's `onBeforeCall` hook and verify on your own backend. */ recaptchaSiteKey?: string; /** convai `disable-banner` — accepted no-op (we're blank by default). */ disableBanner: boolean; brand: WidgetBrand; } /** * A single dynamic-variable definition — the same preset/ask-user shape the Widget * Studio and the demo-link editor both save (see trillet-backend's widgetConfig.js). * Arrives either on the `dynamic-variable-defs` attribute or inside the saved design. */ interface DynamicVariableDef { key: string; mode: 'preset' | 'prompt'; value?: string; label?: string; placeholder?: string; required?: boolean; } interface TrilletWidgetProps { agentId: string; signedUrlEndpoint?: string; /** * JS-only: invoked at call-start to mint room details (cannot be an HTML attribute). * Receives the modality being started, so you can mint a voice or a text session. */ getRoomDetails?: (context: { mode: 'voice' | 'text'; }) => Promise | TrilletRoomDetails; /** API host override (whitelabel API domain, or a local backend in development). */ apiBase?: string; /** Load the design saved in the Trillet dashboard (default true). */ remoteConfig?: boolean; /** JS-only: static pre-minted room details. */ roomDetails?: TrilletRoomDetails; workspaceId?: string; agentName?: string; callFlowName?: string; workspaceName?: string; avatar?: string; /** convai alias of `avatar`. */ avatarImageUrl?: string; /** Legacy single accent/orb color; alias of orbColor1. */ orbColor?: string; /** Gradient orb color 1 (convai `avatar-orb-color-1`). */ orbColor1?: string; /** Gradient orb color 2 (convai `avatar-orb-color-2`). */ orbColor2?: string; /** Accepts both our `compact|expanded` and convai's `tiny|compact|full`. */ variant?: WidgetVariantInput; placement?: WidgetPlacement; dismissible?: boolean; actionText?: string; startCallText?: string; endCallText?: string; /** Label for ending a text chat (default from `language`, e.g. "End chat" / "Chat beenden"). */ endChatText?: string; /** UI language for the built-in labels: en | de | fr | it. Default: the page's . */ language?: string; /** Label for the text/chat entry point in mode="both" (default "Message"). */ messageText?: string; switchToTextText?: string; switchToVoiceText?: string; listeningText?: string; speakingText?: string; expandText?: string; collapseText?: string; /** Copy shown above the reCAPTCHA checkbox, when `recaptchaSiteKey` is set. */ recaptchaText?: string; /** Short line shown beside the closed launcher. */ greeting?: string; /** Placeholder in the chat message box. */ inputPlaceholder?: string; /** Tap-to-send starter questions for text chats. */ suggestedPrompts?: string[]; theme?: WidgetTheme; /** "voice" | "text" | "both" (multimodal, user-switchable). */ mode?: WidgetMode; variables?: Record; /** convai alias of `variables`. */ dynamicVariables?: Record; maxCallDuration?: number; /** * Google reCAPTCHA v2 site key. Renders a checkbox the visitor solves once per * session before the first conversation. BYO and client-only — the token is never * sent to Trillet nor verified, so it is UI friction, not bot protection. */ recaptchaSiteKey?: string; /** convai `disable-banner` — accepted no-op (blank by default). */ disableBanner?: boolean; brand?: WidgetBrand; /** Primary. Fires alongside onCallStart. */ onConversationStart?: () => void; /** Primary. Fires alongside onCallEnd. */ onConversationEnd?: (durationSeconds: number) => void; /** @deprecated Use onConversationStart. Still fired for back-compat. */ onCallStart?: () => void; /** @deprecated Use onConversationEnd. Still fired for back-compat. */ onCallEnd?: (durationSeconds: number) => void; onError?: (error: Error) => void; onTranscript?: (transcripts: Transcript[]) => void; className?: string; style?: React.CSSProperties; } declare const TrilletWidget: React.FC; type ActiveMode = 'voice' | 'text'; type SessionMode = 'voice' | 'text' | 'multimodal'; declare class TrilletWidgetElement extends HTMLElement { static get observedAttributes(): readonly string[]; private root; private config; private agent; private state; private open; private micEnabled; private speaking; private transcripts; private display; private activeMode; private switching; private remote; private remoteDisplay; private remoteLoadedFor; private held; getRoomDetails?: (context: { /** The side the conversation starts on. */ mode: ActiveMode; /** Session type to mint: `multimodal` for mode="both" (type or talk). */ session: SessionMode; /** * Presets plus whatever the visitor just entered, resolved for this * conversation. A room minted here is built before the widget can send * anything itself, so a minting endpoint has to forward these as * `dynamic_variables` or the agent never sees them and `{{key}}` stays * literal in the prompt. */ variables: Record; }) => Promise | TrilletRoomDetails; roomDetails?: TrilletRoomDetails; private durationTimer; private remainingSeconds; private elapsedSeconds; private recaptchaSolved; private recaptchaSlot; private recaptchaWidgetId; private styleEl; private container; constructor(); connectedCallback(): void; private refreshConfig; /** * Fetch the design saved in the dashboard. Best-effort: on any failure the widget * keeps rendering from its attributes, exactly as before this existed. */ private loadRemoteConfig; disconnectedCallback(): void; attributeChangedCallback(): void; /** * Send a chat message as the visitor (text sessions). Opens and starts the chat * first when needed; the message is delivered as soon as the session connects. */ sendMessage(text: string): Promise; /** Send now, or behind a message still held for the agent's greeting (TRI-2230). */ private deliver; /** * Imperatively start a conversation. Primary headless API (convai-aligned). * @param modality - optional; only used in `mode="both"` to pick voice vs text. */ startConversation(modality?: ActiveMode): Promise; /** Imperatively end the active conversation. Primary headless API. */ endConversation(): void; /** * Fully reset: tear down any live session (without dispatching its end-of-call * events — this isn't "the conversation ended", it's "forget it happened"), wipe the * transcript, and start a brand new one. Reachable at any time, live or already * ended — unlike {@link endConversation}, which keeps the transcript visible, this * always lands back in a fresh pre-call state so quick-question suggestions and the * dynamic-variables form (if configured) reappear. */ startOver(modality?: ActiveMode): void; /** @deprecated Use {@link startConversation}. Kept as a thin alias for back-compat. */ startCall(): Promise; /** @deprecated Use {@link endConversation}. Kept as a thin alias for back-compat. */ endCall(): void; /** The concrete modality to run for the current session (`both` -> activeMode). */ private resolvedMode; /** Keep activeMode consistent with the configured mode. */ private syncActiveMode; /** Tear down the current agent cleanly: detach listeners, end the call, drop the ref. */ private teardownAgent; /** * Switch between typing and talking (mode="both"). Same session, same conversation: * the SDK turns the mic on/off and asks the agent to turn its speech on/off. If the * mic is refused, the conversation simply stays in text and says why. */ private switchModality; /** * Listening <-> Speaking flips several times a second at turn edges. Patch the few * nodes that show it instead of re-rendering, which would rebuild (and flash) the UI. */ private setSpeaking; private lastView; private notice; private switchingSide; private callGeneration; private beginCall; private wireAgentEvents; private endLocalCall; private handleError; private startDurationTimer; private clearDurationTimer; private setState; private dispatch; private applyTheme; private formatTime; /** The line under the agent's name in the header. */ private statusText; private renderStatus; private timerText; /** * Agent voice level (0..1) from the live audio. Written straight to a CSS variable * on the host, so the presence ring moves with the real voice without re-rendering. */ private setLevel; private smoothedLevel; private render; /** Avatar style: an explicit choice, else the image when one is set, else the orb. */ private avatarStyle; /** * The mark: who the visitor is talking to, as a small rounded tile. A gradient in * the brand colours (default), the business's image, or initials. While the agent * speaks on a call, the tile breathes with the voice level (--tw-level). */ private buildAvatar; /** The name shown to visitors: business name, else the agent/flow name. */ private speakerName; /** Live voice level as five bars (heights follow --tw-level). */ private buildWave; private iconButton; private showTerms; private pendingStart; private callId; private feedbackState; /** Acceptance is remembered per agent and per version of the text. */ private termsKey; private termsAccepted; private termsAcceptedThisPage; private renderTerms; private showVariablesForm; private dynamicVariableValues; private renderVariablesForm; /** "How was this conversation?" thumbs, once, after a conversation ends. */ private renderFeedback; /** * The ask bar: the widget's resting state. * * [mark] Ask Firelink anything… (mic) (send) * * Input-first: typing + Enter opens the chat with that message already sent; the * mic starts a call and the bar becomes the call bar. Voice-only shows "Talk to …" * with a call button; chat-only drops the mic. */ private renderCard; private askFocused; /** Suggested questions just above the ask bar while it has focus. */ private renderAskSuggestions; /** * Open the panel. A text-only widget with no prior conversation starts the chat * straight away, so the agent's welcome is already there when the panel opens, like * any website chat. `both` waits for the visitor to pick call or message. Reopening * never clears anything on its own — an ended conversation's transcript stays put * until the visitor explicitly starts over (see {@link startOver}). */ private openPanel; private renderPanel; /** * The header title identifying who the user is talking to. Each identity value is * code-overridable per value: a static `agent-name`/`call-flow-name`/`workspace-name` * config value takes precedence over the corresponding backend `display.*` value * (which only arrives on `connected`), falling back to it when unset. `brand.name` * is intentionally NOT part of this chain; it renders as the status line pre-call. */ private headerTitle; private renderHeader; /** Start, call and gate screens centre a large avatar in the body. */ private bodyShowsLargeAvatar; /** * True when a `both` widget is idle/ended with no modality chosen and nothing to * show. A finished conversation keeps its thread on screen instead, so ending a call * never hides what was said; the choose-how-to-talk entry comes back only once the * visitor starts over. */ private isBothPreCall; /** True when a site key is configured and this session has not solved it yet. */ private needsRecaptcha; /** * The pre-call gate shown in the panel: prompt, the reCAPTCHA checkbox, and a * disabled start button. The button enables once the checkbox is solved. * * The checkbox itself is projected in via a : reCAPTCHA v2 hangs inside a * shadow root (its anchor iframe never finishes initializing), so the actual widget * is rendered into a LIGHT-DOM node — a child of the host element — that is assigned * to this slot. It therefore *displays* here inside the panel while its DOM home * stays in the light tree, where reCAPTCHA works. */ private renderRecaptchaGate; /** * Create the light-DOM node that hosts the reCAPTCHA checkbox and render the checkbox * into it. Idempotent: every re-render recreates the , but this node (and its * iframe) persists in the light DOM untouched, so the checkbox renders exactly once. */ private ensureRecaptchaSlot; /** Remove the slotted light-DOM checkbox node. Safe to call when none exists. */ private removeRecaptchaSlot; private renderBody; /** Pre-call panel for mode="both": the visitor picks how to talk. */ private renderBothEntry; /** Voice call: the agent's presence (ring follows their voice), status, controls. */ private renderVoiceBody; /** Text/chat UI: conversation thread + message input. */ private renderTextBody; /** Starter questions, shown until the visitor has said something. */ private renderSuggestions; private renderControls; /** * The call bar. Resting (floating) it replaces the ask bar during a call; inside the * chat panel it replaces the composer on the voice side of a type-or-talk chat. * * ||||| Speaking (mic) (💬 / ⌨) (end) * Firelink · 0:42 */ private renderVoiceBar; private errorText; private draft; private renderTextInput; /** Fill a chat thread element with the current messages. */ private fillThread; /** Connecting, or the visitor spoke last and the agent hasn't started answering. */ private isAwaitingReply; /** * Patch just the chat thread (and starter questions) in place. Returns false when * there is no text thread on screen, in which case the caller does a full render. */ private updateThread; /** The chat thread: a fixed-height window that scrolls internally. */ private renderTranscript; } declare const TRILLET_WIDGET_TAG = "trillet-widget"; declare function registerTrilletWidget(tag?: string): void; export { type RemoteWidgetConfig, TRILLET_WIDGET_TAG, TrilletWidget, TrilletWidgetElement, type TrilletWidgetProps, type WidgetBrand, type WidgetConfig, type WidgetMode, type WidgetPlacement, type WidgetTheme, type WidgetVariant, type WidgetVariantInput, registerTrilletWidget };