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