vanilla-agent 0.2.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -21
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +98 -61
- package/dist/index.d.ts +98 -61
- package/dist/index.global.js +36 -30
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/install.global.js +1 -1
- package/dist/install.global.js.map +1 -1
- package/dist/widget.css +73 -0
- package/package.json +2 -2
- package/src/client.ts +14 -14
- package/src/components/forms.ts +7 -5
- package/src/components/launcher.ts +4 -4
- package/src/components/message-bubble.ts +43 -4
- package/src/components/messages.ts +4 -2
- package/src/components/panel.ts +254 -13
- package/src/components/reasoning-bubble.ts +2 -2
- package/src/components/suggestions.ts +4 -4
- package/src/components/tool-bubble.ts +2 -2
- package/src/defaults.ts +180 -0
- package/src/index.ts +21 -18
- package/src/install.ts +8 -8
- package/src/plugins/registry.ts +7 -5
- package/src/plugins/types.ts +13 -11
- package/src/runtime/init.ts +11 -8
- package/src/session.ts +32 -23
- package/src/styles/widget.css +73 -0
- package/src/types.ts +56 -31
- package/src/ui.ts +338 -53
- package/src/utils/constants.ts +4 -2
- package/src/utils/dom.ts +2 -0
- package/src/utils/formatting.ts +8 -6
- package/src/utils/icons.ts +1 -1
- package/src/utils/positioning.ts +2 -0
- package/src/utils/theme.ts +4 -2
package/README.md
CHANGED
|
@@ -23,39 +23,39 @@ pnpm build
|
|
|
23
23
|
```ts
|
|
24
24
|
import 'vanilla-agent/widget.css';
|
|
25
25
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
initAgentWidget,
|
|
27
|
+
createAgentExperience,
|
|
28
28
|
markdownPostprocessor,
|
|
29
|
-
directivePostprocessor
|
|
29
|
+
directivePostprocessor,
|
|
30
|
+
DEFAULT_WIDGET_CONFIG
|
|
30
31
|
} from 'vanilla-agent';
|
|
31
32
|
|
|
32
33
|
const proxyUrl = '/api/chat/dispatch';
|
|
33
34
|
|
|
34
35
|
// Inline embed
|
|
35
36
|
const inlineHost = document.querySelector('#inline-widget')!;
|
|
36
|
-
|
|
37
|
+
createAgentExperience(inlineHost, {
|
|
38
|
+
...DEFAULT_WIDGET_CONFIG,
|
|
37
39
|
apiUrl: proxyUrl,
|
|
38
40
|
launcher: { enabled: false },
|
|
39
|
-
theme: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
showToolCalls: true // Show tool usage bubbles (default: true)
|
|
41
|
+
theme: {
|
|
42
|
+
...DEFAULT_WIDGET_CONFIG.theme,
|
|
43
|
+
accent: '#2563eb'
|
|
43
44
|
},
|
|
44
45
|
suggestionChips: ['What can you do?', 'Show API docs'],
|
|
45
46
|
postprocessMessage: ({ text }) => markdownPostprocessor(text)
|
|
46
47
|
});
|
|
47
48
|
|
|
48
49
|
// Floating launcher with runtime updates
|
|
49
|
-
const controller =
|
|
50
|
+
const controller = initAgentWidget({
|
|
50
51
|
target: '#launcher-root',
|
|
51
52
|
config: {
|
|
53
|
+
...DEFAULT_WIDGET_CONFIG,
|
|
52
54
|
apiUrl: proxyUrl,
|
|
53
55
|
launcher: {
|
|
54
|
-
|
|
55
|
-
autoExpand: false,
|
|
56
|
+
...DEFAULT_WIDGET_CONFIG.launcher,
|
|
56
57
|
title: 'AI Assistant',
|
|
57
|
-
subtitle: 'Here to help you get answers fast'
|
|
58
|
-
width: 'min(420px, 95vw)'
|
|
58
|
+
subtitle: 'Here to help you get answers fast'
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
});
|
|
@@ -74,10 +74,10 @@ controller.update({
|
|
|
74
74
|
|
|
75
75
|
### Programmatic control
|
|
76
76
|
|
|
77
|
-
`
|
|
77
|
+
`initAgentWidget` (and `createAgentExperience`) return a controller with `open()`, `close()`, and `toggle()` helpers so you can launch the widget from your own UI elements.
|
|
78
78
|
|
|
79
79
|
```ts
|
|
80
|
-
const chat =
|
|
80
|
+
const chat = initAgentWidget({
|
|
81
81
|
target: '#launcher-root',
|
|
82
82
|
config: { /* ... */ }
|
|
83
83
|
})
|
|
@@ -175,7 +175,7 @@ For more control, manually load CSS and JavaScript:
|
|
|
175
175
|
|
|
176
176
|
<!-- Initialize widget -->
|
|
177
177
|
<script>
|
|
178
|
-
window.
|
|
178
|
+
window.AgentWidget.initAgentWidget({
|
|
179
179
|
target: '#vanilla-agent-anchor', // or 'body' for floating launcher
|
|
180
180
|
config: {
|
|
181
181
|
apiUrl: '/api/chat/dispatch',
|
|
@@ -206,7 +206,39 @@ Replace `VERSION` with `latest` for auto-updates, or a specific version like `0.
|
|
|
206
206
|
- `index.global.js` - Widget JavaScript (IIFE format)
|
|
207
207
|
- `install.global.js` - Automatic installer script
|
|
208
208
|
|
|
209
|
-
The script build exposes a `window.
|
|
209
|
+
The script build exposes a `window.AgentWidget` global with `initAgentWidget()` and other exports.
|
|
210
|
+
|
|
211
|
+
### Using default configuration
|
|
212
|
+
|
|
213
|
+
The package exports a complete default configuration that you can use as a base:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import { DEFAULT_WIDGET_CONFIG, mergeWithDefaults } from 'vanilla-agent';
|
|
217
|
+
|
|
218
|
+
// Option 1: Use defaults with selective overrides
|
|
219
|
+
const controller = initAgentWidget({
|
|
220
|
+
target: '#app',
|
|
221
|
+
config: {
|
|
222
|
+
...DEFAULT_WIDGET_CONFIG,
|
|
223
|
+
apiUrl: '/api/chat/dispatch',
|
|
224
|
+
theme: {
|
|
225
|
+
...DEFAULT_WIDGET_CONFIG.theme,
|
|
226
|
+
accent: '#custom-color' // Override only what you need
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Option 2: Use the merge helper
|
|
232
|
+
const controller = initAgentWidget({
|
|
233
|
+
target: '#app',
|
|
234
|
+
config: mergeWithDefaults({
|
|
235
|
+
apiUrl: '/api/chat/dispatch',
|
|
236
|
+
theme: { accent: '#custom-color' }
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
This ensures all configuration values are set to sensible defaults while allowing you to customize only what you need.
|
|
210
242
|
|
|
211
243
|
### Configuration reference
|
|
212
244
|
|
|
@@ -217,16 +249,16 @@ The script build exposes a `window.ChatWidget` global with `initChatWidget()` an
|
|
|
217
249
|
| `headers` | `Record<string, string>` | Extra headers forwarded to your proxy. |
|
|
218
250
|
| `copy` | `{ welcomeTitle?, welcomeSubtitle?, inputPlaceholder?, sendButtonLabel? }` | Customize user-facing text. |
|
|
219
251
|
| `theme` | `{ primary?, secondary?, surface?, muted?, accent?, radiusSm?, radiusMd?, radiusLg?, radiusFull? }` | Override CSS variables for the widget. Colors: `primary` (text/UI), `secondary` (unused), `surface` (backgrounds), `muted` (secondary text), `accent` (buttons/links). Border radius: `radiusSm` (0.75rem, inputs), `radiusMd` (1rem, cards), `radiusLg` (1.5rem, panels/bubbles), `radiusFull` (9999px, pills/buttons). |
|
|
220
|
-
| `features` | `
|
|
252
|
+
| `features` | `AgentWidgetFeatureFlags` | Toggle UI features: `showReasoning?` (show thinking bubbles, default: `true`), `showToolCalls?` (show tool usage bubbles, default: `true`). |
|
|
221
253
|
| `launcher` | `{ enabled?, autoExpand?, title?, subtitle?, iconUrl?, position? }` | Controls the floating launcher button. |
|
|
222
|
-
| `initialMessages` | `
|
|
254
|
+
| `initialMessages` | `AgentWidgetMessage[]` | Seed the conversation transcript. |
|
|
223
255
|
| `suggestionChips` | `string[]` | Render quick reply buttons above the composer. |
|
|
224
256
|
| `postprocessMessage` | `(ctx) => string` | Transform message text before it renders (return HTML). Combine with `markdownPostprocessor` for rich output. |
|
|
225
257
|
| `formEndpoint` | `string` | Endpoint used by built-in directives (defaults to `/form`). |
|
|
226
|
-
| `launcherWidth` | `string` | CSS width applied to the floating launcher panel (e.g. `320px`, `90vw`). Defaults to `min(
|
|
258
|
+
| `launcherWidth` | `string` | CSS width applied to the floating launcher panel (e.g. `320px`, `90vw`). Defaults to `min(400px, calc(100vw - 24px))`. |
|
|
227
259
|
| `debug` | `boolean` | Emits verbose logs to `console`. |
|
|
228
260
|
|
|
229
|
-
All options are safe to mutate via `
|
|
261
|
+
All options are safe to mutate via `initAgentWidget(...).update(newConfig)`.
|
|
230
262
|
|
|
231
263
|
### Optional proxy server
|
|
232
264
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Xn=Object.create;var Ke=Object.defineProperty;var Yn=Object.getOwnPropertyDescriptor;var Vn=Object.getOwnPropertyNames;var Gn=Object.getPrototypeOf,Kn=Object.prototype.hasOwnProperty;var Jn=(t,n)=>{for(var e in n)Ke(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))!Kn.call(t,o)&&o!==e&&Ke(t,o,{get:()=>n[o],enumerable:!(s=Yn(n,o))||s.enumerable});return t};var Zn=(t,n,e)=>(e=t!=null?Xn(Gn(t)):{},Nn(n||!t||!t.__esModule?Ke(e,"default",{value:t,enumerable:!0}):e,t)),Qn=t=>Nn(Ke({},"__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:()=>hn,markdownPostprocessor:()=>nn,mergeWithDefaults:()=>Ze,pluginRegistry:()=>Ye});module.exports=Qn(uo);var en=require("marked");en.marked.setOptions({breaks:!0});var nn=t=>en.marked.parse(t),Je=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),to=t=>t.replace(/"/g,""").replace(/</g,"<").replace(/>/g,">"),Fn=t=>`%%FORM_PLACEHOLDER_${t}%%`,eo=(t,n)=>{let e=t;return e=e.replace(/<Directive>([\s\S]*?)<\/Directive>/gi,(s,o)=>{try{let l=JSON.parse(o.trim());if(l&&typeof l=="object"&&l.component==="form"&&l.type){let a=Fn(n.length);return n.push({token:a,type:String(l.type)}),a}}catch{return s}return s}),e=e.replace(/<Form\s+type="([^"]+)"\s*\/>/gi,(s,o)=>{let l=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 a=new RegExp(o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),C=`<div class="tvw-form-directive" data-tv-form="${to(l)}"></div>`;s=s.replace(a,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((a,L)=>{let C=new Date(a.createdAt).getTime(),M=new Date(L.createdAt).getTime();return C-M}).map(a=>({role:a.role,content:a.content,createdAt:a.createdAt})),...this.config.flowId&&{flowId:this.config.flowId}};this.debug&&console.debug("[AgentWidgetClient] dispatch body",o);let l=await fetch(this.apiUrl,{method:"POST",headers:this.headers,body:JSON.stringify(o),signal:s.signal});if(!l.ok||!l.body){let a=new Error(`Chat backend request failed: ${l.status} ${l.statusText}`);throw e({type:"error",error:a}),a}e({type:"status",status:"connected"});try{await this.streamResponse(l.body,e)}finally{e({type:"status",status:"idle"})}}async streamResponse(n,e){var Ct,T,j,f,ct,At,Xt,Ft,$,bt,D,Gt,ve,Dt,X,Kt,Jt,fe,ye,Ae,It,qt,at,Et,W,Q,be,q,Mt,pt,ht,Ht,Rt,xe,Ce,Bt,Te,Zt,se,G,zt,ie,ae,Ee,le,de,ce,ue,pe;let s=n.getReader(),o=new TextDecoder,l="",a=Date.now(),L=0,C=()=>a+L++,M=w=>{let R=w.reasoning?{...w.reasoning,chunks:[...w.reasoning.chunks]}:void 0,z=w.toolCall?{...w.toolCall,chunks:w.toolCall.chunks?[...w.toolCall.chunks]:void 0}:void 0,J=w.tools?w.tools.map(r=>({...r,chunks:r.chunks?[...r.chunks]:void 0})):void 0;return{...w,reasoning:R,toolCall:z,tools:J}},y=w=>{e({type:"message",message:M(w)})},I=null,h=new Map,_=new Map,A={lastId:null,byStep:new Map},Y={lastId:null,byCall:new Map},E=w=>{if(w==null)return null;try{return String(w)}catch{return null}},N=w=>{var R,z,J,r,v;return E((v=(r=(J=(z=(R=w.stepId)!=null?R:w.step_id)!=null?z:w.step)!=null?J:w.parentId)!=null?r:w.flowStepId)!=null?v:w.flow_step_id)},P=w=>{var R,z,J,r,v,H,u;return E((u=(H=(v=(r=(J=(z=(R=w.callId)!=null?R:w.call_id)!=null?z:w.requestId)!=null?J:w.request_id)!=null?r:w.toolCallId)!=null?v:w.tool_call_id)!=null?H:w.stepId)!=null?u:w.step_id)},S=()=>I||(I={id:`assistant-${Date.now()}-${Math.random().toString(16).slice(2)}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"assistant",sequence:C()},y(I),I),dt=(w,R)=>{A.lastId=R,w&&A.byStep.set(w,R)},B=(w,R)=>{var v;let z=(v=w.reasoningId)!=null?v:w.id,J=N(w);if(z){let H=String(z);return dt(J,H),H}if(J){let H=A.byStep.get(J);if(H)return A.lastId=H,H}if(A.lastId&&!R)return A.lastId;if(!R)return null;let r=`reason-${C()}`;return dt(J,r),r},b=w=>{let R=h.get(w);if(R)return R;let z={id:`reason-${w}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"reasoning",sequence:C(),reasoning:{id:w,status:"streaming",chunks:[]}};return h.set(w,z),y(z),z},V=(w,R)=>{Y.lastId=R,w&&Y.byCall.set(w,R)},Z=(w,R)=>{var v;let z=(v=w.toolId)!=null?v:w.id,J=P(w);if(z){let H=String(z);return V(J,H),H}if(J){let H=Y.byCall.get(J);if(H)return Y.lastId=H,H}if(Y.lastId&&!R)return Y.lastId;if(!R)return null;let r=`tool-${C()}`;return V(J,r),r},nt=w=>{let R=_.get(w);if(R)return R;let z={id:`tool-${w}`,role:"assistant",content:"",createdAt:new Date().toISOString(),streaming:!0,variant:"tool",sequence:C(),toolCall:{id:w,status:"pending"}};return _.set(w,z),y(z),z},ut=w=>{if(typeof w=="number"&&Number.isFinite(w))return w;if(typeof w=="string"){let R=Number(w);if(!Number.isNaN(R)&&Number.isFinite(R))return R;let z=Date.parse(w);if(!Number.isNaN(z))return z}return Date.now()};for(;;){let{done:w,value:R}=await s.read();if(w)break;l+=o.decode(R,{stream:!0});let z=l.split(`
|
|
2
2
|
|
|
3
|
-
`);l=(
|
|
4
|
-
`),
|
|
3
|
+
`);l=(Ct=z.pop())!=null?Ct:"";for(let J of z){let r=J.split(`
|
|
4
|
+
`),v="message",H="";for(let c of r)c.startsWith("event:")?v=c.replace("event:","").trim():c.startsWith("data:")&&(H+=c.replace("data:","").trim());if(!H)continue;let u;try{u=JSON.parse(H)}catch(c){e({type:"error",error:c instanceof Error?c:new Error("Failed to parse chat stream payload")});continue}let d=v!=="message"?v:(T=u.type)!=null?T:"message";if(d==="reason_start"){let c=(j=B(u,!0))!=null?j:`reason-${C()}`,i=b(c);i.reasoning=(f=i.reasoning)!=null?f:{id:c,status:"streaming",chunks:[]},i.reasoning.startedAt=(At=i.reasoning.startedAt)!=null?At:ut((ct=u.startedAt)!=null?ct:u.timestamp),i.reasoning.completedAt=void 0,i.reasoning.durationMs=void 0,i.streaming=!0,i.reasoning.status="streaming",y(i)}else if(d==="reason_chunk"){let c=(Ft=(Xt=B(u,!1))!=null?Xt:B(u,!0))!=null?Ft:`reason-${C()}`,i=b(c);i.reasoning=($=i.reasoning)!=null?$:{id:c,status:"streaming",chunks:[]},i.reasoning.startedAt=(D=i.reasoning.startedAt)!=null?D:ut((bt=u.startedAt)!=null?bt:u.timestamp);let g=(Dt=(ve=(Gt=u.reasoningText)!=null?Gt:u.text)!=null?ve:u.delta)!=null?Dt:"";if(g&&u.hidden!==!0&&i.reasoning.chunks.push(String(g)),i.reasoning.status=u.done?"complete":"streaming",u.done){i.reasoning.completedAt=ut((X=u.completedAt)!=null?X:u.timestamp);let m=(Kt=i.reasoning.startedAt)!=null?Kt:Date.now();i.reasoning.durationMs=Math.max(0,((Jt=i.reasoning.completedAt)!=null?Jt:Date.now())-m)}i.streaming=i.reasoning.status!=="complete",y(i)}else if(d==="reason_complete"){let c=(ye=(fe=B(u,!1))!=null?fe:B(u,!0))!=null?ye:`reason-${C()}`,i=h.get(c);if(i!=null&&i.reasoning){i.reasoning.status="complete",i.reasoning.completedAt=ut((Ae=u.completedAt)!=null?Ae:u.timestamp);let m=(It=i.reasoning.startedAt)!=null?It:Date.now();i.reasoning.durationMs=Math.max(0,((qt=i.reasoning.completedAt)!=null?qt:Date.now())-m),i.streaming=!1,y(i)}let g=N(u);g&&A.byStep.delete(g)}else if(d==="tool_start"){let c=(at=Z(u,!0))!=null?at:`tool-${C()}`,i=nt(c),g=(Et=i.toolCall)!=null?Et:{id:c,status:"pending"};g.name=(W=u.toolName)!=null?W:g.name,g.status="running",u.args!==void 0&&(g.args=u.args),g.startedAt=(be=g.startedAt)!=null?be:ut((Q=u.startedAt)!=null?Q:u.timestamp),g.completedAt=void 0,g.durationMs=void 0,i.toolCall=g,i.streaming=!0,y(i)}else if(d==="tool_chunk"){let c=(Mt=(q=Z(u,!1))!=null?q:Z(u,!0))!=null?Mt:`tool-${C()}`,i=nt(c),g=(pt=i.toolCall)!=null?pt:{id:c,status:"running"};g.startedAt=(Ht=g.startedAt)!=null?Ht:ut((ht=u.startedAt)!=null?ht:u.timestamp);let m=(Ce=(xe=(Rt=u.text)!=null?Rt:u.delta)!=null?xe:u.message)!=null?Ce:"";m&&(g.chunks=(Bt=g.chunks)!=null?Bt:[],g.chunks.push(String(m))),g.status="running",i.toolCall=g,i.streaming=!0,y(i)}else if(d==="tool_complete"){let c=(Zt=(Te=Z(u,!1))!=null?Te:Z(u,!0))!=null?Zt:`tool-${C()}`,i=nt(c),g=(se=i.toolCall)!=null?se:{id:c,status:"running"};if(g.status="complete",u.result!==void 0&&(g.result=u.result),typeof u.duration=="number"&&(g.duration=u.duration),g.completedAt=ut((G=u.completedAt)!=null?G:u.timestamp),typeof u.duration=="number")g.durationMs=u.duration;else{let F=(zt=g.startedAt)!=null?zt:Date.now();g.durationMs=Math.max(0,((ie=g.completedAt)!=null?ie:Date.now())-F)}i.toolCall=g,i.streaming=!1,y(i);let m=P(u);m&&Y.byCall.delete(m)}else if(d==="step_chunk"){let c=S(),i=(le=(Ee=(ae=u.text)!=null?ae:u.delta)!=null?Ee:u.content)!=null?le:"";if(i&&(c.content+=i,y(c)),u.isComplete){let g=(ce=(de=u.result)==null?void 0:de.response)!=null?ce:c.content;g&&(c.content=g,c.streaming=!1,y(c))}}else if(d==="step_complete"){let c=(ue=u.result)==null?void 0:ue.response,i=S();c?(i.content=c,i.streaming=!1,y(i)):(i.streaming=!1,y(i))}else if(d==="flow_complete"){let c=(pe=u.result)==null?void 0:pe.response;if(c){let i=S();c!==i.content&&(i.content=c,y(i)),i.streaming=!1,y(i)}else{let i=I;if(i){let g=i;g.streaming=!1,y(g)}}e({type:"status",status:"idle"})}else d==="error"&&u.error&&e({type:"error",error:u.error instanceof Error?u.error:new Error(String(u.error))})}}}};var 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 a,L,C,M,y;let e=n.trim();if(!e)return;(a=this.abortController)==null||a.abort();let s={id:`user-${Date.now()}`,role:"user",content:e,createdAt:new Date().toISOString(),sequence:this.nextSequence()};this.appendMessage(s),this.setStreaming(!0);let o=new AbortController;this.abortController=o;let l=[...this.messages];try{await this.client.dispatch({messages:l,signal:o.signal},this.handleEvent)}catch(I){let h={id:`assistant-${Date.now()}`,role:"assistant",createdAt:new Date().toISOString(),content:"It looks like the proxy isn't returning a real response yet. Here's a sample message so you can continue testing locally.",sequence:this.nextSequence()};this.appendMessage(h),this.setStatus("idle"),this.setStreaming(!1),this.abortController=null,I instanceof Error?(C=(L=this.callbacks).onError)==null||C.call(L,I):(y=(M=this.callbacks).onError)==null||y.call(M,new Error(String(I)))}}cancel(){var n;(n=this.abortController)==null||n.abort(),this.abortController=null,this.setStreaming(!1),this.setStatus("idle")}clearMessages(){var n;(n=this.abortController)==null||n.abort(),this.abortController=null,this.messages=[],this.setStreaming(!1),this.setStatus("idle"),this.callbacks.onMessagesChanged([...this.messages])}setStatus(n){this.status!==n&&(this.status=n,this.callbacks.onStatusChanged(n))}setStreaming(n){this.streaming!==n&&(this.streaming=n,this.callbacks.onStreamingChanged(n))}appendMessage(n){let e=this.ensureSequence(n);this.messages=this.sortMessages([...this.messages,e]),this.callbacks.onMessagesChanged([...this.messages])}upsertMessage(n){let e=this.ensureSequence(n),s=this.messages.findIndex(o=>o.id===e.id);if(s===-1){this.appendMessage(e);return}this.messages=this.messages.map((o,l)=>l===s?{...o,...e}:o),this.messages=this.sortMessages(this.messages),this.callbacks.onMessagesChanged([...this.messages])}ensureSequence(n){return n.sequence!==void 0?{...n}:{...n,sequence:this.nextSequence()}}nextSequence(){return this.sequenceCounter++}sortMessages(n){return[...n].sort((e,s)=>{var C,M;let o=new Date(e.createdAt).getTime(),l=new Date(s.createdAt).getTime();if(!Number.isNaN(o)&&!Number.isNaN(l)&&o!==l)return o-l;let a=(C=e.sequence)!=null?C:0,L=(M=s.sequence)!=null?M:0;return a!==L?a-L:e.id.localeCompare(s.id)})}};var 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 a=o.replace(/[A-Z]/g,L=>`-${L.toLowerCase()}`);t.style.setProperty(`--cw-${a}`,String(l))})};var oo=Zn(require("lucide"),1),ft=(t,n=24,e="currentColor",s=2)=>{try{let o=t.split("-").map(a=>a.charAt(0).toUpperCase()+a.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 a=l[0],L=l[1];if(L){let C=document.createElementNS("http://www.w3.org/2000/svg",a);Object.entries(L).forEach(([M,y])=>{M!=="stroke"&&C.setAttribute(M,String(y))}),o.appendChild(C)}}}),o}var p=(t,n)=>{let e=document.createElement(t);return n&&(e.className=n),e};var yt={idle:"Online",connecting:"Connecting\u2026",connected:"Streaming\u2026",error:"Offline"};var he={"bottom-right":"tvw-bottom-6 tvw-right-6","bottom-left":"tvw-bottom-6 tvw-left-6","top-right":"tvw-top-6 tvw-right-6","top-left":"tvw-top-6 tvw-left-6"};var 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 i=l=>{var $,ut,P,_,ot,it,M,f,O,G;let a=($=l.launcher)!=null?$:{},C=e.querySelector("[data-role='launcher-title']");C&&(C.textContent=(ut=a.title)!=null?ut:"Chat Assistant");let b=e.querySelector("[data-role='launcher-subtitle']");b&&(b.textContent=(P=a.subtitle)!=null?P:"Get answers fast");let T=e.querySelector(".tvw-flex-col");T&&(a.textHidden?T.style.display="none":T.style.display="");let v=e.querySelector("[data-role='launcher-icon']");if(v)if(a.agentIconHidden)v.style.display="none";else{let tt=(_=a.agentIconSize)!=null?_:"40px";if(v.style.height=tt,v.style.width=tt,v.innerHTML="",a.agentIconName){let J=parseFloat(tt)||24,B=Tt(a.agentIconName,J*.6,"#ffffff",2);B?(v.appendChild(B),v.style.display=""):(v.textContent=(ot=a.agentIconText)!=null?ot:"\u{1F4AC}",v.style.display="")}else a.iconUrl?v.style.display="none":(v.textContent=(it=a.agentIconText)!=null?it:"\u{1F4AC}",v.style.display="")}let W=e.querySelector("[data-role='launcher-image']");if(W){let tt=(M=a.agentIconSize)!=null?M:"40px";W.style.height=tt,W.style.width=tt,a.iconUrl&&!a.agentIconName&&!a.agentIconHidden?(W.src=a.iconUrl,W.style.display="block"):W.style.display="none"}let w=e.querySelector("[data-role='launcher-call-to-action-icon']");if(w){let tt=(f=a.callToActionIconSize)!=null?f:"32px";w.style.height=tt,w.style.width=tt,a.callToActionIconBackgroundColor?(w.style.backgroundColor=a.callToActionIconBackgroundColor,w.classList.remove("tvw-bg-cw-primary")):(w.style.backgroundColor="",w.classList.add("tvw-bg-cw-primary"));let J=0;if(a.callToActionIconPadding?(w.style.boxSizing="border-box",w.style.padding=a.callToActionIconPadding,J=(parseFloat(a.callToActionIconPadding)||0)*2):(w.style.boxSizing="",w.style.padding=""),a.callToActionIconHidden)w.style.display="none";else if(w.style.display="",w.innerHTML="",a.callToActionIconName){let B=parseFloat(tt)||24,H=Math.max(B-J,8),U=Tt(a.callToActionIconName,H,"currentColor",2);U?w.appendChild(U):w.textContent=(O=a.callToActionIconText)!=null?O:"\u2197"}else w.textContent=(G=a.callToActionIconText)!=null?G:"\u2197"}let z=a.position&&Gt[a.position]?Gt[a.position]:Gt["bottom-right"],x="tvw-fixed tvw-flex tvw-items-center tvw-gap-3 tvw-rounded-launcher tvw-bg-cw-surface tvw-py-2.5 tvw-pl-3 tvw-pr-3 tvw-shadow-lg tvw-border tvw-border-gray-200 tvw-transition hover:tvw-translate-y-[-2px] tvw-cursor-pointer";e.className=`${x} ${z}`},o=()=>{e.removeEventListener("click",n),e.remove()};return t&&i(t),{element:e,update:i,destroy:o}};var yn=t=>{var b,T,v,W,w;if(!((T=(b=t==null?void 0:t.launcher)==null?void 0:b.enabled)!=null?T:!0)){let z=u("div","tvw-relative tvw-w-full tvw-h-full"),x=u("div","tvw-relative tvw-w-full tvw-h-full tvw-min-h-[360px]");return z.appendChild(x),{wrapper:z,panel:x}}let e=(v=t==null?void 0:t.launcher)!=null?v:{},i=e.position&&Gt[e.position]?Gt[e.position]:Gt["bottom-right"],o=u("div",`tvw-fixed ${i} tvw-z-50 tvw-transition`),l=u("div","tvw-relative tvw-min-h-[320px]"),a=(w=(W=t==null?void 0:t.launcher)==null?void 0:W.width)!=null?w:t==null?void 0:t.launcherWidth,C=a!=null?a:"min(360px, calc(100vw - 24px))";return l.style.width=C,l.style.maxWidth=C,o.appendChild(l),{wrapper:o,panel:l}},bn=(t,n=!0)=>{var Rt,It,Ct,Nt,zt,$t,Pt,rt,mt,St,vt,Jt,Zt,ft,Qt,Ft,Ot,j,Et,Ut,jt,_t,Vt,Xt,Yt,Kt,g,A,N,V,s,h,S,c,r,m,d,p,E,et,Z,F,Q;let e=u("div","tvw-flex tvw-h-full tvw-w-full tvw-flex-col tvw-bg-cw-surface tvw-text-cw-primary tvw-rounded-2xl tvw-overflow-hidden tvw-shadow-2xl tvw-border tvw-border-cw-border"),i=u("div","tvw-flex tvw-items-center tvw-gap-3 tvw-bg-cw-surface tvw-px-6 tvw-py-5 tvw-border-b-cw-divider"),o=(Rt=t==null?void 0:t.launcher)!=null?Rt:{},l=(It=o.headerIconSize)!=null?It:"48px",a=(Ct=o.closeButtonSize)!=null?Ct:"32px",C=(Nt=o.closeButtonPlacement)!=null?Nt:"inline",b=(zt=o.headerIconHidden)!=null?zt:!1,T=o.headerIconName,v=u("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-xl");if(v.style.height=l,v.style.width=l,!b)if(T){let I=parseFloat(l)||24,K=Tt(T,I*.6,"#ffffff",2);K?v.replaceChildren(K):v.textContent=(Pt=($t=t==null?void 0:t.launcher)==null?void 0:$t.agentIconText)!=null?Pt:"\u{1F4AC}"}else if((rt=t==null?void 0:t.launcher)!=null&&rt.iconUrl){let I=u("img");I.src=t.launcher.iconUrl,I.alt="",I.className="tvw-rounded-xl tvw-object-cover",I.style.height=l,I.style.width=l,v.replaceChildren(I)}else v.textContent=(St=(mt=t==null?void 0:t.launcher)==null?void 0:mt.agentIconText)!=null?St:"\u{1F4AC}";let W=u("div","tvw-flex tvw-flex-col"),w=u("span","tvw-text-base tvw-font-semibold");w.textContent=(Jt=(vt=t==null?void 0:t.launcher)==null?void 0:vt.title)!=null?Jt:"Chat Assistant";let z=u("span","tvw-text-xs tvw-text-cw-muted");z.textContent=(ft=(Zt=t==null?void 0:t.launcher)==null?void 0:Zt.subtitle)!=null?ft:"Here to help you get answers fast",W.append(w,z),b?i.append(W):i.append(v,W);let x=u("button",C==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50 tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none":"tvw-ml-auto tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none");if(x.style.height=a,x.style.width=a,x.type="button",x.setAttribute("aria-label","Close chat"),x.textContent="\xD7",x.style.display=n?"":"none",o.closeButtonColor?(x.style.color=o.closeButtonColor,x.classList.remove("tvw-text-cw-muted")):(x.style.color="",x.classList.add("tvw-text-cw-muted")),o.closeButtonBackgroundColor?(x.style.backgroundColor=o.closeButtonBackgroundColor,x.classList.remove("hover:tvw-bg-gray-100")):(x.style.backgroundColor="",x.classList.add("hover:tvw-bg-gray-100")),o.closeButtonBorderWidth||o.closeButtonBorderColor){let I=o.closeButtonBorderWidth||"0px",K=o.closeButtonBorderColor||"transparent";x.style.border=`${I} solid ${K}`,x.classList.remove("tvw-border-none")}else x.style.border="",x.classList.add("tvw-border-none");o.closeButtonBorderRadius?(x.style.borderRadius=o.closeButtonBorderRadius,x.classList.remove("tvw-rounded-full")):(x.style.borderRadius="",x.classList.add("tvw-rounded-full")),C==="top-right"?(e.style.position="relative",e.appendChild(x)):i.appendChild(x);let $=u("div","tvw-flex tvw-flex-1 tvw-min-h-0 tvw-flex-col tvw-gap-6 tvw-overflow-y-auto tvw-bg-cw-container tvw-px-6 tvw-py-6"),ut=u("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),P=u("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");P.textContent=(Ft=(Qt=t==null?void 0:t.copy)==null?void 0:Qt.welcomeTitle)!=null?Ft:"Hello \u{1F44B}";let _=u("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");_.textContent=(j=(Ot=t==null?void 0:t.copy)==null?void 0:Ot.welcomeSubtitle)!=null?j:"Ask anything about your account or products.",ut.append(P,_);let ot=u("div","tvw-flex tvw-flex-col tvw-gap-3");$.append(ut,ot);let it=u("div","tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),M=u("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),f=((Et=t==null?void 0:t.voiceRecognition)==null?void 0:Et.enabled)===!0,O=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),J=u("form",`tvw-flex tvw-items-end ${f&&O?"tvw-gap-1":"tvw-gap-3"} tvw-rounded-2xl tvw-border tvw-border-gray-200 tvw-bg-cw-input-background tvw-px-4 tvw-py-3`);J.style.outline="none";let B=u("textarea");B.placeholder=(jt=(Ut=t==null?void 0:t.copy)==null?void 0:Ut.inputPlaceholder)!=null?jt:"Type your message\u2026",B.className="tvw-min-h-[48px] tvw-flex-1 tvw-resize-none tvw-border-none tvw-bg-transparent tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-none",B.rows=1;let H=(Vt=(_t=t==null?void 0:t.theme)==null?void 0:_t.inputFontFamily)!=null?Vt:"sans-serif",U=(Yt=(Xt=t==null?void 0:t.theme)==null?void 0:Xt.inputFontWeight)!=null?Yt:"400",y=I=>{switch(I){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};B.style.fontFamily=y(H),B.style.fontWeight=U,B.style.border="none",B.style.outline="none",B.style.borderWidth="0",B.style.borderStyle="none",B.style.borderColor="transparent",B.addEventListener("focus",()=>{B.style.border="none",B.style.outline="none",B.style.borderWidth="0",B.style.borderStyle="none",B.style.borderColor="transparent",B.style.boxShadow="none"}),B.addEventListener("blur",()=>{B.style.border="none",B.style.outline="none"});let R=(Kt=t==null?void 0:t.sendButton)!=null?Kt:{},wt=(g=R.useIcon)!=null?g:!1,Mt=(A=R.iconText)!=null?A:"\u2191",ht=R.iconName,D=(N=R.tooltipText)!=null?N:"Send message",Bt=(V=R.showTooltip)!=null?V:!1,lt=(s=R.size)!=null?s:"40px",Lt=R.backgroundColor,st=R.textColor,pt=u("div","tvw-send-button-wrapper"),L=u("button",wt?"tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer":"tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold disabled:tvw-opacity-50 tvw-cursor-pointer");if(L.type="submit",wt){if(L.style.width=lt,L.style.height=lt,L.style.minWidth=lt,L.style.minHeight=lt,L.style.fontSize="18px",L.style.lineHeight="1",L.innerHTML="",ht){let I=parseFloat(lt)||24,K=st&&typeof st=="string"&&st.trim()?st.trim():"currentColor",yt=Tt(ht,I,K,2);yt?(L.appendChild(yt),L.style.color=K):(L.textContent=Mt,st?L.style.color=st:L.classList.add("tvw-text-white"))}else L.textContent=Mt,st?L.style.color=st:L.classList.add("tvw-text-white");Lt?L.style.backgroundColor=Lt:L.classList.add("tvw-bg-cw-primary")}else L.textContent=(S=(h=t==null?void 0:t.copy)==null?void 0:h.sendButtonLabel)!=null?S:"Send",st?L.style.color=st:L.classList.add("tvw-text-white");if(R.borderWidth&&(L.style.borderWidth=R.borderWidth,L.style.borderStyle="solid"),R.borderColor&&(L.style.borderColor=R.borderColor),R.paddingX?(L.style.paddingLeft=R.paddingX,L.style.paddingRight=R.paddingX):(L.style.paddingLeft="",L.style.paddingRight=""),R.paddingY?(L.style.paddingTop=R.paddingY,L.style.paddingBottom=R.paddingY):(L.style.paddingTop="",L.style.paddingBottom=""),Bt&&D){let I=u("div","tvw-send-button-tooltip");I.textContent=D,pt.appendChild(I)}pt.appendChild(L);let Y=(c=t==null?void 0:t.voiceRecognition)!=null?c:{},Dt=Y.enabled===!0,q=null,xt=null,se=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(Dt&&se){xt=u("div","tvw-send-button-wrapper"),q=u("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),q.type="button",q.setAttribute("aria-label","Start voice recognition");let I=(r=Y.iconName)!=null?r:"mic",K=(m=Y.iconSize)!=null?m:lt,yt=parseFloat(K)||24,te=(d=Y.backgroundColor)!=null?d:Lt,bt=(p=Y.iconColor)!=null?p:st;q.style.width=K,q.style.height=K,q.style.minWidth=K,q.style.minHeight=K,q.style.fontSize="18px",q.style.lineHeight="1";let Wt=bt||"currentColor",dt=Tt(I,yt,Wt,1.5);dt?(q.appendChild(dt),q.style.color=Wt):(q.textContent="\u{1F3A4}",q.style.color=Wt),te?q.style.backgroundColor=te:q.classList.add("tvw-bg-cw-primary"),bt?q.style.color=bt:!bt&&!st&&q.classList.add("tvw-text-white"),Y.borderWidth&&(q.style.borderWidth=Y.borderWidth,q.style.borderStyle="solid"),Y.borderColor&&(q.style.borderColor=Y.borderColor),Y.paddingX&&(q.style.paddingLeft=Y.paddingX,q.style.paddingRight=Y.paddingX),Y.paddingY&&(q.style.paddingTop=Y.paddingY,q.style.paddingBottom=Y.paddingY),xt.appendChild(q);let kt=(E=Y.tooltipText)!=null?E:"Start voice recognition";if(((et=Y.showTooltip)!=null?et:!1)&&kt){let ee=u("div","tvw-send-button-tooltip");ee.textContent=kt,xt.appendChild(ee)}}J.addEventListener("click",I=>{I.target!==L&&I.target!==pt&&I.target!==q&&I.target!==xt&&B.focus()}),J.append(B),xt&&J.append(xt),J.append(pt);let Ht=u("div","tvw-mt-2 tvw-text-right tvw-text-xs tvw-text-cw-muted"),At=(Z=t==null?void 0:t.statusIndicator)!=null?Z:{},re=(F=At.visible)!=null?F:!0;return Ht.style.display=re?"":"none",Ht.textContent=(Q=At.idleText)!=null?Q:"Online",it.append(M,J,Ht),e.append(i,$,it),{container:e,body:$,messagesWrapper:ot,suggestions:M,textarea:B,sendButton:L,sendButtonWrapper:pt,micButton:q,micButtonWrapper:xt,composerForm:J,statusText:Ht,introTitle:P,introSubtitle:_,closeButton:x,iconHolder:v}};var ye=(t,n)=>{let e=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm"];t.role==="user"?e.push("tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-5","tvw-py-3"):e.push("tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3");let i=u("div",e.join(" "));return i.innerHTML=n({text:t.content,message:t,streaming:!!t.streaming}),i};var be=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)}},qn=t=>{var a,C;let n=(a=t.completedAt)!=null?a:Date.now(),e=(C=t.startedAt)!=null?C: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`},xn=t=>t.status==="complete"?qn(t):t.status==="pending"?"Waiting":"",Dn=t=>{var o,l,a;let e=(typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,((o=t.completedAt)!=null?o:Date.now())-((a=(l=t.startedAt)!=null?l:t.completedAt)!=null?a:Date.now())))/1e3;return e<.1?"Used tool for <0.1 seconds":`Used tool for ${e>=10?Math.round(e).toString():e.toFixed(1).replace(/\.0$/,"")} seconds`};var Cn=t=>t.status==="complete"?Dn(t):"Using tool...";var xe=new Set,Ce=t=>{let n=t.reasoning,e=u("div",["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(!n)return e;let i=xe.has(t.id),o=u("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");o.type="button",o.setAttribute("aria-expanded",i?"true":"false");let l=u("div","tvw-flex tvw-flex-col tvw-text-left"),a=u("span","tvw-text-xs tvw-font-semibold tvw-text-cw-primary");a.textContent="Thinking...",l.appendChild(a);let C=u("span","tvw-text-xs tvw-text-cw-primary");C.textContent=xn(n),l.appendChild(C),n.status==="complete"?a.style.display="none":a.style.display="";let b=u("span","tvw-text-xs tvw-text-cw-primary");b.textContent=i?"Hide":"Show",o.append(l,b);let T=u("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-px-4 tvw-py-3");T.style.display=i?"":"none";let v=n.chunks.join(""),W=u("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");W.textContent=v||(n.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),T.appendChild(W);let w=()=>{o.setAttribute("aria-expanded",i?"true":"false"),b.textContent=i?"Hide":"Show",T.style.display=i?"":"none"},z=()=>{i=!i,i?xe.add(t.id):xe.delete(t.id),w()};return o.addEventListener("pointerdown",x=>{x.preventDefault(),z()}),o.addEventListener("keydown",x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),z())}),w(),e.append(o,T),e};var Se=new Set,Te=t=>{let n=t.toolCall,e=u("div",["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(!n)return e;let i=Se.has(t.id),o=u("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");o.type="button",o.setAttribute("aria-expanded",i?"true":"false");let l=u("div","tvw-flex tvw-flex-col tvw-text-left"),a=u("span","tvw-text-xs tvw-text-cw-primary");if(a.textContent=Cn(n),l.appendChild(a),n.name){let w=u("span","tvw-text-[11px] tvw-text-cw-muted");w.textContent=n.name,l.appendChild(w)}let C=u("span","tvw-text-xs tvw-text-cw-primary");C.textContent=i?"Hide":"Show";let b=u("div","tvw-flex tvw-items-center tvw-gap-2");b.append(C),o.append(l,b);let T=u("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(T.style.display=i?"":"none",n.args!==void 0){let w=u("div","tvw-space-y-1"),z=u("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");z.textContent="Arguments";let x=u("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-font-xxs tvw-text-cw-primary");x.textContent=be(n.args),w.append(z,x),T.appendChild(w)}if(n.chunks&&n.chunks.length){let w=u("div","tvw-space-y-1"),z=u("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");z.textContent="Activity";let x=u("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-font-xxs tvw-text-cw-primary");x.textContent=n.chunks.join(`
|
|
13
|
-
`),w.append(z,x),T.appendChild(w)}if(n.status==="complete"&&n.result!==void 0){let w=u("div","tvw-space-y-1"),z=u("div","tvw-font-xxs tvw-text-sm tvw-text-cw-muted");z.textContent="Result";let x=u("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-font-xxs tvw-text-cw-primary");x.textContent=be(n.result),w.append(z,x),T.appendChild(w)}if(n.status==="complete"&&typeof n.duration=="number"){let w=u("div","tvw-font-xxs tvw-text-cw-muted");w.textContent=`Duration: ${n.duration}ms`,T.appendChild(w)}let v=()=>{o.setAttribute("aria-expanded",i?"true":"false"),C.textContent=i?"Hide":"Show",T.style.display=i?"":"none"},W=()=>{i=!i,i?Se.add(t.id):Se.delete(t.id),v()};return o.addEventListener("pointerdown",w=>{w.preventDefault(),W()}),o.addEventListener("keydown",w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),W())}),v(),e.append(o,T),e};var Sn=t=>{let n=[];return{buttons:n,render:(i,o,l,a)=>{if(t.innerHTML="",n.length=0,!i||!i.length||(a!=null?a:o?o.getMessages():[]).some(W=>W.role==="user"))return;let T=document.createDocumentFragment(),v=o?o.isStreaming():!1;i.forEach(W=>{let w=u("button","tvw-rounded-button tvw-bg-cw-surface tvw-px-3 tvw-py-1.5 tvw-text-xs tvw-font-medium tvw-text-cw-muted hover:tvw-opacity-90 tvw-cursor-pointer tvw-border tvw-border-gray-200");w.type="button",w.textContent=W,w.disabled=v,w.addEventListener("click",()=>{!o||o.isStreaming()||(l.value="",o.sendMessage(W))}),T.appendChild(w),n.push(w)}),t.appendChild(T)}}};var Tn={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"}},Me=(t,n,e,i)=>{let o=t.querySelectorAll("[data-tv-form]");o.length&&o.forEach(l=>{var x,$,ut;if(l.dataset.enhanced==="true")return;let a=(x=l.dataset.tvForm)!=null?x:"init";l.dataset.enhanced="true";let C=($=Tn[a])!=null?$:Tn.init;l.classList.add("tvw-form-card","tvw-space-y-4");let b=u("div","tvw-space-y-1"),T=u("h3","tvw-text-base tvw-font-semibold tvw-text-cw-primary");if(T.textContent=C.title,b.appendChild(T),C.description){let P=u("p","tvw-text-sm tvw-text-cw-muted");P.textContent=C.description,b.appendChild(P)}let v=document.createElement("form");v.className="tvw-form-grid tvw-space-y-3",C.fields.forEach(P=>{var f,O;let _=u("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");_.htmlFor=`${n.id}-${a}-${P.name}`;let ot=u("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");ot.textContent=P.label,_.appendChild(ot);let it=(f=P.type)!=null?f:"text",M;it==="textarea"?(M=document.createElement("textarea"),M.rows=3):(M=document.createElement("input"),M.type=it),M.className="tvw-rounded-xl tvw-border tvw-border-gray-200 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-cw-primary",M.id=`${n.id}-${a}-${P.name}`,M.name=P.name,M.placeholder=(O=P.placeholder)!=null?O:"",P.required&&(M.required=!0),_.appendChild(M),v.appendChild(_)});let W=u("div","tvw-flex tvw-items-center tvw-justify-between tvw-gap-2"),w=u("div","tvw-text-xs tvw-text-cw-muted tvw-min-h-[1.5rem]"),z=u("button","tvw-inline-flex tvw-items-center tvw-rounded-full tvw-bg-cw-primary tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-60 tvw-cursor-pointer");z.type="submit",z.textContent=(ut=C.submitLabel)!=null?ut:"Submit",W.appendChild(w),W.appendChild(z),v.appendChild(W),l.replaceChildren(b,v),v.addEventListener("submit",async P=>{var M,f;P.preventDefault();let _=(M=e.formEndpoint)!=null?M:"/form",ot=new FormData(v),it={};ot.forEach((O,G)=>{it[G]=O}),it.type=a,z.disabled=!0,w.textContent="Submitting\u2026";try{let O=await fetch(_,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(it)});if(!O.ok)throw new Error(`Form submission failed (${O.status})`);let G=await O.json();w.textContent=(f=G.message)!=null?f:"Thanks! We'll be in touch soon.",G.success&&G.nextPrompt&&await i.sendMessage(String(G.nextPrompt))}catch(O){w.textContent=O instanceof Error?O.message:"Something went wrong. Please try again."}finally{z.disabled=!1}})})};var Le=class{constructor(){this.plugins=new Map}register(n){var e;this.plugins.has(n.id)&&console.warn(`Plugin "${n.id}" is already registered. Overwriting.`),this.plugins.set(n.id,n),(e=n.onRegister)==null||e.call(n)}unregister(n){var i;let e=this.plugins.get(n);e&&((i=e.onUnregister)==null||i.call(e),this.plugins.delete(n))}getAll(){return Array.from(this.plugins.values()).sort((n,e)=>{var i,o;return((i=e.priority)!=null?i:0)-((o=n.priority)!=null?o:0)})}getForInstance(n){let e=this.getAll();if(!n||n.length===0)return e;let i=new Set(n.map(l=>l.id));return[...e.filter(l=>!i.has(l.id)),...n].sort((l,a)=>{var C,b;return((C=a.priority)!=null?C:0)-((b=l.priority)!=null?b:0)})}clear(){this.plugins.forEach(n=>{var e;return(e=n.onUnregister)==null?void 0:e.call(n)}),this.plugins.clear()}},de=new Le;var Mn=t=>t!=null&&t.postprocessMessage?n=>t.postprocessMessage({text:n.text,message:n.message,streaming:n.streaming}):({text:n})=>ce(n),ue=(t,n)=>{var _t,Vt,Xt,Yt,Kt,g,A,N,V;(!t.id||t.id!=="vanilla-agent-root")&&(t.id="vanilla-agent-root");let e={...n};ve(t,e);let i=de.getForInstance(e.plugins),o=(Vt=(_t=e.launcher)==null?void 0:_t.enabled)!=null?Vt:!0,l=(Yt=(Xt=e.launcher)==null?void 0:Xt.autoExpand)!=null?Yt:!1,a=l,C=o,b=o?l:!0,T=Mn(e),v=(g=(Kt=e.features)==null?void 0:Kt.showReasoning)!=null?g:!0,W=(N=(A=e.features)==null?void 0:A.showToolCalls)!=null?N:!0,w=(V=e.statusIndicator)!=null?V:{},z=s=>{var h,S,c,r;return s==="idle"?(h=w.idleText)!=null?h:ct.idle:s==="connecting"?(S=w.connectingText)!=null?S:ct.connecting:s==="connected"?(c=w.connectedText)!=null?c:ct.connected:s==="error"?(r=w.errorText)!=null?r:ct.error:ct[s]},{wrapper:x,panel:$}=yn(e),ut=bn(e,o),{container:P,body:_,messagesWrapper:ot,suggestions:it,textarea:M,sendButton:f,sendButtonWrapper:O,composerForm:G,statusText:tt,introTitle:J,introSubtitle:B,closeButton:H,iconHolder:U}=ut,y=ut.micButton,R=ut.micButtonWrapper;$.appendChild(P),t.appendChild(x);let wt=[],Mt=Sn(it),ht=null,D,Bt=!1,lt=!0,Lt=0,st=0,pt=null,L=!1,Y=0,Dt=!1,q=125,xt=2e3,se=5,Ht=50,At=(s=!1)=>{if(!lt)return;let h=Date.now();L&&h<Y&&!s||(L&&h>=Y&&(L=!1),!(!s&&!Bt)&&(h-st<q||(st=h,pt&&cancelAnimationFrame(pt),pt=requestAnimationFrame(()=>{L||!lt||(Dt=!0,_.scrollTop=_.scrollHeight,Lt=_.scrollTop,requestAnimationFrame(()=>{Dt=!1}),pt=null)}))))},re=()=>{let s=document.createElement("div");s.className="tvw-flex tvw-items-center tvw-space-x-1 tvw-h-5";let h=document.createElement("div");h.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",h.style.animationDelay="0ms";let S=document.createElement("div");S.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",S.style.animationDelay="250ms";let c=document.createElement("div");c.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",c.style.animationDelay="500ms";let r=document.createElement("span");return r.className="tvw-sr-only",r.textContent="Loading",s.appendChild(h),s.appendChild(S),s.appendChild(c),s.appendChild(r),s},Rt=(s,h,S)=>{s.innerHTML="";let c=document.createDocumentFragment();if(h.forEach(r=>{let m=null,d=i.find(E=>!!(r.variant==="reasoning"&&E.renderReasoning||r.variant==="tool"&&E.renderToolCall||!r.variant&&E.renderMessage));if(d)if(r.variant==="reasoning"&&r.reasoning&&d.renderReasoning){if(!v)return;m=d.renderReasoning({message:r,defaultRenderer:()=>Ce(r),config:e})}else if(r.variant==="tool"&&r.toolCall&&d.renderToolCall){if(!W)return;m=d.renderToolCall({message:r,defaultRenderer:()=>Te(r),config:e})}else d.renderMessage&&(m=d.renderMessage({message:r,defaultRenderer:()=>{let E=ye(r,S);return r.role!=="user"&&Me(E,r,e,D),E},config:e}));if(!m)if(r.variant==="reasoning"&&r.reasoning){if(!v)return;m=Ce(r)}else if(r.variant==="tool"&&r.toolCall){if(!W)return;m=Te(r)}else m=ye(r,S),r.role!=="user"&&Me(m,r,e,D);let p=document.createElement("div");p.className="tvw-flex",r.role==="user"&&p.classList.add("tvw-justify-end"),p.appendChild(m),c.appendChild(p)}),Bt&&h.some(r=>r.role==="user")){let r=re(),m=document.createElement("div");m.className="tvw-flex tvw-justify-end",m.appendChild(r),c.appendChild(m)}s.appendChild(c),s.scrollTop=s.scrollHeight},It=()=>{o&&(b?(x.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),$.classList.remove("tvw-scale-95","tvw-opacity-0"),$.classList.add("tvw-scale-100","tvw-opacity-100"),j&&(j.element.style.display="none")):(x.classList.add("tvw-pointer-events-none","tvw-opacity-0"),$.classList.remove("tvw-scale-100","tvw-opacity-100"),$.classList.add("tvw-scale-95","tvw-opacity-0"),j&&(j.element.style.display="")))},Ct=s=>{o&&b!==s&&(b=s,It(),b&&(Et(),At(!0)))},Nt=s=>{M.disabled=s,f.disabled=s,y&&(y.disabled=s),Mt.buttons.forEach(h=>{h.disabled=s})},zt=()=>{var c,r,m,d,p,E,et,Z,F,Q,I,K;J.textContent=(r=(c=e.copy)==null?void 0:c.welcomeTitle)!=null?r:"Hello \u{1F44B}",B.textContent=(d=(m=e.copy)==null?void 0:m.welcomeSubtitle)!=null?d:"Ask anything about your account or products.",M.placeholder=(E=(p=e.copy)==null?void 0:p.inputPlaceholder)!=null?E:"Type your message\u2026",f.textContent=(Z=(et=e.copy)==null?void 0:et.sendButtonLabel)!=null?Z:"Send";let s=(Q=(F=e.theme)==null?void 0:F.inputFontFamily)!=null?Q:"sans-serif",h=(K=(I=e.theme)==null?void 0:I.inputFontWeight)!=null?K:"400",S=yt=>{switch(yt){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};M.style.fontFamily=S(s),M.style.fontWeight=h};D=new ae(e,{onMessagesChanged(s){Rt(ot,s,T),D&&(s.some(S=>S.role==="user")?Mt.render([],D,M,s):Mt.render(e.suggestionChips,D,M,s)),At(!Bt)},onStatusChanged(s){var c;let h=(c=e.statusIndicator)!=null?c:{},S=r=>{var m,d,p,E;return r==="idle"?(m=h.idleText)!=null?m:ct.idle:r==="connecting"?(d=h.connectingText)!=null?d:ct.connecting:r==="connected"?(p=h.connectedText)!=null?p:ct.connected:r==="error"?(E=h.errorText)!=null?E:ct.error:ct[r]};tt.textContent=S(s)},onStreamingChanged(s){Bt=s,Nt(s),D&&Rt(ot,D.getMessages(),T),s||At(!0)}});let $t=s=>{s.preventDefault();let h=M.value.trim();h&&(M.value="",D.sendMessage(h))},Pt=s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),f.click())},rt=null,mt=!1,St=null,vt=null,Jt=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,Zt=()=>{var r,m,d,p;if(mt||D.isStreaming())return;let s=Jt();if(!s)return;rt=new s;let S=(m=((r=e.voiceRecognition)!=null?r:{}).pauseDuration)!=null?m:2e3;rt.continuous=!0,rt.interimResults=!0,rt.lang="en-US";let c=M.value;rt.onresult=E=>{let et="",Z="";for(let Q=0;Q<E.results.length;Q++){let I=E.results[Q],K=I[0].transcript;I.isFinal?et+=K+" ":Z=K}let F=c+et+Z;M.value=F,St&&clearTimeout(St),(et||Z)&&(St=window.setTimeout(()=>{let Q=M.value.trim();Q&&rt&&mt&&(ft(),M.value="",D.sendMessage(Q))},S))},rt.onerror=E=>{E.error!=="no-speech"&&ft()},rt.onend=()=>{if(mt){let E=M.value.trim();E&&E!==c.trim()&&(M.value="",D.sendMessage(E)),ft()}};try{if(rt.start(),mt=!0,y){vt={backgroundColor:y.style.backgroundColor,color:y.style.color,borderColor:y.style.borderColor};let E=(d=e.voiceRecognition)!=null?d:{},et=(p=E.recordingBackgroundColor)!=null?p:"#ef4444",Z=E.recordingIconColor,F=E.recordingBorderColor;if(y.classList.add("tvw-voice-recording"),y.style.backgroundColor=et,Z){y.style.color=Z;let Q=y.querySelector("svg");Q&&Q.setAttribute("stroke",Z)}F&&(y.style.borderColor=F),y.setAttribute("aria-label","Stop voice recognition")}}catch{ft()}},ft=()=>{if(mt){if(mt=!1,St&&(clearTimeout(St),St=null),rt){try{rt.stop()}catch{}rt=null}if(y){if(y.classList.remove("tvw-voice-recording"),vt){y.style.backgroundColor=vt.backgroundColor,y.style.color=vt.color,y.style.borderColor=vt.borderColor;let s=y.querySelector("svg");s&&s.setAttribute("stroke",vt.color||"currentColor"),vt=null}y.setAttribute("aria-label","Start voice recognition")}}},Qt=(s,h)=>{var yt,te,bt,Wt,dt,kt,qt;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let c=u("div","tvw-send-button-wrapper"),r=u("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");r.type="button",r.setAttribute("aria-label","Start voice recognition");let m=(yt=s==null?void 0:s.iconName)!=null?yt:"mic",d=(te=h==null?void 0:h.size)!=null?te:"40px",p=(bt=s==null?void 0:s.iconSize)!=null?bt:d,E=parseFloat(p)||24,et=(Wt=s==null?void 0:s.backgroundColor)!=null?Wt:h==null?void 0:h.backgroundColor,Z=(dt=s==null?void 0:s.iconColor)!=null?dt:h==null?void 0:h.textColor;r.style.width=p,r.style.height=p,r.style.minWidth=p,r.style.minHeight=p,r.style.fontSize="18px",r.style.lineHeight="1";let F=Z||"currentColor",Q=Tt(m,E,F,1.5);Q?(r.appendChild(Q),r.style.color=F):(r.textContent="\u{1F3A4}",r.style.color=F),et?r.style.backgroundColor=et:r.classList.add("tvw-bg-cw-primary"),Z?r.style.color=Z:!Z&&!(h!=null&&h.textColor)&&r.classList.add("tvw-text-white"),s!=null&&s.borderWidth&&(r.style.borderWidth=s.borderWidth,r.style.borderStyle="solid"),s!=null&&s.borderColor&&(r.style.borderColor=s.borderColor),s!=null&&s.paddingX&&(r.style.paddingLeft=s.paddingX,r.style.paddingRight=s.paddingX),s!=null&&s.paddingY&&(r.style.paddingTop=s.paddingY,r.style.paddingBottom=s.paddingY),c.appendChild(r);let I=(kt=s==null?void 0:s.tooltipText)!=null?kt:"Start voice recognition";if(((qt=s==null?void 0:s.showTooltip)!=null?qt:!1)&&I){let ee=u("div","tvw-send-button-tooltip");ee.textContent=I,c.appendChild(ee)}return{micButton:r,micButtonWrapper:c}},Ft=()=>{if(mt){let s=M.value.trim();ft(),s&&(M.value="",D.sendMessage(s))}else Zt()};y&&(y.addEventListener("click",Ft),wt.push(()=>{ft(),y&&y.removeEventListener("click",Ft)}));let Ot=()=>{Ct(!b)},j=o?fe(e,Ot):null;j&&t.appendChild(j.element),It(),Mt.render(e.suggestionChips,D,M),zt(),Nt(D.isStreaming()),At(!0);let Et=()=>{var d,p;if(!o){$.style.height="",$.style.width="";return}let s=(p=(d=e==null?void 0:e.launcher)==null?void 0:d.width)!=null?p:e==null?void 0:e.launcherWidth,h=s!=null?s:"min(360px, calc(100vw - 24px))";$.style.width=h,$.style.maxWidth=h;let S=window.innerHeight,r=Math.max(200,S-64),m=Math.min(640,r);$.style.height=`${m}px`};Et(),window.addEventListener("resize",Et),wt.push(()=>window.removeEventListener("resize",Et)),Lt=_.scrollTop;let Ut=()=>{let s=_.scrollTop,h=_.scrollHeight,S=_.clientHeight,c=h-s-S,r=Math.abs(s-Lt);if(Lt=s,!Dt&&!(r<=se)){if(!lt&&c<Ht){L=!1,lt=!0;return}lt&&c>Ht&&(L=!0,Y=Date.now()+xt,lt=!1)}};_.addEventListener("scroll",Ut,{passive:!0}),wt.push(()=>_.removeEventListener("scroll",Ut)),wt.push(()=>{pt&&cancelAnimationFrame(pt)});let jt=()=>{H&&(ht&&(H.removeEventListener("click",ht),ht=null),o?(H.style.display="",ht=()=>{b=!1,It()},H.addEventListener("click",ht)):H.style.display="none")};return jt(),G.addEventListener("submit",$t),M.addEventListener("keydown",Pt),wt.push(()=>{G.removeEventListener("submit",$t),M.removeEventListener("keydown",Pt)}),wt.push(()=>{D.cancel()}),j&&wt.push(()=>{j==null||j.destroy()}),{update(s){var ke,He,Ae,Ie,Be,Re,Ne,Fe,qe,De,ze,$e,Pe,Oe,Ue,je,_e,Ve,Xe,Ye,Ke,Ge,Je,Ze,Qe,tn,en,nn,on,sn,rn,an,ln,dn,cn,un,pn,gn;e={...e,...s},ve(t,e);let h=de.getForInstance(e.plugins);i.length=0,i.push(...h),o=(He=(ke=e.launcher)==null?void 0:ke.enabled)!=null?He:!0,l=(Ie=(Ae=e.launcher)==null?void 0:Ae.autoExpand)!=null?Ie:!1,v=(Re=(Be=e.features)==null?void 0:Be.showReasoning)!=null?Re:!0,W=(Fe=(Ne=e.features)==null?void 0:Ne.showToolCalls)!=null?Fe:!0,((qe=e.launcher)==null?void 0:qe.enabled)===!1&&j&&(j.destroy(),j=null),((De=e.launcher)==null?void 0:De.enabled)!==!1&&!j&&(j=fe(e,Ot),t.appendChild(j.element)),j&&j.update(e),o!==C?o?Ct(l):(b=!0,It()):l!==a&&Ct(l),a=l,C=o,Et(),jt();let r=(ze=e.launcher)!=null?ze:{},m=($e=r.headerIconHidden)!=null?$e:!1,d=r.headerIconName,p=(Pe=r.headerIconSize)!=null?Pe:"48px";if(U){let k=P.querySelector(".tvw-border-b-cw-divider"),nt=k==null?void 0:k.querySelector(".tvw-flex-col");if(m)U.style.display="none",k&&nt&&!k.contains(nt)&&k.insertBefore(nt,k.firstChild);else{if(U.style.display="",U.style.height=p,U.style.width=p,k&&nt&&(k.contains(U)?U.nextSibling!==nt&&(U.remove(),k.insertBefore(U,nt)):k.insertBefore(U,nt)),d){let gt=parseFloat(p)||24,X=Tt(d,gt*.6,"#ffffff",2);X?U.replaceChildren(X):U.textContent=(Oe=r.agentIconText)!=null?Oe:"\u{1F4AC}"}else if(r.iconUrl){let gt=U.querySelector("img");if(gt)gt.src=r.iconUrl,gt.style.height=p,gt.style.width=p;else{let X=document.createElement("img");X.src=r.iconUrl,X.alt="",X.className="tvw-rounded-xl tvw-object-cover",X.style.height=p,X.style.width=p,U.replaceChildren(X)}}else{let gt=U.querySelector("svg"),X=U.querySelector("img");(gt||X)&&U.replaceChildren(),U.textContent=(Ue=r.agentIconText)!=null?Ue:"\u{1F4AC}"}let at=U.querySelector("img");at&&(at.style.height=p,at.style.width=p)}}if(H){let k=(je=r.closeButtonSize)!=null?je:"32px",nt=(_e=r.closeButtonPlacement)!=null?_e:"inline";H.style.height=k,H.style.width=k;let at=nt==="top-right",gt=H.classList.contains("tvw-absolute");if(at!==gt)if(H.remove(),at)H.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50 tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none",P.style.position="relative",P.appendChild(H);else{H.className="tvw-ml-auto tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none";let X=P.querySelector(".tvw-border-b-cw-divider");X&&X.appendChild(H)}if(r.closeButtonColor?(H.style.color=r.closeButtonColor,H.classList.remove("tvw-text-cw-muted")):(H.style.color="",H.classList.add("tvw-text-cw-muted")),r.closeButtonBackgroundColor?(H.style.backgroundColor=r.closeButtonBackgroundColor,H.classList.remove("hover:tvw-bg-gray-100")):(H.style.backgroundColor="",H.classList.add("hover:tvw-bg-gray-100")),r.closeButtonBorderWidth||r.closeButtonBorderColor){let X=r.closeButtonBorderWidth||"0px",ie=r.closeButtonBorderColor||"transparent";H.style.border=`${X} solid ${ie}`,H.classList.remove("tvw-border-none")}else H.style.border="",H.classList.add("tvw-border-none");r.closeButtonBorderRadius?(H.style.borderRadius=r.closeButtonBorderRadius,H.classList.remove("tvw-rounded-full")):(H.style.borderRadius="",H.classList.add("tvw-rounded-full"))}T=Mn(e),D.updateConfig(e),Rt(ot,D.getMessages(),T),Mt.render(e.suggestionChips,D,M),zt(),Nt(D.isStreaming());let E=((Ve=e.voiceRecognition)==null?void 0:Ve.enabled)===!0,et=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),Z=E&&et;if(G.classList.remove("tvw-gap-1","tvw-gap-3"),G.classList.add(Z?"tvw-gap-1":"tvw-gap-3"),E&&et)if(!y||!R){let k=Qt(e.voiceRecognition,e.sendButton);k&&(y=k.micButton,R=k.micButtonWrapper,G.insertBefore(R,O),y.addEventListener("click",Ft),y.disabled=D.isStreaming())}else{let k=(Xe=e.voiceRecognition)!=null?Xe:{},nt=(Ye=e.sendButton)!=null?Ye:{},at=(Ke=k.iconName)!=null?Ke:"mic",gt=(Ge=nt.size)!=null?Ge:"40px",X=(Je=k.iconSize)!=null?Je:gt,ie=parseFloat(X)||24;y.style.width=X,y.style.height=X,y.style.minWidth=X,y.style.minHeight=X;let ne=(Qe=(Ze=k.iconColor)!=null?Ze:nt.textColor)!=null?Qe:"currentColor";y.innerHTML="";let wn=Tt(at,ie,ne,2);wn?y.appendChild(wn):y.textContent="\u{1F3A4}";let mn=(tn=k.backgroundColor)!=null?tn:nt.backgroundColor;mn?(y.style.backgroundColor=mn,y.classList.remove("tvw-bg-cw-primary")):(y.style.backgroundColor="",y.classList.add("tvw-bg-cw-primary")),ne?(y.style.color=ne,y.classList.remove("tvw-text-white")):!ne&&!nt.textColor&&(y.style.color="",y.classList.add("tvw-text-white")),k.borderWidth?(y.style.borderWidth=k.borderWidth,y.style.borderStyle="solid"):(y.style.borderWidth="",y.style.borderStyle=""),k.borderColor?y.style.borderColor=k.borderColor:y.style.borderColor="",k.paddingX?(y.style.paddingLeft=k.paddingX,y.style.paddingRight=k.paddingX):(y.style.paddingLeft="",y.style.paddingRight=""),k.paddingY?(y.style.paddingTop=k.paddingY,y.style.paddingBottom=k.paddingY):(y.style.paddingTop="",y.style.paddingBottom="");let le=R==null?void 0:R.querySelector(".tvw-send-button-tooltip"),pe=(en=k.tooltipText)!=null?en:"Start voice recognition";if(((nn=k.showTooltip)!=null?nn:!1)&&pe)if(le)le.textContent=pe,le.style.display="";else{let ge=document.createElement("div");ge.className="tvw-send-button-tooltip",ge.textContent=pe,R==null||R.insertBefore(ge,y)}else le&&(le.style.display="none");R.style.display="",y.disabled=D.isStreaming()}else y&&R&&(R.style.display="none",mt&&ft());let F=(on=e.sendButton)!=null?on:{},Q=(sn=F.useIcon)!=null?sn:!1,I=(rn=F.iconText)!=null?rn:"\u2191",K=F.iconName,yt=(an=F.tooltipText)!=null?an:"Send message",te=(ln=F.showTooltip)!=null?ln:!1,bt=(dn=F.size)!=null?dn:"40px",Wt=F.backgroundColor,dt=F.textColor;if(Q){if(f.style.width=bt,f.style.height=bt,f.style.minWidth=bt,f.style.minHeight=bt,f.style.fontSize="18px",f.style.lineHeight="1",f.innerHTML="",K){let k=parseFloat(bt)||24,nt=dt&&typeof dt=="string"&&dt.trim()?dt.trim():"currentColor",at=Tt(K,k,nt,2);at?(f.appendChild(at),f.style.color=nt):(f.textContent=I,dt?f.style.color=dt:f.classList.add("tvw-text-white"))}else f.textContent=I,dt?f.style.color=dt:f.classList.add("tvw-text-white");f.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",Wt?(f.style.backgroundColor=Wt,f.classList.remove("tvw-bg-cw-primary")):f.classList.add("tvw-bg-cw-primary")}else f.textContent=(un=(cn=e.copy)==null?void 0:cn.sendButtonLabel)!=null?un:"Send",f.style.width="",f.style.height="",f.style.minWidth="",f.style.minHeight="",f.style.fontSize="",f.style.lineHeight="",f.className="tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-50 tvw-cursor-pointer",Wt?(f.style.backgroundColor=Wt,f.classList.remove("tvw-bg-cw-accent")):f.classList.add("tvw-bg-cw-accent"),dt?f.style.color=dt:f.classList.add("tvw-text-white");F.borderWidth?(f.style.borderWidth=F.borderWidth,f.style.borderStyle="solid"):(f.style.borderWidth="",f.style.borderStyle=""),F.borderColor?f.style.borderColor=F.borderColor:f.style.borderColor="",F.paddingX?(f.style.paddingLeft=F.paddingX,f.style.paddingRight=F.paddingX):(f.style.paddingLeft="",f.style.paddingRight=""),F.paddingY?(f.style.paddingTop=F.paddingY,f.style.paddingBottom=F.paddingY):(f.style.paddingTop="",f.style.paddingBottom="");let kt=O==null?void 0:O.querySelector(".tvw-send-button-tooltip");if(te&&yt)if(kt)kt.textContent=yt,kt.style.display="";else{let k=document.createElement("div");k.className="tvw-send-button-tooltip",k.textContent=yt,O==null||O.insertBefore(k,f)}else kt&&(kt.style.display="none");let qt=(pn=e.statusIndicator)!=null?pn:{},ee=(gn=qt.visible)!=null?gn:!0;if(tt.style.display=ee?"":"none",D){let k=D.getStatus(),nt=at=>{var gt,X,ie,ne;return at==="idle"?(gt=qt.idleText)!=null?gt:ct.idle:at==="connecting"?(X=qt.connectingText)!=null?X:ct.connecting:at==="connected"?(ie=qt.connectedText)!=null?ie:ct.connected:at==="error"?(ne=qt.errorText)!=null?ne:ct.error:ct[at]};tt.textContent=nt(k)}},open(){o&&Ct(!0)},close(){o&&Ct(!1)},toggle(){o&&Ct(!b)},destroy(){wt.forEach(s=>s()),x.remove(),j==null||j.destroy(),ht&&H.removeEventListener("click",ht)}}};var Ee={},zn=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},$n=()=>{try{if(typeof Ee!="undefined"&&Ee.url)return new URL("../widget.css",Ee.url).href}catch{}return null},Ln=t=>{let n=$n(),e=()=>{if(!(t instanceof ShadowRoot)||t.querySelector("link[data-vanilla-agent]"))return;let i=document.head.querySelector("link[data-vanilla-agent]");if(!i)return;let o=i.cloneNode(!0);t.insertBefore(o,t.firstChild)};if(t instanceof ShadowRoot)if(n){let i=document.createElement("link");i.rel="stylesheet",i.href=n,i.setAttribute("data-vanilla-agent","true"),t.insertBefore(i,t.firstChild)}else e();else if(!document.head.querySelector("link[data-vanilla-agent]")&&n){let o=document.createElement("link");o.rel="stylesheet",o.href=n,o.setAttribute("data-vanilla-agent","true"),document.head.appendChild(o)}},We=t=>{var C;let n=zn(t.target),e=document.createElement("div");e.className="vanilla-agent-host",n.appendChild(e);let i=t.useShadowDom!==!1,o,l;if(i){let b=e.attachShadow({mode:"open"});l=b,o=document.createElement("div"),o.id="vanilla-agent-root",b.appendChild(o),Ln(b)}else l=e,o=document.createElement("div"),o.id="vanilla-agent-root",e.appendChild(o),Ln(e);let a=ue(o,t.config);return(C=t.onReady)==null||C.call(t),{host:e,update(b){a.update(b)},open(){a.open()},close(){a.close()},toggle(){a.toggle()},destroy(){a.destroy(),e.remove()}}};var Pn=We;0&&(module.exports={ChatWidgetClient,ChatWidgetSession,createChatExperience,directivePostprocessor,escapeHtml,initChatWidget,markdownPostprocessor,pluginRegistry});
|
|
12
|
+
`,e.addEventListener("click",n);let s=l=>{var Y,E,N,P,S,dt,B,b,V,Z;let a=(Y=l.launcher)!=null?Y:{},L=e.querySelector("[data-role='launcher-title']");L&&(L.textContent=(E=a.title)!=null?E:"Chat Assistant");let C=e.querySelector("[data-role='launcher-subtitle']");C&&(C.textContent=(N=a.subtitle)!=null?N:"Get answers fast");let M=e.querySelector(".tvw-flex-col");M&&(a.textHidden?M.style.display="none":M.style.display="");let y=e.querySelector("[data-role='launcher-icon']");if(y)if(a.agentIconHidden)y.style.display="none";else{let nt=(P=a.agentIconSize)!=null?P:"40px";if(y.style.height=nt,y.style.width=nt,y.innerHTML="",a.agentIconName){let ut=parseFloat(nt)||24,Ct=ft(a.agentIconName,ut*.6,"#ffffff",2);Ct?(y.appendChild(Ct),y.style.display=""):(y.textContent=(S=a.agentIconText)!=null?S:"\u{1F4AC}",y.style.display="")}else a.iconUrl?y.style.display="none":(y.textContent=(dt=a.agentIconText)!=null?dt:"\u{1F4AC}",y.style.display="")}let I=e.querySelector("[data-role='launcher-image']");if(I){let nt=(B=a.agentIconSize)!=null?B:"40px";I.style.height=nt,I.style.width=nt,a.iconUrl&&!a.agentIconName&&!a.agentIconHidden?(I.src=a.iconUrl,I.style.display="block"):I.style.display="none"}let h=e.querySelector("[data-role='launcher-call-to-action-icon']");if(h){let nt=(b=a.callToActionIconSize)!=null?b:"32px";h.style.height=nt,h.style.width=nt,a.callToActionIconBackgroundColor?(h.style.backgroundColor=a.callToActionIconBackgroundColor,h.classList.remove("tvw-bg-cw-primary")):(h.style.backgroundColor="",h.classList.add("tvw-bg-cw-primary"));let ut=0;if(a.callToActionIconPadding?(h.style.boxSizing="border-box",h.style.padding=a.callToActionIconPadding,ut=(parseFloat(a.callToActionIconPadding)||0)*2):(h.style.boxSizing="",h.style.padding=""),a.callToActionIconHidden)h.style.display="none";else if(h.style.display="",h.innerHTML="",a.callToActionIconName){let Ct=parseFloat(nt)||24,T=Math.max(Ct-ut,8),j=ft(a.callToActionIconName,T,"currentColor",2);j?h.appendChild(j):h.textContent=(V=a.callToActionIconText)!=null?V:"\u2197"}else h.textContent=(Z=a.callToActionIconText)!=null?Z:"\u2197"}let _=a.position&&he[a.position]?he[a.position]:he["bottom-right"],A="tvw-fixed tvw-flex tvw-items-center tvw-gap-3 tvw-rounded-launcher tvw-bg-cw-surface tvw-py-2.5 tvw-pl-3 tvw-pr-3 tvw-shadow-lg tvw-border tvw-border-gray-200 tvw-transition hover:tvw-translate-y-[-2px] tvw-cursor-pointer";e.className=`${A} ${_}`},o=()=>{e.removeEventListener("click",n),e.remove()};return t&&s(t),{element:e,update:s,destroy:o}};var qn=t=>{var C,M,y,I,h;if(!((M=(C=t==null?void 0:t.launcher)==null?void 0:C.enabled)!=null?M:!0)){let _=p("div","tvw-relative tvw-w-full tvw-h-full"),A=p("div","tvw-relative tvw-w-full tvw-h-full tvw-min-h-[360px]");return _.appendChild(A),{wrapper:_,panel:A}}let e=(y=t==null?void 0:t.launcher)!=null?y:{},s=e.position&&he[e.position]?he[e.position]:he["bottom-right"],o=p("div",`tvw-fixed ${s} tvw-z-50 tvw-transition`),l=p("div","tvw-relative tvw-min-h-[320px]"),a=(h=(I=t==null?void 0:t.launcher)==null?void 0:I.width)!=null?h:t==null?void 0:t.launcherWidth,L=a!=null?a:"min(400px, calc(100vw - 24px))";return l.style.width=L,l.style.maxWidth=L,o.appendChild(l),{wrapper:o,panel:l}},zn=(t,n=!0)=>{var xe,Ce,Bt,Te,Zt,se,G,zt,ie,ae,Ee,le,de,ce,ue,pe,w,R,z,J,r,v,H,u,d,c,i,g,m,F,rt,gt,st,O,Pt,$t,Ot,Nt,Qt,_t,Yt,vt,Ut,ge,Ve,We,ke,Ie,He,Re,Ne,Fe,De,qe,ze,Pe,$e,Oe,_e,Ue;let e=p("div","tvw-flex tvw-h-full tvw-w-full tvw-flex-col tvw-bg-cw-surface tvw-text-cw-primary tvw-rounded-2xl tvw-overflow-hidden tvw-shadow-2xl tvw-border tvw-border-cw-border"),s=p("div","tvw-flex tvw-items-center tvw-gap-3 tvw-bg-cw-surface tvw-px-6 tvw-py-5 tvw-border-b-cw-divider"),o=(xe=t==null?void 0:t.launcher)!=null?xe:{},l=(Ce=o.headerIconSize)!=null?Ce:"48px",a=(Bt=o.closeButtonSize)!=null?Bt:"32px",L=(Te=o.closeButtonPlacement)!=null?Te:"inline",C=(Zt=o.headerIconHidden)!=null?Zt:!1,M=o.headerIconName,y=p("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-xl");if(y.style.height=l,y.style.width=l,!C)if(M){let k=parseFloat(l)||24,tt=ft(M,k*.6,"#ffffff",2);tt?y.replaceChildren(tt):y.textContent=(G=(se=t==null?void 0:t.launcher)==null?void 0:se.agentIconText)!=null?G:"\u{1F4AC}"}else if((zt=t==null?void 0:t.launcher)!=null&&zt.iconUrl){let k=p("img");k.src=t.launcher.iconUrl,k.alt="",k.className="tvw-rounded-xl tvw-object-cover",k.style.height=l,k.style.width=l,y.replaceChildren(k)}else y.textContent=(ae=(ie=t==null?void 0:t.launcher)==null?void 0:ie.agentIconText)!=null?ae:"\u{1F4AC}";let I=p("div","tvw-flex tvw-flex-col"),h=p("span","tvw-text-base tvw-font-semibold");h.textContent=(le=(Ee=t==null?void 0:t.launcher)==null?void 0:Ee.title)!=null?le:"Chat Assistant";let _=p("span","tvw-text-xs tvw-text-cw-muted");_.textContent=(ce=(de=t==null?void 0:t.launcher)==null?void 0:de.subtitle)!=null?ce:"Here to help you get answers fast",I.append(h,_),C?s.append(I):s.append(y,I);let A=(ue=o.clearChat)!=null?ue:{},Y=(pe=A.enabled)!=null?pe:!0,E=null,N=null;if(Y){let k=(w=A.size)!=null?w:"32px",tt=(R=A.iconName)!=null?R:"refresh-cw",mt=(z=A.iconColor)!=null?z:"",jt=(J=A.backgroundColor)!=null?J:"",Tt=(r=A.borderWidth)!=null?r:"",te=(v=A.borderColor)!=null?v:"",me=(H=A.borderRadius)!=null?H:"",ee=(u=A.paddingX)!=null?u:"",Se=(d=A.paddingY)!=null?d:"",ne=(c=A.tooltipText)!=null?c:"Clear chat",Ge=(i=A.showTooltip)!=null?i:!0;N=p("div","tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper"),E=p("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none"),E.style.height=k,E.style.width=k,E.type="button",E.setAttribute("aria-label",ne);let je=ft(tt,"20px",mt||"",2);if(je&&E.appendChild(je),mt&&(E.style.color=mt,E.classList.remove("tvw-text-cw-muted")),jt&&(E.style.backgroundColor=jt,E.classList.remove("hover:tvw-bg-gray-100")),Tt||te){let lt=Tt||"0px",oe=te||"transparent";E.style.border=`${lt} solid ${oe}`,E.classList.remove("tvw-border-none")}if(me&&(E.style.borderRadius=me,E.classList.remove("tvw-rounded-full")),ee?(E.style.paddingLeft=ee,E.style.paddingRight=ee):(E.style.paddingLeft="",E.style.paddingRight=""),Se?(E.style.paddingTop=Se,E.style.paddingBottom=Se):(E.style.paddingTop="",E.style.paddingBottom=""),N.appendChild(E),Ge&&ne&&E&&N){let lt=null,oe=()=>{if(lt||!E)return;lt=p("div","tvw-clear-chat-tooltip"),lt.textContent=ne;let Xe=p("div");Xe.className="tvw-clear-chat-tooltip-arrow",lt.appendChild(Xe);let Me=E.getBoundingClientRect();lt.style.position="fixed",lt.style.left=`${Me.left+Me.width/2}px`,lt.style.top=`${Me.top-8}px`,lt.style.transform="translate(-50%, -100%)",document.body.appendChild(lt)},we=()=>{lt&<.parentNode&&(lt.parentNode.removeChild(lt),lt=null)};N.addEventListener("mouseenter",oe),N.addEventListener("mouseleave",we),E.addEventListener("focus",oe),E.addEventListener("blur",we),N._cleanupTooltip=()=>{we(),N&&(N.removeEventListener("mouseenter",oe),N.removeEventListener("mouseleave",we)),E&&(E.removeEventListener("focus",oe),E.removeEventListener("blur",we))}}s.appendChild(N)}let P=p("div",L==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50":Y?"":"tvw-ml-auto"),S=p("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none");S.style.height=a,S.style.width=a,S.type="button";let dt=(g=o.closeButtonTooltipText)!=null?g:"Close chat",B=(m=o.closeButtonShowTooltip)!=null?m:!0;S.setAttribute("aria-label",dt),S.style.display=n?"":"none";let b=(F=o.closeButtonIconName)!=null?F:"x",V=(rt=o.closeButtonIconText)!=null?rt:"\xD7",Z=ft(b,"20px",o.closeButtonColor||"",2);if(Z?S.appendChild(Z):S.textContent=V,o.closeButtonColor?(S.style.color=o.closeButtonColor,S.classList.remove("tvw-text-cw-muted")):(S.style.color="",S.classList.add("tvw-text-cw-muted")),o.closeButtonBackgroundColor?(S.style.backgroundColor=o.closeButtonBackgroundColor,S.classList.remove("hover:tvw-bg-gray-100")):(S.style.backgroundColor="",S.classList.add("hover:tvw-bg-gray-100")),o.closeButtonBorderWidth||o.closeButtonBorderColor){let k=o.closeButtonBorderWidth||"0px",tt=o.closeButtonBorderColor||"transparent";S.style.border=`${k} solid ${tt}`,S.classList.remove("tvw-border-none")}else S.style.border="",S.classList.add("tvw-border-none");if(o.closeButtonBorderRadius?(S.style.borderRadius=o.closeButtonBorderRadius,S.classList.remove("tvw-rounded-full")):(S.style.borderRadius="",S.classList.add("tvw-rounded-full")),o.closeButtonPaddingX?(S.style.paddingLeft=o.closeButtonPaddingX,S.style.paddingRight=o.closeButtonPaddingX):(S.style.paddingLeft="",S.style.paddingRight=""),o.closeButtonPaddingY?(S.style.paddingTop=o.closeButtonPaddingY,S.style.paddingBottom=o.closeButtonPaddingY):(S.style.paddingTop="",S.style.paddingBottom=""),P.appendChild(S),B&&dt){let k=null,tt=()=>{if(k)return;k=p("div","tvw-clear-chat-tooltip"),k.textContent=dt;let jt=p("div");jt.className="tvw-clear-chat-tooltip-arrow",k.appendChild(jt);let Tt=S.getBoundingClientRect();k.style.position="fixed",k.style.left=`${Tt.left+Tt.width/2}px`,k.style.top=`${Tt.top-8}px`,k.style.transform="translate(-50%, -100%)",document.body.appendChild(k)},mt=()=>{k&&k.parentNode&&(k.parentNode.removeChild(k),k=null)};P.addEventListener("mouseenter",tt),P.addEventListener("mouseleave",mt),S.addEventListener("focus",tt),S.addEventListener("blur",mt),P._cleanupTooltip=()=>{mt(),P.removeEventListener("mouseenter",tt),P.removeEventListener("mouseleave",mt),S.removeEventListener("focus",tt),S.removeEventListener("blur",mt)}}L==="top-right"?(e.style.position="relative",e.appendChild(P)):s.appendChild(P);let nt=p("div","tvw-flex tvw-flex-1 tvw-min-h-0 tvw-flex-col tvw-gap-6 tvw-overflow-y-auto tvw-bg-cw-container tvw-px-6 tvw-py-6"),ut=p("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),Ct=p("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");Ct.textContent=(st=(gt=t==null?void 0:t.copy)==null?void 0:gt.welcomeTitle)!=null?st:"Hello \u{1F44B}";let T=p("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");T.textContent=(Pt=(O=t==null?void 0:t.copy)==null?void 0:O.welcomeSubtitle)!=null?Pt:"Ask anything about your account or products.",ut.append(Ct,T);let j=p("div","tvw-flex tvw-flex-col tvw-gap-3");nt.append(ut,j);let f=p("div","tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),ct=p("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),At=(($t=t==null?void 0:t.voiceRecognition)==null?void 0:$t.enabled)===!0,Xt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),bt=p("form",`tvw-flex tvw-items-end ${At&&Xt?"tvw-gap-1":"tvw-gap-3"} tvw-rounded-2xl tvw-border tvw-border-gray-200 tvw-bg-cw-input-background tvw-px-4 tvw-py-3`);bt.style.outline="none";let D=p("textarea");D.placeholder=(Nt=(Ot=t==null?void 0:t.copy)==null?void 0:Ot.inputPlaceholder)!=null?Nt:"Type your message\u2026",D.className="tvw-min-h-[48px] tvw-flex-1 tvw-resize-none tvw-border-none tvw-bg-transparent tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-none",D.rows=1;let Gt=(_t=(Qt=t==null?void 0:t.theme)==null?void 0:Qt.inputFontFamily)!=null?_t:"sans-serif",ve=(vt=(Yt=t==null?void 0:t.theme)==null?void 0:Yt.inputFontWeight)!=null?vt:"400",Dt=k=>{switch(k){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};D.style.fontFamily=Dt(Gt),D.style.fontWeight=ve,D.style.border="none",D.style.outline="none",D.style.borderWidth="0",D.style.borderStyle="none",D.style.borderColor="transparent",D.addEventListener("focus",()=>{D.style.border="none",D.style.outline="none",D.style.borderWidth="0",D.style.borderStyle="none",D.style.borderColor="transparent",D.style.boxShadow="none"}),D.addEventListener("blur",()=>{D.style.border="none",D.style.outline="none"});let X=(Ut=t==null?void 0:t.sendButton)!=null?Ut:{},Kt=(ge=X.useIcon)!=null?ge:!1,Jt=(Ve=X.iconText)!=null?Ve:"\u2191",fe=X.iconName,ye=(We=X.tooltipText)!=null?We:"Send message",Ae=(ke=X.showTooltip)!=null?ke:!1,It=(Ie=X.size)!=null?Ie:"40px",qt=X.backgroundColor,at=X.textColor,Et=p("div","tvw-send-button-wrapper"),W=p("button",Kt?"tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer":"tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold disabled:tvw-opacity-50 tvw-cursor-pointer");if(W.type="submit",Kt){if(W.style.width=It,W.style.height=It,W.style.minWidth=It,W.style.minHeight=It,W.style.fontSize="18px",W.style.lineHeight="1",W.innerHTML="",fe){let k=parseFloat(It)||24,tt=at&&typeof at=="string"&&at.trim()?at.trim():"currentColor",mt=ft(fe,k,tt,2);mt?(W.appendChild(mt),W.style.color=tt):(W.textContent=Jt,at?W.style.color=at:W.classList.add("tvw-text-white"))}else W.textContent=Jt,at?W.style.color=at:W.classList.add("tvw-text-white");qt?W.style.backgroundColor=qt:W.classList.add("tvw-bg-cw-primary")}else W.textContent=(Re=(He=t==null?void 0:t.copy)==null?void 0:He.sendButtonLabel)!=null?Re:"Send",at?W.style.color=at:W.classList.add("tvw-text-white");if(X.borderWidth&&(W.style.borderWidth=X.borderWidth,W.style.borderStyle="solid"),X.borderColor&&(W.style.borderColor=X.borderColor),X.paddingX?(W.style.paddingLeft=X.paddingX,W.style.paddingRight=X.paddingX):(W.style.paddingLeft="",W.style.paddingRight=""),X.paddingY?(W.style.paddingTop=X.paddingY,W.style.paddingBottom=X.paddingY):(W.style.paddingTop="",W.style.paddingBottom=""),Ae&&ye){let k=p("div","tvw-send-button-tooltip");k.textContent=ye,Et.appendChild(k)}Et.appendChild(W);let Q=(Ne=t==null?void 0:t.voiceRecognition)!=null?Ne:{},be=Q.enabled===!0,q=null,Mt=null,pt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(be&&pt){Mt=p("div","tvw-send-button-wrapper"),q=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),q.type="button",q.setAttribute("aria-label","Start voice recognition");let k=(Fe=Q.iconName)!=null?Fe:"mic",tt=(De=Q.iconSize)!=null?De:It,mt=parseFloat(tt)||24,jt=(qe=Q.backgroundColor)!=null?qe:qt,Tt=(ze=Q.iconColor)!=null?ze:at;q.style.width=tt,q.style.height=tt,q.style.minWidth=tt,q.style.minHeight=tt,q.style.fontSize="18px",q.style.lineHeight="1";let te=Tt||"currentColor",me=ft(k,mt,te,1.5);me?(q.appendChild(me),q.style.color=te):(q.textContent="\u{1F3A4}",q.style.color=te),jt?q.style.backgroundColor=jt:q.classList.add("tvw-bg-cw-primary"),Tt?q.style.color=Tt:!Tt&&!at&&q.classList.add("tvw-text-white"),Q.borderWidth&&(q.style.borderWidth=Q.borderWidth,q.style.borderStyle="solid"),Q.borderColor&&(q.style.borderColor=Q.borderColor),Q.paddingX&&(q.style.paddingLeft=Q.paddingX,q.style.paddingRight=Q.paddingX),Q.paddingY&&(q.style.paddingTop=Q.paddingY,q.style.paddingBottom=Q.paddingY),Mt.appendChild(q);let ee=(Pe=Q.tooltipText)!=null?Pe:"Start voice recognition";if((($e=Q.showTooltip)!=null?$e:!1)&&ee){let ne=p("div","tvw-send-button-tooltip");ne.textContent=ee,Mt.appendChild(ne)}}bt.addEventListener("click",k=>{k.target!==W&&k.target!==Et&&k.target!==q&&k.target!==Mt&&D.focus()}),bt.append(D),Mt&&bt.append(Mt),bt.append(Et);let ht=p("div","tvw-mt-2 tvw-text-right tvw-text-xs tvw-text-cw-muted"),Ht=(Oe=t==null?void 0:t.statusIndicator)!=null?Oe:{},Rt=(_e=Ht.visible)!=null?_e:!0;return ht.style.display=Rt?"":"none",ht.textContent=(Ue=Ht.idleText)!=null?Ue:"Online",f.append(ct,bt,ht),e.append(s,nt,f),{container:e,body:nt,messagesWrapper:j,suggestions:ct,textarea:D,sendButton:W,sendButtonWrapper:Et,micButton:q,micButtonWrapper:Mt,composerForm:bt,statusText:ht,introTitle:Ct,introSubtitle:T,closeButton:S,closeButtonWrapper:P,clearChatButton:E,clearChatButtonWrapper:N,iconHolder:y}};var sn=()=>{let t=document.createElement("div");t.className="tvw-flex tvw-items-center tvw-space-x-1 tvw-h-5 tvw-mt-2";let n=document.createElement("div");n.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",n.style.animationDelay="0ms";let e=document.createElement("div");e.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",e.style.animationDelay="250ms";let s=document.createElement("div");s.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",s.style.animationDelay="500ms";let o=document.createElement("span");return o.className="tvw-sr-only",o.textContent="Loading",t.appendChild(n),t.appendChild(e),t.appendChild(s),t.appendChild(o),t},an=(t,n)=>{let e=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm"];t.role==="user"?e.push("tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-5","tvw-py-3"):e.push("tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3");let s=p("div",e.join(" ")),o=document.createElement("div");if(o.innerHTML=n({text:t.content,message:t,streaming:!!t.streaming}),s.appendChild(o),t.streaming&&t.role==="assistant"&&t.content&&t.content.trim()){let l=sn();s.appendChild(l)}return s};var ln=t=>{if(t===null)return"null";if(t===void 0)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);try{return JSON.stringify(t,null,2)}catch{return String(t)}},so=t=>{var a,L;let n=(a=t.completedAt)!=null?a:Date.now(),e=(L=t.startedAt)!=null?L:n,o=(t.durationMs!==void 0?t.durationMs:Math.max(0,n-e))/1e3;return o<.1?"Thought for <0.1 seconds":`Thought for ${o>=10?Math.round(o).toString():o.toFixed(1).replace(/\.0$/,"")} seconds`},Pn=t=>t.status==="complete"?so(t):t.status==="pending"?"Waiting":"",io=t=>{var o,l,a;let e=(typeof t.duration=="number"?t.duration:typeof t.durationMs=="number"?t.durationMs:Math.max(0,((o=t.completedAt)!=null?o:Date.now())-((a=(l=t.startedAt)!=null?l:t.completedAt)!=null?a:Date.now())))/1e3;return e<.1?"Used tool for <0.1 seconds":`Used tool for ${e>=10?Math.round(e).toString():e.toFixed(1).replace(/\.0$/,"")} seconds`};var $n=t=>t.status==="complete"?io(t):"Using tool...";var dn=new Set,cn=t=>{let n=t.reasoning,e=p("div",["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(!n)return e;let s=dn.has(t.id),o=p("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");o.type="button",o.setAttribute("aria-expanded",s?"true":"false");let l=p("div","tvw-flex tvw-flex-col tvw-text-left"),a=p("span","tvw-text-xs tvw-font-semibold tvw-text-cw-primary");a.textContent="Thinking...",l.appendChild(a);let L=p("span","tvw-text-xs tvw-text-cw-primary");L.textContent=Pn(n),l.appendChild(L),n.status==="complete"?a.style.display="none":a.style.display="";let C=p("span","tvw-text-xs tvw-text-cw-primary");C.textContent=s?"Hide":"Show",o.append(l,C);let M=p("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-px-4 tvw-py-3");M.style.display=s?"":"none";let y=n.chunks.join(""),I=p("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");I.textContent=y||(n.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),M.appendChild(I);let h=()=>{o.setAttribute("aria-expanded",s?"true":"false"),C.textContent=s?"Hide":"Show",M.style.display=s?"":"none"},_=()=>{s=!s,s?dn.add(t.id):dn.delete(t.id),h()};return o.addEventListener("pointerdown",A=>{A.preventDefault(),_()}),o.addEventListener("keydown",A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),_())}),h(),e.append(o,M),e};var un=new Set,pn=t=>{let n=t.toolCall,e=p("div",["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(!n)return e;let s=un.has(t.id),o=p("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");o.type="button",o.setAttribute("aria-expanded",s?"true":"false");let l=p("div","tvw-flex tvw-flex-col tvw-text-left"),a=p("span","tvw-text-xs tvw-text-cw-primary");if(a.textContent=$n(n),l.appendChild(a),n.name){let h=p("span","tvw-text-[11px] tvw-text-cw-muted");h.textContent=n.name,l.appendChild(h)}let L=p("span","tvw-text-xs tvw-text-cw-primary");L.textContent=s?"Hide":"Show";let C=p("div","tvw-flex tvw-items-center tvw-gap-2");C.append(L),o.append(l,C);let M=p("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(M.style.display=s?"":"none",n.args!==void 0){let h=p("div","tvw-space-y-1"),_=p("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");_.textContent="Arguments";let A=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-font-xxs tvw-text-cw-primary");A.textContent=ln(n.args),h.append(_,A),M.appendChild(h)}if(n.chunks&&n.chunks.length){let h=p("div","tvw-space-y-1"),_=p("div","tvw-font-xxs tvw-font-medium tvw-text-cw-muted");_.textContent="Activity";let A=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-font-xxs tvw-text-cw-primary");A.textContent=n.chunks.join(`
|
|
13
|
+
`),h.append(_,A),M.appendChild(h)}if(n.status==="complete"&&n.result!==void 0){let h=p("div","tvw-space-y-1"),_=p("div","tvw-font-xxs tvw-text-sm tvw-text-cw-muted");_.textContent="Result";let A=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-font-xxs tvw-text-cw-primary");A.textContent=ln(n.result),h.append(_,A),M.appendChild(h)}if(n.status==="complete"&&typeof n.duration=="number"){let h=p("div","tvw-font-xxs tvw-text-cw-muted");h.textContent=`Duration: ${n.duration}ms`,M.appendChild(h)}let y=()=>{o.setAttribute("aria-expanded",s?"true":"false"),L.textContent=s?"Hide":"Show",M.style.display=s?"":"none"},I=()=>{s=!s,s?un.add(t.id):un.delete(t.id),y()};return o.addEventListener("pointerdown",h=>{h.preventDefault(),I()}),o.addEventListener("keydown",h=>{(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),I())}),y(),e.append(o,M),e};var On=t=>{let n=[];return{buttons:n,render:(s,o,l,a)=>{if(t.innerHTML="",n.length=0,!s||!s.length||(a!=null?a:o?o.getMessages():[]).some(I=>I.role==="user"))return;let M=document.createDocumentFragment(),y=o?o.isStreaming():!1;s.forEach(I=>{let h=p("button","tvw-rounded-button tvw-bg-cw-surface tvw-px-3 tvw-py-1.5 tvw-text-xs tvw-font-medium tvw-text-cw-muted hover:tvw-opacity-90 tvw-cursor-pointer tvw-border tvw-border-gray-200");h.type="button",h.textContent=I,h.disabled=y,h.addEventListener("click",()=>{!o||o.isStreaming()||(l.value="",o.sendMessage(I))}),M.appendChild(h),n.push(h)}),t.appendChild(M)}}};var _n={init:{title:"Schedule a Demo",description:"Share the basics and we'll follow up with a confirmation.",fields:[{name:"name",label:"Full name",placeholder:"Jane Doe",required:!0},{name:"email",label:"Work email",placeholder:"jane@example.com",type:"email",required:!0},{name:"notes",label:"What would you like to cover?",type:"textarea"}],submitLabel:"Submit details"},followup:{title:"Additional Information",description:"Provide any extra details to tailor the next steps.",fields:[{name:"company",label:"Company",placeholder:"Acme Inc."},{name:"context",label:"Context",type:"textarea",placeholder:"Share more about your use case"}],submitLabel:"Send"}},gn=(t,n,e,s)=>{let o=t.querySelectorAll("[data-tv-form]");o.length&&o.forEach(l=>{var A,Y,E;if(l.dataset.enhanced==="true")return;let a=(A=l.dataset.tvForm)!=null?A:"init";l.dataset.enhanced="true";let L=(Y=_n[a])!=null?Y:_n.init;l.classList.add("tvw-form-card","tvw-space-y-4");let C=p("div","tvw-space-y-1"),M=p("h3","tvw-text-base tvw-font-semibold tvw-text-cw-primary");if(M.textContent=L.title,C.appendChild(M),L.description){let N=p("p","tvw-text-sm tvw-text-cw-muted");N.textContent=L.description,C.appendChild(N)}let y=document.createElement("form");y.className="tvw-form-grid tvw-space-y-3",L.fields.forEach(N=>{var b,V;let P=p("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");P.htmlFor=`${n.id}-${a}-${N.name}`;let S=p("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");S.textContent=N.label,P.appendChild(S);let dt=(b=N.type)!=null?b:"text",B;dt==="textarea"?(B=document.createElement("textarea"),B.rows=3):(B=document.createElement("input"),B.type=dt),B.className="tvw-rounded-xl tvw-border tvw-border-gray-200 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-cw-primary",B.id=`${n.id}-${a}-${N.name}`,B.name=N.name,B.placeholder=(V=N.placeholder)!=null?V:"",N.required&&(B.required=!0),P.appendChild(B),y.appendChild(P)});let I=p("div","tvw-flex tvw-items-center tvw-justify-between tvw-gap-2"),h=p("div","tvw-text-xs tvw-text-cw-muted tvw-min-h-[1.5rem]"),_=p("button","tvw-inline-flex tvw-items-center tvw-rounded-full tvw-bg-cw-primary tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-60 tvw-cursor-pointer");_.type="submit",_.textContent=(E=L.submitLabel)!=null?E:"Submit",I.appendChild(h),I.appendChild(_),y.appendChild(I),l.replaceChildren(C,y),y.addEventListener("submit",async N=>{var B,b;N.preventDefault();let P=(B=e.formEndpoint)!=null?B:"/form",S=new FormData(y),dt={};S.forEach((V,Z)=>{dt[Z]=V}),dt.type=a,_.disabled=!0,h.textContent="Submitting\u2026";try{let V=await fetch(P,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(dt)});if(!V.ok)throw new Error(`Form submission failed (${V.status})`);let Z=await V.json();h.textContent=(b=Z.message)!=null?b:"Thanks! We'll be in touch soon.",Z.success&&Z.nextPrompt&&await s.sendMessage(String(Z.nextPrompt))}catch(V){h.textContent=V instanceof Error?V.message:"Something went wrong. Please try again."}finally{_.disabled=!1}})})};var mn=class{constructor(){this.plugins=new Map}register(n){var e;this.plugins.has(n.id)&&console.warn(`Plugin "${n.id}" is already registered. Overwriting.`),this.plugins.set(n.id,n),(e=n.onRegister)==null||e.call(n)}unregister(n){var s;let e=this.plugins.get(n);e&&((s=e.onUnregister)==null||s.call(e),this.plugins.delete(n))}getAll(){return Array.from(this.plugins.values()).sort((n,e)=>{var s,o;return((s=e.priority)!=null?s:0)-((o=n.priority)!=null?o:0)})}getForInstance(n){let e=this.getAll();if(!n||n.length===0)return e;let s=new Set(n.map(l=>l.id));return[...e.filter(l=>!s.has(l.id)),...n].sort((l,a)=>{var L,C;return((L=a.priority)!=null?L:0)-((C=l.priority)!=null?C:0)})}clear(){this.plugins.forEach(n=>{var e;return(e=n.onUnregister)==null?void 0:e.call(n)}),this.plugins.clear()}},Ye=new mn;var kt={apiUrl:"http://localhost:43111/api/chat/dispatch",theme:{primary:"#111827",accent:"#1d4ed8",surface:"#ffffff",muted:"#6b7280",container:"#f8fafc",border:"#f1f5f9",divider:"#f1f5f9",messageBorder:"#f1f5f9",inputBackground:"#ffffff",callToAction:"#000000",callToActionBackground:"#ffffff",sendButtonBackgroundColor:"#111827",sendButtonTextColor:"#ffffff",sendButtonBorderColor:"#60a5fa",closeButtonColor:"#6b7280",closeButtonBackgroundColor:"transparent",closeButtonBorderColor:"",clearChatIconColor:"#6b7280",clearChatBackgroundColor:"transparent",clearChatBorderColor:"transparent",micIconColor:"#111827",micBackgroundColor:"transparent",micBorderColor:"transparent",recordingIconColor:"#ffffff",recordingBackgroundColor:"#ef4444",recordingBorderColor:"transparent",inputFontFamily:"sans-serif",inputFontWeight:"400",radiusSm:"0.75rem",radiusMd:"1rem",radiusLg:"1.5rem",launcherRadius:"9999px",buttonRadius:"9999px"},launcher:{enabled:!0,title:"Chat Assistant",subtitle:"Here to help you get answers fast",agentIconText:"\u{1F4AC}",position:"bottom-right",width:"min(400px, calc(100vw - 24px))",autoExpand:!1,callToActionIconHidden:!1,agentIconSize:"40px",headerIconSize:"40px",closeButtonSize:"32px",callToActionIconName:"arrow-up-right",callToActionIconText:"",callToActionIconSize:"32px",callToActionIconPadding:"5px",callToActionIconColor:"#000000",callToActionIconBackgroundColor:"#ffffff",closeButtonColor:"#6b7280",closeButtonBackgroundColor:"transparent",clearChat:{iconColor:"#6b7280",backgroundColor:"transparent",borderColor:"transparent",enabled:!0,iconName:"refresh-cw",size:"29px",showTooltip:!0,tooltipText:"Clear chat",paddingX:"0px",paddingY:"0px"},headerIconHidden:!1},copy:{welcomeTitle:"Hello \u{1F44B}",welcomeSubtitle:"Ask anything about your account or products.",inputPlaceholder:"How can I help...",sendButtonLabel:"Send"},sendButton:{borderWidth:"0px",paddingX:"12px",paddingY:"10px",backgroundColor:"#111827",textColor:"#ffffff",borderColor:"#60a5fa",useIcon:!0,iconText:"\u2191",size:"40px",showTooltip:!0,tooltipText:"Send message",iconName:"send"},statusIndicator:{visible:!0,idleText:"Online",connectingText:"Connecting\u2026",connectedText:"Streaming\u2026",errorText:"Offline"},voiceRecognition:{enabled:!0,pauseDuration:2e3,iconName:"mic",iconSize:"39px",borderWidth:"0px",paddingX:"9px",paddingY:"14px",iconColor:"#111827",backgroundColor:"transparent",borderColor:"transparent",recordingIconColor:"#ffffff",recordingBackgroundColor:"#ef4444",recordingBorderColor:"transparent",showTooltip:!0,tooltipText:"Start voice recognition"},features:{showReasoning:!0,showToolCalls:!0},suggestionChips:["What can you help me with?","Tell me about your features","How does this work?"],debug:!1};function Ze(t){var n,e,s;return t?{...kt,...t,theme:{...kt.theme,...t.theme},launcher:{...kt.launcher,...t.launcher,clearChat:{...(n=kt.launcher)==null?void 0:n.clearChat,...(e=t.launcher)==null?void 0:e.clearChat}},copy:{...kt.copy,...t.copy},sendButton:{...kt.sendButton,...t.sendButton},statusIndicator:{...kt.statusIndicator,...t.statusIndicator},voiceRecognition:{...kt.voiceRecognition,...t.voiceRecognition},features:{...kt.features,...t.features},suggestionChips:(s=t.suggestionChips)!=null?s:kt.suggestionChips}:kt}var Un=t=>t!=null&&t.postprocessMessage?n=>t.postprocessMessage({text:n.text,message:n.message,streaming:n.streaming}):({text:n})=>Je(n),Qe=(t,n)=>{var le,de,ce,ue,pe,w,R,z,J;(!t.id||t.id!=="vanilla-agent-root")&&(t.id="vanilla-agent-root");let e=Ze(n);on(t,e);let s=Ye.getForInstance(e.plugins),o=(de=(le=e.launcher)==null?void 0:le.enabled)!=null?de:!0,l=(ue=(ce=e.launcher)==null?void 0:ce.autoExpand)!=null?ue:!1,a=l,L=o,C=o?l:!0,M=Un(e),y=(w=(pe=e.features)==null?void 0:pe.showReasoning)!=null?w:!0,I=(z=(R=e.features)==null?void 0:R.showToolCalls)!=null?z:!0,h=(J=e.statusIndicator)!=null?J:{},_=r=>{var v,H,u,d;return r==="idle"?(v=h.idleText)!=null?v:yt.idle:r==="connecting"?(H=h.connectingText)!=null?H:yt.connecting:r==="connected"?(u=h.connectedText)!=null?u:yt.connected:r==="error"?(d=h.errorText)!=null?d:yt.error:yt[r]},{wrapper:A,panel:Y}=qn(e),E=zn(e,o),{container:N,body:P,messagesWrapper:S,suggestions:dt,textarea:B,sendButton:b,sendButtonWrapper:V,composerForm:Z,statusText:nt,introTitle:ut,introSubtitle:Ct,closeButton:T,iconHolder:j}=E,f=E.micButton,ct=E.micButtonWrapper;Y.appendChild(N),t.appendChild(A);let At=[],Xt=On(dt),Ft=null,$,bt=!1,D=!0,Gt=0,ve=0,Dt=null,X=!1,Kt=0,Jt=!1,fe=125,ye=2e3,Ae=5,It=50,qt=(r=!1)=>{if(!D)return;let v=Date.now();X&&v<Kt&&!r||(X&&v>=Kt&&(X=!1),!(!r&&!bt)&&(v-ve<fe||(ve=v,Dt&&cancelAnimationFrame(Dt),Dt=requestAnimationFrame(()=>{X||!D||(Jt=!0,P.scrollTop=P.scrollHeight,Gt=P.scrollTop,requestAnimationFrame(()=>{Jt=!1}),Dt=null)}))))},at=(r,v,H)=>{r.innerHTML="";let u=document.createDocumentFragment();v.forEach(c=>{let i=null,g=s.find(F=>!!(c.variant==="reasoning"&&F.renderReasoning||c.variant==="tool"&&F.renderToolCall||!c.variant&&F.renderMessage));if(g)if(c.variant==="reasoning"&&c.reasoning&&g.renderReasoning){if(!y)return;i=g.renderReasoning({message:c,defaultRenderer:()=>cn(c),config:e})}else if(c.variant==="tool"&&c.toolCall&&g.renderToolCall){if(!I)return;i=g.renderToolCall({message:c,defaultRenderer:()=>pn(c),config:e})}else g.renderMessage&&(i=g.renderMessage({message:c,defaultRenderer:()=>{let F=an(c,H);return c.role!=="user"&&gn(F,c,e,$),F},config:e}));if(!i)if(c.variant==="reasoning"&&c.reasoning){if(!y)return;i=cn(c)}else if(c.variant==="tool"&&c.toolCall){if(!I)return;i=pn(c)}else i=an(c,H),c.role!=="user"&&gn(i,c,e,$);let m=document.createElement("div");m.className="tvw-flex",c.role==="user"&&m.classList.add("tvw-justify-end"),m.appendChild(i),u.appendChild(m)});let d=v.some(c=>c.role==="assistant"&&c.streaming&&c.content&&c.content.trim());if(bt&&v.some(c=>c.role==="user")&&!d){let c=sn(),i=document.createElement("div");i.className=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3"].join(" "),i.appendChild(c);let g=document.createElement("div");g.className="tvw-flex",g.appendChild(i),u.appendChild(g)}r.appendChild(u),r.scrollTop=r.scrollHeight},Et=()=>{o&&(C?(A.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),Y.classList.remove("tvw-scale-95","tvw-opacity-0"),Y.classList.add("tvw-scale-100","tvw-opacity-100"),G&&(G.element.style.display="none")):(A.classList.add("tvw-pointer-events-none","tvw-opacity-0"),Y.classList.remove("tvw-scale-100","tvw-opacity-100"),Y.classList.add("tvw-scale-95","tvw-opacity-0"),G&&(G.element.style.display="")))},W=r=>{o&&C!==r&&(C=r,Et(),C&&(zt(),qt(!0)))},Q=r=>{B.disabled=r,b.disabled=r,f&&(f.disabled=r),Xt.buttons.forEach(v=>{v.disabled=r})},be=()=>{var d,c,i,g,m,F,rt,gt,st,O,Pt,$t,Ot,Nt;ut.textContent=(c=(d=e.copy)==null?void 0:d.welcomeTitle)!=null?c:"Hello \u{1F44B}",Ct.textContent=(g=(i=e.copy)==null?void 0:i.welcomeSubtitle)!=null?g:"Ask anything about your account or products.",B.placeholder=(F=(m=e.copy)==null?void 0:m.inputPlaceholder)!=null?F:"How can I help...",((gt=(rt=e.sendButton)==null?void 0:rt.useIcon)!=null?gt:!1)||(b.textContent=(O=(st=e.copy)==null?void 0:st.sendButtonLabel)!=null?O:"Send");let v=($t=(Pt=e.theme)==null?void 0:Pt.inputFontFamily)!=null?$t:"sans-serif",H=(Nt=(Ot=e.theme)==null?void 0:Ot.inputFontWeight)!=null?Nt:"400",u=Qt=>{switch(Qt){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};B.style.fontFamily=u(v),B.style.fontWeight=H};$=new Be(e,{onMessagesChanged(r){at(S,r,M),$&&(r.some(H=>H.role==="user")?Xt.render([],$,B,r):Xt.render(e.suggestionChips,$,B,r)),qt(!bt)},onStatusChanged(r){var u;let v=(u=e.statusIndicator)!=null?u:{},H=d=>{var c,i,g,m;return d==="idle"?(c=v.idleText)!=null?c:yt.idle:d==="connecting"?(i=v.connectingText)!=null?i:yt.connecting:d==="connected"?(g=v.connectedText)!=null?g:yt.connected:d==="error"?(m=v.errorText)!=null?m:yt.error:yt[d]};nt.textContent=H(r)},onStreamingChanged(r){bt=r,Q(r),$&&at(S,$.getMessages(),M),r||qt(!0)}});let q=r=>{r.preventDefault();let v=B.value.trim();v&&(B.value="",$.sendMessage(v))},Mt=r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),b.click())},pt=null,ht=!1,Ht=null,Rt=null,xe=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,Ce=()=>{var d,c,i,g;if(ht||$.isStreaming())return;let r=xe();if(!r)return;pt=new r;let H=(c=((d=e.voiceRecognition)!=null?d:{}).pauseDuration)!=null?c:2e3;pt.continuous=!0,pt.interimResults=!0,pt.lang="en-US";let u=B.value;pt.onresult=m=>{let F="",rt="";for(let st=0;st<m.results.length;st++){let O=m.results[st],Pt=O[0].transcript;O.isFinal?F+=Pt+" ":rt=Pt}let gt=u+F+rt;B.value=gt,Ht&&clearTimeout(Ht),(F||rt)&&(Ht=window.setTimeout(()=>{let st=B.value.trim();st&&pt&&ht&&(Bt(),B.value="",$.sendMessage(st))},H))},pt.onerror=m=>{m.error!=="no-speech"&&Bt()},pt.onend=()=>{if(ht){let m=B.value.trim();m&&m!==u.trim()&&(B.value="",$.sendMessage(m)),Bt()}};try{if(pt.start(),ht=!0,f){Rt={backgroundColor:f.style.backgroundColor,color:f.style.color,borderColor:f.style.borderColor};let m=(i=e.voiceRecognition)!=null?i:{},F=(g=m.recordingBackgroundColor)!=null?g:"#ef4444",rt=m.recordingIconColor,gt=m.recordingBorderColor;if(f.classList.add("tvw-voice-recording"),f.style.backgroundColor=F,rt){f.style.color=rt;let st=f.querySelector("svg");st&&st.setAttribute("stroke",rt)}gt&&(f.style.borderColor=gt),f.setAttribute("aria-label","Stop voice recognition")}}catch{Bt()}},Bt=()=>{if(ht){if(ht=!1,Ht&&(clearTimeout(Ht),Ht=null),pt){try{pt.stop()}catch{}pt=null}if(f){if(f.classList.remove("tvw-voice-recording"),Rt){f.style.backgroundColor=Rt.backgroundColor,f.style.color=Rt.color,f.style.borderColor=Rt.borderColor;let r=f.querySelector("svg");r&&r.setAttribute("stroke",Rt.color||"currentColor"),Rt=null}f.setAttribute("aria-label","Start voice recognition")}}},Te=(r,v)=>{var $t,Ot,Nt,Qt,_t,Yt,vt;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let u=p("div","tvw-send-button-wrapper"),d=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");d.type="button",d.setAttribute("aria-label","Start voice recognition");let c=($t=r==null?void 0:r.iconName)!=null?$t:"mic",i=(Ot=v==null?void 0:v.size)!=null?Ot:"40px",g=(Nt=r==null?void 0:r.iconSize)!=null?Nt:i,m=parseFloat(g)||24,F=(Qt=r==null?void 0:r.backgroundColor)!=null?Qt:v==null?void 0:v.backgroundColor,rt=(_t=r==null?void 0:r.iconColor)!=null?_t:v==null?void 0:v.textColor;d.style.width=g,d.style.height=g,d.style.minWidth=g,d.style.minHeight=g,d.style.fontSize="18px",d.style.lineHeight="1";let gt=rt||"currentColor",st=ft(c,m,gt,1.5);st?(d.appendChild(st),d.style.color=gt):(d.textContent="\u{1F3A4}",d.style.color=gt),F?d.style.backgroundColor=F:d.classList.add("tvw-bg-cw-primary"),rt?d.style.color=rt:!rt&&!(v!=null&&v.textColor)&&d.classList.add("tvw-text-white"),r!=null&&r.borderWidth&&(d.style.borderWidth=r.borderWidth,d.style.borderStyle="solid"),r!=null&&r.borderColor&&(d.style.borderColor=r.borderColor),r!=null&&r.paddingX&&(d.style.paddingLeft=r.paddingX,d.style.paddingRight=r.paddingX),r!=null&&r.paddingY&&(d.style.paddingTop=r.paddingY,d.style.paddingBottom=r.paddingY),u.appendChild(d);let O=(Yt=r==null?void 0:r.tooltipText)!=null?Yt:"Start voice recognition";if(((vt=r==null?void 0:r.showTooltip)!=null?vt:!1)&&O){let Ut=p("div","tvw-send-button-tooltip");Ut.textContent=O,u.appendChild(Ut)}return{micButton:d,micButtonWrapper:u}},Zt=()=>{if(ht){let r=B.value.trim();Bt(),r&&(B.value="",$.sendMessage(r))}else Ce()};f&&(f.addEventListener("click",Zt),At.push(()=>{Bt(),f&&f.removeEventListener("click",Zt)}));let se=()=>{W(!C)},G=o?rn(e,se):null;G&&t.appendChild(G.element),Et(),Xt.render(e.suggestionChips,$,B),be(),Q($.isStreaming()),qt(!0);let zt=()=>{var i,g;if(!o){Y.style.height="",Y.style.width="";return}let r=(g=(i=e==null?void 0:e.launcher)==null?void 0:i.width)!=null?g:e==null?void 0:e.launcherWidth,v=r!=null?r:"min(400px, calc(100vw - 24px))";Y.style.width=v,Y.style.maxWidth=v;let H=window.innerHeight,d=Math.max(200,H-64),c=Math.min(640,d);Y.style.height=`${c}px`};zt(),window.addEventListener("resize",zt),At.push(()=>window.removeEventListener("resize",zt)),Gt=P.scrollTop;let ie=()=>{let r=P.scrollTop,v=P.scrollHeight,H=P.clientHeight,u=v-r-H,d=Math.abs(r-Gt);if(Gt=r,!Jt&&!(d<=Ae)){if(!D&&u<It){X=!1,D=!0;return}D&&u>It&&(X=!0,Kt=Date.now()+ye,D=!1)}};P.addEventListener("scroll",ie,{passive:!0}),At.push(()=>P.removeEventListener("scroll",ie)),At.push(()=>{Dt&&cancelAnimationFrame(Dt)});let ae=()=>{T&&(Ft&&(T.removeEventListener("click",Ft),Ft=null),o?(T.style.display="",Ft=()=>{C=!1,Et()},T.addEventListener("click",Ft)):T.style.display="none")};return ae(),(()=>{let{clearChatButton:r}=E;r&&r.addEventListener("click",()=>{$.clearMessages();let v=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});window.dispatchEvent(v)})})(),Z.addEventListener("submit",q),B.addEventListener("keydown",Mt),At.push(()=>{Z.removeEventListener("submit",q),B.removeEventListener("keydown",Mt)}),At.push(()=>{$.cancel()}),G&&At.push(()=>{G==null||G.destroy()}),{update(r){var We,ke,Ie,He,Re,Ne,Fe,De,qe,ze,Pe,$e,Oe,_e,Ue,k,tt,mt,jt,Tt,te,me,ee,Se,ne,Ge,je,lt,oe,we,Xe,Me,vn,fn,yn,bn,xn,Cn,Tn,Sn,Ln,An,En,Mn,Bn,Wn,kn,In,Hn;e={...e,...r},on(t,e);let v=Ye.getForInstance(e.plugins);s.length=0,s.push(...v),o=(ke=(We=e.launcher)==null?void 0:We.enabled)!=null?ke:!0,l=(He=(Ie=e.launcher)==null?void 0:Ie.autoExpand)!=null?He:!1,y=(Ne=(Re=e.features)==null?void 0:Re.showReasoning)!=null?Ne:!0,I=(De=(Fe=e.features)==null?void 0:Fe.showToolCalls)!=null?De:!0,((qe=e.launcher)==null?void 0:qe.enabled)===!1&&G&&(G.destroy(),G=null),((ze=e.launcher)==null?void 0:ze.enabled)!==!1&&!G&&(G=rn(e,se),t.appendChild(G.element)),G&&G.update(e),o!==L?o?W(l):(C=!0,Et()):l!==a&&W(l),a=l,L=o,zt(),ae();let d=(Pe=e.launcher)!=null?Pe:{},c=($e=d.headerIconHidden)!=null?$e:!1,i=d.headerIconName,g=(Oe=d.headerIconSize)!=null?Oe:"48px";if(j){let x=N.querySelector(".tvw-border-b-cw-divider"),ot=x==null?void 0:x.querySelector(".tvw-flex-col");if(c)j.style.display="none",x&&ot&&!x.contains(ot)&&x.insertBefore(ot,x.firstChild);else{if(j.style.display="",j.style.height=g,j.style.width=g,x&&ot&&(x.contains(j)?j.nextSibling!==ot&&(j.remove(),x.insertBefore(j,ot)):x.insertBefore(j,ot)),i){let wt=parseFloat(g)||24,K=ft(i,wt*.6,"#ffffff",2);K?j.replaceChildren(K):j.textContent=(_e=d.agentIconText)!=null?_e:"\u{1F4AC}"}else if(d.iconUrl){let wt=j.querySelector("img");if(wt)wt.src=d.iconUrl,wt.style.height=g,wt.style.width=g;else{let K=document.createElement("img");K.src=d.iconUrl,K.alt="",K.className="tvw-rounded-xl tvw-object-cover",K.style.height=g,K.style.width=g,j.replaceChildren(K)}}else{let wt=j.querySelector("svg"),K=j.querySelector("img");(wt||K)&&j.replaceChildren(),j.textContent=(Ue=d.agentIconText)!=null?Ue:"\u{1F4AC}"}let it=j.querySelector("img");it&&(it.style.height=g,it.style.width=g)}}if(T){let x=(k=d.closeButtonSize)!=null?k:"32px",ot=(tt=d.closeButtonPlacement)!=null?tt:"inline";T.style.height=x,T.style.width=x;let it=ot==="top-right",wt=T.classList.contains("tvw-absolute");if(it!==wt)if(T.remove(),it)T.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50 tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none",N.style.position="relative",N.appendChild(T);else{T.className="tvw-ml-auto tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none";let U=N.querySelector(".tvw-border-b-cw-divider");U&&U.appendChild(T)}if(d.closeButtonColor?(T.style.color=d.closeButtonColor,T.classList.remove("tvw-text-cw-muted")):(T.style.color="",T.classList.add("tvw-text-cw-muted")),d.closeButtonBackgroundColor?(T.style.backgroundColor=d.closeButtonBackgroundColor,T.classList.remove("hover:tvw-bg-gray-100")):(T.style.backgroundColor="",T.classList.add("hover:tvw-bg-gray-100")),d.closeButtonBorderWidth||d.closeButtonBorderColor){let U=d.closeButtonBorderWidth||"0px",Vt=d.closeButtonBorderColor||"transparent";T.style.border=`${U} solid ${Vt}`,T.classList.remove("tvw-border-none")}else T.style.border="",T.classList.add("tvw-border-none");d.closeButtonBorderRadius?(T.style.borderRadius=d.closeButtonBorderRadius,T.classList.remove("tvw-rounded-full")):(T.style.borderRadius="",T.classList.add("tvw-rounded-full")),d.closeButtonPaddingX?(T.style.paddingLeft=d.closeButtonPaddingX,T.style.paddingRight=d.closeButtonPaddingX):(T.style.paddingLeft="",T.style.paddingRight=""),d.closeButtonPaddingY?(T.style.paddingTop=d.closeButtonPaddingY,T.style.paddingBottom=d.closeButtonPaddingY):(T.style.paddingTop="",T.style.paddingBottom="");let K=(mt=d.closeButtonIconName)!=null?mt:"x",re=(jt=d.closeButtonIconText)!=null?jt:"\xD7";T.innerHTML="";let St=ft(K,"20px",d.closeButtonColor||"",2);St?T.appendChild(St):T.textContent=re;let{closeButtonWrapper:xt}=E,et=(Tt=d.closeButtonTooltipText)!=null?Tt:"Close chat",Lt=(te=d.closeButtonShowTooltip)!=null?te:!0;if(T.setAttribute("aria-label",et),xt&&(xt._cleanupTooltip&&(xt._cleanupTooltip(),delete xt._cleanupTooltip),Lt&&et)){let U=null,Vt=()=>{if(U||!T)return;U=p("div","tvw-clear-chat-tooltip"),U.textContent=et;let Rn=p("div");Rn.className="tvw-clear-chat-tooltip-arrow",U.appendChild(Rn);let tn=T.getBoundingClientRect();U.style.position="fixed",U.style.left=`${tn.left+tn.width/2}px`,U.style.top=`${tn.top-8}px`,U.style.transform="translate(-50%, -100%)",document.body.appendChild(U)},Wt=()=>{U&&U.parentNode&&(U.parentNode.removeChild(U),U=null)};xt.addEventListener("mouseenter",Vt),xt.addEventListener("mouseleave",Wt),T.addEventListener("focus",Vt),T.addEventListener("blur",Wt),xt._cleanupTooltip=()=>{Wt(),xt&&(xt.removeEventListener("mouseenter",Vt),xt.removeEventListener("mouseleave",Wt)),T&&(T.removeEventListener("focus",Vt),T.removeEventListener("blur",Wt))}}}let{clearChatButton:m,clearChatButtonWrapper:F}=E;if(m){let x=(me=d.clearChat)!=null?me:{},ot=(ee=x.enabled)!=null?ee:!0;if(F&&(F.style.display=ot?"":"none"),ot){let it=(Se=x.size)!=null?Se:"32px";m.style.height=it,m.style.width=it;let wt=(ne=x.iconName)!=null?ne:"refresh-cw",K=(Ge=x.iconColor)!=null?Ge:"";m.innerHTML="";let re=ft(wt,"20px",K||"",2);if(re&&m.appendChild(re),K?(m.style.color=K,m.classList.remove("tvw-text-cw-muted")):(m.style.color="",m.classList.add("tvw-text-cw-muted")),x.backgroundColor?(m.style.backgroundColor=x.backgroundColor,m.classList.remove("hover:tvw-bg-gray-100")):(m.style.backgroundColor="",m.classList.add("hover:tvw-bg-gray-100")),x.borderWidth||x.borderColor){let et=x.borderWidth||"0px",Lt=x.borderColor||"transparent";m.style.border=`${et} solid ${Lt}`,m.classList.remove("tvw-border-none")}else m.style.border="",m.classList.add("tvw-border-none");x.borderRadius?(m.style.borderRadius=x.borderRadius,m.classList.remove("tvw-rounded-full")):(m.style.borderRadius="",m.classList.add("tvw-rounded-full")),x.paddingX?(m.style.paddingLeft=x.paddingX,m.style.paddingRight=x.paddingX):(m.style.paddingLeft="",m.style.paddingRight=""),x.paddingY?(m.style.paddingTop=x.paddingY,m.style.paddingBottom=x.paddingY):(m.style.paddingTop="",m.style.paddingBottom="");let St=(je=x.tooltipText)!=null?je:"Clear chat",xt=(lt=x.showTooltip)!=null?lt:!0;if(m.setAttribute("aria-label",St),F&&(F._cleanupTooltip&&(F._cleanupTooltip(),delete F._cleanupTooltip),xt&&St)){let et=null,Lt=()=>{if(et||!m)return;et=p("div","tvw-clear-chat-tooltip"),et.textContent=St;let Vt=p("div");Vt.className="tvw-clear-chat-tooltip-arrow",et.appendChild(Vt);let Wt=m.getBoundingClientRect();et.style.position="fixed",et.style.left=`${Wt.left+Wt.width/2}px`,et.style.top=`${Wt.top-8}px`,et.style.transform="translate(-50%, -100%)",document.body.appendChild(et)},U=()=>{et&&et.parentNode&&(et.parentNode.removeChild(et),et=null)};F.addEventListener("mouseenter",Lt),F.addEventListener("mouseleave",U),m.addEventListener("focus",Lt),m.addEventListener("blur",U),F._cleanupTooltip=()=>{U(),F&&(F.removeEventListener("mouseenter",Lt),F.removeEventListener("mouseleave",U)),m&&(m.removeEventListener("focus",Lt),m.removeEventListener("blur",U))}}}}M=Un(e),$.updateConfig(e),at(S,$.getMessages(),M),Xt.render(e.suggestionChips,$,B),be(),Q($.isStreaming());let rt=((oe=e.voiceRecognition)==null?void 0:oe.enabled)===!0,gt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),st=rt&>if(Z.classList.remove("tvw-gap-1","tvw-gap-3"),Z.classList.add(st?"tvw-gap-1":"tvw-gap-3"),rt&>)if(!f||!ct){let x=Te(e.voiceRecognition,e.sendButton);x&&(f=x.micButton,ct=x.micButtonWrapper,Z.insertBefore(ct,V),f.addEventListener("click",Zt),f.disabled=$.isStreaming())}else{let x=(we=e.voiceRecognition)!=null?we:{},ot=(Xe=e.sendButton)!=null?Xe:{},it=(Me=x.iconName)!=null?Me:"mic",wt=(vn=ot.size)!=null?vn:"40px",K=(fn=x.iconSize)!=null?fn:wt,re=parseFloat(K)||24;f.style.width=K,f.style.height=K,f.style.minWidth=K,f.style.minHeight=K;let St=(bn=(yn=x.iconColor)!=null?yn:ot.textColor)!=null?bn:"currentColor";f.innerHTML="";let xt=ft(it,re,St,2);xt?f.appendChild(xt):f.textContent="\u{1F3A4}";let et=(xn=x.backgroundColor)!=null?xn:ot.backgroundColor;et?(f.style.backgroundColor=et,f.classList.remove("tvw-bg-cw-primary")):(f.style.backgroundColor="",f.classList.add("tvw-bg-cw-primary")),St?(f.style.color=St,f.classList.remove("tvw-text-white")):!St&&!ot.textColor&&(f.style.color="",f.classList.add("tvw-text-white")),x.borderWidth?(f.style.borderWidth=x.borderWidth,f.style.borderStyle="solid"):(f.style.borderWidth="",f.style.borderStyle=""),x.borderColor?f.style.borderColor=x.borderColor:f.style.borderColor="",x.paddingX?(f.style.paddingLeft=x.paddingX,f.style.paddingRight=x.paddingX):(f.style.paddingLeft="",f.style.paddingRight=""),x.paddingY?(f.style.paddingTop=x.paddingY,f.style.paddingBottom=x.paddingY):(f.style.paddingTop="",f.style.paddingBottom="");let Lt=ct==null?void 0:ct.querySelector(".tvw-send-button-tooltip"),U=(Cn=x.tooltipText)!=null?Cn:"Start voice recognition";if(((Tn=x.showTooltip)!=null?Tn:!1)&&U)if(Lt)Lt.textContent=U,Lt.style.display="";else{let Wt=document.createElement("div");Wt.className="tvw-send-button-tooltip",Wt.textContent=U,ct==null||ct.insertBefore(Wt,f)}else Lt&&(Lt.style.display="none");ct.style.display="",f.disabled=$.isStreaming()}else f&&ct&&(ct.style.display="none",ht&&Bt());let O=(Sn=e.sendButton)!=null?Sn:{},Pt=(Ln=O.useIcon)!=null?Ln:!1,$t=(An=O.iconText)!=null?An:"\u2191",Ot=O.iconName,Nt=(En=O.tooltipText)!=null?En:"Send message",Qt=(Mn=O.showTooltip)!=null?Mn:!1,_t=(Bn=O.size)!=null?Bn:"40px",Yt=O.backgroundColor,vt=O.textColor;if(Pt){if(b.style.width=_t,b.style.height=_t,b.style.minWidth=_t,b.style.minHeight=_t,b.style.fontSize="18px",b.style.lineHeight="1",b.innerHTML="",Ot){let x=parseFloat(_t)||24,ot=vt&&typeof vt=="string"&&vt.trim()?vt.trim():"currentColor",it=ft(Ot,x,ot,2);it?(b.appendChild(it),b.style.color=ot):(b.textContent=$t,vt?b.style.color=vt:b.classList.add("tvw-text-white"))}else b.textContent=$t,vt?b.style.color=vt:b.classList.add("tvw-text-white");b.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",Yt?(b.style.backgroundColor=Yt,b.classList.remove("tvw-bg-cw-primary")):b.classList.add("tvw-bg-cw-primary")}else b.textContent=(kn=(Wn=e.copy)==null?void 0:Wn.sendButtonLabel)!=null?kn:"Send",b.style.width="",b.style.height="",b.style.minWidth="",b.style.minHeight="",b.style.fontSize="",b.style.lineHeight="",b.className="tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-50 tvw-cursor-pointer",Yt?(b.style.backgroundColor=Yt,b.classList.remove("tvw-bg-cw-accent")):b.classList.add("tvw-bg-cw-accent"),vt?b.style.color=vt:b.classList.add("tvw-text-white");O.borderWidth?(b.style.borderWidth=O.borderWidth,b.style.borderStyle="solid"):(b.style.borderWidth="",b.style.borderStyle=""),O.borderColor?b.style.borderColor=O.borderColor:b.style.borderColor="",O.paddingX?(b.style.paddingLeft=O.paddingX,b.style.paddingRight=O.paddingX):(b.style.paddingLeft="",b.style.paddingRight=""),O.paddingY?(b.style.paddingTop=O.paddingY,b.style.paddingBottom=O.paddingY):(b.style.paddingTop="",b.style.paddingBottom="");let Ut=V==null?void 0:V.querySelector(".tvw-send-button-tooltip");if(Qt&&Nt)if(Ut)Ut.textContent=Nt,Ut.style.display="";else{let x=document.createElement("div");x.className="tvw-send-button-tooltip",x.textContent=Nt,V==null||V.insertBefore(x,b)}else Ut&&(Ut.style.display="none");let ge=(In=e.statusIndicator)!=null?In:{},Ve=(Hn=ge.visible)!=null?Hn:!0;if(nt.style.display=Ve?"":"none",$){let x=$.getStatus(),ot=it=>{var wt,K,re,St;return it==="idle"?(wt=ge.idleText)!=null?wt:yt.idle:it==="connecting"?(K=ge.connectingText)!=null?K:yt.connecting:it==="connected"?(re=ge.connectedText)!=null?re:yt.connected:it==="error"?(St=ge.errorText)!=null?St:yt.error:yt[it]};nt.textContent=ot(x)}},open(){o&&W(!0)},close(){o&&W(!1)},toggle(){o&&W(!C)},clearChat(){$.clearMessages();let r=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});window.dispatchEvent(r)},destroy(){At.forEach(r=>r()),A.remove(),G==null||G.destroy(),Ft&&T.removeEventListener("click",Ft)}}};var wn={},ao=t=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof t=="string"){let n=document.querySelector(t);if(!n)throw new Error(`Chat widget target "${t}" was not found`);return n}return t},lo=()=>{try{if(typeof wn!="undefined"&&wn.url)return new URL("../widget.css",wn.url).href}catch{}return null},jn=t=>{let n=lo(),e=()=>{if(!(t instanceof ShadowRoot)||t.querySelector("link[data-vanilla-agent]"))return;let s=document.head.querySelector("link[data-vanilla-agent]");if(!s)return;let o=s.cloneNode(!0);t.insertBefore(o,t.firstChild)};if(t instanceof ShadowRoot)if(n){let s=document.createElement("link");s.rel="stylesheet",s.href=n,s.setAttribute("data-vanilla-agent","true"),t.insertBefore(s,t.firstChild)}else e();else if(!document.head.querySelector("link[data-vanilla-agent]")&&n){let o=document.createElement("link");o.rel="stylesheet",o.href=n,o.setAttribute("data-vanilla-agent","true"),document.head.appendChild(o)}},hn=t=>{var L;let n=ao(t.target),e=document.createElement("div");e.className="vanilla-agent-host",n.appendChild(e);let s=t.useShadowDom!==!1,o,l;if(s){let C=e.attachShadow({mode:"open"});l=C,o=document.createElement("div"),o.id="vanilla-agent-root",C.appendChild(o),jn(C)}else l=e,o=document.createElement("div"),o.id="vanilla-agent-root",e.appendChild(o),jn(e);let a=Qe(o,t.config);return(L=t.onReady)==null||L.call(t),{host:e,update(C){a.update(C)},open(){a.open()},close(){a.close()},toggle(){a.toggle()},clearChat(){a.clearChat()},destroy(){a.destroy(),e.remove()}}};var co=hn;0&&(module.exports={AgentWidgetClient,AgentWidgetSession,DEFAULT_WIDGET_CONFIG,createAgentExperience,directivePostprocessor,escapeHtml,initAgentWidget,markdownPostprocessor,mergeWithDefaults,pluginRegistry});
|
|
14
14
|
//# sourceMappingURL=index.cjs.map
|