@tavus/widget 0.2.0 → 0.2.1
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/dist/index.iife.js +1 -1
- package/dist/index.mjs +4 -1
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -160,7 +160,7 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
160
160
|
- omitted: host decides border`)});var HN=Z({method:$(`ui/request-display-mode`),params:Z({mode:DN.describe(`The display mode being requested.`)})});Z({mode:DN.describe(`The display mode that was actually set. May differ from requested if not supported.`)}).passthrough();var UN=Q([$(`model`),$(`app`)]).describe(`Tool visibility scope - who can access the tool.`);Z({resourceUri:J().optional(),visibility:X(UN).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
161
161
|
- "model": Tool visible to and callable by the agent
|
|
162
162
|
- "app": Tool callable by the app from this server only`),csp:fk().optional(),permissions:fk().optional()}),Z({mimeTypes:X(J()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')});var WN=Z({method:$(`ui/download-file`),params:Z({contents:X(Q([vM,yM])).describe(`Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.`)})}),GN=Z({method:$(`ui/message`),params:Z({role:$(`user`).describe(`Message role, currently only "user" is supported.`),content:X(bM).describe(`Message content blocks (text, image, etc.).`)})});Z({method:$(`ui/notifications/sandbox-resource-ready`),params:Z({html:J().describe(`HTML content to load into the inner iframe.`),sandbox:J().optional().describe(`Optional override for the inner iframe's sandbox attribute.`),csp:jN.optional().describe(`CSP configuration from resource metadata.`),permissions:MN.optional().describe(`Sandbox permissions from resource metadata.`)})}),Z({method:$(`ui/notifications/tool-result`),params:kM.describe(`Standard MCP tool execution result.`)});var KN=Z({toolInfo:Z({id:YA.optional().describe(`JSON-RPC id of the tools/call request.`),tool:EM.describe(`Tool definition including name, inputSchema, etc.`)}).optional().describe(`Metadata of the tool call that instantiated this App.`),theme:EN.optional().describe(`Current color theme preference.`),styles:FN.optional().describe(`Style configuration for theming the app.`),displayMode:DN.optional().describe(`How the UI is currently displayed.`),availableDisplayModes:X(DN).optional().describe(`Display modes the host supports.`),containerDimensions:Q([Z({height:Y().describe(`Fixed container height in pixels.`)}),Z({maxHeight:Q([Y(),lk()]).optional().describe(`Maximum container height in pixels.`)})]).and(Q([Z({width:Y().describe(`Fixed container width in pixels.`)}),Z({maxWidth:Q([Y(),lk()]).optional().describe(`Maximum container width in pixels.`)})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
163
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:J().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:J().optional().describe(`User's timezone in IANA format.`),userAgent:J().optional().describe(`Host application identifier.`),platform:Q([$(`web`),$(`desktop`),$(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:Z({touch:ck().optional().describe(`Whether the device supports touch input.`),hover:ck().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:Z({top:Y().describe(`Top safe area inset in pixels.`),right:Y().describe(`Right safe area inset in pixels.`),bottom:Y().describe(`Bottom safe area inset in pixels.`),left:Y().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough();Z({method:$(`ui/notifications/host-context-changed`),params:KN.describe(`Partial context update containing only changed fields.`)});var qN=Z({method:$(`ui/update-model-context`),params:Z({content:X(bM).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:gk(J(),dk().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),JN=Z({method:$(`ui/initialize`),params:Z({appInfo:uj.describe(`App identification (name and version).`),appCapabilities:BN.describe(`Features and capabilities this app provides.`),protocolVersion:J().describe(`Protocol version this app supports.`)})});Z({protocolVersion:J().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:uj.describe(`Host application identification and version.`),hostCapabilities:zN.describe(`Features and capabilities provided by the host.`),hostContext:KN.describe(`Rich context about the host environment.`)}).passthrough();var YN=[TN],XN=class extends wN{_client;_hostInfo;_capabilities;_appCapabilities;_hostContext={};_appInfo;_initializedReceived=!1;_baseReplaceRequestHandler=this.replaceRequestHandler;replaceRequestHandler=(e,t)=>{this._baseReplaceRequestHandler(e,(e,n)=>(this._initializedReceived||console.warn(`[ext-apps] AppBridge received '${e.method}' before ui/notifications/initialized. The View is calling host methods before completing the handshake; it should await app.connect() first.`),t(e,n)))};eventSchemas={sizechange:NN,sandboxready:AN,initialized:VN,requestteardown:RN,loggingmessage:LM};constructor(e,t,n,r){super(r),this._client=e,this._hostInfo=t,this._capabilities=n,this.addEventListener(`initialized`,()=>{this._initializedReceived=!0}),this._hostContext=r?.hostContext||{},this.setRequestHandler(JN,e=>this._oninitialize(e)),this.setRequestHandler(bj,(e,t)=>(this.onping?.(e.params,t),{})),this.replaceRequestHandler(HN,e=>({mode:this._hostContext.displayMode??`inline`}))}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;get onsizechange(){return this.getEventHandler(`sizechange`)}set onsizechange(e){this.setEventHandler(`sizechange`,e)}get onsandboxready(){return this.getEventHandler(`sandboxready`)}set onsandboxready(e){this.setEventHandler(`sandboxready`,e)}get oninitialized(){return this.getEventHandler(`initialized`)}set oninitialized(e){this.setEventHandler(`initialized`,e)}_onmessage;get onmessage(){return this._onmessage}set onmessage(e){this.warnIfRequestHandlerReplaced(`onmessage`,this._onmessage,e),this._onmessage=e,this.replaceRequestHandler(GN,async(e,t)=>{if(!this._onmessage)throw Error(`No onmessage handler set`);return this._onmessage(e.params,t)})}_onopenlink;get onopenlink(){return this._onopenlink}set onopenlink(e){this.warnIfRequestHandlerReplaced(`onopenlink`,this._onopenlink,e),this._onopenlink=e,this.replaceRequestHandler(kN,async(e,t)=>{if(!this._onopenlink)throw Error(`No onopenlink handler set`);return this._onopenlink(e.params,t)})}_ondownloadfile;get ondownloadfile(){return this._ondownloadfile}set ondownloadfile(e){this.warnIfRequestHandlerReplaced(`ondownloadfile`,this._ondownloadfile,e),this._ondownloadfile=e,this.replaceRequestHandler(WN,async(e,t)=>{if(!this._ondownloadfile)throw Error(`No ondownloadfile handler set`);return this._ondownloadfile(e.params,t)})}get onrequestteardown(){return this.getEventHandler(`requestteardown`)}set onrequestteardown(e){this.setEventHandler(`requestteardown`,e)}_onrequestdisplaymode;get onrequestdisplaymode(){return this._onrequestdisplaymode}set onrequestdisplaymode(e){this.warnIfRequestHandlerReplaced(`onrequestdisplaymode`,this._onrequestdisplaymode,e),this._onrequestdisplaymode=e,this.replaceRequestHandler(HN,async(e,t)=>{if(!this._onrequestdisplaymode)throw Error(`No onrequestdisplaymode handler set`);return this._onrequestdisplaymode(e.params,t)})}get onloggingmessage(){return this.getEventHandler(`loggingmessage`)}set onloggingmessage(e){this.setEventHandler(`loggingmessage`,e)}_onupdatemodelcontext;get onupdatemodelcontext(){return this._onupdatemodelcontext}set onupdatemodelcontext(e){this.warnIfRequestHandlerReplaced(`onupdatemodelcontext`,this._onupdatemodelcontext,e),this._onupdatemodelcontext=e,this.replaceRequestHandler(qN,async(e,t)=>{if(!this._onupdatemodelcontext)throw Error(`No onupdatemodelcontext handler set`);return this._onupdatemodelcontext(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(jM,async(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}set oncreatesamplingmessage(e){this.setRequestHandler(GM,async(t,n)=>e(t.params,n))}sendToolListChanged(e={}){return this.notification({method:`notifications/tools/list_changed`,params:e})}_onlistresources;get onlistresources(){return this._onlistresources}set onlistresources(e){this.warnIfRequestHandlerReplaced(`onlistresources`,this._onlistresources,e),this._onlistresources=e,this.replaceRequestHandler(qj,async(e,t)=>{if(!this._onlistresources)throw Error(`No onlistresources handler set`);return this._onlistresources(e.params,t)})}_onlistresourcetemplates;get onlistresourcetemplates(){return this._onlistresourcetemplates}set onlistresourcetemplates(e){this.warnIfRequestHandlerReplaced(`onlistresourcetemplates`,this._onlistresourcetemplates,e),this._onlistresourcetemplates=e,this.replaceRequestHandler(Yj,async(e,t)=>{if(!this._onlistresourcetemplates)throw Error(`No onlistresourcetemplates handler set`);return this._onlistresourcetemplates(e.params,t)})}_onreadresource;get onreadresource(){return this._onreadresource}set onreadresource(e){this.warnIfRequestHandlerReplaced(`onreadresource`,this._onreadresource,e),this._onreadresource=e,this.replaceRequestHandler($j,async(e,t)=>{if(!this._onreadresource)throw Error(`No onreadresource handler set`);return this._onreadresource(e.params,t)})}sendResourceListChanged(e={}){return this.notification({method:`notifications/resources/list_changed`,params:e})}_onlistprompts;get onlistprompts(){return this._onlistprompts}set onlistprompts(e){this.warnIfRequestHandlerReplaced(`onlistprompts`,this._onlistprompts,e),this._onlistprompts=e,this.replaceRequestHandler(uM,async(e,t)=>{if(!this._onlistprompts)throw Error(`No onlistprompts handler set`);return this._onlistprompts(e.params,t)})}sendPromptListChanged(e={}){return this.notification({method:`notifications/prompts/list_changed`,params:e})}assertCapabilityForMethod(e){}assertRequestHandlerCapability(e){}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}getCapabilities(){return this._capabilities}async _oninitialize(e){let t=e.params.protocolVersion;return this._appInfo!==void 0&&console.warn(`[ext-apps] AppBridge received a second ui/initialize. The View may be double-mounting (e.g. React StrictMode in dev) without closing the previous App instance. Responding normally; the latest appInfo/appCapabilities replace the previous values.`),this._appCapabilities=e.params.appCapabilities,this._appInfo=e.params.appInfo,{protocolVersion:YN.includes(t)?t:TN,hostCapabilities:this.getCapabilities(),hostInfo:this._hostInfo,hostContext:this._hostContext}}setHostContext(e){let t={},n=!1;for(let r of Object.keys(e)){let i=this._hostContext[r],a=e[r];ZN(i,a)||(t[r]=a,n=!0)}n&&(this._hostContext=e,this.sendHostContextChange(t))}sendHostContextChange(e){return this.notification({method:`ui/notifications/host-context-changed`,params:e})}sendToolInput(e){return this.notification({method:`ui/notifications/tool-input`,params:e})}sendToolInputPartial(e){return this.notification({method:`ui/notifications/tool-input-partial`,params:e})}sendToolResult(e){return this.notification({method:`ui/notifications/tool-result`,params:e})}sendToolCancelled(e){return this.notification({method:`ui/notifications/tool-cancelled`,params:e})}sendSandboxResourceReady(e){return this.notification({method:`ui/notifications/sandbox-resource-ready`,params:e})}teardownResource(e,t){return this.request({method:`ui/resource-teardown`,params:e},IN,t)}sendResourceTeardown=this.teardownResource;callTool(e,t){return this.request({method:`tools/call`,params:e},kM,t)}listTools(e,t){return this.request({method:`tools/list`,params:e},OM,t)}async connect(e){if(this.transport)throw Error(`AppBridge is already connected. Call close() before connecting again.`);if(this._initializedReceived=!1,this._client){let e=this._client.getServerCapabilities();if(!e)throw Error(`Client server capabilities not available`);e.tools&&(this.oncalltool=async(e,t)=>this._client.request({method:`tools/call`,params:e},kM,{signal:t.signal}),e.tools.listChanged&&this._client.setNotificationHandler(MM,e=>this.sendToolListChanged(e.params))),e.resources&&(this.onlistresources=async(e,t)=>this._client.request({method:`resources/list`,params:e},Jj,{signal:t.signal}),this.onlistresourcetemplates=async(e,t)=>this._client.request({method:`resources/templates/list`,params:e},Xj,{signal:t.signal}),this.onreadresource=async(e,t)=>this._client.request({method:`resources/read`,params:e},eM,{signal:t.signal}),e.resources.listChanged&&this._client.setNotificationHandler(tM,e=>this.sendResourceListChanged(e.params))),e.prompts&&(this.onlistprompts=async(e,t)=>this._client.request({method:`prompts/list`,params:e},dM,{signal:t.signal}),e.prompts.listChanged&&this._client.setNotificationHandler(CM,e=>this.sendPromptListChanged(e.params)))}return super.connect(e)}};function ZN(e,t){return JSON.stringify(e)===JSON.stringify(t)}function QN(){let e=ft(kv);if(!e)throw Error(`useTheme must be used within ThemeProvider`);return e}function $N({state:e}){return e.enabled?j(`details`,{class:`pointer-events-auto w-full max-w-md rounded-lg border border-base-300 bg-base-100/95 p-2 text-xs shadow-lg backdrop-blur`,children:[j(`summary`,{class:`cursor-pointer font-medium`,children:`Magic Canvas debug`}),j(`dl`,{class:`mt-2 grid gap-2`,children:[j(eP,{label:`iframe`,value:e.iframeLifecycleState}),j(eP,{label:`post`,value:e.lastInteractionPostResult}),j(eP,{label:`context`,value:e.lastModelContextUpdate}),j(eP,{label:`error`,value:e.lastError}),j(tP,{label:`tool_call`,value:e.lastToolCall}),j(tP,{label:`canvas_config`,value:e.parsedCanvasConfig})]})]}):null}function eP({label:e,value:t}){return t?j(`div`,{children:[j(`dt`,{class:`font-semibold`,children:e}),j(`dd`,{class:`break-words text-base-content/70`,children:t})]}):null}function tP({label:e,value:t}){return t===void 0?null:j(`div`,{children:[j(`dt`,{class:`font-semibold`,children:e}),j(`dd`,{children:j(`pre`,{class:`max-h-40 overflow-auto rounded bg-base-200 p-2 text-[10px] leading-relaxed`,children:JSON.stringify(t,null,2)})})]})}var nP=1e3,rP=5e3,iP=1200,aP=2e3;function oP(e){return e.correct_answer===void 0?iP:aP}var sP=48,cP=`allow-scripts`,lP={"canvas.scheduling_embed":`allow-scripts allow-same-origin allow-popups allow-forms`};function uP(e,t){if(!t.contentWindow||e.source!==t.contentWindow)return!1;let n=e.data;return!!n&&typeof n==`object`&&n?.jsonrpc===`2.0`}var dP=class{onmessage;onerror;onclose;#e;#t;constructor(e){this.#e=e}start(){let e=e=>{uP(e,this.#e)&&this.onmessage?.(e.data)};return this.#t=e,globalThis.addEventListener(`message`,e),Promise.resolve()}send(e){return this.#e.contentWindow?.postMessage(e,`*`),Promise.resolve()}close(){return this.#t&&globalThis.removeEventListener(`message`,this.#t),this.#t=void 0,this.onclose?.(),Promise.resolve()}};function fP(e){for(let t of Mx)if(e.some(e=>DP(e)===t))return t;return null}function pP({onLayoutEffectChange:e,onRenderedSlotChange:t,debugEnabled:n=OP()}={}){let{client:r}=tv(),{dataTheme:i,cssVars:a}=QN(),o=ph(),s=Bg(),[c,l]=E([]),[u,d]=SP(),[f,p]=E(()=>({enabled:n,iframeLifecycleState:`idle`})),m=A(e=>{p(t=>({...t,...e}))},[]),h=A((e,t=`*`)=>{if(s!==`joined-meeting`){m({lastError:`Dropped Magic Canvas app message because the Daily meeting is not joined.`});return}o?.sendAppMessage(e,t)},[o,s,m]),g=k(()=>({theme:i.value===`dark`?`dark`:`light`,cssVars:a.value}),[i.value,a.value]);D(()=>{p(e=>e.enabled===n?e:{...e,enabled:n})},[n]),Qg({onAppMessage:A(e=>{if(s!==`joined-meeting`){m({lastToolCall:e.data,iframeLifecycleState:`idle`,lastError:`Dropped Magic Canvas tool call because the Daily meeting is not joined.`});return}try{let t=TS(e.data);if(!t)return;l(e=>Wx(e,t)),m({lastToolCall:e.data,parsedCanvasConfig:t.kind===`show`?t.instance.canvas_config:void 0,iframeLifecycleState:t.kind===`clear`?`closed`:`received`,lastError:void 0})}catch(e){m({iframeLifecycleState:`error`,lastError:jP(e).message})}},[s,m])});let _=c.map(e=>({instance:e,layout:Zx(e,d)})),v=Qx(_.map(({layout:e})=>e),d),y=[..._].reverse().find(({layout:e})=>e.display_mode===`fullscreen`)?.instance.tool_call_id;D(()=>{e?.(v)},[e,v.active,v.side,v.video_shift_x,v.backdrop.type,v.safe_area?.x,v.safe_area?.y,v.safe_area?.width,v.safe_area?.height]);let b=fP(_.map(({layout:e})=>e));D(()=>{t?.(b)},[t,b]);let x=c.length>0||f.enabled;return j(`div`,{ref:u,"data-magic-canvas-root":!0,class:`pointer-events-none absolute inset-0 z-30`,children:[x&&y&&j(`div`,{class:`absolute inset-0 bg-black/45`}),x&&Mx.map(e=>{let t=_.filter(({layout:t})=>DP(t)===e);return t.length===0?null:j(hP,{slot:e,safeAreaTop:v.safe_area?.y,frameWidth:d.width,children:e=>t.map(({instance:t,layout:n})=>j(gP,{availableHeight:e,client:r,hostTheme:g,instance:t,layout:n,dimmed:!!(y&&y!==t.tool_call_id),onDebug:m,onComplete:()=>{l(e=>e.filter(e=>e.id!==t.id))},onDisplayModeChange:e=>{l(n=>n.map(n=>n.tool_call_id===t.tool_call_id?{...n,layout:{...n.layout,display_mode:e}}:n))},sendAppMessage:h},t.id))},e)}),x&&j(`div`,{class:`absolute right-4 bottom-24 @max-mobile:right-3 @max-mobile:bottom-20`,children:j($N,{state:f})})]})}var mP=16;function hP({slot:e,safeAreaTop:t,frameWidth:n,children:r}){let[i,a]=CP(),o=r(e===`full`?void 0:a);if(e===`safe-area-left`||e===`safe-area-right`){let r=t==null?`1rem`:`${t*100}%`,a=n!=null&&n>0?Math.max(0,n-mP*2):void 0;return j(`div`,{ref:i,class:EP(e),style:{top:r,bottom:`${TP}px`,maxWidth:a},"data-canvas-slot":e,children:j(`div`,{class:`my-auto flex w-full flex-col gap-2`,children:o})})}return j(`div`,{ref:i,class:EP(e),"data-canvas-slot":e,children:o})}function gP({availableHeight:e,client:t,hostTheme:n,instance:r,layout:i,dimmed:a,onDebug:o,onComplete:s,onDisplayModeChange:c,sendAppMessage:l}){let u=O(null),d=O(null),f=O(e),p=O(320),m=O(n),h=O(r),g=O(i),_=O(-1),v=O(s),y=O(c),b=O(l),[x,S]=E(720);D(()=>{h.current=r},[r]),D(()=>{p.current=x,d.current?.setHostContext(bP(h.current,m.current,g.current,f.current,x))},[x]),D(()=>{f.current=e;let t=yP(n,u.current);m.current=t,d.current?.setHostContext(bP(h.current,t,g.current,e,p.current))},[e,n]),D(()=>{g.current=i,d.current?.setHostContext(bP(h.current,m.current,i,e,p.current))},[e,i]),D(()=>{v.current=s,y.current=c,b.current=l},[s,c,l]),D(()=>{let e=u.current;if(!e)return;let n=!1,i=null,a=null,s=null,c=null,l=new URL(r.canvas_config.sandbox_url,globalThis.location.href).href,x=e=>{n||o({iframeLifecycleState:`error`,lastError:jP(e).message})},C=()=>{if(n||!a)return;let e=h.current,t=Yx(e,a);a=null,b.current({message_type:`conversation`,event_type:`conversation.append_llm_context`,conversation_id:e.conversation_id,properties:{context:t}}),o({lastModelContextUpdate:e.canvas_config.component,lastError:void 0})},w=()=>{if(i)return;if(e.src!==l){e.src;return}if(n||!e.contentWindow)return;let u=new XN(null,{name:`tavus-deployment`,version:`0.0.0`},{logging:{},message:{text:{},structuredContent:{}},updateModelContext:{text:{},structuredContent:{}}},{hostContext:bP(r,yP(m.current,e),g.current,f.current,p.current)});i=u,d.current=u,u.oninitialized=()=>{n||(o({iframeLifecycleState:`ready`}),_.current=h.current.revision,u.sendToolInput({arguments:h.current.arguments}).catch(x))},u.onsizechange=({height:e})=>{!n&&typeof e==`number`&&Number.isFinite(e)&&S(Math.min(Math.max(e,sP),720))},u.onmessage=async e=>{let r=Gx(e),i=Jx(e);if(!r){if(i){let e=`Magic Canvas message included text without interaction metadata; no interaction row was recorded.`;return o({lastInteractionPostResult:`error`,lastError:e}),{isError:!0,code:`missing_interaction_metadata`,message:e}}return{}}try{let e=h.current,a=Kx(e,r),s=ES(a),l=new AbortController,u=globalThis.setTimeout(()=>l.abort(),rP);try{await Tn(t,a.conversation_id,s.body,{signal:l.signal})}finally{globalThis.clearTimeout(u)}if(n)return{};i&&b.current({message_type:`conversation`,event_type:`conversation.respond`,conversation_id:e.conversation_id,properties:{text:i}}),o({lastInteractionPostResult:`success`,lastError:void 0}),qx(a)&&(a.type===`submit`?(c&&clearTimeout(c),c=setTimeout(()=>{c=null,n||v.current()},oP(e.arguments))):v.current())}catch(e){let t=jP(e).message;return o({lastInteractionPostResult:`error`,lastError:t}),{isError:!0,code:`interaction_post_failed`,message:t}}return{}},u.onupdatemodelcontext=async e=>(a=e,s||=setTimeout(()=>{s=null,C()},nP),{}),u.onrequestdisplaymode=async({mode:e})=>{let t=e===`fullscreen`?`fullscreen`:`inline`;return y.current(t),g.current={...g.current,display_mode:t,viable_slot:t===`fullscreen`?`full`:g.current.viable_slot},u.setHostContext(bP(h.current,m.current,g.current,f.current,p.current)),{mode:t}},u.connect(new dP(e)).then(()=>void 0).catch(x)};o({iframeLifecycleState:`mounting`,lastInteractionPostResult:void 0}),r.canvas_config.sandbox_url,e.src=r.canvas_config.sandbox_url;let ee=()=>{w()};return e.addEventListener(`load`,ee),w(),()=>{s&&=(clearTimeout(s),null),c&&=(clearTimeout(c),null),C(),n=!0,e.removeEventListener(`load`,ee),d.current=null,o({iframeLifecycleState:`closed`}),i&&Ax(i)}},[t,r.id,r.canvas_config.sandbox_url,o]),D(()=>{r.revision!==0&&(r.revision<=_.current||(_.current=r.revision,d.current?.sendToolInput({arguments:r.arguments}).catch(e=>{o({iframeLifecycleState:`error`,lastError:jP(e).message})})))},[r.arguments,r.revision,o]);let C=i.viable_slot===`full`||i.display_mode===`fullscreen`,w=C?null:xP(x,e),ee=w?.placeholderStyle,te=w?.cardStyle,ne=C?{height:`100%`}:w?.iframeStyle??{height:`${x}px`},re=[`pointer-events-auto w-full overflow-hidden rounded-lg border border-base-300 bg-base-100 shadow-xl transition-[opacity,transform]`,C?`fixed inset-4 z-10 max-w-none`:`max-w-md`,a?`scale-[0.98] opacity-40`:``].filter(Boolean).join(` `),ie=lP[r.canvas_config.component]??cP,ae=j(`div`,{class:re,style:te,"data-canvas-card":i.viable_slot,children:j(`iframe`,{ref:u,title:`${r.canvas_config.component} ${r.canvas_config.component_version}`,class:C?`block h-full w-full border-0 bg-transparent`:`block border-0 bg-transparent`,sandbox:ie,style:ne})});return C?ae:j(`div`,{class:`block w-full`,style:ee,children:ae})}var _P=[`--color-base-100`,`--color-base-200`,`--color-base-300`,`--color-base-content`,`--color-primary`,`--color-error`];function vP(e){if(!e||typeof getComputedStyle!=`function`)return{};let t=getComputedStyle(e),n={};for(let e of _P){let r=t.getPropertyValue(e).trim();r&&(n[e]=r)}return n}function yP(e,t){let n=vP(t);return Object.keys(n).length===0?e:{...e,cssVars:{...e.cssVars,...n}}}function bP(e,t,n,r,i){let a=DS(t,n),o=n.viable_slot===`full`||n.display_mode===`fullscreen`,s=o?void 0:kP(r),c=o?1:xP(i??0,r)?.displayScale??1;return{...e.canvas_config.host_context,...a,containerDimensions:{...AP(a.containerDimensions)?a.containerDimensions:{},...s===void 0?{}:{maxHeight:s},displayScale:c}}}function xP(e,t){if(t===void 0||!Number.isFinite(t)||t<=0)return null;let n=Math.min(e,720);if(n<=t)return{displayScale:1,placeholderStyle:{maxHeight:`${t}px`},cardStyle:void 0,iframeStyle:{width:`100%`,height:`${n}px`}};let r=t/n;return{displayScale:r,placeholderStyle:{height:`${n*r}px`,maxHeight:`${t}px`,overflow:`hidden`},cardStyle:{height:`${n}px`,transform:`scale(${r})`,transformOrigin:`top center`},iframeStyle:{width:`100%`,height:`${n}px`}}}function SP(){let e=O(null),[t,n]=E(()=>wP(null));return D(()=>{let t=()=>n(t=>{let n=wP(e.current);return t.width===n.width&&t.height===n.height&&t.visualViewportHeight===n.visualViewportHeight?t:n});t(),globalThis.addEventListener(`resize`,t),globalThis.visualViewport?.addEventListener(`resize`,t);let r;return typeof ResizeObserver<`u`&&e.current&&(r=new ResizeObserver(t),r.observe(e.current)),()=>{globalThis.removeEventListener(`resize`,t),globalThis.visualViewport?.removeEventListener(`resize`,t),r?.disconnect()}},[]),[e,t]}function CP(){let e=O(null),[t,n]=E();return D(()=>{let t=e.current;if(!t)return;let r=e=>{let r=e??t.getBoundingClientRect().height;!Number.isFinite(r)||r<=0||n(Math.floor(r))},i=()=>r();if(i(),typeof ResizeObserver>`u`)return globalThis.addEventListener(`resize`,i),()=>globalThis.removeEventListener(`resize`,i);let a=new ResizeObserver(e=>{r(e[0]?.contentRect.height)});return a.observe(t),()=>a.disconnect()},[]),[e,t]}function wP(e){let t=globalThis.visualViewport?.height,n=e?.getBoundingClientRect();if(n&&n.width>0&&n.height>0){let e=t===void 0?void 0:Math.max(0,(globalThis.innerHeight||0)-t);return{width:n.width,height:n.height,visualViewportHeight:e===void 0?void 0:Math.max(0,n.height-e)}}return{width:globalThis.innerWidth||1024,height:globalThis.innerHeight||768,visualViewportHeight:t}}var TP=72;function EP(e){let t=`absolute flex gap-2`;switch(e){case`safe-area-left`:return`${t} left-4 w-[28rem] flex-col overflow-y-auto [scrollbar-gutter:stable]`;case`safe-area-right`:return`${t} right-4 w-[28rem] flex-col overflow-y-auto [scrollbar-gutter:stable]`;case`safe-area-bottom`:return`${t} right-4 bottom-24 left-4 flex-col items-center justify-end @max-mobile:right-3 @max-mobile:bottom-20 @max-mobile:left-3`;case`full`:return`${t} inset-4 flex-col items-stretch justify-stretch`}}function DP(e){return e.display_mode===`fullscreen`&&e.preferred_slot!==`full`?e.preferred_slot:e.viable_slot}function OP(){return!1}function kP(e){return e===void 0||!Number.isFinite(e)||e<=0?720:Math.min(Math.floor(e),720)}function AP(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function jP(e){return e instanceof Error?e:Error(String(e))}var MP=1e4;function NP({onTimeout:e,timeoutMs:t=MP,active:n=!0}){let r=hx().length>0,[i,a]=E(!1),o=O(e);return D(()=>{o.current=e},[e]),D(()=>{if(!n||r){a(!1);return}let e=setTimeout(()=>{a(!0),o.current()},t);return()=>clearTimeout(e)},[n,r,t]),{hasJoined:r,timedOut:i}}function PP(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.message_type===`system`&&t.event_type===`system.shutdown`}function FP({onShutdown:e}){let t=O(e);D(()=>{t.current=e},[e]),Qg({onAppMessage:A(e=>{PP(e?.data)&&t.current()},[])})}var IP=vn(`PiP`),LP=360,RP=280;function zP(){return globalThis.window!==void 0&&`documentPictureInPicture`in globalThis.window}function BP(e){let{enabled:t,active:n}=e,[r,i]=E(null),a=zP(),o=ft(kv),s=A(()=>{i(e=>(e&&!e.closed&&e.close(),null))},[]),c=A(async()=>{if(a&&!(!t||!n)&&!(r&&!r.closed))try{let e=await globalThis.window.documentPictureInPicture.requestWindow({width:LP,height:RP}),t=Je.replace(/:host(?=[\s,{])/g,`:host, :root`),n=e.document.createElement(`style`);n.textContent=t,e.document.head.appendChild(n),e.document.body.style.margin=`0`,e.document.body.style.width=`100%`,e.document.body.style.height=`100vh`,e.document.body.style.overflow=`hidden`,e.addEventListener(`pagehide`,()=>{i(t=>t===e?null:t)},{once:!0}),i(e)}catch(e){IP.warn(`Failed to open PiP window`,e)}},[a,t,n,r]);return D(()=>{if(!t||!a||!n)return;let e=()=>{document.visibilityState===`hidden`?c():document.visibilityState===`visible`&&s()};document.addEventListener(`visibilitychange`,e);let r=[],i=null,o=`none`,l=!1;if(typeof navigator<`u`&&`mediaSession`in navigator){let e=navigator.mediaSession;i=e.metadata,o=e.playbackState;try{e.metadata=new MediaMetadata({title:`Tavus conversation`}),e.playbackState=`playing`,l=!0}catch(e){IP.warn(`mediaSession metadata setup failed`,e)}let t=(t,n)=>{try{e.setActionHandler(t,n),r.push(t)}catch(e){IP.warn(`mediaSession.${t} not supported`,e)}};t(`enterpictureinpicture`,()=>{c()}),t(`play`,()=>{}),t(`pause`,()=>{})}return()=>{if(document.removeEventListener(`visibilitychange`,e),typeof navigator<`u`&&`mediaSession`in navigator){let e=navigator.mediaSession;for(let t of r)try{e.setActionHandler(t,null)}catch{}if(l)try{e.metadata=i,e.playbackState=o}catch{}}}},[t,a,n,c,s]),D(()=>{(!n||!t)&&r&&!r.closed&&s()},[n,t,r,s]),D(()=>()=>{r&&!r.closed&&r.close()},[r]),D(()=>{if(!r||r.closed||!o)return;let e=()=>{r.document.body.setAttribute(`data-theme`,o.dataTheme.value);let e=o.cssVars.value;for(let[t,n]of Object.entries(e))r.document.body.style.setProperty(t,n)};e();let t=o.dataTheme.subscribe(()=>e()),n=o.cssVars.subscribe(()=>e());return()=>{t(),n()}},[r,o]),{pipWindow:r,isSupported:a,requestPipWindow:c,closePipWindow:s}}var VP=Ut(null),HP={active:!1,video_shift_x:0,backdrop:{type:`snapshot_mirror`}},UP=va(({id:e,showAudioWave:t=!0})=>{let n=d_(e).isOff;return j(`div`,{class:`relative aspect-square w-32 @max-mobile:w-24 rounded-box overflow-hidden bg-black/30 z-10 ${n?`hidden`:``}`,children:[j(dg,{automirror:!0,sessionId:e,type:`video`,fit:`cover`,className:`w-full h-full object-cover ${n?`hidden`:``}`}),t&&j(`div`,{class:`absolute bottom-2 right-2`,children:j(cx,{id:e})})]})}),WP=va(()=>{let e=Zh(),{isScreenSharing:t}=xb(),n=hx()[0];return j(le,{children:[t&&n&&j(UP,{id:n}),e&&j(UP,{id:e,showAudioWave:!1})]})}),GP=va(()=>j(`div`,{class:`absolute top-4 left-4 flex flex-col items-end gap-2 z-20`,children:j(WP,{})})),KP=va(({isAudioOnly:e,canvasLayoutEffect:t,canvasRenderedSlot:n})=>{let r=Zh(),i=!l_(r??``).isOff,a=gx(e),o=l_(a.phase===`ready`?a.replicaId:``),s=!i&&(o.state===`playable`||o.state===`loading`),c=t.active&&!i&&(!e||s);return a.phase===`left`?j(ox,{}):a.phase===`connecting`?j(ax,{}):e&&!s?j(`div`,{class:`absolute inset-0 flex items-center justify-center`,children:[j(fx,{sessionId:a.replicaId}),j(lg,{sessionId:a.replicaId})]}):j(le,{children:[s?j(oC,{personaSessionId:a.replicaId,isAudioOnly:e,avatarOff:a.videoState.isOff,canvasLayoutEffect:t,smartSidecarActive:c}):j(qP,{personaSessionId:a.replicaId,localId:r,isScreenSharing:i,avatarOff:a.videoState.isOff,smartSidecarActive:c,canvasLayoutEffect:t,canvasRenderedSlot:n}),j(lg,{sessionId:a.replicaId})]})}),qP=va(({personaSessionId:e,localId:t,isScreenSharing:n,avatarOff:r,smartSidecarActive:i,canvasLayoutEffect:a,canvasRenderedSlot:o})=>j(iC,{canvasLayoutEffect:a,smartSidecarActive:i,isScreenSharing:n,captureSnapshot:ZP,personaMode:`auto`,renderedSlot:o,fill:i=>j(bx,{personaSessionId:e,localSessionId:t,isScreenSharing:n,avatarOff:r,videoRef:i})})),JP=va(({items:e})=>{let[t,n]=E(!1),r=O(null);return D(()=>{if(!t)return;let e=e=>{r.current&&!e.composedPath().includes(r.current)&&n(!1)},i=e=>{e.key===`Escape`&&n(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,i)}},[t]),j(`div`,{ref:r,class:`relative`,children:[j(`button`,{type:`button`,onClick:()=>n(e=>!e),"aria-pressed":t,"aria-expanded":t,"aria-haspopup":`true`,"aria-label":t?`Close more controls`:`More controls`,class:`btn btn-control ${t?`btn-primary`:`btn-neutral`}`,children:j(qy,{name:`more`})}),t&&j(`div`,{role:`menu`,class:`absolute bottom-full mb-1 left-1/2 -translate-x-1/2 flex flex-row items-center gap-1 p-1 rounded-box bg-base-100 border border-base-300 shadow-lg z-30 whitespace-nowrap`,children:e})]})}),YP=va(({items:e})=>e.length<=1?j(le,{children:e}):j(JP,{items:e})),XP=va(({onLeave:e})=>{let t=Bg(),{config:n}=tv(),{session:r,end:i}=Kb(),a=Zh(),o=O(null),s=ft(zv)?.frameRef??o,[c,l]=E(!1),[u,d]=E(!1),[f,p]=E(HP),[m,h]=E(null),g=r.value?.conversationUrl,_=n.value.customization.conversation,v=_.modality===`audio`,y=_.modality===`chat`,b=_.modality===`video`,x=_.enable_chat,S=_.enable_closed_captions,C=_.enable_picture_in_picture,{pipWindow:w}=BP({enabled:C&&!y,active:t===`joined-meeting`});D(()=>()=>{i()},[i]);let{camera:ee,requestCamera:te}=Cv(),{isCamMuted:ne}=yb(),re=ee.isGranted&&!ne;D(()=>{b&&t===`joined-meeting`&&(VP.value=re)},[b,t,re]);let ie=O(b&&!a&&VP.value===!0);D(()=>{t===`joined-meeting`&&ie.current&&(ie.current=!1,te())},[t,te]),D(()=>{(t===`left-meeting`||t===`error`)&&e()},[t,e]),D(()=>{let e=()=>{let e=s.current,t=e?.getRootNode(),n=t instanceof Document||t instanceof ShadowRoot?t:null;l(!!e&&n?.fullscreenElement===e)};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let ae=A(()=>{let e=s.current;if(!e)return;let t=e.getRootNode();(t instanceof Document||t instanceof ShadowRoot?t:null)?.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()},[]);A(()=>{d(e=>!e)},[]);let oe=A(()=>{i()},[i]);if(NP({active:!y&&t===`joined-meeting`,onTimeout:oe}),FP({onShutdown:oe}),!g)return null;if(y)return j($b,{defaultOpen:!0,children:j(`div`,{class:`cvi-call-surface absolute inset-0`,children:j(rx,{docked:!0,headerAction:j(`button`,{type:`button`,class:`btn btn-ghost btn-sm btn-circle text-base-content/60 hover:text-error`,onClick:oe,"aria-label":`Leave conversation`,children:j(qy,{name:`leave`,size:20,"aria-label":`Leave conversation`})})})})});let T=[j(Gb,{compact:!0},`screen-share`)];x&&T.push(j(tx,{compact:!0},`chat`));let se=t===`left-meeting`;return j(Jb,{children:j($b,{children:j(Ob,{children:[j(`div`,{class:`cvi-call-surface absolute inset-0`,children:[j(`div`,{class:`relative w-full h-full z-[5]`,children:[j(KP,{isAudioOnly:v,canvasLayoutEffect:f,canvasRenderedSlot:m}),!v&&j(GP,{}),j(Zb,{}),j(pP,{debugEnabled:u,onLayoutEffectChange:p,onRenderedSlotChange:h}),j(`div`,{class:`cvi-autohide absolute top-4 right-4 z-20`,"data-hidden":se,children:j(sx,{active:c,onToggle:ae,compact:!0})})]}),j(rx,{}),j(`div`,{class:`cvi-autohide cvi-autohide-slide pointer-events-none absolute bottom-6 left-0 right-0 z-20`,"data-hidden":se,"aria-hidden":se,children:j(`div`,{class:`cvi-control-rail flex justify-center items-center gap-2 @max-mobile:gap-1`,"data-hidden":se,children:[j(Bb,{level:!0}),!v&&j(Hb,{}),S&&j(Xb,{}),j(YP,{items:T}),j(`button`,{type:`button`,class:`btn btn-control btn-error`,onClick:oe,"aria-label":`Leave call`,children:j(qy,{name:`leave`,"aria-label":`Leave Call`})})]})})]}),w&&Fa(j(vx,{onLeave:oe}),w.document.body)]})})})});function ZP(e){if(!e||e.readyState<2||!e.videoWidth||!e.videoHeight)return null;let t=document.createElement(`canvas`),n=Math.round(640*(e.videoHeight/e.videoWidth));t.width=640,t.height=n;let r=t.getContext(`2d`);if(!r)return null;r.drawImage(e,0,0,640,n);try{return t.toDataURL(`image/jpeg`,.82)}catch{return null}}function QP({loading:e=!1,disabled:t,class:n,children:r,...i}){return j(`button`,{type:`button`,class:`btn relative ${n?` ${n}`:``}`,disabled:t||e,"aria-busy":e||void 0,...i,children:[j(`span`,{children:r}),e&&j(`span`,{class:`absolute inset-0 flex items-center justify-center backdrop-blur-xs`,"aria-hidden":`true`,children:j(`span`,{class:`loading loading-spinner loading-sm`})})]})}function $P({message:e,class:t}){return j(`div`,{class:`w-max max-w-[min(20rem,80vw)] ${t??``}`,children:[j(`div`,{class:`px-4 py-2 rounded-box bg-neutral text-neutral-content text-sm font-medium shadow-lg text-center`,role:`status`,"aria-live":`polite`,children:e}),j(`svg`,{class:`absolute left-1/2 -translate-x-1/2 top-full text-neutral`,width:`16`,height:`8`,viewBox:`0 0 16 8`,"aria-hidden":`true`,children:j(`path`,{d:`M0 0 L8 8 L16 0 Z`,fill:`currentColor`})})]})}function eF(e,t,n){switch(t){case`granted`:return n?e?.cameraOptional??`Camera is optional — turn it on anytime.`:e?.ready??`You're all set — join whenever you're ready.`;case`blocked`:return e?.denied??`Microphone is blocked. Click the mic to see how to allow it.`;case`in-use`:return`Your microphone is in use by another app. Close it and try again.`;case`not-found`:return`No microphone found. Connect one to continue.`;case`unsupported`:return`This browser can't access your microphone.`;case`prompt`:return e?.prompt??`Allow microphone access to join.`;default:return e?.loading??`Getting your microphone ready...`}}var tF=va(({text:e,isJoining:t=!1,onJoin:n,onCancel:r})=>{let i=ph(),{config:a}=tv(),{localSessionId:o,isCamMuted:s}=yb(),{mic:c,camera:l,requestMic:u,requestCamera:d}=Cv(),f=a.value.customization.conversation.modality===`video`;D(()=>{u()},[]);let p=c.isGranted,m=O(!1);D(()=>{!f||!p||m.current||l.isGranted||l.isBlocked||(m.current=!0,d())},[f,p,l.isGranted,l.isBlocked,d]);let h=f&&p&&!l.isGranted,g=eF(e,c.status,h);return j(Ob,{children:j(`div`,{class:`absolute inset-0 motion-safe:animate-[tavusFadeUp_280ms_ease-out]`,children:[l.isGranted&&!s?j(`div`,{class:`absolute inset-0 flex items-center justify-center bg-black overflow-hidden`,children:j(dg,{type:`video`,sessionId:o??``,mirror:!0,fit:`cover`,className:`w-full h-full object-cover!`})}):j(`div`,{class:`absolute inset-0 flex items-center justify-center text-base-content/40`,children:j(qy,{name:`face-smile`,size:`7rem`,"aria-label":`Camera off`})}),j(`div`,{class:`absolute bottom-6 left-1/2 -translate-x-1/2 z-10 flex flex-col items-center gap-2 max-w-[90%]`,children:[g&&j($P,{message:g,class:`relative`}),j(`div`,{class:`flex flex-wrap items-center justify-center gap-1.5 @max-mobile:gap-1`,children:[j(`div`,{class:`flex items-center justify-center gap-1.5 shrink-0 @max-mobile:gap-1`,children:[j(Bb,{level:!0}),f&&j(Hb,{})]}),j(QP,{class:`btn-accent `,loading:t,disabled:!p,onClick:n,children:e?.join??`Join Video Chat`}),c.isBlocked&&j(`button`,{type:`button`,class:`btn btn-error `,onClick:()=>{i&&i.leave(),r?.()},children:e?.cancel??`Cancel`})]})]})]})})}),nF=`Password required`,rF=`Enter the password to start this conversation.`,iF=`Password`,aF=`Continue`;function oF({onSubmit:e,text:t,isSubmitting:n=!1,errorMessage:r}){let[i,a]=E(``),o=mt();return j(`div`,{class:`absolute inset-0 z-30 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`${o}-title`,children:j(`form`,{onSubmit:t=>{t.preventDefault();let r=i.trim();!r||n||e(r)},class:`card bg-base-100 shadow-xl w-full max-w-sm`,children:j(`div`,{class:`card-body gap-3`,children:[j(`h3`,{id:`${o}-title`,class:`card-title text-base-content`,children:t?.title??nF}),j(`p`,{class:`text-sm text-base-content/70`,children:t?.description??rF}),j(`input`,{id:o,type:`password`,autocomplete:`current-password`,class:`input input-bordered w-full`,placeholder:t?.placeholder??iF,value:i,disabled:n,onInput:e=>a(e.target.value),autoFocus:!0}),r&&j(`p`,{class:`text-error text-xs`,role:`alert`,children:r}),j(QP,{class:`btn-primary`,type:`submit`,disabled:!i.trim(),loading:n,children:t?.submit??aF})]})})})}var sF=vn(`CaptchaChallenge`),cF=1;function lF(e){return typeof e==`object`&&!!e&&e.source===`tavus-captcha`&&typeof e.type==`string`}function uF(e,t,n,r,i){return`${e.replace(/\/+$/,``)}${t.startsWith(`/`)?t:`/${t}`}?deployment_uuid=${encodeURIComponent(n)}&action=${encodeURIComponent(r)}&parent_origin=${encodeURIComponent(i)}`}function dF({captcha:e,deploymentId:t,onToken:n,onFallback:r}){let i=(ft(Ct).baseUrl??`https://tavusapi.com`).replace(/\/+$/,``),a=new URL(i).origin,[o,s]=E(0),[c,l]=E(0),[u,d]=E(!1),[f,p]=E(!1),m=uF(i,e.challenge_path,t,e.action,window.location.origin),h=A(()=>{p(!1),s(e=>e+1)},[]);return D(()=>{function e(e){if(u||e.origin!==a)return;let i=e.data;if(lF(i)&&i.deployment_uuid===t){if(i.type===`interactive`){p(!0);return}if(i.type===`token`&&i.token){sF.info(`Captcha token received`),p(!1),n(i.token);return}if(i.type===`expired`){sF.info(`Captcha token expired, reloading iframe`),h();return}i.type===`error`&&(sF.warn(`Captcha error received`,i.code),c<cF?(l(e=>e+1),h()):(sF.warn(`Captcha error retries exhausted, falling back to no-token mode`),d(!0),r()))}}return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[a,t,c,u,n,r,h]),u?null:j(`div`,{class:f?`absolute inset-0 z-30 flex items-center justify-center p-4 bg-base-100/70 backdrop-blur-sm animate-[tavusFadeUp_180ms_ease-out]`:`absolute top-0 left-0 w-0 h-0 overflow-hidden opacity-0 pointer-events-none`,"aria-hidden":!f,children:j(`iframe`,{src:m,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`,title:`Security challenge`,style:{border:`none`,width:`300px`,height:`65px`},scrolling:`no`},o)})}function fF({kind:e,status:t}){if(e===`camera`)return`Allow camera access to use video. Camera is optional.`;switch(t){case`blocked`:return`Microphone is blocked. Allow access in your browser settings to continue.`;case`in-use`:return`Your microphone is in use by another app. Close it and try again.`;case`not-found`:return`No microphone found. Connect one to continue.`;case`unsupported`:return`This browser can't access your microphone.`;default:return`Allow microphone access to start the conversation.`}}function pF({text:e,onStart:t,isStarting:n,permissionRequest:r}){let{config:i,deploymentId:a}=tv(),o=ft(K_),s=Qy(i.value),c=s.btn_title??e?.fallback_button??`Start the conversation`,l=i.value.customization.terms_content?.trim()??``,u=i.value.customization.terms_enabled===!0,d=l.length>0,f=d&&u,p=k(()=>f&&S_(a,l),[f,a,l]),m=f&&!p,h=i.value.has_password===!0,g=o?.password.value??null,_=h&&!g,v=i.value.captcha??null,{captchaReady:y,captchaEpoch:b,handleCaptchaToken:x,handleCaptchaFallback:S}=vv(v,o,n),C=mt(),[w,ee]=E(p),te=v!==null&&!y,ne=n||f&&!w||_||te;return j(sb,{title:s.title,description:s.description,overlay:j(le,{children:[te&&j(dF,{captcha:v,deploymentId:a,onToken:x,onFallback:S},b),_&&o?j(oF,{onSubmit:o.setPassword}):null]}),children:[j(`div`,{class:`relative`,children:[r&&j($P,{message:fF(r),class:`absolute bottom-full left-1/2 -translate-x-1/2 mb-3 z-20`}),j(QP,{class:`btn-neutral rounded-box`,onClick:()=>{f&&w&&!p&&T_(a,l),t()},disabled:ne,loading:n,children:c})]}),d&&j(`div`,{class:`max-w-xs`,children:m?j(`label`,{for:C,class:`flex items-center gap-2 text-xs text-left cursor-pointer`,children:[j(`input`,{id:C,type:`checkbox`,class:`checkbox checkbox-secondary checkbox-xs mt-0.5 shrink-0`,checked:w,onChange:e=>ee(e.target.checked)}),j(`span`,{class:`leading-snug`,children:l})]}):j(`p`,{class:`text-xs leading-snug text-base-content/60`,children:l})})]})}function mF({flow:e,welcomeText:t,onUnavailableCancel:n}){switch(e.state){case`idle`:return j(pF,{text:t,onStart:()=>{e.start()},isStarting:e.isStarting,permissionRequest:e.permissionRequest});case`haircheck`:return j(tF,{onJoin:()=>{e.join()},onCancel:()=>e.cancel(),isJoining:e.isStarting});case`call`:return j(XP,{onLeave:()=>e.leave()});case`ended`:return j(vb,{onRestart:()=>e.restart()});case`unavailable`:return j(fb,{cause:e.unavailableCause??`busy`,canRetry:e.canRetry,onRetry:()=>{e.start()},onCancel:n});default:{let t=e.state;throw Error(`Unreachable flow state: ${String(t)}`)}}}var hF=Fe(null);function gF({children:e}){let{config:t}=ft(bi),n=t.peek().customization?.widget,r=n?.expandable??`default`,i=un(r===`start-expanded`||r===`always`),a=un(n?.variant??`full`),o=un(n?.position??`bottom-right`),s=un(r),c=un(n?.avatar?.type??`orb`),l=O(r);_n(()=>{let e=t.value.customization?.widget,n=e?.expandable??`default`;a.value=e?.variant??`full`,o.value=e?.position??`bottom-right`,s.value=n,c.value=e?.avatar?.type??`orb`,l.current!==n&&(i.value=n===`start-expanded`||n===`always`,l.current=n)});let u=A(()=>{s.peek()!==`always`&&(i.value=!i.peek())},[i,s]),d=A(()=>{i.value=!0},[i]),f=A(()=>{s.peek()!==`always`&&(i.value=!1)},[i,s]),p=k(()=>({expanded:i,variant:a,position:o,expandable:s,avatarType:c,toggle:u,expand:d,collapse:f}),[i,a,o,s,c,u,d,f]);return j(hF.Provider,{value:p,children:e})}function _F(){let{config:e}=tv(),t=e.value.customization.branding;return e.value.show_tavus_branding!==!1&&!t?.hide_tavus_badge?j(vF,{}):t?.logo||t?.text?j(yF,{logo:t.logo,text:t.text}):null}function vF(){let{isDark:e}=QN(),t=e.value?`white`:`#140206`;return j(`a`,{href:`https://tavus.io`,target:`_blank`,rel:`noopener noreferrer`,class:`inline-flex items-center gap-1 text-xs text-base-content/50 hover:text-base-content/80 transition-colors`,children:[j(`svg`,{viewBox:`0 0 488 452`,class:`h-2.5 w-2.5 shrink-0`,fill:`none`,"aria-hidden":`true`,children:[j(`path`,{d:`M160 152V208H104V152H160Z`,fill:t}),j(`path`,{"fill-rule":`evenodd`,"clip-rule":`evenodd`,d:`M488 270.5L436 285L451 326L418.766 346L441 360L423 392L435 452H0V0H394.766L488 270.5ZM24 24V428H216.2L209 392L227 360L204.766 346L237 326L222 285L274 270.5L189.038 24H24ZM352 152C336.536 152 324 164.536 324 180C324 195.464 336.536 208 352 208C367.464 208 380 195.464 380 180C380 164.536 367.464 152 352 152Z`,fill:t})]}),j(`span`,{children:[`Powered by `,j(`span`,{class:`underline`,children:`Tavus`})]})]})}function yF({logo:e,text:t}){return j(`div`,{class:`inline-flex items-center gap-1 text-xs text-base-content/50`,children:[e?j(`img`,{src:e,alt:t||`Branding`,class:`h-2.5 shrink-0`}):null,t?j(`span`,{children:t}):null]})}var bF={title:`Hi! Want to chat?`,btn_title:`Start conversation`};function xF(){let{config:e}=tv(),t=e.value.customization.widget?.text;return k(()=>({title:t?.title||bF.title,btn_title:t?.btn_title||bF.btn_title}),[t])}function SF(){let e=ft(hF);if(!e)throw Error(`useWidgetUI must be used within WidgetUIProvider`);return e}var CF={xs:`w-6 h-6`,sm:`w-8 h-8`,md:`w-10 h-10`,lg:`w-16 h-16`},wF={xs:`w-3 h-3`,sm:`w-4 h-4`,md:`w-5 h-5`,lg:`w-8 h-8`};function TF({size:e=`md`,className:t=``}){let{avatarType:n}=SF(),{config:r}=tv(),i=Zy(r.value);return(Qy(r.value).background.type===`replica`||n.value===`image`)&&i?j(`div`,{class:`relative ${CF[e]} rounded-box overflow-hidden bg-base-300 ${t}`,children:j(nb,{replica:i})}):j(`div`,{class:`relative ${CF[e]} rounded-box bg-primary/15 flex items-center justify-center ${t}`,children:j(`span`,{class:`${wF[e]} rounded-full bg-primary animate-pulse`})})}function EF({variant:e}){let{toggle:t}=SF(),n=xF();return e===`tiny`?j(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`rounded-box overflow-hidden shadow-xl hover:shadow-2xl transition-shadow cursor-pointer`,children:j(TF,{size:`lg`})}):e===`compact`?j(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`group flex items-center gap-2.5 py-2.5 pl-2.5 pr-8 rounded-box bg-base-100 text-base-content border border-base-300 shadow-lg hover:shadow-xl transition-shadow cursor-pointer text-left`,children:[j(TF,{size:`md`}),j(`span`,{class:`flex flex-col gap-0.5`,children:[j(`span`,{class:`text-base font-medium leading-tight`,children:n.title}),j(`span`,{class:`text-sm text-base-content/60 leading-tight`,children:n.btn_title})]})]}):j(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`flex flex-col gap-3 p-3 w-64 rounded-box bg-base-100 text-base-content border border-base-300 shadow-xl hover:shadow-2xl transition-shadow cursor-pointer text-left`,children:[j(`div`,{class:`flex items-center gap-2.5`,children:[j(TF,{size:`md`}),j(`span`,{class:`text-sm font-medium leading-snug`,children:n.title})]}),j(`span`,{class:`btn btn-primary btn-sm w-full pointer-events-none gap-2 flex items-center`,children:[j(qy,{name:`cam`,size:16}),j(`span`,{className:`leading-4`,children:n.btn_title})]})]})}var DF=`tavus:widget:greeting-dismissed`;function OF({anchor:e}){let t=xF(),{variant:n,expand:r}=SF(),[i,a]=E(!1);D(()=>{if(n.value===`tiny`){try{if(sessionStorage.getItem(DF)===`1`)return}catch{}a(!0)}},[n]);let o=A(e=>{e.stopPropagation();try{sessionStorage.setItem(DF,`1`)}catch{}a(!1)},[]);if(!i)return null;let s=e===`right`?`right-[-6px] border-r border-b`:`left-[-6px] border-l border-t`,c=e===`right`?`-right-2`:`-left-2`;return j(`button`,{type:`button`,onClick:r,class:`relative max-w-56 rounded-box bg-base-100 text-base-content shadow-lg border border-base-300 px-3 py-2 text-sm text-left cursor-pointer animate-[tavusFadeUp_240ms_ease-out] hover:bg-base-200 transition-colors`,children:[j(`p`,{class:`leading-snug pr-3`,children:t.title}),j(`span`,{role:`button`,tabIndex:0,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o(e)},class:`absolute -top-2 ${c} btn btn-ghost btn-circle btn-xs bg-base-100 border border-base-300 shadow-sm`,"aria-label":`Dismiss`,children:`×`}),j(`span`,{class:`absolute bottom-3 w-3 h-3 rotate-45 bg-base-100 border-base-300 ${s}`})]})}function kF(){let e=ft(Ev);if(!e)throw Error(`useHostBridge must be used within HostBridgeProvider`);return e}var AF=`bg-base-100 text-base-content rounded-box border border-base-300 shadow-xl w-[22rem] flex flex-col animate-[tavusPopIn_180ms_ease-out]`,jF=`bg-base-100 text-base-content w-[100vw] h-[100dvh] flex flex-col animate-[tavusFadeUp_180ms_ease-out]`,MF=`p-1 flex-1 min-h-0`,NF=`p-1 flex-1 min-h-0`;function PF({variant:e,children:t,onClose:n,fullscreen:r}){let{expandable:i}=SF(),a=i.value!==`always`;return r?j(`div`,{class:jF,children:[j(`div`,{class:`flex items-center justify-end gap-2 px-2.5 py-1.5 border-b border-base-300`,children:a&&j(`button`,{type:`button`,class:`btn btn-ghost btn-circle btn-xs`,onClick:n,"aria-label":`Close`,children:j(qy,{name:`close`,size:14})})}),j(`div`,{class:NF,children:t}),j(`div`,{class:`flex justify-end px-2.5`,children:j(_F,{})})]}):j(`div`,{class:`flex flex-col h-[min(34rem,calc(100dvh-3rem))]`,children:[j(`div`,{class:`${AF} flex-1 overflow-hidden`,children:[j(`div`,{class:`flex items-center justify-end gap-2 px-2.5 pt-1.5 shrink-0`,children:a&&j(`button`,{type:`button`,class:`btn btn-ghost btn-circle btn-xs`,onClick:n,"aria-label":`Close`,children:j(qy,{name:`close`,size:14})})}),j(`div`,{class:MF,children:t})]}),j(`div`,{class:`flex justify-end pr-2 pt-1.5 shrink-0`,children:j(_F,{})})]})}var FF=vn(`Widget`),IF=`1rem`,LF=480;function RF(e,t,n){let r=e.state===`call`,i=r||e.state===`haircheck`||e.isStarting;e.cancel(),r&&e.leave(),i&&t(),n()}function zF(){return typeof window>`u`?!1:window.innerWidth<=LF}function BF(e){switch(e){case`bottom-right`:return{bottom:IF,right:IF};case`bottom-left`:return{bottom:IF,left:IF};case`top-right`:return{top:IF,right:IF};case`top-left`:return{top:IF,left:IF};case`top`:return{top:IF,left:`50%`,transform:`translateX(-50%)`};case`bottom`:return{bottom:IF,left:`50%`,transform:`translateX(-50%)`}}}var VF=[`top`,`bottom`,`left`,`right`,`transform`];function HF(e){return e===`bottom-left`||e===`top-left`?`left`:`right`}function UF(){let{config:e,initError:t}=tv(),n=xF(),{expanded:r,position:i,variant:a,collapse:o}=SF(),{end:s}=Kb(),{shadowHost:c}=kF(),l=pb(),u=un(zF());D(()=>{if(typeof window>`u`)return;u.value=zF();let e=()=>{u.value=zF()};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[u]);let d=k(()=>({fallback_button:n.btn_title}),[n.btn_title]),f=A(()=>{RF(l,s,o)},[l,s,o]);if(_n(()=>{let e=c.value,t=i.value,n=r.value,a=n&&u.value;if(e){if(a)e.style.top=`0`,e.style.right=`0`,e.style.bottom=`0`,e.style.left=`0`,e.style.transform=``;else{let n=BF(t);for(let t of VF)e.style[t]=n[t]??``}e.dataset.tavusWidgetPosition=t,e.dataset.tavusWidgetExpanded=n?`true`:`false`,e.dataset.tavusWidgetFullscreen=a?`true`:`false`,e.dataset.tavusWidgetSmall=u.value?`true`:`false`}}),t.value)return FF.error(`Widget cannot initialize (init request failed):`,t.value),null;if(e.value.is_available===!1&&e.value.unavailable_reason===`total_limit`)return FF.error(`Widget is unavailable (total_limit reached) — not rendering`),null;if(!r.value){let e=HF(i.value),t=e===`right`?`flex items-end gap-2 justify-end`:`flex items-end gap-2 flex-row-reverse justify-end`,n=e===`right`?`justify-end pr-2`:`justify-start pl-2`;return j(`div`,{class:`flex flex-col`,children:[j(`div`,{class:t,children:[j(OF,{anchor:e}),j(EF,{variant:a.value})]}),j(`div`,{class:`flex ${n} pt-1.5`,children:j(_F,{})})]})}return e.value.is_available===!1?j(PF,{variant:a.value,fullscreen:u.value,onClose:f,children:j(Bv,{children:j(fb,{cause:e.value.unavailable_reason??`daily_limit`,canRetry:!1,onRetry:()=>{}})})}):j(PF,{variant:a.value,fullscreen:u.value,onClose:f,children:j(Bv,{children:j(mF,{flow:l,welcomeText:d,onUnavailableCancel:()=>l.restart()})})})}var WF=`:host {
|
|
163
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:J().optional().describe(`User's language and region preference in BCP 47 format.`),timeZone:J().optional().describe(`User's timezone in IANA format.`),userAgent:J().optional().describe(`Host application identifier.`),platform:Q([$(`web`),$(`desktop`),$(`mobile`)]).optional().describe(`Platform type for responsive design decisions.`),deviceCapabilities:Z({touch:ck().optional().describe(`Whether the device supports touch input.`),hover:ck().optional().describe(`Whether the device supports hover interactions.`)}).optional().describe(`Device input capabilities.`),safeAreaInsets:Z({top:Y().describe(`Top safe area inset in pixels.`),right:Y().describe(`Right safe area inset in pixels.`),bottom:Y().describe(`Bottom safe area inset in pixels.`),left:Y().describe(`Left safe area inset in pixels.`)}).optional().describe(`Mobile safe area boundaries in pixels.`)}).passthrough();Z({method:$(`ui/notifications/host-context-changed`),params:KN.describe(`Partial context update containing only changed fields.`)});var qN=Z({method:$(`ui/update-model-context`),params:Z({content:X(bM).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:gk(J(),dk().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),JN=Z({method:$(`ui/initialize`),params:Z({appInfo:uj.describe(`App identification (name and version).`),appCapabilities:BN.describe(`Features and capabilities this app provides.`),protocolVersion:J().describe(`Protocol version this app supports.`)})});Z({protocolVersion:J().describe(`Negotiated protocol version string (e.g., "2025-11-21").`),hostInfo:uj.describe(`Host application identification and version.`),hostCapabilities:zN.describe(`Features and capabilities provided by the host.`),hostContext:KN.describe(`Rich context about the host environment.`)}).passthrough();var YN=[TN],XN=class extends wN{_client;_hostInfo;_capabilities;_appCapabilities;_hostContext={};_appInfo;_initializedReceived=!1;_baseReplaceRequestHandler=this.replaceRequestHandler;replaceRequestHandler=(e,t)=>{this._baseReplaceRequestHandler(e,(e,n)=>(this._initializedReceived||console.warn(`[ext-apps] AppBridge received '${e.method}' before ui/notifications/initialized. The View is calling host methods before completing the handshake; it should await app.connect() first.`),t(e,n)))};eventSchemas={sizechange:NN,sandboxready:AN,initialized:VN,requestteardown:RN,loggingmessage:LM};constructor(e,t,n,r){super(r),this._client=e,this._hostInfo=t,this._capabilities=n,this.addEventListener(`initialized`,()=>{this._initializedReceived=!0}),this._hostContext=r?.hostContext||{},this.setRequestHandler(JN,e=>this._oninitialize(e)),this.setRequestHandler(bj,(e,t)=>(this.onping?.(e.params,t),{})),this.replaceRequestHandler(HN,e=>({mode:this._hostContext.displayMode??`inline`}))}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;get onsizechange(){return this.getEventHandler(`sizechange`)}set onsizechange(e){this.setEventHandler(`sizechange`,e)}get onsandboxready(){return this.getEventHandler(`sandboxready`)}set onsandboxready(e){this.setEventHandler(`sandboxready`,e)}get oninitialized(){return this.getEventHandler(`initialized`)}set oninitialized(e){this.setEventHandler(`initialized`,e)}_onmessage;get onmessage(){return this._onmessage}set onmessage(e){this.warnIfRequestHandlerReplaced(`onmessage`,this._onmessage,e),this._onmessage=e,this.replaceRequestHandler(GN,async(e,t)=>{if(!this._onmessage)throw Error(`No onmessage handler set`);return this._onmessage(e.params,t)})}_onopenlink;get onopenlink(){return this._onopenlink}set onopenlink(e){this.warnIfRequestHandlerReplaced(`onopenlink`,this._onopenlink,e),this._onopenlink=e,this.replaceRequestHandler(kN,async(e,t)=>{if(!this._onopenlink)throw Error(`No onopenlink handler set`);return this._onopenlink(e.params,t)})}_ondownloadfile;get ondownloadfile(){return this._ondownloadfile}set ondownloadfile(e){this.warnIfRequestHandlerReplaced(`ondownloadfile`,this._ondownloadfile,e),this._ondownloadfile=e,this.replaceRequestHandler(WN,async(e,t)=>{if(!this._ondownloadfile)throw Error(`No ondownloadfile handler set`);return this._ondownloadfile(e.params,t)})}get onrequestteardown(){return this.getEventHandler(`requestteardown`)}set onrequestteardown(e){this.setEventHandler(`requestteardown`,e)}_onrequestdisplaymode;get onrequestdisplaymode(){return this._onrequestdisplaymode}set onrequestdisplaymode(e){this.warnIfRequestHandlerReplaced(`onrequestdisplaymode`,this._onrequestdisplaymode,e),this._onrequestdisplaymode=e,this.replaceRequestHandler(HN,async(e,t)=>{if(!this._onrequestdisplaymode)throw Error(`No onrequestdisplaymode handler set`);return this._onrequestdisplaymode(e.params,t)})}get onloggingmessage(){return this.getEventHandler(`loggingmessage`)}set onloggingmessage(e){this.setEventHandler(`loggingmessage`,e)}_onupdatemodelcontext;get onupdatemodelcontext(){return this._onupdatemodelcontext}set onupdatemodelcontext(e){this.warnIfRequestHandlerReplaced(`onupdatemodelcontext`,this._onupdatemodelcontext,e),this._onupdatemodelcontext=e,this.replaceRequestHandler(qN,async(e,t)=>{if(!this._onupdatemodelcontext)throw Error(`No onupdatemodelcontext handler set`);return this._onupdatemodelcontext(e.params,t)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced(`oncalltool`,this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(jM,async(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}set oncreatesamplingmessage(e){this.setRequestHandler(GM,async(t,n)=>e(t.params,n))}sendToolListChanged(e={}){return this.notification({method:`notifications/tools/list_changed`,params:e})}_onlistresources;get onlistresources(){return this._onlistresources}set onlistresources(e){this.warnIfRequestHandlerReplaced(`onlistresources`,this._onlistresources,e),this._onlistresources=e,this.replaceRequestHandler(qj,async(e,t)=>{if(!this._onlistresources)throw Error(`No onlistresources handler set`);return this._onlistresources(e.params,t)})}_onlistresourcetemplates;get onlistresourcetemplates(){return this._onlistresourcetemplates}set onlistresourcetemplates(e){this.warnIfRequestHandlerReplaced(`onlistresourcetemplates`,this._onlistresourcetemplates,e),this._onlistresourcetemplates=e,this.replaceRequestHandler(Yj,async(e,t)=>{if(!this._onlistresourcetemplates)throw Error(`No onlistresourcetemplates handler set`);return this._onlistresourcetemplates(e.params,t)})}_onreadresource;get onreadresource(){return this._onreadresource}set onreadresource(e){this.warnIfRequestHandlerReplaced(`onreadresource`,this._onreadresource,e),this._onreadresource=e,this.replaceRequestHandler($j,async(e,t)=>{if(!this._onreadresource)throw Error(`No onreadresource handler set`);return this._onreadresource(e.params,t)})}sendResourceListChanged(e={}){return this.notification({method:`notifications/resources/list_changed`,params:e})}_onlistprompts;get onlistprompts(){return this._onlistprompts}set onlistprompts(e){this.warnIfRequestHandlerReplaced(`onlistprompts`,this._onlistprompts,e),this._onlistprompts=e,this.replaceRequestHandler(uM,async(e,t)=>{if(!this._onlistprompts)throw Error(`No onlistprompts handler set`);return this._onlistprompts(e.params,t)})}sendPromptListChanged(e={}){return this.notification({method:`notifications/prompts/list_changed`,params:e})}assertCapabilityForMethod(e){}assertRequestHandlerCapability(e){}assertNotificationCapability(e){}assertTaskCapability(e){throw Error(`Tasks are not supported in MCP Apps`)}assertTaskHandlerCapability(e){throw Error(`Task handlers are not supported in MCP Apps`)}getCapabilities(){return this._capabilities}async _oninitialize(e){let t=e.params.protocolVersion;return this._appInfo!==void 0&&console.warn(`[ext-apps] AppBridge received a second ui/initialize. The View may be double-mounting (e.g. React StrictMode in dev) without closing the previous App instance. Responding normally; the latest appInfo/appCapabilities replace the previous values.`),this._appCapabilities=e.params.appCapabilities,this._appInfo=e.params.appInfo,{protocolVersion:YN.includes(t)?t:TN,hostCapabilities:this.getCapabilities(),hostInfo:this._hostInfo,hostContext:this._hostContext}}setHostContext(e){let t={},n=!1;for(let r of Object.keys(e)){let i=this._hostContext[r],a=e[r];ZN(i,a)||(t[r]=a,n=!0)}n&&(this._hostContext=e,this.sendHostContextChange(t))}sendHostContextChange(e){return this.notification({method:`ui/notifications/host-context-changed`,params:e})}sendToolInput(e){return this.notification({method:`ui/notifications/tool-input`,params:e})}sendToolInputPartial(e){return this.notification({method:`ui/notifications/tool-input-partial`,params:e})}sendToolResult(e){return this.notification({method:`ui/notifications/tool-result`,params:e})}sendToolCancelled(e){return this.notification({method:`ui/notifications/tool-cancelled`,params:e})}sendSandboxResourceReady(e){return this.notification({method:`ui/notifications/sandbox-resource-ready`,params:e})}teardownResource(e,t){return this.request({method:`ui/resource-teardown`,params:e},IN,t)}sendResourceTeardown=this.teardownResource;callTool(e,t){return this.request({method:`tools/call`,params:e},kM,t)}listTools(e,t){return this.request({method:`tools/list`,params:e},OM,t)}async connect(e){if(this.transport)throw Error(`AppBridge is already connected. Call close() before connecting again.`);if(this._initializedReceived=!1,this._client){let e=this._client.getServerCapabilities();if(!e)throw Error(`Client server capabilities not available`);e.tools&&(this.oncalltool=async(e,t)=>this._client.request({method:`tools/call`,params:e},kM,{signal:t.signal}),e.tools.listChanged&&this._client.setNotificationHandler(MM,e=>this.sendToolListChanged(e.params))),e.resources&&(this.onlistresources=async(e,t)=>this._client.request({method:`resources/list`,params:e},Jj,{signal:t.signal}),this.onlistresourcetemplates=async(e,t)=>this._client.request({method:`resources/templates/list`,params:e},Xj,{signal:t.signal}),this.onreadresource=async(e,t)=>this._client.request({method:`resources/read`,params:e},eM,{signal:t.signal}),e.resources.listChanged&&this._client.setNotificationHandler(tM,e=>this.sendResourceListChanged(e.params))),e.prompts&&(this.onlistprompts=async(e,t)=>this._client.request({method:`prompts/list`,params:e},dM,{signal:t.signal}),e.prompts.listChanged&&this._client.setNotificationHandler(CM,e=>this.sendPromptListChanged(e.params)))}return super.connect(e)}};function ZN(e,t){return JSON.stringify(e)===JSON.stringify(t)}function QN(){let e=ft(kv);if(!e)throw Error(`useTheme must be used within ThemeProvider`);return e}function $N({state:e}){return e.enabled?j(`details`,{class:`pointer-events-auto w-full max-w-md rounded-lg border border-base-300 bg-base-100/95 p-2 text-xs shadow-lg backdrop-blur`,children:[j(`summary`,{class:`cursor-pointer font-medium`,children:`Magic Canvas debug`}),j(`dl`,{class:`mt-2 grid gap-2`,children:[j(eP,{label:`iframe`,value:e.iframeLifecycleState}),j(eP,{label:`post`,value:e.lastInteractionPostResult}),j(eP,{label:`context`,value:e.lastModelContextUpdate}),j(eP,{label:`error`,value:e.lastError}),j(tP,{label:`tool_call`,value:e.lastToolCall}),j(tP,{label:`canvas_config`,value:e.parsedCanvasConfig})]})]}):null}function eP({label:e,value:t}){return t?j(`div`,{children:[j(`dt`,{class:`font-semibold`,children:e}),j(`dd`,{class:`break-words text-base-content/70`,children:t})]}):null}function tP({label:e,value:t}){return t===void 0?null:j(`div`,{children:[j(`dt`,{class:`font-semibold`,children:e}),j(`dd`,{children:j(`pre`,{class:`max-h-40 overflow-auto rounded bg-base-200 p-2 text-[10px] leading-relaxed`,children:JSON.stringify(t,null,2)})})]})}var nP=1e3,rP=5e3,iP=1200,aP=2e3;function oP(e){return e.correct_answer===void 0?iP:aP}var sP=48,cP=`allow-scripts`,lP={"canvas.scheduling_embed":`allow-scripts allow-same-origin allow-popups allow-forms`,"canvas.text":`allow-scripts allow-popups allow-popups-to-escape-sandbox`};function uP(e,t){if(!t.contentWindow||e.source!==t.contentWindow)return!1;let n=e.data;return!!n&&typeof n==`object`&&n?.jsonrpc===`2.0`}var dP=class{onmessage;onerror;onclose;#e;#t;constructor(e){this.#e=e}start(){let e=e=>{uP(e,this.#e)&&this.onmessage?.(e.data)};return this.#t=e,globalThis.addEventListener(`message`,e),Promise.resolve()}send(e){return this.#e.contentWindow?.postMessage(e,`*`),Promise.resolve()}close(){return this.#t&&globalThis.removeEventListener(`message`,this.#t),this.#t=void 0,this.onclose?.(),Promise.resolve()}};function fP(e){for(let t of Mx)if(e.some(e=>DP(e)===t))return t;return null}function pP({onLayoutEffectChange:e,onRenderedSlotChange:t,debugEnabled:n=OP()}={}){let{client:r}=tv(),{dataTheme:i,cssVars:a}=QN(),o=ph(),s=Bg(),[c,l]=E([]),[u,d]=SP(),[f,p]=E(()=>({enabled:n,iframeLifecycleState:`idle`})),m=A(e=>{p(t=>({...t,...e}))},[]),h=A((e,t=`*`)=>{if(s!==`joined-meeting`){m({lastError:`Dropped Magic Canvas app message because the Daily meeting is not joined.`});return}o?.sendAppMessage(e,t)},[o,s,m]),g=k(()=>({theme:i.value===`dark`?`dark`:`light`,cssVars:a.value}),[i.value,a.value]);D(()=>{p(e=>e.enabled===n?e:{...e,enabled:n})},[n]),Qg({onAppMessage:A(e=>{if(s!==`joined-meeting`){m({lastToolCall:e.data,iframeLifecycleState:`idle`,lastError:`Dropped Magic Canvas tool call because the Daily meeting is not joined.`});return}try{let t=TS(e.data);if(!t)return;l(e=>Wx(e,t)),m({lastToolCall:e.data,parsedCanvasConfig:t.kind===`show`?t.instance.canvas_config:void 0,iframeLifecycleState:t.kind===`clear`?`closed`:`received`,lastError:void 0})}catch(e){m({iframeLifecycleState:`error`,lastError:jP(e).message})}},[s,m])});let _=c.map(e=>({instance:e,layout:Zx(e,d)})),v=Qx(_.map(({layout:e})=>e),d),y=[..._].reverse().find(({layout:e})=>e.display_mode===`fullscreen`)?.instance.tool_call_id;D(()=>{e?.(v)},[e,v.active,v.side,v.video_shift_x,v.backdrop.type,v.safe_area?.x,v.safe_area?.y,v.safe_area?.width,v.safe_area?.height]);let b=fP(_.map(({layout:e})=>e));D(()=>{t?.(b)},[t,b]);let x=c.length>0||f.enabled;return j(`div`,{ref:u,"data-magic-canvas-root":!0,class:`pointer-events-none absolute inset-0 z-30`,children:[x&&y&&j(`div`,{class:`absolute inset-0 bg-black/45`}),x&&Mx.map(e=>{let t=_.filter(({layout:t})=>DP(t)===e);return t.length===0?null:j(hP,{slot:e,safeAreaTop:v.safe_area?.y,frameWidth:d.width,children:e=>t.map(({instance:t,layout:n})=>j(gP,{availableHeight:e,client:r,hostTheme:g,instance:t,layout:n,dimmed:!!(y&&y!==t.tool_call_id),onDebug:m,onComplete:()=>{l(e=>e.filter(e=>e.id!==t.id))},onDisplayModeChange:e=>{l(n=>n.map(n=>n.tool_call_id===t.tool_call_id?{...n,layout:{...n.layout,display_mode:e}}:n))},sendAppMessage:h},t.id))},e)}),x&&j(`div`,{class:`absolute right-4 bottom-24 @max-mobile:right-3 @max-mobile:bottom-20`,children:j($N,{state:f})})]})}var mP=16;function hP({slot:e,safeAreaTop:t,frameWidth:n,children:r}){let[i,a]=CP(),o=r(e===`full`?void 0:a);if(e===`safe-area-left`||e===`safe-area-right`){let r=t==null?`1rem`:`${t*100}%`,a=n!=null&&n>0?Math.max(0,n-mP*2):void 0;return j(`div`,{ref:i,class:EP(e),style:{top:r,bottom:`${TP}px`,maxWidth:a},"data-canvas-slot":e,children:j(`div`,{class:`my-auto flex w-full flex-col gap-2`,children:o})})}return j(`div`,{ref:i,class:EP(e),"data-canvas-slot":e,children:o})}function gP({availableHeight:e,client:t,hostTheme:n,instance:r,layout:i,dimmed:a,onDebug:o,onComplete:s,onDisplayModeChange:c,sendAppMessage:l}){let u=O(null),d=O(null),f=O(e),p=O(320),m=O(n),h=O(r),g=O(i),_=O(-1),v=O(s),y=O(c),b=O(l),[x,S]=E(720);D(()=>{h.current=r},[r]),D(()=>{p.current=x,d.current?.setHostContext(bP(h.current,m.current,g.current,f.current,x))},[x]),D(()=>{f.current=e;let t=yP(n,u.current);m.current=t,d.current?.setHostContext(bP(h.current,t,g.current,e,p.current))},[e,n]),D(()=>{g.current=i,d.current?.setHostContext(bP(h.current,m.current,i,e,p.current))},[e,i]),D(()=>{v.current=s,y.current=c,b.current=l},[s,c,l]),D(()=>{let e=u.current;if(!e)return;let n=!1,i=null,a=null,s=null,c=null,l=new URL(r.canvas_config.sandbox_url,globalThis.location.href).href,x=e=>{n||o({iframeLifecycleState:`error`,lastError:jP(e).message})},C=()=>{if(n||!a)return;let e=h.current,t=Yx(e,a);a=null,b.current({message_type:`conversation`,event_type:`conversation.append_llm_context`,conversation_id:e.conversation_id,properties:{context:t}}),o({lastModelContextUpdate:e.canvas_config.component,lastError:void 0})},w=()=>{if(i)return;if(e.src!==l){e.src;return}if(n||!e.contentWindow)return;let u=new XN(null,{name:`tavus-deployment`,version:`0.0.0`},{logging:{},message:{text:{},structuredContent:{}},updateModelContext:{text:{},structuredContent:{}}},{hostContext:bP(r,yP(m.current,e),g.current,f.current,p.current)});i=u,d.current=u,u.oninitialized=()=>{n||(o({iframeLifecycleState:`ready`}),_.current=h.current.revision,u.sendToolInput({arguments:h.current.arguments}).catch(x))},u.onsizechange=({height:e})=>{!n&&typeof e==`number`&&Number.isFinite(e)&&S(Math.min(Math.max(e,sP),720))},u.onmessage=async e=>{let r=Gx(e),i=Jx(e);if(!r){if(i){let e=`Magic Canvas message included text without interaction metadata; no interaction row was recorded.`;return o({lastInteractionPostResult:`error`,lastError:e}),{isError:!0,code:`missing_interaction_metadata`,message:e}}return{}}try{let e=h.current,a=Kx(e,r),s=ES(a),l=new AbortController,u=globalThis.setTimeout(()=>l.abort(),rP);try{await Tn(t,a.conversation_id,s.body,{signal:l.signal})}finally{globalThis.clearTimeout(u)}if(n)return{};i&&b.current({message_type:`conversation`,event_type:`conversation.respond`,conversation_id:e.conversation_id,properties:{text:i}}),o({lastInteractionPostResult:`success`,lastError:void 0}),qx(a)&&(a.type===`submit`?(c&&clearTimeout(c),c=setTimeout(()=>{c=null,n||v.current()},oP(e.arguments))):v.current())}catch(e){let t=jP(e).message;return o({lastInteractionPostResult:`error`,lastError:t}),{isError:!0,code:`interaction_post_failed`,message:t}}return{}},u.onupdatemodelcontext=async e=>(a=e,s||=setTimeout(()=>{s=null,C()},nP),{}),u.onrequestdisplaymode=async({mode:e})=>{let t=e===`fullscreen`?`fullscreen`:`inline`;return y.current(t),g.current={...g.current,display_mode:t,viable_slot:t===`fullscreen`?`full`:g.current.viable_slot},u.setHostContext(bP(h.current,m.current,g.current,f.current,p.current)),{mode:t}},u.connect(new dP(e)).then(()=>void 0).catch(x)};o({iframeLifecycleState:`mounting`,lastInteractionPostResult:void 0}),r.canvas_config.sandbox_url,e.src=r.canvas_config.sandbox_url;let ee=()=>{w()};return e.addEventListener(`load`,ee),w(),()=>{s&&=(clearTimeout(s),null),c&&=(clearTimeout(c),null),C(),n=!0,e.removeEventListener(`load`,ee),d.current=null,o({iframeLifecycleState:`closed`}),i&&Ax(i)}},[t,r.id,r.canvas_config.sandbox_url,o]),D(()=>{r.revision!==0&&(r.revision<=_.current||(_.current=r.revision,d.current?.sendToolInput({arguments:r.arguments}).catch(e=>{o({iframeLifecycleState:`error`,lastError:jP(e).message})})))},[r.arguments,r.revision,o]);let C=i.viable_slot===`full`||i.display_mode===`fullscreen`,w=C?null:xP(x,e),ee=w?.placeholderStyle,te=w?.cardStyle,ne=C?{height:`100%`}:w?.iframeStyle??{height:`${x}px`},re=[`pointer-events-auto w-full overflow-hidden rounded-lg border border-base-300 bg-base-100 shadow-xl transition-[opacity,transform]`,C?`fixed inset-4 z-10 max-w-none`:`max-w-md`,a?`scale-[0.98] opacity-40`:``].filter(Boolean).join(` `),ie=lP[r.canvas_config.component]??cP,ae=j(`div`,{class:re,style:te,"data-canvas-card":i.viable_slot,children:j(`iframe`,{ref:u,title:`${r.canvas_config.component} ${r.canvas_config.component_version}`,class:C?`block h-full w-full border-0 bg-transparent`:`block border-0 bg-transparent`,sandbox:ie,style:ne})});return C?ae:j(`div`,{class:`block w-full`,style:ee,children:ae})}var _P=[`--color-base-100`,`--color-base-200`,`--color-base-300`,`--color-base-content`,`--color-primary`,`--color-error`];function vP(e){if(!e||typeof getComputedStyle!=`function`)return{};let t=getComputedStyle(e),n={};for(let e of _P){let r=t.getPropertyValue(e).trim();r&&(n[e]=r)}return n}function yP(e,t){let n=vP(t);return Object.keys(n).length===0?e:{...e,cssVars:{...e.cssVars,...n}}}function bP(e,t,n,r,i){let a=DS(t,n),o=n.viable_slot===`full`||n.display_mode===`fullscreen`,s=o?void 0:kP(r),c=o?1:xP(i??0,r)?.displayScale??1;return{...e.canvas_config.host_context,...a,containerDimensions:{...AP(a.containerDimensions)?a.containerDimensions:{},...s===void 0?{}:{maxHeight:s},displayScale:c}}}function xP(e,t){if(t===void 0||!Number.isFinite(t)||t<=0)return null;let n=Math.min(e,720);if(n<=t)return{displayScale:1,placeholderStyle:{maxHeight:`${t}px`},cardStyle:void 0,iframeStyle:{width:`100%`,height:`${n}px`}};let r=t/n;return{displayScale:r,placeholderStyle:{height:`${n*r}px`,maxHeight:`${t}px`,overflow:`hidden`},cardStyle:{height:`${n}px`,transform:`scale(${r})`,transformOrigin:`top center`},iframeStyle:{width:`100%`,height:`${n}px`}}}function SP(){let e=O(null),[t,n]=E(()=>wP(null));return D(()=>{let t=()=>n(t=>{let n=wP(e.current);return t.width===n.width&&t.height===n.height&&t.visualViewportHeight===n.visualViewportHeight?t:n});t(),globalThis.addEventListener(`resize`,t),globalThis.visualViewport?.addEventListener(`resize`,t);let r;return typeof ResizeObserver<`u`&&e.current&&(r=new ResizeObserver(t),r.observe(e.current)),()=>{globalThis.removeEventListener(`resize`,t),globalThis.visualViewport?.removeEventListener(`resize`,t),r?.disconnect()}},[]),[e,t]}function CP(){let e=O(null),[t,n]=E();return D(()=>{let t=e.current;if(!t)return;let r=e=>{let r=e??t.getBoundingClientRect().height;!Number.isFinite(r)||r<=0||n(Math.floor(r))},i=()=>r();if(i(),typeof ResizeObserver>`u`)return globalThis.addEventListener(`resize`,i),()=>globalThis.removeEventListener(`resize`,i);let a=new ResizeObserver(e=>{r(e[0]?.contentRect.height)});return a.observe(t),()=>a.disconnect()},[]),[e,t]}function wP(e){let t=globalThis.visualViewport?.height,n=e?.getBoundingClientRect();if(n&&n.width>0&&n.height>0){let e=t===void 0?void 0:Math.max(0,(globalThis.innerHeight||0)-t);return{width:n.width,height:n.height,visualViewportHeight:e===void 0?void 0:Math.max(0,n.height-e)}}return{width:globalThis.innerWidth||1024,height:globalThis.innerHeight||768,visualViewportHeight:t}}var TP=72;function EP(e){let t=`absolute flex gap-2`;switch(e){case`safe-area-left`:return`${t} left-4 w-[28rem] flex-col overflow-y-auto [scrollbar-gutter:stable]`;case`safe-area-right`:return`${t} right-4 w-[28rem] flex-col overflow-y-auto [scrollbar-gutter:stable]`;case`safe-area-bottom`:return`${t} right-4 bottom-24 left-4 flex-col items-center justify-end @max-mobile:right-3 @max-mobile:bottom-20 @max-mobile:left-3`;case`full`:return`${t} inset-4 flex-col items-stretch justify-stretch`}}function DP(e){return e.display_mode===`fullscreen`&&e.preferred_slot!==`full`?e.preferred_slot:e.viable_slot}function OP(){return!1}function kP(e){return e===void 0||!Number.isFinite(e)||e<=0?720:Math.min(Math.floor(e),720)}function AP(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function jP(e){return e instanceof Error?e:Error(String(e))}var MP=1e4;function NP({onTimeout:e,timeoutMs:t=MP,active:n=!0}){let r=hx().length>0,[i,a]=E(!1),o=O(e);return D(()=>{o.current=e},[e]),D(()=>{if(!n||r){a(!1);return}let e=setTimeout(()=>{a(!0),o.current()},t);return()=>clearTimeout(e)},[n,r,t]),{hasJoined:r,timedOut:i}}function PP(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.message_type===`system`&&t.event_type===`system.shutdown`}function FP({onShutdown:e}){let t=O(e);D(()=>{t.current=e},[e]),Qg({onAppMessage:A(e=>{PP(e?.data)&&t.current()},[])})}var IP=vn(`PiP`),LP=360,RP=280;function zP(){return globalThis.window!==void 0&&`documentPictureInPicture`in globalThis.window}function BP(e){let{enabled:t,active:n}=e,[r,i]=E(null),a=zP(),o=ft(kv),s=A(()=>{i(e=>(e&&!e.closed&&e.close(),null))},[]),c=A(async()=>{if(a&&!(!t||!n)&&!(r&&!r.closed))try{let e=await globalThis.window.documentPictureInPicture.requestWindow({width:LP,height:RP}),t=Je.replace(/:host(?=[\s,{])/g,`:host, :root`),n=e.document.createElement(`style`);n.textContent=t,e.document.head.appendChild(n),e.document.body.style.margin=`0`,e.document.body.style.width=`100%`,e.document.body.style.height=`100vh`,e.document.body.style.overflow=`hidden`,e.addEventListener(`pagehide`,()=>{i(t=>t===e?null:t)},{once:!0}),i(e)}catch(e){IP.warn(`Failed to open PiP window`,e)}},[a,t,n,r]);return D(()=>{if(!t||!a||!n)return;let e=()=>{document.visibilityState===`hidden`?c():document.visibilityState===`visible`&&s()};document.addEventListener(`visibilitychange`,e);let r=[],i=null,o=`none`,l=!1;if(typeof navigator<`u`&&`mediaSession`in navigator){let e=navigator.mediaSession;i=e.metadata,o=e.playbackState;try{e.metadata=new MediaMetadata({title:`Tavus conversation`}),e.playbackState=`playing`,l=!0}catch(e){IP.warn(`mediaSession metadata setup failed`,e)}let t=(t,n)=>{try{e.setActionHandler(t,n),r.push(t)}catch(e){IP.warn(`mediaSession.${t} not supported`,e)}};t(`enterpictureinpicture`,()=>{c()}),t(`play`,()=>{}),t(`pause`,()=>{})}return()=>{if(document.removeEventListener(`visibilitychange`,e),typeof navigator<`u`&&`mediaSession`in navigator){let e=navigator.mediaSession;for(let t of r)try{e.setActionHandler(t,null)}catch{}if(l)try{e.metadata=i,e.playbackState=o}catch{}}}},[t,a,n,c,s]),D(()=>{(!n||!t)&&r&&!r.closed&&s()},[n,t,r,s]),D(()=>()=>{r&&!r.closed&&r.close()},[r]),D(()=>{if(!r||r.closed||!o)return;let e=()=>{r.document.body.setAttribute(`data-theme`,o.dataTheme.value);let e=o.cssVars.value;for(let[t,n]of Object.entries(e))r.document.body.style.setProperty(t,n)};e();let t=o.dataTheme.subscribe(()=>e()),n=o.cssVars.subscribe(()=>e());return()=>{t(),n()}},[r,o]),{pipWindow:r,isSupported:a,requestPipWindow:c,closePipWindow:s}}var VP=Ut(null),HP={active:!1,video_shift_x:0,backdrop:{type:`snapshot_mirror`}},UP=va(({id:e,showAudioWave:t=!0})=>{let n=d_(e).isOff;return j(`div`,{class:`relative aspect-square w-32 @max-mobile:w-24 rounded-box overflow-hidden bg-black/30 z-10 ${n?`hidden`:``}`,children:[j(dg,{automirror:!0,sessionId:e,type:`video`,fit:`cover`,className:`w-full h-full object-cover ${n?`hidden`:``}`}),t&&j(`div`,{class:`absolute bottom-2 right-2`,children:j(cx,{id:e})})]})}),WP=va(()=>{let e=Zh(),{isScreenSharing:t}=xb(),n=hx()[0];return j(le,{children:[t&&n&&j(UP,{id:n}),e&&j(UP,{id:e,showAudioWave:!1})]})}),GP=va(()=>j(`div`,{class:`absolute top-4 left-4 flex flex-col items-end gap-2 z-20`,children:j(WP,{})})),KP=va(({isAudioOnly:e,canvasLayoutEffect:t,canvasRenderedSlot:n})=>{let r=Zh(),i=!l_(r??``).isOff,a=gx(e),o=l_(a.phase===`ready`?a.replicaId:``),s=!i&&(o.state===`playable`||o.state===`loading`),c=t.active&&!i&&(!e||s);return a.phase===`left`?j(ox,{}):a.phase===`connecting`?j(ax,{}):e&&!s?j(`div`,{class:`absolute inset-0 flex items-center justify-center`,children:[j(fx,{sessionId:a.replicaId}),j(lg,{sessionId:a.replicaId})]}):j(le,{children:[s?j(oC,{personaSessionId:a.replicaId,isAudioOnly:e,avatarOff:a.videoState.isOff,canvasLayoutEffect:t,smartSidecarActive:c}):j(qP,{personaSessionId:a.replicaId,localId:r,isScreenSharing:i,avatarOff:a.videoState.isOff,smartSidecarActive:c,canvasLayoutEffect:t,canvasRenderedSlot:n}),j(lg,{sessionId:a.replicaId})]})}),qP=va(({personaSessionId:e,localId:t,isScreenSharing:n,avatarOff:r,smartSidecarActive:i,canvasLayoutEffect:a,canvasRenderedSlot:o})=>j(iC,{canvasLayoutEffect:a,smartSidecarActive:i,isScreenSharing:n,captureSnapshot:ZP,personaMode:`auto`,renderedSlot:o,fill:i=>j(bx,{personaSessionId:e,localSessionId:t,isScreenSharing:n,avatarOff:r,videoRef:i})})),JP=va(({items:e})=>{let[t,n]=E(!1),r=O(null);return D(()=>{if(!t)return;let e=e=>{r.current&&!e.composedPath().includes(r.current)&&n(!1)},i=e=>{e.key===`Escape`&&n(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,i)}},[t]),j(`div`,{ref:r,class:`relative`,children:[j(`button`,{type:`button`,onClick:()=>n(e=>!e),"aria-pressed":t,"aria-expanded":t,"aria-haspopup":`true`,"aria-label":t?`Close more controls`:`More controls`,class:`btn btn-control ${t?`btn-primary`:`btn-neutral`}`,children:j(qy,{name:`more`})}),t&&j(`div`,{role:`menu`,class:`absolute bottom-full mb-1 left-1/2 -translate-x-1/2 flex flex-row items-center gap-1 p-1 rounded-box bg-base-100 border border-base-300 shadow-lg z-30 whitespace-nowrap`,children:e})]})}),YP=va(({items:e})=>e.length<=1?j(le,{children:e}):j(JP,{items:e})),XP=va(({onLeave:e})=>{let t=Bg(),{config:n}=tv(),{session:r,end:i}=Kb(),a=Zh(),o=O(null),s=ft(zv)?.frameRef??o,[c,l]=E(!1),[u,d]=E(!1),[f,p]=E(HP),[m,h]=E(null),g=r.value?.conversationUrl,_=n.value.customization.conversation,v=_.modality===`audio`,y=_.modality===`chat`,b=_.modality===`video`,x=_.enable_chat,S=_.enable_closed_captions,C=_.enable_picture_in_picture,{pipWindow:w}=BP({enabled:C&&!y,active:t===`joined-meeting`});D(()=>()=>{i()},[i]);let{camera:ee,requestCamera:te}=Cv(),{isCamMuted:ne}=yb(),re=ee.isGranted&&!ne;D(()=>{b&&t===`joined-meeting`&&(VP.value=re)},[b,t,re]);let ie=O(b&&!a&&VP.value===!0);D(()=>{t===`joined-meeting`&&ie.current&&(ie.current=!1,te())},[t,te]),D(()=>{(t===`left-meeting`||t===`error`)&&e()},[t,e]),D(()=>{let e=()=>{let e=s.current,t=e?.getRootNode(),n=t instanceof Document||t instanceof ShadowRoot?t:null;l(!!e&&n?.fullscreenElement===e)};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let ae=A(()=>{let e=s.current;if(!e)return;let t=e.getRootNode();(t instanceof Document||t instanceof ShadowRoot?t:null)?.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()},[]);A(()=>{d(e=>!e)},[]);let oe=A(()=>{i()},[i]);if(NP({active:!y&&t===`joined-meeting`,onTimeout:oe}),FP({onShutdown:oe}),!g)return null;if(y)return j($b,{defaultOpen:!0,children:j(`div`,{class:`cvi-call-surface absolute inset-0`,children:j(rx,{docked:!0,headerAction:j(`button`,{type:`button`,class:`btn btn-ghost btn-sm btn-circle text-base-content/60 hover:text-error`,onClick:oe,"aria-label":`Leave conversation`,children:j(qy,{name:`leave`,size:20,"aria-label":`Leave conversation`})})})})});let T=[j(Gb,{compact:!0},`screen-share`)];x&&T.push(j(tx,{compact:!0},`chat`));let se=t===`left-meeting`;return j(Jb,{children:j($b,{children:j(Ob,{children:[j(`div`,{class:`cvi-call-surface absolute inset-0`,children:[j(`div`,{class:`relative w-full h-full z-[5]`,children:[j(KP,{isAudioOnly:v,canvasLayoutEffect:f,canvasRenderedSlot:m}),!v&&j(GP,{}),j(Zb,{}),j(pP,{debugEnabled:u,onLayoutEffectChange:p,onRenderedSlotChange:h}),j(`div`,{class:`cvi-autohide absolute top-4 right-4 z-20`,"data-hidden":se,children:j(sx,{active:c,onToggle:ae,compact:!0})})]}),j(rx,{}),j(`div`,{class:`cvi-autohide cvi-autohide-slide pointer-events-none absolute bottom-6 left-0 right-0 z-20`,"data-hidden":se,"aria-hidden":se,children:j(`div`,{class:`cvi-control-rail flex justify-center items-center gap-2 @max-mobile:gap-1`,"data-hidden":se,children:[j(Bb,{level:!0}),!v&&j(Hb,{}),S&&j(Xb,{}),j(YP,{items:T}),j(`button`,{type:`button`,class:`btn btn-control btn-error`,onClick:oe,"aria-label":`Leave call`,children:j(qy,{name:`leave`,"aria-label":`Leave Call`})})]})})]}),w&&Fa(j(vx,{onLeave:oe}),w.document.body)]})})})});function ZP(e){if(!e||e.readyState<2||!e.videoWidth||!e.videoHeight)return null;let t=document.createElement(`canvas`),n=Math.round(640*(e.videoHeight/e.videoWidth));t.width=640,t.height=n;let r=t.getContext(`2d`);if(!r)return null;r.drawImage(e,0,0,640,n);try{return t.toDataURL(`image/jpeg`,.82)}catch{return null}}function QP({loading:e=!1,disabled:t,class:n,children:r,...i}){return j(`button`,{type:`button`,class:`btn relative ${n?` ${n}`:``}`,disabled:t||e,"aria-busy":e||void 0,...i,children:[j(`span`,{children:r}),e&&j(`span`,{class:`absolute inset-0 flex items-center justify-center backdrop-blur-xs`,"aria-hidden":`true`,children:j(`span`,{class:`loading loading-spinner loading-sm`})})]})}function $P({message:e,class:t}){return j(`div`,{class:`w-max max-w-[min(20rem,80vw)] ${t??``}`,children:[j(`div`,{class:`px-4 py-2 rounded-box bg-neutral text-neutral-content text-sm font-medium shadow-lg text-center`,role:`status`,"aria-live":`polite`,children:e}),j(`svg`,{class:`absolute left-1/2 -translate-x-1/2 top-full text-neutral`,width:`16`,height:`8`,viewBox:`0 0 16 8`,"aria-hidden":`true`,children:j(`path`,{d:`M0 0 L8 8 L16 0 Z`,fill:`currentColor`})})]})}function eF(e,t,n){switch(t){case`granted`:return n?e?.cameraOptional??`Camera is optional — turn it on anytime.`:e?.ready??`You're all set — join whenever you're ready.`;case`blocked`:return e?.denied??`Microphone is blocked. Click the mic to see how to allow it.`;case`in-use`:return`Your microphone is in use by another app. Close it and try again.`;case`not-found`:return`No microphone found. Connect one to continue.`;case`unsupported`:return`This browser can't access your microphone.`;case`prompt`:return e?.prompt??`Allow microphone access to join.`;default:return e?.loading??`Getting your microphone ready...`}}var tF=va(({text:e,isJoining:t=!1,onJoin:n,onCancel:r})=>{let i=ph(),{config:a}=tv(),{localSessionId:o,isCamMuted:s}=yb(),{mic:c,camera:l,requestMic:u,requestCamera:d}=Cv(),f=a.value.customization.conversation.modality===`video`;D(()=>{u()},[]);let p=c.isGranted,m=O(!1);D(()=>{!f||!p||m.current||l.isGranted||l.isBlocked||(m.current=!0,d())},[f,p,l.isGranted,l.isBlocked,d]);let h=f&&p&&!l.isGranted,g=eF(e,c.status,h);return j(Ob,{children:j(`div`,{class:`absolute inset-0 motion-safe:animate-[tavusFadeUp_280ms_ease-out]`,children:[l.isGranted&&!s?j(`div`,{class:`absolute inset-0 flex items-center justify-center bg-black overflow-hidden`,children:j(dg,{type:`video`,sessionId:o??``,mirror:!0,fit:`cover`,className:`w-full h-full object-cover!`})}):j(`div`,{class:`absolute inset-0 flex items-center justify-center text-base-content/40`,children:j(qy,{name:`face-smile`,size:`7rem`,"aria-label":`Camera off`})}),j(`div`,{class:`absolute bottom-6 left-1/2 -translate-x-1/2 z-10 flex flex-col items-center gap-2 max-w-[90%]`,children:[g&&j($P,{message:g,class:`relative`}),j(`div`,{class:`flex flex-wrap items-center justify-center gap-1.5 @max-mobile:gap-1`,children:[j(`div`,{class:`flex items-center justify-center gap-1.5 shrink-0 @max-mobile:gap-1`,children:[j(Bb,{level:!0}),f&&j(Hb,{})]}),j(QP,{class:`btn-accent `,loading:t,disabled:!p,onClick:n,children:e?.join??`Join Video Chat`}),c.isBlocked&&j(`button`,{type:`button`,class:`btn btn-error `,onClick:()=>{i&&i.leave(),r?.()},children:e?.cancel??`Cancel`})]})]})]})})}),nF=`Password required`,rF=`Enter the password to start this conversation.`,iF=`Password`,aF=`Continue`;function oF({onSubmit:e,text:t,isSubmitting:n=!1,errorMessage:r}){let[i,a]=E(``),o=mt();return j(`div`,{class:`absolute inset-0 z-30 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`${o}-title`,children:j(`form`,{onSubmit:t=>{t.preventDefault();let r=i.trim();!r||n||e(r)},class:`card bg-base-100 shadow-xl w-full max-w-sm`,children:j(`div`,{class:`card-body gap-3`,children:[j(`h3`,{id:`${o}-title`,class:`card-title text-base-content`,children:t?.title??nF}),j(`p`,{class:`text-sm text-base-content/70`,children:t?.description??rF}),j(`input`,{id:o,type:`password`,autocomplete:`current-password`,class:`input input-bordered w-full`,placeholder:t?.placeholder??iF,value:i,disabled:n,onInput:e=>a(e.target.value),autoFocus:!0}),r&&j(`p`,{class:`text-error text-xs`,role:`alert`,children:r}),j(QP,{class:`btn-primary`,type:`submit`,disabled:!i.trim(),loading:n,children:t?.submit??aF})]})})})}var sF=vn(`CaptchaChallenge`),cF=1;function lF(e){return typeof e==`object`&&!!e&&e.source===`tavus-captcha`&&typeof e.type==`string`}function uF(e,t,n,r,i){return`${e.replace(/\/+$/,``)}${t.startsWith(`/`)?t:`/${t}`}?deployment_uuid=${encodeURIComponent(n)}&action=${encodeURIComponent(r)}&parent_origin=${encodeURIComponent(i)}`}function dF({captcha:e,deploymentId:t,onToken:n,onFallback:r}){let i=(ft(Ct).baseUrl??`https://tavusapi.com`).replace(/\/+$/,``),a=new URL(i).origin,[o,s]=E(0),[c,l]=E(0),[u,d]=E(!1),[f,p]=E(!1),m=uF(i,e.challenge_path,t,e.action,window.location.origin),h=A(()=>{p(!1),s(e=>e+1)},[]);return D(()=>{function e(e){if(u||e.origin!==a)return;let i=e.data;if(lF(i)&&i.deployment_uuid===t){if(i.type===`interactive`){p(!0);return}if(i.type===`token`&&i.token){sF.info(`Captcha token received`),p(!1),n(i.token);return}if(i.type===`expired`){sF.info(`Captcha token expired, reloading iframe`),h();return}i.type===`error`&&(sF.warn(`Captcha error received`,i.code),c<cF?(l(e=>e+1),h()):(sF.warn(`Captcha error retries exhausted, falling back to no-token mode`),d(!0),r()))}}return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[a,t,c,u,n,r,h]),u?null:j(`div`,{class:f?`absolute inset-0 z-30 flex items-center justify-center p-4 bg-base-100/70 backdrop-blur-sm animate-[tavusFadeUp_180ms_ease-out]`:`absolute top-0 left-0 w-0 h-0 overflow-hidden opacity-0 pointer-events-none`,"aria-hidden":!f,children:j(`iframe`,{src:m,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`,title:`Security challenge`,style:{border:`none`,width:`300px`,height:`65px`},scrolling:`no`},o)})}function fF({kind:e,status:t}){if(e===`camera`)return`Allow camera access to use video. Camera is optional.`;switch(t){case`blocked`:return`Microphone is blocked. Allow access in your browser settings to continue.`;case`in-use`:return`Your microphone is in use by another app. Close it and try again.`;case`not-found`:return`No microphone found. Connect one to continue.`;case`unsupported`:return`This browser can't access your microphone.`;default:return`Allow microphone access to start the conversation.`}}function pF({text:e,onStart:t,isStarting:n,permissionRequest:r}){let{config:i,deploymentId:a}=tv(),o=ft(K_),s=Qy(i.value),c=s.btn_title??e?.fallback_button??`Start the conversation`,l=i.value.customization.terms_content?.trim()??``,u=i.value.customization.terms_enabled===!0,d=l.length>0,f=d&&u,p=k(()=>f&&S_(a,l),[f,a,l]),m=f&&!p,h=i.value.has_password===!0,g=o?.password.value??null,_=h&&!g,v=i.value.captcha??null,{captchaReady:y,captchaEpoch:b,handleCaptchaToken:x,handleCaptchaFallback:S}=vv(v,o,n),C=mt(),[w,ee]=E(p),te=v!==null&&!y,ne=n||f&&!w||_||te;return j(sb,{title:s.title,description:s.description,overlay:j(le,{children:[te&&j(dF,{captcha:v,deploymentId:a,onToken:x,onFallback:S},b),_&&o?j(oF,{onSubmit:o.setPassword}):null]}),children:[j(`div`,{class:`relative`,children:[r&&j($P,{message:fF(r),class:`absolute bottom-full left-1/2 -translate-x-1/2 mb-3 z-20`}),j(QP,{class:`btn-neutral rounded-box`,onClick:()=>{f&&w&&!p&&T_(a,l),t()},disabled:ne,loading:n,children:c})]}),d&&j(`div`,{class:`max-w-xs`,children:m?j(`label`,{for:C,class:`flex items-center gap-2 text-xs text-left cursor-pointer`,children:[j(`input`,{id:C,type:`checkbox`,class:`checkbox checkbox-secondary checkbox-xs mt-0.5 shrink-0`,checked:w,onChange:e=>ee(e.target.checked)}),j(`span`,{class:`leading-snug`,children:l})]}):j(`p`,{class:`text-xs leading-snug text-base-content/60`,children:l})})]})}function mF({flow:e,welcomeText:t,onUnavailableCancel:n}){switch(e.state){case`idle`:return j(pF,{text:t,onStart:()=>{e.start()},isStarting:e.isStarting,permissionRequest:e.permissionRequest});case`haircheck`:return j(tF,{onJoin:()=>{e.join()},onCancel:()=>e.cancel(),isJoining:e.isStarting});case`call`:return j(XP,{onLeave:()=>e.leave()});case`ended`:return j(vb,{onRestart:()=>e.restart()});case`unavailable`:return j(fb,{cause:e.unavailableCause??`busy`,canRetry:e.canRetry,onRetry:()=>{e.start()},onCancel:n});default:{let t=e.state;throw Error(`Unreachable flow state: ${String(t)}`)}}}var hF=Fe(null);function gF({children:e}){let{config:t}=ft(bi),n=t.peek().customization?.widget,r=n?.expandable??`default`,i=un(r===`start-expanded`||r===`always`),a=un(n?.variant??`full`),o=un(n?.position??`bottom-right`),s=un(r),c=un(n?.avatar?.type??`orb`),l=O(r);_n(()=>{let e=t.value.customization?.widget,n=e?.expandable??`default`;a.value=e?.variant??`full`,o.value=e?.position??`bottom-right`,s.value=n,c.value=e?.avatar?.type??`orb`,l.current!==n&&(i.value=n===`start-expanded`||n===`always`,l.current=n)});let u=A(()=>{s.peek()!==`always`&&(i.value=!i.peek())},[i,s]),d=A(()=>{i.value=!0},[i]),f=A(()=>{s.peek()!==`always`&&(i.value=!1)},[i,s]),p=k(()=>({expanded:i,variant:a,position:o,expandable:s,avatarType:c,toggle:u,expand:d,collapse:f}),[i,a,o,s,c,u,d,f]);return j(hF.Provider,{value:p,children:e})}function _F(){let{config:e}=tv(),t=e.value.customization.branding;return e.value.show_tavus_branding!==!1&&!t?.hide_tavus_badge?j(vF,{}):t?.logo||t?.text?j(yF,{logo:t.logo,text:t.text}):null}function vF(){let{isDark:e}=QN(),t=e.value?`white`:`#140206`;return j(`a`,{href:`https://tavus.io`,target:`_blank`,rel:`noopener noreferrer`,class:`inline-flex items-center gap-1 text-xs text-base-content/50 hover:text-base-content/80 transition-colors`,children:[j(`svg`,{viewBox:`0 0 488 452`,class:`h-2.5 w-2.5 shrink-0`,fill:`none`,"aria-hidden":`true`,children:[j(`path`,{d:`M160 152V208H104V152H160Z`,fill:t}),j(`path`,{"fill-rule":`evenodd`,"clip-rule":`evenodd`,d:`M488 270.5L436 285L451 326L418.766 346L441 360L423 392L435 452H0V0H394.766L488 270.5ZM24 24V428H216.2L209 392L227 360L204.766 346L237 326L222 285L274 270.5L189.038 24H24ZM352 152C336.536 152 324 164.536 324 180C324 195.464 336.536 208 352 208C367.464 208 380 195.464 380 180C380 164.536 367.464 152 352 152Z`,fill:t})]}),j(`span`,{children:[`Powered by `,j(`span`,{class:`underline`,children:`Tavus`})]})]})}function yF({logo:e,text:t}){return j(`div`,{class:`inline-flex items-center gap-1 text-xs text-base-content/50`,children:[e?j(`img`,{src:e,alt:t||`Branding`,class:`h-2.5 shrink-0`}):null,t?j(`span`,{children:t}):null]})}var bF={title:`Hi! Want to chat?`,btn_title:`Start conversation`};function xF(){let{config:e}=tv(),t=e.value.customization.widget?.text;return k(()=>({title:t?.title||bF.title,btn_title:t?.btn_title||bF.btn_title}),[t])}function SF(){let e=ft(hF);if(!e)throw Error(`useWidgetUI must be used within WidgetUIProvider`);return e}var CF={xs:`w-6 h-6`,sm:`w-8 h-8`,md:`w-10 h-10`,lg:`w-16 h-16`},wF={xs:`w-3 h-3`,sm:`w-4 h-4`,md:`w-5 h-5`,lg:`w-8 h-8`};function TF({size:e=`md`,className:t=``}){let{avatarType:n}=SF(),{config:r}=tv(),i=Zy(r.value);return(Qy(r.value).background.type===`replica`||n.value===`image`)&&i?j(`div`,{class:`relative ${CF[e]} rounded-box overflow-hidden bg-base-300 ${t}`,children:j(nb,{replica:i})}):j(`div`,{class:`relative ${CF[e]} rounded-box bg-primary/15 flex items-center justify-center ${t}`,children:j(`span`,{class:`${wF[e]} rounded-full bg-primary animate-pulse`})})}function EF({variant:e}){let{toggle:t}=SF(),n=xF();return e===`tiny`?j(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`rounded-box overflow-hidden shadow-xl hover:shadow-2xl transition-shadow cursor-pointer`,children:j(TF,{size:`lg`})}):e===`compact`?j(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`group flex items-center gap-2.5 py-2.5 pl-2.5 pr-8 rounded-box bg-base-100 text-base-content border border-base-300 shadow-lg hover:shadow-xl transition-shadow cursor-pointer text-left`,children:[j(TF,{size:`md`}),j(`span`,{class:`flex flex-col gap-0.5`,children:[j(`span`,{class:`text-base font-medium leading-tight`,children:n.title}),j(`span`,{class:`text-sm text-base-content/60 leading-tight`,children:n.btn_title})]})]}):j(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`flex flex-col gap-3 p-3 w-64 rounded-box bg-base-100 text-base-content border border-base-300 shadow-xl hover:shadow-2xl transition-shadow cursor-pointer text-left`,children:[j(`div`,{class:`flex items-center gap-2.5`,children:[j(TF,{size:`md`}),j(`span`,{class:`text-sm font-medium leading-snug`,children:n.title})]}),j(`span`,{class:`btn btn-primary btn-sm w-full pointer-events-none gap-2 flex items-center`,children:[j(qy,{name:`cam`,size:16}),j(`span`,{className:`leading-4`,children:n.btn_title})]})]})}var DF=`tavus:widget:greeting-dismissed`;function OF({anchor:e}){let t=xF(),{variant:n,expand:r}=SF(),[i,a]=E(!1);D(()=>{if(n.value===`tiny`){try{if(sessionStorage.getItem(DF)===`1`)return}catch{}a(!0)}},[n]);let o=A(e=>{e.stopPropagation();try{sessionStorage.setItem(DF,`1`)}catch{}a(!1)},[]);if(!i)return null;let s=e===`right`?`right-[-6px] border-r border-b`:`left-[-6px] border-l border-t`,c=e===`right`?`-right-2`:`-left-2`;return j(`button`,{type:`button`,onClick:r,class:`relative max-w-56 rounded-box bg-base-100 text-base-content shadow-lg border border-base-300 px-3 py-2 text-sm text-left cursor-pointer animate-[tavusFadeUp_240ms_ease-out] hover:bg-base-200 transition-colors`,children:[j(`p`,{class:`leading-snug pr-3`,children:t.title}),j(`span`,{role:`button`,tabIndex:0,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o(e)},class:`absolute -top-2 ${c} btn btn-ghost btn-circle btn-xs bg-base-100 border border-base-300 shadow-sm`,"aria-label":`Dismiss`,children:`×`}),j(`span`,{class:`absolute bottom-3 w-3 h-3 rotate-45 bg-base-100 border-base-300 ${s}`})]})}function kF(){let e=ft(Ev);if(!e)throw Error(`useHostBridge must be used within HostBridgeProvider`);return e}var AF=`bg-base-100 text-base-content rounded-box border border-base-300 shadow-xl w-[22rem] flex flex-col animate-[tavusPopIn_180ms_ease-out]`,jF=`bg-base-100 text-base-content w-[100vw] h-[100dvh] flex flex-col animate-[tavusFadeUp_180ms_ease-out]`,MF=`p-1 flex-1 min-h-0`,NF=`p-1 flex-1 min-h-0`;function PF({variant:e,children:t,onClose:n,fullscreen:r}){let{expandable:i}=SF(),a=i.value!==`always`;return r?j(`div`,{class:jF,children:[j(`div`,{class:`flex items-center justify-end gap-2 px-2.5 py-1.5 border-b border-base-300`,children:a&&j(`button`,{type:`button`,class:`btn btn-ghost btn-circle btn-xs`,onClick:n,"aria-label":`Close`,children:j(qy,{name:`close`,size:14})})}),j(`div`,{class:NF,children:t}),j(`div`,{class:`flex justify-end px-2.5`,children:j(_F,{})})]}):j(`div`,{class:`flex flex-col h-[min(34rem,calc(100dvh-3rem))]`,children:[j(`div`,{class:`${AF} flex-1 overflow-hidden`,children:[j(`div`,{class:`flex items-center justify-end gap-2 px-2.5 pt-1.5 shrink-0`,children:a&&j(`button`,{type:`button`,class:`btn btn-ghost btn-circle btn-xs`,onClick:n,"aria-label":`Close`,children:j(qy,{name:`close`,size:14})})}),j(`div`,{class:MF,children:t})]}),j(`div`,{class:`flex justify-end pr-2 pt-1.5 shrink-0`,children:j(_F,{})})]})}var FF=vn(`Widget`),IF=`1rem`,LF=480;function RF(e,t,n){let r=e.state===`call`,i=r||e.state===`haircheck`||e.isStarting;e.cancel(),r&&e.leave(),i&&t(),n()}function zF(){return typeof window>`u`?!1:window.innerWidth<=LF}function BF(e){switch(e){case`bottom-right`:return{bottom:IF,right:IF};case`bottom-left`:return{bottom:IF,left:IF};case`top-right`:return{top:IF,right:IF};case`top-left`:return{top:IF,left:IF};case`top`:return{top:IF,left:`50%`,transform:`translateX(-50%)`};case`bottom`:return{bottom:IF,left:`50%`,transform:`translateX(-50%)`}}}var VF=[`top`,`bottom`,`left`,`right`,`transform`];function HF(e){return e===`bottom-left`||e===`top-left`?`left`:`right`}function UF(){let{config:e,initError:t}=tv(),n=xF(),{expanded:r,position:i,variant:a,collapse:o}=SF(),{end:s}=Kb(),{shadowHost:c}=kF(),l=pb(),u=un(zF());D(()=>{if(typeof window>`u`)return;u.value=zF();let e=()=>{u.value=zF()};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[u]);let d=k(()=>({fallback_button:n.btn_title}),[n.btn_title]),f=A(()=>{RF(l,s,o)},[l,s,o]);if(_n(()=>{let e=c.value,t=i.value,n=r.value,a=n&&u.value;if(e){if(a)e.style.top=`0`,e.style.right=`0`,e.style.bottom=`0`,e.style.left=`0`,e.style.transform=``;else{let n=BF(t);for(let t of VF)e.style[t]=n[t]??``}e.dataset.tavusWidgetPosition=t,e.dataset.tavusWidgetExpanded=n?`true`:`false`,e.dataset.tavusWidgetFullscreen=a?`true`:`false`,e.dataset.tavusWidgetSmall=u.value?`true`:`false`}}),t.value)return FF.error(`Widget cannot initialize (init request failed):`,t.value),null;if(e.value.is_available===!1&&e.value.unavailable_reason===`total_limit`)return FF.error(`Widget is unavailable (total_limit reached) — not rendering`),null;if(!r.value){let e=HF(i.value),t=e===`right`?`flex items-end gap-2 justify-end`:`flex items-end gap-2 flex-row-reverse justify-end`,n=e===`right`?`justify-end pr-2`:`justify-start pl-2`;return j(`div`,{class:`flex flex-col`,children:[j(`div`,{class:t,children:[j(OF,{anchor:e}),j(EF,{variant:a.value})]}),j(`div`,{class:`flex ${n} pt-1.5`,children:j(_F,{})})]})}return e.value.is_available===!1?j(PF,{variant:a.value,fullscreen:u.value,onClose:f,children:j(Bv,{children:j(fb,{cause:e.value.unavailable_reason??`daily_limit`,canRetry:!1,onRetry:()=>{}})})}):j(PF,{variant:a.value,fullscreen:u.value,onClose:f,children:j(Bv,{children:j(mF,{flow:l,welcomeText:d,onUnavailableCancel:()=>l.restart()})})})}var WF=`:host {
|
|
164
164
|
display: block;
|
|
165
165
|
position: fixed;
|
|
166
166
|
z-index: 50;
|
package/dist/index.mjs
CHANGED
|
@@ -27121,7 +27121,10 @@ var wN = 1e3, TN = 5e3, EN = 1200, DN = 2e3;
|
|
|
27121
27121
|
function ON(e) {
|
|
27122
27122
|
return e.correct_answer === void 0 ? EN : DN;
|
|
27123
27123
|
}
|
|
27124
|
-
var kN = 48, AN = "allow-scripts", jN = {
|
|
27124
|
+
var kN = 48, AN = "allow-scripts", jN = {
|
|
27125
|
+
"canvas.scheduling_embed": "allow-scripts allow-same-origin allow-popups allow-forms",
|
|
27126
|
+
"canvas.text": "allow-scripts allow-popups allow-popups-to-escape-sandbox"
|
|
27127
|
+
};
|
|
27125
27128
|
function MN(e, t) {
|
|
27126
27129
|
if (!t.contentWindow || e.source !== t.contentWindow) return !1;
|
|
27127
27130
|
let n = e.data;
|