@helpai/elements 0.52.5 → 0.52.6

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.
@@ -4,11 +4,11 @@ var zc=Object.defineProperty;var Uc=(e,t,n)=>t in e?zc(e,t,{enumerable:!0,config
4
4
  `;var ba=`.__P__-standalone-page{margin:0;height:100vh;background:var(--__P__-bg, #fff);display:grid;place-items:stretch}
5
5
  `;var Pa=`:host([data-mode="page"]){min-height:0}:host([data-mode="page"]) .__P__-page-shell{display:grid;grid-template-columns:280px 1fr;width:100%;height:100%;min-height:0;background:var(--__P__-bg);color:var(--__P__-fg);transition:grid-template-columns var(--__P__-dur-base) var(--__P__-ease-in-out)}:host([data-mode="page"]) .__P__-page-shell[data-sidebar-collapsed=true]{grid-template-columns:48px 1fr}:host([data-mode="page"]) .__P__-page-chat{display:flex;flex-direction:column;min-width:0;min-height:0;overflow:hidden}:host([data-mode="page"]) .__P__-anchor{position:static;inset:auto;padding:0;align-items:stretch;width:100%;height:100%;min-width:0;min-height:0;flex:1 1 0}:host([data-mode="page"]) .__P__-panel{width:100%;height:100%;min-width:0;min-height:0;max-width:none;max-height:none;border-radius:0;border:0;box-shadow:none;animation:none}:host([data-mode="page"]) .__P__-sidebar{border-inline-end:1px solid var(--__P__-border);display:flex;flex-direction:column;overflow:hidden;background:var(--__P__-surface)}:host([data-mode="page"]) .__P__-sidebar-header{padding:var(--__P__-space-4) var(--__P__-space-5);border-bottom:1px solid var(--__P__-border);display:flex;align-items:center;justify-content:space-between;gap:var(--__P__-space-2);min-height:56px;box-sizing:border-box}:host([data-mode="page"]) .__P__-sidebar[data-collapsed=true] .__P__-sidebar-header{padding:var(--__P__-space-4) var(--__P__-space-2);justify-content:center}:host([data-mode="page"]) .__P__-sidebar[data-collapsed=true] .__P__-sidebar-logo,:host([data-mode="page"]) .__P__-sidebar[data-collapsed=true] .__P__-sidebar-title{display:none}:host([data-mode="page"]) .__P__-sidebar-toggle{flex:0 0 auto;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:1px solid var(--__P__-border);border-radius:6px;background:transparent;color:var(--__P__-fg);cursor:pointer;transition:background .12s,border-color .12s}:host([data-mode="page"]) .__P__-sidebar-toggle:hover{background:var(--__P__-hover);border-color:var(--__P__-accent)}:host([data-mode="page"]) .__P__-sidebar-toggle:focus-visible{outline:2px solid var(--__P__-accent);outline-offset:2px}:host([data-mode="page"]) .__P__-sidebar-logo{height:32px;display:block}:host([data-mode="page"]) .__P__-sidebar-title{font-size:var(--__P__-text-md);font-weight:600}:host([data-mode="page"]) .__P__-sidebar-section{padding:var(--__P__-space-3) var(--__P__-space-4);border-bottom:1px solid var(--__P__-border)}:host([data-mode="page"]) .__P__-sidebar-nav{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px}:host([data-mode="page"]) .__P__-sidebar-nav-item{display:flex;align-items:center;gap:10px;padding:var(--__P__-space-2) var(--__P__-space-3);border-radius:var(--__P__-radius-sm);color:var(--__P__-fg);text-decoration:none;font-size:calc(14px * var(--__P__-text-scale));transition:background var(--__P__-dur-quick) var(--__P__-ease-out)}:host([data-mode="page"]) .__P__-sidebar-nav-item:hover{background:var(--__P__-hover)}:host([data-mode="page"]) .__P__-sidebar-nav-item:focus-visible{outline:2px solid var(--__P__-focus);outline-offset:-2px}:host([data-mode="page"]) .__P__-sidebar-cards{display:grid;grid-template-columns:1fr;gap:var(--__P__-space-2)}:host([data-mode="page"]) .__P__-sidebar-card{display:block;padding:10px 12px;border:1px solid var(--__P__-border);border-radius:var(--__P__-radius-sm);text-decoration:none;color:var(--__P__-fg);transition:border-color var(--__P__-dur-quick) var(--__P__-ease-out)}:host([data-mode="page"]) .__P__-sidebar-card:hover{border-color:var(--__P__-accent)}:host([data-mode="page"]) .__P__-sidebar-card:focus-visible{outline:2px solid var(--__P__-focus);outline-offset:2px}:host([data-mode="page"]) .__P__-sidebar-card-label{font-weight:600;font-size:calc(14px * var(--__P__-text-scale))}:host([data-mode="page"]) .__P__-sidebar-card-desc{font-size:var(--__P__-text-xs);color:var(--__P__-muted);margin-top:2px}:host([data-mode="page"]) .__P__-sidebar-conversations{flex:1 1 auto;overflow-y:auto;padding:var(--__P__-space-3) var(--__P__-space-4)}:host([data-mode="page"]) .__P__-page-chat{display:flex;flex-direction:column;overflow:hidden}@media(max-width:768px){:host([data-mode="page"]) .__P__-page-shell{grid-template-columns:1fr}:host([data-mode="page"]) .__P__-sidebar{display:none}}
6
6
  `;var Od="helpai",Dd="#5B5BD6",$d="#FFFFFF",Hd="12px",Bd="Inter, system-ui, -apple-system, 'Segoe UI', sans-serif",kr=[ga,ha,va,ba,Pa].join(`
7
- `).replace(/__P__/g,Od).replaceAll("__BRAND_ACCENT_TEXT__",$d).replaceAll("__BRAND_ACCENT__",Dd).replaceAll("__BRAND_RADIUS__",Hd).replaceAll("__BRAND_FONT__",Bd);var Fd=X.scope("mount"),xa=new WeakMap,ya={floating:"all: initial; position: fixed; z-index: 2147483600;",flow:"all: initial; display: block; position: relative; width: 100%; height: 100%; z-index: 1; contain: size;",viewport:"all: initial; display: block; position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1;"};function Sa(e,t){e.style.cssText=ya[t]}function jn(e){return e==="floating"||e==="modal"||e==="drawer"?"floating":e==="standalone"||e==="page"?"viewport":"flow"}function wa(e={}){let t=e.position??"flow";Fd.debug("createShadowMount",{position:t,hasTarget:!!e.target,hasHost:!!e.existingHost});let n=`${x.cssPrefix}-chat-host`;typeof customElements<"u"&&!customElements.get(n)&&customElements.define(n,class extends HTMLElement{});let o;e.existingHost?o=e.existingHost:(o=document.createElement(n),(e.target??document.body).appendChild(o)),o.setAttribute("data-brand",x.id),o.style.cssText=ya[t];let i=o.shadowRoot??o.attachShadow({mode:"open"}),a=o.ownerDocument;if(!zd(i,a)){let s=a.createElement("style");s.textContent=kr,i.appendChild(s)}let l=document.createElement("div");return l.className=`${x.cssPrefix}-app`,i.appendChild(l),{appRoot:l,destroy:()=>o.remove(),hostElement:o,shadowRoot:i}}function zd(e,t){if(!("adoptedStyleSheets"in e))return!1;let n=t.defaultView;if(!n||typeof n.CSSStyleSheet!="function")return!1;let o=xa.get(t);if(!o)try{o=new n.CSSStyleSheet,o.replaceSync(kr),xa.set(t,o)}catch{return!1}try{return e.adoptedStyleSheets=[o],!0}catch{return!1}}function Ud(e,t){let n=x.cssPrefix;t.accent&&e.style.setProperty(`--${n}-accent-user`,t.accent),t.accentText&&e.style.setProperty(`--${n}-accent-text-user`,t.accentText),t.radius&&e.style.setProperty(`--${n}-radius`,t.radius),t.fontFamily&&e.style.setProperty(`--${n}-font`,t.fontFamily)}function Vd(e,t){e.dataset.theme=t}function Wd(e,t){let n=x.cssPrefix;t.width!==void 0&&e.style.setProperty(`--${n}-panel-w`,t.width),t.height!==void 0&&e.style.setProperty(`--${n}-panel-h`,t.height),t.expanded?.width!==void 0&&e.style.setProperty(`--${n}-expanded-w`,t.expanded.width),t.expanded?.height!==void 0&&e.style.setProperty(`--${n}-expanded-h`,t.expanded.height),t.inset!==void 0&&e.style.setProperty(`--${n}-panel-inset`,t.inset)}function qd(e,t){e.dataset.position=t}function Xn(e,t){e.dataset.mode=t}function ka(e,t){Vd(e,t.themeMode),Ud(e,t.themeOverrides),qd(e,t.position),Wd(e,t.size)}var Lt,me,Cr,Ca,en=0,Na=[],ge=J,Ta=ge.__b,Ea=ge.__r,Ra=ge.diffed,Aa=ge.__c,Ia=ge.unmount,La=ge.__;function Jn(e,t){ge.__h&&ge.__h(me,e,en||t),en=0;var n=me.__H||(me.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function A(e){return en=1,Gd(Oa,e)}function Gd(e,t,n){var o=Jn(Lt++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):Oa(void 0,t),function(s){var c=o.__N?o.__N[0]:o.__[0],d=o.t(c,s);c!==d&&(o.__N=[d,o.__[1]],o.__c.setState({}))}],o.__c=me,!me.__f)){var i=function(s,c,d){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(g){return g.__c});if(u.every(function(g){return!g.__N}))return!a||a.call(this,s,c,d);var _=o.__c.props!==s;return u.some(function(g){if(g.__N){var f=g.__[0];g.__=g.__N,g.__N=void 0,f!==g.__[0]&&(_=!0)}}),a&&a.call(this,s,c,d)||_};me.__f=!0;var a=me.shouldComponentUpdate,l=me.componentWillUpdate;me.componentWillUpdate=function(s,c,d){if(this.__e){var u=a;a=void 0,i(s,c,d),a=u}l&&l.call(this,s,c,d)},me.shouldComponentUpdate=i}return o.__N||o.__}function R(e,t){var n=Jn(Lt++,3);!ge.__s&&Er(n.__H,t)&&(n.__=e,n.u=t,me.__H.__h.push(n))}function ht(e,t){var n=Jn(Lt++,4);!ge.__s&&Er(n.__H,t)&&(n.__=e,n.u=t,me.__h.push(n))}function O(e){return en=5,Re(function(){return{current:e}},[])}function Re(e,t){var n=Jn(Lt++,7);return Er(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function D(e,t){return en=8,Re(function(){return e},t)}function Kd(){for(var e;e=Na.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Yn),t.__h.some(Tr),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){me=null,Ta&&Ta(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),La&&La(e,t)},ge.__r=function(e){Ea&&Ea(e),Lt=0;var t=(me=e.__c).__H;t&&(Cr===me?(t.__h=[],me.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(Yn),t.__h.some(Tr),t.__h=[],Lt=0)),Cr=me},ge.diffed=function(e){Ra&&Ra(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Na.push(t)!==1&&Ca===ge.requestAnimationFrame||((Ca=ge.requestAnimationFrame)||jd)(Kd)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Cr=me=null},ge.__c=function(e,t){t.some(function(n){try{n.__h.some(Yn),n.__h=n.__h.filter(function(o){return!o.__||Tr(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],ge.__e(o,n.__v)}}),Aa&&Aa(e,t)},ge.unmount=function(e){Ia&&Ia(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{Yn(o)}catch(i){t=i}}),n.__H=void 0,t&&ge.__e(t,n.__v))};var Ma=typeof requestAnimationFrame=="function";function jd(e){var t,n=function(){clearTimeout(o),Ma&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Ma&&(t=requestAnimationFrame(n))}function Yn(e){var t=me,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),me=t}function Tr(e){var t=me;e.__c=e.__(),me=t}function Er(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function Oa(e,t){return typeof t=="function"?t(e):t}var Xd=Symbol.for("preact-signals");function to(){if(tt>1)tt--;else{var e,t=!1;for((function(){var i=Zn;for(Zn=void 0;i!==void 0;)i.S.v===i.v&&(i.S.i=i.i),i=i.o})();tn!==void 0;){var n=tn;for(tn=void 0,Qn++;n!==void 0;){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Ha(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=o}}if(Qn=0,tt--,t)throw e}}function Mt(e){if(tt>0)return e();Rr=++Yd,tt++;try{return e()}finally{to()}}var ce=void 0;function nn(e){var t=ce;ce=void 0;try{return e()}finally{ce=t}}var Da,tn=void 0,tt=0,Qn=0,Yd=0,Rr=0,Zn=void 0,eo=0;function $a(e){if(ce!==void 0){var t=e.n;if(t===void 0||t.t!==ce)return t={i:0,S:e,p:ce.s,n:void 0,t:ce,e:void 0,x:void 0,r:t},ce.s!==void 0&&(ce.s.n=t),ce.s=t,e.n=t,32&ce.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=ce.s,t.n=void 0,ce.s.n=t,ce.s=t),t}}function Pe(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}Pe.prototype.brand=Xd;Pe.prototype.h=function(){return!0};Pe.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:nn(function(){var o;(o=t.W)==null||o.call(t)}))};Pe.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,o=e.x;n!==void 0&&(n.x=o,e.e=void 0),o!==void 0&&(o.e=n,e.x=void 0),e===this.t&&(this.t=o,o===void 0&&nn(function(){var i;(i=t.Z)==null||i.call(t)}))}};Pe.prototype.subscribe=function(e){var t=this;return nt(function(){var n=t.value;nn(function(){return e(n)})},{name:"sub"})};Pe.prototype.valueOf=function(){return this.value};Pe.prototype.toString=function(){return this.value+""};Pe.prototype.toJSON=function(){return this.value};Pe.prototype.peek=function(){var e=this;return nn(function(){return e.value})};Object.defineProperty(Pe.prototype,"value",{get:function(){var e=$a(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Qn>100)throw new Error("Cycle detected");(function(n){tt!==0&&Qn===0&&n.l!==Rr&&(n.l=Rr,Zn={S:n,v:n.v,i:n.i,o:Zn})})(this),this.v=e,this.i++,eo++,tt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{to()}}}});function H(e,t){return new Pe(e,t)}function Ha(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Ba(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Fa(e){for(var t=e.s,n=void 0;t!==void 0;){var o=t.p;t.i===-1?(t.S.U(t),o!==void 0&&(o.n=t.n),t.n!==void 0&&(t.n.p=o)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=o}e.s=n}function vt(e,t){Pe.call(this,void 0,t),this.x=e,this.s=void 0,this.g=eo-1,this.f=4}vt.prototype=new Pe;vt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===eo))return!0;if(this.g=eo,this.f|=1,this.i>0&&!Ha(this))return this.f&=-2,!0;var e=ce;try{Ba(this),ce=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return ce=e,Fa(this),this.f&=-2,!0};vt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}Pe.prototype.S.call(this,e)};vt.prototype.U=function(e){if(this.t!==void 0&&(Pe.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};vt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(vt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=$a(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function on(e,t){return new vt(e,t)}function za(e){var t=e.m;if(e.m=void 0,typeof t=="function"){tt++;var n=ce;ce=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,Ar(e),o}finally{ce=n,to()}}}function Ar(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,za(e)}function Jd(e){if(ce!==this)throw new Error("Out-of-order effect");Fa(this),ce=e,this.f&=-2,8&this.f&&Ar(this),to()}function Nt(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Da&&Da.push(this)}Nt.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};Nt.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,za(this),Ba(this),tt++;var e=ce;return ce=this,Jd.bind(this,e)};Nt.prototype.N=function(){2&this.f||(this.f|=2,this.u=tn,tn=this)};Nt.prototype.d=function(){this.f|=8,1&this.f||Ar(this)};Nt.prototype.dispose=function(){this.d()};function nt(e,t){var n=new Nt(e,t);try{n.c()}catch(i){throw n.d(),i}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var Ua,ro,no,Qd=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var Va=[];nt(function(){Ua=this.N})();function Ot(e,t){J[e]=t.bind(null,J[e]||function(){})}function oo(e){if(no){var t=no;no=void 0,t()}no=e&&e.S()}function Wa(e){var t=this,n=e.data,o=rn(n);o.value=n;var i=Re(function(){for(var s=t,c=t.__v;c=c.__;)if(c.__c){c.__c.__$f|=4;break}var d=on(function(){var f=o.value.value;return f===0?0:f===!0?"":f||""}),u=on(function(){return!Array.isArray(d.value)&&!cr(d.value)}),_=nt(function(){if(this.N=qa,u.value){var f=d.value;s.__v&&s.__v.__e&&s.__v.__e.nodeType===3&&(s.__v.__e.data=f)}}),g=t.__$u.d;return t.__$u.d=function(){_(),g.call(this)},[u,d]},[]),a=i[0],l=i[1];return a.value?l.peek():l.value}Wa.displayName="ReactiveTextNode";Object.defineProperties(Pe.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Wa},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});Ot("__b",function(e,t){if(typeof t.type=="string"){var n,o=t.props;for(var i in o)if(i!=="children"){var a=o[i];a instanceof Pe&&(n||(t.__np=n={}),n[i]=a,o[i]=a.peek())}}e(t)});Ot("__r",function(e,t){if(e(t),t.type!==ee){oo();var n,o=t.__c;o&&(o.__$f&=-2,(n=o.__$u)===void 0&&(o.__$u=n=(function(i,a){var l;return nt(function(){l=this},{name:a}),l.c=i,l})(function(){var i;Qd&&((i=n.y)==null||i.call(n)),o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),ro=o,oo(n)}});Ot("__e",function(e,t,n,o){oo(),ro=void 0,e(t,n,o)});Ot("diffed",function(e,t){oo(),ro=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var o=t.__np,i=t.props;if(o){var a=n.U;if(a)for(var l in a){var s=a[l];s!==void 0&&!(l in o)&&(s.d(),a[l]=void 0)}else a={},n.U=a;for(var c in o){var d=a[c],u=o[c];d===void 0?(d=Zd(n,c,u,i),a[c]=d):d.o(u,i)}}}e(t)});function Zd(e,t,n,o){var i=t in e&&e.ownerSVGElement===void 0,a=H(n);return{o:function(l,s){a.value=l,o=s},d:nt(function(){this.N=qa;var l=a.value.value;o[t]!==l&&(o[t]=l,i?e[t]=l:l!=null&&(l!==!1||t[4]==="-")?e.setAttribute(t,l):e.removeAttribute(t))})}}Ot("unmount",function(e,t){if(typeof t.type=="string"){var n=t.__e;if(n){var o=n.U;if(o){n.U=void 0;for(var i in o){var a=o[i];a&&a.d()}}}var l=t.__np;if(l){var s=t.props;for(var c in l)s[c]=l[c]}t.__np=void 0}else{var d=t.__c;if(d){var u=d.__$u;u&&(d.__$u=void 0,u.d())}}e(t)});Ot("__h",function(e,t,n,o){(o<3||o===9)&&(t.__$f|=2),e(t,n,o)});lt.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,o=n&&n.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var a=2&this.__$f;if(!(o||a||4&this.__$f)||1&this.__$f)return!0}else if(!(o||4&this.__$f)||3&this.__$f)return!0;for(var l in e)if(l!=="__source"&&e[l]!==this.props[l])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function rn(e,t){return Re(function(){return H(e,t)},[])}function j(e,t){var n=O(e);return n.current=e,ro.__$f|=4,Re(function(){return on(function(){return n.current()},t)},[])}var e_=function(e){queueMicrotask(function(){queueMicrotask(e)})};function t_(){Mt(function(){for(var e;e=Va.shift();)Ua.call(e)})}function qa(){Va.push(this)===1&&(J.requestAnimationFrame||e_)(t_)}function Ga(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Ka(e){return Ga(e)}function ja(e){return!(!Ga(e)||e.navigation!==void 0&&!Array.isArray(e.navigation)||e.linkCards!==void 0&&!Array.isArray(e.linkCards))}function n_(e){return`${x.cssPrefix}:${e}`}function Xa(e,t){let o=Object.entries(t).map(([i,a])=>{let l=n_(i),s=c=>a(c.detail);return e.addEventListener(l,s),[l,s]});return()=>{for(let[i,a]of o)e.removeEventListener(i,a)}}function io(e,t,n){return e==="page"?"page":e==="standalone"?"standalone":e==="inline"?t==="fullscreen"?"fullscreen":"inline":e==="modal"||e==="drawer"?n?t==="fullscreen"?"fullscreen":e:"closed":n?t==="fullscreen"?"fullscreen":t==="expanded"?"expanded":"open":"closed"}var o_=900;function Ir(e,t,n){if(e==="standalone"||e==="page")return"fullscreen";let o=t.initialSize;if(o==="expanded"||o==="fullscreen"||o==="normal")return o;if(o==="auto"){let i=t.autoSizeBreakpoint??o_;return n>=i?"expanded":"normal"}return"normal"}function an(e,t,n,o=null){let a=e.mode==="inline"||e.mode==="standalone"||e.mode==="page"||(n??!e.startMinimized),s=e.mode!=="standalone"&&e.mode!=="page"&&e.mode!=="inline"&&o?o:Ir(e.mode,e.size,t);return{panelOpen:a,panelSize:s}}function Dt(){return typeof window>"u"?0:window.innerWidth}var r_="x-public-key",i_="x-ai-agent-deployment-id";function Ya(e){return{headers(){let t={};return e.aiAgentDeploymentId&&(t[i_]=e.aiAgentDeploymentId),e.publicKey&&(t[e.publicKeyHeader??r_]=e.publicKey),t}}}var ao="0.52.5";var Ve=class extends Error{constructor(n,o,i,a){super(n);V(this,"code",o);V(this,"status",i);V(this,"cause",a);this.name="StreamError"}};var Ja=X.scope("parser");async function*Lr(e,t){if(!e.ok){let i=await e.text().catch(()=>"");throw new Ve(`server responded ${e.status}: ${i.slice(0,200)}`,"server",e.status)}if(!e.body)throw new Ve("response has no body","no-body");let n=e.body.pipeThrough(new TextDecoderStream).getReader(),o="";try{for(;;){if(t.aborted)throw new DOMException("aborted","AbortError");let{done:i,value:a}=await n.read();if(i){let s=o.trim();if(s){let c=Qa(s);c&&(yield c)}return}o+=a;let l;for(;(l=o.indexOf(`
7
+ `).replace(/__P__/g,Od).replaceAll("__BRAND_ACCENT_TEXT__",$d).replaceAll("__BRAND_ACCENT__",Dd).replaceAll("__BRAND_RADIUS__",Hd).replaceAll("__BRAND_FONT__",Bd);var Fd=X.scope("mount"),xa=new WeakMap,ya={floating:"all: initial; position: fixed; z-index: 2147483600;",flow:"all: initial; display: block; position: relative; width: 100%; height: 100%; z-index: 1; contain: size;",viewport:"all: initial; display: block; position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1;"};function Sa(e,t){e.style.cssText=ya[t]}function jn(e){return e==="floating"||e==="modal"||e==="drawer"?"floating":e==="standalone"||e==="page"?"viewport":"flow"}function wa(e={}){let t=e.position??"flow";Fd.debug("createShadowMount",{position:t,hasTarget:!!e.target,hasHost:!!e.existingHost});let n=`${x.cssPrefix}-chat-host`;typeof customElements<"u"&&!customElements.get(n)&&customElements.define(n,class extends HTMLElement{});let o;e.existingHost?o=e.existingHost:(o=document.createElement(n),(e.target??document.body).appendChild(o)),o.setAttribute("data-brand",x.id),o.style.cssText=ya[t];let i=o.shadowRoot??o.attachShadow({mode:"open"}),a=o.ownerDocument;if(!zd(i,a)){let s=a.createElement("style");s.textContent=kr,i.appendChild(s)}let l=document.createElement("div");return l.className=`${x.cssPrefix}-app`,i.appendChild(l),{appRoot:l,destroy:()=>o.remove(),hostElement:o,shadowRoot:i}}function zd(e,t){if(!("adoptedStyleSheets"in e))return!1;let n=t.defaultView;if(!n||typeof n.CSSStyleSheet!="function")return!1;let o=xa.get(t);if(!o)try{o=new n.CSSStyleSheet,o.replaceSync(kr),xa.set(t,o)}catch{return!1}try{return e.adoptedStyleSheets=[o],!0}catch{return!1}}function Ud(e,t){let n=x.cssPrefix;t.accent&&e.style.setProperty(`--${n}-accent-user`,t.accent),t.accentText&&e.style.setProperty(`--${n}-accent-text-user`,t.accentText),t.radius&&e.style.setProperty(`--${n}-radius`,t.radius),t.fontFamily&&e.style.setProperty(`--${n}-font`,t.fontFamily)}function Vd(e,t){e.dataset.theme=t}function Wd(e,t){let n=x.cssPrefix;t.width!==void 0&&e.style.setProperty(`--${n}-panel-w`,t.width),t.height!==void 0&&e.style.setProperty(`--${n}-panel-h`,t.height),t.expanded?.width!==void 0&&e.style.setProperty(`--${n}-expanded-w`,t.expanded.width),t.expanded?.height!==void 0&&e.style.setProperty(`--${n}-expanded-h`,t.expanded.height),t.inset!==void 0&&e.style.setProperty(`--${n}-panel-inset`,t.inset)}function qd(e,t){e.dataset.position=t}function Xn(e,t){e.dataset.mode=t}function ka(e,t){Vd(e,t.themeMode),Ud(e,t.themeOverrides),qd(e,t.position),Wd(e,t.size)}var Lt,me,Cr,Ca,en=0,Na=[],ge=J,Ta=ge.__b,Ea=ge.__r,Ra=ge.diffed,Aa=ge.__c,Ia=ge.unmount,La=ge.__;function Jn(e,t){ge.__h&&ge.__h(me,e,en||t),en=0;var n=me.__H||(me.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function A(e){return en=1,Gd(Oa,e)}function Gd(e,t,n){var o=Jn(Lt++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):Oa(void 0,t),function(s){var c=o.__N?o.__N[0]:o.__[0],d=o.t(c,s);c!==d&&(o.__N=[d,o.__[1]],o.__c.setState({}))}],o.__c=me,!me.__f)){var i=function(s,c,d){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(g){return g.__c});if(u.every(function(g){return!g.__N}))return!a||a.call(this,s,c,d);var _=o.__c.props!==s;return u.some(function(g){if(g.__N){var f=g.__[0];g.__=g.__N,g.__N=void 0,f!==g.__[0]&&(_=!0)}}),a&&a.call(this,s,c,d)||_};me.__f=!0;var a=me.shouldComponentUpdate,l=me.componentWillUpdate;me.componentWillUpdate=function(s,c,d){if(this.__e){var u=a;a=void 0,i(s,c,d),a=u}l&&l.call(this,s,c,d)},me.shouldComponentUpdate=i}return o.__N||o.__}function R(e,t){var n=Jn(Lt++,3);!ge.__s&&Er(n.__H,t)&&(n.__=e,n.u=t,me.__H.__h.push(n))}function ht(e,t){var n=Jn(Lt++,4);!ge.__s&&Er(n.__H,t)&&(n.__=e,n.u=t,me.__h.push(n))}function O(e){return en=5,Re(function(){return{current:e}},[])}function Re(e,t){var n=Jn(Lt++,7);return Er(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function D(e,t){return en=8,Re(function(){return e},t)}function Kd(){for(var e;e=Na.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Yn),t.__h.some(Tr),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){me=null,Ta&&Ta(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),La&&La(e,t)},ge.__r=function(e){Ea&&Ea(e),Lt=0;var t=(me=e.__c).__H;t&&(Cr===me?(t.__h=[],me.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(Yn),t.__h.some(Tr),t.__h=[],Lt=0)),Cr=me},ge.diffed=function(e){Ra&&Ra(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Na.push(t)!==1&&Ca===ge.requestAnimationFrame||((Ca=ge.requestAnimationFrame)||jd)(Kd)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Cr=me=null},ge.__c=function(e,t){t.some(function(n){try{n.__h.some(Yn),n.__h=n.__h.filter(function(o){return!o.__||Tr(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],ge.__e(o,n.__v)}}),Aa&&Aa(e,t)},ge.unmount=function(e){Ia&&Ia(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{Yn(o)}catch(i){t=i}}),n.__H=void 0,t&&ge.__e(t,n.__v))};var Ma=typeof requestAnimationFrame=="function";function jd(e){var t,n=function(){clearTimeout(o),Ma&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Ma&&(t=requestAnimationFrame(n))}function Yn(e){var t=me,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),me=t}function Tr(e){var t=me;e.__c=e.__(),me=t}function Er(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function Oa(e,t){return typeof t=="function"?t(e):t}var Xd=Symbol.for("preact-signals");function to(){if(tt>1)tt--;else{var e,t=!1;for((function(){var i=Zn;for(Zn=void 0;i!==void 0;)i.S.v===i.v&&(i.S.i=i.i),i=i.o})();tn!==void 0;){var n=tn;for(tn=void 0,Qn++;n!==void 0;){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Ha(n))try{n.c()}catch(i){t||(e=i,t=!0)}n=o}}if(Qn=0,tt--,t)throw e}}function Mt(e){if(tt>0)return e();Rr=++Yd,tt++;try{return e()}finally{to()}}var ce=void 0;function nn(e){var t=ce;ce=void 0;try{return e()}finally{ce=t}}var Da,tn=void 0,tt=0,Qn=0,Yd=0,Rr=0,Zn=void 0,eo=0;function $a(e){if(ce!==void 0){var t=e.n;if(t===void 0||t.t!==ce)return t={i:0,S:e,p:ce.s,n:void 0,t:ce,e:void 0,x:void 0,r:t},ce.s!==void 0&&(ce.s.n=t),ce.s=t,e.n=t,32&ce.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=ce.s,t.n=void 0,ce.s.n=t,ce.s=t),t}}function ve(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}ve.prototype.brand=Xd;ve.prototype.h=function(){return!0};ve.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:nn(function(){var o;(o=t.W)==null||o.call(t)}))};ve.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,o=e.x;n!==void 0&&(n.x=o,e.e=void 0),o!==void 0&&(o.e=n,e.x=void 0),e===this.t&&(this.t=o,o===void 0&&nn(function(){var i;(i=t.Z)==null||i.call(t)}))}};ve.prototype.subscribe=function(e){var t=this;return nt(function(){var n=t.value;nn(function(){return e(n)})},{name:"sub"})};ve.prototype.valueOf=function(){return this.value};ve.prototype.toString=function(){return this.value+""};ve.prototype.toJSON=function(){return this.value};ve.prototype.peek=function(){var e=this;return nn(function(){return e.value})};Object.defineProperty(ve.prototype,"value",{get:function(){var e=$a(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Qn>100)throw new Error("Cycle detected");(function(n){tt!==0&&Qn===0&&n.l!==Rr&&(n.l=Rr,Zn={S:n,v:n.v,i:n.i,o:Zn})})(this),this.v=e,this.i++,eo++,tt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{to()}}}});function H(e,t){return new ve(e,t)}function Ha(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Ba(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Fa(e){for(var t=e.s,n=void 0;t!==void 0;){var o=t.p;t.i===-1?(t.S.U(t),o!==void 0&&(o.n=t.n),t.n!==void 0&&(t.n.p=o)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=o}e.s=n}function vt(e,t){ve.call(this,void 0,t),this.x=e,this.s=void 0,this.g=eo-1,this.f=4}vt.prototype=new ve;vt.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===eo))return!0;if(this.g=eo,this.f|=1,this.i>0&&!Ha(this))return this.f&=-2,!0;var e=ce;try{Ba(this),ce=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return ce=e,Fa(this),this.f&=-2,!0};vt.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}ve.prototype.S.call(this,e)};vt.prototype.U=function(e){if(this.t!==void 0&&(ve.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};vt.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(vt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=$a(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function on(e,t){return new vt(e,t)}function za(e){var t=e.m;if(e.m=void 0,typeof t=="function"){tt++;var n=ce;ce=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,Ar(e),o}finally{ce=n,to()}}}function Ar(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,za(e)}function Jd(e){if(ce!==this)throw new Error("Out-of-order effect");Fa(this),ce=e,this.f&=-2,8&this.f&&Ar(this),to()}function Nt(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Da&&Da.push(this)}Nt.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.m=t)}finally{e()}};Nt.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,za(this),Ba(this),tt++;var e=ce;return ce=this,Jd.bind(this,e)};Nt.prototype.N=function(){2&this.f||(this.f|=2,this.u=tn,tn=this)};Nt.prototype.d=function(){this.f|=8,1&this.f||Ar(this)};Nt.prototype.dispose=function(){this.d()};function nt(e,t){var n=new Nt(e,t);try{n.c()}catch(i){throw n.d(),i}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var Ua,ro,no,Qd=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var Va=[];nt(function(){Ua=this.N})();function Ot(e,t){J[e]=t.bind(null,J[e]||function(){})}function oo(e){if(no){var t=no;no=void 0,t()}no=e&&e.S()}function Wa(e){var t=this,n=e.data,o=rn(n);o.value=n;var i=Re(function(){for(var s=t,c=t.__v;c=c.__;)if(c.__c){c.__c.__$f|=4;break}var d=on(function(){var f=o.value.value;return f===0?0:f===!0?"":f||""}),u=on(function(){return!Array.isArray(d.value)&&!cr(d.value)}),_=nt(function(){if(this.N=qa,u.value){var f=d.value;s.__v&&s.__v.__e&&s.__v.__e.nodeType===3&&(s.__v.__e.data=f)}}),g=t.__$u.d;return t.__$u.d=function(){_(),g.call(this)},[u,d]},[]),a=i[0],l=i[1];return a.value?l.peek():l.value}Wa.displayName="ReactiveTextNode";Object.defineProperties(ve.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Wa},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});Ot("__b",function(e,t){if(typeof t.type=="string"){var n,o=t.props;for(var i in o)if(i!=="children"){var a=o[i];a instanceof ve&&(n||(t.__np=n={}),n[i]=a,o[i]=a.peek())}}e(t)});Ot("__r",function(e,t){if(e(t),t.type!==ee){oo();var n,o=t.__c;o&&(o.__$f&=-2,(n=o.__$u)===void 0&&(o.__$u=n=(function(i,a){var l;return nt(function(){l=this},{name:a}),l.c=i,l})(function(){var i;Qd&&((i=n.y)==null||i.call(n)),o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),ro=o,oo(n)}});Ot("__e",function(e,t,n,o){oo(),ro=void 0,e(t,n,o)});Ot("diffed",function(e,t){oo(),ro=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var o=t.__np,i=t.props;if(o){var a=n.U;if(a)for(var l in a){var s=a[l];s!==void 0&&!(l in o)&&(s.d(),a[l]=void 0)}else a={},n.U=a;for(var c in o){var d=a[c],u=o[c];d===void 0?(d=Zd(n,c,u,i),a[c]=d):d.o(u,i)}}}e(t)});function Zd(e,t,n,o){var i=t in e&&e.ownerSVGElement===void 0,a=H(n);return{o:function(l,s){a.value=l,o=s},d:nt(function(){this.N=qa;var l=a.value.value;o[t]!==l&&(o[t]=l,i?e[t]=l:l!=null&&(l!==!1||t[4]==="-")?e.setAttribute(t,l):e.removeAttribute(t))})}}Ot("unmount",function(e,t){if(typeof t.type=="string"){var n=t.__e;if(n){var o=n.U;if(o){n.U=void 0;for(var i in o){var a=o[i];a&&a.d()}}}var l=t.__np;if(l){var s=t.props;for(var c in l)s[c]=l[c]}t.__np=void 0}else{var d=t.__c;if(d){var u=d.__$u;u&&(d.__$u=void 0,u.d())}}e(t)});Ot("__h",function(e,t,n,o){(o<3||o===9)&&(t.__$f|=2),e(t,n,o)});lt.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,o=n&&n.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var a=2&this.__$f;if(!(o||a||4&this.__$f)||1&this.__$f)return!0}else if(!(o||4&this.__$f)||3&this.__$f)return!0;for(var l in e)if(l!=="__source"&&e[l]!==this.props[l])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function rn(e,t){return Re(function(){return H(e,t)},[])}function j(e,t){var n=O(e);return n.current=e,ro.__$f|=4,Re(function(){return on(function(){return n.current()},t)},[])}var e_=function(e){queueMicrotask(function(){queueMicrotask(e)})};function t_(){Mt(function(){for(var e;e=Va.shift();)Ua.call(e)})}function qa(){Va.push(this)===1&&(J.requestAnimationFrame||e_)(t_)}function Ga(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function Ka(e){return Ga(e)}function ja(e){return!(!Ga(e)||e.navigation!==void 0&&!Array.isArray(e.navigation)||e.linkCards!==void 0&&!Array.isArray(e.linkCards))}function n_(e){return`${x.cssPrefix}:${e}`}function Xa(e,t){let o=Object.entries(t).map(([i,a])=>{let l=n_(i),s=c=>a(c.detail);return e.addEventListener(l,s),[l,s]});return()=>{for(let[i,a]of o)e.removeEventListener(i,a)}}function io(e,t,n){return e==="page"?"page":e==="standalone"?"standalone":e==="inline"?t==="fullscreen"?"fullscreen":"inline":e==="modal"||e==="drawer"?n?t==="fullscreen"?"fullscreen":e:"closed":n?t==="fullscreen"?"fullscreen":t==="expanded"?"expanded":"open":"closed"}var o_=900;function Ir(e,t,n){if(e==="standalone"||e==="page")return"fullscreen";let o=t.initialSize;if(o==="expanded"||o==="fullscreen"||o==="normal")return o;if(o==="auto"){let i=t.autoSizeBreakpoint??o_;return n>=i?"expanded":"normal"}return"normal"}function an(e,t,n,o=null){let a=e.mode==="inline"||e.mode==="standalone"||e.mode==="page"||(n??!e.startMinimized),s=e.mode!=="standalone"&&e.mode!=="page"&&e.mode!=="inline"&&o?o:Ir(e.mode,e.size,t);return{panelOpen:a,panelSize:s}}function Dt(){return typeof window>"u"?0:window.innerWidth}var r_="x-public-key",i_="x-ai-agent-deployment-id";function Ya(e){return{headers(){let t={};return e.aiAgentDeploymentId&&(t[i_]=e.aiAgentDeploymentId),e.publicKey&&(t[e.publicKeyHeader??r_]=e.publicKey),t}}}var ao="0.52.6";var Ve=class extends Error{constructor(n,o,i,a){super(n);V(this,"code",o);V(this,"status",i);V(this,"cause",a);this.name="StreamError"}};var Ja=X.scope("parser");async function*Lr(e,t){if(!e.ok){let i=await e.text().catch(()=>"");throw new Ve(`server responded ${e.status}: ${i.slice(0,200)}`,"server",e.status)}if(!e.body)throw new Ve("response has no body","no-body");let n=e.body.pipeThrough(new TextDecoderStream).getReader(),o="";try{for(;;){if(t.aborted)throw new DOMException("aborted","AbortError");let{done:i,value:a}=await n.read();if(i){let s=o.trim();if(s){let c=Qa(s);c&&(yield c)}return}o+=a;let l;for(;(l=o.indexOf(`
8
8
 
9
9
  `))!==-1;){let s=o.slice(0,l);o=o.slice(l+2);let c=Qa(s);c&&(yield c)}}}finally{n.releaseLock()}}function Qa(e){let t="",n;for(let o of e.split(`
10
10
  `))if(!(o===""||o.startsWith(":"))){if(o.startsWith("data:")){let i=o.slice(5).replace(/^ /,"");t=t?`${t}
11
- ${i}`:i;continue}o.startsWith("id:")&&(n=o.slice(3).trim())}if(!t||t==="[DONE]")return null;try{let o=JSON.parse(t);return Ja.trace("chunk",{type:o.type,eventId:n}),{chunk:o,eventId:n}}catch(o){return Ja.trace("frame parse failed",{err:o,payload:t.slice(0,200)}),null}}function a_(e){let t=new TextEncoder().encode(e),n="";for(let o of t)n+=String.fromCharCode(o);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var Za=e=>e&&Object.keys(e).length>0?e:void 0;function es(e,t){let n=Za(e),o=Za(t);if(!n&&!o)return;let i={};return n&&(i.user=n),o&&(i.page=o),a_(JSON.stringify(i))}function so(e){if(!e)return;let t=Date.parse(e);return Number.isFinite(t)?t:void 0}function s_(e){return`tool-${e.startsWith("tool:")?e.slice(5):e}`}function ts(e){return e.startsWith("tool-")?e.slice(5):e}var We={handshake:"/pai/handshake",streamMessage:"/pai/stream-message",streamResume:"/pai/stream-resume",cancelStream:"/pai/cancel-stream",listConversations:"/pai/list-conversations",listMessages:"/pai/list-messages",updateSettings:"/pai/update-settings",markRead:"/pai/mark-read",bootstrap:"/pai/bootstrap",content:"/pai/content",submitForm:"/pai/submit-form"},ns="context";function os(e){let t=e.messages.map(a=>({id:a.serverMessageId??a.id,parts:d_(a),role:a.role,createdAt:a.createdAt!==void 0?new Date(a.createdAt).toISOString():void 0})),n={messages:t,conversationId:e.conversationId,trigger:e.trigger??"submit-message"},o=t.at(-1)?.id;o&&(n.messageId=o),e.visitorId&&(n.visitorId=e.visitorId),e.userPrefs&&(n.userPrefs=e.userPrefs);let i=e.tools?.map(c_).filter(a=>a!==null);return i?.length&&(n.data={tools:i}),n}function l_(e){return e.state==="output-available"||e.state==="output-error"||e.state==="output-denied"||e.approval?.approved!==void 0}function c_(e){return typeof e=="string"?e?{code:e}:null:e?.code?e:null}function d_(e){let t=[];for(let n of e.parts)if(n.kind==="step-start"&&t.push({type:"step-start"}),n.kind==="reasoning"&&n.text&&t.push({type:"reasoning",text:n.text,state:n.done?"done":"streaming"}),n.kind==="text"&&n.text&&t.push({text:n.text,type:"text"}),n.kind==="file"&&n.url&&t.push({mediaType:n.mediaType,type:"file",url:n.url}),n.kind==="tool"&&l_(n)){let o={type:s_(n.toolName),toolCallId:n.toolCallId,state:n.state};n.input!==void 0&&(o.input=n.input),n.output!==void 0&&(o.output=n.output),n.error!==void 0&&(o.errorText=n.error),n.approval&&n.approval.approved!==void 0&&(o.approval=n.approval),t.push(o)}for(let n of e.attachments??[])n.url&&t.push({type:"file",url:n.url,mediaType:n.mediaType,filename:n.name,fileId:n.id,fileSize:n.size});return t}var Q=X.scope("transport"),rs=3,ls=400,__=6e4,is=1e4,as=3,u_=new Set([408,425,429,500,502,503,504]);function ss(e){return ls*2**e+Math.floor(Math.random()*250)}function p_(e){let t=e.get("retry-after");if(!t)return null;let n=Number(t),o=Number.isFinite(n)?n*1e3:Date.parse(t)-Date.now();return Number.isFinite(o)&&o>=0?Math.min(o,3e4):null}function Mr(e,t){return new Promise(n=>{if(t?.aborted)return n();let o=setTimeout(a,e),i=()=>a();t?.addEventListener("abort",i,{once:!0});function a(){clearTimeout(o),t?.removeEventListener("abort",i),n()}})}var lo=class{constructor(t){V(this,"opts",t);V(this,"visitorId");V(this,"conversationId");V(this,"resumeStatus");V(this,"userContext");V(this,"pageContext");V(this,"locale");V(this,"conversationsCache",new Map);V(this,"contentCache",new Map)}setContext(t,n){this.userContext=t,this.pageContext=n}setLocale(t){this.locale=t}primeIdentity(t,n){t&&(this.visitorId=t),n&&(this.conversationId=n)}envelope(){let t={_ev:ao};this.visitorId&&(t.visitorId=this.visitorId),this.conversationId&&(t.conversationId=this.conversationId),this.locale&&(t.locale=this.locale);let n=es(this.userContext,this.pageContext);return n&&(t[ns]=n),t}withEnvelope(t){return{...this.envelope(),...t}}appendEnvelope(t){for(let[n,o]of Object.entries(this.envelope()))t.append(n,o);return t}withEnvelopeQuery(t){let n=new URL(this.url(t));for(let[o,i]of Object.entries(this.envelope()))n.searchParams.has(o)||n.searchParams.set(o,i);return n.toString()}async handshake(t){Q.debug("handshake \u2192",{visitorId:t.visitorId,conversationId:t.conversationId,locale:t.locale});let n=await this.postJson(We.handshake,t,"handshake");return Q.debug("handshake \u2190",{visitorId:n.visitorId,conversationId:n.conversationId,hasWelcome:!!n.welcome,hasConfig:!!n.config,rebind:n.rebind}),f_(n)||Q.warn("handshake response did not match expected shape; using raw response",{response:n}),this.visitorId=n.visitorId??t.visitorId,this.conversationId=n.conversationId,n}async uploadFile(t){Q.debug("uploadFile \u2192",{name:t.name,size:t.size,type:t.type});let n=new FormData;n.append("file",t,t.name);let o=await this.postForm(this.uploadPath,n,"upload");return Q.debug("uploadFile \u2190",{id:o.id,url:o.url}),o}async transcribe(t,n="audio/webm"){Q.debug("transcribe \u2192",{size:t.size,mimeType:n});let o=new FormData;o.append("audio",t,`voice.${m_(n)}`),o.append("mimeType",n);let i=await this.postForm(this.transcribePath,o,"transcribe");return Q.debug("transcribe \u2190",{textLen:i.text.length}),i}conversationsKey(t){return`${this.locale??""}|${JSON.stringify(t,Object.keys(t).toSorted())}`}peekConversations(t={}){let n=this.conversationsCache.get(this.conversationsKey(t));if(n?.value&&Date.now()-n.at<is)return n.value}listConversations(t={}){let n=this.conversationsKey(t),o=this.conversationsCache.get(n);if(o&&Date.now()-o.at<is)return Q.debug("listConversations \u2192 cache",t),o.result;let i={at:Date.now(),result:this.fetchConversations(t).then(a=>(i.value=a,a)).catch(a=>{throw this.conversationsCache.delete(n),a})};return this.conversationsCache.set(n,i),i.result}async fetchConversations(t){let n=new URL(this.url(We.listConversations));t.visitorId&&n.searchParams.set("visitorId",t.visitorId),t.limit&&n.searchParams.set("limit",String(t.limit)),t.cursor&&n.searchParams.set("cursor",t.cursor),Q.debug("listConversations \u2192",{visitorId:t.visitorId??this.visitorId,limit:t.limit,cursor:t.cursor});let o=await this.getJson(n.toString(),"listConversations"),i=o.conversations??[];return Q.debug("listConversations \u2190",{count:i.length,nextCursor:o.nextCursor}),{conversations:i.map(a=>({conversationId:a.conversationId,title:a.title,lastMessageAt:a.lastMessageAt,preview:a.preview,canContinue:a.canContinue,unreadCount:a.unreadCount})),nextCursor:o.nextCursor}}async loadConversation(t){let n=new URL(this.url(We.listMessages));n.searchParams.set("conversationId",t),Q.debug("loadConversation \u2192",{conversationId:t,visitorId:this.visitorId});let o=await this.getJson(n.toString(),"loadConversation"),i=o.messages??[];return Q.debug("loadConversation \u2190",{conversationId:o.conversationId,canContinue:o.canContinue,messageCount:i.length,hasSuggestions:!!o.suggestions}),{conversationId:o.conversationId,canContinue:o.canContinue??!0,messages:i,agent:o.agent,suggestions:o.suggestions}}async markRead(t){if(!(!this.visitorId||!t)){this.conversationsCache.clear(),Q.debug("markRead \u2192",{conversationId:t,visitorId:this.visitorId});try{await this.postJson(We.markRead,{conversationId:t},"markRead")}catch(n){Q.debug("markRead failed (non-fatal)",{err:n})}}}listContent(t={}){let n=`${this.locale??""}|${JSON.stringify(t,Object.keys(t).toSorted())}`,o=this.contentCache.get(n);if(o&&Date.now()-o.at<__)return Q.debug("listContent \u2192 cache",t),o.result;let i=this.fetchContent(t).catch(a=>{throw this.contentCache.delete(n),a});return this.contentCache.set(n,{at:Date.now(),result:i}),i}async fetchContent(t){let n=new URL(this.dataUrl(We.content));for(let[a,l]of Object.entries(t))l!==void 0&&n.searchParams.set(a,Array.isArray(l)?l.join(","):String(l));Q.debug("listContent \u2192",t);let o=await this.getJson(n.toString(),"listContent"),i=(o.items??[]).map(a=>Vi(a,this.locale));return Q.debug("listContent \u2190",{count:i.length,total:o.pagination?.total}),{...o,items:i}}async bootstrap(t){let n=new URL(this.dataUrl(We.bootstrap));t&&n.searchParams.set("conversationId",t),Q.debug("bootstrap \u2192",{conversationId:t??this.conversationId});let o=await this.getJson(n.toString(),"bootstrap"),i=o.forms??[],a=o.formSubmissions??[];return Q.debug("bootstrap \u2190",{forms:i.length,formSubmissions:a.length}),{forms:i,formSubmissions:a}}async saveUserPrefs(t){Q.debug("saveUserPrefs \u2192",{visitorId:this.visitorId,conversationId:this.conversationId,settingsKeys:Object.keys(t)});let n=await this.postJson(We.updateSettings,{userPrefs:t},"saveUserPrefs");return Q.debug("saveUserPrefs \u2190",{ok:n.ok}),n}get uploadPath(){return this.opts.endpoints?.upload??"/pai/upload-file"}get transcribePath(){return this.opts.endpoints?.transcribe??"/pai/transcribe-audio"}get submitFormPath(){return this.opts.endpoints?.submitForm??We.submitForm}async submitForm(t){Q.debug("submitForm \u2192",{formId:t.formId,trigger:t.trigger,fields:Object.keys(t.values).length});try{await this.postJson(this.dataUrl(this.submitFormPath),t,"submitForm")}catch(n){Q.debug("submitForm failed (non-fatal)",{err:n})}}sendMessage(t){this.conversationsCache.clear(),Q.debug("message \u2192",{conversationId:t.conversationId,visitorId:t.visitorId,messageId:t.messageId,messageCount:t.messages.length,trigger:t.trigger,tools:t.data?.tools?.map(l=>l.code)});let n=new AbortController,o=new Set;return{iter:this.runStream(t,n,o),cancel:()=>this.cancelStream(n,t.conversationId),detach:()=>n.abort()}}resumeStream(){let t=new AbortController,n=new Set;this.resumeStatus=void 0;let o=this.resumeStreamGen(t,n,!0),i=()=>t.abort();return{iter:o,cancel:i,detach:i}}async*runStream(t,n,o){(yield*this.drain(this.openMessageStream(t,n.signal),o,n))||(yield*this.resumeStreamGen(n,o,!1))}async*resumeStreamGen(t,n,o){for(let i=1;i<=rs&&!t.signal.aborted;i++){if((!o||i>1)&&(await Mr(ls*i,t.signal),t.signal.aborted))return;let a;try{a=await this.fetchImpl(this.resumeUrl(n.size),{method:"GET",credentials:"omit",headers:{accept:"text/event-stream",...this.opts.auth.headers()},signal:t.signal})}catch(c){if(t.signal.aborted)return;Q.debug("resume fetch failed \u2014 retrying",{attempt:i,err:c});continue}if(a.status===204||!a.ok){Q.debug("resume \u2192 no in-flight stream",{status:a.status});return}if(!(a.headers.get("content-type")??"").includes("text/event-stream")){let c=await a.json().then(d=>d.status).catch(()=>{});if(Q.debug("resume \u2192 no live stream (status response)",{status:c,attempt:i}),c==="pending"&&i<rs)continue;this.resumeStatus=c==="needs-generation"?"needs-generation":"completed";return}this.resumeStatus="live";let s=n.size;if(yield*this.drain(Lr(a,t.signal),n,t))return;if(n.size===s){Q.debug("resume \u2192 stream closed with no new events; nothing to resume");return}}if(!t.signal.aborted)throw new Ve("stream incomplete after resume attempts","server")}async*drain(t,n,o){try{for await(let i of t){if(o.signal.aborted)return!0;if(i.eventId){if(n.has(i.eventId))continue;n.add(i.eventId)}if(yield i,i.chunk.type==="finish"||i.chunk.type==="error")return!0}}catch(i){if(o.signal.aborted)return!0;if(i instanceof Ve&&i.status!==void 0)throw i;Q.debug("stream segment dropped",{err:i})}return!1}cancelStream(t,n){t.signal.aborted||(Q.debug("cancel stream",{conversationId:n,visitorId:this.visitorId}),t.abort(),!(!this.visitorId||!n)&&this.fetchImpl(this.url(We.cancelStream),{method:"POST",credentials:"omit",headers:{"content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope({})),keepalive:!0}).catch(o=>Q.debug("cancel POST failed (non-fatal)",{err:o})))}async*openMessageStream(t,n){let o=await this.fetchImpl(this.url(We.streamMessage),{method:"POST",credentials:"omit",headers:{accept:"text/event-stream","content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope(t)),signal:n});yield*Lr(o,n)}resumeUrl(t){let n=new URL(this.withEnvelopeQuery(We.streamResume));return n.searchParams.set("resumeAt",String(t)),n.toString()}async postJson(t,n,o){let i=await this.fetchWithRetry(()=>[this.url(t),{method:"POST",credentials:"omit",headers:{"content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope(n))}],o);return this.assertOk(i,o)}async postForm(t,n,o){let i=await this.fetchImpl(this.url(t),{method:"POST",credentials:"omit",headers:this.opts.auth.headers(),body:this.appendEnvelope(n)});return this.assertOk(i,o)}async getJson(t,n){let o=await this.fetchWithRetry(()=>[this.withEnvelopeQuery(t),{method:"GET",credentials:"omit",headers:{accept:"application/json",...this.opts.auth.headers()}}],n);return this.assertOk(o,n)}async fetchWithRetry(t,n){for(let o=0;;o++){let[i,a]=t(),l;try{l=await this.fetchImpl(i,a)}catch(c){if(o>=as)throw new Ve(`${n} failed: network error`,"network",void 0,c);Q.debug("request network error \u2014 retrying",{label:n,attempt:o}),await Mr(ss(o));continue}if(l.ok||!u_.has(l.status)||o>=as)return l;let s=p_(l.headers)??ss(o);Q.debug("request retryable status \u2014 retrying",{label:n,status:l.status,attempt:o,wait:s}),await Mr(s)}}async assertOk(t,n){if(!t.ok)throw new Ve(`${n} failed: ${t.status}`,"server",t.status);return await t.json()}url(t){return/^https?:\/\//i.test(t)?t:`${this.opts.agentApiBaseUrl}${t}`}dataUrl(t){return/^https?:\/\//i.test(t)?t:`${this.opts.dataApiBaseUrl}${t}`}get fetchImpl(){return this.opts.fetchImpl??globalThis.fetch.bind(globalThis)}};function m_(e){return e.includes("webm")?"webm":e.includes("ogg")?"ogg":e.includes("mp4")||e.includes("m4a")?"m4a":e.includes("mpeg")?"mp3":e.includes("wav")?"wav":"bin"}function f_(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.visitorId=="string"&&typeof t.conversationId=="string"}function cs(e,t){let n=e?[{kind:"text",id:"t0",textSig:H(e),doneSig:H(!0)}]:[];return{id:Ue(),role:"user",createdAt:Date.now(),status:"complete",attachments:t,partsSig:H(n)}}function sn(){return{id:Ue(),role:"assistant",createdAt:Date.now(),status:"streaming",partsSig:H([])}}function ds(e){let t=Ue();return g_({id:t,role:e.role,createdAt:Date.now(),status:"complete",ephemeral:!0,parts:[{kind:"text",id:`${t}-t0`,text:e.text,done:!0}]})}function g_(e){return{id:e.id,role:e.role,createdAt:e.createdAt,status:e.status,canceled:e.canceled,errorText:e.errorText,finishReason:e.finishReason,serverMessageId:e.serverMessageId,ephemeral:e.ephemeral,attachments:e.attachments,partsSig:H(e.parts.map(x_))}}function h_(e){let t=e.parts.map((n,o)=>n.type==="text"?{kind:"text",id:`${e.id}-t${o}`,textSig:H(n.text),doneSig:H(!0)}:n.type==="reasoning"?{kind:"reasoning",id:`${e.id}-r${o}`,textSig:H(n.text),doneSig:H(n.state!=="streaming")}:n.type==="step-start"?{kind:"step-start",id:`${e.id}-ss${o}`}:n.type==="file"?{kind:"file",url:n.url,mediaType:n.mediaType}:n.type==="source-url"?{kind:"source",sourceId:n.sourceId,url:n.url,title:n.title}:n.type==="source-document"?{kind:"source",sourceId:n.sourceId,title:n.title,filename:n.filename,mediaType:n.mediaType}:n.type.startsWith("tool-")?{kind:"tool",toolCallId:n.toolCallId,toolName:ts(n.type),inputPartialSig:H(""),inputSig:H(n.input),outputSig:H(n.output),errorSig:H(n.errorText),stateSig:H(n.state),approvalSig:H(n.approval)}:null).filter(n=>n!==null);return{id:e.id,role:e.role,serverMessageId:e.id,createdAt:so(e.createdAt)??Date.now(),status:e.status==="failed"?"error":"complete",canceled:e.status==="canceled",partsSig:H(t)}}var v_=new Set(["completed","failed","canceled"]);function b_(e){return!e.parts.some(t=>t.type==="text"&&t.text.trim()!==""||t.type.startsWith("tool-")||t.type==="file"||t.type==="source-url"||t.type==="source-document")}function P_(e){return e.role==="assistant"&&e.status!=null&&!v_.has(e.status)&&b_(e)}function Or(e){return e.filter(t=>!P_(t)).map(h_)}function _s(e){return{id:e.id,role:e.role,createdAt:e.createdAt,status:e.status,canceled:e.canceled,errorText:e.errorText,finishReason:e.finishReason,serverMessageId:e.serverMessageId,ephemeral:e.ephemeral,attachments:e.attachments,parts:e.partsSig.value.map(y_)}}function co(e){let t="";for(let n of e.partsSig.value)n.kind==="text"&&(t+=n.textSig.value);return t}function _o(e){return co(e).trim()!==""?!1:!e.partsSig.value.some(t=>t.kind==="tool"||t.kind==="file"||t.kind==="source")}function ot(e){return e.role==="assistant"&&e.status!=="streaming"&&_o(e)}function us(e){return e.canceled===!0&&ot(e)}function x_(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,textSig:H(e.text),doneSig:H(e.done)}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartialSig:H(e.inputPartial),inputSig:H(e.input),outputSig:H(e.output),errorSig:H(e.error),stateSig:H(e.state),approvalSig:H(e.approval)}:e}function y_(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,text:e.textSig.value,done:e.doneSig.value}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartial:e.inputPartialSig.value,input:e.inputSig.value,output:e.outputSig.value,error:e.errorSig.value,state:e.stateSig.value,approval:e.approvalSig.value}:e}var ps=X.scope("reducer"),uo=class{constructor(t){V(this,"messagesSig",t);V(this,"active",null);V(this,"openTextParts",new Map);V(this,"partSeq",0)}attach(t){this.active=t,this.openTextParts.clear()}detach(){this.active=null,this.openTextParts.clear()}ensureTextPart(t,n,o){let i=`${n}:${o}`,a=this.openTextParts.get(i);if(a)return a;let l={kind:n,id:`${o}#${this.partSeq++}`,textSig:H(""),doneSig:H(!1)};return this.openTextParts.set(i,l),ln(t,l),l}apply(t){let n=this.active;if(n)switch(t.type){case"start":t.messageId&&(n.serverMessageId=t.messageId);return;case"finish-step":this.openTextParts.clear();return;case"start-step":ln(n,{kind:"step-start",id:`ss-${this.partSeq++}`});return;case"finish":ps.debug("finish",{reason:t.finishReason,canContinue:t.canContinue}),n.status="complete",t.finishReason&&(n.finishReason=t.finishReason),this.bumpDone(n);return;case"error":ps.warn("stream error chunk",{errorText:t.errorText}),n.status="error",n.errorText=t.errorText,this.bumpDone(n);return;case"text-start":this.ensureTextPart(n,"text",t.id);return;case"text-delta":{let o=this.ensureTextPart(n,"text",t.id);o.textSig.value+=t.delta;return}case"text-end":this.ensureTextPart(n,"text",t.id).doneSig.value=!0;return;case"reasoning-start":this.ensureTextPart(n,"reasoning",t.id).doneSig.value=!1;return;case"reasoning-delta":{let o=this.ensureTextPart(n,"reasoning",t.id);o.textSig.value+=t.delta;return}case"reasoning-end":this.ensureTextPart(n,"reasoning",t.id).doneSig.value=!0;return;case"tool-input-start":case"tool-input-delta":case"tool-input-available":case"tool-output-available":case"tool-output-error":case"tool-output-denied":case"tool-approval-request":S_(n,t);return;case"file":ln(n,{kind:"file",url:t.url,mediaType:t.mediaType});return;case"source-url":ms(n,{kind:"source",sourceId:t.sourceId,url:t.url,title:t.title});return;case"source-document":ms(n,{kind:"source",sourceId:t.sourceId,title:t.title,filename:t.filename,mediaType:t.mediaType});return;case"data-notification":return;case"data-conversation-rebind":return;default:{let o=t}}}bumpDone(t){t.partsSig.value=[...t.partsSig.value],this.messagesSig.value=[...this.messagesSig.value]}};function bt(e,t,n){let o=e.partsSig.value.find(a=>a.kind==="tool"&&a.toolCallId===t);if(o)return o;let i={kind:"tool",toolCallId:t,toolName:n??"tool",inputPartialSig:H(""),inputSig:H(void 0),outputSig:H(void 0),errorSig:H(void 0),stateSig:H("input-streaming"),approvalSig:H(void 0)};return ln(e,i),i}function ln(e,t){e.partsSig.value=[...e.partsSig.value,t]}function ms(e,t){e.partsSig.value.some(n=>n.kind==="source"&&n.sourceId===t.sourceId)||ln(e,t)}function S_(e,t){switch(t.type){case"tool-input-start":bt(e,t.toolCallId,t.toolName);return;case"tool-input-delta":{let n=bt(e,t.toolCallId);n.inputPartialSig.value+=t.inputTextDelta;return}case"tool-input-available":{let n=bt(e,t.toolCallId,t.toolName);n.inputSig.value=t.input,n.stateSig.value="input-available";return}case"tool-approval-request":{let n=bt(e,t.toolCallId,t.toolName);n.approvalSig.value={id:t.approvalId},n.stateSig.value="approval-requested";return}case"tool-output-available":{let n=bt(e,t.toolCallId);n.outputSig.value=t.output,n.stateSig.value="output-available";return}case"tool-output-error":{let n=bt(e,t.toolCallId);n.errorSig.value=t.errorText,n.stateSig.value="output-error";return}case"tool-output-denied":{let n=bt(e,t.toolCallId);n.stateSig.value="output-denied";return}default:return}}var fs=X.scope("feedback:audio"),po=class{constructor(){V(this,"ctx",null);V(this,"master",null);V(this,"buffers",new Map)}unlock(){if(this.ctx){this.ctx.state==="suspended"&&this.ctx.resume();return}let t=globalThis.AudioContext??globalThis.webkitAudioContext;if(t)try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.gain.value=1,this.master.connect(this.ctx.destination)}catch(n){fs.warn("AudioContext init failed",{err:n})}}setVolume(t){if(!this.master||!this.ctx)return;let n=Math.max(0,Math.min(1,t));this.master.gain.setTargetAtTime(n,this.ctx.currentTime,.01)}playTone(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let i=n.currentTime,a=t.noteMs/1e3;t.notes.forEach((l,s)=>{let c=n.createOscillator();c.type=t.type,c.frequency.value=l;let d=n.createGain(),u=i+s*a;d.gain.setValueAtTime(1e-4,u),d.gain.exponentialRampToValueAtTime(t.peakGain,u+.005),d.gain.exponentialRampToValueAtTime(1e-4,u+a),c.connect(d).connect(o),c.start(u),c.stop(u+a+.01)})}async playUrl(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let i=await this.getBuffer(t);if(!i)return;let a=n.createBufferSource();a.buffer=i,a.connect(o),a.start()}destroy(){this.ctx&&this.ctx.close().catch(()=>{}),this.ctx=null,this.master=null,this.buffers.clear()}async getBuffer(t){if(!this.ctx)return null;let n=this.buffers.get(t);if(n)return n instanceof Promise,n;let o=this.ctx,i=fetch(t).then(a=>a.ok?a.arrayBuffer():Promise.reject(new Error(`fetch ${a.status}`))).then(a=>o.decodeAudioData(a)).then(a=>(this.buffers.set(t,a),a)).catch(a=>(fs.warn("audio fetch/decode failed",{url:t,err:a}),this.buffers.delete(t),null));return this.buffers.set(t,i),i}};var gs={messageReceived:10,messageSent:0,error:[20,40,20],voiceStart:10,voiceStop:0},hs={messageReceived:{notes:[880,1318.51],noteMs:90,type:"sine",peakGain:.45},messageSent:{notes:[1568],noteMs:60,type:"sine",peakGain:.25},error:{notes:[523.25,392],noteMs:120,type:"triangle",peakGain:.55},voiceStart:{notes:[1318.51],noteMs:50,type:"sine",peakGain:.3},voiceStop:{notes:[880],noteMs:50,type:"sine",peakGain:.3}};var ct=null,mo=0;function w_(){return typeof navigator<"u"&&typeof navigator.vibrate=="function"}function k_(){if(typeof document>"u")return null;let e=document.createElement("input");e.type="checkbox",e.setAttribute("switch",""),e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.id=`__${x.cssPrefix}_haptic_${Math.random().toString(36).slice(2)}`;let t=document.createElement("label");t.htmlFor=e.id,t.setAttribute("aria-hidden","true");let n="position:absolute!important;width:1px!important;height:1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;opacity:0!important;pointer-events:none!important;";return e.style.cssText=n,t.style.cssText=n,document.body.append(e,t),{input:e,label:t}}function vs(e){if(!(e===0||Array.isArray(e)&&e.every(t=>t===0))){if(w_())try{navigator.vibrate(e);return}catch{}if(ct||(ct=k_()),!!ct)try{ct.label.click()}catch{}}}function bs(){mo++;let e=!1;return()=>{e||(e=!0,mo=Math.max(0,mo-1),mo===0&&ct&&(ct.input.remove(),ct.label.remove(),ct=null))}}var C_=X.scope("feedback"),T_=100,fo=class{constructor(t,n){V(this,"mutedSig",H(!1));V(this,"audio",new po);V(this,"releaseHaptics");V(this,"sound");V(this,"haptics");V(this,"lastPlayed",new Map);V(this,"reducedMotionMq",null);this.sound=t,this.haptics=n,this.releaseHaptics=bs(),this.audio.setVolume(this.effectiveVolume()),typeof matchMedia<"u"&&(this.reducedMotionMq=matchMedia("(prefers-reduced-motion: reduce)"))}unlock(){this.audio.unlock(),this.audio.setVolume(this.effectiveVolume())}update(t,n){this.sound=t,this.haptics=n,this.audio.setVolume(this.effectiveVolume())}setMuted(t){this.mutedSig.value!==t&&(this.mutedSig.value=t)}toggleMuted(){this.mutedSig.value=!this.mutedSig.value}play(t){this.mutedSig.value||this.isDeduped(t)||(this.lastPlayed.set(t,performance.now()),this.sound.enabled&&this.playSound(t),this.haptics.enabled&&this.isTouchDevice()&&this.playHaptic(t))}destroy(){this.audio.destroy(),this.releaseHaptics()}isDeduped(t){let n=this.lastPlayed.get(t);return n===void 0?!1:performance.now()-n<T_}playSound(t){let n=this.sound.events?.[t];if(n===!1)return;if(typeof n=="string"){this.audio.playUrl(n).catch(i=>C_.warn("audio play failed",{err:i,url:n}));return}let o=hs[t];o&&this.audio.playTone(o)}playHaptic(t){if(this.reducedMotionMq?.matches)return;let n=this.haptics.events?.[t];if(n===!1)return;let o=n===!0||n===void 0?gs[t]:n;vs(o)}effectiveVolume(){let t=this.sound.volume??.3;return this.reducedMotionMq?.matches?t*.5:t}isTouchDevice(){return typeof window>"u"?!1:matchMedia("(hover: none) and (pointer: coarse)").matches}};function Pt(e,t){return e instanceof Ve&&e.status===429?t.errorRateLimited:t.errorGeneric}var E_=0;function r(e,t,n,o,i,a){t||(t={});var l,s,c=t;if("ref"in c)for(s in c={},t)s=="ref"?l=t[s]:c[s]=t[s];var d={type:e,props:c,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--E_,__i:-1,__u:0,__source:i,__self:a};if(typeof e=="function"&&(l=e.defaultProps))for(s in l)c[s]===void 0&&(c[s]=l[s]);return J.vnode&&J.vnode(d),d}var $={fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24"},cn=`${x.cssPrefix}-icon-dir`,R_=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M21 12a8 8 0 0 1-12 6.93L3 21l1.65-5.16A8 8 0 1 1 21 12Z"})}),Xe=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M18 6 6 18M6 6l12 12"})}),Ps=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M12 5v14M5 12h14"})}),xs=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:[r("path",{d:"m22 2-7 20-4-9-9-4Z"}),r("path",{d:"M22 2 11 13"})]}),ys=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M12 19V5M5 12l7-7 7 7"})}),Ss=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:r("path",{d:"M3 20V4l18 8-18 8Z"})}),$t=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:r("path",{d:"m9 18 6-6-6-6"})}),ws=()=>r("svg",{...$,"aria-hidden":"true",children:r("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),ks=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"m21 11-9 9a5.5 5.5 0 0 1-7.78-7.78l8.49-8.49a3.67 3.67 0 0 1 5.19 5.19l-8.49 8.49a1.83 1.83 0 0 1-2.6-2.6l7.78-7.78"})}),Cs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("rect",{x:"9",y:"2",width:"6",height:"12",rx:"3"}),r("path",{d:"M5 10a7 7 0 0 0 14 0M12 19v3"})]}),Ts=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M3 8V3h5M21 8V3h-5M3 16v5h5M21 16v5h-5"})}),Es=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M8 3v5H3M16 3v5h5M8 21v-5H3M16 21v-5h5"})}),Rs=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M3 3h7v2H5v5H3zM21 3h-7v2h5v5h2zM3 21h7v-2H5v-5H3zM21 21h-7v-2h5v-5h2z"})}),As=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M10 3v5H3M14 3v5h7M10 21v-5H3M14 21v-5h7"})}),Is=()=>r("svg",{...$,"aria-hidden":"true",viewBox:"0 0 10 10",children:r("path",{d:"M9 1L1 9M9 5L5 9M9 9H9",strokeWidth:"1.5"})}),Ls=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"12",r:"1.5",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"19",r:"1.5",fill:"currentColor",stroke:"none"})]}),Ms=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM15 9a5 5 0 0 1 0 6M18 7a9 9 0 0 1 0 10"})}),Ns=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM22 9l-6 6M16 9l6 6"})}),Os=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M3 18 8 6l5 12M4.7 14h6.6"}),r("path",{d:"M14.5 18l3.2-7 3.2 7M15.6 15.8h4.2"})]}),Ds=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:r("path",{d:"m5 6 6 6-6 6M13 6l6 6-6 6"})}),dn=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M20 6 9 17l-5-5"})}),$s=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M3 3v6h6"}),r("path",{d:"M3.05 13A9 9 0 1 0 6 5.3L3 9"}),r("path",{d:"M12 7v5l3 2"})]}),Hs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("path",{d:"M2 12h20"}),r("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]}),_n=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),Bs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M12 20h9"}),r("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]}),go=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"m6 9 6 6 6-6"})}),Fs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),r("path",{d:"M14 2v6h6"})]}),A_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"m12 3-1.5 4.5L6 9l4.5 1.5L12 15l1.5-4.5L18 9l-4.5-1.5Z"}),r("path",{d:"M19 15v4M17 17h4M5 3v2M4 4h2"})]}),Dr=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2Z"})}),$r=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),r("path",{d:"M12 17h.01"})]}),I_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"m15 4 3 3-9 9-3-3z"}),r("path",{d:"M18 2v2M20 4h2M3 20l3-3M3 16h2M5 14v2"})]}),L_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("rect",{x:"4",y:"8",width:"16",height:"12",rx:"2"}),r("path",{d:"M12 8V4"}),r("circle",{cx:"12",cy:"3",r:"1"}),r("path",{d:"M2 14h2M20 14h2M9 13h.01M15 13h.01M9.5 17h5"})]}),M_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M4 14v-2a8 8 0 0 1 16 0v2"}),r("rect",{x:"2",y:"14",width:"4",height:"6",rx:"1.5"}),r("rect",{x:"18",y:"14",width:"4",height:"6",rx:"1.5"}),r("path",{d:"M20 20v1a3 3 0 0 1-3 3h-5"})]}),N_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"m4.93 4.93 4.24 4.24M14.83 14.83l4.24 4.24M14.83 9.17l4.24-4.24M4.93 19.07l4.24-4.24"})]}),Hr=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"11",cy:"11",r:"7"}),r("path",{d:"m21 21-4.3-4.3"})]}),zs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m8.5 12 2.5 2.5 4.5-5"})]}),Us=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M3 9.5 12 3l9 6.5"}),r("path",{d:"M5 9v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9"})]}),Vs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"m3 11 15-5v12L3 13z"}),r("path",{d:"M3 11v2a2 2 0 0 0 2 2h1V9H5a2 2 0 0 0-2 2z"}),r("path",{d:"M7 15v3a2 2 0 0 0 4 0v-2"}),r("path",{d:"M21 10a3 3 0 0 1 0 4"})]}),un=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z"}),r("path",{d:"M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1"})]}),Ws=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"})]}),qs=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}),Gs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M12 3v18"}),r("path",{d:"M12 3a9 9 0 0 1 0 18z",fill:"currentColor",stroke:"none"})]}),O_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"10.5",cy:"10.5",r:"6.5"}),r("path",{d:"M8 11a2.5 2.5 0 0 0 5 0"}),r("path",{d:"m20 20-4.4-4.4"})]}),D_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M12 3.5 13.6 9 19 10.5 13.6 12 12 17.5 10.4 12 5 10.5 10.4 9z"}),r("path",{d:"M18.5 4v3M20 5.5h-3M5.5 16v2.5M6.75 17.25h-2.5"})]}),$_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M4 18h16"}),r("path",{d:"M5 18a7 7 0 0 1 14 0"}),r("path",{d:"M12 8V6"}),r("path",{d:"M10 6h4"})]}),H_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M7 11V6.5a1.5 1.5 0 0 1 3 0V10"}),r("path",{d:"M10 10V5.5a1.5 1.5 0 0 1 3 0V10"}),r("path",{d:"M13 10V6.5a1.5 1.5 0 0 1 3 0V12"}),r("path",{d:"M16 9.5a1.5 1.5 0 0 1 3 0v2.5a7 7 0 0 1-7 7 7 7 0 0 1-6.4-4.2L4 12.5a1.5 1.5 0 0 1 2.6-1.5L7 11"})]}),Ks=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M14.7 6.3a4 4 0 0 0-5.4 5.3L3 18l3 3 6.4-6.3a4 4 0 0 0 5.3-5.4l-2.7 2.7-2.6-.7-.7-2.6z"})}),js=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M12 7v5l3 2"})]}),Xs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m8.5 12 2.5 2.5 4.5-5"})]}),Ys=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m15 9-6 6M9 9l6 6"})]}),Js={chat:R_,message:Dr,bubbles:un,spark:A_,wand:I_,bot:L_,help:$r,lifebuoy:N_,headset:M_,search:O_,sparkles:D_,concierge:$_,wave:H_};var L=x.cssPrefix,w={launcher:`${L}-launcher`,callout:`${L}-callout`,calloutDismiss:`${L}-callout-dismiss`,panel:`${L}-panel`,panelHeader:`${L}-panel-header`,resizeGrip:`${L}-resize-grip`,scrollToBottom:`${L}-scroll-to-bottom`,actionHistory:`${L}-action-history`,actionClose:`${L}-action-close`,langSegment:`${L}-lang-segment`,composer:`${L}-composer`,composerInput:`${L}-composer-input`,composerSend:`${L}-composer-send`,composerStop:`${L}-composer-stop`,composerAttach:`${L}-composer-attach`,composerFileInput:`${L}-composer-file-input`,composerVoice:`${L}-composer-voice`,attachmentChip:`${L}-attachment-chip`,attachmentRemove:`${L}-attachment-remove`,suggestion:`${L}-suggestion`,messageBubble:`${L}-message`,messageRetry:`${L}-message-retry`,historyPane:`${L}-history-pane`,historyBack:`${L}-history-back`,historyItem:`${L}-history-item`,sidebar:`${L}-sidebar`,sidebarToggle:`${L}-sidebar-toggle`,sidebarNewConversation:`${L}-sidebar-new-conversation`,sidebarItem:`${L}-sidebar-item`,messengerHome:`${L}-messenger-home`,modulesEmpty:`${L}-modules-empty`,tab:`${L}-tab`,tabBadge:`${L}-tab-badge`,homeView:`${L}-home-view`,homeGreeting:`${L}-home-greeting`,homeBrand:`${L}-home-brand`,backHeader:`${L}-back-header`,contentView:`${L}-content-view`,contentScroll:`${L}-content-scroll`,homeSearch:`${L}-home-search`,helpSearch:`${L}-help-search`,homeRecent:`${L}-home-recent`,homeContentRow:`${L}-home-content-row`,helpArticle:`${L}-help-article`,newsItem:`${L}-news-item`,formGate:`${L}-form-gate`,formDone:`${L}-form-done`,formDoneToggle:`${L}-form-done-toggle`,formAnswers:`${L}-form-answers`,formFill:`${L}-form-fill`,formSubmit:`${L}-form-submit`,formSkip:`${L}-form-skip`,formField:`${L}-form-field`,toolAskInput:`${L}-tool-ask-input`,toolInputSubmit:`${L}-tool-input-submit`,toolInputSkip:`${L}-tool-input-skip`,toolApproval:`${L}-tool-approval`,toolApprove:`${L}-tool-approve`,toolReject:`${L}-tool-reject`,toolEdit:`${L}-tool-edit`,toolDecision:`${L}-tool-decision`,toolCall:`${L}-tool-call`,source:`${L}-source`};function xe(e,t){return`${e}-${t}`}var ho=x.cssPrefix;function Qs({onToggle:e,launcher:t,strings:n,leaving:o,edgeTab:i}){let a=t.variant!=="circle"&&!!t.label;return r("button",{type:"button",class:`${ho}-fab`,"data-variant":t.variant,"data-size":t.size,"data-edge-tab":i?"true":void 0,"data-leaving":o?"true":void 0,"data-testid":w.launcher,onClick:e,"aria-label":n.launcherOpen,children:[B_(t.icon),a?r("span",{class:`${ho}-fab-label`,children:Ee(n,t.label??"")}):null]})}function B_(e){let t=Js[e];return t?r(t,{}):r(F_,{source:e})}function F_({source:e}){return r("span",{ref:t=>{t&&z_(t,e)},"aria-hidden":"true"})}function z_(e,t){if(e.dataset.svgMounted!==t)try{let o=new DOMParser().parseFromString(t,"image/svg+xml").documentElement;o&&o.tagName.toLowerCase()==="svg"&&(e.replaceChildren(document.importNode(o,!0)),e.dataset.svgMounted=t)}catch{}}function Zs({callout:e,launcherPosition:t,strings:n,closeLabel:o,onDismiss:i}){let[a,l]=A(!1);return R(()=>{let s=setTimeout(()=>l(!0),e.delayMs);return()=>clearTimeout(s)},[e.delayMs]),R(()=>{if(!a||e.autoDismissMs<=0)return;let s=setTimeout(i,e.autoDismissMs);return()=>clearTimeout(s)},[a,e.autoDismissMs,i]),a?r("div",{class:`${ho}-callout`,role:"status","data-shape":e.shape,"data-position":U_(e.position,t),"data-animated":e.animated?"true":void 0,"data-testid":w.callout,children:[r("span",{children:Ee(n,e.text)}),r("button",{type:"button",class:`${ho}-callout-close`,onClick:i,"aria-label":o,title:o,"data-testid":w.calloutDismiss,children:r(Xe,{})})]}):null}function U_(e,t){let n=t.endsWith("-right"),o=t.startsWith("bottom-");return e==="vertical"?o?"top":"bottom":n?"left":"right"}function vo({panelEl:e,resize:t,position:n,initialSize:o,onSizeChange:i,strings:a}){let l=x.cssPrefix,s=O(null);if(R(()=>{if(!e)return;let m=e.style;t.minWidth&&m.setProperty(`--${l}-resize-min-w`,t.minWidth),t.maxWidth&&m.setProperty(`--${l}-resize-max-w`,t.maxWidth),t.minHeight&&m.setProperty(`--${l}-resize-min-h`,t.minHeight),t.maxHeight&&m.setProperty(`--${l}-resize-max-h`,t.maxHeight),o&&(m.setProperty(`--${l}-widget-w`,`${o.width}px`),m.setProperty(`--${l}-widget-h`,`${o.height}px`))},[e,t.minWidth,t.maxWidth,t.minHeight,t.maxHeight,l,o]),!e)return null;let c=n.startsWith("top-"),d=n.endsWith("-right"),u=`${l}-resize-grip ${l}-resize-grip--${c?"bottom":"top"}-${d?"left":"right"}`,_=m=>{if(!e)return;let C=m.currentTarget,v=e.getBoundingClientRect();s.current={pointerId:m.pointerId,startX:m.clientX,startY:m.clientY,startW:v.width,startH:v.height,dirX:d?-1:1,dirY:c?1:-1},C.setPointerCapture(m.pointerId),e.setAttribute("data-resizing",""),m.preventDefault()},g=m=>{let C=s.current;if(!C||m.pointerId!==C.pointerId||!e)return;let v=(m.clientX-C.startX)*C.dirX,b=(m.clientY-C.startY)*C.dirY;e.style.setProperty(`--${l}-widget-w`,`${C.startW+v}px`),e.style.setProperty(`--${l}-widget-h`,`${C.startH+b}px`)},f=m=>{let C=s.current;if(!C||m.pointerId!==C.pointerId||!e)return;m.currentTarget.releasePointerCapture(m.pointerId),e.removeAttribute("data-resizing");let v=e.getBoundingClientRect();i({width:Math.round(v.width),height:Math.round(v.height)}),s.current=null};return r("div",{class:u,role:"separator","aria-orientation":"vertical","aria-label":a.resizeHandle,title:a.resizeHandle,onPointerDown:_,onPointerMove:g,onPointerUp:f,onPointerCancel:f,"data-testid":w.resizeGrip,children:r(Is,{})})}var xt=x.cssPrefix,V_=`.${xt}-header, .${xt}-back-header, .${xt}-home-hero`,W_='button, a, input, textarea, select, [role="tab"], [contenteditable]',el=56;function bo(e,t){R(()=>{if(!t||!e)return;let n=c=>Number.parseFloat(c)||0,o=(c,d)=>Math.min(d,Math.max(-d,c)),i=null,a=c=>{let d=c.target;if(!(d instanceof Element)||!d.closest(V_)||d.closest(W_))return;let u=e.getBoundingClientRect();i={id:c.pointerId,x:c.clientX,y:c.clientY,dx:n(e.style.getPropertyValue(`--${xt}-modal-dx`)),dy:n(e.style.getPropertyValue(`--${xt}-modal-dy`)),maxX:(window.innerWidth+u.width)/2-el,maxY:(window.innerHeight+u.height)/2-el},e.dataset.dragging="true",c.preventDefault()},l=c=>{if(!i||c.pointerId!==i.id)return;let d=o(i.dx+c.clientX-i.x,i.maxX),u=o(i.dy+c.clientY-i.y,i.maxY);e.style.setProperty(`--${xt}-modal-dx`,`${d}px`),e.style.setProperty(`--${xt}-modal-dy`,`${u}px`)},s=c=>{!i||c.pointerId!==i.id||(i=null,delete e.dataset.dragging)};return e.addEventListener("pointerdown",a),window.addEventListener("pointermove",l),window.addEventListener("pointerup",s),window.addEventListener("pointercancel",s),()=>{e.removeEventListener("pointerdown",a),window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),window.removeEventListener("pointercancel",s)}},[e,t])}function pn(e,t,n){switch(e){case"clear":case"sound":case"history":case"language":case"theme":case"textSize":return!0;case"expand":return t==="floating";case"fullscreen":return t!=="standalone";case"close":return t==="standalone"||t==="page"?!1:t==="inline"?n==="fullscreen":!0}}function Po(e,t,n){return pn("close",e,t)?n.includes("close"):!1}function tl(e,t){return e==="inline"&&t==="fullscreen"?"exit-fullscreen":"close"}var q_='a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),[tabindex]:not([tabindex="-1"])';function xo(e){let t=n=>{if(n.key!=="Tab")return;let o=[...e.querySelectorAll(q_)].filter(s=>s.offsetParent!==null||s===document.activeElement);if(o.length===0){n.preventDefault();return}let i=o[0],a=o[o.length-1];if(!i||!a)return;let l=e.getRootNode().activeElement;n.shiftKey&&l===i?(n.preventDefault(),a.focus()):!n.shiftKey&&l===a&&(n.preventDefault(),i.focus())};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)}function yo(e){return e.trim().split(/\s+/).slice(0,2).map(t=>t.charAt(0).toUpperCase()).join("")}var Br=x.cssPrefix;function nl({agent:e,strings:t}){let n=e.status??"online",o=Ee(t,e.name),i=e.title?Ee(t,e.title):null;return r("div",{class:`${Br}-agent`,children:[r("div",{class:`${Br}-agent-avatar`,"data-status":n,children:e.avatar?r("img",{src:e.avatar,alt:""}):r("span",{children:yo(o)})}),r("div",{class:`${Br}-agent-meta`,children:[r("strong",{children:o}),i?r("span",{children:i}):null]})]})}var ol=X.scope("attachments");function So(e,t,n){let o=K_(e),i=[],a=[],l=Y_(n.accept),s=t.reduce((d,u)=>d+u.size,0),c=t.length;for(let d of o){let u=G_(d,c,s,n,l);if(u){a.push({file:d,reason:u});continue}i.push(X_(d)),s+=d.size,c+=1}return(i.length||a.length)&&ol.debug("ingest",{accepted:i.length,rejected:a.map(d=>({name:d.file.name,reason:d.reason}))}),{accepted:i,rejected:a}}function Fr(e){try{URL.revokeObjectURL(e.previewUrl)}catch(t){ol.debug("revokeObjectURL failed",{error:t})}}function G_(e,t,n,o,i){return t>=o.maxCount?"count":n+e.size>o.maxBytes?"bytes":J_(e,i)?null:"mime"}function K_(e){return e?Array.isArray(e)?e.filter(t=>t instanceof File):[...e].map(t=>t instanceof File?t:j_(t)).filter(t=>t!==null):[]}function j_(e){let t=e;return!t?.getAsFile||t.kind!=="file"?null:t.getAsFile()}function X_(e){return{file:e,id:Ue(),mediaType:e.type||"application/octet-stream",name:e.name||"pasted-file",previewUrl:URL.createObjectURL(e),size:e.size}}function Y_(e){return e.split(",").map(t=>t.trim().toLowerCase()).filter(Boolean).map(t=>{if(t.startsWith("."))return{kind:"ext",ext:t};let[n="*",o="*"]=t.split("/");return{kind:"mime",type:n,subtype:o}})}function J_(e,t){if(t.length===0)return!0;let[n="*",o="*"]=(e.type||"").toLowerCase().split("/"),i=(e.name||"").toLowerCase();return t.some(a=>a.kind==="ext"?i.endsWith(a.ext):(a.type==="*"||a.type===n)&&(a.subtype==="*"||a.subtype===o))}var mn=x.cssPrefix;function rl({attachment:e,onRemove:t}){let n=e.mediaType.startsWith("image/");return r("span",{class:`${mn}-attachment-chip`,title:e.name,"data-testid":xe(w.attachmentChip,e.id),children:[n?r("img",{class:`${mn}-attachment-thumb`,src:e.previewUrl,alt:""}):r("span",{class:`${mn}-attachment-thumb`,"aria-hidden":"true",children:r(Fs,{})}),r("span",{class:`${mn}-attachment-name`,children:e.name}),r("button",{type:"button",class:`${mn}-attachment-remove`,onClick:t,"aria-label":`Remove ${e.name}`,"data-testid":xe(w.attachmentRemove,e.id),children:r(Xe,{})})]})}var zr={isSupported:!1,start:()=>{},stop:()=>{}};function Ur(e,t,n){return e==="disabled"?zr:e==="server"?tu(n):Q_(t)}function Q_(e){let t=Z_();if(!t)return zr;let n=null;return{isSupported:!0,start(o,i){n=new t,n.continuous=!0,n.interimResults=!0,n.lang=e,n.addEventListener("result",l=>{let s=l,c="",d=!1;for(let u=s.resultIndex;u<s.results.length;u++){let _=s.results[u];_&&(c+=_[0].transcript,_.isFinal&&(d=!0))}o(c,d)});let a=()=>{n=null,i()};n.addEventListener("end",a),n.addEventListener("error",a),n.start()},stop(){n?.stop()}}}function Z_(){let e=globalThis;return e.SpeechRecognition??e.webkitSpeechRecognition}var eu=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus","audio/mp4"];function tu(e){if(typeof MediaRecorder>"u"||!navigator?.mediaDevices?.getUserMedia)return zr;let t=null,n=null,o=[],i=()=>{for(let a of n?.getTracks()??[])a.stop();n=null};return{isSupported:!0,async start(a,l){try{n=await navigator.mediaDevices.getUserMedia({audio:!0});let s=nu();t=new MediaRecorder(n,s?{mimeType:s}:void 0),o=[],t.addEventListener("dataavailable",c=>{c.data.size>0&&o.push(c.data)}),t.addEventListener("stop",async()=>{let c=t?.mimeType??"audio/webm";i();let d=new Blob(o,{type:c});o=[];try{let{text:u}=await e(d,c);u&&a(u,!0)}catch{}finally{l()}}),t.start()}catch{i(),l()}},stop(){t?.stop()}}}function nu(){for(let e of eu)if(MediaRecorder.isTypeSupported(e))return e}var He=x.cssPrefix,yt=X.scope("composer");function Ht(e){return e.reduce((t,n)=>t+n.size,0)}var ou={arrowUp:ys,paperPlane:xs,send:Ss,chevron:$t};function il({options:e,transport:t,feedback:n,bus:o,isStreaming:i,onSend:a,onStop:l,attachApiRef:s}){let c=e.strings,[d,u]=A(""),[_,g]=A([]),[f,m]=A(!1),C=O(null),v=O(null),b=e.features.files,y=e.features.voice,[P,E]=A(()=>Ur(y,e.locale,(k,K)=>t.transcribe(k,K)));R(()=>{f||y==="disabled"||E(Ur(y,e.locale,(k,K)=>t.transcribe(k,K)))},[e.locale,y,t,f]),R(()=>{let k=C.current;if(!k)return;let K=k.getRootNode(),re="activeElement"in K?K.activeElement:null;re&&k.closest(`.${He}-panel`)?.contains(re)||k.focus({preventScroll:!0})},[]),R(()=>{let k=C.current;if(k){if(d.length===0){k.style.height="";return}k.style.height="auto",k.style.height=`${Math.min(k.scrollHeight,160)}px`}},[d]);let B=O(_);B.current=_,R(()=>()=>B.current.forEach(Fr),[]),R(()=>{if(s)return s.current={attachFromDrop:k=>{let K=So(k,B.current,e.attachments);K.accepted.length!==0&&(yt.info("attach (drop)",{count:K.accepted.length,totalBytes:Ht(K.accepted)}),o.emit("attach",{count:K.accepted.length,totalBytes:Ht(K.accepted)}),g(re=>[...re,...K.accepted]))}},()=>{s.current&&(s.current=null)}},[s,e.attachments]),R(()=>{let k=C.current;if(!k)return;let K=k.closest(`.${He}-panel`);if(!K)return;let re=de=>{let ue=de.clipboardData;if(!ue)return;if(b){let ie=So(ue.items,B.current,e.attachments);if(ie.accepted.length>0){de.preventDefault(),yt.info("attach (paste)",{count:ie.accepted.length,totalBytes:Ht(ie.accepted)}),o.emit("attach",{count:ie.accepted.length,totalBytes:Ht(ie.accepted)}),g(ye=>[...ye,...ie.accepted]);return}}if(de.target===k)return;let Ie=ue.getData("text/plain");Ie&&(de.preventDefault(),u(ie=>ie+Ie),k.focus())};return K.addEventListener("paste",re),()=>K.removeEventListener("paste",re)},[b,e.attachments,He]);let le=()=>{let k=d.trim();!k&&_.length===0||i||(a(k,_),u(""),g([]))},M=k=>{k.key!=="Enter"||k.shiftKey||k.isComposing||(k.preventDefault(),i?l():le())},Z=k=>{let K=k.target,re=So(K.files,_,e.attachments);re.accepted.length>0&&(yt.info("attach (file picker)",{count:re.accepted.length,totalBytes:Ht(re.accepted)}),o.emit("attach",{count:re.accepted.length,totalBytes:Ht(re.accepted)}),g(de=>[...de,...re.accepted])),K.value=""},F=k=>{yt.info("removeAttachment",{id:k}),o.emit("removeAttachment",{id:k}),g(K=>{let re=K.find(de=>de.id===k);return re&&Fr(re),K.filter(de=>de.id!==k)})},G=O(null),Y=()=>{if(P.isSupported){if(f){let k=G.current?Date.now()-G.current:0;yt.info("voiceStop",{durationMs:k}),o.emit("voiceStop",{durationMs:k}),P.stop(),m(!1),n.play("voiceStop"),G.current=null;return}G.current=Date.now(),yt.info("voiceStart"),o.emit("voiceStart",void 0),m(!0),n.play("voiceStart"),P.start((k,K)=>u(re=>K?`${re}${k} `:re),()=>{if(m(!1),G.current){let k=Date.now()-G.current;yt.debug("voiceStop (auto)",{durationMs:k}),o.emit("voiceStop",{durationMs:k}),G.current=null}})}},ve=ou[e.composer.sendButton.icon];return r("div",{class:`${He}-composer`,"data-testid":w.composer,children:[_.length>0?r("div",{class:`${He}-attachments`,children:_.map(k=>r(rl,{attachment:k,onRemove:()=>F(k.id)},k.id))}):null,r("div",{class:`${He}-composer-row`,children:[r("div",{class:`${He}-composer-actions`,children:[b?r("button",{type:"button",class:`${He}-icon-btn`,onClick:()=>v.current?.click(),"aria-label":c.attach,"data-testid":w.composerAttach,children:r(ks,{})}):null,P.isSupported?r("button",{type:"button",class:`${He}-icon-btn`,onClick:Y,"aria-label":f?c.micStop:c.micStart,"aria-pressed":f,"data-recording":f?"true":void 0,"data-testid":w.composerVoice,children:r(Cs,{})}):null]}),r("textarea",{ref:C,class:`${He}-textarea`,rows:1,value:d,placeholder:c.composerPlaceholder,onInput:k=>u(k.target.value),onKeyDown:M,"aria-label":c.composerPlaceholder,"data-testid":w.composerInput}),i?r("button",{type:"button",class:`${He}-send`,onClick:l,"aria-label":c.stop,"data-testid":w.composerStop,children:r(ws,{})}):r("button",{type:"button",class:`${He}-send`,"data-shape":e.composer.sendButton.shape,"data-variant":e.composer.sendButton.variant,onClick:le,disabled:!d.trim()&&_.length===0,"aria-label":c.send,"data-testid":w.composerSend,children:r(ve,{})})]}),r("input",{ref:v,type:"file",multiple:!0,accept:e.attachments.accept,onChange:Z,class:`${He}-sr-only`,"data-testid":w.composerFileInput})]})}var ru=x.cssPrefix;function al({visible:e,strings:t}){return e?r("div",{class:`${ru}-dropzone`,role:"status","aria-live":"polite",children:t.dropZone}):null}function wo({containerRef:e,onDrop:t}){let[n,o]=A(!1);return R(()=>{let i=e.current;if(!i)return;let a=0,l=u=>{a+=1,u.dataTransfer?.types.includes("Files")&&(u.preventDefault(),o(!0))},s=()=>{a-=1,!(a>0)&&(a=0,o(!1))},c=u=>{u.dataTransfer?.types.includes("Files")&&u.preventDefault()},d=u=>{a=0,o(!1),u.dataTransfer&&(u.preventDefault(),t(u.dataTransfer.items))};return i.addEventListener("dragenter",l),i.addEventListener("dragleave",s),i.addEventListener("dragover",c),i.addEventListener("drop",d),()=>{i.removeEventListener("dragenter",l),i.removeEventListener("dragleave",s),i.removeEventListener("dragover",c),i.removeEventListener("drop",d)}},[e,t]),{visible:n}}function sl({itemCount:e,initialFocusIndex:t}){let[n,o]=A(!1),i=O(null),a=O(null),[l,s]=A(-1),c=D(()=>{o(!1),s(-1),i.current?.focus()},[]),d=D(()=>o(g=>!g),[]);R(()=>{if(!n)return;let g=f=>{let m=a.current,C=i.current;if(!m||!C)return;let v=f.composedPath();v.includes(m)||v.includes(C)||(o(!1),s(-1))};return document.addEventListener("click",g,!0),()=>document.removeEventListener("click",g,!0)},[n]),R(()=>{if(!n||e===0)return;let g=t?.()??0,f=g<0||g>=e?0:g;s(f)},[n,e,t]),R(()=>{if(!n||l<0)return;a.current?.querySelectorAll("[role='menuitem']")?.[l]?.focus()},[n,l]);let u=D(g=>{(g.key==="ArrowDown"||g.key==="Enter"||g.key===" ")&&(g.preventDefault(),o(!0))},[]),_=D(g=>{if(e!==0)switch(g.key){case"Escape":g.preventDefault(),c();return;case"ArrowDown":g.preventDefault(),s(f=>(f+1)%e);return;case"ArrowUp":g.preventDefault(),s(f=>(f-1+e)%e);return;case"Home":g.preventDefault(),s(0);return;case"End":g.preventDefault(),s(e-1)}},[e,c]);return{open:n,focusIndex:l,triggerRef:i,menuRef:a,toggle:d,close:c,onTriggerKey:u,onMenuKey:_}}function ll({items:e,triggerLabel:t}){let n=x.cssPrefix,o=sl({itemCount:e.length}),i=s=>{s.disabled||(s.onSelect?.(),s.keepOpen||o.close())},a=(s,c)=>s.onSelectValue?.(c),l=(s,c)=>{let d=c.segments;if(!d?.length)return;let u=Math.max(0,d.findIndex(g=>g.value===c.value)),_=-1;if(s.key==="ArrowRight"||s.key==="Enter"||s.key===" ")_=(u+1)%d.length;else if(s.key==="ArrowLeft")_=(u-1+d.length)%d.length;else return;s.preventDefault(),s.stopPropagation(),a(c,d[_].value)};return r("div",{class:`${n}-menu-wrap`,children:[r("button",{ref:o.triggerRef,type:"button",class:`${n}-icon-btn`,"aria-label":t,"aria-haspopup":"menu","aria-expanded":o.open,title:t,onClick:o.toggle,onKeyDown:o.onTriggerKey,children:r(Ls,{})}),o.open?r("div",{ref:o.menuRef,class:`${n}-menu`,role:"menu","aria-label":t,onKeyDown:o.onMenuKey,tabIndex:-1,children:e.map(s=>s.segments?r("div",{role:"menuitem",class:`${n}-menu-item ${n}-menu-item-segmented`,"aria-label":s.label,tabIndex:-1,onKeyDown:c=>l(c,s),children:[s.icon?r("span",{class:`${n}-menu-icon`,children:s.icon}):null,r("span",{class:`${n}-menu-label`,children:s.label}),r("span",{class:`${n}-segmented`,role:"group","aria-label":s.label,children:s.segments.map(c=>{let d=c.value===s.value;return r("button",{type:"button",role:"menuitemradio","aria-checked":d,class:`${n}-segment`,"data-on":d?"true":void 0,lang:c.lang,title:c.value,tabIndex:-1,"data-testid":`${w.langSegment}-${c.value}`,onClick:()=>a(s,c.value),children:c.label},c.value)})})]},s.id):r("button",{type:"button",role:"menuitem",class:`${n}-menu-item`,"aria-pressed":s.type==="switch"?s.on:void 0,disabled:s.disabled,onClick:()=>i(s),children:[s.icon?r("span",{class:`${n}-menu-icon`,children:s.icon}):null,r("span",{class:`${n}-menu-label`,children:s.label}),s.type==="switch"&&s.on?r("span",{class:`${n}-menu-check`,"aria-hidden":"true",children:r(dn,{})}):null]},s.id))}):null]})}var Vr=x.cssPrefix;function iu(e){let t=typeof matchMedia=="function"?matchMedia("(prefers-color-scheme: dark)").matches:!0;return e==="auto"?t?"light":"dark":t?e==="light"?"dark":"auto":e==="dark"?"light":"auto"}var au={normal:"large",large:"small",small:"normal"};function su(e){return e==="light"?r(Ws,{}):e==="dark"?r(qs,{}):r(Gs,{})}function lu(e){return(e.split("-")[0]??e).toUpperCase()}function Ye({panelProps:e,variant:t}){let{options:n,panelSize:o,feedback:i,onClose:a,onClear:l,onExpand:s,onFullscreen:c,onSoundToggle:d}=e,{onToggleHistory:u,onLocaleChange:_,onThemeChange:g,onTextSizeChange:f}=e,m=n.strings,C=n.mode,v=t==="chat",b=j(()=>i.mutedSig.value).value,y=new Set(n.actions),P=k=>y.has(k),E=typeof matchMedia=="function"&&matchMedia("(max-width: 640px)").matches,B=k=>E?!1:pn(k,C,o),le=n.themeMode,M={auto:m.themeAuto,light:m.themeLight,dark:m.themeDark},Z=n.textSize,F={small:m.textSizeSmall,normal:m.textSizeNormal,large:m.textSizeLarge},G=[];if(v&&P("clear")&&G.push({id:"clear",icon:r(Bs,{}),label:m.newConversation,onSelect:l}),P("expand")&&B("expand")){let k=o==="expanded";G.push({id:"expand",icon:k?r(Es,{}):r(Ts,{}),label:k?m.collapse:m.expand,type:"switch",on:k,onSelect:s})}if(P("fullscreen")&&B("fullscreen")){let k=o==="fullscreen";G.push({id:"fullscreen",icon:k?r(As,{}):r(Rs,{}),label:k?m.exitFullscreen:m.fullscreen,type:"switch",on:k,onSelect:c})}v&&P("sound")&&G.push({id:"sound",icon:b?r(Ns,{}):r(Ms,{}),label:b?m.soundOff:m.soundOn,type:"switch",on:!b,onSelect:d}),P("theme")&&G.push({id:"theme",icon:su(le),label:`${m.theme}: ${M[le]}`,onSelect:()=>g(iu(le)),keepOpen:!0}),P("textSize")&&G.push({id:"textSize",icon:r(Os,{}),label:`${m.textSize}: ${F[Z]}`,onSelect:()=>f(au[Z]),keepOpen:!0}),P("language")&&n.availableLocales.length>1&&G.push({id:"language",icon:r(Hs,{}),label:m.language,segments:n.availableLocales.map(k=>({value:k,label:lu(k),lang:k})),value:n.locale,onSelectValue:_});let Y=!!a&&Po(C,o,n.actions),ve=v&&P("history");return r("div",{class:`${Vr}-header-actions`,children:[ve?r("button",{type:"button",class:`${Vr}-icon-btn`,onClick:u,"aria-label":m.history,title:m.history,"data-testid":w.actionHistory,children:r($s,{})}):null,G.length>0?r(ll,{items:G,triggerLabel:m.moreActions}):null,Y?r("button",{type:"button",class:`${Vr}-icon-btn`,onClick:a,"aria-label":m.close,title:m.close,"data-testid":w.actionClose,children:r(Xe,{})}):null]})}var cu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,du=/^https?:\/\/[^\s.]+\.[^\s]+$/i,_u=/^[+]?[\d\s().-]{6,}$/;function Bt(e,t){return e.replace(/\{(\w+)\}/g,(n,o)=>String(t[o]??`{${o}}`))}function uu(e){return Array.isArray(e)?e.length:e&&e.trim()?1:0}function pu(e,t,n){let o=e.required??!0,i=e.validation;if(e.type==="multiselect"){let l=uu(t);return o&&l===0?n.formRequired:l===0?void 0:i?.minSelections!=null&&l<i.minSelections?Bt(n.formChooseAtLeast,{min:i.minSelections}):i?.maxSelections!=null&&l>i.maxSelections?Bt(n.formChooseAtMost,{max:i.maxSelections}):void 0}let a=typeof t=="string"?t.trim():"";if(!a)return o?n.formRequired:void 0;switch(e.type){case"email":if(!cu.test(a))return n.formInvalidEmail;break;case"url":if(!du.test(a))return n.formInvalidUrl;break;case"tel":if(!_u.test(a))return n.formInvalidTel;break;case"number":{let l=Number(a);if(!Number.isFinite(l))return n.formInvalidNumber;if(i?.min!=null&&l<i.min)return Bt(n.formNumberTooSmall,{min:i.min});if(i?.max!=null&&l>i.max)return Bt(n.formNumberTooLarge,{max:i.max});break}default:break}if(i?.minLength!=null&&a.length<i.minLength)return Bt(n.formTooShort,{min:i.minLength});if(i?.maxLength!=null&&a.length>i.maxLength)return Bt(n.formTooLong,{max:i.maxLength});if(i?.pattern)try{if(!new RegExp(i.pattern).test(a))return n.formPatternMismatch}catch{}}function cl(e,t,n){let o={};for(let i of e){let a=pu(i,t[i.name],n);a&&(o[i.name]=a)}return o}function dl(e){let t={};for(let[n,o]of Object.entries(e)){let i=Array.isArray(o)?o.join(", "):o;i&&i.trim()&&(t[n]=i.trim())}return t}var _e=x.cssPrefix,ko="__other__";function Co({fields:e,strings:t,submitLabel:n,onSubmit:o,skipLabel:i,onSkip:a,footerHint:l,submitOnEnter:s,disabled:c,rootTestId:d,submitTestId:u,skipTestId:_}){let[g,f]=A(()=>hu(e)),[m,C]=A({}),[v,b]=A({}),y=M=>{v[M]&&b(Z=>({...Z,[M]:""}))},P=(M,Z)=>{f(F=>({...F,[M]:Z})),y(M)},E=(M,Z)=>{C(F=>({...F,[M]:Z})),y(M)},B=M=>{if(M.preventDefault(),c)return;let Z=vu(e,g,m),F=cl(e,Z,t);if(Object.keys(F).length>0){b(F);return}o(dl(Z))},le=M=>{!s||M.key!=="Enter"||M.shiftKey||M.isComposing||M.target?.tagName==="TEXTAREA"&&B(M)};return r("form",{class:`${_e}-form`,onSubmit:B,onKeyDown:le,"data-testid":d,noValidate:!0,children:[e.map(M=>r(mu,{field:M,value:g[M.name],otherText:m[M.name]??"",error:v[M.name],disabled:c,strings:t,onChange:Z=>P(M.name,Z),onOtherChange:Z=>E(M.name,Z)},M.name)),r("div",{class:`${_e}-form-actions`,children:[l?r("span",{class:`${_e}-form-hint`,children:l}):null,i&&a?r("button",{type:"button",class:`${_e}-form-skip`,onClick:a,disabled:c,"data-testid":_,children:i}):null,r("button",{type:"submit",class:`${_e}-form-submit`,disabled:c,"data-testid":u,children:n})]})]})}function mu({field:e,value:t,otherText:n,error:o,disabled:i,strings:a,onChange:l,onOtherChange:s}){let c=xe(w.formField,e.name),d=fu({field:e,value:t,otherText:n,disabled:i,strings:a,onChange:l,onOtherChange:s,fieldTid:c});return r("label",{class:`${_e}-field`,"data-field":e.name,"data-invalid":o?"true":void 0,children:[r("span",{class:`${_e}-field-label`,children:[e.label,e.required??!0?r("span",{class:`${_e}-field-req`,"aria-hidden":"true",children:" *"}):null]}),d,e.validationHint&&!o?r("span",{class:`${_e}-field-hint`,children:e.validationHint}):null,o?r("span",{class:`${_e}-field-error`,role:"alert",children:o}):null]})}function fu(e){let{field:t,value:n,otherText:o,disabled:i,strings:a,onChange:l,onOtherChange:s,fieldTid:c}=e,d=typeof n=="string"?n:"";switch(t.type){case"textarea":return r("textarea",{class:`${_e}-field-input`,rows:3,value:d,placeholder:t.placeholder,disabled:i,onInput:u=>l(u.target.value),"data-testid":c});case"select":return r("select",{class:`${_e}-field-input`,value:d,disabled:i,onChange:u=>l(u.target.value),"data-testid":c,children:[r("option",{value:"",children:t.placeholder??"\u2014"}),(t.options??[]).map(u=>r("option",{value:u.value,children:u.label??u.value},u.value))]});case"radio":{let u=t.allowOther&&d===ko;return r("div",{class:`${_e}-field-choices`,role:"radiogroup","data-testid":c,children:[(t.options??[]).map(_=>r("label",{class:`${_e}-choice`,children:[r("input",{type:"radio",name:`${_e}-${t.name}`,checked:d===_.value,disabled:i,onChange:()=>l(_.value)}),r("span",{children:_.label??_.value})]},_.value)),t.allowOther?r("label",{class:`${_e}-choice`,children:[r("input",{type:"radio",name:`${_e}-${t.name}`,checked:d===ko,disabled:i,onChange:()=>l(ko)}),r("span",{children:a.formOther})]}):null,u?r("input",{class:`${_e}-field-input`,value:o,placeholder:t.placeholder??a.formOtherPlaceholder,disabled:i,onInput:_=>s(_.target.value)}):null]})}case"checkbox":return r("label",{class:`${_e}-choice`,children:[r("input",{type:"checkbox",checked:d==="true",disabled:i,onChange:u=>l(u.target.checked?"true":""),"data-testid":c}),r("span",{children:t.placeholder??t.label})]});case"multiselect":{let u=Array.isArray(n)?n:[],_=(g,f)=>l(f?[...u,g]:u.filter(m=>m!==g));return r("div",{class:`${_e}-field-choices`,"data-testid":c,children:[(t.options??[]).map(g=>r("label",{class:`${_e}-choice`,children:[r("input",{type:"checkbox",checked:u.includes(g.value),disabled:i,onChange:f=>_(g.value,f.target.checked)}),r("span",{children:g.label??g.value})]},g.value)),t.allowOther||(t.options??[]).length===0?r("textarea",{class:`${_e}-field-input`,rows:2,value:o,placeholder:t.placeholder??a.formOtherPlaceholder,disabled:i,onInput:g=>s(g.target.value)}):null]})}default:return r("input",{class:`${_e}-field-input`,type:gu(t.type),value:d,placeholder:t.placeholder,disabled:i,onInput:u=>l(u.target.value),"data-testid":c})}}function gu(e){switch(e){case"number":case"email":case"tel":case"url":case"date":case"time":return e;default:return"text"}}function hu(e){let t={};for(let n of e)n.defaultValue!=null&&(t[n.name]=n.type==="multiselect"?n.defaultValue.split(",").map(o=>o.trim()).filter(Boolean):n.defaultValue);return t}function vu(e,t,n){let o={...t};for(let i of e){let a=n[i.name]?.trim();if(i.type==="radio"&&i.allowOther&&t[i.name]===ko)o[i.name]=a??"";else if(i.type==="multiselect"&&a){let l=a.split(/[,\n;]+/).map(c=>c.trim()).filter(Boolean),s=Array.isArray(t[i.name])?t[i.name]:[];o[i.name]=[...s,...l]}}return o}var Je=x.cssPrefix;function Wr({form:e,strings:t,onSubmit:n,onSkip:o}){return r("div",{class:`${Je}-form-gate`,"data-testid":w.formGate,children:[e.title?r("h3",{class:`${Je}-form-gate-title`,children:e.title}):null,e.description?r("p",{class:`${Je}-form-gate-desc`,children:e.description}):null,r(Co,{fields:e.fields,strings:t,submitLabel:e.submitLabel??t.formSubmit,onSubmit:n,skipLabel:e.skippable?t.formSkip:void 0,onSkip:e.skippable?o:void 0,submitTestId:w.formSubmit,skipTestId:w.formSkip})]})}function _l({marker:e,strings:t,onFill:n}){let o=e.outcome==="skipped",i=o?t.formSkipped:t.formSubmitted,a=e.title?r(ee,{children:[r("span",{children:e.title}),r("span",{class:`${Je}-sr-only`,children:i})]}):r("span",{children:i}),l=e.form?.reviewable??!1,s=!o&&l&&e.values&&Object.keys(e.values).length>0?e.values:null;if(s){let c=d=>e.form?.fields.find(u=>u.name===d)?.label??d;return r("details",{class:`${Je}-form-done`,"data-outcome":e.outcome,"data-testid":w.formDone,children:[r("summary",{class:`${Je}-form-done-summary`,"data-testid":w.formDoneToggle,children:[r(dn,{}),a,r($t,{})]}),r("dl",{class:`${Je}-form-answers`,"data-testid":w.formAnswers,children:Object.entries(s).map(([d,u])=>r("div",{class:`${Je}-form-answer`,children:[r("dt",{children:c(d)}),r("dd",{children:u})]},d))})]})}return r("div",{class:`${Je}-form-done`,"data-outcome":e.outcome,"data-testid":w.formDone,role:"status",children:[o?r(Ds,{}):r(dn,{}),a,o&&e.form?.reopenable&&n?r("button",{type:"button",class:`${Je}-form-done-fill`,"data-testid":w.formFill,onClick:n,children:t.formFillOut}):null]})}function ul(e){if(!e)return!1;let t=e.startsWith("tool:")?e.slice(5):e;return t==="ask-user-input"||t==="ask_user_input"||t==="request-user-input"||t==="request_user_input"}var Kr=1,ml=2,fl=4,gl=8,hl=16;function bu(e){switch(e){case Kr:return"href";case ml:return"src";case fl:return"class";case gl:return"checked";case hl:return"start"}}var Pu=e=>{switch(e){case 1:return 3;case 2:return 4;case 3:return 5;case 4:return 6;case 5:return 7;default:return 8}},xu=Pu;var pl=24;function Xr(e){let t=new Uint32Array(pl);return t[0]=1,{renderer:e,text:"",pending:"",tokens:t,len:0,token:1,fence_end:0,blockquote_idx:0,hr_char:"",hr_chars:0,fence_start:0,spaces:new Uint8Array(pl),indent:"",indent_len:0,table_state:0}}function vl(e){e.pending.length>0&&Ce(e,`
11
+ ${i}`:i;continue}o.startsWith("id:")&&(n=o.slice(3).trim())}if(!t||t==="[DONE]")return null;try{let o=JSON.parse(t);return Ja.trace("chunk",{type:o.type,eventId:n}),{chunk:o,eventId:n}}catch(o){return Ja.trace("frame parse failed",{err:o,payload:t.slice(0,200)}),null}}function a_(e){let t=new TextEncoder().encode(e),n="";for(let o of t)n+=String.fromCharCode(o);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var Za=e=>e&&Object.keys(e).length>0?e:void 0;function es(e,t){let n=Za(e),o=Za(t);if(!n&&!o)return;let i={};return n&&(i.user=n),o&&(i.page=o),a_(JSON.stringify(i))}function so(e){if(!e)return;let t=Date.parse(e);return Number.isFinite(t)?t:void 0}function s_(e){return`tool-${e.startsWith("tool:")?e.slice(5):e}`}function ts(e){return e.startsWith("tool-")?e.slice(5):e}var We={handshake:"/pai/handshake",streamMessage:"/pai/stream-message",streamResume:"/pai/stream-resume",cancelStream:"/pai/cancel-stream",listConversations:"/pai/list-conversations",listMessages:"/pai/list-messages",updateSettings:"/pai/update-settings",markRead:"/pai/mark-read",bootstrap:"/pai/bootstrap",content:"/pai/content",submitForm:"/pai/submit-form"},ns="context";function os(e){let t=e.messages.map(a=>({id:a.serverMessageId??a.id,parts:d_(a),role:a.role,createdAt:a.createdAt!==void 0?new Date(a.createdAt).toISOString():void 0})),n={messages:t,conversationId:e.conversationId,trigger:e.trigger??"submit-message"},o=t.at(-1)?.id;o&&(n.messageId=o),e.visitorId&&(n.visitorId=e.visitorId),e.userPrefs&&(n.userPrefs=e.userPrefs);let i=e.tools?.map(c_).filter(a=>a!==null);return i?.length&&(n.data={tools:i}),n}function l_(e){return e.state==="output-available"||e.state==="output-error"||e.state==="output-denied"||e.approval?.approved!==void 0}function c_(e){return typeof e=="string"?e?{code:e}:null:e?.code?e:null}function d_(e){let t=[];for(let n of e.parts)if(n.kind==="step-start"&&t.push({type:"step-start"}),n.kind==="reasoning"&&n.text&&t.push({type:"reasoning",text:n.text,state:n.done?"done":"streaming"}),n.kind==="text"&&n.text&&t.push({text:n.text,type:"text"}),n.kind==="file"&&n.url&&t.push({mediaType:n.mediaType,type:"file",url:n.url}),n.kind==="tool"&&l_(n)){let o={type:s_(n.toolName),toolCallId:n.toolCallId,state:n.state};n.input!==void 0&&(o.input=n.input),n.output!==void 0&&(o.output=n.output),n.error!==void 0&&(o.errorText=n.error),n.approval&&n.approval.approved!==void 0&&(o.approval=n.approval),t.push(o)}for(let n of e.attachments??[])n.url&&t.push({type:"file",url:n.url,mediaType:n.mediaType,filename:n.name,fileId:n.id,fileSize:n.size});return t}var Q=X.scope("transport"),rs=3,ls=400,__=6e4,is=1e4,as=3,u_=new Set([408,425,429,500,502,503,504]);function ss(e){return ls*2**e+Math.floor(Math.random()*250)}function p_(e){let t=e.get("retry-after");if(!t)return null;let n=Number(t),o=Number.isFinite(n)?n*1e3:Date.parse(t)-Date.now();return Number.isFinite(o)&&o>=0?Math.min(o,3e4):null}function Mr(e,t){return new Promise(n=>{if(t?.aborted)return n();let o=setTimeout(a,e),i=()=>a();t?.addEventListener("abort",i,{once:!0});function a(){clearTimeout(o),t?.removeEventListener("abort",i),n()}})}var lo=class{constructor(t){V(this,"opts",t);V(this,"visitorId");V(this,"conversationId");V(this,"resumeStatus");V(this,"userContext");V(this,"pageContext");V(this,"locale");V(this,"conversationsCache",new Map);V(this,"contentCache",new Map)}setContext(t,n){this.userContext=t,this.pageContext=n}setLocale(t){this.locale=t}primeIdentity(t,n){t&&(this.visitorId=t),n&&(this.conversationId=n)}envelope(){let t={_ev:ao};this.visitorId&&(t.visitorId=this.visitorId),this.conversationId&&(t.conversationId=this.conversationId),this.locale&&(t.locale=this.locale);let n=es(this.userContext,this.pageContext);return n&&(t[ns]=n),t}withEnvelope(t){return{...this.envelope(),...t}}appendEnvelope(t){for(let[n,o]of Object.entries(this.envelope()))t.append(n,o);return t}withEnvelopeQuery(t){let n=new URL(this.url(t));for(let[o,i]of Object.entries(this.envelope()))n.searchParams.has(o)||n.searchParams.set(o,i);return n.toString()}async handshake(t){Q.debug("handshake \u2192",{visitorId:t.visitorId,conversationId:t.conversationId,locale:t.locale});let n=await this.postJson(We.handshake,t,"handshake");return Q.debug("handshake \u2190",{visitorId:n.visitorId,conversationId:n.conversationId,hasWelcome:!!n.welcome,hasConfig:!!n.config,rebind:n.rebind}),f_(n)||Q.warn("handshake response did not match expected shape; using raw response",{response:n}),this.visitorId=n.visitorId??t.visitorId,this.conversationId=n.conversationId,n}async uploadFile(t){Q.debug("uploadFile \u2192",{name:t.name,size:t.size,type:t.type});let n=new FormData;n.append("file",t,t.name);let o=await this.postForm(this.uploadPath,n,"upload");return Q.debug("uploadFile \u2190",{id:o.id,url:o.url}),o}async transcribe(t,n="audio/webm"){Q.debug("transcribe \u2192",{size:t.size,mimeType:n});let o=new FormData;o.append("audio",t,`voice.${m_(n)}`),o.append("mimeType",n);let i=await this.postForm(this.transcribePath,o,"transcribe");return Q.debug("transcribe \u2190",{textLen:i.text.length}),i}conversationsKey(t){return`${this.locale??""}|${JSON.stringify(t,Object.keys(t).toSorted())}`}peekConversations(t={}){let n=this.conversationsCache.get(this.conversationsKey(t));if(n?.value&&Date.now()-n.at<is)return n.value}listConversations(t={}){let n=this.conversationsKey(t),o=this.conversationsCache.get(n);if(o&&Date.now()-o.at<is)return Q.debug("listConversations \u2192 cache",t),o.result;let i={at:Date.now(),result:this.fetchConversations(t).then(a=>(i.value=a,a)).catch(a=>{throw this.conversationsCache.delete(n),a})};return this.conversationsCache.set(n,i),i.result}async fetchConversations(t){let n=new URL(this.url(We.listConversations));t.visitorId&&n.searchParams.set("visitorId",t.visitorId),t.limit&&n.searchParams.set("limit",String(t.limit)),t.cursor&&n.searchParams.set("cursor",t.cursor),Q.debug("listConversations \u2192",{visitorId:t.visitorId??this.visitorId,limit:t.limit,cursor:t.cursor});let o=await this.getJson(n.toString(),"listConversations"),i=o.conversations??[];return Q.debug("listConversations \u2190",{count:i.length,nextCursor:o.nextCursor}),{conversations:i.map(a=>({conversationId:a.conversationId,title:a.title,lastMessageAt:a.lastMessageAt,preview:a.preview,canContinue:a.canContinue,unreadCount:a.unreadCount})),nextCursor:o.nextCursor}}async loadConversation(t){let n=new URL(this.url(We.listMessages));n.searchParams.set("conversationId",t),Q.debug("loadConversation \u2192",{conversationId:t,visitorId:this.visitorId});let o=await this.getJson(n.toString(),"loadConversation"),i=o.messages??[];return Q.debug("loadConversation \u2190",{conversationId:o.conversationId,canContinue:o.canContinue,messageCount:i.length,hasSuggestions:!!o.suggestions}),{conversationId:o.conversationId,canContinue:o.canContinue??!0,messages:i,agent:o.agent,suggestions:o.suggestions}}async markRead(t){if(!(!this.visitorId||!t)){this.conversationsCache.clear(),Q.debug("markRead \u2192",{conversationId:t,visitorId:this.visitorId});try{await this.postJson(We.markRead,{conversationId:t},"markRead")}catch(n){Q.debug("markRead failed (non-fatal)",{err:n})}}}listContent(t={}){let n=`${this.locale??""}|${JSON.stringify(t,Object.keys(t).toSorted())}`,o=this.contentCache.get(n);if(o&&Date.now()-o.at<__)return Q.debug("listContent \u2192 cache",t),o.result;let i=this.fetchContent(t).catch(a=>{throw this.contentCache.delete(n),a});return this.contentCache.set(n,{at:Date.now(),result:i}),i}async fetchContent(t){let n=new URL(this.dataUrl(We.content));for(let[a,l]of Object.entries(t))l!==void 0&&n.searchParams.set(a,Array.isArray(l)?l.join(","):String(l));Q.debug("listContent \u2192",t);let o=await this.getJson(n.toString(),"listContent"),i=(o.items??[]).map(a=>Vi(a,this.locale));return Q.debug("listContent \u2190",{count:i.length,total:o.pagination?.total}),{...o,items:i}}async bootstrap(t){let n=new URL(this.dataUrl(We.bootstrap));t&&n.searchParams.set("conversationId",t),Q.debug("bootstrap \u2192",{conversationId:t??this.conversationId});let o=await this.getJson(n.toString(),"bootstrap"),i=o.forms??[],a=o.formSubmissions??[];return Q.debug("bootstrap \u2190",{forms:i.length,formSubmissions:a.length}),{forms:i,formSubmissions:a}}async saveUserPrefs(t){Q.debug("saveUserPrefs \u2192",{visitorId:this.visitorId,conversationId:this.conversationId,settingsKeys:Object.keys(t)});let n=await this.postJson(We.updateSettings,{userPrefs:t},"saveUserPrefs");return Q.debug("saveUserPrefs \u2190",{ok:n.ok}),n}get uploadPath(){return this.opts.endpoints?.upload??"/pai/upload-file"}get transcribePath(){return this.opts.endpoints?.transcribe??"/pai/transcribe-audio"}get submitFormPath(){return this.opts.endpoints?.submitForm??We.submitForm}async submitForm(t){Q.debug("submitForm \u2192",{formId:t.formId,trigger:t.trigger,fields:Object.keys(t.values).length});try{await this.postJson(this.dataUrl(this.submitFormPath),t,"submitForm")}catch(n){Q.debug("submitForm failed (non-fatal)",{err:n})}}sendMessage(t){this.conversationsCache.clear(),Q.debug("message \u2192",{conversationId:t.conversationId,visitorId:t.visitorId,messageId:t.messageId,messageCount:t.messages.length,trigger:t.trigger,tools:t.data?.tools?.map(l=>l.code)});let n=new AbortController,o=new Set;return{iter:this.runStream(t,n,o),cancel:()=>this.cancelStream(n,t.conversationId),detach:()=>n.abort()}}resumeStream(){let t=new AbortController,n=new Set;this.resumeStatus=void 0;let o=this.resumeStreamGen(t,n,!0),i=()=>t.abort();return{iter:o,cancel:i,detach:i}}async*runStream(t,n,o){(yield*this.drain(this.openMessageStream(t,n.signal),o,n))||(yield*this.resumeStreamGen(n,o,!1))}async*resumeStreamGen(t,n,o){for(let i=1;i<=rs&&!t.signal.aborted;i++){if((!o||i>1)&&(await Mr(ls*i,t.signal),t.signal.aborted))return;let a;try{a=await this.fetchImpl(this.resumeUrl(n.size),{method:"GET",credentials:"omit",headers:{accept:"text/event-stream",...this.opts.auth.headers()},signal:t.signal})}catch(c){if(t.signal.aborted)return;Q.debug("resume fetch failed \u2014 retrying",{attempt:i,err:c});continue}if(a.status===204||!a.ok){Q.debug("resume \u2192 no in-flight stream",{status:a.status});return}if(!(a.headers.get("content-type")??"").includes("text/event-stream")){let c=await a.json().then(d=>d.status).catch(()=>{});if(Q.debug("resume \u2192 no live stream (status response)",{status:c,attempt:i}),c==="pending"&&i<rs)continue;this.resumeStatus=c==="needs-generation"?"needs-generation":"completed";return}this.resumeStatus="live";let s=n.size;if(yield*this.drain(Lr(a,t.signal),n,t))return;if(n.size===s){Q.debug("resume \u2192 stream closed with no new events; nothing to resume");return}}if(!t.signal.aborted)throw new Ve("stream incomplete after resume attempts","server")}async*drain(t,n,o){try{for await(let i of t){if(o.signal.aborted)return!0;if(i.eventId){if(n.has(i.eventId))continue;n.add(i.eventId)}if(yield i,i.chunk.type==="finish"||i.chunk.type==="error")return!0}}catch(i){if(o.signal.aborted)return!0;if(i instanceof Ve&&i.status!==void 0)throw i;Q.debug("stream segment dropped",{err:i})}return!1}cancelStream(t,n){t.signal.aborted||(Q.debug("cancel stream",{conversationId:n,visitorId:this.visitorId}),t.abort(),!(!this.visitorId||!n)&&this.fetchImpl(this.url(We.cancelStream),{method:"POST",credentials:"omit",headers:{"content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope({})),keepalive:!0}).catch(o=>Q.debug("cancel POST failed (non-fatal)",{err:o})))}async*openMessageStream(t,n){let o=await this.fetchImpl(this.url(We.streamMessage),{method:"POST",credentials:"omit",headers:{accept:"text/event-stream","content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope(t)),signal:n});yield*Lr(o,n)}resumeUrl(t){let n=new URL(this.withEnvelopeQuery(We.streamResume));return n.searchParams.set("resumeAt",String(t)),n.toString()}async postJson(t,n,o){let i=await this.fetchWithRetry(()=>[this.url(t),{method:"POST",credentials:"omit",headers:{"content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope(n))}],o);return this.assertOk(i,o)}async postForm(t,n,o){let i=await this.fetchImpl(this.url(t),{method:"POST",credentials:"omit",headers:this.opts.auth.headers(),body:this.appendEnvelope(n)});return this.assertOk(i,o)}async getJson(t,n){let o=await this.fetchWithRetry(()=>[this.withEnvelopeQuery(t),{method:"GET",credentials:"omit",headers:{accept:"application/json",...this.opts.auth.headers()}}],n);return this.assertOk(o,n)}async fetchWithRetry(t,n){for(let o=0;;o++){let[i,a]=t(),l;try{l=await this.fetchImpl(i,a)}catch(c){if(o>=as)throw new Ve(`${n} failed: network error`,"network",void 0,c);Q.debug("request network error \u2014 retrying",{label:n,attempt:o}),await Mr(ss(o));continue}if(l.ok||!u_.has(l.status)||o>=as)return l;let s=p_(l.headers)??ss(o);Q.debug("request retryable status \u2014 retrying",{label:n,status:l.status,attempt:o,wait:s}),await Mr(s)}}async assertOk(t,n){if(!t.ok)throw new Ve(`${n} failed: ${t.status}`,"server",t.status);return await t.json()}url(t){return/^https?:\/\//i.test(t)?t:`${this.opts.agentApiBaseUrl}${t}`}dataUrl(t){return/^https?:\/\//i.test(t)?t:`${this.opts.dataApiBaseUrl}${t}`}get fetchImpl(){return this.opts.fetchImpl??globalThis.fetch.bind(globalThis)}};function m_(e){return e.includes("webm")?"webm":e.includes("ogg")?"ogg":e.includes("mp4")||e.includes("m4a")?"m4a":e.includes("mpeg")?"mp3":e.includes("wav")?"wav":"bin"}function f_(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.visitorId=="string"&&typeof t.conversationId=="string"}function cs(e,t){let n=e?[{kind:"text",id:"t0",textSig:H(e),doneSig:H(!0)}]:[];return{id:Ue(),role:"user",createdAt:Date.now(),status:"complete",attachments:t,partsSig:H(n)}}function sn(){return{id:Ue(),role:"assistant",createdAt:Date.now(),status:"streaming",partsSig:H([])}}function ds(e){let t=Ue();return g_({id:t,role:e.role,createdAt:Date.now(),status:"complete",ephemeral:!0,parts:[{kind:"text",id:`${t}-t0`,text:e.text,done:!0}]})}function g_(e){return{id:e.id,role:e.role,createdAt:e.createdAt,status:e.status,canceled:e.canceled,errorText:e.errorText,finishReason:e.finishReason,serverMessageId:e.serverMessageId,ephemeral:e.ephemeral,attachments:e.attachments,partsSig:H(e.parts.map(x_))}}function h_(e){let t=e.parts.map((n,o)=>n.type==="text"?{kind:"text",id:`${e.id}-t${o}`,textSig:H(n.text),doneSig:H(!0)}:n.type==="reasoning"?{kind:"reasoning",id:`${e.id}-r${o}`,textSig:H(n.text),doneSig:H(n.state!=="streaming")}:n.type==="step-start"?{kind:"step-start",id:`${e.id}-ss${o}`}:n.type==="file"?{kind:"file",url:n.url,mediaType:n.mediaType}:n.type==="source-url"?{kind:"source",sourceId:n.sourceId,url:n.url,title:n.title}:n.type==="source-document"?{kind:"source",sourceId:n.sourceId,title:n.title,filename:n.filename,mediaType:n.mediaType}:n.type.startsWith("tool-")?{kind:"tool",toolCallId:n.toolCallId,toolName:ts(n.type),inputPartialSig:H(""),inputSig:H(n.input),outputSig:H(n.output),errorSig:H(n.errorText),stateSig:H(n.state),approvalSig:H(n.approval)}:null).filter(n=>n!==null);return{id:e.id,role:e.role,serverMessageId:e.id,createdAt:so(e.createdAt)??Date.now(),status:e.status==="failed"?"error":"complete",canceled:e.status==="canceled",partsSig:H(t)}}var v_=new Set(["completed","failed","canceled"]);function b_(e){return!e.parts.some(t=>t.type==="text"&&t.text.trim()!==""||t.type.startsWith("tool-")||t.type==="file"||t.type==="source-url"||t.type==="source-document")}function P_(e){return e.role==="assistant"&&e.status!=null&&!v_.has(e.status)&&b_(e)}function Or(e){return e.filter(t=>!P_(t)).map(h_)}function _s(e){return{id:e.id,role:e.role,createdAt:e.createdAt,status:e.status,canceled:e.canceled,errorText:e.errorText,finishReason:e.finishReason,serverMessageId:e.serverMessageId,ephemeral:e.ephemeral,attachments:e.attachments,parts:e.partsSig.value.map(y_)}}function co(e){let t="";for(let n of e.partsSig.value)n.kind==="text"&&(t+=n.textSig.value);return t}function _o(e){return co(e).trim()!==""?!1:!e.partsSig.value.some(t=>t.kind==="tool"||t.kind==="file"||t.kind==="source")}function ot(e){return e.role==="assistant"&&e.status!=="streaming"&&_o(e)}function us(e){return e.canceled===!0&&ot(e)}function x_(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,textSig:H(e.text),doneSig:H(e.done)}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartialSig:H(e.inputPartial),inputSig:H(e.input),outputSig:H(e.output),errorSig:H(e.error),stateSig:H(e.state),approvalSig:H(e.approval)}:e}function y_(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,text:e.textSig.value,done:e.doneSig.value}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartial:e.inputPartialSig.value,input:e.inputSig.value,output:e.outputSig.value,error:e.errorSig.value,state:e.stateSig.value,approval:e.approvalSig.value}:e}var ps=X.scope("reducer"),uo=class{constructor(t){V(this,"messagesSig",t);V(this,"active",null);V(this,"openTextParts",new Map);V(this,"partSeq",0)}attach(t){this.active=t,this.openTextParts.clear()}detach(){this.active=null,this.openTextParts.clear()}ensureTextPart(t,n,o){let i=`${n}:${o}`,a=this.openTextParts.get(i);if(a)return a;let l={kind:n,id:`${o}#${this.partSeq++}`,textSig:H(""),doneSig:H(!1)};return this.openTextParts.set(i,l),ln(t,l),l}apply(t){let n=this.active;if(n)switch(t.type){case"start":t.messageId&&(n.serverMessageId=t.messageId);return;case"finish-step":this.openTextParts.clear();return;case"start-step":ln(n,{kind:"step-start",id:`ss-${this.partSeq++}`});return;case"finish":ps.debug("finish",{reason:t.finishReason,canContinue:t.canContinue}),n.status="complete",t.finishReason&&(n.finishReason=t.finishReason),this.bumpDone(n);return;case"error":ps.warn("stream error chunk",{errorText:t.errorText}),n.status="error",n.errorText=t.errorText,this.bumpDone(n);return;case"text-start":this.ensureTextPart(n,"text",t.id);return;case"text-delta":{let o=this.ensureTextPart(n,"text",t.id);o.textSig.value+=t.delta;return}case"text-end":this.ensureTextPart(n,"text",t.id).doneSig.value=!0;return;case"reasoning-start":this.ensureTextPart(n,"reasoning",t.id).doneSig.value=!1;return;case"reasoning-delta":{let o=this.ensureTextPart(n,"reasoning",t.id);o.textSig.value+=t.delta;return}case"reasoning-end":this.ensureTextPart(n,"reasoning",t.id).doneSig.value=!0;return;case"tool-input-start":case"tool-input-delta":case"tool-input-available":case"tool-output-available":case"tool-output-error":case"tool-output-denied":case"tool-approval-request":S_(n,t);return;case"file":ln(n,{kind:"file",url:t.url,mediaType:t.mediaType});return;case"source-url":ms(n,{kind:"source",sourceId:t.sourceId,url:t.url,title:t.title});return;case"source-document":ms(n,{kind:"source",sourceId:t.sourceId,title:t.title,filename:t.filename,mediaType:t.mediaType});return;case"data-notification":return;case"data-conversation-rebind":return;default:{let o=t}}}bumpDone(t){t.partsSig.value=[...t.partsSig.value],this.messagesSig.value=[...this.messagesSig.value]}};function bt(e,t,n){let o=e.partsSig.value.find(a=>a.kind==="tool"&&a.toolCallId===t);if(o)return o;let i={kind:"tool",toolCallId:t,toolName:n??"tool",inputPartialSig:H(""),inputSig:H(void 0),outputSig:H(void 0),errorSig:H(void 0),stateSig:H("input-streaming"),approvalSig:H(void 0)};return ln(e,i),i}function ln(e,t){e.partsSig.value=[...e.partsSig.value,t]}function ms(e,t){e.partsSig.value.some(n=>n.kind==="source"&&n.sourceId===t.sourceId)||ln(e,t)}function S_(e,t){switch(t.type){case"tool-input-start":bt(e,t.toolCallId,t.toolName);return;case"tool-input-delta":{let n=bt(e,t.toolCallId);n.inputPartialSig.value+=t.inputTextDelta;return}case"tool-input-available":{let n=bt(e,t.toolCallId,t.toolName);n.inputSig.value=t.input,n.stateSig.value="input-available";return}case"tool-approval-request":{let n=bt(e,t.toolCallId,t.toolName);n.approvalSig.value={id:t.approvalId},n.stateSig.value="approval-requested";return}case"tool-output-available":{let n=bt(e,t.toolCallId);n.outputSig.value=t.output,n.stateSig.value="output-available";return}case"tool-output-error":{let n=bt(e,t.toolCallId);n.errorSig.value=t.errorText,n.stateSig.value="output-error";return}case"tool-output-denied":{let n=bt(e,t.toolCallId);n.stateSig.value="output-denied";return}default:return}}var fs=X.scope("feedback:audio"),po=class{constructor(){V(this,"ctx",null);V(this,"master",null);V(this,"buffers",new Map)}unlock(){if(this.ctx){this.ctx.state==="suspended"&&this.ctx.resume();return}let t=globalThis.AudioContext??globalThis.webkitAudioContext;if(t)try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.gain.value=1,this.master.connect(this.ctx.destination)}catch(n){fs.warn("AudioContext init failed",{err:n})}}setVolume(t){if(!this.master||!this.ctx)return;let n=Math.max(0,Math.min(1,t));this.master.gain.setTargetAtTime(n,this.ctx.currentTime,.01)}playTone(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let i=n.currentTime,a=t.noteMs/1e3;t.notes.forEach((l,s)=>{let c=n.createOscillator();c.type=t.type,c.frequency.value=l;let d=n.createGain(),u=i+s*a;d.gain.setValueAtTime(1e-4,u),d.gain.exponentialRampToValueAtTime(t.peakGain,u+.005),d.gain.exponentialRampToValueAtTime(1e-4,u+a),c.connect(d).connect(o),c.start(u),c.stop(u+a+.01)})}async playUrl(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let i=await this.getBuffer(t);if(!i)return;let a=n.createBufferSource();a.buffer=i,a.connect(o),a.start()}destroy(){this.ctx&&this.ctx.close().catch(()=>{}),this.ctx=null,this.master=null,this.buffers.clear()}async getBuffer(t){if(!this.ctx)return null;let n=this.buffers.get(t);if(n)return n instanceof Promise,n;let o=this.ctx,i=fetch(t).then(a=>a.ok?a.arrayBuffer():Promise.reject(new Error(`fetch ${a.status}`))).then(a=>o.decodeAudioData(a)).then(a=>(this.buffers.set(t,a),a)).catch(a=>(fs.warn("audio fetch/decode failed",{url:t,err:a}),this.buffers.delete(t),null));return this.buffers.set(t,i),i}};var gs={messageReceived:10,messageSent:0,error:[20,40,20],voiceStart:10,voiceStop:0},hs={messageReceived:{notes:[880,1318.51],noteMs:90,type:"sine",peakGain:.45},messageSent:{notes:[1568],noteMs:60,type:"sine",peakGain:.25},error:{notes:[523.25,392],noteMs:120,type:"triangle",peakGain:.55},voiceStart:{notes:[1318.51],noteMs:50,type:"sine",peakGain:.3},voiceStop:{notes:[880],noteMs:50,type:"sine",peakGain:.3}};var ct=null,mo=0;function w_(){return typeof navigator<"u"&&typeof navigator.vibrate=="function"}function k_(){if(typeof document>"u")return null;let e=document.createElement("input");e.type="checkbox",e.setAttribute("switch",""),e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.id=`__${x.cssPrefix}_haptic_${Math.random().toString(36).slice(2)}`;let t=document.createElement("label");t.htmlFor=e.id,t.setAttribute("aria-hidden","true");let n="position:absolute!important;width:1px!important;height:1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;opacity:0!important;pointer-events:none!important;";return e.style.cssText=n,t.style.cssText=n,document.body.append(e,t),{input:e,label:t}}function vs(e){if(!(e===0||Array.isArray(e)&&e.every(t=>t===0))){if(w_())try{navigator.vibrate(e);return}catch{}if(ct||(ct=k_()),!!ct)try{ct.label.click()}catch{}}}function bs(){mo++;let e=!1;return()=>{e||(e=!0,mo=Math.max(0,mo-1),mo===0&&ct&&(ct.input.remove(),ct.label.remove(),ct=null))}}var C_=X.scope("feedback"),T_=100,fo=class{constructor(t,n){V(this,"mutedSig",H(!1));V(this,"audio",new po);V(this,"releaseHaptics");V(this,"sound");V(this,"haptics");V(this,"lastPlayed",new Map);V(this,"reducedMotionMq",null);this.sound=t,this.haptics=n,this.releaseHaptics=bs(),this.audio.setVolume(this.effectiveVolume()),typeof matchMedia<"u"&&(this.reducedMotionMq=matchMedia("(prefers-reduced-motion: reduce)"))}unlock(){this.audio.unlock(),this.audio.setVolume(this.effectiveVolume())}update(t,n){this.sound=t,this.haptics=n,this.audio.setVolume(this.effectiveVolume())}setMuted(t){this.mutedSig.value!==t&&(this.mutedSig.value=t)}toggleMuted(){this.mutedSig.value=!this.mutedSig.value}play(t){this.mutedSig.value||this.isDeduped(t)||(this.lastPlayed.set(t,performance.now()),this.sound.enabled&&this.playSound(t),this.haptics.enabled&&this.isTouchDevice()&&this.playHaptic(t))}destroy(){this.audio.destroy(),this.releaseHaptics()}isDeduped(t){let n=this.lastPlayed.get(t);return n===void 0?!1:performance.now()-n<T_}playSound(t){let n=this.sound.events?.[t];if(n===!1)return;if(typeof n=="string"){this.audio.playUrl(n).catch(i=>C_.warn("audio play failed",{err:i,url:n}));return}let o=hs[t];o&&this.audio.playTone(o)}playHaptic(t){if(this.reducedMotionMq?.matches)return;let n=this.haptics.events?.[t];if(n===!1)return;let o=n===!0||n===void 0?gs[t]:n;vs(o)}effectiveVolume(){let t=this.sound.volume??.3;return this.reducedMotionMq?.matches?t*.5:t}isTouchDevice(){return typeof window>"u"?!1:matchMedia("(hover: none) and (pointer: coarse)").matches}};function Pt(e,t){return e instanceof Ve&&e.status===429?t.errorRateLimited:t.errorGeneric}var E_=0;function r(e,t,n,o,i,a){t||(t={});var l,s,c=t;if("ref"in c)for(s in c={},t)s=="ref"?l=t[s]:c[s]=t[s];var d={type:e,props:c,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--E_,__i:-1,__u:0,__source:i,__self:a};if(typeof e=="function"&&(l=e.defaultProps))for(s in l)c[s]===void 0&&(c[s]=l[s]);return J.vnode&&J.vnode(d),d}var $={fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24"},cn=`${x.cssPrefix}-icon-dir`,R_=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M21 12a8 8 0 0 1-12 6.93L3 21l1.65-5.16A8 8 0 1 1 21 12Z"})}),Xe=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M18 6 6 18M6 6l12 12"})}),Ps=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M12 5v14M5 12h14"})}),xs=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:[r("path",{d:"m22 2-7 20-4-9-9-4Z"}),r("path",{d:"M22 2 11 13"})]}),ys=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M12 19V5M5 12l7-7 7 7"})}),Ss=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:r("path",{d:"M3 20V4l18 8-18 8Z"})}),$t=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:r("path",{d:"m9 18 6-6-6-6"})}),ws=()=>r("svg",{...$,"aria-hidden":"true",children:r("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),ks=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"m21 11-9 9a5.5 5.5 0 0 1-7.78-7.78l8.49-8.49a3.67 3.67 0 0 1 5.19 5.19l-8.49 8.49a1.83 1.83 0 0 1-2.6-2.6l7.78-7.78"})}),Cs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("rect",{x:"9",y:"2",width:"6",height:"12",rx:"3"}),r("path",{d:"M5 10a7 7 0 0 0 14 0M12 19v3"})]}),Ts=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M3 8V3h5M21 8V3h-5M3 16v5h5M21 16v5h-5"})}),Es=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M8 3v5H3M16 3v5h5M8 21v-5H3M16 21v-5h5"})}),Rs=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M3 3h7v2H5v5H3zM21 3h-7v2h5v5h2zM3 21h7v-2H5v-5H3zM21 21h-7v-2h5v-5h2z"})}),As=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M10 3v5H3M14 3v5h7M10 21v-5H3M14 21v-5h7"})}),Is=()=>r("svg",{...$,"aria-hidden":"true",viewBox:"0 0 10 10",children:r("path",{d:"M9 1L1 9M9 5L5 9M9 9H9",strokeWidth:"1.5"})}),Ls=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"12",r:"1.5",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"19",r:"1.5",fill:"currentColor",stroke:"none"})]}),Ms=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM15 9a5 5 0 0 1 0 6M18 7a9 9 0 0 1 0 10"})}),Ns=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM22 9l-6 6M16 9l6 6"})}),Os=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M3 18 8 6l5 12M4.7 14h6.6"}),r("path",{d:"M14.5 18l3.2-7 3.2 7M15.6 15.8h4.2"})]}),Ds=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:r("path",{d:"m5 6 6 6-6 6M13 6l6 6-6 6"})}),dn=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M20 6 9 17l-5-5"})}),$s=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M3 3v6h6"}),r("path",{d:"M3.05 13A9 9 0 1 0 6 5.3L3 9"}),r("path",{d:"M12 7v5l3 2"})]}),Hs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("path",{d:"M2 12h20"}),r("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]}),_n=()=>r("svg",{...$,class:cn,"aria-hidden":"true",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),Bs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M12 20h9"}),r("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]}),go=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"m6 9 6 6 6-6"})}),Fs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),r("path",{d:"M14 2v6h6"})]}),A_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"m12 3-1.5 4.5L6 9l4.5 1.5L12 15l1.5-4.5L18 9l-4.5-1.5Z"}),r("path",{d:"M19 15v4M17 17h4M5 3v2M4 4h2"})]}),Dr=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2Z"})}),$r=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),r("path",{d:"M12 17h.01"})]}),I_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"m15 4 3 3-9 9-3-3z"}),r("path",{d:"M18 2v2M20 4h2M3 20l3-3M3 16h2M5 14v2"})]}),L_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("rect",{x:"4",y:"8",width:"16",height:"12",rx:"2"}),r("path",{d:"M12 8V4"}),r("circle",{cx:"12",cy:"3",r:"1"}),r("path",{d:"M2 14h2M20 14h2M9 13h.01M15 13h.01M9.5 17h5"})]}),M_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M4 14v-2a8 8 0 0 1 16 0v2"}),r("rect",{x:"2",y:"14",width:"4",height:"6",rx:"1.5"}),r("rect",{x:"18",y:"14",width:"4",height:"6",rx:"1.5"}),r("path",{d:"M20 20v1a3 3 0 0 1-3 3h-5"})]}),N_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"m4.93 4.93 4.24 4.24M14.83 14.83l4.24 4.24M14.83 9.17l4.24-4.24M4.93 19.07l4.24-4.24"})]}),Hr=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"11",cy:"11",r:"7"}),r("path",{d:"m21 21-4.3-4.3"})]}),zs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m8.5 12 2.5 2.5 4.5-5"})]}),Us=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M3 9.5 12 3l9 6.5"}),r("path",{d:"M5 9v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9"})]}),Vs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"m3 11 15-5v12L3 13z"}),r("path",{d:"M3 11v2a2 2 0 0 0 2 2h1V9H5a2 2 0 0 0-2 2z"}),r("path",{d:"M7 15v3a2 2 0 0 0 4 0v-2"}),r("path",{d:"M21 10a3 3 0 0 1 0 4"})]}),un=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z"}),r("path",{d:"M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1"})]}),Ws=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"})]}),qs=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}),Gs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M12 3v18"}),r("path",{d:"M12 3a9 9 0 0 1 0 18z",fill:"currentColor",stroke:"none"})]}),O_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"10.5",cy:"10.5",r:"6.5"}),r("path",{d:"M8 11a2.5 2.5 0 0 0 5 0"}),r("path",{d:"m20 20-4.4-4.4"})]}),D_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M12 3.5 13.6 9 19 10.5 13.6 12 12 17.5 10.4 12 5 10.5 10.4 9z"}),r("path",{d:"M18.5 4v3M20 5.5h-3M5.5 16v2.5M6.75 17.25h-2.5"})]}),$_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M4 18h16"}),r("path",{d:"M5 18a7 7 0 0 1 14 0"}),r("path",{d:"M12 8V6"}),r("path",{d:"M10 6h4"})]}),H_=()=>r("svg",{...$,"aria-hidden":"true",children:[r("path",{d:"M7 11V6.5a1.5 1.5 0 0 1 3 0V10"}),r("path",{d:"M10 10V5.5a1.5 1.5 0 0 1 3 0V10"}),r("path",{d:"M13 10V6.5a1.5 1.5 0 0 1 3 0V12"}),r("path",{d:"M16 9.5a1.5 1.5 0 0 1 3 0v2.5a7 7 0 0 1-7 7 7 7 0 0 1-6.4-4.2L4 12.5a1.5 1.5 0 0 1 2.6-1.5L7 11"})]}),Ks=()=>r("svg",{...$,"aria-hidden":"true",children:r("path",{d:"M14.7 6.3a4 4 0 0 0-5.4 5.3L3 18l3 3 6.4-6.3a4 4 0 0 0 5.3-5.4l-2.7 2.7-2.6-.7-.7-2.6z"})}),js=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M12 7v5l3 2"})]}),Xs=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m8.5 12 2.5 2.5 4.5-5"})]}),Ys=()=>r("svg",{...$,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m15 9-6 6M9 9l6 6"})]}),Js={chat:R_,message:Dr,bubbles:un,spark:A_,wand:I_,bot:L_,help:$r,lifebuoy:N_,headset:M_,search:O_,sparkles:D_,concierge:$_,wave:H_};var L=x.cssPrefix,w={launcher:`${L}-launcher`,callout:`${L}-callout`,calloutDismiss:`${L}-callout-dismiss`,panel:`${L}-panel`,panelHeader:`${L}-panel-header`,resizeGrip:`${L}-resize-grip`,scrollToBottom:`${L}-scroll-to-bottom`,actionHistory:`${L}-action-history`,actionClose:`${L}-action-close`,langSegment:`${L}-lang-segment`,composer:`${L}-composer`,composerInput:`${L}-composer-input`,composerSend:`${L}-composer-send`,composerStop:`${L}-composer-stop`,composerAttach:`${L}-composer-attach`,composerFileInput:`${L}-composer-file-input`,composerVoice:`${L}-composer-voice`,attachmentChip:`${L}-attachment-chip`,attachmentRemove:`${L}-attachment-remove`,suggestion:`${L}-suggestion`,messageBubble:`${L}-message`,messageRetry:`${L}-message-retry`,historyPane:`${L}-history-pane`,historyBack:`${L}-history-back`,historyItem:`${L}-history-item`,sidebar:`${L}-sidebar`,sidebarToggle:`${L}-sidebar-toggle`,sidebarNewConversation:`${L}-sidebar-new-conversation`,sidebarItem:`${L}-sidebar-item`,messengerHome:`${L}-messenger-home`,modulesEmpty:`${L}-modules-empty`,tab:`${L}-tab`,tabBadge:`${L}-tab-badge`,homeView:`${L}-home-view`,homeGreeting:`${L}-home-greeting`,homeBrand:`${L}-home-brand`,backHeader:`${L}-back-header`,contentView:`${L}-content-view`,contentScroll:`${L}-content-scroll`,homeSearch:`${L}-home-search`,helpSearch:`${L}-help-search`,homeRecent:`${L}-home-recent`,homeContentRow:`${L}-home-content-row`,helpArticle:`${L}-help-article`,newsItem:`${L}-news-item`,formGate:`${L}-form-gate`,formDone:`${L}-form-done`,formDoneToggle:`${L}-form-done-toggle`,formAnswers:`${L}-form-answers`,formFill:`${L}-form-fill`,formSubmit:`${L}-form-submit`,formSkip:`${L}-form-skip`,formField:`${L}-form-field`,toolAskInput:`${L}-tool-ask-input`,toolInputSubmit:`${L}-tool-input-submit`,toolInputSkip:`${L}-tool-input-skip`,toolApproval:`${L}-tool-approval`,toolApprove:`${L}-tool-approve`,toolReject:`${L}-tool-reject`,toolEdit:`${L}-tool-edit`,toolDecision:`${L}-tool-decision`,toolCall:`${L}-tool-call`,source:`${L}-source`};function be(e,t){return`${e}-${t}`}var ho=x.cssPrefix;function Qs({onToggle:e,launcher:t,strings:n,leaving:o,edgeTab:i}){let a=t.variant!=="circle"&&!!t.label;return r("button",{type:"button",class:`${ho}-fab`,"data-variant":t.variant,"data-size":t.size,"data-edge-tab":i?"true":void 0,"data-leaving":o?"true":void 0,"data-testid":w.launcher,onClick:e,"aria-label":n.launcherOpen,children:[B_(t.icon),a?r("span",{class:`${ho}-fab-label`,children:Ee(n,t.label??"")}):null]})}function B_(e){let t=Js[e];return t?r(t,{}):r(F_,{source:e})}function F_({source:e}){return r("span",{ref:t=>{t&&z_(t,e)},"aria-hidden":"true"})}function z_(e,t){if(e.dataset.svgMounted!==t)try{let o=new DOMParser().parseFromString(t,"image/svg+xml").documentElement;o&&o.tagName.toLowerCase()==="svg"&&(e.replaceChildren(document.importNode(o,!0)),e.dataset.svgMounted=t)}catch{}}function Zs({callout:e,launcherPosition:t,strings:n,closeLabel:o,onDismiss:i}){let[a,l]=A(!1);return R(()=>{let s=setTimeout(()=>l(!0),e.delayMs);return()=>clearTimeout(s)},[e.delayMs]),R(()=>{if(!a||e.autoDismissMs<=0)return;let s=setTimeout(i,e.autoDismissMs);return()=>clearTimeout(s)},[a,e.autoDismissMs,i]),a?r("div",{class:`${ho}-callout`,role:"status","data-shape":e.shape,"data-position":U_(e.position,t),"data-animated":e.animated?"true":void 0,"data-testid":w.callout,children:[r("span",{children:Ee(n,e.text)}),r("button",{type:"button",class:`${ho}-callout-close`,onClick:i,"aria-label":o,title:o,"data-testid":w.calloutDismiss,children:r(Xe,{})})]}):null}function U_(e,t){let n=t.endsWith("-right"),o=t.startsWith("bottom-");return e==="vertical"?o?"top":"bottom":n?"left":"right"}function vo({panelEl:e,resize:t,position:n,initialSize:o,onSizeChange:i,strings:a}){let l=x.cssPrefix,s=O(null);if(R(()=>{if(!e)return;let m=e.style;t.minWidth&&m.setProperty(`--${l}-resize-min-w`,t.minWidth),t.maxWidth&&m.setProperty(`--${l}-resize-max-w`,t.maxWidth),t.minHeight&&m.setProperty(`--${l}-resize-min-h`,t.minHeight),t.maxHeight&&m.setProperty(`--${l}-resize-max-h`,t.maxHeight),o&&(m.setProperty(`--${l}-widget-w`,`${o.width}px`),m.setProperty(`--${l}-widget-h`,`${o.height}px`))},[e,t.minWidth,t.maxWidth,t.minHeight,t.maxHeight,l,o]),!e)return null;let c=n.startsWith("top-"),d=n.endsWith("-right"),u=`${l}-resize-grip ${l}-resize-grip--${c?"bottom":"top"}-${d?"left":"right"}`,_=m=>{if(!e)return;let C=m.currentTarget,v=e.getBoundingClientRect();s.current={pointerId:m.pointerId,startX:m.clientX,startY:m.clientY,startW:v.width,startH:v.height,dirX:d?-1:1,dirY:c?1:-1},C.setPointerCapture(m.pointerId),e.setAttribute("data-resizing",""),m.preventDefault()},g=m=>{let C=s.current;if(!C||m.pointerId!==C.pointerId||!e)return;let v=(m.clientX-C.startX)*C.dirX,b=(m.clientY-C.startY)*C.dirY;e.style.setProperty(`--${l}-widget-w`,`${C.startW+v}px`),e.style.setProperty(`--${l}-widget-h`,`${C.startH+b}px`)},f=m=>{let C=s.current;if(!C||m.pointerId!==C.pointerId||!e)return;m.currentTarget.releasePointerCapture(m.pointerId),e.removeAttribute("data-resizing");let v=e.getBoundingClientRect();i({width:Math.round(v.width),height:Math.round(v.height)}),s.current=null};return r("div",{class:u,role:"separator","aria-orientation":"vertical","aria-label":a.resizeHandle,title:a.resizeHandle,onPointerDown:_,onPointerMove:g,onPointerUp:f,onPointerCancel:f,"data-testid":w.resizeGrip,children:r(Is,{})})}var xt=x.cssPrefix,V_=`.${xt}-header, .${xt}-back-header, .${xt}-home-hero`,W_='button, a, input, textarea, select, [role="tab"], [contenteditable]',el=56;function bo(e,t){R(()=>{if(!t||!e)return;let n=c=>Number.parseFloat(c)||0,o=(c,d)=>Math.min(d,Math.max(-d,c)),i=null,a=c=>{let d=c.target;if(!(d instanceof Element)||!d.closest(V_)||d.closest(W_))return;let u=e.getBoundingClientRect();i={id:c.pointerId,x:c.clientX,y:c.clientY,dx:n(e.style.getPropertyValue(`--${xt}-modal-dx`)),dy:n(e.style.getPropertyValue(`--${xt}-modal-dy`)),maxX:(window.innerWidth+u.width)/2-el,maxY:(window.innerHeight+u.height)/2-el},e.dataset.dragging="true",c.preventDefault()},l=c=>{if(!i||c.pointerId!==i.id)return;let d=o(i.dx+c.clientX-i.x,i.maxX),u=o(i.dy+c.clientY-i.y,i.maxY);e.style.setProperty(`--${xt}-modal-dx`,`${d}px`),e.style.setProperty(`--${xt}-modal-dy`,`${u}px`)},s=c=>{!i||c.pointerId!==i.id||(i=null,delete e.dataset.dragging)};return e.addEventListener("pointerdown",a),window.addEventListener("pointermove",l),window.addEventListener("pointerup",s),window.addEventListener("pointercancel",s),()=>{e.removeEventListener("pointerdown",a),window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),window.removeEventListener("pointercancel",s)}},[e,t])}function pn(e,t,n){switch(e){case"clear":case"sound":case"history":case"language":case"theme":case"textSize":return!0;case"expand":return t==="floating";case"fullscreen":return t!=="standalone";case"close":return t==="standalone"||t==="page"?!1:t==="inline"?n==="fullscreen":!0}}function Po(e,t,n){return pn("close",e,t)?n.includes("close"):!1}function tl(e,t){return e==="inline"&&t==="fullscreen"?"exit-fullscreen":"close"}var q_='a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),[tabindex]:not([tabindex="-1"])';function xo(e){let t=n=>{if(n.key!=="Tab")return;let o=[...e.querySelectorAll(q_)].filter(s=>s.offsetParent!==null||s===document.activeElement);if(o.length===0){n.preventDefault();return}let i=o[0],a=o[o.length-1];if(!i||!a)return;let l=e.getRootNode().activeElement;n.shiftKey&&l===i?(n.preventDefault(),a.focus()):!n.shiftKey&&l===a&&(n.preventDefault(),i.focus())};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)}function yo(e){return e.trim().split(/\s+/).slice(0,2).map(t=>t.charAt(0).toUpperCase()).join("")}var Br=x.cssPrefix;function nl({agent:e,strings:t}){let n=e.status??"online",o=Ee(t,e.name),i=e.title?Ee(t,e.title):null;return r("div",{class:`${Br}-agent`,children:[r("div",{class:`${Br}-agent-avatar`,"data-status":n,children:e.avatar?r("img",{src:e.avatar,alt:""}):r("span",{children:yo(o)})}),r("div",{class:`${Br}-agent-meta`,children:[r("strong",{children:o}),i?r("span",{children:i}):null]})]})}var ol=X.scope("attachments");function So(e,t,n){let o=K_(e),i=[],a=[],l=Y_(n.accept),s=t.reduce((d,u)=>d+u.size,0),c=t.length;for(let d of o){let u=G_(d,c,s,n,l);if(u){a.push({file:d,reason:u});continue}i.push(X_(d)),s+=d.size,c+=1}return(i.length||a.length)&&ol.debug("ingest",{accepted:i.length,rejected:a.map(d=>({name:d.file.name,reason:d.reason}))}),{accepted:i,rejected:a}}function Fr(e){try{URL.revokeObjectURL(e.previewUrl)}catch(t){ol.debug("revokeObjectURL failed",{error:t})}}function G_(e,t,n,o,i){return t>=o.maxCount?"count":n+e.size>o.maxBytes?"bytes":J_(e,i)?null:"mime"}function K_(e){return e?Array.isArray(e)?e.filter(t=>t instanceof File):[...e].map(t=>t instanceof File?t:j_(t)).filter(t=>t!==null):[]}function j_(e){let t=e;return!t?.getAsFile||t.kind!=="file"?null:t.getAsFile()}function X_(e){return{file:e,id:Ue(),mediaType:e.type||"application/octet-stream",name:e.name||"pasted-file",previewUrl:URL.createObjectURL(e),size:e.size}}function Y_(e){return e.split(",").map(t=>t.trim().toLowerCase()).filter(Boolean).map(t=>{if(t.startsWith("."))return{kind:"ext",ext:t};let[n="*",o="*"]=t.split("/");return{kind:"mime",type:n,subtype:o}})}function J_(e,t){if(t.length===0)return!0;let[n="*",o="*"]=(e.type||"").toLowerCase().split("/"),i=(e.name||"").toLowerCase();return t.some(a=>a.kind==="ext"?i.endsWith(a.ext):(a.type==="*"||a.type===n)&&(a.subtype==="*"||a.subtype===o))}var mn=x.cssPrefix;function rl({attachment:e,onRemove:t}){let n=e.mediaType.startsWith("image/");return r("span",{class:`${mn}-attachment-chip`,title:e.name,"data-testid":be(w.attachmentChip,e.id),children:[n?r("img",{class:`${mn}-attachment-thumb`,src:e.previewUrl,alt:""}):r("span",{class:`${mn}-attachment-thumb`,"aria-hidden":"true",children:r(Fs,{})}),r("span",{class:`${mn}-attachment-name`,children:e.name}),r("button",{type:"button",class:`${mn}-attachment-remove`,onClick:t,"aria-label":`Remove ${e.name}`,"data-testid":be(w.attachmentRemove,e.id),children:r(Xe,{})})]})}var zr={isSupported:!1,start:()=>{},stop:()=>{}};function Ur(e,t,n){return e==="disabled"?zr:e==="server"?tu(n):Q_(t)}function Q_(e){let t=Z_();if(!t)return zr;let n=null;return{isSupported:!0,start(o,i){n=new t,n.continuous=!0,n.interimResults=!0,n.lang=e,n.addEventListener("result",l=>{let s=l,c="",d=!1;for(let u=s.resultIndex;u<s.results.length;u++){let _=s.results[u];_&&(c+=_[0].transcript,_.isFinal&&(d=!0))}o(c,d)});let a=()=>{n=null,i()};n.addEventListener("end",a),n.addEventListener("error",a),n.start()},stop(){n?.stop()}}}function Z_(){let e=globalThis;return e.SpeechRecognition??e.webkitSpeechRecognition}var eu=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus","audio/mp4"];function tu(e){if(typeof MediaRecorder>"u"||!navigator?.mediaDevices?.getUserMedia)return zr;let t=null,n=null,o=[],i=()=>{for(let a of n?.getTracks()??[])a.stop();n=null};return{isSupported:!0,async start(a,l){try{n=await navigator.mediaDevices.getUserMedia({audio:!0});let s=nu();t=new MediaRecorder(n,s?{mimeType:s}:void 0),o=[],t.addEventListener("dataavailable",c=>{c.data.size>0&&o.push(c.data)}),t.addEventListener("stop",async()=>{let c=t?.mimeType??"audio/webm";i();let d=new Blob(o,{type:c});o=[];try{let{text:u}=await e(d,c);u&&a(u,!0)}catch{}finally{l()}}),t.start()}catch{i(),l()}},stop(){t?.stop()}}}function nu(){for(let e of eu)if(MediaRecorder.isTypeSupported(e))return e}var He=x.cssPrefix,yt=X.scope("composer");function Ht(e){return e.reduce((t,n)=>t+n.size,0)}var ou={arrowUp:ys,paperPlane:xs,send:Ss,chevron:$t};function il({options:e,transport:t,feedback:n,bus:o,isStreaming:i,onSend:a,onStop:l,attachApiRef:s}){let c=e.strings,[d,u]=A(""),[_,g]=A([]),[f,m]=A(!1),C=O(null),v=O(null),b=e.features.files,y=e.features.voice,[P,E]=A(()=>Ur(y,e.locale,(k,K)=>t.transcribe(k,K)));R(()=>{f||y==="disabled"||E(Ur(y,e.locale,(k,K)=>t.transcribe(k,K)))},[e.locale,y,t,f]),R(()=>{let k=C.current;if(!k)return;let K=k.getRootNode(),re="activeElement"in K?K.activeElement:null;re&&k.closest(`.${He}-panel`)?.contains(re)||k.focus({preventScroll:!0})},[]),R(()=>{let k=C.current;if(k){if(d.length===0){k.style.height="";return}k.style.height="auto",k.style.height=`${Math.min(k.scrollHeight,160)}px`}},[d]);let B=O(_);B.current=_,R(()=>()=>B.current.forEach(Fr),[]),R(()=>{if(s)return s.current={attachFromDrop:k=>{let K=So(k,B.current,e.attachments);K.accepted.length!==0&&(yt.info("attach (drop)",{count:K.accepted.length,totalBytes:Ht(K.accepted)}),o.emit("attach",{count:K.accepted.length,totalBytes:Ht(K.accepted)}),g(re=>[...re,...K.accepted]))}},()=>{s.current&&(s.current=null)}},[s,e.attachments]),R(()=>{let k=C.current;if(!k)return;let K=k.closest(`.${He}-panel`);if(!K)return;let re=de=>{let ue=de.clipboardData;if(!ue)return;if(b){let ie=So(ue.items,B.current,e.attachments);if(ie.accepted.length>0){de.preventDefault(),yt.info("attach (paste)",{count:ie.accepted.length,totalBytes:Ht(ie.accepted)}),o.emit("attach",{count:ie.accepted.length,totalBytes:Ht(ie.accepted)}),g(Pe=>[...Pe,...ie.accepted]);return}}if(de.target===k)return;let Ie=ue.getData("text/plain");Ie&&(de.preventDefault(),u(ie=>ie+Ie),k.focus())};return K.addEventListener("paste",re),()=>K.removeEventListener("paste",re)},[b,e.attachments,He]);let le=()=>{let k=d.trim();!k&&_.length===0||i||(a(k,_),u(""),g([]))},M=k=>{k.key!=="Enter"||k.shiftKey||k.isComposing||(k.preventDefault(),i?l():le())},Z=k=>{let K=k.target,re=So(K.files,_,e.attachments);re.accepted.length>0&&(yt.info("attach (file picker)",{count:re.accepted.length,totalBytes:Ht(re.accepted)}),o.emit("attach",{count:re.accepted.length,totalBytes:Ht(re.accepted)}),g(de=>[...de,...re.accepted])),K.value=""},F=k=>{yt.info("removeAttachment",{id:k}),o.emit("removeAttachment",{id:k}),g(K=>{let re=K.find(de=>de.id===k);return re&&Fr(re),K.filter(de=>de.id!==k)})},G=O(null),Y=()=>{if(P.isSupported){if(f){let k=G.current?Date.now()-G.current:0;yt.info("voiceStop",{durationMs:k}),o.emit("voiceStop",{durationMs:k}),P.stop(),m(!1),n.play("voiceStop"),G.current=null;return}G.current=Date.now(),yt.info("voiceStart"),o.emit("voiceStart",void 0),m(!0),n.play("voiceStart"),P.start((k,K)=>u(re=>K?`${re}${k} `:re),()=>{if(m(!1),G.current){let k=Date.now()-G.current;yt.debug("voiceStop (auto)",{durationMs:k}),o.emit("voiceStop",{durationMs:k}),G.current=null}})}},he=ou[e.composer.sendButton.icon];return r("div",{class:`${He}-composer`,"data-testid":w.composer,children:[_.length>0?r("div",{class:`${He}-attachments`,children:_.map(k=>r(rl,{attachment:k,onRemove:()=>F(k.id)},k.id))}):null,r("div",{class:`${He}-composer-row`,children:[r("div",{class:`${He}-composer-actions`,children:[b?r("button",{type:"button",class:`${He}-icon-btn`,onClick:()=>v.current?.click(),"aria-label":c.attach,"data-testid":w.composerAttach,children:r(ks,{})}):null,P.isSupported?r("button",{type:"button",class:`${He}-icon-btn`,onClick:Y,"aria-label":f?c.micStop:c.micStart,"aria-pressed":f,"data-recording":f?"true":void 0,"data-testid":w.composerVoice,children:r(Cs,{})}):null]}),r("textarea",{ref:C,class:`${He}-textarea`,rows:1,value:d,placeholder:c.composerPlaceholder,onInput:k=>u(k.target.value),onKeyDown:M,"aria-label":c.composerPlaceholder,"data-testid":w.composerInput}),i?r("button",{type:"button",class:`${He}-send`,onClick:l,"aria-label":c.stop,"data-testid":w.composerStop,children:r(ws,{})}):r("button",{type:"button",class:`${He}-send`,"data-shape":e.composer.sendButton.shape,"data-variant":e.composer.sendButton.variant,onClick:le,disabled:!d.trim()&&_.length===0,"aria-label":c.send,"data-testid":w.composerSend,children:r(he,{})})]}),r("input",{ref:v,type:"file",multiple:!0,accept:e.attachments.accept,onChange:Z,class:`${He}-sr-only`,"data-testid":w.composerFileInput})]})}var ru=x.cssPrefix;function al({visible:e,strings:t}){return e?r("div",{class:`${ru}-dropzone`,role:"status","aria-live":"polite",children:t.dropZone}):null}function wo({containerRef:e,onDrop:t}){let[n,o]=A(!1);return R(()=>{let i=e.current;if(!i)return;let a=0,l=u=>{a+=1,u.dataTransfer?.types.includes("Files")&&(u.preventDefault(),o(!0))},s=()=>{a-=1,!(a>0)&&(a=0,o(!1))},c=u=>{u.dataTransfer?.types.includes("Files")&&u.preventDefault()},d=u=>{a=0,o(!1),u.dataTransfer&&(u.preventDefault(),t(u.dataTransfer.items))};return i.addEventListener("dragenter",l),i.addEventListener("dragleave",s),i.addEventListener("dragover",c),i.addEventListener("drop",d),()=>{i.removeEventListener("dragenter",l),i.removeEventListener("dragleave",s),i.removeEventListener("dragover",c),i.removeEventListener("drop",d)}},[e,t]),{visible:n}}function sl({itemCount:e,initialFocusIndex:t}){let[n,o]=A(!1),i=O(null),a=O(null),[l,s]=A(-1),c=D(()=>{o(!1),s(-1),i.current?.focus()},[]),d=D(()=>o(g=>!g),[]);R(()=>{if(!n)return;let g=f=>{let m=a.current,C=i.current;if(!m||!C)return;let v=f.composedPath();v.includes(m)||v.includes(C)||(o(!1),s(-1))};return document.addEventListener("click",g,!0),()=>document.removeEventListener("click",g,!0)},[n]),R(()=>{if(!n||e===0)return;let g=t?.()??0,f=g<0||g>=e?0:g;s(f)},[n,e,t]),R(()=>{if(!n||l<0)return;a.current?.querySelectorAll("[role='menuitem']")?.[l]?.focus()},[n,l]);let u=D(g=>{(g.key==="ArrowDown"||g.key==="Enter"||g.key===" ")&&(g.preventDefault(),o(!0))},[]),_=D(g=>{if(e!==0)switch(g.key){case"Escape":g.preventDefault(),c();return;case"ArrowDown":g.preventDefault(),s(f=>(f+1)%e);return;case"ArrowUp":g.preventDefault(),s(f=>(f-1+e)%e);return;case"Home":g.preventDefault(),s(0);return;case"End":g.preventDefault(),s(e-1)}},[e,c]);return{open:n,focusIndex:l,triggerRef:i,menuRef:a,toggle:d,close:c,onTriggerKey:u,onMenuKey:_}}function ll({items:e,triggerLabel:t}){let n=x.cssPrefix,o=sl({itemCount:e.length}),i=s=>{s.disabled||(s.onSelect?.(),s.keepOpen||o.close())},a=(s,c)=>s.onSelectValue?.(c),l=(s,c)=>{let d=c.segments;if(!d?.length)return;let u=Math.max(0,d.findIndex(g=>g.value===c.value)),_=-1;if(s.key==="ArrowRight"||s.key==="Enter"||s.key===" ")_=(u+1)%d.length;else if(s.key==="ArrowLeft")_=(u-1+d.length)%d.length;else return;s.preventDefault(),s.stopPropagation(),a(c,d[_].value)};return r("div",{class:`${n}-menu-wrap`,children:[r("button",{ref:o.triggerRef,type:"button",class:`${n}-icon-btn`,"aria-label":t,"aria-haspopup":"menu","aria-expanded":o.open,title:t,onClick:o.toggle,onKeyDown:o.onTriggerKey,children:r(Ls,{})}),o.open?r("div",{ref:o.menuRef,class:`${n}-menu`,role:"menu","aria-label":t,onKeyDown:o.onMenuKey,tabIndex:-1,children:e.map(s=>s.segments?r("div",{role:"menuitem",class:`${n}-menu-item ${n}-menu-item-segmented`,"aria-label":s.label,tabIndex:-1,onKeyDown:c=>l(c,s),children:[s.icon?r("span",{class:`${n}-menu-icon`,children:s.icon}):null,r("span",{class:`${n}-menu-label`,children:s.label}),r("span",{class:`${n}-segmented`,role:"group","aria-label":s.label,children:s.segments.map(c=>{let d=c.value===s.value;return r("button",{type:"button",role:"menuitemradio","aria-checked":d,class:`${n}-segment`,"data-on":d?"true":void 0,lang:c.lang,title:c.value,tabIndex:-1,"data-testid":`${w.langSegment}-${c.value}`,onClick:()=>a(s,c.value),children:c.label},c.value)})})]},s.id):r("button",{type:"button",role:"menuitem",class:`${n}-menu-item`,"aria-pressed":s.type==="switch"?s.on:void 0,disabled:s.disabled,onClick:()=>i(s),children:[s.icon?r("span",{class:`${n}-menu-icon`,children:s.icon}):null,r("span",{class:`${n}-menu-label`,children:s.label}),s.type==="switch"&&s.on?r("span",{class:`${n}-menu-check`,"aria-hidden":"true",children:r(dn,{})}):null]},s.id))}):null]})}var Vr=x.cssPrefix;function iu(e){let t=typeof matchMedia=="function"?matchMedia("(prefers-color-scheme: dark)").matches:!0;return e==="auto"?t?"light":"dark":t?e==="light"?"dark":"auto":e==="dark"?"light":"auto"}var au={normal:"large",large:"small",small:"normal"};function su(e){return e==="light"?r(Ws,{}):e==="dark"?r(qs,{}):r(Gs,{})}function lu(e){return(e.split("-")[0]??e).toUpperCase()}function Ye({panelProps:e,variant:t}){let{options:n,panelSize:o,feedback:i,onClose:a,onClear:l,onExpand:s,onFullscreen:c,onSoundToggle:d}=e,{onToggleHistory:u,onLocaleChange:_,onThemeChange:g,onTextSizeChange:f}=e,m=n.strings,C=n.mode,v=t==="chat",b=j(()=>i.mutedSig.value).value,y=new Set(n.actions),P=k=>y.has(k),E=typeof matchMedia=="function"&&matchMedia("(max-width: 640px)").matches,B=k=>E?!1:pn(k,C,o),le=n.themeMode,M={auto:m.themeAuto,light:m.themeLight,dark:m.themeDark},Z=n.textSize,F={small:m.textSizeSmall,normal:m.textSizeNormal,large:m.textSizeLarge},G=[];if(v&&P("clear")&&G.push({id:"clear",icon:r(Bs,{}),label:m.newConversation,onSelect:l}),P("expand")&&B("expand")){let k=o==="expanded";G.push({id:"expand",icon:k?r(Es,{}):r(Ts,{}),label:k?m.collapse:m.expand,type:"switch",on:k,onSelect:s})}if(P("fullscreen")&&B("fullscreen")){let k=o==="fullscreen";G.push({id:"fullscreen",icon:k?r(As,{}):r(Rs,{}),label:k?m.exitFullscreen:m.fullscreen,type:"switch",on:k,onSelect:c})}v&&P("sound")&&G.push({id:"sound",icon:b?r(Ns,{}):r(Ms,{}),label:b?m.soundOff:m.soundOn,type:"switch",on:!b,onSelect:d}),P("theme")&&G.push({id:"theme",icon:su(le),label:`${m.theme}: ${M[le]}`,onSelect:()=>g(iu(le)),keepOpen:!0}),P("textSize")&&G.push({id:"textSize",icon:r(Os,{}),label:`${m.textSize}: ${F[Z]}`,onSelect:()=>f(au[Z]),keepOpen:!0}),P("language")&&n.availableLocales.length>1&&G.push({id:"language",icon:r(Hs,{}),label:m.language,segments:n.availableLocales.map(k=>({value:k,label:lu(k),lang:k})),value:n.locale,onSelectValue:_});let Y=!!a&&Po(C,o,n.actions),he=v&&P("history");return r("div",{class:`${Vr}-header-actions`,children:[he?r("button",{type:"button",class:`${Vr}-icon-btn`,onClick:u,"aria-label":m.history,title:m.history,"data-testid":w.actionHistory,children:r($s,{})}):null,G.length>0?r(ll,{items:G,triggerLabel:m.moreActions}):null,Y?r("button",{type:"button",class:`${Vr}-icon-btn`,onClick:a,"aria-label":m.close,title:m.close,"data-testid":w.actionClose,children:r(Xe,{})}):null]})}var cu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,du=/^https?:\/\/[^\s.]+\.[^\s]+$/i,_u=/^[+]?[\d\s().-]{6,}$/;function Bt(e,t){return e.replace(/\{(\w+)\}/g,(n,o)=>String(t[o]??`{${o}}`))}function uu(e){return Array.isArray(e)?e.length:e&&e.trim()?1:0}function pu(e,t,n){let o=e.required??!0,i=e.validation;if(e.type==="multiselect"){let l=uu(t);return o&&l===0?n.formRequired:l===0?void 0:i?.minSelections!=null&&l<i.minSelections?Bt(n.formChooseAtLeast,{min:i.minSelections}):i?.maxSelections!=null&&l>i.maxSelections?Bt(n.formChooseAtMost,{max:i.maxSelections}):void 0}let a=typeof t=="string"?t.trim():"";if(!a)return o?n.formRequired:void 0;switch(e.type){case"email":if(!cu.test(a))return n.formInvalidEmail;break;case"url":if(!du.test(a))return n.formInvalidUrl;break;case"tel":if(!_u.test(a))return n.formInvalidTel;break;case"number":{let l=Number(a);if(!Number.isFinite(l))return n.formInvalidNumber;if(i?.min!=null&&l<i.min)return Bt(n.formNumberTooSmall,{min:i.min});if(i?.max!=null&&l>i.max)return Bt(n.formNumberTooLarge,{max:i.max});break}default:break}if(i?.minLength!=null&&a.length<i.minLength)return Bt(n.formTooShort,{min:i.minLength});if(i?.maxLength!=null&&a.length>i.maxLength)return Bt(n.formTooLong,{max:i.maxLength});if(i?.pattern)try{if(!new RegExp(i.pattern).test(a))return n.formPatternMismatch}catch{}}function cl(e,t,n){let o={};for(let i of e){let a=pu(i,t[i.name],n);a&&(o[i.name]=a)}return o}function dl(e){let t={};for(let[n,o]of Object.entries(e)){let i=Array.isArray(o)?o.join(", "):o;i&&i.trim()&&(t[n]=i.trim())}return t}var _e=x.cssPrefix,ko="__other__";function Co({fields:e,strings:t,submitLabel:n,onSubmit:o,skipLabel:i,onSkip:a,footerHint:l,submitOnEnter:s,disabled:c,rootTestId:d,submitTestId:u,skipTestId:_}){let[g,f]=A(()=>hu(e)),[m,C]=A({}),[v,b]=A({}),y=M=>{v[M]&&b(Z=>({...Z,[M]:""}))},P=(M,Z)=>{f(F=>({...F,[M]:Z})),y(M)},E=(M,Z)=>{C(F=>({...F,[M]:Z})),y(M)},B=M=>{if(M.preventDefault(),c)return;let Z=vu(e,g,m),F=cl(e,Z,t);if(Object.keys(F).length>0){b(F);return}o(dl(Z))},le=M=>{!s||M.key!=="Enter"||M.shiftKey||M.isComposing||M.target?.tagName==="TEXTAREA"&&B(M)};return r("form",{class:`${_e}-form`,onSubmit:B,onKeyDown:le,"data-testid":d,noValidate:!0,children:[e.map(M=>r(mu,{field:M,value:g[M.name],otherText:m[M.name]??"",error:v[M.name],disabled:c,strings:t,onChange:Z=>P(M.name,Z),onOtherChange:Z=>E(M.name,Z)},M.name)),r("div",{class:`${_e}-form-actions`,children:[l?r("span",{class:`${_e}-form-hint`,children:l}):null,i&&a?r("button",{type:"button",class:`${_e}-form-skip`,onClick:a,disabled:c,"data-testid":_,children:i}):null,r("button",{type:"submit",class:`${_e}-form-submit`,disabled:c,"data-testid":u,children:n})]})]})}function mu({field:e,value:t,otherText:n,error:o,disabled:i,strings:a,onChange:l,onOtherChange:s}){let c=be(w.formField,e.name),d=fu({field:e,value:t,otherText:n,disabled:i,strings:a,onChange:l,onOtherChange:s,fieldTid:c});return r("label",{class:`${_e}-field`,"data-field":e.name,"data-invalid":o?"true":void 0,children:[r("span",{class:`${_e}-field-label`,children:[e.label,e.required??!0?r("span",{class:`${_e}-field-req`,"aria-hidden":"true",children:" *"}):null]}),d,e.validationHint&&!o?r("span",{class:`${_e}-field-hint`,children:e.validationHint}):null,o?r("span",{class:`${_e}-field-error`,role:"alert",children:o}):null]})}function fu(e){let{field:t,value:n,otherText:o,disabled:i,strings:a,onChange:l,onOtherChange:s,fieldTid:c}=e,d=typeof n=="string"?n:"";switch(t.type){case"textarea":return r("textarea",{class:`${_e}-field-input`,rows:3,value:d,placeholder:t.placeholder,disabled:i,onInput:u=>l(u.target.value),"data-testid":c});case"select":return r("select",{class:`${_e}-field-input`,value:d,disabled:i,onChange:u=>l(u.target.value),"data-testid":c,children:[r("option",{value:"",children:t.placeholder??"\u2014"}),(t.options??[]).map(u=>r("option",{value:u.value,children:u.label??u.value},u.value))]});case"radio":{let u=t.allowOther&&d===ko;return r("div",{class:`${_e}-field-choices`,role:"radiogroup","data-testid":c,children:[(t.options??[]).map(_=>r("label",{class:`${_e}-choice`,children:[r("input",{type:"radio",name:`${_e}-${t.name}`,checked:d===_.value,disabled:i,onChange:()=>l(_.value)}),r("span",{children:_.label??_.value})]},_.value)),t.allowOther?r("label",{class:`${_e}-choice`,children:[r("input",{type:"radio",name:`${_e}-${t.name}`,checked:d===ko,disabled:i,onChange:()=>l(ko)}),r("span",{children:a.formOther})]}):null,u?r("input",{class:`${_e}-field-input`,value:o,placeholder:t.placeholder??a.formOtherPlaceholder,disabled:i,onInput:_=>s(_.target.value)}):null]})}case"checkbox":return r("label",{class:`${_e}-choice`,children:[r("input",{type:"checkbox",checked:d==="true",disabled:i,onChange:u=>l(u.target.checked?"true":""),"data-testid":c}),r("span",{children:t.placeholder??t.label})]});case"multiselect":{let u=Array.isArray(n)?n:[],_=(g,f)=>l(f?[...u,g]:u.filter(m=>m!==g));return r("div",{class:`${_e}-field-choices`,"data-testid":c,children:[(t.options??[]).map(g=>r("label",{class:`${_e}-choice`,children:[r("input",{type:"checkbox",checked:u.includes(g.value),disabled:i,onChange:f=>_(g.value,f.target.checked)}),r("span",{children:g.label??g.value})]},g.value)),t.allowOther||(t.options??[]).length===0?r("textarea",{class:`${_e}-field-input`,rows:2,value:o,placeholder:t.placeholder??a.formOtherPlaceholder,disabled:i,onInput:g=>s(g.target.value)}):null]})}default:return r("input",{class:`${_e}-field-input`,type:gu(t.type),value:d,placeholder:t.placeholder,disabled:i,onInput:u=>l(u.target.value),"data-testid":c})}}function gu(e){switch(e){case"number":case"email":case"tel":case"url":case"date":case"time":return e;default:return"text"}}function hu(e){let t={};for(let n of e)n.defaultValue!=null&&(t[n.name]=n.type==="multiselect"?n.defaultValue.split(",").map(o=>o.trim()).filter(Boolean):n.defaultValue);return t}function vu(e,t,n){let o={...t};for(let i of e){let a=n[i.name]?.trim();if(i.type==="radio"&&i.allowOther&&t[i.name]===ko)o[i.name]=a??"";else if(i.type==="multiselect"&&a){let l=a.split(/[,\n;]+/).map(c=>c.trim()).filter(Boolean),s=Array.isArray(t[i.name])?t[i.name]:[];o[i.name]=[...s,...l]}}return o}var Je=x.cssPrefix;function Wr({form:e,strings:t,onSubmit:n,onSkip:o}){return r("div",{class:`${Je}-form-gate`,"data-testid":w.formGate,children:[e.title?r("h3",{class:`${Je}-form-gate-title`,children:e.title}):null,e.description?r("p",{class:`${Je}-form-gate-desc`,children:e.description}):null,r(Co,{fields:e.fields,strings:t,submitLabel:e.submitLabel??t.formSubmit,onSubmit:n,skipLabel:e.skippable?t.formSkip:void 0,onSkip:e.skippable?o:void 0,submitTestId:w.formSubmit,skipTestId:w.formSkip})]})}function _l({marker:e,strings:t,onFill:n}){let o=e.outcome==="skipped",i=o?t.formSkipped:t.formSubmitted,a=e.title?r(ee,{children:[r("span",{children:e.title}),r("span",{class:`${Je}-sr-only`,children:i})]}):r("span",{children:i}),l=e.form?.reviewable??!1,s=!o&&l&&e.values&&Object.keys(e.values).length>0?e.values:null;if(s){let c=d=>e.form?.fields.find(u=>u.name===d)?.label??d;return r("details",{class:`${Je}-form-done`,"data-outcome":e.outcome,"data-testid":w.formDone,children:[r("summary",{class:`${Je}-form-done-summary`,"data-testid":w.formDoneToggle,children:[r(dn,{}),a,r($t,{})]}),r("dl",{class:`${Je}-form-answers`,"data-testid":w.formAnswers,children:Object.entries(s).map(([d,u])=>r("div",{class:`${Je}-form-answer`,children:[r("dt",{children:c(d)}),r("dd",{children:u})]},d))})]})}return r("div",{class:`${Je}-form-done`,"data-outcome":e.outcome,"data-testid":w.formDone,role:"status",children:[o?r(Ds,{}):r(dn,{}),a,o&&e.form?.reopenable&&n?r("button",{type:"button",class:`${Je}-form-done-fill`,"data-testid":w.formFill,onClick:n,children:t.formFillOut}):null]})}function ul(e){if(!e)return!1;let t=e.startsWith("tool:")?e.slice(5):e;return t==="ask-user-input"||t==="ask_user_input"||t==="request-user-input"||t==="request_user_input"}var Kr=1,ml=2,fl=4,gl=8,hl=16;function bu(e){switch(e){case Kr:return"href";case ml:return"src";case fl:return"class";case gl:return"checked";case hl:return"start"}}var Pu=e=>{switch(e){case 1:return 3;case 2:return 4;case 3:return 5;case 4:return 6;case 5:return 7;default:return 8}},xu=Pu;var pl=24;function Xr(e){let t=new Uint32Array(pl);return t[0]=1,{renderer:e,text:"",pending:"",tokens:t,len:0,token:1,fence_end:0,blockquote_idx:0,hr_char:"",hr_chars:0,fence_start:0,spaces:new Uint8Array(pl),indent:"",indent_len:0,table_state:0}}function vl(e){e.pending.length>0&&Ce(e,`
12
12
  `)}function te(e){e.text.length!==0&&(console.assert(e.len>0,"Never adding text to root"),e.renderer.add_text(e.renderer.data,e.text),e.text="")}function fe(e){console.assert(e.len>0,"No nodes to end"),e.len-=1,e.token=e.tokens[e.len],e.renderer.end_token(e.renderer.data)}function ne(e,t){(e.tokens[e.len]===24||e.tokens[e.len]===23)&&t!==25&&fe(e),e.len+=1,e.tokens[e.len]=t,e.token=t,e.renderer.add_token(e.renderer.data,t)}function yu(e,t,n){for(;n<=e.len;){if(e.tokens[n]===t)return n;n+=1}return-1}function St(e,t){for(e.fence_start=0;e.len>t;)fe(e)}function To(e,t){let n=0;for(let o=0;o<=e.len&&(t-=e.spaces[o],!(t<0));o+=1)switch(e.tokens[o]){case 9:case 10:case 20:case 25:n=o;break}for(;e.len>n;)fe(e);return t}function qr(e,t){let n=-1,o=-1;for(let i=e.blockquote_idx+1;i<=e.len;i+=1)if(e.tokens[i]===25){if(e.indent_len<e.spaces[i]){o=-1;break}o=i}else e.tokens[i]===t&&(n=i);return o===-1?n===-1?(St(e,e.blockquote_idx),ne(e,t),!0):(St(e,n),!1):(St(e,o),ne(e,t),!0)}function Gr(e,t){ne(e,25),e.spaces[e.len]=e.indent_len+t,rt(e),e.token=103}function rt(e){e.indent="",e.indent_len=0,e.pending=""}function jr(e){switch(e){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return!0;default:return!1}}function Su(e){switch(e){case 32:case 58:case 59:case 41:case 44:case 33:case 46:case 63:case 93:case 10:return!0;default:return!1}}function wu(e){return jr(e)||Su(e)}function Ce(e,t){for(let n of t){if(e.token===101){switch(n){case" ":e.indent_len+=1;continue;case" ":e.indent_len+=4;continue}let i=To(e,e.indent_len);e.indent_len=0,e.token=e.tokens[e.len],i>0&&Ce(e," ".repeat(i))}let o=e.pending+n;switch(e.token){case 21:case 1:case 20:case 24:case 23:switch(console.assert(e.text.length===0,"Root should not have any text"),e.pending[0]){case void 0:e.pending=n;continue;case" ":console.assert(e.pending.length===1),e.pending=n,e.indent+=" ",e.indent_len+=1;continue;case" ":console.assert(e.pending.length===1),e.pending=n,e.indent+=" ",e.indent_len+=4;continue;case`
13
13
  `:if(console.assert(e.pending.length===1),e.tokens[e.len]===25&&e.token===21){fe(e),rt(e),e.pending=n;continue}St(e,e.blockquote_idx),rt(e),e.blockquote_idx=0,e.fence_start=0,e.pending=n;continue;case"#":switch(n){case"#":if(e.pending.length<6){e.pending=o;continue}break;case" ":To(e,e.indent_len),ne(e,xu(e.pending.length)),rt(e);continue}break;case">":{let a=yu(e,20,e.blockquote_idx+1);a===-1?(St(e,e.blockquote_idx),e.blockquote_idx+=1,e.fence_start=0,ne(e,20)):e.blockquote_idx=a,rt(e),e.pending=n;continue}case"-":case"*":case"_":if(e.hr_chars===0&&(console.assert(e.pending.length===1,"Pending should be one character"),e.hr_chars=1,e.hr_char=e.pending),e.hr_chars>0){switch(n){case e.hr_char:e.hr_chars+=1,e.pending=o;continue;case" ":e.pending=o;continue;case`
14
14
  `:if(e.hr_chars<3)break;To(e,e.indent_len),e.renderer.add_token(e.renderer.data,22),e.renderer.end_token(e.renderer.data),rt(e),e.hr_chars=0;continue}e.hr_chars=0}if(e.pending[0]!=="_"&&e.pending[1]===" "){qr(e,23),Gr(e,2),Ce(e,o.slice(2));continue}break;case"`":if(e.pending.length<3){if(n==="`"){e.pending=o,e.fence_start=o.length;continue}e.fence_start=0;break}switch(n){case"`":e.pending.length===e.fence_start?(e.pending=o,e.fence_start=o.length):(ne(e,2),rt(e),e.fence_start=0,Ce(e,o));continue;case`
@@ -36,5 +36,5 @@ ${i}`:i;continue}o.startsWith("id:")&&(n=o.slice(3).trim())}if(!t||t==="[DONE]")
36
36
  `?"":n,e.pending="");continue;case"_":case"*":{if(e.token===19||e.token===30||e.token===31||e.token===14)break;let i=12,a=14,l=e.pending[0];if(l==="_"&&(i=13,a=15),e.pending.length===1){if(l===n){e.pending=o;continue}if(n!==" "&&n!==`
37
37
  `){te(e),ne(e,i),e.pending=n;continue}}else{if(l===n){te(e),ne(e,a),ne(e,i),e.pending="";continue}if(n!==" "&&n!==`
38
38
  `){te(e),ne(e,a),e.pending=n;continue}}break}case"~":if(e.token!==19&&e.token!==16){if(e.pending==="~"){if(n==="~"){e.pending=o;continue}}else if(n!==" "&&n!==`
39
- `){te(e),ne(e,16),e.pending=n;continue}}break;case"$":if(e.token!==19&&e.token!==16&&e.pending==="$")if(n==="$"){e.token=105,e.pending=o;continue}else{if(wu(n.charCodeAt(0)))break;te(e),ne(e,31),e.pending=n;continue}break;case"[":if(e.token!==19&&e.token!==17&&e.token!==30&&e.token!==31&&n!=="]"){te(e),ne(e,17),e.pending=n;continue}break;case"!":if(e.token!==19&&n==="["){te(e),ne(e,19),e.pending="";continue}break;case" ":if(e.pending.length===1&&n===" ")continue;break}if(e.token!==19&&e.token!==17&&e.token!==30&&e.token!==31&&n==="h"&&(e.pending===" "||e.pending==="")){e.text+=e.pending,e.pending=n,e.token=102;continue}e.text+=e.pending,e.pending=n}te(e)}function Yr(e){return{add_token:ku,end_token:Cu,add_text:Tu,set_attr:Eu,data:{nodes:[e,,,,,],index:0}}}function ku(e,t){let n=e.nodes[e.index],o;switch(t){case 1:return;case 20:o=document.createElement("blockquote");break;case 2:o=document.createElement("p");break;case 21:o=document.createElement("br");break;case 22:o=document.createElement("hr");break;case 3:o=document.createElement("h1");break;case 4:o=document.createElement("h2");break;case 5:o=document.createElement("h3");break;case 6:o=document.createElement("h4");break;case 7:o=document.createElement("h5");break;case 8:o=document.createElement("h6");break;case 12:case 13:o=document.createElement("em");break;case 14:case 15:o=document.createElement("strong");break;case 16:o=document.createElement("s");break;case 11:o=document.createElement("code");break;case 18:case 17:o=document.createElement("a");break;case 19:o=document.createElement("img");break;case 23:o=document.createElement("ul");break;case 24:o=document.createElement("ol");break;case 25:o=document.createElement("li");break;case 26:let i=o=document.createElement("input");i.type="checkbox",i.disabled=!0;break;case 9:case 10:n=n.appendChild(document.createElement("pre")),o=document.createElement("code");break;case 27:o=document.createElement("table");break;case 28:switch(n.children.length){case 0:n=n.appendChild(document.createElement("thead"));break;case 1:n=n.appendChild(document.createElement("tbody"));break;default:n=n.children[1]}o=document.createElement("tr");break;case 29:o=document.createElement(n.parentElement?.tagName==="THEAD"?"th":"td");break;case 30:o=document.createElement("equation-block");break;case 31:o=document.createElement("equation-inline");break}e.nodes[++e.index]=n.appendChild(o)}function Cu(e){e.index-=1}function Tu(e,t){e.nodes[e.index].appendChild(document.createTextNode(t))}function Eu(e,t,n){e.nodes[e.index].setAttribute(bu(t),n)}function Eo({textSig:e,doneSig:t}){let n=O(null);return ht(()=>{let o=n.current;if(!o)return;o.classList.add(`${x.cssPrefix}-md`);let i=Yr(o),a=Xr(i),l=0,s=nt(()=>{let u=e.value,_=t.value;u.length<l&&(o.replaceChildren(),i=Yr(o),a=Xr(i),l=0);let g=u.slice(l);g&&Ce(a,g),l=u.length,_&&vl(a)}),c=new MutationObserver(u=>{for(let _ of u)for(let g of _.addedNodes){if(!(g instanceof HTMLElement))continue;let f=g.matches?.("a")?[g]:[...g.querySelectorAll?.("a")??[]];for(let m of f)bl(m)}});c.observe(o,{childList:!0,subtree:!0});for(let u of o.querySelectorAll("a"))bl(u);let d=u=>{let _=u.target?.closest?.("a");if(!_||!(_ instanceof HTMLAnchorElement))return;let g=_.getAttribute("href")??"";!g||g.startsWith("#")||(u.preventDefault(),window.open(g,"_blank","noopener,noreferrer"))};return o.addEventListener("click",d),()=>{s(),c.disconnect(),o.removeEventListener("click",d)}},[e,t]),r("div",{ref:n})}function Pl({text:e}){let t=Re(()=>H(e),[e]),n=Re(()=>H(!0),[]);return r(Eo,{textSig:t,doneSig:n})}function bl(e){let t=e.getAttribute("href")??"";if(!t||t.startsWith("#"))return;e.target!=="_blank"&&(e.target="_blank");let n=new Set((e.rel||"").split(/\s+/).filter(Boolean));n.add("noopener"),n.add("noreferrer"),e.rel=[...n].join(" ")}var Ft=x.cssPrefix;function xl({part:e,strings:t}){let n=e.title||e.filename||e.url||t.sources;return e.url?r("a",{class:`${Ft}-source`,href:e.url,target:"_blank",rel:"noreferrer noopener","data-testid":w.source,children:[r("span",{class:`${Ft}-source-icon`,"aria-hidden":"true",children:"\u{1F517}"}),r("span",{class:`${Ft}-source-label`,children:n})]}):r("span",{class:`${Ft}-source`,"data-testid":w.source,children:[r("span",{class:`${Ft}-source-icon`,"aria-hidden":"true",children:"\u{1F4C4}"}),r("span",{class:`${Ft}-source-label`,children:n})]})}var it=x.cssPrefix;function Ro(e){return e.startsWith("tool:")||e.startsWith("tool-")?e.slice(5):e}function Ao(e,t){let n=e==="output-available"||e==="output-error"||e==="output-denied",o=e==="approval-responded"||t?.approved!==void 0;return{terminal:n,responded:o,decided:n||o}}function Au(e,t){return e==="output-error"?"error":e==="output-denied"||t?.approved===!1?"denied":e==="output-available"?"completed":e==="approval-responded"||t?.approved===!0?"responded":e==="approval-requested"?"awaiting":"running"}function Iu({status:e}){return e==="denied"||e==="error"||e==="superseded"?r(Ys,{}):e==="completed"||e==="responded"?r(Xs,{}):r(js,{})}function Lu(e,t){switch(e){case"awaiting":return t.statusAwaiting;case"responded":return t.statusResponded;case"completed":return t.statusCompleted;case"denied":return t.statusDenied;case"error":return t.statusError;case"superseded":return t.statusSuperseded;default:return t.statusRunning}}function Mu({state:e,approval:t,strings:n,superseded:o}){let i=Au(e,t),a=o&&(i==="awaiting"||i==="running")?"superseded":i;return r("span",{class:`${it}-toolui-badge ${it}-toolui-status`,"data-status":a,children:[r("span",{class:`${it}-toolui-status-icon`,children:r(Iu,{status:a})}),Lu(a,n)]})}function Io({name:e,state:t,approval:n,strings:o,superseded:i}){return r(ee,{children:[r("span",{class:`${it}-toolui-wrench`,children:r(Ks,{})}),r("strong",{class:`${it}-toolui-title`,children:e}),r(Mu,{state:t,approval:n,strings:o,superseded:i}),r("span",{class:`${it}-toolui-chevron`,children:r(go,{})})]})}function dt({label:e,value:t,error:n}){let o=n?String(t??""):Lo(Jr(t));return o?r("div",{class:`${it}-toolui-section`,children:[r("span",{class:`${it}-toolui-label`,children:e}),r("pre",{class:`${it}-toolui-code`,"data-error":n?"true":void 0,children:o})]}):null}function Jr(e){if(e&&typeof e=="object"){let t=e;if(t.storage==="tool-result-ref"&&"summary"in t)return t.summary}return e}function Lo(e){if(e==null)return"";try{let t=typeof e=="string"?e:JSON.stringify(e,null,2);return!t||t==="{}"||t==="[]"||t==='""'?"":t.length>800?`${t.slice(0,800)}\u2026`:t}catch{return""}}var Ae=x.cssPrefix;function yl({part:e,strings:t,active:n,superseded:o=!1,onDecision:i,onEdit:a}){let l=j(()=>e.approvalSig.value),s=j(()=>e.stateSig.value),c=j(()=>e.inputSig.value),d=j(()=>e.outputSig.value),u=j(()=>e.errorSig.value),_=Ro(e.toolName),g=l.value?.approved,{terminal:f,responded:m,decided:C}=Ao(s.value,l.value),v=m&&n&&!f,b=o&&!C,y=e.toolCallId;return r("div",{class:`${Ae}-toolui-group`,"data-testid":C?w.toolDecision:w.toolApproval,children:[r("details",{class:`${Ae}-toolui ${Ae}-toolui-collapsible`,children:[r("summary",{class:`${Ae}-toolui-head`,children:r(Io,{name:_,state:s.value,approval:l.value,strings:t,superseded:b})}),r(dt,{label:t.toolParameters,value:c.value}),d.value!==void 0?r(dt,{label:t.toolResult,value:d.value}):null,u.value?r(dt,{label:t.statusError,value:u.value,error:!0}):null]}),b||f?null:r("div",{class:`${Ae}-toolui ${Ae}-toolui-body`,children:[m?r(ee,{children:[r("p",{class:`${Ae}-toolui-prompt`,children:[t.approvalYourResponse.replace("{decision}",g?t.approve:t.reject),l.value?.reason?` \u2014 ${l.value.reason}`:""]}),v?r("p",{class:`${Ae}-toolui-subtle`,children:t.approvalEditHint}):null,!v&&!f?r("p",{class:`${Ae}-toolui-subtle`,children:t.approvalSubmitting}):null]}):r(ee,{children:[r("p",{class:`${Ae}-toolui-prompt`,children:t.approvalPrompt.replace("{tool}",_)}),r("p",{class:`${Ae}-toolui-subtle`,children:t.approvalBody})]}),!C&&n?r("div",{class:`${Ae}-toolui-actions`,children:[r("button",{type:"button",class:`${Ae}-form-skip`,onClick:()=>i(y,!1),"data-testid":w.toolReject,children:t.reject}),r("button",{type:"button",class:`${Ae}-form-submit`,onClick:()=>i(y,!0),"data-testid":w.toolApprove,children:t.approve})]}):v?r("div",{class:`${Ae}-toolui-actions`,children:r("button",{type:"button",class:`${Ae}-form-skip`,onClick:()=>a(y),"data-testid":w.toolEdit,children:t.edit})}):null]})]})}function wl(e){let t=e&&typeof e=="object"?e:{},n=t.responseType;return{title:fn(t.title),question:fn(t.question)??"Please provide the missing information.",description:fn(t.description),placeholder:fn(t.placeholder),responseType:n==="single-choice"||n==="multi-choice"||n==="confirmation"||n==="free-text"?n:"free-text",choices:Array.isArray(t.choices)?t.choices:void 0,allowOther:typeof t.allowOther=="boolean"?t.allowOther:void 0,required:typeof t.required=="boolean"?t.required:!0,defaultValues:Array.isArray(t.defaultValues)?t.defaultValues.filter(o=>typeof o=="string"):void 0,minSelections:Sl(t.minSelections),maxSelections:Sl(t.maxSelections),validationHint:fn(t.validationHint)}}function kl(e){if(e.responseType==="confirmation")return[];let t=(e.choices??[]).map(Nu).filter(i=>i!==null),n="textarea";e.responseType==="single-choice"&&t.length>0?n="radio":e.responseType==="multi-choice"&&(n="multiselect");let o=n==="multiselect"?e.defaultValues?.join(", "):e.defaultValues?.[0];return[{name:"answer",label:e.question,type:n,placeholder:e.placeholder,required:e.required??!0,defaultValue:o,options:t.length>0?t:void 0,allowOther:e.allowOther,validationHint:e.validationHint,validation:n==="multiselect"?{minSelections:e.minSelections,maxSelections:e.maxSelections}:void 0}]}function Nu(e){return typeof e=="string"?e?{value:e,label:e}:null:e&&typeof e.value=="string"&&e.value?{value:e.value,label:e.label??e.value,description:e.description}:null}function fn(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Sl(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}var oe=x.cssPrefix;function Ou(e,t){switch(e.responseType){case"single-choice":return t.respSingleChoice;case"multi-choice":return t.respMultiChoice;case"confirmation":return t.respConfirmation;default:return t.respFreeText}}function Cl({part:e,strings:t,active:n,superseded:o=!1,onSubmit:i,onDecision:a,onEdit:l}){let s=j(()=>e.stateSig.value),c=j(()=>e.approvalSig.value),d=j(()=>wl(e.inputSig.value)),{terminal:u,responded:_,decided:g}=Ao(s.value,c.value),f=c.value!==void 0,m=(b,y)=>{f?a(e.toolCallId,y,b):d.value.responseType==="confirmation"?i(e.toolCallId,{confirmed:y}):i(e.toolCallId,y?{answer:b}:{})},C=d.value;if(g)return r(Hu,{part:e,strings:t,req:C,editable:_&&n&&!u,onEdit:()=>l(e.toolCallId)});let v=o;return r("div",{class:`${oe}-toolui${v?` ${oe}-toolui-stale`:""}`,"data-testid":w.toolAskInput,children:[r("div",{class:`${oe}-toolui-head`,children:v?r(ee,{children:[r("span",{class:`${oe}-toolui-badge ${oe}-toolui-badge-accent`,children:t.inputBadge}),r("span",{class:`${oe}-toolui-badge ${oe}-toolui-badge-muted`,children:t.statusSuperseded})]}):r(ee,{children:[r("span",{class:`${oe}-toolui-badge ${oe}-toolui-badge-accent`,children:t.inputRequired}),r("span",{class:`${oe}-toolui-badge`,children:Ou(C,t)})]})}),C.description?r("div",{class:`${oe}-toolui-desc`,children:C.description}):null,r(Qr,{label:t.inputQuestion,text:C.question}),v?null:r(Du,{req:C,strings:t,resolve:m})]})}function Du({req:e,strings:t,resolve:n}){if(e.responseType==="confirmation")return r($u,{req:e,strings:t,resolve:n});let o=kl(e).map(i=>(i.label=t.inputYourAnswer,i.placeholder=i.placeholder??t.inputAnswerPlaceholder,i));return r(Co,{fields:o,strings:t,submitLabel:t.inputSubmit,footerHint:e.responseType==="free-text"?t.inputSubmitHint:void 0,onSubmit:i=>n(i.answer??Object.values(i).join(", "),!0),skipLabel:t.inputSkip,onSkip:()=>n(void 0,!1),submitOnEnter:!0,submitTestId:w.toolInputSubmit,skipTestId:w.toolInputSkip})}function $u({req:e,strings:t,resolve:n}){let[o,i]=A(""),a=e.allowOther??!0,l=()=>n(o.trim()||void 0,!0),s=()=>n(void 0,!1),c=d=>{d.key!=="Enter"||d.shiftKey||d.isComposing||(d.preventDefault(),l())};return r(ee,{children:[a?r("label",{class:`${oe}-field`,children:[r("span",{class:`${oe}-field-label`,children:t.inputOptionalNote}),r("textarea",{class:`${oe}-field-input`,rows:2,value:o,placeholder:e.placeholder??t.inputOptionalNotePlaceholder,onInput:d=>i(d.target.value),onKeyDown:c,"data-testid":`${w.formField}-note`})]}):null,r("div",{class:`${oe}-form-actions`,children:[r("span",{class:`${oe}-form-hint`,children:t.inputConfirmHint}),r("button",{type:"button",class:`${oe}-form-skip`,onClick:s,"data-testid":w.toolInputSkip,children:t.confirmNo}),r("button",{type:"button",class:`${oe}-form-submit`,onClick:l,"data-testid":w.toolInputSubmit,children:t.confirmYes})]})]})}function Qr({label:e,text:t}){return r("div",{class:`${oe}-toolui-section`,children:[r("span",{class:`${oe}-toolui-label`,children:e}),r("p",{class:`${oe}-toolui-text`,children:t})]})}function Hu({part:e,strings:t,req:n,editable:o,onEdit:i}){let a=j(()=>e.outputSig.value),l=j(()=>e.approvalSig.value),s=l.value?.approved===!1,c=l.value?.approved!==void 0?l.value.reason??"":Bu(a.value,t);return r("div",{class:`${oe}-toolui`,"data-testid":w.toolDecision,children:[r("div",{class:`${oe}-toolui-head`,children:[r("span",{class:`${oe}-toolui-badge ${oe}-toolui-badge-accent`,children:t.inputBadge}),r("span",{class:`${oe}-toolui-badge`,children:s?t.inputSkipped:t.inputAnswered})]}),n.description?r("div",{class:`${oe}-toolui-desc`,children:n.description}):null,r(Qr,{label:t.inputQuestion,text:n.question}),!s&&c?r(Qr,{label:t.inputYourAnswer,text:c}):null,o?r("div",{class:`${oe}-toolui-actions`,children:r("button",{type:"button",class:`${oe}-form-skip`,onClick:i,"data-testid":w.toolEdit,children:t.edit})}):null]})}function Bu(e,t){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="object"){let n=e;return"confirmed"in n?n.confirmed?t.confirmYes:t.confirmNo:typeof n.responseText=="string"&&n.responseText?n.responseText:Object.values(n).filter(o=>typeof o=="string"||typeof o=="number").join(", ")}return String(e)}var Zr=x.cssPrefix;function Tl({part:e,strings:t}){let n=j(()=>e.inputSig.value),o=j(()=>e.outputSig.value),i=j(()=>e.errorSig.value),a=j(()=>e.stateSig.value),l=j(()=>e.approvalSig.value);return j(()=>!!Lo(n.value)||!!i.value||!!Lo(Jr(o.value))).value?r("details",{class:`${Zr}-toolui ${Zr}-toolui-collapsible`,"data-testid":w.toolCall,children:[r("summary",{class:`${Zr}-toolui-head`,children:r(Io,{name:Ro(e.toolName),state:a.value,approval:l.value,strings:t})}),r(dt,{label:t.toolParameters,value:n.value}),o.value!==void 0?r(dt,{label:t.toolResult,value:o.value}):null,i.value?r(dt,{label:t.statusError,value:i.value,error:!0}):null]}):null}var De=x.cssPrefix;function El({message:e,strings:t,responseMode:n,showReasoning:o,showToolCalls:i,showSources:a,interactive:l=!1,superseded:s=!1,tool:c,onRetry:d}){let _=j(()=>e.partsSig.value).value,g=j(()=>ot(e)),f=j(()=>us(e)),m=j(()=>e.partsSig.value.some(B=>B.kind==="text"&&B.textSig.value.length>0)),C=j(()=>o&&e.partsSig.value.some(B=>B.kind==="reasoning")),v=e.role==="assistant"&&e.status==="streaming",b=n==="buffered"&&v,y=v&&!m.value,P=v&&!b&&!(C.value&&y);if(f.value)return null;let E=Fu(e.createdAt);return r("div",{class:`${De}-bubble-row`,"data-role":e.role,"data-testid":xe(w.messageBubble,e.id),children:r("div",{class:`${De}-bubble-col`,children:[r("div",{class:`${De}-bubble`,children:[b?r(Gu,{label:t.loading}):_.map(B=>r(zu,{part:B,active:y,strings:t,showReasoning:o,showToolCalls:i,showSources:a,interactive:l,superseded:s,tool:c},Wu(B))),P&&r(qu,{}),e.status==="error"&&e.errorText||g.value?r("div",{class:`${De}-error`,role:"alert",children:[r("span",{children:e.errorText??t.errorGeneric}),d?r("button",{type:"button",class:`${De}-error-retry`,onClick:d,"data-testid":w.messageRetry,children:t.errorRetry}):null]}):null]}),E?r("time",{class:`${De}-bubble-time`,dateTime:E.iso,title:E.full,children:E.short}):null]})})}function Fu(e){if(typeof e!="number"||!Number.isFinite(e))return null;try{let t=new Date(e);return{short:t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),full:t.toLocaleString(void 0,{dateStyle:"full",timeStyle:"short"}),iso:t.toISOString()}}catch{return null}}function zu({part:e,active:t,strings:n,showReasoning:o,showToolCalls:i,showSources:a,interactive:l,superseded:s,tool:c}){switch(e.kind){case"step-start":return null;case"text":return r(Eo,{textSig:e.textSig,doneSig:e.doneSig});case"reasoning":return o?r(Vu,{part:e,active:t,strings:n}):null;case"tool":return r(Uu,{part:e,strings:n,showToolCalls:i,interactive:l,superseded:s,tool:c});case"file":return e.mediaType.startsWith("image/")?r("img",{src:e.url,alt:"",loading:"lazy"}):r("a",{href:e.url,target:"_blank",rel:"noreferrer noopener",children:e.url});case"source":return a?r(xl,{part:e,strings:n}):null}}function Uu({part:e,strings:t,showToolCalls:n,interactive:o,superseded:i,tool:a}){let l=j(()=>e.approvalSig.value!==void 0);if(a?.humanInLoop){if(ul(e.toolName))return r(Cl,{part:e,strings:t,active:o,superseded:i,onSubmit:a.onResult,onDecision:a.onDecision,onEdit:a.onEdit});if(l.value)return r(yl,{part:e,strings:t,active:o,superseded:i,onDecision:a.onDecision,onEdit:a.onEdit})}return n?r(Tl,{part:e,strings:t}):null}function Vu({part:e,active:t,strings:n}){return r("details",{class:`${De}-reasoning`,open:t,"data-active":t?"true":void 0,children:[r("summary",{class:`${De}-reasoning-summary`,children:r("span",{class:`${De}-reasoning-label`,children:t?n.thinking:n.thoughts})}),r("div",{class:`${De}-reasoning-body`,children:r(Eo,{textSig:e.textSig,doneSig:e.doneSig})})]})}function Wu(e){switch(e.kind){case"text":case"reasoning":case"step-start":return`${e.kind}:${e.id}`;case"tool":return`tool:${e.toolCallId}`;case"file":return`file:${e.url}`;case"source":return`source:${e.sourceId}`}}function qu(){return r("span",{class:`${De}-typing`,"aria-hidden":"true",children:[r("span",{}),r("span",{}),r("span",{})]})}function Gu({label:e}){return r("span",{class:`${De}-loading`,role:"status",children:[r("span",{class:`${De}-loading-spinner`,"aria-hidden":"true"}),r("span",{class:`${De}-loading-label`,children:e})]})}var zt=x.cssPrefix,ei=120,Ku=350;function Rl({messagesSig:e,strings:t,responseMode:n,showReasoning:o,showToolCalls:i,showSources:a,loading:l,idle:s,tool:c,onRetry:d,form:u,formMarkers:_,onFillForm:g}){let f=O(null),m=j(()=>e.value),[C,v]=A(!1),b=O(!1),y=O(!1),P=O(!1),E=O(0),B=()=>P.current||performance.now()-E.current<Ku,le=O(0),M=S=>{le.current=performance.now(),S.scrollTop=S.scrollHeight},Z=(S,z)=>{M(S);let be=z,Se=0,he=()=>{M(S),--be>0&&(Se=requestAnimationFrame(he))};return z>0&&(Se=requestAnimationFrame(he)),()=>cancelAnimationFrame(Se)},F=(S,z)=>{let be,Se,he,Ge=-1,Ke=()=>{be.disconnect(),Se.disconnect(),clearTimeout(he)},Ze=()=>{if(y.current||B()||Ge>=0&&S.scrollTop<Ge-4)return Ke();M(S),Ge=S.scrollTop};return be=new ResizeObserver(Ze),Se=new MutationObserver(Ze),Ze(),be.observe(S),Se.observe(S,{childList:!0,subtree:!0,characterData:!0}),he=setTimeout(Ke,z),Ke},G=m.value[0]?.id;ht(()=>{let S=f.current;if(S&&m.value.length!==0&&(b.current=!0,!!m.value.some(z=>z.role==="user")))return F(S,300)},[G]);let Y=O(0);R(()=>{let S=f.current,z=m.value,be=Y.current;if(Y.current=z.length,!S||!b.current)return;if(z.slice(be).some(he=>he.role==="user"))return y.current=!1,Z(S,3);if(!z.some(he=>he.role==="user")||y.current||B())return;S.scrollHeight-S.scrollTop-S.clientHeight<ei&&M(S)},[m.value.length]);let ve=O(null);R(()=>{let S=f.current,z=m.value.at(-1),be=ve.current;if(ve.current=z?.id??null,!!S&&b.current&&!(!z||z.id!==be||z.status!=="streaming"))return y.current=!1,Z(S,3)},[m.value]),R(()=>{let S=f.current;if(!S)return;let z=m.value.at(-1);if(!z||z.status!=="streaming"&&!m.value.some(he=>he.role==="user"))return;let be=()=>{if(y.current||B())return;S.scrollHeight-S.scrollTop-S.clientHeight<ei*2&&M(S)};if(z.status!=="streaming"){let he=requestAnimationFrame(be);return()=>cancelAnimationFrame(he)}be();let Se=new MutationObserver(be);return Se.observe(S,{childList:!0,subtree:!0,characterData:!0}),()=>Se.disconnect()},[m.value]);let k=u?.form.id,K=!!u&&(_??[]).some(S=>S.formId===u.form.id);ht(()=>{let S=f.current;!S||!k||y.current||m.value.some(z=>z.role==="user")&&(K?S.querySelector(`[data-testid="${w.formGate}"]`)?.scrollIntoView({block:"nearest"}):M(S))},[k,K]),R(()=>{let S=f.current;if(!S)return;let z=()=>v(S.scrollHeight-S.scrollTop-S.clientHeight>ei*2),be=()=>{z(),performance.now()-le.current>150&&(y.current=S.scrollHeight-S.scrollTop-S.clientHeight>8)},Se=()=>{y.current=!0},he=Fe=>{Fe.deltaY<0&&Se()},Ge=0,Ke=Fe=>{Ge=Fe.touches[0]?.clientY??0,P.current=!0},Ze=Fe=>{(Fe.touches[0]?.clientY??0)>Ge+4&&Se()},Be=()=>{P.current=!1,E.current=performance.now()},Le=()=>{P.current=!0};return S.addEventListener("scroll",be,{passive:!0}),S.addEventListener("wheel",he,{passive:!0}),S.addEventListener("touchstart",Ke,{passive:!0}),S.addEventListener("touchmove",Ze,{passive:!0}),S.addEventListener("touchend",Be,{passive:!0}),S.addEventListener("touchcancel",Be,{passive:!0}),S.addEventListener("pointerdown",Le,{passive:!0}),window.addEventListener("pointerup",Be,{passive:!0}),window.addEventListener("pointercancel",Be,{passive:!0}),z(),()=>{S.removeEventListener("scroll",be),S.removeEventListener("wheel",he),S.removeEventListener("touchstart",Ke),S.removeEventListener("touchmove",Ze),S.removeEventListener("touchend",Be),S.removeEventListener("touchcancel",Be),S.removeEventListener("pointerdown",Le),window.removeEventListener("pointerup",Be),window.removeEventListener("pointercancel",Be)}},[]);let re=()=>{let S=f.current;S&&(y.current=!1,M(S))},de=[],ue="",Ie=m.value.at(-1)?.id,ie=[..._??[]].toSorted((S,z)=>(S.createdAt??1/0)-(z.createdAt??1/0)),ye=S=>u&&S.formId===u.form.id?r(Wr,{form:u.form,strings:t,onSubmit:u.onSubmit,onSkip:u.onSkip},`gate:${S.formId}`):r(_l,{marker:S,strings:t,onFill:!u&&g?()=>g(S.formId):void 0},S.key),Qe=S=>{for(let z=ie[0];z?.createdAt!==void 0&&!(S!==void 0&&z.createdAt>S);z=ie[0])ie.shift(),de.push(ye(z))};for(let S of m.value){if(S.role==="assistant"&&S.id!==Ie&&ot(S))continue;Qe(S.createdAt);let z=ju(S.createdAt);z&&z!==ue&&(de.push(r("div",{class:`${zt}-date-divider`,children:r("span",{class:`${zt}-date-pill`,title:Xu(S.createdAt),children:Yu(S.createdAt,t)})},`day:${z}`)),ue=z),de.push(r(El,{message:S,strings:t,responseMode:n,showReasoning:o,showToolCalls:i,showSources:a,interactive:!!s&&S.id===Ie,superseded:S.id!==Ie,tool:c,onRetry:s&&S.id===Ie?d:void 0},S.id))}for(let S of ie)de.push(ye(S));return r("div",{class:`${zt}-list-wrap`,children:[r("div",{ref:f,class:`${zt}-list`,role:"log","aria-live":"polite","aria-relevant":"additions text",children:[l&&m.value.length===0?r("div",{class:`${zt}-list-loading`,role:"status",children:t.conversationLoading}):null,de,u&&!K?r(Wr,{form:u.form,strings:t,onSubmit:u.onSubmit,onSkip:u.onSkip}):null]}),C?r("button",{type:"button",class:`${zt}-jump`,onClick:re,"aria-label":t.scrollToBottom,title:t.scrollToBottom,"data-testid":w.scrollToBottom,children:r(go,{})}):null]})}function ju(e){if(typeof e!="number"||!Number.isFinite(e))return"";let t=new Date(e);return`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`}function Xu(e){if(typeof e!="number"||!Number.isFinite(e))return"";try{return new Date(e).toLocaleDateString(void 0,{dateStyle:"full"})}catch{return""}}function Yu(e,t){let n=new Date(e),o=a=>new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),i=Math.round((o(new Date)-o(n))/864e5);return i<=0?t.dateToday:i===1?t.dateYesterday:i<7?n.toLocaleDateString(void 0,{weekday:"long"}):n.toLocaleDateString(void 0,{month:"long",day:"numeric",year:"numeric"})}var Ju=["today","yesterday","lastWeek","older"];function Qu(e,t){let n=Date.parse(t);if(!Number.isFinite(n))return"older";let o=Math.floor((Al(e)-Al(n))/(1440*60*1e3));return o<=0?"today":o===1?"yesterday":o<7?"lastWeek":"older"}function Il(e,t){let n=new Map;for(let o of t){let i=Qu(e,o.lastMessageAt),a=n.get(i);a?a.push(o):n.set(i,[o])}return Ju.filter(o=>n.has(o)).map(o=>({bucket:o,conversations:n.get(o)}))}function Al(e){let t=new Date(e);return t.setUTCHours(0,0,0,0),t.getTime()}var Zu=X.scope("history"),ep=3,tp=6,np={today:"dateToday",yesterday:"dateYesterday",lastWeek:"dateLastWeek",older:"dateOlder"};function op(e,t,n){let o=Date.parse(e);return Number.isFinite(o)?new Date(o).toDateString()===new Date(t).toDateString()?new Intl.DateTimeFormat(n,{hour:"numeric",minute:"2-digit"}).format(o):t-o<10080*60*1e3?new Intl.DateTimeFormat(n,{weekday:"short"}).format(o):new Intl.DateTimeFormat(n,{month:"short",day:"numeric"}).format(o):""}function Mo({transport:e,strings:t,locale:n,persistence:o,visitorId:i,onSelect:a,onNewConversation:l}){let s=x.cssPrefix,c=e.peekConversations({visitorId:i}),[d,u]=A(c?"loaded":"loading"),[_,g]=A(c?.conversations??[]);R(()=>{let v=!1;return e.listConversations({visitorId:i}).then(b=>{if(v)return;let y=b.conversations??[];g(y),u("loaded"),o.saveHistoryCount(y.length)}).catch(b=>{v||(Zu.warn("listConversations failed",{err:b}),u("error"))}),()=>{v=!0}},[e,i,o]);let f=l?r("div",{class:`${s}-history-footer`,children:r("button",{type:"button",class:`${s}-history-new`,onClick:l,"data-testid":w.sidebarNewConversation,children:[r(Ps,{}),t.newConversation]})}):null;if(d==="loading"){let v=Math.min(o.loadHistoryCount()??ep,tp);return r(ee,{children:[r("div",{class:`${s}-history`,"aria-busy":"true","aria-label":t.historyLoading,children:r("div",{class:`${s}-history-group`,"aria-hidden":"true",children:[r("div",{class:`${s}-history-heading`,children:r("span",{class:`${s}-skeleton ${s}-skeleton-heading`})}),r("div",{class:`${s}-history-card`,children:Array.from({length:Math.max(1,v)},(b,y)=>r("div",{class:`${s}-history-item ${s}-history-item-skeleton`,children:[r("span",{class:`${s}-history-avatar ${s}-skeleton`}),r("span",{class:`${s}-history-body`,children:[r("span",{class:`${s}-history-row`,children:[r("span",{class:`${s}-history-title`,children:r("span",{class:`${s}-skeleton ${s}-skeleton-title`})}),r("span",{class:`${s}-history-time`,children:r("span",{class:`${s}-skeleton ${s}-skeleton-time`})})]}),r("span",{class:`${s}-history-row`,children:r("span",{class:`${s}-history-preview`,children:r("span",{class:`${s}-skeleton ${s}-skeleton-preview`})})})]})]},y))})]})}),f]})}if(d==="error"||_.length===0)return r(ee,{children:[r("div",{class:`${s}-history-empty`,children:t.historyEmpty}),f]});let m=Date.now(),C=Il(m,_);return r(ee,{children:[r("div",{class:`${s}-history`,role:"list",children:C.map(v=>r("div",{class:`${s}-history-group`,children:[r("div",{class:`${s}-history-heading`,children:t[np[v.bucket]]}),r("div",{class:`${s}-history-card`,children:v.conversations.map(b=>r("button",{type:"button",role:"listitem",class:`${s}-history-item`,onClick:()=>a(b),"data-closed":b.canContinue?void 0:"true","data-unread":(b.unreadCount??0)>0?"true":void 0,"data-testid":xe(w.historyItem,b.conversationId),children:[r("span",{class:`${s}-history-avatar`,"aria-hidden":"true",children:r(Dr,{})}),r("span",{class:`${s}-history-body`,children:[r("span",{class:`${s}-history-row`,children:[r("span",{class:`${s}-history-title`,children:b.title}),r("span",{class:`${s}-history-time`,children:op(b.lastMessageAt,m,n)})]}),r("span",{class:`${s}-history-row`,children:[r("span",{class:`${s}-history-preview`,children:b.preview??(b.canContinue?t.historyContinue:t.conversationClosed)}),(b.unreadCount??0)>0?r("span",{class:`${s}-history-dot`}):null]})]})]},b.conversationId))})]},v.bucket))}),f]})}var Ll=x.cssPrefix;function Ml({suggestions:e,onPick:t}){return e.length===0?null:r("div",{class:`${Ll}-suggestions`,role:"group","aria-label":"Suggested replies",children:e.map((n,o)=>r("button",{type:"button",class:`${Ll}-suggestion`,onClick:()=>t(n),"data-testid":xe(w.suggestion,o),children:n.label},n.id))})}var Ne=x.cssPrefix;function Nl(e){let{options:t,onClose:n}=e,o=t.strings,i=O(null);R(()=>{let c=i.current;if(!c)return;let d=xo(c),u=_=>{_.key==="Escape"&&n?.()};return c.addEventListener("keydown",u),()=>{d(),c.removeEventListener("keydown",u)}},[n]);let a=O(null),l=D(c=>{a.current?.attachFromDrop(c)},[]),{visible:s}=wo({containerRef:i,onDrop:l});return bo(i.current,t.mode==="modal"),r("div",{ref:i,class:`${Ne}-panel`,role:"dialog","aria-modal":"false","aria-label":o.panelTitle,style:{position:"relative"},"data-testid":w.panel,children:[r(ti,{...e,containerEl:i.current,dragOver:s,composerAttachApiRef:a}),r(ni,{poweredBy:e.options.poweredBy})]})}function ti(e){let{options:t,transport:n,feedback:o,bus:i,persistence:a,panelSize:l,view:s,canSend:c,isStreaming:d,loadingMessages:u,messagesSig:_,agent:g,suggestions:f,initialWidgetSize:m,visitorId:C,onClose:v,onBack:b,onClear:y,onToggleHistory:P,onSelectHistoryConversation:E,onNewConversation:B,onWidgetSizeChange:le,onSend:M,onStop:Z,onSuggestion:F,activeForm:G,formMarkers:Y,onFormSubmit:ve,onFormSkip:k,onFormFill:K,tool:re,onRetry:de,containerEl:ue,dragOver:Ie,composerAttachApiRef:ie}=e,ye=t.strings,Qe;return G?Qe=null:c?Qe=r(ee,{children:[r(Ml,{suggestions:f,onPick:F}),r(il,{options:t,transport:n,feedback:o,bus:i,isStreaming:d,onSend:M,onStop:Z,attachApiRef:ie})]}):Qe=r(ip,{label:ye.conversationClosed,ctaLabel:ye.startNewConversation,onNewConversation:y}),r(ee,{children:[s==="history"?r(rp,{strings:ye,onBack:P,onClose:v,showClose:Po(t.mode,l,t.actions)}):r("header",{class:`${Ne}-header`,"data-testid":w.panelHeader,children:[b?r("button",{type:"button",class:`${Ne}-icon-btn`,onClick:b,"aria-label":ye.moduleBack,title:ye.moduleBack,children:r(_n,{})}):null,g?r(nl,{agent:g,strings:ye}):r("h1",{children:ye.panelTitle}),r(Ye,{panelProps:e,variant:"chat"})]}),s==="history"?r(Mo,{transport:n,strings:ye,locale:t.locale,persistence:a,visitorId:C,onSelect:S=>E(S.conversationId),onNewConversation:B}):r(ee,{children:[r(al,{visible:Ie,strings:ye}),r(Rl,{messagesSig:_,strings:ye,responseMode:t.responseMode,showReasoning:t.showReasoning,showToolCalls:t.showToolCalls,showSources:t.showSources,loading:u,idle:!d,tool:re,onRetry:de,form:G?{form:G,onSubmit:ve,onSkip:k}:null,formMarkers:Y,onFillForm:K}),Qe,r(ap,{disclaimer:t.composerDisclaimer})]}),t.size.resize?.enabled?r(vo,{panelEl:ue,resize:t.size.resize,position:t.position,initialSize:m,onSizeChange:le,strings:ye}):null]})}function rp({strings:e,onBack:t,onClose:n,showClose:o}){return r("header",{class:`${Ne}-header`,children:[r("button",{type:"button",class:`${Ne}-icon-btn`,onClick:t,"aria-label":e.historyBack,title:e.historyBack,children:r(_n,{})}),r("h1",{children:e.historyTitle}),o?r("button",{type:"button",class:`${Ne}-icon-btn`,onClick:n,"aria-label":e.close,title:e.close,children:r(Xe,{})}):null]})}function ip({label:e,ctaLabel:t,onNewConversation:n}){return r("div",{class:`${Ne}-readonly-banner`,role:"note",children:[r("span",{class:`${Ne}-readonly-label`,children:e}),r("button",{type:"button",class:`${Ne}-readonly-cta`,onClick:n,children:t})]})}function ap({disclaimer:e}){return e?r("div",{class:`${Ne}-composer-footer`,children:r("div",{class:`${Ne}-disclaimer`,children:e})}):null}function ni({poweredBy:e}){return e?r("div",{class:`${Ne}-poweredby-bar`,children:r(sp,{logoUrl:e.logoUrl,text:e.text,href:e.href})}):null}function sp({logoUrl:e,text:t,href:n}){let o=r(ee,{children:[e?r("img",{class:`${Ne}-poweredby-logo`,src:e,alt:"",loading:"lazy"}):null,t?r("span",{children:t}):null]});return n?r("a",{class:`${Ne}-poweredby`,href:n,target:"_blank",rel:"noopener noreferrer",children:o}):r("span",{class:`${Ne}-poweredby`,children:o})}function Ol(e){let t=O(e);t.current=e;let n=O(null);return n.current??(n.current=lp(t)),n.current}function lp(e){let t=H(null),n=new Set,o=c=>`${e.current.conversationId()??""}:${c}`,i=c=>c.frequency==="always"?!1:c.frequency==="conversation"?n.has(o(c.id)):c.id in e.current.persistence.loadFormsDone(),a=(c,d)=>{if(t.value)return;let u=e.current;if(c==="manual"){let _=u.forms.list.find(g=>g.id===d);_&&(t.value={form:_,trigger:"manual"});return}for(let _ of u.forms.byTrigger[c]??[]){let g=_.triggers.find(f=>f.kind===c);if(!(!g||!cp(g,u)||i(_)||!dp(_,u))){t.value={form:_,trigger:c};return}}},l=(c,d)=>{let u=t.value;if(!u)return;t.value=null;let{form:_,trigger:g}=u;_.frequency==="conversation"?n.add(o(_.id)):_.frequency!=="always"&&e.current.persistence.saveFormDone(_.id),e.current.onComplete(_,g,c,d)};return{activeForm:t,fire:a,refresh:()=>{let c=t.value;if(!c)return;let d=e.current.forms.list.find(u=>u.id===c.form.id);d&&d!==c.form&&(t.value={form:d,trigger:c.trigger})},complete:c=>l(c,!1),skip:()=>l({},!0)}}function cp(e,t){return e.kind==="after-messages"?t.messageCount()>=Number(e.param??0):e.kind==="page-area"?t.pageArea()===e.param:!0}function dp(e,t){let n=e.when;if(!n)return!0;if(n.missingContext?.length){let i=t.userContext()??{};if(n.missingContext.some(a=>i[a]!==void 0&&i[a]!==""))return!1}if(n.pageArea&&!(Array.isArray(n.pageArea)?n.pageArea:[n.pageArea]).includes(t.pageArea()??""))return!1;let o=t.messageCount();return!(n.minMessages!=null&&o<n.minMessages||n.maxMessages!=null&&o>n.maxMessages)}function Dl(e){let t=x.cssPrefix,{site:n,blocks:o,strings:i,collapsed:a}=e,l=o?.navigation??[],s=o?.linkCards??[],c=a?i.expandSidebar:i.collapseSidebar;return r("aside",{class:`${t}-sidebar`,"data-collapsed":a?"true":"false","data-testid":w.sidebar,children:[r("div",{class:`${t}-sidebar-header`,children:[r(_p,{site:n}),r("button",{type:"button",class:`${t}-sidebar-toggle`,"aria-label":c,"aria-expanded":a?"false":"true",title:c,onClick:e.onToggleCollapsed,"data-testid":w.sidebarToggle,children:r(up,{collapsed:a})})]}),a?null:r(ee,{children:[l.length>0?r("nav",{class:`${t}-sidebar-section`,"data-section":"navigation",children:r(pp,{items:l})}):null,s.length>0?r("div",{class:`${t}-sidebar-section`,"data-section":"link-cards",children:r(mp,{items:s})}):null,e.showConversations?r("div",{class:`${t}-sidebar-conversations`,children:r(Mo,{transport:e.transport,strings:e.strings,locale:e.locale,persistence:e.persistence,visitorId:e.visitorId,onSelect:e.onSelectConversation,onNewConversation:e.onNewConversation})}):null]})]})}function _p({site:e}){let t=x.cssPrefix;if(e?.logo?.url){let n=e.logo.alt??e.title??"Logo";return r("picture",{children:[e.logoDark?.url?r("source",{srcset:e.logoDark.url,media:"(prefers-color-scheme: dark)"}):null,r("img",{class:`${t}-sidebar-logo`,src:e.logo.url,alt:n})]})}return r("div",{class:`${t}-sidebar-title`,children:e?.title??x.name})}function up({collapsed:e}){return r("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","aria-hidden":"true",children:e?r("polyline",{points:"9 6 15 12 9 18"}):r("polyline",{points:"15 6 9 12 15 18"})})}function pp({items:e}){let t=x.cssPrefix;return r("ul",{class:`${t}-sidebar-nav`,children:e.map(n=>r("li",{children:r("a",{class:`${t}-sidebar-nav-item`,href:n.href,target:n.href?"_blank":void 0,rel:n.href?"noreferrer":void 0,children:[n.icon?r("span",{class:`${t}-sidebar-nav-icon`,"data-icon":n.icon}):null,r("span",{class:`${t}-sidebar-nav-label`,children:n.label})]})},n.id??n.label))})}function mp({items:e}){let t=x.cssPrefix;return r("div",{class:`${t}-sidebar-cards`,children:e.map(n=>r("a",{class:`${t}-sidebar-card`,href:n.href,target:n.href?"_blank":void 0,rel:n.href?"noreferrer":void 0,children:[r("div",{class:`${t}-sidebar-card-label`,children:n.label}),n.description?r("div",{class:`${t}-sidebar-card-desc`,children:n.description}):null]},n.id??n.label))})}var $l=x.cssPrefix;function Hl(e){return r("main",{class:`${$l}-page-shell`,"data-sidebar-collapsed":e.sidebarCollapsed?"true":"false",children:[r(Dl,{site:e.site,blocks:e.blocks,transport:e.transport,strings:e.strings,locale:e.locale,persistence:e.persistence,visitorId:e.visitorId,showConversations:e.showConversations,onSelectConversation:e.onSelectConversation,onNewConversation:e.onNewConversation,collapsed:e.sidebarCollapsed,onToggleCollapsed:e.onToggleSidebarCollapsed}),r("section",{class:`${$l}-page-chat`,"aria-label":"Chat",children:e.children})]})}var Bl=e=>Object.fromEntries(e.map(t=>[t,[]]));function Fl(e,t,n){let o=H({activeTab:e,stacks:Bl(t)});return{sig:o,switchTab(i){o.value.activeTab!==i&&(o.value={...o.value,activeTab:i},n?.(i))},push(i){let a=o.value,l=a.stacks[a.activeTab]??[];o.value={...a,stacks:{...a.stacks,[a.activeTab]:[...l,i]}}},pop(){let i=o.value,a=i.stacks[i.activeTab]??[];a.length!==0&&(o.value={...i,stacks:{...i.stacks,[i.activeTab]:a.slice(0,-1)}})},reset(i){o.value={activeTab:i,stacks:Bl(t)}}}}var zl=e=>e.stacks[e.activeTab]??[],Ul=e=>zl(e).at(-1),Vl=e=>zl(e).length===0;var Wl={Icon:un};var _t=x.cssPrefix;function No({title:e,actions:t}){return r("header",{class:`${_t}-back-header`,"data-variant":"title",children:[r("span",{class:`${_t}-back-spacer`,"aria-hidden":"true"}),r("h1",{class:`${_t}-back-title`,children:e}),t??r("span",{class:`${_t}-back-spacer`,"aria-hidden":"true"})]})}function Oo({title:e,backLabel:t,onBack:n,actions:o,testid:i}){return r("header",{class:`${_t}-back-header`,"data-testid":i,children:[r("button",{type:"button",class:`${_t}-icon-btn`,onClick:n,"aria-label":t,title:t,children:r(_n,{})}),r("h1",{class:`${_t}-back-title`,children:e}),o??r("span",{class:`${_t}-back-spacer`,"aria-hidden":"true"})]})}var Ut=x.cssPrefix;function ql({placeholder:e,onActivate:t}){return r("button",{type:"button",class:`${Ut}-home-search`,onClick:t,"data-testid":w.homeSearch,children:[r("span",{class:`${Ut}-home-search-text`,children:e}),r("span",{class:`${Ut}-home-search-icon`,"aria-hidden":"true",children:r(Hr,{})})]})}function Gl({placeholder:e,value:t,onInput:n}){return r("div",{class:`${Ut}-home-search`,"data-input":"true",children:[r("input",{type:"search",class:`${Ut}-home-search-input`,placeholder:e,value:t,onInput:o=>n(o.currentTarget.value),"data-testid":w.helpSearch}),r("span",{class:`${Ut}-home-search-icon`,"aria-hidden":"true",children:r(Hr,{})})]})}var gn=x.cssPrefix;function Do({title:e,subtitle:t,onClick:n,testid:o}){return r("button",{type:"button",class:`${gn}-list-row`,onClick:n,"data-testid":o,children:[r("span",{class:`${gn}-list-row-body`,children:[r("span",{class:`${gn}-list-row-title`,children:e}),t?r("span",{class:`${gn}-list-row-sub`,children:t}):null]}),r("span",{class:`${gn}-list-row-chevron`,"aria-hidden":"true",children:r($t,{})})]})}var Kl=x.cssPrefix;function qe({tone:e="info",message:t,onRetry:n,strings:o}){return r("div",{class:`${Kl}-module-empty`,role:e==="error"?"alert":"status","aria-live":"polite",children:[r("span",{children:t}),n?r("button",{type:"button",class:`${Kl}-module-retry`,onClick:n,children:o.errorRetry}):null]})}var wt=x.cssPrefix,fp=X.scope("help"),gp=(e,t)=>t.url?e.push({kind:"iframe",url:t.url,title:t.title}):e.push({kind:"content",id:t.id,title:t.title});function hp(e){let t=new Map;for(let n of e){let o=n.categories?.[0]??"";(t.get(o)??t.set(o,[]).get(o)).push(n)}return[...t.entries()]}function jl(e,t){let n=t.toLowerCase(),o=n.indexOf(e);if(o!==-1)return 100-Math.min(o,99);let i=0;for(let a of e){if(i=n.indexOf(a,i),i===-1)return 0;i+=1}return 1}function vp(e,t){let n=t.toLowerCase().trim();return n?e.map(o=>({item:o,score:Math.max(jl(n,o.title)*2,jl(n,o.description??""))})).filter(o=>o.score>0).toSorted((o,i)=>i.score-o.score).map(o=>o.item):[]}function Xl({article:e,nav:t}){return r(Do,{title:e.title,subtitle:e.description,onClick:()=>gp(t,e),testid:xe(w.helpArticle,e.id)})}function bp({transport:e,strings:t,config:n,nav:o,bus:i,panelProps:a}){let l=n.contentTags,[s,c]=A("loading"),[d,u]=A(t.errorGeneric),[_,g]=A([]),[f,m]=A(""),[C,v]=A(0);R(()=>{let P=!1;return c("loading"),e.listContent({tags:l,sortBy:"order",limit:100}).then(E=>{if(P)return;let B=E.items??[];g(B),c("loaded"),i.emit("contentView",{section:"help",tags:l?.join(","),count:B.length})}).catch(E=>{P||(fp.warn("listContent (help) failed",{err:E}),u(Pt(E,t)),c("error"))}),()=>{P=!0}},[e,l,C,i]);let b=Re(()=>vp(_,f),[_,f]);R(()=>{let P=f.trim();if(!P)return;let E=setTimeout(()=>i.emit("contentSearch",{queryLength:P.length,hitCount:b.length}),600);return()=>clearTimeout(E)},[f,b,i]);function y(){return f.trim().length>0?b.length===0?r(qe,{message:t.helpSearchEmpty,strings:t}):r("div",{class:`${wt}-help-card`,children:b.map(P=>r(Xl,{article:P,nav:o},P.id))}):s==="loading"?r(qe,{message:t.helpLoading,strings:t}):s==="error"?r(qe,{tone:"error",message:d,onRetry:()=>v(P=>P+1),strings:t}):_.length===0?r(qe,{message:t.helpEmpty,strings:t}):hp(_).map(([P,E])=>r("section",{class:`${wt}-help-group`,children:[P?r("h2",{class:`${wt}-help-section-title`,children:P}):null,r("div",{class:`${wt}-help-card`,children:E.map(B=>r(Xl,{article:B,nav:o},B.id))})]},P))}return r("div",{class:`${wt}-module`,children:[r(No,{title:t.helpTitle,actions:r(Ye,{panelProps:a,variant:"plain"})}),r("div",{class:`${wt}-module-pad`,children:r(Gl,{placeholder:t.helpSearchPlaceholder,value:f,onInput:m})}),r("div",{class:`${wt}-help-list`,children:y()})]})}var Yl={Icon:$r,Root:e=>r(bp,{...e})};var Jl=x.cssPrefix;function oi({onClick:e,children:t,testid:n}){return e?r("button",{type:"button",class:`${Jl}-home-card`,"data-interactive":"true",onClick:e,"data-testid":n,children:t}):r("div",{class:`${Jl}-home-card`,"data-testid":n,children:t})}var se=x.cssPrefix,Ql=X.scope("home");function Pp(e){let t=e.options.userContext?.name,n=e.config.greetingText?Ee(e.strings,e.config.greetingText):void 0;return n?{title:t?n.replace("{name}",t):n.replace(/\s*\{name\}\s*/," ").trim(),subtitle:e.strings.homeGreetingLead}:t?{title:e.strings.homeGreetingNamed.replace("{name}",t),subtitle:e.strings.homeGreetingLead}:{title:e.strings.homeGreeting}}var xp=(e,t)=>t.url?e.push({kind:"iframe",url:t.url,title:t.title}):e.push({kind:"content",id:t.id,title:t.title});function yp(e){let{transport:t,strings:n,config:o,nav:i,bus:a,panelProps:l}=e,[s,c]=A(null),[d,u]=A([]),_=o.contentTags?.join(",");R(()=>{if(!o.showRecentConversations)return;let b=!1;return t.listConversations({limit:1}).then(y=>!b&&c(y.conversations?.[0]??null)).catch(y=>!b&&Ql.warn("listConversations (home) failed",{err:y})),()=>{b=!0}},[t,o.showRecentConversations]),R(()=>{if(!o.contentTags?.length)return;let b=!1;return t.listContent({tags:o.contentTags,limit:6}).then(y=>{if(b)return;let P=y.items??[];u(P),a.emit("contentView",{section:"home",tags:_,count:P.length})}).catch(y=>!b&&Ql.warn("listContent (home) failed",{err:y})),()=>{b=!0}},[t,_,a]);let g=Pp(e),f=o.userAvatars??[],m=o.status,C=m?.text?Ee(n,m.text):n.homeStatus,v=o.contentBlockTitle?Ee(n,o.contentBlockTitle):n.homeContentTitle;return r("div",{class:`${se}-module ${se}-home`,"data-testid":w.homeView,children:r("div",{class:`${se}-home-scroll`,children:[r("div",{class:`${se}-home-hero`,children:[r("div",{class:`${se}-home-hero-top`,children:[o.brandName?r("span",{class:`${se}-home-brand`,"data-testid":w.homeBrand,children:o.brandName}):r("span",{class:`${se}-home-brand-spacer`,"aria-hidden":"true"}),r("div",{class:`${se}-home-hero-actions`,children:[f.length>0?r("div",{class:`${se}-home-avatars`,children:f.map(b=>r("span",{class:`${se}-home-avatar`,title:b.role?`${b.name} \xB7 ${b.role}`:b.name,children:b.avatar?r("img",{src:b.avatar,alt:"",loading:"lazy"}):r("span",{children:yo(b.name)})},b.name))}):null,r(Ye,{panelProps:l,variant:"plain"})]})]}),o.showGreeting!==!1?r(ee,{children:[r("h1",{class:`${se}-home-greeting`,"data-testid":w.homeGreeting,children:g.title}),g.subtitle?r("p",{class:`${se}-home-lead`,children:g.subtitle}):null]}):null]}),r("div",{class:`${se}-home-cards`,children:[o.showSearchBar!==!1?r(ql,{placeholder:n.homeSearchPlaceholder,onActivate:()=>i.switchToLayout("help")}):null,s?r(oi,{onClick:()=>i.selectConversation(s.conversationId),testid:w.homeRecent,children:r("div",{class:`${se}-home-recent-row`,"data-unread":(s.unreadCount??0)>0?"true":void 0,children:[r("span",{class:`${se}-home-recent-avatar`,"aria-hidden":"true",children:r(un,{})}),r("span",{class:`${se}-home-recent-body`,children:[r("span",{class:`${se}-home-recent-title`,children:s.title}),s.preview?r("span",{class:`${se}-home-recent-preview`,children:s.preview}):null]}),(s.unreadCount??0)>0?r("span",{class:`${se}-home-recent-dot`,"aria-label":"Unread"}):null]})}):null,m?r(oi,{onClick:m.url?()=>i.push({kind:"iframe",url:m.url,title:C}):void 0,children:r("div",{class:`${se}-home-status`,"data-level":m.level??"operational",children:[r("span",{class:`${se}-home-status-icon`,"aria-hidden":"true",children:r(zs,{})}),r("span",{class:`${se}-home-status-text`,children:C})]})}):null,d.length>0?r("section",{class:`${se}-home-content`,children:[r("div",{class:`${se}-home-content-title`,children:v}),r("div",{class:`${se}-home-content-list`,children:d.map(b=>r(Do,{title:b.title,subtitle:b.description,onClick:()=>xp(i,b),testid:xe(w.homeContentRow,b.id)},b.id))})]}):null]})]})})}var Zl={Icon:Us,Root:e=>r(yp,{...e})};var ut=x.cssPrefix,Sp=X.scope("news");function wp({transport:e,strings:t,config:n,nav:o,bus:i,panelProps:a}){let l=n.contentTags,[s,c]=A("loading"),[d,u]=A(t.errorGeneric),[_,g]=A([]),[f,m]=A(0);R(()=>{let v=!1;return c("loading"),e.listContent({tags:l,sortBy:"publishedAt",sortOrder:"desc"}).then(b=>{if(v)return;let y=b.items??[];g(y),c("loaded"),i.emit("contentView",{section:"news",tags:l?.join(","),count:y.length})}).catch(b=>{v||(Sp.warn("listContent (news) failed",{err:b}),u(Pt(b,t)),c("error"))}),()=>{v=!0}},[e,l,f,i]);function C(){return s==="loading"?r(qe,{message:t.newsLoading,strings:t}):s==="error"?r(qe,{tone:"error",message:d,onRetry:()=>m(v=>v+1),strings:t}):_.length===0?r(qe,{message:t.newsEmpty,strings:t}):r("div",{class:`${ut}-news-list`,children:_.map(v=>r("button",{type:"button",class:`${ut}-news-card`,onClick:()=>o.push({kind:"content",id:v.id,title:v.title}),"data-testid":xe(w.newsItem,v.id),children:[v.image?r("img",{class:`${ut}-news-hero`,src:v.image,alt:"",loading:"lazy"}):null,r("span",{class:`${ut}-news-body`,children:[r("span",{class:`${ut}-news-title`,children:v.title}),v.description?r("span",{class:`${ut}-news-summary`,children:v.description}):null]})]},v.id))})}return r("div",{class:`${ut}-module`,children:[r(No,{title:t.newsTitle,actions:r(Ye,{panelProps:a,variant:"plain"})}),r("div",{class:`${ut}-module-scroll`,children:C()})]})}var ec={Icon:Vs,Root:e=>r(wp,{...e})};var $o={chat:Wl,home:Zl,help:Yl,news:ec};var hn=x.cssPrefix;function tc({modules:e,activeTab:t,strings:n,unreadCount:o,onSelect:i}){return r("nav",{class:`${hn}-tabbar`,role:"tablist","aria-label":n.panelTitle,children:e.map(a=>{let l=$o[a.layout].Icon,s=a.id===t,c=a.layout==="chat"&&o>0?o>9?"9+":String(o):null;return r("button",{type:"button",role:"tab","aria-selected":s,class:`${hn}-tab`,onClick:()=>i(a.id),"data-testid":xe(w.tab,a.id),children:[r("span",{class:`${hn}-tab-icon`,"aria-hidden":"true",children:[r(l,{}),c?r("span",{class:`${hn}-tab-badge`,"data-testid":w.tabBadge,children:c}):null]}),r("span",{class:`${hn}-tab-label`,children:Ee(n,a.label)})]},a.id)})})}var nc=x.cssPrefix,kp="allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-downloads";function oc({url:e,title:t,strings:n,onBack:o,actions:i}){return r("div",{class:`${nc}-module`,children:[r(Oo,{title:t||n.moduleBack,backLabel:n.moduleBack,onBack:o,actions:i}),r("iframe",{class:`${nc}-content-frame`,src:e,title:t||"content",sandbox:kp,referrerpolicy:"no-referrer",loading:"lazy",allow:"fullscreen"})]})}var vn=x.cssPrefix,Cp=X.scope("content"),Tp=5e3;function rc({id:e,title:t,transport:n,strings:o,bus:i,onBack:a,actions:l}){let[s,c]=A(null),[d,u]=A(!1),[_,g]=A(0),f=D(()=>{u(!1),c(null),g(v=>v+1)},[]);R(()=>{let v=!1;return n.listContent({ids:[e],limit:1}).then(b=>{if(v)return;let y=b.items[0];y?(c(y),i.emit("contentOpen",{contentId:e,tags:y.tags?.length?y.tags.join(","):void 0})):u(!0)}).catch(b=>{v||(Cp.warn("listContent (reader) failed",{err:b}),u(!0))}),()=>{v=!0}},[n,e,_,i]),R(()=>{if(!s)return;let v=setTimeout(()=>i.emit("contentRead",{contentId:e}),Tp);return()=>clearTimeout(v)},[s,e,i]);let m=D(v=>{let y=v.target?.closest?.("a")?.getAttribute("href")??"";y&&!y.startsWith("#")&&i.emit("contentLinkClick",{contentId:e})},[i,e]);function C(){return d?r(qe,{tone:"error",message:o.errorGeneric,onRetry:f,strings:o}):s===null?r(qe,{message:o.contentLoading,strings:o}):r("article",{class:`${vn}-content`,"data-testid":w.contentView,onClick:m,children:[s.image?r("img",{class:`${vn}-content-hero`,src:s.image,alt:"",loading:"lazy"}):null,s.description?r("p",{class:`${vn}-content-subtitle`,children:s.description}):null,r(Pl,{text:s.content??""})]})}return r("div",{class:`${vn}-module`,children:[r(Oo,{title:s?.title||t||o.moduleBack,backLabel:o.moduleBack,onBack:a,actions:l,testid:w.backHeader}),r("div",{class:`${vn}-module-scroll`,"data-testid":w.contentScroll,children:C()})]})}var Ho=x.cssPrefix;function ic({panelProps:e,enabledModules:t,nav:n,bus:o,unreadCount:i,onSelectConversation:a,onStartNewConversation:l,onSetPanelSize:s}){let c=e.options,d=c.strings,u=O(null),_=O(new Set);R(()=>{let Y=u.current;if(!Y)return;let ve=xo(Y),k=K=>{K.key==="Escape"&&e.onClose?.()};return Y.addEventListener("keydown",k),()=>{ve(),Y.removeEventListener("keydown",k)}},[e.onClose]);let g=O(null),f=D(Y=>{g.current?.attachFromDrop(Y)},[]),{visible:m}=wo({containerRef:u,onDrop:f});bo(u.current,c.mode==="modal");let C=j(()=>n.sig.value).value,v=Ul(C),b=c.modules.byId[C.activeTab],y=v?.kind==="iframe"||v?.kind==="content",P=t.length>1&&(Vl(C)||!y),E=O(null);R(()=>{if(y&&E.current===null)E.current=e.panelSize,e.panelSize==="normal"&&s("expanded");else if(!y&&E.current!==null){let Y=E.current;E.current=null,s(Y)}},[y]);let B={push:n.push,pop:n.pop,switchTab:n.switchTab,switchToLayout:Y=>{let ve=t.find(k=>k.layout===Y);ve&&n.switchTab(ve.id)},selectConversation:a,startNewConversation:l},le=Y=>({options:c,transport:e.transport,strings:d,config:Y,visitorId:e.visitorId,nav:B,bus:o,panelProps:e}),M=r(Ye,{panelProps:e,variant:"plain"});b&&_.current.add(b.id);let Z=t.filter(Y=>_.current.has(Y.id)),F=Y=>{if(Y.layout==="chat")return r(ti,{...e,containerEl:u.current,dragOver:m,composerAttachApiRef:g});let ve=$o[Y.layout].Root;return ve?r(ve,{...le(Y)}):null},G=()=>v?.kind==="iframe"?r(oc,{url:v.url,title:v.title,strings:d,onBack:n.pop,actions:M}):v?.kind==="content"?r(rc,{id:v.id,title:v.title,transport:e.transport,strings:d,bus:o,onBack:n.pop,actions:M}):null;return r("div",{ref:u,class:`${Ho}-panel ${Ho}-messenger`,role:"dialog","aria-modal":"false","aria-label":d.panelTitle,style:{position:"relative"},"data-testid":w.messengerHome,children:[r("div",{class:`${Ho}-messenger-body`,children:[Z.map(Y=>r("div",{class:`${Ho}-messenger-pane`,hidden:y||Y.id!==b?.id,children:F(Y)},Y.id)),G()]}),P?r(tc,{modules:t,activeTab:C.activeTab,strings:d,unreadCount:i,onSelect:n.switchTab}):null,r(ni,{poweredBy:c.poweredBy}),c.size.resize?.enabled&&!(b?.layout==="chat"&&!v)?r(vo,{panelEl:u.current,resize:c.size.resize,position:c.position,initialSize:e.initialWidgetSize,onSizeChange:e.onWidgetSizeChange,strings:d}):null]})}var bn=x.cssPrefix;function ac({strings:e,onClose:t}){return r("div",{class:`${bn}-panel ${bn}-modules-empty`,role:"dialog","aria-label":e.panelTitle,"data-testid":w.modulesEmpty,children:[t?r("button",{type:"button",class:`${bn}-icon-btn ${bn}-modules-empty-close`,onClick:t,"aria-label":e.close,title:e.close,children:r(Xe,{})}):null,r("p",{class:`${bn}-modules-empty-text`,children:e.modulesEmpty})]})}function sc({callout:e,persistence:t}){let n=e?.text??"",o=e?.persistent??!0,[i,a]=A(()=>o?!1:t.loadCalloutDismissed(n));R(()=>{a(o?!1:t.loadCalloutDismissed(n))},[n,o,t]);let l=D(()=>{a(!0),o||t.saveCalloutDismissed(n)},[t,n,o]);return{dismissed:i,dismissCallout:l}}var W=X.scope("app"),Bo=x.cssPrefix;function lc(e,t){return ds({...e,text:Ee(t,e.text)})}function Ep(e){let t=e.partsSig.value.filter(n=>n.kind==="tool");return t.length>0&&t.every(n=>{let o=n.stateSig.value;return o==="output-available"||o==="output-error"||o==="output-denied"||o==="approval-responded"})}function cc(e){return e instanceof DOMException?e.name==="AbortError":e?.name==="AbortError"}function dc({options:e,hostElement:t,bus:n}){let[o]=A(()=>It(e.widgetId,e.storage,e.aiAgentDeploymentId)),[i,a]=A(()=>o.getVisitorId()),l=o.loadUserPrefs(),[s,c]=A(()=>l.locale??e.locale),[d,u]=A(()=>l.themeMode??e.themeMode),[_,g]=A(()=>l.textSize??e.textSize),f=rn(o.loadConversationId()),m=rn([]),C=rn(0),[v,b]=A(!1),[y,P]=A([]);function E(){let p=e.modules.list,h=new Set(p.map(N=>N.id)),T=o.loadActiveModule();return T&&h.has(T)?T:p[0]?.id??""}function B(){return e.modules.list.find(p=>p.layout==="chat")?.id}let le=O();if(!le.current){let p=e.modules.list.map(h=>h.id);le.current=Fl(E(),p,h=>o.saveActiveModule(h))}let M=le.current,Z=O(void 0);Z.current=B();let[F,G]=A(!1),[Y,ve]=A(null),[k,K]=A(!1),re=e.mode==="standalone"||e.mode==="inline",de=O(an(e,Dt(),o.loadPanelOpen(),o.loadPanelSize())),[ue,Ie]=A(de.current.panelOpen),[ie,ye]=A(de.current.panelOpen),Qe=O(ie);Qe.current=ie;let S=O(!1),z=O(void 0);R(()=>{ue&&ye(!0)},[ue]);let be=O(!1),[Se,he]=A(!1),{dismissed:Ge,dismissCallout:Ke}=sc({callout:e.launcher.callout,persistence:o}),Ze=e.launcher.callout?.persistent??!0,Be=D(()=>{W.info("calloutDismiss"),n.emit("calloutDismiss",void 0),Ke()},[n,Ke]),[Le,Fe]=A(de.current.panelSize),Uo=O(!1),[fc,Vo]=A("chat"),[Vt,Wt]=A(!0),[we,Pn]=A(!1),[gc,ai]=A(null),[Wo,xn]=A([]),[si,yn]=A(null),[Sn,wn]=A(null),kn=O(e.strings),[hc,vc]=A(void 0),[bc,Pc]=A(void 0),[xc,yc]=A(()=>o.loadSidebarCollapsed()??!1),[qo,Sc]=A({}),[q]=A(()=>new lo({agentApiBaseUrl:e.agentApiBaseUrl,dataApiBaseUrl:e.dataApiBaseUrl,auth:Ya({publicKey:e.publicKey,aiAgentDeploymentId:e.aiAgentDeploymentId,publicKeyHeader:"x-public-key"}),endpoints:e.endpoints})),[Me]=A(()=>new uo(m)),[ae]=A(()=>new fo(e.sound,e.haptics)),je=D(p=>{o.patchUserPrefs(p),q.saveUserPrefs(o.loadUserPrefs()).catch(h=>{W.warn("saveUserPrefs failed",{err:h})})},[o,q]);R(()=>{l.soundMuted!==void 0&&ae.setMuted(l.soundMuted)},[]),R(()=>{t.dataset.theme=d},[t,d,e]),R(()=>{t.dataset.textSize=_},[t,_,e]),R(()=>{ae.update(e.sound,e.haptics)},[ae,e.sound,e.haptics]),R(()=>()=>ae.destroy(),[ae]),R(()=>{let p=!0;return ae.mutedSig.subscribe(h=>{if(p){p=!1;return}je({soundMuted:h})})},[ae,je]),R(()=>{Uo.current||!e.size.initialSize||(Uo.current=!0,!o.loadPanelSize()&&Fe(Ir(e.mode,e.size,Dt())))},[e.mode,e.size,o]),R(()=>{if(!F||be.current)return;be.current=!0;let p=an(e,Dt(),o.loadPanelOpen(),o.loadPanelSize());Ie(p.panelOpen),Fe(p.panelSize)},[F,e,o]);let li=O(!1),ci=O(!1),qt=O(null),Go=O(null),Ko=O(!1);R(()=>{if(!(!F||li.current)){if(li.current=!0,ci.current){let p=Z.current;p&&M.switchTab(p);return}M.reset(E())}},[F]);let Cn=D(p=>{!p||p.length===0||(m.value=p.map(h=>lc(h,kn.current)))},[m]),jo=O(null),Tn=D(async p=>{try{let{formSubmissions:h}=await(p?q.bootstrap(p):jo.current??q.bootstrap()),T=new Map;return h.forEach((N,U)=>T.set(N.formId,U)),h.filter((N,U)=>!N.skipped||T.get(N.formId)===U).map((N,U)=>({key:`wire:${N.formId}:${N.createdAt??U}`,formId:N.formId,outcome:N.skipped?"skipped":"submitted",createdAt:so(N.createdAt),values:N.values}))}catch(h){return W.debug("bootstrap failed \u2014 no form markers (non-fatal)",{err:h}),[]}},[q]),Gt=O(0),Kt=D((p,h)=>{let T=[...p.map(I=>I.createdAt),...h.map(I=>I.createdAt)].filter(I=>I!==void 0),N=(T.length?Math.min(...T):Date.now())-1;return[...(z.current?.messages??[]).map(I=>{let Te=lc(I,kn.current);return Te.createdAt=N,Te}),...p]},[]),Xo=D(async p=>{let h=Gt.current,T=()=>h!==Gt.current;b(!0);try{let[N,U]=await Promise.all([q.loadConversation(p),Tn()]);if(T())return;let I=Or(N.messages??[]);P(U);let Te=qt.current?[qt.current]:[];I.length||Te.length?(m.value=[...Kt(I,U),...Te],Wt(N.canContinue??!0),xn(N.suggestions??[])):m.value=Kt([],U),q.resumeStatus==="needs-generation"&&Go.current?.()}catch(N){if(T())return;W.warn("loadThread failed; resetting conversationId",{err:N,conversationId:p}),f.value=void 0,o.saveConversationId(void 0)}finally{T()||b(!1)}},[q,Tn,m,f,o,Kt]),jt=D(async({newConversation:p})=>{let h=++Gt.current,T=()=>h!==Gt.current,N=f.value,U=p||!N?Ue():N;U!==N&&(f.value=U,o.saveConversationId(U));let I;try{I=await q.handshake({visitorId:i,conversationId:U,userPrefs:o.loadUserPrefs(),locale:s})}catch(ze){if(T())return;n.emit("error",ze),e.onError?.(ze),p||G(!0);return}if(T())return;if(I.visitorId&&I.visitorId!==i&&(W.info("visitor rebound",{previous:i,current:I.visitorId,reason:I.rebind?.visitorId}),o.setVisitorId(I.visitorId),a(I.visitorId),n.emit("visitorRebound",{previous:i,current:I.visitorId,reason:I.rebind?.visitorId})),I.conversationId&&I.conversationId!==U&&(W.info("conversation rebound",{previous:U,current:I.conversationId,reason:I.rebind?.conversationId}),n.emit("conversationRebound",{previous:U,current:I.conversationId,reason:I.rebind?.conversationId})),I.agent&&ai(I.agent),e.mode==="page"&&(I.site&&Ka(I.site)?vc(I.site):I.site&&W.warn("invalid site config, using fallback",{site:I.site}),I.blocks&&ja(I.blocks)?Pc(I.blocks):I.blocks&&W.warn("invalid blocks config, using fallback",{blocks:I.blocks})),I.userPrefs&&!p&&(o.saveUserPrefs(I.userPrefs),I.userPrefs.locale&&c(I.userPrefs.locale),I.userPrefs.soundMuted!==void 0&&ae.setMuted(I.userPrefs.soundMuted),I.userPrefs.themeMode&&u(I.userPrefs.themeMode),I.userPrefs.textSize&&g(I.userPrefs.textSize)),z.current=I.welcome,p||n.emit("handshake",I),I.welcome?.suggestions){let ze=kn.current;xn(I.welcome.suggestions.map(ke=>({...ke,label:Ee(ze,ke.label),...ke.text===void 0?{}:{text:Ee(ze,ke.text)}})))}!p&&N&&I.conversationId===N?Qe.current?Xo(N):S.current=!0:(f.value=I.conversationId,o.saveConversationId(I.conversationId),Cn(I.welcome?.messages)),p||G(!0)},[q,i,o,e,n,f,ae,Cn,Xo,s]),Xt=JSON.stringify(e.userContext??null),wc=JSON.stringify(e.pageContext??null),kc=JSON.stringify(qo);R(()=>{let p=Object.keys(qo).length?{...qo,...e.userContext}:e.userContext;q.setContext(p,Rp(e.pageContext))},[q,Xt,wc,kc]);let $e=At(s,e.availableLocales,e.defaultLocale);R(()=>{q.setLocale($e)},[q,$e]),R(()=>{t.dir=zi($e)?"rtl":"ltr"},[t,$e]),R(()=>{$e!==s&&c($e)},[$e,s]);let En=D(p=>{if(p.type!=="data-conversation-rebind")return!1;let h=p.data?.conversationId;if(h&&h!==f.value){let T=f.value;f.value=h,o.saveConversationId(h),q.primeIdentity(void 0,h),W.info("conversation rebound (in-stream)",{previous:T,current:h}),T&&n.emit("conversationRebound",{previous:T,current:h,reason:h})}return!0},[f,o,q,n]),di=D(async p=>{let h=null;try{for await(let T of p.iter)if(!En(T.chunk)){if(!h){h=sn(),qt.current=h,Me.attach(h),m.value=[...m.value,h],Pn(!0),yn(()=>p.cancel),wn(()=>p.detach),ci.current=!0;let N=Z.current;N&&M.switchTab(N),W.info("resumed in-flight reply on mount")}Me.apply(T.chunk),T.chunk.type==="finish"&&T.chunk.canContinue===!1&&Wt(!1)}h&&(h.status==="error"||ot(h)?(h.status="error",h.errorText=e.strings.errorGeneric,ae.play("error")):(h.status="complete",ae.play("messageReceived"),ri(n,e,"assistant",co(h))))}catch(T){h&&(cc(T)?_o(h)?m.value=m.value.filter(N=>N!==h):h.status="complete":(h.status="error",h.errorText=Pt(T,e.strings),ae.play("error"))),W.debug("resume ended without completing",{err:T})}finally{qt.current=null,h&&(Me.detach(),Pn(!1),yn(null),wn(null),m.value=[...m.value])}},[Me,m,ae,n,e,M,En]),_i=O(null),Yo=D(async()=>{let p=q.resumeStream();_i.current=p,await di(p),q.resumeStatus==="needs-generation"&&Go.current?.()},[q,di]);R(()=>{let p=f.value;return p&&q.primeIdentity(i,p),jt({newConversation:!1}),()=>{Gt.current++,_i.current?.cancel()}},[]),R(()=>{ie&&(jo.current=q.bootstrap(),(async()=>{try{let p=await jo.current;ve(Zt((p??{forms:[]}).forms,$e))}catch(p){W.debug("bootstrap failed \u2014 treating as no forms",{err:p})}finally{K(!0)}})(),(async()=>{let p=[];if(S.current){S.current=!1;let h=f.value;h&&p.push(Xo(h))}f.value&&p.push(Yo()),p.length!==0&&await Promise.allSettled(p)})())},[ie]);let Rn=O(null);R(()=>{if(!ie)return;if(Rn.current===null){Rn.current=$e;return}if(Rn.current===$e)return;Rn.current=$e;let p=!1;return q.bootstrap().then(h=>{p||ve(Zt((h??{forms:[]}).forms,$e))}).catch(h=>W.debug("forms re-localize failed \u2014 keeping current copy",{err:h})),()=>{p=!0}},[ie,$e,q]);let ui=O(Xt);R(()=>{!F||ui.current===Xt||(ui.current=Xt,jt({newConversation:!1}))},[Xt,F,jt]),ht(()=>{Xn(t,io(e.mode,Le,ue))},[t,ue,Le,e.mode]),R(()=>{if(e.mode!=="modal"||!ue)return;let p=h=>{h.composedPath().some(U=>U instanceof HTMLElement&&U.classList.contains(`${x.cssPrefix}-panel`))||Ie(!1)};return t.addEventListener("click",p),()=>t.removeEventListener("click",p)},[t,ue,e.mode]),R(()=>{if(e.mode!=="drawer"||!ue)return;let p=h=>{h.key==="Escape"&&Ie(!1)};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[ue,e.mode]);let at=D(async(p,{continueExisting:h})=>{let T=f.value??Ue();f.value||(f.value=T,o.saveConversationId(T));let N=(h?m.value:m.value.slice(0,-1)).filter(Te=>!Te.ephemeral),U=os({messages:N.map(_s),conversationId:T,tools:e.features.tools,visitorId:i,userPrefs:o.loadUserPrefs()});Pn(!0);let I=q.sendMessage(U);yn(()=>I.cancel),wn(()=>I.detach);try{for await(let ke of I.iter)En(ke.chunk)||(Me.apply(ke.chunk),ke.chunk.type==="finish"&&ke.chunk.canContinue===!1&&Wt(!1));let Te=p.status==="error",ze=ot(p);if(Te||ze){p.status="error",p.errorText=e.strings.errorGeneric,ae.play("error");let ke=new Error(Te?"stream error chunk":"empty reply");n.emit("error",ke),e.onError?.(ke)}else p.status="complete",ae.play("messageReceived"),ri(n,e,"assistant",co(p))}catch(Te){cc(Te)?_o(p)?m.value=m.value.filter(ze=>ze!==p):p.status="complete":(p.status="error",p.errorText=Pt(Te,e.strings),ae.play("error"),n.emit("error",Te),e.onError?.(Te))}finally{Me.detach(),Pn(!1),yn(null),wn(null),m.value=[...m.value]}},[q,Me,m,f,e,n,ae,o,i,En]),pi=D(()=>{if(we||Ko.current||qt.current||m.value.filter(T=>!T.ephemeral).at(-1)?.role!=="user")return;Ko.current=!0,W.info("regenerating dangling user turn (needs-generation)");let h=sn();m.value=[...m.value,h],Me.attach(h),at(h,{continueExisting:!1}).finally(()=>{Ko.current=!1})},[we,m,Me,at]);R(()=>{Go.current=pi},[pi]);let An=D((p,h)=>{if(we)return;let T=m.value.at(-1),N=T?.partsSig.value.find(U=>U.kind==="tool"&&U.toolCallId===p);if(!T||!N){W.warn("decideTool: tool part not found",{toolCallId:p});return}h(N),T.partsSig.value=[...T.partsSig.value],Ep(T)&&(T.status="streaming",m.value=[...m.value],Me.attach(T),at(T,{continueExisting:!0}))},[we,m,Me,at]),mi=D((p,h)=>{W.info("toolResult",{toolCallId:p}),n.emit("toolResult",{toolCallId:p}),An(p,T=>{T.outputSig.value=h,T.stateSig.value="output-available"})},[n,An]),fi=D((p,h,T)=>{W.info("toolDecision",{toolCallId:p,approved:h}),n.emit("toolDecision",{toolCallId:p,approved:h}),An(p,N=>{let U=N.approvalSig.value?.id??p;N.approvalSig.value={id:U,approved:h,reason:T},N.stateSig.value="approval-responded"})},[n,An]),gi=D(p=>{if(we)return;let h=m.value.at(-1),T=h?.partsSig.value.find(U=>U.kind==="tool"&&U.toolCallId===p);if(!h||!T)return;let N=T.approvalSig.value?.id??p;T.approvalSig.value={id:N},T.stateSig.value="approval-requested",h.partsSig.value=[...h.partsSig.value]},[we,m]),Cc=Re(()=>({humanInLoop:e.features.humanInLoop,onResult:mi,onDecision:fi,onEdit:gi}),[e.features.humanInLoop,mi,fi,gi]),Tc=()=>m.value.reduce((p,h)=>p+(h.role==="user"?1:0),0),kt=e.forms.list.length>0?e.forms:Y??e.forms,pe=Ol({forms:kt,persistence:o,userContext:()=>e.userContext,messageCount:Tc,pageArea:()=>e.pageContext?.area?String(e.pageContext.area):void 0,conversationId:()=>f.value,onComplete:(p,h,T,N)=>{W.info("formSubmit",{formId:p.id,trigger:h,skipped:N}),n.emit("formSubmit",{formId:p.id,values:T,skipped:N}),P(I=>{let ze=I.find(ke=>ke.formId===p.id&&ke.outcome==="skipped")?.createdAt??Date.now();return[...I.filter(ke=>!(ke.formId===p.id&&ke.outcome==="skipped")),{key:`local:${p.id}:${ze}`,formId:p.id,outcome:N?"skipped":"submitted",createdAt:ze,...N?{}:{values:T}}]});let U=f.value??Ue();f.value||(f.value=U,o.saveConversationId(U),q.primeIdentity(void 0,U)),!N&&p.mirrorToContext&&Sc(I=>({...I,...T})),q.submitForm({formId:p.id,conversationId:U,trigger:h,values:T,skipped:N})}}),Ec=j(()=>pe.activeForm.value);R(()=>{pe.refresh()},[kt,pe]);let hi=e.pageContext?.area?String(e.pageContext.area):void 0,Rc=j(()=>m.value.length);R(()=>{F&&k&&pe.fire("pre-chat")},[F,k,pe]),R(()=>{k&&!Vt&&pe.fire("conversation-closed")},[k,Vt,pe]),R(()=>{F&&k&&hi&&pe.fire("page-area")},[F,k,hi,pe]);let Jo=Re(()=>{let p=kt.list.flatMap(h=>h.triggers).filter(h=>h.kind==="idle").map(h=>Number(h.param));return p.length?Math.min(...p)*1e3:0},[kt]);R(()=>{if(!Jo||!ue)return;let p=setTimeout(()=>pe.fire("idle"),Jo);return()=>clearTimeout(p)},[Jo,ue,pe,Rc.value]);let vi=D(async(p,h)=>{if(W.info("send",{textLen:p.length,attachments:h.length,streaming:we}),we)return;n.emit("send",{text:p,attachmentCount:h.length}),Wo.length>0&&xn([]);let T=await Ip(q,h,I=>{W.warn("upload failed",{err:I}),n.emit("error",I),e.onError?.(I)});ae.unlock(),ae.play("messageSent");let N=cs(p,T),U=sn();m.value=[...m.value,N,U],Me.attach(U),ri(n,e,"user",p),await at(U,{continueExisting:!1}),pe.fire("after-messages")},[we,q,n,e,Wo.length,m,Me,at,pe]),Ac=D(()=>{W.info("stop"),n.emit("stop",void 0),si?.()},[si,n]),Ic=D(()=>{if(we)return;let p=m.value,h=p.at(-1);if(!h||h.role!=="assistant"||h.status!=="error"&&!ot(h))return;let T=sn();m.value=[...p.slice(0,-1),T],Me.attach(T),W.info("retry"),at(T,{continueExisting:!1})},[we,m,Me,at]),Lc=D(()=>{ae.toggleMuted();let p=ae.mutedSig.value;W.info("soundToggle",{muted:p}),n.emit("soundToggle",{muted:p})},[ae,n]),Yt=D(()=>{if(tl(e.mode,Le)==="exit-fullscreen"){W.info("close \u2192 exit-fullscreen",{mode:e.mode}),Fe("normal"),n.emit("fullscreen",!1);return}W.info("close \u2192 panel closed",{mode:e.mode}),pe.fire("panel-close"),Ie(!1),o.savePanelOpen(!1),n.emit("close",void 0),e.onClose?.()},[n,e,o,Le,pe]),Ct=D(()=>{e.modules.list.some(p=>p.layout==="chat")&&q.listConversations({limit:50}).then(p=>{C.value=p.conversations.reduce((h,T)=>h+(T.unreadCount??0),0)}).catch(p=>W.debug("refreshUnread failed (non-fatal)",{err:p}))},[q,e.modules,C]),bi=O(!1);R(()=>{!ie||!F||bi.current||(bi.current=!0,Ct())},[ie,F,Ct]);let Qo=D(()=>{W.info("open",{mode:e.mode}),ae.unlock(),he(!0),Ie(!0),o.savePanelOpen(!0),!Ge&&!Ze&&Be(),setTimeout(()=>he(!1),Ap),Ct(),n.emit("open",void 0),e.onOpen?.()},[n,e,ae,o,Ge,Ze,Be,Ct]),Zo=D(()=>{if(!m.value.some(h=>h.role==="user")&&Vt&&f.value){W.info("clear \u2192 reusing empty conversation",{conversationId:f.value}),m.value.length===0&&Cn(z.current?.messages);return}W.info("clear \u2192 new conversation",{wasStreaming:we}),n.emit("clear",void 0),we&&Sn?.(),Mt(()=>{m.value=[],f.value=void 0}),o.clearConversation(),Wt(!0),P([]),jt({newConversation:!0})},[we,Sn,m,f,o,jt,n,Vt,Cn]),er=D(()=>{Zo(),Vo("chat");let p=e.modules.list.find(h=>h.layout==="chat")?.id;p&&M.switchTab(p)},[Zo,M,e]),tr=D(()=>{let p=Le==="expanded"?"normal":"expanded";W.info("expand",{from:Le,expanded:p==="expanded"}),Fe(p),o.savePanelSize(p),n.emit("expand",p==="expanded")},[n,Le,o]),nr=D(()=>{let p=Le==="fullscreen"?"normal":"fullscreen";W.info("fullscreen",{from:Le,fullscreen:p==="fullscreen"}),Fe(p),o.savePanelSize(p),n.emit("fullscreen",p==="fullscreen")},[n,Le,o]),Mc=D(()=>{Vo(p=>{let h=p==="history"?"chat":"history";return W.info("toggleHistory",{view:h}),n.emit("toggleHistory",{view:h}),h})},[n]),Nc=D(p=>{W.info("localeChange",{locale:p}),c(p),je({locale:p}),n.emit("localeChange",p)},[je,n]),Oc=D(p=>{W.info("themeChange",{mode:p}),u(p),t.dataset.theme=p,je({themeMode:p}),n.emit("themeChange",p)},[t,je,n]),Dc=D(p=>{W.info("textSizeChange",{size:p}),g(p),t.dataset.textSize=p,je({textSize:p}),n.emit("textSizeChange",p)},[t,je,n]),$c=D(()=>{yc(p=>{let h=!p;return W.info("sidebarToggle",{collapsed:h}),o.saveSidebarCollapsed(h),n.emit("sidebarToggle",{collapsed:h}),h})},[o,n]),Hc=D(p=>{W.info("resize",p),je({widgetSize:p}),n.emit("resize",p)},[je,n]),or=D(async p=>{W.info("selectConversation",{conversationId:p,wasStreaming:we}),n.emit("selectConversation",{conversationId:p}),we&&Sn?.();try{let[h,T]=await Promise.all([q.loadConversation(p),Tn(p)]),N=Or(h.messages);Mt(()=>{m.value=Kt(N,T),f.value=h.conversationId}),P(T),o.saveConversationId(h.conversationId),q.primeIdentity(i,h.conversationId),h.agent&&ai(h.agent),Wt(h.canContinue),xn(h.suggestions??[]),Vo("chat"),Yo(),await q.markRead(p),Ct()}catch(h){n.emit("error",h),e.onError?.(h)}},[q,m,f,n,e,o,Ct,Tn,Kt,we,Sn,i,Yo]),In=O(null),Pi=D(p=>{typeof p=="string"&&(k?pe.fire("manual",p):In.current=p)},[k,pe]);R(()=>{!k||!In.current||(pe.fire("manual",In.current),In.current=null)},[k,pe]),R(()=>Xa(t,{open:Qo,close:Yt,expand:tr,fullscreen:nr,openForm:Pi}),[t,Qo,Yt,tr,nr,Pi]);let Oe=Re(()=>xr(e,s,d,_),[e,s,d,_]);kn.current=Oe.strings;let Bc=Re(()=>y.map(p=>{let h=kt.list.find(T=>T.id===p.formId);return{...p,title:h?.title,form:h}}),[y,kt]),xi={options:Oe,transport:q,feedback:ae,bus:n,persistence:o,view:fc,canSend:Vt,isStreaming:we,loadingMessages:v,messagesSig:m,agent:gc,suggestions:Wo,initialWidgetSize:l.widgetSize??null,visitorId:i,onClose:Yt,onClear:Zo,onExpand:tr,onFullscreen:nr,onSoundToggle:Lc,onToggleHistory:Mc,onSelectHistoryConversation:or,onNewConversation:er,onLocaleChange:Nc,onThemeChange:Oc,onTextSizeChange:Dc,onWidgetSizeChange:Hc,onSend:vi,onStop:Ac,onSuggestion:p=>{let h=p.text??p.label;W.info("suggestion",{text:h}),n.emit("suggestion",{text:h}),vi(h,[])},activeForm:Ec.value?.form??null,formMarkers:Bc,onFormSubmit:pe.complete,onFormSkip:pe.skip,onFormFill:p=>pe.fire("manual",p),tool:Cc,onRetry:Ic},Fc=p=>{or(p);let h=B();h&&M.switchTab(h)};if(!F)return null;let Jt=Oe.modules.list,rr=p=>{let h=pn("close",Oe.mode,p);return Jt.length===0?r(ac,{strings:Oe.strings,onClose:h?Yt:void 0}):Jt.length===1&&Jt[0]?.layout==="chat"?r(Nl,{...xi,panelSize:p}):r(ic,{panelProps:{...xi,panelSize:p,onClose:h?Yt:void 0},enabledModules:Jt,nav:M,bus:n,unreadCount:C.value,onSelectConversation:Fc,onStartNewConversation:er,onSetPanelSize:Fe})};if(e.mode==="page"){let p=T=>{or(T.conversationId)},h=Jt.some(T=>T.layout==="chat");return r("div",{class:`${Bo}-anchor`,children:r(Hl,{site:hc,blocks:bc,transport:q,strings:Oe.strings,locale:Oe.locale,persistence:o,visitorId:i,showConversations:h,onSelectConversation:p,onNewConversation:er,sidebarCollapsed:xc,onToggleSidebarCollapsed:$c,children:rr("fullscreen")})})}if(re){let p=e.mode==="standalone"?"fullscreen":Le;return r("div",{class:`${Bo}-anchor`,children:rr(p)})}let yi=e.mode==="drawer",Si=!(e.mode==="modal")&&!e.launcher.hidden&&(!ue||Se),wi=Si&&!Se&&!Ge&&!yi?Oe.launcher.callout:null;return r("div",{class:`${Bo}-anchor`,"data-launcher-size":Oe.launcher.size,children:[ue||ie?r("div",{class:`${Bo}-surface`,hidden:!ue,children:rr(Le)}):null,Si?r(Qs,{onToggle:Qo,launcher:Oe.launcher,strings:Oe.strings,leaving:Se,edgeTab:yi}):null,wi?r(Zs,{callout:wi,launcherPosition:Oe.position,strings:Oe.strings,closeLabel:Oe.strings.close,onDismiss:Be}):null]})}function Rp(e){let t=e?.url??(typeof location<"u"?location.href:void 0);if(!(!e&&!t))return{...e,...t?{url:t}:{}}}var Ap=120;async function Ip(e,t,n){let o=[];for(let i of t)try{let{id:a,url:l}=await e.uploadFile(i.file);o.push({id:a,name:i.name,mediaType:i.mediaType,size:i.size,url:l})}catch(a){n(a)}return o}function ri(e,t,n,o){let i={role:n,text:o};e.emit("message",i),t.onMessage?.(i)}var Lp=X.scope("error-boundary"),Fo=class extends lt{constructor(){super(...arguments);V(this,"state",{crashed:!1})}componentDidCatch(n,o){Lp.error("widget render crashed",{error:n,componentStack:o?.componentStack}),this.setState({crashed:!0}),this.props.onError(n,o?.componentStack)}render(){return this.state.crashed?this.props.fallback:this.props.children}};var Mp="1",Np=60,Op=2e3,_c={open:()=>{},close:()=>{},expand:e=>({on:e}),fullscreen:e=>({on:e}),send:e=>({attachments:e.attachmentCount}),message:e=>({role:e.role}),stop:()=>{},clear:()=>{},suggestion:()=>{},toggleHistory:e=>({view:e.view}),handshake:()=>{},formSubmit:e=>({formId:e.formId,skipped:e.skipped}),toolResult:()=>{},toolDecision:e=>({approved:e.approved}),contentView:e=>({section:e.section,tags:e.tags,count:e.count}),contentOpen:e=>({contentId:e.contentId,tags:e.tags}),contentSearch:e=>({qlen:e.queryLength,hits:e.hitCount}),contentRead:e=>({contentId:e.contentId}),contentLinkClick:e=>({contentId:e.contentId}),attach:e=>({count:e.count,bytes:e.totalBytes}),voiceStart:()=>{},voiceStop:e=>({ms:e.durationMs}),voiceCancel:()=>{},localeChange:e=>({locale:e}),themeChange:e=>({theme:e}),textSizeChange:e=>({size:e}),soundToggle:e=>({muted:e.muted}),sidebarToggle:e=>({collapsed:e.collapsed}),calloutDismiss:()=>{},error:()=>{}};function Dp(){let e=navigator;return e.globalPrivacyControl===!0||e.doNotTrack==="1"}function $p(){return location.origin+location.pathname}function Hp(){try{return document.referrer?new URL(document.referrer).origin:""}catch{return""}}function uc(e,t){let n=Math.random(),o=0,i=0,a=new Set,l=(c,d)=>{let{tracking:u,publicKey:_,aiAgentDeploymentId:g,mode:f,themeMode:m}=t.getOptions();if(!u.enabled||Dp()||n>=u.sampleRate)return;let C=performance.now();if(C-o>6e4&&(o=C,i=0),++i>Np)return;let v=new URLSearchParams;v.set("v",Mp),v.set("_ev",ao),v.set("e",c),u.token&&v.set("tk",u.token),_&&v.set("pk",_),g&&v.set("dep",g),v.set("vid",t.getVisitorId());let b=t.getConversationId();b&&v.set("cid",b),v.set("url",$p());let y=Hp();y&&v.set("ref",y),v.set("sw",String(screen.width)),v.set("sh",String(screen.height)),v.set("vw",String(innerWidth)),v.set("vh",String(innerHeight)),v.set("dpr",String(devicePixelRatio)),v.set("lang",navigator.language);try{v.set("tz",Intl.DateTimeFormat().resolvedOptions().timeZone)}catch{}if(v.set("m",f),v.set("th",m),d)for(let[le,M]of Object.entries(d))M!==void 0&&v.set(le,String(M));v.set("ts",String(Date.now()));let P=`${u.endpoint}?${v}`;if(P.length>Op)return;let E=new Image(1,1);a.add(E);let B=()=>a.delete(E);E.addEventListener("load",B,{once:!0}),E.addEventListener("error",B,{once:!0}),E.src=P},s=Object.keys(_c).map(c=>e.on(c,d=>l(c,_c[c]?.(d))));return()=>{for(let c of s)c();a.clear()}}function pc(e){let{bus:t,host:n,appRoot:o,persistence:i,reportError:a}=e,l=e.initialRaw,s,c=Rt(l),d=!0,u=()=>{c=Rt(s?yr(l,s):l)},_=()=>{Sa(n,jn(c.mode));let m=i.loadUserPrefs().themeMode;ka(n,m?{...c,themeMode:m}:c),d&&(Xn(n,Bp(c)),d=!1)},g=()=>{_(),zn(Fn(Fo,{onError:a},Fn(dc,{bus:t,hostElement:n,options:c})),o)};t.on("handshake",m=>{m.config&&(m.config.storageVersion&&i.rememberStorageVersion(m.config.storageVersion),s=m.config,u(),g())});let f=uc(t,{getOptions:()=>c,getVisitorId:()=>i.getVisitorId(),getConversationId:()=>i.loadConversationId()});return{getOptions:()=>c,getUserOptions:()=>l,render:g,setUserOptions:m=>{l=m,u(),g()},patchUserOptions:m=>{l={...l,...m},u(),g()},destroy:()=>f()}}function Bp(e){if(e.mode==="standalone")return"standalone";if(e.mode==="inline")return"inline";let t=It(e.widgetId,e.storage,e.aiAgentDeploymentId),{panelOpen:n,panelSize:o}=an(e,Dt(),t.loadPanelOpen(),t.loadPanelSize());return io(e.mode,o,n)}var zo=class{constructor(){V(this,"handlers",new Map)}on(t,n){let o=this.handlers.get(t);return o||(o=new Set,this.handlers.set(t,o)),o.add(n),()=>this.handlers.get(t)?.delete(n)}emit(t,n){let o=this.handlers.get(t);if(o)for(let i of o)try{i(n)}catch{}}clear(){this.handlers.clear()}};var ii=class extends HTMLElement{constructor(){super(...arguments);V(this,"bus",new zo);V(this,"mountResult",null);V(this,"runtime",null)}static get observedAttributes(){return Sr}connectedCallback(){this.boot()}disconnectedCallback(){this.mountResult&&(this.runtime?.destroy(),this.runtime=null,zn(null,this.mountResult.appRoot),this.bus.clear())}attributeChangedCallback(){this.isConnected&&this.boot()}boot(){let n=wr(a=>this.getAttribute(a));if(this.runtime){this.runtime.setUserOptions(n);return}let o=Rt(n);this.mountResult||(this.mountResult=wa({existingHost:this,position:jn(o.mode)}));let i=It(o.widgetId,o.storage,o.aiAgentDeploymentId);this.runtime=pc({bus:this.bus,host:this.mountResult.hostElement,appRoot:this.mountResult.appRoot,persistence:i,initialRaw:n,reportError:a=>this.bus.emit("error",a)}),this.runtime.render()}},mc=!1;function Fp(){if(mc||typeof customElements>"u")return;let e=x.tagName;customElements.get(e)||customElements.define(e,ii),mc=!0}typeof customElements<"u"&&Fp();export{Fp as registerWebComponent};
39
+ `){te(e),ne(e,16),e.pending=n;continue}}break;case"$":if(e.token!==19&&e.token!==16&&e.pending==="$")if(n==="$"){e.token=105,e.pending=o;continue}else{if(wu(n.charCodeAt(0)))break;te(e),ne(e,31),e.pending=n;continue}break;case"[":if(e.token!==19&&e.token!==17&&e.token!==30&&e.token!==31&&n!=="]"){te(e),ne(e,17),e.pending=n;continue}break;case"!":if(e.token!==19&&n==="["){te(e),ne(e,19),e.pending="";continue}break;case" ":if(e.pending.length===1&&n===" ")continue;break}if(e.token!==19&&e.token!==17&&e.token!==30&&e.token!==31&&n==="h"&&(e.pending===" "||e.pending==="")){e.text+=e.pending,e.pending=n,e.token=102;continue}e.text+=e.pending,e.pending=n}te(e)}function Yr(e){return{add_token:ku,end_token:Cu,add_text:Tu,set_attr:Eu,data:{nodes:[e,,,,,],index:0}}}function ku(e,t){let n=e.nodes[e.index],o;switch(t){case 1:return;case 20:o=document.createElement("blockquote");break;case 2:o=document.createElement("p");break;case 21:o=document.createElement("br");break;case 22:o=document.createElement("hr");break;case 3:o=document.createElement("h1");break;case 4:o=document.createElement("h2");break;case 5:o=document.createElement("h3");break;case 6:o=document.createElement("h4");break;case 7:o=document.createElement("h5");break;case 8:o=document.createElement("h6");break;case 12:case 13:o=document.createElement("em");break;case 14:case 15:o=document.createElement("strong");break;case 16:o=document.createElement("s");break;case 11:o=document.createElement("code");break;case 18:case 17:o=document.createElement("a");break;case 19:o=document.createElement("img");break;case 23:o=document.createElement("ul");break;case 24:o=document.createElement("ol");break;case 25:o=document.createElement("li");break;case 26:let i=o=document.createElement("input");i.type="checkbox",i.disabled=!0;break;case 9:case 10:n=n.appendChild(document.createElement("pre")),o=document.createElement("code");break;case 27:o=document.createElement("table");break;case 28:switch(n.children.length){case 0:n=n.appendChild(document.createElement("thead"));break;case 1:n=n.appendChild(document.createElement("tbody"));break;default:n=n.children[1]}o=document.createElement("tr");break;case 29:o=document.createElement(n.parentElement?.tagName==="THEAD"?"th":"td");break;case 30:o=document.createElement("equation-block");break;case 31:o=document.createElement("equation-inline");break}e.nodes[++e.index]=n.appendChild(o)}function Cu(e){e.index-=1}function Tu(e,t){e.nodes[e.index].appendChild(document.createTextNode(t))}function Eu(e,t,n){e.nodes[e.index].setAttribute(bu(t),n)}function Eo({textSig:e,doneSig:t}){let n=O(null);return ht(()=>{let o=n.current;if(!o)return;o.classList.add(`${x.cssPrefix}-md`);let i=Yr(o),a=Xr(i),l=0,s=nt(()=>{let u=e.value,_=t.value;u.length<l&&(o.replaceChildren(),i=Yr(o),a=Xr(i),l=0);let g=u.slice(l);g&&Ce(a,g),l=u.length,_&&vl(a)}),c=new MutationObserver(u=>{for(let _ of u)for(let g of _.addedNodes){if(!(g instanceof HTMLElement))continue;let f=g.matches?.("a")?[g]:[...g.querySelectorAll?.("a")??[]];for(let m of f)bl(m)}});c.observe(o,{childList:!0,subtree:!0});for(let u of o.querySelectorAll("a"))bl(u);let d=u=>{let _=u.target?.closest?.("a");if(!_||!(_ instanceof HTMLAnchorElement))return;let g=_.getAttribute("href")??"";!g||g.startsWith("#")||(u.preventDefault(),window.open(g,"_blank","noopener,noreferrer"))};return o.addEventListener("click",d),()=>{s(),c.disconnect(),o.removeEventListener("click",d)}},[e,t]),r("div",{ref:n})}function Pl({text:e}){let t=Re(()=>H(e),[e]),n=Re(()=>H(!0),[]);return r(Eo,{textSig:t,doneSig:n})}function bl(e){let t=e.getAttribute("href")??"";if(!t||t.startsWith("#"))return;e.target!=="_blank"&&(e.target="_blank");let n=new Set((e.rel||"").split(/\s+/).filter(Boolean));n.add("noopener"),n.add("noreferrer"),e.rel=[...n].join(" ")}var Ft=x.cssPrefix;function xl({part:e,strings:t}){let n=e.title||e.filename||e.url||t.sources;return e.url?r("a",{class:`${Ft}-source`,href:e.url,target:"_blank",rel:"noreferrer noopener","data-testid":w.source,children:[r("span",{class:`${Ft}-source-icon`,"aria-hidden":"true",children:"\u{1F517}"}),r("span",{class:`${Ft}-source-label`,children:n})]}):r("span",{class:`${Ft}-source`,"data-testid":w.source,children:[r("span",{class:`${Ft}-source-icon`,"aria-hidden":"true",children:"\u{1F4C4}"}),r("span",{class:`${Ft}-source-label`,children:n})]})}var it=x.cssPrefix;function Ro(e){return e.startsWith("tool:")||e.startsWith("tool-")?e.slice(5):e}function Ao(e,t){let n=e==="output-available"||e==="output-error"||e==="output-denied",o=e==="approval-responded"||t?.approved!==void 0;return{terminal:n,responded:o,decided:n||o}}function Au(e,t){return e==="output-error"?"error":e==="output-denied"||t?.approved===!1?"denied":e==="output-available"?"completed":e==="approval-responded"||t?.approved===!0?"responded":e==="approval-requested"?"awaiting":"running"}function Iu({status:e}){return e==="denied"||e==="error"||e==="superseded"?r(Ys,{}):e==="completed"||e==="responded"?r(Xs,{}):r(js,{})}function Lu(e,t){switch(e){case"awaiting":return t.statusAwaiting;case"responded":return t.statusResponded;case"completed":return t.statusCompleted;case"denied":return t.statusDenied;case"error":return t.statusError;case"superseded":return t.statusSuperseded;default:return t.statusRunning}}function Mu({state:e,approval:t,strings:n,superseded:o}){let i=Au(e,t),a=o&&(i==="awaiting"||i==="running")?"superseded":i;return r("span",{class:`${it}-toolui-badge ${it}-toolui-status`,"data-status":a,children:[r("span",{class:`${it}-toolui-status-icon`,children:r(Iu,{status:a})}),Lu(a,n)]})}function Io({name:e,state:t,approval:n,strings:o,superseded:i}){return r(ee,{children:[r("span",{class:`${it}-toolui-wrench`,children:r(Ks,{})}),r("strong",{class:`${it}-toolui-title`,children:e}),r(Mu,{state:t,approval:n,strings:o,superseded:i}),r("span",{class:`${it}-toolui-chevron`,children:r(go,{})})]})}function dt({label:e,value:t,error:n}){let o=n?String(t??""):Lo(Jr(t));return o?r("div",{class:`${it}-toolui-section`,children:[r("span",{class:`${it}-toolui-label`,children:e}),r("pre",{class:`${it}-toolui-code`,"data-error":n?"true":void 0,children:o})]}):null}function Jr(e){if(e&&typeof e=="object"){let t=e;if(t.storage==="tool-result-ref"&&"summary"in t)return t.summary}return e}function Lo(e){if(e==null)return"";try{let t=typeof e=="string"?e:JSON.stringify(e,null,2);return!t||t==="{}"||t==="[]"||t==='""'?"":t.length>800?`${t.slice(0,800)}\u2026`:t}catch{return""}}var Ae=x.cssPrefix;function yl({part:e,strings:t,active:n,superseded:o=!1,onDecision:i,onEdit:a}){let l=j(()=>e.approvalSig.value),s=j(()=>e.stateSig.value),c=j(()=>e.inputSig.value),d=j(()=>e.outputSig.value),u=j(()=>e.errorSig.value),_=Ro(e.toolName),g=l.value?.approved,{terminal:f,responded:m,decided:C}=Ao(s.value,l.value),v=m&&n&&!f,b=o&&!C,y=e.toolCallId;return r("div",{class:`${Ae}-toolui-group`,"data-testid":C?w.toolDecision:w.toolApproval,children:[r("details",{class:`${Ae}-toolui ${Ae}-toolui-collapsible`,children:[r("summary",{class:`${Ae}-toolui-head`,children:r(Io,{name:_,state:s.value,approval:l.value,strings:t,superseded:b})}),r(dt,{label:t.toolParameters,value:c.value}),d.value!==void 0?r(dt,{label:t.toolResult,value:d.value}):null,u.value?r(dt,{label:t.statusError,value:u.value,error:!0}):null]}),b||f?null:r("div",{class:`${Ae}-toolui ${Ae}-toolui-body`,children:[m?r(ee,{children:[r("p",{class:`${Ae}-toolui-prompt`,children:[t.approvalYourResponse.replace("{decision}",g?t.approve:t.reject),l.value?.reason?` \u2014 ${l.value.reason}`:""]}),v?r("p",{class:`${Ae}-toolui-subtle`,children:t.approvalEditHint}):null,!v&&!f?r("p",{class:`${Ae}-toolui-subtle`,children:t.approvalSubmitting}):null]}):r(ee,{children:[r("p",{class:`${Ae}-toolui-prompt`,children:t.approvalPrompt.replace("{tool}",_)}),r("p",{class:`${Ae}-toolui-subtle`,children:t.approvalBody})]}),!C&&n?r("div",{class:`${Ae}-toolui-actions`,children:[r("button",{type:"button",class:`${Ae}-form-skip`,onClick:()=>i(y,!1),"data-testid":w.toolReject,children:t.reject}),r("button",{type:"button",class:`${Ae}-form-submit`,onClick:()=>i(y,!0),"data-testid":w.toolApprove,children:t.approve})]}):v?r("div",{class:`${Ae}-toolui-actions`,children:r("button",{type:"button",class:`${Ae}-form-skip`,onClick:()=>a(y),"data-testid":w.toolEdit,children:t.edit})}):null]})]})}function wl(e){let t=e&&typeof e=="object"?e:{},n=t.responseType;return{title:fn(t.title),question:fn(t.question)??"Please provide the missing information.",description:fn(t.description),placeholder:fn(t.placeholder),responseType:n==="single-choice"||n==="multi-choice"||n==="confirmation"||n==="free-text"?n:"free-text",choices:Array.isArray(t.choices)?t.choices:void 0,allowOther:typeof t.allowOther=="boolean"?t.allowOther:void 0,required:typeof t.required=="boolean"?t.required:!0,defaultValues:Array.isArray(t.defaultValues)?t.defaultValues.filter(o=>typeof o=="string"):void 0,minSelections:Sl(t.minSelections),maxSelections:Sl(t.maxSelections),validationHint:fn(t.validationHint)}}function kl(e){if(e.responseType==="confirmation")return[];let t=(e.choices??[]).map(Nu).filter(i=>i!==null),n="textarea";e.responseType==="single-choice"&&t.length>0?n="radio":e.responseType==="multi-choice"&&(n="multiselect");let o=n==="multiselect"?e.defaultValues?.join(", "):e.defaultValues?.[0];return[{name:"answer",label:e.question,type:n,placeholder:e.placeholder,required:e.required??!0,defaultValue:o,options:t.length>0?t:void 0,allowOther:e.allowOther,validationHint:e.validationHint,validation:n==="multiselect"?{minSelections:e.minSelections,maxSelections:e.maxSelections}:void 0}]}function Nu(e){return typeof e=="string"?e?{value:e,label:e}:null:e&&typeof e.value=="string"&&e.value?{value:e.value,label:e.label??e.value,description:e.description}:null}function fn(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Sl(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}var oe=x.cssPrefix;function Ou(e,t){switch(e.responseType){case"single-choice":return t.respSingleChoice;case"multi-choice":return t.respMultiChoice;case"confirmation":return t.respConfirmation;default:return t.respFreeText}}function Cl({part:e,strings:t,active:n,superseded:o=!1,onSubmit:i,onDecision:a,onEdit:l}){let s=j(()=>e.stateSig.value),c=j(()=>e.approvalSig.value),d=j(()=>wl(e.inputSig.value)),{terminal:u,responded:_,decided:g}=Ao(s.value,c.value),f=c.value!==void 0,m=(b,y)=>{f?a(e.toolCallId,y,b):d.value.responseType==="confirmation"?i(e.toolCallId,{confirmed:y}):i(e.toolCallId,y?{answer:b}:{})},C=d.value;if(g)return r(Hu,{part:e,strings:t,req:C,editable:_&&n&&!u,onEdit:()=>l(e.toolCallId)});let v=o;return r("div",{class:`${oe}-toolui${v?` ${oe}-toolui-stale`:""}`,"data-testid":w.toolAskInput,children:[r("div",{class:`${oe}-toolui-head`,children:v?r(ee,{children:[r("span",{class:`${oe}-toolui-badge ${oe}-toolui-badge-accent`,children:t.inputBadge}),r("span",{class:`${oe}-toolui-badge ${oe}-toolui-badge-muted`,children:t.statusSuperseded})]}):r(ee,{children:[r("span",{class:`${oe}-toolui-badge ${oe}-toolui-badge-accent`,children:t.inputRequired}),r("span",{class:`${oe}-toolui-badge`,children:Ou(C,t)})]})}),C.description?r("div",{class:`${oe}-toolui-desc`,children:C.description}):null,r(Qr,{label:t.inputQuestion,text:C.question}),v?null:r(Du,{req:C,strings:t,resolve:m})]})}function Du({req:e,strings:t,resolve:n}){if(e.responseType==="confirmation")return r($u,{req:e,strings:t,resolve:n});let o=kl(e).map(i=>(i.label=t.inputYourAnswer,i.placeholder=i.placeholder??t.inputAnswerPlaceholder,i));return r(Co,{fields:o,strings:t,submitLabel:t.inputSubmit,footerHint:e.responseType==="free-text"?t.inputSubmitHint:void 0,onSubmit:i=>n(i.answer??Object.values(i).join(", "),!0),skipLabel:t.inputSkip,onSkip:()=>n(void 0,!1),submitOnEnter:!0,submitTestId:w.toolInputSubmit,skipTestId:w.toolInputSkip})}function $u({req:e,strings:t,resolve:n}){let[o,i]=A(""),a=e.allowOther??!0,l=()=>n(o.trim()||void 0,!0),s=()=>n(void 0,!1),c=d=>{d.key!=="Enter"||d.shiftKey||d.isComposing||(d.preventDefault(),l())};return r(ee,{children:[a?r("label",{class:`${oe}-field`,children:[r("span",{class:`${oe}-field-label`,children:t.inputOptionalNote}),r("textarea",{class:`${oe}-field-input`,rows:2,value:o,placeholder:e.placeholder??t.inputOptionalNotePlaceholder,onInput:d=>i(d.target.value),onKeyDown:c,"data-testid":`${w.formField}-note`})]}):null,r("div",{class:`${oe}-form-actions`,children:[r("span",{class:`${oe}-form-hint`,children:t.inputConfirmHint}),r("button",{type:"button",class:`${oe}-form-skip`,onClick:s,"data-testid":w.toolInputSkip,children:t.confirmNo}),r("button",{type:"button",class:`${oe}-form-submit`,onClick:l,"data-testid":w.toolInputSubmit,children:t.confirmYes})]})]})}function Qr({label:e,text:t}){return r("div",{class:`${oe}-toolui-section`,children:[r("span",{class:`${oe}-toolui-label`,children:e}),r("p",{class:`${oe}-toolui-text`,children:t})]})}function Hu({part:e,strings:t,req:n,editable:o,onEdit:i}){let a=j(()=>e.outputSig.value),l=j(()=>e.approvalSig.value),s=l.value?.approved===!1,c=l.value?.approved!==void 0?l.value.reason??"":Bu(a.value,t);return r("div",{class:`${oe}-toolui`,"data-testid":w.toolDecision,children:[r("div",{class:`${oe}-toolui-head`,children:[r("span",{class:`${oe}-toolui-badge ${oe}-toolui-badge-accent`,children:t.inputBadge}),r("span",{class:`${oe}-toolui-badge`,children:s?t.inputSkipped:t.inputAnswered})]}),n.description?r("div",{class:`${oe}-toolui-desc`,children:n.description}):null,r(Qr,{label:t.inputQuestion,text:n.question}),!s&&c?r(Qr,{label:t.inputYourAnswer,text:c}):null,o?r("div",{class:`${oe}-toolui-actions`,children:r("button",{type:"button",class:`${oe}-form-skip`,onClick:i,"data-testid":w.toolEdit,children:t.edit})}):null]})}function Bu(e,t){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="object"){let n=e;return"confirmed"in n?n.confirmed?t.confirmYes:t.confirmNo:typeof n.responseText=="string"&&n.responseText?n.responseText:Object.values(n).filter(o=>typeof o=="string"||typeof o=="number").join(", ")}return String(e)}var Zr=x.cssPrefix;function Tl({part:e,strings:t}){let n=j(()=>e.inputSig.value),o=j(()=>e.outputSig.value),i=j(()=>e.errorSig.value),a=j(()=>e.stateSig.value),l=j(()=>e.approvalSig.value);return j(()=>!!Lo(n.value)||!!i.value||!!Lo(Jr(o.value))).value?r("details",{class:`${Zr}-toolui ${Zr}-toolui-collapsible`,"data-testid":w.toolCall,children:[r("summary",{class:`${Zr}-toolui-head`,children:r(Io,{name:Ro(e.toolName),state:a.value,approval:l.value,strings:t})}),r(dt,{label:t.toolParameters,value:n.value}),o.value!==void 0?r(dt,{label:t.toolResult,value:o.value}):null,i.value?r(dt,{label:t.statusError,value:i.value,error:!0}):null]}):null}var De=x.cssPrefix;function El({message:e,strings:t,responseMode:n,showReasoning:o,showToolCalls:i,showSources:a,interactive:l=!1,superseded:s=!1,tool:c,onRetry:d}){let _=j(()=>e.partsSig.value).value,g=j(()=>ot(e)),f=j(()=>us(e)),m=j(()=>e.partsSig.value.some(B=>B.kind==="text"&&B.textSig.value.length>0)),C=j(()=>o&&e.partsSig.value.some(B=>B.kind==="reasoning")),v=e.role==="assistant"&&e.status==="streaming",b=n==="buffered"&&v,y=v&&!m.value,P=v&&!b&&!(C.value&&y);if(f.value)return null;let E=Fu(e.createdAt);return r("div",{class:`${De}-bubble-row`,"data-role":e.role,"data-testid":be(w.messageBubble,e.id),children:r("div",{class:`${De}-bubble-col`,children:[r("div",{class:`${De}-bubble`,children:[b?r(Gu,{label:t.loading}):_.map(B=>r(zu,{part:B,active:y,strings:t,showReasoning:o,showToolCalls:i,showSources:a,interactive:l,superseded:s,tool:c},Wu(B))),P&&r(qu,{}),e.status==="error"&&e.errorText||g.value?r("div",{class:`${De}-error`,role:"alert",children:[r("span",{children:e.errorText??t.errorGeneric}),d?r("button",{type:"button",class:`${De}-error-retry`,onClick:d,"data-testid":w.messageRetry,children:t.errorRetry}):null]}):null]}),E?r("time",{class:`${De}-bubble-time`,dateTime:E.iso,title:E.full,children:E.short}):null]})})}function Fu(e){if(typeof e!="number"||!Number.isFinite(e))return null;try{let t=new Date(e);return{short:t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),full:t.toLocaleString(void 0,{dateStyle:"full",timeStyle:"short"}),iso:t.toISOString()}}catch{return null}}function zu({part:e,active:t,strings:n,showReasoning:o,showToolCalls:i,showSources:a,interactive:l,superseded:s,tool:c}){switch(e.kind){case"step-start":return null;case"text":return r(Eo,{textSig:e.textSig,doneSig:e.doneSig});case"reasoning":return o?r(Vu,{part:e,active:t,strings:n}):null;case"tool":return r(Uu,{part:e,strings:n,showToolCalls:i,interactive:l,superseded:s,tool:c});case"file":return e.mediaType.startsWith("image/")?r("img",{src:e.url,alt:"",loading:"lazy"}):r("a",{href:e.url,target:"_blank",rel:"noreferrer noopener",children:e.url});case"source":return a?r(xl,{part:e,strings:n}):null}}function Uu({part:e,strings:t,showToolCalls:n,interactive:o,superseded:i,tool:a}){let l=j(()=>e.approvalSig.value!==void 0);if(a?.humanInLoop){if(ul(e.toolName))return r(Cl,{part:e,strings:t,active:o,superseded:i,onSubmit:a.onResult,onDecision:a.onDecision,onEdit:a.onEdit});if(l.value)return r(yl,{part:e,strings:t,active:o,superseded:i,onDecision:a.onDecision,onEdit:a.onEdit})}return n?r(Tl,{part:e,strings:t}):null}function Vu({part:e,active:t,strings:n}){return r("details",{class:`${De}-reasoning`,open:t,"data-active":t?"true":void 0,children:[r("summary",{class:`${De}-reasoning-summary`,children:r("span",{class:`${De}-reasoning-label`,children:t?n.thinking:n.thoughts})}),r("div",{class:`${De}-reasoning-body`,children:r(Eo,{textSig:e.textSig,doneSig:e.doneSig})})]})}function Wu(e){switch(e.kind){case"text":case"reasoning":case"step-start":return`${e.kind}:${e.id}`;case"tool":return`tool:${e.toolCallId}`;case"file":return`file:${e.url}`;case"source":return`source:${e.sourceId}`}}function qu(){return r("span",{class:`${De}-typing`,"aria-hidden":"true",children:[r("span",{}),r("span",{}),r("span",{})]})}function Gu({label:e}){return r("span",{class:`${De}-loading`,role:"status",children:[r("span",{class:`${De}-loading-spinner`,"aria-hidden":"true"}),r("span",{class:`${De}-loading-label`,children:e})]})}var zt=x.cssPrefix,ei=120,Ku=350;function Rl({messagesSig:e,strings:t,responseMode:n,showReasoning:o,showToolCalls:i,showSources:a,loading:l,idle:s,tool:c,onRetry:d,form:u,formMarkers:_,onFillForm:g}){let f=O(null),m=j(()=>e.value),[C,v]=A(!1),b=O(!1),y=O(!1),P=O(!1),E=O(0),B=()=>P.current||performance.now()-E.current<Ku,le=O(0),M=S=>{le.current=performance.now(),S.scrollTop=S.scrollHeight},Z=(S,z)=>{M(S);let xe=z,ye=0,Se=()=>{M(S),--xe>0&&(ye=requestAnimationFrame(Se))};return z>0&&(ye=requestAnimationFrame(Se)),()=>cancelAnimationFrame(ye)},F=(S,z)=>{let xe,ye,Se,Ge=-1,Ke=()=>{xe.disconnect(),ye.disconnect(),clearTimeout(Se)},Ze=()=>{if(y.current||B()||Ge>=0&&S.scrollTop<Ge-4)return Ke();M(S),Ge=S.scrollTop};return xe=new ResizeObserver(Ze),ye=new MutationObserver(Ze),Ze(),xe.observe(S),ye.observe(S,{childList:!0,subtree:!0,characterData:!0}),Se=setTimeout(Ke,z),Ke},G=m.value[0]?.id;ht(()=>{let S=f.current;if(S&&m.value.length!==0&&(b.current=!0,!!m.value.some(z=>z.role==="user")))return F(S,300)},[G]);let Y=O(0);R(()=>{let S=f.current,z=m.value,xe=Y.current;if(Y.current=z.length,!S||!b.current)return;if(z.slice(xe).some(Se=>Se.role==="user"))return y.current=!1,Z(S,3);if(!z.some(Se=>Se.role==="user")||y.current||B())return;S.scrollHeight-S.scrollTop-S.clientHeight<ei&&M(S)},[m.value.length]);let he=O(null);R(()=>{let S=f.current,z=m.value.at(-1),xe=he.current;if(he.current=z?.id??null,!!S&&b.current&&!(!z||z.id!==xe||z.status!=="streaming"))return y.current=!1,Z(S,3)},[m.value]),R(()=>{let S=f.current;if(!S)return;let z=m.value.at(-1);if(!z||z.status!=="streaming"&&!m.value.some(Se=>Se.role==="user"))return;let xe=()=>{if(y.current||B())return;S.scrollHeight-S.scrollTop-S.clientHeight<ei*2&&M(S)};if(z.status!=="streaming")return F(S,300);xe();let ye=new MutationObserver(xe);return ye.observe(S,{childList:!0,subtree:!0,characterData:!0}),()=>ye.disconnect()},[m.value]);let k=u?.form.id,K=!!u&&(_??[]).some(S=>S.formId===u.form.id);ht(()=>{let S=f.current;!S||!k||y.current||m.value.some(z=>z.role==="user")&&(K?S.querySelector(`[data-testid="${w.formGate}"]`)?.scrollIntoView({block:"nearest"}):M(S))},[k,K]),R(()=>{let S=f.current;if(!S)return;let z=()=>v(S.scrollHeight-S.scrollTop-S.clientHeight>ei*2),xe=()=>{z(),performance.now()-le.current>150&&(y.current=S.scrollHeight-S.scrollTop-S.clientHeight>8)},ye=()=>{y.current=!0},Se=Fe=>{Fe.deltaY<0&&ye()},Ge=0,Ke=Fe=>{Ge=Fe.touches[0]?.clientY??0,P.current=!0},Ze=Fe=>{(Fe.touches[0]?.clientY??0)>Ge+4&&ye()},Be=()=>{P.current=!1,E.current=performance.now()},Le=()=>{P.current=!0};return S.addEventListener("scroll",xe,{passive:!0}),S.addEventListener("wheel",Se,{passive:!0}),S.addEventListener("touchstart",Ke,{passive:!0}),S.addEventListener("touchmove",Ze,{passive:!0}),S.addEventListener("touchend",Be,{passive:!0}),S.addEventListener("touchcancel",Be,{passive:!0}),S.addEventListener("pointerdown",Le,{passive:!0}),window.addEventListener("pointerup",Be,{passive:!0}),window.addEventListener("pointercancel",Be,{passive:!0}),z(),()=>{S.removeEventListener("scroll",xe),S.removeEventListener("wheel",Se),S.removeEventListener("touchstart",Ke),S.removeEventListener("touchmove",Ze),S.removeEventListener("touchend",Be),S.removeEventListener("touchcancel",Be),S.removeEventListener("pointerdown",Le),window.removeEventListener("pointerup",Be),window.removeEventListener("pointercancel",Be)}},[]);let re=()=>{let S=f.current;S&&(y.current=!1,M(S))},de=[],ue="",Ie=m.value.at(-1)?.id,ie=[..._??[]].toSorted((S,z)=>(S.createdAt??1/0)-(z.createdAt??1/0)),Pe=S=>u&&S.formId===u.form.id?r(Wr,{form:u.form,strings:t,onSubmit:u.onSubmit,onSkip:u.onSkip},`gate:${S.formId}`):r(_l,{marker:S,strings:t,onFill:!u&&g?()=>g(S.formId):void 0},S.key),Qe=S=>{for(let z=ie[0];z?.createdAt!==void 0&&!(S!==void 0&&z.createdAt>S);z=ie[0])ie.shift(),de.push(Pe(z))};for(let S of m.value){if(S.role==="assistant"&&S.id!==Ie&&ot(S))continue;Qe(S.createdAt);let z=ju(S.createdAt);z&&z!==ue&&(de.push(r("div",{class:`${zt}-date-divider`,children:r("span",{class:`${zt}-date-pill`,title:Xu(S.createdAt),children:Yu(S.createdAt,t)})},`day:${z}`)),ue=z),de.push(r(El,{message:S,strings:t,responseMode:n,showReasoning:o,showToolCalls:i,showSources:a,interactive:!!s&&S.id===Ie,superseded:S.id!==Ie,tool:c,onRetry:s&&S.id===Ie?d:void 0},S.id))}for(let S of ie)de.push(Pe(S));return r("div",{class:`${zt}-list-wrap`,children:[r("div",{ref:f,class:`${zt}-list`,role:"log","aria-live":"polite","aria-relevant":"additions text",children:[l&&m.value.length===0?r("div",{class:`${zt}-list-loading`,role:"status",children:t.conversationLoading}):null,de,u&&!K?r(Wr,{form:u.form,strings:t,onSubmit:u.onSubmit,onSkip:u.onSkip}):null]}),C?r("button",{type:"button",class:`${zt}-jump`,onClick:re,"aria-label":t.scrollToBottom,title:t.scrollToBottom,"data-testid":w.scrollToBottom,children:r(go,{})}):null]})}function ju(e){if(typeof e!="number"||!Number.isFinite(e))return"";let t=new Date(e);return`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`}function Xu(e){if(typeof e!="number"||!Number.isFinite(e))return"";try{return new Date(e).toLocaleDateString(void 0,{dateStyle:"full"})}catch{return""}}function Yu(e,t){let n=new Date(e),o=a=>new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),i=Math.round((o(new Date)-o(n))/864e5);return i<=0?t.dateToday:i===1?t.dateYesterday:i<7?n.toLocaleDateString(void 0,{weekday:"long"}):n.toLocaleDateString(void 0,{month:"long",day:"numeric",year:"numeric"})}var Ju=["today","yesterday","lastWeek","older"];function Qu(e,t){let n=Date.parse(t);if(!Number.isFinite(n))return"older";let o=Math.floor((Al(e)-Al(n))/(1440*60*1e3));return o<=0?"today":o===1?"yesterday":o<7?"lastWeek":"older"}function Il(e,t){let n=new Map;for(let o of t){let i=Qu(e,o.lastMessageAt),a=n.get(i);a?a.push(o):n.set(i,[o])}return Ju.filter(o=>n.has(o)).map(o=>({bucket:o,conversations:n.get(o)}))}function Al(e){let t=new Date(e);return t.setUTCHours(0,0,0,0),t.getTime()}var Zu=X.scope("history"),ep=3,tp=6,np={today:"dateToday",yesterday:"dateYesterday",lastWeek:"dateLastWeek",older:"dateOlder"};function op(e,t,n){let o=Date.parse(e);return Number.isFinite(o)?new Date(o).toDateString()===new Date(t).toDateString()?new Intl.DateTimeFormat(n,{hour:"numeric",minute:"2-digit"}).format(o):t-o<10080*60*1e3?new Intl.DateTimeFormat(n,{weekday:"short"}).format(o):new Intl.DateTimeFormat(n,{month:"short",day:"numeric"}).format(o):""}function Mo({transport:e,strings:t,locale:n,persistence:o,visitorId:i,onSelect:a,onNewConversation:l}){let s=x.cssPrefix,c=e.peekConversations({visitorId:i}),[d,u]=A(c?"loaded":"loading"),[_,g]=A(c?.conversations??[]);R(()=>{let v=!1;return e.listConversations({visitorId:i}).then(b=>{if(v)return;let y=b.conversations??[];g(y),u("loaded"),o.saveHistoryCount(y.length)}).catch(b=>{v||(Zu.warn("listConversations failed",{err:b}),u("error"))}),()=>{v=!0}},[e,i,o]);let f=l?r("div",{class:`${s}-history-footer`,children:r("button",{type:"button",class:`${s}-history-new`,onClick:l,"data-testid":w.sidebarNewConversation,children:[r(Ps,{}),t.newConversation]})}):null;if(d==="loading"){let v=Math.min(o.loadHistoryCount()??ep,tp);return r(ee,{children:[r("div",{class:`${s}-history`,"aria-busy":"true","aria-label":t.historyLoading,children:r("div",{class:`${s}-history-group`,"aria-hidden":"true",children:[r("div",{class:`${s}-history-heading`,children:r("span",{class:`${s}-skeleton ${s}-skeleton-heading`})}),r("div",{class:`${s}-history-card`,children:Array.from({length:Math.max(1,v)},(b,y)=>r("div",{class:`${s}-history-item ${s}-history-item-skeleton`,children:[r("span",{class:`${s}-history-avatar ${s}-skeleton`}),r("span",{class:`${s}-history-body`,children:[r("span",{class:`${s}-history-row`,children:[r("span",{class:`${s}-history-title`,children:r("span",{class:`${s}-skeleton ${s}-skeleton-title`})}),r("span",{class:`${s}-history-time`,children:r("span",{class:`${s}-skeleton ${s}-skeleton-time`})})]}),r("span",{class:`${s}-history-row`,children:r("span",{class:`${s}-history-preview`,children:r("span",{class:`${s}-skeleton ${s}-skeleton-preview`})})})]})]},y))})]})}),f]})}if(d==="error"||_.length===0)return r(ee,{children:[r("div",{class:`${s}-history-empty`,children:t.historyEmpty}),f]});let m=Date.now(),C=Il(m,_);return r(ee,{children:[r("div",{class:`${s}-history`,role:"list",children:C.map(v=>r("div",{class:`${s}-history-group`,children:[r("div",{class:`${s}-history-heading`,children:t[np[v.bucket]]}),r("div",{class:`${s}-history-card`,children:v.conversations.map(b=>r("button",{type:"button",role:"listitem",class:`${s}-history-item`,onClick:()=>a(b),"data-closed":b.canContinue?void 0:"true","data-unread":(b.unreadCount??0)>0?"true":void 0,"data-testid":be(w.historyItem,b.conversationId),children:[r("span",{class:`${s}-history-avatar`,"aria-hidden":"true",children:r(Dr,{})}),r("span",{class:`${s}-history-body`,children:[r("span",{class:`${s}-history-row`,children:[r("span",{class:`${s}-history-title`,children:b.title}),r("span",{class:`${s}-history-time`,children:op(b.lastMessageAt,m,n)})]}),r("span",{class:`${s}-history-row`,children:[r("span",{class:`${s}-history-preview`,children:b.preview??(b.canContinue?t.historyContinue:t.conversationClosed)}),(b.unreadCount??0)>0?r("span",{class:`${s}-history-dot`}):null]})]})]},b.conversationId))})]},v.bucket))}),f]})}var Ll=x.cssPrefix;function Ml({suggestions:e,onPick:t}){return e.length===0?null:r("div",{class:`${Ll}-suggestions`,role:"group","aria-label":"Suggested replies",children:e.map((n,o)=>r("button",{type:"button",class:`${Ll}-suggestion`,onClick:()=>t(n),"data-testid":be(w.suggestion,o),children:n.label},n.id))})}var Ne=x.cssPrefix;function Nl(e){let{options:t,onClose:n}=e,o=t.strings,i=O(null);R(()=>{let c=i.current;if(!c)return;let d=xo(c),u=_=>{_.key==="Escape"&&n?.()};return c.addEventListener("keydown",u),()=>{d(),c.removeEventListener("keydown",u)}},[n]);let a=O(null),l=D(c=>{a.current?.attachFromDrop(c)},[]),{visible:s}=wo({containerRef:i,onDrop:l});return bo(i.current,t.mode==="modal"),r("div",{ref:i,class:`${Ne}-panel`,role:"dialog","aria-modal":"false","aria-label":o.panelTitle,style:{position:"relative"},"data-testid":w.panel,children:[r(ti,{...e,containerEl:i.current,dragOver:s,composerAttachApiRef:a}),r(ni,{poweredBy:e.options.poweredBy})]})}function ti(e){let{options:t,transport:n,feedback:o,bus:i,persistence:a,panelSize:l,view:s,canSend:c,isStreaming:d,loadingMessages:u,messagesSig:_,agent:g,suggestions:f,initialWidgetSize:m,visitorId:C,onClose:v,onBack:b,onClear:y,onToggleHistory:P,onSelectHistoryConversation:E,onNewConversation:B,onWidgetSizeChange:le,onSend:M,onStop:Z,onSuggestion:F,activeForm:G,formMarkers:Y,onFormSubmit:he,onFormSkip:k,onFormFill:K,tool:re,onRetry:de,containerEl:ue,dragOver:Ie,composerAttachApiRef:ie}=e,Pe=t.strings,Qe;return G?Qe=null:c?Qe=r(ee,{children:[r(Ml,{suggestions:f,onPick:F}),r(il,{options:t,transport:n,feedback:o,bus:i,isStreaming:d,onSend:M,onStop:Z,attachApiRef:ie})]}):Qe=r(ip,{label:Pe.conversationClosed,ctaLabel:Pe.startNewConversation,onNewConversation:y}),r(ee,{children:[s==="history"?r(rp,{strings:Pe,onBack:P,onClose:v,showClose:Po(t.mode,l,t.actions)}):r("header",{class:`${Ne}-header`,"data-testid":w.panelHeader,children:[b?r("button",{type:"button",class:`${Ne}-icon-btn`,onClick:b,"aria-label":Pe.moduleBack,title:Pe.moduleBack,children:r(_n,{})}):null,g?r(nl,{agent:g,strings:Pe}):r("h1",{children:Pe.panelTitle}),r(Ye,{panelProps:e,variant:"chat"})]}),s==="history"?r(Mo,{transport:n,strings:Pe,locale:t.locale,persistence:a,visitorId:C,onSelect:S=>E(S.conversationId),onNewConversation:B}):r(ee,{children:[r(al,{visible:Ie,strings:Pe}),r(Rl,{messagesSig:_,strings:Pe,responseMode:t.responseMode,showReasoning:t.showReasoning,showToolCalls:t.showToolCalls,showSources:t.showSources,loading:u,idle:!d,tool:re,onRetry:de,form:G?{form:G,onSubmit:he,onSkip:k}:null,formMarkers:Y,onFillForm:K}),Qe,r(ap,{disclaimer:t.composerDisclaimer})]}),t.size.resize?.enabled?r(vo,{panelEl:ue,resize:t.size.resize,position:t.position,initialSize:m,onSizeChange:le,strings:Pe}):null]})}function rp({strings:e,onBack:t,onClose:n,showClose:o}){return r("header",{class:`${Ne}-header`,children:[r("button",{type:"button",class:`${Ne}-icon-btn`,onClick:t,"aria-label":e.historyBack,title:e.historyBack,children:r(_n,{})}),r("h1",{children:e.historyTitle}),o?r("button",{type:"button",class:`${Ne}-icon-btn`,onClick:n,"aria-label":e.close,title:e.close,children:r(Xe,{})}):null]})}function ip({label:e,ctaLabel:t,onNewConversation:n}){return r("div",{class:`${Ne}-readonly-banner`,role:"note",children:[r("span",{class:`${Ne}-readonly-label`,children:e}),r("button",{type:"button",class:`${Ne}-readonly-cta`,onClick:n,children:t})]})}function ap({disclaimer:e}){return e?r("div",{class:`${Ne}-composer-footer`,children:r("div",{class:`${Ne}-disclaimer`,children:e})}):null}function ni({poweredBy:e}){return e?r("div",{class:`${Ne}-poweredby-bar`,children:r(sp,{logoUrl:e.logoUrl,text:e.text,href:e.href})}):null}function sp({logoUrl:e,text:t,href:n}){let o=r(ee,{children:[e?r("img",{class:`${Ne}-poweredby-logo`,src:e,alt:"",loading:"lazy"}):null,t?r("span",{children:t}):null]});return n?r("a",{class:`${Ne}-poweredby`,href:n,target:"_blank",rel:"noopener noreferrer",children:o}):r("span",{class:`${Ne}-poweredby`,children:o})}function Ol(e){let t=O(e);t.current=e;let n=O(null);return n.current??(n.current=lp(t)),n.current}function lp(e){let t=H(null),n=new Set,o=c=>`${e.current.conversationId()??""}:${c}`,i=c=>c.frequency==="always"?!1:c.frequency==="conversation"?n.has(o(c.id)):c.id in e.current.persistence.loadFormsDone(),a=(c,d)=>{if(t.value)return;let u=e.current;if(c==="manual"){let _=u.forms.list.find(g=>g.id===d);_&&(t.value={form:_,trigger:"manual"});return}for(let _ of u.forms.byTrigger[c]??[]){let g=_.triggers.find(f=>f.kind===c);if(!(!g||!cp(g,u)||i(_)||!dp(_,u))){t.value={form:_,trigger:c};return}}},l=(c,d)=>{let u=t.value;if(!u)return;t.value=null;let{form:_,trigger:g}=u;_.frequency==="conversation"?n.add(o(_.id)):_.frequency!=="always"&&e.current.persistence.saveFormDone(_.id),e.current.onComplete(_,g,c,d)};return{activeForm:t,fire:a,refresh:()=>{let c=t.value;if(!c)return;let d=e.current.forms.list.find(u=>u.id===c.form.id);d&&d!==c.form&&(t.value={form:d,trigger:c.trigger})},complete:c=>l(c,!1),skip:()=>l({},!0)}}function cp(e,t){return e.kind==="after-messages"?t.messageCount()>=Number(e.param??0):e.kind==="page-area"?t.pageArea()===e.param:!0}function dp(e,t){let n=e.when;if(!n)return!0;if(n.missingContext?.length){let i=t.userContext()??{};if(n.missingContext.some(a=>i[a]!==void 0&&i[a]!==""))return!1}if(n.pageArea&&!(Array.isArray(n.pageArea)?n.pageArea:[n.pageArea]).includes(t.pageArea()??""))return!1;let o=t.messageCount();return!(n.minMessages!=null&&o<n.minMessages||n.maxMessages!=null&&o>n.maxMessages)}function Dl(e){let t=x.cssPrefix,{site:n,blocks:o,strings:i,collapsed:a}=e,l=o?.navigation??[],s=o?.linkCards??[],c=a?i.expandSidebar:i.collapseSidebar;return r("aside",{class:`${t}-sidebar`,"data-collapsed":a?"true":"false","data-testid":w.sidebar,children:[r("div",{class:`${t}-sidebar-header`,children:[r(_p,{site:n}),r("button",{type:"button",class:`${t}-sidebar-toggle`,"aria-label":c,"aria-expanded":a?"false":"true",title:c,onClick:e.onToggleCollapsed,"data-testid":w.sidebarToggle,children:r(up,{collapsed:a})})]}),a?null:r(ee,{children:[l.length>0?r("nav",{class:`${t}-sidebar-section`,"data-section":"navigation",children:r(pp,{items:l})}):null,s.length>0?r("div",{class:`${t}-sidebar-section`,"data-section":"link-cards",children:r(mp,{items:s})}):null,e.showConversations?r("div",{class:`${t}-sidebar-conversations`,children:r(Mo,{transport:e.transport,strings:e.strings,locale:e.locale,persistence:e.persistence,visitorId:e.visitorId,onSelect:e.onSelectConversation,onNewConversation:e.onNewConversation})}):null]})]})}function _p({site:e}){let t=x.cssPrefix;if(e?.logo?.url){let n=e.logo.alt??e.title??"Logo";return r("picture",{children:[e.logoDark?.url?r("source",{srcset:e.logoDark.url,media:"(prefers-color-scheme: dark)"}):null,r("img",{class:`${t}-sidebar-logo`,src:e.logo.url,alt:n})]})}return r("div",{class:`${t}-sidebar-title`,children:e?.title??x.name})}function up({collapsed:e}){return r("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","aria-hidden":"true",children:e?r("polyline",{points:"9 6 15 12 9 18"}):r("polyline",{points:"15 6 9 12 15 18"})})}function pp({items:e}){let t=x.cssPrefix;return r("ul",{class:`${t}-sidebar-nav`,children:e.map(n=>r("li",{children:r("a",{class:`${t}-sidebar-nav-item`,href:n.href,target:n.href?"_blank":void 0,rel:n.href?"noreferrer":void 0,children:[n.icon?r("span",{class:`${t}-sidebar-nav-icon`,"data-icon":n.icon}):null,r("span",{class:`${t}-sidebar-nav-label`,children:n.label})]})},n.id??n.label))})}function mp({items:e}){let t=x.cssPrefix;return r("div",{class:`${t}-sidebar-cards`,children:e.map(n=>r("a",{class:`${t}-sidebar-card`,href:n.href,target:n.href?"_blank":void 0,rel:n.href?"noreferrer":void 0,children:[r("div",{class:`${t}-sidebar-card-label`,children:n.label}),n.description?r("div",{class:`${t}-sidebar-card-desc`,children:n.description}):null]},n.id??n.label))})}var $l=x.cssPrefix;function Hl(e){return r("main",{class:`${$l}-page-shell`,"data-sidebar-collapsed":e.sidebarCollapsed?"true":"false",children:[r(Dl,{site:e.site,blocks:e.blocks,transport:e.transport,strings:e.strings,locale:e.locale,persistence:e.persistence,visitorId:e.visitorId,showConversations:e.showConversations,onSelectConversation:e.onSelectConversation,onNewConversation:e.onNewConversation,collapsed:e.sidebarCollapsed,onToggleCollapsed:e.onToggleSidebarCollapsed}),r("section",{class:`${$l}-page-chat`,"aria-label":"Chat",children:e.children})]})}var Bl=e=>Object.fromEntries(e.map(t=>[t,[]]));function Fl(e,t,n){let o=H({activeTab:e,stacks:Bl(t)});return{sig:o,switchTab(i){o.value.activeTab!==i&&(o.value={...o.value,activeTab:i},n?.(i))},push(i){let a=o.value,l=a.stacks[a.activeTab]??[];o.value={...a,stacks:{...a.stacks,[a.activeTab]:[...l,i]}}},pop(){let i=o.value,a=i.stacks[i.activeTab]??[];a.length!==0&&(o.value={...i,stacks:{...i.stacks,[i.activeTab]:a.slice(0,-1)}})},reset(i){o.value={activeTab:i,stacks:Bl(t)}}}}var zl=e=>e.stacks[e.activeTab]??[],Ul=e=>zl(e).at(-1),Vl=e=>zl(e).length===0;var Wl={Icon:un};var _t=x.cssPrefix;function No({title:e,actions:t}){return r("header",{class:`${_t}-back-header`,"data-variant":"title",children:[r("span",{class:`${_t}-back-spacer`,"aria-hidden":"true"}),r("h1",{class:`${_t}-back-title`,children:e}),t??r("span",{class:`${_t}-back-spacer`,"aria-hidden":"true"})]})}function Oo({title:e,backLabel:t,onBack:n,actions:o,testid:i}){return r("header",{class:`${_t}-back-header`,"data-testid":i,children:[r("button",{type:"button",class:`${_t}-icon-btn`,onClick:n,"aria-label":t,title:t,children:r(_n,{})}),r("h1",{class:`${_t}-back-title`,children:e}),o??r("span",{class:`${_t}-back-spacer`,"aria-hidden":"true"})]})}var Ut=x.cssPrefix;function ql({placeholder:e,onActivate:t}){return r("button",{type:"button",class:`${Ut}-home-search`,onClick:t,"data-testid":w.homeSearch,children:[r("span",{class:`${Ut}-home-search-text`,children:e}),r("span",{class:`${Ut}-home-search-icon`,"aria-hidden":"true",children:r(Hr,{})})]})}function Gl({placeholder:e,value:t,onInput:n}){return r("div",{class:`${Ut}-home-search`,"data-input":"true",children:[r("input",{type:"search",class:`${Ut}-home-search-input`,placeholder:e,value:t,onInput:o=>n(o.currentTarget.value),"data-testid":w.helpSearch}),r("span",{class:`${Ut}-home-search-icon`,"aria-hidden":"true",children:r(Hr,{})})]})}var gn=x.cssPrefix;function Do({title:e,subtitle:t,onClick:n,testid:o}){return r("button",{type:"button",class:`${gn}-list-row`,onClick:n,"data-testid":o,children:[r("span",{class:`${gn}-list-row-body`,children:[r("span",{class:`${gn}-list-row-title`,children:e}),t?r("span",{class:`${gn}-list-row-sub`,children:t}):null]}),r("span",{class:`${gn}-list-row-chevron`,"aria-hidden":"true",children:r($t,{})})]})}var Kl=x.cssPrefix;function qe({tone:e="info",message:t,onRetry:n,strings:o}){return r("div",{class:`${Kl}-module-empty`,role:e==="error"?"alert":"status","aria-live":"polite",children:[r("span",{children:t}),n?r("button",{type:"button",class:`${Kl}-module-retry`,onClick:n,children:o.errorRetry}):null]})}var wt=x.cssPrefix,fp=X.scope("help"),gp=(e,t)=>t.url?e.push({kind:"iframe",url:t.url,title:t.title}):e.push({kind:"content",id:t.id,title:t.title});function hp(e){let t=new Map;for(let n of e){let o=n.categories?.[0]??"";(t.get(o)??t.set(o,[]).get(o)).push(n)}return[...t.entries()]}function jl(e,t){let n=t.toLowerCase(),o=n.indexOf(e);if(o!==-1)return 100-Math.min(o,99);let i=0;for(let a of e){if(i=n.indexOf(a,i),i===-1)return 0;i+=1}return 1}function vp(e,t){let n=t.toLowerCase().trim();return n?e.map(o=>({item:o,score:Math.max(jl(n,o.title)*2,jl(n,o.description??""))})).filter(o=>o.score>0).toSorted((o,i)=>i.score-o.score).map(o=>o.item):[]}function Xl({article:e,nav:t}){return r(Do,{title:e.title,subtitle:e.description,onClick:()=>gp(t,e),testid:be(w.helpArticle,e.id)})}function bp({transport:e,strings:t,config:n,nav:o,bus:i,panelProps:a}){let l=n.contentTags,[s,c]=A("loading"),[d,u]=A(t.errorGeneric),[_,g]=A([]),[f,m]=A(""),[C,v]=A(0);R(()=>{let P=!1;return c("loading"),e.listContent({tags:l,sortBy:"order",limit:100}).then(E=>{if(P)return;let B=E.items??[];g(B),c("loaded"),i.emit("contentView",{section:"help",tags:l?.join(","),count:B.length})}).catch(E=>{P||(fp.warn("listContent (help) failed",{err:E}),u(Pt(E,t)),c("error"))}),()=>{P=!0}},[e,l,C,i]);let b=Re(()=>vp(_,f),[_,f]);R(()=>{let P=f.trim();if(!P)return;let E=setTimeout(()=>i.emit("contentSearch",{queryLength:P.length,hitCount:b.length}),600);return()=>clearTimeout(E)},[f,b,i]);function y(){return f.trim().length>0?b.length===0?r(qe,{message:t.helpSearchEmpty,strings:t}):r("div",{class:`${wt}-help-card`,children:b.map(P=>r(Xl,{article:P,nav:o},P.id))}):s==="loading"?r(qe,{message:t.helpLoading,strings:t}):s==="error"?r(qe,{tone:"error",message:d,onRetry:()=>v(P=>P+1),strings:t}):_.length===0?r(qe,{message:t.helpEmpty,strings:t}):hp(_).map(([P,E])=>r("section",{class:`${wt}-help-group`,children:[P?r("h2",{class:`${wt}-help-section-title`,children:P}):null,r("div",{class:`${wt}-help-card`,children:E.map(B=>r(Xl,{article:B,nav:o},B.id))})]},P))}return r("div",{class:`${wt}-module`,children:[r(No,{title:t.helpTitle,actions:r(Ye,{panelProps:a,variant:"plain"})}),r("div",{class:`${wt}-module-pad`,children:r(Gl,{placeholder:t.helpSearchPlaceholder,value:f,onInput:m})}),r("div",{class:`${wt}-help-list`,children:y()})]})}var Yl={Icon:$r,Root:e=>r(bp,{...e})};var Jl=x.cssPrefix;function oi({onClick:e,children:t,testid:n}){return e?r("button",{type:"button",class:`${Jl}-home-card`,"data-interactive":"true",onClick:e,"data-testid":n,children:t}):r("div",{class:`${Jl}-home-card`,"data-testid":n,children:t})}var se=x.cssPrefix,Ql=X.scope("home");function Pp(e){let t=e.options.userContext?.name,n=e.config.greetingText?Ee(e.strings,e.config.greetingText):void 0;return n?{title:t?n.replace("{name}",t):n.replace(/\s*\{name\}\s*/," ").trim(),subtitle:e.strings.homeGreetingLead}:t?{title:e.strings.homeGreetingNamed.replace("{name}",t),subtitle:e.strings.homeGreetingLead}:{title:e.strings.homeGreeting}}var xp=(e,t)=>t.url?e.push({kind:"iframe",url:t.url,title:t.title}):e.push({kind:"content",id:t.id,title:t.title});function yp(e){let{transport:t,strings:n,config:o,nav:i,bus:a,panelProps:l}=e,[s,c]=A(null),[d,u]=A([]),_=o.contentTags?.join(",");R(()=>{if(!o.showRecentConversations)return;let b=!1;return t.listConversations({limit:1}).then(y=>!b&&c(y.conversations?.[0]??null)).catch(y=>!b&&Ql.warn("listConversations (home) failed",{err:y})),()=>{b=!0}},[t,o.showRecentConversations]),R(()=>{if(!o.contentTags?.length)return;let b=!1;return t.listContent({tags:o.contentTags,limit:6}).then(y=>{if(b)return;let P=y.items??[];u(P),a.emit("contentView",{section:"home",tags:_,count:P.length})}).catch(y=>!b&&Ql.warn("listContent (home) failed",{err:y})),()=>{b=!0}},[t,_,a]);let g=Pp(e),f=o.userAvatars??[],m=o.status,C=m?.text?Ee(n,m.text):n.homeStatus,v=o.contentBlockTitle?Ee(n,o.contentBlockTitle):n.homeContentTitle;return r("div",{class:`${se}-module ${se}-home`,"data-testid":w.homeView,children:r("div",{class:`${se}-home-scroll`,children:[r("div",{class:`${se}-home-hero`,children:[r("div",{class:`${se}-home-hero-top`,children:[o.brandName?r("span",{class:`${se}-home-brand`,"data-testid":w.homeBrand,children:o.brandName}):r("span",{class:`${se}-home-brand-spacer`,"aria-hidden":"true"}),r("div",{class:`${se}-home-hero-actions`,children:[f.length>0?r("div",{class:`${se}-home-avatars`,children:f.map(b=>r("span",{class:`${se}-home-avatar`,title:b.role?`${b.name} \xB7 ${b.role}`:b.name,children:b.avatar?r("img",{src:b.avatar,alt:"",loading:"lazy"}):r("span",{children:yo(b.name)})},b.name))}):null,r(Ye,{panelProps:l,variant:"plain"})]})]}),o.showGreeting!==!1?r(ee,{children:[r("h1",{class:`${se}-home-greeting`,"data-testid":w.homeGreeting,children:g.title}),g.subtitle?r("p",{class:`${se}-home-lead`,children:g.subtitle}):null]}):null]}),r("div",{class:`${se}-home-cards`,children:[o.showSearchBar!==!1?r(ql,{placeholder:n.homeSearchPlaceholder,onActivate:()=>i.switchToLayout("help")}):null,s?r(oi,{onClick:()=>i.selectConversation(s.conversationId),testid:w.homeRecent,children:r("div",{class:`${se}-home-recent-row`,"data-unread":(s.unreadCount??0)>0?"true":void 0,children:[r("span",{class:`${se}-home-recent-avatar`,"aria-hidden":"true",children:r(un,{})}),r("span",{class:`${se}-home-recent-body`,children:[r("span",{class:`${se}-home-recent-title`,children:s.title}),s.preview?r("span",{class:`${se}-home-recent-preview`,children:s.preview}):null]}),(s.unreadCount??0)>0?r("span",{class:`${se}-home-recent-dot`,"aria-label":"Unread"}):null]})}):null,m?r(oi,{onClick:m.url?()=>i.push({kind:"iframe",url:m.url,title:C}):void 0,children:r("div",{class:`${se}-home-status`,"data-level":m.level??"operational",children:[r("span",{class:`${se}-home-status-icon`,"aria-hidden":"true",children:r(zs,{})}),r("span",{class:`${se}-home-status-text`,children:C})]})}):null,d.length>0?r("section",{class:`${se}-home-content`,children:[r("div",{class:`${se}-home-content-title`,children:v}),r("div",{class:`${se}-home-content-list`,children:d.map(b=>r(Do,{title:b.title,subtitle:b.description,onClick:()=>xp(i,b),testid:be(w.homeContentRow,b.id)},b.id))})]}):null]})]})})}var Zl={Icon:Us,Root:e=>r(yp,{...e})};var ut=x.cssPrefix,Sp=X.scope("news");function wp({transport:e,strings:t,config:n,nav:o,bus:i,panelProps:a}){let l=n.contentTags,[s,c]=A("loading"),[d,u]=A(t.errorGeneric),[_,g]=A([]),[f,m]=A(0);R(()=>{let v=!1;return c("loading"),e.listContent({tags:l,sortBy:"publishedAt",sortOrder:"desc"}).then(b=>{if(v)return;let y=b.items??[];g(y),c("loaded"),i.emit("contentView",{section:"news",tags:l?.join(","),count:y.length})}).catch(b=>{v||(Sp.warn("listContent (news) failed",{err:b}),u(Pt(b,t)),c("error"))}),()=>{v=!0}},[e,l,f,i]);function C(){return s==="loading"?r(qe,{message:t.newsLoading,strings:t}):s==="error"?r(qe,{tone:"error",message:d,onRetry:()=>m(v=>v+1),strings:t}):_.length===0?r(qe,{message:t.newsEmpty,strings:t}):r("div",{class:`${ut}-news-list`,children:_.map(v=>r("button",{type:"button",class:`${ut}-news-card`,onClick:()=>o.push({kind:"content",id:v.id,title:v.title}),"data-testid":be(w.newsItem,v.id),children:[v.image?r("img",{class:`${ut}-news-hero`,src:v.image,alt:"",loading:"lazy"}):null,r("span",{class:`${ut}-news-body`,children:[r("span",{class:`${ut}-news-title`,children:v.title}),v.description?r("span",{class:`${ut}-news-summary`,children:v.description}):null]})]},v.id))})}return r("div",{class:`${ut}-module`,children:[r(No,{title:t.newsTitle,actions:r(Ye,{panelProps:a,variant:"plain"})}),r("div",{class:`${ut}-module-scroll`,children:C()})]})}var ec={Icon:Vs,Root:e=>r(wp,{...e})};var $o={chat:Wl,home:Zl,help:Yl,news:ec};var hn=x.cssPrefix;function tc({modules:e,activeTab:t,strings:n,unreadCount:o,onSelect:i}){return r("nav",{class:`${hn}-tabbar`,role:"tablist","aria-label":n.panelTitle,children:e.map(a=>{let l=$o[a.layout].Icon,s=a.id===t,c=a.layout==="chat"&&o>0?o>9?"9+":String(o):null;return r("button",{type:"button",role:"tab","aria-selected":s,class:`${hn}-tab`,onClick:()=>i(a.id),"data-testid":be(w.tab,a.id),children:[r("span",{class:`${hn}-tab-icon`,"aria-hidden":"true",children:[r(l,{}),c?r("span",{class:`${hn}-tab-badge`,"data-testid":w.tabBadge,children:c}):null]}),r("span",{class:`${hn}-tab-label`,children:Ee(n,a.label)})]},a.id)})})}var nc=x.cssPrefix,kp="allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-downloads";function oc({url:e,title:t,strings:n,onBack:o,actions:i}){return r("div",{class:`${nc}-module`,children:[r(Oo,{title:t||n.moduleBack,backLabel:n.moduleBack,onBack:o,actions:i}),r("iframe",{class:`${nc}-content-frame`,src:e,title:t||"content",sandbox:kp,referrerpolicy:"no-referrer",loading:"lazy",allow:"fullscreen"})]})}var vn=x.cssPrefix,Cp=X.scope("content"),Tp=5e3;function rc({id:e,title:t,transport:n,strings:o,bus:i,onBack:a,actions:l}){let[s,c]=A(null),[d,u]=A(!1),[_,g]=A(0),f=D(()=>{u(!1),c(null),g(v=>v+1)},[]);R(()=>{let v=!1;return n.listContent({ids:[e],limit:1}).then(b=>{if(v)return;let y=b.items[0];y?(c(y),i.emit("contentOpen",{contentId:e,tags:y.tags?.length?y.tags.join(","):void 0})):u(!0)}).catch(b=>{v||(Cp.warn("listContent (reader) failed",{err:b}),u(!0))}),()=>{v=!0}},[n,e,_,i]),R(()=>{if(!s)return;let v=setTimeout(()=>i.emit("contentRead",{contentId:e}),Tp);return()=>clearTimeout(v)},[s,e,i]);let m=D(v=>{let y=v.target?.closest?.("a")?.getAttribute("href")??"";y&&!y.startsWith("#")&&i.emit("contentLinkClick",{contentId:e})},[i,e]);function C(){return d?r(qe,{tone:"error",message:o.errorGeneric,onRetry:f,strings:o}):s===null?r(qe,{message:o.contentLoading,strings:o}):r("article",{class:`${vn}-content`,"data-testid":w.contentView,onClick:m,children:[s.image?r("img",{class:`${vn}-content-hero`,src:s.image,alt:"",loading:"lazy"}):null,s.description?r("p",{class:`${vn}-content-subtitle`,children:s.description}):null,r(Pl,{text:s.content??""})]})}return r("div",{class:`${vn}-module`,children:[r(Oo,{title:s?.title||t||o.moduleBack,backLabel:o.moduleBack,onBack:a,actions:l,testid:w.backHeader}),r("div",{class:`${vn}-module-scroll`,"data-testid":w.contentScroll,children:C()})]})}var Ho=x.cssPrefix;function ic({panelProps:e,enabledModules:t,nav:n,bus:o,unreadCount:i,onSelectConversation:a,onStartNewConversation:l,onSetPanelSize:s}){let c=e.options,d=c.strings,u=O(null),_=O(new Set);R(()=>{let Y=u.current;if(!Y)return;let he=xo(Y),k=K=>{K.key==="Escape"&&e.onClose?.()};return Y.addEventListener("keydown",k),()=>{he(),Y.removeEventListener("keydown",k)}},[e.onClose]);let g=O(null),f=D(Y=>{g.current?.attachFromDrop(Y)},[]),{visible:m}=wo({containerRef:u,onDrop:f});bo(u.current,c.mode==="modal");let C=j(()=>n.sig.value).value,v=Ul(C),b=c.modules.byId[C.activeTab],y=v?.kind==="iframe"||v?.kind==="content",P=t.length>1&&(Vl(C)||!y),E=O(null);R(()=>{if(y&&E.current===null)E.current=e.panelSize,e.panelSize==="normal"&&s("expanded");else if(!y&&E.current!==null){let Y=E.current;E.current=null,s(Y)}},[y]);let B={push:n.push,pop:n.pop,switchTab:n.switchTab,switchToLayout:Y=>{let he=t.find(k=>k.layout===Y);he&&n.switchTab(he.id)},selectConversation:a,startNewConversation:l},le=Y=>({options:c,transport:e.transport,strings:d,config:Y,visitorId:e.visitorId,nav:B,bus:o,panelProps:e}),M=r(Ye,{panelProps:e,variant:"plain"});b&&_.current.add(b.id);let Z=t.filter(Y=>_.current.has(Y.id)),F=Y=>{if(Y.layout==="chat")return r(ti,{...e,containerEl:u.current,dragOver:m,composerAttachApiRef:g});let he=$o[Y.layout].Root;return he?r(he,{...le(Y)}):null},G=()=>v?.kind==="iframe"?r(oc,{url:v.url,title:v.title,strings:d,onBack:n.pop,actions:M}):v?.kind==="content"?r(rc,{id:v.id,title:v.title,transport:e.transport,strings:d,bus:o,onBack:n.pop,actions:M}):null;return r("div",{ref:u,class:`${Ho}-panel ${Ho}-messenger`,role:"dialog","aria-modal":"false","aria-label":d.panelTitle,style:{position:"relative"},"data-testid":w.messengerHome,children:[r("div",{class:`${Ho}-messenger-body`,children:[Z.map(Y=>r("div",{class:`${Ho}-messenger-pane`,hidden:y||Y.id!==b?.id,children:F(Y)},Y.id)),G()]}),P?r(tc,{modules:t,activeTab:C.activeTab,strings:d,unreadCount:i,onSelect:n.switchTab}):null,r(ni,{poweredBy:c.poweredBy}),c.size.resize?.enabled&&!(b?.layout==="chat"&&!v)?r(vo,{panelEl:u.current,resize:c.size.resize,position:c.position,initialSize:e.initialWidgetSize,onSizeChange:e.onWidgetSizeChange,strings:d}):null]})}var bn=x.cssPrefix;function ac({strings:e,onClose:t}){return r("div",{class:`${bn}-panel ${bn}-modules-empty`,role:"dialog","aria-label":e.panelTitle,"data-testid":w.modulesEmpty,children:[t?r("button",{type:"button",class:`${bn}-icon-btn ${bn}-modules-empty-close`,onClick:t,"aria-label":e.close,title:e.close,children:r(Xe,{})}):null,r("p",{class:`${bn}-modules-empty-text`,children:e.modulesEmpty})]})}function sc({callout:e,persistence:t}){let n=e?.text??"",o=e?.persistent??!0,[i,a]=A(()=>o?!1:t.loadCalloutDismissed(n));R(()=>{a(o?!1:t.loadCalloutDismissed(n))},[n,o,t]);let l=D(()=>{a(!0),o||t.saveCalloutDismissed(n)},[t,n,o]);return{dismissed:i,dismissCallout:l}}var W=X.scope("app"),Bo=x.cssPrefix;function lc(e,t){return ds({...e,text:Ee(t,e.text)})}function Ep(e){let t=e.partsSig.value.filter(n=>n.kind==="tool");return t.length>0&&t.every(n=>{let o=n.stateSig.value;return o==="output-available"||o==="output-error"||o==="output-denied"||o==="approval-responded"})}function cc(e){return e instanceof DOMException?e.name==="AbortError":e?.name==="AbortError"}function dc({options:e,hostElement:t,bus:n}){let[o]=A(()=>It(e.widgetId,e.storage,e.aiAgentDeploymentId)),[i,a]=A(()=>o.getVisitorId()),l=o.loadUserPrefs(),[s,c]=A(()=>l.locale??e.locale),[d,u]=A(()=>l.themeMode??e.themeMode),[_,g]=A(()=>l.textSize??e.textSize),f=rn(o.loadConversationId()),m=rn([]),C=rn(0),[v,b]=A(!1),[y,P]=A([]);function E(){let p=e.modules.list,h=new Set(p.map(N=>N.id)),T=o.loadActiveModule();return T&&h.has(T)?T:p[0]?.id??""}function B(){return e.modules.list.find(p=>p.layout==="chat")?.id}let le=O();if(!le.current){let p=e.modules.list.map(h=>h.id);le.current=Fl(E(),p,h=>o.saveActiveModule(h))}let M=le.current,Z=O(void 0);Z.current=B();let[F,G]=A(!1),[Y,he]=A(null),[k,K]=A(!1),re=e.mode==="standalone"||e.mode==="inline",de=O(an(e,Dt(),o.loadPanelOpen(),o.loadPanelSize())),[ue,Ie]=A(de.current.panelOpen),[ie,Pe]=A(de.current.panelOpen),Qe=O(ie);Qe.current=ie;let S=O(!1),z=O(void 0);R(()=>{ue&&Pe(!0)},[ue]);let xe=O(!1),[ye,Se]=A(!1),{dismissed:Ge,dismissCallout:Ke}=sc({callout:e.launcher.callout,persistence:o}),Ze=e.launcher.callout?.persistent??!0,Be=D(()=>{W.info("calloutDismiss"),n.emit("calloutDismiss",void 0),Ke()},[n,Ke]),[Le,Fe]=A(de.current.panelSize),Uo=O(!1),[fc,Vo]=A("chat"),[Vt,Wt]=A(!0),[we,Pn]=A(!1),[gc,ai]=A(null),[Wo,xn]=A([]),[si,yn]=A(null),[Sn,wn]=A(null),kn=O(e.strings),[hc,vc]=A(void 0),[bc,Pc]=A(void 0),[xc,yc]=A(()=>o.loadSidebarCollapsed()??!1),[qo,Sc]=A({}),[q]=A(()=>new lo({agentApiBaseUrl:e.agentApiBaseUrl,dataApiBaseUrl:e.dataApiBaseUrl,auth:Ya({publicKey:e.publicKey,aiAgentDeploymentId:e.aiAgentDeploymentId,publicKeyHeader:"x-public-key"}),endpoints:e.endpoints})),[Me]=A(()=>new uo(m)),[ae]=A(()=>new fo(e.sound,e.haptics)),je=D(p=>{o.patchUserPrefs(p),q.saveUserPrefs(o.loadUserPrefs()).catch(h=>{W.warn("saveUserPrefs failed",{err:h})})},[o,q]);R(()=>{l.soundMuted!==void 0&&ae.setMuted(l.soundMuted)},[]),R(()=>{t.dataset.theme=d},[t,d,e]),R(()=>{t.dataset.textSize=_},[t,_,e]),R(()=>{ae.update(e.sound,e.haptics)},[ae,e.sound,e.haptics]),R(()=>()=>ae.destroy(),[ae]),R(()=>{let p=!0;return ae.mutedSig.subscribe(h=>{if(p){p=!1;return}je({soundMuted:h})})},[ae,je]),R(()=>{Uo.current||!e.size.initialSize||(Uo.current=!0,!o.loadPanelSize()&&Fe(Ir(e.mode,e.size,Dt())))},[e.mode,e.size,o]),R(()=>{if(!F||xe.current)return;xe.current=!0;let p=an(e,Dt(),o.loadPanelOpen(),o.loadPanelSize());Ie(p.panelOpen),Fe(p.panelSize)},[F,e,o]);let li=O(!1),ci=O(!1),qt=O(null),Go=O(null),Ko=O(!1);R(()=>{if(!(!F||li.current)){if(li.current=!0,ci.current){let p=Z.current;p&&M.switchTab(p);return}M.reset(E())}},[F]);let Cn=D(p=>{!p||p.length===0||(m.value=p.map(h=>lc(h,kn.current)))},[m]),jo=O(null),Tn=D(async p=>{try{let{formSubmissions:h}=await(p?q.bootstrap(p):jo.current??q.bootstrap()),T=new Map;return h.forEach((N,U)=>T.set(N.formId,U)),h.filter((N,U)=>!N.skipped||T.get(N.formId)===U).map((N,U)=>({key:`wire:${N.formId}:${N.createdAt??U}`,formId:N.formId,outcome:N.skipped?"skipped":"submitted",createdAt:so(N.createdAt),values:N.values}))}catch(h){return W.debug("bootstrap failed \u2014 no form markers (non-fatal)",{err:h}),[]}},[q]),Gt=O(0),Kt=D((p,h)=>{let T=[...p.map(I=>I.createdAt),...h.map(I=>I.createdAt)].filter(I=>I!==void 0),N=(T.length?Math.min(...T):Date.now())-1;return[...(z.current?.messages??[]).map(I=>{let Te=lc(I,kn.current);return Te.createdAt=N,Te}),...p]},[]),Xo=D(async p=>{let h=Gt.current,T=()=>h!==Gt.current;b(!0);try{let[N,U]=await Promise.all([q.loadConversation(p),Tn()]);if(T())return;let I=Or(N.messages??[]);P(U);let Te=qt.current?[qt.current]:[];I.length||Te.length?(m.value=[...Kt(I,U),...Te],Wt(N.canContinue??!0),xn(N.suggestions??[])):m.value=Kt([],U),q.resumeStatus==="needs-generation"&&Go.current?.()}catch(N){if(T())return;W.warn("loadThread failed; resetting conversationId",{err:N,conversationId:p}),f.value=void 0,o.saveConversationId(void 0)}finally{T()||b(!1)}},[q,Tn,m,f,o,Kt]),jt=D(async({newConversation:p})=>{let h=++Gt.current,T=()=>h!==Gt.current,N=f.value,U=p||!N?Ue():N;U!==N&&(f.value=U,o.saveConversationId(U));let I;try{I=await q.handshake({visitorId:i,conversationId:U,userPrefs:o.loadUserPrefs(),locale:s})}catch(ze){if(T())return;n.emit("error",ze),e.onError?.(ze),p||G(!0);return}if(T())return;if(I.visitorId&&I.visitorId!==i&&(W.info("visitor rebound",{previous:i,current:I.visitorId,reason:I.rebind?.visitorId}),o.setVisitorId(I.visitorId),a(I.visitorId),n.emit("visitorRebound",{previous:i,current:I.visitorId,reason:I.rebind?.visitorId})),I.conversationId&&I.conversationId!==U&&(W.info("conversation rebound",{previous:U,current:I.conversationId,reason:I.rebind?.conversationId}),n.emit("conversationRebound",{previous:U,current:I.conversationId,reason:I.rebind?.conversationId})),I.agent&&ai(I.agent),e.mode==="page"&&(I.site&&Ka(I.site)?vc(I.site):I.site&&W.warn("invalid site config, using fallback",{site:I.site}),I.blocks&&ja(I.blocks)?Pc(I.blocks):I.blocks&&W.warn("invalid blocks config, using fallback",{blocks:I.blocks})),I.userPrefs&&!p&&(o.saveUserPrefs(I.userPrefs),I.userPrefs.locale&&c(I.userPrefs.locale),I.userPrefs.soundMuted!==void 0&&ae.setMuted(I.userPrefs.soundMuted),I.userPrefs.themeMode&&u(I.userPrefs.themeMode),I.userPrefs.textSize&&g(I.userPrefs.textSize)),z.current=I.welcome,p||n.emit("handshake",I),I.welcome?.suggestions){let ze=kn.current;xn(I.welcome.suggestions.map(ke=>({...ke,label:Ee(ze,ke.label),...ke.text===void 0?{}:{text:Ee(ze,ke.text)}})))}!p&&N&&I.conversationId===N?Qe.current?Xo(N):S.current=!0:(f.value=I.conversationId,o.saveConversationId(I.conversationId),Cn(I.welcome?.messages)),p||G(!0)},[q,i,o,e,n,f,ae,Cn,Xo,s]),Xt=JSON.stringify(e.userContext??null),wc=JSON.stringify(e.pageContext??null),kc=JSON.stringify(qo);R(()=>{let p=Object.keys(qo).length?{...qo,...e.userContext}:e.userContext;q.setContext(p,Rp(e.pageContext))},[q,Xt,wc,kc]);let $e=At(s,e.availableLocales,e.defaultLocale);R(()=>{q.setLocale($e)},[q,$e]),R(()=>{t.dir=zi($e)?"rtl":"ltr"},[t,$e]),R(()=>{$e!==s&&c($e)},[$e,s]);let En=D(p=>{if(p.type!=="data-conversation-rebind")return!1;let h=p.data?.conversationId;if(h&&h!==f.value){let T=f.value;f.value=h,o.saveConversationId(h),q.primeIdentity(void 0,h),W.info("conversation rebound (in-stream)",{previous:T,current:h}),T&&n.emit("conversationRebound",{previous:T,current:h,reason:h})}return!0},[f,o,q,n]),di=D(async p=>{let h=null;try{for await(let T of p.iter)if(!En(T.chunk)){if(!h){h=sn(),qt.current=h,Me.attach(h),m.value=[...m.value,h],Pn(!0),yn(()=>p.cancel),wn(()=>p.detach),ci.current=!0;let N=Z.current;N&&M.switchTab(N),W.info("resumed in-flight reply on mount")}Me.apply(T.chunk),T.chunk.type==="finish"&&T.chunk.canContinue===!1&&Wt(!1)}h&&(h.status==="error"||ot(h)?(h.status="error",h.errorText=e.strings.errorGeneric,ae.play("error")):(h.status="complete",ae.play("messageReceived"),ri(n,e,"assistant",co(h))))}catch(T){h&&(cc(T)?_o(h)?m.value=m.value.filter(N=>N!==h):h.status="complete":(h.status="error",h.errorText=Pt(T,e.strings),ae.play("error"))),W.debug("resume ended without completing",{err:T})}finally{qt.current=null,h&&(Me.detach(),Pn(!1),yn(null),wn(null),m.value=[...m.value])}},[Me,m,ae,n,e,M,En]),_i=O(null),Yo=D(async()=>{let p=q.resumeStream();_i.current=p,await di(p),q.resumeStatus==="needs-generation"&&Go.current?.()},[q,di]);R(()=>{let p=f.value;return p&&q.primeIdentity(i,p),jt({newConversation:!1}),()=>{Gt.current++,_i.current?.cancel()}},[]),R(()=>{ie&&(jo.current=q.bootstrap(),(async()=>{try{let p=await jo.current;he(Zt((p??{forms:[]}).forms,$e))}catch(p){W.debug("bootstrap failed \u2014 treating as no forms",{err:p})}finally{K(!0)}})(),(async()=>{let p=[];if(S.current){S.current=!1;let h=f.value;h&&p.push(Xo(h))}f.value&&p.push(Yo()),p.length!==0&&await Promise.allSettled(p)})())},[ie]);let Rn=O(null);R(()=>{if(!ie)return;if(Rn.current===null){Rn.current=$e;return}if(Rn.current===$e)return;Rn.current=$e;let p=!1;return q.bootstrap().then(h=>{p||he(Zt((h??{forms:[]}).forms,$e))}).catch(h=>W.debug("forms re-localize failed \u2014 keeping current copy",{err:h})),()=>{p=!0}},[ie,$e,q]);let ui=O(Xt);R(()=>{!F||ui.current===Xt||(ui.current=Xt,jt({newConversation:!1}))},[Xt,F,jt]),ht(()=>{Xn(t,io(e.mode,Le,ue))},[t,ue,Le,e.mode]),R(()=>{if(e.mode!=="modal"||!ue)return;let p=h=>{h.composedPath().some(U=>U instanceof HTMLElement&&U.classList.contains(`${x.cssPrefix}-panel`))||Ie(!1)};return t.addEventListener("click",p),()=>t.removeEventListener("click",p)},[t,ue,e.mode]),R(()=>{if(e.mode!=="drawer"||!ue)return;let p=h=>{h.key==="Escape"&&Ie(!1)};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[ue,e.mode]);let at=D(async(p,{continueExisting:h})=>{let T=f.value??Ue();f.value||(f.value=T,o.saveConversationId(T));let N=(h?m.value:m.value.slice(0,-1)).filter(Te=>!Te.ephemeral),U=os({messages:N.map(_s),conversationId:T,tools:e.features.tools,visitorId:i,userPrefs:o.loadUserPrefs()});Pn(!0);let I=q.sendMessage(U);yn(()=>I.cancel),wn(()=>I.detach);try{for await(let ke of I.iter)En(ke.chunk)||(Me.apply(ke.chunk),ke.chunk.type==="finish"&&ke.chunk.canContinue===!1&&Wt(!1));let Te=p.status==="error",ze=ot(p);if(Te||ze){p.status="error",p.errorText=e.strings.errorGeneric,ae.play("error");let ke=new Error(Te?"stream error chunk":"empty reply");n.emit("error",ke),e.onError?.(ke)}else p.status="complete",ae.play("messageReceived"),ri(n,e,"assistant",co(p))}catch(Te){cc(Te)?_o(p)?m.value=m.value.filter(ze=>ze!==p):p.status="complete":(p.status="error",p.errorText=Pt(Te,e.strings),ae.play("error"),n.emit("error",Te),e.onError?.(Te))}finally{Me.detach(),Pn(!1),yn(null),wn(null),m.value=[...m.value]}},[q,Me,m,f,e,n,ae,o,i,En]),pi=D(()=>{if(we||Ko.current||qt.current||m.value.filter(T=>!T.ephemeral).at(-1)?.role!=="user")return;Ko.current=!0,W.info("regenerating dangling user turn (needs-generation)");let h=sn();m.value=[...m.value,h],Me.attach(h),at(h,{continueExisting:!1}).finally(()=>{Ko.current=!1})},[we,m,Me,at]);R(()=>{Go.current=pi},[pi]);let An=D((p,h)=>{if(we)return;let T=m.value.at(-1),N=T?.partsSig.value.find(U=>U.kind==="tool"&&U.toolCallId===p);if(!T||!N){W.warn("decideTool: tool part not found",{toolCallId:p});return}h(N),T.partsSig.value=[...T.partsSig.value],Ep(T)&&(T.status="streaming",m.value=[...m.value],Me.attach(T),at(T,{continueExisting:!0}))},[we,m,Me,at]),mi=D((p,h)=>{W.info("toolResult",{toolCallId:p}),n.emit("toolResult",{toolCallId:p}),An(p,T=>{T.outputSig.value=h,T.stateSig.value="output-available"})},[n,An]),fi=D((p,h,T)=>{W.info("toolDecision",{toolCallId:p,approved:h}),n.emit("toolDecision",{toolCallId:p,approved:h}),An(p,N=>{let U=N.approvalSig.value?.id??p;N.approvalSig.value={id:U,approved:h,reason:T},N.stateSig.value="approval-responded"})},[n,An]),gi=D(p=>{if(we)return;let h=m.value.at(-1),T=h?.partsSig.value.find(U=>U.kind==="tool"&&U.toolCallId===p);if(!h||!T)return;let N=T.approvalSig.value?.id??p;T.approvalSig.value={id:N},T.stateSig.value="approval-requested",h.partsSig.value=[...h.partsSig.value]},[we,m]),Cc=Re(()=>({humanInLoop:e.features.humanInLoop,onResult:mi,onDecision:fi,onEdit:gi}),[e.features.humanInLoop,mi,fi,gi]),Tc=()=>m.value.reduce((p,h)=>p+(h.role==="user"?1:0),0),kt=e.forms.list.length>0?e.forms:Y??e.forms,pe=Ol({forms:kt,persistence:o,userContext:()=>e.userContext,messageCount:Tc,pageArea:()=>e.pageContext?.area?String(e.pageContext.area):void 0,conversationId:()=>f.value,onComplete:(p,h,T,N)=>{W.info("formSubmit",{formId:p.id,trigger:h,skipped:N}),n.emit("formSubmit",{formId:p.id,values:T,skipped:N}),P(I=>{let ze=I.find(ke=>ke.formId===p.id&&ke.outcome==="skipped")?.createdAt??Date.now();return[...I.filter(ke=>!(ke.formId===p.id&&ke.outcome==="skipped")),{key:`local:${p.id}:${ze}`,formId:p.id,outcome:N?"skipped":"submitted",createdAt:ze,...N?{}:{values:T}}]});let U=f.value??Ue();f.value||(f.value=U,o.saveConversationId(U),q.primeIdentity(void 0,U)),!N&&p.mirrorToContext&&Sc(I=>({...I,...T})),q.submitForm({formId:p.id,conversationId:U,trigger:h,values:T,skipped:N})}}),Ec=j(()=>pe.activeForm.value);R(()=>{pe.refresh()},[kt,pe]);let hi=e.pageContext?.area?String(e.pageContext.area):void 0,Rc=j(()=>m.value.length);R(()=>{F&&k&&pe.fire("pre-chat")},[F,k,pe]),R(()=>{k&&!Vt&&pe.fire("conversation-closed")},[k,Vt,pe]),R(()=>{F&&k&&hi&&pe.fire("page-area")},[F,k,hi,pe]);let Jo=Re(()=>{let p=kt.list.flatMap(h=>h.triggers).filter(h=>h.kind==="idle").map(h=>Number(h.param));return p.length?Math.min(...p)*1e3:0},[kt]);R(()=>{if(!Jo||!ue)return;let p=setTimeout(()=>pe.fire("idle"),Jo);return()=>clearTimeout(p)},[Jo,ue,pe,Rc.value]);let vi=D(async(p,h)=>{if(W.info("send",{textLen:p.length,attachments:h.length,streaming:we}),we)return;n.emit("send",{text:p,attachmentCount:h.length}),Wo.length>0&&xn([]);let T=await Ip(q,h,I=>{W.warn("upload failed",{err:I}),n.emit("error",I),e.onError?.(I)});ae.unlock(),ae.play("messageSent");let N=cs(p,T),U=sn();m.value=[...m.value,N,U],Me.attach(U),ri(n,e,"user",p),await at(U,{continueExisting:!1}),pe.fire("after-messages")},[we,q,n,e,Wo.length,m,Me,at,pe]),Ac=D(()=>{W.info("stop"),n.emit("stop",void 0),si?.()},[si,n]),Ic=D(()=>{if(we)return;let p=m.value,h=p.at(-1);if(!h||h.role!=="assistant"||h.status!=="error"&&!ot(h))return;let T=sn();m.value=[...p.slice(0,-1),T],Me.attach(T),W.info("retry"),at(T,{continueExisting:!1})},[we,m,Me,at]),Lc=D(()=>{ae.toggleMuted();let p=ae.mutedSig.value;W.info("soundToggle",{muted:p}),n.emit("soundToggle",{muted:p})},[ae,n]),Yt=D(()=>{if(tl(e.mode,Le)==="exit-fullscreen"){W.info("close \u2192 exit-fullscreen",{mode:e.mode}),Fe("normal"),n.emit("fullscreen",!1);return}W.info("close \u2192 panel closed",{mode:e.mode}),pe.fire("panel-close"),Ie(!1),o.savePanelOpen(!1),n.emit("close",void 0),e.onClose?.()},[n,e,o,Le,pe]),Ct=D(()=>{e.modules.list.some(p=>p.layout==="chat")&&q.listConversations({limit:50}).then(p=>{C.value=p.conversations.reduce((h,T)=>h+(T.unreadCount??0),0)}).catch(p=>W.debug("refreshUnread failed (non-fatal)",{err:p}))},[q,e.modules,C]),bi=O(!1);R(()=>{!ie||!F||bi.current||(bi.current=!0,Ct())},[ie,F,Ct]);let Qo=D(()=>{W.info("open",{mode:e.mode}),ae.unlock(),Se(!0),Ie(!0),o.savePanelOpen(!0),!Ge&&!Ze&&Be(),setTimeout(()=>Se(!1),Ap),Ct(),n.emit("open",void 0),e.onOpen?.()},[n,e,ae,o,Ge,Ze,Be,Ct]),Zo=D(()=>{if(!m.value.some(h=>h.role==="user")&&Vt&&f.value){W.info("clear \u2192 reusing empty conversation",{conversationId:f.value}),m.value.length===0&&Cn(z.current?.messages);return}W.info("clear \u2192 new conversation",{wasStreaming:we}),n.emit("clear",void 0),we&&Sn?.(),Mt(()=>{m.value=[],f.value=void 0}),o.clearConversation(),Wt(!0),P([]),jt({newConversation:!0})},[we,Sn,m,f,o,jt,n,Vt,Cn]),er=D(()=>{Zo(),Vo("chat");let p=e.modules.list.find(h=>h.layout==="chat")?.id;p&&M.switchTab(p)},[Zo,M,e]),tr=D(()=>{let p=Le==="expanded"?"normal":"expanded";W.info("expand",{from:Le,expanded:p==="expanded"}),Fe(p),o.savePanelSize(p),n.emit("expand",p==="expanded")},[n,Le,o]),nr=D(()=>{let p=Le==="fullscreen"?"normal":"fullscreen";W.info("fullscreen",{from:Le,fullscreen:p==="fullscreen"}),Fe(p),o.savePanelSize(p),n.emit("fullscreen",p==="fullscreen")},[n,Le,o]),Mc=D(()=>{Vo(p=>{let h=p==="history"?"chat":"history";return W.info("toggleHistory",{view:h}),n.emit("toggleHistory",{view:h}),h})},[n]),Nc=D(p=>{W.info("localeChange",{locale:p}),c(p),je({locale:p}),n.emit("localeChange",p)},[je,n]),Oc=D(p=>{W.info("themeChange",{mode:p}),u(p),t.dataset.theme=p,je({themeMode:p}),n.emit("themeChange",p)},[t,je,n]),Dc=D(p=>{W.info("textSizeChange",{size:p}),g(p),t.dataset.textSize=p,je({textSize:p}),n.emit("textSizeChange",p)},[t,je,n]),$c=D(()=>{yc(p=>{let h=!p;return W.info("sidebarToggle",{collapsed:h}),o.saveSidebarCollapsed(h),n.emit("sidebarToggle",{collapsed:h}),h})},[o,n]),Hc=D(p=>{W.info("resize",p),je({widgetSize:p}),n.emit("resize",p)},[je,n]),or=D(async p=>{W.info("selectConversation",{conversationId:p,wasStreaming:we}),n.emit("selectConversation",{conversationId:p}),we&&Sn?.();try{let[h,T]=await Promise.all([q.loadConversation(p),Tn(p)]),N=Or(h.messages);Mt(()=>{m.value=Kt(N,T),f.value=h.conversationId}),P(T),o.saveConversationId(h.conversationId),q.primeIdentity(i,h.conversationId),h.agent&&ai(h.agent),Wt(h.canContinue),xn(h.suggestions??[]),Vo("chat"),Yo(),await q.markRead(p),Ct()}catch(h){n.emit("error",h),e.onError?.(h)}},[q,m,f,n,e,o,Ct,Tn,Kt,we,Sn,i,Yo]),In=O(null),Pi=D(p=>{typeof p=="string"&&(k?pe.fire("manual",p):In.current=p)},[k,pe]);R(()=>{!k||!In.current||(pe.fire("manual",In.current),In.current=null)},[k,pe]),R(()=>Xa(t,{open:Qo,close:Yt,expand:tr,fullscreen:nr,openForm:Pi}),[t,Qo,Yt,tr,nr,Pi]);let Oe=Re(()=>xr(e,s,d,_),[e,s,d,_]);kn.current=Oe.strings;let Bc=Re(()=>y.map(p=>{let h=kt.list.find(T=>T.id===p.formId);return{...p,title:h?.title,form:h}}),[y,kt]),xi={options:Oe,transport:q,feedback:ae,bus:n,persistence:o,view:fc,canSend:Vt,isStreaming:we,loadingMessages:v,messagesSig:m,agent:gc,suggestions:Wo,initialWidgetSize:l.widgetSize??null,visitorId:i,onClose:Yt,onClear:Zo,onExpand:tr,onFullscreen:nr,onSoundToggle:Lc,onToggleHistory:Mc,onSelectHistoryConversation:or,onNewConversation:er,onLocaleChange:Nc,onThemeChange:Oc,onTextSizeChange:Dc,onWidgetSizeChange:Hc,onSend:vi,onStop:Ac,onSuggestion:p=>{let h=p.text??p.label;W.info("suggestion",{text:h}),n.emit("suggestion",{text:h}),vi(h,[])},activeForm:Ec.value?.form??null,formMarkers:Bc,onFormSubmit:pe.complete,onFormSkip:pe.skip,onFormFill:p=>pe.fire("manual",p),tool:Cc,onRetry:Ic},Fc=p=>{or(p);let h=B();h&&M.switchTab(h)};if(!F)return null;let Jt=Oe.modules.list,rr=p=>{let h=pn("close",Oe.mode,p);return Jt.length===0?r(ac,{strings:Oe.strings,onClose:h?Yt:void 0}):Jt.length===1&&Jt[0]?.layout==="chat"?r(Nl,{...xi,panelSize:p}):r(ic,{panelProps:{...xi,panelSize:p,onClose:h?Yt:void 0},enabledModules:Jt,nav:M,bus:n,unreadCount:C.value,onSelectConversation:Fc,onStartNewConversation:er,onSetPanelSize:Fe})};if(e.mode==="page"){let p=T=>{or(T.conversationId)},h=Jt.some(T=>T.layout==="chat");return r("div",{class:`${Bo}-anchor`,children:r(Hl,{site:hc,blocks:bc,transport:q,strings:Oe.strings,locale:Oe.locale,persistence:o,visitorId:i,showConversations:h,onSelectConversation:p,onNewConversation:er,sidebarCollapsed:xc,onToggleSidebarCollapsed:$c,children:rr("fullscreen")})})}if(re){let p=e.mode==="standalone"?"fullscreen":Le;return r("div",{class:`${Bo}-anchor`,children:rr(p)})}let yi=e.mode==="drawer",Si=!(e.mode==="modal")&&!e.launcher.hidden&&(!ue||ye),wi=Si&&!ye&&!Ge&&!yi?Oe.launcher.callout:null;return r("div",{class:`${Bo}-anchor`,"data-launcher-size":Oe.launcher.size,children:[ue||ie?r("div",{class:`${Bo}-surface`,hidden:!ue,children:rr(Le)}):null,Si?r(Qs,{onToggle:Qo,launcher:Oe.launcher,strings:Oe.strings,leaving:ye,edgeTab:yi}):null,wi?r(Zs,{callout:wi,launcherPosition:Oe.position,strings:Oe.strings,closeLabel:Oe.strings.close,onDismiss:Be}):null]})}function Rp(e){let t=e?.url??(typeof location<"u"?location.href:void 0);if(!(!e&&!t))return{...e,...t?{url:t}:{}}}var Ap=120;async function Ip(e,t,n){let o=[];for(let i of t)try{let{id:a,url:l}=await e.uploadFile(i.file);o.push({id:a,name:i.name,mediaType:i.mediaType,size:i.size,url:l})}catch(a){n(a)}return o}function ri(e,t,n,o){let i={role:n,text:o};e.emit("message",i),t.onMessage?.(i)}var Lp=X.scope("error-boundary"),Fo=class extends lt{constructor(){super(...arguments);V(this,"state",{crashed:!1})}componentDidCatch(n,o){Lp.error("widget render crashed",{error:n,componentStack:o?.componentStack}),this.setState({crashed:!0}),this.props.onError(n,o?.componentStack)}render(){return this.state.crashed?this.props.fallback:this.props.children}};var Mp="1",Np=60,Op=2e3,_c={open:()=>{},close:()=>{},expand:e=>({on:e}),fullscreen:e=>({on:e}),send:e=>({attachments:e.attachmentCount}),message:e=>({role:e.role}),stop:()=>{},clear:()=>{},suggestion:()=>{},toggleHistory:e=>({view:e.view}),handshake:()=>{},formSubmit:e=>({formId:e.formId,skipped:e.skipped}),toolResult:()=>{},toolDecision:e=>({approved:e.approved}),contentView:e=>({section:e.section,tags:e.tags,count:e.count}),contentOpen:e=>({contentId:e.contentId,tags:e.tags}),contentSearch:e=>({qlen:e.queryLength,hits:e.hitCount}),contentRead:e=>({contentId:e.contentId}),contentLinkClick:e=>({contentId:e.contentId}),attach:e=>({count:e.count,bytes:e.totalBytes}),voiceStart:()=>{},voiceStop:e=>({ms:e.durationMs}),voiceCancel:()=>{},localeChange:e=>({locale:e}),themeChange:e=>({theme:e}),textSizeChange:e=>({size:e}),soundToggle:e=>({muted:e.muted}),sidebarToggle:e=>({collapsed:e.collapsed}),calloutDismiss:()=>{},error:()=>{}};function Dp(){let e=navigator;return e.globalPrivacyControl===!0||e.doNotTrack==="1"}function $p(){return location.origin+location.pathname}function Hp(){try{return document.referrer?new URL(document.referrer).origin:""}catch{return""}}function uc(e,t){let n=Math.random(),o=0,i=0,a=new Set,l=(c,d)=>{let{tracking:u,publicKey:_,aiAgentDeploymentId:g,mode:f,themeMode:m}=t.getOptions();if(!u.enabled||Dp()||n>=u.sampleRate)return;let C=performance.now();if(C-o>6e4&&(o=C,i=0),++i>Np)return;let v=new URLSearchParams;v.set("v",Mp),v.set("_ev",ao),v.set("e",c),u.token&&v.set("tk",u.token),_&&v.set("pk",_),g&&v.set("dep",g),v.set("vid",t.getVisitorId());let b=t.getConversationId();b&&v.set("cid",b),v.set("url",$p());let y=Hp();y&&v.set("ref",y),v.set("sw",String(screen.width)),v.set("sh",String(screen.height)),v.set("vw",String(innerWidth)),v.set("vh",String(innerHeight)),v.set("dpr",String(devicePixelRatio)),v.set("lang",navigator.language);try{v.set("tz",Intl.DateTimeFormat().resolvedOptions().timeZone)}catch{}if(v.set("m",f),v.set("th",m),d)for(let[le,M]of Object.entries(d))M!==void 0&&v.set(le,String(M));v.set("ts",String(Date.now()));let P=`${u.endpoint}?${v}`;if(P.length>Op)return;let E=new Image(1,1);a.add(E);let B=()=>a.delete(E);E.addEventListener("load",B,{once:!0}),E.addEventListener("error",B,{once:!0}),E.src=P},s=Object.keys(_c).map(c=>e.on(c,d=>l(c,_c[c]?.(d))));return()=>{for(let c of s)c();a.clear()}}function pc(e){let{bus:t,host:n,appRoot:o,persistence:i,reportError:a}=e,l=e.initialRaw,s,c=Rt(l),d=!0,u=()=>{c=Rt(s?yr(l,s):l)},_=()=>{Sa(n,jn(c.mode));let m=i.loadUserPrefs().themeMode;ka(n,m?{...c,themeMode:m}:c),d&&(Xn(n,Bp(c)),d=!1)},g=()=>{_(),zn(Fn(Fo,{onError:a},Fn(dc,{bus:t,hostElement:n,options:c})),o)};t.on("handshake",m=>{m.config&&(m.config.storageVersion&&i.rememberStorageVersion(m.config.storageVersion),s=m.config,u(),g())});let f=uc(t,{getOptions:()=>c,getVisitorId:()=>i.getVisitorId(),getConversationId:()=>i.loadConversationId()});return{getOptions:()=>c,getUserOptions:()=>l,render:g,setUserOptions:m=>{l=m,u(),g()},patchUserOptions:m=>{l={...l,...m},u(),g()},destroy:()=>f()}}function Bp(e){if(e.mode==="standalone")return"standalone";if(e.mode==="inline")return"inline";let t=It(e.widgetId,e.storage,e.aiAgentDeploymentId),{panelOpen:n,panelSize:o}=an(e,Dt(),t.loadPanelOpen(),t.loadPanelSize());return io(e.mode,o,n)}var zo=class{constructor(){V(this,"handlers",new Map)}on(t,n){let o=this.handlers.get(t);return o||(o=new Set,this.handlers.set(t,o)),o.add(n),()=>this.handlers.get(t)?.delete(n)}emit(t,n){let o=this.handlers.get(t);if(o)for(let i of o)try{i(n)}catch{}}clear(){this.handlers.clear()}};var ii=class extends HTMLElement{constructor(){super(...arguments);V(this,"bus",new zo);V(this,"mountResult",null);V(this,"runtime",null)}static get observedAttributes(){return Sr}connectedCallback(){this.boot()}disconnectedCallback(){this.mountResult&&(this.runtime?.destroy(),this.runtime=null,zn(null,this.mountResult.appRoot),this.bus.clear())}attributeChangedCallback(){this.isConnected&&this.boot()}boot(){let n=wr(a=>this.getAttribute(a));if(this.runtime){this.runtime.setUserOptions(n);return}let o=Rt(n);this.mountResult||(this.mountResult=wa({existingHost:this,position:jn(o.mode)}));let i=It(o.widgetId,o.storage,o.aiAgentDeploymentId);this.runtime=pc({bus:this.bus,host:this.mountResult.hostElement,appRoot:this.mountResult.appRoot,persistence:i,initialRaw:n,reportError:a=>this.bus.emit("error",a)}),this.runtime.render()}},mc=!1;function Fp(){if(mc||typeof customElements>"u")return;let e=x.tagName;customElements.get(e)||customElements.define(e,ii),mc=!0}typeof customElements<"u"&&Fp();export{Fp as registerWebComponent};
40
40
  //# sourceMappingURL=elements-web-component.esm.js.map