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