@helpai/elements 6.9.0 → 6.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/configurator.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{useEffect as e,useLayoutEffect as t,useMemo as n,useRef as r,useState as i}from"preact/hooks";import{z as a}from"zod";import{createPortal as o}from"preact/compat";import{Fragment as s,jsx as c,jsxs as l}from"preact/jsx-runtime";const u=a.object({url:a.string().min(1).max(2048).describe(`Public URL of the image. Must be a full URL or root-relative path.`),alt:a.string().min(1).max(200).optional().describe(`Alt text for screen readers. Omit only for purely decorative images.`)}).strict().describe(`A single image asset (logo, hero, icon).`),d=a.object({id:a.string().min(1).max(100).optional().describe(`Stable id: the Preact key, the analytics target, and how its translations find it.`),label:a.string().min(1).max(120).describe(`Visible link text.`),href:a.string().min(1).max(2048).optional().describe(`Click target. Optional — when omitted the link renders as a non-clickable heading.`),icon:a.string().min(1).max(100).optional().describe(`Built-in icon preset name (chat / spark / message / help / wand) or a custom string.`),description:a.string().min(1).max(300).optional().describe(`Subtitle shown below the label. Used by link cards in page mode.`)}).loose().describe(`A navigation link / link card.`),f=a.string().min(1).max(120).describe("Any CSS length — `640px`, `80vh`, `calc(100vh - 64px)`, etc. Validated only for size, not syntax."),p=a.string().min(1).max(120).describe("Any CSS colour — hex, `rgb()`, `hsl()`, `oklch()`, a named colour, or a `var(--token)`."),m=a.string().min(1).max(35).describe("BCP-47 locale tag (e.g. `en`, `fr-CA`, `zh-Hant-HK`)."),h=a.uuidv7().describe(`UUID v7 (RFC 9562) — the single id format for visitor / conversation / message / file / content ids.`),g=a.object({name:a.string().max(120).optional().describe('The persona visitors chat with, such as `Bea`. May be an i18n key resolved against `i18n.strings`. Set, a labelled launcher with no `label` reads "Ask Bea" in the visitor\'s language.'),title:a.string().max(200).optional().describe(`The line under the name in the chat header. May be an i18n key.`),avatar:a.url({protocol:/^https?$/}).max(2048).optional().describe(`The persona's picture, a rounded square in the chat header. Unset = the name's initials.`)}).loose().describe(`The assistant persona: its name, subtitle and picture in the chat header.`).meta({examples:[{name:`Bea`,title:`Store assistant`,avatar:`https://cdn.example.com/bea.png`}]}),_=a.enum([`normal`,`expanded`,`fullscreen`,`auto`]),v=a.object({enabled:a.boolean().default(!0).describe("Show a resize handle (default on): a corner grip on the floating panel, the inner edge of a drawer. Hidden in every other mode and on phones, where the panel is edge to edge. `false` turns it off."),minWidth:f.optional().describe("Smallest width the user can drag the panel to. Default `320px`."),maxWidth:f.optional().describe(`Largest width the user can drag the panel to.`),minHeight:f.optional().describe("Smallest height the user can drag the floating panel to. Default `400px`."),maxHeight:f.optional().describe(`Largest height the user can drag the floating panel to.`)}).loose().describe("Drag-resize controls. While `enabled` (the default), visitors resize the floating panel from its corner or a drawer from its inner edge, by pointer or arrow keys, within the min/max bounds; the size is remembered.").meta({examples:[{enabled:!1},{enabled:!0,minWidth:`320px`,maxWidth:`720px`,minHeight:`400px`,maxHeight:`90vh`}]}),y=a.object({width:f.optional().describe("Panel width (CSS length). Mode-specific defaults — floating `380px`, modal `min(960px, 92vw)`, drawer `clamp(440px, 32vw, 640px)`. Set this to override; inline/standalone/page modes ignore it."),height:f.optional().describe("Panel height (CSS length). Mode-specific defaults — floating `600px`, modal `min(720px, 88vh)`, drawer `100vh` (clamped to `100vh − inset-y × 2`). Set this to override."),expanded:a.object({width:f.optional().describe(`Width when the user clicks the expand button.`),height:f.optional().describe(`Height when the user clicks the expand button.`)}).loose().optional().describe("Dimensions when the panel is in its `expanded` tier (between normal and fullscreen). Applies to floating / modal / drawer; ignored in inline / standalone / page where the panel always fills its parent."),resize:v.optional().describe(`Drag-resize controls — a corner grip on the floating panel, the inner edge of a drawer.`),inset:f.optional().describe("Drawer-mode edge inset — gap from each viewport edge (top/bottom/left/right). Single value applied to all four sides. Defaults to `3vh` vertical / `12px` horizontal. Use `0` for a full-edge drawer (no gap), or `5vh` for a centered-looking flyout with extra breathing room. Ignored by every other mode."),initialSize:_.default(`auto`).describe("Which size tier to open with on the first mount: `normal` / `expanded` / `fullscreen` / `auto`. Default `auto` is responsive by viewport: phones (< 640 px) open `fullscreen` edge-to-edge, tablets (640 px … `autoSizeBreakpoint`) open `normal`, and desktop/laptop (≥ `autoSizeBreakpoint`) open `expanded` — so the panel is right for the device out of the box. Set a literal to pin one tier everywhere; the user's own resize is remembered per-device and wins on reload."),autoSizeBreakpoint:a.number().int().min(0).max(1e4).default(900).describe("Viewport width (px) at/above which `initialSize: auto` opens `expanded` instead of `normal`. (Phones below 640 px always open `fullscreen`.)")}).loose().describe("Panel dimensions and drawer inset. Width/height override the mode-specific defaults (floating compact popover, modal centered dialog, drawer flyout). `inset` only affects drawer mode.").meta({examples:[{width:`420px`,height:`640px`},{width:`min(560px, 92vw)`,height:`min(640px, 90vh)`},{width:`420px`,expanded:{width:`640px`,height:`780px`},initialSize:`auto`,autoSizeBreakpoint:900},{width:`min(1100px, 95vw)`,height:`min(820px, 92vh)`},{width:`360px`,inset:`8vh`},{width:`420px`,height:`100vh`,inset:`0`},{width:`420px`,height:`60vh`,inset:`20vh`}]}),b=a.enum([`floating`,`inline`,`standalone`,`page`,`modal`,`drawer`]),x=a.enum([`bottom-right`,`bottom-left`,`top-right`,`top-left`]),S=a.object({mode:b.default(`floating`).describe("Rendering shape. `floating` (FAB + popover), `inline` (in-flow block), `standalone` (full viewport), `page` (sidebar + chat), `modal` (centered overlay), `drawer` (side dock)."),position:x.optional().describe("Anchor corner. `floating` uses it for the FAB; `drawer` uses the `*-left` / `*-right` suffix to pick the dock side. Unset is Automatic: bottom-right, or bottom-left when the chat reads right to left. A set corner is fixed. Ignored in other modes."),size:y.optional().describe("Panel dimensions. Mode-aware defaults (floating compact popover, modal centered dialog, drawer flyout) — fields here override them. Includes `inset` (drawer flyout gap), `expanded` tier, drag-resize grip.")}).loose().describe(`Layout fundamentals — mode, anchor corner, panel size + drawer inset.`).meta({examples:[{mode:`floating`,position:`bottom-right`},{mode:`modal`,size:{width:`min(1100px, 95vw)`,height:`min(820px, 92vh)`}},{mode:`drawer`,position:`bottom-right`},{mode:`drawer`,position:`top-right`,size:{width:`360px`,inset:`8vh`}},{mode:`drawer`,position:`bottom-right`,size:{width:`420px`,height:`100vh`,inset:`0`}}]}),ee=a.enum([`streaming`,`buffered`]),te=a.object({startMinimized:a.boolean().default(!0).describe("Don't auto-open the floating panel on first visit. `true` (default) shows the FAB collapsed; `false` opens the panel on mount."),responseMode:ee.default(`streaming`).describe("How the assistant's reply arrives. `streaming` (default) types tokens as they generate; `buffered` waits + shows the full reply at once."),showReasoning:a.boolean().default(!1).describe(`Show the model's reasoning ("thoughts") as a collapsible block above each answer. \`false\` (default) hides it — a loading indicator still shows while the model works. Reasoning is absent from durable history, but the current turn's short-lived resume backlog may replay it after an immediate reconnect or reload.`),stepDisplay:a.object({showSteps:a.boolean().optional().describe(`Every step the AI takes (a search, an order) appears as one folded line under the reply. Off: only the steps that involve the visitor.`),stepDetails:a.enum([`none`,`values`,`table`,`json`,`table-and-json`]).optional().describe("What an opened step shows: `none` (the step line alone; a step waiting on a decision still shows its values), `values` (quiet label and value lines, no ids), `table` (tables of what it ran on and what came back, ids included), `json` (its raw input and result), `table-and-json` (the tables, with the JSON folded under Raw data)."),showStepSystem:a.boolean().optional().describe(`The system that ran a step follows its name, such as "Cancel an order · BC Co. shop".`),showDecidedBy:a.boolean().optional().describe(`Each approval says who decided it, and steps the rules decided show as steps. Off: a rules decision shows only its outcome; the visitor's own choice always shows.`),foldApprovals:a.boolean().optional().describe(`A decided approval folds into the steps line. Off: it stays in the reply as a card.`)}).optional().describe("How the AI's steps and approvals show. Unset keys take the Simple preset: steps, system and who decided off, step details `values`, approvals folded. An approval always shows what it will do."),showSources:a.boolean().default(!1).describe("Show the citation sources behind an answer (web links + document/file references) in the transcript. `false` (default) hides them."),disableMessageFeedback:a.boolean().default(!1).describe("Turn OFF the 👍/👎 feedback controls under each rateable reply (AI or operator). Unset/`false` = shown (default), `true` = hidden. A choice fires the `messageFeedback` event and is POSTed best-effort to `/pai/message-feedback`."),autoSendSuggestions:a.boolean().default(!1).describe("Auto-send a suggestion chip's text the moment it's tapped. `false` (default) fills the composer with the text so the visitor can edit before sending; `true` sends it immediately."),cardAnswerWaitSeconds:a.number().int().min(0).max(600).default(60).describe("How long a message the visitor queued while a reply streamed waits, after that reply ends on a card (an approval or questions), for the visitor to answer the card first. `60` (default); `0` sends it at once. The message always goes: a card never blocks it."),popOutUrl:a.string().trim().min(1).max(2048).optional().describe("URL opened by the `popOut` header action. The widget adds the active conversation, widget, and deployment identity as query parameters.")}).loose().describe(`Conversation behaviour — lifecycle, streaming, and the transcript surface (scroll, feedback).`).meta({examples:[{startMinimized:!0,responseMode:`streaming`},{startMinimized:!1,responseMode:`buffered`,disableMessageFeedback:!0}]}),C=a.enum([`auto`,`light`,`dark`,`host`]),ne=a.object({mode:C.optional().describe("Light/dark beside the token overrides: `host` (the default: the page's own light/dark, flipping with the site's toggle, else the OS), `auto` (the OS), `light` or `dark`."),accent:p.optional().describe(`Brand accent colour. Drives the FAB, send button, links, and active states. CSS colour.`),accentText:p.optional().describe(`Foreground colour rendered ON the accent (FAB icon, send-button glyph). CSS colour.`),radius:f.optional().describe("Corner radius for the panel + buttons. CSS length (`8px`, `0.75rem`, `12px`)."),fontFamily:a.string().min(1).max(200).optional().describe("Font stack used inside the widget. Standard CSS `font-family` value."),contentMaxWidth:f.optional().describe("Max width of the readable content column (messages, history, home, composer) on a wide surface — content centres, full-bleed bars keep their edges. CSS length; default `768px`. Set `100%` to fill the surface (no cap). Modal + drawer already fill their card by default.")}).loose().describe(`Theme token overrides. Any field left unset falls through to the brand's default theme.`).meta({examples:[{accent:`#10b981`,radius:`12px`},{accent:`#7c3aed`,accentText:`#ffffff`,radius:`16px`,fontFamily:`'Inter', system-ui`},{accent:`oklch(0.7 0.2 145)`,radius:`0.5rem`},{accent:`#5b5bd6`,contentMaxWidth:`960px`}]}),w=a.union([C,ne]).describe(`'host' | 'auto' | 'light' | 'dark', or a tokens override object.`).meta({examples:[`host`,`dark`,{accent:`#10b981`,radius:`12px`},{accent:`#7c3aed`,accentText:`#fff`,radius:`16px`,fontFamily:`'Inter', system-ui`}]}),re=a.enum([`circle`,`pill`,`bar`,`minimal`]),ie=a.enum([`sm`,`md`,`lg`]),ae=a.enum([`pill`,`bubble`,`callout`]),oe=a.enum([`auto`,`horizontal`,`vertical`]),se=a.object({text:a.string().min(1).max(500).default(`👋 Hi! Need any help?`).describe("The message to show in the bubble. Defaults to a friendly greeting; replace with your own copy (e.g. 'Click here →'). May also be an i18n key (e.g. `launcherCallout`) resolved against `i18n.strings` for per-locale copy; a non-key literal renders as-is."),shape:ae.default(`pill`).describe("Visual shape — `pill` (slim label + arrow), `bubble` (speech-bubble tail), `callout` (loud variant)."),position:oe.default(`auto`).describe("Where the bubble sits relative to the FAB. `auto` (default) picks the side facing into the page. `horizontal` anchors beside the FAB (left/right depending on the FAB's corner). `vertical` anchors above/below the FAB. Concrete left/right/top/bottom is derived from the FAB's corner so the bubble always stays on-screen."),delayMs:a.number().int().min(0).max(6e4).default(1200).describe(`How long to wait after page load before the bubble appears, in milliseconds.`),autoDismissMs:a.number().int().min(0).max(6e5).default(0).describe("Auto-hide the bubble after this many milliseconds. `0` (default) keeps it until the user dismisses."),animated:a.boolean().default(!0).describe("Subtle horizontal nudge to draw the eye. Disabled automatically by `prefers-reduced-motion`."),persistent:a.boolean().default(!0).describe("How dismissals stick. `true` (default) — re-show on every visit regardless of prior dismissal (the 'recurring greeting' behaviour). `false` — clicking X stores the message text and that exact message stays hidden across visits (the 'one-time hint' behaviour).")}).loose().describe(`Pre-engagement message bubble next to the FAB. Use it for a greeting ('Hi, need help?'), an attention-grabbing nudge ('Click here →'), or any one-time onboarding tip — same component, configured for the use case.`),ce=a.object({variant:re.default(`circle`).describe("FAB visual style. `circle` — round bubble (icon only). `pill` — icon + label. `bar` — wide rectangular button. `minimal` — text-only outline."),size:ie.default(`md`).describe(`FAB size preset — small / medium / large.`),label:a.string().max(200).optional().describe("Text rendered on the FAB (only shown for `pill` / `bar` / `minimal` variants)."),icon:a.string().max(8e3).optional().describe("Icon shown on the FAB / drawer edge tab. Built-in presets: `chat` / `message` / `bubbles` / `spark` / `wand` / `bot` / `help` / `lifebuoy` / `headset`. Anything else is treated as raw SVG."),hidden:a.boolean().default(!1).describe("Hide the FAB entirely (page brings its own trigger that calls `instance.open()`)."),callout:se.optional()}).loose().describe(`Floating-launcher (FAB) appearance and behaviour. The FAB is the round button in the corner that opens the chat panel. Floating mode, and drawer mode as its edge tab.`).meta({examples:[{variant:`circle`,size:`md`},{variant:`pill`,label:`Ask AI`,icon:`spark`},{variant:`circle`,callout:{text:`👋 Need help?`,shape:`bubble`,persistent:!0}},{variant:`circle`,callout:{text:`Click to start`,shape:`pill`,delayMs:1200}}]}),le=a.enum([`local`,`server`,`disabled`]),ue=a.object({disableFileUpload:a.boolean().default(!1).describe("Turn OFF file uploads — hide the paperclip button + reject drag/drop/paste. Unset/`false` = enabled (default), `true` = disabled."),voice:le.default(`local`).describe("Voice input mode. `local` — speech recognition built into the browser (Web Speech API, free). `server` — record audio + upload to the transcribe endpoint. `disabled` — hide the mic button."),disableHumanInLoop:a.boolean().default(!1).describe("Turn OFF the human-in-the-loop tool UI — the inline ask-questions form + approve/reject controls for gated tools. Unset/`false` = shown (default), `true` = suppressed (the wire still carries the signals)."),disableEmailTranscript:a.boolean().default(!1).describe('Turn OFF the "Email transcript" item in the conversation menu, which emails a copy of the conversation to an address the visitor confirms (prefilled with the one the widget knows). Unset/`false` = shown once the chat has a real turn (default), `true` = hidden.'),enableOperatorRequest:a.boolean().default(!1).describe("Opt IN operator control — expose the 'Talk to a person' affordance + connected-to-operator states for this deployment. Unset/`false` = off (default), `true` = on. Unlike the `disable*` flags this is a positive opt-in for a new capability."),hideRequestOperatorButton:a.boolean().default(!1).describe("Hide the 'Talk to a person' button while operator requests stay on: visitors ask the AI for a person and its `request-operator` tool brings one in. Unset/`false` = shown (default), `true` = hidden.")}).loose().describe(`Capability flags — file upload, voice mode, HITL, email transcript, and operator requests.`).meta({examples:[{voice:`local`},{disableFileUpload:!0,voice:`disabled`},{voice:`server`,enableOperatorRequest:!0}]}),de=a.enum([`clear`,`expand`,`fullscreen`,`popOut`,`sound`,`history`,`language`,`theme`,`textSize`,`close`]),fe=a.array(de).max(10).describe("Which actions the header exposes. `history` + `close` are dedicated buttons; the rest appear in the ⋯ menu. Unlisted actions are hidden; order is irrelevant. Pick from: `clear`, `expand`, `fullscreen`, `popOut`, `sound`, `history`, `language`, `theme`, `textSize`, `close`. Per-mode defaults live in `DEFAULT_ACTIONS_BY_MODE`.").meta({examples:[[`theme`,`history`,`close`,`clear`,`fullscreen`,`sound`,`language`],[`theme`,`history`,`clear`,`language`],[`close`]]}),pe=a.object({actions:fe.optional().describe(`Which header actions are enabled (history/✕ buttons + ⋯ menu).`),variant:a.enum([`plain`,`accent`]).default(`plain`).describe("Header fill. `plain` uses the panel surface; `accent` fills it with the theme accent and its readable text colour (adaptive in light and dark)."),notice:a.string().max(1e3).optional().describe("Notice at the top of every conversation, in Markdown: links open in a new tab. May be an i18n key resolved against `i18n.strings`, so it can read in each language. Blank = the built-in \"You're chatting with an AI assistant.\" (`chatNotice`) in the visitor's language."),hideNotice:a.boolean().default(!1).describe("Turn OFF the conversation notice. Unset/`false` = shown (default), `true` = hidden.")}).loose().describe(`Panel-header configuration: actions, fill and the conversation notice.`).meta({examples:[{actions:[`theme`,`history`,`close`,`clear`,`fullscreen`]},{variant:`accent`,notice:`You're chatting with our AI assistant. See our [privacy policy](https://example.com/privacy).`},{hideNotice:!0}]}),T=a.enum([`messageReceived`,`messageSent`,`error`,`voiceStart`,`voiceStop`]),me=a.object({enabled:a.boolean().default(!0).describe(`Master on/off for audible notifications. On by default — browser autoplay policy still requires a prior user gesture before any sound plays.`),volume:a.number().min(0).max(1).default(.3).describe("Global volume 0..1. `0.3` (default) is intentionally subtle."),events:a.partialRecord(T,a.union([a.boolean(),a.string().min(1).max(2048)])).optional().describe("Per-event override map. Value: `true` = built-in tone, `false` = silent, `string` = URL to a custom audio file (mp3/wav/ogg).")}).loose().describe("Audible notifications. `events` accepts true (default tone), false (off), or a URL to an audio file.").meta({examples:[{enabled:!0,volume:.3},{enabled:!0,volume:.5,events:{messageReceived:!0,error:!1}},{enabled:!0,events:{messageReceived:`https://cdn.help.ai/ping.mp3`}}]}),he=a.object({enabled:a.boolean().default(!0).describe(`Master on/off. Default: on for touch devices, silently ignored elsewhere.`),events:a.partialRecord(T,a.union([a.boolean(),a.number().int(),a.array(a.number().int())])).optional().describe("Per-event vibration pattern. Value: `true` = default pattern, `false` = silent, number = single vibrate ms, array = `[vibrate, pause, vibrate, …]`.")}).loose().describe("Touch-device vibration. `events` accepts true (default), number (single vibrate ms), or [vibrate,pause,vibrate,…].").meta({examples:[{enabled:!0},{enabled:!0,events:{messageReceived:30,error:[40,60,40]}}]}),ge=a.object({sound:me.optional(),haptics:he.optional()}).loose().describe(`Audible + tactile feedback.`).meta({examples:[{sound:{enabled:!0,volume:.3},haptics:{enabled:!0}},{sound:{enabled:!1},haptics:{enabled:!1}}]}),E=a.enum([`circle`,`square`,`pill`]),D=a.enum([`arrowUp`,`paperPlane`,`send`,`chevron`]),O=a.enum([`filled`,`outline`,`ghost`]),k=a.object({shape:E.default(`circle`).describe("Send button outline shape — `circle` / `square` / `pill`."),icon:D.default(`arrowUp`).describe("Icon inside the send button — `arrowUp` / `paperPlane` / `send` / `chevron`."),variant:O.default(`filled`).describe("Fill treatment — `filled` (solid accent), `outline` (border only), `ghost` (no border, no fill).")}).loose().describe(`Send-button styling — shape, icon, and fill treatment.`).meta({examples:[{shape:`circle`,icon:`arrowUp`,variant:`filled`},{shape:`pill`,icon:`send`,variant:`outline`},{shape:`square`,icon:`paperPlane`,variant:`ghost`}]}),A=a.object({maxBytes:a.number().int().min(0).max(1073741824).default(10485760).describe("Maximum total size of the files attached to one message, in bytes. `10 MiB` (10485760) by default."),maxCount:a.number().int().min(0).max(100).default(10).describe(`Maximum number of attachments per message.`),accept:a.string().max(2e3).default(`*/*`).describe("Allowed MIME types — comma-separated `accept` attribute string, e.g. `image/*,application/pdf`.")}).loose().describe(`Client-side attachment limits. Server enforcement is still required.`).meta({examples:[{maxBytes:10485760,maxCount:10,accept:`*/*`},{maxBytes:5242880,maxCount:3,accept:`image/*,application/pdf`}]}),j=a.object({sendButton:k.optional(),attachments:A.optional()}).loose().describe(`Composer chrome — send-button styling + attachment limits.`).meta({examples:[{sendButton:{shape:`circle`,icon:`arrowUp`,variant:`filled`}},{sendButton:{shape:`pill`,icon:`send`,variant:`outline`}},{attachments:{maxBytes:5242880,maxCount:3}}]}),M=a.object({text:a.string().max(200).optional().describe("Visible attribution text (e.g. `Powered by Help AI`)."),href:a.url().max(2048).optional().describe("Click target — the attribution becomes a link. Must be a full URL (`https://…`)."),logoUrl:a.url().max(2048).optional().describe(`Small logo rendered before the text. Must be a full URL.`)}).loose().describe(`"Powered by …" attribution shown below the composer.`).meta({examples:[{text:`Powered by Help AI`},{text:`Powered by Help AI`,href:`https://help.ai`,logoUrl:`https://help.ai/logo.svg`}]}),N=a.object({poweredBy:M.optional(),composerDisclaimer:a.string().max(500).optional().describe(`Small muted text under the composer (like ChatGPT's 'ChatGPT can make mistakes.'). Empty = hidden.`)}).loose().describe(`Footer — attribution + composer disclaimer.`).meta({examples:[{poweredBy:{text:`Powered by Help AI`,href:`https://help.ai`}},{composerDisclaimer:`AI responses may be inaccurate.`}]}),P=a.record(a.string(),a.string()),F=a.union([P,a.record(m,P)]).describe(`Per-instance UI string overrides. Flat = active-locale only; nested = multi-locale map. Both forms are partial — missing keys fall through to built-in defaults.`).meta({examples:[{send:`Click`,stop:`Halt`,composerPlaceholder:`Type your question…`},{en:{send:`Send`,composerPlaceholder:`Type a message…`},fr:{send:`Envoyer`,composerPlaceholder:`Tapez un message…`}}]}),I=a.object({locale:m.optional().describe("BCP-47 locale tag forced for this widget instance (e.g. `fr-CA`). Page-owner explicit override."),defaultLocale:a.union([a.literal(`auto`),m]).default(`auto`).describe("Initial / fallback locale for users who haven't picked one. `auto` sniffs `navigator.language`."),availableLocales:a.array(m).max(200).optional().describe(`BCP-47 locale tags shown in the runtime language switcher. Hidden when fewer than 2 entries.`),strings:F.optional()}).loose().describe(`Locale + i18n overrides.`).meta({examples:[{defaultLocale:`auto`},{defaultLocale:`en`,availableLocales:[`en`,`fr`,`de`]},{locale:`fr-CA`,strings:{send:`Envoyer`}}]}),L=a.enum([`chat`,`home`,`help`,`news`]),_e=a.object({label:a.string().min(1).max(40).describe("Tab label — an i18n key (resolved against the i18n strings, e.g. `tabHome`) or a literal. Translations ride `i18n.strings`."),layout:L.describe("UI layout that renders this tab: `chat` (the conversation), `home`, `help`, or `news`."),contentCollectionIds:a.array(h).max(20).optional().describe("Content collections this tab shows, in order — the `contentCollectionIds` filter on `GET /pai/content`; Help groups its sections by them. Omit for the `chat` layout."),id:a.string().max(60).optional().describe("Stable id for navigation + last-tab persistence. Defaults to the first `contentCollectionIds` entry, else `layout`."),brandName:a.string().max(80).optional().describe("`home` — hero wordmark (e.g. your company name)."),hideGreeting:a.boolean().optional().describe("`home` — hide the greeting hero. Unset/`false` = shown (default), `true` = hidden."),greetingText:a.string().max(280).optional().describe("`home` — override the greeting headline (default 'How can we help?'); supports a `{name}` token."),userAvatars:a.array(a.object({id:a.string().min(1).max(100).optional().describe("Stable id: how its translations (`role`) find it."),name:a.string().min(1).max(80),avatar:a.string().max(2048).optional().describe("Image URL; falls back to initials of `name`."),role:a.string().max(80).optional()}).loose()).max(10).optional().describe("`home` — team/agent avatars shown in the hero."),hideSearchBar:a.boolean().optional().describe("`home` — hide the 'Search for help' bar. Unset/`false` = shown (default), `true` = hidden. The bar opens the Help tab, so it shows only when the widget has one."),hideRecentConversations:a.boolean().optional().describe("`home` — hide the visitor's most recent conversation card. Unset/`false` = shown (default), `true` = hidden."),status:a.object({text:a.string().min(1).max(120).optional().describe("`home` — status line; an i18n key or a literal (resolved via `localizeText`). Omit to use the built-in generic `homeStatus` string (localized, no custom key needed)."),level:a.string().max(40).optional().describe("`home` — status severity, drives the status icon colour. Free text; `operational` (green, default), `degraded` (amber), and `down` (red) are styled, any other value falls back to the operational style.").meta({examples:[`operational`,`degraded`,`down`]}),url:a.string().max(2048).optional().describe(`Opens in a new tab when tapped.`)}).optional().describe("`home` — system-status card. Omit to hide."),contentBlockTitle:a.string().max(80).optional().describe("`home` — heading for the content list: the pinned items of the tab's `contentCollectionIds` (default 'Popular articles').")}).loose(),ve=a.array(_e).max(4).describe("Messenger tabs — an ordered list of up to 4 tabs, each picking a `layout` + the content collections it shows (`contentCollectionIds`) + a translatable `label`. One tab → no tab bar (just that content); zero → an empty state. Floating / drawer / modal only.").meta({examples:[[{label:`tabConversations`,layout:`chat`}],[{label:`tabHome`,layout:`home`,brandName:`Acme`,contentBlockTitle:`Popular articles`,contentCollectionIds:[`019a0b6c-7e2a-7000-9d3e-4a5b6c7d8e01`]},{label:`tabConversations`,layout:`chat`},{id:`help`,label:`tabHelp`,layout:`help`,contentCollectionIds:[`019a0b6c-7e2a-7000-9d3e-4a5b6c7d8e01`,`019a0b6c-7e2a-7000-9d3e-4a5b6c7d8e02`]},{id:`news`,label:`tabNews`,layout:`news`,contentCollectionIds:[`019a0b6c-7e2a-7000-9d3e-4a5b6c7d8e03`]}]]}),ye=a.object({enabled:a.boolean().optional().describe("Master switch. Default `true` — the widget always fires; the data module gates ingestion per deployment server-side. Set `false` to silence the client entirely."),endpoint:a.url().max(2048).optional().describe("Pixel collector URL. Default: `${dataApiBaseUrl}/pai/elements-px.gif` (e.g. `https://help.ai/api/data/pai/elements-px.gif`). Must be a full URL."),sampleRate:a.number().min(0).max(1).optional().describe("Per-widget-runtime sampling 0..1 (one decision per mounted runtime, keeping that runtime's funnel intact). Default `1`."),token:a.string().max(512).optional().describe("Anti-forgery token, echoed as `tk=` on every hit. Server-issued in the `/handshake` response — never set by hand (see `docs/api/tracking-collector.md`).")}).loose().describe(`Anonymous usage tracking for the widget owner — GA-style pixel events (open, send, form submit, …) with page / device / locale dimensions. Never includes message or form content; the only visitor identifier is the widget's anonymous visitorId.`).meta({examples:[{enabled:!0},{enabled:!0,sampleRate:.5}]}),be=a.object({upload:a.string().min(1).max(2048).default(`/pai/upload-file`),transcribe:a.string().min(1).max(2048).default(`/pai/transcribe-audio`)}).loose().describe("HTTP endpoint overrides. `upload` / `transcribe` paths are appended to the agent base (`${baseUrl}/api/agent`); absolute URLs are accepted too.").meta({examples:[{upload:`/pai/upload-file`,transcribe:`/pai/transcribe-audio`},{upload:`https://help.ai/uploads/presign`}]}),R=a.object({id:a.string().min(1).max(200).optional().describe(`Host's stable id for the user — informational context the agent/backend can key on (not auth).`),email:a.string().min(1).max(320).optional().describe(`User email — surfaced to the agent for context (optional).`),name:a.string().min(1).max(200).optional().describe("Display name — shown in the Home greeting (`{name}`) and conversation transcripts (optional)."),plan:a.string().min(1).max(120).optional().describe("Subscription / pricing tier, e.g. `pro` (optional)."),role:a.string().min(1).max(120).optional().describe("The user's role on the host site, e.g. `admin` (optional)."),phone:a.string().min(1).max(40).optional().describe(`Phone number (optional).`)}).catchall(a.union([a.string(),a.number(),a.boolean()])).describe("Host-asserted visitor context (informational, untrusted — not authentication). Recognised `id` / `email` / `name` / `plan` / `role` / `phone` plus any extra custom scalar fields forwarded to the agent.").meta({examples:[{id:`u_123`},{id:`u_123`,email:`alex@acme.com`,name:`Alex Lee`,plan:`pro`}]}),xe=a.object({area:a.string().min(1).max(64).optional().describe(`Host-defined surface the visitor is on. Free-form; suggested: home | docs | help-desk | support | pricing | checkout | orders | account | blog.`),url:a.string().min(1).max(2048).optional().describe(`Full page URL. Auto-filled from the host page when omitted.`),path:a.string().min(1).max(2048).optional().describe("Page path, e.g. `/pricing/enterprise`."),title:a.string().min(1).max(300).optional().describe(`Human-readable page title.`)}).catchall(a.union([a.string(),a.number(),a.boolean()])).describe("Host-asserted page/visit context (informational, untrusted). Where the visitor is + the surface (`area`) they're using, plus any custom scalar fields, forwarded to the agent.").meta({examples:[{area:`pricing`,path:`/pricing`},{area:`help-desk`}]}),z=a.object({widgetId:a.string().min(1).max(80).default(`default`).describe(`Stable per-instance id used to namespace localStorage keys. Set this when mounting more than one widget on the same page so their conversation state doesn't collide.`),publicKey:a.string().min(1).max(200).optional().describe("Deployment public key (`agent_pk_…`) issued from the dashboard. Sent on every API call as the `x-public-key` header when present."),aiAgentDeploymentId:a.string().min(1).max(200).describe("Required deployment UUID from the dashboard. Picks which agent / settings bundle answers this mount. Sent as `x-ai-agent-deployment-id`."),baseUrl:a.string().min(1).max(2048).optional().describe("MAIN site origin (e.g. `https://help.ai`) — the API modules derive from it: agent API at `${baseUrl}/api/agent`, data API at `${baseUrl}/api/data`. Set this to point at your staging / self-hosted / custom backend. Default: the brand's `defaultBaseUrl` baked at build time."),agentApiBaseUrl:a.string().min(1).max(2048).optional().describe("Full agent-API base — set it to reach a STANDALONE `module-agent-api` directly (local module on its own port, e.g. `http://localhost:3069`; routes attach as-is: `/pai/handshake`). Precedence: this option > derived from the main origin (`${baseUrl}/api/agent`). Not server-pushable."),dataApiBaseUrl:a.string().min(1).max(2048).optional().describe("Full data-API base (e.g. `https://help.ai/api/data`, or a standalone local module like `http://localhost:3071`) — the service serving content and the tracking pixel. Precedence: this option > server-pushed `config.dataApiBaseUrl` > derived from the main origin (`${baseUrl}/api/data`)."),continueLink:a.string().min(1).max(400).optional().describe("A Continue in chat link's proof (`<conversationId>.<workspaceId>.<exp>.<signature>`), set by help.ai's own chat page for a visitor who came from an email: the widget opens that email conversation as its visitor, sending it as `x-continue-link` on every agent call. Not server-pushable."),userContext:R.optional(),pageContext:xe.optional(),endpoints:be.optional(),debug:a.union([a.boolean(),a.enum([`off`,`error`,`warn`,`info`,`debug`,`trace`])]).optional().describe('Console log verbosity. `false` / `"off"` silences everything (default in production). `true` → `"debug"`. Levels `error` / `warn` / `info` / `debug` / `trace` gate output additively. Use `"trace"` to capture per-chunk SSE frames + every state transition. Also toggleable at runtime via `chat.setDebug(level)` or `?<brand>-debug=trace` in the page URL — the URL beats this option, this option beats the persisted `localStorage` value.')}).loose().describe("Where the widget talks to and how it authenticates. Owned by the embedding developer (typically baked into the page template / env var) — distinct from `userPrefs`, which is the dashboard-pushable UX surface.").meta({examples:[{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`},{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`,widgetId:`support`},{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`,baseUrl:`https://api.acme.com`}]}),B=a.object({agent:g.optional(),presentation:S.optional(),behavior:te.optional(),theme:w.default(`host`).describe("Theme preference (`host`, the default, follows the page and else the OS) or a tokens override object (`accent`, `radius`, `fontFamily`)."),launcher:ce.optional(),header:pe.optional(),composer:j.optional(),feedback:ge.optional(),i18n:I.optional(),footer:N.optional(),features:ue.optional(),modules:ve.optional(),tracking:ye.optional()}).loose().describe("Portal-configurable widget settings — thirteen sections, one per dashboard tab. The backend pushes this shape on `/pai/handshake` under `config`.").meta({examples:[{presentation:{mode:`floating`,position:`bottom-right`},theme:`auto`},{presentation:{mode:`floating`},theme:{accent:`#7c3aed`,radius:`12px`},launcher:{variant:`pill`,label:`Ask AI`,callout:{text:`👋 Need help?`}}},{presentation:{mode:`inline`},behavior:{responseMode:`streaming`},features:{voice:`local`}}]}),V=z.extend({...B.shape,site:a.unknown().optional().describe('Site config — applies in `mode: "page"`. Comes from the handshake response, not user-edited.'),blocks:a.unknown().optional().describe('Blocks (nav + link cards) — applies in `mode: "page"`. Comes from the handshake response.')}).describe("Full tooling config — connection (where + auth) + widget settings (look + behaviour) + page-mode handshake extras. The production widget does not import this Zod schema. Mode-specific constraints (e.g. `position` only meaningful in `floating`) are NOT enforced here so the same object can flow across mode changes.").meta({examples:[{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`,presentation:{mode:`floating`},theme:`auto`},{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`,presentation:{mode:`modal`,size:{width:`720px`,height:`640px`}}}]});V.partial(),B.partial(),z.partial();const Se=B.partial().extend({dataApiBaseUrl:a.string().min(1).max(2048).optional(),storageVersion:a.string().min(1).max(64).optional(),history:a.object({enabled:a.boolean().optional().describe("`false` hides the history button and never lists past conversations. Default `true`.")}).loose().optional().describe(`The deployment's Keep conversations setting.`),login:a.object({url:a.url({protocol:/^https?$/}).max(2048).refine(e=>e.includes(`{returnTo}`),`Put {returnTo} where your login page reads the page to come back to`).optional().describe("Your site's login page, as a URI Template with `{returnTo}` (RFC 6570): Log in sends the page there, with `{returnTo}` replaced by the page's address, URL-encoded. Set, login is on: anonymous visitors see the Log in bar and the Log in screen has a Log in button. A page listening to `loginRequested` opens its own login instead.").meta({examples:[`https://globalvillages.com/login?return_to={returnTo}`]}),required:a.boolean().optional().describe("Only visitors your site logs in (`userToken`) can chat: anyone else sees the Log in screen in place of the composer. Default `false`."),hidePrompt:a.boolean().optional().describe("Hide the Log in bar for anonymous visitors: logging in then starts from your site's own button (`loginRequested`) or the Log in screen. Default `false`."),hideUser:a.boolean().optional().describe('Hide the "Logged in as Maya" bar for logged-in visitors. Default `false`.')}).optional().describe(`The deployment's login settings. See [Logging in](../features/login.md).`),maxMessageCharacters:a.number().int().positive().optional().describe("The longest visitor message the deployment takes: the composer stops there, and a longer message is refused with `400 MESSAGE_TOO_LONG`.")}),Ce=a.object({title:a.string().min(1).max(120).optional().describe(`Brand / site name. Used as the logo's alt-text fallback.`),logo:u.optional().describe(`Brand logo shown at the top of the page-mode sidebar.`),logoDark:u.optional().describe("Optional dark-theme logo variant. Falls back to `logo` when the active theme is light or `logoDark` is unset.")}).loose(),we=a.object({navigation:a.array(d).max(100).optional().describe(`Sidebar navigation links (vertical list, primary nav).`),linkCards:a.array(d).max(100).optional().describe("Sidebar link cards (richer entries with optional `description`).")}).loose(),Te=a.object({id:a.string(),role:a.enum([`assistant`,`system`]),text:a.string()}).loose(),Ee=a.object({id:a.string(),label:a.string(),text:a.string().optional()}).loose();a.object({deployment:a.object({id:a.string(),name:a.string(),slug:a.string().optional(),publicKey:a.string().optional()}).loose(),agent:a.object({id:a.string(),name:a.string(),title:a.string().optional(),status:a.enum([`online`,`away`,`offline`]).optional()}).loose(),config:Se.optional(),site:Ce.optional(),blocks:we.optional(),welcome:a.object({messages:a.array(Te).optional(),suggestions:a.array(Ee).optional()}).loose().optional(),translations:a.array(a.object({locale:a.string()}).loose()).optional(),visitorId:a.string(),conversationId:a.string(),loginStatus:a.enum([`loggedIn`,`expired`,`anonymous`]).optional(),userPrefs:a.record(a.string(),a.unknown()).optional(),rebind:a.object({conversationId:a.string()}).strict().optional()}).loose();function H({description:e,examples:t,onPick:n}){let[a,o]=i(!1),u=r(null);return!e&&t.length===0?null:/* @__PURE__ */ l(s,{children:[/* @__PURE__ */ c(`button`,{ref:u,type:`button`,class:`cfg-help-trigger`,"aria-label":`Field info`,"aria-expanded":a?`true`:`false`,title:`Field info`,"data-open":a?`true`:void 0,onClick:e=>{e.preventDefault(),e.stopPropagation(),o(e=>!e)},children:/* @__PURE__ */ c(`span`,{"aria-hidden":`true`,children:`?`})}),a?/* @__PURE__ */ c(De,{anchor:u,description:e,examples:t,onClose:()=>o(!1),onPick:e=>{n(e),o(!1)}}):null]})}function De({anchor:n,description:a,examples:s,onClose:u,onPick:d}){let f=r(null),[p,m]=i(null);return t(()=>{function e(){let e=n.current;if(!e)return;let t=e.getBoundingClientRect(),r=f.current?.offsetWidth||320,i=f.current?.offsetHeight||240,a=window.innerHeight-t.bottom>=i+8+4?t.bottom+6:Math.max(8,t.top-i-6),o=Math.max(8,Math.min(a,window.innerHeight-i-8)),s=window.innerWidth-t.right,c=window.innerWidth-r-8;m({top:o,right:Math.max(8,Math.min(c,s))})}e();let t=requestAnimationFrame(e);return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{cancelAnimationFrame(t),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[n]),e(()=>{function e(e){e.key===`Escape`&&u()}function t(e){let t=f.current,r=n.current,i=e.target instanceof Node?e.target:null;t&&i&&(t.contains(i)||r?.contains(i)||u())}window.addEventListener(`keydown`,e);let r=setTimeout(()=>window.addEventListener(`mousedown`,t),0);return()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`mousedown`,t),clearTimeout(r)}},[n,u]),p?o(/* @__PURE__ */ l(`div`,{ref:f,class:`cfg-help-popover`,role:`dialog`,style:{top:`${p.top}px`,right:`${p.right}px`},children:[a?/* @__PURE__ */ c(`p`,{class:`cfg-help-description`,children:a}):null,s.length>0?/* @__PURE__ */ l(`div`,{class:`cfg-help-examples`,children:[/* @__PURE__ */ l(`span`,{class:`cfg-help-examples-title`,children:[`Example`,s.length===1?``:`s`,` (`,s.length,`)`]}),/* @__PURE__ */ c(`ul`,{children:s.map((e,t)=>/* @__PURE__ */ c(`li`,{children:/* @__PURE__ */ c(`button`,{type:`button`,class:`cfg-help-example-btn`,onClick:()=>d(e),children:/* @__PURE__ */ c(`code`,{children:Oe(e)})})},t))})]}):null]}),document.body):null}function Oe(e){if(typeof e==`string`)return e.length>60?`${e.slice(0,60)}…`:e;try{let t=JSON.stringify(e);return t.length>80?`${t.slice(0,80)}…`:t}catch{return String(e)}}function ke({name:e,label:t,value:n,defaultValue:r,description:i,help:a,onChange:o}){return/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-boolean`,title:i,children:[/* @__PURE__ */ c(`input`,{type:`checkbox`,name:e,checked:n??r??!1,onInput:e=>o(e.currentTarget.checked)}),/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),a]})}function Ae({name:e,label:t,value:n,description:r,help:i,onChange:a}){let o=n??``,s=/^#[0-9a-f]{6}$/i.test(o)?o:`#000000`;return/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-color`,title:r,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),i]}),/* @__PURE__ */ l(`span`,{class:`cfg-color-row`,children:[/* @__PURE__ */ c(`input`,{type:`color`,value:s,"aria-label":`${t} swatch`,onInput:e=>a(e.currentTarget.value)}),/* @__PURE__ */ c(`input`,{type:`text`,name:e,value:n??``,placeholder:`#10b981 / oklch(...) / var(...)`,onInput:e=>{let t=e.currentTarget.value;a(t===``?void 0:t)}})]})]})}function je({name:e,label:t,value:n,defaultValue:r,description:i,options:a,optional:o,help:s,onChange:u}){let d=n??r??(o?``:void 0),f=o?[{id:``,label:`default`},...a.map(e=>({id:e,label:e}))]:a.map(e=>({id:e,label:e}));return/* @__PURE__ */ l(`div`,{class:`cfg-field cfg-field-enum`,title:i,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),s]}),/* @__PURE__ */ c(`div`,{class:`cfg-segmented`,"data-segmented-name":e,role:`radiogroup`,"aria-label":t,children:f.map(e=>{let t=d===e.id;return/* @__PURE__ */ c(`button`,{type:`button`,role:`radio`,"aria-checked":t?`true`:`false`,class:`cfg-segmented-item`,"data-value":e.id,"data-active":t?`true`:void 0,onClick:()=>u(e.id===``?void 0:e.id),children:e.label},e.id)})}),/* @__PURE__ */ c(`input`,{type:`hidden`,name:e,value:n??``})]})}function Me({name:e,label:t,value:n,step:r,min:i,max:a,description:o,help:s,onChange:u}){return/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-number`,title:o,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),s]}),/* @__PURE__ */ c(`input`,{type:`number`,name:e,value:n===void 0?``:String(n),step:r,min:i,max:a,onInput:e=>{let t=e.currentTarget.value;if(t===``)return u(void 0);let n=Number(t);Number.isFinite(n)&&u(n)}})]})}function Ne({name:e,label:t,value:n,placeholder:r,maxLength:i,description:a,help:o,onChange:s}){return/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-string`,title:a,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),o]}),/* @__PURE__ */ c(`input`,{type:`text`,name:e,value:n??``,placeholder:r,maxLength:i,onInput:e=>{let t=e.currentTarget.value;s(t===``?void 0:t)}})]})}function U(e){return e._def??{}}function W(e){let t=e,n=!1,r=!1,i;for(let e=0;e<8;e++){let e=U(t),a=e.type;if(a===`optional`&&e.innerType)n=!0,t=e.innerType;else if(a===`nullable`&&e.innerType)r=!0,t=e.innerType;else if(a==="default"&&e.innerType)i=typeof e.defaultValue==`function`?e.defaultValue():e.defaultValue,t=e.innerType;else break}return{inner:t,optional:n,nullable:r,defaultValue:i}}function G(e){switch(U(e).type){case`string`:return`string`;case`number`:return`number`;case`boolean`:return`boolean`;case`enum`:return`enum`;case`object`:return`object`;case`array`:return`array`;case`union`:return`union`;case`literal`:return`literal`;case`record`:return`record`;default:return`unknown`}}function K(e){let t=U(e);return t.entries?Object.values(t.entries):[]}function q(e){return U(e).shape??{}}function J(e){let t=e._zod?.bag;return{maxLength:typeof t?.maximum==`number`?t.maximum:void 0,minLength:typeof t?.minimum==`number`?t.minimum:void 0,pattern:t?.pattern instanceof RegExp?t.pattern.source:void 0}}function Y(e){return/color|accent|background/i.test(e)}function X(e){return e.description}function Z(e){let t=e.meta?.();return Array.isArray(t?.examples)?t.examples:[]}function Q(e){let t=Z(e);if(t.length!==0)try{return JSON.stringify(t[0])}catch{return}}function $({schema:e,value:t,path:n,onChange:r,columns:i=1}){let a=q(e),o=t??{},s={},u=e.safeParse(o);if(!u.success)for(let e of u.error.issues){let t=e.path[0];if(typeof t!=`string`&&typeof t!=`number`)continue;let n=String(t);n in s||(s[n]=e.message)}function d(e,t){let n={...o};t===void 0?delete n[e]:n[e]=t,r(Object.keys(n).length===0?void 0:n)}let f=Object.entries(a).map(([e,t])=>{let{inner:r,optional:i,defaultValue:a}=W(t),u=G(r),f=[...n,e].join(`.`),p=Le(e),m=o[e],h=X(t)??X(r),g=Z(t),_=g.length>0?g:Z(r),v=s[e];function y(t){return d(e,t)}let b=/* @__PURE__ */ c(H,{description:h,examples:_,onPick:y}),x=`${f}-error`;function S(e){return/* @__PURE__ */ l(`div`,{class:`cfg-field-wrap`,"data-invalid":v?`true`:void 0,children:[e,/* @__PURE__ */ c(`p`,{class:`cfg-field-error`,id:x,role:v?`alert`:void 0,children:v?`⚠ ${v}`:``})]})}switch(u){case`string`:return Y(e)?S(/* @__PURE__ */ c(Ae,{name:f,label:p,value:typeof m==`string`?m:void 0,description:h,help:b,onChange:t=>d(e,t)},e)):S(/* @__PURE__ */ c(Ne,{name:f,label:p,value:typeof m==`string`?m:void 0,maxLength:J(r).maxLength,placeholder:Re(a,_),description:h,help:b,onChange:t=>d(e,t)},e));case`number`:return S(/* @__PURE__ */ c(Me,{name:f,label:p,value:typeof m==`number`?m:void 0,description:h,help:b,onChange:t=>d(e,t)},e));case`boolean`:return S(/* @__PURE__ */ c(ke,{name:f,label:p,value:typeof m==`boolean`?m:void 0,defaultValue:typeof a==`boolean`?a:void 0,description:h,help:b,onChange:t=>d(e,t)},e));case`enum`:return S(/* @__PURE__ */ c(je,{name:f,label:p,value:typeof m==`string`?m:void 0,defaultValue:typeof a==`string`?a:void 0,description:h,options:K(r),optional:i,help:b,onChange:t=>d(e,t)},e));case`object`:return/* @__PURE__ */ c(Ie,{label:p,description:h,examples:_,onPick:t=>d(e,t),isPopulated:m!==void 0,children:/* @__PURE__ */ c($,{schema:r,value:Pe(m)?m:void 0,path:[...n,e],onChange:t=>d(e,t)})},e);default:{let n=Q(t)??Q(r);return S(/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-json`,title:h,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label`,children:[p,` `,/* @__PURE__ */ c(`span`,{class:`cfg-hint`,children:`(JSON)`})]}),b]}),/* @__PURE__ */ c(`textarea`,{name:f,value:m===void 0?``:JSON.stringify(m,null,2),rows:3,placeholder:n,onInput:t=>{let n=t.currentTarget.value;if(n===``)return d(e,void 0);try{d(e,JSON.parse(n))}catch{}}})]},e))}}});if(n.length===0&&i===2){let e=Object.entries(a),t=[],n=[],r=0,i=0;for(let[a,s]of f.entries()){let c=e[a];if(!c)continue;let[l,u]=c,d=Fe(u,o[l]);r<=i?(t.push(s),r+=d):(n.push(s),i+=d)}return/* @__PURE__ */ l(`div`,{class:`cfg-object cfg-object-masonry`,children:[/* @__PURE__ */ c(`div`,{class:`cfg-masonry-col`,children:t}),/* @__PURE__ */ c(`div`,{class:`cfg-masonry-col`,children:n})]})}return/* @__PURE__ */ c(`div`,{class:`cfg-object`,children:f})}function Pe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Fe(e,t){if(t===void 0||typeof t==`object`&&t&&Object.keys(t).length===0)return 1;let{inner:n}=W(e);if(G(n)===`object`){let e=q(n);return 1+Object.keys(e).length}return 1}function Ie({label:e,description:t,examples:n,onPick:r,isPopulated:i,children:a}){return/* @__PURE__ */ l(`details`,{class:`cfg-nested`,open:i,title:t,children:[/* @__PURE__ */ l(`summary`,{class:`cfg-nested-summary`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-nested-label`,children:e}),/* @__PURE__ */ c(H,{description:t,examples:n,onPick:r})]}),a]})}function Le(e){let t=e.replace(/([A-Z])/g,` $1`).trim();return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function Re(e,t){if(typeof e==`string`)return e;let n=t[0];return typeof n==`string`?n:void 0}function ze({schema:e,value:t,onChange:r,title:i,columns:a=1}){let o=e??V,s=n(()=>JSON.stringify(t,null,2),[t]),u=Object.keys(t).length===0;return/* @__PURE__ */ l(`div`,{class:`cfg-root`,children:[/* @__PURE__ */ l(`div`,{class:`cfg-header`,children:[i?/* @__PURE__ */ c(`h2`,{class:`cfg-title`,children:i}):/* @__PURE__ */ c(`span`,{}),/* @__PURE__ */ c(`button`,{type:`button`,class:`cfg-reset`,onClick:()=>r({}),disabled:u,title:`Clear every field — schema defaults take over`,children:`Reset to defaults`})]}),/* @__PURE__ */ c($,{schema:o,value:t,path:[],onChange:e=>r(e??{}),columns:a}),/* @__PURE__ */ l(`details`,{class:`cfg-json`,children:[/* @__PURE__ */ c(`summary`,{children:`JSON output`}),/* @__PURE__ */ c(`pre`,{children:s})]})]})}export{ze as Configurator,$ as ObjectField,K as enumValues,G as kindOf,Y as looksLikeColor,q as objectFields,Q as placeholderFromExamples,X as schemaDescription,Z as schemaExamples,J as stringHints,W as unwrap};
1
+ import{useEffect as e,useLayoutEffect as t,useMemo as n,useRef as r,useState as i}from"preact/hooks";import{z as a}from"zod";import{createPortal as o}from"preact/compat";import{Fragment as s,jsx as c,jsxs as l}from"preact/jsx-runtime";const u=a.object({url:a.string().min(1).max(2048).describe(`Public URL of the image. Must be a full URL or root-relative path.`),alt:a.string().min(1).max(200).optional().describe(`Alt text for screen readers. Omit only for purely decorative images.`)}).strict().describe(`A single image asset (logo, hero, icon).`),d=a.object({id:a.string().min(1).max(100).optional().describe(`Stable id: the Preact key, the analytics target, and how its translations find it.`),label:a.string().min(1).max(120).describe(`Visible link text.`),href:a.string().min(1).max(2048).optional().describe(`Click target. Optional — when omitted the link renders as a non-clickable heading.`),icon:a.string().min(1).max(100).optional().describe(`Built-in icon preset name (chat / spark / message / help / wand) or a custom string.`),description:a.string().min(1).max(300).optional().describe(`Subtitle shown below the label. Used by link cards in page mode.`)}).loose().describe(`A navigation link / link card.`),f=a.string().min(1).max(120).describe("Any CSS length — `640px`, `80vh`, `calc(100vh - 64px)`, etc. Validated only for size, not syntax."),p=a.string().min(1).max(120).describe("Any CSS colour — hex, `rgb()`, `hsl()`, `oklch()`, a named colour, or a `var(--token)`."),m=a.string().min(1).max(35).describe("BCP-47 locale tag (e.g. `en`, `fr-CA`, `zh-Hant-HK`)."),h=a.uuidv7().describe(`UUID v7 (RFC 9562) — the single id format for visitor / conversation / message / file / content ids.`),g=a.object({name:a.string().max(120).optional().describe('The persona visitors chat with, such as `Bea`. May be an i18n key resolved against `i18n.strings`. Set, a labelled launcher with no `label` reads "Ask Bea" in the visitor\'s language.'),title:a.string().max(200).optional().describe(`The line under the name in the chat header. May be an i18n key.`),avatar:a.url({protocol:/^https?$/}).max(2048).optional().describe(`The persona's picture, a rounded square in the chat header. Unset = the name's initials.`)}).loose().describe(`The assistant persona: its name, subtitle and picture in the chat header.`).meta({examples:[{name:`Bea`,title:`Store assistant`,avatar:`https://cdn.example.com/bea.png`}]}),_=a.enum([`normal`,`expanded`,`fullscreen`,`auto`]),v=a.object({enabled:a.boolean().default(!0).describe("Show a resize handle (default on): a corner grip on the floating panel, the inner edge of a drawer. Hidden in every other mode and on phones, where the panel is edge to edge. `false` turns it off."),minWidth:f.optional().describe("Smallest width the user can drag the panel to. Default `320px`."),maxWidth:f.optional().describe(`Largest width the user can drag the panel to.`),minHeight:f.optional().describe("Smallest height the user can drag the floating panel to. Default `400px`."),maxHeight:f.optional().describe(`Largest height the user can drag the floating panel to.`)}).loose().describe("Drag-resize controls. While `enabled` (the default), visitors resize the floating panel from its corner or a drawer from its inner edge, by pointer or arrow keys, within the min/max bounds; the size is remembered.").meta({examples:[{enabled:!1},{enabled:!0,minWidth:`320px`,maxWidth:`720px`,minHeight:`400px`,maxHeight:`90vh`}]}),y=a.object({width:f.optional().describe("Panel width (CSS length). Mode-specific defaults — floating `380px`, modal `min(960px, 92vw)`, drawer `clamp(440px, 32vw, 640px)`. Set this to override; inline/standalone/page modes ignore it."),height:f.optional().describe("Panel height (CSS length). Mode-specific defaults — floating `600px`, modal `min(720px, 88vh)`, drawer `100vh` (clamped to `100vh − inset-y × 2`). Set this to override."),expanded:a.object({width:f.optional().describe(`Width when the user clicks the expand button.`),height:f.optional().describe(`Height when the user clicks the expand button.`)}).loose().optional().describe("Dimensions when the panel is in its `expanded` tier (between normal and fullscreen). Applies to floating / modal / drawer; ignored in inline / standalone / page where the panel always fills its parent."),resize:v.optional().describe(`Drag-resize controls — a corner grip on the floating panel, the inner edge of a drawer.`),inset:f.optional().describe("Drawer-mode edge inset — gap from each viewport edge (top/bottom/left/right). Single value applied to all four sides. Defaults to `3vh` vertical / `12px` horizontal. Use `0` for a full-edge drawer (no gap), or `5vh` for a centered-looking flyout with extra breathing room. Ignored by every other mode."),initialSize:_.default(`auto`).describe("Which size tier to open with on the first mount: `normal` / `expanded` / `fullscreen` / `auto`. Default `auto` is responsive by viewport: phones (< 640 px) open `fullscreen` edge-to-edge, tablets (640 px … `autoSizeBreakpoint`) open `normal`, and desktop/laptop (≥ `autoSizeBreakpoint`) open `expanded` — so the panel is right for the device out of the box. Set a literal to pin one tier everywhere; the user's own resize is remembered per-device and wins on reload."),autoSizeBreakpoint:a.number().int().min(0).max(1e4).default(900).describe("Viewport width (px) at/above which `initialSize: auto` opens `expanded` instead of `normal`. (Phones below 640 px always open `fullscreen`.)")}).loose().describe("Panel dimensions and drawer inset. Width/height override the mode-specific defaults (floating compact popover, modal centered dialog, drawer flyout). `inset` only affects drawer mode.").meta({examples:[{width:`420px`,height:`640px`},{width:`min(560px, 92vw)`,height:`min(640px, 90vh)`},{width:`420px`,expanded:{width:`640px`,height:`780px`},initialSize:`auto`,autoSizeBreakpoint:900},{width:`min(1100px, 95vw)`,height:`min(820px, 92vh)`},{width:`360px`,inset:`8vh`},{width:`420px`,height:`100vh`,inset:`0`},{width:`420px`,height:`60vh`,inset:`20vh`}]}),b=a.enum([`floating`,`inline`,`standalone`,`page`,`modal`,`drawer`]),x=a.enum([`bottom-right`,`bottom-left`,`top-right`,`top-left`]),S=a.object({mode:b.default(`floating`).describe("Rendering shape. `floating` (FAB + popover), `inline` (in-flow block), `standalone` (full viewport), `page` (sidebar + chat), `modal` (centered overlay), `drawer` (side dock)."),position:x.optional().describe("Anchor corner. `floating` uses it for the FAB; `drawer` uses the `*-left` / `*-right` suffix to pick the dock side. Unset is Automatic: bottom-right, or bottom-left when the chat reads right to left. A set corner is fixed. Ignored in other modes."),size:y.optional().describe("Panel dimensions. Mode-aware defaults (floating compact popover, modal centered dialog, drawer flyout) — fields here override them. Includes `inset` (drawer flyout gap), `expanded` tier, drag-resize grip.")}).loose().describe(`Layout fundamentals — mode, anchor corner, panel size + drawer inset.`).meta({examples:[{mode:`floating`,position:`bottom-right`},{mode:`modal`,size:{width:`min(1100px, 95vw)`,height:`min(820px, 92vh)`}},{mode:`drawer`,position:`bottom-right`},{mode:`drawer`,position:`top-right`,size:{width:`360px`,inset:`8vh`}},{mode:`drawer`,position:`bottom-right`,size:{width:`420px`,height:`100vh`,inset:`0`}}]}),ee=a.enum([`streaming`,`buffered`]),te=a.object({startMinimized:a.boolean().default(!0).describe("Don't auto-open the floating panel on first visit. `true` (default) shows the FAB collapsed; `false` opens the panel on mount."),responseMode:ee.default(`streaming`).describe("How the assistant's reply arrives. `streaming` (default) types tokens as they generate; `buffered` waits + shows the full reply at once."),showReasoning:a.boolean().default(!1).describe(`Show the model's reasoning ("thoughts") as a collapsible block above each answer. \`false\` (default) hides it — a loading indicator still shows while the model works. Reasoning is absent from durable history, but the current turn's short-lived resume backlog may replay it after an immediate reconnect or reload.`),stepDisplay:a.object({stepsFrom:a.array(a.enum([`platform`,`mcp`,`api`,`webmcp`])).optional().describe("Where the steps that may appear come from: `platform` (help.ai's own tools), `mcp` (an MCP server's), `api` (a call to an API integration), `webmcp` (the page's own tools, run in the visitor's browser). Unset: every origin."),stepsShown:a.array(a.enum([`decided`,`auto-decided`,`unasked`,`failed`])).optional().describe("Which kinds of steps appear, folded into one line under the reply, beside the visitor's own decisions and anything waiting on them, which always show: `decided` (it asked someone else), `auto-decided` (the rules decided it), `unasked` (it ran without asking), `failed` (it failed, whoever decided it). A step has every kind that applies and shows when its origin is in `stepsFrom` and any of its kinds is here. Empty: only those that always show."),stepDetails:a.enum([`none`,`values`,`table`,`json`,`table-and-json`]).optional().describe("What an opened step shows: `none` (the step line alone; a step waiting on a decision still shows its values), `values` (quiet label and value lines, no ids), `table` (tables of what it ran on and what came back, ids included), `json` (its raw input and result), `table-and-json` (the tables, with the JSON folded under Raw data)."),showStepSystem:a.boolean().optional().describe(`The system that ran a step follows its name, such as "Cancel an order · BC Co. shop".`),showDecidedBy:a.boolean().optional().describe(`Each decision someone else or the rules made says who made it. Off: it shows only its outcome; the visitor's own choice always shows.`),foldApprovals:a.boolean().optional().describe(`A decided approval folds into the steps line. Off: it stays in the reply as a card.`)}).optional().describe("How the AI's steps and approvals show. Unset keys take a visitor's defaults: every origin, no kinds of steps beyond their own decisions, step details `values`, system and who decided off, approvals folded. A decision still open always shows what it will do."),showSources:a.boolean().default(!1).describe("Show the citation sources behind an answer (web links + document/file references) in the transcript. `false` (default) hides them."),disableMessageFeedback:a.boolean().default(!1).describe("Turn OFF the 👍/👎 feedback controls under each rateable reply (AI or operator). Unset/`false` = shown (default), `true` = hidden. A choice fires the `messageFeedback` event and is POSTed best-effort to `/pai/message-feedback`."),autoSendSuggestions:a.boolean().default(!1).describe("Auto-send a suggestion chip's text the moment it's tapped. `false` (default) fills the composer with the text so the visitor can edit before sending; `true` sends it immediately."),cardAnswerWaitSeconds:a.number().int().min(0).max(600).default(60).describe("How long a message the visitor queued while a reply streamed waits, after that reply ends on a card (an approval or questions), for the visitor to answer the card first. `60` (default); `0` sends it at once. The message always goes: a card never blocks it."),popOutUrl:a.string().trim().min(1).max(2048).optional().describe("URL opened by the `popOut` header action. The widget adds the active conversation, widget, and deployment identity as query parameters.")}).loose().describe(`Conversation behaviour — lifecycle, streaming, and the transcript surface (scroll, feedback).`).meta({examples:[{startMinimized:!0,responseMode:`streaming`},{startMinimized:!1,responseMode:`buffered`,disableMessageFeedback:!0}]}),C=a.enum([`auto`,`light`,`dark`,`host`]),ne=a.object({mode:C.optional().describe("Light/dark beside the token overrides: `host` (the default: the page's own light/dark, flipping with the site's toggle, else the OS), `auto` (the OS), `light` or `dark`."),accent:p.optional().describe(`Brand accent colour. Drives the FAB, send button, links, and active states. CSS colour.`),accentText:p.optional().describe(`Foreground colour rendered ON the accent (FAB icon, send-button glyph). CSS colour.`),radius:f.optional().describe("Corner radius for the panel + buttons. CSS length (`8px`, `0.75rem`, `12px`)."),fontFamily:a.string().min(1).max(200).optional().describe("Font stack used inside the widget. Standard CSS `font-family` value."),contentMaxWidth:f.optional().describe("Max width of the readable content column (messages, history, home, composer) on a wide surface — content centres, full-bleed bars keep their edges. CSS length; default `768px`. Set `100%` to fill the surface (no cap). Modal + drawer already fill their card by default.")}).loose().describe(`Theme token overrides. Any field left unset falls through to the brand's default theme.`).meta({examples:[{accent:`#10b981`,radius:`12px`},{accent:`#7c3aed`,accentText:`#ffffff`,radius:`16px`,fontFamily:`'Inter', system-ui`},{accent:`oklch(0.7 0.2 145)`,radius:`0.5rem`},{accent:`#5b5bd6`,contentMaxWidth:`960px`}]}),w=a.union([C,ne]).describe(`'host' | 'auto' | 'light' | 'dark', or a tokens override object.`).meta({examples:[`host`,`dark`,{accent:`#10b981`,radius:`12px`},{accent:`#7c3aed`,accentText:`#fff`,radius:`16px`,fontFamily:`'Inter', system-ui`}]}),re=a.enum([`circle`,`pill`,`bar`,`minimal`]),ie=a.enum([`sm`,`md`,`lg`]),ae=a.enum([`pill`,`bubble`,`callout`]),oe=a.enum([`auto`,`horizontal`,`vertical`]),se=a.object({text:a.string().min(1).max(500).default(`👋 Hi! Need any help?`).describe("The message to show in the bubble. Defaults to a friendly greeting; replace with your own copy (e.g. 'Click here →'). May also be an i18n key (e.g. `launcherCallout`) resolved against `i18n.strings` for per-locale copy; a non-key literal renders as-is."),shape:ae.default(`pill`).describe("Visual shape — `pill` (slim label + arrow), `bubble` (speech-bubble tail), `callout` (loud variant)."),position:oe.default(`auto`).describe("Where the bubble sits relative to the FAB. `auto` (default) picks the side facing into the page. `horizontal` anchors beside the FAB (left/right depending on the FAB's corner). `vertical` anchors above/below the FAB. Concrete left/right/top/bottom is derived from the FAB's corner so the bubble always stays on-screen."),delayMs:a.number().int().min(0).max(6e4).default(1200).describe(`How long to wait after page load before the bubble appears, in milliseconds.`),autoDismissMs:a.number().int().min(0).max(6e5).default(0).describe("Auto-hide the bubble after this many milliseconds. `0` (default) keeps it until the user dismisses."),animated:a.boolean().default(!0).describe("Subtle horizontal nudge to draw the eye. Disabled automatically by `prefers-reduced-motion`."),persistent:a.boolean().default(!0).describe("How dismissals stick. `true` (default) — re-show on every visit regardless of prior dismissal (the 'recurring greeting' behaviour). `false` — clicking X stores the message text and that exact message stays hidden across visits (the 'one-time hint' behaviour).")}).loose().describe(`Pre-engagement message bubble next to the FAB. Use it for a greeting ('Hi, need help?'), an attention-grabbing nudge ('Click here →'), or any one-time onboarding tip — same component, configured for the use case.`),ce=a.object({variant:re.default(`circle`).describe("FAB visual style. `circle` — round bubble (icon only). `pill` — icon + label. `bar` — wide rectangular button. `minimal` — text-only outline."),size:ie.default(`md`).describe(`FAB size preset — small / medium / large.`),label:a.string().max(200).optional().describe("Text rendered on the FAB (only shown for `pill` / `bar` / `minimal` variants)."),icon:a.string().max(8e3).optional().describe("Icon shown on the FAB / drawer edge tab. Built-in presets: `chat` / `message` / `bubbles` / `spark` / `wand` / `bot` / `help` / `lifebuoy` / `headset`. Anything else is treated as raw SVG."),hidden:a.boolean().default(!1).describe("Hide the FAB entirely (page brings its own trigger that calls `instance.open()`)."),callout:se.optional()}).loose().describe(`Floating-launcher (FAB) appearance and behaviour. The FAB is the round button in the corner that opens the chat panel. Floating mode, and drawer mode as its edge tab.`).meta({examples:[{variant:`circle`,size:`md`},{variant:`pill`,label:`Ask AI`,icon:`spark`},{variant:`circle`,callout:{text:`👋 Need help?`,shape:`bubble`,persistent:!0}},{variant:`circle`,callout:{text:`Click to start`,shape:`pill`,delayMs:1200}}]}),le=a.enum([`local`,`server`,`disabled`]),ue=a.object({disableFileUpload:a.boolean().default(!1).describe("Turn OFF file uploads — hide the paperclip button + reject drag/drop/paste. Unset/`false` = enabled (default), `true` = disabled."),voice:le.default(`local`).describe("Voice input mode. `local` — speech recognition built into the browser (Web Speech API, free). `server` — record audio + upload to the transcribe endpoint. `disabled` — hide the mic button."),disableHumanInLoop:a.boolean().default(!1).describe("Turn OFF the human-in-the-loop tool UI — the inline ask-questions form + approve/reject controls for gated tools. Unset/`false` = shown (default), `true` = suppressed (the wire still carries the signals)."),disableEmailTranscript:a.boolean().default(!1).describe('Turn OFF the "Email transcript" item in the conversation menu, which emails a copy of the conversation to an address the visitor confirms (prefilled with the one the widget knows). Unset/`false` = shown once the chat has a real turn (default), `true` = hidden.'),enableOperatorRequest:a.boolean().default(!1).describe("Opt IN operator control — expose the 'Talk to a person' affordance + connected-to-operator states for this deployment. Unset/`false` = off (default), `true` = on. Unlike the `disable*` flags this is a positive opt-in for a new capability."),hideRequestOperatorButton:a.boolean().default(!1).describe("Hide the 'Talk to a person' button while operator requests stay on: visitors ask the AI for a person and its `request-operator` tool brings one in. Unset/`false` = shown (default), `true` = hidden.")}).loose().describe(`Capability flags — file upload, voice mode, HITL, email transcript, and operator requests.`).meta({examples:[{voice:`local`},{disableFileUpload:!0,voice:`disabled`},{voice:`server`,enableOperatorRequest:!0}]}),de=a.enum([`clear`,`expand`,`fullscreen`,`popOut`,`sound`,`history`,`language`,`theme`,`textSize`,`close`]),fe=a.array(de).max(10).describe("Which actions the header exposes. `history` + `close` are dedicated buttons; the rest appear in the ⋯ menu. Unlisted actions are hidden; order is irrelevant. Pick from: `clear`, `expand`, `fullscreen`, `popOut`, `sound`, `history`, `language`, `theme`, `textSize`, `close`. Per-mode defaults live in `DEFAULT_ACTIONS_BY_MODE`.").meta({examples:[[`theme`,`history`,`close`,`clear`,`fullscreen`,`sound`,`language`],[`theme`,`history`,`clear`,`language`],[`close`]]}),pe=a.object({actions:fe.optional().describe(`Which header actions are enabled (history/✕ buttons + ⋯ menu).`),variant:a.enum([`plain`,`accent`]).default(`plain`).describe("Header fill. `plain` uses the panel surface; `accent` fills it with the theme accent and its readable text colour (adaptive in light and dark)."),notice:a.string().max(1e3).optional().describe("Notice at the top of every conversation, in Markdown: links open in a new tab. May be an i18n key resolved against `i18n.strings`, so it can read in each language. Blank = the built-in \"You're chatting with an AI assistant.\" (`chatNotice`) in the visitor's language."),hideNotice:a.boolean().default(!1).describe("Turn OFF the conversation notice. Unset/`false` = shown (default), `true` = hidden.")}).loose().describe(`Panel-header configuration: actions, fill and the conversation notice.`).meta({examples:[{actions:[`theme`,`history`,`close`,`clear`,`fullscreen`]},{variant:`accent`,notice:`You're chatting with our AI assistant. See our [privacy policy](https://example.com/privacy).`},{hideNotice:!0}]}),T=a.enum([`messageReceived`,`messageSent`,`error`,`voiceStart`,`voiceStop`]),me=a.object({enabled:a.boolean().default(!0).describe(`Master on/off for audible notifications. On by default — browser autoplay policy still requires a prior user gesture before any sound plays.`),volume:a.number().min(0).max(1).default(.3).describe("Global volume 0..1. `0.3` (default) is intentionally subtle."),events:a.partialRecord(T,a.union([a.boolean(),a.string().min(1).max(2048)])).optional().describe("Per-event override map. Value: `true` = built-in tone, `false` = silent, `string` = URL to a custom audio file (mp3/wav/ogg).")}).loose().describe("Audible notifications. `events` accepts true (default tone), false (off), or a URL to an audio file.").meta({examples:[{enabled:!0,volume:.3},{enabled:!0,volume:.5,events:{messageReceived:!0,error:!1}},{enabled:!0,events:{messageReceived:`https://cdn.help.ai/ping.mp3`}}]}),he=a.object({enabled:a.boolean().default(!0).describe(`Master on/off. Default: on for touch devices, silently ignored elsewhere.`),events:a.partialRecord(T,a.union([a.boolean(),a.number().int(),a.array(a.number().int())])).optional().describe("Per-event vibration pattern. Value: `true` = default pattern, `false` = silent, number = single vibrate ms, array = `[vibrate, pause, vibrate, …]`.")}).loose().describe("Touch-device vibration. `events` accepts true (default), number (single vibrate ms), or [vibrate,pause,vibrate,…].").meta({examples:[{enabled:!0},{enabled:!0,events:{messageReceived:30,error:[40,60,40]}}]}),ge=a.object({sound:me.optional(),haptics:he.optional()}).loose().describe(`Audible + tactile feedback.`).meta({examples:[{sound:{enabled:!0,volume:.3},haptics:{enabled:!0}},{sound:{enabled:!1},haptics:{enabled:!1}}]}),E=a.enum([`circle`,`square`,`pill`]),D=a.enum([`arrowUp`,`paperPlane`,`send`,`chevron`]),O=a.enum([`filled`,`outline`,`ghost`]),k=a.object({shape:E.default(`circle`).describe("Send button outline shape — `circle` / `square` / `pill`."),icon:D.default(`arrowUp`).describe("Icon inside the send button — `arrowUp` / `paperPlane` / `send` / `chevron`."),variant:O.default(`filled`).describe("Fill treatment — `filled` (solid accent), `outline` (border only), `ghost` (no border, no fill).")}).loose().describe(`Send-button styling — shape, icon, and fill treatment.`).meta({examples:[{shape:`circle`,icon:`arrowUp`,variant:`filled`},{shape:`pill`,icon:`send`,variant:`outline`},{shape:`square`,icon:`paperPlane`,variant:`ghost`}]}),A=a.object({maxBytes:a.number().int().min(0).max(1073741824).default(10485760).describe("Maximum total size of the files attached to one message, in bytes. `10 MiB` (10485760) by default."),maxCount:a.number().int().min(0).max(100).default(10).describe(`Maximum number of attachments per message.`),accept:a.string().max(2e3).default(`*/*`).describe("Allowed MIME types — comma-separated `accept` attribute string, e.g. `image/*,application/pdf`.")}).loose().describe(`Client-side attachment limits. Server enforcement is still required.`).meta({examples:[{maxBytes:10485760,maxCount:10,accept:`*/*`},{maxBytes:5242880,maxCount:3,accept:`image/*,application/pdf`}]}),j=a.object({sendButton:k.optional(),attachments:A.optional()}).loose().describe(`Composer chrome — send-button styling + attachment limits.`).meta({examples:[{sendButton:{shape:`circle`,icon:`arrowUp`,variant:`filled`}},{sendButton:{shape:`pill`,icon:`send`,variant:`outline`}},{attachments:{maxBytes:5242880,maxCount:3}}]}),M=a.object({text:a.string().max(200).optional().describe("Visible attribution text (e.g. `Powered by Help AI`)."),href:a.url().max(2048).optional().describe("Click target — the attribution becomes a link. Must be a full URL (`https://…`)."),logoUrl:a.url().max(2048).optional().describe(`Small logo rendered before the text. Must be a full URL.`)}).loose().describe(`"Powered by …" attribution shown below the composer.`).meta({examples:[{text:`Powered by Help AI`},{text:`Powered by Help AI`,href:`https://help.ai`,logoUrl:`https://help.ai/logo.svg`}]}),N=a.object({poweredBy:M.optional(),composerDisclaimer:a.string().max(500).optional().describe(`Small muted text under the composer (like ChatGPT's 'ChatGPT can make mistakes.'). Empty = hidden.`)}).loose().describe(`Footer — attribution + composer disclaimer.`).meta({examples:[{poweredBy:{text:`Powered by Help AI`,href:`https://help.ai`}},{composerDisclaimer:`AI responses may be inaccurate.`}]}),P=a.record(a.string(),a.string()),F=a.union([P,a.record(m,P)]).describe(`Per-instance UI string overrides. Flat = active-locale only; nested = multi-locale map. Both forms are partial — missing keys fall through to built-in defaults.`).meta({examples:[{send:`Click`,stop:`Halt`,composerPlaceholder:`Type your question…`},{en:{send:`Send`,composerPlaceholder:`Type a message…`},fr:{send:`Envoyer`,composerPlaceholder:`Tapez un message…`}}]}),I=a.object({locale:m.optional().describe("BCP-47 locale tag forced for this widget instance (e.g. `fr-CA`). Page-owner explicit override."),defaultLocale:a.union([a.literal(`auto`),m]).default(`auto`).describe("Initial / fallback locale for users who haven't picked one. `auto` sniffs `navigator.language`."),availableLocales:a.array(m).max(200).optional().describe(`BCP-47 locale tags shown in the runtime language switcher. Hidden when fewer than 2 entries.`),strings:F.optional()}).loose().describe(`Locale + i18n overrides.`).meta({examples:[{defaultLocale:`auto`},{defaultLocale:`en`,availableLocales:[`en`,`fr`,`de`]},{locale:`fr-CA`,strings:{send:`Envoyer`}}]}),L=a.enum([`chat`,`home`,`help`,`news`]),_e=a.object({label:a.string().min(1).max(40).describe("Tab label — an i18n key (resolved against the i18n strings, e.g. `tabHome`) or a literal. Translations ride `i18n.strings`."),layout:L.describe("UI layout that renders this tab: `chat` (the conversation), `home`, `help`, or `news`."),contentCollectionIds:a.array(h).max(20).optional().describe("Content collections this tab shows, in order — the `contentCollectionIds` filter on `GET /pai/content`; Help groups its sections by them. Omit for the `chat` layout."),id:a.string().max(60).optional().describe("Stable id for navigation + last-tab persistence. Defaults to the first `contentCollectionIds` entry, else `layout`."),brandName:a.string().max(80).optional().describe("`home` — hero wordmark (e.g. your company name)."),hideGreeting:a.boolean().optional().describe("`home` — hide the greeting hero. Unset/`false` = shown (default), `true` = hidden."),greetingText:a.string().max(280).optional().describe("`home` — override the greeting headline (default 'How can we help?'); supports a `{name}` token."),userAvatars:a.array(a.object({id:a.string().min(1).max(100).optional().describe("Stable id: how its translations (`role`) find it."),name:a.string().min(1).max(80),avatar:a.string().max(2048).optional().describe("Image URL; falls back to initials of `name`."),role:a.string().max(80).optional()}).loose()).max(10).optional().describe("`home` — team/agent avatars shown in the hero."),hideSearchBar:a.boolean().optional().describe("`home` — hide the 'Search for help' bar. Unset/`false` = shown (default), `true` = hidden. The bar opens the Help tab, so it shows only when the widget has one."),hideRecentConversations:a.boolean().optional().describe("`home` — hide the visitor's most recent conversation card. Unset/`false` = shown (default), `true` = hidden."),status:a.object({text:a.string().min(1).max(120).optional().describe("`home` — status line; an i18n key or a literal (resolved via `localizeText`). Omit to use the built-in generic `homeStatus` string (localized, no custom key needed)."),level:a.string().max(40).optional().describe("`home` — status severity, drives the status icon colour. Free text; `operational` (green, default), `degraded` (amber), and `down` (red) are styled, any other value falls back to the operational style.").meta({examples:[`operational`,`degraded`,`down`]}),url:a.string().max(2048).optional().describe(`Opens in a new tab when tapped.`)}).optional().describe("`home` — system-status card. Omit to hide."),contentBlockTitle:a.string().max(80).optional().describe("`home` — heading for the content list: the pinned items of the tab's `contentCollectionIds` (default 'Popular articles').")}).loose(),ve=a.array(_e).max(4).describe("Messenger tabs — an ordered list of up to 4 tabs, each picking a `layout` + the content collections it shows (`contentCollectionIds`) + a translatable `label`. One tab → no tab bar (just that content); zero → an empty state. Floating / drawer / modal only.").meta({examples:[[{label:`tabConversations`,layout:`chat`}],[{label:`tabHome`,layout:`home`,brandName:`Acme`,contentBlockTitle:`Popular articles`,contentCollectionIds:[`019a0b6c-7e2a-7000-9d3e-4a5b6c7d8e01`]},{label:`tabConversations`,layout:`chat`},{id:`help`,label:`tabHelp`,layout:`help`,contentCollectionIds:[`019a0b6c-7e2a-7000-9d3e-4a5b6c7d8e01`,`019a0b6c-7e2a-7000-9d3e-4a5b6c7d8e02`]},{id:`news`,label:`tabNews`,layout:`news`,contentCollectionIds:[`019a0b6c-7e2a-7000-9d3e-4a5b6c7d8e03`]}]]}),ye=a.object({enabled:a.boolean().optional().describe("Master switch. Default `true` — the widget always fires; the data module gates ingestion per deployment server-side. Set `false` to silence the client entirely."),endpoint:a.url().max(2048).optional().describe("Pixel collector URL. Default: `${dataApiBaseUrl}/pai/elements-px.gif` (e.g. `https://help.ai/api/data/pai/elements-px.gif`). Must be a full URL."),sampleRate:a.number().min(0).max(1).optional().describe("Per-widget-runtime sampling 0..1 (one decision per mounted runtime, keeping that runtime's funnel intact). Default `1`."),token:a.string().max(512).optional().describe("Anti-forgery token, echoed as `tk=` on every hit. Server-issued in the `/handshake` response — never set by hand (see `docs/api/tracking-collector.md`).")}).loose().describe(`Anonymous usage tracking for the widget owner — GA-style pixel events (open, send, form submit, …) with page / device / locale dimensions. Never includes message or form content; the only visitor identifier is the widget's anonymous visitorId.`).meta({examples:[{enabled:!0},{enabled:!0,sampleRate:.5}]}),be=a.object({upload:a.string().min(1).max(2048).default(`/pai/upload-file`),transcribe:a.string().min(1).max(2048).default(`/pai/transcribe-audio`)}).loose().describe("HTTP endpoint overrides. `upload` / `transcribe` paths are appended to the agent base (`${baseUrl}/api/agent`); absolute URLs are accepted too.").meta({examples:[{upload:`/pai/upload-file`,transcribe:`/pai/transcribe-audio`},{upload:`https://help.ai/uploads/presign`}]}),R=a.object({id:a.string().min(1).max(200).optional().describe(`Host's stable id for the user — informational context the agent/backend can key on (not auth).`),email:a.string().min(1).max(320).optional().describe(`User email — surfaced to the agent for context (optional).`),name:a.string().min(1).max(200).optional().describe("Display name — shown in the Home greeting (`{name}`) and conversation transcripts (optional)."),plan:a.string().min(1).max(120).optional().describe("Subscription / pricing tier, e.g. `pro` (optional)."),role:a.string().min(1).max(120).optional().describe("The user's role on the host site, e.g. `admin` (optional)."),phone:a.string().min(1).max(40).optional().describe(`Phone number (optional).`)}).catchall(a.union([a.string(),a.number(),a.boolean()])).describe("Host-asserted visitor context (informational, untrusted — not authentication). Recognised `id` / `email` / `name` / `plan` / `role` / `phone` plus any extra custom scalar fields forwarded to the agent.").meta({examples:[{id:`u_123`},{id:`u_123`,email:`alex@acme.com`,name:`Alex Lee`,plan:`pro`}]}),xe=a.object({area:a.string().min(1).max(64).optional().describe(`Host-defined surface the visitor is on. Free-form; suggested: home | docs | help-desk | support | pricing | checkout | orders | account | blog.`),url:a.string().min(1).max(2048).optional().describe(`Full page URL. Auto-filled from the host page when omitted.`),path:a.string().min(1).max(2048).optional().describe("Page path, e.g. `/pricing/enterprise`."),title:a.string().min(1).max(300).optional().describe(`Human-readable page title.`)}).catchall(a.union([a.string(),a.number(),a.boolean()])).describe("Host-asserted page/visit context (informational, untrusted). Where the visitor is + the surface (`area`) they're using, plus any custom scalar fields, forwarded to the agent.").meta({examples:[{area:`pricing`,path:`/pricing`},{area:`help-desk`}]}),z=a.object({widgetId:a.string().min(1).max(80).default(`default`).describe(`Stable per-instance id used to namespace localStorage keys. Set this when mounting more than one widget on the same page so their conversation state doesn't collide.`),publicKey:a.string().min(1).max(200).optional().describe("Deployment public key (`agent_pk_…`) issued from the dashboard. Sent on every API call as the `x-public-key` header when present."),aiAgentDeploymentId:a.string().min(1).max(200).describe("Required deployment UUID from the dashboard. Picks which agent / settings bundle answers this mount. Sent as `x-ai-agent-deployment-id`."),baseUrl:a.string().min(1).max(2048).optional().describe("MAIN site origin (e.g. `https://help.ai`) — the API modules derive from it: agent API at `${baseUrl}/api/agent`, data API at `${baseUrl}/api/data`. Set this to point at your staging / self-hosted / custom backend. Default: the brand's `defaultBaseUrl` baked at build time."),agentApiBaseUrl:a.string().min(1).max(2048).optional().describe("Full agent-API base — set it to reach a STANDALONE `module-agent-api` directly (local module on its own port, e.g. `http://localhost:3069`; routes attach as-is: `/pai/handshake`). Precedence: this option > derived from the main origin (`${baseUrl}/api/agent`). Not server-pushable."),dataApiBaseUrl:a.string().min(1).max(2048).optional().describe("Full data-API base (e.g. `https://help.ai/api/data`, or a standalone local module like `http://localhost:3071`) — the service serving content and the tracking pixel. Precedence: this option > server-pushed `config.dataApiBaseUrl` > derived from the main origin (`${baseUrl}/api/data`)."),continueLink:a.string().min(1).max(400).optional().describe("A Continue in chat link's proof (`<conversationId>.<workspaceId>.<exp>.<signature>`), set by help.ai's own chat page for a visitor who came from an email: the widget opens that email conversation as its visitor, sending it as `x-continue-link` on every agent call. Not server-pushable."),userContext:R.optional(),pageContext:xe.optional(),endpoints:be.optional(),debug:a.union([a.boolean(),a.enum([`off`,`error`,`warn`,`info`,`debug`,`trace`])]).optional().describe('Console log verbosity. `false` / `"off"` silences everything (default in production). `true` → `"debug"`. Levels `error` / `warn` / `info` / `debug` / `trace` gate output additively. Use `"trace"` to capture per-chunk SSE frames + every state transition. Also toggleable at runtime via `chat.setDebug(level)` or `?<brand>-debug=trace` in the page URL — the URL beats this option, this option beats the persisted `localStorage` value.')}).loose().describe("Where the widget talks to and how it authenticates. Owned by the embedding developer (typically baked into the page template / env var) — distinct from `userPrefs`, which is the dashboard-pushable UX surface.").meta({examples:[{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`},{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`,widgetId:`support`},{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`,baseUrl:`https://api.acme.com`}]}),B=a.object({agent:g.optional(),presentation:S.optional(),behavior:te.optional(),theme:w.default(`host`).describe("Theme preference (`host`, the default, follows the page and else the OS) or a tokens override object (`accent`, `radius`, `fontFamily`)."),launcher:ce.optional(),header:pe.optional(),composer:j.optional(),feedback:ge.optional(),i18n:I.optional(),footer:N.optional(),features:ue.optional(),modules:ve.optional(),tracking:ye.optional()}).loose().describe("Portal-configurable widget settings — thirteen sections, one per dashboard tab. The backend pushes this shape on `/pai/handshake` under `config`.").meta({examples:[{presentation:{mode:`floating`,position:`bottom-right`},theme:`auto`},{presentation:{mode:`floating`},theme:{accent:`#7c3aed`,radius:`12px`},launcher:{variant:`pill`,label:`Ask AI`,callout:{text:`👋 Need help?`}}},{presentation:{mode:`inline`},behavior:{responseMode:`streaming`},features:{voice:`local`}}]}),V=z.extend({...B.shape,site:a.unknown().optional().describe('Site config — applies in `mode: "page"`. Comes from the handshake response, not user-edited.'),blocks:a.unknown().optional().describe('Blocks (nav + link cards) — applies in `mode: "page"`. Comes from the handshake response.')}).describe("Full tooling config — connection (where + auth) + widget settings (look + behaviour) + page-mode handshake extras. The production widget does not import this Zod schema. Mode-specific constraints (e.g. `position` only meaningful in `floating`) are NOT enforced here so the same object can flow across mode changes.").meta({examples:[{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`,presentation:{mode:`floating`},theme:`auto`},{publicKey:`agent_pk_demo`,aiAgentDeploymentId:`01900000-0000-7000-8000-000000000001`,presentation:{mode:`modal`,size:{width:`720px`,height:`640px`}}}]});V.partial(),B.partial(),z.partial();const Se=B.partial().extend({dataApiBaseUrl:a.string().min(1).max(2048).optional(),storageVersion:a.string().min(1).max(64).optional(),history:a.object({enabled:a.boolean().optional().describe("`false` hides the history button and never lists past conversations. Default `true`.")}).loose().optional().describe(`The deployment's Keep conversations setting.`),login:a.object({url:a.url({protocol:/^https?$/}).max(2048).refine(e=>e.includes(`{returnTo}`),`Put {returnTo} where your login page reads the page to come back to`).optional().describe("Your site's login page, as a URI Template with `{returnTo}` (RFC 6570): Log in sends the page there, with `{returnTo}` replaced by the page's address, URL-encoded. Set, login is on: anonymous visitors see the Log in bar and the Log in screen has a Log in button. A page listening to `loginRequested` opens its own login instead.").meta({examples:[`https://globalvillages.com/login?return_to={returnTo}`]}),required:a.boolean().optional().describe("Only visitors your site logs in (`userToken`) can chat: anyone else sees the Log in screen in place of the composer. Default `false`."),hidePrompt:a.boolean().optional().describe("Hide the Log in bar for anonymous visitors: logging in then starts from your site's own button (`loginRequested`) or the Log in screen. Default `false`."),hideUser:a.boolean().optional().describe('Hide the "Logged in as Maya" bar for logged-in visitors. Default `false`.')}).optional().describe(`The deployment's login settings. See [Logging in](../features/login.md).`),maxMessageCharacters:a.number().int().positive().optional().describe("The longest visitor message the deployment takes: the composer stops there, and a longer message is refused with `400 MESSAGE_TOO_LONG`.")}),Ce=a.object({title:a.string().min(1).max(120).optional().describe(`Brand / site name. Used as the logo's alt-text fallback.`),logo:u.optional().describe(`Brand logo shown at the top of the page-mode sidebar.`),logoDark:u.optional().describe("Optional dark-theme logo variant. Falls back to `logo` when the active theme is light or `logoDark` is unset.")}).loose(),we=a.object({navigation:a.array(d).max(100).optional().describe(`Sidebar navigation links (vertical list, primary nav).`),linkCards:a.array(d).max(100).optional().describe("Sidebar link cards (richer entries with optional `description`).")}).loose(),Te=a.object({id:a.string(),role:a.enum([`assistant`,`system`]),text:a.string()}).loose(),Ee=a.object({id:a.string(),label:a.string(),text:a.string().optional()}).loose();a.object({deployment:a.object({id:a.string(),name:a.string(),slug:a.string().optional(),publicKey:a.string().optional()}).loose(),agent:a.object({id:a.string(),name:a.string(),title:a.string().optional(),status:a.enum([`online`,`away`,`offline`]).optional()}).loose(),config:Se.optional(),site:Ce.optional(),blocks:we.optional(),welcome:a.object({messages:a.array(Te).optional(),suggestions:a.array(Ee).optional()}).loose().optional(),translations:a.array(a.object({locale:a.string()}).loose()).optional(),visitorId:a.string(),conversationId:a.string(),loginStatus:a.enum([`loggedIn`,`expired`,`anonymous`]).optional(),userPrefs:a.record(a.string(),a.unknown()).optional(),rebind:a.object({conversationId:a.string()}).strict().optional()}).loose();function H({description:e,examples:t,onPick:n}){let[a,o]=i(!1),u=r(null);return!e&&t.length===0?null:/* @__PURE__ */ l(s,{children:[/* @__PURE__ */ c(`button`,{ref:u,type:`button`,class:`cfg-help-trigger`,"aria-label":`Field info`,"aria-expanded":a?`true`:`false`,title:`Field info`,"data-open":a?`true`:void 0,onClick:e=>{e.preventDefault(),e.stopPropagation(),o(e=>!e)},children:/* @__PURE__ */ c(`span`,{"aria-hidden":`true`,children:`?`})}),a?/* @__PURE__ */ c(De,{anchor:u,description:e,examples:t,onClose:()=>o(!1),onPick:e=>{n(e),o(!1)}}):null]})}function De({anchor:n,description:a,examples:s,onClose:u,onPick:d}){let f=r(null),[p,m]=i(null);return t(()=>{function e(){let e=n.current;if(!e)return;let t=e.getBoundingClientRect(),r=f.current?.offsetWidth||320,i=f.current?.offsetHeight||240,a=window.innerHeight-t.bottom>=i+8+4?t.bottom+6:Math.max(8,t.top-i-6),o=Math.max(8,Math.min(a,window.innerHeight-i-8)),s=window.innerWidth-t.right,c=window.innerWidth-r-8;m({top:o,right:Math.max(8,Math.min(c,s))})}e();let t=requestAnimationFrame(e);return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{cancelAnimationFrame(t),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[n]),e(()=>{function e(e){e.key===`Escape`&&u()}function t(e){let t=f.current,r=n.current,i=e.target instanceof Node?e.target:null;t&&i&&(t.contains(i)||r?.contains(i)||u())}window.addEventListener(`keydown`,e);let r=setTimeout(()=>window.addEventListener(`mousedown`,t),0);return()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`mousedown`,t),clearTimeout(r)}},[n,u]),p?o(/* @__PURE__ */ l(`div`,{ref:f,class:`cfg-help-popover`,role:`dialog`,style:{top:`${p.top}px`,right:`${p.right}px`},children:[a?/* @__PURE__ */ c(`p`,{class:`cfg-help-description`,children:a}):null,s.length>0?/* @__PURE__ */ l(`div`,{class:`cfg-help-examples`,children:[/* @__PURE__ */ l(`span`,{class:`cfg-help-examples-title`,children:[`Example`,s.length===1?``:`s`,` (`,s.length,`)`]}),/* @__PURE__ */ c(`ul`,{children:s.map((e,t)=>/* @__PURE__ */ c(`li`,{children:/* @__PURE__ */ c(`button`,{type:`button`,class:`cfg-help-example-btn`,onClick:()=>d(e),children:/* @__PURE__ */ c(`code`,{children:Oe(e)})})},t))})]}):null]}),document.body):null}function Oe(e){if(typeof e==`string`)return e.length>60?`${e.slice(0,60)}…`:e;try{let t=JSON.stringify(e);return t.length>80?`${t.slice(0,80)}…`:t}catch{return String(e)}}function ke({name:e,label:t,value:n,defaultValue:r,description:i,help:a,onChange:o}){return/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-boolean`,title:i,children:[/* @__PURE__ */ c(`input`,{type:`checkbox`,name:e,checked:n??r??!1,onInput:e=>o(e.currentTarget.checked)}),/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),a]})}function Ae({name:e,label:t,value:n,description:r,help:i,onChange:a}){let o=n??``,s=/^#[0-9a-f]{6}$/i.test(o)?o:`#000000`;return/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-color`,title:r,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),i]}),/* @__PURE__ */ l(`span`,{class:`cfg-color-row`,children:[/* @__PURE__ */ c(`input`,{type:`color`,value:s,"aria-label":`${t} swatch`,onInput:e=>a(e.currentTarget.value)}),/* @__PURE__ */ c(`input`,{type:`text`,name:e,value:n??``,placeholder:`#10b981 / oklch(...) / var(...)`,onInput:e=>{let t=e.currentTarget.value;a(t===``?void 0:t)}})]})]})}function je({name:e,label:t,value:n,defaultValue:r,description:i,options:a,optional:o,help:s,onChange:u}){let d=n??r??(o?``:void 0),f=o?[{id:``,label:`default`},...a.map(e=>({id:e,label:e}))]:a.map(e=>({id:e,label:e}));return/* @__PURE__ */ l(`div`,{class:`cfg-field cfg-field-enum`,title:i,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),s]}),/* @__PURE__ */ c(`div`,{class:`cfg-segmented`,"data-segmented-name":e,role:`radiogroup`,"aria-label":t,children:f.map(e=>{let t=d===e.id;return/* @__PURE__ */ c(`button`,{type:`button`,role:`radio`,"aria-checked":t?`true`:`false`,class:`cfg-segmented-item`,"data-value":e.id,"data-active":t?`true`:void 0,onClick:()=>u(e.id===``?void 0:e.id),children:e.label},e.id)})}),/* @__PURE__ */ c(`input`,{type:`hidden`,name:e,value:n??``})]})}function Me({name:e,label:t,value:n,step:r,min:i,max:a,description:o,help:s,onChange:u}){return/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-number`,title:o,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),s]}),/* @__PURE__ */ c(`input`,{type:`number`,name:e,value:n===void 0?``:String(n),step:r,min:i,max:a,onInput:e=>{let t=e.currentTarget.value;if(t===``)return u(void 0);let n=Number(t);Number.isFinite(n)&&u(n)}})]})}function Ne({name:e,label:t,value:n,placeholder:r,maxLength:i,description:a,help:o,onChange:s}){return/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-string`,title:a,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-label`,children:t}),o]}),/* @__PURE__ */ c(`input`,{type:`text`,name:e,value:n??``,placeholder:r,maxLength:i,onInput:e=>{let t=e.currentTarget.value;s(t===``?void 0:t)}})]})}function U(e){return e._def??{}}function W(e){let t=e,n=!1,r=!1,i;for(let e=0;e<8;e++){let e=U(t),a=e.type;if(a===`optional`&&e.innerType)n=!0,t=e.innerType;else if(a===`nullable`&&e.innerType)r=!0,t=e.innerType;else if(a==="default"&&e.innerType)i=typeof e.defaultValue==`function`?e.defaultValue():e.defaultValue,t=e.innerType;else break}return{inner:t,optional:n,nullable:r,defaultValue:i}}function G(e){switch(U(e).type){case`string`:return`string`;case`number`:return`number`;case`boolean`:return`boolean`;case`enum`:return`enum`;case`object`:return`object`;case`array`:return`array`;case`union`:return`union`;case`literal`:return`literal`;case`record`:return`record`;default:return`unknown`}}function K(e){let t=U(e);return t.entries?Object.values(t.entries):[]}function q(e){return U(e).shape??{}}function J(e){let t=e._zod?.bag;return{maxLength:typeof t?.maximum==`number`?t.maximum:void 0,minLength:typeof t?.minimum==`number`?t.minimum:void 0,pattern:t?.pattern instanceof RegExp?t.pattern.source:void 0}}function Y(e){return/color|accent|background/i.test(e)}function X(e){return e.description}function Z(e){let t=e.meta?.();return Array.isArray(t?.examples)?t.examples:[]}function Q(e){let t=Z(e);if(t.length!==0)try{return JSON.stringify(t[0])}catch{return}}function $({schema:e,value:t,path:n,onChange:r,columns:i=1}){let a=q(e),o=t??{},s={},u=e.safeParse(o);if(!u.success)for(let e of u.error.issues){let t=e.path[0];if(typeof t!=`string`&&typeof t!=`number`)continue;let n=String(t);n in s||(s[n]=e.message)}function d(e,t){let n={...o};t===void 0?delete n[e]:n[e]=t,r(Object.keys(n).length===0?void 0:n)}let f=Object.entries(a).map(([e,t])=>{let{inner:r,optional:i,defaultValue:a}=W(t),u=G(r),f=[...n,e].join(`.`),p=Le(e),m=o[e],h=X(t)??X(r),g=Z(t),_=g.length>0?g:Z(r),v=s[e];function y(t){return d(e,t)}let b=/* @__PURE__ */ c(H,{description:h,examples:_,onPick:y}),x=`${f}-error`;function S(e){return/* @__PURE__ */ l(`div`,{class:`cfg-field-wrap`,"data-invalid":v?`true`:void 0,children:[e,/* @__PURE__ */ c(`p`,{class:`cfg-field-error`,id:x,role:v?`alert`:void 0,children:v?`⚠ ${v}`:``})]})}switch(u){case`string`:return Y(e)?S(/* @__PURE__ */ c(Ae,{name:f,label:p,value:typeof m==`string`?m:void 0,description:h,help:b,onChange:t=>d(e,t)},e)):S(/* @__PURE__ */ c(Ne,{name:f,label:p,value:typeof m==`string`?m:void 0,maxLength:J(r).maxLength,placeholder:Re(a,_),description:h,help:b,onChange:t=>d(e,t)},e));case`number`:return S(/* @__PURE__ */ c(Me,{name:f,label:p,value:typeof m==`number`?m:void 0,description:h,help:b,onChange:t=>d(e,t)},e));case`boolean`:return S(/* @__PURE__ */ c(ke,{name:f,label:p,value:typeof m==`boolean`?m:void 0,defaultValue:typeof a==`boolean`?a:void 0,description:h,help:b,onChange:t=>d(e,t)},e));case`enum`:return S(/* @__PURE__ */ c(je,{name:f,label:p,value:typeof m==`string`?m:void 0,defaultValue:typeof a==`string`?a:void 0,description:h,options:K(r),optional:i,help:b,onChange:t=>d(e,t)},e));case`object`:return/* @__PURE__ */ c(Ie,{label:p,description:h,examples:_,onPick:t=>d(e,t),isPopulated:m!==void 0,children:/* @__PURE__ */ c($,{schema:r,value:Pe(m)?m:void 0,path:[...n,e],onChange:t=>d(e,t)})},e);default:{let n=Q(t)??Q(r);return S(/* @__PURE__ */ l(`label`,{class:`cfg-field cfg-field-json`,title:h,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label-row`,children:[/* @__PURE__ */ l(`span`,{class:`cfg-label`,children:[p,` `,/* @__PURE__ */ c(`span`,{class:`cfg-hint`,children:`(JSON)`})]}),b]}),/* @__PURE__ */ c(`textarea`,{name:f,value:m===void 0?``:JSON.stringify(m,null,2),rows:3,placeholder:n,onInput:t=>{let n=t.currentTarget.value;if(n===``)return d(e,void 0);try{d(e,JSON.parse(n))}catch{}}})]},e))}}});if(n.length===0&&i===2){let e=Object.entries(a),t=[],n=[],r=0,i=0;for(let[a,s]of f.entries()){let c=e[a];if(!c)continue;let[l,u]=c,d=Fe(u,o[l]);r<=i?(t.push(s),r+=d):(n.push(s),i+=d)}return/* @__PURE__ */ l(`div`,{class:`cfg-object cfg-object-masonry`,children:[/* @__PURE__ */ c(`div`,{class:`cfg-masonry-col`,children:t}),/* @__PURE__ */ c(`div`,{class:`cfg-masonry-col`,children:n})]})}return/* @__PURE__ */ c(`div`,{class:`cfg-object`,children:f})}function Pe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Fe(e,t){if(t===void 0||typeof t==`object`&&t&&Object.keys(t).length===0)return 1;let{inner:n}=W(e);if(G(n)===`object`){let e=q(n);return 1+Object.keys(e).length}return 1}function Ie({label:e,description:t,examples:n,onPick:r,isPopulated:i,children:a}){return/* @__PURE__ */ l(`details`,{class:`cfg-nested`,open:i,title:t,children:[/* @__PURE__ */ l(`summary`,{class:`cfg-nested-summary`,children:[/* @__PURE__ */ c(`span`,{class:`cfg-nested-label`,children:e}),/* @__PURE__ */ c(H,{description:t,examples:n,onPick:r})]}),a]})}function Le(e){let t=e.replace(/([A-Z])/g,` $1`).trim();return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function Re(e,t){if(typeof e==`string`)return e;let n=t[0];return typeof n==`string`?n:void 0}function ze({schema:e,value:t,onChange:r,title:i,columns:a=1}){let o=e??V,s=n(()=>JSON.stringify(t,null,2),[t]),u=Object.keys(t).length===0;return/* @__PURE__ */ l(`div`,{class:`cfg-root`,children:[/* @__PURE__ */ l(`div`,{class:`cfg-header`,children:[i?/* @__PURE__ */ c(`h2`,{class:`cfg-title`,children:i}):/* @__PURE__ */ c(`span`,{}),/* @__PURE__ */ c(`button`,{type:`button`,class:`cfg-reset`,onClick:()=>r({}),disabled:u,title:`Clear every field — schema defaults take over`,children:`Reset to defaults`})]}),/* @__PURE__ */ c($,{schema:o,value:t,path:[],onChange:e=>r(e??{}),columns:a}),/* @__PURE__ */ l(`details`,{class:`cfg-json`,children:[/* @__PURE__ */ c(`summary`,{children:`JSON output`}),/* @__PURE__ */ c(`pre`,{children:s})]})]})}export{ze as Configurator,$ as ObjectField,K as enumValues,G as kindOf,Y as looksLikeColor,q as objectFields,Q as placeholderFromExamples,X as schemaDescription,Z as schemaExamples,J as stringHints,W as unwrap};
2
2
  //# sourceMappingURL=configurator.mjs.map
@@ -156,13 +156,14 @@ ran from one that didn't; everything else works the same.
156
156
 
157
157
  ## What the visitor sees
158
158
 
159
- A tool that runs on its own appears as a step when the deployment shows steps (`behavior.stepDisplay.showSteps`,
159
+ Every call to a page tool carries the origin `webmcp`. A tool that runs on its own appears as a step when the
160
+ deployment shows that origin and kind (`behavior.stepDisplay.stepsFrom` with `webmcp`, `stepsShown` with `unasked`;
160
161
  `../features/step-display.md`), named by its `title` with your site's host as its
161
162
  system: "Working", then done, "Failed" (or "Didn't work" with step details `values`), or "Stopped" when the visitor stopped
162
163
  it or moved on, or a reload cut it short. A tool with `consequentialHint` shows an approval card, "Place your order?",
163
164
  with its `preview` and every input value; Decline tells the agent the visitor chose not to go ahead, and the function
164
- never runs. When the agent's auto mode rules allow the call, there is no card: it runs at once, and reads "Approved
165
- automatically" where the deployment shows who decided.
165
+ never runs. When the agent's auto mode rules allow the call, there is no card: it runs at once, and reads "Auto-approved"
166
+ where the deployment shows steps the rules decided (`auto-decided`).
166
167
 
167
168
  ## Events
168
169