@tavus/embed 0.0.1-beta.11 → 0.0.1-beta.12

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.
@@ -156,10 +156,10 @@ Boolean requesting whether a visible border and background is provided by the ho
156
156
  - omitted: host decides border`)});var Qj=Z({method:$(`ui/request-display-mode`),params:Z({mode:Lj.describe(`The display mode being requested.`)})});Z({mode:Lj.describe(`The display mode that was actually set. May differ from requested if not supported.`)}).passthrough();var $j=Q([$(`model`),$(`app`)]).describe(`Tool visibility scope - who can access the tool.`);Z({resourceUri:J().optional(),visibility:X($j).optional().describe(`Who can access this tool. Default: ["model", "app"]
157
157
  - "model": Tool visible to and callable by the agent
158
158
  - "app": Tool callable by the app from this server only`),csp:SD().optional(),permissions:SD().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 eM=Z({method:$(`ui/download-file`),params:Z({contents:X(Q([OA,kA])).describe(`Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.`)})}),tM=Z({method:$(`ui/message`),params:Z({role:$(`user`).describe(`Message role, currently only "user" is supported.`),content:X(AA).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:Vj.optional().describe(`CSP configuration from resource metadata.`),permissions:Hj.optional().describe(`Sandbox permissions from resource metadata.`)})}),Z({method:$(`ui/notifications/tool-result`),params:zA.describe(`Standard MCP tool execution result.`)});var nM=Z({toolInfo:Z({id:ak.optional().describe(`JSON-RPC id of the tools/call request.`),tool:IA.describe(`Tool definition including name, inputSchema, etc.`)}).optional().describe(`Metadata of the tool call that instantiated this App.`),theme:Ij.optional().describe(`Current color theme preference.`),styles:Gj.optional().describe(`Style configuration for theming the app.`),displayMode:Lj.optional().describe(`How the UI is currently displayed.`),availableDisplayModes:X(Lj).optional().describe(`Display modes the host supports.`),containerDimensions:Q([Z({height:Y().describe(`Fixed container height in pixels.`)}),Z({maxHeight:Q([Y(),yD()]).optional().describe(`Maximum container height in pixels.`)})]).and(Q([Z({width:Y().describe(`Fixed container width in pixels.`)}),Z({maxWidth:Q([Y(),yD()]).optional().describe(`Maximum container width in pixels.`)})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
159
- 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:vD().optional().describe(`Whether the device supports touch input.`),hover:vD().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:nM.describe(`Partial context update containing only changed fields.`)});var rM=Z({method:$(`ui/update-model-context`),params:Z({content:X(AA).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:ED(J(),xD().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),iM=Z({method:$(`ui/initialize`),params:Z({appInfo:bk.describe(`App identification (name and version).`),appCapabilities:Xj.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:bk.describe(`Host application identification and version.`),hostCapabilities:Yj.describe(`Features and capabilities provided by the host.`),hostContext:nM.describe(`Rich context about the host environment.`)}).passthrough();var aM=[Fj],oM=class extends Pj{_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:Uj,sandboxready:Bj,initialized:Zj,requestteardown:Jj,loggingmessage:qA};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(iM,e=>this._oninitialize(e)),this.setRequestHandler(Ak,(e,t)=>(this.onping?.(e.params,t),{})),this.replaceRequestHandler(Qj,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(tM,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(zj,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(eM,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(Qj,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(rM,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(VA,async(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}set oncreatesamplingmessage(e){this.setRequestHandler(tj,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(rA,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(aA,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(lA,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(bA,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:aM.includes(t)?t:Fj,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];sM(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},Kj,t)}sendResourceTeardown=this.teardownResource;callTool(e,t){return this.request({method:`tools/call`,params:e},zA,t)}listTools(e,t){return this.request({method:`tools/list`,params:e},RA,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},zA,{signal:t.signal}),e.tools.listChanged&&this._client.setNotificationHandler(HA,e=>this.sendToolListChanged(e.params))),e.resources&&(this.onlistresources=async(e,t)=>this._client.request({method:`resources/list`,params:e},iA,{signal:t.signal}),this.onlistresourcetemplates=async(e,t)=>this._client.request({method:`resources/templates/list`,params:e},oA,{signal:t.signal}),this.onreadresource=async(e,t)=>this._client.request({method:`resources/read`,params:e},uA,{signal:t.signal}),e.resources.listChanged&&this._client.setNotificationHandler(dA,e=>this.sendResourceListChanged(e.params))),e.prompts&&(this.onlistprompts=async(e,t)=>this._client.request({method:`prompts/list`,params:e},xA,{signal:t.signal}),e.prompts.listChanged&&this._client.setNotificationHandler(NA,e=>this.sendPromptListChanged(e.params)))}return super.connect(e)}};function sM(e,t){return JSON.stringify(e)===JSON.stringify(t)}function cM(){let e=ft(hv);if(!e)throw Error(`useTheme must be used within ThemeProvider`);return e}async function lM(e){try{await e.teardownResource({},{timeout:1e3})}catch{}try{await e.close()}catch{}}function uM({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(dM,{label:`iframe`,value:e.iframeLifecycleState}),j(dM,{label:`post`,value:e.lastInteractionPostResult}),j(dM,{label:`context`,value:e.lastModelContextUpdate}),j(dM,{label:`error`,value:e.lastError}),j(fM,{label:`tool_call`,value:e.lastToolCall}),j(fM,{label:`canvas_config`,value:e.parsedCanvasConfig})]})]}):null}function dM({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 fM({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 pM=new Set([`mcp-ui.tavus.io`,`mcp-ui.tavus-preview.io`]),mM=[`.sandbox-tavus.io`],hM=new Set([`tavusapi.com`]);function gM(e){let t;try{t=new URL(e)}catch{return!1}return yM(t)?!0:t.protocol===`https:`?pM.has(t.hostname)?!0:mM.some(e=>t.hostname.endsWith(e)):!1}function _M(e){return gM(e)}function vM(e){let t;try{t=new URL(e)}catch{return!1}return bM(t)?!0:t.protocol===`https:`&&hM.has(t.hostname)}function yM(e){return bM(e)}function bM(e){return!xM()||e.protocol!==`http:`&&e.protocol!==`https:`?!1:[`localhost`,`127.0.0.1`,`::1`,`[::1]`].includes(e.hostname)}function xM(){try{let e=globalThis.location?.hostname;return typeof e==`string`&&[`localhost`,`127.0.0.1`,`::1`,`[::1]`].includes(e)}catch{return!1}}var SM=`tavus.canvas.interaction`,CM=[`safe-area-right`,`safe-area-left`,`safe-area-bottom`,`full`],wM=`safe-area-right`,TM={x:275/1280,y:111/720,width:730/1280,height:609/720},EM={type:`snapshot_mirror`};function DM(e){return XM(e)?e.message_type===`conversation`&&e.event_type===`conversation.tool_call`&&typeof e.conversation_id==`string`&&XM(e.properties):!1}function OM(e){if(!XM(e))return null;let t=uN(e,`component`),n=uN(e,`component_version`),r=uN(e,`sandbox_url`),i=pN(e,`mcp_server_url`,_M),a=pN(e,`api_base_url`,vM),o=pN(e,`interaction_url`,vM),s=eN(e.layout),c=e.version;return c!==1||!t||!n||!r||!gM(r)||i===null||a===null||o===null||s===null?null:{version:c,component:t,component_version:n,resource_uri:uN(e,`resource_uri`),sandbox_url:r,mcp_server_url:i,mcp_tool_name:uN(e,`mcp_tool_name`),api_base_url:a,interaction_url:o,layout:s,host_context:XM(e.host_context)?e.host_context:void 0}}function kM(e){if(e===void 0)return{ok:!0,value:{}};if(XM(e))return{ok:!0,value:e};if(typeof e!=`string`)return{ok:!1,error:Error(`Magic Canvas tool arguments must be an object or JSON string.`)};try{let t=JSON.parse(e);return XM(t)?{ok:!0,value:t}:{ok:!1,error:Error(`Magic Canvas tool arguments must decode to an object.`)}}catch(e){return{ok:!1,error:ZM(e)}}}function AM(e){let t=e.properties.name;if(t!==`canvas_clear`&&t!==`update_component`)return null;let n=kM(e.properties.arguments);if(!n.ok)throw n.error;if(t===`canvas_clear`){let t=n.value.tool_call_id,r=n.value.reason;if(t!==void 0&&typeof t!=`string`)throw Error(`Magic Canvas clear tool_call_id must be a string when provided.`);if(r!==void 0&&typeof r!=`string`)throw Error(`Magic Canvas clear reason must be a string when provided.`);return{kind:`clear`,conversation_id:e.conversation_id,tool_call_id:t,reason:r}}let r=n.value.tool_call_id,i=n.value.updates;if(typeof r!=`string`||r.length===0)throw Error(`Magic Canvas update_component requires a target tool_call_id.`);if(!XM(i))throw Error(`Magic Canvas update_component requires an object updates payload.`);return{kind:`update`,conversation_id:e.conversation_id,tool_call_id:r,updates:i}}var jM=[`safe-area-left`,`safe-area-right`];function MM(e){let t=jM.includes(e.preferred_slot)?e.preferred_slot:wM;return t===e.preferred_slot&&e.display_mode===`inline`?e:{...e,preferred_slot:t,display_mode:`inline`}}function NM(e){return e.display_mode===`fullscreen`?`full`:e.preferred_slot}function PM(e){return e===`full`||e===`safe-area-bottom`}function FM(e,t){let n=NM(t.layout);return PM(n)?[t]:[...e.filter(e=>{let t=NM(e.layout);return!PM(t)&&t!==n}),t]}function IM(e,t){switch(t.kind){case`show`:{let n=e.find(e=>e.id===t.instance.id),r=n?{...t.instance,revision:n.revision+1}:t.instance;return FM(e.filter(e=>e.id!==t.instance.id),r)}case`update`:{let n=e=>e.conversation_id===t.conversation_id&&e.tool_call_id===t.tool_call_id,r=KM(t.updates),i,a=e.map(e=>{if(!n(e))return e;let t={...e,arguments:{...e.arguments,...r.componentArguments},layout:MM({preferred_slot:r.preferredSlot??e.layout.preferred_slot,display_mode:r.displayMode??e.layout.display_mode,avoid_safe_area:r.avoidSafeArea??e.layout.avoid_safe_area,safe_area:r.safeArea??e.layout.safe_area,backdrop:r.backdrop??e.layout.backdrop}),revision:e.revision+1};return i=t,t});if(i===void 0)return a;let o=e.find(n);return o&&NM(o.layout)===NM(i.layout)?a:FM(a.filter(e=>!n(e)),i)}case`clear`:return t.tool_call_id?e.filter(e=>!(e.conversation_id===t.conversation_id&&e.tool_call_id===t.tool_call_id)):e.filter(e=>e.conversation_id!==t.conversation_id)}}function LM(e){if(!XM(e)||!Array.isArray(e.content))return null;for(let t of e.content){if(!XM(t))continue;let e=(XM(t._meta)?t._meta:null)?.[SM];if(XM(e))return mN(e)}return null}function RM(e,t){let n=t.type,r=t.value;if(!n)throw Error(`Magic Canvas interaction is missing type.`);if(r===void 0)throw Error(`Magic Canvas interaction is missing value.`);return{interaction_id:t.interaction_id??YM(e.tool_call_id,n),conversation_id:e.conversation_id,tool_call_id:e.tool_call_id,component:t.component??e.canvas_config.component,component_version:t.component_version??e.canvas_config.component_version,type:n,value:r,metadata:XM(t.metadata)?t.metadata:{}}}function zM(e){return e.type===`dismiss`||e.type===`clear`?!0:e.type!==`submit`&&e.type!==`skip`?!1:e.component===`canvas.question`||e.component===`canvas.input`||e.component===`canvas.calendar`}function BM(e){return!XM(e)||!Array.isArray(e.content)?``:e.content.map(e=>XM(e)&&e.type===`text`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
160
- `).trim()}function VM(e,t){let n=XM(t.structuredContent)?t.structuredContent:void 0,r=QM(t.content),i=typeof n?.state==`string`?n.state:`updated`,a=typeof n?.summary==`string`?n.summary:r,o=[`Magic Canvas state update for ${e.canvas_config.component} (${e.tool_call_id}).`,`State: ${i}.`];return a&&o.push(`Summary: ${a}`),n&&o.push(`Structured state: ${$M(n)}`),r&&r!==a&&o.push(r),o.join(`
161
- `)}function HM({conversationId:e,toolCallId:t,args:n,canvasConfig:r}){let i=KM(n);return{id:t,conversation_id:e,tool_call_id:t,arguments:i.componentArguments,canvas_config:r,layout:MM({preferred_slot:i.preferredSlot??r.layout?.preferred_slot??qM(r.component),display_mode:i.displayMode??`inline`,avoid_safe_area:i.avoidSafeArea??r.layout?.avoid_safe_area??!0,safe_area:i.safeArea??r.layout?.safe_area??TM,backdrop:i.backdrop??r.layout?.backdrop??EM}),revision:0}}function UM(e,t){let n=e.layout.display_mode;return{...e.layout,display_mode:n,viable_slot:n===`fullscreen`?`full`:GM(e.layout.preferred_slot,t)}}function WM(e,t){let n=e.filter(e=>!e.avoid_safe_area||e.display_mode===`fullscreen`?!1:e.viable_slot===`safe-area-left`||e.viable_slot===`safe-area-right`),r=n.some(e=>e.viable_slot===`safe-area-left`),i=n.some(e=>e.viable_slot===`safe-area-right`);if(r&&i)return{active:!1,video_shift_x:0,backdrop:EM};let a=[...n].reverse()[0];if(!a||t.width<900)return{active:!1,video_shift_x:0,backdrop:EM};let o=Math.min(448,Math.max(0,t.width-32)),s=a.safe_area,c=s.x*t.width,l=(s.x+s.width)*t.width,u=Math.min(360,t.width*.3),d=0;return d=a.viable_slot===`safe-area-left`?fN(16+o+24-c,0,u):-fN(l-(t.width-16-o-24),0,u),{active:!0,side:a.viable_slot===`safe-area-left`?`left`:`right`,video_shift_x:Math.round(d),safe_area:s,backdrop:a.backdrop}}function GM(e,t){return e===`full`||e===`safe-area-bottom`&&t.visualViewportHeight!==void 0&&t.visualViewportHeight<t.height*.75?`full`:(e===`safe-area-left`||e===`safe-area-right`)&&t.width<768&&t.height>=t.width?`safe-area-bottom`:e}function KM(e){let t={};for(let[n,r]of Object.entries(e))n===`layout`||n===`preferred_slot`||n===`preferredSlot`||n===`display_mode`||n===`displayMode`||n===`presentation`||n===`fullscreen`||n===`avoid_safe_area`||n===`avoidSafeArea`||n===`safe_area`||n===`safeArea`||n===`backdrop`||(t[n]=r);return{componentArguments:t,preferredSlot:tN(e.layout)??tN(e.preferred_slot)??tN(e.preferredSlot),displayMode:nN(e),avoidSafeArea:rN(e),safeArea:iN(e),backdrop:aN(e)}}function qM(e){switch(e){case`canvas.alert`:return`safe-area-bottom`;case`canvas.chart`:case`canvas.image`:case`canvas.video`:return`full`;default:return wM}}function JM(e,t){let n=t?.displayScale??1;if(e.display_mode===`fullscreen`||e.viable_slot===`full`)return{maxWidth:void 0,maxHeight:void 0,displayScale:n};let r=t?.maxHeight??720;return e.viable_slot===`safe-area-bottom`?{maxWidth:720,maxHeight:r,displayScale:n}:{width:384,maxHeight:r,displayScale:n}}function YM(e,t){return`ci_${e.replace(/[^a-zA-Z0-9_-]/g,`_`)}_${t}_${globalThis.crypto?.randomUUID?.()??Math.random().toString(36).slice(2,10)}`}function XM(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ZM(e){return e instanceof Error?e:Error(String(e))}function QM(e){return Array.isArray(e)?e.map(e=>XM(e)&&e.type===`text`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
162
- `).trim():``}function $M(e){let t=JSON.stringify(e);return t?t.length<=2e3?t:`${t.slice(0,2e3)}...`:`{}`}function eN(e){if(e===void 0)return;if(!XM(e))return null;let t=tN(e),n=oN(e.safe_area??e.safeArea),r=sN(e.backdrop);return n===null||r===null?null:{...t?{preferred_slot:t}:{},...cN(e.avoid_safe_area??e.avoidSafeArea,`avoid_safe_area`),...n?{safe_area:n}:{},...r?{backdrop:r}:{}}}function tN(e){if(typeof e==`string`&&lN(e))return e;if(!XM(e))return;let t=e.preferred_slot??e.preferredSlot??e.slot;return typeof t==`string`&&lN(t)?t:void 0}function nN(e){if(e.presentation===!0||e.fullscreen===!0)return`fullscreen`;if(e.presentation===!1||e.fullscreen===!1)return`inline`;let t=e.display_mode??e.displayMode;return t===`fullscreen`||t===`inline`?t:void 0}function rN(e){let t=XM(e.layout)?e.layout:void 0,n=e.avoid_safe_area??e.avoidSafeArea??t?.avoid_safe_area??t?.avoidSafeArea;return typeof n==`boolean`?n:void 0}function iN(e){let t=XM(e.layout)?e.layout:void 0;return oN(e.safe_area??e.safeArea??t?.safe_area??t?.safeArea)??void 0}function aN(e){let t=XM(e.layout)?e.layout:void 0;return sN(e.backdrop??t?.backdrop)??void 0}function oN(e){if(e===void 0)return;if(!XM(e))return null;let t=dN(e,`x`),n=dN(e,`y`),r=dN(e,`width`),i=dN(e,`height`);return t===void 0||n===void 0||r===void 0||i===void 0||t<0||n<0||r<=0||i<=0||t+r>1.001||n+i>1.001?null:{x:fN(t,0,1),y:fN(n,0,1),width:fN(r,0,1),height:fN(i,0,1)}}function sN(e){if(e===void 0)return;if(e===`snapshot_mirror`||e===`none`)return{type:e};if(!XM(e))return null;let t=e.type;return t===`snapshot_mirror`||t===`none`?{type:t}:null}function cN(e,t){return typeof e==`boolean`?{[t]:e}:{}}function lN(e){return CM.includes(e)}function uN(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function dN(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function fN(e,t,n){return Math.min(Math.max(e,t),n)}function pN(e,t,n){let r=uN(e,t);if(r)return n(r)?r:null}function mN(e){return e.interaction_id!==void 0&&typeof e.interaction_id!=`string`||e.component!==void 0&&typeof e.component!=`string`||e.component_version!==void 0&&typeof e.component_version!=`string`||e.type!==void 0&&typeof e.type!=`string`||e.metadata!==void 0&&!XM(e.metadata)?null:e}var hN=`tavus-deployment magic-canvas/0.0.0`;function gN(e){if(!DM(e)||e.canvas_config===void 0||e.canvas_config===null)return null;let t=OM(e.canvas_config),n=e.properties.tool_call_id;if(!t)return null;if(!n)throw Error(`Received Magic Canvas tool call without tool_call_id.`);let r=kM(e.properties.arguments);if(!r.ok)throw r.error;return HM({conversationId:e.conversation_id,toolCallId:n,args:r.value,canvasConfig:t})}function _N(e){if(!DM(e))return null;if(e.canvas_config!==void 0&&e.canvas_config!==null){let t=gN(e);return t?{kind:`show`,instance:t}:null}return AM(e)}function vN(e){return{body:{interaction_id:e.interaction_id,tool_call_id:e.tool_call_id,component:e.component,component_version:e.component_version,type:e.type,value:e.value,metadata:e.metadata}}}function yN(e,t){return{theme:e.theme,displayMode:t?.display_mode??`inline`,availableDisplayModes:[`inline`,`fullscreen`],...t?{containerDimensions:JM(t),layout:{preferred_slot:t.preferred_slot,viable_slot:t.viable_slot,avoid_safe_area:t.avoid_safe_area,safe_area:t.safe_area,backdrop:t.backdrop}}:{},platform:`web`,userAgent:hN,styles:{variables:bN(e.cssVars)}}}function bN(e){return{"--border-radius-md":e[`--radius-box`]??e[`--tavus-boxes-radius`]??`0.5rem`,"--border-radius-sm":e[`--radius-field`]??e[`--tavus-field-radius`]??`0.375rem`,"--border-radius-xs":e[`--radius-selector`]??`0.25rem`,"--border-radius-lg":e[`--radius-box`]??e[`--tavus-boxes-radius`]??`0.75rem`,"--border-width-regular":e[`--border`]??e[`--tavus-border-width`]??`1px`,"--font-text-sm-size":`0.875rem`,"--font-text-md-size":`1rem`,...xN(e)}}function xN(e){let t=e[`--color-base-content`],n=e[`--color-base-100`],r=e[`--color-base-200`],i=e[`--color-base-300`],a=e[`--color-error`],o={},s=(e,t)=>{t&&(o[e]=t)},c=(e,t,n)=>e&&n?`color-mix(in oklch, ${e} ${t}%, ${n})`:void 0;return s(`--color-background-primary`,n),s(`--color-background-secondary`,r),s(`--color-border-secondary`,i),s(`--color-border-primary`,c(t,28,n)),s(`--color-text-primary`,t),s(`--color-text-secondary`,c(t,62,n)),s(`--color-text-danger`,a),s(`--color-border-danger`,a),o}var SN=1e3,CN=5e3,wN=1200,TN=48,EN=`allow-scripts`,DN={"canvas.scheduling_embed":`allow-scripts allow-same-origin allow-popups allow-forms`};function ON(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 kN=class{onmessage;onerror;onclose;#e;#t;constructor(e){this.#e=e}start(){let e=e=>{ON(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 AN(e){for(let t of CM)if(e.some(e=>GN(e)===t))return t;return null}function jN({onLayoutEffectChange:e,onRenderedSlotChange:t,debugEnabled:n=KN()}={}){let{client:r}=K_(),{dataTheme:i,cssVars:a}=cM(),o=oh(),s=Mg(),[c,l]=E([]),[u,d]=BN(),[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]),Wg({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=_N(e.data);if(!t)return;l(e=>IM(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:YN(e).message})}},[s,m])});let _=c.map(e=>({instance:e,layout:UM(e,d)})),v=WM(_.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=AN(_.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&&CM.map(e=>{let t=_.filter(({layout:t})=>GN(t)===e);return t.length===0?null:j(NN,{slot:e,safeAreaTop:v.safe_area?.y,frameWidth:d.width,children:e=>t.map(({instance:t,layout:n})=>j(PN,{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(uM,{state:f})})]})}var MN=16;function NN({slot:e,safeAreaTop:t,frameWidth:n,children:r}){let[i,a]=VN(),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-MN*2):void 0;return j(`div`,{ref:i,class:WN(e),style:{top:r,bottom:`${UN}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:WN(e),"data-canvas-slot":e,children:o})}function PN({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(320);D(()=>{h.current=r},[r]),D(()=>{p.current=x,d.current?.setHostContext(RN(h.current,m.current,g.current,f.current,x))},[x]),D(()=>{f.current=e;let t=LN(n,u.current);m.current=t,d.current?.setHostContext(RN(h.current,t,g.current,e,p.current))},[e,n]),D(()=>{g.current=i,d.current?.setHostContext(RN(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:YN(e).message})},C=()=>{if(n||!a)return;let e=h.current,t=VM(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 oM(null,{name:`tavus-deployment`,version:`0.0.0`},{logging:{},message:{text:{},structuredContent:{}},updateModelContext:{text:{},structuredContent:{}}},{hostContext:RN(r,LN(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,TN),720))},u.onmessage=async e=>{let r=LM(e),i=BM(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=RM(e,r),s=vN(a),l=new AbortController,u=globalThis.setTimeout(()=>l.abort(),CN);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}),zM(a)&&(a.type===`submit`?(c&&clearTimeout(c),c=setTimeout(()=>{c=null,n||v.current()},wN)):v.current())}catch(e){let t=YN(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()},SN),{}),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(RN(h.current,m.current,g.current,f.current,p.current)),{mode:t}},u.connect(new kN(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&&lM(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:YN(e).message})})))},[r.arguments,r.revision,o]);let C=i.viable_slot===`full`||i.display_mode===`fullscreen`,w=C?null:zN(x,e),ee=w?.placeholderStyle,T=w?.cardStyle,te=C?{height:`100%`}:w?.iframeStyle??{height:`${x}px`},ne=[`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(` `),re=DN[r.canvas_config.component]??EN,ie=j(`div`,{class:ne,style:T,"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:re,style:te})});return C?ie:j(`div`,{class:`block w-full`,style:ee,children:ie})}var FN=[`--color-base-100`,`--color-base-200`,`--color-base-300`,`--color-base-content`,`--color-primary`,`--color-error`];function IN(e){if(!e||typeof getComputedStyle!=`function`)return{};let t=getComputedStyle(e),n={};for(let e of FN){let r=t.getPropertyValue(e).trim();r&&(n[e]=r)}return n}function LN(e,t){let n=IN(t);return Object.keys(n).length===0?e:{...e,cssVars:{...e.cssVars,...n}}}function RN(e,t,n,r,i){let a=yN(t,n),o=n.viable_slot===`full`||n.display_mode===`fullscreen`,s=o?void 0:qN(r),c=o?1:zN(i??0,r)?.displayScale??1;return{...e.canvas_config.host_context,...a,containerDimensions:{...JN(a.containerDimensions)?a.containerDimensions:{},...s===void 0?{}:{maxHeight:s},displayScale:c}}}function zN(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 r>=.85?{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`}}:{displayScale:1,placeholderStyle:{maxHeight:`${t}px`},cardStyle:void 0,iframeStyle:{width:`100%`,height:`${t}px`}}}function BN(){let e=O(null),[t,n]=E(()=>HN(null));return D(()=>{let t=()=>n(t=>{let n=HN(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 VN(){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 HN(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 UN=72;function WN(e){let t=`absolute flex gap-2`;switch(e){case`safe-area-left`:return`${t} left-4 w-[28rem] flex-col overflow-y-auto`;case`safe-area-right`:return`${t} right-4 w-[28rem] flex-col overflow-y-auto`;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 GN(e){return e.display_mode===`fullscreen`&&e.preferred_slot!==`full`?e.preferred_slot:e.viable_slot}function KN(){return!1}function qN(e){return e===void 0||!Number.isFinite(e)||e<=0?720:Math.min(Math.floor(e),720)}function JN(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function YN(e){return e instanceof Error?e:Error(String(e))}var XN=24,ZN=96;function QN(e=document){let t=Array.from(e.querySelectorAll(`[data-canvas-card]`)).map(e=>e.getBoundingClientRect());return t.length===0?null:{left:Math.min(...t.map(e=>e.left)),right:Math.max(...t.map(e=>e.right)),top:Math.min(...t.map(e=>e.top)),bottom:Math.max(...t.map(e=>e.bottom))}}function $N(e){let t=e?.getRootNode();return t instanceof ShadowRoot?t:document}function eP(e){if(!e)return null;let t=e.getBoundingClientRect();return t.width<=0||t.height<=0?null:{left:t.left,right:t.right,top:t.top,bottom:t.bottom}}function tP(e,t,n,r){if(!t)return!1;let i=r?r.left:0,a=r?r.top:0,o=r?r.right-r.left:globalThis.innerWidth,s=r?r.bottom-r.top:globalThis.innerHeight,c=e?.safe_area??TM,l=i+c.x*o+n,u=i+(c.x+c.width)*o+n,d=a+c.y*s,f=a+(c.y+c.height)*s;return l<t.right&&u>t.left&&d<t.bottom&&f>t.top}function nP(e,t,n){let[r,i]=E(()=>e?QN($N(n?.current)):null);return ut(()=>{if(!e){i(null);return}let t=$N(n?.current),r=()=>i(QN(t)),a=new ResizeObserver(r),o=()=>{for(let e of t.querySelectorAll(`[data-canvas-card]`))a.observe(e)};r(),o(),a.observe(document.documentElement);let s=globalThis.requestAnimationFrame(()=>{r(),o()});return globalThis.addEventListener(`resize`,r),()=>{a.disconnect(),globalThis.removeEventListener(`resize`,r),globalThis.cancelAnimationFrame(s)}},[e,t,n]),e?r:null}function rP(e,t,n){let[r,i]=E(()=>t?eP(e.current):null);return ut(()=>{if(!t){i(null);return}let n=()=>i(eP(e.current)),r=new ResizeObserver(n);n(),e.current&&r.observe(e.current),r.observe(document.documentElement);let a=globalThis.requestAnimationFrame(n);return globalThis.addEventListener(`resize`,n),()=>{r.disconnect(),globalThis.removeEventListener(`resize`,n),globalThis.cancelAnimationFrame(a)}},[t,n,e]),t?r:null}function iP(e,t,n,r,i,a){let o=e?.side??(n===`safe-area-left`?`left`:n===`safe-area-right`?`right`:null);return{usePip:o!=null&&(t===`pip`||t===`auto`&&tP(e,r,i,a)),side:o}}function aP(e,t=document,n){let r=n?n.left:0,i=n?n.right:globalThis.innerWidth,a=n?n.top:0,o=n?n.bottom:globalThis.innerHeight,s=i-r,c=o-a,l=Array.from(t.querySelectorAll(`[data-canvas-card]`)).map(e=>e.getBoundingClientRect()),u,d,f,p;if(l.length>0){let t=Math.min(...l.map(e=>e.left)),n=Math.max(...l.map(e=>e.right));f=Math.min(...l.map(e=>e.top)),p=Math.max(...l.map(e=>e.bottom)),[u,d]=e===`right`?[r,t]:[n,i]}else{let t=Math.min(448,Math.max(0,s-32));[u,d]=e===`right`?[r,i-16-t]:[r+16+t,i],f=a,p=o}let m=d-u>=144&&p-f>=ZN&&u>=r&&d<=i;if(l.length>0&&!m){let t=Math.min(448,Math.max(0,s-32));[u,d]=e===`right`?[r,i-16-t]:[r+16+t,i],f=a,p=o}let h=Math.max(0,d-u-XN*2),g=Math.max(ZN,Math.min(h,c-XN*2));return{centerX:(u+d)/2-r,centerY:(f+p)/2-a,diameter:g}}var oP=`560ms linear(0, 0, .0001, .0002, .0003, .0005, .0007, .001, .0013, .0016, .002, .0024, .0029, .0033, .0039, .0044, .005, .0057, .0063, .007, .0079, .0086, .0094, .0103, .0112, .0121, .0132 1.84%, .0153, .0175, .0201, .0226, .0253, .0283, .0313, .0345, .038, .0416, .0454, .0493, .0535, .0576, .0621, .0667, .0714, .0764, .0816 5.04%, .0897, .098 5.62%, .1071, .1165, .1263 6.56%, .137, .1481 7.25%, .1601 7.62%, .1706 7.94%, .1819 8.28%, .194, .2068 9.02%, .2331 9.79%, .2898 11.44%, .3151 12.18%, .3412 12.95%, .3533, .365 13.66%, .3786, .3918, .4045, .4167, .4288, .4405, .452, .4631 16.72%, .4759, .4884, .5005, .5124, .5242, .5354, .5467, .5576, .5686, .5791, .5894, .5995, .6094, .6194, .6289, .6385, .6477, .6569, .6659 24.45%, .6702, .6747, .6789, .6833, .6877, .6919, .696, .7002, .7043, .7084, .7125, .7165, .7205, .7244, .7283, .7321, .7358, .7396, .7433, .7471, .7507, .7544, .7579, .7615, .7649, .7685, .7718, .7752, .7786, .782, .7853, .7885, .7918, .7951, .7982, .8013, .8043, .8075, .8104, .8135, .8165, .8195, .8224, .8253, .8281, .8309, .8336, .8365, .8391, .8419, .8446, .8472, .8499, .8524, .855, .8575, .8599, .8625 37.27%, .8651, .8678, .8703, .8729, .8754, .8779, .8803, .8827, .8851, .8875, .8898, .892, .8942, .8965, .8987, .9009, .903, .9051, .9071, .9092, .9112, .9132, .9151, .9171, .919, .9209, .9227, .9245, .9262, .928, .9297, .9314, .9331, .9347, .9364, .9379, .9395, .941, .9425, .944, .9454, .9469, .9483, .9497, .951, .9524, .9537, .955, .9562, .9574, .9586, .9599, .961, .9622, .9633, .9644, .9655, .9665, .9676, .9686, .9696, .9705, .9715, .9724, .9733, .9742, .975, .9758, .9766, .9774, .9782, .9789, .9796, .9804, .9811, .9817, .9824, .9831, .9837, .9843, .9849, .9855, .986, .9866, .9871, .9877, .9882, .9887, .9892, .9896 70.56%, .9905 71.67%, .9914 72.82%, .9922, .9929 75.2%, .9936 76.43%, .9942 77.71%, .9948 79.03%, .9954 80.39%, .9959 81.81%, .9963 83.28%, .9968 84.82%, .9972 86.41%, .9975 88.07%, .9979 89.81%, .9982 91.64%, .9984 93.56%, .9987 95.58%, .9989 97.72%, .9991)`;function sP(e,t){let n=Math.abs(t)/2;return e===`left`?`${n}px center`:`calc(100% - ${n}px) center`}function cP(e,t,n){let[r,i]=E(()=>e&&t?aP(t,$N(n?.current),eP(n?.current)):null);return ut(()=>{if(!e||!t){i(null);return}let r=$N(n?.current),a=()=>i(aP(t,r,eP(n?.current))),o=new ResizeObserver(a),s=()=>{for(let e of r.querySelectorAll(`[data-canvas-card]`))o.observe(e)};a(),s(),n?.current&&o.observe(n.current),o.observe(document.documentElement);let c=globalThis.requestAnimationFrame(()=>{a(),s()});return globalThis.addEventListener(`resize`,a),()=>{o.disconnect(),globalThis.removeEventListener(`resize`,a),globalThis.cancelAnimationFrame(c)}},[e,t,n]),e&&t?r:null}function lP(e,t){let[n,r]=E(null);return ut(()=>{if(!t){r(null);return}let n=e.current;if(!n)return;let i=()=>{let e=n.clientWidth,t=n.clientHeight;r(e&&t?{width:e,height:t}:null)},a=new ResizeObserver(i);return a.observe(n),i(),()=>a.disconnect()},[t,e]),t?n:null}var uP=1;function dP(e,t,n){return Math.min(Math.max(e,t),n)}function fP(e,t,n,r){let i=Math.min(e.diameter/t.height,1),a=r?.safe_area??TM,o=((a.x+a.width/2)*t.width+n)*i,s=(a.y+a.height/2)*t.height*i,c=e.diameter/2;return{scale:i,tx:dP(e.centerX-o,e.centerX+c-t.width*i,e.centerX-c),ty:dP(e.centerY-s,e.centerY+c-t.height*i,e.centerY-c)}}var pP=[`cx`,`cy`,`r`,`tx`,`ty`,`s`,`shift`];function mP(e,t,n,r,i){if(!n)return null;let{width:a,height:o}=n,s={x:a/2,y:o/2},c=null;if(e&&(c=fP(e,n,r,i),s={x:(e.centerX-c.tx)/c.scale,y:(e.centerY-c.ty)/c.scale}),t&&c&&e)return{cx:s.x,cy:s.y,r:e.diameter/2/c.scale,tx:c.tx,ty:c.ty,s:c.scale,shift:r};let l=Math.hypot(Math.max(s.x,a-s.x),Math.max(s.y,o-s.y));return{cx:s.x,cy:s.y,r:l*1.1,tx:0,ty:0,s:1,shift:r}}function hP(e,t,n){let r=O(null),i=O(e),a=O(n),o=O(0),s=O(0);i.current=e,a.current=n,D(()=>{let e=i.current;if(!e)return;if(!r.current||gP()){r.current={values:{...e},velocity:{cx:0,cy:0,r:0,tx:0,ty:0,s:0,shift:0}},a.current(e,!0);return}if(o.current)return;let n=Math.max(t,160)/4e3;s.current=performance.now();let c=e=>{o.current=0;let t=i.current,l=r.current;if(!t||!l)return;let u=Math.min((e-s.current)/1e3,1/30);s.current=e;let d=!0;for(let e of pP){let r=(t[e]-l.values[e])/(n*n)-2/n*l.velocity[e],i=l.velocity[e]+r*u,a=l.values[e]+i*u,o=e===`s`?.001:.25;Math.abs(t[e]-a)<o&&Math.abs(i)*n<o?(l.values[e]=t[e],l.velocity[e]=0):(l.values[e]=a,l.velocity[e]=i,d=!1)}a.current(l.values,d),d||(o.current=globalThis.requestAnimationFrame(c))};o.current=globalThis.requestAnimationFrame(c)},[e?pP.map(t=>Math.round(e[t]*100)).join():``,t]),D(()=>()=>{o.current&&globalThis.cancelAnimationFrame(o.current)},[])}function gP(){return globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1}function _P({geom:e,visible:t}){return j(`div`,{"aria-hidden":`true`,"data-morph":`ring`,class:`pointer-events-none absolute z-10 rounded-full`,style:{top:`${e.centerY-e.diameter/2}px`,left:`${e.centerX-e.diameter/2}px`,width:`${e.diameter}px`,height:`${e.diameter}px`,boxShadow:`0 0 0 3px rgb(255 255 255 / 12%), 0 18px 50px rgb(0 0 0 / 55%)`,opacity:+!!t,transition:`opacity 240ms ease-out`}})}function vP(e,t){let n=t>=0?`left`:`right`,r=O({side:n,shift:t});D(()=>{e&&(r.current={side:n,shift:t})},[e,n,t]);let i=e?n:r.current.side;return{side:i,transformOrigin:sP(i,e?t:r.current.shift),translateX:e?0:-r.current.shift}}function yP(e,t,n){return`${e.side??``}:${e.active}:${t}:${n??``}`}function bP({snapshotUrl:e,transformOrigin:t}){return j(`div`,{class:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url("${e}")`,transform:`scaleX(-1)`,transformOrigin:t}})}function xP({snapshotUrl:e,translateX:t,transition:n,transformOrigin:r}){return j(`div`,{"aria-hidden":`true`,"data-morph":`mirror`,class:`pointer-events-none absolute z-0 overflow-hidden`,style:{inset:`0 0`,transform:`translate3d(${t}px, 0, 0)`,transition:`transform ${n}`,willChange:`transform`},children:j(bP,{snapshotUrl:e,transformOrigin:r})})}function SP({ambient:e,usePip:t,transition:n}){return e===`none`?null:j(`div`,{"aria-hidden":`true`,"data-morph":`ambient`,class:`pointer-events-none absolute inset-0 z-0`,style:{opacity:+!!t,transition:`opacity ${n}`,background:e===`darker`?`rgb(0 0 0 / 40%)`:`rgb(0 0 0 / 15%)`}})}function CP({morphCapable:e,snapshotUrl:t,mirrorSide:n,videoShiftX:r,transition:i,sceneRef:a,videoWrapRef:o,fill:s,videoRef:c}){return j(`div`,{ref:a,"data-morph":`scene`,class:`absolute inset-0`,style:e?{transformOrigin:`top left`}:void 0,children:j(`div`,{ref:o,class:`absolute inset-0`,style:e?void 0:{transform:`translate3d(${r}px, 0, 0)`,transition:`transform ${i}`},children:[s(c),e&&t!==null&&j(`div`,{"aria-hidden":`true`,"data-morph":`window-mirror`,class:`absolute top-0 bottom-0 w-full`,style:n===`right`?{left:`calc(100% - ${uP}px)`}:{right:`calc(100% - ${uP}px)`},children:j(bP,{snapshotUrl:t,transformOrigin:`center`})})]})})}function wP({canvasLayoutEffect:e,smartSidecarActive:t,isScreenSharing:n,fill:r,captureSnapshot:i,transition:a=oP,transitionMs:o=560,personaMode:s=`shift`,renderedSlot:c=null,ambient:l=`default`,children:u}){let d=O(null),[f,p]=E(null),m=t&&e.backdrop.type===`snapshot_mirror`,h=t?e.video_shift_x:0,g=O(null),_=yP(e,h,c),{usePip:v,side:y}=iP(e,s,c,nP(s!==`shift`,_,g),h,rP(g,s!==`shift`,_)),b=cP(s!==`shift`,y,g),x=vP(m,h);D(()=>{if(!m)return;let e=!1,t=0,n,r=0,a=()=>{if(e)return;let t=i(d.current);if(t){p(t);return}r+=1,r<8&&(n=globalThis.setTimeout(a,150))};return typeof globalThis.requestAnimationFrame==`function`?t=globalThis.requestAnimationFrame(a):n=globalThis.setTimeout(a,0),()=>{e=!0,t&&globalThis.cancelAnimationFrame?.(t),n&&globalThis.clearTimeout(n)}},[m,e.side,e.video_shift_x,i]),D(()=>{if(m||f===null)return;let e=globalThis.setTimeout(()=>{p(null)},o);return()=>globalThis.clearTimeout(e)},[m,f,o]);let S=v&&y!=null&&b!=null,C=s!==`shift`,w=lP(g,C),ee=f!==null&&!C,T=C&&y!=null,te=O(null),ne=O(null),[re,ie]=E(!0),ae=O(!0),oe=A((e,t)=>{let n=te.current;n&&(n.style.clipPath=`circle(${e.r}px at ${e.cx}px ${e.cy}px)`,n.style.transform=`translate(${e.tx}px, ${e.ty}px) scale(${e.s})`);let r=ne.current;r&&(r.style.transform=`translate3d(${e.shift}px, 0, 0)`),ae.current!==t&&(ae.current=t,ie(t))},[]);return hP(C?mP(b,S,w,h,e):null,o,oe),j(`div`,{ref:g,class:`relative w-full h-full overflow-hidden ${n?`flex items-center justify-center`:``}`,children:[ee&&f!==null&&j(xP,{snapshotUrl:f,translateX:x.translateX,transition:a,transformOrigin:x.transformOrigin}),T&&j(SP,{ambient:l,usePip:v,transition:a}),j(`div`,{"data-morph":`fg`,class:`absolute inset-0 z-10`,children:j(CP,{morphCapable:C,snapshotUrl:f,mirrorSide:x.side,videoShiftX:h,transition:a,sceneRef:te,videoWrapRef:ne,fill:r,videoRef:d})}),C&&b&&j(_P,{geom:b,visible:S&&re}),u]})}var TP=1e4;function EP({onTimeout:e,timeoutMs:t=TP,active:n=!0}){let r=fx().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 DP(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.message_type===`system`&&t.event_type===`system.shutdown`}function OP({onShutdown:e}){let t=O(e);D(()=>{t.current=e},[e]),Wg({onAppMessage:A(e=>{DP(e?.data)&&t.current()},[])})}function kP(){let e=oh();return{joinCall:A(({url:t,micOnly:n=!1})=>{e?.join(n?{url:t,videoSource:!1}:{url:t})},[e]),leaveCall:A(()=>{e?.leave()},[e])}}var AP=vn(`PiP`),jP=360,MP=280;function NP(){return globalThis.window!==void 0&&`documentPictureInPicture`in globalThis.window}function PP(e){let{enabled:t,active:n}=e,[r,i]=E(null),a=NP(),o=ft(hv),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:jP,height:MP}),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){AP.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){AP.warn(`mediaSession metadata setup failed`,e)}let t=(t,n)=>{try{e.setActionHandler(t,n),r.push(t)}catch(e){AP.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 FP=Ut(null),IP={active:!1,video_shift_x:0,backdrop:{type:`snapshot_mirror`}},LP=ba(({id:e,showAudioWave:t=!0})=>{let n=r_(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(rg,{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})})]})}),RP=ba(()=>{let e=Uh(),{isScreenSharing:t}=_b(),n=fx()[0];return j(le,{children:[t&&n&&j(LP,{id:n}),e&&j(LP,{id:e,showAudioWave:!1})]})}),zP=ba(()=>j(`div`,{class:`absolute top-4 left-4 flex flex-col items-end gap-2 z-20`,children:j(RP,{})})),BP=ba(({isAudioOnly:e,canvasLayoutEffect:t,canvasRenderedSlot:n})=>{let r=Uh(),i=!t_(r??``).isOff,a=px(e),o=t_(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(lx,{sessionId:a.replicaId}),j(tg,{sessionId:a.replicaId})]}):j(wP,{canvasLayoutEffect:s?{...t,backdrop:{type:`none`}}:t,smartSidecarActive:c,isScreenSharing:i,captureSnapshot:WP,personaMode:s?`shift`:`auto`,renderedSlot:n,fill:t=>j(gx,{personaSessionId:a.replicaId,localSessionId:r,isPresenting:s,isScreenSharing:i,isAudioOnly:e,avatarOff:a.videoState.isOff,videoRef:t}),children:j(tg,{sessionId:a.replicaId})})}),VP=ba(({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(Wy,{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})]})}),HP=ba(({items:e})=>e.length<=1?j(le,{children:e}):j(VP,{items:e})),UP=ba(({onLeave:e})=>{let{joinCall:t,leaveCall:n}=kP(),r=Mg(),{config:i}=K_(),{session:a,end:o}=Kb(),s=Uh(),c=O(null),l=ft(Iv)?.frameRef??c,[u,d]=E(!1),[f,p]=E(!1),[m,h]=E(IP),[g,_]=E(null),v=a.value?.conversationUrl,y=i.value.customization.conversation,b=y.modality===`audio`,x=y.enable_chat,S=y.enable_closed_captions,C=y.enable_picture_in_picture,{pipWindow:w}=PP({enabled:C,active:r===`joined-meeting`});D(()=>(v&&t({url:v,micOnly:!s}),()=>{n()}),[]);let{camera:ee,requestCamera:T}=Sb(),{isCamMuted:te}=hb(),ne=ee.isGranted&&!te;D(()=>{!b&&r===`joined-meeting`&&(FP.value=ne)},[b,r,ne]);let re=O(!b&&!s&&FP.value===!0);D(()=>{r===`joined-meeting`&&re.current&&(re.current=!1,T())},[r,T]),D(()=>{(r===`left-meeting`||r===`error`)&&e()},[r,e]),D(()=>{let e=()=>{let e=l.current,t=e?.getRootNode(),n=t instanceof Document||t instanceof ShadowRoot?t:null;d(!!e&&n?.fullscreenElement===e)};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let ie=A(()=>{let e=l.current;if(!e)return;let t=e.getRootNode();(t instanceof Document||t instanceof ShadowRoot?t:null)?.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()},[]);A(()=>{p(e=>!e)},[]);let ae=A(()=>{o(),n()},[o]);if(EP({active:r===`joined-meeting`,onTimeout:ae}),OP({onShutdown:ae}),!v)return null;let oe=[j(Gb,{compact:!0},`screen-share`)];return x&&oe.push(j(tx,{compact:!0},`chat`)),j(Jb,{children:j($b,{children:j(kb,{children:[j(`div`,{class:`absolute inset-0`,children:[j(`div`,{class:`relative w-full h-full z-[5]`,children:[j(BP,{isAudioOnly:b,canvasLayoutEffect:m,canvasRenderedSlot:g}),!b&&j(zP,{}),j(Zb,{}),j(jN,{debugEnabled:f,onLayoutEffectChange:h,onRenderedSlotChange:_}),j(`div`,{class:`absolute top-4 right-4 z-20`,children:j(sx,{active:u,onToggle:ie,compact:!0})})]}),j(rx,{}),j(`div`,{class:`pointer-events-none absolute bottom-6 left-0 right-0 z-20 transition-opacity transition-transform ${r===`left-meeting`?`opacity-0 translate-y-5`:`opacity-100 translate-y-0`}`,"aria-hidden":r===`left-meeting`,children:j(`div`,{class:`flex justify-center items-center gap-2 @max-mobile:gap-1 ${r===`left-meeting`?``:`pointer-events-auto`}`,children:[j(Bb,{}),!b&&j(Hb,{}),S&&j(Xb,{}),j(HP,{items:oe}),j(`button`,{type:`button`,class:`btn btn-control btn-error`,onClick:ae,"aria-label":`Leave call`,children:j(Wy,{name:`leave`,"aria-label":`Leave Call`})})]})})]}),w&&La(j(hx,{onLeave:ae}),w.document.body)]})})})});function WP(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 GP({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 KP(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...`}}function qP({message:e}){return j(`div`,{class:`relative max-w-[min(20rem,90%)]`,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`})})]})}var JP=ba(({text:e,isJoining:t=!1,onJoin:n,onCancel:r})=>{let i=oh(),{config:a}=K_(),{localSessionId:o,isCamMuted:s}=hb(),{mic:c,camera:l,requestMic:u,requestCamera:d}=Sb(),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=KP(e,c.status,h);return j(kb,{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(rg,{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(Wy,{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(qP,{message:g}),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,{}),f&&j(Hb,{})]}),j(GP,{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`})]})]})]})})}),YP=`Password required`,XP=`Enter the password to start this conversation.`,ZP=`Password`,QP=`Continue`;function $P({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??YP}),j(`p`,{class:`text-sm text-base-content/70`,children:t?.description??XP}),j(`input`,{id:o,type:`password`,autocomplete:`current-password`,class:`input input-bordered w-full`,placeholder:t?.placeholder??ZP,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(GP,{class:`btn-primary`,type:`submit`,disabled:!i.trim(),loading:n,children:t?.submit??QP})]})})})}var eF=vn(`CaptchaChallenge`),tF=1;function nF(e){return typeof e==`object`&&!!e&&e.source===`tavus-captcha`&&typeof e.type==`string`}function rF({captcha:e,deploymentId:t,onToken:n,onFallback:r}){let i=(ft(Ct).baseUrl??`https://tavusapi.com`).replace(/\/+$/,``).split(`/`).slice(0,3).join(`/`),[a,o]=E(0),[s,c]=E(0),[l,u]=E(!1),[d,f]=E(!1),p=`${i}${e.challenge_path}?deployment_uuid=${encodeURIComponent(t)}&action=${encodeURIComponent(e.action)}&parent_origin=${encodeURIComponent(window.location.origin)}`,m=A(()=>{f(!1),o(e=>e+1)},[]);return D(()=>{function e(e){if(l||e.origin!==i)return;let a=e.data;if(nF(a)&&a.deployment_uuid===t){if(a.type===`interactive`){f(!0);return}if(a.type===`token`&&a.token){eF.info(`Captcha token received`),f(!1),n(a.token);return}if(a.type===`expired`){eF.info(`Captcha token expired, reloading iframe`),m();return}a.type===`error`&&(eF.warn(`Captcha error received`,a.code),s<tF?(c(e=>e+1),m()):(eF.warn(`Captcha error retries exhausted, falling back to no-token mode`),u(!0),r()))}}return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[i,t,s,l,n,r,m]),l?null:j(`div`,{class:d?`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":!d,children:j(`iframe`,{src:p,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`,title:`Security challenge`,style:{border:`none`,width:`300px`,height:`65px`},scrolling:`no`},a)})}function iF({text:e,onStart:t,isStarting:n}){let{config:r,deploymentId:i}=K_(),a=ft(L_),o=Yy(r.value),s=o.btn_title??e?.fallback_button??`Start the conversation`,c=r.value.customization.terms_content?.trim()??``,l=r.value.customization.terms_enabled===!0,u=c.length>0,d=u&&l,f=k(()=>d&&m_(i,c),[d,i,c]),p=d&&!f,m=r.value.has_password===!0,h=a?.password.value??null,g=m&&!h,_=r.value.captcha??null,{captchaReady:v,captchaEpoch:y,handleCaptchaToken:b,handleCaptchaFallback:x}=lv(_,a),S=mt(),[C,w]=E(f),ee=_!==null&&!v,T=n||d&&!C||g||ee;return j(tb,{title:o.title,description:o.description,overlay:j(le,{children:[ee&&j(rF,{captcha:_,deploymentId:i,onToken:b,onFallback:x},y),g&&a?j($P,{onSubmit:a.setPassword}):null]}),children:[j(GP,{class:`btn-neutral rounded-box`,onClick:()=>{d&&C&&!f&&__(i,c),t()},disabled:T,loading:n,children:s}),u&&j(`div`,{class:`max-w-xs`,children:p?j(`label`,{for:S,class:`flex items-center gap-2 text-xs text-left cursor-pointer`,children:[j(`input`,{id:S,type:`checkbox`,class:`checkbox checkbox-secondary checkbox-xs mt-0.5 shrink-0`,checked:C,onChange:e=>w(e.target.checked)}),j(`span`,{class:`leading-snug`,children:c})]}):j(`p`,{class:`text-xs leading-snug text-base-content/60`,children:c})})]})}function aF({flow:e,welcomeText:t,onUnavailableCancel:n}){switch(e.state){case`idle`:return j(iF,{text:t,onStart:()=>{e.start()},isStarting:e.isStarting});case`haircheck`:return j(JP,{onJoin:()=>{e.join()},onCancel:()=>e.cancel(),isJoining:e.isStarting});case`call`:return j(UP,{onLeave:()=>e.leave()});case`ended`:return j(mb,{onRestart:()=>e.restart()});case`unavailable`:return j(ob,{cause:e.unavailableCause??`busy`,canRetry:e.canRetry,onRetry:()=>{e.start()},onCancel:n});default:{let t=e.state;throw Error(`Unreachable flow state: ${String(t)}`)}}}function oF(){let{config:e,configError:t}=K_(),n=lb(),r=sb(),i=k(()=>({fallback_button:n.start_button}),[n.start_button]),a=e.value.is_available,o=e.value.unavailable_reason;return j(Lv,{children:t.value?j(ob,{cause:`error`,canRetry:!1,onRetry:()=>{}}):a===!1?j(ob,{cause:o??`daily_limit`,canRetry:!1,onRetry:()=>{}}):j(aF,{flow:r,welcomeText:i})})}var sF=`:host {
159
+ 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:vD().optional().describe(`Whether the device supports touch input.`),hover:vD().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:nM.describe(`Partial context update containing only changed fields.`)});var rM=Z({method:$(`ui/update-model-context`),params:Z({content:X(AA).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:ED(J(),xD().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),iM=Z({method:$(`ui/initialize`),params:Z({appInfo:bk.describe(`App identification (name and version).`),appCapabilities:Xj.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:bk.describe(`Host application identification and version.`),hostCapabilities:Yj.describe(`Features and capabilities provided by the host.`),hostContext:nM.describe(`Rich context about the host environment.`)}).passthrough();var aM=[Fj],oM=class extends Pj{_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:Uj,sandboxready:Bj,initialized:Zj,requestteardown:Jj,loggingmessage:qA};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(iM,e=>this._oninitialize(e)),this.setRequestHandler(Ak,(e,t)=>(this.onping?.(e.params,t),{})),this.replaceRequestHandler(Qj,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(tM,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(zj,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(eM,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(Qj,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(rM,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(VA,async(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}set oncreatesamplingmessage(e){this.setRequestHandler(tj,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(rA,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(aA,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(lA,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(bA,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:aM.includes(t)?t:Fj,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];sM(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},Kj,t)}sendResourceTeardown=this.teardownResource;callTool(e,t){return this.request({method:`tools/call`,params:e},zA,t)}listTools(e,t){return this.request({method:`tools/list`,params:e},RA,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},zA,{signal:t.signal}),e.tools.listChanged&&this._client.setNotificationHandler(HA,e=>this.sendToolListChanged(e.params))),e.resources&&(this.onlistresources=async(e,t)=>this._client.request({method:`resources/list`,params:e},iA,{signal:t.signal}),this.onlistresourcetemplates=async(e,t)=>this._client.request({method:`resources/templates/list`,params:e},oA,{signal:t.signal}),this.onreadresource=async(e,t)=>this._client.request({method:`resources/read`,params:e},uA,{signal:t.signal}),e.resources.listChanged&&this._client.setNotificationHandler(dA,e=>this.sendResourceListChanged(e.params))),e.prompts&&(this.onlistprompts=async(e,t)=>this._client.request({method:`prompts/list`,params:e},xA,{signal:t.signal}),e.prompts.listChanged&&this._client.setNotificationHandler(NA,e=>this.sendPromptListChanged(e.params)))}return super.connect(e)}};function sM(e,t){return JSON.stringify(e)===JSON.stringify(t)}function cM(){let e=ft(hv);if(!e)throw Error(`useTheme must be used within ThemeProvider`);return e}var lM=new Set([`mcp-ui.tavus.io`,`mcp-ui.tavus-preview.io`]),uM=[`.sandbox-tavus.io`],dM=new Set([`tavusapi.com`]);function fM(e){let t;try{t=new URL(e)}catch{return!1}return hM(t)?!0:t.protocol===`https:`?lM.has(t.hostname)?!0:uM.some(e=>t.hostname.endsWith(e)):!1}function pM(e){return fM(e)}function mM(e){let t;try{t=new URL(e)}catch{return!1}return gM(t)?!0:t.protocol===`https:`&&dM.has(t.hostname)}function hM(e){return gM(e)}function gM(e){return!_M()||e.protocol!==`http:`&&e.protocol!==`https:`?!1:[`localhost`,`127.0.0.1`,`::1`,`[::1]`].includes(e.hostname)}function _M(){try{let e=globalThis.location?.hostname;return typeof e==`string`&&[`localhost`,`127.0.0.1`,`::1`,`[::1]`].includes(e)}catch{return!1}}async function vM(e){try{await e.teardownResource({},{timeout:1e3})}catch{}try{await e.close?.()}catch{}}var yM=`tavus.canvas.interaction`,bM=[`safe-area-right`,`safe-area-left`,`safe-area-bottom`,`full`],xM=`safe-area-right`,SM={x:275/1280,y:111/720,width:730/1280,height:609/720},CM={type:`snapshot_mirror`};function wM(e){return KM(e)?e.message_type===`conversation`&&e.event_type===`conversation.tool_call`&&typeof e.conversation_id==`string`&&KM(e.properties):!1}function TM(e){if(!KM(e))return null;let t=oN(e,`component`),n=oN(e,`component_version`),r=oN(e,`sandbox_url`),i=lN(e,`mcp_server_url`,pM),a=lN(e,`api_base_url`,mM),o=lN(e,`interaction_url`,mM),s=XM(e.layout),c=e.version;return c!==1||!t||!n||!r||!fM(r)||i===null||a===null||o===null||s===null?null:{version:c,component:t,component_version:n,resource_uri:oN(e,`resource_uri`),sandbox_url:r,mcp_server_url:i,mcp_tool_name:oN(e,`mcp_tool_name`),api_base_url:a,interaction_url:o,layout:s,host_context:KM(e.host_context)?e.host_context:void 0}}function EM(e){if(e===void 0)return{ok:!0,value:{}};if(KM(e))return{ok:!0,value:e};if(typeof e!=`string`)return{ok:!1,error:Error(`Magic Canvas tool arguments must be an object or JSON string.`)};try{let t=JSON.parse(e);return KM(t)?{ok:!0,value:t}:{ok:!1,error:Error(`Magic Canvas tool arguments must decode to an object.`)}}catch(e){return{ok:!1,error:qM(e)}}}function DM(e){let t=e.properties.name;if(t!==`canvas_clear`&&t!==`update_component`)return null;let n=EM(e.properties.arguments);if(!n.ok)throw n.error;if(t===`canvas_clear`){let t=n.value.tool_call_id,r=n.value.reason;if(t!==void 0&&typeof t!=`string`)throw Error(`Magic Canvas clear tool_call_id must be a string when provided.`);if(r!==void 0&&typeof r!=`string`)throw Error(`Magic Canvas clear reason must be a string when provided.`);return{kind:`clear`,conversation_id:e.conversation_id,tool_call_id:t,reason:r}}let r=n.value.tool_call_id,i=n.value.updates;if(typeof r!=`string`||r.length===0)throw Error(`Magic Canvas update_component requires a target tool_call_id.`);if(!KM(i))throw Error(`Magic Canvas update_component requires an object updates payload.`);return{kind:`update`,conversation_id:e.conversation_id,tool_call_id:r,updates:i}}var OM=[`safe-area-left`,`safe-area-right`];function kM(e){let t=OM.includes(e.preferred_slot)?e.preferred_slot:xM;return t===e.preferred_slot&&e.display_mode===`inline`?e:{...e,preferred_slot:t,display_mode:`inline`}}function AM(e){return e.display_mode===`fullscreen`?`full`:e.preferred_slot}function jM(e,t){return[t]}function MM(e,t){switch(t.kind){case`show`:{let n=e.find(e=>e.id===t.instance.id),r=n?{...t.instance,revision:n.revision+1}:t.instance;return jM(e.filter(e=>e.id!==t.instance.id),r)}case`update`:{let n=e=>e.conversation_id===t.conversation_id&&e.tool_call_id===t.tool_call_id,r=HM(t.updates),i,a=e.map(e=>{if(!n(e))return e;let t={...e,arguments:{...e.arguments,...r.componentArguments},layout:kM({preferred_slot:r.preferredSlot??e.layout.preferred_slot,display_mode:r.displayMode??e.layout.display_mode,avoid_safe_area:r.avoidSafeArea??e.layout.avoid_safe_area,safe_area:r.safeArea??e.layout.safe_area,backdrop:r.backdrop??e.layout.backdrop}),revision:e.revision+1};return i=t,t});if(i===void 0)return a;let o=e.find(n);return o&&AM(o.layout)===AM(i.layout)?a:jM(a.filter(e=>!n(e)),i)}case`clear`:return t.tool_call_id?e.filter(e=>!(e.conversation_id===t.conversation_id&&e.tool_call_id===t.tool_call_id)):e.filter(e=>e.conversation_id!==t.conversation_id)}}function NM(e){if(!KM(e)||!Array.isArray(e.content))return null;for(let t of e.content){if(!KM(t))continue;let e=(KM(t._meta)?t._meta:null)?.[yM];if(KM(e))return uN(e)}return null}function PM(e,t){let n=t.type,r=t.value;if(!n)throw Error(`Magic Canvas interaction is missing type.`);if(r===void 0)throw Error(`Magic Canvas interaction is missing value.`);return{interaction_id:t.interaction_id??GM(e.tool_call_id,n),conversation_id:e.conversation_id,tool_call_id:e.tool_call_id,component:t.component??e.canvas_config.component,component_version:t.component_version??e.canvas_config.component_version,type:n,value:r,metadata:KM(t.metadata)?t.metadata:{}}}function FM(e){return e.type===`dismiss`||e.type===`clear`?!0:e.type!==`submit`&&e.type!==`skip`?!1:e.component===`canvas.question`||e.component===`canvas.input`||e.component===`canvas.calendar`}function IM(e){return!KM(e)||!Array.isArray(e.content)?``:e.content.map(e=>KM(e)&&e.type===`text`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
160
+ `).trim()}function LM(e,t){let n=KM(t.structuredContent)?t.structuredContent:void 0,r=JM(t.content),i=typeof n?.state==`string`?n.state:`updated`,a=typeof n?.summary==`string`?n.summary:r,o=[`Magic Canvas state update for ${e.canvas_config.component} (${e.tool_call_id}).`,`State: ${i}.`];return a&&o.push(`Summary: ${a}`),n&&o.push(`Structured state: ${YM(n)}`),r&&r!==a&&o.push(r),o.join(`
161
+ `)}function RM({conversationId:e,toolCallId:t,args:n,canvasConfig:r}){let i=HM(n);return{id:t,conversation_id:e,tool_call_id:t,arguments:i.componentArguments,canvas_config:r,layout:kM({preferred_slot:i.preferredSlot??r.layout?.preferred_slot??UM(r.component),display_mode:i.displayMode??`inline`,avoid_safe_area:i.avoidSafeArea??r.layout?.avoid_safe_area??!0,safe_area:i.safeArea??r.layout?.safe_area??SM,backdrop:i.backdrop??r.layout?.backdrop??CM}),revision:0}}function zM(e,t){let n=e.layout.display_mode;return{...e.layout,display_mode:n,viable_slot:n===`fullscreen`?`full`:VM(e.layout.preferred_slot,t)}}function BM(e,t){let n=e.filter(e=>!e.avoid_safe_area||e.display_mode===`fullscreen`?!1:e.viable_slot===`safe-area-left`||e.viable_slot===`safe-area-right`),r=n.some(e=>e.viable_slot===`safe-area-left`),i=n.some(e=>e.viable_slot===`safe-area-right`);if(r&&i)return{active:!1,video_shift_x:0,backdrop:CM};let a=[...n].reverse()[0];if(!a||t.width<900)return{active:!1,video_shift_x:0,backdrop:CM};let o=Math.min(448,Math.max(0,t.width-32)),s=a.safe_area,c=s.x*t.width,l=(s.x+s.width)*t.width,u=Math.min(360,t.width*.3),d=0;return d=a.viable_slot===`safe-area-left`?cN(16+o+24-c,0,u):-cN(l-(t.width-16-o-24),0,u),{active:!0,side:a.viable_slot===`safe-area-left`?`left`:`right`,video_shift_x:Math.round(d),safe_area:s,backdrop:a.backdrop}}function VM(e,t){return e===`full`||e===`safe-area-bottom`&&t.visualViewportHeight!==void 0&&t.visualViewportHeight<t.height*.75?`full`:(e===`safe-area-left`||e===`safe-area-right`)&&t.width<768&&t.height>=t.width?`safe-area-bottom`:e}function HM(e){let t={};for(let[n,r]of Object.entries(e))n===`layout`||n===`preferred_slot`||n===`preferredSlot`||n===`display_mode`||n===`displayMode`||n===`presentation`||n===`fullscreen`||n===`avoid_safe_area`||n===`avoidSafeArea`||n===`safe_area`||n===`safeArea`||n===`backdrop`||(t[n]=r);return{componentArguments:t,preferredSlot:ZM(e.layout)??ZM(e.preferred_slot)??ZM(e.preferredSlot),displayMode:QM(e),avoidSafeArea:$M(e),safeArea:eN(e),backdrop:tN(e)}}function UM(e){switch(e){case`canvas.alert`:return`safe-area-bottom`;case`canvas.chart`:case`canvas.image`:case`canvas.video`:return`full`;default:return xM}}function WM(e,t){let n=t?.displayScale??1;if(e.display_mode===`fullscreen`||e.viable_slot===`full`)return{maxWidth:void 0,maxHeight:void 0,displayScale:n};let r=t?.maxHeight??720;return e.viable_slot===`safe-area-bottom`?{maxWidth:720,maxHeight:r,displayScale:n}:{width:384,maxHeight:r,displayScale:n}}function GM(e,t){return`ci_${e.replace(/[^a-zA-Z0-9_-]/g,`_`)}_${t}_${globalThis.crypto?.randomUUID?.()??Math.random().toString(36).slice(2,10)}`}function KM(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function qM(e){return e instanceof Error?e:Error(String(e))}function JM(e){return Array.isArray(e)?e.map(e=>KM(e)&&e.type===`text`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
162
+ `).trim():``}function YM(e){let t=JSON.stringify(e);return t?t.length<=2e3?t:`${t.slice(0,2e3)}...`:`{}`}function XM(e){if(e===void 0)return;if(!KM(e))return null;let t=ZM(e),n=nN(e.safe_area??e.safeArea),r=rN(e.backdrop);return n===null||r===null?null:{...t?{preferred_slot:t}:{},...iN(e.avoid_safe_area??e.avoidSafeArea,`avoid_safe_area`),...n?{safe_area:n}:{},...r?{backdrop:r}:{}}}function ZM(e){if(typeof e==`string`&&aN(e))return e;if(!KM(e))return;let t=e.preferred_slot??e.preferredSlot??e.slot;return typeof t==`string`&&aN(t)?t:void 0}function QM(e){if(e.presentation===!0||e.fullscreen===!0)return`fullscreen`;if(e.presentation===!1||e.fullscreen===!1)return`inline`;let t=e.display_mode??e.displayMode;return t===`fullscreen`||t===`inline`?t:void 0}function $M(e){let t=KM(e.layout)?e.layout:void 0,n=e.avoid_safe_area??e.avoidSafeArea??t?.avoid_safe_area??t?.avoidSafeArea;return typeof n==`boolean`?n:void 0}function eN(e){let t=KM(e.layout)?e.layout:void 0;return nN(e.safe_area??e.safeArea??t?.safe_area??t?.safeArea)??void 0}function tN(e){let t=KM(e.layout)?e.layout:void 0;return rN(e.backdrop??t?.backdrop)??void 0}function nN(e){if(e===void 0)return;if(!KM(e))return null;let t=sN(e,`x`),n=sN(e,`y`),r=sN(e,`width`),i=sN(e,`height`);return t===void 0||n===void 0||r===void 0||i===void 0||t<0||n<0||r<=0||i<=0||t+r>1.001||n+i>1.001?null:{x:cN(t,0,1),y:cN(n,0,1),width:cN(r,0,1),height:cN(i,0,1)}}function rN(e){if(e===void 0)return;if(e===`snapshot_mirror`||e===`none`)return{type:e};if(!KM(e))return null;let t=e.type;return t===`snapshot_mirror`||t===`none`?{type:t}:null}function iN(e,t){return typeof e==`boolean`?{[t]:e}:{}}function aN(e){return bM.includes(e)}function oN(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function sN(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function cN(e,t,n){return Math.min(Math.max(e,t),n)}function lN(e,t,n){let r=oN(e,t);if(r)return n(r)?r:null}function uN(e){return e.interaction_id!==void 0&&typeof e.interaction_id!=`string`||e.component!==void 0&&typeof e.component!=`string`||e.component_version!==void 0&&typeof e.component_version!=`string`||e.type!==void 0&&typeof e.type!=`string`||e.metadata!==void 0&&!KM(e.metadata)?null:e}function dN({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(fN,{label:`iframe`,value:e.iframeLifecycleState}),j(fN,{label:`post`,value:e.lastInteractionPostResult}),j(fN,{label:`context`,value:e.lastModelContextUpdate}),j(fN,{label:`error`,value:e.lastError}),j(pN,{label:`tool_call`,value:e.lastToolCall}),j(pN,{label:`canvas_config`,value:e.parsedCanvasConfig})]})]}):null}function fN({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 pN({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 mN=`tavus-deployment magic-canvas/0.0.0`;function hN(e){if(!wM(e)||e.canvas_config===void 0||e.canvas_config===null)return null;let t=TM(e.canvas_config),n=e.properties.tool_call_id;if(!t)return null;if(!n)throw Error(`Received Magic Canvas tool call without tool_call_id.`);let r=EM(e.properties.arguments);if(!r.ok)throw r.error;return RM({conversationId:e.conversation_id,toolCallId:n,args:r.value,canvasConfig:t})}function gN(e){if(!wM(e))return null;if(e.canvas_config!==void 0&&e.canvas_config!==null){let t=hN(e);return t?{kind:`show`,instance:t}:null}return DM(e)}function _N(e){return{body:{interaction_id:e.interaction_id,tool_call_id:e.tool_call_id,component:e.component,component_version:e.component_version,type:e.type,value:e.value,metadata:e.metadata}}}function vN(e,t){return{theme:e.theme,displayMode:t?.display_mode??`inline`,availableDisplayModes:[`inline`,`fullscreen`],...t?{containerDimensions:WM(t),layout:{preferred_slot:t.preferred_slot,viable_slot:t.viable_slot,avoid_safe_area:t.avoid_safe_area,safe_area:t.safe_area,backdrop:t.backdrop}}:{},platform:`web`,userAgent:mN,styles:{variables:yN(e.cssVars)}}}function yN(e){return{"--border-radius-md":e[`--radius-box`]??e[`--tavus-boxes-radius`]??`0.5rem`,"--border-radius-sm":e[`--radius-field`]??e[`--tavus-field-radius`]??`0.375rem`,"--border-radius-xs":e[`--radius-selector`]??`0.25rem`,"--border-radius-lg":e[`--radius-box`]??e[`--tavus-boxes-radius`]??`0.75rem`,"--border-width-regular":e[`--border`]??e[`--tavus-border-width`]??`1px`,"--font-text-sm-size":`0.875rem`,"--font-text-md-size":`1rem`,...bN(e)}}function bN(e){let t=e[`--color-base-content`],n=e[`--color-base-100`],r=e[`--color-base-200`],i=e[`--color-base-300`],a=e[`--color-error`],o={},s=(e,t)=>{t&&(o[e]=t)},c=(e,t,n)=>e&&n?`color-mix(in oklch, ${e} ${t}%, ${n})`:void 0;return s(`--color-background-primary`,n),s(`--color-background-secondary`,r),s(`--color-border-secondary`,i),s(`--color-border-primary`,c(t,28,n)),s(`--color-text-primary`,t),s(`--color-text-secondary`,c(t,62,n)),s(`--color-text-danger`,a),s(`--color-border-danger`,a),o}var xN=1e3,SN=5e3,CN=1200,wN=48,TN=`allow-scripts`,EN={"canvas.scheduling_embed":`allow-scripts allow-same-origin allow-popups allow-forms`};function DN(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 ON=class{onmessage;onerror;onclose;#e;#t;constructor(e){this.#e=e}start(){let e=e=>{DN(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 kN(e){for(let t of bM)if(e.some(e=>WN(e)===t))return t;return null}function AN({onLayoutEffectChange:e,onRenderedSlotChange:t,debugEnabled:n=GN()}={}){let{client:r}=K_(),{dataTheme:i,cssVars:a}=cM(),o=oh(),s=Mg(),[c,l]=E([]),[u,d]=zN(),[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]),Wg({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=gN(e.data);if(!t)return;l(e=>MM(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:JN(e).message})}},[s,m])});let _=c.map(e=>({instance:e,layout:zM(e,d)})),v=BM(_.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=kN(_.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&&bM.map(e=>{let t=_.filter(({layout:t})=>WN(t)===e);return t.length===0?null:j(MN,{slot:e,safeAreaTop:v.safe_area?.y,frameWidth:d.width,children:e=>t.map(({instance:t,layout:n})=>j(NN,{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(dN,{state:f})})]})}var jN=16;function MN({slot:e,safeAreaTop:t,frameWidth:n,children:r}){let[i,a]=BN(),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-jN*2):void 0;return j(`div`,{ref:i,class:UN(e),style:{top:r,bottom:`${HN}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:UN(e),"data-canvas-slot":e,children:o})}function NN({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(320);D(()=>{h.current=r},[r]),D(()=>{p.current=x,d.current?.setHostContext(LN(h.current,m.current,g.current,f.current,x))},[x]),D(()=>{f.current=e;let t=IN(n,u.current);m.current=t,d.current?.setHostContext(LN(h.current,t,g.current,e,p.current))},[e,n]),D(()=>{g.current=i,d.current?.setHostContext(LN(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:JN(e).message})},C=()=>{if(n||!a)return;let e=h.current,t=LM(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 oM(null,{name:`tavus-deployment`,version:`0.0.0`},{logging:{},message:{text:{},structuredContent:{}},updateModelContext:{text:{},structuredContent:{}}},{hostContext:LN(r,IN(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,wN),720))},u.onmessage=async e=>{let r=NM(e),i=IM(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=PM(e,r),s=_N(a),l=new AbortController,u=globalThis.setTimeout(()=>l.abort(),SN);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}),FM(a)&&(a.type===`submit`?(c&&clearTimeout(c),c=setTimeout(()=>{c=null,n||v.current()},CN)):v.current())}catch(e){let t=JN(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()},xN),{}),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(LN(h.current,m.current,g.current,f.current,p.current)),{mode:t}},u.connect(new ON(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&&vM(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:JN(e).message})})))},[r.arguments,r.revision,o]);let C=i.viable_slot===`full`||i.display_mode===`fullscreen`,w=C?null:RN(x,e),ee=w?.placeholderStyle,T=w?.cardStyle,te=C?{height:`100%`}:w?.iframeStyle??{height:`${x}px`},ne=[`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(` `),re=EN[r.canvas_config.component]??TN,ie=j(`div`,{class:ne,style:T,"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:re,style:te})});return C?ie:j(`div`,{class:`block w-full`,style:ee,children:ie})}var PN=[`--color-base-100`,`--color-base-200`,`--color-base-300`,`--color-base-content`,`--color-primary`,`--color-error`];function FN(e){if(!e||typeof getComputedStyle!=`function`)return{};let t=getComputedStyle(e),n={};for(let e of PN){let r=t.getPropertyValue(e).trim();r&&(n[e]=r)}return n}function IN(e,t){let n=FN(t);return Object.keys(n).length===0?e:{...e,cssVars:{...e.cssVars,...n}}}function LN(e,t,n,r,i){let a=vN(t,n),o=n.viable_slot===`full`||n.display_mode===`fullscreen`,s=o?void 0:KN(r),c=o?1:RN(i??0,r)?.displayScale??1;return{...e.canvas_config.host_context,...a,containerDimensions:{...qN(a.containerDimensions)?a.containerDimensions:{},...s===void 0?{}:{maxHeight:s},displayScale:c}}}function RN(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 r>=.85?{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`}}:{displayScale:1,placeholderStyle:{maxHeight:`${t}px`},cardStyle:void 0,iframeStyle:{width:`100%`,height:`${t}px`}}}function zN(){let e=O(null),[t,n]=E(()=>VN(null));return D(()=>{let t=()=>n(t=>{let n=VN(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 BN(){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 VN(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 HN=72;function UN(e){let t=`absolute flex gap-2`;switch(e){case`safe-area-left`:return`${t} left-4 w-[28rem] flex-col overflow-y-auto`;case`safe-area-right`:return`${t} right-4 w-[28rem] flex-col overflow-y-auto`;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 WN(e){return e.display_mode===`fullscreen`&&e.preferred_slot!==`full`?e.preferred_slot:e.viable_slot}function GN(){return!1}function KN(e){return e===void 0||!Number.isFinite(e)||e<=0?720:Math.min(Math.floor(e),720)}function qN(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function JN(e){return e instanceof Error?e:Error(String(e))}var YN=24,XN=96;function ZN(e=document){let t=Array.from(e.querySelectorAll(`[data-canvas-card]`)).map(e=>e.getBoundingClientRect());return t.length===0?null:{left:Math.min(...t.map(e=>e.left)),right:Math.max(...t.map(e=>e.right)),top:Math.min(...t.map(e=>e.top)),bottom:Math.max(...t.map(e=>e.bottom))}}function QN(e){let t=e?.getRootNode();return t instanceof ShadowRoot?t:document}function $N(e){if(!e)return null;let t=e.getBoundingClientRect();return t.width<=0||t.height<=0?null:{left:t.left,right:t.right,top:t.top,bottom:t.bottom}}function eP(e,t,n,r){if(!t)return!1;let i=r?r.left:0,a=r?r.top:0,o=r?r.right-r.left:globalThis.innerWidth,s=r?r.bottom-r.top:globalThis.innerHeight,c=e?.safe_area??SM,l=i+c.x*o+n,u=i+(c.x+c.width)*o+n,d=a+c.y*s,f=a+(c.y+c.height)*s;return l<t.right&&u>t.left&&d<t.bottom&&f>t.top}function tP(e,t,n){let[r,i]=E(()=>e?ZN(QN(n?.current)):null);return ut(()=>{if(!e){i(null);return}let t=QN(n?.current),r=()=>i(ZN(t)),a=new ResizeObserver(r),o=()=>{for(let e of t.querySelectorAll(`[data-canvas-card]`))a.observe(e)};r(),o(),a.observe(document.documentElement);let s=globalThis.requestAnimationFrame(()=>{r(),o()});return globalThis.addEventListener(`resize`,r),()=>{a.disconnect(),globalThis.removeEventListener(`resize`,r),globalThis.cancelAnimationFrame(s)}},[e,t,n]),e?r:null}function nP(e,t,n){let[r,i]=E(()=>t?$N(e.current):null);return ut(()=>{if(!t){i(null);return}let n=()=>i($N(e.current)),r=new ResizeObserver(n);n(),e.current&&r.observe(e.current),r.observe(document.documentElement);let a=globalThis.requestAnimationFrame(n);return globalThis.addEventListener(`resize`,n),()=>{r.disconnect(),globalThis.removeEventListener(`resize`,n),globalThis.cancelAnimationFrame(a)}},[t,n,e]),t?r:null}function rP(e,t,n,r,i,a){let o=e?.side??(n===`safe-area-left`?`left`:n===`safe-area-right`?`right`:null);return{usePip:o!=null&&(t===`pip`||t===`auto`&&eP(e,r,i,a)),side:o}}function iP(e,t=document,n){let r=n?n.left:0,i=n?n.right:globalThis.innerWidth,a=n?n.top:0,o=n?n.bottom:globalThis.innerHeight,s=i-r,c=o-a,l=Array.from(t.querySelectorAll(`[data-canvas-card]`)).map(e=>e.getBoundingClientRect()),u,d,f,p;if(l.length>0){let t=Math.min(...l.map(e=>e.left)),n=Math.max(...l.map(e=>e.right));f=Math.min(...l.map(e=>e.top)),p=Math.max(...l.map(e=>e.bottom)),[u,d]=e===`right`?[r,t]:[n,i]}else{let t=Math.min(448,Math.max(0,s-32));[u,d]=e===`right`?[r,i-16-t]:[r+16+t,i],f=a,p=o}let m=d-u>=144&&p-f>=XN&&u>=r&&d<=i;if(l.length>0&&!m){let t=Math.min(448,Math.max(0,s-32));[u,d]=e===`right`?[r,i-16-t]:[r+16+t,i],f=a,p=o}let h=Math.max(0,d-u-YN*2),g=Math.max(XN,Math.min(h,c-YN*2));return{centerX:(u+d)/2-r,centerY:(f+p)/2-a,diameter:g}}var aP=`560ms linear(0, 0, .0001, .0002, .0003, .0005, .0007, .001, .0013, .0016, .002, .0024, .0029, .0033, .0039, .0044, .005, .0057, .0063, .007, .0079, .0086, .0094, .0103, .0112, .0121, .0132 1.84%, .0153, .0175, .0201, .0226, .0253, .0283, .0313, .0345, .038, .0416, .0454, .0493, .0535, .0576, .0621, .0667, .0714, .0764, .0816 5.04%, .0897, .098 5.62%, .1071, .1165, .1263 6.56%, .137, .1481 7.25%, .1601 7.62%, .1706 7.94%, .1819 8.28%, .194, .2068 9.02%, .2331 9.79%, .2898 11.44%, .3151 12.18%, .3412 12.95%, .3533, .365 13.66%, .3786, .3918, .4045, .4167, .4288, .4405, .452, .4631 16.72%, .4759, .4884, .5005, .5124, .5242, .5354, .5467, .5576, .5686, .5791, .5894, .5995, .6094, .6194, .6289, .6385, .6477, .6569, .6659 24.45%, .6702, .6747, .6789, .6833, .6877, .6919, .696, .7002, .7043, .7084, .7125, .7165, .7205, .7244, .7283, .7321, .7358, .7396, .7433, .7471, .7507, .7544, .7579, .7615, .7649, .7685, .7718, .7752, .7786, .782, .7853, .7885, .7918, .7951, .7982, .8013, .8043, .8075, .8104, .8135, .8165, .8195, .8224, .8253, .8281, .8309, .8336, .8365, .8391, .8419, .8446, .8472, .8499, .8524, .855, .8575, .8599, .8625 37.27%, .8651, .8678, .8703, .8729, .8754, .8779, .8803, .8827, .8851, .8875, .8898, .892, .8942, .8965, .8987, .9009, .903, .9051, .9071, .9092, .9112, .9132, .9151, .9171, .919, .9209, .9227, .9245, .9262, .928, .9297, .9314, .9331, .9347, .9364, .9379, .9395, .941, .9425, .944, .9454, .9469, .9483, .9497, .951, .9524, .9537, .955, .9562, .9574, .9586, .9599, .961, .9622, .9633, .9644, .9655, .9665, .9676, .9686, .9696, .9705, .9715, .9724, .9733, .9742, .975, .9758, .9766, .9774, .9782, .9789, .9796, .9804, .9811, .9817, .9824, .9831, .9837, .9843, .9849, .9855, .986, .9866, .9871, .9877, .9882, .9887, .9892, .9896 70.56%, .9905 71.67%, .9914 72.82%, .9922, .9929 75.2%, .9936 76.43%, .9942 77.71%, .9948 79.03%, .9954 80.39%, .9959 81.81%, .9963 83.28%, .9968 84.82%, .9972 86.41%, .9975 88.07%, .9979 89.81%, .9982 91.64%, .9984 93.56%, .9987 95.58%, .9989 97.72%, .9991)`;function oP(e,t){let n=Math.abs(t)/2;return e===`left`?`${n}px center`:`calc(100% - ${n}px) center`}function sP(e,t,n){let[r,i]=E(()=>e&&t?iP(t,QN(n?.current),$N(n?.current)):null);return ut(()=>{if(!e||!t){i(null);return}let r=QN(n?.current),a=()=>i(iP(t,r,$N(n?.current))),o=new ResizeObserver(a),s=()=>{for(let e of r.querySelectorAll(`[data-canvas-card]`))o.observe(e)};a(),s(),n?.current&&o.observe(n.current),o.observe(document.documentElement);let c=globalThis.requestAnimationFrame(()=>{a(),s()});return globalThis.addEventListener(`resize`,a),()=>{o.disconnect(),globalThis.removeEventListener(`resize`,a),globalThis.cancelAnimationFrame(c)}},[e,t,n]),e&&t?r:null}function cP(e,t){let[n,r]=E(null);return ut(()=>{if(!t){r(null);return}let n=e.current;if(!n)return;let i=()=>{let e=n.clientWidth,t=n.clientHeight;r(e&&t?{width:e,height:t}:null)},a=new ResizeObserver(i);return a.observe(n),i(),()=>a.disconnect()},[t,e]),t?n:null}var lP=1;function uP(e,t,n){return Math.min(Math.max(e,t),n)}function dP(e,t,n,r){let i=Math.min(e.diameter/t.height,1),a=r?.safe_area??SM,o=((a.x+a.width/2)*t.width+n)*i,s=(a.y+a.height/2)*t.height*i,c=e.diameter/2;return{scale:i,tx:uP(e.centerX-o,e.centerX+c-t.width*i,e.centerX-c),ty:uP(e.centerY-s,e.centerY+c-t.height*i,e.centerY-c)}}var fP=[`cx`,`cy`,`r`,`tx`,`ty`,`s`,`shift`];function pP(e,t,n,r,i){if(!n)return null;let{width:a,height:o}=n,s={x:a/2,y:o/2},c=null;if(e&&(c=dP(e,n,r,i),s={x:(e.centerX-c.tx)/c.scale,y:(e.centerY-c.ty)/c.scale}),t&&c&&e)return{cx:s.x,cy:s.y,r:e.diameter/2/c.scale,tx:c.tx,ty:c.ty,s:c.scale,shift:r};let l=Math.hypot(Math.max(s.x,a-s.x),Math.max(s.y,o-s.y));return{cx:s.x,cy:s.y,r:l*1.1,tx:0,ty:0,s:1,shift:r}}function mP(e,t,n){let r=O(null),i=O(e),a=O(n),o=O(0),s=O(0);i.current=e,a.current=n,D(()=>{let e=i.current;if(!e)return;if(!r.current||hP()){r.current={values:{...e},velocity:{cx:0,cy:0,r:0,tx:0,ty:0,s:0,shift:0}},a.current(e,!0);return}if(o.current)return;let n=Math.max(t,160)/4e3;s.current=performance.now();let c=e=>{o.current=0;let t=i.current,l=r.current;if(!t||!l)return;let u=Math.min((e-s.current)/1e3,1/30);s.current=e;let d=!0;for(let e of fP){let r=(t[e]-l.values[e])/(n*n)-2/n*l.velocity[e],i=l.velocity[e]+r*u,a=l.values[e]+i*u,o=e===`s`?.001:.25;Math.abs(t[e]-a)<o&&Math.abs(i)*n<o?(l.values[e]=t[e],l.velocity[e]=0):(l.values[e]=a,l.velocity[e]=i,d=!1)}a.current(l.values,d),d||(o.current=globalThis.requestAnimationFrame(c))};o.current=globalThis.requestAnimationFrame(c)},[e?fP.map(t=>Math.round(e[t]*100)).join():``,t]),D(()=>()=>{o.current&&globalThis.cancelAnimationFrame(o.current)},[])}function hP(){return globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1}function gP({geom:e,visible:t}){return j(`div`,{"aria-hidden":`true`,"data-morph":`ring`,class:`pointer-events-none absolute z-10 rounded-full`,style:{top:`${e.centerY-e.diameter/2}px`,left:`${e.centerX-e.diameter/2}px`,width:`${e.diameter}px`,height:`${e.diameter}px`,boxShadow:`0 0 0 3px rgb(255 255 255 / 12%), 0 18px 50px rgb(0 0 0 / 55%)`,opacity:+!!t,transition:`opacity 240ms ease-out`}})}function _P(e,t){let n=t>=0?`left`:`right`,r=O({side:n,shift:t});D(()=>{e&&(r.current={side:n,shift:t})},[e,n,t]);let i=e?n:r.current.side;return{side:i,transformOrigin:oP(i,e?t:r.current.shift),translateX:e?0:-r.current.shift}}function vP(e,t,n){return`${e.side??``}:${e.active}:${t}:${n??``}`}function yP({snapshotUrl:e,transformOrigin:t}){return j(`div`,{class:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url("${e}")`,transform:`scaleX(-1)`,transformOrigin:t}})}function bP({snapshotUrl:e,translateX:t,transition:n,transformOrigin:r}){return j(`div`,{"aria-hidden":`true`,"data-morph":`mirror`,class:`pointer-events-none absolute z-0 overflow-hidden`,style:{inset:`0 0`,transform:`translate3d(${t}px, 0, 0)`,transition:`transform ${n}`,willChange:`transform`},children:j(yP,{snapshotUrl:e,transformOrigin:r})})}function xP({ambient:e,usePip:t,transition:n}){return e===`none`?null:j(`div`,{"aria-hidden":`true`,"data-morph":`ambient`,class:`pointer-events-none absolute inset-0 z-0`,style:{opacity:+!!t,transition:`opacity ${n}`,background:e===`darker`?`rgb(0 0 0 / 40%)`:`rgb(0 0 0 / 15%)`}})}function SP({morphCapable:e,snapshotUrl:t,mirrorSide:n,videoShiftX:r,transition:i,sceneRef:a,videoWrapRef:o,fill:s,videoRef:c}){return j(`div`,{ref:a,"data-morph":`scene`,class:`absolute inset-0`,style:e?{transformOrigin:`top left`}:void 0,children:j(`div`,{ref:o,class:`absolute inset-0`,style:e?void 0:{transform:`translate3d(${r}px, 0, 0)`,transition:`transform ${i}`},children:[s(c),e&&t!==null&&j(`div`,{"aria-hidden":`true`,"data-morph":`window-mirror`,class:`absolute top-0 bottom-0 w-full`,style:n===`right`?{left:`calc(100% - ${lP}px)`}:{right:`calc(100% - ${lP}px)`},children:j(yP,{snapshotUrl:t,transformOrigin:`center`})})]})})}function CP({canvasLayoutEffect:e,smartSidecarActive:t,isScreenSharing:n,fill:r,captureSnapshot:i,transition:a=aP,transitionMs:o=560,personaMode:s=`shift`,renderedSlot:c=null,ambient:l=`default`,children:u}){let d=O(null),[f,p]=E(null),m=t&&e.backdrop.type===`snapshot_mirror`,h=t?e.video_shift_x:0,g=O(null),_=vP(e,h,c),{usePip:v,side:y}=rP(e,s,c,tP(s!==`shift`,_,g),h,nP(g,s!==`shift`,_)),b=sP(s!==`shift`,y,g),x=_P(m,h);D(()=>{if(!m)return;let e=!1,t=0,n,r=0,a=()=>{if(e)return;let t=i(d.current);if(t){p(t);return}r+=1,r<8&&(n=globalThis.setTimeout(a,150))};return typeof globalThis.requestAnimationFrame==`function`?t=globalThis.requestAnimationFrame(a):n=globalThis.setTimeout(a,0),()=>{e=!0,t&&globalThis.cancelAnimationFrame?.(t),n&&globalThis.clearTimeout(n)}},[m,e.side,e.video_shift_x,i]),D(()=>{if(m||f===null)return;let e=globalThis.setTimeout(()=>{p(null)},o);return()=>globalThis.clearTimeout(e)},[m,f,o]);let S=v&&y!=null&&b!=null,C=s!==`shift`,w=cP(g,C),ee=f!==null&&!C,T=C&&y!=null,te=O(null),ne=O(null),[re,ie]=E(!0),ae=O(!0),oe=A((e,t)=>{let n=te.current;n&&(n.style.clipPath=`circle(${e.r}px at ${e.cx}px ${e.cy}px)`,n.style.transform=`translate(${e.tx}px, ${e.ty}px) scale(${e.s})`);let r=ne.current;r&&(r.style.transform=`translate3d(${e.shift}px, 0, 0)`),ae.current!==t&&(ae.current=t,ie(t))},[]);return mP(C?pP(b,S,w,h,e):null,o,oe),j(`div`,{ref:g,class:`relative w-full h-full overflow-hidden ${n?`flex items-center justify-center`:``}`,children:[ee&&f!==null&&j(bP,{snapshotUrl:f,translateX:x.translateX,transition:a,transformOrigin:x.transformOrigin}),T&&j(xP,{ambient:l,usePip:v,transition:a}),j(`div`,{"data-morph":`fg`,class:`absolute inset-0 z-10`,children:j(SP,{morphCapable:C,snapshotUrl:f,mirrorSide:x.side,videoShiftX:h,transition:a,sceneRef:te,videoWrapRef:ne,fill:r,videoRef:d})}),C&&b&&j(gP,{geom:b,visible:S&&re}),u]})}var wP=1e4;function TP({onTimeout:e,timeoutMs:t=wP,active:n=!0}){let r=fx().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 EP(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.message_type===`system`&&t.event_type===`system.shutdown`}function DP({onShutdown:e}){let t=O(e);D(()=>{t.current=e},[e]),Wg({onAppMessage:A(e=>{EP(e?.data)&&t.current()},[])})}function OP(){let e=oh();return{joinCall:A(({url:t,micOnly:n=!1})=>{e?.join(n?{url:t,videoSource:!1}:{url:t})},[e]),leaveCall:A(()=>{e?.leave()},[e])}}var kP=vn(`PiP`),AP=360,jP=280;function MP(){return globalThis.window!==void 0&&`documentPictureInPicture`in globalThis.window}function NP(e){let{enabled:t,active:n}=e,[r,i]=E(null),a=MP(),o=ft(hv),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:AP,height:jP}),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){kP.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){kP.warn(`mediaSession metadata setup failed`,e)}let t=(t,n)=>{try{e.setActionHandler(t,n),r.push(t)}catch(e){kP.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 PP=Ut(null),FP={active:!1,video_shift_x:0,backdrop:{type:`snapshot_mirror`}},IP=ba(({id:e,showAudioWave:t=!0})=>{let n=r_(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(rg,{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})})]})}),LP=ba(()=>{let e=Uh(),{isScreenSharing:t}=_b(),n=fx()[0];return j(le,{children:[t&&n&&j(IP,{id:n}),e&&j(IP,{id:e,showAudioWave:!1})]})}),RP=ba(()=>j(`div`,{class:`absolute top-4 left-4 flex flex-col items-end gap-2 z-20`,children:j(LP,{})})),zP=ba(({isAudioOnly:e,canvasLayoutEffect:t,canvasRenderedSlot:n})=>{let r=Uh(),i=!t_(r??``).isOff,a=px(e),o=t_(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(lx,{sessionId:a.replicaId}),j(tg,{sessionId:a.replicaId})]}):j(CP,{canvasLayoutEffect:s?{...t,backdrop:{type:`none`}}:t,smartSidecarActive:c,isScreenSharing:i,captureSnapshot:UP,personaMode:s?`shift`:`auto`,renderedSlot:n,fill:t=>j(gx,{personaSessionId:a.replicaId,localSessionId:r,isPresenting:s,isScreenSharing:i,isAudioOnly:e,avatarOff:a.videoState.isOff,videoRef:t}),children:j(tg,{sessionId:a.replicaId})})}),BP=ba(({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(Wy,{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})]})}),VP=ba(({items:e})=>e.length<=1?j(le,{children:e}):j(BP,{items:e})),HP=ba(({onLeave:e})=>{let{joinCall:t,leaveCall:n}=OP(),r=Mg(),{config:i}=K_(),{session:a,end:o}=Kb(),s=Uh(),c=O(null),l=ft(Iv)?.frameRef??c,[u,d]=E(!1),[f,p]=E(!1),[m,h]=E(FP),[g,_]=E(null),v=a.value?.conversationUrl,y=i.value.customization.conversation,b=y.modality===`audio`,x=y.enable_chat,S=y.enable_closed_captions,C=y.enable_picture_in_picture,{pipWindow:w}=NP({enabled:C,active:r===`joined-meeting`});D(()=>(v&&t({url:v,micOnly:!s}),()=>{n()}),[]);let{camera:ee,requestCamera:T}=Sb(),{isCamMuted:te}=hb(),ne=ee.isGranted&&!te;D(()=>{!b&&r===`joined-meeting`&&(PP.value=ne)},[b,r,ne]);let re=O(!b&&!s&&PP.value===!0);D(()=>{r===`joined-meeting`&&re.current&&(re.current=!1,T())},[r,T]),D(()=>{(r===`left-meeting`||r===`error`)&&e()},[r,e]),D(()=>{let e=()=>{let e=l.current,t=e?.getRootNode(),n=t instanceof Document||t instanceof ShadowRoot?t:null;d(!!e&&n?.fullscreenElement===e)};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let ie=A(()=>{let e=l.current;if(!e)return;let t=e.getRootNode();(t instanceof Document||t instanceof ShadowRoot?t:null)?.fullscreenElement===e?document.exitFullscreen?.():e.requestFullscreen?.()},[]);A(()=>{p(e=>!e)},[]);let ae=A(()=>{o(),n()},[o]);if(TP({active:r===`joined-meeting`,onTimeout:ae}),DP({onShutdown:ae}),!v)return null;let oe=[j(Gb,{compact:!0},`screen-share`)];return x&&oe.push(j(tx,{compact:!0},`chat`)),j(Jb,{children:j($b,{children:j(kb,{children:[j(`div`,{class:`absolute inset-0`,children:[j(`div`,{class:`relative w-full h-full z-[5]`,children:[j(zP,{isAudioOnly:b,canvasLayoutEffect:m,canvasRenderedSlot:g}),!b&&j(RP,{}),j(Zb,{}),j(AN,{debugEnabled:f,onLayoutEffectChange:h,onRenderedSlotChange:_}),j(`div`,{class:`absolute top-4 right-4 z-20`,children:j(sx,{active:u,onToggle:ie,compact:!0})})]}),j(rx,{}),j(`div`,{class:`pointer-events-none absolute bottom-6 left-0 right-0 z-20 transition-opacity transition-transform ${r===`left-meeting`?`opacity-0 translate-y-5`:`opacity-100 translate-y-0`}`,"aria-hidden":r===`left-meeting`,children:j(`div`,{class:`flex justify-center items-center gap-2 @max-mobile:gap-1 ${r===`left-meeting`?``:`pointer-events-auto`}`,children:[j(Bb,{}),!b&&j(Hb,{}),S&&j(Xb,{}),j(VP,{items:oe}),j(`button`,{type:`button`,class:`btn btn-control btn-error`,onClick:ae,"aria-label":`Leave call`,children:j(Wy,{name:`leave`,"aria-label":`Leave Call`})})]})})]}),w&&La(j(hx,{onLeave:ae}),w.document.body)]})})})});function UP(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 WP({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 GP(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...`}}function KP({message:e}){return j(`div`,{class:`relative max-w-[min(20rem,90%)]`,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`})})]})}var qP=ba(({text:e,isJoining:t=!1,onJoin:n,onCancel:r})=>{let i=oh(),{config:a}=K_(),{localSessionId:o,isCamMuted:s}=hb(),{mic:c,camera:l,requestMic:u,requestCamera:d}=Sb(),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=GP(e,c.status,h);return j(kb,{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(rg,{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(Wy,{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(KP,{message:g}),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,{}),f&&j(Hb,{})]}),j(WP,{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`})]})]})]})})}),JP=`Password required`,YP=`Enter the password to start this conversation.`,XP=`Password`,ZP=`Continue`;function QP({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??JP}),j(`p`,{class:`text-sm text-base-content/70`,children:t?.description??YP}),j(`input`,{id:o,type:`password`,autocomplete:`current-password`,class:`input input-bordered w-full`,placeholder:t?.placeholder??XP,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(WP,{class:`btn-primary`,type:`submit`,disabled:!i.trim(),loading:n,children:t?.submit??ZP})]})})})}var $P=vn(`CaptchaChallenge`),eF=1;function tF(e){return typeof e==`object`&&!!e&&e.source===`tavus-captcha`&&typeof e.type==`string`}function nF({captcha:e,deploymentId:t,onToken:n,onFallback:r}){let i=(ft(Ct).baseUrl??`https://tavusapi.com`).replace(/\/+$/,``).split(`/`).slice(0,3).join(`/`),[a,o]=E(0),[s,c]=E(0),[l,u]=E(!1),[d,f]=E(!1),p=`${i}${e.challenge_path}?deployment_uuid=${encodeURIComponent(t)}&action=${encodeURIComponent(e.action)}&parent_origin=${encodeURIComponent(window.location.origin)}`,m=A(()=>{f(!1),o(e=>e+1)},[]);return D(()=>{function e(e){if(l||e.origin!==i)return;let a=e.data;if(tF(a)&&a.deployment_uuid===t){if(a.type===`interactive`){f(!0);return}if(a.type===`token`&&a.token){$P.info(`Captcha token received`),f(!1),n(a.token);return}if(a.type===`expired`){$P.info(`Captcha token expired, reloading iframe`),m();return}a.type===`error`&&($P.warn(`Captcha error received`,a.code),s<eF?(c(e=>e+1),m()):($P.warn(`Captcha error retries exhausted, falling back to no-token mode`),u(!0),r()))}}return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[i,t,s,l,n,r,m]),l?null:j(`div`,{class:d?`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":!d,children:j(`iframe`,{src:p,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`,title:`Security challenge`,style:{border:`none`,width:`300px`,height:`65px`},scrolling:`no`},a)})}function rF({text:e,onStart:t,isStarting:n}){let{config:r,deploymentId:i}=K_(),a=ft(L_),o=Yy(r.value),s=o.btn_title??e?.fallback_button??`Start the conversation`,c=r.value.customization.terms_content?.trim()??``,l=r.value.customization.terms_enabled===!0,u=c.length>0,d=u&&l,f=k(()=>d&&m_(i,c),[d,i,c]),p=d&&!f,m=r.value.has_password===!0,h=a?.password.value??null,g=m&&!h,_=r.value.captcha??null,{captchaReady:v,captchaEpoch:y,handleCaptchaToken:b,handleCaptchaFallback:x}=lv(_,a),S=mt(),[C,w]=E(f),ee=_!==null&&!v,T=n||d&&!C||g||ee;return j(tb,{title:o.title,description:o.description,overlay:j(le,{children:[ee&&j(nF,{captcha:_,deploymentId:i,onToken:b,onFallback:x},y),g&&a?j(QP,{onSubmit:a.setPassword}):null]}),children:[j(WP,{class:`btn-neutral rounded-box`,onClick:()=>{d&&C&&!f&&__(i,c),t()},disabled:T,loading:n,children:s}),u&&j(`div`,{class:`max-w-xs`,children:p?j(`label`,{for:S,class:`flex items-center gap-2 text-xs text-left cursor-pointer`,children:[j(`input`,{id:S,type:`checkbox`,class:`checkbox checkbox-secondary checkbox-xs mt-0.5 shrink-0`,checked:C,onChange:e=>w(e.target.checked)}),j(`span`,{class:`leading-snug`,children:c})]}):j(`p`,{class:`text-xs leading-snug text-base-content/60`,children:c})})]})}function iF({flow:e,welcomeText:t,onUnavailableCancel:n}){switch(e.state){case`idle`:return j(rF,{text:t,onStart:()=>{e.start()},isStarting:e.isStarting});case`haircheck`:return j(qP,{onJoin:()=>{e.join()},onCancel:()=>e.cancel(),isJoining:e.isStarting});case`call`:return j(HP,{onLeave:()=>e.leave()});case`ended`:return j(mb,{onRestart:()=>e.restart()});case`unavailable`:return j(ob,{cause:e.unavailableCause??`busy`,canRetry:e.canRetry,onRetry:()=>{e.start()},onCancel:n});default:{let t=e.state;throw Error(`Unreachable flow state: ${String(t)}`)}}}function aF(){let{config:e,configError:t}=K_(),n=lb(),r=sb(),i=k(()=>({fallback_button:n.start_button}),[n.start_button]),a=e.value.is_available,o=e.value.unavailable_reason;return j(Lv,{children:t.value?j(ob,{cause:`error`,canRetry:!1,onRetry:()=>{}}):a===!1?j(ob,{cause:o??`daily_limit`,canRetry:!1,onRetry:()=>{}}):j(iF,{flow:r,welcomeText:i})})}var oF=`:host {
163
163
  display: block;
164
164
  width: 100%;
165
165
  height: 100%;
@@ -167,4 +167,4 @@ container holding the app. Specify either width or maxWidth, and either height o
167
167
  overflow: hidden;
168
168
  background: transparent;
169
169
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
170
- }`;function cF(e){return j(le,{children:[j(`style`,{dangerouslySetInnerHTML:{__html:Je}}),j(`style`,{dangerouslySetInnerHTML:{__html:sF}}),j(Tt,{"deployment-id":e[`deployment-id`],"override-config":e[`override-config`],"conversational-context":e[`conversational-context`],"custom-greeting":e[`custom-greeting`],"memory-stores":e[`memory-stores`],"base-url":e[`base-url`],token:e.token,children:j(xi,{fallback:j(Fv,{}),children:j(Ci,{children:j(R_,{children:j(uv,{children:j(mv,{children:j(gv,{children:j(Ev,{children:j(oF,{})})})})})})})})})]})}var lF;function uF(){lF||=Be(cF,`tavus-embed`,[`deployment-id`,`override-config`,`conversational-context`,`custom-greeting`,`memory-stores`,`base-url`,`token`],{shadow:!0,mode:`open`})}Fe(null),vn(`Widget`);var dF=[`tavus:chat-message`,`tavus:conversation-ended`,`tavus:conversation-started`,`tavus:error`,`tavus:message`,`tavus:mode-change`,`tavus:protocol-message`,`tavus:ready`,`tavus:state-change`,`tavus:tool-call`],fF=class{element=null;tagName;constructor(e=`tavus-embed`){this.tagName=e,this.element=document.querySelector(this.tagName)}getElement(){if(this.element||=document.querySelector(this.tagName),!this.element)throw Error(`Element <${this.tagName}> not found in the DOM`);return this.element}open(){this.getElement().open?.()}close(){this.getElement().close?.()}startConversation(){this.getElement().startConversation?.()}endConversation(){this.getElement().endConversation?.()}sendMessage(e){let t=this.getElement();if(typeof e==`string`){let n={event_type:`conversation.respond`,properties:{text:e}};t.tavus?.sendMessage?.(n)}else t.tavus?.sendMessage?.(e)}updateConfig(e){this.getElement().updateConfig?.(e)}destroy(){this.getElement().destroy?.(),this.element=null}on(e,t){this.getElement().addEventListener(e,t)}off(e,t){this.getElement().removeEventListener(e,t)}};return typeof window<`u`&&uF(),e.TAVUS_EVENT_NAMES=dF,e.TavusIntegration=fF,e})({});
170
+ }`;function sF(e){return j(le,{children:[j(`style`,{dangerouslySetInnerHTML:{__html:Je}}),j(`style`,{dangerouslySetInnerHTML:{__html:oF}}),j(Tt,{"deployment-id":e[`deployment-id`],"override-config":e[`override-config`],"conversational-context":e[`conversational-context`],"custom-greeting":e[`custom-greeting`],"memory-stores":e[`memory-stores`],"base-url":e[`base-url`],token:e.token,children:j(xi,{fallback:j(Fv,{}),children:j(Ci,{children:j(R_,{children:j(uv,{children:j(mv,{children:j(gv,{children:j(Ev,{children:j(aF,{})})})})})})})})})]})}var cF;function lF(){cF||=Be(sF,`tavus-embed`,[`deployment-id`,`override-config`,`conversational-context`,`custom-greeting`,`memory-stores`,`base-url`,`token`],{shadow:!0,mode:`open`})}Fe(null),vn(`Widget`);var uF=[`tavus:chat-message`,`tavus:conversation-ended`,`tavus:conversation-started`,`tavus:error`,`tavus:message`,`tavus:mode-change`,`tavus:protocol-message`,`tavus:ready`,`tavus:state-change`,`tavus:tool-call`],dF=class{element=null;tagName;constructor(e=`tavus-embed`){this.tagName=e,this.element=document.querySelector(this.tagName)}getElement(){if(this.element||=document.querySelector(this.tagName),!this.element)throw Error(`Element <${this.tagName}> not found in the DOM`);return this.element}open(){this.getElement().open?.()}close(){this.getElement().close?.()}startConversation(){this.getElement().startConversation?.()}endConversation(){this.getElement().endConversation?.()}sendMessage(e){let t=this.getElement();if(typeof e==`string`){let n={event_type:`conversation.respond`,properties:{text:e}};t.tavus?.sendMessage?.(n)}else t.tavus?.sendMessage?.(e)}updateConfig(e){this.getElement().updateConfig?.(e)}destroy(){this.getElement().destroy?.(),this.element=null}on(e,t){this.getElement().addEventListener(e,t)}off(e,t){this.getElement().removeEventListener(e,t)}};return typeof window<`u`&&lF(),e.TAVUS_EVENT_NAMES=uF,e.TavusIntegration=dF,e})({});