vanilla-agent 1.0.0 → 1.1.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,7 +1,7 @@
1
- "use strict";var Xn=Object.create;var Ke=Object.defineProperty;var Yn=Object.getOwnPropertyDescriptor;var Vn=Object.getOwnPropertyNames;var Gn=Object.getPrototypeOf,Kn=Object.prototype.hasOwnProperty;var Jn=(t,n)=>{for(var e in n)Ke(t,e,{get:n[e],enumerable:!0})},Nn=(t,n,e,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Vn(n))!Kn.call(t,o)&&o!==e&&Ke(t,o,{get:()=>n[o],enumerable:!(i=Yn(n,o))||i.enumerable});return t};var Zn=(t,n,e)=>(e=t!=null?Xn(Gn(t)):{},Nn(n||!t||!t.__esModule?Ke(e,"default",{value:t,enumerable:!0}):e,t)),Qn=t=>Nn(Ke({},"__esModule",{value:!0}),t);var uo={};Jn(uo,{AgentWidgetClient:()=>Ae,AgentWidgetSession:()=>We,DEFAULT_WIDGET_CONFIG:()=>It,createAgentExperience:()=>Qe,default:()=>co,directivePostprocessor:()=>Dn,escapeHtml:()=>Je,initAgentWidget:()=>wn,markdownPostprocessor:()=>nn,mergeWithDefaults:()=>Ze,pluginRegistry:()=>Ye});module.exports=Qn(uo);var en=require("marked");en.marked.setOptions({breaks:!0});var nn=t=>en.marked.parse(t),Je=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),to=t=>t.replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Fn=t=>`%%FORM_PLACEHOLDER_${t}%%`,eo=(t,n)=>{let e=t;return e=e.replace(/<Directive>([\s\S]*?)<\/Directive>/gi,(i,o)=>{try{let d=JSON.parse(o.trim());if(d&&typeof d=="object"&&d.component==="form"&&d.type){let a=Fn(n.length);return n.push({token:a,type:String(d.type)}),a}}catch{return i}return i}),e=e.replace(/<Form\s+type="([^"]+)"\s*\/>/gi,(i,o)=>{let d=Fn(n.length);return n.push({token:d,type:o}),d}),e},Dn=t=>{let n=[],e=eo(t,n),i=nn(e);return n.forEach(({token:o,type:d})=>{let a=new RegExp(o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),x=`<div class="tvw-form-directive" data-tv-form="${to(d)}"></div>`;i=i.replace(a,x)}),i};var no="https://api.travrse.ai/v1/dispatch",Ae=class{constructor(n={}){this.config=n;var e;this.apiUrl=(e=n.apiUrl)!=null?e:no,this.headers={"Content-Type":"application/json",...n.headers},this.debug=!!n.debug}async dispatch(n,e){let i=new AbortController;n.signal&&n.signal.addEventListener("abort",()=>i.abort()),e({type:"status",status:"connecting"});let o={messages:n.messages.slice().sort((a,S)=>{let x=new Date(a.createdAt).getTime(),E=new Date(S.createdAt).getTime();return x-E}).map(a=>({role:a.role,content:a.content,createdAt:a.createdAt})),...this.config.flowId&&{flowId:this.config.flowId}};this.debug&&console.debug("[AgentWidgetClient] dispatch body",o);let d=await fetch(this.apiUrl,{method:"POST",headers:this.headers,body:JSON.stringify(o),signal:i.signal});if(!d.ok||!d.body){let a=new Error(`Chat backend request failed: ${d.status} ${d.statusText}`);throw e({type:"error",error:a}),a}e({type:"status",status:"connected"});try{await this.streamResponse(d.body,e)}finally{e({type:"status",status:"idle"})}}async streamResponse(n,e){var Ct,C,U,v,ut,Et,Yt,Ft,P,bt,F,Kt,fe,Dt,j,Jt,Zt,ye,be,Ee,Ht,qt,gt,Rt,I,V,ie,D,Mt,xe,it,Tt,zt,Bt,Ce,Te,Wt,Se,Qt,ae,G,Pt,le,de,Me,ce,ue,pe,ge;let i=n.getReader(),o=new TextDecoder,d="",a=Date.now(),S=0,x=()=>a+S++,E=g=>{let R=g.reasoning?{...g.reasoning,chunks:[...g.reasoning.chunks]}:void 0,q=g.toolCall?{...g.toolCall,chunks:g.toolCall.chunks?[...g.toolCall.chunks]:void 0}:void 0,Z=g.tools?g.tools.map(tt=>({...tt,chunks:tt.chunks?[...tt.chunks]:void 0})):void 0;return{...g,reasoning:R,toolCall:q,tools:Z}},f=g=>{e({type:"message",message:E(g)})},k=null,h=new Map,O=new Map,L={lastId:null,byStep:new Map},X={lastId:null,byCall:new Map},A=g=>{if(g==null)return null;try{return String(g)}catch{return null}},N=g=>{var R,q,Z,tt,r;return A((r=(tt=(Z=(q=(R=g.stepId)!=null?R:g.step_id)!=null?q:g.step)!=null?Z:g.parentId)!=null?tt:g.flowStepId)!=null?r:g.flow_step_id)},z=g=>{var R,q,Z,tt,r,p,c;return A((c=(p=(r=(tt=(Z=(q=(R=g.callId)!=null?R:g.call_id)!=null?q:g.requestId)!=null?Z:g.request_id)!=null?tt:g.toolCallId)!=null?r:g.tool_call_id)!=null?p:g.stepId)!=null?c:g.step_id)},T=()=>k||(k={id:`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"assistant",sequence:x()},f(k),k),ct=(g,R)=>{L.lastId=R,g&&L.byStep.set(g,R)},M=(g,R)=>{var r;let q=(r=g.reasoningId)!=null?r:g.id,Z=N(g);if(q){let p=String(q);return ct(Z,p),p}if(Z){let p=L.byStep.get(Z);if(p)return L.lastId=p,p}if(L.lastId&&!R)return L.lastId;if(!R)return null;let tt=`reason-${x()}`;return ct(Z,tt),tt},y=g=>{let R=h.get(g);if(R)return R;let q={id:`reason-${g}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"reasoning",sequence:x(),reasoning:{id:g,status:"streaming",chunks:[]}};return h.set(g,q),f(q),q},Y=(g,R)=>{X.lastId=R,g&&X.byCall.set(g,R)},Q=(g,R)=>{var r;let q=(r=g.toolId)!=null?r:g.id,Z=z(g);if(q){let p=String(q);return Y(Z,p),p}if(Z){let p=X.byCall.get(Z);if(p)return X.lastId=p,p}if(X.lastId&&!R)return X.lastId;if(!R)return null;let tt=`tool-${x()}`;return Y(Z,tt),tt},ot=g=>{let R=O.get(g);if(R)return R;let q={id:`tool-${g}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"tool",sequence:x(),toolCall:{id:g,status:"pending"}};return O.set(g,q),f(q),q},pt=g=>{if(typeof g=="number"&&Number.isFinite(g))return g;if(typeof g=="string"){let R=Number(g);if(!Number.isNaN(R)&&Number.isFinite(R))return R;let q=Date.parse(g);if(!Number.isNaN(q))return q}return Date.now()};for(;;){let{done:g,value:R}=await i.read();if(g)break;d+=o.decode(R,{stream:!0});let q=d.split(`
1
+ "use strict";var Xn=Object.create;var Ke=Object.defineProperty;var Yn=Object.getOwnPropertyDescriptor;var Vn=Object.getOwnPropertyNames;var Gn=Object.getPrototypeOf,Kn=Object.prototype.hasOwnProperty;var Jn=(t,n)=>{for(var e in n)Ke(t,e,{get:n[e],enumerable:!0})},Nn=(t,n,e,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Vn(n))!Kn.call(t,o)&&o!==e&&Ke(t,o,{get:()=>n[o],enumerable:!(s=Yn(n,o))||s.enumerable});return t};var Zn=(t,n,e)=>(e=t!=null?Xn(Gn(t)):{},Nn(n||!t||!t.__esModule?Ke(e,"default",{value:t,enumerable:!0}):e,t)),Qn=t=>Nn(Ke({},"__esModule",{value:!0}),t);var uo={};Jn(uo,{AgentWidgetClient:()=>Le,AgentWidgetSession:()=>Be,DEFAULT_WIDGET_CONFIG:()=>kt,createAgentExperience:()=>Qe,default:()=>co,directivePostprocessor:()=>Dn,escapeHtml:()=>Je,initAgentWidget:()=>hn,markdownPostprocessor:()=>nn,mergeWithDefaults:()=>Ze,pluginRegistry:()=>Ye});module.exports=Qn(uo);var en=require("marked");en.marked.setOptions({breaks:!0});var nn=t=>en.marked.parse(t),Je=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),to=t=>t.replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Fn=t=>`%%FORM_PLACEHOLDER_${t}%%`,eo=(t,n)=>{let e=t;return e=e.replace(/<Directive>([\s\S]*?)<\/Directive>/gi,(s,o)=>{try{let l=JSON.parse(o.trim());if(l&&typeof l=="object"&&l.component==="form"&&l.type){let a=Fn(n.length);return n.push({token:a,type:String(l.type)}),a}}catch{return s}return s}),e=e.replace(/<Form\s+type="([^"]+)"\s*\/>/gi,(s,o)=>{let l=Fn(n.length);return n.push({token:l,type:o}),l}),e},Dn=t=>{let n=[],e=eo(t,n),s=nn(e);return n.forEach(({token:o,type:l})=>{let a=new RegExp(o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),C=`<div class="tvw-form-directive" data-tv-form="${to(l)}"></div>`;s=s.replace(a,C)}),s};var no="https://api.travrse.ai/v1/dispatch",Le=class{constructor(n={}){this.config=n;var e;this.apiUrl=(e=n.apiUrl)!=null?e:no,this.headers={"Content-Type":"application/json",...n.headers},this.debug=!!n.debug}async dispatch(n,e){let s=new AbortController;n.signal&&n.signal.addEventListener("abort",()=>s.abort()),e({type:"status",status:"connecting"});let o={messages:n.messages.slice().sort((a,L)=>{let C=new Date(a.createdAt).getTime(),M=new Date(L.createdAt).getTime();return C-M}).map(a=>({role:a.role,content:a.content,createdAt:a.createdAt})),...this.config.flowId&&{flowId:this.config.flowId}};this.debug&&console.debug("[AgentWidgetClient] dispatch body",o);let l=await fetch(this.apiUrl,{method:"POST",headers:this.headers,body:JSON.stringify(o),signal:s.signal});if(!l.ok||!l.body){let a=new Error(`Chat backend request failed: ${l.status} ${l.statusText}`);throw e({type:"error",error:a}),a}e({type:"status",status:"connected"});try{await this.streamResponse(l.body,e)}finally{e({type:"status",status:"idle"})}}async streamResponse(n,e){var Ct,T,j,f,ct,At,Xt,Ft,$,bt,D,Gt,ve,Dt,X,Kt,Jt,fe,ye,Ae,It,qt,at,Et,W,Q,be,q,Mt,pt,ht,Ht,Rt,xe,Ce,Bt,Te,Zt,se,G,zt,ie,ae,Ee,le,de,ce,ue,pe;let s=n.getReader(),o=new TextDecoder,l="",a=Date.now(),L=0,C=()=>a+L++,M=w=>{let R=w.reasoning?{...w.reasoning,chunks:[...w.reasoning.chunks]}:void 0,z=w.toolCall?{...w.toolCall,chunks:w.toolCall.chunks?[...w.toolCall.chunks]:void 0}:void 0,J=w.tools?w.tools.map(r=>({...r,chunks:r.chunks?[...r.chunks]:void 0})):void 0;return{...w,reasoning:R,toolCall:z,tools:J}},y=w=>{e({type:"message",message:M(w)})},I=null,h=new Map,_=new Map,A={lastId:null,byStep:new Map},Y={lastId:null,byCall:new Map},E=w=>{if(w==null)return null;try{return String(w)}catch{return null}},N=w=>{var R,z,J,r,v;return E((v=(r=(J=(z=(R=w.stepId)!=null?R:w.step_id)!=null?z:w.step)!=null?J:w.parentId)!=null?r:w.flowStepId)!=null?v:w.flow_step_id)},P=w=>{var R,z,J,r,v,H,u;return E((u=(H=(v=(r=(J=(z=(R=w.callId)!=null?R:w.call_id)!=null?z:w.requestId)!=null?J:w.request_id)!=null?r:w.toolCallId)!=null?v:w.tool_call_id)!=null?H:w.stepId)!=null?u:w.step_id)},S=()=>I||(I={id:`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"assistant",sequence:C()},y(I),I),dt=(w,R)=>{A.lastId=R,w&&A.byStep.set(w,R)},B=(w,R)=>{var v;let z=(v=w.reasoningId)!=null?v:w.id,J=N(w);if(z){let H=String(z);return dt(J,H),H}if(J){let H=A.byStep.get(J);if(H)return A.lastId=H,H}if(A.lastId&&!R)return A.lastId;if(!R)return null;let r=`reason-${C()}`;return dt(J,r),r},b=w=>{let R=h.get(w);if(R)return R;let z={id:`reason-${w}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"reasoning",sequence:C(),reasoning:{id:w,status:"streaming",chunks:[]}};return h.set(w,z),y(z),z},V=(w,R)=>{Y.lastId=R,w&&Y.byCall.set(w,R)},Z=(w,R)=>{var v;let z=(v=w.toolId)!=null?v:w.id,J=P(w);if(z){let H=String(z);return V(J,H),H}if(J){let H=Y.byCall.get(J);if(H)return Y.lastId=H,H}if(Y.lastId&&!R)return Y.lastId;if(!R)return null;let r=`tool-${C()}`;return V(J,r),r},nt=w=>{let R=_.get(w);if(R)return R;let z={id:`tool-${w}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"tool",sequence:C(),toolCall:{id:w,status:"pending"}};return _.set(w,z),y(z),z},ut=w=>{if(typeof w=="number"&&Number.isFinite(w))return w;if(typeof w=="string"){let R=Number(w);if(!Number.isNaN(R)&&Number.isFinite(R))return R;let z=Date.parse(w);if(!Number.isNaN(z))return z}return Date.now()};for(;;){let{done:w,value:R}=await s.read();if(w)break;l+=o.decode(R,{stream:!0});let z=l.split(`
2
2
 
3
- `);d=(Ct=q.pop())!=null?Ct:"";for(let Z of q){let tt=Z.split(`
4
- `),r="message",p="";for(let s of tt)s.startsWith("event:")?r=s.replace("event:","").trim():s.startsWith("data:")&&(p+=s.replace("data:","").trim());if(!p)continue;let c;try{c=JSON.parse(p)}catch(s){e({type:"error",error:s instanceof Error?s:new Error("Failed to parse chat stream payload")});continue}let H=r!=="message"?r:(C=c.type)!=null?C:"message";if(H==="reason_start"){let s=(U=M(c,!0))!=null?U:`reason-${x()}`,l=y(s);l.reasoning=(v=l.reasoning)!=null?v:{id:s,status:"streaming",chunks:[]},l.reasoning.startedAt=(Et=l.reasoning.startedAt)!=null?Et:pt((ut=c.startedAt)!=null?ut:c.timestamp),l.reasoning.completedAt=void 0,l.reasoning.durationMs=void 0,l.streaming=!0,l.reasoning.status="streaming",f(l)}else if(H==="reason_chunk"){let s=(Ft=(Yt=M(c,!1))!=null?Yt:M(c,!0))!=null?Ft:`reason-${x()}`,l=y(s);l.reasoning=(P=l.reasoning)!=null?P:{id:s,status:"streaming",chunks:[]},l.reasoning.startedAt=(F=l.reasoning.startedAt)!=null?F:pt((bt=c.startedAt)!=null?bt:c.timestamp);let m=(Dt=(fe=(Kt=c.reasoningText)!=null?Kt:c.text)!=null?fe:c.delta)!=null?Dt:"";if(m&&c.hidden!==!0&&l.reasoning.chunks.push(String(m)),l.reasoning.status=c.done?"complete":"streaming",c.done){l.reasoning.completedAt=pt((j=c.completedAt)!=null?j:c.timestamp);let B=(Jt=l.reasoning.startedAt)!=null?Jt:Date.now();l.reasoning.durationMs=Math.max(0,((Zt=l.reasoning.completedAt)!=null?Zt:Date.now())-B)}l.streaming=l.reasoning.status!=="complete",f(l)}else if(H==="reason_complete"){let s=(be=(ye=M(c,!1))!=null?ye:M(c,!0))!=null?be:`reason-${x()}`,l=h.get(s);if(l!=null&&l.reasoning){l.reasoning.status="complete",l.reasoning.completedAt=pt((Ee=c.completedAt)!=null?Ee:c.timestamp);let B=(Ht=l.reasoning.startedAt)!=null?Ht:Date.now();l.reasoning.durationMs=Math.max(0,((qt=l.reasoning.completedAt)!=null?qt:Date.now())-B),l.streaming=!1,f(l)}let m=N(c);m&&L.byStep.delete(m)}else if(H==="tool_start"){let s=(gt=Q(c,!0))!=null?gt:`tool-${x()}`,l=ot(s),m=(Rt=l.toolCall)!=null?Rt:{id:s,status:"pending"};m.name=(I=c.toolName)!=null?I:m.name,m.status="running",c.args!==void 0&&(m.args=c.args),m.startedAt=(ie=m.startedAt)!=null?ie:pt((V=c.startedAt)!=null?V:c.timestamp),m.completedAt=void 0,m.durationMs=void 0,l.toolCall=m,l.streaming=!0,f(l)}else if(H==="tool_chunk"){let s=(Mt=(D=Q(c,!1))!=null?D:Q(c,!0))!=null?Mt:`tool-${x()}`,l=ot(s),m=(xe=l.toolCall)!=null?xe:{id:s,status:"running"};m.startedAt=(Tt=m.startedAt)!=null?Tt:pt((it=c.startedAt)!=null?it:c.timestamp);let B=(Ce=(Bt=(zt=c.text)!=null?zt:c.delta)!=null?Bt:c.message)!=null?Ce:"";B&&(m.chunks=(Te=m.chunks)!=null?Te:[],m.chunks.push(String(B))),m.status="running",l.toolCall=m,l.streaming=!0,f(l)}else if(H==="tool_complete"){let s=(Se=(Wt=Q(c,!1))!=null?Wt:Q(c,!0))!=null?Se:`tool-${x()}`,l=ot(s),m=(Qt=l.toolCall)!=null?Qt:{id:s,status:"running"};if(m.status="complete",c.result!==void 0&&(m.result=c.result),typeof c.duration=="number"&&(m.duration=c.duration),m.completedAt=pt((ae=c.completedAt)!=null?ae:c.timestamp),typeof c.duration=="number")m.durationMs=c.duration;else{let w=(G=m.startedAt)!=null?G:Date.now();m.durationMs=Math.max(0,((Pt=m.completedAt)!=null?Pt:Date.now())-w)}l.toolCall=m,l.streaming=!1,f(l);let B=z(c);B&&X.byCall.delete(B)}else if(H==="step_chunk"){let s=T(),l=(Me=(de=(le=c.text)!=null?le:c.delta)!=null?de:c.content)!=null?Me:"";if(l&&(s.content+=l,f(s)),c.isComplete){let m=(ue=(ce=c.result)==null?void 0:ce.response)!=null?ue:s.content;m&&(s.content=m,s.streaming=!1,f(s))}}else if(H==="step_complete"){let s=(pe=c.result)==null?void 0:pe.response,l=T();s?(l.content=s,l.streaming=!1,f(l)):(l.streaming=!1,f(l))}else if(H==="flow_complete"){let s=(ge=c.result)==null?void 0:ge.response;if(s){let l=T();s!==l.content&&(l.content=s,f(l)),l.streaming=!1,f(l)}else{let l=k;if(l){let m=l;m.streaming=!1,f(m)}}e({type:"status",status:"idle"})}else H==="error"&&c.error&&e({type:"error",error:c.error instanceof Error?c.error:new Error(String(c.error))})}}}};var We=class{constructor(n={},e){this.config=n;this.callbacks=e;this.status="idle";this.streaming=!1;this.abortController=null;this.sequenceCounter=Date.now();this.handleEvent=n=>{var e,i;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,(i=(e=this.callbacks).onError)==null||i.call(e,n.error))};var i;this.messages=[...(i=n.initialMessages)!=null?i:[]].map(o=>{var d;return{...o,sequence:(d=o.sequence)!=null?d:this.nextSequence()}}),this.messages=this.sortMessages(this.messages),this.client=new Ae(n),this.messages.length&&this.callbacks.onMessagesChanged([...this.messages]),this.callbacks.onStatusChanged(this.status)}updateConfig(n){this.config={...this.config,...n},this.client=new Ae(this.config)}getMessages(){return[...this.messages]}getStatus(){return this.status}isStreaming(){return this.streaming}async sendMessage(n){var a,S,x,E,f;let e=n.trim();if(!e)return;(a=this.abortController)==null||a.abort();let i={id:`user-${Date.now()}`,role:"user",content:e,createdAt:new Date().toISOString(),sequence:this.nextSequence()};this.appendMessage(i),this.setStreaming(!0);let o=new AbortController;this.abortController=o;let d=[...this.messages];try{await this.client.dispatch({messages:d,signal:o.signal},this.handleEvent)}catch(k){let h={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(h),this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,k instanceof Error?(x=(S=this.callbacks).onError)==null||x.call(S,k):(f=(E=this.callbacks).onError)==null||f.call(E,new Error(String(k)))}}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])}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 e=this.ensureSequence(n);this.messages=this.sortMessages([...this.messages,e]),this.callbacks.onMessagesChanged([...this.messages])}upsertMessage(n){let e=this.ensureSequence(n),i=this.messages.findIndex(o=>o.id===e.id);if(i===-1){this.appendMessage(e);return}this.messages=this.messages.map((o,d)=>d===i?{...o,...e}: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((e,i)=>{var x,E;let o=new Date(e.createdAt).getTime(),d=new Date(i.createdAt).getTime();if(!Number.isNaN(o)&&!Number.isNaN(d)&&o!==d)return o-d;let a=(x=e.sequence)!=null?x:0,S=(E=i.sequence)!=null?E:0;return a!==S?a-S:e.id.localeCompare(i.id)})}};var on=(t,n)=>{var i;let e=(i=n==null?void 0:n.theme)!=null?i:{};Object.entries(e).forEach(([o,d])=>{if(d==null||d==="")return;let a=o.replace(/[A-Z]/g,S=>`-${S.toLowerCase()}`);t.style.setProperty(`--cw-${a}`,String(d))})};var oo=Zn(require("lucide"),1),ft=(t,n=24,e="currentColor",i=2)=>{try{let o=t.split("-").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(""),d=oo[o];return d?so(d,n,e,i):(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 so(t,n,e,i){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",e),o.setAttribute("stroke-width",String(i)),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.setAttribute("aria-hidden","true"),t.forEach(d=>{if(Array.isArray(d)&&d.length>=2){let a=d[0],S=d[1];if(S){let x=document.createElementNS("http://www.w3.org/2000/svg",a);Object.entries(S).forEach(([E,f])=>{E!=="stroke"&&x.setAttribute(E,String(f))}),o.appendChild(x)}}}),o}var u=(t,n)=>{let e=document.createElement(t);return n&&(e.className=n),e};var yt={idle:"Online",connecting:"Connecting\u2026",connected:"Streaming\u2026",error:"Offline"};var ve={"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 sn=(t,n)=>{let e=u("button");e.type="button",e.innerHTML=`
3
+ `);l=(Ct=z.pop())!=null?Ct:"";for(let J of z){let r=J.split(`
4
+ `),v="message",H="";for(let c of r)c.startsWith("event:")?v=c.replace("event:","").trim():c.startsWith("data:")&&(H+=c.replace("data:","").trim());if(!H)continue;let u;try{u=JSON.parse(H)}catch(c){e({type:"error",error:c instanceof Error?c:new Error("Failed to parse chat stream payload")});continue}let d=v!=="message"?v:(T=u.type)!=null?T:"message";if(d==="reason_start"){let c=(j=B(u,!0))!=null?j:`reason-${C()}`,i=b(c);i.reasoning=(f=i.reasoning)!=null?f:{id:c,status:"streaming",chunks:[]},i.reasoning.startedAt=(At=i.reasoning.startedAt)!=null?At:ut((ct=u.startedAt)!=null?ct:u.timestamp),i.reasoning.completedAt=void 0,i.reasoning.durationMs=void 0,i.streaming=!0,i.reasoning.status="streaming",y(i)}else if(d==="reason_chunk"){let c=(Ft=(Xt=B(u,!1))!=null?Xt:B(u,!0))!=null?Ft:`reason-${C()}`,i=b(c);i.reasoning=($=i.reasoning)!=null?$:{id:c,status:"streaming",chunks:[]},i.reasoning.startedAt=(D=i.reasoning.startedAt)!=null?D:ut((bt=u.startedAt)!=null?bt:u.timestamp);let g=(Dt=(ve=(Gt=u.reasoningText)!=null?Gt:u.text)!=null?ve:u.delta)!=null?Dt:"";if(g&&u.hidden!==!0&&i.reasoning.chunks.push(String(g)),i.reasoning.status=u.done?"complete":"streaming",u.done){i.reasoning.completedAt=ut((X=u.completedAt)!=null?X:u.timestamp);let m=(Kt=i.reasoning.startedAt)!=null?Kt:Date.now();i.reasoning.durationMs=Math.max(0,((Jt=i.reasoning.completedAt)!=null?Jt:Date.now())-m)}i.streaming=i.reasoning.status!=="complete",y(i)}else if(d==="reason_complete"){let c=(ye=(fe=B(u,!1))!=null?fe:B(u,!0))!=null?ye:`reason-${C()}`,i=h.get(c);if(i!=null&&i.reasoning){i.reasoning.status="complete",i.reasoning.completedAt=ut((Ae=u.completedAt)!=null?Ae:u.timestamp);let m=(It=i.reasoning.startedAt)!=null?It:Date.now();i.reasoning.durationMs=Math.max(0,((qt=i.reasoning.completedAt)!=null?qt:Date.now())-m),i.streaming=!1,y(i)}let g=N(u);g&&A.byStep.delete(g)}else if(d==="tool_start"){let c=(at=Z(u,!0))!=null?at:`tool-${C()}`,i=nt(c),g=(Et=i.toolCall)!=null?Et:{id:c,status:"pending"};g.name=(W=u.toolName)!=null?W:g.name,g.status="running",u.args!==void 0&&(g.args=u.args),g.startedAt=(be=g.startedAt)!=null?be:ut((Q=u.startedAt)!=null?Q:u.timestamp),g.completedAt=void 0,g.durationMs=void 0,i.toolCall=g,i.streaming=!0,y(i)}else if(d==="tool_chunk"){let c=(Mt=(q=Z(u,!1))!=null?q:Z(u,!0))!=null?Mt:`tool-${C()}`,i=nt(c),g=(pt=i.toolCall)!=null?pt:{id:c,status:"running"};g.startedAt=(Ht=g.startedAt)!=null?Ht:ut((ht=u.startedAt)!=null?ht:u.timestamp);let m=(Ce=(xe=(Rt=u.text)!=null?Rt:u.delta)!=null?xe:u.message)!=null?Ce:"";m&&(g.chunks=(Bt=g.chunks)!=null?Bt:[],g.chunks.push(String(m))),g.status="running",i.toolCall=g,i.streaming=!0,y(i)}else if(d==="tool_complete"){let c=(Zt=(Te=Z(u,!1))!=null?Te:Z(u,!0))!=null?Zt:`tool-${C()}`,i=nt(c),g=(se=i.toolCall)!=null?se:{id:c,status:"running"};if(g.status="complete",u.result!==void 0&&(g.result=u.result),typeof u.duration=="number"&&(g.duration=u.duration),g.completedAt=ut((G=u.completedAt)!=null?G:u.timestamp),typeof u.duration=="number")g.durationMs=u.duration;else{let F=(zt=g.startedAt)!=null?zt:Date.now();g.durationMs=Math.max(0,((ie=g.completedAt)!=null?ie:Date.now())-F)}i.toolCall=g,i.streaming=!1,y(i);let m=P(u);m&&Y.byCall.delete(m)}else if(d==="step_chunk"){let c=S(),i=(le=(Ee=(ae=u.text)!=null?ae:u.delta)!=null?Ee:u.content)!=null?le:"";if(i&&(c.content+=i,y(c)),u.isComplete){let g=(ce=(de=u.result)==null?void 0:de.response)!=null?ce:c.content;g&&(c.content=g,c.streaming=!1,y(c))}}else if(d==="step_complete"){let c=(ue=u.result)==null?void 0:ue.response,i=S();c?(i.content=c,i.streaming=!1,y(i)):(i.streaming=!1,y(i))}else if(d==="flow_complete"){let c=(pe=u.result)==null?void 0:pe.response;if(c){let i=S();c!==i.content&&(i.content=c,y(i)),i.streaming=!1,y(i)}else{let i=I;if(i){let g=i;g.streaming=!1,y(g)}}e({type:"status",status:"idle"})}else d==="error"&&u.error&&e({type:"error",error:u.error instanceof Error?u.error:new Error(String(u.error))})}}}};var Be=class{constructor(n={},e){this.config=n;this.callbacks=e;this.status="idle";this.streaming=!1;this.abortController=null;this.sequenceCounter=Date.now();this.handleEvent=n=>{var e,s;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,(s=(e=this.callbacks).onError)==null||s.call(e,n.error))};var s;this.messages=[...(s=n.initialMessages)!=null?s:[]].map(o=>{var l;return{...o,sequence:(l=o.sequence)!=null?l:this.nextSequence()}}),this.messages=this.sortMessages(this.messages),this.client=new Le(n),this.messages.length&&this.callbacks.onMessagesChanged([...this.messages]),this.callbacks.onStatusChanged(this.status)}updateConfig(n){this.config={...this.config,...n},this.client=new Le(this.config)}getMessages(){return[...this.messages]}getStatus(){return this.status}isStreaming(){return this.streaming}async sendMessage(n){var a,L,C,M,y;let e=n.trim();if(!e)return;(a=this.abortController)==null||a.abort();let s={id:`user-${Date.now()}`,role:"user",content:e,createdAt:new Date().toISOString(),sequence:this.nextSequence()};this.appendMessage(s),this.setStreaming(!0);let o=new AbortController;this.abortController=o;let l=[...this.messages];try{await this.client.dispatch({messages:l,signal:o.signal},this.handleEvent)}catch(I){let h={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(h),this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,I instanceof Error?(C=(L=this.callbacks).onError)==null||C.call(L,I):(y=(M=this.callbacks).onError)==null||y.call(M,new Error(String(I)))}}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])}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 e=this.ensureSequence(n);this.messages=this.sortMessages([...this.messages,e]),this.callbacks.onMessagesChanged([...this.messages])}upsertMessage(n){let e=this.ensureSequence(n),s=this.messages.findIndex(o=>o.id===e.id);if(s===-1){this.appendMessage(e);return}this.messages=this.messages.map((o,l)=>l===s?{...o,...e}: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((e,s)=>{var C,M;let o=new Date(e.createdAt).getTime(),l=new Date(s.createdAt).getTime();if(!Number.isNaN(o)&&!Number.isNaN(l)&&o!==l)return o-l;let a=(C=e.sequence)!=null?C:0,L=(M=s.sequence)!=null?M:0;return a!==L?a-L:e.id.localeCompare(s.id)})}};var on=(t,n)=>{var s;let e=(s=n==null?void 0:n.theme)!=null?s:{};Object.entries(e).forEach(([o,l])=>{if(l==null||l==="")return;let a=o.replace(/[A-Z]/g,L=>`-${L.toLowerCase()}`);t.style.setProperty(`--cw-${a}`,String(l))})};var oo=Zn(require("lucide"),1),ft=(t,n=24,e="currentColor",s=2)=>{try{let o=t.split("-").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(""),l=oo[o];return l?ro(l,n,e,s):(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 ro(t,n,e,s){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",e),o.setAttribute("stroke-width",String(s)),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.setAttribute("aria-hidden","true"),t.forEach(l=>{if(Array.isArray(l)&&l.length>=2){let a=l[0],L=l[1];if(L){let C=document.createElementNS("http://www.w3.org/2000/svg",a);Object.entries(L).forEach(([M,y])=>{M!=="stroke"&&C.setAttribute(M,String(y))}),o.appendChild(C)}}}),o}var p=(t,n)=>{let e=document.createElement(t);return n&&(e.className=n),e};var yt={idle:"Online",connecting:"Connecting\u2026",connected:"Streaming\u2026",error:"Offline"};var he={"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 e=p("button");e.type="button",e.innerHTML=`
5
5
  <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>
6
6
  <img data-role="launcher-image" class="tvw-rounded-full tvw-object-cover" alt="" style="display:none" />
7
7
  <span class="tvw-flex tvw-flex-col tvw-items-start tvw-text-left">
@@ -9,6 +9,6 @@
9
9
  <span class="tvw-text-xs tvw-text-cw-muted" data-role="launcher-subtitle"></span>
10
10
  </span>
11
11
  <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>
12
- `,e.addEventListener("click",n);let i=d=>{var X,A,N,z,T,ct,M,y,Y,Q;let a=(X=d.launcher)!=null?X:{},S=e.querySelector("[data-role='launcher-title']");S&&(S.textContent=(A=a.title)!=null?A:"Chat Assistant");let x=e.querySelector("[data-role='launcher-subtitle']");x&&(x.textContent=(N=a.subtitle)!=null?N:"Get answers fast");let E=e.querySelector(".tvw-flex-col");E&&(a.textHidden?E.style.display="none":E.style.display="");let f=e.querySelector("[data-role='launcher-icon']");if(f)if(a.agentIconHidden)f.style.display="none";else{let ot=(z=a.agentIconSize)!=null?z:"40px";if(f.style.height=ot,f.style.width=ot,f.innerHTML="",a.agentIconName){let pt=parseFloat(ot)||24,Ct=ft(a.agentIconName,pt*.6,"#ffffff",2);Ct?(f.appendChild(Ct),f.style.display=""):(f.textContent=(T=a.agentIconText)!=null?T:"\u{1F4AC}",f.style.display="")}else a.iconUrl?f.style.display="none":(f.textContent=(ct=a.agentIconText)!=null?ct:"\u{1F4AC}",f.style.display="")}let k=e.querySelector("[data-role='launcher-image']");if(k){let ot=(M=a.agentIconSize)!=null?M:"40px";k.style.height=ot,k.style.width=ot,a.iconUrl&&!a.agentIconName&&!a.agentIconHidden?(k.src=a.iconUrl,k.style.display="block"):k.style.display="none"}let h=e.querySelector("[data-role='launcher-call-to-action-icon']");if(h){let ot=(y=a.callToActionIconSize)!=null?y:"32px";h.style.height=ot,h.style.width=ot,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 pt=0;if(a.callToActionIconPadding?(h.style.boxSizing="border-box",h.style.padding=a.callToActionIconPadding,pt=(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 Ct=parseFloat(ot)||24,C=Math.max(Ct-pt,8),U=ft(a.callToActionIconName,C,"currentColor",2);U?h.appendChild(U):h.textContent=(Y=a.callToActionIconText)!=null?Y:"\u2197"}else h.textContent=(Q=a.callToActionIconText)!=null?Q:"\u2197"}let O=a.position&&ve[a.position]?ve[a.position]:ve["bottom-right"],L="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";e.className=`${L} ${O}`},o=()=>{e.removeEventListener("click",n),e.remove()};return t&&i(t),{element:e,update:i,destroy:o}};var qn=t=>{var x,E,f,k,h;if(!((E=(x=t==null?void 0:t.launcher)==null?void 0:x.enabled)!=null?E:!0)){let O=u("div","tvw-relative tvw-w-full tvw-h-full"),L=u("div","tvw-relative tvw-w-full tvw-h-full tvw-min-h-[360px]");return O.appendChild(L),{wrapper:O,panel:L}}let e=(f=t==null?void 0:t.launcher)!=null?f:{},i=e.position&&ve[e.position]?ve[e.position]:ve["bottom-right"],o=u("div",`tvw-fixed ${i} tvw-z-50 tvw-transition`),d=u("div","tvw-relative tvw-min-h-[320px]"),a=(h=(k=t==null?void 0:t.launcher)==null?void 0:k.width)!=null?h:t==null?void 0:t.launcherWidth,S=a!=null?a:"min(400px, calc(100vw - 24px))";return d.style.width=S,d.style.maxWidth=S,o.appendChild(d),{wrapper:o,panel:d}},zn=(t,n=!0)=>{var Bt,Ce,Te,Wt,Se,Qt,ae,G,Pt,le,de,Me,ce,ue,pe,ge,g,R,q,Z,tt,r,p,c,H,s,l,m,B,w,K,rt,mt,at,$,$t,Ot,_t,Nt,te,Ut,Vt,vt,jt,me,Ve,ke,Ie,He,Re,Ne,Fe,De,qe,ze,Pe,$e,Oe,_e,Ue;let e=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"),i=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=(Bt=t==null?void 0:t.launcher)!=null?Bt:{},d=(Ce=o.headerIconSize)!=null?Ce:"48px",a=(Te=o.closeButtonSize)!=null?Te:"32px",S=(Wt=o.closeButtonPlacement)!=null?Wt:"inline",x=(Se=o.headerIconHidden)!=null?Se:!1,E=o.headerIconName,f=u("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-xl");if(f.style.height=d,f.style.width=d,!x)if(E){let W=parseFloat(d)||24,et=ft(E,W*.6,"#ffffff",2);et?f.replaceChildren(et):f.textContent=(ae=(Qt=t==null?void 0:t.launcher)==null?void 0:Qt.agentIconText)!=null?ae:"\u{1F4AC}"}else if((G=t==null?void 0:t.launcher)!=null&&G.iconUrl){let W=u("img");W.src=t.launcher.iconUrl,W.alt="",W.className="tvw-rounded-xl tvw-object-cover",W.style.height=d,W.style.width=d,f.replaceChildren(W)}else f.textContent=(le=(Pt=t==null?void 0:t.launcher)==null?void 0:Pt.agentIconText)!=null?le:"\u{1F4AC}";let k=u("div","tvw-flex tvw-flex-col"),h=u("span","tvw-text-base tvw-font-semibold");h.textContent=(Me=(de=t==null?void 0:t.launcher)==null?void 0:de.title)!=null?Me:"Chat Assistant";let O=u("span","tvw-text-xs tvw-text-cw-muted");O.textContent=(ue=(ce=t==null?void 0:t.launcher)==null?void 0:ce.subtitle)!=null?ue:"Here to help you get answers fast",k.append(h,O),x?i.append(k):i.append(f,k);let L=(pe=o.clearChat)!=null?pe:{},X=(ge=L.enabled)!=null?ge:!0,A=null,N=null;if(X){let W=(g=L.size)!=null?g:"32px",et=(R=L.iconName)!=null?R:"refresh-cw",wt=(q=L.iconColor)!=null?q:"",Xt=(Z=L.backgroundColor)!=null?Z:"",St=(tt=L.borderWidth)!=null?tt:"",ee=(r=L.borderColor)!=null?r:"",we=(p=L.borderRadius)!=null?p:"",ne=(c=L.paddingX)!=null?c:"",Le=(H=L.paddingY)!=null?H:"",oe=(s=L.tooltipText)!=null?s:"Clear chat",Ge=(l=L.showTooltip)!=null?l:!0;N=u("div","tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper"),A=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"),A.style.height=W,A.style.width=W,A.type="button",A.setAttribute("aria-label",oe);let je=ft(et,"20px",wt||"",2);if(je&&A.appendChild(je),wt&&(A.style.color=wt,A.classList.remove("tvw-text-cw-muted")),Xt&&(A.style.backgroundColor=Xt,A.classList.remove("hover:tvw-bg-gray-100")),St||ee){let dt=St||"0px",se=ee||"transparent";A.style.border=`${dt} solid ${se}`,A.classList.remove("tvw-border-none")}if(we&&(A.style.borderRadius=we,A.classList.remove("tvw-rounded-full")),ne?(A.style.paddingLeft=ne,A.style.paddingRight=ne):(A.style.paddingLeft="",A.style.paddingRight=""),Le?(A.style.paddingTop=Le,A.style.paddingBottom=Le):(A.style.paddingTop="",A.style.paddingBottom=""),N.appendChild(A),Ge&&oe&&A&&N){let dt=null,se=()=>{if(dt||!A)return;dt=u("div","tvw-clear-chat-tooltip"),dt.textContent=oe;let Xe=u("div");Xe.className="tvw-clear-chat-tooltip-arrow",dt.appendChild(Xe);let Be=A.getBoundingClientRect();dt.style.position="fixed",dt.style.left=`${Be.left+Be.width/2}px`,dt.style.top=`${Be.top-8}px`,dt.style.transform="translate(-50%, -100%)",document.body.appendChild(dt)},he=()=>{dt&&dt.parentNode&&(dt.parentNode.removeChild(dt),dt=null)};N.addEventListener("mouseenter",se),N.addEventListener("mouseleave",he),A.addEventListener("focus",se),A.addEventListener("blur",he),N._cleanupTooltip=()=>{he(),N&&(N.removeEventListener("mouseenter",se),N.removeEventListener("mouseleave",he)),A&&(A.removeEventListener("focus",se),A.removeEventListener("blur",he))}}i.appendChild(N)}let z=u("div",S==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50":X?"":"tvw-ml-auto"),T=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");T.style.height=a,T.style.width=a,T.type="button";let ct=(m=o.closeButtonTooltipText)!=null?m:"Close chat",M=(B=o.closeButtonShowTooltip)!=null?B:!0;T.setAttribute("aria-label",ct),T.style.display=n?"":"none";let y=(w=o.closeButtonIconName)!=null?w:"x",Y=(K=o.closeButtonIconText)!=null?K:"\xD7",Q=ft(y,"20px",o.closeButtonColor||"",2);if(Q?T.appendChild(Q):T.textContent=Y,o.closeButtonColor?(T.style.color=o.closeButtonColor,T.classList.remove("tvw-text-cw-muted")):(T.style.color="",T.classList.add("tvw-text-cw-muted")),o.closeButtonBackgroundColor?(T.style.backgroundColor=o.closeButtonBackgroundColor,T.classList.remove("hover:tvw-bg-gray-100")):(T.style.backgroundColor="",T.classList.add("hover:tvw-bg-gray-100")),o.closeButtonBorderWidth||o.closeButtonBorderColor){let W=o.closeButtonBorderWidth||"0px",et=o.closeButtonBorderColor||"transparent";T.style.border=`${W} solid ${et}`,T.classList.remove("tvw-border-none")}else T.style.border="",T.classList.add("tvw-border-none");if(o.closeButtonBorderRadius?(T.style.borderRadius=o.closeButtonBorderRadius,T.classList.remove("tvw-rounded-full")):(T.style.borderRadius="",T.classList.add("tvw-rounded-full")),o.closeButtonPaddingX?(T.style.paddingLeft=o.closeButtonPaddingX,T.style.paddingRight=o.closeButtonPaddingX):(T.style.paddingLeft="",T.style.paddingRight=""),o.closeButtonPaddingY?(T.style.paddingTop=o.closeButtonPaddingY,T.style.paddingBottom=o.closeButtonPaddingY):(T.style.paddingTop="",T.style.paddingBottom=""),z.appendChild(T),M&&ct){let W=null,et=()=>{if(W)return;W=u("div","tvw-clear-chat-tooltip"),W.textContent=ct;let Xt=u("div");Xt.className="tvw-clear-chat-tooltip-arrow",W.appendChild(Xt);let St=T.getBoundingClientRect();W.style.position="fixed",W.style.left=`${St.left+St.width/2}px`,W.style.top=`${St.top-8}px`,W.style.transform="translate(-50%, -100%)",document.body.appendChild(W)},wt=()=>{W&&W.parentNode&&(W.parentNode.removeChild(W),W=null)};z.addEventListener("mouseenter",et),z.addEventListener("mouseleave",wt),T.addEventListener("focus",et),T.addEventListener("blur",wt),z._cleanupTooltip=()=>{wt(),z.removeEventListener("mouseenter",et),z.removeEventListener("mouseleave",wt),T.removeEventListener("focus",et),T.removeEventListener("blur",wt)}}S==="top-right"?(e.style.position="relative",e.appendChild(z)):i.appendChild(z);let ot=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"),pt=u("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),Ct=u("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");Ct.textContent=(mt=(rt=t==null?void 0:t.copy)==null?void 0:rt.welcomeTitle)!=null?mt:"Hello \u{1F44B}";let C=u("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");C.textContent=($=(at=t==null?void 0:t.copy)==null?void 0:at.welcomeSubtitle)!=null?$:"Ask anything about your account or products.",pt.append(Ct,C);let U=u("div","tvw-flex tvw-flex-col tvw-gap-3");ot.append(pt,U);let v=u("div","tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),ut=u("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),Et=(($t=t==null?void 0:t.voiceRecognition)==null?void 0:$t.enabled)===!0,Yt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),bt=u("form",`tvw-flex tvw-items-end ${Et&&Yt?"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`);bt.style.outline="none";let F=u("textarea");F.placeholder=(_t=(Ot=t==null?void 0:t.copy)==null?void 0:Ot.inputPlaceholder)!=null?_t:"Type your message\u2026",F.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",F.rows=1;let Kt=(te=(Nt=t==null?void 0:t.theme)==null?void 0:Nt.inputFontFamily)!=null?te:"sans-serif",fe=(Vt=(Ut=t==null?void 0:t.theme)==null?void 0:Ut.inputFontWeight)!=null?Vt:"400",Dt=W=>{switch(W){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'}};F.style.fontFamily=Dt(Kt),F.style.fontWeight=fe,F.style.border="none",F.style.outline="none",F.style.borderWidth="0",F.style.borderStyle="none",F.style.borderColor="transparent",F.addEventListener("focus",()=>{F.style.border="none",F.style.outline="none",F.style.borderWidth="0",F.style.borderStyle="none",F.style.borderColor="transparent",F.style.boxShadow="none"}),F.addEventListener("blur",()=>{F.style.border="none",F.style.outline="none"});let j=(vt=t==null?void 0:t.sendButton)!=null?vt:{},Jt=(jt=j.useIcon)!=null?jt:!1,Zt=(me=j.iconText)!=null?me:"\u2191",ye=j.iconName,be=(Ve=j.tooltipText)!=null?Ve:"Send message",Ee=(ke=j.showTooltip)!=null?ke:!1,Ht=(Ie=j.size)!=null?Ie:"40px",qt=j.backgroundColor,gt=j.textColor,Rt=u("div","tvw-send-button-wrapper"),I=u("button",Jt?"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(I.type="submit",Jt){if(I.style.width=Ht,I.style.height=Ht,I.style.minWidth=Ht,I.style.minHeight=Ht,I.style.fontSize="18px",I.style.lineHeight="1",I.innerHTML="",ye){let W=parseFloat(Ht)||24,et=gt&&typeof gt=="string"&&gt.trim()?gt.trim():"currentColor",wt=ft(ye,W,et,2);wt?(I.appendChild(wt),I.style.color=et):(I.textContent=Zt,gt?I.style.color=gt:I.classList.add("tvw-text-white"))}else I.textContent=Zt,gt?I.style.color=gt:I.classList.add("tvw-text-white");qt?I.style.backgroundColor=qt:I.classList.add("tvw-bg-cw-primary")}else I.textContent=(Re=(He=t==null?void 0:t.copy)==null?void 0:He.sendButtonLabel)!=null?Re:"Send",gt?I.style.color=gt:I.classList.add("tvw-text-white");if(j.borderWidth&&(I.style.borderWidth=j.borderWidth,I.style.borderStyle="solid"),j.borderColor&&(I.style.borderColor=j.borderColor),j.paddingX?(I.style.paddingLeft=j.paddingX,I.style.paddingRight=j.paddingX):(I.style.paddingLeft="",I.style.paddingRight=""),j.paddingY?(I.style.paddingTop=j.paddingY,I.style.paddingBottom=j.paddingY):(I.style.paddingTop="",I.style.paddingBottom=""),Ee&&be){let W=u("div","tvw-send-button-tooltip");W.textContent=be,Rt.appendChild(W)}Rt.appendChild(I);let V=(Ne=t==null?void 0:t.voiceRecognition)!=null?Ne:{},ie=V.enabled===!0,D=null,Mt=null,xe=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(ie&&xe){Mt=u("div","tvw-send-button-wrapper"),D=u("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),D.type="button",D.setAttribute("aria-label","Start voice recognition");let W=(Fe=V.iconName)!=null?Fe:"mic",et=(De=V.iconSize)!=null?De:Ht,wt=parseFloat(et)||24,Xt=(qe=V.backgroundColor)!=null?qe:qt,St=(ze=V.iconColor)!=null?ze:gt;D.style.width=et,D.style.height=et,D.style.minWidth=et,D.style.minHeight=et,D.style.fontSize="18px",D.style.lineHeight="1";let ee=St||"currentColor",we=ft(W,wt,ee,1.5);we?(D.appendChild(we),D.style.color=ee):(D.textContent="\u{1F3A4}",D.style.color=ee),Xt?D.style.backgroundColor=Xt:D.classList.add("tvw-bg-cw-primary"),St?D.style.color=St:!St&&!gt&&D.classList.add("tvw-text-white"),V.borderWidth&&(D.style.borderWidth=V.borderWidth,D.style.borderStyle="solid"),V.borderColor&&(D.style.borderColor=V.borderColor),V.paddingX&&(D.style.paddingLeft=V.paddingX,D.style.paddingRight=V.paddingX),V.paddingY&&(D.style.paddingTop=V.paddingY,D.style.paddingBottom=V.paddingY),Mt.appendChild(D);let ne=(Pe=V.tooltipText)!=null?Pe:"Start voice recognition";if((($e=V.showTooltip)!=null?$e:!1)&&ne){let oe=u("div","tvw-send-button-tooltip");oe.textContent=ne,Mt.appendChild(oe)}}bt.addEventListener("click",W=>{W.target!==I&&W.target!==Rt&&W.target!==D&&W.target!==Mt&&F.focus()}),bt.append(F),Mt&&bt.append(Mt),bt.append(Rt);let it=u("div","tvw-mt-2 tvw-text-right tvw-text-xs tvw-text-cw-muted"),Tt=(Oe=t==null?void 0:t.statusIndicator)!=null?Oe:{},zt=(_e=Tt.visible)!=null?_e:!0;return it.style.display=zt?"":"none",it.textContent=(Ue=Tt.idleText)!=null?Ue:"Online",v.append(ut,bt,it),e.append(i,ot,v),{container:e,body:ot,messagesWrapper:U,suggestions:ut,textarea:F,sendButton:I,sendButtonWrapper:Rt,micButton:D,micButtonWrapper:Mt,composerForm:bt,statusText:it,introTitle:Ct,introSubtitle:C,closeButton:T,closeButtonWrapper:z,clearChatButton:A,clearChatButtonWrapper:N,iconHolder:f}};var rn=(t,n)=>{let e=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm"];t.role==="user"?e.push("tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-5","tvw-py-3"):e.push("tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3");let i=u("div",e.join(" "));return i.innerHTML=n({text:t.content,message:t,streaming:!!t.streaming}),i};var an=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)}},ro=t=>{var a,S;let n=(a=t.completedAt)!=null?a:Date.now(),e=(S=t.startedAt)!=null?S:n,o=(t.durationMs!==void 0?t.durationMs:Math.max(0,n-e))/1e3;return o<.1?"Thought for <0.1 seconds":`Thought for ${o>=10?Math.round(o).toString():o.toFixed(1).replace(/\.0$/,"")} seconds`},Pn=t=>t.status==="complete"?ro(t):t.status==="pending"?"Waiting":"",io=t=>{var o,d,a;let e=(typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,((o=t.completedAt)!=null?o:Date.now())-((a=(d=t.startedAt)!=null?d:t.completedAt)!=null?a:Date.now())))/1e3;return e<.1?"Used tool for <0.1 seconds":`Used tool for ${e>=10?Math.round(e).toString():e.toFixed(1).replace(/\.0$/,"")} seconds`};var $n=t=>t.status==="complete"?io(t):"Using tool...";var ln=new Set,dn=t=>{let n=t.reasoning,e=u("div",["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 e;let i=ln.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",i?"true":"false");let d=u("div","tvw-flex tvw-flex-col tvw-text-left"),a=u("span","tvw-text-xs tvw-font-semibold tvw-text-cw-primary");a.textContent="Thinking...",d.appendChild(a);let S=u("span","tvw-text-xs tvw-text-cw-primary");S.textContent=Pn(n),d.appendChild(S),n.status==="complete"?a.style.display="none":a.style.display="";let x=u("span","tvw-text-xs tvw-text-cw-primary");x.textContent=i?"Hide":"Show",o.append(d,x);let E=u("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-px-4 tvw-py-3");E.style.display=i?"":"none";let f=n.chunks.join(""),k=u("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");k.textContent=f||(n.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),E.appendChild(k);let h=()=>{o.setAttribute("aria-expanded",i?"true":"false"),x.textContent=i?"Hide":"Show",E.style.display=i?"":"none"},O=()=>{i=!i,i?ln.add(t.id):ln.delete(t.id),h()};return o.addEventListener("pointerdown",L=>{L.preventDefault(),O()}),o.addEventListener("keydown",L=>{(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),O())}),h(),e.append(o,E),e};var cn=new Set,un=t=>{let n=t.toolCall,e=u("div",["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 e;let i=cn.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",i?"true":"false");let d=u("div","tvw-flex tvw-flex-col tvw-text-left"),a=u("span","tvw-text-xs tvw-text-cw-primary");if(a.textContent=$n(n),d.appendChild(a),n.name){let h=u("span","tvw-text-[11px] tvw-text-cw-muted");h.textContent=n.name,d.appendChild(h)}let S=u("span","tvw-text-xs tvw-text-cw-primary");S.textContent=i?"Hide":"Show";let x=u("div","tvw-flex tvw-items-center tvw-gap-2");x.append(S),o.append(d,x);let E=u("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(E.style.display=i?"":"none",n.args!==void 0){let h=u("div","tvw-space-y-1"),O=u("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");O.textContent="Arguments";let L=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-font-xxs tvw-text-cw-primary");L.textContent=an(n.args),h.append(O,L),E.appendChild(h)}if(n.chunks&&n.chunks.length){let h=u("div","tvw-space-y-1"),O=u("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");O.textContent="Activity";let L=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-font-xxs tvw-text-cw-primary");L.textContent=n.chunks.join(`
13
- `),h.append(O,L),E.appendChild(h)}if(n.status==="complete"&&n.result!==void 0){let h=u("div","tvw-space-y-1"),O=u("div","tvw-font-xxs tvw-text-sm tvw-text-cw-muted");O.textContent="Result";let L=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-font-xxs tvw-text-cw-primary");L.textContent=an(n.result),h.append(O,L),E.appendChild(h)}if(n.status==="complete"&&typeof n.duration=="number"){let h=u("div","tvw-font-xxs tvw-text-cw-muted");h.textContent=`Duration: ${n.duration}ms`,E.appendChild(h)}let f=()=>{o.setAttribute("aria-expanded",i?"true":"false"),S.textContent=i?"Hide":"Show",E.style.display=i?"":"none"},k=()=>{i=!i,i?cn.add(t.id):cn.delete(t.id),f()};return o.addEventListener("pointerdown",h=>{h.preventDefault(),k()}),o.addEventListener("keydown",h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),k())}),f(),e.append(o,E),e};var On=t=>{let n=[];return{buttons:n,render:(i,o,d,a)=>{if(t.innerHTML="",n.length=0,!i||!i.length||(a!=null?a:o?o.getMessages():[]).some(k=>k.role==="user"))return;let E=document.createDocumentFragment(),f=o?o.isStreaming():!1;i.forEach(k=>{let h=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");h.type="button",h.textContent=k,h.disabled=f,h.addEventListener("click",()=>{!o||o.isStreaming()||(d.value="",o.sendMessage(k))}),E.appendChild(h),n.push(h)}),t.appendChild(E)}}};var _n={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"}},pn=(t,n,e,i)=>{let o=t.querySelectorAll("[data-tv-form]");o.length&&o.forEach(d=>{var L,X,A;if(d.dataset.enhanced==="true")return;let a=(L=d.dataset.tvForm)!=null?L:"init";d.dataset.enhanced="true";let S=(X=_n[a])!=null?X:_n.init;d.classList.add("tvw-form-card","tvw-space-y-4");let x=u("div","tvw-space-y-1"),E=u("h3","tvw-text-base tvw-font-semibold tvw-text-cw-primary");if(E.textContent=S.title,x.appendChild(E),S.description){let N=u("p","tvw-text-sm tvw-text-cw-muted");N.textContent=S.description,x.appendChild(N)}let f=document.createElement("form");f.className="tvw-form-grid tvw-space-y-3",S.fields.forEach(N=>{var y,Y;let z=u("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");z.htmlFor=`${n.id}-${a}-${N.name}`;let T=u("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");T.textContent=N.label,z.appendChild(T);let ct=(y=N.type)!=null?y:"text",M;ct==="textarea"?(M=document.createElement("textarea"),M.rows=3):(M=document.createElement("input"),M.type=ct),M.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",M.id=`${n.id}-${a}-${N.name}`,M.name=N.name,M.placeholder=(Y=N.placeholder)!=null?Y:"",N.required&&(M.required=!0),z.appendChild(M),f.appendChild(z)});let k=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]"),O=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");O.type="submit",O.textContent=(A=S.submitLabel)!=null?A:"Submit",k.appendChild(h),k.appendChild(O),f.appendChild(k),d.replaceChildren(x,f),f.addEventListener("submit",async N=>{var M,y;N.preventDefault();let z=(M=e.formEndpoint)!=null?M:"/form",T=new FormData(f),ct={};T.forEach((Y,Q)=>{ct[Q]=Y}),ct.type=a,O.disabled=!0,h.textContent="Submitting\u2026";try{let Y=await fetch(z,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ct)});if(!Y.ok)throw new Error(`Form submission failed (${Y.status})`);let Q=await Y.json();h.textContent=(y=Q.message)!=null?y:"Thanks! We'll be in touch soon.",Q.success&&Q.nextPrompt&&await i.sendMessage(String(Q.nextPrompt))}catch(Y){h.textContent=Y instanceof Error?Y.message:"Something went wrong. Please try again."}finally{O.disabled=!1}})})};var gn=class{constructor(){this.plugins=new Map}register(n){var e;this.plugins.has(n.id)&&console.warn(`Plugin "${n.id}" is already registered. Overwriting.`),this.plugins.set(n.id,n),(e=n.onRegister)==null||e.call(n)}unregister(n){var i;let e=this.plugins.get(n);e&&((i=e.onUnregister)==null||i.call(e),this.plugins.delete(n))}getAll(){return Array.from(this.plugins.values()).sort((n,e)=>{var i,o;return((i=e.priority)!=null?i:0)-((o=n.priority)!=null?o:0)})}getForInstance(n){let e=this.getAll();if(!n||n.length===0)return e;let i=new Set(n.map(d=>d.id));return[...e.filter(d=>!i.has(d.id)),...n].sort((d,a)=>{var S,x;return((S=a.priority)!=null?S:0)-((x=d.priority)!=null?x:0)})}clear(){this.plugins.forEach(n=>{var e;return(e=n.onUnregister)==null?void 0:e.call(n)}),this.plugins.clear()}},Ye=new gn;var It={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?"],debug:!1};function Ze(t){var n,e,i;return t?{...It,...t,theme:{...It.theme,...t.theme},launcher:{...It.launcher,...t.launcher,clearChat:{...(n=It.launcher)==null?void 0:n.clearChat,...(e=t.launcher)==null?void 0:e.clearChat}},copy:{...It.copy,...t.copy},sendButton:{...It.sendButton,...t.sendButton},statusIndicator:{...It.statusIndicator,...t.statusIndicator},voiceRecognition:{...It.voiceRecognition,...t.voiceRecognition},features:{...It.features,...t.features},suggestionChips:(i=t.suggestionChips)!=null?i:It.suggestionChips}:It}var Un=t=>t!=null&&t.postprocessMessage?n=>t.postprocessMessage({text:n.text,message:n.message,streaming:n.streaming}):({text:n})=>Je(n),Qe=(t,n)=>{var ce,ue,pe,ge,g,R,q,Z,tt;(!t.id||t.id!=="vanilla-agent-root")&&(t.id="vanilla-agent-root");let e=Ze(n);on(t,e);let i=Ye.getForInstance(e.plugins),o=(ue=(ce=e.launcher)==null?void 0:ce.enabled)!=null?ue:!0,d=(ge=(pe=e.launcher)==null?void 0:pe.autoExpand)!=null?ge:!1,a=d,S=o,x=o?d:!0,E=Un(e),f=(R=(g=e.features)==null?void 0:g.showReasoning)!=null?R:!0,k=(Z=(q=e.features)==null?void 0:q.showToolCalls)!=null?Z:!0,h=(tt=e.statusIndicator)!=null?tt:{},O=r=>{var p,c,H,s;return r==="idle"?(p=h.idleText)!=null?p:yt.idle:r==="connecting"?(c=h.connectingText)!=null?c:yt.connecting:r==="connected"?(H=h.connectedText)!=null?H:yt.connected:r==="error"?(s=h.errorText)!=null?s:yt.error:yt[r]},{wrapper:L,panel:X}=qn(e),A=zn(e,o),{container:N,body:z,messagesWrapper:T,suggestions:ct,textarea:M,sendButton:y,sendButtonWrapper:Y,composerForm:Q,statusText:ot,introTitle:pt,introSubtitle:Ct,closeButton:C,iconHolder:U}=A,v=A.micButton,ut=A.micButtonWrapper;X.appendChild(N),t.appendChild(L);let Et=[],Yt=On(ct),Ft=null,P,bt=!1,F=!0,Kt=0,fe=0,Dt=null,j=!1,Jt=0,Zt=!1,ye=125,be=2e3,Ee=5,Ht=50,qt=(r=!1)=>{if(!F)return;let p=Date.now();j&&p<Jt&&!r||(j&&p>=Jt&&(j=!1),!(!r&&!bt)&&(p-fe<ye||(fe=p,Dt&&cancelAnimationFrame(Dt),Dt=requestAnimationFrame(()=>{j||!F||(Zt=!0,z.scrollTop=z.scrollHeight,Kt=z.scrollTop,requestAnimationFrame(()=>{Zt=!1}),Dt=null)}))))},gt=()=>{let r=document.createElement("div");r.className="tvw-flex tvw-items-center tvw-space-x-1 tvw-h-5";let p=document.createElement("div");p.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",p.style.animationDelay="0ms";let c=document.createElement("div");c.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",c.style.animationDelay="250ms";let H=document.createElement("div");H.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",H.style.animationDelay="500ms";let s=document.createElement("span");return s.className="tvw-sr-only",s.textContent="Loading",r.appendChild(p),r.appendChild(c),r.appendChild(H),r.appendChild(s),r},Rt=(r,p,c)=>{r.innerHTML="";let H=document.createDocumentFragment();if(p.forEach(s=>{let l=null,m=i.find(w=>!!(s.variant==="reasoning"&&w.renderReasoning||s.variant==="tool"&&w.renderToolCall||!s.variant&&w.renderMessage));if(m)if(s.variant==="reasoning"&&s.reasoning&&m.renderReasoning){if(!f)return;l=m.renderReasoning({message:s,defaultRenderer:()=>dn(s),config:e})}else if(s.variant==="tool"&&s.toolCall&&m.renderToolCall){if(!k)return;l=m.renderToolCall({message:s,defaultRenderer:()=>un(s),config:e})}else m.renderMessage&&(l=m.renderMessage({message:s,defaultRenderer:()=>{let w=rn(s,c);return s.role!=="user"&&pn(w,s,e,P),w},config:e}));if(!l)if(s.variant==="reasoning"&&s.reasoning){if(!f)return;l=dn(s)}else if(s.variant==="tool"&&s.toolCall){if(!k)return;l=un(s)}else l=rn(s,c),s.role!=="user"&&pn(l,s,e,P);let B=document.createElement("div");B.className="tvw-flex",s.role==="user"&&B.classList.add("tvw-justify-end"),B.appendChild(l),H.appendChild(B)}),bt&&p.some(s=>s.role==="user")){let s=gt(),l=document.createElement("div");l.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(" "),l.appendChild(s);let m=document.createElement("div");m.className="tvw-flex",m.appendChild(l),H.appendChild(m)}r.appendChild(H),r.scrollTop=r.scrollHeight},I=()=>{o&&(x?(L.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),X.classList.remove("tvw-scale-95","tvw-opacity-0"),X.classList.add("tvw-scale-100","tvw-opacity-100"),G&&(G.element.style.display="none")):(L.classList.add("tvw-pointer-events-none","tvw-opacity-0"),X.classList.remove("tvw-scale-100","tvw-opacity-100"),X.classList.add("tvw-scale-95","tvw-opacity-0"),G&&(G.element.style.display="")))},V=r=>{o&&x!==r&&(x=r,I(),x&&(Pt(),qt(!0)))},ie=r=>{M.disabled=r,y.disabled=r,v&&(v.disabled=r),Yt.buttons.forEach(p=>{p.disabled=r})},D=()=>{var s,l,m,B,w,K,rt,mt,at,$,$t,Ot,_t,Nt;pt.textContent=(l=(s=e.copy)==null?void 0:s.welcomeTitle)!=null?l:"Hello \u{1F44B}",Ct.textContent=(B=(m=e.copy)==null?void 0:m.welcomeSubtitle)!=null?B:"Ask anything about your account or products.",M.placeholder=(K=(w=e.copy)==null?void 0:w.inputPlaceholder)!=null?K:"How can I help...",((mt=(rt=e.sendButton)==null?void 0:rt.useIcon)!=null?mt:!1)||(y.textContent=($=(at=e.copy)==null?void 0:at.sendButtonLabel)!=null?$:"Send");let p=(Ot=($t=e.theme)==null?void 0:$t.inputFontFamily)!=null?Ot:"sans-serif",c=(Nt=(_t=e.theme)==null?void 0:_t.inputFontWeight)!=null?Nt:"400",H=te=>{switch(te){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'}};M.style.fontFamily=H(p),M.style.fontWeight=c};P=new We(e,{onMessagesChanged(r){Rt(T,r,E),P&&(r.some(c=>c.role==="user")?Yt.render([],P,M,r):Yt.render(e.suggestionChips,P,M,r)),qt(!bt)},onStatusChanged(r){var H;let p=(H=e.statusIndicator)!=null?H:{},c=s=>{var l,m,B,w;return s==="idle"?(l=p.idleText)!=null?l:yt.idle:s==="connecting"?(m=p.connectingText)!=null?m:yt.connecting:s==="connected"?(B=p.connectedText)!=null?B:yt.connected:s==="error"?(w=p.errorText)!=null?w:yt.error:yt[s]};ot.textContent=c(r)},onStreamingChanged(r){bt=r,ie(r),P&&Rt(T,P.getMessages(),E),r||qt(!0)}});let Mt=r=>{r.preventDefault();let p=M.value.trim();p&&(M.value="",P.sendMessage(p))},xe=r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),y.click())},it=null,Tt=!1,zt=null,Bt=null,Ce=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,Te=()=>{var s,l,m,B;if(Tt||P.isStreaming())return;let r=Ce();if(!r)return;it=new r;let c=(l=((s=e.voiceRecognition)!=null?s:{}).pauseDuration)!=null?l:2e3;it.continuous=!0,it.interimResults=!0,it.lang="en-US";let H=M.value;it.onresult=w=>{let K="",rt="";for(let at=0;at<w.results.length;at++){let $=w.results[at],$t=$[0].transcript;$.isFinal?K+=$t+" ":rt=$t}let mt=H+K+rt;M.value=mt,zt&&clearTimeout(zt),(K||rt)&&(zt=window.setTimeout(()=>{let at=M.value.trim();at&&it&&Tt&&(Wt(),M.value="",P.sendMessage(at))},c))},it.onerror=w=>{w.error!=="no-speech"&&Wt()},it.onend=()=>{if(Tt){let w=M.value.trim();w&&w!==H.trim()&&(M.value="",P.sendMessage(w)),Wt()}};try{if(it.start(),Tt=!0,v){Bt={backgroundColor:v.style.backgroundColor,color:v.style.color,borderColor:v.style.borderColor};let w=(m=e.voiceRecognition)!=null?m:{},K=(B=w.recordingBackgroundColor)!=null?B:"#ef4444",rt=w.recordingIconColor,mt=w.recordingBorderColor;if(v.classList.add("tvw-voice-recording"),v.style.backgroundColor=K,rt){v.style.color=rt;let at=v.querySelector("svg");at&&at.setAttribute("stroke",rt)}mt&&(v.style.borderColor=mt),v.setAttribute("aria-label","Stop voice recognition")}}catch{Wt()}},Wt=()=>{if(Tt){if(Tt=!1,zt&&(clearTimeout(zt),zt=null),it){try{it.stop()}catch{}it=null}if(v){if(v.classList.remove("tvw-voice-recording"),Bt){v.style.backgroundColor=Bt.backgroundColor,v.style.color=Bt.color,v.style.borderColor=Bt.borderColor;let r=v.querySelector("svg");r&&r.setAttribute("stroke",Bt.color||"currentColor"),Bt=null}v.setAttribute("aria-label","Start voice recognition")}}},Se=(r,p)=>{var Ot,_t,Nt,te,Ut,Vt,vt;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let H=u("div","tvw-send-button-wrapper"),s=u("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");s.type="button",s.setAttribute("aria-label","Start voice recognition");let l=(Ot=r==null?void 0:r.iconName)!=null?Ot:"mic",m=(_t=p==null?void 0:p.size)!=null?_t:"40px",B=(Nt=r==null?void 0:r.iconSize)!=null?Nt:m,w=parseFloat(B)||24,K=(te=r==null?void 0:r.backgroundColor)!=null?te:p==null?void 0:p.backgroundColor,rt=(Ut=r==null?void 0:r.iconColor)!=null?Ut:p==null?void 0:p.textColor;s.style.width=B,s.style.height=B,s.style.minWidth=B,s.style.minHeight=B,s.style.fontSize="18px",s.style.lineHeight="1";let mt=rt||"currentColor",at=ft(l,w,mt,1.5);at?(s.appendChild(at),s.style.color=mt):(s.textContent="\u{1F3A4}",s.style.color=mt),K?s.style.backgroundColor=K:s.classList.add("tvw-bg-cw-primary"),rt?s.style.color=rt:!rt&&!(p!=null&&p.textColor)&&s.classList.add("tvw-text-white"),r!=null&&r.borderWidth&&(s.style.borderWidth=r.borderWidth,s.style.borderStyle="solid"),r!=null&&r.borderColor&&(s.style.borderColor=r.borderColor),r!=null&&r.paddingX&&(s.style.paddingLeft=r.paddingX,s.style.paddingRight=r.paddingX),r!=null&&r.paddingY&&(s.style.paddingTop=r.paddingY,s.style.paddingBottom=r.paddingY),H.appendChild(s);let $=(Vt=r==null?void 0:r.tooltipText)!=null?Vt:"Start voice recognition";if(((vt=r==null?void 0:r.showTooltip)!=null?vt:!1)&&$){let jt=u("div","tvw-send-button-tooltip");jt.textContent=$,H.appendChild(jt)}return{micButton:s,micButtonWrapper:H}},Qt=()=>{if(Tt){let r=M.value.trim();Wt(),r&&(M.value="",P.sendMessage(r))}else Te()};v&&(v.addEventListener("click",Qt),Et.push(()=>{Wt(),v&&v.removeEventListener("click",Qt)}));let ae=()=>{V(!x)},G=o?sn(e,ae):null;G&&t.appendChild(G.element),I(),Yt.render(e.suggestionChips,P,M),D(),ie(P.isStreaming()),qt(!0);let Pt=()=>{var m,B;if(!o){X.style.height="",X.style.width="";return}let r=(B=(m=e==null?void 0:e.launcher)==null?void 0:m.width)!=null?B:e==null?void 0:e.launcherWidth,p=r!=null?r:"min(400px, calc(100vw - 24px))";X.style.width=p,X.style.maxWidth=p;let c=window.innerHeight,s=Math.max(200,c-64),l=Math.min(640,s);X.style.height=`${l}px`};Pt(),window.addEventListener("resize",Pt),Et.push(()=>window.removeEventListener("resize",Pt)),Kt=z.scrollTop;let le=()=>{let r=z.scrollTop,p=z.scrollHeight,c=z.clientHeight,H=p-r-c,s=Math.abs(r-Kt);if(Kt=r,!Zt&&!(s<=Ee)){if(!F&&H<Ht){j=!1,F=!0;return}F&&H>Ht&&(j=!0,Jt=Date.now()+be,F=!1)}};z.addEventListener("scroll",le,{passive:!0}),Et.push(()=>z.removeEventListener("scroll",le)),Et.push(()=>{Dt&&cancelAnimationFrame(Dt)});let de=()=>{C&&(Ft&&(C.removeEventListener("click",Ft),Ft=null),o?(C.style.display="",Ft=()=>{x=!1,I()},C.addEventListener("click",Ft)):C.style.display="none")};return de(),(()=>{let{clearChatButton:r}=A;r&&r.addEventListener("click",()=>{P.clearMessages();let p=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});window.dispatchEvent(p)})})(),Q.addEventListener("submit",Mt),M.addEventListener("keydown",xe),Et.push(()=>{Q.removeEventListener("submit",Mt),M.removeEventListener("keydown",xe)}),Et.push(()=>{P.cancel()}),G&&Et.push(()=>{G==null||G.destroy()}),{update(r){var ke,Ie,He,Re,Ne,Fe,De,qe,ze,Pe,$e,Oe,_e,Ue,W,et,wt,Xt,St,ee,we,ne,Le,oe,Ge,je,dt,se,he,Xe,Be,hn,vn,fn,yn,bn,xn,Cn,Tn,Sn,Ln,An,En,Mn,Bn,Wn,kn,In,Hn;e={...e,...r},on(t,e);let p=Ye.getForInstance(e.plugins);i.length=0,i.push(...p),o=(Ie=(ke=e.launcher)==null?void 0:ke.enabled)!=null?Ie:!0,d=(Re=(He=e.launcher)==null?void 0:He.autoExpand)!=null?Re:!1,f=(Fe=(Ne=e.features)==null?void 0:Ne.showReasoning)!=null?Fe:!0,k=(qe=(De=e.features)==null?void 0:De.showToolCalls)!=null?qe:!0,((ze=e.launcher)==null?void 0:ze.enabled)===!1&&G&&(G.destroy(),G=null),((Pe=e.launcher)==null?void 0:Pe.enabled)!==!1&&!G&&(G=sn(e,ae),t.appendChild(G.element)),G&&G.update(e),o!==S?o?V(d):(x=!0,I()):d!==a&&V(d),a=d,S=o,Pt(),de();let s=($e=e.launcher)!=null?$e:{},l=(Oe=s.headerIconHidden)!=null?Oe:!1,m=s.headerIconName,B=(_e=s.headerIconSize)!=null?_e:"48px";if(U){let b=N.querySelector(".tvw-border-b-cw-divider"),st=b==null?void 0:b.querySelector(".tvw-flex-col");if(l)U.style.display="none",b&&st&&!b.contains(st)&&b.insertBefore(st,b.firstChild);else{if(U.style.display="",U.style.height=B,U.style.width=B,b&&st&&(b.contains(U)?U.nextSibling!==st&&(U.remove(),b.insertBefore(U,st)):b.insertBefore(U,st)),m){let ht=parseFloat(B)||24,J=ft(m,ht*.6,"#ffffff",2);J?U.replaceChildren(J):U.textContent=(Ue=s.agentIconText)!=null?Ue:"\u{1F4AC}"}else if(s.iconUrl){let ht=U.querySelector("img");if(ht)ht.src=s.iconUrl,ht.style.height=B,ht.style.width=B;else{let J=document.createElement("img");J.src=s.iconUrl,J.alt="",J.className="tvw-rounded-xl tvw-object-cover",J.style.height=B,J.style.width=B,U.replaceChildren(J)}}else{let ht=U.querySelector("svg"),J=U.querySelector("img");(ht||J)&&U.replaceChildren(),U.textContent=(W=s.agentIconText)!=null?W:"\u{1F4AC}"}let lt=U.querySelector("img");lt&&(lt.style.height=B,lt.style.width=B)}}if(C){let b=(et=s.closeButtonSize)!=null?et:"32px",st=(wt=s.closeButtonPlacement)!=null?wt:"inline";C.style.height=b,C.style.width=b;let lt=st==="top-right",ht=C.classList.contains("tvw-absolute");if(lt!==ht)if(C.remove(),lt)C.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",N.style.position="relative",N.appendChild(C);else{C.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 _=N.querySelector(".tvw-border-b-cw-divider");_&&_.appendChild(C)}if(s.closeButtonColor?(C.style.color=s.closeButtonColor,C.classList.remove("tvw-text-cw-muted")):(C.style.color="",C.classList.add("tvw-text-cw-muted")),s.closeButtonBackgroundColor?(C.style.backgroundColor=s.closeButtonBackgroundColor,C.classList.remove("hover:tvw-bg-gray-100")):(C.style.backgroundColor="",C.classList.add("hover:tvw-bg-gray-100")),s.closeButtonBorderWidth||s.closeButtonBorderColor){let _=s.closeButtonBorderWidth||"0px",Gt=s.closeButtonBorderColor||"transparent";C.style.border=`${_} solid ${Gt}`,C.classList.remove("tvw-border-none")}else C.style.border="",C.classList.add("tvw-border-none");s.closeButtonBorderRadius?(C.style.borderRadius=s.closeButtonBorderRadius,C.classList.remove("tvw-rounded-full")):(C.style.borderRadius="",C.classList.add("tvw-rounded-full")),s.closeButtonPaddingX?(C.style.paddingLeft=s.closeButtonPaddingX,C.style.paddingRight=s.closeButtonPaddingX):(C.style.paddingLeft="",C.style.paddingRight=""),s.closeButtonPaddingY?(C.style.paddingTop=s.closeButtonPaddingY,C.style.paddingBottom=s.closeButtonPaddingY):(C.style.paddingTop="",C.style.paddingBottom="");let J=(Xt=s.closeButtonIconName)!=null?Xt:"x",re=(St=s.closeButtonIconText)!=null?St:"\xD7";C.innerHTML="";let Lt=ft(J,"20px",s.closeButtonColor||"",2);Lt?C.appendChild(Lt):C.textContent=re;let{closeButtonWrapper:xt}=A,nt=(ee=s.closeButtonTooltipText)!=null?ee:"Close chat",At=(we=s.closeButtonShowTooltip)!=null?we:!0;if(C.setAttribute("aria-label",nt),xt&&(xt._cleanupTooltip&&(xt._cleanupTooltip(),delete xt._cleanupTooltip),At&&nt)){let _=null,Gt=()=>{if(_||!C)return;_=u("div","tvw-clear-chat-tooltip"),_.textContent=nt;let Rn=u("div");Rn.className="tvw-clear-chat-tooltip-arrow",_.appendChild(Rn);let tn=C.getBoundingClientRect();_.style.position="fixed",_.style.left=`${tn.left+tn.width/2}px`,_.style.top=`${tn.top-8}px`,_.style.transform="translate(-50%, -100%)",document.body.appendChild(_)},kt=()=>{_&&_.parentNode&&(_.parentNode.removeChild(_),_=null)};xt.addEventListener("mouseenter",Gt),xt.addEventListener("mouseleave",kt),C.addEventListener("focus",Gt),C.addEventListener("blur",kt),xt._cleanupTooltip=()=>{kt(),xt&&(xt.removeEventListener("mouseenter",Gt),xt.removeEventListener("mouseleave",kt)),C&&(C.removeEventListener("focus",Gt),C.removeEventListener("blur",kt))}}}let{clearChatButton:w,clearChatButtonWrapper:K}=A;if(w){let b=(ne=s.clearChat)!=null?ne:{},st=(Le=b.enabled)!=null?Le:!0;if(K&&(K.style.display=st?"":"none"),st){let lt=(oe=b.size)!=null?oe:"32px";w.style.height=lt,w.style.width=lt;let ht=(Ge=b.iconName)!=null?Ge:"refresh-cw",J=(je=b.iconColor)!=null?je:"";w.innerHTML="";let re=ft(ht,"20px",J||"",2);if(re&&w.appendChild(re),J?(w.style.color=J,w.classList.remove("tvw-text-cw-muted")):(w.style.color="",w.classList.add("tvw-text-cw-muted")),b.backgroundColor?(w.style.backgroundColor=b.backgroundColor,w.classList.remove("hover:tvw-bg-gray-100")):(w.style.backgroundColor="",w.classList.add("hover:tvw-bg-gray-100")),b.borderWidth||b.borderColor){let nt=b.borderWidth||"0px",At=b.borderColor||"transparent";w.style.border=`${nt} solid ${At}`,w.classList.remove("tvw-border-none")}else w.style.border="",w.classList.add("tvw-border-none");b.borderRadius?(w.style.borderRadius=b.borderRadius,w.classList.remove("tvw-rounded-full")):(w.style.borderRadius="",w.classList.add("tvw-rounded-full")),b.paddingX?(w.style.paddingLeft=b.paddingX,w.style.paddingRight=b.paddingX):(w.style.paddingLeft="",w.style.paddingRight=""),b.paddingY?(w.style.paddingTop=b.paddingY,w.style.paddingBottom=b.paddingY):(w.style.paddingTop="",w.style.paddingBottom="");let Lt=(dt=b.tooltipText)!=null?dt:"Clear chat",xt=(se=b.showTooltip)!=null?se:!0;if(w.setAttribute("aria-label",Lt),K&&(K._cleanupTooltip&&(K._cleanupTooltip(),delete K._cleanupTooltip),xt&&Lt)){let nt=null,At=()=>{if(nt||!w)return;nt=u("div","tvw-clear-chat-tooltip"),nt.textContent=Lt;let Gt=u("div");Gt.className="tvw-clear-chat-tooltip-arrow",nt.appendChild(Gt);let kt=w.getBoundingClientRect();nt.style.position="fixed",nt.style.left=`${kt.left+kt.width/2}px`,nt.style.top=`${kt.top-8}px`,nt.style.transform="translate(-50%, -100%)",document.body.appendChild(nt)},_=()=>{nt&&nt.parentNode&&(nt.parentNode.removeChild(nt),nt=null)};K.addEventListener("mouseenter",At),K.addEventListener("mouseleave",_),w.addEventListener("focus",At),w.addEventListener("blur",_),K._cleanupTooltip=()=>{_(),K&&(K.removeEventListener("mouseenter",At),K.removeEventListener("mouseleave",_)),w&&(w.removeEventListener("focus",At),w.removeEventListener("blur",_))}}}}E=Un(e),P.updateConfig(e),Rt(T,P.getMessages(),E),Yt.render(e.suggestionChips,P,M),D(),ie(P.isStreaming());let rt=((he=e.voiceRecognition)==null?void 0:he.enabled)===!0,mt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),at=rt&&mt;if(Q.classList.remove("tvw-gap-1","tvw-gap-3"),Q.classList.add(at?"tvw-gap-1":"tvw-gap-3"),rt&&mt)if(!v||!ut){let b=Se(e.voiceRecognition,e.sendButton);b&&(v=b.micButton,ut=b.micButtonWrapper,Q.insertBefore(ut,Y),v.addEventListener("click",Qt),v.disabled=P.isStreaming())}else{let b=(Xe=e.voiceRecognition)!=null?Xe:{},st=(Be=e.sendButton)!=null?Be:{},lt=(hn=b.iconName)!=null?hn:"mic",ht=(vn=st.size)!=null?vn:"40px",J=(fn=b.iconSize)!=null?fn:ht,re=parseFloat(J)||24;v.style.width=J,v.style.height=J,v.style.minWidth=J,v.style.minHeight=J;let Lt=(bn=(yn=b.iconColor)!=null?yn:st.textColor)!=null?bn:"currentColor";v.innerHTML="";let xt=ft(lt,re,Lt,2);xt?v.appendChild(xt):v.textContent="\u{1F3A4}";let nt=(xn=b.backgroundColor)!=null?xn:st.backgroundColor;nt?(v.style.backgroundColor=nt,v.classList.remove("tvw-bg-cw-primary")):(v.style.backgroundColor="",v.classList.add("tvw-bg-cw-primary")),Lt?(v.style.color=Lt,v.classList.remove("tvw-text-white")):!Lt&&!st.textColor&&(v.style.color="",v.classList.add("tvw-text-white")),b.borderWidth?(v.style.borderWidth=b.borderWidth,v.style.borderStyle="solid"):(v.style.borderWidth="",v.style.borderStyle=""),b.borderColor?v.style.borderColor=b.borderColor:v.style.borderColor="",b.paddingX?(v.style.paddingLeft=b.paddingX,v.style.paddingRight=b.paddingX):(v.style.paddingLeft="",v.style.paddingRight=""),b.paddingY?(v.style.paddingTop=b.paddingY,v.style.paddingBottom=b.paddingY):(v.style.paddingTop="",v.style.paddingBottom="");let At=ut==null?void 0:ut.querySelector(".tvw-send-button-tooltip"),_=(Cn=b.tooltipText)!=null?Cn:"Start voice recognition";if(((Tn=b.showTooltip)!=null?Tn:!1)&&_)if(At)At.textContent=_,At.style.display="";else{let kt=document.createElement("div");kt.className="tvw-send-button-tooltip",kt.textContent=_,ut==null||ut.insertBefore(kt,v)}else At&&(At.style.display="none");ut.style.display="",v.disabled=P.isStreaming()}else v&&ut&&(ut.style.display="none",Tt&&Wt());let $=(Sn=e.sendButton)!=null?Sn:{},$t=(Ln=$.useIcon)!=null?Ln:!1,Ot=(An=$.iconText)!=null?An:"\u2191",_t=$.iconName,Nt=(En=$.tooltipText)!=null?En:"Send message",te=(Mn=$.showTooltip)!=null?Mn:!1,Ut=(Bn=$.size)!=null?Bn:"40px",Vt=$.backgroundColor,vt=$.textColor;if($t){if(y.style.width=Ut,y.style.height=Ut,y.style.minWidth=Ut,y.style.minHeight=Ut,y.style.fontSize="18px",y.style.lineHeight="1",y.innerHTML="",_t){let b=parseFloat(Ut)||24,st=vt&&typeof vt=="string"&&vt.trim()?vt.trim():"currentColor",lt=ft(_t,b,st,2);lt?(y.appendChild(lt),y.style.color=st):(y.textContent=Ot,vt?y.style.color=vt:y.classList.add("tvw-text-white"))}else y.textContent=Ot,vt?y.style.color=vt:y.classList.add("tvw-text-white");y.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",Vt?(y.style.backgroundColor=Vt,y.classList.remove("tvw-bg-cw-primary")):y.classList.add("tvw-bg-cw-primary")}else y.textContent=(kn=(Wn=e.copy)==null?void 0:Wn.sendButtonLabel)!=null?kn:"Send",y.style.width="",y.style.height="",y.style.minWidth="",y.style.minHeight="",y.style.fontSize="",y.style.lineHeight="",y.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?(y.style.backgroundColor=Vt,y.classList.remove("tvw-bg-cw-accent")):y.classList.add("tvw-bg-cw-accent"),vt?y.style.color=vt:y.classList.add("tvw-text-white");$.borderWidth?(y.style.borderWidth=$.borderWidth,y.style.borderStyle="solid"):(y.style.borderWidth="",y.style.borderStyle=""),$.borderColor?y.style.borderColor=$.borderColor:y.style.borderColor="",$.paddingX?(y.style.paddingLeft=$.paddingX,y.style.paddingRight=$.paddingX):(y.style.paddingLeft="",y.style.paddingRight=""),$.paddingY?(y.style.paddingTop=$.paddingY,y.style.paddingBottom=$.paddingY):(y.style.paddingTop="",y.style.paddingBottom="");let jt=Y==null?void 0:Y.querySelector(".tvw-send-button-tooltip");if(te&&Nt)if(jt)jt.textContent=Nt,jt.style.display="";else{let b=document.createElement("div");b.className="tvw-send-button-tooltip",b.textContent=Nt,Y==null||Y.insertBefore(b,y)}else jt&&(jt.style.display="none");let me=(In=e.statusIndicator)!=null?In:{},Ve=(Hn=me.visible)!=null?Hn:!0;if(ot.style.display=Ve?"":"none",P){let b=P.getStatus(),st=lt=>{var ht,J,re,Lt;return lt==="idle"?(ht=me.idleText)!=null?ht:yt.idle:lt==="connecting"?(J=me.connectingText)!=null?J:yt.connecting:lt==="connected"?(re=me.connectedText)!=null?re:yt.connected:lt==="error"?(Lt=me.errorText)!=null?Lt:yt.error:yt[lt]};ot.textContent=st(b)}},open(){o&&V(!0)},close(){o&&V(!1)},toggle(){o&&V(!x)},clearChat(){P.clearMessages();let r=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});window.dispatchEvent(r)},destroy(){Et.forEach(r=>r()),L.remove(),G==null||G.destroy(),Ft&&C.removeEventListener("click",Ft)}}};var mn={},ao=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},lo=()=>{try{if(typeof mn!="undefined"&&mn.url)return new URL("../widget.css",mn.url).href}catch{}return null},jn=t=>{let n=lo(),e=()=>{if(!(t instanceof ShadowRoot)||t.querySelector("link[data-vanilla-agent]"))return;let i=document.head.querySelector("link[data-vanilla-agent]");if(!i)return;let o=i.cloneNode(!0);t.insertBefore(o,t.firstChild)};if(t instanceof ShadowRoot)if(n){let i=document.createElement("link");i.rel="stylesheet",i.href=n,i.setAttribute("data-vanilla-agent","true"),t.insertBefore(i,t.firstChild)}else e();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)}},wn=t=>{var S;let n=ao(t.target),e=document.createElement("div");e.className="vanilla-agent-host",n.appendChild(e);let i=t.useShadowDom!==!1,o,d;if(i){let x=e.attachShadow({mode:"open"});d=x,o=document.createElement("div"),o.id="vanilla-agent-root",x.appendChild(o),jn(x)}else d=e,o=document.createElement("div"),o.id="vanilla-agent-root",e.appendChild(o),jn(e);let a=Qe(o,t.config);return(S=t.onReady)==null||S.call(t),{host:e,update(x){a.update(x)},open(){a.open()},close(){a.close()},toggle(){a.toggle()},clearChat(){a.clearChat()},destroy(){a.destroy(),e.remove()}}};var co=wn;0&&(module.exports={AgentWidgetClient,AgentWidgetSession,DEFAULT_WIDGET_CONFIG,createAgentExperience,directivePostprocessor,escapeHtml,initAgentWidget,markdownPostprocessor,mergeWithDefaults,pluginRegistry});
12
+ `,e.addEventListener("click",n);let s=l=>{var Y,E,N,P,S,dt,B,b,V,Z;let a=(Y=l.launcher)!=null?Y:{},L=e.querySelector("[data-role='launcher-title']");L&&(L.textContent=(E=a.title)!=null?E:"Chat Assistant");let C=e.querySelector("[data-role='launcher-subtitle']");C&&(C.textContent=(N=a.subtitle)!=null?N:"Get answers fast");let M=e.querySelector(".tvw-flex-col");M&&(a.textHidden?M.style.display="none":M.style.display="");let y=e.querySelector("[data-role='launcher-icon']");if(y)if(a.agentIconHidden)y.style.display="none";else{let nt=(P=a.agentIconSize)!=null?P:"40px";if(y.style.height=nt,y.style.width=nt,y.innerHTML="",a.agentIconName){let ut=parseFloat(nt)||24,Ct=ft(a.agentIconName,ut*.6,"#ffffff",2);Ct?(y.appendChild(Ct),y.style.display=""):(y.textContent=(S=a.agentIconText)!=null?S:"\u{1F4AC}",y.style.display="")}else a.iconUrl?y.style.display="none":(y.textContent=(dt=a.agentIconText)!=null?dt:"\u{1F4AC}",y.style.display="")}let I=e.querySelector("[data-role='launcher-image']");if(I){let nt=(B=a.agentIconSize)!=null?B:"40px";I.style.height=nt,I.style.width=nt,a.iconUrl&&!a.agentIconName&&!a.agentIconHidden?(I.src=a.iconUrl,I.style.display="block"):I.style.display="none"}let h=e.querySelector("[data-role='launcher-call-to-action-icon']");if(h){let nt=(b=a.callToActionIconSize)!=null?b:"32px";h.style.height=nt,h.style.width=nt,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 ut=0;if(a.callToActionIconPadding?(h.style.boxSizing="border-box",h.style.padding=a.callToActionIconPadding,ut=(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 Ct=parseFloat(nt)||24,T=Math.max(Ct-ut,8),j=ft(a.callToActionIconName,T,"currentColor",2);j?h.appendChild(j):h.textContent=(V=a.callToActionIconText)!=null?V:"\u2197"}else h.textContent=(Z=a.callToActionIconText)!=null?Z:"\u2197"}let _=a.position&&he[a.position]?he[a.position]:he["bottom-right"],A="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";e.className=`${A} ${_}`},o=()=>{e.removeEventListener("click",n),e.remove()};return t&&s(t),{element:e,update:s,destroy:o}};var qn=t=>{var C,M,y,I,h;if(!((M=(C=t==null?void 0:t.launcher)==null?void 0:C.enabled)!=null?M:!0)){let _=p("div","tvw-relative tvw-w-full tvw-h-full"),A=p("div","tvw-relative tvw-w-full tvw-h-full tvw-min-h-[360px]");return _.appendChild(A),{wrapper:_,panel:A}}let e=(y=t==null?void 0:t.launcher)!=null?y:{},s=e.position&&he[e.position]?he[e.position]:he["bottom-right"],o=p("div",`tvw-fixed ${s} tvw-z-50 tvw-transition`),l=p("div","tvw-relative tvw-min-h-[320px]"),a=(h=(I=t==null?void 0:t.launcher)==null?void 0:I.width)!=null?h:t==null?void 0:t.launcherWidth,L=a!=null?a:"min(400px, calc(100vw - 24px))";return l.style.width=L,l.style.maxWidth=L,o.appendChild(l),{wrapper:o,panel:l}},zn=(t,n=!0)=>{var xe,Ce,Bt,Te,Zt,se,G,zt,ie,ae,Ee,le,de,ce,ue,pe,w,R,z,J,r,v,H,u,d,c,i,g,m,F,rt,gt,st,O,Pt,$t,Ot,Nt,Qt,_t,Yt,vt,Ut,ge,Ve,We,ke,Ie,He,Re,Ne,Fe,De,qe,ze,Pe,$e,Oe,_e,Ue;let e=p("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"),s=p("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=(xe=t==null?void 0:t.launcher)!=null?xe:{},l=(Ce=o.headerIconSize)!=null?Ce:"48px",a=(Bt=o.closeButtonSize)!=null?Bt:"32px",L=(Te=o.closeButtonPlacement)!=null?Te:"inline",C=(Zt=o.headerIconHidden)!=null?Zt:!1,M=o.headerIconName,y=p("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-xl");if(y.style.height=l,y.style.width=l,!C)if(M){let k=parseFloat(l)||24,tt=ft(M,k*.6,"#ffffff",2);tt?y.replaceChildren(tt):y.textContent=(G=(se=t==null?void 0:t.launcher)==null?void 0:se.agentIconText)!=null?G:"\u{1F4AC}"}else if((zt=t==null?void 0:t.launcher)!=null&&zt.iconUrl){let k=p("img");k.src=t.launcher.iconUrl,k.alt="",k.className="tvw-rounded-xl tvw-object-cover",k.style.height=l,k.style.width=l,y.replaceChildren(k)}else y.textContent=(ae=(ie=t==null?void 0:t.launcher)==null?void 0:ie.agentIconText)!=null?ae:"\u{1F4AC}";let I=p("div","tvw-flex tvw-flex-col"),h=p("span","tvw-text-base tvw-font-semibold");h.textContent=(le=(Ee=t==null?void 0:t.launcher)==null?void 0:Ee.title)!=null?le:"Chat Assistant";let _=p("span","tvw-text-xs tvw-text-cw-muted");_.textContent=(ce=(de=t==null?void 0:t.launcher)==null?void 0:de.subtitle)!=null?ce:"Here to help you get answers fast",I.append(h,_),C?s.append(I):s.append(y,I);let A=(ue=o.clearChat)!=null?ue:{},Y=(pe=A.enabled)!=null?pe:!0,E=null,N=null;if(Y){let k=(w=A.size)!=null?w:"32px",tt=(R=A.iconName)!=null?R:"refresh-cw",mt=(z=A.iconColor)!=null?z:"",jt=(J=A.backgroundColor)!=null?J:"",Tt=(r=A.borderWidth)!=null?r:"",te=(v=A.borderColor)!=null?v:"",me=(H=A.borderRadius)!=null?H:"",ee=(u=A.paddingX)!=null?u:"",Se=(d=A.paddingY)!=null?d:"",ne=(c=A.tooltipText)!=null?c:"Clear chat",Ge=(i=A.showTooltip)!=null?i:!0;N=p("div","tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper"),E=p("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"),E.style.height=k,E.style.width=k,E.type="button",E.setAttribute("aria-label",ne);let je=ft(tt,"20px",mt||"",2);if(je&&E.appendChild(je),mt&&(E.style.color=mt,E.classList.remove("tvw-text-cw-muted")),jt&&(E.style.backgroundColor=jt,E.classList.remove("hover:tvw-bg-gray-100")),Tt||te){let lt=Tt||"0px",oe=te||"transparent";E.style.border=`${lt} solid ${oe}`,E.classList.remove("tvw-border-none")}if(me&&(E.style.borderRadius=me,E.classList.remove("tvw-rounded-full")),ee?(E.style.paddingLeft=ee,E.style.paddingRight=ee):(E.style.paddingLeft="",E.style.paddingRight=""),Se?(E.style.paddingTop=Se,E.style.paddingBottom=Se):(E.style.paddingTop="",E.style.paddingBottom=""),N.appendChild(E),Ge&&ne&&E&&N){let lt=null,oe=()=>{if(lt||!E)return;lt=p("div","tvw-clear-chat-tooltip"),lt.textContent=ne;let Xe=p("div");Xe.className="tvw-clear-chat-tooltip-arrow",lt.appendChild(Xe);let Me=E.getBoundingClientRect();lt.style.position="fixed",lt.style.left=`${Me.left+Me.width/2}px`,lt.style.top=`${Me.top-8}px`,lt.style.transform="translate(-50%, -100%)",document.body.appendChild(lt)},we=()=>{lt&&lt.parentNode&&(lt.parentNode.removeChild(lt),lt=null)};N.addEventListener("mouseenter",oe),N.addEventListener("mouseleave",we),E.addEventListener("focus",oe),E.addEventListener("blur",we),N._cleanupTooltip=()=>{we(),N&&(N.removeEventListener("mouseenter",oe),N.removeEventListener("mouseleave",we)),E&&(E.removeEventListener("focus",oe),E.removeEventListener("blur",we))}}s.appendChild(N)}let P=p("div",L==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50":Y?"":"tvw-ml-auto"),S=p("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");S.style.height=a,S.style.width=a,S.type="button";let dt=(g=o.closeButtonTooltipText)!=null?g:"Close chat",B=(m=o.closeButtonShowTooltip)!=null?m:!0;S.setAttribute("aria-label",dt),S.style.display=n?"":"none";let b=(F=o.closeButtonIconName)!=null?F:"x",V=(rt=o.closeButtonIconText)!=null?rt:"\xD7",Z=ft(b,"20px",o.closeButtonColor||"",2);if(Z?S.appendChild(Z):S.textContent=V,o.closeButtonColor?(S.style.color=o.closeButtonColor,S.classList.remove("tvw-text-cw-muted")):(S.style.color="",S.classList.add("tvw-text-cw-muted")),o.closeButtonBackgroundColor?(S.style.backgroundColor=o.closeButtonBackgroundColor,S.classList.remove("hover:tvw-bg-gray-100")):(S.style.backgroundColor="",S.classList.add("hover:tvw-bg-gray-100")),o.closeButtonBorderWidth||o.closeButtonBorderColor){let k=o.closeButtonBorderWidth||"0px",tt=o.closeButtonBorderColor||"transparent";S.style.border=`${k} solid ${tt}`,S.classList.remove("tvw-border-none")}else S.style.border="",S.classList.add("tvw-border-none");if(o.closeButtonBorderRadius?(S.style.borderRadius=o.closeButtonBorderRadius,S.classList.remove("tvw-rounded-full")):(S.style.borderRadius="",S.classList.add("tvw-rounded-full")),o.closeButtonPaddingX?(S.style.paddingLeft=o.closeButtonPaddingX,S.style.paddingRight=o.closeButtonPaddingX):(S.style.paddingLeft="",S.style.paddingRight=""),o.closeButtonPaddingY?(S.style.paddingTop=o.closeButtonPaddingY,S.style.paddingBottom=o.closeButtonPaddingY):(S.style.paddingTop="",S.style.paddingBottom=""),P.appendChild(S),B&&dt){let k=null,tt=()=>{if(k)return;k=p("div","tvw-clear-chat-tooltip"),k.textContent=dt;let jt=p("div");jt.className="tvw-clear-chat-tooltip-arrow",k.appendChild(jt);let Tt=S.getBoundingClientRect();k.style.position="fixed",k.style.left=`${Tt.left+Tt.width/2}px`,k.style.top=`${Tt.top-8}px`,k.style.transform="translate(-50%, -100%)",document.body.appendChild(k)},mt=()=>{k&&k.parentNode&&(k.parentNode.removeChild(k),k=null)};P.addEventListener("mouseenter",tt),P.addEventListener("mouseleave",mt),S.addEventListener("focus",tt),S.addEventListener("blur",mt),P._cleanupTooltip=()=>{mt(),P.removeEventListener("mouseenter",tt),P.removeEventListener("mouseleave",mt),S.removeEventListener("focus",tt),S.removeEventListener("blur",mt)}}L==="top-right"?(e.style.position="relative",e.appendChild(P)):s.appendChild(P);let nt=p("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"),ut=p("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),Ct=p("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");Ct.textContent=(st=(gt=t==null?void 0:t.copy)==null?void 0:gt.welcomeTitle)!=null?st:"Hello \u{1F44B}";let T=p("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");T.textContent=(Pt=(O=t==null?void 0:t.copy)==null?void 0:O.welcomeSubtitle)!=null?Pt:"Ask anything about your account or products.",ut.append(Ct,T);let j=p("div","tvw-flex tvw-flex-col tvw-gap-3");nt.append(ut,j);let f=p("div","tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),ct=p("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),At=(($t=t==null?void 0:t.voiceRecognition)==null?void 0:$t.enabled)===!0,Xt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),bt=p("form",`tvw-flex tvw-items-end ${At&&Xt?"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`);bt.style.outline="none";let D=p("textarea");D.placeholder=(Nt=(Ot=t==null?void 0:t.copy)==null?void 0:Ot.inputPlaceholder)!=null?Nt:"Type your message\u2026",D.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",D.rows=1;let Gt=(_t=(Qt=t==null?void 0:t.theme)==null?void 0:Qt.inputFontFamily)!=null?_t:"sans-serif",ve=(vt=(Yt=t==null?void 0:t.theme)==null?void 0:Yt.inputFontWeight)!=null?vt:"400",Dt=k=>{switch(k){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'}};D.style.fontFamily=Dt(Gt),D.style.fontWeight=ve,D.style.border="none",D.style.outline="none",D.style.borderWidth="0",D.style.borderStyle="none",D.style.borderColor="transparent",D.addEventListener("focus",()=>{D.style.border="none",D.style.outline="none",D.style.borderWidth="0",D.style.borderStyle="none",D.style.borderColor="transparent",D.style.boxShadow="none"}),D.addEventListener("blur",()=>{D.style.border="none",D.style.outline="none"});let X=(Ut=t==null?void 0:t.sendButton)!=null?Ut:{},Kt=(ge=X.useIcon)!=null?ge:!1,Jt=(Ve=X.iconText)!=null?Ve:"\u2191",fe=X.iconName,ye=(We=X.tooltipText)!=null?We:"Send message",Ae=(ke=X.showTooltip)!=null?ke:!1,It=(Ie=X.size)!=null?Ie:"40px",qt=X.backgroundColor,at=X.textColor,Et=p("div","tvw-send-button-wrapper"),W=p("button",Kt?"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(W.type="submit",Kt){if(W.style.width=It,W.style.height=It,W.style.minWidth=It,W.style.minHeight=It,W.style.fontSize="18px",W.style.lineHeight="1",W.innerHTML="",fe){let k=parseFloat(It)||24,tt=at&&typeof at=="string"&&at.trim()?at.trim():"currentColor",mt=ft(fe,k,tt,2);mt?(W.appendChild(mt),W.style.color=tt):(W.textContent=Jt,at?W.style.color=at:W.classList.add("tvw-text-white"))}else W.textContent=Jt,at?W.style.color=at:W.classList.add("tvw-text-white");qt?W.style.backgroundColor=qt:W.classList.add("tvw-bg-cw-primary")}else W.textContent=(Re=(He=t==null?void 0:t.copy)==null?void 0:He.sendButtonLabel)!=null?Re:"Send",at?W.style.color=at:W.classList.add("tvw-text-white");if(X.borderWidth&&(W.style.borderWidth=X.borderWidth,W.style.borderStyle="solid"),X.borderColor&&(W.style.borderColor=X.borderColor),X.paddingX?(W.style.paddingLeft=X.paddingX,W.style.paddingRight=X.paddingX):(W.style.paddingLeft="",W.style.paddingRight=""),X.paddingY?(W.style.paddingTop=X.paddingY,W.style.paddingBottom=X.paddingY):(W.style.paddingTop="",W.style.paddingBottom=""),Ae&&ye){let k=p("div","tvw-send-button-tooltip");k.textContent=ye,Et.appendChild(k)}Et.appendChild(W);let Q=(Ne=t==null?void 0:t.voiceRecognition)!=null?Ne:{},be=Q.enabled===!0,q=null,Mt=null,pt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(be&&pt){Mt=p("div","tvw-send-button-wrapper"),q=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),q.type="button",q.setAttribute("aria-label","Start voice recognition");let k=(Fe=Q.iconName)!=null?Fe:"mic",tt=(De=Q.iconSize)!=null?De:It,mt=parseFloat(tt)||24,jt=(qe=Q.backgroundColor)!=null?qe:qt,Tt=(ze=Q.iconColor)!=null?ze:at;q.style.width=tt,q.style.height=tt,q.style.minWidth=tt,q.style.minHeight=tt,q.style.fontSize="18px",q.style.lineHeight="1";let te=Tt||"currentColor",me=ft(k,mt,te,1.5);me?(q.appendChild(me),q.style.color=te):(q.textContent="\u{1F3A4}",q.style.color=te),jt?q.style.backgroundColor=jt:q.classList.add("tvw-bg-cw-primary"),Tt?q.style.color=Tt:!Tt&&!at&&q.classList.add("tvw-text-white"),Q.borderWidth&&(q.style.borderWidth=Q.borderWidth,q.style.borderStyle="solid"),Q.borderColor&&(q.style.borderColor=Q.borderColor),Q.paddingX&&(q.style.paddingLeft=Q.paddingX,q.style.paddingRight=Q.paddingX),Q.paddingY&&(q.style.paddingTop=Q.paddingY,q.style.paddingBottom=Q.paddingY),Mt.appendChild(q);let ee=(Pe=Q.tooltipText)!=null?Pe:"Start voice recognition";if((($e=Q.showTooltip)!=null?$e:!1)&&ee){let ne=p("div","tvw-send-button-tooltip");ne.textContent=ee,Mt.appendChild(ne)}}bt.addEventListener("click",k=>{k.target!==W&&k.target!==Et&&k.target!==q&&k.target!==Mt&&D.focus()}),bt.append(D),Mt&&bt.append(Mt),bt.append(Et);let ht=p("div","tvw-mt-2 tvw-text-right tvw-text-xs tvw-text-cw-muted"),Ht=(Oe=t==null?void 0:t.statusIndicator)!=null?Oe:{},Rt=(_e=Ht.visible)!=null?_e:!0;return ht.style.display=Rt?"":"none",ht.textContent=(Ue=Ht.idleText)!=null?Ue:"Online",f.append(ct,bt,ht),e.append(s,nt,f),{container:e,body:nt,messagesWrapper:j,suggestions:ct,textarea:D,sendButton:W,sendButtonWrapper:Et,micButton:q,micButtonWrapper:Mt,composerForm:bt,statusText:ht,introTitle:Ct,introSubtitle:T,closeButton:S,closeButtonWrapper:P,clearChatButton:E,clearChatButtonWrapper:N,iconHolder:y}};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 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="250ms";let s=document.createElement("div");s.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",s.style.animationDelay="500ms";let o=document.createElement("span");return o.className="tvw-sr-only",o.textContent="Loading",t.appendChild(n),t.appendChild(e),t.appendChild(s),t.appendChild(o),t},an=(t,n)=>{let e=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm"];t.role==="user"?e.push("tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-5","tvw-py-3"):e.push("tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3");let s=p("div",e.join(" ")),o=document.createElement("div");if(o.innerHTML=n({text:t.content,message:t,streaming:!!t.streaming}),s.appendChild(o),t.streaming&&t.role==="assistant"&&t.content&&t.content.trim()){let l=sn();s.appendChild(l)}return s};var ln=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)}},so=t=>{var a,L;let n=(a=t.completedAt)!=null?a:Date.now(),e=(L=t.startedAt)!=null?L:n,o=(t.durationMs!==void 0?t.durationMs:Math.max(0,n-e))/1e3;return o<.1?"Thought for <0.1 seconds":`Thought for ${o>=10?Math.round(o).toString():o.toFixed(1).replace(/\.0$/,"")} seconds`},Pn=t=>t.status==="complete"?so(t):t.status==="pending"?"Waiting":"",io=t=>{var o,l,a;let e=(typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,((o=t.completedAt)!=null?o:Date.now())-((a=(l=t.startedAt)!=null?l:t.completedAt)!=null?a:Date.now())))/1e3;return e<.1?"Used tool for <0.1 seconds":`Used tool for ${e>=10?Math.round(e).toString():e.toFixed(1).replace(/\.0$/,"")} seconds`};var $n=t=>t.status==="complete"?io(t):"Using tool...";var dn=new Set,cn=t=>{let n=t.reasoning,e=p("div",["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 e;let s=dn.has(t.id),o=p("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",s?"true":"false");let l=p("div","tvw-flex tvw-flex-col tvw-text-left"),a=p("span","tvw-text-xs tvw-font-semibold tvw-text-cw-primary");a.textContent="Thinking...",l.appendChild(a);let L=p("span","tvw-text-xs tvw-text-cw-primary");L.textContent=Pn(n),l.appendChild(L),n.status==="complete"?a.style.display="none":a.style.display="";let C=p("span","tvw-text-xs tvw-text-cw-primary");C.textContent=s?"Hide":"Show",o.append(l,C);let M=p("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-px-4 tvw-py-3");M.style.display=s?"":"none";let y=n.chunks.join(""),I=p("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");I.textContent=y||(n.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),M.appendChild(I);let h=()=>{o.setAttribute("aria-expanded",s?"true":"false"),C.textContent=s?"Hide":"Show",M.style.display=s?"":"none"},_=()=>{s=!s,s?dn.add(t.id):dn.delete(t.id),h()};return o.addEventListener("pointerdown",A=>{A.preventDefault(),_()}),o.addEventListener("keydown",A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),_())}),h(),e.append(o,M),e};var un=new Set,pn=t=>{let n=t.toolCall,e=p("div",["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 e;let s=un.has(t.id),o=p("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",s?"true":"false");let l=p("div","tvw-flex tvw-flex-col tvw-text-left"),a=p("span","tvw-text-xs tvw-text-cw-primary");if(a.textContent=$n(n),l.appendChild(a),n.name){let h=p("span","tvw-text-[11px] tvw-text-cw-muted");h.textContent=n.name,l.appendChild(h)}let L=p("span","tvw-text-xs tvw-text-cw-primary");L.textContent=s?"Hide":"Show";let C=p("div","tvw-flex tvw-items-center tvw-gap-2");C.append(L),o.append(l,C);let M=p("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(M.style.display=s?"":"none",n.args!==void 0){let h=p("div","tvw-space-y-1"),_=p("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");_.textContent="Arguments";let A=p("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-font-xxs tvw-text-cw-primary");A.textContent=ln(n.args),h.append(_,A),M.appendChild(h)}if(n.chunks&&n.chunks.length){let h=p("div","tvw-space-y-1"),_=p("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");_.textContent="Activity";let A=p("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-font-xxs tvw-text-cw-primary");A.textContent=n.chunks.join(`
13
+ `),h.append(_,A),M.appendChild(h)}if(n.status==="complete"&&n.result!==void 0){let h=p("div","tvw-space-y-1"),_=p("div","tvw-font-xxs tvw-text-sm tvw-text-cw-muted");_.textContent="Result";let A=p("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-font-xxs tvw-text-cw-primary");A.textContent=ln(n.result),h.append(_,A),M.appendChild(h)}if(n.status==="complete"&&typeof n.duration=="number"){let h=p("div","tvw-font-xxs tvw-text-cw-muted");h.textContent=`Duration: ${n.duration}ms`,M.appendChild(h)}let y=()=>{o.setAttribute("aria-expanded",s?"true":"false"),L.textContent=s?"Hide":"Show",M.style.display=s?"":"none"},I=()=>{s=!s,s?un.add(t.id):un.delete(t.id),y()};return o.addEventListener("pointerdown",h=>{h.preventDefault(),I()}),o.addEventListener("keydown",h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),I())}),y(),e.append(o,M),e};var On=t=>{let n=[];return{buttons:n,render:(s,o,l,a)=>{if(t.innerHTML="",n.length=0,!s||!s.length||(a!=null?a:o?o.getMessages():[]).some(I=>I.role==="user"))return;let M=document.createDocumentFragment(),y=o?o.isStreaming():!1;s.forEach(I=>{let h=p("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");h.type="button",h.textContent=I,h.disabled=y,h.addEventListener("click",()=>{!o||o.isStreaming()||(l.value="",o.sendMessage(I))}),M.appendChild(h),n.push(h)}),t.appendChild(M)}}};var _n={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"}},gn=(t,n,e,s)=>{let o=t.querySelectorAll("[data-tv-form]");o.length&&o.forEach(l=>{var A,Y,E;if(l.dataset.enhanced==="true")return;let a=(A=l.dataset.tvForm)!=null?A:"init";l.dataset.enhanced="true";let L=(Y=_n[a])!=null?Y:_n.init;l.classList.add("tvw-form-card","tvw-space-y-4");let C=p("div","tvw-space-y-1"),M=p("h3","tvw-text-base tvw-font-semibold tvw-text-cw-primary");if(M.textContent=L.title,C.appendChild(M),L.description){let N=p("p","tvw-text-sm tvw-text-cw-muted");N.textContent=L.description,C.appendChild(N)}let y=document.createElement("form");y.className="tvw-form-grid tvw-space-y-3",L.fields.forEach(N=>{var b,V;let P=p("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");P.htmlFor=`${n.id}-${a}-${N.name}`;let S=p("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");S.textContent=N.label,P.appendChild(S);let dt=(b=N.type)!=null?b:"text",B;dt==="textarea"?(B=document.createElement("textarea"),B.rows=3):(B=document.createElement("input"),B.type=dt),B.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",B.id=`${n.id}-${a}-${N.name}`,B.name=N.name,B.placeholder=(V=N.placeholder)!=null?V:"",N.required&&(B.required=!0),P.appendChild(B),y.appendChild(P)});let I=p("div","tvw-flex tvw-items-center tvw-justify-between tvw-gap-2"),h=p("div","tvw-text-xs tvw-text-cw-muted tvw-min-h-[1.5rem]"),_=p("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");_.type="submit",_.textContent=(E=L.submitLabel)!=null?E:"Submit",I.appendChild(h),I.appendChild(_),y.appendChild(I),l.replaceChildren(C,y),y.addEventListener("submit",async N=>{var B,b;N.preventDefault();let P=(B=e.formEndpoint)!=null?B:"/form",S=new FormData(y),dt={};S.forEach((V,Z)=>{dt[Z]=V}),dt.type=a,_.disabled=!0,h.textContent="Submitting\u2026";try{let V=await fetch(P,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(dt)});if(!V.ok)throw new Error(`Form submission failed (${V.status})`);let Z=await V.json();h.textContent=(b=Z.message)!=null?b:"Thanks! We'll be in touch soon.",Z.success&&Z.nextPrompt&&await s.sendMessage(String(Z.nextPrompt))}catch(V){h.textContent=V instanceof Error?V.message:"Something went wrong. Please try again."}finally{_.disabled=!1}})})};var mn=class{constructor(){this.plugins=new Map}register(n){var e;this.plugins.has(n.id)&&console.warn(`Plugin "${n.id}" is already registered. Overwriting.`),this.plugins.set(n.id,n),(e=n.onRegister)==null||e.call(n)}unregister(n){var s;let e=this.plugins.get(n);e&&((s=e.onUnregister)==null||s.call(e),this.plugins.delete(n))}getAll(){return Array.from(this.plugins.values()).sort((n,e)=>{var s,o;return((s=e.priority)!=null?s:0)-((o=n.priority)!=null?o:0)})}getForInstance(n){let e=this.getAll();if(!n||n.length===0)return e;let s=new Set(n.map(l=>l.id));return[...e.filter(l=>!s.has(l.id)),...n].sort((l,a)=>{var L,C;return((L=a.priority)!=null?L:0)-((C=l.priority)!=null?C:0)})}clear(){this.plugins.forEach(n=>{var e;return(e=n.onUnregister)==null?void 0:e.call(n)}),this.plugins.clear()}},Ye=new mn;var kt={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?"],debug:!1};function Ze(t){var n,e,s;return t?{...kt,...t,theme:{...kt.theme,...t.theme},launcher:{...kt.launcher,...t.launcher,clearChat:{...(n=kt.launcher)==null?void 0:n.clearChat,...(e=t.launcher)==null?void 0:e.clearChat}},copy:{...kt.copy,...t.copy},sendButton:{...kt.sendButton,...t.sendButton},statusIndicator:{...kt.statusIndicator,...t.statusIndicator},voiceRecognition:{...kt.voiceRecognition,...t.voiceRecognition},features:{...kt.features,...t.features},suggestionChips:(s=t.suggestionChips)!=null?s:kt.suggestionChips}:kt}var Un=t=>t!=null&&t.postprocessMessage?n=>t.postprocessMessage({text:n.text,message:n.message,streaming:n.streaming}):({text:n})=>Je(n),Qe=(t,n)=>{var le,de,ce,ue,pe,w,R,z,J;(!t.id||t.id!=="vanilla-agent-root")&&(t.id="vanilla-agent-root");let e=Ze(n);on(t,e);let s=Ye.getForInstance(e.plugins),o=(de=(le=e.launcher)==null?void 0:le.enabled)!=null?de:!0,l=(ue=(ce=e.launcher)==null?void 0:ce.autoExpand)!=null?ue:!1,a=l,L=o,C=o?l:!0,M=Un(e),y=(w=(pe=e.features)==null?void 0:pe.showReasoning)!=null?w:!0,I=(z=(R=e.features)==null?void 0:R.showToolCalls)!=null?z:!0,h=(J=e.statusIndicator)!=null?J:{},_=r=>{var v,H,u,d;return r==="idle"?(v=h.idleText)!=null?v:yt.idle:r==="connecting"?(H=h.connectingText)!=null?H:yt.connecting:r==="connected"?(u=h.connectedText)!=null?u:yt.connected:r==="error"?(d=h.errorText)!=null?d:yt.error:yt[r]},{wrapper:A,panel:Y}=qn(e),E=zn(e,o),{container:N,body:P,messagesWrapper:S,suggestions:dt,textarea:B,sendButton:b,sendButtonWrapper:V,composerForm:Z,statusText:nt,introTitle:ut,introSubtitle:Ct,closeButton:T,iconHolder:j}=E,f=E.micButton,ct=E.micButtonWrapper;Y.appendChild(N),t.appendChild(A);let At=[],Xt=On(dt),Ft=null,$,bt=!1,D=!0,Gt=0,ve=0,Dt=null,X=!1,Kt=0,Jt=!1,fe=125,ye=2e3,Ae=5,It=50,qt=(r=!1)=>{if(!D)return;let v=Date.now();X&&v<Kt&&!r||(X&&v>=Kt&&(X=!1),!(!r&&!bt)&&(v-ve<fe||(ve=v,Dt&&cancelAnimationFrame(Dt),Dt=requestAnimationFrame(()=>{X||!D||(Jt=!0,P.scrollTop=P.scrollHeight,Gt=P.scrollTop,requestAnimationFrame(()=>{Jt=!1}),Dt=null)}))))},at=(r,v,H)=>{r.innerHTML="";let u=document.createDocumentFragment();v.forEach(c=>{let i=null,g=s.find(F=>!!(c.variant==="reasoning"&&F.renderReasoning||c.variant==="tool"&&F.renderToolCall||!c.variant&&F.renderMessage));if(g)if(c.variant==="reasoning"&&c.reasoning&&g.renderReasoning){if(!y)return;i=g.renderReasoning({message:c,defaultRenderer:()=>cn(c),config:e})}else if(c.variant==="tool"&&c.toolCall&&g.renderToolCall){if(!I)return;i=g.renderToolCall({message:c,defaultRenderer:()=>pn(c),config:e})}else g.renderMessage&&(i=g.renderMessage({message:c,defaultRenderer:()=>{let F=an(c,H);return c.role!=="user"&&gn(F,c,e,$),F},config:e}));if(!i)if(c.variant==="reasoning"&&c.reasoning){if(!y)return;i=cn(c)}else if(c.variant==="tool"&&c.toolCall){if(!I)return;i=pn(c)}else i=an(c,H),c.role!=="user"&&gn(i,c,e,$);let m=document.createElement("div");m.className="tvw-flex",c.role==="user"&&m.classList.add("tvw-justify-end"),m.appendChild(i),u.appendChild(m)});let d=v.some(c=>c.role==="assistant"&&c.streaming&&c.content&&c.content.trim());if(bt&&v.some(c=>c.role==="user")&&!d){let c=sn(),i=document.createElement("div");i.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(" "),i.appendChild(c);let g=document.createElement("div");g.className="tvw-flex",g.appendChild(i),u.appendChild(g)}r.appendChild(u),r.scrollTop=r.scrollHeight},Et=()=>{o&&(C?(A.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),Y.classList.remove("tvw-scale-95","tvw-opacity-0"),Y.classList.add("tvw-scale-100","tvw-opacity-100"),G&&(G.element.style.display="none")):(A.classList.add("tvw-pointer-events-none","tvw-opacity-0"),Y.classList.remove("tvw-scale-100","tvw-opacity-100"),Y.classList.add("tvw-scale-95","tvw-opacity-0"),G&&(G.element.style.display="")))},W=r=>{o&&C!==r&&(C=r,Et(),C&&(zt(),qt(!0)))},Q=r=>{B.disabled=r,b.disabled=r,f&&(f.disabled=r),Xt.buttons.forEach(v=>{v.disabled=r})},be=()=>{var d,c,i,g,m,F,rt,gt,st,O,Pt,$t,Ot,Nt;ut.textContent=(c=(d=e.copy)==null?void 0:d.welcomeTitle)!=null?c:"Hello \u{1F44B}",Ct.textContent=(g=(i=e.copy)==null?void 0:i.welcomeSubtitle)!=null?g:"Ask anything about your account or products.",B.placeholder=(F=(m=e.copy)==null?void 0:m.inputPlaceholder)!=null?F:"How can I help...",((gt=(rt=e.sendButton)==null?void 0:rt.useIcon)!=null?gt:!1)||(b.textContent=(O=(st=e.copy)==null?void 0:st.sendButtonLabel)!=null?O:"Send");let v=($t=(Pt=e.theme)==null?void 0:Pt.inputFontFamily)!=null?$t:"sans-serif",H=(Nt=(Ot=e.theme)==null?void 0:Ot.inputFontWeight)!=null?Nt:"400",u=Qt=>{switch(Qt){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'}};B.style.fontFamily=u(v),B.style.fontWeight=H};$=new Be(e,{onMessagesChanged(r){at(S,r,M),$&&(r.some(H=>H.role==="user")?Xt.render([],$,B,r):Xt.render(e.suggestionChips,$,B,r)),qt(!bt)},onStatusChanged(r){var u;let v=(u=e.statusIndicator)!=null?u:{},H=d=>{var c,i,g,m;return d==="idle"?(c=v.idleText)!=null?c:yt.idle:d==="connecting"?(i=v.connectingText)!=null?i:yt.connecting:d==="connected"?(g=v.connectedText)!=null?g:yt.connected:d==="error"?(m=v.errorText)!=null?m:yt.error:yt[d]};nt.textContent=H(r)},onStreamingChanged(r){bt=r,Q(r),$&&at(S,$.getMessages(),M),r||qt(!0)}});let q=r=>{r.preventDefault();let v=B.value.trim();v&&(B.value="",$.sendMessage(v))},Mt=r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),b.click())},pt=null,ht=!1,Ht=null,Rt=null,xe=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,Ce=()=>{var d,c,i,g;if(ht||$.isStreaming())return;let r=xe();if(!r)return;pt=new r;let H=(c=((d=e.voiceRecognition)!=null?d:{}).pauseDuration)!=null?c:2e3;pt.continuous=!0,pt.interimResults=!0,pt.lang="en-US";let u=B.value;pt.onresult=m=>{let F="",rt="";for(let st=0;st<m.results.length;st++){let O=m.results[st],Pt=O[0].transcript;O.isFinal?F+=Pt+" ":rt=Pt}let gt=u+F+rt;B.value=gt,Ht&&clearTimeout(Ht),(F||rt)&&(Ht=window.setTimeout(()=>{let st=B.value.trim();st&&pt&&ht&&(Bt(),B.value="",$.sendMessage(st))},H))},pt.onerror=m=>{m.error!=="no-speech"&&Bt()},pt.onend=()=>{if(ht){let m=B.value.trim();m&&m!==u.trim()&&(B.value="",$.sendMessage(m)),Bt()}};try{if(pt.start(),ht=!0,f){Rt={backgroundColor:f.style.backgroundColor,color:f.style.color,borderColor:f.style.borderColor};let m=(i=e.voiceRecognition)!=null?i:{},F=(g=m.recordingBackgroundColor)!=null?g:"#ef4444",rt=m.recordingIconColor,gt=m.recordingBorderColor;if(f.classList.add("tvw-voice-recording"),f.style.backgroundColor=F,rt){f.style.color=rt;let st=f.querySelector("svg");st&&st.setAttribute("stroke",rt)}gt&&(f.style.borderColor=gt),f.setAttribute("aria-label","Stop voice recognition")}}catch{Bt()}},Bt=()=>{if(ht){if(ht=!1,Ht&&(clearTimeout(Ht),Ht=null),pt){try{pt.stop()}catch{}pt=null}if(f){if(f.classList.remove("tvw-voice-recording"),Rt){f.style.backgroundColor=Rt.backgroundColor,f.style.color=Rt.color,f.style.borderColor=Rt.borderColor;let r=f.querySelector("svg");r&&r.setAttribute("stroke",Rt.color||"currentColor"),Rt=null}f.setAttribute("aria-label","Start voice recognition")}}},Te=(r,v)=>{var $t,Ot,Nt,Qt,_t,Yt,vt;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let u=p("div","tvw-send-button-wrapper"),d=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");d.type="button",d.setAttribute("aria-label","Start voice recognition");let c=($t=r==null?void 0:r.iconName)!=null?$t:"mic",i=(Ot=v==null?void 0:v.size)!=null?Ot:"40px",g=(Nt=r==null?void 0:r.iconSize)!=null?Nt:i,m=parseFloat(g)||24,F=(Qt=r==null?void 0:r.backgroundColor)!=null?Qt:v==null?void 0:v.backgroundColor,rt=(_t=r==null?void 0:r.iconColor)!=null?_t:v==null?void 0:v.textColor;d.style.width=g,d.style.height=g,d.style.minWidth=g,d.style.minHeight=g,d.style.fontSize="18px",d.style.lineHeight="1";let gt=rt||"currentColor",st=ft(c,m,gt,1.5);st?(d.appendChild(st),d.style.color=gt):(d.textContent="\u{1F3A4}",d.style.color=gt),F?d.style.backgroundColor=F:d.classList.add("tvw-bg-cw-primary"),rt?d.style.color=rt:!rt&&!(v!=null&&v.textColor)&&d.classList.add("tvw-text-white"),r!=null&&r.borderWidth&&(d.style.borderWidth=r.borderWidth,d.style.borderStyle="solid"),r!=null&&r.borderColor&&(d.style.borderColor=r.borderColor),r!=null&&r.paddingX&&(d.style.paddingLeft=r.paddingX,d.style.paddingRight=r.paddingX),r!=null&&r.paddingY&&(d.style.paddingTop=r.paddingY,d.style.paddingBottom=r.paddingY),u.appendChild(d);let O=(Yt=r==null?void 0:r.tooltipText)!=null?Yt:"Start voice recognition";if(((vt=r==null?void 0:r.showTooltip)!=null?vt:!1)&&O){let Ut=p("div","tvw-send-button-tooltip");Ut.textContent=O,u.appendChild(Ut)}return{micButton:d,micButtonWrapper:u}},Zt=()=>{if(ht){let r=B.value.trim();Bt(),r&&(B.value="",$.sendMessage(r))}else Ce()};f&&(f.addEventListener("click",Zt),At.push(()=>{Bt(),f&&f.removeEventListener("click",Zt)}));let se=()=>{W(!C)},G=o?rn(e,se):null;G&&t.appendChild(G.element),Et(),Xt.render(e.suggestionChips,$,B),be(),Q($.isStreaming()),qt(!0);let zt=()=>{var i,g;if(!o){Y.style.height="",Y.style.width="";return}let r=(g=(i=e==null?void 0:e.launcher)==null?void 0:i.width)!=null?g:e==null?void 0:e.launcherWidth,v=r!=null?r:"min(400px, calc(100vw - 24px))";Y.style.width=v,Y.style.maxWidth=v;let H=window.innerHeight,d=Math.max(200,H-64),c=Math.min(640,d);Y.style.height=`${c}px`};zt(),window.addEventListener("resize",zt),At.push(()=>window.removeEventListener("resize",zt)),Gt=P.scrollTop;let ie=()=>{let r=P.scrollTop,v=P.scrollHeight,H=P.clientHeight,u=v-r-H,d=Math.abs(r-Gt);if(Gt=r,!Jt&&!(d<=Ae)){if(!D&&u<It){X=!1,D=!0;return}D&&u>It&&(X=!0,Kt=Date.now()+ye,D=!1)}};P.addEventListener("scroll",ie,{passive:!0}),At.push(()=>P.removeEventListener("scroll",ie)),At.push(()=>{Dt&&cancelAnimationFrame(Dt)});let ae=()=>{T&&(Ft&&(T.removeEventListener("click",Ft),Ft=null),o?(T.style.display="",Ft=()=>{C=!1,Et()},T.addEventListener("click",Ft)):T.style.display="none")};return ae(),(()=>{let{clearChatButton:r}=E;r&&r.addEventListener("click",()=>{$.clearMessages();let v=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});window.dispatchEvent(v)})})(),Z.addEventListener("submit",q),B.addEventListener("keydown",Mt),At.push(()=>{Z.removeEventListener("submit",q),B.removeEventListener("keydown",Mt)}),At.push(()=>{$.cancel()}),G&&At.push(()=>{G==null||G.destroy()}),{update(r){var We,ke,Ie,He,Re,Ne,Fe,De,qe,ze,Pe,$e,Oe,_e,Ue,k,tt,mt,jt,Tt,te,me,ee,Se,ne,Ge,je,lt,oe,we,Xe,Me,vn,fn,yn,bn,xn,Cn,Tn,Sn,Ln,An,En,Mn,Bn,Wn,kn,In,Hn;e={...e,...r},on(t,e);let v=Ye.getForInstance(e.plugins);s.length=0,s.push(...v),o=(ke=(We=e.launcher)==null?void 0:We.enabled)!=null?ke:!0,l=(He=(Ie=e.launcher)==null?void 0:Ie.autoExpand)!=null?He:!1,y=(Ne=(Re=e.features)==null?void 0:Re.showReasoning)!=null?Ne:!0,I=(De=(Fe=e.features)==null?void 0:Fe.showToolCalls)!=null?De:!0,((qe=e.launcher)==null?void 0:qe.enabled)===!1&&G&&(G.destroy(),G=null),((ze=e.launcher)==null?void 0:ze.enabled)!==!1&&!G&&(G=rn(e,se),t.appendChild(G.element)),G&&G.update(e),o!==L?o?W(l):(C=!0,Et()):l!==a&&W(l),a=l,L=o,zt(),ae();let d=(Pe=e.launcher)!=null?Pe:{},c=($e=d.headerIconHidden)!=null?$e:!1,i=d.headerIconName,g=(Oe=d.headerIconSize)!=null?Oe:"48px";if(j){let x=N.querySelector(".tvw-border-b-cw-divider"),ot=x==null?void 0:x.querySelector(".tvw-flex-col");if(c)j.style.display="none",x&&ot&&!x.contains(ot)&&x.insertBefore(ot,x.firstChild);else{if(j.style.display="",j.style.height=g,j.style.width=g,x&&ot&&(x.contains(j)?j.nextSibling!==ot&&(j.remove(),x.insertBefore(j,ot)):x.insertBefore(j,ot)),i){let wt=parseFloat(g)||24,K=ft(i,wt*.6,"#ffffff",2);K?j.replaceChildren(K):j.textContent=(_e=d.agentIconText)!=null?_e:"\u{1F4AC}"}else if(d.iconUrl){let wt=j.querySelector("img");if(wt)wt.src=d.iconUrl,wt.style.height=g,wt.style.width=g;else{let K=document.createElement("img");K.src=d.iconUrl,K.alt="",K.className="tvw-rounded-xl tvw-object-cover",K.style.height=g,K.style.width=g,j.replaceChildren(K)}}else{let wt=j.querySelector("svg"),K=j.querySelector("img");(wt||K)&&j.replaceChildren(),j.textContent=(Ue=d.agentIconText)!=null?Ue:"\u{1F4AC}"}let it=j.querySelector("img");it&&(it.style.height=g,it.style.width=g)}}if(T){let x=(k=d.closeButtonSize)!=null?k:"32px",ot=(tt=d.closeButtonPlacement)!=null?tt:"inline";T.style.height=x,T.style.width=x;let it=ot==="top-right",wt=T.classList.contains("tvw-absolute");if(it!==wt)if(T.remove(),it)T.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",N.style.position="relative",N.appendChild(T);else{T.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 U=N.querySelector(".tvw-border-b-cw-divider");U&&U.appendChild(T)}if(d.closeButtonColor?(T.style.color=d.closeButtonColor,T.classList.remove("tvw-text-cw-muted")):(T.style.color="",T.classList.add("tvw-text-cw-muted")),d.closeButtonBackgroundColor?(T.style.backgroundColor=d.closeButtonBackgroundColor,T.classList.remove("hover:tvw-bg-gray-100")):(T.style.backgroundColor="",T.classList.add("hover:tvw-bg-gray-100")),d.closeButtonBorderWidth||d.closeButtonBorderColor){let U=d.closeButtonBorderWidth||"0px",Vt=d.closeButtonBorderColor||"transparent";T.style.border=`${U} solid ${Vt}`,T.classList.remove("tvw-border-none")}else T.style.border="",T.classList.add("tvw-border-none");d.closeButtonBorderRadius?(T.style.borderRadius=d.closeButtonBorderRadius,T.classList.remove("tvw-rounded-full")):(T.style.borderRadius="",T.classList.add("tvw-rounded-full")),d.closeButtonPaddingX?(T.style.paddingLeft=d.closeButtonPaddingX,T.style.paddingRight=d.closeButtonPaddingX):(T.style.paddingLeft="",T.style.paddingRight=""),d.closeButtonPaddingY?(T.style.paddingTop=d.closeButtonPaddingY,T.style.paddingBottom=d.closeButtonPaddingY):(T.style.paddingTop="",T.style.paddingBottom="");let K=(mt=d.closeButtonIconName)!=null?mt:"x",re=(jt=d.closeButtonIconText)!=null?jt:"\xD7";T.innerHTML="";let St=ft(K,"20px",d.closeButtonColor||"",2);St?T.appendChild(St):T.textContent=re;let{closeButtonWrapper:xt}=E,et=(Tt=d.closeButtonTooltipText)!=null?Tt:"Close chat",Lt=(te=d.closeButtonShowTooltip)!=null?te:!0;if(T.setAttribute("aria-label",et),xt&&(xt._cleanupTooltip&&(xt._cleanupTooltip(),delete xt._cleanupTooltip),Lt&&et)){let U=null,Vt=()=>{if(U||!T)return;U=p("div","tvw-clear-chat-tooltip"),U.textContent=et;let Rn=p("div");Rn.className="tvw-clear-chat-tooltip-arrow",U.appendChild(Rn);let tn=T.getBoundingClientRect();U.style.position="fixed",U.style.left=`${tn.left+tn.width/2}px`,U.style.top=`${tn.top-8}px`,U.style.transform="translate(-50%, -100%)",document.body.appendChild(U)},Wt=()=>{U&&U.parentNode&&(U.parentNode.removeChild(U),U=null)};xt.addEventListener("mouseenter",Vt),xt.addEventListener("mouseleave",Wt),T.addEventListener("focus",Vt),T.addEventListener("blur",Wt),xt._cleanupTooltip=()=>{Wt(),xt&&(xt.removeEventListener("mouseenter",Vt),xt.removeEventListener("mouseleave",Wt)),T&&(T.removeEventListener("focus",Vt),T.removeEventListener("blur",Wt))}}}let{clearChatButton:m,clearChatButtonWrapper:F}=E;if(m){let x=(me=d.clearChat)!=null?me:{},ot=(ee=x.enabled)!=null?ee:!0;if(F&&(F.style.display=ot?"":"none"),ot){let it=(Se=x.size)!=null?Se:"32px";m.style.height=it,m.style.width=it;let wt=(ne=x.iconName)!=null?ne:"refresh-cw",K=(Ge=x.iconColor)!=null?Ge:"";m.innerHTML="";let re=ft(wt,"20px",K||"",2);if(re&&m.appendChild(re),K?(m.style.color=K,m.classList.remove("tvw-text-cw-muted")):(m.style.color="",m.classList.add("tvw-text-cw-muted")),x.backgroundColor?(m.style.backgroundColor=x.backgroundColor,m.classList.remove("hover:tvw-bg-gray-100")):(m.style.backgroundColor="",m.classList.add("hover:tvw-bg-gray-100")),x.borderWidth||x.borderColor){let et=x.borderWidth||"0px",Lt=x.borderColor||"transparent";m.style.border=`${et} solid ${Lt}`,m.classList.remove("tvw-border-none")}else m.style.border="",m.classList.add("tvw-border-none");x.borderRadius?(m.style.borderRadius=x.borderRadius,m.classList.remove("tvw-rounded-full")):(m.style.borderRadius="",m.classList.add("tvw-rounded-full")),x.paddingX?(m.style.paddingLeft=x.paddingX,m.style.paddingRight=x.paddingX):(m.style.paddingLeft="",m.style.paddingRight=""),x.paddingY?(m.style.paddingTop=x.paddingY,m.style.paddingBottom=x.paddingY):(m.style.paddingTop="",m.style.paddingBottom="");let St=(je=x.tooltipText)!=null?je:"Clear chat",xt=(lt=x.showTooltip)!=null?lt:!0;if(m.setAttribute("aria-label",St),F&&(F._cleanupTooltip&&(F._cleanupTooltip(),delete F._cleanupTooltip),xt&&St)){let et=null,Lt=()=>{if(et||!m)return;et=p("div","tvw-clear-chat-tooltip"),et.textContent=St;let Vt=p("div");Vt.className="tvw-clear-chat-tooltip-arrow",et.appendChild(Vt);let Wt=m.getBoundingClientRect();et.style.position="fixed",et.style.left=`${Wt.left+Wt.width/2}px`,et.style.top=`${Wt.top-8}px`,et.style.transform="translate(-50%, -100%)",document.body.appendChild(et)},U=()=>{et&&et.parentNode&&(et.parentNode.removeChild(et),et=null)};F.addEventListener("mouseenter",Lt),F.addEventListener("mouseleave",U),m.addEventListener("focus",Lt),m.addEventListener("blur",U),F._cleanupTooltip=()=>{U(),F&&(F.removeEventListener("mouseenter",Lt),F.removeEventListener("mouseleave",U)),m&&(m.removeEventListener("focus",Lt),m.removeEventListener("blur",U))}}}}M=Un(e),$.updateConfig(e),at(S,$.getMessages(),M),Xt.render(e.suggestionChips,$,B),be(),Q($.isStreaming());let rt=((oe=e.voiceRecognition)==null?void 0:oe.enabled)===!0,gt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),st=rt&&gt;if(Z.classList.remove("tvw-gap-1","tvw-gap-3"),Z.classList.add(st?"tvw-gap-1":"tvw-gap-3"),rt&&gt)if(!f||!ct){let x=Te(e.voiceRecognition,e.sendButton);x&&(f=x.micButton,ct=x.micButtonWrapper,Z.insertBefore(ct,V),f.addEventListener("click",Zt),f.disabled=$.isStreaming())}else{let x=(we=e.voiceRecognition)!=null?we:{},ot=(Xe=e.sendButton)!=null?Xe:{},it=(Me=x.iconName)!=null?Me:"mic",wt=(vn=ot.size)!=null?vn:"40px",K=(fn=x.iconSize)!=null?fn:wt,re=parseFloat(K)||24;f.style.width=K,f.style.height=K,f.style.minWidth=K,f.style.minHeight=K;let St=(bn=(yn=x.iconColor)!=null?yn:ot.textColor)!=null?bn:"currentColor";f.innerHTML="";let xt=ft(it,re,St,2);xt?f.appendChild(xt):f.textContent="\u{1F3A4}";let et=(xn=x.backgroundColor)!=null?xn:ot.backgroundColor;et?(f.style.backgroundColor=et,f.classList.remove("tvw-bg-cw-primary")):(f.style.backgroundColor="",f.classList.add("tvw-bg-cw-primary")),St?(f.style.color=St,f.classList.remove("tvw-text-white")):!St&&!ot.textColor&&(f.style.color="",f.classList.add("tvw-text-white")),x.borderWidth?(f.style.borderWidth=x.borderWidth,f.style.borderStyle="solid"):(f.style.borderWidth="",f.style.borderStyle=""),x.borderColor?f.style.borderColor=x.borderColor:f.style.borderColor="",x.paddingX?(f.style.paddingLeft=x.paddingX,f.style.paddingRight=x.paddingX):(f.style.paddingLeft="",f.style.paddingRight=""),x.paddingY?(f.style.paddingTop=x.paddingY,f.style.paddingBottom=x.paddingY):(f.style.paddingTop="",f.style.paddingBottom="");let Lt=ct==null?void 0:ct.querySelector(".tvw-send-button-tooltip"),U=(Cn=x.tooltipText)!=null?Cn:"Start voice recognition";if(((Tn=x.showTooltip)!=null?Tn:!1)&&U)if(Lt)Lt.textContent=U,Lt.style.display="";else{let Wt=document.createElement("div");Wt.className="tvw-send-button-tooltip",Wt.textContent=U,ct==null||ct.insertBefore(Wt,f)}else Lt&&(Lt.style.display="none");ct.style.display="",f.disabled=$.isStreaming()}else f&&ct&&(ct.style.display="none",ht&&Bt());let O=(Sn=e.sendButton)!=null?Sn:{},Pt=(Ln=O.useIcon)!=null?Ln:!1,$t=(An=O.iconText)!=null?An:"\u2191",Ot=O.iconName,Nt=(En=O.tooltipText)!=null?En:"Send message",Qt=(Mn=O.showTooltip)!=null?Mn:!1,_t=(Bn=O.size)!=null?Bn:"40px",Yt=O.backgroundColor,vt=O.textColor;if(Pt){if(b.style.width=_t,b.style.height=_t,b.style.minWidth=_t,b.style.minHeight=_t,b.style.fontSize="18px",b.style.lineHeight="1",b.innerHTML="",Ot){let x=parseFloat(_t)||24,ot=vt&&typeof vt=="string"&&vt.trim()?vt.trim():"currentColor",it=ft(Ot,x,ot,2);it?(b.appendChild(it),b.style.color=ot):(b.textContent=$t,vt?b.style.color=vt:b.classList.add("tvw-text-white"))}else b.textContent=$t,vt?b.style.color=vt:b.classList.add("tvw-text-white");b.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",Yt?(b.style.backgroundColor=Yt,b.classList.remove("tvw-bg-cw-primary")):b.classList.add("tvw-bg-cw-primary")}else b.textContent=(kn=(Wn=e.copy)==null?void 0:Wn.sendButtonLabel)!=null?kn:"Send",b.style.width="",b.style.height="",b.style.minWidth="",b.style.minHeight="",b.style.fontSize="",b.style.lineHeight="",b.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",Yt?(b.style.backgroundColor=Yt,b.classList.remove("tvw-bg-cw-accent")):b.classList.add("tvw-bg-cw-accent"),vt?b.style.color=vt:b.classList.add("tvw-text-white");O.borderWidth?(b.style.borderWidth=O.borderWidth,b.style.borderStyle="solid"):(b.style.borderWidth="",b.style.borderStyle=""),O.borderColor?b.style.borderColor=O.borderColor:b.style.borderColor="",O.paddingX?(b.style.paddingLeft=O.paddingX,b.style.paddingRight=O.paddingX):(b.style.paddingLeft="",b.style.paddingRight=""),O.paddingY?(b.style.paddingTop=O.paddingY,b.style.paddingBottom=O.paddingY):(b.style.paddingTop="",b.style.paddingBottom="");let Ut=V==null?void 0:V.querySelector(".tvw-send-button-tooltip");if(Qt&&Nt)if(Ut)Ut.textContent=Nt,Ut.style.display="";else{let x=document.createElement("div");x.className="tvw-send-button-tooltip",x.textContent=Nt,V==null||V.insertBefore(x,b)}else Ut&&(Ut.style.display="none");let ge=(In=e.statusIndicator)!=null?In:{},Ve=(Hn=ge.visible)!=null?Hn:!0;if(nt.style.display=Ve?"":"none",$){let x=$.getStatus(),ot=it=>{var wt,K,re,St;return it==="idle"?(wt=ge.idleText)!=null?wt:yt.idle:it==="connecting"?(K=ge.connectingText)!=null?K:yt.connecting:it==="connected"?(re=ge.connectedText)!=null?re:yt.connected:it==="error"?(St=ge.errorText)!=null?St:yt.error:yt[it]};nt.textContent=ot(x)}},open(){o&&W(!0)},close(){o&&W(!1)},toggle(){o&&W(!C)},clearChat(){$.clearMessages();let r=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});window.dispatchEvent(r)},destroy(){At.forEach(r=>r()),A.remove(),G==null||G.destroy(),Ft&&T.removeEventListener("click",Ft)}}};var wn={},ao=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},lo=()=>{try{if(typeof wn!="undefined"&&wn.url)return new URL("../widget.css",wn.url).href}catch{}return null},jn=t=>{let n=lo(),e=()=>{if(!(t instanceof ShadowRoot)||t.querySelector("link[data-vanilla-agent]"))return;let s=document.head.querySelector("link[data-vanilla-agent]");if(!s)return;let o=s.cloneNode(!0);t.insertBefore(o,t.firstChild)};if(t instanceof ShadowRoot)if(n){let s=document.createElement("link");s.rel="stylesheet",s.href=n,s.setAttribute("data-vanilla-agent","true"),t.insertBefore(s,t.firstChild)}else e();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)}},hn=t=>{var L;let n=ao(t.target),e=document.createElement("div");e.className="vanilla-agent-host",n.appendChild(e);let s=t.useShadowDom!==!1,o,l;if(s){let C=e.attachShadow({mode:"open"});l=C,o=document.createElement("div"),o.id="vanilla-agent-root",C.appendChild(o),jn(C)}else l=e,o=document.createElement("div"),o.id="vanilla-agent-root",e.appendChild(o),jn(e);let a=Qe(o,t.config);return(L=t.onReady)==null||L.call(t),{host:e,update(C){a.update(C)},open(){a.open()},close(){a.close()},toggle(){a.toggle()},clearChat(){a.clearChat()},destroy(){a.destroy(),e.remove()}}};var co=hn;0&&(module.exports={AgentWidgetClient,AgentWidgetSession,DEFAULT_WIDGET_CONFIG,createAgentExperience,directivePostprocessor,escapeHtml,initAgentWidget,markdownPostprocessor,mergeWithDefaults,pluginRegistry});
14
14
  //# sourceMappingURL=index.cjs.map