vanilla-agent 0.2.0 → 1.1.0

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