vanilla-agent 1.9.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";var Ko=Object.create;var on=Object.defineProperty;var Xo=Object.getOwnPropertyDescriptor;var Yo=Object.getOwnPropertyNames;var Jo=Object.getPrototypeOf,Go=Object.prototype.hasOwnProperty;var Zo=(t,n)=>{for(var r in n)on(t,r,{get:n[r],enumerable:!0})},ko=(t,n,r,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Yo(n))!Go.call(t,o)&&o!==r&&on(t,o,{get:()=>n[o],enumerable:!(e=Xo(n,o))||e.enumerable});return t};var Qo=(t,n,r)=>(r=t!=null?Ko(Jo(t)):{},ko(n||!t||!t.__esModule?on(r,"default",{value:t,enumerable:!0}):r,t)),er=t=>ko(on({},"__esModule",{value:!0}),t);var vr={};Zo(vr,{AgentWidgetClient:()=>Ut,AgentWidgetSession:()=>Yt,DEFAULT_WIDGET_CONFIG:()=>Ze,createActionManager:()=>nn,createAgentExperience:()=>gn,createFlexibleJsonStreamParser:()=>Po,createJsonStreamParser:()=>dn,createLocalStorageAdapter:()=>Vo,createPlainTextParser:()=>an,createRegexJsonParser:()=>ln,createXmlParser:()=>cn,default:()=>hr,defaultActionHandlers:()=>Kt,defaultJsonActionParser:()=>tn,directivePostprocessor:()=>Ro,escapeHtml:()=>rn,initAgentWidget:()=>kn,markdownPostprocessor:()=>fn,mergeWithDefaults:()=>un,pluginRegistry:()=>en});module.exports=er(vr);var mn=require("marked");mn.marked.setOptions({breaks:!0});var fn=t=>mn.marked.parse(t),rn=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),tr=t=>t.replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Bo=t=>`%%FORM_PLACEHOLDER_${t}%%`,nr=(t,n)=>{let r=t;return r=r.replace(/<Directive>([\s\S]*?)<\/Directive>/gi,(e,o)=>{try{let s=JSON.parse(o.trim());if(s&&typeof s=="object"&&s.component==="form"&&s.type){let a=Bo(n.length);return n.push({token:a,type:String(s.type)}),a}}catch{return e}return e}),r=r.replace(/<Form\s+type="([^"]+)"\s*\/>/gi,(e,o)=>{let s=Bo(n.length);return n.push({token:s,type:o}),s}),r},Ro=t=>{let n=[],r=nr(t,n),e=fn(r);return n.forEach(({token:o,type:s})=>{let a=new RegExp(o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),b=`<div class="tvw-form-directive" data-tv-form="${tr(s)}"></div>`;e=e.replace(a,b)}),e};var Tt=require("partial-json"),wn=t=>{if(t===null)return"null";if(t===void 0)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t,null,2)}catch{return String(t)}},or=t=>{var a,c;let n=(a=t.completedAt)!=null?a:Date.now(),r=(c=t.startedAt)!=null?c:n,o=(t.durationMs!==void 0?t.durationMs:Math.max(0,n-r))/1e3;return o<.1?"Thought for <0.1 seconds":`Thought for ${o>=10?Math.round(o).toString():o.toFixed(1).replace(/\.0$/,"")} seconds`},Ho=t=>t.status==="complete"?or(t):t.status==="pending"?"Waiting":"",rr=t=>{var o,s,a;let r=(typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,((o=t.completedAt)!=null?o:Date.now())-((a=(s=t.startedAt)!=null?s:t.completedAt)!=null?a:Date.now())))/1e3;return r<.1?"Used tool for <0.1 seconds":`Used tool for ${r>=10?Math.round(r).toString():r.toFixed(1).replace(/\.0$/,"")} seconds`};var Io=t=>t.status==="complete"?rr(t):"Using tool...",sr=()=>{let t=null,n=0,r=e=>{let o=/"text"\s*:\s*"((?:[^"\\]|\\.|")*?)"/,s=e.match(o);if(s&&s[1])try{return s[1].replace(/\\n/g,`
2
- `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return s[1]}let a=/"text"\s*:\s*"((?:[^"\\]|\\.)*)/,c=e.match(a);if(c&&c[1])try{return c[1].replace(/\\n/g,`
3
- `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return c[1]}return null};return{getExtractedText:()=>t,processChunk:async e=>{if(e.length<=n)return t!==null?{text:t,raw:e}:null;let o=e.trim();if(!o.startsWith("{")&&!o.startsWith("["))return null;let s=r(e);return s!==null&&(t=s),n=e.length,t!==null?{text:t,raw:e}:null},close:async()=>{}}},sn=t=>{try{let n=JSON.parse(t);if(n&&typeof n=="object"&&typeof n.text=="string")return n.text}catch{return null}return null},an=()=>{let t={processChunk:n=>null,getExtractedText:()=>null};return t.__isPlainTextParser=!0,t},ln=()=>{var n;let t=sr();return{processChunk:async r=>{let e=r.trim();return!e.startsWith("{")&&!e.startsWith("[")?null:t.processChunk(r)},getExtractedText:t.getExtractedText.bind(t),close:(n=t.close)==null?void 0:n.bind(t)}},dn=()=>{let t=null,n=0;return{getExtractedText:()=>t,processChunk:r=>{let e=r.trim();if(!e.startsWith("{")&&!e.startsWith("["))return null;if(r.length<=n)return t!==null?{text:t,raw:r}:null;try{let o=(0,Tt.parse)(r,Tt.STR|Tt.OBJ);o&&typeof o=="object"&&typeof o.text=="string"&&(t=o.text)}catch{}return n=r.length,t!==null?{text:t,raw:r}:null},close:()=>{}}},Po=t=>{let n=null,r=0,o=t||(s=>{if(!s||typeof s!="object")return null;if(s.action)switch(s.action){case"nav_then_click":return s.on_load_text||s.text||null;case"message":case"message_and_click":case"checkout":return s.text||null;default:return s.text||s.display_text||s.message||null}return s.text||s.display_text||s.message||s.content||null});return{getExtractedText:()=>n,processChunk:s=>{let a=s.trim();if(!a.startsWith("{")&&!a.startsWith("["))return null;if(s.length<=r)return n!==null?{text:n,raw:s}:null;try{let c=(0,Tt.parse)(s,Tt.STR|Tt.OBJ),b=o(c);b!==null&&(n=b)}catch{}return r=s.length,{text:n||"",raw:s}},close:()=>{}}},cn=()=>{let t=null;return{processChunk:n=>{if(!n.trim().startsWith("<"))return null;let e=n.match(/<text[^>]*>([\s\S]*?)<\/text>/);return e&&e[1]?(t=e[1],{text:t,raw:n}):null},getExtractedText:()=>t}};var ir="https://api.travrse.ai/v1/dispatch";function ar(t){switch(t){case"json":return dn;case"regex-json":return ln;case"xml":return cn;case"plain":default:return an}}var Ut=class{constructor(n={}){this.config=n;var r,e,o;this.apiUrl=(r=n.apiUrl)!=null?r:ir,this.headers={"Content-Type":"application/json",...n.headers},this.debug=!!n.debug,this.createStreamParser=(e=n.streamParser)!=null?e:ar(n.parserType),this.contextProviders=(o=n.contextProviders)!=null?o:[],this.requestMiddleware=n.requestMiddleware}async dispatch(n,r){let e=new AbortController;n.signal&&n.signal.addEventListener("abort",()=>e.abort()),r({type:"status",status:"connecting"});let o=await this.buildPayload(n.messages);this.debug&&console.debug("[AgentWidgetClient] dispatch body",o);let s=await fetch(this.apiUrl,{method:"POST",headers:this.headers,body:JSON.stringify(o),signal:e.signal});if(!s.ok||!s.body){let a=new Error(`Chat backend request failed: ${s.status} ${s.statusText}`);throw r({type:"error",error:a}),a}r({type:"status",status:"connected"});try{await this.streamResponse(s.body,r)}finally{r({type:"status",status:"idle"})}}async buildPayload(n){let e={messages:n.slice().sort((o,s)=>{let a=new Date(o.createdAt).getTime(),c=new Date(s.createdAt).getTime();return a-c}).map(o=>({role:o.role,content:o.content,createdAt:o.createdAt})),...this.config.flowId&&{flowId:this.config.flowId}};if(this.contextProviders.length){let o={};await Promise.all(this.contextProviders.map(async s=>{try{let a=await s({messages:n,config:this.config});a&&typeof a=="object"&&Object.assign(o,a)}catch(a){typeof console!="undefined"&&console.warn("[AgentWidget] Context provider failed:",a)}})),Object.keys(o).length&&(e.context=o)}if(this.requestMiddleware)try{let o=await this.requestMiddleware({payload:{...e},config:this.config});if(o&&typeof o=="object")return o}catch(o){typeof console!="undefined"&&console.error("[AgentWidget] Request middleware error:",o)}return e}async streamResponse(n,r){var It,J,E,ot,yt,Pt,rt,oe,L,we,Ft,he,S,Ne,_e,dt,st,R,ct,Te,Qe,O,ie,ut,U,Ke,Xt,bt,Nt,Dt,xt,re,At,Mt,it,qt,zt,Wt,ft,at,_t,Ot,$t,wt,ht,Oe,Ct,Et,Lt,kt,De,$e,lt,et,Bt;let e=n.getReader(),o=new TextDecoder,s="",a=Date.now(),c=0,b=()=>a+c++,z=f=>{let _=f.reasoning?{...f.reasoning,chunks:[...f.reasoning.chunks]}:void 0,X=f.toolCall?{...f.toolCall,chunks:f.toolCall.chunks?[...f.toolCall.chunks]:void 0}:void 0,ce=f.tools?f.tools.map(Ae=>({...Ae,chunks:Ae.chunks?[...Ae.chunks]:void 0})):void 0;return{...f,reasoning:_,toolCall:X,tools:ce}},g=f=>{r({type:"message",message:z(f)})},F=null,H=new Map,B=new Map,y={lastId:null,byStep:new Map},G={lastId:null,byCall:new Map},I=f=>{if(f==null)return null;try{return String(f)}catch{return null}},x=f=>{var _,X,ce,Ae,Le;return I((Le=(Ae=(ce=(X=(_=f.stepId)!=null?_:f.step_id)!=null?X:f.step)!=null?ce:f.parentId)!=null?Ae:f.flowStepId)!=null?Le:f.flow_step_id)},M=f=>{var _,X,ce,Ae,Le,D,v;return I((v=(D=(Le=(Ae=(ce=(X=(_=f.callId)!=null?_:f.call_id)!=null?X:f.requestId)!=null?ce:f.request_id)!=null?Ae:f.toolCallId)!=null?Le:f.tool_call_id)!=null?D:f.stepId)!=null?v:f.step_id)},m=()=>F||(F={id:`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"assistant",sequence:b()},g(F),F),ke=(f,_)=>{y.lastId=_,f&&y.byStep.set(f,_)},ne=(f,_)=>{var Le;let X=(Le=f.reasoningId)!=null?Le:f.id,ce=x(f);if(X){let D=String(X);return ke(ce,D),D}if(ce){let D=y.byStep.get(ce);if(D)return y.lastId=D,D}if(y.lastId&&!_)return y.lastId;if(!_)return null;let Ae=`reason-${b()}`;return ke(ce,Ae),Ae},Fe=f=>{let _=H.get(f);if(_)return _;let X={id:`reason-${f}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"reasoning",sequence:b(),reasoning:{id:f,status:"streaming",chunks:[]}};return H.set(f,X),g(X),X},Be=(f,_)=>{G.lastId=_,f&&G.byCall.set(f,_)},me=(f,_)=>{var Le;let X=(Le=f.toolId)!=null?Le:f.id,ce=M(f);if(X){let D=String(X);return Be(ce,D),D}if(ce){let D=G.byCall.get(ce);if(D)return G.lastId=D,D}if(G.lastId&&!_)return G.lastId;if(!_)return null;let Ae=`tool-${b()}`;return Be(ce,Ae),Ae},Z=f=>{let _=B.get(f);if(_)return _;let X={id:`tool-${f}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"tool",sequence:b(),toolCall:{id:f,status:"pending"}};return B.set(f,X),g(X),X},Se=f=>{if(typeof f=="number"&&Number.isFinite(f))return f;if(typeof f=="string"){let _=Number(f);if(!Number.isNaN(_)&&Number.isFinite(_))return _;let X=Date.parse(f);if(!Number.isNaN(X))return X}return Date.now()},fe=f=>{if(typeof f=="string")return f;if(f==null)return"";try{return JSON.stringify(f)}catch{return String(f)}},K=new Map,Q=new Map;for(;;){let{done:f,value:_}=await e.read();if(f)break;s+=o.decode(_,{stream:!0});let X=s.split(`
1
+ "use strict";var Er=Object.create;var mn=Object.defineProperty;var Mr=Object.getOwnPropertyDescriptor;var Lr=Object.getOwnPropertyNames;var Br=Object.getPrototypeOf,Hr=Object.prototype.hasOwnProperty;var kr=(t,n)=>{for(var o in n)mn(t,o,{get:n[o],enumerable:!0})},ar=(t,n,o,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Lr(n))!Hr.call(t,r)&&r!==o&&mn(t,r,{get:()=>n[r],enumerable:!(e=Mr(n,r))||e.enumerable});return t};var Rr=(t,n,o)=>(o=t!=null?Er(Br(t)):{},ar(n||!t||!t.__esModule?mn(o,"default",{value:t,enumerable:!0}):o,t)),Ir=t=>ar(mn({},"__esModule",{value:!0}),t);var os={};kr(os,{AgentWidgetClient:()=>$t,AgentWidgetSession:()=>Vt,DEFAULT_WIDGET_CONFIG:()=>Ne,attachHeaderToContainer:()=>Kt,buildComposer:()=>Xt,buildDefaultHeader:()=>Pn,buildExpandedHeader:()=>Nn,buildHeader:()=>Ft,buildHeaderWithLayout:()=>Cn,buildMinimalHeader:()=>Fn,componentRegistry:()=>Jt,createActionManager:()=>dn,createAgentExperience:()=>Ln,createBubbleWithLayout:()=>hr,createComponentMiddleware:()=>Cr,createComponentStreamParser:()=>An,createFlexibleJsonStreamParser:()=>pr,createJsonStreamParser:()=>yn,createLocalStorageAdapter:()=>Tn,createPlainTextParser:()=>wn,createRegexJsonParser:()=>vn,createStandardBubble:()=>Yt,createTypingIndicator:()=>sn,createXmlParser:()=>xn,default:()=>ns,defaultActionHandlers:()=>_t,defaultJsonActionParser:()=>ln,directivePostprocessor:()=>dr,escapeHtml:()=>fn,extractComponentDirectiveFromMessage:()=>Mn,getHeaderLayout:()=>Dn,hasComponentDirective:()=>En,headerLayouts:()=>bn,initAgentWidget:()=>Yn,isComponentDirectiveType:()=>br,markdownPostprocessor:()=>kn,mergeWithDefaults:()=>Sn,pluginRegistry:()=>an,renderComponentDirective:()=>Wn});module.exports=Ir(os);var Hn=require("marked");Hn.marked.setOptions({breaks:!0});var kn=t=>Hn.marked.parse(t),fn=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),Pr=t=>t.replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),lr=t=>`%%FORM_PLACEHOLDER_${t}%%`,Fr=(t,n)=>{let o=t;return o=o.replace(/<Directive>([\s\S]*?)<\/Directive>/gi,(e,r)=>{try{let s=JSON.parse(r.trim());if(s&&typeof s=="object"&&s.component==="form"&&s.type){let i=lr(n.length);return n.push({token:i,type:String(s.type)}),i}}catch{return e}return e}),o=o.replace(/<Form\s+type="([^"]+)"\s*\/>/gi,(e,r)=>{let s=lr(n.length);return n.push({token:s,type:r}),s}),o},dr=t=>{let n=[],o=Fr(t,n),e=kn(o);return n.forEach(({token:r,type:s})=>{let i=new RegExp(r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),u=`<div class="tvw-form-directive" data-tv-form="${Pr(s)}"></div>`;e=e.replace(i,u)}),e};var Et=require("partial-json"),Rn=t=>{if(t===null)return"null";if(t===void 0)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t,null,2)}catch{return String(t)}},Nr=t=>{var i,l;let n=(i=t.completedAt)!=null?i:Date.now(),o=(l=t.startedAt)!=null?l:n,r=(t.durationMs!==void 0?t.durationMs:Math.max(0,n-o))/1e3;return r<.1?"Thought for <0.1 seconds":`Thought for ${r>=10?Math.round(r).toString():r.toFixed(1).replace(/\.0$/,"")} seconds`},cr=t=>t.status==="complete"?Nr(t):t.status==="pending"?"Waiting":"",Dr=t=>{var r,s,i;let o=(typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,((r=t.completedAt)!=null?r:Date.now())-((i=(s=t.startedAt)!=null?s:t.completedAt)!=null?i:Date.now())))/1e3;return o<.1?"Used tool for <0.1 seconds":`Used tool for ${o>=10?Math.round(o).toString():o.toFixed(1).replace(/\.0$/,"")} seconds`};var ur=t=>t.status==="complete"?Dr(t):"Using tool...",qr=()=>{let t=null,n=0,o=e=>{let r=/"text"\s*:\s*"((?:[^"\\]|\\.|")*?)"/,s=e.match(r);if(s&&s[1])try{return s[1].replace(/\\n/g,`
2
+ `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return s[1]}let i=/"text"\s*:\s*"((?:[^"\\]|\\.)*)/,l=e.match(i);if(l&&l[1])try{return l[1].replace(/\\n/g,`
3
+ `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\")}catch{return l[1]}return null};return{getExtractedText:()=>t,processChunk:async e=>{if(e.length<=n)return t!==null?{text:t,raw:e}:null;let r=e.trim();if(!r.startsWith("{")&&!r.startsWith("["))return null;let s=o(e);return s!==null&&(t=s),n=e.length,t!==null?{text:t,raw:e}:null},close:async()=>{}}},hn=t=>{try{let n=JSON.parse(t);if(n&&typeof n=="object"&&typeof n.text=="string")return n.text}catch{return null}return null},wn=()=>{let t={processChunk:n=>null,getExtractedText:()=>null};return t.__isPlainTextParser=!0,t},vn=()=>{var n;let t=qr();return{processChunk:async o=>{let e=o.trim();return!e.startsWith("{")&&!e.startsWith("[")?null:t.processChunk(o)},getExtractedText:t.getExtractedText.bind(t),close:(n=t.close)==null?void 0:n.bind(t)}},yn=()=>{let t=null,n=0;return{getExtractedText:()=>t,processChunk:o=>{let e=o.trim();if(!e.startsWith("{")&&!e.startsWith("["))return null;if(o.length<=n)return t!==null||t===""?{text:t||"",raw:o}:null;try{let r=(0,Et.parse)(o,Et.STR|Et.OBJ);r&&typeof r=="object"&&(r.component&&typeof r.component=="string"?t=typeof r.text=="string"?r.text:"":r.type==="init"&&r.form?t="":typeof r.text=="string"&&(t=r.text))}catch{}return n=o.length,t!==null?{text:t,raw:o}:null},close:()=>{}}},pr=t=>{let n=null,o=0,r=t||(s=>{if(!s||typeof s!="object")return null;if(s.component&&typeof s.component=="string")return typeof s.text=="string"?s.text:"";if(s.type==="init"&&s.form)return"";if(s.action)switch(s.action){case"nav_then_click":return s.on_load_text||s.text||null;case"message":case"message_and_click":case"checkout":return s.text||null;default:return s.text||s.display_text||s.message||null}return s.text||s.display_text||s.message||s.content||null});return{getExtractedText:()=>n,processChunk:s=>{let i=s.trim();if(!i.startsWith("{")&&!i.startsWith("["))return null;if(s.length<=o)return n!==null?{text:n,raw:s}:null;try{let l=(0,Et.parse)(s,Et.STR|Et.OBJ),u=r(l);u!==null&&(n=u)}catch{}return o=s.length,{text:n||"",raw:s}},close:()=>{}}},xn=()=>{let t=null;return{processChunk:n=>{if(!n.trim().startsWith("<"))return null;let e=n.match(/<text[^>]*>([\s\S]*?)<\/text>/);return e&&e[1]?(t=e[1],{text:t,raw:n}):null},getExtractedText:()=>t}};var zr="https://api.travrse.ai/v1/dispatch";function Or(t){switch(t){case"json":return yn;case"regex-json":return vn;case"xml":return xn;case"plain":default:return wn}}var $t=class{constructor(n={}){this.config=n;var o,e,r;this.apiUrl=(o=n.apiUrl)!=null?o:zr,this.headers={"Content-Type":"application/json",...n.headers},this.debug=!!n.debug,this.createStreamParser=(e=n.streamParser)!=null?e:Or(n.parserType),this.contextProviders=(r=n.contextProviders)!=null?r:[],this.requestMiddleware=n.requestMiddleware,this.customFetch=n.customFetch,this.parseSSEEvent=n.parseSSEEvent,this.getHeaders=n.getHeaders}async dispatch(n,o){let e=new AbortController;n.signal&&n.signal.addEventListener("abort",()=>e.abort()),o({type:"status",status:"connecting"});let r=await this.buildPayload(n.messages);this.debug&&console.debug("[AgentWidgetClient] dispatch payload",r);let s={...this.headers};if(this.getHeaders)try{let l=await this.getHeaders();s={...s,...l}}catch(l){typeof console!="undefined"&&console.error("[AgentWidget] getHeaders error:",l)}let i;if(this.customFetch)try{i=await this.customFetch(this.apiUrl,{method:"POST",headers:s,body:JSON.stringify(r),signal:e.signal},r)}catch(l){let u=l instanceof Error?l:new Error(String(l));throw o({type:"error",error:u}),u}else i=await fetch(this.apiUrl,{method:"POST",headers:s,body:JSON.stringify(r),signal:e.signal});if(!i.ok||!i.body){let l=new Error(`Chat backend request failed: ${i.status} ${i.statusText}`);throw o({type:"error",error:l}),l}o({type:"status",status:"connected"});try{await this.streamResponse(i.body,o)}finally{o({type:"status",status:"idle"})}}async buildPayload(n){let e={messages:n.slice().sort((r,s)=>{let i=new Date(r.createdAt).getTime(),l=new Date(s.createdAt).getTime();return i-l}).map(r=>({role:r.role,content:r.rawContent||r.content,createdAt:r.createdAt})),...this.config.flowId&&{flowId:this.config.flowId}};if(this.contextProviders.length){let r={};await Promise.all(this.contextProviders.map(async s=>{try{let i=await s({messages:n,config:this.config});i&&typeof i=="object"&&Object.assign(r,i)}catch(i){typeof console!="undefined"&&console.warn("[AgentWidget] Context provider failed:",i)}})),Object.keys(r).length&&(e.context=r)}if(this.requestMiddleware)try{let r=await this.requestMiddleware({payload:{...e},config:this.config});if(r&&typeof r=="object")return r}catch(r){typeof console!="undefined"&&console.error("[AgentWidget] Request middleware error:",r)}return e}async handleCustomSSEEvent(n,o,e,r,s){if(!this.parseSSEEvent)return!1;try{let i=await this.parseSSEEvent(n);if(i===null)return!1;let l=()=>{if(e.current)return e.current;let u={id:`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"assistant",sequence:s()};return e.current=u,r(u),u};if(i.text!==void 0){let u=l();u.content+=i.text,r(u)}return i.done&&(e.current&&(e.current.streaming=!1,r(e.current)),o({type:"status",status:"idle"})),i.error&&o({type:"error",error:new Error(i.error)}),!0}catch(i){return typeof console!="undefined"&&console.error("[AgentWidget] parseSSEEvent error:",i),!1}}async streamResponse(n,o){var oe,P,_e,Ke,et,wt,vt,N,de,pt,gt,Xe,st,B,ke,it,at,St,mt,Fe,tt,je,D,lt,Ye,We,qe,K,ve,Re,Ue,nt,yt,Mt,ct,xt,ie,Nt,Lt,me,ft,bt,Bt,ht,Tt,cn,un,pn,Dt,qt,ot,jt,Qt,en,tn,Je;let e=n.getReader(),r=new TextDecoder,s="",i=Date.now(),l=0,u=()=>i+l++,m=y=>{let G=y.reasoning?{...y.reasoning,chunks:[...y.reasoning.chunks]}:void 0,Q=y.toolCall?{...y.toolCall,chunks:y.toolCall.chunks?[...y.toolCall.chunks]:void 0}:void 0,Ee=y.tools?y.tools.map(Me=>({...Me,chunks:Me.chunks?[...Me.chunks]:void 0})):void 0;return{...y,reasoning:G,toolCall:Q,tools:Ee}},d=y=>{o({type:"message",message:m(y)})},W=null,h={current:null},C=new Map,v=new Map,O={lastId:null,byStep:new Map},q={lastId:null,byCall:new Map},f=y=>{if(y==null)return null;try{return String(y)}catch{return null}},S=y=>{var G,Q,Ee,Me,ye;return f((ye=(Me=(Ee=(Q=(G=y.stepId)!=null?G:y.step_id)!=null?Q:y.step)!=null?Ee:y.parentId)!=null?Me:y.flowStepId)!=null?ye:y.flow_step_id)},I=y=>{var G,Q,Ee,Me,ye,Le,E;return f((E=(Le=(ye=(Me=(Ee=(Q=(G=y.callId)!=null?G:y.call_id)!=null?Q:y.requestId)!=null?Ee:y.request_id)!=null?Me:y.toolCallId)!=null?ye:y.tool_call_id)!=null?Le:y.stepId)!=null?E:y.step_id)},T=()=>W||(W={id:`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,sequence:u()},d(W),W),U=(y,G)=>{O.lastId=G,y&&O.byStep.set(y,G)},R=(y,G)=>{var ye;let Q=(ye=y.reasoningId)!=null?ye:y.id,Ee=S(y);if(Q){let Le=String(Q);return U(Ee,Le),Le}if(Ee){let Le=O.byStep.get(Ee);if(Le)return O.lastId=Le,Le}if(O.lastId&&!G)return O.lastId;if(!G)return null;let Me=`reason-${u()}`;return U(Ee,Me),Me},J=y=>{let G=C.get(y);if(G)return G;let Q={id:`reason-${y}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"reasoning",sequence:u(),reasoning:{id:y,status:"streaming",chunks:[]}};return C.set(y,Q),d(Q),Q},te=(y,G)=>{q.lastId=G,y&&q.byCall.set(y,G)},A=(y,G)=>{var ye;let Q=(ye=y.toolId)!=null?ye:y.id,Ee=I(y);if(Q){let Le=String(Q);return te(Ee,Le),Le}if(Ee){let Le=q.byCall.get(Ee);if(Le)return q.lastId=Le,Le}if(q.lastId&&!G)return q.lastId;if(!G)return null;let Me=`tool-${u()}`;return te(Ee,Me),Me},se=y=>{let G=v.get(y);if(G)return G;let Q={id:`tool-${y}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"tool",sequence:u(),toolCall:{id:y,status:"pending"}};return v.set(y,Q),d(Q),Q},V=y=>{if(typeof y=="number"&&Number.isFinite(y))return y;if(typeof y=="string"){let G=Number(y);if(!Number.isNaN(G)&&Number.isFinite(G))return G;let Q=Date.parse(y);if(!Number.isNaN(Q))return Q}return Date.now()},j=y=>{if(typeof y=="string")return y;if(y==null)return"";try{return JSON.stringify(y)}catch{return String(y)}},ne=new Map,ue=new Map;for(;;){let{done:y,value:G}=await e.read();if(y)break;s+=r.decode(G,{stream:!0});let Q=s.split(`
4
4
 
5
- `);s=(It=X.pop())!=null?It:"";for(let ce of X){let Ae=ce.split(`
6
- `),Le="message",D="";for(let $ of Ae)$.startsWith("event:")?Le=$.replace("event:","").trim():$.startsWith("data:")&&(D+=$.replace("data:","").trim());if(!D)continue;let v;try{v=JSON.parse(D)}catch($){r({type:"error",error:$ instanceof Error?$:new Error("Failed to parse chat stream payload")});continue}let je=Le!=="message"?Le:(J=v.type)!=null?J:"message";if(je==="reason_start"){let $=(E=ne(v,!0))!=null?E:`reason-${b()}`,h=Fe($);h.reasoning=(ot=h.reasoning)!=null?ot:{id:$,status:"streaming",chunks:[]},h.reasoning.startedAt=(Pt=h.reasoning.startedAt)!=null?Pt:Se((yt=v.startedAt)!=null?yt:v.timestamp),h.reasoning.completedAt=void 0,h.reasoning.durationMs=void 0,h.streaming=!0,h.reasoning.status="streaming",g(h)}else if(je==="reason_chunk"){let $=(oe=(rt=ne(v,!1))!=null?rt:ne(v,!0))!=null?oe:`reason-${b()}`,h=Fe($);h.reasoning=(L=h.reasoning)!=null?L:{id:$,status:"streaming",chunks:[]},h.reasoning.startedAt=(Ft=h.reasoning.startedAt)!=null?Ft:Se((we=v.startedAt)!=null?we:v.timestamp);let d=(Ne=(S=(he=v.reasoningText)!=null?he:v.text)!=null?S:v.delta)!=null?Ne:"";if(d&&v.hidden!==!0&&h.reasoning.chunks.push(String(d)),h.reasoning.status=v.done?"complete":"streaming",v.done){h.reasoning.completedAt=Se((_e=v.completedAt)!=null?_e:v.timestamp);let P=(dt=h.reasoning.startedAt)!=null?dt:Date.now();h.reasoning.durationMs=Math.max(0,((st=h.reasoning.completedAt)!=null?st:Date.now())-P)}h.streaming=h.reasoning.status!=="complete",g(h)}else if(je==="reason_complete"){let $=(ct=(R=ne(v,!1))!=null?R:ne(v,!0))!=null?ct:`reason-${b()}`,h=H.get($);if(h!=null&&h.reasoning){h.reasoning.status="complete",h.reasoning.completedAt=Se((Te=v.completedAt)!=null?Te:v.timestamp);let P=(Qe=h.reasoning.startedAt)!=null?Qe:Date.now();h.reasoning.durationMs=Math.max(0,((O=h.reasoning.completedAt)!=null?O:Date.now())-P),h.streaming=!1,g(h)}let d=x(v);d&&y.byStep.delete(d)}else if(je==="tool_start"){let $=(ie=me(v,!0))!=null?ie:`tool-${b()}`,h=Z($),d=(ut=h.toolCall)!=null?ut:{id:$,status:"pending"};d.name=(U=v.toolName)!=null?U:d.name,d.status="running",v.args!==void 0&&(d.args=v.args),d.startedAt=(Xt=d.startedAt)!=null?Xt:Se((Ke=v.startedAt)!=null?Ke:v.timestamp),d.completedAt=void 0,d.durationMs=void 0,h.toolCall=d,h.streaming=!0,g(h)}else if(je==="tool_chunk"){let $=(Nt=(bt=me(v,!1))!=null?bt:me(v,!0))!=null?Nt:`tool-${b()}`,h=Z($),d=(Dt=h.toolCall)!=null?Dt:{id:$,status:"running"};d.startedAt=(re=d.startedAt)!=null?re:Se((xt=v.startedAt)!=null?xt:v.timestamp);let P=(it=(Mt=(At=v.text)!=null?At:v.delta)!=null?Mt:v.message)!=null?it:"";P&&(d.chunks=(qt=d.chunks)!=null?qt:[],d.chunks.push(String(P))),d.status="running",h.toolCall=d,h.streaming=!0,g(h)}else if(je==="tool_complete"){let $=(Wt=(zt=me(v,!1))!=null?zt:me(v,!0))!=null?Wt:`tool-${b()}`,h=Z($),d=(ft=h.toolCall)!=null?ft:{id:$,status:"running"};if(d.status="complete",v.result!==void 0&&(d.result=v.result),typeof v.duration=="number"&&(d.duration=v.duration),d.completedAt=Se((at=v.completedAt)!=null?at:v.timestamp),typeof v.duration=="number")d.durationMs=v.duration;else{let ae=(_t=d.startedAt)!=null?_t:Date.now();d.durationMs=Math.max(0,((Ot=d.completedAt)!=null?Ot:Date.now())-ae)}h.toolCall=d,h.streaming=!1,g(h);let P=M(v);P&&G.byCall.delete(P)}else if(je==="step_chunk"){let $=v.stepType,h=v.executionType;if($==="tool"||h==="context")continue;let d=m(),P=(ht=(wt=($t=v.text)!=null?$t:v.delta)!=null?wt:v.content)!=null?ht:"";if(P){let le=((Oe=Q.get(d.id))!=null?Oe:"")+P;d.rawContent=le,K.has(d.id)||K.set(d.id,this.createStreamParser());let ue=K.get(d.id),Re=le.trim().startsWith("{")||le.trim().startsWith("[");if(Re&&Q.set(d.id,le),ue.__isPlainTextParser===!0){d.content+=P,Q.delete(d.id),K.delete(d.id),d.rawContent=void 0,g(d);continue}let de=ue.processChunk(le);if(de instanceof Promise)de.then(j=>{var pe;let se=typeof j=="string"?j:(pe=j==null?void 0:j.text)!=null?pe:null;if(se!==null&&se.trim()!==""){let ve=F;ve&&ve.id===d.id&&(ve.content=se,g(ve))}else if(!Re&&!le.trim().startsWith("<")){let ve=F;ve&&ve.id===d.id&&(ve.content+=P,Q.delete(ve.id),K.delete(ve.id),ve.rawContent=void 0,g(ve))}}).catch(()=>{d.content+=P,Q.delete(d.id),K.delete(d.id),d.rawContent=void 0,g(d)});else{let j=typeof de=="string"?de:(Ct=de==null?void 0:de.text)!=null?Ct:null;j!==null&&j.trim()!==""?(d.content=j,g(d)):!Re&&!le.trim().startsWith("<")&&(d.content+=P,Q.delete(d.id),K.delete(d.id),d.rawContent=void 0,g(d))}}if(v.isComplete){let ae=(Lt=(Et=v.result)==null?void 0:Et.response)!=null?Lt:d.content;if(ae){let le=Q.get(d.id),ue=le!=null?le:fe(ae);d.rawContent=ue;let Re=K.get(d.id),Me=null;if(Re&&(Me=Re.getExtractedText(),Me===null&&(Me=sn(ue)),Me===null)){let j=Re.processChunk(ue);j instanceof Promise?j.then(se=>{var ve;let pe=typeof se=="string"?se:(ve=se==null?void 0:se.text)!=null?ve:null;if(pe!==null){let He=F;He&&He.id===d.id&&(He.content=pe,He.streaming=!1,g(He))}}):Me=typeof j=="string"?j:(kt=j==null?void 0:j.text)!=null?kt:null}Me!==null&&Me.trim()!==""?d.content=Me:Q.has(d.id)||(d.content=fe(ae));let de=K.get(d.id);if(de){let j=(De=de.close)==null?void 0:De.call(de);j instanceof Promise&&j.catch(()=>{}),K.delete(d.id)}Q.delete(d.id),d.streaming=!1,g(d)}}}else if(je==="step_complete"){let $=v.stepType,h=v.executionType;if($==="tool"||h==="context")continue;let d=($e=v.result)==null?void 0:$e.response,P=m();if(d!=null){let ae=K.get(P.id),le=!1;if(ae){let ue=ae.getExtractedText(),Re=Q.get(P.id),Me=Re!=null?Re:fe(d);if(P.rawContent=Me,ue!==null&&ue.trim()!=="")P.content=ue,le=!0;else{let de=sn(Me);if(de!==null)P.content=de,le=!0;else{let j=ae.processChunk(Me);if(j instanceof Promise)j.then(se=>{var ve;let pe=typeof se=="string"?se:(ve=se==null?void 0:se.text)!=null?ve:null;if(pe!==null&&pe.trim()!==""){let He=F;He&&He.id===P.id&&(He.content=pe,He.streaming=!1,g(He))}else{let He=ae.getExtractedText();if(He===null||He.trim()===""){let gt=F;gt&&gt.id===P.id&&(Q.has(P.id)||(gt.content=fe(d)),gt.streaming=!1,g(gt))}}});else{let se=typeof j=="string"?j:(lt=j==null?void 0:j.text)!=null?lt:null;if(se!==null&&se.trim()!=="")P.content=se,le=!0;else{let pe=ae.getExtractedText();pe!==null&&pe.trim()!==""&&(P.content=pe,le=!0)}}}}}if(!P.rawContent){let ue=Q.get(P.id);P.rawContent=ue!=null?ue:fe(d)}if(!le&&!Q.has(P.id)&&(P.content=fe(d)),ae){let ue=(et=ae.close)==null?void 0:et.call(ae);ue instanceof Promise&&ue.catch(()=>{})}K.delete(P.id),Q.delete(P.id),P.streaming=!1,g(P)}else K.delete(P.id),Q.delete(P.id),P.streaming=!1,g(P)}else if(je==="flow_complete"){let $=(Bt=v.result)==null?void 0:Bt.response;if($!=null){let h=m(),d=Q.get(h.id),P=d!=null?d:fe($);h.rawContent=P;let ae=fe($),le=K.get(h.id);if(le){let ue=sn(P);if(ue!==null)ae=ue;else{let Re=le.processChunk(P);Re instanceof Promise&&Re.then(de=>{var se;let j=typeof de=="string"?de:(se=de==null?void 0:de.text)!=null?se:null;if(j!==null){let pe=F;pe&&pe.id===h.id&&(pe.content=j,pe.streaming=!1,g(pe))}});let Me=le.getExtractedText();Me!==null&&(ae=Me)}}K.delete(h.id),Q.delete(h.id),ae!==h.content&&(h.content=ae,g(h)),h.streaming=!1,g(h)}else if(F!==null){let h=F;K.delete(h.id),Q.delete(h.id),h.streaming=!1,g(h)}r({type:"status",status:"idle"})}else je==="error"&&v.error&&r({type:"error",error:v.error instanceof Error?v.error:new Error(String(v.error))})}}}};var Yt=class{constructor(n={},r){this.config=n;this.callbacks=r;this.status="idle";this.streaming=!1;this.abortController=null;this.sequenceCounter=Date.now();this.handleEvent=n=>{var r,e;n.type==="message"?this.upsertMessage(n.message):n.type==="status"?(this.setStatus(n.status),n.status==="connecting"?this.setStreaming(!0):(n.status==="idle"||n.status==="error")&&(this.setStreaming(!1),this.abortController=null)):n.type==="error"&&(this.setStatus("error"),this.setStreaming(!1),this.abortController=null,(e=(r=this.callbacks).onError)==null||e.call(r,n.error))};var e;this.messages=[...(e=n.initialMessages)!=null?e:[]].map(o=>{var s;return{...o,sequence:(s=o.sequence)!=null?s:this.nextSequence()}}),this.messages=this.sortMessages(this.messages),this.client=new Ut(n),this.messages.length&&this.callbacks.onMessagesChanged([...this.messages]),this.callbacks.onStatusChanged(this.status)}updateConfig(n){this.config={...this.config,...n},this.client=new Ut(this.config)}getMessages(){return[...this.messages]}getStatus(){return this.status}isStreaming(){return this.streaming}injectTestEvent(n){this.handleEvent(n)}async sendMessage(n,r){var c,b,z,g,F;let e=n.trim();if(!e)return;(c=this.abortController)==null||c.abort();let o={id:`user-${Date.now()}`,role:"user",content:e,createdAt:new Date().toISOString(),sequence:this.nextSequence(),viaVoice:(r==null?void 0:r.viaVoice)||!1};this.appendMessage(o),this.setStreaming(!0);let s=new AbortController;this.abortController=s;let a=[...this.messages];try{await this.client.dispatch({messages:a,signal:s.signal},this.handleEvent)}catch(H){let B={id:`assistant-${Date.now()}`,role:"assistant",createdAt:new Date().toISOString(),content:"It looks like the proxy isn't returning a real response yet. Here's a sample message so you can continue testing locally.",sequence:this.nextSequence()};this.appendMessage(B),this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,H instanceof Error?(z=(b=this.callbacks).onError)==null||z.call(b,H):(F=(g=this.callbacks).onError)==null||F.call(g,new Error(String(H)))}}cancel(){var n;(n=this.abortController)==null||n.abort(),this.abortController=null,this.setStreaming(!1),this.setStatus("idle")}clearMessages(){var n;(n=this.abortController)==null||n.abort(),this.abortController=null,this.messages=[],this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}hydrateMessages(n){var r;(r=this.abortController)==null||r.abort(),this.abortController=null,this.messages=this.sortMessages(n.map(e=>{var o;return{...e,streaming:!1,sequence:(o=e.sequence)!=null?o:this.nextSequence()}})),this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}setStatus(n){this.status!==n&&(this.status=n,this.callbacks.onStatusChanged(n))}setStreaming(n){this.streaming!==n&&(this.streaming=n,this.callbacks.onStreamingChanged(n))}appendMessage(n){let r=this.ensureSequence(n);this.messages=this.sortMessages([...this.messages,r]),this.callbacks.onMessagesChanged([...this.messages])}upsertMessage(n){let r=this.ensureSequence(n),e=this.messages.findIndex(o=>o.id===r.id);if(e===-1){this.appendMessage(r);return}this.messages=this.messages.map((o,s)=>s===e?{...o,...r}:o),this.messages=this.sortMessages(this.messages),this.callbacks.onMessagesChanged([...this.messages])}ensureSequence(n){return n.sequence!==void 0?{...n}:{...n,sequence:this.nextSequence()}}nextSequence(){return this.sequenceCounter++}sortMessages(n){return[...n].sort((r,e)=>{var b,z;let o=new Date(r.createdAt).getTime(),s=new Date(e.createdAt).getTime();if(!Number.isNaN(o)&&!Number.isNaN(s)&&o!==s)return o-s;let a=(b=r.sequence)!=null?b:0,c=(z=e.sequence)!=null?z:0;return a!==c?a-c:r.id.localeCompare(e.id)})}};var hn=(t,n)=>{var e;let r=(e=n==null?void 0:n.theme)!=null?e:{};Object.entries(r).forEach(([o,s])=>{if(s==null||s==="")return;let a=o.replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`);t.style.setProperty(`--cw-${a}`,String(s))})};var lr=Qo(require("lucide"),1),Ee=(t,n=24,r="currentColor",e=2)=>{try{let o=t.split("-").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(""),s=lr[o];return s?dr(s,n,r,e):(console.warn(`Lucide icon "${t}" not found (tried "${o}"). Available icons: https://lucide.dev/icons`),null)}catch(o){return console.warn(`Failed to render Lucide icon "${t}":`,o),null}};function dr(t,n,r,e){if(!t||!Array.isArray(t))return null;let o=document.createElementNS("http://www.w3.org/2000/svg","svg");return o.setAttribute("width",String(n)),o.setAttribute("height",String(n)),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("stroke",r),o.setAttribute("stroke-width",String(e)),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.setAttribute("aria-hidden","true"),t.forEach(s=>{if(Array.isArray(s)&&s.length>=2){let a=s[0],c=s[1];if(c){let b=document.createElementNS("http://www.w3.org/2000/svg",a);Object.entries(c).forEach(([z,g])=>{z!=="stroke"&&b.setAttribute(z,String(g))}),o.appendChild(b)}}}),o}var u=(t,n)=>{let r=document.createElement(t);return n&&(r.className=n),r};var Ve={idle:"Online",connecting:"Connecting\u2026",connected:"Streaming\u2026",error:"Offline"};var Ht={"bottom-right":"tvw-bottom-6 tvw-right-6","bottom-left":"tvw-bottom-6 tvw-left-6","top-right":"tvw-top-6 tvw-right-6","top-left":"tvw-top-6 tvw-left-6"};var vn=(t,n)=>{let r=u("button");r.type="button",r.innerHTML=`
5
+ `);s=(oe=Q.pop())!=null?oe:"";for(let Ee of Q){let Me=Ee.split(`
6
+ `),ye="message",Le="";for(let Y of Me)Y.startsWith("event:")?ye=Y.replace("event:","").trim():Y.startsWith("data:")&&(Le+=Y.replace("data:","").trim());if(!Le)continue;let E;try{E=JSON.parse(Le)}catch(Y){o({type:"error",error:Y instanceof Error?Y:new Error("Failed to parse chat stream payload")});continue}let ut=ye!=="message"?ye:(P=E.type)!=null?P:"message";if(this.parseSSEEvent){h.current=W;let Y=await this.handleCustomSSEEvent(E,o,h,d,u);if(h.current&&!W&&(W=h.current),Y)continue}if(ut==="reason_start"){let Y=(_e=R(E,!0))!=null?_e:`reason-${u()}`,w=J(Y);w.reasoning=(Ke=w.reasoning)!=null?Ke:{id:Y,status:"streaming",chunks:[]},w.reasoning.startedAt=(wt=w.reasoning.startedAt)!=null?wt:V((et=E.startedAt)!=null?et:E.timestamp),w.reasoning.completedAt=void 0,w.reasoning.durationMs=void 0,w.streaming=!0,w.reasoning.status="streaming",d(w)}else if(ut==="reason_chunk"){let Y=(N=(vt=R(E,!1))!=null?vt:R(E,!0))!=null?N:`reason-${u()}`,w=J(Y);w.reasoning=(de=w.reasoning)!=null?de:{id:Y,status:"streaming",chunks:[]},w.reasoning.startedAt=(gt=w.reasoning.startedAt)!=null?gt:V((pt=E.startedAt)!=null?pt:E.timestamp);let g=(B=(st=(Xe=E.reasoningText)!=null?Xe:E.text)!=null?st:E.delta)!=null?B:"";if(g&&E.hidden!==!0&&w.reasoning.chunks.push(String(g)),w.reasoning.status=E.done?"complete":"streaming",E.done){w.reasoning.completedAt=V((ke=E.completedAt)!=null?ke:E.timestamp);let z=(it=w.reasoning.startedAt)!=null?it:Date.now();w.reasoning.durationMs=Math.max(0,((at=w.reasoning.completedAt)!=null?at:Date.now())-z)}w.streaming=w.reasoning.status!=="complete",d(w)}else if(ut==="reason_complete"){let Y=(mt=(St=R(E,!1))!=null?St:R(E,!0))!=null?mt:`reason-${u()}`,w=C.get(Y);if(w!=null&&w.reasoning){w.reasoning.status="complete",w.reasoning.completedAt=V((Fe=E.completedAt)!=null?Fe:E.timestamp);let z=(tt=w.reasoning.startedAt)!=null?tt:Date.now();w.reasoning.durationMs=Math.max(0,((je=w.reasoning.completedAt)!=null?je:Date.now())-z),w.streaming=!1,d(w)}let g=S(E);g&&O.byStep.delete(g)}else if(ut==="tool_start"){let Y=(D=A(E,!0))!=null?D:`tool-${u()}`,w=se(Y),g=(lt=w.toolCall)!=null?lt:{id:Y,status:"pending"};g.name=(Ye=E.toolName)!=null?Ye:g.name,g.status="running",E.args!==void 0&&(g.args=E.args),g.startedAt=(qe=g.startedAt)!=null?qe:V((We=E.startedAt)!=null?We:E.timestamp),g.completedAt=void 0,g.durationMs=void 0,w.toolCall=g,w.streaming=!0,d(w)}else if(ut==="tool_chunk"){let Y=(ve=(K=A(E,!1))!=null?K:A(E,!0))!=null?ve:`tool-${u()}`,w=se(Y),g=(Re=w.toolCall)!=null?Re:{id:Y,status:"running"};g.startedAt=(nt=g.startedAt)!=null?nt:V((Ue=E.startedAt)!=null?Ue:E.timestamp);let z=(ct=(Mt=(yt=E.text)!=null?yt:E.delta)!=null?Mt:E.message)!=null?ct:"";z&&(g.chunks=(xt=g.chunks)!=null?xt:[],g.chunks.push(String(z))),g.status="running",w.toolCall=g,w.streaming=!0,d(w)}else if(ut==="tool_complete"){let Y=(Nt=(ie=A(E,!1))!=null?ie:A(E,!0))!=null?Nt:`tool-${u()}`,w=se(Y),g=(Lt=w.toolCall)!=null?Lt:{id:Y,status:"running"};if(g.status="complete",E.result!==void 0&&(g.result=E.result),typeof E.duration=="number"&&(g.duration=E.duration),g.completedAt=V((me=E.completedAt)!=null?me:E.timestamp),typeof E.duration=="number")g.durationMs=E.duration;else{let xe=(ft=g.startedAt)!=null?ft:Date.now();g.durationMs=Math.max(0,((bt=g.completedAt)!=null?bt:Date.now())-xe)}w.toolCall=g,w.streaming=!1,d(w);let z=I(E);z&&q.byCall.delete(z)}else if(ut==="step_chunk"){let Y=E.stepType,w=E.executionType;if(Y==="tool"||w==="context")continue;let g=T(),z=(cn=(Tt=(ht=(Bt=E.text)!=null?Bt:E.delta)!=null?ht:E.content)!=null?Tt:E.chunk)!=null?cn:"";if(z){let be=((un=ue.get(g.id))!=null?un:"")+z;g.rawContent=be,ne.has(g.id)||ne.set(g.id,this.createStreamParser());let Ie=ne.get(g.id),Ce=be.trim().startsWith("{")||be.trim().startsWith("[");if(Ce&&ue.set(g.id,be),Ie.__isPlainTextParser===!0){g.content+=z,ue.delete(g.id),ne.delete(g.id),g.rawContent=void 0,d(g);continue}let Se=Ie.processChunk(be);if(Se instanceof Promise)Se.then(re=>{var Be;let we=typeof re=="string"?re:(Be=re==null?void 0:re.text)!=null?Be:null;if(we!==null&&we.trim()!==""){let Pe=W;Pe&&Pe.id===g.id&&(Pe.content=we,d(Pe))}else if(!Ce&&!be.trim().startsWith("<")){let Pe=W;Pe&&Pe.id===g.id&&(Pe.content+=z,ue.delete(Pe.id),ne.delete(Pe.id),Pe.rawContent=void 0,d(Pe))}}).catch(()=>{g.content+=z,ue.delete(g.id),ne.delete(g.id),g.rawContent=void 0,d(g)});else{let re=typeof Se=="string"?Se:(pn=Se==null?void 0:Se.text)!=null?pn:null;re!==null&&re.trim()!==""?(g.content=re,d(g)):!Ce&&!be.trim().startsWith("<")&&(g.content+=z,ue.delete(g.id),ne.delete(g.id),g.rawContent=void 0,d(g))}}if(E.isComplete){let xe=(qt=(Dt=E.result)==null?void 0:Dt.response)!=null?qt:g.content;if(xe){let be=ue.get(g.id),Ie=be!=null?be:j(xe);g.rawContent=Ie;let Ce=ne.get(g.id),ze=null;if(Ce&&(ze=Ce.getExtractedText(),ze===null&&(ze=hn(Ie)),ze===null)){let re=Ce.processChunk(Ie);re instanceof Promise?re.then(we=>{var Pe;let Be=typeof we=="string"?we:(Pe=we==null?void 0:we.text)!=null?Pe:null;if(Be!==null){let Oe=W;Oe&&Oe.id===g.id&&(Oe.content=Be,Oe.streaming=!1,d(Oe))}}):ze=typeof re=="string"?re:(ot=re==null?void 0:re.text)!=null?ot:null}ze!==null&&ze.trim()!==""?g.content=ze:ue.has(g.id)||(g.content=j(xe));let Se=ne.get(g.id);if(Se){let re=(jt=Se.close)==null?void 0:jt.call(Se);re instanceof Promise&&re.catch(()=>{}),ne.delete(g.id)}ue.delete(g.id),g.streaming=!1,d(g)}}}else if(ut==="step_complete"){let Y=E.stepType,w=E.executionType;if(Y==="tool"||w==="context")continue;let g=(Qt=E.result)==null?void 0:Qt.response,z=T();if(g!=null){let xe=ne.get(z.id),be=!1;if(xe){let Ie=xe.getExtractedText(),Ce=ue.get(z.id),ze=Ce!=null?Ce:j(g);if(z.rawContent=ze,Ie!==null&&Ie.trim()!=="")z.content=Ie,be=!0;else{let Se=hn(ze);if(Se!==null)z.content=Se,be=!0;else{let re=xe.processChunk(ze);if(re instanceof Promise)re.then(we=>{var Pe;let Be=typeof we=="string"?we:(Pe=we==null?void 0:we.text)!=null?Pe:null;if(Be!==null&&Be.trim()!==""){let Oe=W;Oe&&Oe.id===z.id&&(Oe.content=Be,Oe.streaming=!1,d(Oe))}else{let Oe=xe.getExtractedText();if(Oe===null||Oe.trim()===""){let Ht=W;Ht&&Ht.id===z.id&&(ue.has(z.id)||(Ht.content=j(g)),Ht.streaming=!1,d(Ht))}}});else{let we=typeof re=="string"?re:(en=re==null?void 0:re.text)!=null?en:null;if(we!==null&&we.trim()!=="")z.content=we,be=!0;else{let Be=xe.getExtractedText();Be!==null&&Be.trim()!==""&&(z.content=Be,be=!0)}}}}}if(!z.rawContent){let Ie=ue.get(z.id);z.rawContent=Ie!=null?Ie:j(g)}if(!be&&!ue.has(z.id)&&(z.content=j(g)),xe){let Ie=(tn=xe.close)==null?void 0:tn.call(xe);Ie instanceof Promise&&Ie.catch(()=>{})}ne.delete(z.id),ue.delete(z.id),z.streaming=!1,d(z)}else ne.delete(z.id),ue.delete(z.id),z.streaming=!1,d(z)}else if(ut==="flow_complete"){let Y=(Je=E.result)==null?void 0:Je.response;if(Y!=null){let w=T(),g=ue.get(w.id),z=g!=null?g:j(Y);w.rawContent=z;let xe=j(Y),be=ne.get(w.id);if(be){let Ie=hn(z);if(Ie!==null)xe=Ie;else{let Ce=be.processChunk(z);Ce instanceof Promise&&Ce.then(Se=>{var we;let re=typeof Se=="string"?Se:(we=Se==null?void 0:Se.text)!=null?we:null;if(re!==null){let Be=W;Be&&Be.id===w.id&&(Be.content=re,Be.streaming=!1,d(Be))}});let ze=be.getExtractedText();ze!==null&&(xe=ze)}}ne.delete(w.id),ue.delete(w.id),xe!==w.content&&(w.content=xe,d(w)),w.streaming=!1,d(w)}else if(W!==null){let w=W;ne.delete(w.id),ue.delete(w.id),w.streaming=!1,d(w)}o({type:"status",status:"idle"})}else ut==="error"&&E.error&&o({type:"error",error:E.error instanceof Error?E.error:new Error(String(E.error))})}}}};var Vt=class{constructor(n={},o){this.config=n;this.callbacks=o;this.status="idle";this.streaming=!1;this.abortController=null;this.sequenceCounter=Date.now();this.handleEvent=n=>{var o,e;n.type==="message"?this.upsertMessage(n.message):n.type==="status"?(this.setStatus(n.status),n.status==="connecting"?this.setStreaming(!0):(n.status==="idle"||n.status==="error")&&(this.setStreaming(!1),this.abortController=null)):n.type==="error"&&(this.setStatus("error"),this.setStreaming(!1),this.abortController=null,(e=(o=this.callbacks).onError)==null||e.call(o,n.error))};var e;this.messages=[...(e=n.initialMessages)!=null?e:[]].map(r=>{var s;return{...r,sequence:(s=r.sequence)!=null?s:this.nextSequence()}}),this.messages=this.sortMessages(this.messages),this.client=new $t(n),this.messages.length&&this.callbacks.onMessagesChanged([...this.messages]),this.callbacks.onStatusChanged(this.status)}updateConfig(n){this.config={...this.config,...n},this.client=new $t(this.config)}getMessages(){return[...this.messages]}getStatus(){return this.status}isStreaming(){return this.streaming}injectTestEvent(n){this.handleEvent(n)}async sendMessage(n,o){var l,u,m,d,W;let e=n.trim();if(!e)return;(l=this.abortController)==null||l.abort();let r={id:`user-${Date.now()}`,role:"user",content:e,createdAt:new Date().toISOString(),sequence:this.nextSequence(),viaVoice:(o==null?void 0:o.viaVoice)||!1};this.appendMessage(r),this.setStreaming(!0);let s=new AbortController;this.abortController=s;let i=[...this.messages];try{await this.client.dispatch({messages:i,signal:s.signal},this.handleEvent)}catch(h){let C={id:`assistant-${Date.now()}`,role:"assistant",createdAt:new Date().toISOString(),content:"It looks like the proxy isn't returning a real response yet. Here's a sample message so you can continue testing locally.",sequence:this.nextSequence()};this.appendMessage(C),this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,h instanceof Error?(m=(u=this.callbacks).onError)==null||m.call(u,h):(W=(d=this.callbacks).onError)==null||W.call(d,new Error(String(h)))}}cancel(){var n;(n=this.abortController)==null||n.abort(),this.abortController=null,this.setStreaming(!1),this.setStatus("idle")}clearMessages(){var n;(n=this.abortController)==null||n.abort(),this.abortController=null,this.messages=[],this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}hydrateMessages(n){var o;(o=this.abortController)==null||o.abort(),this.abortController=null,this.messages=this.sortMessages(n.map(e=>{var r;return{...e,streaming:!1,sequence:(r=e.sequence)!=null?r:this.nextSequence()}})),this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}setStatus(n){this.status!==n&&(this.status=n,this.callbacks.onStatusChanged(n))}setStreaming(n){this.streaming!==n&&(this.streaming=n,this.callbacks.onStreamingChanged(n))}appendMessage(n){let o=this.ensureSequence(n);this.messages=this.sortMessages([...this.messages,o]),this.callbacks.onMessagesChanged([...this.messages])}upsertMessage(n){let o=this.ensureSequence(n),e=this.messages.findIndex(r=>r.id===o.id);if(e===-1){this.appendMessage(o);return}this.messages=this.messages.map((r,s)=>s===e?{...r,...o}:r),this.messages=this.sortMessages(this.messages),this.callbacks.onMessagesChanged([...this.messages])}ensureSequence(n){return n.sequence!==void 0?{...n}:{...n,sequence:this.nextSequence()}}nextSequence(){return this.sequenceCounter++}sortMessages(n){return[...n].sort((o,e)=>{var u,m;let r=new Date(o.createdAt).getTime(),s=new Date(e.createdAt).getTime();if(!Number.isNaN(r)&&!Number.isNaN(s)&&r!==s)return r-s;let i=(u=o.sequence)!=null?u:0,l=(m=e.sequence)!=null?m:0;return i!==l?i-l:o.id.localeCompare(e.id)})}};var In=(t,n)=>{var e;let o=(e=n==null?void 0:n.theme)!=null?e:{};Object.entries(o).forEach(([r,s])=>{if(s==null||s==="")return;let i=r.replace(/[A-Z]/g,l=>`-${l.toLowerCase()}`);t.style.setProperty(`--cw-${i}`,String(s))})};var $r=Rr(require("lucide"),1),ge=(t,n=24,o="currentColor",e=2)=>{try{let r=t.split("-").map(i=>i.charAt(0).toUpperCase()+i.slice(1)).join(""),s=$r[r];return s?_r(s,n,o,e):(console.warn(`Lucide icon "${t}" not found (tried "${r}"). Available icons: https://lucide.dev/icons`),null)}catch(r){return console.warn(`Failed to render Lucide icon "${t}":`,r),null}};function _r(t,n,o,e){if(!t||!Array.isArray(t))return null;let r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.setAttribute("width",String(n)),r.setAttribute("height",String(n)),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none"),r.setAttribute("stroke",o),r.setAttribute("stroke-width",String(e)),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("aria-hidden","true"),t.forEach(s=>{if(Array.isArray(s)&&s.length>=2){let i=s[0],l=s[1];if(l){let u=document.createElementNS("http://www.w3.org/2000/svg",i);Object.entries(l).forEach(([m,d])=>{m!=="stroke"&&u.setAttribute(m,String(d))}),r.appendChild(u)}}}),r}var c=(t,n)=>{let o=document.createElement(t);return n&&(o.className=n),o};var Ve={idle:"Online",connecting:"Connecting\u2026",connected:"Streaming\u2026",error:"Offline"};var Pt={"bottom-right":"tvw-bottom-6 tvw-right-6","bottom-left":"tvw-bottom-6 tvw-left-6","top-right":"tvw-top-6 tvw-right-6","top-left":"tvw-top-6 tvw-left-6"};var rn=(t,n)=>{let o=c("button");o.type="button",o.innerHTML=`
7
7
  <span class="tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-bg-cw-primary tvw-text-white" data-role="launcher-icon">\u{1F4AC}</span>
8
8
  <img data-role="launcher-image" class="tvw-rounded-full tvw-object-cover" alt="" style="display:none" />
9
9
  <span class="tvw-flex tvw-flex-col tvw-items-start tvw-text-left">
@@ -11,6 +11,45 @@
11
11
  <span class="tvw-text-xs tvw-text-cw-muted" data-role="launcher-subtitle"></span>
12
12
  </span>
13
13
  <span class="tvw-ml-2 tvw-grid tvw-place-items-center tvw-rounded-full tvw-bg-cw-primary tvw-text-cw-call-to-action" data-role="launcher-call-to-action-icon">\u2197</span>
14
- `,r.addEventListener("click",n);let e=s=>{var G,I,x,M,m,ke,ne,Fe,Be,me;let a=(G=s.launcher)!=null?G:{},c=r.querySelector("[data-role='launcher-title']");c&&(c.textContent=(I=a.title)!=null?I:"Chat Assistant");let b=r.querySelector("[data-role='launcher-subtitle']");b&&(b.textContent=(x=a.subtitle)!=null?x:"Get answers fast");let z=r.querySelector(".tvw-flex-col");z&&(a.textHidden?z.style.display="none":z.style.display="");let g=r.querySelector("[data-role='launcher-icon']");if(g)if(a.agentIconHidden)g.style.display="none";else{let Z=(M=a.agentIconSize)!=null?M:"40px";if(g.style.height=Z,g.style.width=Z,g.innerHTML="",a.agentIconName){let Se=parseFloat(Z)||24,fe=Ee(a.agentIconName,Se*.6,"#ffffff",2);fe?(g.appendChild(fe),g.style.display=""):(g.textContent=(m=a.agentIconText)!=null?m:"\u{1F4AC}",g.style.display="")}else a.iconUrl?g.style.display="none":(g.textContent=(ke=a.agentIconText)!=null?ke:"\u{1F4AC}",g.style.display="")}let F=r.querySelector("[data-role='launcher-image']");if(F){let Z=(ne=a.agentIconSize)!=null?ne:"40px";F.style.height=Z,F.style.width=Z,a.iconUrl&&!a.agentIconName&&!a.agentIconHidden?(F.src=a.iconUrl,F.style.display="block"):F.style.display="none"}let H=r.querySelector("[data-role='launcher-call-to-action-icon']");if(H){let Z=(Fe=a.callToActionIconSize)!=null?Fe:"32px";H.style.height=Z,H.style.width=Z,a.callToActionIconBackgroundColor?(H.style.backgroundColor=a.callToActionIconBackgroundColor,H.classList.remove("tvw-bg-cw-primary")):(H.style.backgroundColor="",H.classList.add("tvw-bg-cw-primary"));let Se=0;if(a.callToActionIconPadding?(H.style.boxSizing="border-box",H.style.padding=a.callToActionIconPadding,Se=(parseFloat(a.callToActionIconPadding)||0)*2):(H.style.boxSizing="",H.style.padding=""),a.callToActionIconHidden)H.style.display="none";else if(H.style.display="",H.innerHTML="",a.callToActionIconName){let fe=parseFloat(Z)||24,K=Math.max(fe-Se,8),Q=Ee(a.callToActionIconName,K,"currentColor",2);Q?H.appendChild(Q):H.textContent=(Be=a.callToActionIconText)!=null?Be:"\u2197"}else H.textContent=(me=a.callToActionIconText)!=null?me:"\u2197"}let B=a.position&&Ht[a.position]?Ht[a.position]:Ht["bottom-right"],y="tvw-fixed tvw-flex tvw-items-center tvw-gap-3 tvw-rounded-launcher tvw-bg-cw-surface tvw-py-2.5 tvw-pl-3 tvw-pr-3 tvw-shadow-lg tvw-border tvw-border-gray-200 tvw-transition hover:tvw-translate-y-[-2px] tvw-cursor-pointer tvw-z-50";r.className=`${y} ${B}`},o=()=>{r.removeEventListener("click",n),r.remove()};return t&&e(t),{element:r,update:e,destroy:o}};var Fo=t=>{var b,z,g,F,H;if(!((z=(b=t==null?void 0:t.launcher)==null?void 0:b.enabled)!=null?z:!0)){let B=u("div","tvw-relative tvw-w-full tvw-h-full"),y=u("div","tvw-relative tvw-w-full tvw-h-full tvw-min-h-[360px]");return B.appendChild(y),{wrapper:B,panel:y}}let r=(g=t==null?void 0:t.launcher)!=null?g:{},e=r.position&&Ht[r.position]?Ht[r.position]:Ht["bottom-right"],o=u("div",`tvw-fixed ${e} tvw-z-50 tvw-transition`),s=u("div","tvw-relative tvw-min-h-[320px]"),a=(H=(F=t==null?void 0:t.launcher)==null?void 0:F.width)!=null?H:t==null?void 0:t.launcherWidth,c=a!=null?a:"min(400px, calc(100vw - 24px))";return s.style.width=c,s.style.maxWidth=c,o.appendChild(s),{wrapper:o,panel:s}},No=(t,n=!0)=>{var xt,re,At,Mt,it,qt,zt,Wt,ft,at,_t,Ot,$t,wt,ht,Oe,Ct,Et,Lt,kt,De,$e,lt,et,Bt,f,_,X,ce,Ae,Le,D,v,je,$,h,d,P,ae,le,ue,Re,Me,de,j,se,pe,ve,He,gt,Gt,i,l,C,N,W,k,T,V,ye;let r=u("div","tvw-flex tvw-h-full tvw-w-full tvw-flex-col tvw-bg-cw-surface tvw-text-cw-primary tvw-rounded-2xl tvw-overflow-hidden tvw-shadow-2xl tvw-border tvw-border-cw-border"),e=u("div","tvw-flex tvw-items-center tvw-gap-3 tvw-bg-cw-surface tvw-px-6 tvw-py-5 tvw-border-b-cw-divider"),o=(xt=t==null?void 0:t.launcher)!=null?xt:{},s=(re=o.headerIconSize)!=null?re:"48px",a=(At=o.closeButtonSize)!=null?At:"32px",c=(Mt=o.closeButtonPlacement)!=null?Mt:"inline",b=(it=o.headerIconHidden)!=null?it:!1,z=o.headerIconName,g=u("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-xl");if(g.style.height=s,g.style.width=s,!b)if(z){let p=parseFloat(s)||24,w=Ee(z,p*.6,"#ffffff",2);w?g.replaceChildren(w):g.textContent=(zt=(qt=t==null?void 0:t.launcher)==null?void 0:qt.agentIconText)!=null?zt:"\u{1F4AC}"}else if((Wt=t==null?void 0:t.launcher)!=null&&Wt.iconUrl){let p=u("img");p.src=t.launcher.iconUrl,p.alt="",p.className="tvw-rounded-xl tvw-object-cover",p.style.height=s,p.style.width=s,g.replaceChildren(p)}else g.textContent=(at=(ft=t==null?void 0:t.launcher)==null?void 0:ft.agentIconText)!=null?at:"\u{1F4AC}";let F=u("div","tvw-flex tvw-flex-col"),H=u("span","tvw-text-base tvw-font-semibold");H.textContent=(Ot=(_t=t==null?void 0:t.launcher)==null?void 0:_t.title)!=null?Ot:"Chat Assistant";let B=u("span","tvw-text-xs tvw-text-cw-muted");B.textContent=(wt=($t=t==null?void 0:t.launcher)==null?void 0:$t.subtitle)!=null?wt:"Here to help you get answers fast",F.append(H,B),b?e.append(F):e.append(g,F);let y=(ht=o.clearChat)!=null?ht:{},G=(Oe=y.enabled)!=null?Oe:!0,I=null,x=null;if(G){let p=(Ct=y.size)!=null?Ct:"32px",w=(Et=y.iconName)!=null?Et:"refresh-cw",q=(Lt=y.iconColor)!=null?Lt:"",be=(kt=y.backgroundColor)!=null?kt:"",Y=(De=y.borderWidth)!=null?De:"",qe=($e=y.borderColor)!=null?$e:"",Pe=(lt=y.borderRadius)!=null?lt:"",Xe=(et=y.paddingX)!=null?et:"",ee=(Bt=y.paddingY)!=null?Bt:"",tt=(f=y.tooltipText)!=null?f:"Clear chat",jt=(_=y.showTooltip)!=null?_:!0;x=u("div","tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper"),I=u("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none"),I.style.height=p,I.style.width=p,I.type="button",I.setAttribute("aria-label",tt);let Rt=Ee(w,"20px",q||"",2);if(Rt&&I.appendChild(Rt),q&&(I.style.color=q,I.classList.remove("tvw-text-cw-muted")),be&&(I.style.backgroundColor=be,I.classList.remove("hover:tvw-bg-gray-100")),Y||qe){let xe=Y||"0px",pt=qe||"transparent";I.style.border=`${xe} solid ${pt}`,I.classList.remove("tvw-border-none")}if(Pe&&(I.style.borderRadius=Pe,I.classList.remove("tvw-rounded-full")),Xe?(I.style.paddingLeft=Xe,I.style.paddingRight=Xe):(I.style.paddingLeft="",I.style.paddingRight=""),ee?(I.style.paddingTop=ee,I.style.paddingBottom=ee):(I.style.paddingTop="",I.style.paddingBottom=""),x.appendChild(I),jt&&tt&&I&&x){let xe=null,pt=()=>{if(xe||!I)return;xe=u("div","tvw-clear-chat-tooltip"),xe.textContent=tt;let Vt=u("div");Vt.className="tvw-clear-chat-tooltip-arrow",xe.appendChild(Vt);let Ye=I.getBoundingClientRect();xe.style.position="fixed",xe.style.left=`${Ye.left+Ye.width/2}px`,xe.style.top=`${Ye.top-8}px`,xe.style.transform="translate(-50%, -100%)",document.body.appendChild(xe)},mt=()=>{xe&&xe.parentNode&&(xe.parentNode.removeChild(xe),xe=null)};x.addEventListener("mouseenter",pt),x.addEventListener("mouseleave",mt),I.addEventListener("focus",pt),I.addEventListener("blur",mt),x._cleanupTooltip=()=>{mt(),x&&(x.removeEventListener("mouseenter",pt),x.removeEventListener("mouseleave",mt)),I&&(I.removeEventListener("focus",pt),I.removeEventListener("blur",mt))}}e.appendChild(x)}let M=u("div",c==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50":G?"":"tvw-ml-auto"),m=u("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none");m.style.height=a,m.style.width=a,m.type="button";let ke=(X=o.closeButtonTooltipText)!=null?X:"Close chat",ne=(ce=o.closeButtonShowTooltip)!=null?ce:!0;m.setAttribute("aria-label",ke),m.style.display=n?"":"none";let Fe=(Ae=o.closeButtonIconName)!=null?Ae:"x",Be=(Le=o.closeButtonIconText)!=null?Le:"\xD7",me=Ee(Fe,"20px",o.closeButtonColor||"",2);if(me?m.appendChild(me):m.textContent=Be,o.closeButtonColor?(m.style.color=o.closeButtonColor,m.classList.remove("tvw-text-cw-muted")):(m.style.color="",m.classList.add("tvw-text-cw-muted")),o.closeButtonBackgroundColor?(m.style.backgroundColor=o.closeButtonBackgroundColor,m.classList.remove("hover:tvw-bg-gray-100")):(m.style.backgroundColor="",m.classList.add("hover:tvw-bg-gray-100")),o.closeButtonBorderWidth||o.closeButtonBorderColor){let p=o.closeButtonBorderWidth||"0px",w=o.closeButtonBorderColor||"transparent";m.style.border=`${p} solid ${w}`,m.classList.remove("tvw-border-none")}else m.style.border="",m.classList.add("tvw-border-none");if(o.closeButtonBorderRadius?(m.style.borderRadius=o.closeButtonBorderRadius,m.classList.remove("tvw-rounded-full")):(m.style.borderRadius="",m.classList.add("tvw-rounded-full")),o.closeButtonPaddingX?(m.style.paddingLeft=o.closeButtonPaddingX,m.style.paddingRight=o.closeButtonPaddingX):(m.style.paddingLeft="",m.style.paddingRight=""),o.closeButtonPaddingY?(m.style.paddingTop=o.closeButtonPaddingY,m.style.paddingBottom=o.closeButtonPaddingY):(m.style.paddingTop="",m.style.paddingBottom=""),M.appendChild(m),ne&&ke){let p=null,w=()=>{if(p)return;p=u("div","tvw-clear-chat-tooltip"),p.textContent=ke;let be=u("div");be.className="tvw-clear-chat-tooltip-arrow",p.appendChild(be);let Y=m.getBoundingClientRect();p.style.position="fixed",p.style.left=`${Y.left+Y.width/2}px`,p.style.top=`${Y.top-8}px`,p.style.transform="translate(-50%, -100%)",document.body.appendChild(p)},q=()=>{p&&p.parentNode&&(p.parentNode.removeChild(p),p=null)};M.addEventListener("mouseenter",w),M.addEventListener("mouseleave",q),m.addEventListener("focus",w),m.addEventListener("blur",q),M._cleanupTooltip=()=>{q(),M.removeEventListener("mouseenter",w),M.removeEventListener("mouseleave",q),m.removeEventListener("focus",w),m.removeEventListener("blur",q)}}c==="top-right"?(r.style.position="relative",r.appendChild(M)):e.appendChild(M);let Z=u("div","tvw-flex tvw-flex-1 tvw-min-h-0 tvw-flex-col tvw-gap-6 tvw-overflow-y-auto tvw-bg-cw-container tvw-px-6 tvw-py-6");Z.id="vanilla-agent-scroll-container";let Se=u("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),fe=u("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");fe.textContent=(v=(D=t==null?void 0:t.copy)==null?void 0:D.welcomeTitle)!=null?v:"Hello \u{1F44B}";let K=u("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");K.textContent=($=(je=t==null?void 0:t.copy)==null?void 0:je.welcomeSubtitle)!=null?$:"Ask anything about your account or products.",Se.append(fe,K);let Q=u("div","tvw-flex tvw-flex-col tvw-gap-3");Z.append(Se,Q);let It=u("div","tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),J=u("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),E=((h=t==null?void 0:t.voiceRecognition)==null?void 0:h.enabled)===!0,ot=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),rt=u("form",`tvw-flex tvw-items-end ${E&&ot?"tvw-gap-1":"tvw-gap-3"} tvw-rounded-2xl tvw-border tvw-border-gray-200 tvw-bg-cw-input-background tvw-px-4 tvw-py-3`);rt.style.outline="none";let oe=u("textarea");oe.placeholder=(P=(d=t==null?void 0:t.copy)==null?void 0:d.inputPlaceholder)!=null?P:"Type your message\u2026",oe.className="tvw-min-h-[48px] tvw-flex-1 tvw-resize-none tvw-border-none tvw-bg-transparent tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-none",oe.rows=1;let L=(le=(ae=t==null?void 0:t.theme)==null?void 0:ae.inputFontFamily)!=null?le:"sans-serif",we=(Re=(ue=t==null?void 0:t.theme)==null?void 0:ue.inputFontWeight)!=null?Re:"400",Ft=p=>{switch(p){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};oe.style.fontFamily=Ft(L),oe.style.fontWeight=we,oe.style.border="none",oe.style.outline="none",oe.style.borderWidth="0",oe.style.borderStyle="none",oe.style.borderColor="transparent",oe.addEventListener("focus",()=>{oe.style.border="none",oe.style.outline="none",oe.style.borderWidth="0",oe.style.borderStyle="none",oe.style.borderColor="transparent",oe.style.boxShadow="none"}),oe.addEventListener("blur",()=>{oe.style.border="none",oe.style.outline="none"});let he=(Me=t==null?void 0:t.sendButton)!=null?Me:{},S=(de=he.useIcon)!=null?de:!1,Ne=(j=he.iconText)!=null?j:"\u2191",_e=he.iconName,dt=(se=he.tooltipText)!=null?se:"Send message",st=(pe=he.showTooltip)!=null?pe:!1,R=(ve=he.size)!=null?ve:"40px",ct=he.backgroundColor,Te=he.textColor,Qe=u("div","tvw-send-button-wrapper"),O=u("button",S?"tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer":"tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold disabled:tvw-opacity-50 tvw-cursor-pointer");if(O.type="submit",S){if(O.style.width=R,O.style.height=R,O.style.minWidth=R,O.style.minHeight=R,O.style.fontSize="18px",O.style.lineHeight="1",O.innerHTML="",_e){let p=parseFloat(R)||24,w=Te&&typeof Te=="string"&&Te.trim()?Te.trim():"currentColor",q=Ee(_e,p,w,2);q?(O.appendChild(q),O.style.color=w):(O.textContent=Ne,Te?O.style.color=Te:O.classList.add("tvw-text-white"))}else O.textContent=Ne,Te?O.style.color=Te:O.classList.add("tvw-text-white");ct?O.style.backgroundColor=ct:O.classList.add("tvw-bg-cw-primary")}else O.textContent=(gt=(He=t==null?void 0:t.copy)==null?void 0:He.sendButtonLabel)!=null?gt:"Send",Te?O.style.color=Te:O.classList.add("tvw-text-white");if(he.borderWidth&&(O.style.borderWidth=he.borderWidth,O.style.borderStyle="solid"),he.borderColor&&(O.style.borderColor=he.borderColor),he.paddingX?(O.style.paddingLeft=he.paddingX,O.style.paddingRight=he.paddingX):(O.style.paddingLeft="",O.style.paddingRight=""),he.paddingY?(O.style.paddingTop=he.paddingY,O.style.paddingBottom=he.paddingY):(O.style.paddingTop="",O.style.paddingBottom=""),st&&dt){let p=u("div","tvw-send-button-tooltip");p.textContent=dt,Qe.appendChild(p)}Qe.appendChild(O);let ie=(Gt=t==null?void 0:t.voiceRecognition)!=null?Gt:{},ut=ie.enabled===!0,U=null,Ke=null,Xt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(ut&&Xt){Ke=u("div","tvw-send-button-wrapper"),U=u("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),U.type="button",U.setAttribute("aria-label","Start voice recognition");let p=(i=ie.iconName)!=null?i:"mic",w=(l=ie.iconSize)!=null?l:R,q=parseFloat(w)||24,be=(C=ie.backgroundColor)!=null?C:ct,Y=(N=ie.iconColor)!=null?N:Te;U.style.width=w,U.style.height=w,U.style.minWidth=w,U.style.minHeight=w,U.style.fontSize="18px",U.style.lineHeight="1";let qe=Y||"currentColor",Pe=Ee(p,q,qe,1.5);Pe?(U.appendChild(Pe),U.style.color=qe):(U.textContent="\u{1F3A4}",U.style.color=qe),be?U.style.backgroundColor=be:U.classList.add("tvw-bg-cw-primary"),Y?U.style.color=Y:!Y&&!Te&&U.classList.add("tvw-text-white"),ie.borderWidth&&(U.style.borderWidth=ie.borderWidth,U.style.borderStyle="solid"),ie.borderColor&&(U.style.borderColor=ie.borderColor),ie.paddingX&&(U.style.paddingLeft=ie.paddingX,U.style.paddingRight=ie.paddingX),ie.paddingY&&(U.style.paddingTop=ie.paddingY,U.style.paddingBottom=ie.paddingY),Ke.appendChild(U);let Xe=(W=ie.tooltipText)!=null?W:"Start voice recognition";if(((k=ie.showTooltip)!=null?k:!1)&&Xe){let tt=u("div","tvw-send-button-tooltip");tt.textContent=Xe,Ke.appendChild(tt)}}rt.addEventListener("click",p=>{p.target!==O&&p.target!==Qe&&p.target!==U&&p.target!==Ke&&oe.focus()}),rt.append(oe),Ke&&rt.append(Ke),rt.append(Qe);let bt=u("div","tvw-mt-2 tvw-text-right tvw-text-xs tvw-text-cw-muted"),Nt=(T=t==null?void 0:t.statusIndicator)!=null?T:{},Dt=(V=Nt.visible)!=null?V:!0;return bt.style.display=Dt?"":"none",bt.textContent=(ye=Nt.idleText)!=null?ye:"Online",It.append(J,rt,bt),r.append(e,Z,It),{container:r,body:Z,messagesWrapper:Q,suggestions:J,textarea:oe,sendButton:O,sendButtonWrapper:Qe,micButton:U,micButtonWrapper:Ke,composerForm:rt,statusText:bt,introTitle:fe,introSubtitle:K,closeButton:m,closeButtonWrapper:M,clearChatButton:I,clearChatButtonWrapper:x,iconHolder:g,headerTitle:H,headerSubtitle:B}};var yn=()=>{let t=document.createElement("div");t.className="tvw-flex tvw-items-center tvw-space-x-1 tvw-h-5 tvw-mt-2";let n=document.createElement("div");n.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",n.style.animationDelay="0ms";let r=document.createElement("div");r.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",r.style.animationDelay="250ms";let e=document.createElement("div");e.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",e.style.animationDelay="500ms";let o=document.createElement("span");return o.className="tvw-sr-only",o.textContent="Loading",t.appendChild(n),t.appendChild(r),t.appendChild(e),t.appendChild(o),t},bn=(t,n)=>{let r=["vanilla-message-bubble","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm"];t.role==="user"?r.push("vanilla-message-user-bubble","tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-5","tvw-py-3"):r.push("vanilla-message-assistant-bubble","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3");let e=u("div",r.join(" ")),o=document.createElement("div");if(o.innerHTML=n({text:t.content,message:t,streaming:!!t.streaming,raw:t.rawContent}),e.appendChild(o),t.streaming&&t.role==="assistant"&&(!t.content||!t.content.trim())){let s=yn();e.appendChild(s)}return e};var xn=new Set,Cn=t=>{let n=t.reasoning,r=u("div",["vanilla-message-bubble","vanilla-reasoning-bubble","tvw-w-full","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(!n)return r;let e=xn.has(t.id),o=u("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");o.type="button",o.setAttribute("aria-expanded",e?"true":"false");let s=u("div","tvw-flex tvw-flex-col tvw-text-left"),a=u("span","tvw-text-xs tvw-text-cw-primary");a.textContent="Thinking...",s.appendChild(a);let c=u("span","tvw-text-xs tvw-text-cw-primary");c.textContent=Ho(n),s.appendChild(c),n.status==="complete"?a.style.display="none":a.style.display="";let b=u("div","tvw-flex tvw-items-center"),g=Ee(e?"chevron-up":"chevron-down",16,"currentColor",2);g?b.appendChild(g):b.textContent=e?"Hide":"Show";let F=u("div","tvw-flex tvw-items-center tvw-ml-auto");F.append(b),o.append(s,F);let H=u("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-px-4 tvw-py-3");H.style.display=e?"":"none";let B=n.chunks.join(""),y=u("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");y.textContent=B||(n.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),H.appendChild(y);let G=()=>{o.setAttribute("aria-expanded",e?"true":"false"),b.innerHTML="";let M=Ee(e?"chevron-up":"chevron-down",16,"currentColor",2);M?b.appendChild(M):b.textContent=e?"Hide":"Show",H.style.display=e?"":"none"},I=()=>{e=!e,e?xn.add(t.id):xn.delete(t.id),G()};return o.addEventListener("pointerdown",x=>{x.preventDefault(),I()}),o.addEventListener("keydown",x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),I())}),G(),r.append(o,H),r};var Sn=new Set,Tn=(t,n)=>{var I;let r=t.toolCall,e=(I=n==null?void 0:n.toolCall)!=null?I:{},o=u("div",["vanilla-message-bubble","vanilla-tool-bubble","tvw-w-full","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(e.backgroundColor&&(o.style.backgroundColor=e.backgroundColor),e.borderColor&&(o.style.borderColor=e.borderColor),e.borderWidth&&(o.style.borderWidth=e.borderWidth),e.borderRadius&&(o.style.borderRadius=e.borderRadius),!r)return o;let s=Sn.has(t.id),a=u("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");a.type="button",a.setAttribute("aria-expanded",s?"true":"false"),e.headerBackgroundColor&&(a.style.backgroundColor=e.headerBackgroundColor),e.headerPaddingX&&(a.style.paddingLeft=e.headerPaddingX,a.style.paddingRight=e.headerPaddingX),e.headerPaddingY&&(a.style.paddingTop=e.headerPaddingY,a.style.paddingBottom=e.headerPaddingY);let c=u("div","tvw-flex tvw-flex-col tvw-text-left"),b=u("span","tvw-text-xs tvw-text-cw-primary");e.headerTextColor&&(b.style.color=e.headerTextColor),b.textContent=Io(r),c.appendChild(b);let z=u("div","tvw-flex tvw-items-center"),g=e.toggleTextColor||e.headerTextColor||"currentColor",F=Ee(s?"chevron-up":"chevron-down",16,g,2);F?z.appendChild(F):z.textContent=s?"Hide":"Show";let H=u("div","tvw-flex tvw-items-center tvw-gap-2 tvw-ml-auto");H.append(z),a.append(c,H);let B=u("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(B.style.display=s?"":"none",e.contentBackgroundColor&&(B.style.backgroundColor=e.contentBackgroundColor),e.contentTextColor&&(B.style.color=e.contentTextColor),e.contentPaddingX&&(B.style.paddingLeft=e.contentPaddingX,B.style.paddingRight=e.contentPaddingX),e.contentPaddingY&&(B.style.paddingTop=e.contentPaddingY,B.style.paddingBottom=e.contentPaddingY),r.name){let x=u("div","tvw-text-xs tvw-text-cw-muted tvw-italic");e.contentTextColor?x.style.color=e.contentTextColor:e.headerTextColor&&(x.style.color=e.headerTextColor),x.textContent=r.name,B.appendChild(x)}if(r.args!==void 0){let x=u("div","tvw-space-y-1"),M=u("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(M.style.color=e.labelTextColor),M.textContent="Arguments";let m=u("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");m.style.fontSize="0.75rem",m.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(m.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(m.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(m.style.color=e.codeBlockTextColor),m.textContent=wn(r.args),x.append(M,m),B.appendChild(x)}if(r.chunks&&r.chunks.length){let x=u("div","tvw-space-y-1"),M=u("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(M.style.color=e.labelTextColor),M.textContent="Activity";let m=u("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");m.style.fontSize="0.75rem",m.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(m.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(m.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(m.style.color=e.codeBlockTextColor),m.textContent=r.chunks.join(`
15
- `),x.append(M,m),B.appendChild(x)}if(r.status==="complete"&&r.result!==void 0){let x=u("div","tvw-space-y-1"),M=u("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(M.style.color=e.labelTextColor),M.textContent="Result";let m=u("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");m.style.fontSize="0.75rem",m.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(m.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(m.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(m.style.color=e.codeBlockTextColor),m.textContent=wn(r.result),x.append(M,m),B.appendChild(x)}if(r.status==="complete"&&typeof r.duration=="number"){let x=u("div","tvw-text-xs tvw-text-cw-muted");e.contentTextColor&&(x.style.color=e.contentTextColor),x.textContent=`Duration: ${r.duration}ms`,B.appendChild(x)}let y=()=>{a.setAttribute("aria-expanded",s?"true":"false"),z.innerHTML="";let x=e.toggleTextColor||e.headerTextColor||"currentColor",M=Ee(s?"chevron-up":"chevron-down",16,x,2);M?z.appendChild(M):z.textContent=s?"Hide":"Show",B.style.display=s?"":"none"},G=()=>{s=!s,s?Sn.add(t.id):Sn.delete(t.id),y()};return a.addEventListener("pointerdown",x=>{x.preventDefault(),G()}),a.addEventListener("keydown",x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),G())}),y(),o.append(a,B),o};var Do=t=>{let n=[];return{buttons:n,render:(e,o,s,a,c)=>{if(t.innerHTML="",n.length=0,!e||!e.length||(a!=null?a:o?o.getMessages():[]).some(B=>B.role==="user"))return;let g=document.createDocumentFragment(),F=o?o.isStreaming():!1,H=B=>{switch(B){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};e.forEach(B=>{let y=u("button","tvw-rounded-button tvw-bg-cw-surface tvw-px-3 tvw-py-1.5 tvw-text-xs tvw-font-medium tvw-text-cw-muted hover:tvw-opacity-90 tvw-cursor-pointer tvw-border tvw-border-gray-200");y.type="button",y.textContent=B,y.disabled=F,c!=null&&c.fontFamily&&(y.style.fontFamily=H(c.fontFamily)),c!=null&&c.fontWeight&&(y.style.fontWeight=c.fontWeight),c!=null&&c.paddingX&&(y.style.paddingLeft=c.paddingX,y.style.paddingRight=c.paddingX),c!=null&&c.paddingY&&(y.style.paddingTop=c.paddingY,y.style.paddingBottom=c.paddingY),y.addEventListener("click",()=>{!o||o.isStreaming()||(s.value="",o.sendMessage(B))}),g.appendChild(y),n.push(y)}),t.appendChild(g)}}};var qo={init:{title:"Schedule a Demo",description:"Share the basics and we'll follow up with a confirmation.",fields:[{name:"name",label:"Full name",placeholder:"Jane Doe",required:!0},{name:"email",label:"Work email",placeholder:"jane@example.com",type:"email",required:!0},{name:"notes",label:"What would you like to cover?",type:"textarea"}],submitLabel:"Submit details"},followup:{title:"Additional Information",description:"Provide any extra details to tailor the next steps.",fields:[{name:"company",label:"Company",placeholder:"Acme Inc."},{name:"context",label:"Context",type:"textarea",placeholder:"Share more about your use case"}],submitLabel:"Send"}},An=(t,n,r,e)=>{let o=t.querySelectorAll("[data-tv-form]");o.length&&o.forEach(s=>{var y,G,I;if(s.dataset.enhanced==="true")return;let a=(y=s.dataset.tvForm)!=null?y:"init";s.dataset.enhanced="true";let c=(G=qo[a])!=null?G:qo.init;s.classList.add("tvw-form-card","tvw-space-y-4");let b=u("div","tvw-space-y-1"),z=u("h3","tvw-text-base tvw-font-semibold tvw-text-cw-primary");if(z.textContent=c.title,b.appendChild(z),c.description){let x=u("p","tvw-text-sm tvw-text-cw-muted");x.textContent=c.description,b.appendChild(x)}let g=document.createElement("form");g.className="tvw-form-grid tvw-space-y-3",c.fields.forEach(x=>{var Fe,Be;let M=u("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");M.htmlFor=`${n.id}-${a}-${x.name}`;let m=u("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");m.textContent=x.label,M.appendChild(m);let ke=(Fe=x.type)!=null?Fe:"text",ne;ke==="textarea"?(ne=document.createElement("textarea"),ne.rows=3):(ne=document.createElement("input"),ne.type=ke),ne.className="tvw-rounded-xl tvw-border tvw-border-gray-200 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-cw-primary",ne.id=`${n.id}-${a}-${x.name}`,ne.name=x.name,ne.placeholder=(Be=x.placeholder)!=null?Be:"",x.required&&(ne.required=!0),M.appendChild(ne),g.appendChild(M)});let F=u("div","tvw-flex tvw-items-center tvw-justify-between tvw-gap-2"),H=u("div","tvw-text-xs tvw-text-cw-muted tvw-min-h-[1.5rem]"),B=u("button","tvw-inline-flex tvw-items-center tvw-rounded-full tvw-bg-cw-primary tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-60 tvw-cursor-pointer");B.type="submit",B.textContent=(I=c.submitLabel)!=null?I:"Submit",F.appendChild(H),F.appendChild(B),g.appendChild(F),s.replaceChildren(b,g),g.addEventListener("submit",async x=>{var ne,Fe;x.preventDefault();let M=(ne=r.formEndpoint)!=null?ne:"/form",m=new FormData(g),ke={};m.forEach((Be,me)=>{ke[me]=Be}),ke.type=a,B.disabled=!0,H.textContent="Submitting\u2026";try{let Be=await fetch(M,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ke)});if(!Be.ok)throw new Error(`Form submission failed (${Be.status})`);let me=await Be.json();H.textContent=(Fe=me.message)!=null?Fe:"Thanks! We'll be in touch soon.",me.success&&me.nextPrompt&&await e.sendMessage(String(me.nextPrompt))}catch(Be){H.textContent=Be instanceof Error?Be.message:"Something went wrong. Please try again."}finally{B.disabled=!1}})})};var Mn=class{constructor(){this.plugins=new Map}register(n){var r;this.plugins.has(n.id)&&console.warn(`Plugin "${n.id}" is already registered. Overwriting.`),this.plugins.set(n.id,n),(r=n.onRegister)==null||r.call(n)}unregister(n){var e;let r=this.plugins.get(n);r&&((e=r.onUnregister)==null||e.call(r),this.plugins.delete(n))}getAll(){return Array.from(this.plugins.values()).sort((n,r)=>{var e,o;return((e=r.priority)!=null?e:0)-((o=n.priority)!=null?o:0)})}getForInstance(n){let r=this.getAll();if(!n||n.length===0)return r;let e=new Set(n.map(s=>s.id));return[...r.filter(s=>!e.has(s.id)),...n].sort((s,a)=>{var c,b;return((c=a.priority)!=null?c:0)-((b=s.priority)!=null?b:0)})}clear(){this.plugins.forEach(n=>{var r;return(r=n.onUnregister)==null?void 0:r.call(n)}),this.plugins.clear()}},en=new Mn;var Ze={apiUrl:"http://localhost:43111/api/chat/dispatch",theme:{primary:"#111827",accent:"#1d4ed8",surface:"#ffffff",muted:"#6b7280",container:"#f8fafc",border:"#f1f5f9",divider:"#f1f5f9",messageBorder:"#f1f5f9",inputBackground:"#ffffff",callToAction:"#000000",callToActionBackground:"#ffffff",sendButtonBackgroundColor:"#111827",sendButtonTextColor:"#ffffff",sendButtonBorderColor:"#60a5fa",closeButtonColor:"#6b7280",closeButtonBackgroundColor:"transparent",closeButtonBorderColor:"",clearChatIconColor:"#6b7280",clearChatBackgroundColor:"transparent",clearChatBorderColor:"transparent",micIconColor:"#111827",micBackgroundColor:"transparent",micBorderColor:"transparent",recordingIconColor:"#ffffff",recordingBackgroundColor:"#ef4444",recordingBorderColor:"transparent",inputFontFamily:"sans-serif",inputFontWeight:"400",radiusSm:"0.75rem",radiusMd:"1rem",radiusLg:"1.5rem",launcherRadius:"9999px",buttonRadius:"9999px"},launcher:{enabled:!0,title:"Chat Assistant",subtitle:"Here to help you get answers fast",agentIconText:"\u{1F4AC}",position:"bottom-right",width:"min(400px, calc(100vw - 24px))",autoExpand:!1,callToActionIconHidden:!1,agentIconSize:"40px",headerIconSize:"40px",closeButtonSize:"32px",callToActionIconName:"arrow-up-right",callToActionIconText:"",callToActionIconSize:"32px",callToActionIconPadding:"5px",callToActionIconColor:"#000000",callToActionIconBackgroundColor:"#ffffff",closeButtonColor:"#6b7280",closeButtonBackgroundColor:"transparent",clearChat:{iconColor:"#6b7280",backgroundColor:"transparent",borderColor:"transparent",enabled:!0,iconName:"refresh-cw",size:"29px",showTooltip:!0,tooltipText:"Clear chat",paddingX:"0px",paddingY:"0px"},headerIconHidden:!1},copy:{welcomeTitle:"Hello \u{1F44B}",welcomeSubtitle:"Ask anything about your account or products.",inputPlaceholder:"How can I help...",sendButtonLabel:"Send"},sendButton:{borderWidth:"0px",paddingX:"12px",paddingY:"10px",backgroundColor:"#111827",textColor:"#ffffff",borderColor:"#60a5fa",useIcon:!0,iconText:"\u2191",size:"40px",showTooltip:!0,tooltipText:"Send message",iconName:"send"},statusIndicator:{visible:!0,idleText:"Online",connectingText:"Connecting\u2026",connectedText:"Streaming\u2026",errorText:"Offline"},voiceRecognition:{enabled:!0,pauseDuration:2e3,iconName:"mic",iconSize:"39px",borderWidth:"0px",paddingX:"9px",paddingY:"14px",iconColor:"#111827",backgroundColor:"transparent",borderColor:"transparent",recordingIconColor:"#ffffff",recordingBackgroundColor:"#ef4444",recordingBorderColor:"transparent",showTooltip:!0,tooltipText:"Start voice recognition"},features:{showReasoning:!0,showToolCalls:!0},suggestionChips:["What can you help me with?","Tell me about your features","How does this work?"],suggestionChipsConfig:{fontFamily:"sans-serif",fontWeight:"500",paddingX:"12px",paddingY:"6px"},debug:!1};function un(t){var n,r,e;return t?{...Ze,...t,theme:{...Ze.theme,...t.theme},launcher:{...Ze.launcher,...t.launcher,clearChat:{...(n=Ze.launcher)==null?void 0:n.clearChat,...(r=t.launcher)==null?void 0:r.clearChat}},copy:{...Ze.copy,...t.copy},sendButton:{...Ze.sendButton,...t.sendButton},statusIndicator:{...Ze.statusIndicator,...t.statusIndicator},voiceRecognition:{...Ze.voiceRecognition,...t.voiceRecognition},features:{...Ze.features,...t.features},suggestionChips:(e=t.suggestionChips)!=null?e:Ze.suggestionChips,suggestionChipsConfig:{...Ze.suggestionChipsConfig,...t.suggestionChipsConfig}}:Ze}var zo=()=>{let t=new Map,n=(o,s)=>(t.has(o)||t.set(o,new Set),t.get(o).add(s),()=>r(o,s)),r=(o,s)=>{var a;(a=t.get(o))==null||a.delete(s)};return{on:n,off:r,emit:(o,s)=>{var a;(a=t.get(o))==null||a.forEach(c=>{try{c(s)}catch(b){typeof console!="undefined"&&console.error("[AgentWidget] Event handler error:",b)}})}}};var cr=t=>{let n=t.match(/```(?:json)?\s*([\s\S]*?)```/i);return n?n[1]:t},ur=t=>{let n=t.trim(),r=n.indexOf("{");if(r===-1)return null;let e=0;for(let o=r;o<n.length;o+=1){let s=n[o];if(s==="{"&&(e+=1),s==="}"&&(e-=1,e===0))return n.slice(r,o+1)}return null},tn=({text:t})=>{if(!t||!t.includes("{"))return null;try{let n=cr(t),r=ur(n);if(!r)return null;let e=JSON.parse(r);if(!e||typeof e!="object"||!e.action)return null;let{action:o,...s}=e;return{type:String(o),payload:s,raw:e}}catch{return null}},Wn=t=>typeof t=="string"?t:t==null?"":String(t),Kt={message:t=>t.type!=="message"?void 0:{handled:!0,displayText:Wn(t.payload.text)},messageAndClick:(t,n)=>{var o;if(t.type!=="message_and_click")return;let r=t.payload,e=Wn(r.element);if(e&&((o=n.document)!=null&&o.querySelector)){let s=n.document.querySelector(e);s?setTimeout(()=>{s.click()},400):typeof console!="undefined"&&console.warn("[AgentWidget] Element not found for selector:",e)}return{handled:!0,displayText:Wn(r.text)}}},_o=t=>Array.isArray(t)?t.map(n=>String(n)):[],nn=t=>{let n=new Set(_o(t.getMetadata().processedActionMessageIds)),r=()=>{n=new Set(_o(t.getMetadata().processedActionMessageIds))},e=()=>{let s=Array.from(n);t.updateMetadata(a=>({...a,processedActionMessageIds:s}))};return{process:s=>{if(s.streaming||s.message.role!=="assistant"||!s.text||n.has(s.message.id))return null;let a=typeof s.raw=="string"&&s.raw||typeof s.message.rawContent=="string"&&s.message.rawContent||typeof s.text=="string"&&s.text||null;!a&&typeof s.text=="string"&&s.text.trim().startsWith("{")&&typeof console!="undefined"&&console.warn("[AgentWidget] Structured response detected but no raw payload was provided. Ensure your stream parser returns { text, raw }.");let c=a?t.parsers.reduce((z,g)=>z||(g==null?void 0:g({text:a,message:s.message}))||null,null):null;if(!c)return null;n.add(s.message.id),e();let b={action:c,message:s.message};t.emit("action:detected",b);for(let z of t.handlers)if(z)try{let g=z(c,{message:s.message,metadata:t.getMetadata(),updateMetadata:t.updateMetadata,document:t.documentRef});if(!g)continue;if(g.handled){let F=g.persistMessage!==!1;return{text:g.displayText!==void 0?g.displayText:"",persist:F}}}catch(g){typeof console!="undefined"&&console.error("[AgentWidget] Action handler error:",g)}return{text:"",persist:!0}},syncFromMetadata:r}};var Jt="vanilla-agent-chat-history",gr=30*1e3,En=t=>!t||typeof t!="object"?{}:{...t},Oo=t=>t.map(n=>({...n,streaming:!1})),$o=(t,n)=>r=>{var s,a,c;let e=(s=r.text)!=null?s:"",o=(a=r.message.rawContent)!=null?a:null;if(n){let b=n.process({text:e,raw:o!=null?o:e,message:r.message,streaming:r.streaming});b!==null&&(e=b.text,b.persist||(r.message.__skipPersist=!0))}return t!=null&&t.postprocessMessage?t.postprocessMessage({...r,text:e,raw:(c=o!=null?o:r.text)!=null?c:""}):rn(e)},gn=(t,n,r)=>{var ae,le,ue,Re,Me,de,j,se,pe,ve,He,gt,Gt;(!t.id||t.id!=="vanilla-agent-root")&&(t.id="vanilla-agent-root");let e=un(n);hn(t,e);let o=en.getForInstance(e.plugins),s=zo(),a=e.storageAdapter,c={},b=null;if(a!=null&&a.load)try{let i=a.load();if(i&&typeof i.then=="function")b=i;else if(i){let l=i;l.metadata&&(c=En(l.metadata)),(ae=l.messages)!=null&&ae.length&&(e={...e,initialMessages:l.messages})}}catch(i){typeof console!="undefined"&&console.error("[AgentWidget] Failed to load stored state:",i)}let z=()=>c,g=i=>{var C;c=(C=i({...c}))!=null?C:{},Wt()},F=e.actionParsers&&e.actionParsers.length?e.actionParsers:[tn],H=e.actionHandlers&&e.actionHandlers.length?e.actionHandlers:[Kt.message,Kt.messageAndClick],B=nn({parsers:F,handlers:H,getMetadata:z,updateMetadata:g,emit:s.emit,documentRef:typeof document!="undefined"?document:null});B.syncFromMetadata();let y=(ue=(le=e.launcher)==null?void 0:le.enabled)!=null?ue:!0,G=(Me=(Re=e.launcher)==null?void 0:Re.autoExpand)!=null?Me:!1,I=G,x=y,M=y?G:!0,m=$o(e,B),ke=(j=(de=e.features)==null?void 0:de.showReasoning)!=null?j:!0,ne=(pe=(se=e.features)==null?void 0:se.showToolCalls)!=null?pe:!0,Fe=(ve=e.statusIndicator)!=null?ve:{},Be=i=>{var l,C,N,W;return i==="idle"?(l=Fe.idleText)!=null?l:Ve.idle:i==="connecting"?(C=Fe.connectingText)!=null?C:Ve.connecting:i==="connected"?(N=Fe.connectedText)!=null?N:Ve.connected:i==="error"?(W=Fe.errorText)!=null?W:Ve.error:Ve[i]},{wrapper:me,panel:Z}=Fo(e),Se=No(e,y),{container:fe,body:K,messagesWrapper:Q,suggestions:It,textarea:J,sendButton:E,sendButtonWrapper:ot,composerForm:yt,statusText:Pt,introTitle:rt,introSubtitle:oe,closeButton:L,iconHolder:we,headerTitle:Ft,headerSubtitle:he}=Se,S=Se.micButton,Ne=Se.micButtonWrapper;Z.appendChild(fe),t.appendChild(me);let _e=[],dt=Do(It),st=null,R,ct=!1,Te=!0,Qe=0,O=0,ie=null,ut=!1,U=0,Ke=!1,Xt=125,bt=2e3,Nt=5,Dt=50,xt=new Map,re={active:!1,manuallyDeactivated:!1,lastUserMessageWasVoice:!1},At=(gt=(He=e.voiceRecognition)==null?void 0:He.autoResume)!=null?gt:!1,Mt=i=>{s.emit("voice:state",{active:re.active,source:i,timestamp:Date.now()})},it=()=>{g(i=>({...i,voiceState:{active:re.active,timestamp:Date.now(),manuallyDeactivated:re.manuallyDeactivated}}))},qt=()=>{var N,W;if(((N=e.voiceRecognition)==null?void 0:N.enabled)===!1)return;let i=En(c.voiceState),l=!!i.active,C=Number((W=i.timestamp)!=null?W:0);re.manuallyDeactivated=!!i.manuallyDeactivated,l&&Date.now()-C<gr&&setTimeout(()=>{re.active||(re.manuallyDeactivated=!1,f("restore"))},1e3)},zt=()=>R?Oo(R.getMessages()).filter(i=>!i.__skipPersist):[];function Wt(i){if(!(a!=null&&a.save)||!R)return;let l={messages:i?Oo(i):zt(),metadata:c};try{let C=a.save(l);C instanceof Promise&&C.catch(N=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",N)})}catch(C){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",C)}}let ft=(i=!1)=>{if(!Te)return;let l=Date.now();ut&&l<U&&!i||(ut&&l>=U&&(ut=!1),!(!i&&!ct)&&(l-O<Xt||(O=l,ie&&cancelAnimationFrame(ie),ie=requestAnimationFrame(()=>{ut||!Te||(Ke=!0,K.scrollTop=K.scrollHeight,Qe=K.scrollTop,requestAnimationFrame(()=>{Ke=!1}),ie=null)}))))},at=null,_t=()=>me.querySelector("#vanilla-agent-scroll-container")||K,Ot=(i,l=500)=>{let C=i.scrollTop,N=i.clientHeight,W=i.scrollHeight,k=W-C;if(C+N>=W-2||Math.abs(k)<5)return;at!==null&&(cancelAnimationFrame(at),at=null);let V=performance.now(),ye=w=>1-Math.pow(1-w,3),p=w=>{let q=i.scrollHeight;q!==W&&(W=q,k=W-C);let be=w-V,Y=Math.min(be/l,1),qe=ye(Y),Pe=C+k*qe;i.scrollTop=Pe,Y<1?at=requestAnimationFrame(p):(i.scrollTop=i.scrollHeight,at=null)};at=requestAnimationFrame(p)},$t=i=>{let l=new Map;i.forEach(C=>{let N=xt.get(C.id);l.set(C.id,{streaming:C.streaming,role:C.role}),!N&&C.role==="assistant"&&s.emit("assistant:message",C),C.role==="assistant"&&(N!=null&&N.streaming)&&C.streaming===!1&&s.emit("assistant:complete",C)}),xt.clear(),l.forEach((C,N)=>{xt.set(N,C)})},wt=(i,l,C)=>{i.innerHTML="";let N=document.createDocumentFragment();l.forEach(k=>{let T=null,V=o.find(p=>!!(k.variant==="reasoning"&&p.renderReasoning||k.variant==="tool"&&p.renderToolCall||!k.variant&&p.renderMessage));if(V)if(k.variant==="reasoning"&&k.reasoning&&V.renderReasoning){if(!ke)return;T=V.renderReasoning({message:k,defaultRenderer:()=>Cn(k),config:e})}else if(k.variant==="tool"&&k.toolCall&&V.renderToolCall){if(!ne)return;T=V.renderToolCall({message:k,defaultRenderer:()=>Tn(k,e),config:e})}else V.renderMessage&&(T=V.renderMessage({message:k,defaultRenderer:()=>{let p=bn(k,C);return k.role!=="user"&&An(p,k,e,R),p},config:e}));if(!T)if(k.variant==="reasoning"&&k.reasoning){if(!ke)return;T=Cn(k)}else if(k.variant==="tool"&&k.toolCall){if(!ne)return;T=Tn(k,e)}else T=bn(k,C),k.role!=="user"&&An(T,k,e,R);let ye=document.createElement("div");ye.className="tvw-flex",k.role==="user"&&ye.classList.add("tvw-justify-end"),ye.appendChild(T),N.appendChild(ye)});let W=l.some(k=>k.role==="assistant"&&k.streaming);if(ct&&l.some(k=>k.role==="user")&&!W){let k=yn(),T=document.createElement("div");T.className=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3"].join(" "),T.appendChild(k);let V=document.createElement("div");V.className="tvw-flex",V.appendChild(T),N.appendChild(V)}i.appendChild(N),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let k=_t();Ot(k)})})},ht=()=>{y&&(M?(me.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),Z.classList.remove("tvw-scale-95","tvw-opacity-0"),Z.classList.add("tvw-scale-100","tvw-opacity-100"),D&&(D.element.style.display="none")):(me.classList.add("tvw-pointer-events-none","tvw-opacity-0"),Z.classList.remove("tvw-scale-100","tvw-opacity-100"),Z.classList.add("tvw-scale-95","tvw-opacity-0"),D&&(D.element.style.display="")))},Oe=(i,l="user")=>{if(!y||M===i)return;let C=M;M=i,ht(),M&&(v(),ft(!0));let N={open:M,source:l,timestamp:Date.now()};M&&!C?s.emit("widget:opened",N):!M&&C&&s.emit("widget:closed",N),s.emit("widget:state",{open:M,launcherEnabled:y,voiceActive:re.active,streaming:R.isStreaming()})},Ct=i=>{J.disabled=i,E.disabled=i,S&&(S.disabled=i),dt.buttons.forEach(l=>{l.disabled=i})},Et=()=>{var W,k,T,V,ye,p,w,q,be,Y,qe,Pe,Xe,ee;rt.textContent=(k=(W=e.copy)==null?void 0:W.welcomeTitle)!=null?k:"Hello \u{1F44B}",oe.textContent=(V=(T=e.copy)==null?void 0:T.welcomeSubtitle)!=null?V:"Ask anything about your account or products.",J.placeholder=(p=(ye=e.copy)==null?void 0:ye.inputPlaceholder)!=null?p:"How can I help...",((q=(w=e.sendButton)==null?void 0:w.useIcon)!=null?q:!1)||(E.textContent=(Y=(be=e.copy)==null?void 0:be.sendButtonLabel)!=null?Y:"Send");let l=(Pe=(qe=e.theme)==null?void 0:qe.inputFontFamily)!=null?Pe:"sans-serif",C=(ee=(Xe=e.theme)==null?void 0:Xe.inputFontWeight)!=null?ee:"400",N=tt=>{switch(tt){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};J.style.fontFamily=N(l),J.style.fontWeight=C};R=new Yt(e,{onMessagesChanged(i){wt(Q,i,m),R&&(i.some(N=>N.role==="user")?dt.render([],R,J,i):dt.render(e.suggestionChips,R,J,i,e.suggestionChipsConfig)),ft(!ct),$t(i);let l=[...i].reverse().find(C=>C.role==="user");re.lastUserMessageWasVoice=!!(l!=null&&l.viaVoice),Wt(i)},onStatusChanged(i){var N;let l=(N=e.statusIndicator)!=null?N:{},C=W=>{var k,T,V,ye;return W==="idle"?(k=l.idleText)!=null?k:Ve.idle:W==="connecting"?(T=l.connectingText)!=null?T:Ve.connecting:W==="connected"?(V=l.connectedText)!=null?V:Ve.connected:W==="error"?(ye=l.errorText)!=null?ye:Ve.error:Ve[W]};Pt.textContent=C(i)},onStreamingChanged(i){ct=i,Ct(i),R&&wt(Q,R.getMessages(),m),i||ft(!0)}}),b&&b.then(i=>{var l;i&&(i.metadata&&(c=En(i.metadata),B.syncFromMetadata()),(l=i.messages)!=null&&l.length&&R.hydrateMessages(i.messages))}).catch(i=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to hydrate stored state:",i)});let Lt=i=>{i.preventDefault();let l=J.value.trim();l&&(J.value="",R.sendMessage(l))},kt=i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),E.click())},De=null,$e=!1,lt=null,et=null,Bt=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,f=(i="user")=>{var k,T,V,ye;if($e||R.isStreaming())return;let l=Bt();if(!l)return;De=new l;let N=(T=((k=e.voiceRecognition)!=null?k:{}).pauseDuration)!=null?T:2e3;De.continuous=!0,De.interimResults=!0,De.lang="en-US";let W=J.value;De.onresult=p=>{let w="",q="";for(let Y=0;Y<p.results.length;Y++){let qe=p.results[Y],Pe=qe[0].transcript;qe.isFinal?w+=Pe+" ":q=Pe}let be=W+w+q;J.value=be,lt&&clearTimeout(lt),(w||q)&&(lt=window.setTimeout(()=>{let Y=J.value.trim();Y&&De&&$e&&(_(),J.value="",R.sendMessage(Y,{viaVoice:!0}))},N))},De.onerror=p=>{p.error!=="no-speech"&&_()},De.onend=()=>{if($e){let p=J.value.trim();p&&p!==W.trim()&&(J.value="",R.sendMessage(p,{viaVoice:!0})),_()}};try{if(De.start(),$e=!0,re.active=!0,i!=="system"&&(re.manuallyDeactivated=!1),Mt(i),it(),S){et={backgroundColor:S.style.backgroundColor,color:S.style.color,borderColor:S.style.borderColor};let p=(V=e.voiceRecognition)!=null?V:{},w=(ye=p.recordingBackgroundColor)!=null?ye:"#ef4444",q=p.recordingIconColor,be=p.recordingBorderColor;if(S.classList.add("tvw-voice-recording"),S.style.backgroundColor=w,q){S.style.color=q;let Y=S.querySelector("svg");Y&&Y.setAttribute("stroke",q)}be&&(S.style.borderColor=be),S.setAttribute("aria-label","Stop voice recognition")}}catch{_("system")}},_=(i="user")=>{if($e){if($e=!1,lt&&(clearTimeout(lt),lt=null),De){try{De.stop()}catch{}De=null}if(re.active=!1,Mt(i),it(),S){if(S.classList.remove("tvw-voice-recording"),et){S.style.backgroundColor=et.backgroundColor,S.style.color=et.color,S.style.borderColor=et.borderColor;let l=S.querySelector("svg");l&&l.setAttribute("stroke",et.color||"currentColor"),et=null}S.setAttribute("aria-label","Start voice recognition")}}},X=(i,l)=>{var Pe,Xe,ee,tt,jt,Rt,xe;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let N=u("div","tvw-send-button-wrapper"),W=u("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");W.type="button",W.setAttribute("aria-label","Start voice recognition");let k=(Pe=i==null?void 0:i.iconName)!=null?Pe:"mic",T=(Xe=l==null?void 0:l.size)!=null?Xe:"40px",V=(ee=i==null?void 0:i.iconSize)!=null?ee:T,ye=parseFloat(V)||24,p=(tt=i==null?void 0:i.backgroundColor)!=null?tt:l==null?void 0:l.backgroundColor,w=(jt=i==null?void 0:i.iconColor)!=null?jt:l==null?void 0:l.textColor;W.style.width=V,W.style.height=V,W.style.minWidth=V,W.style.minHeight=V,W.style.fontSize="18px",W.style.lineHeight="1";let q=w||"currentColor",be=Ee(k,ye,q,1.5);be?(W.appendChild(be),W.style.color=q):(W.textContent="\u{1F3A4}",W.style.color=q),p?W.style.backgroundColor=p:W.classList.add("tvw-bg-cw-primary"),w?W.style.color=w:!w&&!(l!=null&&l.textColor)&&W.classList.add("tvw-text-white"),i!=null&&i.borderWidth&&(W.style.borderWidth=i.borderWidth,W.style.borderStyle="solid"),i!=null&&i.borderColor&&(W.style.borderColor=i.borderColor),i!=null&&i.paddingX&&(W.style.paddingLeft=i.paddingX,W.style.paddingRight=i.paddingX),i!=null&&i.paddingY&&(W.style.paddingTop=i.paddingY,W.style.paddingBottom=i.paddingY),N.appendChild(W);let Y=(Rt=i==null?void 0:i.tooltipText)!=null?Rt:"Start voice recognition";if(((xe=i==null?void 0:i.showTooltip)!=null?xe:!1)&&Y){let pt=u("div","tvw-send-button-tooltip");pt.textContent=Y,N.appendChild(pt)}return{micButton:W,micButtonWrapper:N}},ce=()=>{if($e){let i=J.value.trim();re.manuallyDeactivated=!0,it(),_("user"),i&&(J.value="",R.sendMessage(i))}else re.manuallyDeactivated=!1,it(),f("user")};S&&(S.addEventListener("click",ce),_e.push(()=>{_("system"),S&&S.removeEventListener("click",ce)}));let Ae=s.on("assistant:complete",()=>{At&&(re.active||re.manuallyDeactivated||At==="assistant"&&!re.lastUserMessageWasVoice||setTimeout(()=>{!re.active&&!re.manuallyDeactivated&&f("auto")},600))});_e.push(Ae);let Le=()=>{Oe(!M,"user")},D=y?vn(e,Le):null;D&&t.appendChild(D.element),ht(),dt.render(e.suggestionChips,R,J,void 0,e.suggestionChipsConfig),Et(),Ct(R.isStreaming()),ft(!0),qt();let v=()=>{var T,V;if(!y){Z.style.height="",Z.style.width="";return}let i=(V=(T=e==null?void 0:e.launcher)==null?void 0:T.width)!=null?V:e==null?void 0:e.launcherWidth,l=i!=null?i:"min(400px, calc(100vw - 24px))";Z.style.width=l,Z.style.maxWidth=l;let C=window.innerHeight,W=Math.max(200,C-64),k=Math.min(640,W);Z.style.height=`${k}px`};v(),window.addEventListener("resize",v),_e.push(()=>window.removeEventListener("resize",v)),Qe=K.scrollTop;let je=()=>{let i=K.scrollTop,l=K.scrollHeight,C=K.clientHeight,N=l-i-C,W=Math.abs(i-Qe);if(Qe=i,!Ke&&!(W<=Nt)){if(!Te&&N<Dt){ut=!1,Te=!0;return}Te&&N>Dt&&(ut=!0,U=Date.now()+bt,Te=!1)}};K.addEventListener("scroll",je,{passive:!0}),_e.push(()=>K.removeEventListener("scroll",je)),_e.push(()=>{ie&&cancelAnimationFrame(ie)});let $=()=>{L&&(st&&(L.removeEventListener("click",st),st=null),y?(L.style.display="",st=()=>{M=!1,ht()},L.addEventListener("click",st)):L.style.display="none")};$(),(()=>{let{clearChatButton:i}=Se;i&&i.addEventListener("click",()=>{R.clearMessages();try{localStorage.removeItem(Jt),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Jt}`)}catch(C){console.error("[AgentWidget] Failed to clear default localStorage:",C)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==Jt)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(C){console.error("[AgentWidget] Failed to clear custom localStorage:",C)}let l=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(l),a!=null&&a.clear)try{let C=a.clear();C instanceof Promise&&C.catch(N=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",N)})}catch(C){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",C)}c={},B.syncFromMetadata()})})(),yt.addEventListener("submit",Lt),J.addEventListener("keydown",kt),_e.push(()=>{yt.removeEventListener("submit",Lt),J.removeEventListener("keydown",kt)}),_e.push(()=>{R.cancel()}),D&&_e.push(()=>{D==null||D.destroy()});let d={update(i){var Bn,Rn,Hn,In,Pn,Fn,Nn,Dn,qn,zn,_n,On,$n,jn,Vn,Un,Kn,Xn,Yn,Jn,Gn,Zn,Qn,eo,to,no,oo,ro,so,io,ao,lo,co,uo,go,po,mo,fo,wo,ho,vo,yo,bo,xo,Co,So,To,Ao,Mo,Wo,Eo;let l=e.toolCall;e={...e,...i},hn(t,e);let C=en.getForInstance(e.plugins);o.length=0,o.push(...C),y=(Rn=(Bn=e.launcher)==null?void 0:Bn.enabled)!=null?Rn:!0,G=(In=(Hn=e.launcher)==null?void 0:Hn.autoExpand)!=null?In:!1,ke=(Fn=(Pn=e.features)==null?void 0:Pn.showReasoning)!=null?Fn:!0,ne=(Dn=(Nn=e.features)==null?void 0:Nn.showToolCalls)!=null?Dn:!0,((qn=e.launcher)==null?void 0:qn.enabled)===!1&&D&&(D.destroy(),D=null),((zn=e.launcher)==null?void 0:zn.enabled)!==!1&&!D&&(D=vn(e,Le),t.appendChild(D.element)),D&&D.update(e),Ft&&((_n=e.launcher)==null?void 0:_n.title)!==void 0&&(Ft.textContent=e.launcher.title),he&&((On=e.launcher)==null?void 0:On.subtitle)!==void 0&&(he.textContent=e.launcher.subtitle),y!==x?y?Oe(G,"auto"):(M=!0,ht()):G!==I&&Oe(G,"auto"),I=G,x=y,v(),$(),JSON.stringify(i.toolCall)!==JSON.stringify(l)&&R&&wt(Q,R.getMessages(),m);let T=($n=e.launcher)!=null?$n:{},V=(jn=T.headerIconHidden)!=null?jn:!1,ye=T.headerIconName,p=(Vn=T.headerIconSize)!=null?Vn:"48px";if(we){let A=fe.querySelector(".tvw-border-b-cw-divider"),We=A==null?void 0:A.querySelector(".tvw-flex-col");if(V)we.style.display="none",A&&We&&!A.contains(We)&&A.insertBefore(We,A.firstChild);else{if(we.style.display="",we.style.height=p,we.style.width=p,A&&We&&(A.contains(we)?we.nextSibling!==We&&(we.remove(),A.insertBefore(we,We)):A.insertBefore(we,We)),ye){let ze=parseFloat(p)||24,ge=Ee(ye,ze*.6,"#ffffff",2);ge?we.replaceChildren(ge):we.textContent=(Un=T.agentIconText)!=null?Un:"\u{1F4AC}"}else if(T.iconUrl){let ze=we.querySelector("img");if(ze)ze.src=T.iconUrl,ze.style.height=p,ze.style.width=p;else{let ge=document.createElement("img");ge.src=T.iconUrl,ge.alt="",ge.className="tvw-rounded-xl tvw-object-cover",ge.style.height=p,ge.style.width=p,we.replaceChildren(ge)}}else{let ze=we.querySelector("svg"),ge=we.querySelector("img");(ze||ge)&&we.replaceChildren(),we.textContent=(Kn=T.agentIconText)!=null?Kn:"\u{1F4AC}"}let Ie=we.querySelector("img");Ie&&(Ie.style.height=p,Ie.style.width=p)}}if(L){let A=(Xn=T.closeButtonSize)!=null?Xn:"32px",We=(Yn=T.closeButtonPlacement)!=null?Yn:"inline";L.style.height=A,L.style.width=A;let Ie=We==="top-right",ze=L.classList.contains("tvw-absolute");if(Ie!==ze)if(L.remove(),Ie)L.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50 tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none",fe.style.position="relative",fe.appendChild(L);else{L.className="tvw-ml-auto tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none";let te=fe.querySelector(".tvw-border-b-cw-divider");te&&te.appendChild(L)}if(T.closeButtonColor?(L.style.color=T.closeButtonColor,L.classList.remove("tvw-text-cw-muted")):(L.style.color="",L.classList.add("tvw-text-cw-muted")),T.closeButtonBackgroundColor?(L.style.backgroundColor=T.closeButtonBackgroundColor,L.classList.remove("hover:tvw-bg-gray-100")):(L.style.backgroundColor="",L.classList.add("hover:tvw-bg-gray-100")),T.closeButtonBorderWidth||T.closeButtonBorderColor){let te=T.closeButtonBorderWidth||"0px",vt=T.closeButtonBorderColor||"transparent";L.style.border=`${te} solid ${vt}`,L.classList.remove("tvw-border-none")}else L.style.border="",L.classList.add("tvw-border-none");T.closeButtonBorderRadius?(L.style.borderRadius=T.closeButtonBorderRadius,L.classList.remove("tvw-rounded-full")):(L.style.borderRadius="",L.classList.add("tvw-rounded-full")),T.closeButtonPaddingX?(L.style.paddingLeft=T.closeButtonPaddingX,L.style.paddingRight=T.closeButtonPaddingX):(L.style.paddingLeft="",L.style.paddingRight=""),T.closeButtonPaddingY?(L.style.paddingTop=T.closeButtonPaddingY,L.style.paddingBottom=T.closeButtonPaddingY):(L.style.paddingTop="",L.style.paddingBottom="");let ge=(Jn=T.closeButtonIconName)!=null?Jn:"x",St=(Gn=T.closeButtonIconText)!=null?Gn:"\xD7";L.innerHTML="";let Je=Ee(ge,"20px",T.closeButtonColor||"",2);Je?L.appendChild(Je):L.textContent=St;let{closeButtonWrapper:Ue}=Se,Ce=(Zn=T.closeButtonTooltipText)!=null?Zn:"Close chat",Ge=(Qn=T.closeButtonShowTooltip)!=null?Qn:!0;if(L.setAttribute("aria-label",Ce),Ue&&(Ue._cleanupTooltip&&(Ue._cleanupTooltip(),delete Ue._cleanupTooltip),Ge&&Ce)){let te=null,vt=()=>{if(te||!L)return;te=u("div","tvw-clear-chat-tooltip"),te.textContent=Ce;let Lo=u("div");Lo.className="tvw-clear-chat-tooltip-arrow",te.appendChild(Lo);let pn=L.getBoundingClientRect();te.style.position="fixed",te.style.left=`${pn.left+pn.width/2}px`,te.style.top=`${pn.top-8}px`,te.style.transform="translate(-50%, -100%)",document.body.appendChild(te)},nt=()=>{te&&te.parentNode&&(te.parentNode.removeChild(te),te=null)};Ue.addEventListener("mouseenter",vt),Ue.addEventListener("mouseleave",nt),L.addEventListener("focus",vt),L.addEventListener("blur",nt),Ue._cleanupTooltip=()=>{nt(),Ue&&(Ue.removeEventListener("mouseenter",vt),Ue.removeEventListener("mouseleave",nt)),L&&(L.removeEventListener("focus",vt),L.removeEventListener("blur",nt))}}}let{clearChatButton:w,clearChatButtonWrapper:q}=Se;if(w){let A=(eo=T.clearChat)!=null?eo:{},We=(to=A.enabled)!=null?to:!0;if(q&&(q.style.display=We?"":"none"),We){let Ie=(no=A.size)!=null?no:"32px";w.style.height=Ie,w.style.width=Ie;let ze=(oo=A.iconName)!=null?oo:"refresh-cw",ge=(ro=A.iconColor)!=null?ro:"";w.innerHTML="";let St=Ee(ze,"20px",ge||"",2);if(St&&w.appendChild(St),ge?(w.style.color=ge,w.classList.remove("tvw-text-cw-muted")):(w.style.color="",w.classList.add("tvw-text-cw-muted")),A.backgroundColor?(w.style.backgroundColor=A.backgroundColor,w.classList.remove("hover:tvw-bg-gray-100")):(w.style.backgroundColor="",w.classList.add("hover:tvw-bg-gray-100")),A.borderWidth||A.borderColor){let Ce=A.borderWidth||"0px",Ge=A.borderColor||"transparent";w.style.border=`${Ce} solid ${Ge}`,w.classList.remove("tvw-border-none")}else w.style.border="",w.classList.add("tvw-border-none");A.borderRadius?(w.style.borderRadius=A.borderRadius,w.classList.remove("tvw-rounded-full")):(w.style.borderRadius="",w.classList.add("tvw-rounded-full")),A.paddingX?(w.style.paddingLeft=A.paddingX,w.style.paddingRight=A.paddingX):(w.style.paddingLeft="",w.style.paddingRight=""),A.paddingY?(w.style.paddingTop=A.paddingY,w.style.paddingBottom=A.paddingY):(w.style.paddingTop="",w.style.paddingBottom="");let Je=(so=A.tooltipText)!=null?so:"Clear chat",Ue=(io=A.showTooltip)!=null?io:!0;if(w.setAttribute("aria-label",Je),q&&(q._cleanupTooltip&&(q._cleanupTooltip(),delete q._cleanupTooltip),Ue&&Je)){let Ce=null,Ge=()=>{if(Ce||!w)return;Ce=u("div","tvw-clear-chat-tooltip"),Ce.textContent=Je;let vt=u("div");vt.className="tvw-clear-chat-tooltip-arrow",Ce.appendChild(vt);let nt=w.getBoundingClientRect();Ce.style.position="fixed",Ce.style.left=`${nt.left+nt.width/2}px`,Ce.style.top=`${nt.top-8}px`,Ce.style.transform="translate(-50%, -100%)",document.body.appendChild(Ce)},te=()=>{Ce&&Ce.parentNode&&(Ce.parentNode.removeChild(Ce),Ce=null)};q.addEventListener("mouseenter",Ge),q.addEventListener("mouseleave",te),w.addEventListener("focus",Ge),w.addEventListener("blur",te),q._cleanupTooltip=()=>{te(),q&&(q.removeEventListener("mouseenter",Ge),q.removeEventListener("mouseleave",te)),w&&(w.removeEventListener("focus",Ge),w.removeEventListener("blur",te))}}}}let be=e.actionParsers&&e.actionParsers.length?e.actionParsers:[tn],Y=e.actionHandlers&&e.actionHandlers.length?e.actionHandlers:[Kt.message,Kt.messageAndClick];B=nn({parsers:be,handlers:Y,getMetadata:z,updateMetadata:g,emit:s.emit,documentRef:typeof document!="undefined"?document:null}),m=$o(e,B),R.updateConfig(e),wt(Q,R.getMessages(),m),dt.render(e.suggestionChips,R,J,void 0,e.suggestionChipsConfig),Et(),Ct(R.isStreaming());let qe=((ao=e.voiceRecognition)==null?void 0:ao.enabled)===!0,Pe=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),Xe=qe&&Pe;if(yt.classList.remove("tvw-gap-1","tvw-gap-3"),yt.classList.add(Xe?"tvw-gap-1":"tvw-gap-3"),qe&&Pe)if(!S||!Ne){let A=X(e.voiceRecognition,e.sendButton);A&&(S=A.micButton,Ne=A.micButtonWrapper,yt.insertBefore(Ne,ot),S.addEventListener("click",ce),S.disabled=R.isStreaming())}else{let A=(lo=e.voiceRecognition)!=null?lo:{},We=(co=e.sendButton)!=null?co:{},Ie=(uo=A.iconName)!=null?uo:"mic",ze=(go=We.size)!=null?go:"40px",ge=(po=A.iconSize)!=null?po:ze,St=parseFloat(ge)||24;S.style.width=ge,S.style.height=ge,S.style.minWidth=ge,S.style.minHeight=ge;let Je=(fo=(mo=A.iconColor)!=null?mo:We.textColor)!=null?fo:"currentColor";S.innerHTML="";let Ue=Ee(Ie,St,Je,2);Ue?S.appendChild(Ue):S.textContent="\u{1F3A4}";let Ce=(wo=A.backgroundColor)!=null?wo:We.backgroundColor;Ce?(S.style.backgroundColor=Ce,S.classList.remove("tvw-bg-cw-primary")):(S.style.backgroundColor="",S.classList.add("tvw-bg-cw-primary")),Je?(S.style.color=Je,S.classList.remove("tvw-text-white")):!Je&&!We.textColor&&(S.style.color="",S.classList.add("tvw-text-white")),A.borderWidth?(S.style.borderWidth=A.borderWidth,S.style.borderStyle="solid"):(S.style.borderWidth="",S.style.borderStyle=""),A.borderColor?S.style.borderColor=A.borderColor:S.style.borderColor="",A.paddingX?(S.style.paddingLeft=A.paddingX,S.style.paddingRight=A.paddingX):(S.style.paddingLeft="",S.style.paddingRight=""),A.paddingY?(S.style.paddingTop=A.paddingY,S.style.paddingBottom=A.paddingY):(S.style.paddingTop="",S.style.paddingBottom="");let Ge=Ne==null?void 0:Ne.querySelector(".tvw-send-button-tooltip"),te=(ho=A.tooltipText)!=null?ho:"Start voice recognition";if(((vo=A.showTooltip)!=null?vo:!1)&&te)if(Ge)Ge.textContent=te,Ge.style.display="";else{let nt=document.createElement("div");nt.className="tvw-send-button-tooltip",nt.textContent=te,Ne==null||Ne.insertBefore(nt,S)}else Ge&&(Ge.style.display="none");Ne.style.display="",S.disabled=R.isStreaming()}else S&&Ne&&(Ne.style.display="none",$e&&_());let ee=(yo=e.sendButton)!=null?yo:{},tt=(bo=ee.useIcon)!=null?bo:!1,jt=(xo=ee.iconText)!=null?xo:"\u2191",Rt=ee.iconName,xe=(Co=ee.tooltipText)!=null?Co:"Send message",pt=(So=ee.showTooltip)!=null?So:!1,mt=(To=ee.size)!=null?To:"40px",Vt=ee.backgroundColor,Ye=ee.textColor;if(tt){if(E.style.width=mt,E.style.height=mt,E.style.minWidth=mt,E.style.minHeight=mt,E.style.fontSize="18px",E.style.lineHeight="1",E.innerHTML="",Rt){let A=parseFloat(mt)||24,We=Ye&&typeof Ye=="string"&&Ye.trim()?Ye.trim():"currentColor",Ie=Ee(Rt,A,We,2);Ie?(E.appendChild(Ie),E.style.color=We):(E.textContent=jt,Ye?E.style.color=Ye:E.classList.add("tvw-text-white"))}else E.textContent=jt,Ye?E.style.color=Ye:E.classList.add("tvw-text-white");E.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",Vt?(E.style.backgroundColor=Vt,E.classList.remove("tvw-bg-cw-primary")):E.classList.add("tvw-bg-cw-primary")}else E.textContent=(Mo=(Ao=e.copy)==null?void 0:Ao.sendButtonLabel)!=null?Mo:"Send",E.style.width="",E.style.height="",E.style.minWidth="",E.style.minHeight="",E.style.fontSize="",E.style.lineHeight="",E.className="tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-50 tvw-cursor-pointer",Vt?(E.style.backgroundColor=Vt,E.classList.remove("tvw-bg-cw-accent")):E.classList.add("tvw-bg-cw-accent"),Ye?E.style.color=Ye:E.classList.add("tvw-text-white");ee.borderWidth?(E.style.borderWidth=ee.borderWidth,E.style.borderStyle="solid"):(E.style.borderWidth="",E.style.borderStyle=""),ee.borderColor?E.style.borderColor=ee.borderColor:E.style.borderColor="",ee.paddingX?(E.style.paddingLeft=ee.paddingX,E.style.paddingRight=ee.paddingX):(E.style.paddingLeft="",E.style.paddingRight=""),ee.paddingY?(E.style.paddingTop=ee.paddingY,E.style.paddingBottom=ee.paddingY):(E.style.paddingTop="",E.style.paddingBottom="");let Zt=ot==null?void 0:ot.querySelector(".tvw-send-button-tooltip");if(pt&&xe)if(Zt)Zt.textContent=xe,Zt.style.display="";else{let A=document.createElement("div");A.className="tvw-send-button-tooltip",A.textContent=xe,ot==null||ot.insertBefore(A,E)}else Zt&&(Zt.style.display="none");let Qt=(Wo=e.statusIndicator)!=null?Wo:{},Uo=(Eo=Qt.visible)!=null?Eo:!0;if(Pt.style.display=Uo?"":"none",R){let A=R.getStatus(),We=Ie=>{var ze,ge,St,Je;return Ie==="idle"?(ze=Qt.idleText)!=null?ze:Ve.idle:Ie==="connecting"?(ge=Qt.connectingText)!=null?ge:Ve.connecting:Ie==="connected"?(St=Qt.connectedText)!=null?St:Ve.connected:Ie==="error"?(Je=Qt.errorText)!=null?Je:Ve.error:Ve[Ie]};Pt.textContent=We(A)}},open(){y&&Oe(!0,"api")},close(){y&&Oe(!1,"api")},toggle(){y&&Oe(!M,"api")},clearChat(){R.clearMessages();try{localStorage.removeItem(Jt),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Jt}`)}catch(l){console.error("[AgentWidget] Failed to clear default localStorage:",l)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==Jt)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(l){console.error("[AgentWidget] Failed to clear custom localStorage:",l)}let i=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(i),a!=null&&a.clear)try{let l=a.clear();l instanceof Promise&&l.catch(C=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",C)})}catch(l){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",l)}c={},B.syncFromMetadata()},setMessage(i){return!J||R.isStreaming()?!1:(!M&&y&&Oe(!0,"system"),J.value=i,J.dispatchEvent(new Event("input",{bubbles:!0})),!0)},submitMessage(i){if(R.isStreaming())return!1;let l=(i==null?void 0:i.trim())||J.value.trim();return l?(!M&&y&&Oe(!0,"system"),J.value="",R.sendMessage(l),!0):!1},startVoiceRecognition(){return $e||R.isStreaming()||!Bt()?!1:(!M&&y&&Oe(!0,"system"),re.manuallyDeactivated=!1,it(),f("user"),!0)},stopVoiceRecognition(){return $e?(re.manuallyDeactivated=!0,it(),_("user"),!0):!1},injectTestMessage(i){!M&&y&&Oe(!0,"system"),R.injectTestEvent(i)},getMessages(){return R.getMessages()},getStatus(){return R.getStatus()},getPersistentMetadata(){return{...c}},updatePersistentMetadata(i){g(i)},on(i,l){return s.on(i,l)},off(i,l){s.off(i,l)},isOpen(){return y&&M},isVoiceActive(){return re.active},getState(){return{open:y&&M,launcherEnabled:y,voiceActive:re.active,streaming:R.isStreaming()}},destroy(){_e.forEach(i=>i()),me.remove(),D==null||D.destroy(),st&&L.removeEventListener("click",st)}};if((((Gt=r==null?void 0:r.debugTools)!=null?Gt:!1)||!!e.debug)&&typeof window!="undefined"){let i=window.AgentWidgetBrowser,l={controller:d,getMessages:d.getMessages,getStatus:d.getStatus,getMetadata:d.getPersistentMetadata,updateMetadata:d.updatePersistentMetadata,clearHistory:()=>d.clearChat(),setVoiceActive:C=>C?d.startVoiceRecognition():d.stopVoiceRecognition()};window.AgentWidgetBrowser=l,_e.push(()=>{window.AgentWidgetBrowser===l&&(window.AgentWidgetBrowser=i)})}return d};var Ln={},pr=t=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof t=="string"){let n=document.querySelector(t);if(!n)throw new Error(`Chat widget target "${t}" was not found`);return n}return t},mr=()=>{try{if(typeof Ln!="undefined"&&Ln.url)return new URL("../widget.css",Ln.url).href}catch{}return null},jo=t=>{let n=mr(),r=()=>{if(!(t instanceof ShadowRoot)||t.querySelector("link[data-vanilla-agent]"))return;let e=document.head.querySelector("link[data-vanilla-agent]");if(!e)return;let o=e.cloneNode(!0);t.insertBefore(o,t.firstChild)};if(t instanceof ShadowRoot)if(n){let e=document.createElement("link");e.rel="stylesheet",e.href=n,e.setAttribute("data-vanilla-agent","true"),t.insertBefore(e,t.firstChild)}else r();else if(!document.head.querySelector("link[data-vanilla-agent]")&&n){let o=document.createElement("link");o.rel="stylesheet",o.href=n,o.setAttribute("data-vanilla-agent","true"),document.head.appendChild(o)}},kn=t=>{var b;let n=pr(t.target),r=document.createElement("div");r.className="vanilla-agent-host",n.appendChild(r);let e=t.useShadowDom!==!1,o,s;if(e){let z=r.attachShadow({mode:"open"});s=z,o=document.createElement("div"),o.id="vanilla-agent-root",z.appendChild(o),jo(z)}else s=r,o=document.createElement("div"),o.id="vanilla-agent-root",r.appendChild(o),jo(r);let a=gn(o,t.config,{debugTools:t.debugTools});(b=t.onReady)==null||b.call(t);let c={...a,host:r,destroy(){a.destroy(),r.remove(),t.windowKey&&typeof window!="undefined"&&delete window[t.windowKey]}};return t.windowKey&&typeof window!="undefined"&&(window[t.windowKey]=c),c};var fr=t=>{if(!t)return null;try{return JSON.parse(t)}catch(n){return typeof console!="undefined"&&console.error("[AgentWidget] Failed to parse stored state:",n),null}},wr=t=>t.map(n=>({...n,streaming:!1})),Vo=(t="vanilla-agent-state")=>{let n=()=>typeof window=="undefined"||!window.localStorage?null:window.localStorage;return{load:()=>{let r=n();return r?fr(r.getItem(t)):null},save:r=>{let e=n();if(e)try{let o={...r,messages:r.messages?wr(r.messages):void 0};e.setItem(t,JSON.stringify(o))}catch(o){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",o)}},clear:()=>{let r=n();if(r)try{r.removeItem(t)}catch(e){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear stored state:",e)}}}};var hr=kn;0&&(module.exports={AgentWidgetClient,AgentWidgetSession,DEFAULT_WIDGET_CONFIG,createActionManager,createAgentExperience,createFlexibleJsonStreamParser,createJsonStreamParser,createLocalStorageAdapter,createPlainTextParser,createRegexJsonParser,createXmlParser,defaultActionHandlers,defaultJsonActionParser,directivePostprocessor,escapeHtml,initAgentWidget,markdownPostprocessor,mergeWithDefaults,pluginRegistry});
14
+ `,o.addEventListener("click",n);let e=s=>{var O,q,f,S,I,T,U,R,J,te;let i=(O=s.launcher)!=null?O:{},l=o.querySelector("[data-role='launcher-title']");l&&(l.textContent=(q=i.title)!=null?q:"Chat Assistant");let u=o.querySelector("[data-role='launcher-subtitle']");u&&(u.textContent=(f=i.subtitle)!=null?f:"Get answers fast");let m=o.querySelector(".tvw-flex-col");m&&(i.textHidden?m.style.display="none":m.style.display="");let d=o.querySelector("[data-role='launcher-icon']");if(d)if(i.agentIconHidden)d.style.display="none";else{let A=(S=i.agentIconSize)!=null?S:"40px";if(d.style.height=A,d.style.width=A,d.innerHTML="",i.agentIconName){let se=parseFloat(A)||24,V=ge(i.agentIconName,se*.6,"#ffffff",2);V?(d.appendChild(V),d.style.display=""):(d.textContent=(I=i.agentIconText)!=null?I:"\u{1F4AC}",d.style.display="")}else i.iconUrl?d.style.display="none":(d.textContent=(T=i.agentIconText)!=null?T:"\u{1F4AC}",d.style.display="")}let W=o.querySelector("[data-role='launcher-image']");if(W){let A=(U=i.agentIconSize)!=null?U:"40px";W.style.height=A,W.style.width=A,i.iconUrl&&!i.agentIconName&&!i.agentIconHidden?(W.src=i.iconUrl,W.style.display="block"):W.style.display="none"}let h=o.querySelector("[data-role='launcher-call-to-action-icon']");if(h){let A=(R=i.callToActionIconSize)!=null?R:"32px";h.style.height=A,h.style.width=A,i.callToActionIconBackgroundColor?(h.style.backgroundColor=i.callToActionIconBackgroundColor,h.classList.remove("tvw-bg-cw-primary")):(h.style.backgroundColor="",h.classList.add("tvw-bg-cw-primary"));let se=0;if(i.callToActionIconPadding?(h.style.boxSizing="border-box",h.style.padding=i.callToActionIconPadding,se=(parseFloat(i.callToActionIconPadding)||0)*2):(h.style.boxSizing="",h.style.padding=""),i.callToActionIconHidden)h.style.display="none";else if(h.style.display="",h.innerHTML="",i.callToActionIconName){let V=parseFloat(A)||24,j=Math.max(V-se,8),ne=ge(i.callToActionIconName,j,"currentColor",2);ne?h.appendChild(ne):h.textContent=(J=i.callToActionIconText)!=null?J:"\u2197"}else h.textContent=(te=i.callToActionIconText)!=null?te:"\u2197"}let C=i.position&&Pt[i.position]?Pt[i.position]:Pt["bottom-right"],v="tvw-fixed tvw-flex tvw-items-center tvw-gap-3 tvw-rounded-launcher tvw-bg-cw-surface tvw-py-2.5 tvw-pl-3 tvw-pr-3 tvw-shadow-lg tvw-border tvw-border-gray-200 tvw-transition hover:tvw-translate-y-[-2px] tvw-cursor-pointer tvw-z-50";o.className=`${v} ${C}`},r=()=>{o.removeEventListener("click",n),o.remove()};return t&&e(t),{element:o,update:e,destroy:r}};var Ft=t=>{var se,V,j,ne,ue,oe,P,_e,Ke,et,wt,vt,N,de,pt,gt,Xe,st,B,ke,it,at,St,mt,Fe,tt,je,D,lt,Ye,We,qe;let{config:n,showClose:o=!0}=t,e=c("div","tvw-flex tvw-items-center tvw-gap-3 tvw-bg-cw-surface tvw-px-6 tvw-py-5 tvw-border-b-cw-divider"),r=(se=n==null?void 0:n.launcher)!=null?se:{},s=(V=r.headerIconSize)!=null?V:"48px",i=(j=r.closeButtonSize)!=null?j:"32px",l=(ne=r.closeButtonPlacement)!=null?ne:"inline",u=(ue=r.headerIconHidden)!=null?ue:!1,m=r.headerIconName,d=c("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-xl");if(d.style.height=s,d.style.width=s,!u)if(m){let K=parseFloat(s)||24,ve=ge(m,K*.6,"#ffffff",2);ve?d.replaceChildren(ve):d.textContent=(P=(oe=n==null?void 0:n.launcher)==null?void 0:oe.agentIconText)!=null?P:"\u{1F4AC}"}else if((_e=n==null?void 0:n.launcher)!=null&&_e.iconUrl){let K=c("img");K.src=n.launcher.iconUrl,K.alt="",K.className="tvw-rounded-xl tvw-object-cover",K.style.height=s,K.style.width=s,d.replaceChildren(K)}else d.textContent=(et=(Ke=n==null?void 0:n.launcher)==null?void 0:Ke.agentIconText)!=null?et:"\u{1F4AC}";let W=c("div","tvw-flex tvw-flex-col"),h=c("span","tvw-text-base tvw-font-semibold");h.textContent=(vt=(wt=n==null?void 0:n.launcher)==null?void 0:wt.title)!=null?vt:"Chat Assistant";let C=c("span","tvw-text-xs tvw-text-cw-muted");C.textContent=(de=(N=n==null?void 0:n.launcher)==null?void 0:N.subtitle)!=null?de:"Here to help you get answers fast",W.append(h,C),u?e.append(W):e.append(d,W);let v=(pt=r.clearChat)!=null?pt:{},O=(gt=v.enabled)!=null?gt:!0,q=(Xe=v.placement)!=null?Xe:"inline",f=null,S=null;if(O){let K=(st=v.size)!=null?st:"32px",ve=(B=v.iconName)!=null?B:"refresh-cw",Re=(ke=v.iconColor)!=null?ke:"",Ue=(it=v.backgroundColor)!=null?it:"",nt=(at=v.borderWidth)!=null?at:"",yt=(St=v.borderColor)!=null?St:"",Mt=(mt=v.borderRadius)!=null?mt:"",ct=(Fe=v.paddingX)!=null?Fe:"",xt=(tt=v.paddingY)!=null?tt:"",ie=(je=v.tooltipText)!=null?je:"Clear chat",Nt=(D=v.showTooltip)!=null?D:!0;S=c("div",q==="top-right"?"tvw-absolute tvw-top-4 tvw-z-50":"tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper"),q==="top-right"&&(S.style.right="48px"),f=c("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none"),f.style.height=K,f.style.width=K,f.type="button",f.setAttribute("aria-label",ie);let Lt=ge(ve,"20px",Re||"",2);if(Lt&&f.appendChild(Lt),Re&&(f.style.color=Re,f.classList.remove("tvw-text-cw-muted")),Ue&&(f.style.backgroundColor=Ue,f.classList.remove("hover:tvw-bg-gray-100")),nt||yt){let me=nt||"0px",ft=yt||"transparent";f.style.border=`${me} solid ${ft}`,f.classList.remove("tvw-border-none")}if(Mt&&(f.style.borderRadius=Mt,f.classList.remove("tvw-rounded-full")),ct?(f.style.paddingLeft=ct,f.style.paddingRight=ct):(f.style.paddingLeft="",f.style.paddingRight=""),xt?(f.style.paddingTop=xt,f.style.paddingBottom=xt):(f.style.paddingTop="",f.style.paddingBottom=""),S.appendChild(f),Nt&&ie&&f&&S){let me=null,ft=()=>{if(me||!f)return;me=c("div","tvw-clear-chat-tooltip"),me.textContent=ie;let Bt=c("div");Bt.className="tvw-clear-chat-tooltip-arrow",me.appendChild(Bt);let ht=f.getBoundingClientRect();me.style.position="fixed",me.style.left=`${ht.left+ht.width/2}px`,me.style.top=`${ht.top-8}px`,me.style.transform="translate(-50%, -100%)",document.body.appendChild(me)},bt=()=>{me&&me.parentNode&&(me.parentNode.removeChild(me),me=null)};S.addEventListener("mouseenter",ft),S.addEventListener("mouseleave",bt),f.addEventListener("focus",ft),f.addEventListener("blur",bt),S._cleanupTooltip=()=>{bt(),S&&(S.removeEventListener("mouseenter",ft),S.removeEventListener("mouseleave",bt)),f&&(f.removeEventListener("focus",ft),f.removeEventListener("blur",bt))}}q==="inline"&&e.appendChild(S)}let I=c("div",l==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50":O&&q==="inline"?"":"tvw-ml-auto"),T=c("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none");T.style.height=i,T.style.width=i,T.type="button";let U=(lt=r.closeButtonTooltipText)!=null?lt:"Close chat",R=(Ye=r.closeButtonShowTooltip)!=null?Ye:!0;T.setAttribute("aria-label",U),T.style.display=o?"":"none";let J=(We=r.closeButtonIconName)!=null?We:"x",te=(qe=r.closeButtonIconText)!=null?qe:"\xD7",A=ge(J,"20px",r.closeButtonColor||"",2);if(A?T.appendChild(A):T.textContent=te,r.closeButtonColor?(T.style.color=r.closeButtonColor,T.classList.remove("tvw-text-cw-muted")):(T.style.color="",T.classList.add("tvw-text-cw-muted")),r.closeButtonBackgroundColor?(T.style.backgroundColor=r.closeButtonBackgroundColor,T.classList.remove("hover:tvw-bg-gray-100")):(T.style.backgroundColor="",T.classList.add("hover:tvw-bg-gray-100")),r.closeButtonBorderWidth||r.closeButtonBorderColor){let K=r.closeButtonBorderWidth||"0px",ve=r.closeButtonBorderColor||"transparent";T.style.border=`${K} solid ${ve}`,T.classList.remove("tvw-border-none")}else T.style.border="",T.classList.add("tvw-border-none");if(r.closeButtonBorderRadius?(T.style.borderRadius=r.closeButtonBorderRadius,T.classList.remove("tvw-rounded-full")):(T.style.borderRadius="",T.classList.add("tvw-rounded-full")),r.closeButtonPaddingX?(T.style.paddingLeft=r.closeButtonPaddingX,T.style.paddingRight=r.closeButtonPaddingX):(T.style.paddingLeft="",T.style.paddingRight=""),r.closeButtonPaddingY?(T.style.paddingTop=r.closeButtonPaddingY,T.style.paddingBottom=r.closeButtonPaddingY):(T.style.paddingTop="",T.style.paddingBottom=""),I.appendChild(T),R&&U){let K=null,ve=()=>{if(K)return;K=c("div","tvw-clear-chat-tooltip"),K.textContent=U;let Ue=c("div");Ue.className="tvw-clear-chat-tooltip-arrow",K.appendChild(Ue);let nt=T.getBoundingClientRect();K.style.position="fixed",K.style.left=`${nt.left+nt.width/2}px`,K.style.top=`${nt.top-8}px`,K.style.transform="translate(-50%, -100%)",document.body.appendChild(K)},Re=()=>{K&&K.parentNode&&(K.parentNode.removeChild(K),K=null)};I.addEventListener("mouseenter",ve),I.addEventListener("mouseleave",Re),T.addEventListener("focus",ve),T.addEventListener("blur",Re),I._cleanupTooltip=()=>{Re(),I.removeEventListener("mouseenter",ve),I.removeEventListener("mouseleave",Re),T.removeEventListener("focus",ve),T.removeEventListener("blur",Re)}}return l!=="top-right"&&e.appendChild(I),{header:e,iconHolder:d,headerTitle:h,headerSubtitle:C,closeButton:T,closeButtonWrapper:I,clearChatButton:f,clearChatButtonWrapper:S}},Kt=(t,n,o)=>{var i,l,u,m;let e=(i=o==null?void 0:o.launcher)!=null?i:{},r=(l=e.closeButtonPlacement)!=null?l:"inline",s=(m=(u=e.clearChat)==null?void 0:u.placement)!=null?m:"inline";t.appendChild(n.header),r==="top-right"&&(t.style.position="relative",t.appendChild(n.closeButtonWrapper)),n.clearChatButtonWrapper&&s==="top-right"&&(t.style.position="relative",t.appendChild(n.clearChatButtonWrapper))};var Pn=t=>Ft({config:t.config,showClose:t.showClose,onClose:t.onClose,onClearChat:t.onClearChat}),Fn=t=>{var v,O,q,f;let{config:n,showClose:o=!0,onClose:e}=t,r=(v=n==null?void 0:n.launcher)!=null?v:{},s=c("div","tvw-flex tvw-items-center tvw-justify-between tvw-bg-cw-surface tvw-px-6 tvw-py-4 tvw-border-b-cw-divider"),i=c("span","tvw-text-base tvw-font-semibold");i.textContent=(O=r.title)!=null?O:"Chat Assistant",s.appendChild(i);let l=(q=r.closeButtonSize)!=null?q:"32px",u=c("div",""),m=c("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none");m.style.height=l,m.style.width=l,m.type="button",m.setAttribute("aria-label","Close chat"),m.style.display=o?"":"none";let d=(f=r.closeButtonIconName)!=null?f:"x",W=ge(d,"20px",r.closeButtonColor||"",2);W?m.appendChild(W):m.textContent="\xD7",e&&m.addEventListener("click",e),u.appendChild(m),s.appendChild(u);let h=c("div");h.style.display="none";let C=c("span");return C.style.display="none",{header:s,iconHolder:h,headerTitle:i,headerSubtitle:C,closeButton:m,closeButtonWrapper:u,clearChatButton:null,clearChatButtonWrapper:null}},Nn=t=>{var T,U,R,J,te,A,se,V;let{config:n,showClose:o=!0,onClose:e,onClearChat:r}=t,s=(T=n==null?void 0:n.launcher)!=null?T:{},i=c("div","tvw-flex tvw-flex-col tvw-bg-cw-surface tvw-px-6 tvw-py-5 tvw-border-b-cw-divider"),l=c("div","tvw-flex tvw-items-center tvw-gap-3"),u=(U=s.headerIconSize)!=null?U:"56px",m=c("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-2xl");m.style.height=u,m.style.width=u;let d=s.headerIconName;if(d){let j=parseFloat(u)||24,ne=ge(d,j*.5,"#ffffff",2);ne?m.replaceChildren(ne):m.textContent=(R=s.agentIconText)!=null?R:"\u{1F4AC}"}else if(s.iconUrl){let j=c("img");j.src=s.iconUrl,j.alt="",j.className="tvw-rounded-xl tvw-object-cover",j.style.height=u,j.style.width=u,m.replaceChildren(j)}else m.textContent=(J=s.agentIconText)!=null?J:"\u{1F4AC}";let W=c("div","tvw-flex tvw-flex-col tvw-flex-1"),h=c("span","tvw-text-lg tvw-font-semibold");h.textContent=(te=s.title)!=null?te:"Chat Assistant";let C=c("span","tvw-text-sm tvw-text-cw-muted");C.textContent=(A=s.subtitle)!=null?A:"Here to help you get answers fast",W.append(h,C),l.append(m,W);let v=(se=s.closeButtonSize)!=null?se:"32px",O=c("div",""),q=c("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none");q.style.height=v,q.style.width=v,q.type="button",q.setAttribute("aria-label","Close chat"),q.style.display=o?"":"none";let f=(V=s.closeButtonIconName)!=null?V:"x",S=ge(f,"20px",s.closeButtonColor||"",2);S?q.appendChild(S):q.textContent="\xD7",e&&q.addEventListener("click",e),O.appendChild(q),l.appendChild(O),i.appendChild(l);let I=c("div","tvw-mt-3 tvw-pt-3 tvw-border-t tvw-border-gray-100 tvw-text-xs tvw-text-cw-muted");return I.textContent="Online and ready to help",i.appendChild(I),{header:i,iconHolder:m,headerTitle:h,headerSubtitle:C,closeButton:q,closeButtonWrapper:O,clearChatButton:null,clearChatButtonWrapper:null}},bn={default:Pn,minimal:Fn,expanded:Nn},Dn=t=>{var n;return(n=bn[t])!=null?n:bn.default},Cn=(t,n,o)=>{var i,l,u;if(n!=null&&n.render){let m=n.render({config:t,onClose:o==null?void 0:o.onClose,onClearChat:o==null?void 0:o.onClearChat}),d=c("div");d.style.display="none";let W=c("span"),h=c("span"),C=c("button");C.style.display="none";let v=c("div");return v.style.display="none",{header:m,iconHolder:d,headerTitle:W,headerSubtitle:h,closeButton:C,closeButtonWrapper:v,clearChatButton:null,clearChatButtonWrapper:null}}let e=(i=n==null?void 0:n.layout)!=null?i:"default",s=Dn(e)({config:t,showClose:(u=(l=n==null?void 0:n.showCloseButton)!=null?l:o==null?void 0:o.showClose)!=null?u:!0,onClose:o==null?void 0:o.onClose,onClearChat:o==null?void 0:o.onClearChat});return n&&(n.showIcon===!1&&(s.iconHolder.style.display="none"),n.showTitle===!1&&(s.headerTitle.style.display="none"),n.showSubtitle===!1&&(s.headerSubtitle.style.display="none"),n.showCloseButton===!1&&(s.closeButton.style.display="none"),n.showClearChat===!1&&s.clearChatButtonWrapper&&(s.clearChatButtonWrapper.style.display="none")),s};var jr=t=>{switch(t){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}},Xt=t=>{var oe,P,_e,Ke,et,wt,vt,N,de,pt,gt,Xe,st,B,ke,it,at,St,mt,Fe,tt,je,D,lt,Ye;let{config:n}=t,o=c("div","tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),e=c("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),r=((oe=n==null?void 0:n.voiceRecognition)==null?void 0:oe.enabled)===!0,s=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),u=c("form",`tvw-flex tvw-items-end ${r&&s?"tvw-gap-1":"tvw-gap-3"} tvw-rounded-2xl tvw-border tvw-border-gray-200 tvw-bg-cw-input-background tvw-px-4 tvw-py-3`);u.style.outline="none";let m=c("textarea");m.placeholder=(_e=(P=n==null?void 0:n.copy)==null?void 0:P.inputPlaceholder)!=null?_e:"Type your message\u2026",m.className="tvw-min-h-[48px] tvw-flex-1 tvw-resize-none tvw-border-none tvw-bg-transparent tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-none",m.rows=1;let d=(et=(Ke=n==null?void 0:n.theme)==null?void 0:Ke.inputFontFamily)!=null?et:"sans-serif",W=(vt=(wt=n==null?void 0:n.theme)==null?void 0:wt.inputFontWeight)!=null?vt:"400";m.style.fontFamily=jr(d),m.style.fontWeight=W,m.style.border="none",m.style.outline="none",m.style.borderWidth="0",m.style.borderStyle="none",m.style.borderColor="transparent",m.addEventListener("focus",()=>{m.style.border="none",m.style.outline="none",m.style.borderWidth="0",m.style.borderStyle="none",m.style.borderColor="transparent",m.style.boxShadow="none"}),m.addEventListener("blur",()=>{m.style.border="none",m.style.outline="none"});let h=(N=n==null?void 0:n.sendButton)!=null?N:{},C=(de=h.useIcon)!=null?de:!1,v=(pt=h.iconText)!=null?pt:"\u2191",O=h.iconName,q=(gt=h.tooltipText)!=null?gt:"Send message",f=(Xe=h.showTooltip)!=null?Xe:!1,S=(st=h.size)!=null?st:"40px",I=h.backgroundColor,T=h.textColor,U=c("div","tvw-send-button-wrapper"),R=c("button",C?"tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer":"tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold disabled:tvw-opacity-50 tvw-cursor-pointer");if(R.type="submit",C){if(R.style.width=S,R.style.height=S,R.style.minWidth=S,R.style.minHeight=S,R.style.fontSize="18px",R.style.lineHeight="1",R.innerHTML="",O){let We=parseFloat(S)||24,qe=T&&typeof T=="string"&&T.trim()?T.trim():"currentColor",K=ge(O,We,qe,2);K?(R.appendChild(K),R.style.color=qe):(R.textContent=v,T?R.style.color=T:R.classList.add("tvw-text-white"))}else R.textContent=v,T?R.style.color=T:R.classList.add("tvw-text-white");I?R.style.backgroundColor=I:R.classList.add("tvw-bg-cw-primary")}else R.textContent=(ke=(B=n==null?void 0:n.copy)==null?void 0:B.sendButtonLabel)!=null?ke:"Send",T?R.style.color=T:R.classList.add("tvw-text-white");if(h.borderWidth&&(R.style.borderWidth=h.borderWidth,R.style.borderStyle="solid"),h.borderColor&&(R.style.borderColor=h.borderColor),h.paddingX?(R.style.paddingLeft=h.paddingX,R.style.paddingRight=h.paddingX):(R.style.paddingLeft="",R.style.paddingRight=""),h.paddingY?(R.style.paddingTop=h.paddingY,R.style.paddingBottom=h.paddingY):(R.style.paddingTop="",R.style.paddingBottom=""),f&&q){let We=c("div","tvw-send-button-tooltip");We.textContent=q,U.appendChild(We)}U.appendChild(R);let J=(it=n==null?void 0:n.voiceRecognition)!=null?it:{},te=J.enabled===!0,A=null,se=null,V=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(te&&V){se=c("div","tvw-send-button-wrapper"),A=c("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),A.type="button",A.setAttribute("aria-label","Start voice recognition");let We=(at=J.iconName)!=null?at:"mic",qe=(St=J.iconSize)!=null?St:S,K=parseFloat(qe)||24,ve=(mt=J.backgroundColor)!=null?mt:I,Re=(Fe=J.iconColor)!=null?Fe:T;A.style.width=qe,A.style.height=qe,A.style.minWidth=qe,A.style.minHeight=qe,A.style.fontSize="18px",A.style.lineHeight="1";let Ue=Re||"currentColor",nt=ge(We,K,Ue,1.5);nt?(A.appendChild(nt),A.style.color=Ue):(A.textContent="\u{1F3A4}",A.style.color=Ue),ve?A.style.backgroundColor=ve:A.classList.add("tvw-bg-cw-primary"),Re?A.style.color=Re:!Re&&!T&&A.classList.add("tvw-text-white"),J.borderWidth&&(A.style.borderWidth=J.borderWidth,A.style.borderStyle="solid"),J.borderColor&&(A.style.borderColor=J.borderColor),J.paddingX&&(A.style.paddingLeft=J.paddingX,A.style.paddingRight=J.paddingX),J.paddingY&&(A.style.paddingTop=J.paddingY,A.style.paddingBottom=J.paddingY),se.appendChild(A);let yt=(tt=J.tooltipText)!=null?tt:"Start voice recognition";if(((je=J.showTooltip)!=null?je:!1)&&yt){let ct=c("div","tvw-send-button-tooltip");ct.textContent=yt,se.appendChild(ct)}}u.addEventListener("click",We=>{We.target!==R&&We.target!==U&&We.target!==A&&We.target!==se&&m.focus()}),u.append(m),se&&u.append(se),u.append(U);let j=c("div","tvw-mt-2 tvw-text-right tvw-text-xs tvw-text-cw-muted"),ne=(D=n==null?void 0:n.statusIndicator)!=null?D:{},ue=(lt=ne.visible)!=null?lt:!0;return j.style.display=ue?"":"none",j.textContent=(Ye=ne.idleText)!=null?Ye:"Online",o.append(e,u,j),{footer:o,suggestions:e,composerForm:u,textarea:m,sendButton:R,sendButtonWrapper:U,micButton:A,micButtonWrapper:se,statusText:j}};var gr=t=>{var u,m,d,W,h;if(!((m=(u=t==null?void 0:t.launcher)==null?void 0:u.enabled)!=null?m:!0)){let C=c("div","tvw-relative tvw-w-full tvw-h-full tvw-flex tvw-flex-col tvw-flex-1 tvw-min-h-0"),v=c("div","tvw-relative tvw-w-full tvw-flex-1 tvw-flex tvw-flex-col tvw-min-h-0");return C.appendChild(v),{wrapper:C,panel:v}}let o=(d=t==null?void 0:t.launcher)!=null?d:{},e=o.position&&Pt[o.position]?Pt[o.position]:Pt["bottom-right"],r=c("div",`tvw-fixed ${e} tvw-z-50 tvw-transition`),s=c("div","tvw-relative tvw-min-h-[320px]"),i=(h=(W=t==null?void 0:t.launcher)==null?void 0:W.width)!=null?h:t==null?void 0:t.launcherWidth,l=i!=null?i:"min(400px, calc(100vw - 24px))";return s.style.width=l,s.style.maxWidth=l,r.appendChild(s),{wrapper:r,panel:s}},mr=(t,n=!0)=>{var W,h,C,v,O;let o=c("div","tvw-flex tvw-h-full tvw-w-full tvw-flex-1 tvw-min-h-0 tvw-flex-col tvw-bg-cw-surface tvw-text-cw-primary tvw-rounded-2xl tvw-overflow-hidden tvw-shadow-2xl tvw-border tvw-border-cw-border"),e=(W=t==null?void 0:t.layout)==null?void 0:W.header,r=e?Cn(t,e,{showClose:n}):Ft({config:t,showClose:n}),s=c("div","tvw-flex tvw-flex-1 tvw-min-h-0 tvw-flex-col tvw-gap-6 tvw-overflow-y-auto tvw-bg-cw-container tvw-px-6 tvw-py-6");s.id="vanilla-agent-scroll-container";let i=c("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),l=c("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");l.textContent=(C=(h=t==null?void 0:t.copy)==null?void 0:h.welcomeTitle)!=null?C:"Hello \u{1F44B}";let u=c("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");u.textContent=(O=(v=t==null?void 0:t.copy)==null?void 0:v.welcomeSubtitle)!=null?O:"Ask anything about your account or products.",i.append(l,u);let m=c("div","tvw-flex tvw-flex-col tvw-gap-3");s.append(i,m);let d=Xt({config:t});return Kt(o,r,t),o.append(s,d.footer),{container:o,body:s,messagesWrapper:m,suggestions:d.suggestions,textarea:d.textarea,sendButton:d.sendButton,sendButtonWrapper:d.sendButtonWrapper,micButton:d.micButton,micButtonWrapper:d.micButtonWrapper,composerForm:d.composerForm,statusText:d.statusText,introTitle:l,introSubtitle:u,closeButton:r.closeButton,closeButtonWrapper:r.closeButtonWrapper,clearChatButton:r.clearChatButton,clearChatButtonWrapper:r.clearChatButtonWrapper,iconHolder:r.iconHolder,headerTitle:r.headerTitle,headerSubtitle:r.headerSubtitle,header:r.header,footer:d.footer}};var sn=()=>{let t=document.createElement("div");t.className="tvw-flex tvw-items-center tvw-space-x-1 tvw-h-5 tvw-mt-2";let n=document.createElement("div");n.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",n.style.animationDelay="0ms";let o=document.createElement("div");o.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",o.style.animationDelay="250ms";let e=document.createElement("div");e.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",e.style.animationDelay="500ms";let r=document.createElement("span");return r.className="tvw-sr-only",r.textContent="Loading",t.appendChild(n),t.appendChild(o),t.appendChild(e),t.appendChild(r),t},Ur=(t,n)=>{let o=c("div","tvw-flex-shrink-0 tvw-w-8 tvw-h-8 tvw-rounded-full tvw-flex tvw-items-center tvw-justify-center tvw-text-sm"),e=n==="user"?t.userAvatar:t.assistantAvatar;if(e)if(e.startsWith("http")||e.startsWith("/")||e.startsWith("data:")){let r=c("img");r.src=e,r.alt=n==="user"?"User":"Assistant",r.className="tvw-w-full tvw-h-full tvw-rounded-full tvw-object-cover",o.appendChild(r)}else o.textContent=e,o.classList.add(n==="user"?"tvw-bg-cw-accent":"tvw-bg-cw-primary","tvw-text-white");else o.textContent=n==="user"?"U":"A",o.classList.add(n==="user"?"tvw-bg-cw-accent":"tvw-bg-cw-primary","tvw-text-white");return o},fr=(t,n)=>{let o=c("div","tvw-text-xs tvw-text-cw-muted"),e=new Date(t.createdAt);return n.format?o.textContent=n.format(e):o.textContent=e.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),o},Vr=(t,n="bubble")=>{let o=["vanilla-message-bubble","tvw-max-w-[85%]"];switch(n){case"flat":t==="user"?o.push("vanilla-message-user-bubble","tvw-ml-auto","tvw-text-cw-primary","tvw-py-2"):o.push("vanilla-message-assistant-bubble","tvw-text-cw-primary","tvw-py-2");break;case"minimal":o.push("tvw-text-sm","tvw-leading-relaxed"),t==="user"?o.push("vanilla-message-user-bubble","tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-3","tvw-py-2","tvw-rounded-lg"):o.push("vanilla-message-assistant-bubble","tvw-bg-cw-surface","tvw-text-cw-primary","tvw-px-3","tvw-py-2","tvw-rounded-lg");break;case"bubble":default:o.push("tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm"),t==="user"?o.push("vanilla-message-user-bubble","tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-5","tvw-py-3"):o.push("vanilla-message-assistant-bubble","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3");break}return o},Yt=(t,n,o)=>{var q,f,S,I,T;let e=o!=null?o:{},r=(q=e.layout)!=null?q:"bubble",s=e.avatar,i=e.timestamp,l=(f=s==null?void 0:s.show)!=null?f:!1,u=(S=i==null?void 0:i.show)!=null?S:!1,m=(I=s==null?void 0:s.position)!=null?I:"left",d=(T=i==null?void 0:i.position)!=null?T:"below",W=Vr(t.role,r),h=c("div",W.join(" ")),C=document.createElement("div");if(C.innerHTML=n({text:t.content,message:t,streaming:!!t.streaming,raw:t.rawContent}),u&&d==="inline"&&t.createdAt){let U=fr(t,i);U.classList.add("tvw-ml-2","tvw-inline"),C.appendChild(U)}if(h.appendChild(C),u&&d==="below"&&t.createdAt){let U=fr(t,i);U.classList.add("tvw-mt-1"),h.appendChild(U)}if(t.streaming&&t.role==="assistant"&&(!t.content||!t.content.trim())){let U=sn();h.appendChild(U)}if(!l||t.role==="system")return h;let v=c("div",`tvw-flex tvw-gap-2 ${t.role==="user"?"tvw-flex-row-reverse":""}`),O=Ur(s,t.role);return m==="right"||m==="left"&&t.role==="user"?v.append(h,O):v.append(O,h),h.classList.remove("tvw-max-w-[85%]"),h.classList.add("tvw-max-w-[calc(85%-2.5rem)]"),v},hr=(t,n,o)=>{let e=o!=null?o:{};return t.role==="user"&&e.renderUserMessage?e.renderUserMessage({message:t,config:{},streaming:!!t.streaming}):t.role==="assistant"&&e.renderAssistantMessage?e.renderAssistantMessage({message:t,config:{},streaming:!!t.streaming}):Yt(t,n,o)};var qn=new Set,zn=t=>{let n=t.reasoning,o=c("div",["vanilla-message-bubble","vanilla-reasoning-bubble","tvw-w-full","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(!n)return o;let e=qn.has(t.id),r=c("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");r.type="button",r.setAttribute("aria-expanded",e?"true":"false");let s=c("div","tvw-flex tvw-flex-col tvw-text-left"),i=c("span","tvw-text-xs tvw-text-cw-primary");i.textContent="Thinking...",s.appendChild(i);let l=c("span","tvw-text-xs tvw-text-cw-primary");l.textContent=cr(n),s.appendChild(l),n.status==="complete"?i.style.display="none":i.style.display="";let u=c("div","tvw-flex tvw-items-center"),d=ge(e?"chevron-up":"chevron-down",16,"currentColor",2);d?u.appendChild(d):u.textContent=e?"Hide":"Show";let W=c("div","tvw-flex tvw-items-center tvw-ml-auto");W.append(u),r.append(s,W);let h=c("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-px-4 tvw-py-3");h.style.display=e?"":"none";let C=n.chunks.join(""),v=c("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");v.textContent=C||(n.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),h.appendChild(v);let O=()=>{r.setAttribute("aria-expanded",e?"true":"false"),u.innerHTML="";let S=ge(e?"chevron-up":"chevron-down",16,"currentColor",2);S?u.appendChild(S):u.textContent=e?"Hide":"Show",h.style.display=e?"":"none"},q=()=>{e=!e,e?qn.add(t.id):qn.delete(t.id),O()};return r.addEventListener("pointerdown",f=>{f.preventDefault(),q()}),r.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),q())}),O(),o.append(r,h),o};var On=new Set,$n=(t,n)=>{var q;let o=t.toolCall,e=(q=n==null?void 0:n.toolCall)!=null?q:{},r=c("div",["vanilla-message-bubble","vanilla-tool-bubble","tvw-w-full","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(e.backgroundColor&&(r.style.backgroundColor=e.backgroundColor),e.borderColor&&(r.style.borderColor=e.borderColor),e.borderWidth&&(r.style.borderWidth=e.borderWidth),e.borderRadius&&(r.style.borderRadius=e.borderRadius),!o)return r;let s=On.has(t.id),i=c("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");i.type="button",i.setAttribute("aria-expanded",s?"true":"false"),e.headerBackgroundColor&&(i.style.backgroundColor=e.headerBackgroundColor),e.headerPaddingX&&(i.style.paddingLeft=e.headerPaddingX,i.style.paddingRight=e.headerPaddingX),e.headerPaddingY&&(i.style.paddingTop=e.headerPaddingY,i.style.paddingBottom=e.headerPaddingY);let l=c("div","tvw-flex tvw-flex-col tvw-text-left"),u=c("span","tvw-text-xs tvw-text-cw-primary");e.headerTextColor&&(u.style.color=e.headerTextColor),u.textContent=ur(o),l.appendChild(u);let m=c("div","tvw-flex tvw-items-center"),d=e.toggleTextColor||e.headerTextColor||"currentColor",W=ge(s?"chevron-up":"chevron-down",16,d,2);W?m.appendChild(W):m.textContent=s?"Hide":"Show";let h=c("div","tvw-flex tvw-items-center tvw-gap-2 tvw-ml-auto");h.append(m),i.append(l,h);let C=c("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(C.style.display=s?"":"none",e.contentBackgroundColor&&(C.style.backgroundColor=e.contentBackgroundColor),e.contentTextColor&&(C.style.color=e.contentTextColor),e.contentPaddingX&&(C.style.paddingLeft=e.contentPaddingX,C.style.paddingRight=e.contentPaddingX),e.contentPaddingY&&(C.style.paddingTop=e.contentPaddingY,C.style.paddingBottom=e.contentPaddingY),o.name){let f=c("div","tvw-text-xs tvw-text-cw-muted tvw-italic");e.contentTextColor?f.style.color=e.contentTextColor:e.headerTextColor&&(f.style.color=e.headerTextColor),f.textContent=o.name,C.appendChild(f)}if(o.args!==void 0){let f=c("div","tvw-space-y-1"),S=c("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(S.style.color=e.labelTextColor),S.textContent="Arguments";let I=c("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");I.style.fontSize="0.75rem",I.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(I.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(I.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(I.style.color=e.codeBlockTextColor),I.textContent=Rn(o.args),f.append(S,I),C.appendChild(f)}if(o.chunks&&o.chunks.length){let f=c("div","tvw-space-y-1"),S=c("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(S.style.color=e.labelTextColor),S.textContent="Activity";let I=c("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");I.style.fontSize="0.75rem",I.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(I.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(I.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(I.style.color=e.codeBlockTextColor),I.textContent=o.chunks.join(`
15
+ `),f.append(S,I),C.appendChild(f)}if(o.status==="complete"&&o.result!==void 0){let f=c("div","tvw-space-y-1"),S=c("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(S.style.color=e.labelTextColor),S.textContent="Result";let I=c("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");I.style.fontSize="0.75rem",I.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(I.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(I.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(I.style.color=e.codeBlockTextColor),I.textContent=Rn(o.result),f.append(S,I),C.appendChild(f)}if(o.status==="complete"&&typeof o.duration=="number"){let f=c("div","tvw-text-xs tvw-text-cw-muted");e.contentTextColor&&(f.style.color=e.contentTextColor),f.textContent=`Duration: ${o.duration}ms`,C.appendChild(f)}let v=()=>{i.setAttribute("aria-expanded",s?"true":"false"),m.innerHTML="";let f=e.toggleTextColor||e.headerTextColor||"currentColor",S=ge(s?"chevron-up":"chevron-down",16,f,2);S?m.appendChild(S):m.textContent=s?"Hide":"Show",C.style.display=s?"":"none"},O=()=>{s=!s,s?On.add(t.id):On.delete(t.id),v()};return i.addEventListener("pointerdown",f=>{f.preventDefault(),O()}),i.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),O())}),v(),r.append(i,C),r};var wr=t=>{let n=[];return{buttons:n,render:(e,r,s,i,l)=>{if(t.innerHTML="",n.length=0,!e||!e.length||(i!=null?i:r?r.getMessages():[]).some(C=>C.role==="user"))return;let d=document.createDocumentFragment(),W=r?r.isStreaming():!1,h=C=>{switch(C){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};e.forEach(C=>{let v=c("button","tvw-rounded-button tvw-bg-cw-surface tvw-px-3 tvw-py-1.5 tvw-text-xs tvw-font-medium tvw-text-cw-muted hover:tvw-opacity-90 tvw-cursor-pointer tvw-border tvw-border-gray-200");v.type="button",v.textContent=C,v.disabled=W,l!=null&&l.fontFamily&&(v.style.fontFamily=h(l.fontFamily)),l!=null&&l.fontWeight&&(v.style.fontWeight=l.fontWeight),l!=null&&l.paddingX&&(v.style.paddingLeft=l.paddingX,v.style.paddingRight=l.paddingX),l!=null&&l.paddingY&&(v.style.paddingTop=l.paddingY,v.style.paddingBottom=l.paddingY),v.addEventListener("click",()=>{!r||r.isStreaming()||(s.value="",r.sendMessage(C))}),d.appendChild(v),n.push(v)}),t.appendChild(d)}}};var vr={init:{title:"Schedule a Demo",description:"Share the basics and we'll follow up with a confirmation.",fields:[{name:"name",label:"Full name",placeholder:"Jane Doe",required:!0},{name:"email",label:"Work email",placeholder:"jane@example.com",type:"email",required:!0},{name:"notes",label:"What would you like to cover?",type:"textarea"}],submitLabel:"Submit details"},followup:{title:"Additional Information",description:"Provide any extra details to tailor the next steps.",fields:[{name:"company",label:"Company",placeholder:"Acme Inc."},{name:"context",label:"Context",type:"textarea",placeholder:"Share more about your use case"}],submitLabel:"Send"}},_n=(t,n,o,e)=>{let r=t.querySelectorAll("[data-tv-form]");r.length&&r.forEach(s=>{var v,O,q;if(s.dataset.enhanced==="true")return;let i=(v=s.dataset.tvForm)!=null?v:"init";s.dataset.enhanced="true";let l=(O=vr[i])!=null?O:vr.init;s.classList.add("tvw-form-card","tvw-space-y-4");let u=c("div","tvw-space-y-1"),m=c("h3","tvw-text-base tvw-font-semibold tvw-text-cw-primary");if(m.textContent=l.title,u.appendChild(m),l.description){let f=c("p","tvw-text-sm tvw-text-cw-muted");f.textContent=l.description,u.appendChild(f)}let d=document.createElement("form");d.className="tvw-form-grid tvw-space-y-3",l.fields.forEach(f=>{var R,J;let S=c("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");S.htmlFor=`${n.id}-${i}-${f.name}`;let I=c("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");I.textContent=f.label,S.appendChild(I);let T=(R=f.type)!=null?R:"text",U;T==="textarea"?(U=document.createElement("textarea"),U.rows=3):(U=document.createElement("input"),U.type=T),U.className="tvw-rounded-xl tvw-border tvw-border-gray-200 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-cw-primary",U.id=`${n.id}-${i}-${f.name}`,U.name=f.name,U.placeholder=(J=f.placeholder)!=null?J:"",f.required&&(U.required=!0),S.appendChild(U),d.appendChild(S)});let W=c("div","tvw-flex tvw-items-center tvw-justify-between tvw-gap-2"),h=c("div","tvw-text-xs tvw-text-cw-muted tvw-min-h-[1.5rem]"),C=c("button","tvw-inline-flex tvw-items-center tvw-rounded-full tvw-bg-cw-primary tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-60 tvw-cursor-pointer");C.type="submit",C.textContent=(q=l.submitLabel)!=null?q:"Submit",W.appendChild(h),W.appendChild(C),d.appendChild(W),s.replaceChildren(u,d),d.addEventListener("submit",async f=>{var U,R;f.preventDefault();let S=(U=o.formEndpoint)!=null?U:"/form",I=new FormData(d),T={};I.forEach((J,te)=>{T[te]=J}),T.type=i,C.disabled=!0,h.textContent="Submitting\u2026";try{let J=await fetch(S,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)});if(!J.ok)throw new Error(`Form submission failed (${J.status})`);let te=await J.json();h.textContent=(R=te.message)!=null?R:"Thanks! We'll be in touch soon.",te.success&&te.nextPrompt&&await e.sendMessage(String(te.nextPrompt))}catch(J){h.textContent=J instanceof Error?J.message:"Something went wrong. Please try again."}finally{C.disabled=!1}})})};var jn=class{constructor(){this.plugins=new Map}register(n){var o;this.plugins.has(n.id)&&console.warn(`Plugin "${n.id}" is already registered. Overwriting.`),this.plugins.set(n.id,n),(o=n.onRegister)==null||o.call(n)}unregister(n){var e;let o=this.plugins.get(n);o&&((e=o.onUnregister)==null||e.call(o),this.plugins.delete(n))}getAll(){return Array.from(this.plugins.values()).sort((n,o)=>{var e,r;return((e=o.priority)!=null?e:0)-((r=n.priority)!=null?r:0)})}getForInstance(n){let o=this.getAll();if(!n||n.length===0)return o;let e=new Set(n.map(s=>s.id));return[...o.filter(s=>!e.has(s.id)),...n].sort((s,i)=>{var l,u;return((l=i.priority)!=null?l:0)-((u=s.priority)!=null?u:0)})}clear(){this.plugins.forEach(n=>{var o;return(o=n.onUnregister)==null?void 0:o.call(n)}),this.plugins.clear()}},an=new jn;var Ne={apiUrl:"http://localhost:43111/api/chat/dispatch",theme:{primary:"#111827",accent:"#1d4ed8",surface:"#ffffff",muted:"#6b7280",container:"#f8fafc",border:"#f1f5f9",divider:"#f1f5f9",messageBorder:"#f1f5f9",inputBackground:"#ffffff",callToAction:"#000000",callToActionBackground:"#ffffff",sendButtonBackgroundColor:"#111827",sendButtonTextColor:"#ffffff",sendButtonBorderColor:"#60a5fa",closeButtonColor:"#6b7280",closeButtonBackgroundColor:"transparent",closeButtonBorderColor:"",clearChatIconColor:"#6b7280",clearChatBackgroundColor:"transparent",clearChatBorderColor:"transparent",micIconColor:"#111827",micBackgroundColor:"transparent",micBorderColor:"transparent",recordingIconColor:"#ffffff",recordingBackgroundColor:"#ef4444",recordingBorderColor:"transparent",inputFontFamily:"sans-serif",inputFontWeight:"400",radiusSm:"0.75rem",radiusMd:"1rem",radiusLg:"1.5rem",launcherRadius:"9999px",buttonRadius:"9999px"},launcher:{enabled:!0,title:"Chat Assistant",subtitle:"Here to help you get answers fast",agentIconText:"\u{1F4AC}",position:"bottom-right",width:"min(400px, calc(100vw - 24px))",autoExpand:!1,callToActionIconHidden:!1,agentIconSize:"40px",headerIconSize:"40px",closeButtonSize:"32px",callToActionIconName:"arrow-up-right",callToActionIconText:"",callToActionIconSize:"32px",callToActionIconPadding:"5px",callToActionIconColor:"#000000",callToActionIconBackgroundColor:"#ffffff",closeButtonColor:"#6b7280",closeButtonBackgroundColor:"transparent",clearChat:{iconColor:"#6b7280",backgroundColor:"transparent",borderColor:"transparent",enabled:!0,placement:"inline",iconName:"refresh-cw",size:"32px",showTooltip:!0,tooltipText:"Clear chat",paddingX:"0px",paddingY:"0px"},headerIconHidden:!1},copy:{welcomeTitle:"Hello \u{1F44B}",welcomeSubtitle:"Ask anything about your account or products.",inputPlaceholder:"How can I help...",sendButtonLabel:"Send"},sendButton:{borderWidth:"0px",paddingX:"12px",paddingY:"10px",backgroundColor:"#111827",textColor:"#ffffff",borderColor:"#60a5fa",useIcon:!0,iconText:"\u2191",size:"40px",showTooltip:!0,tooltipText:"Send message",iconName:"send"},statusIndicator:{visible:!0,idleText:"Online",connectingText:"Connecting\u2026",connectedText:"Streaming\u2026",errorText:"Offline"},voiceRecognition:{enabled:!0,pauseDuration:2e3,iconName:"mic",iconSize:"39px",borderWidth:"0px",paddingX:"9px",paddingY:"14px",iconColor:"#111827",backgroundColor:"transparent",borderColor:"transparent",recordingIconColor:"#ffffff",recordingBackgroundColor:"#ef4444",recordingBorderColor:"transparent",showTooltip:!0,tooltipText:"Start voice recognition"},features:{showReasoning:!0,showToolCalls:!0},suggestionChips:["What can you help me with?","Tell me about your features","How does this work?"],suggestionChipsConfig:{fontFamily:"sans-serif",fontWeight:"500",paddingX:"12px",paddingY:"6px"},layout:{header:{layout:"default",showIcon:!0,showTitle:!0,showSubtitle:!0,showCloseButton:!0,showClearChat:!0},messages:{layout:"bubble",avatar:{show:!1,position:"left"},timestamp:{show:!1,position:"below"},groupConsecutive:!1},slots:{}},debug:!1};function Sn(t){var n,o,e,r,s,i,l,u,m,d,W,h,C,v,O,q,f;return t?{...Ne,...t,theme:{...Ne.theme,...t.theme},launcher:{...Ne.launcher,...t.launcher,clearChat:{...(n=Ne.launcher)==null?void 0:n.clearChat,...(o=t.launcher)==null?void 0:o.clearChat}},copy:{...Ne.copy,...t.copy},sendButton:{...Ne.sendButton,...t.sendButton},statusIndicator:{...Ne.statusIndicator,...t.statusIndicator},voiceRecognition:{...Ne.voiceRecognition,...t.voiceRecognition},features:{...Ne.features,...t.features},suggestionChips:(e=t.suggestionChips)!=null?e:Ne.suggestionChips,suggestionChipsConfig:{...Ne.suggestionChipsConfig,...t.suggestionChipsConfig},layout:{...Ne.layout,...t.layout,header:{...(r=Ne.layout)==null?void 0:r.header,...(s=t.layout)==null?void 0:s.header},messages:{...(i=Ne.layout)==null?void 0:i.messages,...(l=t.layout)==null?void 0:l.messages,avatar:{...(m=(u=Ne.layout)==null?void 0:u.messages)==null?void 0:m.avatar,...(W=(d=t.layout)==null?void 0:d.messages)==null?void 0:W.avatar},timestamp:{...(C=(h=Ne.layout)==null?void 0:h.messages)==null?void 0:C.timestamp,...(O=(v=t.layout)==null?void 0:v.messages)==null?void 0:O.timestamp}},slots:{...(q=Ne.layout)==null?void 0:q.slots,...(f=t.layout)==null?void 0:f.slots}}}:Ne}var yr=()=>{let t=new Map,n=(r,s)=>(t.has(r)||t.set(r,new Set),t.get(r).add(s),()=>o(r,s)),o=(r,s)=>{var i;(i=t.get(r))==null||i.delete(s)};return{on:n,off:o,emit:(r,s)=>{var i;(i=t.get(r))==null||i.forEach(l=>{try{l(s)}catch(u){typeof console!="undefined"&&console.error("[AgentWidget] Event handler error:",u)}})}}};var Kr=t=>{let n=t.match(/```(?:json)?\s*([\s\S]*?)```/i);return n?n[1]:t},Xr=t=>{let n=t.trim(),o=n.indexOf("{");if(o===-1)return null;let e=0;for(let r=o;r<n.length;r+=1){let s=n[r];if(s==="{"&&(e+=1),s==="}"&&(e-=1,e===0))return n.slice(o,r+1)}return null},ln=({text:t})=>{if(!t||!t.includes("{"))return null;try{let n=Kr(t),o=Xr(n);if(!o)return null;let e=JSON.parse(o);if(!e||typeof e!="object"||!e.action)return null;let{action:r,...s}=e;return{type:String(r),payload:s,raw:e}}catch{return null}},Un=t=>typeof t=="string"?t:t==null?"":String(t),_t={message:t=>t.type!=="message"?void 0:{handled:!0,displayText:Un(t.payload.text)},messageAndClick:(t,n)=>{var r;if(t.type!=="message_and_click")return;let o=t.payload,e=Un(o.element);if(e&&((r=n.document)!=null&&r.querySelector)){let s=n.document.querySelector(e);s?setTimeout(()=>{s.click()},400):typeof console!="undefined"&&console.warn("[AgentWidget] Element not found for selector:",e)}return{handled:!0,displayText:Un(o.text)}}},xr=t=>Array.isArray(t)?t.map(n=>String(n)):[],dn=t=>{let n=new Set(xr(t.getMetadata().processedActionMessageIds)),o=()=>{n=new Set(xr(t.getMetadata().processedActionMessageIds))},e=()=>{let s=Array.from(n);t.updateMetadata(i=>({...i,processedActionMessageIds:s}))};return{process:s=>{if(s.streaming||s.message.role!=="assistant"||!s.text||n.has(s.message.id))return null;let i=typeof s.raw=="string"&&s.raw||typeof s.message.rawContent=="string"&&s.message.rawContent||typeof s.text=="string"&&s.text||null;!i&&typeof s.text=="string"&&s.text.trim().startsWith("{")&&typeof console!="undefined"&&console.warn("[AgentWidget] Structured response detected but no raw payload was provided. Ensure your stream parser returns { text, raw }.");let l=i?t.parsers.reduce((m,d)=>m||(d==null?void 0:d({text:i,message:s.message}))||null,null):null;if(!l)return null;n.add(s.message.id),e();let u={action:l,message:s.message};t.emit("action:detected",u);for(let m of t.handlers)if(m)try{let d=m(l,{message:s.message,metadata:t.getMetadata(),updateMetadata:t.updateMetadata,document:t.documentRef});if(!d)continue;if(d.handled){let W=d.persistMessage!==!1;return{text:d.displayText!==void 0?d.displayText:"",persist:W}}}catch(d){typeof console!="undefined"&&console.error("[AgentWidget] Action handler error:",d)}return{text:"",persist:!0}},syncFromMetadata:o}};var Yr=t=>{if(!t)return null;try{return JSON.parse(t)}catch(n){return typeof console!="undefined"&&console.error("[AgentWidget] Failed to parse stored state:",n),null}},Jr=t=>t.map(n=>({...n,streaming:!1})),Tn=(t="vanilla-agent-state")=>{let n=()=>typeof window=="undefined"||!window.localStorage?null:window.localStorage;return{load:()=>{let o=n();return o?Yr(o.getItem(t)):null},save:o=>{let e=n();if(e)try{let r={...o,messages:o.messages?Jr(o.messages):void 0};e.setItem(t,JSON.stringify(r))}catch(r){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",r)}},clear:()=>{let o=n();if(o)try{o.removeItem(t)}catch(e){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear stored state:",e)}}}};var Vn=class{constructor(){this.components=new Map}register(n,o){this.components.has(n)&&console.warn(`[ComponentRegistry] Component "${n}" is already registered. Overwriting.`),this.components.set(n,o)}unregister(n){this.components.delete(n)}get(n){return this.components.get(n)}has(n){return this.components.has(n)}getAllNames(){return Array.from(this.components.keys())}clear(){this.components.clear()}registerAll(n){Object.entries(n).forEach(([o,e])=>{this.register(o,e)})}},Jt=new Vn;var Gt=require("partial-json");function Gr(t){if(!t||typeof t!="object"||!("component"in t))return!1;let n=t.component;return typeof n=="string"&&n.length>0}function Zr(t,n){if(!Gr(t))return null;let o=t.props&&typeof t.props=="object"&&t.props!==null?t.props:{};return{component:t.component,props:o,raw:n}}function An(){let t=null,n=0;return{getExtractedDirective:()=>t,processChunk:o=>{let e=o.trim();if(!e.startsWith("{")&&!e.startsWith("["))return null;if(o.length<=n)return t;try{let r=(0,Gt.parse)(o,Gt.STR|Gt.OBJ),s=Zr(r,o);s&&(t=s)}catch{}return n=o.length,t},reset:()=>{t=null,n=0}}}function br(t){return typeof t=="object"&&t!==null&&"component"in t&&typeof t.component=="string"&&"props"in t&&typeof t.props=="object"}function Wn(t,n){let{config:o,message:e,onPropsUpdate:r}=n,s=Jt.get(t.component);if(!s)return console.warn(`[ComponentMiddleware] Component "${t.component}" not found in registry. Falling back to default rendering.`),null;let i={message:e,config:o,updateProps:l=>{r&&r(l)}};try{return s(t.props,i)}catch(l){return console.error(`[ComponentMiddleware] Error rendering component "${t.component}":`,l),null}}function Cr(){let t=An();return{processChunk:n=>t.processChunk(n),getDirective:()=>t.getExtractedDirective(),reset:()=>{t.reset()}}}function En(t){if(!t.rawContent)return!1;try{let n=JSON.parse(t.rawContent);return typeof n=="object"&&n!==null&&"component"in n&&typeof n.component=="string"}catch{return!1}}function Mn(t){if(!t.rawContent)return null;try{let n=JSON.parse(t.rawContent);if(typeof n=="object"&&n!==null&&"component"in n&&typeof n.component=="string")return{component:n.component,props:n.props&&typeof n.props=="object"&&n.props!==null?n.props:{},raw:t.rawContent}}catch{}return null}var Zt="vanilla-agent-chat-history",Qr=30*1e3,Kn=t=>!t||typeof t!="object"?{}:{...t},Sr=t=>t.map(n=>({...n,streaming:!1})),Tr=(t,n)=>o=>{var s,i,l;let e=(s=o.text)!=null?s:"",r=(i=o.message.rawContent)!=null?i:null;if(n){let u=n.process({text:e,raw:r!=null?r:e,message:o.message,streaming:o.streaming});u!==null&&(e=u.text,u.persist||(o.message.__skipPersist=!0))}return t!=null&&t.postprocessMessage?t.postprocessMessage({...o,text:e,raw:(l=r!=null?r:o.text)!=null?l:""}):fn(e)},Ln=(t,n,o)=>{var Se,re,we,Be,Pe,Oe,Ht,Jn,Gn,Zn,Qn,eo,to,no;(!t.id||t.id!=="vanilla-agent-root")&&(t.id="vanilla-agent-root");let e=Sn(n);In(t,e);let r=an.getForInstance(e.plugins);e.components&&Jt.registerAll(e.components);let s=yr(),i=(Se=e.storageAdapter)!=null?Se:Tn(),l={},u=null;if(i!=null&&i.load)try{let a=i.load();if(a&&typeof a.then=="function")u=a;else if(a){let p=a;p.metadata&&(l=Kn(p.metadata)),(re=p.messages)!=null&&re.length&&(e={...e,initialMessages:p.messages})}}catch(a){typeof console!="undefined"&&console.error("[AgentWidget] Failed to load stored state:",a)}let m=()=>l,d=a=>{var M;l=(M=a({...l}))!=null?M:{},Bt()},W=e.actionParsers&&e.actionParsers.length?e.actionParsers:[ln],h=e.actionHandlers&&e.actionHandlers.length?e.actionHandlers:[_t.message,_t.messageAndClick],C=dn({parsers:W,handlers:h,getMetadata:m,updateMetadata:d,emit:s.emit,documentRef:typeof document!="undefined"?document:null});C.syncFromMetadata();let v=(Be=(we=e.launcher)==null?void 0:we.enabled)!=null?Be:!0,O=(Oe=(Pe=e.launcher)==null?void 0:Pe.autoExpand)!=null?Oe:!1,q=O,f=v,S=v?O:!0,I=Tr(e,C),T=(Jn=(Ht=e.features)==null?void 0:Ht.showReasoning)!=null?Jn:!0,U=(Zn=(Gn=e.features)==null?void 0:Gn.showToolCalls)!=null?Zn:!0,R=(Qn=e.statusIndicator)!=null?Qn:{},J=a=>{var p,M,F,H;return a==="idle"?(p=R.idleText)!=null?p:Ve.idle:a==="connecting"?(M=R.connectingText)!=null?M:Ve.connecting:a==="connected"?(F=R.connectedText)!=null?F:Ve.connected:a==="error"?(H=R.errorText)!=null?H:Ve.error:Ve[a]},{wrapper:te,panel:A}=gr(e),se=mr(e,v),{container:V,body:j,messagesWrapper:ne,suggestions:ue,textarea:oe,sendButton:P,sendButtonWrapper:_e,composerForm:Ke,statusText:et,introTitle:wt,introSubtitle:vt,closeButton:N,iconHolder:de,headerTitle:pt,headerSubtitle:gt,header:Xe,footer:st}=se,B=se.micButton,ke=se.micButtonWrapper,it=r.find(a=>a.renderHeader);if(it!=null&&it.renderHeader){let a=it.renderHeader({config:e,defaultRenderer:()=>{let p=Ft({config:e,showClose:v});return Kt(V,p,e),p.header},onClose:()=>ot(!1,"user")});if(a){let p=V.querySelector(".tvw-border-b-cw-divider");p&&(p.replaceWith(a),Xe=a)}}let at=r.find(a=>a.renderComposer);if(at!=null&&at.renderComposer){let a=at.renderComposer({config:e,defaultRenderer:()=>Xt({config:e}).footer,onSubmit:p=>{D&&!D.isStreaming()&&D.sendMessage(p)},disabled:!1});a&&(st.replaceWith(a),st=a)}(()=>{var F,H;let a=(H=(F=e.layout)==null?void 0:F.slots)!=null?H:{},p=x=>{switch(x){case"body-top":return V.querySelector(".tvw-rounded-2xl.tvw-bg-cw-surface.tvw-p-6")||null;case"messages":return ne;case"footer-top":return ue;case"composer":return Ke;case"footer-bottom":return et;default:return null}},M=(x,b)=>{var X;switch(x){case"header-left":case"header-center":case"header-right":if(x==="header-left")Xe.insertBefore(b,Xe.firstChild);else if(x==="header-right")Xe.appendChild(b);else{let $=Xe.querySelector(".tvw-flex-col");$?(X=$.parentNode)==null||X.insertBefore(b,$.nextSibling):Xe.appendChild(b)}break;case"body-top":let ae=j.querySelector(".tvw-rounded-2xl.tvw-bg-cw-surface.tvw-p-6");ae?ae.replaceWith(b):j.insertBefore(b,j.firstChild);break;case"body-bottom":j.appendChild(b);break;case"footer-top":ue.replaceWith(b);break;case"footer-bottom":et.replaceWith(b);break;default:break}};for(let[x,b]of Object.entries(a))if(b)try{let X=b({config:e,defaultContent:()=>p(x)});X&&M(x,X)}catch(X){typeof console!="undefined"&&console.error(`[AgentWidget] Error rendering slot "${x}":`,X)}})(),A.appendChild(V),t.appendChild(te);let mt=()=>{var _,ee,fe,$e,He,rt,pe,At,kt,Rt,Wt,zt;let a=(ee=(_=e.launcher)==null?void 0:_.sidebarMode)!=null?ee:!1,p=a||(($e=(fe=e.launcher)==null?void 0:fe.fullHeight)!=null?$e:!1),M=(He=e.theme)!=null?He:{},F=(pe=(rt=e.launcher)==null?void 0:rt.position)!=null?pe:"bottom-left",H=F==="bottom-left"||F==="top-left",x=a?"none":"1px solid var(--tvw-cw-border)",b=a?H?"2px 0 12px rgba(0, 0, 0, 0.08)":"-2px 0 12px rgba(0, 0, 0, 0.08)":"0 25px 50px -12px rgba(0, 0, 0, 0.25)",X=a?"0":"16px",ae=(At=M.panelBorder)!=null?At:x,$=(kt=M.panelShadow)!=null?kt:b,k=(Rt=M.panelBorderRadius)!=null?Rt:X;if(V.style.border=ae,V.style.boxShadow=$,V.style.borderRadius=k,p&&(t.style.display="flex",t.style.flexDirection="column",t.style.height="100%",t.style.minHeight="0",te.style.display="flex",te.style.flexDirection="column",te.style.flex="1 1 0%",te.style.minHeight="0",te.style.maxHeight="100%",te.style.height="100%",te.style.overflow="hidden",A.style.display="flex",A.style.flexDirection="column",A.style.flex="1 1 0%",A.style.minHeight="0",A.style.maxHeight="100%",A.style.height="100%",A.style.overflow="hidden",V.style.display="flex",V.style.flexDirection="column",V.style.flex="1 1 0%",V.style.minHeight="0",V.style.maxHeight="100%",V.style.overflow="hidden",j.style.flex="1 1 0%",j.style.minHeight="0",j.style.overflowY="auto",st.style.flexShrink="0"),a){let Ot=(zt=(Wt=e.launcher)==null?void 0:Wt.sidebarWidth)!=null?zt:"420px";te.classList.remove("tvw-bottom-6","tvw-right-6","tvw-left-6","tvw-top-6","tvw-bottom-4","tvw-right-4","tvw-left-4","tvw-top-4"),te.style.cssText=`
16
+ position: fixed !important;
17
+ top: 0 !important;
18
+ bottom: 0 !important;
19
+ width: ${Ot} !important;
20
+ height: 100vh !important;
21
+ max-height: 100vh !important;
22
+ margin: 0 !important;
23
+ padding: 0 !important;
24
+ display: flex !important;
25
+ flex-direction: column !important;
26
+ ${H?"left: 0 !important; right: auto !important;":"left: auto !important; right: 0 !important;"}
27
+ `,A.style.cssText=`
28
+ position: relative !important;
29
+ display: flex !important;
30
+ flex-direction: column !important;
31
+ flex: 1 1 0% !important;
32
+ width: 100% !important;
33
+ max-width: 100% !important;
34
+ height: 100% !important;
35
+ min-height: 0 !important;
36
+ margin: 0 !important;
37
+ padding: 0 !important;
38
+ `,A.style.setProperty("width","100%","important"),A.style.setProperty("max-width","100%","important"),V.style.cssText=`
39
+ display: flex !important;
40
+ flex-direction: column !important;
41
+ flex: 1 1 0% !important;
42
+ width: 100% !important;
43
+ height: 100% !important;
44
+ min-height: 0 !important;
45
+ max-height: 100% !important;
46
+ overflow: hidden !important;
47
+ border-radius: ${k} !important;
48
+ border: ${ae} !important;
49
+ box-shadow: ${$} !important;
50
+ `,st.style.cssText=`
51
+ flex-shrink: 0 !important;
52
+ border-top: none !important;
53
+ padding: 8px 16px 12px 16px !important;
54
+ `}};mt();let Fe=[],tt=wr(ue),je=null,D,lt=!1,Ye=!0,We=0,qe=0,K=null,ve=!1,Re=0,Ue=!1,nt=125,yt=2e3,Mt=5,ct=50,xt=new Map,ie={active:!1,manuallyDeactivated:!1,lastUserMessageWasVoice:!1},Nt=(to=(eo=e.voiceRecognition)==null?void 0:eo.autoResume)!=null?to:!1,Lt=a=>{s.emit("voice:state",{active:ie.active,source:a,timestamp:Date.now()})},me=()=>{d(a=>({...a,voiceState:{active:ie.active,timestamp:Date.now(),manuallyDeactivated:ie.manuallyDeactivated}}))},ft=()=>{var F,H;if(((F=e.voiceRecognition)==null?void 0:F.enabled)===!1)return;let a=Kn(l.voiceState),p=!!a.active,M=Number((H=a.timestamp)!=null?H:0);ie.manuallyDeactivated=!!a.manuallyDeactivated,p&&Date.now()-M<Qr&&setTimeout(()=>{ie.active||(ie.manuallyDeactivated=!1,Me("restore"))},1e3)},bt=()=>D?Sr(D.getMessages()).filter(a=>!a.__skipPersist):[];function Bt(a){if(!(i!=null&&i.save))return;let M={messages:a?Sr(a):D?bt():[],metadata:l};try{let F=i.save(M);F instanceof Promise&&F.catch(H=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",H)})}catch(F){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",F)}}let ht=(a=!1)=>{if(!Ye)return;let p=Date.now();ve&&p<Re&&!a||(ve&&p>=Re&&(ve=!1),!(!a&&!lt)&&(p-qe<nt||(qe=p,K&&cancelAnimationFrame(K),K=requestAnimationFrame(()=>{ve||!Ye||(Ue=!0,j.scrollTop=j.scrollHeight,We=j.scrollTop,requestAnimationFrame(()=>{Ue=!1}),K=null)}))))},Tt=null,cn=()=>te.querySelector("#vanilla-agent-scroll-container")||j,un=(a,p=500)=>{let M=a.scrollTop,F=a.clientHeight,H=a.scrollHeight,x=H-M;if(M+F>=H-2||Math.abs(x)<5)return;Tt!==null&&(cancelAnimationFrame(Tt),Tt=null);let X=performance.now(),ae=k=>1-Math.pow(1-k,3),$=k=>{let _=a.scrollHeight;_!==H&&(H=_,x=H-M);let ee=k-X,fe=Math.min(ee/p,1),$e=ae(fe),He=M+x*$e;a.scrollTop=He,fe<1?Tt=requestAnimationFrame($):(a.scrollTop=a.scrollHeight,Tt=null)};Tt=requestAnimationFrame($)},pn=a=>{let p=new Map;a.forEach(M=>{let F=xt.get(M.id);p.set(M.id,{streaming:M.streaming,role:M.role}),!F&&M.role==="assistant"&&s.emit("assistant:message",M),M.role==="assistant"&&(F!=null&&F.streaming)&&M.streaming===!1&&s.emit("assistant:complete",M)}),xt.clear(),p.forEach((M,F)=>{xt.set(F,M)})},Dt=(a,p,M)=>{a.innerHTML="";let F=document.createDocumentFragment();p.forEach(x=>{var k,_;let b=null,X=r.find(ee=>!!(x.variant==="reasoning"&&ee.renderReasoning||x.variant==="tool"&&ee.renderToolCall||!x.variant&&ee.renderMessage)),ae=(k=e.layout)==null?void 0:k.messages;if(X)if(x.variant==="reasoning"&&x.reasoning&&X.renderReasoning){if(!T)return;b=X.renderReasoning({message:x,defaultRenderer:()=>zn(x),config:e})}else if(x.variant==="tool"&&x.toolCall&&X.renderToolCall){if(!U)return;b=X.renderToolCall({message:x,defaultRenderer:()=>$n(x,e),config:e})}else X.renderMessage&&(b=X.renderMessage({message:x,defaultRenderer:()=>{let ee=Yt(x,M,ae);return x.role!=="user"&&_n(ee,x,e,D),ee},config:e}));if(!b&&x.role==="assistant"&&!x.variant&&e.enableComponentStreaming!==!1&&En(x)){let fe=Mn(x);if(fe){let $e=Wn(fe,{config:e,message:x,transform:M});if($e){let He=document.createElement("div");if(He.className=["vanilla-message-bubble","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-p-4"].join(" "),He.setAttribute("data-message-id",x.id),x.content&&x.content.trim()){let rt=document.createElement("div");rt.className="tvw-mb-3 tvw-text-sm tvw-leading-relaxed",rt.innerHTML=M({text:x.content,message:x,streaming:!!x.streaming,raw:x.rawContent}),He.appendChild(rt)}He.appendChild($e),b=He}}}if(!b)if(x.variant==="reasoning"&&x.reasoning){if(!T)return;b=zn(x)}else if(x.variant==="tool"&&x.toolCall){if(!U)return;b=$n(x,e)}else{let ee=(_=e.layout)==null?void 0:_.messages;ee!=null&&ee.renderUserMessage&&x.role==="user"?b=ee.renderUserMessage({message:x,config:e,streaming:!!x.streaming}):ee!=null&&ee.renderAssistantMessage&&x.role==="assistant"?b=ee.renderAssistantMessage({message:x,config:e,streaming:!!x.streaming}):b=Yt(x,M,ee),x.role!=="user"&&b&&_n(b,x,e,D)}let $=document.createElement("div");$.className="tvw-flex",x.role==="user"&&$.classList.add("tvw-justify-end"),$.appendChild(b),F.appendChild($)});let H=p.some(x=>x.role==="assistant"&&x.streaming);if(lt&&p.some(x=>x.role==="user")&&!H){let x=sn(),b=document.createElement("div");b.className=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3"].join(" "),b.appendChild(x);let X=document.createElement("div");X.className="tvw-flex",X.appendChild(b),F.appendChild(X)}a.appendChild(F),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let x=cn();un(x)})})},qt=()=>{v&&(S?(te.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),A.classList.remove("tvw-scale-95","tvw-opacity-0"),A.classList.add("tvw-scale-100","tvw-opacity-100"),w?w.element.style.display="none":g&&(g.style.display="none")):(te.classList.add("tvw-pointer-events-none","tvw-opacity-0"),A.classList.remove("tvw-scale-100","tvw-opacity-100"),A.classList.add("tvw-scale-95","tvw-opacity-0"),w?w.element.style.display="":g&&(g.style.display="")))},ot=(a,p="user")=>{if(!v||S===a)return;let M=S;S=a,qt(),S&&(z(),ht(!0));let F={open:S,source:p,timestamp:Date.now()};S&&!M?s.emit("widget:opened",F):!S&&M&&s.emit("widget:closed",F),s.emit("widget:state",{open:S,launcherEnabled:v,voiceActive:ie.active,streaming:D.isStreaming()})},jt=a=>{oe.disabled=a,P.disabled=a,B&&(B.disabled=a),tt.buttons.forEach(p=>{p.disabled=a})},Qt=()=>{var H,x,b,X,ae,$,k,_,ee,fe,$e,He,rt,pe;wt.textContent=(x=(H=e.copy)==null?void 0:H.welcomeTitle)!=null?x:"Hello \u{1F44B}",vt.textContent=(X=(b=e.copy)==null?void 0:b.welcomeSubtitle)!=null?X:"Ask anything about your account or products.",oe.placeholder=($=(ae=e.copy)==null?void 0:ae.inputPlaceholder)!=null?$:"How can I help...",((_=(k=e.sendButton)==null?void 0:k.useIcon)!=null?_:!1)||(P.textContent=(fe=(ee=e.copy)==null?void 0:ee.sendButtonLabel)!=null?fe:"Send");let p=(He=($e=e.theme)==null?void 0:$e.inputFontFamily)!=null?He:"sans-serif",M=(pe=(rt=e.theme)==null?void 0:rt.inputFontWeight)!=null?pe:"400",F=At=>{switch(At){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};oe.style.fontFamily=F(p),oe.style.fontWeight=M};D=new Vt(e,{onMessagesChanged(a){Dt(ne,a,I),D&&(a.some(F=>F.role==="user")?tt.render([],D,oe,a):tt.render(e.suggestionChips,D,oe,a,e.suggestionChipsConfig)),ht(!lt),pn(a);let p=[...a].reverse().find(M=>M.role==="user");ie.lastUserMessageWasVoice=!!(p!=null&&p.viaVoice),Bt(a)},onStatusChanged(a){var F;let p=(F=e.statusIndicator)!=null?F:{},M=H=>{var x,b,X,ae;return H==="idle"?(x=p.idleText)!=null?x:Ve.idle:H==="connecting"?(b=p.connectingText)!=null?b:Ve.connecting:H==="connected"?(X=p.connectedText)!=null?X:Ve.connected:H==="error"?(ae=p.errorText)!=null?ae:Ve.error:Ve[H]};et.textContent=M(a)},onStreamingChanged(a){lt=a,jt(a),D&&Dt(ne,D.getMessages(),I),a||ht(!0)}}),u&&u.then(a=>{var p;a&&(a.metadata&&(l=Kn(a.metadata),C.syncFromMetadata()),(p=a.messages)!=null&&p.length&&D.hydrateMessages(a.messages))}).catch(a=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to hydrate stored state:",a)});let en=a=>{a.preventDefault();let p=oe.value.trim();p&&(oe.value="",D.sendMessage(p))},tn=a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),P.click())},Je=null,y=!1,G=null,Q=null,Ee=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,Me=(a="user")=>{var x,b,X,ae;if(y||D.isStreaming())return;let p=Ee();if(!p)return;Je=new p;let F=(b=((x=e.voiceRecognition)!=null?x:{}).pauseDuration)!=null?b:2e3;Je.continuous=!0,Je.interimResults=!0,Je.lang="en-US";let H=oe.value;Je.onresult=$=>{let k="",_="";for(let fe=0;fe<$.results.length;fe++){let $e=$.results[fe],He=$e[0].transcript;$e.isFinal?k+=He+" ":_=He}let ee=H+k+_;oe.value=ee,G&&clearTimeout(G),(k||_)&&(G=window.setTimeout(()=>{let fe=oe.value.trim();fe&&Je&&y&&(ye(),oe.value="",D.sendMessage(fe,{viaVoice:!0}))},F))},Je.onerror=$=>{$.error!=="no-speech"&&ye()},Je.onend=()=>{if(y){let $=oe.value.trim();$&&$!==H.trim()&&(oe.value="",D.sendMessage($,{viaVoice:!0})),ye()}};try{if(Je.start(),y=!0,ie.active=!0,a!=="system"&&(ie.manuallyDeactivated=!1),Lt(a),me(),B){Q={backgroundColor:B.style.backgroundColor,color:B.style.color,borderColor:B.style.borderColor};let $=(X=e.voiceRecognition)!=null?X:{},k=(ae=$.recordingBackgroundColor)!=null?ae:"#ef4444",_=$.recordingIconColor,ee=$.recordingBorderColor;if(B.classList.add("tvw-voice-recording"),B.style.backgroundColor=k,_){B.style.color=_;let fe=B.querySelector("svg");fe&&fe.setAttribute("stroke",_)}ee&&(B.style.borderColor=ee),B.setAttribute("aria-label","Stop voice recognition")}}catch{ye("system")}},ye=(a="user")=>{if(y){if(y=!1,G&&(clearTimeout(G),G=null),Je){try{Je.stop()}catch{}Je=null}if(ie.active=!1,Lt(a),me(),B){if(B.classList.remove("tvw-voice-recording"),Q){B.style.backgroundColor=Q.backgroundColor,B.style.color=Q.color,B.style.borderColor=Q.borderColor;let p=B.querySelector("svg");p&&p.setAttribute("stroke",Q.color||"currentColor"),Q=null}B.setAttribute("aria-label","Start voice recognition")}}},Le=(a,p)=>{var He,rt,pe,At,kt,Rt,Wt;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let F=c("div","tvw-send-button-wrapper"),H=c("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");H.type="button",H.setAttribute("aria-label","Start voice recognition");let x=(He=a==null?void 0:a.iconName)!=null?He:"mic",b=(rt=p==null?void 0:p.size)!=null?rt:"40px",X=(pe=a==null?void 0:a.iconSize)!=null?pe:b,ae=parseFloat(X)||24,$=(At=a==null?void 0:a.backgroundColor)!=null?At:p==null?void 0:p.backgroundColor,k=(kt=a==null?void 0:a.iconColor)!=null?kt:p==null?void 0:p.textColor;H.style.width=X,H.style.height=X,H.style.minWidth=X,H.style.minHeight=X,H.style.fontSize="18px",H.style.lineHeight="1";let _=k||"currentColor",ee=ge(x,ae,_,1.5);ee?(H.appendChild(ee),H.style.color=_):(H.textContent="\u{1F3A4}",H.style.color=_),$?H.style.backgroundColor=$:H.classList.add("tvw-bg-cw-primary"),k?H.style.color=k:!k&&!(p!=null&&p.textColor)&&H.classList.add("tvw-text-white"),a!=null&&a.borderWidth&&(H.style.borderWidth=a.borderWidth,H.style.borderStyle="solid"),a!=null&&a.borderColor&&(H.style.borderColor=a.borderColor),a!=null&&a.paddingX&&(H.style.paddingLeft=a.paddingX,H.style.paddingRight=a.paddingX),a!=null&&a.paddingY&&(H.style.paddingTop=a.paddingY,H.style.paddingBottom=a.paddingY),F.appendChild(H);let fe=(Rt=a==null?void 0:a.tooltipText)!=null?Rt:"Start voice recognition";if(((Wt=a==null?void 0:a.showTooltip)!=null?Wt:!1)&&fe){let zt=c("div","tvw-send-button-tooltip");zt.textContent=fe,F.appendChild(zt)}return{micButton:H,micButtonWrapper:F}},E=()=>{if(y){let a=oe.value.trim();ie.manuallyDeactivated=!0,me(),ye("user"),a&&(oe.value="",D.sendMessage(a))}else ie.manuallyDeactivated=!1,me(),Me("user")};B&&(B.addEventListener("click",E),Fe.push(()=>{ye("system"),B&&B.removeEventListener("click",E)}));let ut=s.on("assistant:complete",()=>{Nt&&(ie.active||ie.manuallyDeactivated||Nt==="assistant"&&!ie.lastUserMessageWasVoice||setTimeout(()=>{!ie.active&&!ie.manuallyDeactivated&&Me("auto")},600))});Fe.push(ut);let Y=()=>{ot(!S,"user")},w=null,g=null;if(v){let a=r.find(p=>p.renderLauncher);if(a!=null&&a.renderLauncher){let p=a.renderLauncher({config:e,defaultRenderer:()=>rn(e,Y).element,onToggle:Y});p&&(g=p)}g||(w=rn(e,Y))}w?t.appendChild(w.element):g&&t.appendChild(g),qt(),tt.render(e.suggestionChips,D,oe,void 0,e.suggestionChipsConfig),Qt(),jt(D.isStreaming()),ht(!0),ft();let z=()=>{var M,F,H,x,b,X;let a=(F=(M=e.launcher)==null?void 0:M.sidebarMode)!=null?F:!1,p=a||((x=(H=e.launcher)==null?void 0:H.fullHeight)!=null?x:!1);if(!v){A.style.height="",A.style.width="";return}if(!a){let ae=(X=(b=e==null?void 0:e.launcher)==null?void 0:b.width)!=null?X:e==null?void 0:e.launcherWidth,$=ae!=null?ae:"min(400px, calc(100vw - 24px))";A.style.width=$,A.style.maxWidth=$}if(!p){let ae=window.innerHeight,k=Math.max(200,ae-64),_=Math.min(640,k);A.style.height=`${_}px`}};z(),window.addEventListener("resize",z),Fe.push(()=>window.removeEventListener("resize",z)),We=j.scrollTop;let xe=()=>{let a=j.scrollTop,p=j.scrollHeight,M=j.clientHeight,F=p-a-M,H=Math.abs(a-We);if(We=a,!Ue&&!(H<=Mt)){if(!Ye&&F<ct){ve=!1,Ye=!0;return}Ye&&F>ct&&(ve=!0,Re=Date.now()+yt,Ye=!1)}};j.addEventListener("scroll",xe,{passive:!0}),Fe.push(()=>j.removeEventListener("scroll",xe)),Fe.push(()=>{K&&cancelAnimationFrame(K)});let be=()=>{N&&(je&&(N.removeEventListener("click",je),je=null),v?(N.style.display="",je=()=>{S=!1,qt()},N.addEventListener("click",je)):N.style.display="none")};be(),(()=>{let{clearChatButton:a}=se;a&&a.addEventListener("click",()=>{D.clearMessages();try{localStorage.removeItem(Zt),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Zt}`)}catch(M){console.error("[AgentWidget] Failed to clear default localStorage:",M)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==Zt)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(M){console.error("[AgentWidget] Failed to clear custom localStorage:",M)}let p=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(p),i!=null&&i.clear)try{let M=i.clear();M instanceof Promise&&M.catch(F=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",F)})}catch(M){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",M)}l={},C.syncFromMetadata()})})(),Ke.addEventListener("submit",en),oe.addEventListener("keydown",tn),Fe.push(()=>{Ke.removeEventListener("submit",en),oe.removeEventListener("keydown",tn)}),Fe.push(()=>{D.cancel()}),w?Fe.push(()=>{w==null||w.destroy()}):g&&Fe.push(()=>{g==null||g.remove()});let Ce={update(a){var oo,ro,so,io,ao,lo,co,uo,po,go,mo,fo,ho,wo,vo,yo,xo,bo,Co,So,To,Ao,Wo,Eo,Mo,Lo,Bo,Ho,ko,Ro,Io,Po,Fo,No,Do,qo,zo,Oo,$o,_o,jo,Uo,Vo,Ko,Xo,Yo,Jo,Go,Zo,Qo,er,tr,nr,or,rr,sr,ir;let p=e.toolCall;e={...e,...a},In(t,e),mt();let M=an.getForInstance(e.plugins);if(r.length=0,r.push(...M),v=(ro=(oo=e.launcher)==null?void 0:oo.enabled)!=null?ro:!0,O=(io=(so=e.launcher)==null?void 0:so.autoExpand)!=null?io:!1,T=(lo=(ao=e.features)==null?void 0:ao.showReasoning)!=null?lo:!0,U=(uo=(co=e.features)==null?void 0:co.showToolCalls)!=null?uo:!0,((po=e.launcher)==null?void 0:po.enabled)===!1&&w&&(w.destroy(),w=null),((go=e.launcher)==null?void 0:go.enabled)===!1&&g&&(g.remove(),g=null),((mo=e.launcher)==null?void 0:mo.enabled)!==!1&&!w&&!g){let L=r.find(ce=>ce.renderLauncher);if(L!=null&&L.renderLauncher){let ce=L.renderLauncher({config:e,defaultRenderer:()=>rn(e,Y).element,onToggle:Y});ce&&(g=ce,t.appendChild(g))}g||(w=rn(e,Y),t.appendChild(w.element))}w&&w.update(e),pt&&((fo=e.launcher)==null?void 0:fo.title)!==void 0&&(pt.textContent=e.launcher.title),gt&&((ho=e.launcher)==null?void 0:ho.subtitle)!==void 0&&(gt.textContent=e.launcher.subtitle),v!==f?v?ot(O,"auto"):(S=!0,qt()):O!==q&&ot(O,"auto"),q=O,f=v,z(),be(),JSON.stringify(a.toolCall)!==JSON.stringify(p)&&D&&Dt(ne,D.getMessages(),I);let b=(wo=e.launcher)!=null?wo:{},X=(vo=b.headerIconHidden)!=null?vo:!1,ae=b.headerIconName,$=(yo=b.headerIconSize)!=null?yo:"48px";if(de){let L=V.querySelector(".tvw-border-b-cw-divider"),ce=L==null?void 0:L.querySelector(".tvw-flex-col");if(X)de.style.display="none",L&&ce&&!L.contains(ce)&&L.insertBefore(ce,L.firstChild);else{if(de.style.display="",de.style.height=$,de.style.width=$,L&&ce&&(L.contains(de)?de.nextSibling!==ce&&(de.remove(),L.insertBefore(de,ce)):L.insertBefore(de,ce)),ae){let Ae=parseFloat($)||24,he=ge(ae,Ae*.6,"#ffffff",2);he?de.replaceChildren(he):de.textContent=(xo=b.agentIconText)!=null?xo:"\u{1F4AC}"}else if(b.iconUrl){let Ae=de.querySelector("img");if(Ae)Ae.src=b.iconUrl,Ae.style.height=$,Ae.style.width=$;else{let he=document.createElement("img");he.src=b.iconUrl,he.alt="",he.className="tvw-rounded-xl tvw-object-cover",he.style.height=$,he.style.width=$,de.replaceChildren(he)}}else{let Ae=de.querySelector("svg"),he=de.querySelector("img");(Ae||he)&&de.replaceChildren(),de.textContent=(bo=b.agentIconText)!=null?bo:"\u{1F4AC}"}let Z=de.querySelector("img");Z&&(Z.style.height=$,Z.style.width=$)}}if(N){let L=(Co=b.closeButtonSize)!=null?Co:"32px",ce=(So=b.closeButtonPlacement)!=null?So:"inline";N.style.height=L,N.style.width=L;let{closeButtonWrapper:Z}=se,Ae=ce==="top-right",he=Z==null?void 0:Z.classList.contains("tvw-absolute");if(Z&&Ae!==he)if(Z.remove(),Ae)Z.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50",V.style.position="relative",V.appendChild(Z);else{let le=(Ao=(To=b.clearChat)==null?void 0:To.placement)!=null?Ao:"inline",Ze=(Eo=(Wo=b.clearChat)==null?void 0:Wo.enabled)!=null?Eo:!0;Z.className=Ze&&le==="inline"?"":"tvw-ml-auto";let Qe=V.querySelector(".tvw-border-b-cw-divider");Qe&&Qe.appendChild(Z)}if(b.closeButtonColor?(N.style.color=b.closeButtonColor,N.classList.remove("tvw-text-cw-muted")):(N.style.color="",N.classList.add("tvw-text-cw-muted")),b.closeButtonBackgroundColor?(N.style.backgroundColor=b.closeButtonBackgroundColor,N.classList.remove("hover:tvw-bg-gray-100")):(N.style.backgroundColor="",N.classList.add("hover:tvw-bg-gray-100")),b.closeButtonBorderWidth||b.closeButtonBorderColor){let le=b.closeButtonBorderWidth||"0px",Ze=b.closeButtonBorderColor||"transparent";N.style.border=`${le} solid ${Ze}`,N.classList.remove("tvw-border-none")}else N.style.border="",N.classList.add("tvw-border-none");b.closeButtonBorderRadius?(N.style.borderRadius=b.closeButtonBorderRadius,N.classList.remove("tvw-rounded-full")):(N.style.borderRadius="",N.classList.add("tvw-rounded-full")),b.closeButtonPaddingX?(N.style.paddingLeft=b.closeButtonPaddingX,N.style.paddingRight=b.closeButtonPaddingX):(N.style.paddingLeft="",N.style.paddingRight=""),b.closeButtonPaddingY?(N.style.paddingTop=b.closeButtonPaddingY,N.style.paddingBottom=b.closeButtonPaddingY):(N.style.paddingTop="",N.style.paddingBottom="");let Ge=(Mo=b.closeButtonIconName)!=null?Mo:"x",De=(Lo=b.closeButtonIconText)!=null?Lo:"\xD7";N.innerHTML="";let dt=ge(Ge,"20px",b.closeButtonColor||"",2);dt?N.appendChild(dt):N.textContent=De;let It=(Bo=b.closeButtonTooltipText)!=null?Bo:"Close chat",Te=(Ho=b.closeButtonShowTooltip)!=null?Ho:!0;if(N.setAttribute("aria-label",It),Z&&(Z._cleanupTooltip&&(Z._cleanupTooltip(),delete Z._cleanupTooltip),Te&&It)){let le=null,Ze=()=>{if(le||!N)return;le=c("div","tvw-clear-chat-tooltip"),le.textContent=It;let Ut=c("div");Ut.className="tvw-clear-chat-tooltip-arrow",le.appendChild(Ut);let Bn=N.getBoundingClientRect();le.style.position="fixed",le.style.left=`${Bn.left+Bn.width/2}px`,le.style.top=`${Bn.top-8}px`,le.style.transform="translate(-50%, -100%)",document.body.appendChild(le)},Qe=()=>{le&&le.parentNode&&(le.parentNode.removeChild(le),le=null)};Z.addEventListener("mouseenter",Ze),Z.addEventListener("mouseleave",Qe),N.addEventListener("focus",Ze),N.addEventListener("blur",Qe),Z._cleanupTooltip=()=>{Qe(),Z&&(Z.removeEventListener("mouseenter",Ze),Z.removeEventListener("mouseleave",Qe)),N&&(N.removeEventListener("focus",Ze),N.removeEventListener("blur",Qe))}}}let{clearChatButton:k,clearChatButtonWrapper:_}=se;if(k){let L=(ko=b.clearChat)!=null?ko:{},ce=(Ro=L.enabled)!=null?Ro:!0,Z=(Io=L.placement)!=null?Io:"inline";if(_){_.style.display=ce?"":"none";let Ae=Z==="top-right",he=_.classList.contains("tvw-absolute");if(Ae!==he&&ce){if(_.remove(),Ae)_.className="tvw-absolute tvw-top-4 tvw-z-50",_.style.right="48px",V.style.position="relative",V.appendChild(_);else{_.className="tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper",_.style.right="";let De=V.querySelector(".tvw-border-b-cw-divider"),dt=se.closeButtonWrapper;De&&dt&&dt.parentElement===De?De.insertBefore(_,dt):De&&De.appendChild(_)}let Ge=se.closeButtonWrapper;Ge&&!Ge.classList.contains("tvw-absolute")&&(Ae?Ge.classList.add("tvw-ml-auto"):Ge.classList.remove("tvw-ml-auto"))}}if(ce){let Ae=(Po=L.size)!=null?Po:"32px";k.style.height=Ae,k.style.width=Ae;let he=(Fo=L.iconName)!=null?Fo:"refresh-cw",Ge=(No=L.iconColor)!=null?No:"";k.innerHTML="";let De=ge(he,"20px",Ge||"",2);if(De&&k.appendChild(De),Ge?(k.style.color=Ge,k.classList.remove("tvw-text-cw-muted")):(k.style.color="",k.classList.add("tvw-text-cw-muted")),L.backgroundColor?(k.style.backgroundColor=L.backgroundColor,k.classList.remove("hover:tvw-bg-gray-100")):(k.style.backgroundColor="",k.classList.add("hover:tvw-bg-gray-100")),L.borderWidth||L.borderColor){let Te=L.borderWidth||"0px",le=L.borderColor||"transparent";k.style.border=`${Te} solid ${le}`,k.classList.remove("tvw-border-none")}else k.style.border="",k.classList.add("tvw-border-none");L.borderRadius?(k.style.borderRadius=L.borderRadius,k.classList.remove("tvw-rounded-full")):(k.style.borderRadius="",k.classList.add("tvw-rounded-full")),L.paddingX?(k.style.paddingLeft=L.paddingX,k.style.paddingRight=L.paddingX):(k.style.paddingLeft="",k.style.paddingRight=""),L.paddingY?(k.style.paddingTop=L.paddingY,k.style.paddingBottom=L.paddingY):(k.style.paddingTop="",k.style.paddingBottom="");let dt=(Do=L.tooltipText)!=null?Do:"Clear chat",It=(qo=L.showTooltip)!=null?qo:!0;if(k.setAttribute("aria-label",dt),_&&(_._cleanupTooltip&&(_._cleanupTooltip(),delete _._cleanupTooltip),It&&dt)){let Te=null,le=()=>{if(Te||!k)return;Te=c("div","tvw-clear-chat-tooltip"),Te.textContent=dt;let Qe=c("div");Qe.className="tvw-clear-chat-tooltip-arrow",Te.appendChild(Qe);let Ut=k.getBoundingClientRect();Te.style.position="fixed",Te.style.left=`${Ut.left+Ut.width/2}px`,Te.style.top=`${Ut.top-8}px`,Te.style.transform="translate(-50%, -100%)",document.body.appendChild(Te)},Ze=()=>{Te&&Te.parentNode&&(Te.parentNode.removeChild(Te),Te=null)};_.addEventListener("mouseenter",le),_.addEventListener("mouseleave",Ze),k.addEventListener("focus",le),k.addEventListener("blur",Ze),_._cleanupTooltip=()=>{Ze(),_&&(_.removeEventListener("mouseenter",le),_.removeEventListener("mouseleave",Ze)),k&&(k.removeEventListener("focus",le),k.removeEventListener("blur",Ze))}}}}let ee=e.actionParsers&&e.actionParsers.length?e.actionParsers:[ln],fe=e.actionHandlers&&e.actionHandlers.length?e.actionHandlers:[_t.message,_t.messageAndClick];C=dn({parsers:ee,handlers:fe,getMetadata:m,updateMetadata:d,emit:s.emit,documentRef:typeof document!="undefined"?document:null}),I=Tr(e,C),D.updateConfig(e),Dt(ne,D.getMessages(),I),tt.render(e.suggestionChips,D,oe,void 0,e.suggestionChipsConfig),Qt(),jt(D.isStreaming());let $e=((zo=e.voiceRecognition)==null?void 0:zo.enabled)===!0,He=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),rt=$e&&He;if(Ke.classList.remove("tvw-gap-1","tvw-gap-3"),Ke.classList.add(rt?"tvw-gap-1":"tvw-gap-3"),$e&&He)if(!B||!ke){let L=Le(e.voiceRecognition,e.sendButton);L&&(B=L.micButton,ke=L.micButtonWrapper,Ke.insertBefore(ke,_e),B.addEventListener("click",E),B.disabled=D.isStreaming())}else{let L=(Oo=e.voiceRecognition)!=null?Oo:{},ce=($o=e.sendButton)!=null?$o:{},Z=(_o=L.iconName)!=null?_o:"mic",Ae=(jo=ce.size)!=null?jo:"40px",he=(Uo=L.iconSize)!=null?Uo:Ae,Ge=parseFloat(he)||24;B.style.width=he,B.style.height=he,B.style.minWidth=he,B.style.minHeight=he;let De=(Ko=(Vo=L.iconColor)!=null?Vo:ce.textColor)!=null?Ko:"currentColor";B.innerHTML="";let dt=ge(Z,Ge,De,2);dt?B.appendChild(dt):B.textContent="\u{1F3A4}";let It=(Xo=L.backgroundColor)!=null?Xo:ce.backgroundColor;It?(B.style.backgroundColor=It,B.classList.remove("tvw-bg-cw-primary")):(B.style.backgroundColor="",B.classList.add("tvw-bg-cw-primary")),De?(B.style.color=De,B.classList.remove("tvw-text-white")):!De&&!ce.textColor&&(B.style.color="",B.classList.add("tvw-text-white")),L.borderWidth?(B.style.borderWidth=L.borderWidth,B.style.borderStyle="solid"):(B.style.borderWidth="",B.style.borderStyle=""),L.borderColor?B.style.borderColor=L.borderColor:B.style.borderColor="",L.paddingX?(B.style.paddingLeft=L.paddingX,B.style.paddingRight=L.paddingX):(B.style.paddingLeft="",B.style.paddingRight=""),L.paddingY?(B.style.paddingTop=L.paddingY,B.style.paddingBottom=L.paddingY):(B.style.paddingTop="",B.style.paddingBottom="");let Te=ke==null?void 0:ke.querySelector(".tvw-send-button-tooltip"),le=(Yo=L.tooltipText)!=null?Yo:"Start voice recognition";if(((Jo=L.showTooltip)!=null?Jo:!1)&&le)if(Te)Te.textContent=le,Te.style.display="";else{let Qe=document.createElement("div");Qe.className="tvw-send-button-tooltip",Qe.textContent=le,ke==null||ke.insertBefore(Qe,B)}else Te&&(Te.style.display="none");ke.style.display="",B.disabled=D.isStreaming()}else B&&ke&&(ke.style.display="none",y&&ye());let pe=(Go=e.sendButton)!=null?Go:{},At=(Zo=pe.useIcon)!=null?Zo:!1,kt=(Qo=pe.iconText)!=null?Qo:"\u2191",Rt=pe.iconName,Wt=(er=pe.tooltipText)!=null?er:"Send message",zt=(tr=pe.showTooltip)!=null?tr:!1,Ot=(nr=pe.size)!=null?nr:"40px",gn=pe.backgroundColor,Ct=pe.textColor;if(At){if(P.style.width=Ot,P.style.height=Ot,P.style.minWidth=Ot,P.style.minHeight=Ot,P.style.fontSize="18px",P.style.lineHeight="1",P.innerHTML="",Rt){let L=parseFloat(Ot)||24,ce=Ct&&typeof Ct=="string"&&Ct.trim()?Ct.trim():"currentColor",Z=ge(Rt,L,ce,2);Z?(P.appendChild(Z),P.style.color=ce):(P.textContent=kt,Ct?P.style.color=Ct:P.classList.add("tvw-text-white"))}else P.textContent=kt,Ct?P.style.color=Ct:P.classList.add("tvw-text-white");P.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",gn?(P.style.backgroundColor=gn,P.classList.remove("tvw-bg-cw-primary")):P.classList.add("tvw-bg-cw-primary")}else P.textContent=(rr=(or=e.copy)==null?void 0:or.sendButtonLabel)!=null?rr:"Send",P.style.width="",P.style.height="",P.style.minWidth="",P.style.minHeight="",P.style.fontSize="",P.style.lineHeight="",P.className="tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-50 tvw-cursor-pointer",gn?(P.style.backgroundColor=gn,P.classList.remove("tvw-bg-cw-accent")):P.classList.add("tvw-bg-cw-accent"),Ct?P.style.color=Ct:P.classList.add("tvw-text-white");pe.borderWidth?(P.style.borderWidth=pe.borderWidth,P.style.borderStyle="solid"):(P.style.borderWidth="",P.style.borderStyle=""),pe.borderColor?P.style.borderColor=pe.borderColor:P.style.borderColor="",pe.paddingX?(P.style.paddingLeft=pe.paddingX,P.style.paddingRight=pe.paddingX):(P.style.paddingLeft="",P.style.paddingRight=""),pe.paddingY?(P.style.paddingTop=pe.paddingY,P.style.paddingBottom=pe.paddingY):(P.style.paddingTop="",P.style.paddingBottom="");let nn=_e==null?void 0:_e.querySelector(".tvw-send-button-tooltip");if(zt&&Wt)if(nn)nn.textContent=Wt,nn.style.display="";else{let L=document.createElement("div");L.className="tvw-send-button-tooltip",L.textContent=Wt,_e==null||_e.insertBefore(L,P)}else nn&&(nn.style.display="none");let on=(sr=e.statusIndicator)!=null?sr:{},Wr=(ir=on.visible)!=null?ir:!0;if(et.style.display=Wr?"":"none",D){let L=D.getStatus(),ce=Z=>{var Ae,he,Ge,De;return Z==="idle"?(Ae=on.idleText)!=null?Ae:Ve.idle:Z==="connecting"?(he=on.connectingText)!=null?he:Ve.connecting:Z==="connected"?(Ge=on.connectedText)!=null?Ge:Ve.connected:Z==="error"?(De=on.errorText)!=null?De:Ve.error:Ve[Z]};et.textContent=ce(L)}},open(){v&&ot(!0,"api")},close(){v&&ot(!1,"api")},toggle(){v&&ot(!S,"api")},clearChat(){D.clearMessages();try{localStorage.removeItem(Zt),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Zt}`)}catch(p){console.error("[AgentWidget] Failed to clear default localStorage:",p)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==Zt)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(p){console.error("[AgentWidget] Failed to clear custom localStorage:",p)}let a=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(a),i!=null&&i.clear)try{let p=i.clear();p instanceof Promise&&p.catch(M=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",M)})}catch(p){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",p)}l={},C.syncFromMetadata()},setMessage(a){return!oe||D.isStreaming()?!1:(!S&&v&&ot(!0,"system"),oe.value=a,oe.dispatchEvent(new Event("input",{bubbles:!0})),!0)},submitMessage(a){if(D.isStreaming())return!1;let p=(a==null?void 0:a.trim())||oe.value.trim();return p?(!S&&v&&ot(!0,"system"),oe.value="",D.sendMessage(p),!0):!1},startVoiceRecognition(){return y||D.isStreaming()||!Ee()?!1:(!S&&v&&ot(!0,"system"),ie.manuallyDeactivated=!1,me(),Me("user"),!0)},stopVoiceRecognition(){return y?(ie.manuallyDeactivated=!0,me(),ye("user"),!0):!1},injectTestMessage(a){!S&&v&&ot(!0,"system"),D.injectTestEvent(a)},getMessages(){return D.getMessages()},getStatus(){return D.getStatus()},getPersistentMetadata(){return{...l}},updatePersistentMetadata(a){d(a)},on(a,p){return s.on(a,p)},off(a,p){s.off(a,p)},isOpen(){return v&&S},isVoiceActive(){return ie.active},getState(){return{open:v&&S,launcherEnabled:v,voiceActive:ie.active,streaming:D.isStreaming()}},destroy(){Fe.forEach(a=>a()),te.remove(),w==null||w.destroy(),g==null||g.remove(),je&&N.removeEventListener("click",je)}};if((((no=o==null?void 0:o.debugTools)!=null?no:!1)||!!e.debug)&&typeof window!="undefined"){let a=window.AgentWidgetBrowser,p={controller:Ce,getMessages:Ce.getMessages,getStatus:Ce.getStatus,getMetadata:Ce.getPersistentMetadata,updateMetadata:Ce.updatePersistentMetadata,clearHistory:()=>Ce.clearChat(),setVoiceActive:M=>M?Ce.startVoiceRecognition():Ce.stopVoiceRecognition()};window.AgentWidgetBrowser=p,Fe.push(()=>{window.AgentWidgetBrowser===p&&(window.AgentWidgetBrowser=a)})}return Ce};var Xn={},es=t=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof t=="string"){let n=document.querySelector(t);if(!n)throw new Error(`Chat widget target "${t}" was not found`);return n}return t},ts=()=>{try{if(typeof Xn!="undefined"&&Xn.url)return new URL("../widget.css",Xn.url).href}catch{}return null},Ar=t=>{let n=ts(),o=()=>{if(!(t instanceof ShadowRoot)||t.querySelector("link[data-vanilla-agent]"))return;let e=document.head.querySelector("link[data-vanilla-agent]");if(!e)return;let r=e.cloneNode(!0);t.insertBefore(r,t.firstChild)};if(t instanceof ShadowRoot)if(n){let e=document.createElement("link");e.rel="stylesheet",e.href=n,e.setAttribute("data-vanilla-agent","true"),t.insertBefore(e,t.firstChild)}else o();else if(!document.head.querySelector("link[data-vanilla-agent]")&&n){let r=document.createElement("link");r.rel="stylesheet",r.href=n,r.setAttribute("data-vanilla-agent","true"),document.head.appendChild(r)}},Yn=t=>{var m,d,W,h;let n=es(t.target),o=document.createElement("div");o.className="vanilla-agent-host";let e=(W=(d=(m=t.config)==null?void 0:m.launcher)==null?void 0:d.enabled)!=null?W:!0;e||(o.style.height="100%",o.style.display="flex",o.style.flexDirection="column"),n.appendChild(o);let r=t.useShadowDom!==!1,s,i;if(r){let C=o.attachShadow({mode:"open"});i=C,s=document.createElement("div"),s.id="vanilla-agent-root",e||(s.style.height="100%",s.style.display="flex",s.style.flexDirection="column",s.style.flex="1",s.style.minHeight="0"),C.appendChild(s),Ar(C)}else i=o,s=document.createElement("div"),s.id="vanilla-agent-root",e||(s.style.height="100%",s.style.display="flex",s.style.flexDirection="column",s.style.flex="1",s.style.minHeight="0"),o.appendChild(s),Ar(o);let l=Ln(s,t.config,{debugTools:t.debugTools});(h=t.onReady)==null||h.call(t);let u={...l,host:o,destroy(){l.destroy(),o.remove(),t.windowKey&&typeof window!="undefined"&&delete window[t.windowKey]}};return t.windowKey&&typeof window!="undefined"&&(window[t.windowKey]=u),u};var ns=Yn;0&&(module.exports={AgentWidgetClient,AgentWidgetSession,DEFAULT_WIDGET_CONFIG,attachHeaderToContainer,buildComposer,buildDefaultHeader,buildExpandedHeader,buildHeader,buildHeaderWithLayout,buildMinimalHeader,componentRegistry,createActionManager,createAgentExperience,createBubbleWithLayout,createComponentMiddleware,createComponentStreamParser,createFlexibleJsonStreamParser,createJsonStreamParser,createLocalStorageAdapter,createPlainTextParser,createRegexJsonParser,createStandardBubble,createTypingIndicator,createXmlParser,defaultActionHandlers,defaultJsonActionParser,directivePostprocessor,escapeHtml,extractComponentDirectiveFromMessage,getHeaderLayout,hasComponentDirective,headerLayouts,initAgentWidget,isComponentDirectiveType,markdownPostprocessor,mergeWithDefaults,pluginRegistry,renderComponentDirective});
16
55
  //# sourceMappingURL=index.cjs.map