vanilla-agent 1.2.0 → 1.3.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/README.md CHANGED
@@ -49,6 +49,7 @@ createAgentExperience(inlineHost, {
49
49
  // Floating launcher with runtime updates
50
50
  const controller = initAgentWidget({
51
51
  target: '#launcher-root',
52
+ windowKey: 'chatController', // Optional: stores controller on window.chatController
52
53
  config: {
53
54
  ...DEFAULT_WIDGET_CONFIG,
54
55
  apiUrl: proxyUrl,
@@ -69,12 +70,26 @@ controller.update({
69
70
  });
70
71
  ```
71
72
 
73
+ ### Initialization options
74
+
75
+ `initAgentWidget` accepts the following options:
76
+
77
+ | Option | Type | Description |
78
+ | --- | --- | --- |
79
+ | `target` | `string \| HTMLElement` | CSS selector or element where widget mounts. |
80
+ | `config` | `AgentWidgetConfig` | Widget configuration object (see [Configuration reference](#configuration-reference) below). |
81
+ | `useShadowDom` | `boolean` | Use Shadow DOM for style isolation (default: `true`). |
82
+ | `onReady` | `() => void` | Callback fired when widget is initialized. |
83
+ | `windowKey` | `string` | If provided, stores the controller on `window[windowKey]` for global access. Automatically cleaned up on `destroy()`. |
84
+
72
85
  > **Security note:** When you return HTML from `postprocessMessage`, make sure you sanitise it before injecting into the page. The provided postprocessors (`markdownPostprocessor`, `directivePostprocessor`) do not perform sanitisation.
73
86
 
74
87
 
75
88
  ### Programmatic control
76
89
 
77
- `initAgentWidget` (and `createAgentExperience`) return a controller with `open()`, `close()`, and `toggle()` helpers so you can launch the widget from your own UI elements.
90
+ `initAgentWidget` (and `createAgentExperience`) return a controller with methods to programmatically control the widget.
91
+
92
+ #### Basic controls
78
93
 
79
94
  ```ts
80
95
  const chat = initAgentWidget({
@@ -84,6 +99,89 @@ const chat = initAgentWidget({
84
99
 
85
100
  document.getElementById('open-chat')?.addEventListener('click', () => chat.open())
86
101
  document.getElementById('toggle-chat')?.addEventListener('click', () => chat.toggle())
102
+ document.getElementById('close-chat')?.addEventListener('click', () => chat.close())
103
+ ```
104
+
105
+ #### Message hooks
106
+
107
+ You can programmatically set messages, submit messages, and control voice recognition:
108
+
109
+ ```ts
110
+ const chat = initAgentWidget({
111
+ target: '#launcher-root',
112
+ config: { /* ... */ }
113
+ })
114
+
115
+ // Set a message in the input field (doesn't submit)
116
+ chat.setMessage("Hello, I need help")
117
+
118
+ // Submit a message (uses textarea value if no argument provided)
119
+ chat.submitMessage()
120
+ // Or submit a specific message
121
+ chat.submitMessage("What are your hours?")
122
+
123
+ // Start voice recognition
124
+ chat.startVoiceRecognition()
125
+
126
+ // Stop voice recognition
127
+ chat.stopVoiceRecognition()
128
+ ```
129
+
130
+ All hook methods return `boolean` indicating success (`true`) or failure (`false`). They will automatically open the widget if it's currently closed (when launcher is enabled).
131
+
132
+ #### Accessing from window
133
+
134
+ To access the controller globally (e.g., from browser console or external scripts), use the `windowKey` option:
135
+
136
+ ```ts
137
+ const chat = initAgentWidget({
138
+ target: '#launcher-root',
139
+ windowKey: 'chatController', // Stores controller on window.chatController
140
+ config: { /* ... */ }
141
+ })
142
+
143
+ // Now accessible globally
144
+ window.chatController.setMessage("Hello from console!")
145
+ window.chatController.submitMessage("Test message")
146
+ window.chatController.startVoiceRecognition()
147
+ ```
148
+
149
+ #### Message Types
150
+
151
+ The widget uses `AgentWidgetMessage` objects to represent messages in the conversation. You can access these through `postprocessMessage` callbacks or by inspecting the session's message array.
152
+
153
+ ```typescript
154
+ type AgentWidgetMessage = {
155
+ id: string; // Unique message identifier
156
+ role: "user" | "assistant" | "system";
157
+ content: string; // Message text content
158
+ createdAt: string; // ISO timestamp
159
+ streaming?: boolean; // Whether message is still streaming
160
+ variant?: "assistant" | "reasoning" | "tool";
161
+ sequence?: number; // Message ordering
162
+ reasoning?: AgentWidgetReasoning;
163
+ toolCall?: AgentWidgetToolCall;
164
+ tools?: AgentWidgetToolCall[];
165
+ viaVoice?: boolean; // Indicates if user message was sent via voice input
166
+ };
167
+ ```
168
+
169
+ **`viaVoice` field**: Set to `true` when a user message is sent through voice recognition. This allows you to implement voice-specific behaviors, such as automatically reactivating voice recognition after assistant responses. You can check this field in your `postprocessMessage` callback:
170
+
171
+ ```ts
172
+ postprocessMessage: ({ message, text, streaming }) => {
173
+ if (message.role === 'user' && message.viaVoice) {
174
+ console.log('User sent message via voice');
175
+ }
176
+ return text;
177
+ }
178
+ ```
179
+
180
+ Alternatively, manually assign the controller:
181
+
182
+ ```ts
183
+ const chat = initAgentWidget({ /* ... */ })
184
+ window.chatController = chat
87
185
  ```
88
186
 
89
187
  ### Travrse adapter
@@ -175,8 +273,9 @@ For more control, manually load CSS and JavaScript:
175
273
 
176
274
  <!-- Initialize widget -->
177
275
  <script>
178
- window.AgentWidget.initAgentWidget({
276
+ const chatController = window.AgentWidget.initAgentWidget({
179
277
  target: '#vanilla-agent-anchor', // or 'body' for floating launcher
278
+ windowKey: 'chatWidget', // Optional: stores controller on window.chatWidget
180
279
  config: {
181
280
  apiUrl: '/api/chat/dispatch',
182
281
  launcher: {
@@ -190,6 +289,9 @@ For more control, manually load CSS and JavaScript:
190
289
  }
191
290
  }
192
291
  });
292
+
293
+ // Controller is now available as window.chatWidget (if windowKey was used)
294
+ // or use the returned chatController variable
193
295
  </script>
194
296
  ```
195
297
 
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),to=t=>t.replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Fn=t=>`%%FORM_PLACEHOLDER_${t}%%`,eo=(t,n)=>{let e=t;return e=e.replace(/<Directive>([\s\S]*?)<\/Directive>/gi,(s,o)=>{try{let l=JSON.parse(o.trim());if(l&&typeof l=="object"&&l.component==="form"&&l.type){let 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(`
1
+ "use strict";var jn=Object.create;var Ge=Object.defineProperty;var Xn=Object.getOwnPropertyDescriptor;var Yn=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 Yn(n))!Gn.call(t,o)&&o!==e&&Ge(t,o,{get:()=>n[o],enumerable:!(s=Xn(n,o))||s.enumerable});return t};var Zn=(t,n,e)=>(e=t!=null?jn(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:()=>Xe});module.exports=Qn(uo);var en=require("marked");en.marked.setOptions({breaks:!0});var nn=t=>en.marked.parse(t),Je=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),to=t=>t.replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Fn=t=>`%%FORM_PLACEHOLDER_${t}%%`,eo=(t,n)=>{let e=t;return e=e.replace(/<Directive>([\s\S]*?)<\/Directive>/gi,(s,o)=>{try{let l=JSON.parse(o.trim());if(l&&typeof l=="object"&&l.component==="form"&&l.type){let 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,V,h,ct,Et,jt,Ft,D,bt,q,Kt,ye,Dt,j,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=f=>{let R=f.reasoning?{...f.reasoning,chunks:[...f.reasoning.chunks]}:void 0,P=f.toolCall?{...f.toolCall,chunks:f.toolCall.chunks?[...f.toolCall.chunks]:void 0}:void 0,J=f.tools?f.tools.map(r=>({...r,chunks:r.chunks?[...r.chunks]:void 0})):void 0;return{...f,reasoning:R,toolCall:P,tools:J}},y=f=>{e({type:"message",message:S(f)})},H=null,w=new Map,O=new Map,M={lastId:null,byStep:new Map},X={lastId:null,byCall:new Map},B=f=>{if(f==null)return null;try{return String(f)}catch{return null}},N=f=>{var R,P,J,r,v;return B((v=(r=(J=(P=(R=f.stepId)!=null?R:f.step_id)!=null?P:f.step)!=null?J:f.parentId)!=null?r:f.flowStepId)!=null?v:f.flow_step_id)},$=f=>{var R,P,J,r,v,I,u;return B((u=(I=(v=(r=(J=(P=(R=f.callId)!=null?R:f.call_id)!=null?P:f.requestId)!=null?J:f.request_id)!=null?r:f.toolCallId)!=null?v:f.tool_call_id)!=null?I:f.stepId)!=null?u:f.step_id)},L=()=>H||(H={id:`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"assistant",sequence:C()},y(H),H),dt=(f,R)=>{M.lastId=R,f&&M.byStep.set(f,R)},E=(f,R)=>{var v;let P=(v=f.reasoningId)!=null?v:f.id,J=N(f);if(P){let I=String(P);return dt(J,I),I}if(J){let I=M.byStep.get(J);if(I)return M.lastId=I,I}if(M.lastId&&!R)return M.lastId;if(!R)return null;let r=`reason-${C()}`;return dt(J,r),r},b=f=>{let R=w.get(f);if(R)return R;let P={id:`reason-${f}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"reasoning",sequence:C(),reasoning:{id:f,status:"streaming",chunks:[]}};return w.set(f,P),y(P),P},Y=(f,R)=>{X.lastId=R,f&&X.byCall.set(f,R)},Z=(f,R)=>{var v;let P=(v=f.toolId)!=null?v:f.id,J=$(f);if(P){let I=String(P);return Y(J,I),I}if(J){let I=X.byCall.get(J);if(I)return X.lastId=I,I}if(X.lastId&&!R)return X.lastId;if(!R)return null;let r=`tool-${C()}`;return Y(J,r),r},nt=f=>{let R=O.get(f);if(R)return R;let P={id:`tool-${f}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"tool",sequence:C(),toolCall:{id:f,status:"pending"}};return O.set(f,P),y(P),P},pt=f=>{if(typeof f=="number"&&Number.isFinite(f))return f;if(typeof f=="string"){let R=Number(f);if(!Number.isNaN(R)&&Number.isFinite(R))return R;let P=Date.parse(f);if(!Number.isNaN(P))return P}return Date.now()};for(;;){let{done:f,value:R}=await s.read();if(f)break;l+=o.decode(R,{stream:!0});let P=l.split(`
2
2
 
3
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=`
4
+ `),v="message",I="";for(let c of r)c.startsWith("event:")?v=c.replace("event:","").trim():c.startsWith("data:")&&(I+=c.replace("data:","").trim());if(!I)continue;let u;try{u=JSON.parse(I)}catch(c){e({type:"error",error:c instanceof Error?c:new Error("Failed to parse chat stream payload")});continue}let d=v!=="message"?v:(T=u.type)!=null?T:"message";if(d==="reason_start"){let c=(V=E(u,!0))!=null?V:`reason-${C()}`,a=b(c);a.reasoning=(h=a.reasoning)!=null?h:{id:c,status:"streaming",chunks:[]},a.reasoning.startedAt=(Et=a.reasoning.startedAt)!=null?Et:pt((ct=u.startedAt)!=null?ct:u.timestamp),a.reasoning.completedAt=void 0,a.reasoning.durationMs=void 0,a.streaming=!0,a.reasoning.status="streaming",y(a)}else if(d==="reason_chunk"){let c=(Ft=(jt=E(u,!1))!=null?jt:E(u,!0))!=null?Ft:`reason-${C()}`,a=b(c);a.reasoning=(D=a.reasoning)!=null?D:{id:c,status:"streaming",chunks:[]},a.reasoning.startedAt=(q=a.reasoning.startedAt)!=null?q:pt((bt=u.startedAt)!=null?bt:u.timestamp);let g=(Dt=(ye=(Kt=u.reasoningText)!=null?Kt:u.text)!=null?ye:u.delta)!=null?Dt:"";if(g&&u.hidden!==!0&&a.reasoning.chunks.push(String(g)),a.reasoning.status=u.done?"complete":"streaming",u.done){a.reasoning.completedAt=pt((j=u.completedAt)!=null?j:u.timestamp);let m=(Gt=a.reasoning.startedAt)!=null?Gt:Date.now();a.reasoning.durationMs=Math.max(0,((Jt=a.reasoning.completedAt)!=null?Jt:Date.now())-m)}a.streaming=a.reasoning.status!=="complete",y(a)}else if(d==="reason_complete"){let c=(xe=(be=E(u,!1))!=null?be:E(u,!0))!=null?xe:`reason-${C()}`,a=w.get(c);if(a!=null&&a.reasoning){a.reasoning.status="complete",a.reasoning.completedAt=pt((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&&X.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=H;if(a){let g=a;g.streaming=!1,y(g)}}e({type:"status",status:"idle"})}else d==="error"&&u.error&&e({type:"error",error:u.error instanceof Error?u.error:new Error(String(u.error))})}}}};var 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,e){var A,C,S,y,H;let s=n.trim();if(!s)return;(A=this.abortController)==null||A.abort();let o={id:`user-${Date.now()}`,role:"user",content:s,createdAt:new Date().toISOString(),sequence:this.nextSequence(),viaVoice:(e==null?void 0:e.viaVoice)||!1};this.appendMessage(o),this.setStreaming(!0);let l=new AbortController;this.abortController=l;let i=[...this.messages];try{await this.client.dispatch({messages:i,signal:l.signal},this.handleEvent)}catch(w){let O={id:`assistant-${Date.now()}`,role:"assistant",createdAt:new Date().toISOString(),content:"It looks like the proxy isn't returning a real response yet. Here's a sample message so you can continue testing locally.",sequence:this.nextSequence()};this.appendMessage(O),this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,w instanceof Error?(S=(C=this.callbacks).onError)==null||S.call(C,w):(H=(y=this.callbacks).onError)==null||H.call(y,new Error(String(w)))}}cancel(){var n;(n=this.abortController)==null||n.abort(),this.abortController=null,this.setStreaming(!1),this.setStatus("idle")}clearMessages(){var n;(n=this.abortController)==null||n.abort(),this.abortController=null,this.messages=[],this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}setStatus(n){this.status!==n&&(this.status=n,this.callbacks.onStatusChanged(n))}setStreaming(n){this.streaming!==n&&(this.streaming=n,this.callbacks.onStreamingChanged(n))}appendMessage(n){let e=this.ensureSequence(n);this.messages=this.sortMessages([...this.messages,e]),this.callbacks.onMessagesChanged([...this.messages])}upsertMessage(n){let e=this.ensureSequence(n),s=this.messages.findIndex(o=>o.id===e.id);if(s===-1){this.appendMessage(e);return}this.messages=this.messages.map((o,l)=>l===s?{...o,...e}:o),this.messages=this.sortMessages(this.messages),this.callbacks.onMessagesChanged([...this.messages])}ensureSequence(n){return n.sequence!==void 0?{...n}:{...n,sequence:this.nextSequence()}}nextSequence(){return this.sequenceCounter++}sortMessages(n){return[...n].sort((e,s)=>{var C,S;let o=new Date(e.createdAt).getTime(),l=new Date(s.createdAt).getTime();if(!Number.isNaN(o)&&!Number.isNaN(l)&&o!==l)return o-l;let i=(C=e.sequence)!=null?C:0,A=(S=s.sequence)!=null?S:0;return i!==A?i-A:e.id.localeCompare(s.id)})}};var 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,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&&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&&gt){Bt=p("div","tvw-send-button-wrapper"),z=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),z.type="button",z.setAttribute("aria-label","Start voice recognition");let k=(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&&gt&&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});
12
+ `,e.addEventListener("click",n);let s=l=>{var X,B,N,$,L,dt,E,b,Y,Z;let i=(X=l.launcher)!=null?X:{},A=e.querySelector("[data-role='launcher-title']");A&&(A.textContent=(B=i.title)!=null?B:"Chat Assistant");let C=e.querySelector("[data-role='launcher-subtitle']");C&&(C.textContent=(N=i.subtitle)!=null?N:"Get answers fast");let S=e.querySelector(".tvw-flex-col");S&&(i.textHidden?S.style.display="none":S.style.display="");let y=e.querySelector("[data-role='launcher-icon']");if(y)if(i.agentIconHidden)y.style.display="none";else{let nt=($=i.agentIconSize)!=null?$:"40px";if(y.style.height=nt,y.style.width=nt,y.innerHTML="",i.agentIconName){let pt=parseFloat(nt)||24,Ct=ht(i.agentIconName,pt*.6,"#ffffff",2);Ct?(y.appendChild(Ct),y.style.display=""):(y.textContent=(L=i.agentIconText)!=null?L:"\u{1F4AC}",y.style.display="")}else i.iconUrl?y.style.display="none":(y.textContent=(dt=i.agentIconText)!=null?dt:"\u{1F4AC}",y.style.display="")}let H=e.querySelector("[data-role='launcher-image']");if(H){let nt=(E=i.agentIconSize)!=null?E:"40px";H.style.height=nt,H.style.width=nt,i.iconUrl&&!i.agentIconName&&!i.agentIconHidden?(H.src=i.iconUrl,H.style.display="block"):H.style.display="none"}let w=e.querySelector("[data-role='launcher-call-to-action-icon']");if(w){let nt=(b=i.callToActionIconSize)!=null?b:"32px";w.style.height=nt,w.style.width=nt,i.callToActionIconBackgroundColor?(w.style.backgroundColor=i.callToActionIconBackgroundColor,w.classList.remove("tvw-bg-cw-primary")):(w.style.backgroundColor="",w.classList.add("tvw-bg-cw-primary"));let pt=0;if(i.callToActionIconPadding?(w.style.boxSizing="border-box",w.style.padding=i.callToActionIconPadding,pt=(parseFloat(i.callToActionIconPadding)||0)*2):(w.style.boxSizing="",w.style.padding=""),i.callToActionIconHidden)w.style.display="none";else if(w.style.display="",w.innerHTML="",i.callToActionIconName){let Ct=parseFloat(nt)||24,T=Math.max(Ct-pt,8),V=ht(i.callToActionIconName,T,"currentColor",2);V?w.appendChild(V):w.textContent=(Y=i.callToActionIconText)!=null?Y:"\u2197"}else w.textContent=(Z=i.callToActionIconText)!=null?Z:"\u2197"}let O=i.position&&he[i.position]?he[i.position]:he["bottom-right"],M="tvw-fixed tvw-flex tvw-items-center tvw-gap-3 tvw-rounded-launcher tvw-bg-cw-surface tvw-py-2.5 tvw-pl-3 tvw-pr-3 tvw-shadow-lg tvw-border tvw-border-gray-200 tvw-transition hover:tvw-translate-y-[-2px] tvw-cursor-pointer";e.className=`${M} ${O}`},o=()=>{e.removeEventListener("click",n),e.remove()};return t&&s(t),{element:e,update:s,destroy:o}};var qn=t=>{var C,S,y,H,w;if(!((S=(C=t==null?void 0:t.launcher)==null?void 0:C.enabled)!=null?S:!0)){let O=p("div","tvw-relative tvw-w-full tvw-h-full"),M=p("div","tvw-relative tvw-w-full tvw-h-full tvw-min-h-[360px]");return O.appendChild(M),{wrapper:O,panel:M}}let e=(y=t==null?void 0:t.launcher)!=null?y:{},s=e.position&&he[e.position]?he[e.position]:he["bottom-right"],o=p("div",`tvw-fixed ${s} tvw-z-50 tvw-transition`),l=p("div","tvw-relative tvw-min-h-[320px]"),i=(w=(H=t==null?void 0:t.launcher)==null?void 0:H.width)!=null?w:t==null?void 0:t.launcherWidth,A=i!=null?i:"min(400px, calc(100vw - 24px))";return l.style.width=A,l.style.maxWidth=A,o.appendChild(l),{wrapper:o,panel:l}},zn=(t,n=!0)=>{var se,ie,Tt,Te,Zt,ae,K,zt,le,de,Ee,ce,ue,pe,ge,me,f,R,P,J,r,v,I,u,d,c,a,g,m,F,rt,mt,st,_,Pt,$t,Ot,Nt,Qt,_t,Xt,vt,Ut,we,Ye,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 H=p("div","tvw-flex tvw-flex-col"),w=p("span","tvw-text-base tvw-font-semibold");w.textContent=(ce=(Ee=t==null?void 0:t.launcher)==null?void 0:Ee.title)!=null?ce:"Chat Assistant";let O=p("span","tvw-text-xs tvw-text-cw-muted");O.textContent=(pe=(ue=t==null?void 0:t.launcher)==null?void 0:ue.subtitle)!=null?pe:"Here to help you get answers fast",H.append(w,O),C?s.append(H):s.append(y,H);let M=(ge=o.clearChat)!=null?ge:{},X=(me=M.enabled)!=null?me:!0,B=null,N=null;if(X){let k=(f=M.size)!=null?f:"32px",tt=(R=M.iconName)!=null?R:"refresh-cw",wt=(P=M.iconColor)!=null?P:"",Vt=(J=M.backgroundColor)!=null?J:"",St=(r=M.borderWidth)!=null?r:"",te=(v=M.borderColor)!=null?v:"",fe=(I=M.borderRadius)!=null?I:"",ee=(u=M.paddingX)!=null?u:"",Se=(d=M.paddingY)!=null?d:"",ne=(c=M.tooltipText)!=null?c:"Clear chat",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 Ve=ht(tt,"20px",wt||"",2);if(Ve&&B.appendChild(Ve),wt&&(B.style.color=wt,B.classList.remove("tvw-text-cw-muted")),Vt&&(B.style.backgroundColor=Vt,B.classList.remove("hover:tvw-bg-gray-100")),St||te){let lt=St||"0px",oe=te||"transparent";B.style.border=`${lt} solid ${oe}`,B.classList.remove("tvw-border-none")}if(fe&&(B.style.borderRadius=fe,B.classList.remove("tvw-rounded-full")),ee?(B.style.paddingLeft=ee,B.style.paddingRight=ee):(B.style.paddingLeft="",B.style.paddingRight=""),Se?(B.style.paddingTop=Se,B.style.paddingBottom=Se):(B.style.paddingTop="",B.style.paddingBottom=""),N.appendChild(B),Ke&&ne&&B&&N){let lt=null,oe=()=>{if(lt||!B)return;lt=p("div","tvw-clear-chat-tooltip"),lt.textContent=ne;let je=p("div");je.className="tvw-clear-chat-tooltip-arrow",lt.appendChild(je);let 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&&lt.parentNode&&(lt.parentNode.removeChild(lt),lt=null)};N.addEventListener("mouseenter",oe),N.addEventListener("mouseleave",ve),B.addEventListener("focus",oe),B.addEventListener("blur",ve),N._cleanupTooltip=()=>{ve(),N&&(N.removeEventListener("mouseenter",oe),N.removeEventListener("mouseleave",ve)),B&&(B.removeEventListener("focus",oe),B.removeEventListener("blur",ve))}}s.appendChild(N)}let $=p("div",A==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50":X?"":"tvw-ml-auto"),L=p("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none");L.style.height=i,L.style.width=i,L.type="button";let dt=(g=o.closeButtonTooltipText)!=null?g:"Close chat",E=(m=o.closeButtonShowTooltip)!=null?m:!0;L.setAttribute("aria-label",dt),L.style.display=n?"":"none";let b=(F=o.closeButtonIconName)!=null?F:"x",Y=(rt=o.closeButtonIconText)!=null?rt:"\xD7",Z=ht(b,"20px",o.closeButtonColor||"",2);if(Z?L.appendChild(Z):L.textContent=Y,o.closeButtonColor?(L.style.color=o.closeButtonColor,L.classList.remove("tvw-text-cw-muted")):(L.style.color="",L.classList.add("tvw-text-cw-muted")),o.closeButtonBackgroundColor?(L.style.backgroundColor=o.closeButtonBackgroundColor,L.classList.remove("hover:tvw-bg-gray-100")):(L.style.backgroundColor="",L.classList.add("hover:tvw-bg-gray-100")),o.closeButtonBorderWidth||o.closeButtonBorderColor){let k=o.closeButtonBorderWidth||"0px",tt=o.closeButtonBorderColor||"transparent";L.style.border=`${k} solid ${tt}`,L.classList.remove("tvw-border-none")}else L.style.border="",L.classList.add("tvw-border-none");if(o.closeButtonBorderRadius?(L.style.borderRadius=o.closeButtonBorderRadius,L.classList.remove("tvw-rounded-full")):(L.style.borderRadius="",L.classList.add("tvw-rounded-full")),o.closeButtonPaddingX?(L.style.paddingLeft=o.closeButtonPaddingX,L.style.paddingRight=o.closeButtonPaddingX):(L.style.paddingLeft="",L.style.paddingRight=""),o.closeButtonPaddingY?(L.style.paddingTop=o.closeButtonPaddingY,L.style.paddingBottom=o.closeButtonPaddingY):(L.style.paddingTop="",L.style.paddingBottom=""),$.appendChild(L),E&&dt){let k=null,tt=()=>{if(k)return;k=p("div","tvw-clear-chat-tooltip"),k.textContent=dt;let Vt=p("div");Vt.className="tvw-clear-chat-tooltip-arrow",k.appendChild(Vt);let St=L.getBoundingClientRect();k.style.position="fixed",k.style.left=`${St.left+St.width/2}px`,k.style.top=`${St.top-8}px`,k.style.transform="translate(-50%, -100%)",document.body.appendChild(k)},wt=()=>{k&&k.parentNode&&(k.parentNode.removeChild(k),k=null)};$.addEventListener("mouseenter",tt),$.addEventListener("mouseleave",wt),L.addEventListener("focus",tt),L.addEventListener("blur",wt),$._cleanupTooltip=()=>{wt(),$.removeEventListener("mouseenter",tt),$.removeEventListener("mouseleave",wt),L.removeEventListener("focus",tt),L.removeEventListener("blur",wt)}}A==="top-right"?(e.style.position="relative",e.appendChild($)):s.appendChild($);let nt=p("div","tvw-flex tvw-flex-1 tvw-min-h-0 tvw-flex-col tvw-gap-6 tvw-overflow-y-auto tvw-bg-cw-container tvw-px-6 tvw-py-6"),pt=p("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),Ct=p("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");Ct.textContent=(st=(mt=t==null?void 0:t.copy)==null?void 0:mt.welcomeTitle)!=null?st:"Hello \u{1F44B}";let T=p("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");T.textContent=(Pt=(_=t==null?void 0:t.copy)==null?void 0:_.welcomeSubtitle)!=null?Pt:"Ask anything about your account or products.",pt.append(Ct,T);let V=p("div","tvw-flex tvw-flex-col tvw-gap-3");nt.append(pt,V);let h=p("div","tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),ct=p("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),Et=(($t=t==null?void 0:t.voiceRecognition)==null?void 0:$t.enabled)===!0,jt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),bt=p("form",`tvw-flex tvw-items-end ${Et&&jt?"tvw-gap-1":"tvw-gap-3"} tvw-rounded-2xl tvw-border tvw-border-gray-200 tvw-bg-cw-input-background tvw-px-4 tvw-py-3`);bt.style.outline="none";let q=p("textarea");q.placeholder=(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=(Xt=t==null?void 0:t.theme)==null?void 0:Xt.inputFontWeight)!=null?vt:"400",Dt=k=>{switch(k){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};q.style.fontFamily=Dt(Kt),q.style.fontWeight=ye,q.style.border="none",q.style.outline="none",q.style.borderWidth="0",q.style.borderStyle="none",q.style.borderColor="transparent",q.addEventListener("focus",()=>{q.style.border="none",q.style.outline="none",q.style.borderWidth="0",q.style.borderStyle="none",q.style.borderColor="transparent",q.style.boxShadow="none"}),q.addEventListener("blur",()=>{q.style.border="none",q.style.outline="none"});let j=(Ut=t==null?void 0:t.sendButton)!=null?Ut:{},Gt=(we=j.useIcon)!=null?we:!1,Jt=(Ye=j.iconText)!=null?Ye:"\u2191",be=j.iconName,xe=(We=j.tooltipText)!=null?We:"Send message",Ae=(ke=j.showTooltip)!=null?ke:!1,It=(Ie=j.size)!=null?Ie:"40px",qt=j.backgroundColor,at=j.textColor,Mt=p("div","tvw-send-button-wrapper"),W=p("button",Gt?"tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer":"tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold disabled:tvw-opacity-50 tvw-cursor-pointer");if(W.type="submit",Gt){if(W.style.width=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(j.borderWidth&&(W.style.borderWidth=j.borderWidth,W.style.borderStyle="solid"),j.borderColor&&(W.style.borderColor=j.borderColor),j.paddingX?(W.style.paddingLeft=j.paddingX,W.style.paddingRight=j.paddingX):(W.style.paddingLeft="",W.style.paddingRight=""),j.paddingY?(W.style.paddingTop=j.paddingY,W.style.paddingBottom=j.paddingY):(W.style.paddingTop="",W.style.paddingBottom=""),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&&gt){Bt=p("div","tvw-send-button-wrapper"),z=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),z.type="button",z.setAttribute("aria-label","Start voice recognition");let k=(Fe=Q.iconName)!=null?Fe:"mic",tt=(De=Q.iconSize)!=null?De:It,wt=parseFloat(tt)||24,Vt=(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),Vt?z.style.backgroundColor=Vt:z.classList.add("tvw-bg-cw-primary"),St?z.style.color=St:!St&&!at&&z.classList.add("tvw-text-white"),Q.borderWidth&&(z.style.borderWidth=Q.borderWidth,z.style.borderStyle="solid"),Q.borderColor&&(z.style.borderColor=Q.borderColor),Q.paddingX&&(z.style.paddingLeft=Q.paddingX,z.style.paddingRight=Q.paddingX),Q.paddingY&&(z.style.paddingTop=Q.paddingY,z.style.paddingBottom=Q.paddingY),Bt.appendChild(z);let ee=(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:V,suggestions:ct,textarea:q,sendButton:W,sendButtonWrapper:Mt,micButton:z,micButtonWrapper:Bt,composerForm:bt,statusText:ut,introTitle:Ct,introSubtitle:T,closeButton:L,closeButtonWrapper:$,clearChatButton:B,clearChatButtonWrapper:N,iconHolder:y}};var 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(""),H=p("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");H.textContent=y||(n.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),S.appendChild(H);let w=()=>{o.setAttribute("aria-expanded",s?"true":"false"),C.textContent=s?"Hide":"Show",S.style.display=s?"":"none"},O=()=>{s=!s,s?dn.add(t.id):dn.delete(t.id),w()};return o.addEventListener("pointerdown",M=>{M.preventDefault(),O()}),o.addEventListener("keydown",M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),O())}),w(),e.append(o,S),e};var 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 w=p("span","tvw-text-[11px] tvw-text-cw-muted");w.textContent=n.name,l.appendChild(w)}let A=p("span","tvw-text-xs tvw-text-cw-primary");A.textContent=s?"Hide":"Show";let C=p("div","tvw-flex tvw-items-center tvw-gap-2");C.append(A),o.append(l,C);let S=p("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(S.style.display=s?"":"none",n.args!==void 0){let w=p("div","tvw-space-y-1"),O=p("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");O.textContent="Arguments";let M=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-font-xxs tvw-text-cw-primary");M.textContent=ln(n.args),w.append(O,M),S.appendChild(w)}if(n.chunks&&n.chunks.length){let w=p("div","tvw-space-y-1"),O=p("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");O.textContent="Activity";let M=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-font-xxs tvw-text-cw-primary");M.textContent=n.chunks.join(`
13
+ `),w.append(O,M),S.appendChild(w)}if(n.status==="complete"&&n.result!==void 0){let w=p("div","tvw-space-y-1"),O=p("div","tvw-font-xxs tvw-text-sm tvw-text-cw-muted");O.textContent="Result";let M=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-font-xxs tvw-text-cw-primary");M.textContent=ln(n.result),w.append(O,M),S.appendChild(w)}if(n.status==="complete"&&typeof n.duration=="number"){let w=p("div","tvw-font-xxs tvw-text-cw-muted");w.textContent=`Duration: ${n.duration}ms`,S.appendChild(w)}let y=()=>{o.setAttribute("aria-expanded",s?"true":"false"),A.textContent=s?"Hide":"Show",S.style.display=s?"":"none"},H=()=>{s=!s,s?un.add(t.id):un.delete(t.id),y()};return o.addEventListener("pointerdown",w=>{w.preventDefault(),H()}),o.addEventListener("keydown",w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),H())}),y(),e.append(o,S),e};var 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(H=>H.role==="user"))return;let S=document.createDocumentFragment(),y=o?o.isStreaming():!1;s.forEach(H=>{let w=p("button","tvw-rounded-button tvw-bg-cw-surface tvw-px-3 tvw-py-1.5 tvw-text-xs tvw-font-medium tvw-text-cw-muted hover:tvw-opacity-90 tvw-cursor-pointer tvw-border tvw-border-gray-200");w.type="button",w.textContent=H,w.disabled=y,w.addEventListener("click",()=>{!o||o.isStreaming()||(l.value="",o.sendMessage(H))}),S.appendChild(w),n.push(w)}),t.appendChild(S)}}};var _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,X,B;if(l.dataset.enhanced==="true")return;let i=(M=l.dataset.tvForm)!=null?M:"init";l.dataset.enhanced="true";let A=(X=_n[i])!=null?X:_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,Y;let $=p("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");$.htmlFor=`${n.id}-${i}-${N.name}`;let L=p("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");L.textContent=N.label,$.appendChild(L);let dt=(b=N.type)!=null?b:"text",E;dt==="textarea"?(E=document.createElement("textarea"),E.rows=3):(E=document.createElement("input"),E.type=dt),E.className="tvw-rounded-xl tvw-border tvw-border-gray-200 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-cw-primary",E.id=`${n.id}-${i}-${N.name}`,E.name=N.name,E.placeholder=(Y=N.placeholder)!=null?Y:"",N.required&&(E.required=!0),$.appendChild(E),y.appendChild($)});let H=p("div","tvw-flex tvw-items-center tvw-justify-between tvw-gap-2"),w=p("div","tvw-text-xs tvw-text-cw-muted tvw-min-h-[1.5rem]"),O=p("button","tvw-inline-flex tvw-items-center tvw-rounded-full tvw-bg-cw-primary tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-60 tvw-cursor-pointer");O.type="submit",O.textContent=(B=A.submitLabel)!=null?B:"Submit",H.appendChild(w),H.appendChild(O),y.appendChild(H),l.replaceChildren(C,y),y.addEventListener("submit",async N=>{var E,b;N.preventDefault();let $=(E=e.formEndpoint)!=null?E:"/form",L=new FormData(y),dt={};L.forEach((Y,Z)=>{dt[Z]=Y}),dt.type=i,O.disabled=!0,w.textContent="Submitting\u2026";try{let Y=await fetch($,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(dt)});if(!Y.ok)throw new Error(`Form submission failed (${Y.status})`);let Z=await Y.json();w.textContent=(b=Z.message)!=null?b:"Thanks! We'll be in touch soon.",Z.success&&Z.nextPrompt&&await s.sendMessage(String(Z.nextPrompt))}catch(Y){w.textContent=Y instanceof Error?Y.message:"Something went wrong. Please try again."}finally{O.disabled=!1}})})};var 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()}},Xe=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,f,R,P,J;(!t.id||t.id!=="vanilla-agent-root")&&(t.id="vanilla-agent-root");let e=Ze(n);on(t,e);let s=Xe.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=(f=(me=e.features)==null?void 0:me.showReasoning)!=null?f:!0,H=(P=(R=e.features)==null?void 0:R.showToolCalls)!=null?P:!0,w=(J=e.statusIndicator)!=null?J:{},O=r=>{var v,I,u,d;return r==="idle"?(v=w.idleText)!=null?v:yt.idle:r==="connecting"?(I=w.connectingText)!=null?I:yt.connecting:r==="connected"?(u=w.connectedText)!=null?u:yt.connected:r==="error"?(d=w.errorText)!=null?d:yt.error:yt[r]},{wrapper:M,panel:X}=qn(e),B=zn(e,o),{container:N,body:$,messagesWrapper:L,suggestions:dt,textarea:E,sendButton:b,sendButtonWrapper:Y,composerForm:Z,statusText:nt,introTitle:pt,introSubtitle:Ct,closeButton:T,iconHolder:V}=B,h=B.micButton,ct=B.micButtonWrapper;X.appendChild(N),t.appendChild(M);let Et=[],jt=On(dt),Ft=null,D,bt=!1,q=!0,Kt=0,ye=0,Dt=null,j=!1,Gt=0,Jt=!1,be=125,xe=2e3,Ae=5,It=50,qt=(r=!1)=>{if(!q)return;let v=Date.now();j&&v<Gt&&!r||(j&&v>=Gt&&(j=!1),!(!r&&!bt)&&(v-ye<be||(ye=v,Dt&&cancelAnimationFrame(Dt),Dt=requestAnimationFrame(()=>{j||!q||(Jt=!0,$.scrollTop=$.scrollHeight,Kt=$.scrollTop,requestAnimationFrame(()=>{Jt=!1}),Dt=null)}))))},at=(r,v,I)=>{r.innerHTML="";let u=document.createDocumentFragment();v.forEach(c=>{let a=null,g=s.find(F=>!!(c.variant==="reasoning"&&F.renderReasoning||c.variant==="tool"&&F.renderToolCall||!c.variant&&F.renderMessage));if(g)if(c.variant==="reasoning"&&c.reasoning&&g.renderReasoning){if(!y)return;a=g.renderReasoning({message:c,defaultRenderer:()=>cn(c),config:e})}else if(c.variant==="tool"&&c.toolCall&&g.renderToolCall){if(!H)return;a=g.renderToolCall({message:c,defaultRenderer:()=>pn(c),config:e})}else g.renderMessage&&(a=g.renderMessage({message:c,defaultRenderer:()=>{let F=an(c,I);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(!H)return;a=pn(c)}else a=an(c,I),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"),X.classList.remove("tvw-scale-95","tvw-opacity-0"),X.classList.add("tvw-scale-100","tvw-opacity-100"),K&&(K.element.style.display="none")):(M.classList.add("tvw-pointer-events-none","tvw-opacity-0"),X.classList.remove("tvw-scale-100","tvw-opacity-100"),X.classList.add("tvw-scale-95","tvw-opacity-0"),K&&(K.element.style.display="")))},W=r=>{o&&C!==r&&(C=r,Mt(),C&&(zt(),qt(!0)))},Q=r=>{E.disabled=r,b.disabled=r,h&&(h.disabled=r),jt.buttons.forEach(v=>{v.disabled=r})},Ce=()=>{var d,c,a,g,m,F,rt,mt,st,_,Pt,$t,Ot,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=(_=(st=e.copy)==null?void 0:st.sendButtonLabel)!=null?_:"Send");let v=($t=(Pt=e.theme)==null?void 0:Pt.inputFontFamily)!=null?$t:"sans-serif",I=(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=I};D=new Be(e,{onMessagesChanged(r){at(L,r,S),D&&(r.some(I=>I.role==="user")?jt.render([],D,E,r):jt.render(e.suggestionChips,D,E,r)),qt(!bt)},onStatusChanged(r){var u;let v=(u=e.statusIndicator)!=null?u:{},I=d=>{var c,a,g,m;return d==="idle"?(c=v.idleText)!=null?c:yt.idle:d==="connecting"?(a=v.connectingText)!=null?a:yt.connecting:d==="connected"?(g=v.connectedText)!=null?g:yt.connected:d==="error"?(m=v.errorText)!=null?m:yt.error:yt[d]};nt.textContent=I(r)},onStreamingChanged(r){bt=r,Q(r),D&&at(L,D.getMessages(),S),r||qt(!0)}});let z=r=>{r.preventDefault();let v=E.value.trim();v&&(E.value="",D.sendMessage(v))},Bt=r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),b.click())},gt=null,ut=!1,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 I=(c=((d=e.voiceRecognition)!=null?d:{}).pauseDuration)!=null?c:2e3;gt.continuous=!0,gt.interimResults=!0,gt.lang="en-US";let u=E.value;gt.onresult=m=>{let F="",rt="";for(let st=0;st<m.results.length;st++){let _=m.results[st],Pt=_[0].transcript;_.isFinal?F+=Pt+" ":rt=Pt}let mt=u+F+rt;E.value=mt,Ht&&clearTimeout(Ht),(F||rt)&&(Ht=window.setTimeout(()=>{let st=E.value.trim();st&&gt&&ut&&(Tt(),E.value="",D.sendMessage(st,{viaVoice:!0}))},I))},gt.onerror=m=>{m.error!=="no-speech"&&Tt()},gt.onend=()=>{if(ut){let m=E.value.trim();m&&m!==u.trim()&&(E.value="",D.sendMessage(m,{viaVoice:!0})),Tt()}};try{if(gt.start(),ut=!0,h){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,Xt,vt;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let u=p("div","tvw-send-button-wrapper"),d=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");d.type="button",d.setAttribute("aria-label","Start voice recognition");let c=($t=r==null?void 0:r.iconName)!=null?$t:"mic",a=(Ot=v==null?void 0:v.size)!=null?Ot:"40px",g=(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 _=(Xt=r==null?void 0:r.tooltipText)!=null?Xt:"Start voice recognition";if(((vt=r==null?void 0:r.showTooltip)!=null?vt:!1)&&_){let Ut=p("div","tvw-send-button-tooltip");Ut.textContent=_,u.appendChild(Ut)}return{micButton:d,micButtonWrapper:u}},Zt=()=>{if(ut){let r=E.value.trim();Tt(),r&&(E.value="",D.sendMessage(r))}else ie()};h&&(h.addEventListener("click",Zt),Et.push(()=>{Tt(),h&&h.removeEventListener("click",Zt)}));let ae=()=>{W(!C)},K=o?rn(e,ae):null;K&&t.appendChild(K.element),Mt(),jt.render(e.suggestionChips,D,E),Ce(),Q(D.isStreaming()),qt(!0);let zt=()=>{var a,g;if(!o){X.style.height="",X.style.width="";return}let r=(g=(a=e==null?void 0:e.launcher)==null?void 0:a.width)!=null?g:e==null?void 0:e.launcherWidth,v=r!=null?r:"min(400px, calc(100vw - 24px))";X.style.width=v,X.style.maxWidth=v;let I=window.innerHeight,d=Math.max(200,I-64),c=Math.min(640,d);X.style.height=`${c}px`};zt(),window.addEventListener("resize",zt),Et.push(()=>window.removeEventListener("resize",zt)),Kt=$.scrollTop;let le=()=>{let r=$.scrollTop,v=$.scrollHeight,I=$.clientHeight,u=v-r-I,d=Math.abs(r-Kt);if(Kt=r,!Jt&&!(d<=Ae)){if(!q&&u<It){j=!1,q=!0;return}q&&u>It&&(j=!0,Gt=Date.now()+xe,q=!1)}};$.addEventListener("scroll",le,{passive:!0}),Et.push(()=>$.removeEventListener("scroll",le)),Et.push(()=>{Dt&&cancelAnimationFrame(Dt)});let de=()=>{T&&(Ft&&(T.removeEventListener("click",Ft),Ft=null),o?(T.style.display="",Ft=()=>{C=!1,Mt()},T.addEventListener("click",Ft)):T.style.display="none")};return de(),(()=>{let{clearChatButton:r}=B;r&&r.addEventListener("click",()=>{D.clearMessages();let v=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});window.dispatchEvent(v)})})(),Z.addEventListener("submit",z),E.addEventListener("keydown",Bt),Et.push(()=>{Z.removeEventListener("submit",z),E.removeEventListener("keydown",Bt)}),Et.push(()=>{D.cancel()}),K&&Et.push(()=>{K==null||K.destroy()}),{update(r){var We,ke,Ie,He,Re,Ne,Fe,De,qe,ze,Pe,$e,Oe,_e,Ue,k,tt,wt,Vt,St,te,fe,ee,Se,ne,Ke,Ve,lt,oe,ve,je,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=Xe.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,H=(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(V){let x=N.querySelector(".tvw-border-b-cw-divider"),ot=x==null?void 0:x.querySelector(".tvw-flex-col");if(c)V.style.display="none",x&&ot&&!x.contains(ot)&&x.insertBefore(ot,x.firstChild);else{if(V.style.display="",V.style.height=g,V.style.width=g,x&&ot&&(x.contains(V)?V.nextSibling!==ot&&(V.remove(),x.insertBefore(V,ot)):x.insertBefore(V,ot)),a){let ft=parseFloat(g)||24,G=ht(a,ft*.6,"#ffffff",2);G?V.replaceChildren(G):V.textContent=(_e=d.agentIconText)!=null?_e:"\u{1F4AC}"}else if(d.iconUrl){let ft=V.querySelector("img");if(ft)ft.src=d.iconUrl,ft.style.height=g,ft.style.width=g;else{let G=document.createElement("img");G.src=d.iconUrl,G.alt="",G.className="tvw-rounded-xl tvw-object-cover",G.style.height=g,G.style.width=g,V.replaceChildren(G)}}else{let ft=V.querySelector("svg"),G=V.querySelector("img");(ft||G)&&V.replaceChildren(),V.textContent=(Ue=d.agentIconText)!=null?Ue:"\u{1F4AC}"}let it=V.querySelector("img");it&&(it.style.height=g,it.style.width=g)}}if(T){let x=(k=d.closeButtonSize)!=null?k:"32px",ot=(tt=d.closeButtonPlacement)!=null?tt:"inline";T.style.height=x,T.style.width=x;let it=ot==="top-right",ft=T.classList.contains("tvw-absolute");if(it!==ft)if(T.remove(),it)T.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50 tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none",N.style.position="relative",N.appendChild(T);else{T.className="tvw-ml-auto tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none";let U=N.querySelector(".tvw-border-b-cw-divider");U&&U.appendChild(T)}if(d.closeButtonColor?(T.style.color=d.closeButtonColor,T.classList.remove("tvw-text-cw-muted")):(T.style.color="",T.classList.add("tvw-text-cw-muted")),d.closeButtonBackgroundColor?(T.style.backgroundColor=d.closeButtonBackgroundColor,T.classList.remove("hover:tvw-bg-gray-100")):(T.style.backgroundColor="",T.classList.add("hover:tvw-bg-gray-100")),d.closeButtonBorderWidth||d.closeButtonBorderColor){let U=d.closeButtonBorderWidth||"0px",Yt=d.closeButtonBorderColor||"transparent";T.style.border=`${U} solid ${Yt}`,T.classList.remove("tvw-border-none")}else T.style.border="",T.classList.add("tvw-border-none");d.closeButtonBorderRadius?(T.style.borderRadius=d.closeButtonBorderRadius,T.classList.remove("tvw-rounded-full")):(T.style.borderRadius="",T.classList.add("tvw-rounded-full")),d.closeButtonPaddingX?(T.style.paddingLeft=d.closeButtonPaddingX,T.style.paddingRight=d.closeButtonPaddingX):(T.style.paddingLeft="",T.style.paddingRight=""),d.closeButtonPaddingY?(T.style.paddingTop=d.closeButtonPaddingY,T.style.paddingBottom=d.closeButtonPaddingY):(T.style.paddingTop="",T.style.paddingBottom="");let G=(wt=d.closeButtonIconName)!=null?wt:"x",re=(Vt=d.closeButtonIconText)!=null?Vt:"\xD7";T.innerHTML="";let Lt=ht(G,"20px",d.closeButtonColor||"",2);Lt?T.appendChild(Lt):T.textContent=re;let{closeButtonWrapper:xt}=B,et=(St=d.closeButtonTooltipText)!=null?St:"Close chat",At=(te=d.closeButtonShowTooltip)!=null?te:!0;if(T.setAttribute("aria-label",et),xt&&(xt._cleanupTooltip&&(xt._cleanupTooltip(),delete xt._cleanupTooltip),At&&et)){let U=null,Yt=()=>{if(U||!T)return;U=p("div","tvw-clear-chat-tooltip"),U.textContent=et;let 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",Yt),xt.addEventListener("mouseleave",Wt),T.addEventListener("focus",Yt),T.addEventListener("blur",Wt),xt._cleanupTooltip=()=>{Wt(),xt&&(xt.removeEventListener("mouseenter",Yt),xt.removeEventListener("mouseleave",Wt)),T&&(T.removeEventListener("focus",Yt),T.removeEventListener("blur",Wt))}}}let{clearChatButton:m,clearChatButtonWrapper:F}=B;if(m){let x=(fe=d.clearChat)!=null?fe:{},ot=(ee=x.enabled)!=null?ee:!0;if(F&&(F.style.display=ot?"":"none"),ot){let it=(Se=x.size)!=null?Se:"32px";m.style.height=it,m.style.width=it;let ft=(ne=x.iconName)!=null?ne:"refresh-cw",G=(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=(Ve=x.tooltipText)!=null?Ve:"Clear chat",xt=(lt=x.showTooltip)!=null?lt:!0;if(m.setAttribute("aria-label",Lt),F&&(F._cleanupTooltip&&(F._cleanupTooltip(),delete F._cleanupTooltip),xt&&Lt)){let et=null,At=()=>{if(et||!m)return;et=p("div","tvw-clear-chat-tooltip"),et.textContent=Lt;let Yt=p("div");Yt.className="tvw-clear-chat-tooltip-arrow",et.appendChild(Yt);let Wt=m.getBoundingClientRect();et.style.position="fixed",et.style.left=`${Wt.left+Wt.width/2}px`,et.style.top=`${Wt.top-8}px`,et.style.transform="translate(-50%, -100%)",document.body.appendChild(et)},U=()=>{et&&et.parentNode&&(et.parentNode.removeChild(et),et=null)};F.addEventListener("mouseenter",At),F.addEventListener("mouseleave",U),m.addEventListener("focus",At),m.addEventListener("blur",U),F._cleanupTooltip=()=>{U(),F&&(F.removeEventListener("mouseenter",At),F.removeEventListener("mouseleave",U)),m&&(m.removeEventListener("focus",At),m.removeEventListener("blur",U))}}}}S=Un(e),D.updateConfig(e),at(L,D.getMessages(),S),jt.render(e.suggestionChips,D,E),Ce(),Q(D.isStreaming());let rt=((oe=e.voiceRecognition)==null?void 0:oe.enabled)===!0,mt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),st=rt&&mt;if(Z.classList.remove("tvw-gap-1","tvw-gap-3"),Z.classList.add(st?"tvw-gap-1":"tvw-gap-3"),rt&&mt)if(!h||!ct){let x=Te(e.voiceRecognition,e.sendButton);x&&(h=x.micButton,ct=x.micButtonWrapper,Z.insertBefore(ct,Y),h.addEventListener("click",Zt),h.disabled=D.isStreaming())}else{let x=(ve=e.voiceRecognition)!=null?ve:{},ot=(je=e.sendButton)!=null?je:{},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 _=(Sn=e.sendButton)!=null?Sn:{},Pt=(Ln=_.useIcon)!=null?Ln:!1,$t=(An=_.iconText)!=null?An:"\u2191",Ot=_.iconName,Nt=(En=_.tooltipText)!=null?En:"Send message",Qt=(Mn=_.showTooltip)!=null?Mn:!1,_t=(Bn=_.size)!=null?Bn:"40px",Xt=_.backgroundColor,vt=_.textColor;if(Pt){if(b.style.width=_t,b.style.height=_t,b.style.minWidth=_t,b.style.minHeight=_t,b.style.fontSize="18px",b.style.lineHeight="1",b.innerHTML="",Ot){let x=parseFloat(_t)||24,ot=vt&&typeof vt=="string"&&vt.trim()?vt.trim():"currentColor",it=ht(Ot,x,ot,2);it?(b.appendChild(it),b.style.color=ot):(b.textContent=$t,vt?b.style.color=vt:b.classList.add("tvw-text-white"))}else b.textContent=$t,vt?b.style.color=vt:b.classList.add("tvw-text-white");b.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",Xt?(b.style.backgroundColor=Xt,b.classList.remove("tvw-bg-cw-primary")):b.classList.add("tvw-bg-cw-primary")}else b.textContent=(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",Xt?(b.style.backgroundColor=Xt,b.classList.remove("tvw-bg-cw-accent")):b.classList.add("tvw-bg-cw-accent"),vt?b.style.color=vt:b.classList.add("tvw-text-white");_.borderWidth?(b.style.borderWidth=_.borderWidth,b.style.borderStyle="solid"):(b.style.borderWidth="",b.style.borderStyle=""),_.borderColor?b.style.borderColor=_.borderColor:b.style.borderColor="",_.paddingX?(b.style.paddingLeft=_.paddingX,b.style.paddingRight=_.paddingX):(b.style.paddingLeft="",b.style.paddingRight=""),_.paddingY?(b.style.paddingTop=_.paddingY,b.style.paddingBottom=_.paddingY):(b.style.paddingTop="",b.style.paddingBottom="");let Ut=Y==null?void 0:Y.querySelector(".tvw-send-button-tooltip");if(Qt&&Nt)if(Ut)Ut.textContent=Nt,Ut.style.display="";else{let x=document.createElement("div");x.className="tvw-send-button-tooltip",x.textContent=Nt,Y==null||Y.insertBefore(x,b)}else Ut&&(Ut.style.display="none");let we=(In=e.statusIndicator)!=null?In:{},Ye=(Hn=we.visible)!=null?Hn:!0;if(nt.style.display=Ye?"":"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},Vn=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),Vn(S)}else l=e,o=document.createElement("div"),o.id="vanilla-agent-root",e.appendChild(o),Vn(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