vanilla-agent 1.3.0 → 1.4.1

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