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