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