@tavus/widget 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.
- package/dist/index.iife.js +5 -5
- package/dist/index.mjs +478 -485
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -156,13 +156,13 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
156
156
|
- omitted: host decides border`)});var zj=Z({method:$(`ui/request-display-mode`),params:Z({mode:wj.describe(`The display mode being requested.`)})});Z({mode:wj.describe(`The display mode that was actually set. May differ from requested if not supported.`)}).passthrough();var Bj=Q([$(`model`),$(`app`)]).describe(`Tool visibility scope - who can access the tool.`);Z({resourceUri:J().optional(),visibility:X(Bj).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:lD().optional(),permissions:lD().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 Vj=Z({method:$(`ui/download-file`),params:Z({contents:X(Q([hA,gA])).describe(`Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.`)})}),Hj=Z({method:$(`ui/message`),params:Z({role:$(`user`).describe(`Message role, currently only "user" is supported.`),content:X(_A).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:Oj.optional().describe(`CSP configuration from resource metadata.`),permissions:kj.optional().describe(`Sandbox permissions from resource metadata.`)})}),Z({method:$(`ui/notifications/tool-result`),params:EA.describe(`Standard MCP tool execution result.`)});var Uj=Z({toolInfo:Z({id:KO.optional().describe(`JSON-RPC id of the tools/call request.`),tool:CA.describe(`Tool definition including name, inputSchema, etc.`)}).optional().describe(`Metadata of the tool call that instantiated this App.`),theme:Cj.optional().describe(`Current color theme preference.`),styles:Mj.optional().describe(`Style configuration for theming the app.`),displayMode:wj.optional().describe(`How the UI is currently displayed.`),availableDisplayModes:X(wj).optional().describe(`Display modes the host supports.`),containerDimensions:Q([Z({height:Y().describe(`Fixed container height in pixels.`)}),Z({maxHeight:Q([Y(),oD()]).optional().describe(`Maximum container height in pixels.`)})]).and(Q([Z({width:Y().describe(`Fixed container width in pixels.`)}),Z({maxWidth:Q([Y(),oD()]).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:aD().optional().describe(`Whether the device supports touch input.`),hover:aD().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:Uj.describe(`Partial context update containing only changed fields.`)});var Wj=Z({method:$(`ui/update-model-context`),params:Z({content:X(_A).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:pD(J(),cD().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),Gj=Z({method:$(`ui/initialize`),params:Z({appInfo:sk.describe(`App identification (name and version).`),appCapabilities:Lj.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:sk.describe(`Host application identification and version.`),hostCapabilities:Ij.describe(`Features and capabilities provided by the host.`),hostContext:Uj.describe(`Rich context about the host environment.`)}).passthrough();var Kj=[Sj],qj=class extends xj{_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:Aj,sandboxready:Dj,initialized:Rj,requestteardown:Fj,loggingmessage:PA};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(Gj,e=>this._oninitialize(e)),this.setRequestHandler(_k,(e,t)=>(this.onping?.(e.params,t),{})),this.replaceRequestHandler(zj,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(Hj,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(Ej,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(Vj,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(zj,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(Wj,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(OA,async(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}set oncreatesamplingmessage(e){this.setRequestHandler(HA,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(Wk,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(Kk,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(Xk,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(sA,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:Kj.includes(t)?t:Sj,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];Jj(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},Nj,t)}sendResourceTeardown=this.teardownResource;callTool(e,t){return this.request({method:`tools/call`,params:e},EA,t)}listTools(e,t){return this.request({method:`tools/list`,params:e},TA,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},EA,{signal:t.signal}),e.tools.listChanged&&this._client.setNotificationHandler(kA,e=>this.sendToolListChanged(e.params))),e.resources&&(this.onlistresources=async(e,t)=>this._client.request({method:`resources/list`,params:e},Gk,{signal:t.signal}),this.onlistresourcetemplates=async(e,t)=>this._client.request({method:`resources/templates/list`,params:e},qk,{signal:t.signal}),this.onreadresource=async(e,t)=>this._client.request({method:`resources/read`,params:e},Zk,{signal:t.signal}),e.resources.listChanged&&this._client.setNotificationHandler(Qk,e=>this.sendResourceListChanged(e.params))),e.prompts&&(this.onlistprompts=async(e,t)=>this._client.request({method:`prompts/list`,params:e},cA,{signal:t.signal}),e.prompts.listChanged&&this._client.setNotificationHandler(bA,e=>this.sendPromptListChanged(e.params)))}return super.connect(e)}};function Jj(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Yj(){let e=pt(hv);if(!e)throw Error(`useTheme must be used within ThemeProvider`);return e}async function Xj(e){try{await e.teardownResource({},{timeout:1e3})}catch{}try{await e.close()}catch{}}function Zj({state:e}){return e.enabled?A(`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:[A(`summary`,{class:`cursor-pointer font-medium`,children:`Magic Canvas debug`}),A(`dl`,{class:`mt-2 grid gap-2`,children:[A(Qj,{label:`iframe`,value:e.iframeLifecycleState}),A(Qj,{label:`post`,value:e.lastInteractionPostResult}),A(Qj,{label:`context`,value:e.lastModelContextUpdate}),A(Qj,{label:`error`,value:e.lastError}),A($j,{label:`tool_call`,value:e.lastToolCall}),A($j,{label:`canvas_config`,value:e.parsedCanvasConfig})]})]}):null}function Qj({label:e,value:t}){return t?A(`div`,{children:[A(`dt`,{class:`font-semibold`,children:e}),A(`dd`,{class:`break-words text-base-content/70`,children:t})]}):null}function $j({label:e,value:t}){return t===void 0?null:A(`div`,{children:[A(`dt`,{class:`font-semibold`,children:e}),A(`dd`,{children:A(`pre`,{class:`max-h-40 overflow-auto rounded bg-base-200 p-2 text-[10px] leading-relaxed`,children:JSON.stringify(t,null,2)})})]})}var eM=new Set([`mcp-ui.tavus.io`,`mcp-ui.tavus-preview.io`]),tM=[`.sandbox-tavus.io`],nM=new Set([`tavusapi.com`]);function rM(e){let t;try{t=new URL(e)}catch{return!1}return oM(t)?!0:t.protocol===`https:`?eM.has(t.hostname)?!0:tM.some(e=>t.hostname.endsWith(e)):!1}function iM(e){return rM(e)}function aM(e){let t;try{t=new URL(e)}catch{return!1}return sM(t)?!0:t.protocol===`https:`&&nM.has(t.hostname)}function oM(e){return sM(e)}function sM(e){return!cM()||e.protocol!==`http:`&&e.protocol!==`https:`?!1:[`localhost`,`127.0.0.1`,`::1`,`[::1]`].includes(e.hostname)}function cM(){try{let e=globalThis.location?.hostname;return typeof e==`string`&&[`localhost`,`127.0.0.1`,`::1`,`[::1]`].includes(e)}catch{return!1}}var lM=`tavus.canvas.interaction`,uM=[`safe-area-right`,`safe-area-left`,`safe-area-bottom`,`full`],dM=`safe-area-right`,fM={x:275/1280,y:111/720,width:730/1280,height:609/720},pM={type:`snapshot_mirror`};function mM(e){return LM(e)?e.message_type===`conversation`&&e.event_type===`conversation.tool_call`&&typeof e.conversation_id==`string`&&LM(e.properties):!1}function hM(e){if(!LM(e))return null;let t=ZM(e,`component`),n=ZM(e,`component_version`),r=ZM(e,`sandbox_url`),i=eN(e,`mcp_server_url`,iM),a=eN(e,`api_base_url`,aM),o=eN(e,`interaction_url`,aM),s=VM(e.layout),c=e.version;return c!==1||!t||!n||!r||!rM(r)||i===null||a===null||o===null||s===null?null:{version:c,component:t,component_version:n,resource_uri:ZM(e,`resource_uri`),sandbox_url:r,mcp_server_url:i,mcp_tool_name:ZM(e,`mcp_tool_name`),api_base_url:a,interaction_url:o,layout:s,host_context:LM(e.host_context)?e.host_context:void 0}}function gM(e){if(e===void 0)return{ok:!0,value:{}};if(LM(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 LM(t)?{ok:!0,value:t}:{ok:!1,error:Error(`Magic Canvas tool arguments must decode to an object.`)}}catch(e){return{ok:!1,error:RM(e)}}}function _M(e){let t=e.properties.name;if(t!==`canvas_clear`&&t!==`update_component`)return null;let n=gM(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(!LM(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 vM=[`safe-area-left`,`safe-area-right`];function yM(e){let t=vM.includes(e.preferred_slot)?e.preferred_slot:dM;return t===e.preferred_slot&&e.display_mode===`inline`?e:{...e,preferred_slot:t,display_mode:`inline`}}function bM(e){return e.display_mode===`fullscreen`?`full`:e.preferred_slot}function xM(e){return e===`full`||e===`safe-area-bottom`}function SM(e,t){let n=bM(t.layout);return xM(n)?[t]:[...e.filter(e=>{let t=bM(e.layout);return!xM(t)&&t!==n}),t]}function CM(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 SM(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=NM(t.updates),i,a=e.map(e=>{if(!n(e))return e;let t={...e,arguments:{...e.arguments,...r.componentArguments},layout:yM({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&&bM(o.layout)===bM(i.layout)?a:SM(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 wM(e){if(!LM(e)||!Array.isArray(e.content))return null;for(let t of e.content){if(!LM(t))continue;let e=(LM(t._meta)?t._meta:null)?.[lM];if(LM(e))return tN(e)}return null}function TM(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??IM(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:LM(t.metadata)?t.metadata:{}}}function EM(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 DM(e){return!LM(e)||!Array.isArray(e.content)?``:e.content.map(e=>LM(e)&&e.type===`text`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
|
|
160
|
-
`).trim()}function
|
|
161
|
-
`)}function
|
|
162
|
-
`).trim():``}function BM(e){let t=JSON.stringify(e);return t?t.length<=2e3?t:`${t.slice(0,2e3)}...`:`{}`}function VM(e){if(e===void 0)return;if(!LM(e))return null;let t=HM(e),n=qM(e.safe_area??e.safeArea),r=JM(e.backdrop);return n===null||r===null?null:{...t?{preferred_slot:t}:{},...YM(e.avoid_safe_area??e.avoidSafeArea,`avoid_safe_area`),...n?{safe_area:n}:{},...r?{backdrop:r}:{}}}function HM(e){if(typeof e==`string`&&XM(e))return e;if(!LM(e))return;let t=e.preferred_slot??e.preferredSlot??e.slot;return typeof t==`string`&&XM(t)?t:void 0}function UM(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 WM(e){let t=LM(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 GM(e){let t=LM(e.layout)?e.layout:void 0;return qM(e.safe_area??e.safeArea??t?.safe_area??t?.safeArea)??void 0}function KM(e){let t=LM(e.layout)?e.layout:void 0;return JM(e.backdrop??t?.backdrop)??void 0}function qM(e){if(e===void 0)return;if(!LM(e))return null;let t=QM(e,`x`),n=QM(e,`y`),r=QM(e,`width`),i=QM(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:$M(t,0,1),y:$M(n,0,1),width:$M(r,0,1),height:$M(i,0,1)}}function JM(e){if(e===void 0)return;if(e===`snapshot_mirror`||e===`none`)return{type:e};if(!LM(e))return null;let t=e.type;return t===`snapshot_mirror`||t===`none`?{type:t}:null}function YM(e,t){return typeof e==`boolean`?{[t]:e}:{}}function XM(e){return uM.includes(e)}function ZM(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function QM(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function $M(e,t,n){return Math.min(Math.max(e,t),n)}function eN(e,t,n){let r=ZM(e,t);if(r)return n(r)?r:null}function tN(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&&!LM(e.metadata)?null:e}var nN=`tavus-deployment magic-canvas/0.0.0`;function rN(e){if(!mM(e)||e.canvas_config===void 0||e.canvas_config===null)return null;let t=hM(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=gM(e.properties.arguments);if(!r.ok)throw r.error;return kM({conversationId:e.conversation_id,toolCallId:n,args:r.value,canvasConfig:t})}function iN(e){if(!mM(e))return null;if(e.canvas_config!==void 0&&e.canvas_config!==null){let t=rN(e);return t?{kind:`show`,instance:t}:null}return _M(e)}function aN(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 oN(e,t){return{theme:e.theme,displayMode:t?.display_mode??`inline`,availableDisplayModes:[`inline`,`fullscreen`],...t?{containerDimensions:FM(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:nN,styles:{variables:sN(e.cssVars)}}}function sN(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`,...cN(e)}}function cN(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 lN=1e3,uN=5e3,dN=1200,fN=48,pN=`allow-scripts`,mN={"canvas.scheduling_embed":`allow-scripts allow-same-origin allow-popups allow-forms`};function hN(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 gN=class{onmessage;onerror;onclose;#e;#t;constructor(e){this.#e=e}start(){let e=e=>{hN(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 _N(e){for(let t of uM)if(e.some(e=>MN(e)===t))return t;return null}function vN({onLayoutEffectChange:e,onRenderedSlotChange:t,debugEnabled:n=NN()}={}){let{client:r}=K_(),{dataTheme:i,cssVars:a}=Yj(),o=oh(),s=Mg(),[c,l]=T([]),[u,d]=DN(),[f,p]=T(()=>({enabled:n,iframeLifecycleState:`idle`})),m=k(e=>{p(t=>({...t,...e}))},[]),h=k((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=O(()=>({theme:i.value===`dark`?`dark`:`light`,cssVars:a.value}),[i.value,a.value]);E(()=>{p(e=>e.enabled===n?e:{...e,enabled:n})},[n]),Wg({onAppMessage:k(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=iN(e.data);if(!t)return;l(e=>CM(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:IN(e).message})}},[s,m])});let _=c.map(e=>({instance:e,layout:AM(e,d)})),v=jM(_.map(({layout:e})=>e),d),y=[..._].reverse().find(({layout:e})=>e.display_mode===`fullscreen`)?.instance.tool_call_id;E(()=>{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=_N(_.map(({layout:e})=>e));E(()=>{t?.(b)},[t,b]);let x=c.length>0||f.enabled;return A(`div`,{ref:u,"data-magic-canvas-root":!0,class:`pointer-events-none absolute inset-0 z-30`,children:[x&&y&&A(`div`,{class:`absolute inset-0 bg-black/45`}),x&&uM.map(e=>{let t=_.filter(({layout:t})=>MN(t)===e);return t.length===0?null:A(bN,{slot:e,safeAreaTop:v.safe_area?.y,frameWidth:d.width,children:e=>t.map(({instance:t,layout:n})=>A(xN,{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&&A(`div`,{class:`absolute right-4 bottom-24 @max-mobile:right-3 @max-mobile:bottom-20`,children:A(Zj,{state:f})})]})}var yN=16;function bN({slot:e,safeAreaTop:t,frameWidth:n,children:r}){let[i,a]=ON(),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-yN*2):void 0;return A(`div`,{ref:i,class:jN(e),style:{top:r,bottom:`${AN}px`,maxWidth:a},"data-canvas-slot":e,children:A(`div`,{class:`my-auto flex w-full flex-col gap-2`,children:o})})}return A(`div`,{ref:i,class:jN(e),"data-canvas-slot":e,children:o})}function xN({availableHeight:e,client:t,hostTheme:n,instance:r,layout:i,dimmed:a,onDebug:o,onComplete:s,onDisplayModeChange:c,sendAppMessage:l}){let u=D(null),d=D(null),f=D(e),p=D(320),m=D(n),h=D(r),g=D(i),_=D(-1),v=D(s),y=D(c),b=D(l),[x,S]=T(320);E(()=>{h.current=r},[r]),E(()=>{p.current=x,d.current?.setHostContext(TN(h.current,m.current,g.current,f.current,x))},[x]),E(()=>{f.current=e;let t=wN(n,u.current);m.current=t,d.current?.setHostContext(TN(h.current,t,g.current,e,p.current))},[e,n]),E(()=>{g.current=i,d.current?.setHostContext(TN(h.current,m.current,i,e,p.current))},[e,i]),E(()=>{v.current=s,y.current=c,b.current=l},[s,c,l]),E(()=>{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:IN(e).message})},C=()=>{if(n||!a)return;let e=h.current,t=OM(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 qj(null,{name:`tavus-deployment`,version:`0.0.0`},{logging:{},message:{text:{},structuredContent:{}},updateModelContext:{text:{},structuredContent:{}}},{hostContext:TN(r,wN(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,fN),720))},u.onmessage=async e=>{let r=wM(e),i=DM(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=TM(e,r),s=aN(a),l=new AbortController,u=globalThis.setTimeout(()=>l.abort(),uN);try{await En(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}),EM(a)&&(a.type===`submit`?(c&&clearTimeout(c),c=setTimeout(()=>{c=null,n||v.current()},dN)):v.current())}catch(e){let t=IN(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()},lN),{}),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(TN(h.current,m.current,g.current,f.current,p.current)),{mode:t}},u.connect(new gN(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&&Xj(i)}},[t,r.id,r.canvas_config.sandbox_url,o]),E(()=>{r.revision!==0&&(r.revision<=_.current||(_.current=r.revision,d.current?.sendToolInput({arguments:r.arguments}).catch(e=>{o({iframeLifecycleState:`error`,lastError:IN(e).message})})))},[r.arguments,r.revision,o]);let C=i.viable_slot===`full`||i.display_mode===`fullscreen`,w=C?null:EN(x,e),ee=w?.placeholderStyle,te=w?.cardStyle,ne=C?{height:`100%`}:w?.iframeStyle??{height:`${x}px`},re=[`pointer-events-auto w-full overflow-hidden rounded-lg border border-base-300 bg-base-100 shadow-xl transition-[opacity,transform]`,C?`fixed inset-4 z-10 max-w-none`:`max-w-md`,a?`scale-[0.98] opacity-40`:``].filter(Boolean).join(` `),ie=mN[r.canvas_config.component]??pN,ae=A(`div`,{class:re,style:te,"data-canvas-card":i.viable_slot,children:A(`iframe`,{ref:u,title:`${r.canvas_config.component} ${r.canvas_config.component_version}`,class:C?`block h-full w-full border-0 bg-transparent`:`block border-0 bg-transparent`,sandbox:ie,style:ne})});return C?ae:A(`div`,{class:`block w-full`,style:ee,children:ae})}var SN=[`--color-base-100`,`--color-base-200`,`--color-base-300`,`--color-base-content`,`--color-primary`,`--color-error`];function CN(e){if(!e||typeof getComputedStyle!=`function`)return{};let t=getComputedStyle(e),n={};for(let e of SN){let r=t.getPropertyValue(e).trim();r&&(n[e]=r)}return n}function wN(e,t){let n=CN(t);return Object.keys(n).length===0?e:{...e,cssVars:{...e.cssVars,...n}}}function TN(e,t,n,r,i){let a=oN(t,n),o=n.viable_slot===`full`||n.display_mode===`fullscreen`,s=o?void 0:PN(r),c=o?1:EN(i??0,r)?.displayScale??1;return{...e.canvas_config.host_context,...a,containerDimensions:{...FN(a.containerDimensions)?a.containerDimensions:{},...s===void 0?{}:{maxHeight:s},displayScale:c}}}function EN(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 DN(){let e=D(null),[t,n]=T(()=>kN(null));return E(()=>{let t=()=>n(t=>{let n=kN(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 ON(){let e=D(null),[t,n]=T();return E(()=>{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 kN(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 AN=72;function jN(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 MN(e){return e.display_mode===`fullscreen`&&e.preferred_slot!==`full`?e.preferred_slot:e.viable_slot}function NN(){return!1}function PN(e){return e===void 0||!Number.isFinite(e)||e<=0?720:Math.min(Math.floor(e),720)}function FN(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function IN(e){return e instanceof Error?e:Error(String(e))}var LN=24,RN=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 BN(e){let t=e?.getRootNode();return t instanceof ShadowRoot?t:document}function VN(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 HN(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??fM,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 UN(e,t,n){let[r,i]=T(()=>e?zN(BN(n?.current)):null);return dt(()=>{if(!e){i(null);return}let t=BN(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 WN(e,t,n){let[r,i]=T(()=>t?VN(e.current):null);return dt(()=>{if(!t){i(null);return}let n=()=>i(VN(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 GN(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`&&HN(e,r,i,a)),side:o}}function KN(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>=RN&&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-LN*2),g=Math.max(RN,Math.min(h,c-LN*2));return{centerX:(u+d)/2-r,centerY:(f+p)/2-a,diameter:g}}var qN=`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 JN(e,t){let n=Math.abs(t)/2;return e===`left`?`${n}px center`:`calc(100% - ${n}px) center`}function YN(e,t,n){let[r,i]=T(()=>e&&t?KN(t,BN(n?.current),VN(n?.current)):null);return dt(()=>{if(!e||!t){i(null);return}let r=BN(n?.current),a=()=>i(KN(t,r,VN(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 XN(e,t){let[n,r]=T(null);return dt(()=>{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 ZN=1;function QN(e,t,n){return Math.min(Math.max(e,t),n)}function $N(e,t,n,r){let i=Math.min(e.diameter/t.height,1),a=r?.safe_area??fM,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:QN(e.centerX-o,e.centerX+c-t.width*i,e.centerX-c),ty:QN(e.centerY-s,e.centerY+c-t.height*i,e.centerY-c)}}var eP=[`cx`,`cy`,`r`,`tx`,`ty`,`s`,`shift`];function tP(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=$N(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 nP(e,t,n){let r=D(null),i=D(e),a=D(n),o=D(0),s=D(0);i.current=e,a.current=n,E(()=>{let e=i.current;if(!e)return;if(!r.current||rP()){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 eP){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?eP.map(t=>Math.round(e[t]*100)).join():``,t]),E(()=>()=>{o.current&&globalThis.cancelAnimationFrame(o.current)},[])}function rP(){return globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1}function iP({geom:e,visible:t}){return A(`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 aP(e,t){let n=t>=0?`left`:`right`,r=D({side:n,shift:t});E(()=>{e&&(r.current={side:n,shift:t})},[e,n,t]);let i=e?n:r.current.side;return{side:i,transformOrigin:JN(i,e?t:r.current.shift),translateX:e?0:-r.current.shift}}function oP(e,t,n){return`${e.side??``}:${e.active}:${t}:${n??``}`}function sP({snapshotUrl:e,transformOrigin:t}){return A(`div`,{class:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url("${e}")`,transform:`scaleX(-1)`,transformOrigin:t}})}function cP({snapshotUrl:e,translateX:t,transition:n,transformOrigin:r}){return A(`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:A(sP,{snapshotUrl:e,transformOrigin:r})})}function lP({ambient:e,usePip:t,transition:n}){return e===`none`?null:A(`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 uP({morphCapable:e,snapshotUrl:t,mirrorSide:n,videoShiftX:r,transition:i,sceneRef:a,videoWrapRef:o,fill:s,videoRef:c}){return A(`div`,{ref:a,"data-morph":`scene`,class:`absolute inset-0`,style:e?{transformOrigin:`top left`}:void 0,children:A(`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&&A(`div`,{"aria-hidden":`true`,"data-morph":`window-mirror`,class:`absolute top-0 bottom-0 w-full`,style:n===`right`?{left:`calc(100% - ${ZN}px)`}:{right:`calc(100% - ${ZN}px)`},children:A(sP,{snapshotUrl:t,transformOrigin:`center`})})]})})}function dP({canvasLayoutEffect:e,smartSidecarActive:t,isScreenSharing:n,fill:r,captureSnapshot:i,transition:a=qN,transitionMs:o=560,personaMode:s=`shift`,renderedSlot:c=null,ambient:l=`default`,children:u}){let d=D(null),[f,p]=T(null),m=t&&e.backdrop.type===`snapshot_mirror`,h=t?e.video_shift_x:0,g=D(null),_=oP(e,h,c),{usePip:v,side:y}=GN(e,s,c,UN(s!==`shift`,_,g),h,WN(g,s!==`shift`,_)),b=YN(s!==`shift`,y,g),x=aP(m,h);E(()=>{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]),E(()=>{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=XN(g,C),ee=f!==null&&!C,te=C&&y!=null,ne=D(null),re=D(null),[ie,ae]=T(!0),oe=D(!0),se=k((e,t)=>{let n=ne.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=re.current;r&&(r.style.transform=`translate3d(${e.shift}px, 0, 0)`),oe.current!==t&&(oe.current=t,ae(t))},[]);return nP(C?tP(b,S,w,h,e):null,o,se),A(`div`,{ref:g,class:`relative w-full h-full overflow-hidden ${n?`flex items-center justify-center`:``}`,children:[ee&&f!==null&&A(cP,{snapshotUrl:f,translateX:x.translateX,transition:a,transformOrigin:x.transformOrigin}),te&&A(lP,{ambient:l,usePip:v,transition:a}),A(`div`,{"data-morph":`fg`,class:`absolute inset-0 z-10`,children:A(uP,{morphCapable:C,snapshotUrl:f,mirrorSide:x.side,videoShiftX:h,transition:a,sceneRef:ne,videoWrapRef:re,fill:r,videoRef:d})}),C&&b&&A(iP,{geom:b,visible:S&&ie}),u]})}var fP=1e4;function pP({onTimeout:e,timeoutMs:t=fP,active:n=!0}){let r=$b().length>0,[i,a]=T(!1),o=D(e);return E(()=>{o.current=e},[e]),E(()=>{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 mP(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.message_type===`system`&&t.event_type===`system.shutdown`}function hP({onShutdown:e}){let t=D(e);E(()=>{t.current=e},[e]),Wg({onAppMessage:k(e=>{mP(e?.data)&&t.current()},[])})}function gP(){let e=oh();return{joinCall:k(({url:t,micOnly:n=!1})=>{e?.join(n?{url:t,videoSource:!1}:{url:t})},[e]),leaveCall:k(()=>{e?.leave()},[e])}}var _P=yn(`PiP`),vP=360,yP=280;function bP(){return globalThis.window!==void 0&&`documentPictureInPicture`in globalThis.window}function xP(e){let{enabled:t,active:n}=e,[r,i]=T(null),a=bP(),o=pt(hv),s=k(()=>{i(e=>(e&&!e.closed&&e.close(),null))},[]),c=k(async()=>{if(a&&!(!t||!n)&&!(r&&!r.closed))try{let e=await globalThis.window.documentPictureInPicture.requestWindow({width:vP,height:yP}),t=Ye.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){_P.warn(`Failed to open PiP window`,e)}},[a,t,n,r]);return E(()=>{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){_P.warn(`mediaSession metadata setup failed`,e)}let t=(t,n)=>{try{e.setActionHandler(t,n),r.push(t)}catch(e){_P.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]),E(()=>{(!n||!t)&&r&&!r.closed&&s()},[n,t,r,s]),E(()=>()=>{r&&!r.closed&&r.close()},[r]),E(()=>{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 SP=Wt(null),CP={active:!1,video_shift_x:0,backdrop:{type:`snapshot_mirror`}},wP=ba(({id:e,showAudioWave:t=!0})=>{let n=r_(e).isOff;return A(`div`,{class:`relative aspect-square w-32 @max-mobile:w-24 rounded-box overflow-hidden bg-black/30 z-10 ${n?`hidden`:``}`,children:[A(rg,{automirror:!0,sessionId:e,type:`video`,fit:`cover`,className:`w-full h-full object-cover ${n?`hidden`:``}`}),t&&A(`div`,{class:`absolute bottom-2 right-2`,children:A(Yb,{id:e})})]})}),TP=ba(()=>{let e=Uh(),{isScreenSharing:t}=ib(),n=$b()[0];return A(ue,{children:[t&&n&&A(wP,{id:n}),e&&A(wP,{id:e,showAudioWave:!1})]})}),EP=ba(()=>A(`div`,{class:`absolute top-4 left-4 flex flex-col items-end gap-2 z-20`,children:A(TP,{})})),DP=ba(({isAudioOnly:e,canvasLayoutEffect:t,canvasRenderedSlot:n})=>{let r=Uh(),i=!t_(r??``).isOff,a=ex(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`?A(qb,{}):a.phase===`connecting`?A(Kb,{}):e&&!s?A(`div`,{class:`absolute inset-0 flex items-center justify-center`,children:[A(Xb,{sessionId:a.replicaId}),A(tg,{sessionId:a.replicaId})]}):A(dP,{canvasLayoutEffect:s?{...t,backdrop:{type:`none`}}:t,smartSidecarActive:c,isScreenSharing:i,captureSnapshot:jP,personaMode:s?`shift`:`auto`,renderedSlot:n,fill:t=>A(rx,{personaSessionId:a.replicaId,localSessionId:r,isPresenting:s,isScreenSharing:i,isAudioOnly:e,avatarOff:a.videoState.isOff,videoRef:t}),children:A(tg,{sessionId:a.replicaId})})}),OP=ba(({items:e})=>{let[t,n]=T(!1),r=D(null);return E(()=>{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]),A(`div`,{ref:r,class:`relative`,children:[A(`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:A(Ny,{name:`more`})}),t&&A(`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})]})}),kP=ba(({items:e})=>e.length<=1?A(ue,{children:e}):A(OP,{items:e})),AP=ba(({onLeave:e})=>{let{joinCall:t,leaveCall:n}=gP(),r=Mg(),{config:i}=K_(),{session:a,end:o}=Nb(),s=Uh(),c=D(null),l=pt(Tv)?.frameRef??c,[u,d]=T(!1),[f,p]=T(!1),[m,h]=T(CP),[g,_]=T(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}=xP({enabled:C,active:r===`joined-meeting`});E(()=>(v&&t({url:v,micOnly:!s}),()=>{n()}),[]);let{camera:ee,requestCamera:te}=lb(),{isCamMuted:ne}=nb(),re=ee.isGranted&&!ne;E(()=>{!b&&r===`joined-meeting`&&(SP.value=re)},[b,r,re]);let ie=D(!b&&!s&&SP.value===!0);E(()=>{r===`joined-meeting`&&ie.current&&(ie.current=!1,te())},[r,te]),E(()=>{(r===`left-meeting`||r===`error`)&&e()},[r,e]),E(()=>{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 ae=k(()=>{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?.()},[]);k(()=>{p(e=>!e)},[]);let oe=k(()=>{o(),n()},[o]);if(pP({active:r===`joined-meeting`,onTimeout:oe}),hP({onShutdown:oe}),!v)return null;let se=[A(Mb,{compact:!0},`screen-share`)];return x&&se.push(A(Hb,{compact:!0},`chat`)),A(Fb,{children:A(Bb,{children:A(gb,{children:[A(`div`,{class:`absolute inset-0`,children:[A(`div`,{class:`relative w-full h-full z-[5]`,children:[A(DP,{isAudioOnly:b,canvasLayoutEffect:m,canvasRenderedSlot:g}),!b&&A(EP,{}),A(Rb,{}),A(vN,{debugEnabled:f,onLayoutEffectChange:h,onRenderedSlotChange:_}),A(`div`,{class:`absolute top-4 right-4 z-20`,children:A(Jb,{active:u,onToggle:ae,compact:!0})})]}),A(Wb,{}),A(`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:A(`div`,{class:`flex justify-center items-center gap-2 @max-mobile:gap-1 ${r===`left-meeting`?``:`pointer-events-auto`}`,children:[A(Db,{}),!b&&A(kb,{}),S&&A(Lb,{}),A(kP,{items:se}),A(`button`,{type:`button`,class:`btn btn-control btn-error`,onClick:oe,"aria-label":`Leave call`,children:A(Ny,{name:`leave`,"aria-label":`Leave Call`})})]})})]}),w&&La(A(nx,{onLeave:oe}),w.document.body)]})})})});function jP(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 MP({loading:e=!1,disabled:t,class:n,children:r,...i}){return A(`button`,{type:`button`,class:`btn relative ${n?` ${n}`:``}`,disabled:t||e,"aria-busy":e||void 0,...i,children:[A(`span`,{children:r}),e&&A(`span`,{class:`absolute inset-0 flex items-center justify-center backdrop-blur-xs`,"aria-hidden":`true`,children:A(`span`,{class:`loading loading-spinner loading-sm`})})]})}function NP(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 PP({message:e}){return A(`div`,{class:`relative max-w-[min(20rem,90%)]`,children:[A(`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}),A(`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:A(`path`,{d:`M0 0 L8 8 L16 0 Z`,fill:`currentColor`})})]})}var FP=ba(({text:e,isJoining:t=!1,onJoin:n,onCancel:r})=>{let i=oh(),{config:a}=K_(),{localSessionId:o,isCamMuted:s}=nb(),{mic:c,camera:l,requestMic:u,requestCamera:d}=lb(),f=a.value.customization.conversation.modality===`video`;E(()=>{u()},[]);let p=c.isGranted,m=D(!1);E(()=>{!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=NP(e,c.status,h);return A(gb,{children:A(`div`,{class:`absolute inset-0 motion-safe:animate-[tavusFadeUp_280ms_ease-out]`,children:[l.isGranted&&!s?A(`div`,{class:`absolute inset-0 flex items-center justify-center bg-black overflow-hidden`,children:A(rg,{type:`video`,sessionId:o??``,mirror:!0,fit:`cover`,className:`w-full h-full object-cover!`})}):A(`div`,{class:`absolute inset-0 flex items-center justify-center text-base-content/40`,children:A(Ny,{name:`face-smile`,size:`7rem`,"aria-label":`Camera off`})}),A(`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&&A(PP,{message:g}),A(`div`,{class:`flex flex-wrap items-center justify-center gap-1.5 @max-mobile:gap-1`,children:[A(`div`,{class:`flex items-center justify-center gap-1.5 shrink-0 @max-mobile:gap-1`,children:[A(Db,{}),f&&A(kb,{})]}),A(MP,{class:`btn-accent `,loading:t,disabled:!p,onClick:n,children:e?.join??`Join Video Chat`}),c.isBlocked&&A(`button`,{type:`button`,class:`btn btn-error `,onClick:()=>{i&&i.leave(),r?.()},children:e?.cancel??`Cancel`})]})]})]})})}),IP=`Password required`,LP=`Enter the password to start this conversation.`,RP=`Password`,zP=`Continue`;function BP({onSubmit:e,text:t,isSubmitting:n=!1,errorMessage:r}){let[i,a]=T(``),o=ht();return A(`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:A(`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:A(`div`,{class:`card-body gap-3`,children:[A(`h3`,{id:`${o}-title`,class:`card-title text-base-content`,children:t?.title??IP}),A(`p`,{class:`text-sm text-base-content/70`,children:t?.description??LP}),A(`input`,{id:o,type:`password`,autocomplete:`current-password`,class:`input input-bordered w-full`,placeholder:t?.placeholder??RP,value:i,disabled:n,onInput:e=>a(e.target.value),autoFocus:!0}),r&&A(`p`,{class:`text-error text-xs`,role:`alert`,children:r}),A(MP,{class:`btn-primary`,type:`submit`,disabled:!i.trim(),loading:n,children:t?.submit??zP})]})})})}var VP=yn(`CaptchaChallenge`),HP=1;function UP(e){return typeof e==`object`&&!!e&&e.source===`tavus-captcha`&&typeof e.type==`string`}function WP({captcha:e,deploymentId:t,onToken:n,onFallback:r}){let i=(pt(wt).baseUrl??`https://tavusapi.com`).replace(/\/+$/,``).split(`/`).slice(0,3).join(`/`),[a,o]=T(0),[s,c]=T(0),[l,u]=T(!1),[d,f]=T(!1),p=`${i}${e.challenge_path}?deployment_uuid=${encodeURIComponent(t)}&action=${encodeURIComponent(e.action)}&parent_origin=${encodeURIComponent(window.location.origin)}`,m=k(()=>{f(!1),o(e=>e+1)},[]);return E(()=>{function e(e){if(l||e.origin!==i)return;let a=e.data;if(UP(a)&&a.deployment_uuid===t){if(a.type===`interactive`){f(!0);return}if(a.type===`token`&&a.token){VP.info(`Captcha token received`),f(!1),n(a.token);return}if(a.type===`expired`){VP.info(`Captcha token expired, reloading iframe`),m();return}a.type===`error`&&(VP.warn(`Captcha error received`,a.code),s<HP?(c(e=>e+1),m()):(VP.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:A(`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:A(`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 GP({text:e,onStart:t,isStarting:n}){let{config:r,deploymentId:i}=K_(),a=pt(L_),o=Ry(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=O(()=>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=ht(),[C,w]=T(f),ee=_!==null&&!v,te=n||d&&!C||g||ee;return A(Wy,{title:o.title,description:o.description,overlay:A(ue,{children:[ee&&A(WP,{captcha:_,deploymentId:i,onToken:b,onFallback:x},y),g&&a?A(BP,{onSubmit:a.setPassword}):null]}),children:[A(MP,{class:`btn-neutral rounded-box`,onClick:()=>{d&&C&&!f&&__(i,c),t()},disabled:te,loading:n,children:s}),u&&A(`div`,{class:`max-w-xs`,children:p?A(`label`,{for:S,class:`flex items-center gap-2 text-xs text-left cursor-pointer`,children:[A(`input`,{id:S,type:`checkbox`,class:`checkbox checkbox-secondary checkbox-xs mt-0.5 shrink-0`,checked:C,onChange:e=>w(e.target.checked)}),A(`span`,{class:`leading-snug`,children:c})]}):A(`p`,{class:`text-xs leading-snug text-base-content/60`,children:c})})]})}function KP({flow:e,welcomeText:t,onUnavailableCancel:n}){switch(e.state){case`idle`:return A(GP,{text:t,onStart:()=>{e.start()},isStarting:e.isStarting});case`haircheck`:return A(FP,{onJoin:()=>{e.join()},onCancel:()=>e.cancel(),isJoining:e.isStarting});case`call`:return A(AP,{onLeave:()=>e.leave()});case`ended`:return A(tb,{onRestart:()=>e.restart()});case`unavailable`:return A(Yy,{cause:e.unavailableCause??`busy`,canRetry:e.canRetry,onRetry:()=>{e.start()},onCancel:n});default:{let t=e.state;throw Error(`Unreachable flow state: ${String(t)}`)}}}var qP=Ie(null);function JP({children:e}){let{config:t}=pt(bi),n=t.peek().customization?.widget,r=n?.expandable??`default`,i=dn(r===`start-expanded`||r===`always`),a=dn(n?.variant??`full`),o=dn(n?.position??`bottom-right`),s=dn(r),c=dn(n?.avatar?.type??`orb`),l=D(r);vn(()=>{let e=t.value.customization?.widget,n=e?.expandable??`default`;a.value=e?.variant??`full`,o.value=e?.position??`bottom-right`,s.value=n,c.value=e?.avatar?.type??`orb`,l.current!==n&&(i.value=n===`start-expanded`||n===`always`,l.current=n)});let u=k(()=>{s.peek()!==`always`&&(i.value=!i.peek())},[i,s]),d=k(()=>{i.value=!0},[i]),f=k(()=>{s.peek()!==`always`&&(i.value=!1)},[i,s]),p=O(()=>({expanded:i,variant:a,position:o,expandable:s,avatarType:c,toggle:u,expand:d,collapse:f}),[i,a,o,s,c,u,d,f]);return A(qP.Provider,{value:p,children:e})}function YP(){let{config:e}=K_(),t=e.value.customization.branding;return e.value.show_tavus_branding!==!1&&!t?.hide_tavus_badge?A(XP,{}):t?.logo||t?.text?A(ZP,{logo:t.logo,text:t.text}):null}function XP(){let{isDark:e}=Yj(),t=e.value?`white`:`#140206`;return A(`a`,{href:`https://tavus.io`,target:`_blank`,rel:`noopener noreferrer`,class:`inline-flex items-center gap-1 text-xs text-base-content/50 hover:text-base-content/80 transition-colors`,children:[A(`svg`,{viewBox:`0 0 488 452`,class:`h-2.5 w-2.5 shrink-0`,fill:`none`,"aria-hidden":`true`,children:[A(`path`,{d:`M160 152V208H104V152H160Z`,fill:t}),A(`path`,{"fill-rule":`evenodd`,"clip-rule":`evenodd`,d:`M488 270.5L436 285L451 326L418.766 346L441 360L423 392L435 452H0V0H394.766L488 270.5ZM24 24V428H216.2L209 392L227 360L204.766 346L237 326L222 285L274 270.5L189.038 24H24ZM352 152C336.536 152 324 164.536 324 180C324 195.464 336.536 208 352 208C367.464 208 380 195.464 380 180C380 164.536 367.464 152 352 152Z`,fill:t})]}),A(`span`,{children:[`Powered by `,A(`span`,{class:`underline`,children:`Tavus`})]})]})}function ZP({logo:e,text:t}){return A(`div`,{class:`inline-flex items-center gap-1 text-xs text-base-content/50`,children:[e?A(`img`,{src:e,alt:t||`Branding`,class:`h-2.5 shrink-0`}):null,t?A(`span`,{children:t}):null]})}var QP={title:`Hi! Want to chat?`,btn_title:`Start conversation`};function $P(){let{config:e}=K_(),t=e.value.customization.widget?.text;return O(()=>({title:t?.title||QP.title,btn_title:t?.btn_title||QP.btn_title}),[t])}function eF(){let e=pt(qP);if(!e)throw Error(`useWidgetUI must be used within WidgetUIProvider`);return e}var tF={xs:`w-6 h-6`,sm:`w-8 h-8`,md:`w-10 h-10`,lg:`w-16 h-16`},nF={xs:`w-3 h-3`,sm:`w-4 h-4`,md:`w-5 h-5`,lg:`w-8 h-8`};function rF({size:e=`md`,className:t=``}){let{avatarType:n}=eF(),{config:r}=K_(),i=Ly(r.value);return(Ry(r.value).background.type===`replica`||n.value===`image`)&&i?A(`div`,{class:`relative ${tF[e]} rounded-box overflow-hidden bg-base-300 ${t}`,children:i.kind===`image`?A(`img`,{src:i.url,class:`absolute inset-0 w-full h-full object-cover`,loading:`lazy`,alt:``}):A(`video`,{src:i.url,class:`absolute inset-0 w-full h-full object-cover`,muted:!0,autoplay:!0,loop:!0,playsinline:!0})}):A(`div`,{class:`relative ${tF[e]} rounded-box bg-primary/15 flex items-center justify-center ${t}`,children:A(`span`,{class:`${nF[e]} rounded-full bg-primary animate-pulse`})})}function iF({variant:e}){let{toggle:t}=eF(),n=$P();return e===`tiny`?A(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`rounded-box overflow-hidden shadow-xl hover:shadow-2xl transition-shadow cursor-pointer`,children:A(rF,{size:`lg`})}):e===`compact`?A(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`group flex items-center gap-2.5 py-2.5 pl-2.5 pr-8 rounded-box bg-base-100 text-base-content border border-base-300 shadow-lg hover:shadow-xl transition-shadow cursor-pointer text-left`,children:[A(rF,{size:`md`}),A(`span`,{class:`flex flex-col gap-0.5`,children:[A(`span`,{class:`text-base font-medium leading-tight`,children:n.title}),A(`span`,{class:`text-sm text-base-content/60 leading-tight`,children:n.btn_title})]})]}):A(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`flex flex-col gap-3 p-3 w-64 rounded-box bg-base-100 text-base-content border border-base-300 shadow-xl hover:shadow-2xl transition-shadow cursor-pointer text-left`,children:[A(`div`,{class:`flex items-center gap-2.5`,children:[A(rF,{size:`md`}),A(`span`,{class:`text-sm font-medium leading-snug`,children:n.title})]}),A(`span`,{class:`btn btn-primary btn-sm w-full pointer-events-none gap-2 flex items-center`,children:[A(Ny,{name:`cam`,size:16}),A(`span`,{className:`leading-4`,children:n.btn_title})]})]})}var aF=`tavus:widget:greeting-dismissed`;function oF({anchor:e}){let t=$P(),{variant:n,expand:r}=eF(),[i,a]=T(!1);E(()=>{if(n.value===`tiny`){try{if(sessionStorage.getItem(aF)===`1`)return}catch{}a(!0)}},[n]);let o=k(e=>{e.stopPropagation();try{sessionStorage.setItem(aF,`1`)}catch{}a(!1)},[]);if(!i)return null;let s=e===`right`?`right-[-6px] border-r border-b`:`left-[-6px] border-l border-t`,c=e===`right`?`-right-2`:`-left-2`;return A(`button`,{type:`button`,onClick:r,class:`relative max-w-56 rounded-box bg-base-100 text-base-content shadow-lg border border-base-300 px-3 py-2 text-sm text-left cursor-pointer animate-[tavusFadeUp_240ms_ease-out] hover:bg-base-200 transition-colors`,children:[A(`p`,{class:`leading-snug pr-3`,children:t.title}),A(`span`,{role:`button`,tabIndex:0,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o(e)},class:`absolute -top-2 ${c} btn btn-ghost btn-circle btn-xs bg-base-100 border border-base-300 shadow-sm`,"aria-label":`Dismiss`,children:`×`}),A(`span`,{class:`absolute bottom-3 w-3 h-3 rotate-45 bg-base-100 border-base-300 ${s}`})]})}function sF(){let e=pt(fv);if(!e)throw Error(`useHostBridge must be used within HostBridgeProvider`);return e}var cF=`bg-base-100 text-base-content rounded-box border border-base-300 shadow-xl w-[22rem] flex flex-col animate-[tavusPopIn_180ms_ease-out]`,lF=`bg-base-100 text-base-content w-[100vw] h-[100dvh] flex flex-col animate-[tavusFadeUp_180ms_ease-out]`,uF=`p-1 flex-1 min-h-0`,dF=`p-1 flex-1 min-h-0`;function fF({variant:e,children:t,fullscreen:n}){let{collapse:r,expandable:i}=eF(),a=i.value!==`always`;return n?A(`div`,{class:lF,children:[A(`div`,{class:`flex items-center justify-end gap-2 px-2.5 py-1.5 border-b border-base-300`,children:a&&A(`button`,{type:`button`,class:`btn btn-ghost btn-circle btn-xs`,onClick:r,"aria-label":`Close`,children:A(Ny,{name:`close`,size:14})})}),A(`div`,{class:dF,children:t}),A(`div`,{class:`flex justify-end px-2.5`,children:A(YP,{})})]}):A(`div`,{class:`flex flex-col h-[min(34rem,calc(100dvh-3rem))]`,children:[A(`div`,{class:`${cF} flex-1 overflow-hidden`,children:[A(`div`,{class:`flex items-center justify-end gap-2 px-2.5 pt-1.5 shrink-0`,children:a&&A(`button`,{type:`button`,class:`btn btn-ghost btn-circle btn-xs`,onClick:r,"aria-label":`Close`,children:A(Ny,{name:`close`,size:14})})}),A(`div`,{class:uF,children:t})]}),A(`div`,{class:`flex justify-end pr-2 pt-1.5 shrink-0`,children:A(YP,{})})]})}var pF=yn(`Widget`),mF=`1rem`,hF=480;function gF(){return typeof window>`u`?!1:window.innerWidth<=hF}function _F(e){switch(e){case`bottom-right`:return{bottom:mF,right:mF};case`bottom-left`:return{bottom:mF,left:mF};case`top-right`:return{top:mF,right:mF};case`top-left`:return{top:mF,left:mF};case`top`:return{top:mF,left:`50%`,transform:`translateX(-50%)`};case`bottom`:return{bottom:mF,left:`50%`,transform:`translateX(-50%)`}}}var vF=[`top`,`bottom`,`left`,`right`,`transform`];function yF(e){return e===`bottom-left`||e===`top-left`?`left`:`right`}function bF(){let{config:e,initError:t}=K_(),n=$P(),{expanded:r,position:i,variant:a}=eF(),{shadowHost:o}=sF(),s=Xy(),c=dn(gF());E(()=>{if(typeof window>`u`)return;c.value=gF();let e=()=>{c.value=gF()};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[c]);let l=O(()=>({fallback_button:n.btn_title}),[n.btn_title]);if(vn(()=>{let e=o.value,t=i.value,n=r.value,a=n&&c.value;if(e){if(a)e.style.top=`0`,e.style.right=`0`,e.style.bottom=`0`,e.style.left=`0`,e.style.transform=``;else{let n=_F(t);for(let t of vF)e.style[t]=n[t]??``}e.dataset.tavusWidgetPosition=t,e.dataset.tavusWidgetExpanded=n?`true`:`false`,e.dataset.tavusWidgetFullscreen=a?`true`:`false`,e.dataset.tavusWidgetSmall=c.value?`true`:`false`}}),t.value)return pF.error(`Widget cannot initialize (init request failed):`,t.value),null;if(e.value.is_available===!1&&e.value.unavailable_reason===`total_limit`)return pF.error(`Widget is unavailable (total_limit reached) — not rendering`),null;if(!r.value){let e=yF(i.value),t=e===`right`?`flex items-end gap-2 justify-end`:`flex items-end gap-2 flex-row-reverse justify-end`,n=e===`right`?`justify-end pr-2`:`justify-start pl-2`;return A(`div`,{class:`flex flex-col`,children:[A(`div`,{class:t,children:[A(oF,{anchor:e}),A(iF,{variant:a.value})]}),A(`div`,{class:`flex ${n} pt-1.5`,children:A(YP,{})})]})}return e.value.is_available===!1?A(fF,{variant:a.value,fullscreen:c.value,children:A(Ev,{children:A(Yy,{cause:e.value.unavailable_reason??`daily_limit`,canRetry:!1,onRetry:()=>{}})})}):A(fF,{variant:a.value,fullscreen:c.value,children:A(Ev,{children:A(KP,{flow:s,welcomeText:l,onUnavailableCancel:()=>s.restart()})})})}var xF=`: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:aD().optional().describe(`Whether the device supports touch input.`),hover:aD().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:Uj.describe(`Partial context update containing only changed fields.`)});var Wj=Z({method:$(`ui/update-model-context`),params:Z({content:X(_A).optional().describe(`Context content blocks (text, image, etc.).`),structuredContent:pD(J(),cD().describe(`Structured content for machine-readable context data.`)).optional().describe(`Structured content for machine-readable context data.`)})}),Gj=Z({method:$(`ui/initialize`),params:Z({appInfo:sk.describe(`App identification (name and version).`),appCapabilities:Lj.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:sk.describe(`Host application identification and version.`),hostCapabilities:Ij.describe(`Features and capabilities provided by the host.`),hostContext:Uj.describe(`Rich context about the host environment.`)}).passthrough();var Kj=[Sj],qj=class extends xj{_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:Aj,sandboxready:Dj,initialized:Rj,requestteardown:Fj,loggingmessage:PA};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(Gj,e=>this._oninitialize(e)),this.setRequestHandler(_k,(e,t)=>(this.onping?.(e.params,t),{})),this.replaceRequestHandler(zj,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(Hj,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(Ej,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(Vj,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(zj,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(Wj,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(OA,async(e,t)=>{if(!this._oncalltool)throw Error(`No oncalltool handler set`);return this._oncalltool(e.params,t)})}set oncreatesamplingmessage(e){this.setRequestHandler(HA,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(Wk,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(Kk,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(Xk,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(sA,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:Kj.includes(t)?t:Sj,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];Jj(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},Nj,t)}sendResourceTeardown=this.teardownResource;callTool(e,t){return this.request({method:`tools/call`,params:e},EA,t)}listTools(e,t){return this.request({method:`tools/list`,params:e},TA,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},EA,{signal:t.signal}),e.tools.listChanged&&this._client.setNotificationHandler(kA,e=>this.sendToolListChanged(e.params))),e.resources&&(this.onlistresources=async(e,t)=>this._client.request({method:`resources/list`,params:e},Gk,{signal:t.signal}),this.onlistresourcetemplates=async(e,t)=>this._client.request({method:`resources/templates/list`,params:e},qk,{signal:t.signal}),this.onreadresource=async(e,t)=>this._client.request({method:`resources/read`,params:e},Zk,{signal:t.signal}),e.resources.listChanged&&this._client.setNotificationHandler(Qk,e=>this.sendResourceListChanged(e.params))),e.prompts&&(this.onlistprompts=async(e,t)=>this._client.request({method:`prompts/list`,params:e},cA,{signal:t.signal}),e.prompts.listChanged&&this._client.setNotificationHandler(bA,e=>this.sendPromptListChanged(e.params)))}return super.connect(e)}};function Jj(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Yj(){let e=pt(hv);if(!e)throw Error(`useTheme must be used within ThemeProvider`);return e}var Xj=new Set([`mcp-ui.tavus.io`,`mcp-ui.tavus-preview.io`]),Zj=[`.sandbox-tavus.io`],Qj=new Set([`tavusapi.com`]);function $j(e){let t;try{t=new URL(e)}catch{return!1}return nM(t)?!0:t.protocol===`https:`?Xj.has(t.hostname)?!0:Zj.some(e=>t.hostname.endsWith(e)):!1}function eM(e){return $j(e)}function tM(e){let t;try{t=new URL(e)}catch{return!1}return rM(t)?!0:t.protocol===`https:`&&Qj.has(t.hostname)}function nM(e){return rM(e)}function rM(e){return!iM()||e.protocol!==`http:`&&e.protocol!==`https:`?!1:[`localhost`,`127.0.0.1`,`::1`,`[::1]`].includes(e.hostname)}function iM(){try{let e=globalThis.location?.hostname;return typeof e==`string`&&[`localhost`,`127.0.0.1`,`::1`,`[::1]`].includes(e)}catch{return!1}}async function aM(e){try{await e.teardownResource({},{timeout:1e3})}catch{}try{await e.close?.()}catch{}}var oM=`tavus.canvas.interaction`,sM=[`safe-area-right`,`safe-area-left`,`safe-area-bottom`,`full`],cM=`safe-area-right`,lM={x:275/1280,y:111/720,width:730/1280,height:609/720},uM={type:`snapshot_mirror`};function dM(e){return NM(e)?e.message_type===`conversation`&&e.event_type===`conversation.tool_call`&&typeof e.conversation_id==`string`&&NM(e.properties):!1}function fM(e){if(!NM(e))return null;let t=qM(e,`component`),n=qM(e,`component_version`),r=qM(e,`sandbox_url`),i=XM(e,`mcp_server_url`,eM),a=XM(e,`api_base_url`,tM),o=XM(e,`interaction_url`,tM),s=LM(e.layout),c=e.version;return c!==1||!t||!n||!r||!$j(r)||i===null||a===null||o===null||s===null?null:{version:c,component:t,component_version:n,resource_uri:qM(e,`resource_uri`),sandbox_url:r,mcp_server_url:i,mcp_tool_name:qM(e,`mcp_tool_name`),api_base_url:a,interaction_url:o,layout:s,host_context:NM(e.host_context)?e.host_context:void 0}}function pM(e){if(e===void 0)return{ok:!0,value:{}};if(NM(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 NM(t)?{ok:!0,value:t}:{ok:!1,error:Error(`Magic Canvas tool arguments must decode to an object.`)}}catch(e){return{ok:!1,error:PM(e)}}}function mM(e){let t=e.properties.name;if(t!==`canvas_clear`&&t!==`update_component`)return null;let n=pM(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(!NM(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 hM=[`safe-area-left`,`safe-area-right`];function gM(e){let t=hM.includes(e.preferred_slot)?e.preferred_slot:cM;return t===e.preferred_slot&&e.display_mode===`inline`?e:{...e,preferred_slot:t,display_mode:`inline`}}function _M(e){return e.display_mode===`fullscreen`?`full`:e.preferred_slot}function vM(e,t){return[t]}function yM(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 vM(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:gM({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&&_M(o.layout)===_M(i.layout)?a:vM(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 bM(e){if(!NM(e)||!Array.isArray(e.content))return null;for(let t of e.content){if(!NM(t))continue;let e=(NM(t._meta)?t._meta:null)?.[oM];if(NM(e))return ZM(e)}return null}function xM(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??MM(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:NM(t.metadata)?t.metadata:{}}}function SM(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 CM(e){return!NM(e)||!Array.isArray(e.content)?``:e.content.map(e=>NM(e)&&e.type===`text`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
|
|
160
|
+
`).trim()}function wM(e,t){let n=NM(t.structuredContent)?t.structuredContent:void 0,r=FM(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: ${IM(n)}`),r&&r!==a&&o.push(r),o.join(`
|
|
161
|
+
`)}function TM({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:gM({preferred_slot:i.preferredSlot??r.layout?.preferred_slot??AM(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??lM,backdrop:i.backdrop??r.layout?.backdrop??uM}),revision:0}}function EM(e,t){let n=e.layout.display_mode;return{...e.layout,display_mode:n,viable_slot:n===`fullscreen`?`full`:OM(e.layout.preferred_slot,t)}}function DM(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:uM};let a=[...n].reverse()[0];if(!a||t.width<900)return{active:!1,video_shift_x:0,backdrop:uM};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`?YM(16+o+24-c,0,u):-YM(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 OM(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:RM(e.layout)??RM(e.preferred_slot)??RM(e.preferredSlot),displayMode:zM(e),avoidSafeArea:BM(e),safeArea:VM(e),backdrop:HM(e)}}function AM(e){switch(e){case`canvas.alert`:return`safe-area-bottom`;case`canvas.chart`:case`canvas.image`:case`canvas.video`:return`full`;default:return cM}}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 MM(e,t){return`ci_${e.replace(/[^a-zA-Z0-9_-]/g,`_`)}_${t}_${globalThis.crypto?.randomUUID?.()??Math.random().toString(36).slice(2,10)}`}function NM(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function PM(e){return e instanceof Error?e:Error(String(e))}function FM(e){return Array.isArray(e)?e.map(e=>NM(e)&&e.type===`text`&&typeof e.text==`string`?e.text:``).filter(Boolean).join(`
|
|
162
|
+
`).trim():``}function IM(e){let t=JSON.stringify(e);return t?t.length<=2e3?t:`${t.slice(0,2e3)}...`:`{}`}function LM(e){if(e===void 0)return;if(!NM(e))return null;let t=RM(e),n=UM(e.safe_area??e.safeArea),r=WM(e.backdrop);return n===null||r===null?null:{...t?{preferred_slot:t}:{},...GM(e.avoid_safe_area??e.avoidSafeArea,`avoid_safe_area`),...n?{safe_area:n}:{},...r?{backdrop:r}:{}}}function RM(e){if(typeof e==`string`&&KM(e))return e;if(!NM(e))return;let t=e.preferred_slot??e.preferredSlot??e.slot;return typeof t==`string`&&KM(t)?t:void 0}function zM(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 BM(e){let t=NM(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 VM(e){let t=NM(e.layout)?e.layout:void 0;return UM(e.safe_area??e.safeArea??t?.safe_area??t?.safeArea)??void 0}function HM(e){let t=NM(e.layout)?e.layout:void 0;return WM(e.backdrop??t?.backdrop)??void 0}function UM(e){if(e===void 0)return;if(!NM(e))return null;let t=JM(e,`x`),n=JM(e,`y`),r=JM(e,`width`),i=JM(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:YM(t,0,1),y:YM(n,0,1),width:YM(r,0,1),height:YM(i,0,1)}}function WM(e){if(e===void 0)return;if(e===`snapshot_mirror`||e===`none`)return{type:e};if(!NM(e))return null;let t=e.type;return t===`snapshot_mirror`||t===`none`?{type:t}:null}function GM(e,t){return typeof e==`boolean`?{[t]:e}:{}}function KM(e){return sM.includes(e)}function qM(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function JM(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:void 0}function YM(e,t,n){return Math.min(Math.max(e,t),n)}function XM(e,t,n){let r=qM(e,t);if(r)return n(r)?r:null}function ZM(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&&!NM(e.metadata)?null:e}function QM({state:e}){return e.enabled?A(`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:[A(`summary`,{class:`cursor-pointer font-medium`,children:`Magic Canvas debug`}),A(`dl`,{class:`mt-2 grid gap-2`,children:[A($M,{label:`iframe`,value:e.iframeLifecycleState}),A($M,{label:`post`,value:e.lastInteractionPostResult}),A($M,{label:`context`,value:e.lastModelContextUpdate}),A($M,{label:`error`,value:e.lastError}),A(eN,{label:`tool_call`,value:e.lastToolCall}),A(eN,{label:`canvas_config`,value:e.parsedCanvasConfig})]})]}):null}function $M({label:e,value:t}){return t?A(`div`,{children:[A(`dt`,{class:`font-semibold`,children:e}),A(`dd`,{class:`break-words text-base-content/70`,children:t})]}):null}function eN({label:e,value:t}){return t===void 0?null:A(`div`,{children:[A(`dt`,{class:`font-semibold`,children:e}),A(`dd`,{children:A(`pre`,{class:`max-h-40 overflow-auto rounded bg-base-200 p-2 text-[10px] leading-relaxed`,children:JSON.stringify(t,null,2)})})]})}var tN=`tavus-deployment magic-canvas/0.0.0`;function nN(e){if(!dM(e)||e.canvas_config===void 0||e.canvas_config===null)return null;let t=fM(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=pM(e.properties.arguments);if(!r.ok)throw r.error;return TM({conversationId:e.conversation_id,toolCallId:n,args:r.value,canvasConfig:t})}function rN(e){if(!dM(e))return null;if(e.canvas_config!==void 0&&e.canvas_config!==null){let t=nN(e);return t?{kind:`show`,instance:t}:null}return mM(e)}function iN(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 aN(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:tN,styles:{variables:oN(e.cssVars)}}}function oN(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`,...sN(e)}}function sN(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 cN=1e3,lN=5e3,uN=1200,dN=48,fN=`allow-scripts`,pN={"canvas.scheduling_embed":`allow-scripts allow-same-origin allow-popups allow-forms`};function mN(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 hN=class{onmessage;onerror;onclose;#e;#t;constructor(e){this.#e=e}start(){let e=e=>{mN(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 gN(e){for(let t of sM)if(e.some(e=>jN(e)===t))return t;return null}function _N({onLayoutEffectChange:e,onRenderedSlotChange:t,debugEnabled:n=MN()}={}){let{client:r}=K_(),{dataTheme:i,cssVars:a}=Yj(),o=oh(),s=Mg(),[c,l]=T([]),[u,d]=EN(),[f,p]=T(()=>({enabled:n,iframeLifecycleState:`idle`})),m=k(e=>{p(t=>({...t,...e}))},[]),h=k((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=O(()=>({theme:i.value===`dark`?`dark`:`light`,cssVars:a.value}),[i.value,a.value]);E(()=>{p(e=>e.enabled===n?e:{...e,enabled:n})},[n]),Wg({onAppMessage:k(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=rN(e.data);if(!t)return;l(e=>yM(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:FN(e).message})}},[s,m])});let _=c.map(e=>({instance:e,layout:EM(e,d)})),v=DM(_.map(({layout:e})=>e),d),y=[..._].reverse().find(({layout:e})=>e.display_mode===`fullscreen`)?.instance.tool_call_id;E(()=>{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=gN(_.map(({layout:e})=>e));E(()=>{t?.(b)},[t,b]);let x=c.length>0||f.enabled;return A(`div`,{ref:u,"data-magic-canvas-root":!0,class:`pointer-events-none absolute inset-0 z-30`,children:[x&&y&&A(`div`,{class:`absolute inset-0 bg-black/45`}),x&&sM.map(e=>{let t=_.filter(({layout:t})=>jN(t)===e);return t.length===0?null:A(yN,{slot:e,safeAreaTop:v.safe_area?.y,frameWidth:d.width,children:e=>t.map(({instance:t,layout:n})=>A(bN,{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&&A(`div`,{class:`absolute right-4 bottom-24 @max-mobile:right-3 @max-mobile:bottom-20`,children:A(QM,{state:f})})]})}var vN=16;function yN({slot:e,safeAreaTop:t,frameWidth:n,children:r}){let[i,a]=DN(),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-vN*2):void 0;return A(`div`,{ref:i,class:AN(e),style:{top:r,bottom:`${kN}px`,maxWidth:a},"data-canvas-slot":e,children:A(`div`,{class:`my-auto flex w-full flex-col gap-2`,children:o})})}return A(`div`,{ref:i,class:AN(e),"data-canvas-slot":e,children:o})}function bN({availableHeight:e,client:t,hostTheme:n,instance:r,layout:i,dimmed:a,onDebug:o,onComplete:s,onDisplayModeChange:c,sendAppMessage:l}){let u=D(null),d=D(null),f=D(e),p=D(320),m=D(n),h=D(r),g=D(i),_=D(-1),v=D(s),y=D(c),b=D(l),[x,S]=T(320);E(()=>{h.current=r},[r]),E(()=>{p.current=x,d.current?.setHostContext(wN(h.current,m.current,g.current,f.current,x))},[x]),E(()=>{f.current=e;let t=CN(n,u.current);m.current=t,d.current?.setHostContext(wN(h.current,t,g.current,e,p.current))},[e,n]),E(()=>{g.current=i,d.current?.setHostContext(wN(h.current,m.current,i,e,p.current))},[e,i]),E(()=>{v.current=s,y.current=c,b.current=l},[s,c,l]),E(()=>{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:FN(e).message})},C=()=>{if(n||!a)return;let e=h.current,t=wM(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 qj(null,{name:`tavus-deployment`,version:`0.0.0`},{logging:{},message:{text:{},structuredContent:{}},updateModelContext:{text:{},structuredContent:{}}},{hostContext:wN(r,CN(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,dN),720))},u.onmessage=async e=>{let r=bM(e),i=CM(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=xM(e,r),s=iN(a),l=new AbortController,u=globalThis.setTimeout(()=>l.abort(),lN);try{await En(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}),SM(a)&&(a.type===`submit`?(c&&clearTimeout(c),c=setTimeout(()=>{c=null,n||v.current()},uN)):v.current())}catch(e){let t=FN(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()},cN),{}),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(wN(h.current,m.current,g.current,f.current,p.current)),{mode:t}},u.connect(new hN(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&&aM(i)}},[t,r.id,r.canvas_config.sandbox_url,o]),E(()=>{r.revision!==0&&(r.revision<=_.current||(_.current=r.revision,d.current?.sendToolInput({arguments:r.arguments}).catch(e=>{o({iframeLifecycleState:`error`,lastError:FN(e).message})})))},[r.arguments,r.revision,o]);let C=i.viable_slot===`full`||i.display_mode===`fullscreen`,w=C?null:TN(x,e),ee=w?.placeholderStyle,te=w?.cardStyle,ne=C?{height:`100%`}:w?.iframeStyle??{height:`${x}px`},re=[`pointer-events-auto w-full overflow-hidden rounded-lg border border-base-300 bg-base-100 shadow-xl transition-[opacity,transform]`,C?`fixed inset-4 z-10 max-w-none`:`max-w-md`,a?`scale-[0.98] opacity-40`:``].filter(Boolean).join(` `),ie=pN[r.canvas_config.component]??fN,ae=A(`div`,{class:re,style:te,"data-canvas-card":i.viable_slot,children:A(`iframe`,{ref:u,title:`${r.canvas_config.component} ${r.canvas_config.component_version}`,class:C?`block h-full w-full border-0 bg-transparent`:`block border-0 bg-transparent`,sandbox:ie,style:ne})});return C?ae:A(`div`,{class:`block w-full`,style:ee,children:ae})}var xN=[`--color-base-100`,`--color-base-200`,`--color-base-300`,`--color-base-content`,`--color-primary`,`--color-error`];function SN(e){if(!e||typeof getComputedStyle!=`function`)return{};let t=getComputedStyle(e),n={};for(let e of xN){let r=t.getPropertyValue(e).trim();r&&(n[e]=r)}return n}function CN(e,t){let n=SN(t);return Object.keys(n).length===0?e:{...e,cssVars:{...e.cssVars,...n}}}function wN(e,t,n,r,i){let a=aN(t,n),o=n.viable_slot===`full`||n.display_mode===`fullscreen`,s=o?void 0:NN(r),c=o?1:TN(i??0,r)?.displayScale??1;return{...e.canvas_config.host_context,...a,containerDimensions:{...PN(a.containerDimensions)?a.containerDimensions:{},...s===void 0?{}:{maxHeight:s},displayScale:c}}}function TN(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 EN(){let e=D(null),[t,n]=T(()=>ON(null));return E(()=>{let t=()=>n(t=>{let n=ON(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 DN(){let e=D(null),[t,n]=T();return E(()=>{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 ON(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 kN=72;function AN(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 jN(e){return e.display_mode===`fullscreen`&&e.preferred_slot!==`full`?e.preferred_slot:e.viable_slot}function MN(){return!1}function NN(e){return e===void 0||!Number.isFinite(e)||e<=0?720:Math.min(Math.floor(e),720)}function PN(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function FN(e){return e instanceof Error?e:Error(String(e))}var IN=24,LN=96;function RN(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 zN(e){let t=e?.getRootNode();return t instanceof ShadowRoot?t:document}function BN(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 VN(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??lM,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 HN(e,t,n){let[r,i]=T(()=>e?RN(zN(n?.current)):null);return dt(()=>{if(!e){i(null);return}let t=zN(n?.current),r=()=>i(RN(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 UN(e,t,n){let[r,i]=T(()=>t?BN(e.current):null);return dt(()=>{if(!t){i(null);return}let n=()=>i(BN(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 WN(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`&&VN(e,r,i,a)),side:o}}function GN(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>=LN&&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-IN*2),g=Math.max(LN,Math.min(h,c-IN*2));return{centerX:(u+d)/2-r,centerY:(f+p)/2-a,diameter:g}}var KN=`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 qN(e,t){let n=Math.abs(t)/2;return e===`left`?`${n}px center`:`calc(100% - ${n}px) center`}function JN(e,t,n){let[r,i]=T(()=>e&&t?GN(t,zN(n?.current),BN(n?.current)):null);return dt(()=>{if(!e||!t){i(null);return}let r=zN(n?.current),a=()=>i(GN(t,r,BN(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 YN(e,t){let[n,r]=T(null);return dt(()=>{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 XN=1;function ZN(e,t,n){return Math.min(Math.max(e,t),n)}function QN(e,t,n,r){let i=Math.min(e.diameter/t.height,1),a=r?.safe_area??lM,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:ZN(e.centerX-o,e.centerX+c-t.width*i,e.centerX-c),ty:ZN(e.centerY-s,e.centerY+c-t.height*i,e.centerY-c)}}var $N=[`cx`,`cy`,`r`,`tx`,`ty`,`s`,`shift`];function eP(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=QN(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 tP(e,t,n){let r=D(null),i=D(e),a=D(n),o=D(0),s=D(0);i.current=e,a.current=n,E(()=>{let e=i.current;if(!e)return;if(!r.current||nP()){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 $N){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?$N.map(t=>Math.round(e[t]*100)).join():``,t]),E(()=>()=>{o.current&&globalThis.cancelAnimationFrame(o.current)},[])}function nP(){return globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1}function rP({geom:e,visible:t}){return A(`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 iP(e,t){let n=t>=0?`left`:`right`,r=D({side:n,shift:t});E(()=>{e&&(r.current={side:n,shift:t})},[e,n,t]);let i=e?n:r.current.side;return{side:i,transformOrigin:qN(i,e?t:r.current.shift),translateX:e?0:-r.current.shift}}function aP(e,t,n){return`${e.side??``}:${e.active}:${t}:${n??``}`}function oP({snapshotUrl:e,transformOrigin:t}){return A(`div`,{class:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url("${e}")`,transform:`scaleX(-1)`,transformOrigin:t}})}function sP({snapshotUrl:e,translateX:t,transition:n,transformOrigin:r}){return A(`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:A(oP,{snapshotUrl:e,transformOrigin:r})})}function cP({ambient:e,usePip:t,transition:n}){return e===`none`?null:A(`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 lP({morphCapable:e,snapshotUrl:t,mirrorSide:n,videoShiftX:r,transition:i,sceneRef:a,videoWrapRef:o,fill:s,videoRef:c}){return A(`div`,{ref:a,"data-morph":`scene`,class:`absolute inset-0`,style:e?{transformOrigin:`top left`}:void 0,children:A(`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&&A(`div`,{"aria-hidden":`true`,"data-morph":`window-mirror`,class:`absolute top-0 bottom-0 w-full`,style:n===`right`?{left:`calc(100% - ${XN}px)`}:{right:`calc(100% - ${XN}px)`},children:A(oP,{snapshotUrl:t,transformOrigin:`center`})})]})})}function uP({canvasLayoutEffect:e,smartSidecarActive:t,isScreenSharing:n,fill:r,captureSnapshot:i,transition:a=KN,transitionMs:o=560,personaMode:s=`shift`,renderedSlot:c=null,ambient:l=`default`,children:u}){let d=D(null),[f,p]=T(null),m=t&&e.backdrop.type===`snapshot_mirror`,h=t?e.video_shift_x:0,g=D(null),_=aP(e,h,c),{usePip:v,side:y}=WN(e,s,c,HN(s!==`shift`,_,g),h,UN(g,s!==`shift`,_)),b=JN(s!==`shift`,y,g),x=iP(m,h);E(()=>{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]),E(()=>{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=YN(g,C),ee=f!==null&&!C,te=C&&y!=null,ne=D(null),re=D(null),[ie,ae]=T(!0),oe=D(!0),se=k((e,t)=>{let n=ne.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=re.current;r&&(r.style.transform=`translate3d(${e.shift}px, 0, 0)`),oe.current!==t&&(oe.current=t,ae(t))},[]);return tP(C?eP(b,S,w,h,e):null,o,se),A(`div`,{ref:g,class:`relative w-full h-full overflow-hidden ${n?`flex items-center justify-center`:``}`,children:[ee&&f!==null&&A(sP,{snapshotUrl:f,translateX:x.translateX,transition:a,transformOrigin:x.transformOrigin}),te&&A(cP,{ambient:l,usePip:v,transition:a}),A(`div`,{"data-morph":`fg`,class:`absolute inset-0 z-10`,children:A(lP,{morphCapable:C,snapshotUrl:f,mirrorSide:x.side,videoShiftX:h,transition:a,sceneRef:ne,videoWrapRef:re,fill:r,videoRef:d})}),C&&b&&A(rP,{geom:b,visible:S&&ie}),u]})}var dP=1e4;function fP({onTimeout:e,timeoutMs:t=dP,active:n=!0}){let r=$b().length>0,[i,a]=T(!1),o=D(e);return E(()=>{o.current=e},[e]),E(()=>{if(!n||r){a(!1);return}let e=setTimeout(()=>{a(!0),o.current()},t);return()=>clearTimeout(e)},[n,r,t]),{hasJoined:r,timedOut:i}}function pP(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.message_type===`system`&&t.event_type===`system.shutdown`}function mP({onShutdown:e}){let t=D(e);E(()=>{t.current=e},[e]),Wg({onAppMessage:k(e=>{pP(e?.data)&&t.current()},[])})}function hP(){let e=oh();return{joinCall:k(({url:t,micOnly:n=!1})=>{e?.join(n?{url:t,videoSource:!1}:{url:t})},[e]),leaveCall:k(()=>{e?.leave()},[e])}}var gP=yn(`PiP`),_P=360,vP=280;function yP(){return globalThis.window!==void 0&&`documentPictureInPicture`in globalThis.window}function bP(e){let{enabled:t,active:n}=e,[r,i]=T(null),a=yP(),o=pt(hv),s=k(()=>{i(e=>(e&&!e.closed&&e.close(),null))},[]),c=k(async()=>{if(a&&!(!t||!n)&&!(r&&!r.closed))try{let e=await globalThis.window.documentPictureInPicture.requestWindow({width:_P,height:vP}),t=Ye.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){gP.warn(`Failed to open PiP window`,e)}},[a,t,n,r]);return E(()=>{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){gP.warn(`mediaSession metadata setup failed`,e)}let t=(t,n)=>{try{e.setActionHandler(t,n),r.push(t)}catch(e){gP.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]),E(()=>{(!n||!t)&&r&&!r.closed&&s()},[n,t,r,s]),E(()=>()=>{r&&!r.closed&&r.close()},[r]),E(()=>{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 xP=Wt(null),SP={active:!1,video_shift_x:0,backdrop:{type:`snapshot_mirror`}},CP=ba(({id:e,showAudioWave:t=!0})=>{let n=r_(e).isOff;return A(`div`,{class:`relative aspect-square w-32 @max-mobile:w-24 rounded-box overflow-hidden bg-black/30 z-10 ${n?`hidden`:``}`,children:[A(rg,{automirror:!0,sessionId:e,type:`video`,fit:`cover`,className:`w-full h-full object-cover ${n?`hidden`:``}`}),t&&A(`div`,{class:`absolute bottom-2 right-2`,children:A(Yb,{id:e})})]})}),wP=ba(()=>{let e=Uh(),{isScreenSharing:t}=ib(),n=$b()[0];return A(ue,{children:[t&&n&&A(CP,{id:n}),e&&A(CP,{id:e,showAudioWave:!1})]})}),TP=ba(()=>A(`div`,{class:`absolute top-4 left-4 flex flex-col items-end gap-2 z-20`,children:A(wP,{})})),EP=ba(({isAudioOnly:e,canvasLayoutEffect:t,canvasRenderedSlot:n})=>{let r=Uh(),i=!t_(r??``).isOff,a=ex(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`?A(qb,{}):a.phase===`connecting`?A(Kb,{}):e&&!s?A(`div`,{class:`absolute inset-0 flex items-center justify-center`,children:[A(Xb,{sessionId:a.replicaId}),A(tg,{sessionId:a.replicaId})]}):A(uP,{canvasLayoutEffect:s?{...t,backdrop:{type:`none`}}:t,smartSidecarActive:c,isScreenSharing:i,captureSnapshot:AP,personaMode:s?`shift`:`auto`,renderedSlot:n,fill:t=>A(rx,{personaSessionId:a.replicaId,localSessionId:r,isPresenting:s,isScreenSharing:i,isAudioOnly:e,avatarOff:a.videoState.isOff,videoRef:t}),children:A(tg,{sessionId:a.replicaId})})}),DP=ba(({items:e})=>{let[t,n]=T(!1),r=D(null);return E(()=>{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]),A(`div`,{ref:r,class:`relative`,children:[A(`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:A(Ny,{name:`more`})}),t&&A(`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})]})}),OP=ba(({items:e})=>e.length<=1?A(ue,{children:e}):A(DP,{items:e})),kP=ba(({onLeave:e})=>{let{joinCall:t,leaveCall:n}=hP(),r=Mg(),{config:i}=K_(),{session:a,end:o}=Nb(),s=Uh(),c=D(null),l=pt(Tv)?.frameRef??c,[u,d]=T(!1),[f,p]=T(!1),[m,h]=T(SP),[g,_]=T(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}=bP({enabled:C,active:r===`joined-meeting`});E(()=>(v&&t({url:v,micOnly:!s}),()=>{n()}),[]);let{camera:ee,requestCamera:te}=lb(),{isCamMuted:ne}=nb(),re=ee.isGranted&&!ne;E(()=>{!b&&r===`joined-meeting`&&(xP.value=re)},[b,r,re]);let ie=D(!b&&!s&&xP.value===!0);E(()=>{r===`joined-meeting`&&ie.current&&(ie.current=!1,te())},[r,te]),E(()=>{(r===`left-meeting`||r===`error`)&&e()},[r,e]),E(()=>{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 ae=k(()=>{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?.()},[]);k(()=>{p(e=>!e)},[]);let oe=k(()=>{o(),n()},[o]);if(fP({active:r===`joined-meeting`,onTimeout:oe}),mP({onShutdown:oe}),!v)return null;let se=[A(Mb,{compact:!0},`screen-share`)];return x&&se.push(A(Hb,{compact:!0},`chat`)),A(Fb,{children:A(Bb,{children:A(gb,{children:[A(`div`,{class:`absolute inset-0`,children:[A(`div`,{class:`relative w-full h-full z-[5]`,children:[A(EP,{isAudioOnly:b,canvasLayoutEffect:m,canvasRenderedSlot:g}),!b&&A(TP,{}),A(Rb,{}),A(_N,{debugEnabled:f,onLayoutEffectChange:h,onRenderedSlotChange:_}),A(`div`,{class:`absolute top-4 right-4 z-20`,children:A(Jb,{active:u,onToggle:ae,compact:!0})})]}),A(Wb,{}),A(`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:A(`div`,{class:`flex justify-center items-center gap-2 @max-mobile:gap-1 ${r===`left-meeting`?``:`pointer-events-auto`}`,children:[A(Db,{}),!b&&A(kb,{}),S&&A(Lb,{}),A(OP,{items:se}),A(`button`,{type:`button`,class:`btn btn-control btn-error`,onClick:oe,"aria-label":`Leave call`,children:A(Ny,{name:`leave`,"aria-label":`Leave Call`})})]})})]}),w&&La(A(nx,{onLeave:oe}),w.document.body)]})})})});function AP(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 jP({loading:e=!1,disabled:t,class:n,children:r,...i}){return A(`button`,{type:`button`,class:`btn relative ${n?` ${n}`:``}`,disabled:t||e,"aria-busy":e||void 0,...i,children:[A(`span`,{children:r}),e&&A(`span`,{class:`absolute inset-0 flex items-center justify-center backdrop-blur-xs`,"aria-hidden":`true`,children:A(`span`,{class:`loading loading-spinner loading-sm`})})]})}function MP(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 NP({message:e}){return A(`div`,{class:`relative max-w-[min(20rem,90%)]`,children:[A(`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}),A(`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:A(`path`,{d:`M0 0 L8 8 L16 0 Z`,fill:`currentColor`})})]})}var PP=ba(({text:e,isJoining:t=!1,onJoin:n,onCancel:r})=>{let i=oh(),{config:a}=K_(),{localSessionId:o,isCamMuted:s}=nb(),{mic:c,camera:l,requestMic:u,requestCamera:d}=lb(),f=a.value.customization.conversation.modality===`video`;E(()=>{u()},[]);let p=c.isGranted,m=D(!1);E(()=>{!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=MP(e,c.status,h);return A(gb,{children:A(`div`,{class:`absolute inset-0 motion-safe:animate-[tavusFadeUp_280ms_ease-out]`,children:[l.isGranted&&!s?A(`div`,{class:`absolute inset-0 flex items-center justify-center bg-black overflow-hidden`,children:A(rg,{type:`video`,sessionId:o??``,mirror:!0,fit:`cover`,className:`w-full h-full object-cover!`})}):A(`div`,{class:`absolute inset-0 flex items-center justify-center text-base-content/40`,children:A(Ny,{name:`face-smile`,size:`7rem`,"aria-label":`Camera off`})}),A(`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&&A(NP,{message:g}),A(`div`,{class:`flex flex-wrap items-center justify-center gap-1.5 @max-mobile:gap-1`,children:[A(`div`,{class:`flex items-center justify-center gap-1.5 shrink-0 @max-mobile:gap-1`,children:[A(Db,{}),f&&A(kb,{})]}),A(jP,{class:`btn-accent `,loading:t,disabled:!p,onClick:n,children:e?.join??`Join Video Chat`}),c.isBlocked&&A(`button`,{type:`button`,class:`btn btn-error `,onClick:()=>{i&&i.leave(),r?.()},children:e?.cancel??`Cancel`})]})]})]})})}),FP=`Password required`,IP=`Enter the password to start this conversation.`,LP=`Password`,RP=`Continue`;function zP({onSubmit:e,text:t,isSubmitting:n=!1,errorMessage:r}){let[i,a]=T(``),o=ht();return A(`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:A(`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:A(`div`,{class:`card-body gap-3`,children:[A(`h3`,{id:`${o}-title`,class:`card-title text-base-content`,children:t?.title??FP}),A(`p`,{class:`text-sm text-base-content/70`,children:t?.description??IP}),A(`input`,{id:o,type:`password`,autocomplete:`current-password`,class:`input input-bordered w-full`,placeholder:t?.placeholder??LP,value:i,disabled:n,onInput:e=>a(e.target.value),autoFocus:!0}),r&&A(`p`,{class:`text-error text-xs`,role:`alert`,children:r}),A(jP,{class:`btn-primary`,type:`submit`,disabled:!i.trim(),loading:n,children:t?.submit??RP})]})})})}var BP=yn(`CaptchaChallenge`),VP=1;function HP(e){return typeof e==`object`&&!!e&&e.source===`tavus-captcha`&&typeof e.type==`string`}function UP({captcha:e,deploymentId:t,onToken:n,onFallback:r}){let i=(pt(wt).baseUrl??`https://tavusapi.com`).replace(/\/+$/,``).split(`/`).slice(0,3).join(`/`),[a,o]=T(0),[s,c]=T(0),[l,u]=T(!1),[d,f]=T(!1),p=`${i}${e.challenge_path}?deployment_uuid=${encodeURIComponent(t)}&action=${encodeURIComponent(e.action)}&parent_origin=${encodeURIComponent(window.location.origin)}`,m=k(()=>{f(!1),o(e=>e+1)},[]);return E(()=>{function e(e){if(l||e.origin!==i)return;let a=e.data;if(HP(a)&&a.deployment_uuid===t){if(a.type===`interactive`){f(!0);return}if(a.type===`token`&&a.token){BP.info(`Captcha token received`),f(!1),n(a.token);return}if(a.type===`expired`){BP.info(`Captcha token expired, reloading iframe`),m();return}a.type===`error`&&(BP.warn(`Captcha error received`,a.code),s<VP?(c(e=>e+1),m()):(BP.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:A(`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:A(`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 WP({text:e,onStart:t,isStarting:n}){let{config:r,deploymentId:i}=K_(),a=pt(L_),o=Ry(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=O(()=>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=ht(),[C,w]=T(f),ee=_!==null&&!v,te=n||d&&!C||g||ee;return A(Wy,{title:o.title,description:o.description,overlay:A(ue,{children:[ee&&A(UP,{captcha:_,deploymentId:i,onToken:b,onFallback:x},y),g&&a?A(zP,{onSubmit:a.setPassword}):null]}),children:[A(jP,{class:`btn-neutral rounded-box`,onClick:()=>{d&&C&&!f&&__(i,c),t()},disabled:te,loading:n,children:s}),u&&A(`div`,{class:`max-w-xs`,children:p?A(`label`,{for:S,class:`flex items-center gap-2 text-xs text-left cursor-pointer`,children:[A(`input`,{id:S,type:`checkbox`,class:`checkbox checkbox-secondary checkbox-xs mt-0.5 shrink-0`,checked:C,onChange:e=>w(e.target.checked)}),A(`span`,{class:`leading-snug`,children:c})]}):A(`p`,{class:`text-xs leading-snug text-base-content/60`,children:c})})]})}function GP({flow:e,welcomeText:t,onUnavailableCancel:n}){switch(e.state){case`idle`:return A(WP,{text:t,onStart:()=>{e.start()},isStarting:e.isStarting});case`haircheck`:return A(PP,{onJoin:()=>{e.join()},onCancel:()=>e.cancel(),isJoining:e.isStarting});case`call`:return A(kP,{onLeave:()=>e.leave()});case`ended`:return A(tb,{onRestart:()=>e.restart()});case`unavailable`:return A(Yy,{cause:e.unavailableCause??`busy`,canRetry:e.canRetry,onRetry:()=>{e.start()},onCancel:n});default:{let t=e.state;throw Error(`Unreachable flow state: ${String(t)}`)}}}var KP=Ie(null);function qP({children:e}){let{config:t}=pt(bi),n=t.peek().customization?.widget,r=n?.expandable??`default`,i=dn(r===`start-expanded`||r===`always`),a=dn(n?.variant??`full`),o=dn(n?.position??`bottom-right`),s=dn(r),c=dn(n?.avatar?.type??`orb`),l=D(r);vn(()=>{let e=t.value.customization?.widget,n=e?.expandable??`default`;a.value=e?.variant??`full`,o.value=e?.position??`bottom-right`,s.value=n,c.value=e?.avatar?.type??`orb`,l.current!==n&&(i.value=n===`start-expanded`||n===`always`,l.current=n)});let u=k(()=>{s.peek()!==`always`&&(i.value=!i.peek())},[i,s]),d=k(()=>{i.value=!0},[i]),f=k(()=>{s.peek()!==`always`&&(i.value=!1)},[i,s]),p=O(()=>({expanded:i,variant:a,position:o,expandable:s,avatarType:c,toggle:u,expand:d,collapse:f}),[i,a,o,s,c,u,d,f]);return A(KP.Provider,{value:p,children:e})}function JP(){let{config:e}=K_(),t=e.value.customization.branding;return e.value.show_tavus_branding!==!1&&!t?.hide_tavus_badge?A(YP,{}):t?.logo||t?.text?A(XP,{logo:t.logo,text:t.text}):null}function YP(){let{isDark:e}=Yj(),t=e.value?`white`:`#140206`;return A(`a`,{href:`https://tavus.io`,target:`_blank`,rel:`noopener noreferrer`,class:`inline-flex items-center gap-1 text-xs text-base-content/50 hover:text-base-content/80 transition-colors`,children:[A(`svg`,{viewBox:`0 0 488 452`,class:`h-2.5 w-2.5 shrink-0`,fill:`none`,"aria-hidden":`true`,children:[A(`path`,{d:`M160 152V208H104V152H160Z`,fill:t}),A(`path`,{"fill-rule":`evenodd`,"clip-rule":`evenodd`,d:`M488 270.5L436 285L451 326L418.766 346L441 360L423 392L435 452H0V0H394.766L488 270.5ZM24 24V428H216.2L209 392L227 360L204.766 346L237 326L222 285L274 270.5L189.038 24H24ZM352 152C336.536 152 324 164.536 324 180C324 195.464 336.536 208 352 208C367.464 208 380 195.464 380 180C380 164.536 367.464 152 352 152Z`,fill:t})]}),A(`span`,{children:[`Powered by `,A(`span`,{class:`underline`,children:`Tavus`})]})]})}function XP({logo:e,text:t}){return A(`div`,{class:`inline-flex items-center gap-1 text-xs text-base-content/50`,children:[e?A(`img`,{src:e,alt:t||`Branding`,class:`h-2.5 shrink-0`}):null,t?A(`span`,{children:t}):null]})}var ZP={title:`Hi! Want to chat?`,btn_title:`Start conversation`};function QP(){let{config:e}=K_(),t=e.value.customization.widget?.text;return O(()=>({title:t?.title||ZP.title,btn_title:t?.btn_title||ZP.btn_title}),[t])}function $P(){let e=pt(KP);if(!e)throw Error(`useWidgetUI must be used within WidgetUIProvider`);return e}var eF={xs:`w-6 h-6`,sm:`w-8 h-8`,md:`w-10 h-10`,lg:`w-16 h-16`},tF={xs:`w-3 h-3`,sm:`w-4 h-4`,md:`w-5 h-5`,lg:`w-8 h-8`};function nF({size:e=`md`,className:t=``}){let{avatarType:n}=$P(),{config:r}=K_(),i=Ly(r.value);return(Ry(r.value).background.type===`replica`||n.value===`image`)&&i?A(`div`,{class:`relative ${eF[e]} rounded-box overflow-hidden bg-base-300 ${t}`,children:i.kind===`image`?A(`img`,{src:i.url,class:`absolute inset-0 w-full h-full object-cover`,loading:`lazy`,alt:``}):A(`video`,{src:i.url,class:`absolute inset-0 w-full h-full object-cover`,muted:!0,autoplay:!0,loop:!0,playsinline:!0})}):A(`div`,{class:`relative ${eF[e]} rounded-box bg-primary/15 flex items-center justify-center ${t}`,children:A(`span`,{class:`${tF[e]} rounded-full bg-primary animate-pulse`})})}function rF({variant:e}){let{toggle:t}=$P(),n=QP();return e===`tiny`?A(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`rounded-box overflow-hidden shadow-xl hover:shadow-2xl transition-shadow cursor-pointer`,children:A(nF,{size:`lg`})}):e===`compact`?A(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`group flex items-center gap-2.5 py-2.5 pl-2.5 pr-8 rounded-box bg-base-100 text-base-content border border-base-300 shadow-lg hover:shadow-xl transition-shadow cursor-pointer text-left`,children:[A(nF,{size:`md`}),A(`span`,{class:`flex flex-col gap-0.5`,children:[A(`span`,{class:`text-base font-medium leading-tight`,children:n.title}),A(`span`,{class:`text-sm text-base-content/60 leading-tight`,children:n.btn_title})]})]}):A(`button`,{type:`button`,onClick:t,"aria-label":n.btn_title,class:`flex flex-col gap-3 p-3 w-64 rounded-box bg-base-100 text-base-content border border-base-300 shadow-xl hover:shadow-2xl transition-shadow cursor-pointer text-left`,children:[A(`div`,{class:`flex items-center gap-2.5`,children:[A(nF,{size:`md`}),A(`span`,{class:`text-sm font-medium leading-snug`,children:n.title})]}),A(`span`,{class:`btn btn-primary btn-sm w-full pointer-events-none gap-2 flex items-center`,children:[A(Ny,{name:`cam`,size:16}),A(`span`,{className:`leading-4`,children:n.btn_title})]})]})}var iF=`tavus:widget:greeting-dismissed`;function aF({anchor:e}){let t=QP(),{variant:n,expand:r}=$P(),[i,a]=T(!1);E(()=>{if(n.value===`tiny`){try{if(sessionStorage.getItem(iF)===`1`)return}catch{}a(!0)}},[n]);let o=k(e=>{e.stopPropagation();try{sessionStorage.setItem(iF,`1`)}catch{}a(!1)},[]);if(!i)return null;let s=e===`right`?`right-[-6px] border-r border-b`:`left-[-6px] border-l border-t`,c=e===`right`?`-right-2`:`-left-2`;return A(`button`,{type:`button`,onClick:r,class:`relative max-w-56 rounded-box bg-base-100 text-base-content shadow-lg border border-base-300 px-3 py-2 text-sm text-left cursor-pointer animate-[tavusFadeUp_240ms_ease-out] hover:bg-base-200 transition-colors`,children:[A(`p`,{class:`leading-snug pr-3`,children:t.title}),A(`span`,{role:`button`,tabIndex:0,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o(e)},class:`absolute -top-2 ${c} btn btn-ghost btn-circle btn-xs bg-base-100 border border-base-300 shadow-sm`,"aria-label":`Dismiss`,children:`×`}),A(`span`,{class:`absolute bottom-3 w-3 h-3 rotate-45 bg-base-100 border-base-300 ${s}`})]})}function oF(){let e=pt(fv);if(!e)throw Error(`useHostBridge must be used within HostBridgeProvider`);return e}var sF=`bg-base-100 text-base-content rounded-box border border-base-300 shadow-xl w-[22rem] flex flex-col animate-[tavusPopIn_180ms_ease-out]`,cF=`bg-base-100 text-base-content w-[100vw] h-[100dvh] flex flex-col animate-[tavusFadeUp_180ms_ease-out]`,lF=`p-1 flex-1 min-h-0`,uF=`p-1 flex-1 min-h-0`;function dF({variant:e,children:t,fullscreen:n}){let{collapse:r,expandable:i}=$P(),a=i.value!==`always`;return n?A(`div`,{class:cF,children:[A(`div`,{class:`flex items-center justify-end gap-2 px-2.5 py-1.5 border-b border-base-300`,children:a&&A(`button`,{type:`button`,class:`btn btn-ghost btn-circle btn-xs`,onClick:r,"aria-label":`Close`,children:A(Ny,{name:`close`,size:14})})}),A(`div`,{class:uF,children:t}),A(`div`,{class:`flex justify-end px-2.5`,children:A(JP,{})})]}):A(`div`,{class:`flex flex-col h-[min(34rem,calc(100dvh-3rem))]`,children:[A(`div`,{class:`${sF} flex-1 overflow-hidden`,children:[A(`div`,{class:`flex items-center justify-end gap-2 px-2.5 pt-1.5 shrink-0`,children:a&&A(`button`,{type:`button`,class:`btn btn-ghost btn-circle btn-xs`,onClick:r,"aria-label":`Close`,children:A(Ny,{name:`close`,size:14})})}),A(`div`,{class:lF,children:t})]}),A(`div`,{class:`flex justify-end pr-2 pt-1.5 shrink-0`,children:A(JP,{})})]})}var fF=yn(`Widget`),pF=`1rem`,mF=480;function hF(){return typeof window>`u`?!1:window.innerWidth<=mF}function gF(e){switch(e){case`bottom-right`:return{bottom:pF,right:pF};case`bottom-left`:return{bottom:pF,left:pF};case`top-right`:return{top:pF,right:pF};case`top-left`:return{top:pF,left:pF};case`top`:return{top:pF,left:`50%`,transform:`translateX(-50%)`};case`bottom`:return{bottom:pF,left:`50%`,transform:`translateX(-50%)`}}}var _F=[`top`,`bottom`,`left`,`right`,`transform`];function vF(e){return e===`bottom-left`||e===`top-left`?`left`:`right`}function yF(){let{config:e,initError:t}=K_(),n=QP(),{expanded:r,position:i,variant:a}=$P(),{shadowHost:o}=oF(),s=Xy(),c=dn(hF());E(()=>{if(typeof window>`u`)return;c.value=hF();let e=()=>{c.value=hF()};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[c]);let l=O(()=>({fallback_button:n.btn_title}),[n.btn_title]);if(vn(()=>{let e=o.value,t=i.value,n=r.value,a=n&&c.value;if(e){if(a)e.style.top=`0`,e.style.right=`0`,e.style.bottom=`0`,e.style.left=`0`,e.style.transform=``;else{let n=gF(t);for(let t of _F)e.style[t]=n[t]??``}e.dataset.tavusWidgetPosition=t,e.dataset.tavusWidgetExpanded=n?`true`:`false`,e.dataset.tavusWidgetFullscreen=a?`true`:`false`,e.dataset.tavusWidgetSmall=c.value?`true`:`false`}}),t.value)return fF.error(`Widget cannot initialize (init request failed):`,t.value),null;if(e.value.is_available===!1&&e.value.unavailable_reason===`total_limit`)return fF.error(`Widget is unavailable (total_limit reached) — not rendering`),null;if(!r.value){let e=vF(i.value),t=e===`right`?`flex items-end gap-2 justify-end`:`flex items-end gap-2 flex-row-reverse justify-end`,n=e===`right`?`justify-end pr-2`:`justify-start pl-2`;return A(`div`,{class:`flex flex-col`,children:[A(`div`,{class:t,children:[A(aF,{anchor:e}),A(rF,{variant:a.value})]}),A(`div`,{class:`flex ${n} pt-1.5`,children:A(JP,{})})]})}return e.value.is_available===!1?A(dF,{variant:a.value,fullscreen:c.value,children:A(Ev,{children:A(Yy,{cause:e.value.unavailable_reason??`daily_limit`,canRetry:!1,onRetry:()=>{}})})}):A(dF,{variant:a.value,fullscreen:c.value,children:A(Ev,{children:A(GP,{flow:s,welcomeText:l,onUnavailableCancel:()=>s.restart()})})})}var bF=`:host {
|
|
163
163
|
display: block;
|
|
164
164
|
position: fixed;
|
|
165
165
|
z-index: 50;
|
|
166
166
|
background: transparent;
|
|
167
167
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
168
|
-
}`;function
|
|
168
|
+
}`;function xF(e){return A(ue,{children:[A(`style`,{dangerouslySetInnerHTML:{__html:Ye}}),A(`style`,{dangerouslySetInnerHTML:{__html:bF}}),A(Et,{"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:A(xi,{children:A(Ci,{children:A(R_,{children:A(uv,{children:A(mv,{children:A(gv,{children:A(qP,{children:A(yF,{})})})})})})})})})]})}var SF;function CF(){SF||=Ve(xF,`tavus-widget`,[`deployment-id`,`override-config`,`conversational-context`,`custom-greeting`,`memory-stores`,`base-url`,`token`],{shadow:!0,mode:`open`})}var wF=[`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`],TF=class{element=null;tagName;constructor(e=`tavus-widget`){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`&&CF(),e.TAVUS_EVENT_NAMES=wF,e.TavusIntegration=TF,e})({});
|