@runtypelabs/persona 4.2.0 → 4.3.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/README.md +22 -6
- package/dist/animations/glyph-cycle.d.cts +1 -1
- package/dist/animations/glyph-cycle.d.ts +1 -1
- package/dist/animations/{types-B_xbfvR0.d.cts → types-C6tFDxKy.d.cts} +1 -1
- package/dist/animations/{types-B_xbfvR0.d.ts → types-C6tFDxKy.d.ts} +1 -1
- package/dist/animations/wipe.d.cts +1 -1
- package/dist/animations/wipe.d.ts +1 -1
- package/dist/codegen.cjs +6 -6
- package/dist/codegen.js +9 -9
- package/dist/index.cjs +44 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -3
- package/dist/index.d.ts +101 -3
- package/dist/index.global.js +33 -33
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +44 -44
- package/dist/index.js.map +1 -1
- package/dist/install.global.js +1 -1
- package/dist/install.global.js.map +1 -1
- package/dist/launcher.global.js.map +1 -1
- package/dist/smart-dom-reader.d.cts +76 -1
- package/dist/smart-dom-reader.d.ts +76 -1
- package/dist/theme-editor-preview.cjs +35 -35
- package/dist/theme-editor-preview.d.cts +76 -1
- package/dist/theme-editor-preview.d.ts +76 -1
- package/dist/theme-editor-preview.js +37 -37
- package/dist/theme-editor.cjs +1 -1
- package/dist/theme-editor.d.cts +76 -1
- package/dist/theme-editor.d.ts +76 -1
- package/dist/theme-editor.js +1 -1
- package/package.json +1 -1
- package/src/client.test.ts +349 -29
- package/src/client.ts +96 -24
- package/src/defaults.ts +2 -0
- package/src/index-core.ts +2 -0
- package/src/install.ts +9 -1
- package/src/session.ts +6 -3
- package/src/session.voice.test.ts +65 -0
- package/src/types.ts +57 -2
- package/src/utils/__fixtures__/unified-translator.oracle.ts +3 -3
- package/src/utils/code-generators.ts +10 -0
- package/src/utils/target.test.ts +51 -0
- package/src/utils/target.ts +90 -0
package/dist/install.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var SiteAgentInstaller=(()=>{var L=Object.defineProperty;var
|
|
1
|
+
"use strict";var SiteAgentInstaller=(()=>{var L=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var Q=(d,l,m,r)=>{if(l&&typeof l=="object"||typeof l=="function")for(let i of J(l))!H.call(d,i)&&i!==m&&L(d,i,{get:()=>l[i],enumerable:!(r=O(l,i))||r.enumerable});return d};var N=d=>Q(L({},"__esModule",{value:!0}),d);var K={};(function(){"use strict";if(window.__siteAgentInstallerLoaded)return;window.__siteAgentInstallerLoaded=!0;let l=(()=>{let t=document.currentScript;if(!t)return{};let n={},e=t.getAttribute("data-config");if(e)try{let w=e.replace(/[\r\n]+\s*/g,""),h=JSON.parse(w);if(h.config){let{__proto__:z,constructor:G,prototype:V,...D}=h;Object.assign(n,D)}else n.config=h}catch(w){console.error("Failed to parse data-config JSON:",w)}let o=t.getAttribute("data-runtype-token");o&&(n.clientToken=o);let s=t.getAttribute("data-flow-id");s&&(n.flowId=s);let a=t.getAttribute("data-agent-id");a&&(n.agentId=a);let c=t.getAttribute("data-api-url");c&&(n.apiUrl=c);let I=t.getAttribute("data-preview-param");return I&&(n.previewQueryParam=I),n})(),r={...window.siteAgentConfig||{},...l},i=(t,n)=>{try{t==null||t(n)}catch(e){console.error("[Persona] lifecycle callback threw:",e)}},u=(t,n)=>{try{window.dispatchEvent(new CustomEvent(t,{detail:n}))}catch{}},f=(t,n)=>{console.error("Failed to install AgentWidget:",n),i(r.onError,{phase:t,error:n}),u("persona:error",{phase:t,error:n})},y=t=>{var e,o;let n=(e=t.launcher)!=null?e:{};return n.enabled===!1?!1:((o=n.mountMode)!=null?o:"floating")==="floating"};if(i(r.onScriptLoad,{version:r.version||"latest"}),u("persona:script-load",{version:r.version||"latest"}),!(()=>{if(!r.previewQueryParam)return!0;let n=new URLSearchParams(window.location.search).get(r.previewQueryParam);return n!==null&&n!==""&&n.toLowerCase()!=="false"&&n!=="0"})())return;let U=r.version||"latest",P=r.cdn||"jsdelivr",E=r.autoInit!==!1,j=()=>{if(r.cssUrl&&r.jsUrl){let o=r.jsUrl.replace(/index\.global\.js($|\?)/,"launcher.global.js$1");return{cssUrl:r.cssUrl,jsUrl:r.jsUrl,launcherUrl:o!==r.jsUrl?o:null}}let n=`/npm/@runtypelabs/persona@${U}/dist`,e=P==="unpkg"?"https://unpkg.com":"https://cdn.jsdelivr.net";return{cssUrl:`${e}${n}/widget.css`,jsUrl:`${e}${n}/index.global.js`,launcherUrl:`${e}${n}/launcher.global.js`}},{cssUrl:b,jsUrl:g,launcherUrl:p}=j(),T=()=>!!document.head.querySelector("link[data-persona]")||!!document.head.querySelector('link[href*="widget.css"]'),k=()=>!!window.AgentWidget,W=t=>{let n=!1,e=()=>{n||(n=!0,t())},o=()=>{typeof requestIdleCallback!="undefined"?requestIdleCallback(()=>{requestAnimationFrame(()=>{requestAnimationFrame(e)})},{timeout:3e3}):setTimeout(e,300)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",o):o()},A=()=>new Promise((t,n)=>{if(T()){t();return}let e=document.createElement("link");e.rel="stylesheet",e.href=b,e.setAttribute("data-persona","true"),e.onload=()=>t(),e.onerror=()=>n(new Error(`Failed to load CSS from ${b}`)),document.head.appendChild(e)}),C=()=>new Promise((t,n)=>{if(k()){t();return}let e=document.createElement("script");e.src=g,e.async=!0,e.onload=()=>t(),e.onerror=()=>n(new Error(`Failed to load JS from ${g}`)),document.head.appendChild(e)}),$=()=>!!window.AgentWidgetLauncher,F=()=>new Promise((t,n)=>{if($()||!p){t();return}let e=document.createElement("script");e.src=p,e.async=!0,e.onload=()=>t(),e.onerror=()=>n(new Error(`Failed to load launcher from ${p}`)),document.head.appendChild(e)}),M=()=>{let t=()=>{if(!k()){let e=document.createElement("link");e.rel="prefetch",e.as="script",e.href=g,document.head.appendChild(e)}let n=g.replace(/index\.global\.js($|\?)/,"markdown-parsers.js$1");if(n!==g){let e=document.createElement("link");e.rel="prefetch",e.as="script",e.href=n,document.head.appendChild(e)}};typeof requestIdleCallback!="undefined"?requestIdleCallback(t,{timeout:4e3}):setTimeout(t,1200)},v=()=>{let t=r.target||"body",n={...r.config};r.apiUrl&&!n.apiUrl&&(n.apiUrl=r.apiUrl),r.clientToken&&!n.clientToken&&(n.clientToken=r.clientToken),r.flowId&&!n.flowId&&(n.flowId=r.flowId),r.agentId&&!n.agentId&&(n.agentId=r.agentId);let e=!!(n.apiUrl||n.clientToken);return{target:t,widgetConfig:n,hasApiConfig:e}},S=(t=!1)=>{var s;if(!window.AgentWidget||!window.AgentWidget.initAgentWidget){console.warn("AgentWidget not available. Make sure the script loaded successfully.");return}let{target:n,widgetConfig:e,hasApiConfig:o}=v();if(!(!o&&Object.keys(e).length===0)){!e.postprocessMessage&&window.AgentWidget.markdownPostprocessor&&(e.postprocessMessage=({text:a})=>window.AgentWidget.markdownPostprocessor(a));try{let a=window.AgentWidget.initAgentWidget({target:n,config:e,useShadowDom:(s=r.useShadowDom)!=null?s:!1,windowKey:r.windowKey});return t&&a&&typeof a.open=="function"&&a.open(),!t&&y(e)&&(i(r.onLauncherShown,{deferred:!1}),u("persona:launcher-shown",{deferred:!1})),i(r.onChatReady,a),u("persona:chat-ready",a),a}catch(a){f("init",a)}}},_=t=>{var a;let n=t.persistState;if(!n)return!1;let e=typeof n=="object"?n:null;if(e&&((a=e.persist)==null?void 0:a.openState)===!1)return!1;let o=e&&e.keyPrefix||"persona-",s=e&&e.storage||"session";try{return(s==="local"?window.localStorage:window.sessionStorage).getItem(`${o}widget-open`)==="true"}catch{return!1}},x=t=>{var e;return!(!p||!y(t)||((e=t.launcher)!=null?e:{}).autoExpand===!0||typeof t.onStateLoaded=="function"||_(t))},q=(t,n)=>{let e="idle",o,s=()=>{e==="idle"&&(e="loading",C().then(()=>{S(!0),o==null||o.destroy(),e="done"}).catch(c=>{e="idle",console.error("Failed to load AgentWidget on open:",c),i(r.onError,{phase:"bundle",error:c}),u("persona:error",{phase:"bundle",error:c})}))},a=window.AgentWidgetLauncher.mount({target:t,config:n,onOpen:s});o=a,i(r.onLauncherShown,{deferred:!0,element:a.element}),u("persona:launcher-shown",{deferred:!0,element:a.element}),M()};W(async()=>{try{let t=E&&(r.config||r.apiUrl||r.clientToken);if(t){let{target:n,widgetConfig:e}=v();if(x(e))try{if(await Promise.all([A(),F()]),window.AgentWidgetLauncher&&window.AgentWidgetLauncher.mount){q(n,e);return}}catch(o){console.warn("Deferred launcher failed; falling back to eager load.",o)}}try{await A()}catch(n){return f("css",n)}try{await C()}catch(n){return f("bundle",n)}t&&setTimeout(()=>S(!1),0)}catch(t){f("init",t)}})})();return N(K);})();
|
|
2
2
|
//# sourceMappingURL=install.global.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/install.ts"],"sourcesContent":["/**\n * Standalone installer script for easy script tag installation\n * This script automatically loads CSS and JS, then initializes the widget\n * if configuration is provided via window.siteAgentConfig\n */\n\nexport {};\n\ninterface SiteAgentInstallConfig {\n version?: string;\n cdn?: \"unpkg\" | \"jsdelivr\";\n cssUrl?: string;\n jsUrl?: string;\n target?: string | HTMLElement;\n config?: any;\n autoInit?: boolean;\n // Client token mode options (can also be set via data attributes)\n clientToken?: string;\n flowId?: string;\n apiUrl?: string;\n // Optional query param key that gates widget installation in preview mode\n previewQueryParam?: string;\n // Shadow DOM option (defaults to false for better CSS compatibility)\n useShadowDom?: boolean;\n // Expose the widget handle on window[windowKey] for programmatic access\n windowKey?: string;\n /**\n * Fired as soon as the installer script executes, before it loads or gates\n * anything. For diagnostics / load-timing baselines (\"did my embed run\").\n */\n onScriptLoad?: (info: { version: string }) => void;\n /**\n * Fired when the floating launcher is painted on the page: at page-load time.\n * Deferred installs: the critical launcher mounts. Eager floating installs:\n * the full widget's launcher mounts. Use this for \"widget appeared\" analytics.\n * Does NOT fire for inline / docked / composer-bar installs (no floating\n * launcher): use `onChatReady` there.\n */\n onLauncherShown?: (info: { deferred: boolean; element?: HTMLElement }) => void;\n /**\n * Fired when the full widget is initialized and its controller API is\n * callable. Deferred installs: after the user first opens the panel. Eager\n * installs: on page load.\n */\n onChatReady?: (handle: any) => void;\n /**\n * Fired when a load step fails (stylesheet, full bundle, or init), so you can\n * detect ad-blocked / timed-out installs instead of failing silently.\n */\n onError?: (info: { phase: \"css\" | \"bundle\" | \"init\"; error: unknown }) => void;\n}\n\ndeclare global {\n interface Window {\n siteAgentConfig?: SiteAgentInstallConfig;\n AgentWidget?: any;\n AgentWidgetLauncher?: any;\n }\n}\n\n(function() {\n \"use strict\";\n\n // Prevent double installation\n if ((window as any).__siteAgentInstallerLoaded) {\n return;\n }\n (window as any).__siteAgentInstallerLoaded = true;\n\n /**\n * Read configuration from data attributes on the current script tag.\n * Supports: data-config (JSON), data-runtype-token, data-flow-id, data-api-url\n */\n const getConfigFromScript = (): Partial<SiteAgentInstallConfig> => {\n // Try to get the current script element\n const script = document.currentScript as HTMLScriptElement | null;\n if (!script) return {};\n\n const scriptConfig: Partial<SiteAgentInstallConfig> = {};\n\n // Full config from data-config attribute (JSON string)\n const configJson = script.getAttribute('data-config');\n if (configJson) {\n try {\n // HTML attributes preserve literal newlines/tabs which are invalid\n // control characters inside JSON string literals: strip them.\n const normalizedJson = configJson.replace(/[\\r\\n]+\\s*/g, '');\n const parsedConfig = JSON.parse(normalizedJson);\n // If it has nested 'config' property, use it; otherwise treat as widget config\n if (parsedConfig.config) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { __proto__: _a, constructor: _b, prototype: _c, ...safeConfig } = parsedConfig;\n Object.assign(scriptConfig, safeConfig);\n } else {\n // Treat the entire object as widget config\n scriptConfig.config = parsedConfig;\n }\n } catch (e) {\n console.error(\"Failed to parse data-config JSON:\", e);\n }\n }\n\n // Client token from data attribute (primary method for client token mode)\n const token = script.getAttribute('data-runtype-token');\n if (token) {\n scriptConfig.clientToken = token;\n }\n\n // Optional flow ID\n const flowId = script.getAttribute('data-flow-id');\n if (flowId) {\n scriptConfig.flowId = flowId;\n }\n\n // Optional API URL override\n const apiUrl = script.getAttribute('data-api-url');\n if (apiUrl) {\n scriptConfig.apiUrl = apiUrl;\n }\n\n // Optional preview query param gate\n const previewQueryParam = script.getAttribute('data-preview-param');\n if (previewQueryParam) {\n scriptConfig.previewQueryParam = previewQueryParam;\n }\n\n return scriptConfig;\n };\n\n // Get config from script attributes (must be called synchronously during script execution)\n const scriptConfig = getConfigFromScript();\n\n // Merge script attributes with window config (script attributes take precedence)\n const windowConfig: SiteAgentInstallConfig = window.siteAgentConfig || {};\n const config: SiteAgentInstallConfig = { ...windowConfig, ...scriptConfig };\n\n // --- Lifecycle helpers -----------------------------------------------------\n // A throwing user callback must never break the installer.\n const safeCall = <T>(fn: ((arg: T) => void) | undefined, arg: T): void => {\n try {\n fn?.(arg);\n } catch (e) {\n console.error(\"[Persona] lifecycle callback threw:\", e);\n }\n };\n const dispatchLifecycle = (name: string, detail: unknown): void => {\n try {\n window.dispatchEvent(new CustomEvent(name, { detail }));\n } catch {\n /* CustomEvent unsupported: ignore */\n }\n };\n const fail = (phase: \"css\" | \"bundle\" | \"init\", error: unknown): void => {\n console.error(\"Failed to install AgentWidget:\", error);\n safeCall(config.onError, { phase, error });\n dispatchLifecycle(\"persona:error\", { phase, error });\n };\n // True when the config renders a standard floating launcher button: the only\n // case that paints a clickable launcher at load. Shared by the deferral gate\n // and the eager-path `onLauncherShown` so the event name stays honest.\n const hasFloatingLauncher = (widgetConfig: any): boolean => {\n const launcher = widgetConfig.launcher ?? {};\n if (launcher.enabled === false) return false; // inline embed\n return (launcher.mountMode ?? \"floating\") === \"floating\"; // not docked / composer-bar\n };\n\n // Earliest signal: the installer has executed. Fire before any loading or\n // preview-gating so it's a reliable \"did my embed run\" beacon for diagnostics.\n safeCall(config.onScriptLoad, { version: config.version || \"latest\" });\n dispatchLifecycle(\"persona:script-load\", { version: config.version || \"latest\" });\n\n const isPreviewModeEnabled = (): boolean => {\n if (!config.previewQueryParam) {\n return true;\n }\n\n const params = new URLSearchParams(window.location.search);\n const value = params.get(config.previewQueryParam);\n return value !== null && value !== \"\" && value.toLowerCase() !== \"false\" && value !== \"0\";\n };\n\n if (!isPreviewModeEnabled()) {\n return;\n }\n \n const version = config.version || \"latest\";\n const cdn = config.cdn || \"jsdelivr\";\n const autoInit = config.autoInit !== false; // Default to true\n\n // Determine CDN base URL\n const getCdnBase = () => {\n // For a custom URL override, derive the sibling launcher URL when the\n // override mirrors the dist layout (…/index.global.js → …/launcher.global.js)\n // so self-hosted deployments still get the optimization. A non-standard\n // jsUrl yields null → eager-load fallback.\n if (config.cssUrl && config.jsUrl) {\n const derivedLauncherUrl = config.jsUrl.replace(/index\\.global\\.js($|\\?)/, \"launcher.global.js$1\");\n return {\n cssUrl: config.cssUrl,\n jsUrl: config.jsUrl,\n launcherUrl: (derivedLauncherUrl !== config.jsUrl ? derivedLauncherUrl : null) as string | null,\n };\n }\n\n const packageName = \"@runtypelabs/persona\";\n const basePath = `/npm/${packageName}@${version}/dist`;\n const host = cdn === \"unpkg\" ? \"https://unpkg.com\" : \"https://cdn.jsdelivr.net\";\n\n return {\n cssUrl: `${host}${basePath}/widget.css`,\n jsUrl: `${host}${basePath}/index.global.js`,\n launcherUrl: `${host}${basePath}/launcher.global.js` as string | null,\n };\n };\n\n const { cssUrl, jsUrl, launcherUrl } = getCdnBase();\n\n // Check if CSS is already loaded\n const isCssLoaded = () => {\n return !!document.head.querySelector('link[data-persona]') ||\n !!document.head.querySelector(`link[href*=\"widget.css\"]`);\n };\n\n // Check if JS is already loaded\n const isJsLoaded = () => {\n return !!(window as any).AgentWidget;\n };\n\n /**\n * Wait for framework hydration to complete (Next.js, Nuxt, etc.)\n * This prevents the framework from removing dynamically added CSS during reconciliation.\n * Uses requestIdleCallback + double requestAnimationFrame for reliable detection.\n */\n const waitForHydration = (callback: () => void): void => {\n let executed = false;\n \n const execute = () => {\n if (executed) return;\n executed = true;\n callback();\n };\n\n const afterDom = () => {\n // Strategy 1: Use requestIdleCallback if available (best for detecting idle after hydration)\n if (typeof requestIdleCallback !== 'undefined') {\n requestIdleCallback(() => {\n // Double requestAnimationFrame ensures at least one full paint cycle completed\n requestAnimationFrame(() => {\n requestAnimationFrame(execute);\n });\n }, { timeout: 3000 }); // Max wait 3 seconds, then proceed anyway\n } else {\n // Strategy 2: Fallback for Safari (no requestIdleCallback)\n // 300ms is typically enough for hydration on most pages\n setTimeout(execute, 300);\n }\n };\n\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', afterDom);\n } else {\n // DOM already ready, but still wait for potential hydration\n afterDom();\n }\n };\n\n // Load CSS\n const loadCSS = (): Promise<void> => {\n return new Promise((resolve, reject) => {\n if (isCssLoaded()) {\n resolve();\n return;\n }\n\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = cssUrl;\n link.setAttribute(\"data-persona\", \"true\");\n \n link.onload = () => resolve();\n link.onerror = () => reject(new Error(`Failed to load CSS from ${cssUrl}`));\n document.head.appendChild(link);\n });\n };\n\n // Load JS\n const loadJS = (): Promise<void> => {\n return new Promise((resolve, reject) => {\n if (isJsLoaded()) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.src = jsUrl;\n script.async = true;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(`Failed to load JS from ${jsUrl}`));\n document.head.appendChild(script);\n });\n };\n\n // Load the tiny launcher-only critical bundle (launcher.global.js)\n const isLauncherLoaded = () => !!window.AgentWidgetLauncher;\n\n const loadLauncher = (): Promise<void> => {\n return new Promise((resolve, reject) => {\n if (isLauncherLoaded() || !launcherUrl) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.src = launcherUrl;\n script.async = true;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(`Failed to load launcher from ${launcherUrl}`));\n document.head.appendChild(script);\n });\n };\n\n // Warm the full bundle in the background (download-only, not executed) so the\n // first open is quick. Runs at idle so it never competes with the launcher.\n const prefetchFullBundle = (): void => {\n const addPrefetch = () => {\n if (!isJsLoaded()) {\n const link = document.createElement(\"link\");\n link.rel = \"prefetch\";\n link.as = \"script\";\n link.href = jsUrl;\n document.head.appendChild(link);\n }\n\n // Also prefetch the markdown parsers chunk\n const markdownUrl = jsUrl.replace(/index\\.global\\.js($|\\?)/, \"markdown-parsers.js$1\");\n if (markdownUrl !== jsUrl) {\n const link2 = document.createElement(\"link\");\n link2.rel = \"prefetch\";\n link2.as = \"script\";\n link2.href = markdownUrl;\n document.head.appendChild(link2);\n }\n };\n if (typeof requestIdleCallback !== \"undefined\") {\n requestIdleCallback(addPrefetch, { timeout: 4000 });\n } else {\n setTimeout(addPrefetch, 1200);\n }\n };\n\n // Merge top-level installer options into the widget config. Shared by the\n // eager init path and the deferred-launcher path.\n const buildWidgetInit = (): { target: string | HTMLElement; widgetConfig: any; hasApiConfig: boolean } => {\n const target = config.target || \"body\";\n const widgetConfig: any = { ...config.config };\n\n if (config.apiUrl && !widgetConfig.apiUrl) widgetConfig.apiUrl = config.apiUrl;\n if (config.clientToken && !widgetConfig.clientToken) widgetConfig.clientToken = config.clientToken;\n if (config.flowId && !widgetConfig.flowId) widgetConfig.flowId = config.flowId;\n\n const hasApiConfig = !!(widgetConfig.apiUrl || widgetConfig.clientToken);\n return { target, widgetConfig, hasApiConfig };\n };\n\n // Initialize the full widget. When `openAfter` is true (the deferred-launcher\n // handoff), open the panel immediately via the public controller API so the\n // user's click on the critical launcher carries through.\n const initWidget = (openAfter = false): any => {\n if (!window.AgentWidget || !window.AgentWidget.initAgentWidget) {\n console.warn(\"AgentWidget not available. Make sure the script loaded successfully.\");\n return;\n }\n\n const { target, widgetConfig, hasApiConfig } = buildWidgetInit();\n\n // Only initialize if we have either apiUrl OR clientToken (or other config)\n if (!hasApiConfig && Object.keys(widgetConfig).length === 0) {\n return;\n }\n\n // Auto-apply markdown postprocessor if not explicitly set and available\n if (!widgetConfig.postprocessMessage && window.AgentWidget.markdownPostprocessor) {\n widgetConfig.postprocessMessage = ({ text }: { text: string }) =>\n window.AgentWidget.markdownPostprocessor(text);\n }\n\n try {\n const handle = window.AgentWidget.initAgentWidget({\n target,\n config: widgetConfig,\n // Explicitly disable shadow DOM for better CSS compatibility with host page\n useShadowDom: config.useShadowDom ?? false,\n windowKey: config.windowKey\n });\n\n // Handoff from the critical launcher: the user already clicked, so open\n // the panel via the existing public controller method.\n if (openAfter && handle && typeof handle.open === \"function\") {\n handle.open();\n }\n\n // Eager floating installs paint their launcher at load time too: emit the\n // same page-load \"appeared\" signal as the deferred path. The deferred\n // handoff (openAfter) already fired it at launcher mount, and non-floating\n // modes have no launcher, so guard on both.\n if (!openAfter && hasFloatingLauncher(widgetConfig)) {\n safeCall(config.onLauncherShown, { deferred: false });\n dispatchLifecycle(\"persona:launcher-shown\", { deferred: false });\n }\n\n // The full widget is initialized and its controller API is callable.\n safeCall(config.onChatReady, handle);\n dispatchLifecycle(\"persona:chat-ready\", handle);\n return handle;\n } catch (error) {\n fail(\"init\", error);\n }\n };\n\n // A persisted \"open\" state reopens the panel on reload with no click\n // (ui.ts:7513). The installer can't see that from config, so it reads the very\n // same storage key the widget writes. Mirrors normalizePersistStateConfig\n // (ui.ts:213): openState persistence defaults on, storage to sessionStorage,\n // key prefix to \"persona-\".\n const hasPersistedOpenState = (widgetConfig: any): boolean => {\n const persistState = widgetConfig.persistState;\n if (!persistState) return false; // persistence off → nothing to restore\n const asObject = typeof persistState === \"object\" ? persistState : null;\n if (asObject && asObject.persist?.openState === false) return false; // open-state persistence opted out\n const keyPrefix = (asObject && asObject.keyPrefix) || \"persona-\";\n const storageType = (asObject && asObject.storage) || \"session\";\n try {\n const storage = storageType === \"local\" ? window.localStorage : window.sessionStorage;\n return storage.getItem(`${keyPrefix}widget-open`) === \"true\";\n } catch {\n return false; // storage blocked (private mode) → the widget can't restore either\n }\n };\n\n // The deferred-launcher optimization only applies to the common floating case\n // that paints a collapsed launcher and waits for a click. Anything that starts\n // open or renders differently eager-loads the full bundle exactly as before: // including the two open triggers config alone can't express: a host\n // onStateLoaded hook that may request open, and a restored \"was open\" state.\n const shouldDeferPanel = (widgetConfig: any): boolean => {\n if (!launcherUrl) return false; // custom bundle URL override: can't derive launcher URL\n if (!hasFloatingLauncher(widgetConfig)) return false; // inline / docked / composer-bar\n const launcher = widgetConfig.launcher ?? {};\n if (launcher.autoExpand === true) return false; // starts open\n if (typeof widgetConfig.onStateLoaded === \"function\") return false; // hook may request open\n if (hasPersistedOpenState(widgetConfig)) return false; // restored \"was open\"\n return true;\n };\n\n // Render the real launcher from the tiny critical bundle; load + mount the\n // full widget on first click, then remove the critical launcher.\n const mountDeferredLauncher = (target: string | HTMLElement, widgetConfig: any): void => {\n let phase: \"idle\" | \"loading\" | \"done\" = \"idle\";\n let launcherHandle: { destroy: () => void } | undefined;\n\n const onOpen = () => {\n if (phase !== \"idle\") return; // already loading or handed off\n phase = \"loading\";\n loadJS()\n .then(() => {\n initWidget(true); // mount the full widget + open the panel\n launcherHandle?.destroy(); // remove the critical launcher (same component → invisible)\n phase = \"done\";\n })\n .catch((error) => {\n phase = \"idle\"; // allow the click to be retried\n console.error(\"Failed to load AgentWidget on open:\", error);\n safeCall(config.onError, { phase: \"bundle\", error });\n dispatchLifecycle(\"persona:error\", { phase: \"bundle\", error });\n });\n };\n\n const mounted = window.AgentWidgetLauncher.mount({ target, config: widgetConfig, onOpen });\n launcherHandle = mounted;\n\n // The real launcher is now painted at page-load time: emit the page-load\n // \"appeared\" signal (distinct from `onChatReady`, which waits for first open).\n safeCall(config.onLauncherShown, { deferred: true, element: mounted.element });\n dispatchLifecycle(\"persona:launcher-shown\", { deferred: true, element: mounted.element });\n\n // Warm the full bundle so the first open is quick.\n prefetchFullBundle();\n };\n\n // Main installation flow (called after hydration completes)\n const install = async () => {\n try {\n // Auto-init if we have config OR apiUrl OR clientToken\n const shouldAutoInit = autoInit && (\n config.config ||\n config.apiUrl ||\n config.clientToken\n );\n\n // Fast path: render the real launcher from the ~13 KB critical bundle and\n // defer the full widget until first open. Only for the common floating\n // case; everything else falls through to the eager path below.\n if (shouldAutoInit) {\n const { target, widgetConfig } = buildWidgetInit();\n if (shouldDeferPanel(widgetConfig)) {\n try {\n // CSS + launcher in parallel so the launcher paints correctly styled.\n await Promise.all([loadCSS(), loadLauncher()]);\n if (window.AgentWidgetLauncher && window.AgentWidgetLauncher.mount) {\n mountDeferredLauncher(target, widgetConfig);\n return;\n }\n } catch (error) {\n console.warn(\"Deferred launcher failed; falling back to eager load.\", error);\n }\n // Fall through to the eager path on any failure.\n }\n }\n\n // Eager path (unchanged behavior): load the full bundle, then init.\n try {\n await loadCSS();\n } catch (error) {\n return fail(\"css\", error);\n }\n try {\n await loadJS();\n } catch (error) {\n return fail(\"bundle\", error);\n }\n if (shouldAutoInit) {\n // Wait a tick to ensure AgentWidget is fully initialized\n setTimeout(() => initWidget(false), 0);\n }\n } catch (error) {\n // Safety net for anything unexpected before the eager loads above.\n fail(\"init\", error);\n }\n };\n\n // Start installation after hydration completes\n // This prevents Next.js/Nuxt/etc. from removing dynamically added CSS\n waitForHydration(install);\n})();\n\n"],"mappings":"4YAAA,IAAAA,EAAA,IA4DC,UAAW,CACV,aAGA,GAAK,OAAe,2BAClB,OAED,OAAe,2BAA6B,GA+D7C,IAAMC,GAzDsB,IAAuC,CAEjE,IAAMC,EAAS,SAAS,cACxB,GAAI,CAACA,EAAQ,MAAO,CAAC,EAErB,IAAMD,EAAgD,CAAC,EAGjDE,EAAaD,EAAO,aAAa,aAAa,EACpD,GAAIC,EACF,GAAI,CAGF,IAAMC,EAAiBD,EAAW,QAAQ,cAAe,EAAE,EACrDE,EAAe,KAAK,MAAMD,CAAc,EAE9C,GAAIC,EAAa,OAAQ,CAEvB,GAAM,CAAE,UAAWC,EAAI,YAAaC,EAAI,UAAWC,EAAI,GAAGC,CAAW,EAAIJ,EACzE,OAAO,OAAOJ,EAAcQ,CAAU,CACxC,MAEER,EAAa,OAASI,CAE1B,OAASK,EAAG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ACIkD,GAEF,WAAW,IAAMd,EAAW,EAAK,EAAG,CAAC,CAEzC,OAASpC,EAAO,CAEdF,EAAK,OAAQE,CAAK,CACpB,CACF,CAIwB,CAC1B,GAAG","names":["install_exports","scriptConfig","script","configJson","normalizedJson","parsedConfig","_a","_b","_c","safeConfig","e","token","flowId","apiUrl","previewQueryParam","config","safeCall","fn","arg","dispatchLifecycle","name","detail","fail","phase","error","hasFloatingLauncher","widgetConfig","launcher","value","version","cdn","autoInit","getCdnBase","derivedLauncherUrl","basePath","host","cssUrl","jsUrl","launcherUrl","isCssLoaded","isJsLoaded","waitForHydration","callback","executed","execute","afterDom","loadCSS","resolve","reject","link","loadJS","isLauncherLoaded","loadLauncher","prefetchFullBundle","addPrefetch","markdownUrl","link2","buildWidgetInit","target","hasApiConfig","initWidget","openAfter","text","handle","hasPersistedOpenState","persistState","asObject","keyPrefix","storageType","shouldDeferPanel","mountDeferredLauncher","launcherHandle","onOpen","mounted","shouldAutoInit"]}
|
|
1
|
+
{"version":3,"sources":["../src/install.ts"],"sourcesContent":["/**\n * Standalone installer script for easy script tag installation\n * This script automatically loads CSS and JS, then initializes the widget\n * if configuration is provided via window.siteAgentConfig\n */\n\nexport {};\n\ninterface SiteAgentInstallConfig {\n version?: string;\n cdn?: \"unpkg\" | \"jsdelivr\";\n cssUrl?: string;\n jsUrl?: string;\n target?: string | HTMLElement;\n config?: any;\n autoInit?: boolean;\n // Client token mode options (can also be set via data attributes)\n clientToken?: string;\n flowId?: string;\n agentId?: string;\n apiUrl?: string;\n // Optional query param key that gates widget installation in preview mode\n previewQueryParam?: string;\n // Shadow DOM option (defaults to false for better CSS compatibility)\n useShadowDom?: boolean;\n // Expose the widget handle on window[windowKey] for programmatic access\n windowKey?: string;\n /**\n * Fired as soon as the installer script executes, before it loads or gates\n * anything. For diagnostics / load-timing baselines (\"did my embed run\").\n */\n onScriptLoad?: (info: { version: string }) => void;\n /**\n * Fired when the floating launcher is painted on the page: at page-load time.\n * Deferred installs: the critical launcher mounts. Eager floating installs:\n * the full widget's launcher mounts. Use this for \"widget appeared\" analytics.\n * Does NOT fire for inline / docked / composer-bar installs (no floating\n * launcher): use `onChatReady` there.\n */\n onLauncherShown?: (info: { deferred: boolean; element?: HTMLElement }) => void;\n /**\n * Fired when the full widget is initialized and its controller API is\n * callable. Deferred installs: after the user first opens the panel. Eager\n * installs: on page load.\n */\n onChatReady?: (handle: any) => void;\n /**\n * Fired when a load step fails (stylesheet, full bundle, or init), so you can\n * detect ad-blocked / timed-out installs instead of failing silently.\n */\n onError?: (info: { phase: \"css\" | \"bundle\" | \"init\"; error: unknown }) => void;\n}\n\ndeclare global {\n interface Window {\n siteAgentConfig?: SiteAgentInstallConfig;\n AgentWidget?: any;\n AgentWidgetLauncher?: any;\n }\n}\n\n(function() {\n \"use strict\";\n\n // Prevent double installation\n if ((window as any).__siteAgentInstallerLoaded) {\n return;\n }\n (window as any).__siteAgentInstallerLoaded = true;\n\n /**\n * Read configuration from data attributes on the current script tag.\n * Supports: data-config (JSON), data-runtype-token, data-flow-id, data-agent-id, data-api-url\n */\n const getConfigFromScript = (): Partial<SiteAgentInstallConfig> => {\n // Try to get the current script element\n const script = document.currentScript as HTMLScriptElement | null;\n if (!script) return {};\n\n const scriptConfig: Partial<SiteAgentInstallConfig> = {};\n\n // Full config from data-config attribute (JSON string)\n const configJson = script.getAttribute('data-config');\n if (configJson) {\n try {\n // HTML attributes preserve literal newlines/tabs which are invalid\n // control characters inside JSON string literals: strip them.\n const normalizedJson = configJson.replace(/[\\r\\n]+\\s*/g, '');\n const parsedConfig = JSON.parse(normalizedJson);\n // If it has nested 'config' property, use it; otherwise treat as widget config\n if (parsedConfig.config) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { __proto__: _a, constructor: _b, prototype: _c, ...safeConfig } = parsedConfig;\n Object.assign(scriptConfig, safeConfig);\n } else {\n // Treat the entire object as widget config\n scriptConfig.config = parsedConfig;\n }\n } catch (e) {\n console.error(\"Failed to parse data-config JSON:\", e);\n }\n }\n\n // Client token from data attribute (primary method for client token mode)\n const token = script.getAttribute('data-runtype-token');\n if (token) {\n scriptConfig.clientToken = token;\n }\n\n // Optional flow ID\n const flowId = script.getAttribute('data-flow-id');\n if (flowId) {\n scriptConfig.flowId = flowId;\n }\n\n // Optional agent ID\n const agentId = script.getAttribute('data-agent-id');\n if (agentId) {\n scriptConfig.agentId = agentId;\n }\n\n // Optional API URL override\n const apiUrl = script.getAttribute('data-api-url');\n if (apiUrl) {\n scriptConfig.apiUrl = apiUrl;\n }\n\n // Optional preview query param gate\n const previewQueryParam = script.getAttribute('data-preview-param');\n if (previewQueryParam) {\n scriptConfig.previewQueryParam = previewQueryParam;\n }\n\n return scriptConfig;\n };\n\n // Get config from script attributes (must be called synchronously during script execution)\n const scriptConfig = getConfigFromScript();\n\n // Merge script attributes with window config (script attributes take precedence)\n const windowConfig: SiteAgentInstallConfig = window.siteAgentConfig || {};\n const config: SiteAgentInstallConfig = { ...windowConfig, ...scriptConfig };\n\n // --- Lifecycle helpers -----------------------------------------------------\n // A throwing user callback must never break the installer.\n const safeCall = <T>(fn: ((arg: T) => void) | undefined, arg: T): void => {\n try {\n fn?.(arg);\n } catch (e) {\n console.error(\"[Persona] lifecycle callback threw:\", e);\n }\n };\n const dispatchLifecycle = (name: string, detail: unknown): void => {\n try {\n window.dispatchEvent(new CustomEvent(name, { detail }));\n } catch {\n /* CustomEvent unsupported: ignore */\n }\n };\n const fail = (phase: \"css\" | \"bundle\" | \"init\", error: unknown): void => {\n console.error(\"Failed to install AgentWidget:\", error);\n safeCall(config.onError, { phase, error });\n dispatchLifecycle(\"persona:error\", { phase, error });\n };\n // True when the config renders a standard floating launcher button: the only\n // case that paints a clickable launcher at load. Shared by the deferral gate\n // and the eager-path `onLauncherShown` so the event name stays honest.\n const hasFloatingLauncher = (widgetConfig: any): boolean => {\n const launcher = widgetConfig.launcher ?? {};\n if (launcher.enabled === false) return false; // inline embed\n return (launcher.mountMode ?? \"floating\") === \"floating\"; // not docked / composer-bar\n };\n\n // Earliest signal: the installer has executed. Fire before any loading or\n // preview-gating so it's a reliable \"did my embed run\" beacon for diagnostics.\n safeCall(config.onScriptLoad, { version: config.version || \"latest\" });\n dispatchLifecycle(\"persona:script-load\", { version: config.version || \"latest\" });\n\n const isPreviewModeEnabled = (): boolean => {\n if (!config.previewQueryParam) {\n return true;\n }\n\n const params = new URLSearchParams(window.location.search);\n const value = params.get(config.previewQueryParam);\n return value !== null && value !== \"\" && value.toLowerCase() !== \"false\" && value !== \"0\";\n };\n\n if (!isPreviewModeEnabled()) {\n return;\n }\n \n const version = config.version || \"latest\";\n const cdn = config.cdn || \"jsdelivr\";\n const autoInit = config.autoInit !== false; // Default to true\n\n // Determine CDN base URL\n const getCdnBase = () => {\n // For a custom URL override, derive the sibling launcher URL when the\n // override mirrors the dist layout (…/index.global.js → …/launcher.global.js)\n // so self-hosted deployments still get the optimization. A non-standard\n // jsUrl yields null → eager-load fallback.\n if (config.cssUrl && config.jsUrl) {\n const derivedLauncherUrl = config.jsUrl.replace(/index\\.global\\.js($|\\?)/, \"launcher.global.js$1\");\n return {\n cssUrl: config.cssUrl,\n jsUrl: config.jsUrl,\n launcherUrl: (derivedLauncherUrl !== config.jsUrl ? derivedLauncherUrl : null) as string | null,\n };\n }\n\n const packageName = \"@runtypelabs/persona\";\n const basePath = `/npm/${packageName}@${version}/dist`;\n const host = cdn === \"unpkg\" ? \"https://unpkg.com\" : \"https://cdn.jsdelivr.net\";\n\n return {\n cssUrl: `${host}${basePath}/widget.css`,\n jsUrl: `${host}${basePath}/index.global.js`,\n launcherUrl: `${host}${basePath}/launcher.global.js` as string | null,\n };\n };\n\n const { cssUrl, jsUrl, launcherUrl } = getCdnBase();\n\n // Check if CSS is already loaded\n const isCssLoaded = () => {\n return !!document.head.querySelector('link[data-persona]') ||\n !!document.head.querySelector(`link[href*=\"widget.css\"]`);\n };\n\n // Check if JS is already loaded\n const isJsLoaded = () => {\n return !!(window as any).AgentWidget;\n };\n\n /**\n * Wait for framework hydration to complete (Next.js, Nuxt, etc.)\n * This prevents the framework from removing dynamically added CSS during reconciliation.\n * Uses requestIdleCallback + double requestAnimationFrame for reliable detection.\n */\n const waitForHydration = (callback: () => void): void => {\n let executed = false;\n \n const execute = () => {\n if (executed) return;\n executed = true;\n callback();\n };\n\n const afterDom = () => {\n // Strategy 1: Use requestIdleCallback if available (best for detecting idle after hydration)\n if (typeof requestIdleCallback !== 'undefined') {\n requestIdleCallback(() => {\n // Double requestAnimationFrame ensures at least one full paint cycle completed\n requestAnimationFrame(() => {\n requestAnimationFrame(execute);\n });\n }, { timeout: 3000 }); // Max wait 3 seconds, then proceed anyway\n } else {\n // Strategy 2: Fallback for Safari (no requestIdleCallback)\n // 300ms is typically enough for hydration on most pages\n setTimeout(execute, 300);\n }\n };\n\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', afterDom);\n } else {\n // DOM already ready, but still wait for potential hydration\n afterDom();\n }\n };\n\n // Load CSS\n const loadCSS = (): Promise<void> => {\n return new Promise((resolve, reject) => {\n if (isCssLoaded()) {\n resolve();\n return;\n }\n\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = cssUrl;\n link.setAttribute(\"data-persona\", \"true\");\n \n link.onload = () => resolve();\n link.onerror = () => reject(new Error(`Failed to load CSS from ${cssUrl}`));\n document.head.appendChild(link);\n });\n };\n\n // Load JS\n const loadJS = (): Promise<void> => {\n return new Promise((resolve, reject) => {\n if (isJsLoaded()) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.src = jsUrl;\n script.async = true;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(`Failed to load JS from ${jsUrl}`));\n document.head.appendChild(script);\n });\n };\n\n // Load the tiny launcher-only critical bundle (launcher.global.js)\n const isLauncherLoaded = () => !!window.AgentWidgetLauncher;\n\n const loadLauncher = (): Promise<void> => {\n return new Promise((resolve, reject) => {\n if (isLauncherLoaded() || !launcherUrl) {\n resolve();\n return;\n }\n\n const script = document.createElement(\"script\");\n script.src = launcherUrl;\n script.async = true;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(`Failed to load launcher from ${launcherUrl}`));\n document.head.appendChild(script);\n });\n };\n\n // Warm the full bundle in the background (download-only, not executed) so the\n // first open is quick. Runs at idle so it never competes with the launcher.\n const prefetchFullBundle = (): void => {\n const addPrefetch = () => {\n if (!isJsLoaded()) {\n const link = document.createElement(\"link\");\n link.rel = \"prefetch\";\n link.as = \"script\";\n link.href = jsUrl;\n document.head.appendChild(link);\n }\n\n // Also prefetch the markdown parsers chunk\n const markdownUrl = jsUrl.replace(/index\\.global\\.js($|\\?)/, \"markdown-parsers.js$1\");\n if (markdownUrl !== jsUrl) {\n const link2 = document.createElement(\"link\");\n link2.rel = \"prefetch\";\n link2.as = \"script\";\n link2.href = markdownUrl;\n document.head.appendChild(link2);\n }\n };\n if (typeof requestIdleCallback !== \"undefined\") {\n requestIdleCallback(addPrefetch, { timeout: 4000 });\n } else {\n setTimeout(addPrefetch, 1200);\n }\n };\n\n // Merge top-level installer options into the widget config. Shared by the\n // eager init path and the deferred-launcher path.\n const buildWidgetInit = (): { target: string | HTMLElement; widgetConfig: any; hasApiConfig: boolean } => {\n const target = config.target || \"body\";\n const widgetConfig: any = { ...config.config };\n\n if (config.apiUrl && !widgetConfig.apiUrl) widgetConfig.apiUrl = config.apiUrl;\n if (config.clientToken && !widgetConfig.clientToken) widgetConfig.clientToken = config.clientToken;\n if (config.flowId && !widgetConfig.flowId) widgetConfig.flowId = config.flowId;\n if (config.agentId && !widgetConfig.agentId) widgetConfig.agentId = config.agentId;\n\n const hasApiConfig = !!(widgetConfig.apiUrl || widgetConfig.clientToken);\n return { target, widgetConfig, hasApiConfig };\n };\n\n // Initialize the full widget. When `openAfter` is true (the deferred-launcher\n // handoff), open the panel immediately via the public controller API so the\n // user's click on the critical launcher carries through.\n const initWidget = (openAfter = false): any => {\n if (!window.AgentWidget || !window.AgentWidget.initAgentWidget) {\n console.warn(\"AgentWidget not available. Make sure the script loaded successfully.\");\n return;\n }\n\n const { target, widgetConfig, hasApiConfig } = buildWidgetInit();\n\n // Only initialize if we have either apiUrl OR clientToken (or other config)\n if (!hasApiConfig && Object.keys(widgetConfig).length === 0) {\n return;\n }\n\n // Auto-apply markdown postprocessor if not explicitly set and available\n if (!widgetConfig.postprocessMessage && window.AgentWidget.markdownPostprocessor) {\n widgetConfig.postprocessMessage = ({ text }: { text: string }) =>\n window.AgentWidget.markdownPostprocessor(text);\n }\n\n try {\n const handle = window.AgentWidget.initAgentWidget({\n target,\n config: widgetConfig,\n // Explicitly disable shadow DOM for better CSS compatibility with host page\n useShadowDom: config.useShadowDom ?? false,\n windowKey: config.windowKey\n });\n\n // Handoff from the critical launcher: the user already clicked, so open\n // the panel via the existing public controller method.\n if (openAfter && handle && typeof handle.open === \"function\") {\n handle.open();\n }\n\n // Eager floating installs paint their launcher at load time too: emit the\n // same page-load \"appeared\" signal as the deferred path. The deferred\n // handoff (openAfter) already fired it at launcher mount, and non-floating\n // modes have no launcher, so guard on both.\n if (!openAfter && hasFloatingLauncher(widgetConfig)) {\n safeCall(config.onLauncherShown, { deferred: false });\n dispatchLifecycle(\"persona:launcher-shown\", { deferred: false });\n }\n\n // The full widget is initialized and its controller API is callable.\n safeCall(config.onChatReady, handle);\n dispatchLifecycle(\"persona:chat-ready\", handle);\n return handle;\n } catch (error) {\n fail(\"init\", error);\n }\n };\n\n // A persisted \"open\" state reopens the panel on reload with no click\n // (ui.ts:7513). The installer can't see that from config, so it reads the very\n // same storage key the widget writes. Mirrors normalizePersistStateConfig\n // (ui.ts:213): openState persistence defaults on, storage to sessionStorage,\n // key prefix to \"persona-\".\n const hasPersistedOpenState = (widgetConfig: any): boolean => {\n const persistState = widgetConfig.persistState;\n if (!persistState) return false; // persistence off → nothing to restore\n const asObject = typeof persistState === \"object\" ? persistState : null;\n if (asObject && asObject.persist?.openState === false) return false; // open-state persistence opted out\n const keyPrefix = (asObject && asObject.keyPrefix) || \"persona-\";\n const storageType = (asObject && asObject.storage) || \"session\";\n try {\n const storage = storageType === \"local\" ? window.localStorage : window.sessionStorage;\n return storage.getItem(`${keyPrefix}widget-open`) === \"true\";\n } catch {\n return false; // storage blocked (private mode) → the widget can't restore either\n }\n };\n\n // The deferred-launcher optimization only applies to the common floating case\n // that paints a collapsed launcher and waits for a click. Anything that starts\n // open or renders differently eager-loads the full bundle exactly as before: // including the two open triggers config alone can't express: a host\n // onStateLoaded hook that may request open, and a restored \"was open\" state.\n const shouldDeferPanel = (widgetConfig: any): boolean => {\n if (!launcherUrl) return false; // custom bundle URL override: can't derive launcher URL\n if (!hasFloatingLauncher(widgetConfig)) return false; // inline / docked / composer-bar\n const launcher = widgetConfig.launcher ?? {};\n if (launcher.autoExpand === true) return false; // starts open\n if (typeof widgetConfig.onStateLoaded === \"function\") return false; // hook may request open\n if (hasPersistedOpenState(widgetConfig)) return false; // restored \"was open\"\n return true;\n };\n\n // Render the real launcher from the tiny critical bundle; load + mount the\n // full widget on first click, then remove the critical launcher.\n const mountDeferredLauncher = (target: string | HTMLElement, widgetConfig: any): void => {\n let phase: \"idle\" | \"loading\" | \"done\" = \"idle\";\n let launcherHandle: { destroy: () => void } | undefined;\n\n const onOpen = () => {\n if (phase !== \"idle\") return; // already loading or handed off\n phase = \"loading\";\n loadJS()\n .then(() => {\n initWidget(true); // mount the full widget + open the panel\n launcherHandle?.destroy(); // remove the critical launcher (same component → invisible)\n phase = \"done\";\n })\n .catch((error) => {\n phase = \"idle\"; // allow the click to be retried\n console.error(\"Failed to load AgentWidget on open:\", error);\n safeCall(config.onError, { phase: \"bundle\", error });\n dispatchLifecycle(\"persona:error\", { phase: \"bundle\", error });\n });\n };\n\n const mounted = window.AgentWidgetLauncher.mount({ target, config: widgetConfig, onOpen });\n launcherHandle = mounted;\n\n // The real launcher is now painted at page-load time: emit the page-load\n // \"appeared\" signal (distinct from `onChatReady`, which waits for first open).\n safeCall(config.onLauncherShown, { deferred: true, element: mounted.element });\n dispatchLifecycle(\"persona:launcher-shown\", { deferred: true, element: mounted.element });\n\n // Warm the full bundle so the first open is quick.\n prefetchFullBundle();\n };\n\n // Main installation flow (called after hydration completes)\n const install = async () => {\n try {\n // Auto-init if we have config OR apiUrl OR clientToken\n const shouldAutoInit = autoInit && (\n config.config ||\n config.apiUrl ||\n config.clientToken\n );\n\n // Fast path: render the real launcher from the ~13 KB critical bundle and\n // defer the full widget until first open. Only for the common floating\n // case; everything else falls through to the eager path below.\n if (shouldAutoInit) {\n const { target, widgetConfig } = buildWidgetInit();\n if (shouldDeferPanel(widgetConfig)) {\n try {\n // CSS + launcher in parallel so the launcher paints correctly styled.\n await Promise.all([loadCSS(), loadLauncher()]);\n if (window.AgentWidgetLauncher && window.AgentWidgetLauncher.mount) {\n mountDeferredLauncher(target, widgetConfig);\n return;\n }\n } catch (error) {\n console.warn(\"Deferred launcher failed; falling back to eager load.\", error);\n }\n // Fall through to the eager path on any failure.\n }\n }\n\n // Eager path (unchanged behavior): load the full bundle, then init.\n try {\n await loadCSS();\n } catch (error) {\n return fail(\"css\", error);\n }\n try {\n await loadJS();\n } catch (error) {\n return fail(\"bundle\", error);\n }\n if (shouldAutoInit) {\n // Wait a tick to ensure AgentWidget is fully initialized\n setTimeout(() => initWidget(false), 0);\n }\n } catch (error) {\n // Safety net for anything unexpected before the eager loads above.\n fail(\"init\", error);\n }\n };\n\n // Start installation after hydration completes\n // This prevents Next.js/Nuxt/etc. from removing dynamically added CSS\n waitForHydration(install);\n})();\n\n"],"mappings":"4YAAA,IAAAA,EAAA,IA6DC,UAAW,CACV,aAGA,GAAK,OAAe,2BAClB,OAED,OAAe,2BAA6B,GAqE7C,IAAMC,GA/DsB,IAAuC,CAEjE,IAAMC,EAAS,SAAS,cACxB,GAAI,CAACA,EAAQ,MAAO,CAAC,EAErB,IAAMD,EAAgD,CAAC,EAGjDE,EAAaD,EAAO,aAAa,aAAa,EACpD,GAAIC,EACF,GAAI,CAGF,IAAMC,EAAi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AI,CAACoB,EAAQ,EAAGM,EAAa,CAAC,CAAC,EACzC,OAAO,qBAAuB,OAAO,oBAAoB,MAAO,CAClEkB,EAAsBZ,EAAQhC,CAAY,EAC1C,MACF,CACF,OAASF,EAAO,CACd,QAAQ,KAAK,wDAAyDA,CAAK,CAC7E,CAGJ,CAGA,GAAI,CACF,MAAMsB,EAAQ,CAChB,OAAStB,EAAO,CACd,OAAOF,EAAK,MAAOE,CAAK,CAC1B,CACA,GAAI,CACF,MAAM0B,EAAO,CACf,OAAS1B,EAAO,CACd,OAAOF,EAAK,SAAUE,CAAK,CAC7B,CACIkD,GAEF,WAAW,IAAMd,EAAW,EAAK,EAAG,CAAC,CAEzC,OAASpC,EAAO,CAEdF,EAAK,OAAQE,CAAK,CACpB,CACF,CAIwB,CAC1B,GAAG","names":["install_exports","scriptConfig","script","configJson","normalizedJson","parsedConfig","_a","_b","_c","safeConfig","e","token","flowId","agentId","apiUrl","previewQueryParam","config","safeCall","fn","arg","dispatchLifecycle","name","detail","fail","phase","error","hasFloatingLauncher","widgetConfig","launcher","value","version","cdn","autoInit","getCdnBase","derivedLauncherUrl","basePath","host","cssUrl","jsUrl","launcherUrl","isCssLoaded","isJsLoaded","waitForHydration","callback","executed","execute","afterDom","loadCSS","resolve","reject","link","loadJS","isLauncherLoaded","loadLauncher","prefetchFullBundle","addPrefetch","markdownUrl","link2","buildWidgetInit","target","hasApiConfig","initWidget","openAfter","text","handle","hasPersistedOpenState","persistState","asObject","keyPrefix","storageType","shouldDeferPanel","mountDeferredLauncher","launcherHandle","onOpen","mounted","shouldAutoInit"]}
|