@helpai/elements 0.56.2 → 0.56.3

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 Wc=Object.defineProperty;var Gc=(e,t,n)=>t in e?Wc(e,t,{enumerable:!0,config
4
4
  `;var vi=`.__P__-standalone-page{margin:0;height:100vh;background:var(--__P__-bg, #fff);display:grid;place-items:stretch}
5
5
  `;var bi=`: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 Hd="helpai",zd="#5B5BD6",Ud="#FFFFFF",Vd="12px",qd="Inter, system-ui, -apple-system, 'Segoe UI', sans-serif",kr=[fi,gi,hi,vi,bi].join(`
7
- `).replace(/__P__/g,Hd).replaceAll("__BRAND_ACCENT_TEXT__",Ud).replaceAll("__BRAND_ACCENT__",zd).replaceAll("__BRAND_RADIUS__",Vd).replaceAll("__BRAND_FONT__",qd);var Wd=Z.scope("mount"),Pi=new WeakMap,xi={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 yi(e,t){e.style.cssText=xi[t]}function Xn(e){return e==="floating"||e==="modal"||e==="drawer"?"floating":e==="standalone"||e==="page"?"viewport":"flow"}function Si(e={}){let t=e.position??"flow";Wd.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=xi[t];let a=o.shadowRoot??o.attachShadow({mode:"open"}),i=o.ownerDocument;if(!Gd(a,i)){let s=i.createElement("style");s.textContent=kr,a.appendChild(s)}let l=document.createElement("div");return l.className=`${x.cssPrefix}-app`,a.appendChild(l),{appRoot:l,destroy:()=>o.remove(),hostElement:o,shadowRoot:a}}function Gd(e,t){if(!("adoptedStyleSheets"in e))return!1;let n=t.defaultView;if(!n||typeof n.CSSStyleSheet!="function")return!1;let o=Pi.get(t);if(!o)try{o=new n.CSSStyleSheet,o.replaceSync(kr),Pi.set(t,o)}catch{return!1}try{return e.adoptedStyleSheets=[o],!0}catch{return!1}}function Kd(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 jd(e,t){e.dataset.theme=t}function Xd(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 Yd(e,t){e.dataset.position=t}function Yn(e,t){e.dataset.mode=t}function ki(e,t){jd(e,t.themeMode),Kd(e,t.themeOverrides),Yd(e,t.position),Xd(e,t.size)}var $t,me,wr,wi,nn=0,Ni=[],ge=ee,Ci=ge.__b,Ti=ge.__r,Ei=ge.diffed,Ri=ge.__c,Ai=ge.unmount,Ii=ge.__;function Jn(e,t){ge.__h&&ge.__h(me,e,nn||t),nn=0;var n=me.__H||(me.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function R(e){return nn=1,Jd(Oi,e)}function Jd(e,t,n){var o=Jn($t++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):Oi(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 a=function(s,c,d){if(!o.__c.__H)return!0;var u=!1,h=o.__c.props!==s;if(o.__c.__H.__.some(function(f){if(f.__N){u=!0;var m=f.__[0];f.__=f.__N,f.__N=void 0,m!==f.__[0]&&(h=!0)}}),i){var _=i.call(this,s,c,d);return u?_||h:_}return!u||h};me.__f=!0;var i=me.shouldComponentUpdate,l=me.componentWillUpdate;me.componentWillUpdate=function(s,c,d){if(this.__e){var u=i;i=void 0,a(s,c,d),i=u}l&&l.call(this,s,c,d)},me.shouldComponentUpdate=a}return o.__N||o.__}function T(e,t){var n=Jn($t++,3);!ge.__s&&Tr(n.__H,t)&&(n.__=e,n.u=t,me.__H.__h.push(n))}function vt(e,t){var n=Jn($t++,4);!ge.__s&&Tr(n.__H,t)&&(n.__=e,n.u=t,me.__h.push(n))}function D(e){return nn=5,Ae(function(){return{current:e}},[])}function Ae(e,t){var n=Jn($t++,7);return Tr(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function $(e,t){return nn=8,Ae(function(){return e},t)}function Li(){for(var e;e=Ni.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Cr),t.__h.some(Di),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){me=null,Ci&&Ci(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ii&&Ii(e,t)},ge.__r=function(e){Ti&&Ti(e),$t=0;var t=(me=e.__c).__H;t&&(wr===me?(t.__h=[],me.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.length&&Li(),$t=0)),wr=me},ge.diffed=function(e){Ei&&Ei(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Ni.push(t)!==1&&wi===ge.requestAnimationFrame||((wi=ge.requestAnimationFrame)||Qd)(Li)),t.__H.__.some(function(n){n.u&&(n.__H=n.u,n.u=void 0)})),wr=me=null},ge.__c=function(e,t){t.some(function(n){try{n.__h.some(Cr),n.__h=n.__h.filter(function(o){return!o.__||Di(o)})}catch(o){t.some(function(a){a.__h&&(a.__h=[])}),t=[],ge.__e(o,n.__v)}}),Ri&&Ri(e,t)},ge.unmount=function(e){Ai&&Ai(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{Cr(o)}catch(a){t=a}}),n.__H=void 0,t&&ge.__e(t,n.__v))};var Mi=typeof requestAnimationFrame=="function";function Qd(e){var t,n=function(){clearTimeout(o),Mi&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Mi&&(t=requestAnimationFrame(n))}function Cr(e){var t=me,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),me=t}function Di(e){var t=me;e.__c=e.__(),me=t}function Tr(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function Oi(e,t){return typeof t=="function"?t(e):t}var Zd=Symbol.for("preact-signals");function to(){if(ot>1)ot--;else{var e,t=!1;for((function(){var a=Zn;for(Zn=void 0;a!==void 0;)a.S.v===a.v&&(a.S.i=a.i),a=a.o})();on!==void 0;){var n=on;for(on=void 0,Qn++;n!==void 0;){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Bi(n))try{n.c()}catch(a){t||(e=a,t=!0)}n=o}}if(Qn=0,ot--,t)throw e}}function Ft(e){if(ot>0)return e();Er=++e_,ot++;try{return e()}finally{to()}}var ce=void 0;function rn(e){var t=ce;ce=void 0;try{return e()}finally{ce=t}}var $i,on=void 0,ot=0,Qn=0,e_=0,Er=0,Zn=void 0,eo=0;function Fi(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=Zd;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:rn(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&&rn(function(){var a;(a=t.Z)==null||a.call(t)}))}};Pe.prototype.subscribe=function(e){var t=this;return rt(function(){var n=t.value;rn(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 rn(function(){return e.value})};Object.defineProperty(Pe.prototype,"value",{get:function(){var e=Fi(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){ot!==0&&Qn===0&&n.l!==Er&&(n.l=Er,Zn={S:n,v:n.v,i:n.i,o:Zn})})(this),this.v=e,this.i++,eo++,ot++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{to()}}}});function B(e,t){return new Pe(e,t)}function Bi(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 Hi(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 zi(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 bt(e,t){Pe.call(this,void 0,t),this.x=e,this.s=void 0,this.g=eo-1,this.f=4}bt.prototype=new Pe;bt.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&&!Bi(this))return this.f&=-2,!0;var e=ce;try{Hi(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,zi(this),this.f&=-2,!0};bt.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)};bt.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)}};bt.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(bt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Fi(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function an(e,t){return new bt(e,t)}function Ui(e){var t=e.m;if(e.m=void 0,typeof t=="function"){ot++;var n=ce;ce=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,Rr(e),o}finally{ce=n,to()}}}function Rr(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Ui(e)}function t_(e){if(ce!==this)throw new Error("Out-of-order effect");zi(this),ce=e,this.f&=-2,8&this.f&&Rr(this),to()}function Bt(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,$i&&$i.push(this)}Bt.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()}};Bt.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Ui(this),Hi(this),ot++;var e=ce;return ce=this,t_.bind(this,e)};Bt.prototype.N=function(){2&this.f||(this.f|=2,this.u=on,on=this)};Bt.prototype.d=function(){this.f|=8,1&this.f||Rr(this)};Bt.prototype.dispose=function(){this.d()};function rt(e,t){var n=new Bt(e,t);try{n.c()}catch(a){throw n.d(),a}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var Vi,ro,no,n_=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var qi=[];rt(function(){Vi=this.N})();function Ht(e,t){ee[e]=t.bind(null,ee[e]||function(){})}function oo(e){if(no){var t=no;no=void 0,t()}no=e&&e.S()}function Wi(e){var t=this,n=e.data,o=sn(n);o.value=n;var a=Ae(function(){for(var s=t,c=t.__v;c=c.__;)if(c.__c){c.__c.__$f|=4;break}var d=an(function(){var f=o.value.value;return f===0?0:f===!0?"":f||""}),u=an(function(){return!Array.isArray(d.value)&&!lr(d.value)}),h=rt(function(){if(this.N=Gi,u.value){var f=d.value;s.__v&&s.__v.__e&&s.__v.__e.nodeType===3&&(s.__v.__e.data=f)}}),_=t.__$u.d;return t.__$u.d=function(){h(),_.call(this)},[u,d]},[]),i=a[0],l=a[1];return i.value?l.peek():l.value}Wi.displayName="ReactiveTextNode";Object.defineProperties(Pe.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Wi},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});Ht("__b",function(e,t){if(typeof t.type=="string"){var n,o=t.props;for(var a in o)if(a!=="children"){var i=o[a];i instanceof Pe&&(n||(t.__np=n={}),n[a]=i,o[a]=i.peek())}}e(t)});Ht("__r",function(e,t){if(e(t),t.type!==oe){oo();var n,o=t.__c;o&&(o.__$f&=-2,(n=o.__$u)===void 0&&(o.__$u=n=(function(a,i){var l;return rt(function(){l=this},{name:i}),l.c=a,l})(function(){var a;n_&&((a=n.y)==null||a.call(n)),o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),ro=o,oo(n)}});Ht("__e",function(e,t,n,o){oo(),ro=void 0,e(t,n,o)});Ht("diffed",function(e,t){oo(),ro=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var o=t.__np,a=t.props;if(o){var i=n.U;if(i)for(var l in i){var s=i[l];s!==void 0&&!(l in o)&&(s.d(),i[l]=void 0)}else i={},n.U=i;for(var c in o){var d=i[c],u=o[c];d===void 0?(d=o_(n,c,u,a),i[c]=d):d.o(u,a)}}}e(t)});function o_(e,t,n,o){var a=t in e&&e.ownerSVGElement===void 0,i=B(n);return{o:function(l,s){i.value=l,o=s},d:rt(function(){this.N=Gi;var l=i.value.value;o[t]!==l&&(o[t]=l,a?e[t]=l:l!=null&&(l!==!1||t[4]==="-")?e.setAttribute(t,l):e.removeAttribute(t))})}}Ht("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 a in o){var i=o[a];i&&i.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)});Ht("__h",function(e,t,n,o){(o<3||o===9)&&(t.__$f|=2),e(t,n,o)});dt.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,o=n&&n.s!==void 0;for(var a in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var i=2&this.__$f;if(!(o||i||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 sn(e,t){return Ae(function(){return B(e,t)},[])}function J(e,t){var n=D(e);return n.current=e,ro.__$f|=4,Ae(function(){return an(function(){return n.current()},t)},[])}var r_=function(e){queueMicrotask(function(){queueMicrotask(e)})};function a_(){Ft(function(){for(var e;e=qi.shift();)Vi.call(e)})}function Gi(){qi.push(this)===1&&(ee.requestAnimationFrame||r_)(a_)}function Ki(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ji(e){return Ki(e)}function Xi(e){return!(!Ki(e)||e.navigation!==void 0&&!Array.isArray(e.navigation)||e.linkCards!==void 0&&!Array.isArray(e.linkCards))}function i_(e){return`${x.cssPrefix}:${e}`}function Yi(e,t){let o=Object.entries(t).map(([a,i])=>{let l=i_(a),s=c=>i(c.detail);return e.addEventListener(l,s),[l,s]});return()=>{for(let[a,i]of o)e.removeEventListener(a,i)}}function ao(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 s_=900;function Ar(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 a=t.autoSizeBreakpoint??s_;return n>=a?"expanded":"normal"}return"normal"}function ln(e,t,n,o=null){let i=e.mode==="inline"||e.mode==="standalone"||e.mode==="page"||(n??!e.startMinimized),s=e.mode!=="standalone"&&e.mode!=="page"&&e.mode!=="inline"&&o?o:Ar(e.mode,e.size,t);return{panelOpen:i,panelSize:s}}function zt(){return typeof window>"u"?0:window.innerWidth}var l_="x-public-key",c_="x-ai-agent-deployment-id";function Ji(e){return{headers(){let t={};return e.aiAgentDeploymentId&&(t[c_]=e.aiAgentDeploymentId),e.publicKey&&(t[e.publicKeyHeader??l_]=e.publicKey),t}}}var io="0.56.2";var qe=class extends Error{constructor(n,o,a,i){super(n);j(this,"code",o);j(this,"status",a);j(this,"cause",i);this.name="StreamError"}};var Qi=Z.scope("parser");async function*Ir(e,t){if(!e.ok){let a=await e.text().catch(()=>"");throw new qe(`server responded ${e.status}: ${a.slice(0,200)}`,"server",e.status)}if(!e.body)throw new qe("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:a,value:i}=await n.read();if(a){let s=o.trim();if(s){let c=Zi(s);c&&(yield c)}return}o+=i;let l;for(;(l=o.indexOf(`
7
+ `).replace(/__P__/g,Hd).replaceAll("__BRAND_ACCENT_TEXT__",Ud).replaceAll("__BRAND_ACCENT__",zd).replaceAll("__BRAND_RADIUS__",Vd).replaceAll("__BRAND_FONT__",qd);var Wd=Z.scope("mount"),Pi=new WeakMap,xi={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 yi(e,t){e.style.cssText=xi[t]}function Xn(e){return e==="floating"||e==="modal"||e==="drawer"?"floating":e==="standalone"||e==="page"?"viewport":"flow"}function Si(e={}){let t=e.position??"flow";Wd.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=xi[t];let a=o.shadowRoot??o.attachShadow({mode:"open"}),i=o.ownerDocument;if(!Gd(a,i)){let s=i.createElement("style");s.textContent=kr,a.appendChild(s)}let l=document.createElement("div");return l.className=`${x.cssPrefix}-app`,a.appendChild(l),{appRoot:l,destroy:()=>o.remove(),hostElement:o,shadowRoot:a}}function Gd(e,t){if(!("adoptedStyleSheets"in e))return!1;let n=t.defaultView;if(!n||typeof n.CSSStyleSheet!="function")return!1;let o=Pi.get(t);if(!o)try{o=new n.CSSStyleSheet,o.replaceSync(kr),Pi.set(t,o)}catch{return!1}try{return e.adoptedStyleSheets=[o],!0}catch{return!1}}function Kd(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 jd(e,t){e.dataset.theme=t}function Xd(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 Yd(e,t){e.dataset.position=t}function Yn(e,t){e.dataset.mode=t}function ki(e,t){jd(e,t.themeMode),Kd(e,t.themeOverrides),Yd(e,t.position),Xd(e,t.size)}var $t,me,wr,wi,nn=0,Ni=[],ge=ee,Ci=ge.__b,Ti=ge.__r,Ei=ge.diffed,Ri=ge.__c,Ai=ge.unmount,Ii=ge.__;function Jn(e,t){ge.__h&&ge.__h(me,e,nn||t),nn=0;var n=me.__H||(me.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function R(e){return nn=1,Jd(Oi,e)}function Jd(e,t,n){var o=Jn($t++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):Oi(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 a=function(s,c,d){if(!o.__c.__H)return!0;var u=!1,h=o.__c.props!==s;if(o.__c.__H.__.some(function(f){if(f.__N){u=!0;var m=f.__[0];f.__=f.__N,f.__N=void 0,m!==f.__[0]&&(h=!0)}}),i){var _=i.call(this,s,c,d);return u?_||h:_}return!u||h};me.__f=!0;var i=me.shouldComponentUpdate,l=me.componentWillUpdate;me.componentWillUpdate=function(s,c,d){if(this.__e){var u=i;i=void 0,a(s,c,d),i=u}l&&l.call(this,s,c,d)},me.shouldComponentUpdate=a}return o.__N||o.__}function T(e,t){var n=Jn($t++,3);!ge.__s&&Tr(n.__H,t)&&(n.__=e,n.u=t,me.__H.__h.push(n))}function vt(e,t){var n=Jn($t++,4);!ge.__s&&Tr(n.__H,t)&&(n.__=e,n.u=t,me.__h.push(n))}function D(e){return nn=5,Ae(function(){return{current:e}},[])}function Ae(e,t){var n=Jn($t++,7);return Tr(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function $(e,t){return nn=8,Ae(function(){return e},t)}function Li(){for(var e;e=Ni.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Cr),t.__h.some(Di),t.__h=[]}catch(n){t.__h=[],ge.__e(n,e.__v)}}}ge.__b=function(e){me=null,Ci&&Ci(e)},ge.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ii&&Ii(e,t)},ge.__r=function(e){Ti&&Ti(e),$t=0;var t=(me=e.__c).__H;t&&(wr===me?(t.__h=[],me.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.length&&Li(),$t=0)),wr=me},ge.diffed=function(e){Ei&&Ei(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Ni.push(t)!==1&&wi===ge.requestAnimationFrame||((wi=ge.requestAnimationFrame)||Qd)(Li)),t.__H.__.some(function(n){n.u&&(n.__H=n.u,n.u=void 0)})),wr=me=null},ge.__c=function(e,t){t.some(function(n){try{n.__h.some(Cr),n.__h=n.__h.filter(function(o){return!o.__||Di(o)})}catch(o){t.some(function(a){a.__h&&(a.__h=[])}),t=[],ge.__e(o,n.__v)}}),Ri&&Ri(e,t)},ge.unmount=function(e){Ai&&Ai(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(o){try{Cr(o)}catch(a){t=a}}),n.__H=void 0,t&&ge.__e(t,n.__v))};var Mi=typeof requestAnimationFrame=="function";function Qd(e){var t,n=function(){clearTimeout(o),Mi&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);Mi&&(t=requestAnimationFrame(n))}function Cr(e){var t=me,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),me=t}function Di(e){var t=me;e.__c=e.__(),me=t}function Tr(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function Oi(e,t){return typeof t=="function"?t(e):t}var Zd=Symbol.for("preact-signals");function to(){if(ot>1)ot--;else{var e,t=!1;for((function(){var a=Zn;for(Zn=void 0;a!==void 0;)a.S.v===a.v&&(a.S.i=a.i),a=a.o})();on!==void 0;){var n=on;for(on=void 0,Qn++;n!==void 0;){var o=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Bi(n))try{n.c()}catch(a){t||(e=a,t=!0)}n=o}}if(Qn=0,ot--,t)throw e}}function Ft(e){if(ot>0)return e();Er=++e_,ot++;try{return e()}finally{to()}}var ce=void 0;function rn(e){var t=ce;ce=void 0;try{return e()}finally{ce=t}}var $i,on=void 0,ot=0,Qn=0,e_=0,Er=0,Zn=void 0,eo=0;function Fi(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=Zd;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:rn(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&&rn(function(){var a;(a=t.Z)==null||a.call(t)}))}};Pe.prototype.subscribe=function(e){var t=this;return rt(function(){var n=t.value;rn(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 rn(function(){return e.value})};Object.defineProperty(Pe.prototype,"value",{get:function(){var e=Fi(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){ot!==0&&Qn===0&&n.l!==Er&&(n.l=Er,Zn={S:n,v:n.v,i:n.i,o:Zn})})(this),this.v=e,this.i++,eo++,ot++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{to()}}}});function B(e,t){return new Pe(e,t)}function Bi(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 Hi(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 zi(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 bt(e,t){Pe.call(this,void 0,t),this.x=e,this.s=void 0,this.g=eo-1,this.f=4}bt.prototype=new Pe;bt.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&&!Bi(this))return this.f&=-2,!0;var e=ce;try{Hi(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,zi(this),this.f&=-2,!0};bt.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)};bt.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)}};bt.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(bt.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Fi(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function an(e,t){return new bt(e,t)}function Ui(e){var t=e.m;if(e.m=void 0,typeof t=="function"){ot++;var n=ce;ce=void 0;try{t()}catch(o){throw e.f&=-2,e.f|=8,Rr(e),o}finally{ce=n,to()}}}function Rr(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Ui(e)}function t_(e){if(ce!==this)throw new Error("Out-of-order effect");zi(this),ce=e,this.f&=-2,8&this.f&&Rr(this),to()}function Bt(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,$i&&$i.push(this)}Bt.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()}};Bt.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Ui(this),Hi(this),ot++;var e=ce;return ce=this,t_.bind(this,e)};Bt.prototype.N=function(){2&this.f||(this.f|=2,this.u=on,on=this)};Bt.prototype.d=function(){this.f|=8,1&this.f||Rr(this)};Bt.prototype.dispose=function(){this.d()};function rt(e,t){var n=new Bt(e,t);try{n.c()}catch(a){throw n.d(),a}var o=n.d.bind(n);return o[Symbol.dispose]=o,o}var Vi,ro,no,n_=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__;var qi=[];rt(function(){Vi=this.N})();function Ht(e,t){ee[e]=t.bind(null,ee[e]||function(){})}function oo(e){if(no){var t=no;no=void 0,t()}no=e&&e.S()}function Wi(e){var t=this,n=e.data,o=sn(n);o.value=n;var a=Ae(function(){for(var s=t,c=t.__v;c=c.__;)if(c.__c){c.__c.__$f|=4;break}var d=an(function(){var f=o.value.value;return f===0?0:f===!0?"":f||""}),u=an(function(){return!Array.isArray(d.value)&&!lr(d.value)}),h=rt(function(){if(this.N=Gi,u.value){var f=d.value;s.__v&&s.__v.__e&&s.__v.__e.nodeType===3&&(s.__v.__e.data=f)}}),_=t.__$u.d;return t.__$u.d=function(){h(),_.call(this)},[u,d]},[]),i=a[0],l=a[1];return i.value?l.peek():l.value}Wi.displayName="ReactiveTextNode";Object.defineProperties(Pe.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Wi},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});Ht("__b",function(e,t){if(typeof t.type=="string"){var n,o=t.props;for(var a in o)if(a!=="children"){var i=o[a];i instanceof Pe&&(n||(t.__np=n={}),n[a]=i,o[a]=i.peek())}}e(t)});Ht("__r",function(e,t){if(e(t),t.type!==oe){oo();var n,o=t.__c;o&&(o.__$f&=-2,(n=o.__$u)===void 0&&(o.__$u=n=(function(a,i){var l;return rt(function(){l=this},{name:i}),l.c=a,l})(function(){var a;n_&&((a=n.y)==null||a.call(n)),o.__$f|=1,o.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),ro=o,oo(n)}});Ht("__e",function(e,t,n,o){oo(),ro=void 0,e(t,n,o)});Ht("diffed",function(e,t){oo(),ro=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var o=t.__np,a=t.props;if(o){var i=n.U;if(i)for(var l in i){var s=i[l];s!==void 0&&!(l in o)&&(s.d(),i[l]=void 0)}else i={},n.U=i;for(var c in o){var d=i[c],u=o[c];d===void 0?(d=o_(n,c,u,a),i[c]=d):d.o(u,a)}}}e(t)});function o_(e,t,n,o){var a=t in e&&e.ownerSVGElement===void 0,i=B(n);return{o:function(l,s){i.value=l,o=s},d:rt(function(){this.N=Gi;var l=i.value.value;o[t]!==l&&(o[t]=l,a?e[t]=l:l!=null&&(l!==!1||t[4]==="-")?e.setAttribute(t,l):e.removeAttribute(t))})}}Ht("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 a in o){var i=o[a];i&&i.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)});Ht("__h",function(e,t,n,o){(o<3||o===9)&&(t.__$f|=2),e(t,n,o)});dt.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,o=n&&n.s!==void 0;for(var a in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var i=2&this.__$f;if(!(o||i||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 sn(e,t){return Ae(function(){return B(e,t)},[])}function J(e,t){var n=D(e);return n.current=e,ro.__$f|=4,Ae(function(){return an(function(){return n.current()},t)},[])}var r_=function(e){queueMicrotask(function(){queueMicrotask(e)})};function a_(){Ft(function(){for(var e;e=qi.shift();)Vi.call(e)})}function Gi(){qi.push(this)===1&&(ee.requestAnimationFrame||r_)(a_)}function Ki(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function ji(e){return Ki(e)}function Xi(e){return!(!Ki(e)||e.navigation!==void 0&&!Array.isArray(e.navigation)||e.linkCards!==void 0&&!Array.isArray(e.linkCards))}function i_(e){return`${x.cssPrefix}:${e}`}function Yi(e,t){let o=Object.entries(t).map(([a,i])=>{let l=i_(a),s=c=>i(c.detail);return e.addEventListener(l,s),[l,s]});return()=>{for(let[a,i]of o)e.removeEventListener(a,i)}}function ao(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 s_=900;function Ar(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 a=t.autoSizeBreakpoint??s_;return n>=a?"expanded":"normal"}return"normal"}function ln(e,t,n,o=null){let i=e.mode==="inline"||e.mode==="standalone"||e.mode==="page"||(n??!e.startMinimized),s=e.mode!=="standalone"&&e.mode!=="page"&&e.mode!=="inline"&&o?o:Ar(e.mode,e.size,t);return{panelOpen:i,panelSize:s}}function zt(){return typeof window>"u"?0:window.innerWidth}var l_="x-public-key",c_="x-ai-agent-deployment-id";function Ji(e){return{headers(){let t={};return e.aiAgentDeploymentId&&(t[c_]=e.aiAgentDeploymentId),e.publicKey&&(t[e.publicKeyHeader??l_]=e.publicKey),t}}}var io="0.56.3";var qe=class extends Error{constructor(n,o,a,i){super(n);j(this,"code",o);j(this,"status",a);j(this,"cause",i);this.name="StreamError"}};var Qi=Z.scope("parser");async function*Ir(e,t){if(!e.ok){let a=await e.text().catch(()=>"");throw new qe(`server responded ${e.status}: ${a.slice(0,200)}`,"server",e.status)}if(!e.body)throw new qe("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:a,value:i}=await n.read();if(a){let s=o.trim();if(s){let c=Zi(s);c&&(yield c)}return}o+=i;let l;for(;(l=o.indexOf(`
8
8
 
9
9
  `))!==-1;){let s=o.slice(0,l);o=o.slice(l+2);let c=Zi(s);c&&(yield c)}}}finally{n.releaseLock()}}function Zi(e){let t="",n;for(let o of e.split(`
10
10
  `))if(!(o===""||o.startsWith(":"))){if(o.startsWith("data:")){let a=o.slice(5).replace(/^ /,"");t=t?`${t}
11
- ${a}`:a;continue}o.startsWith("id:")&&(n=o.slice(3).trim())}if(!t||t==="[DONE]")return null;try{let o=JSON.parse(t);return Qi.trace("chunk",{type:o.type,eventId:n}),{chunk:o,eventId:n}}catch(o){return Qi.trace("frame parse failed",{err:o,payload:t.slice(0,200)}),null}}function d_(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 es=e=>e&&Object.keys(e).length>0?e:void 0;function ts(e,t){let n=es(e),o=es(t);if(!n&&!o)return;let a={};return n&&(a.user=n),o&&(a.page=o),d_(JSON.stringify(a))}function so(e){if(!e)return;let t=Date.parse(e);return Number.isFinite(t)?t:void 0}function __(e){return`tool-${e.startsWith("tool:")?e.slice(5):e}`}function ns(e){return e.startsWith("tool-")?e.slice(5):e}var Be={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",messageFeedback:"/pai/message-feedback",bootstrap:"/pai/bootstrap",content:"/pai/content",submitForm:"/pai/submit-form"},os="context";function rs(e){let t=e.messages.map(i=>({id:i.serverMessageId??i.id,parts:m_(i),role:i.role,createdAt:i.createdAt!==void 0?new Date(i.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 a=e.tools?.map(p_).filter(i=>i!==null);return a?.length&&(n.data={tools:a}),n}function u_(e){return e.state==="output-available"||e.state==="output-error"||e.state==="output-denied"||e.approval?.approved!==void 0}function p_(e){return typeof e=="string"?e?{code:e}:null:e?.code?e:null}function m_(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"&&u_(n)){let o={type:__(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=Z.scope("transport"),as=3,cs=400,f_=6e4,is=1e4,ss=3,g_=new Set([408,425,429,500,502,503,504]);function ls(e){return cs*2**e+Math.floor(Math.random()*250)}function h_(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 Lr(e,t){return new Promise(n=>{if(t?.aborted)return n();let o=setTimeout(i,e),a=()=>i();t?.addEventListener("abort",a,{once:!0});function i(){clearTimeout(o),t?.removeEventListener("abort",a),n()}})}var lo=class{constructor(t){j(this,"opts",t);j(this,"visitorId");j(this,"conversationId");j(this,"resumeStatus");j(this,"userContext");j(this,"pageContext");j(this,"locale");j(this,"conversationsCache",new Map);j(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:io};this.visitorId&&(t.visitorId=this.visitorId),this.conversationId&&(t.conversationId=this.conversationId),this.locale&&(t.locale=this.locale);let n=ts(this.userContext,this.pageContext);return n&&(t[os]=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,a]of Object.entries(this.envelope()))n.searchParams.has(o)||n.searchParams.set(o,a);return n.toString()}async handshake(t){Q.debug("handshake \u2192",{visitorId:t.visitorId,conversationId:t.conversationId,locale:t.locale});let n=await this.postJson(Be.handshake,t,"handshake");return Q.debug("handshake \u2190",{visitorId:n.visitorId,conversationId:n.conversationId,hasWelcome:!!n.welcome,hasConfig:!!n.config,rebind:n.rebind}),b_(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.${v_(n)}`),o.append("mimeType",n);let a=await this.postForm(this.transcribePath,o,"transcribe");return Q.debug("transcribe \u2190",{textLen:a.text.length}),a}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 a={at:Date.now(),result:this.fetchConversations(t).then(i=>(a.value=i,i)).catch(i=>{throw this.conversationsCache.delete(n),i})};return this.conversationsCache.set(n,a),a.result}async fetchConversations(t){let n=new URL(this.url(Be.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"),a=o.conversations??[];return Q.debug("listConversations \u2190",{count:a.length,nextCursor:o.nextCursor}),{conversations:a.map(i=>({conversationId:i.conversationId,title:i.title,lastMessageAt:i.lastMessageAt,preview:i.preview,canContinue:i.canContinue,hasUnread:i.hasUnread})),nextCursor:o.nextCursor}}async loadConversation(t){let n=new URL(this.url(Be.listMessages));n.searchParams.set("conversationId",t),Q.debug("loadConversation \u2192",{conversationId:t,visitorId:this.visitorId});let o=await this.getJson(n.toString(),"loadConversation"),a=o.messages??[];return Q.debug("loadConversation \u2190",{conversationId:o.conversationId,canContinue:o.canContinue,messageCount:a.length,hasSuggestions:!!o.suggestions}),{conversationId:o.conversationId,canContinue:o.canContinue??!0,messages:a,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(Be.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<f_)return Q.debug("listContent \u2192 cache",t),o.result;let a=this.fetchContent(t).catch(i=>{throw this.contentCache.delete(n),i});return this.contentCache.set(n,{at:Date.now(),result:a}),a}async fetchContent(t){let n=new URL(this.dataUrl(Be.content));for(let[i,l]of Object.entries(t))l!==void 0&&n.searchParams.set(i,Array.isArray(l)?l.join(","):String(l));Q.debug("listContent \u2192",t);let o=await this.getJson(n.toString(),"listContent"),a=(o.items??[]).map(i=>Ua(i,this.locale));return Q.debug("listContent \u2190",{count:a.length,total:o.pagination?.total}),{...o,items:a}}async bootstrap(t){let n=new URL(this.dataUrl(Be.bootstrap));t&&n.searchParams.set("conversationId",t),Q.debug("bootstrap \u2192",{conversationId:t??this.conversationId});let o=await this.getJson(n.toString(),"bootstrap"),a=o.forms??[],i=o.formSubmissions??[];return Q.debug("bootstrap \u2190",{forms:a.length,formSubmissions:i.length}),{forms:a,formSubmissions:i}}async saveUserPrefs(t){Q.debug("saveUserPrefs \u2192",{visitorId:this.visitorId,conversationId:this.conversationId,settingsKeys:Object.keys(t)});let n=await this.postJson(Be.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??Be.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})}}async submitFeedback(t){Q.debug("submitFeedback \u2192",{messageId:t.messageId,value:t.value});try{await this.postJson(Be.messageFeedback,{messageId:t.messageId,set:{feedback:t.value}},"submitFeedback")}catch(n){Q.debug("submitFeedback 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),a=()=>t.abort();return{iter:o,cancel:a,detach:a}}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 a=1;a<=as&&!t.signal.aborted;a++){if((!o||a>1)&&(await Lr(cs*a,t.signal),t.signal.aborted))return;let i;try{i=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:a,err:c});continue}if(i.status===204||!i.ok){Q.debug("resume \u2192 no in-flight stream",{status:i.status});return}if(!(i.headers.get("content-type")??"").includes("text/event-stream")){let c=await i.json().then(d=>d.status).catch(()=>{});if(Q.debug("resume \u2192 no live stream (status response)",{status:c,attempt:a}),c==="pending"&&a<as)continue;this.resumeStatus=c==="needs-generation"?"needs-generation":"completed";return}this.resumeStatus="live";let s=n.size;if(yield*this.drain(Ir(i,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 qe("stream incomplete after resume attempts","server")}async*drain(t,n,o){try{for await(let a of t){if(o.signal.aborted)return!0;if(a.eventId){if(n.has(a.eventId))continue;n.add(a.eventId)}if(yield a,a.chunk.type==="finish"||a.chunk.type==="error")return!0}}catch(a){if(o.signal.aborted)return!0;if(a instanceof qe&&a.status!==void 0)throw a;Q.debug("stream segment dropped",{err:a})}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(Be.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(Be.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*Ir(o,n)}resumeUrl(t){let n=new URL(this.withEnvelopeQuery(Be.streamResume));return n.searchParams.set("resumeAt",String(t)),n.toString()}async postJson(t,n,o){let a=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(a,o)}async postForm(t,n,o){let a=await this.fetchImpl(this.url(t),{method:"POST",credentials:"omit",headers:this.opts.auth.headers(),body:this.appendEnvelope(n)});return this.assertOk(a,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[a,i]=t(),l;try{l=await this.fetchImpl(a,i)}catch(c){if(o>=ss)throw new qe(`${n} failed: network error`,"network",void 0,c);Q.debug("request network error \u2014 retrying",{label:n,attempt:o}),await Lr(ls(o));continue}if(l.ok||!g_.has(l.status)||o>=ss)return l;let s=h_(l.headers)??ls(o);Q.debug("request retryable status \u2014 retrying",{label:n,status:l.status,attempt:o,wait:s}),await Lr(s)}}async assertOk(t,n){if(!t.ok)throw new qe(`${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 v_(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 b_(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.visitorId=="string"&&typeof t.conversationId=="string"}function ds(e,t){let n=e?[{kind:"text",id:"t0",textSig:B(e),doneSig:B(!0)}]:[];return{id:Ve(),role:"user",createdAt:Date.now(),status:"complete",attachments:t,partsSig:B(n)}}function cn(){return{id:Ve(),role:"assistant",createdAt:Date.now(),status:"streaming",partsSig:B([])}}function _s(e){let t=Ve();return P_({id:t,role:e.role,createdAt:Date.now(),status:"complete",ephemeral:!0,parts:[{kind:"text",id:`${t}-t0`,text:e.text,done:!0}]})}function P_(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,feedback:e.feedback,partsSig:B(e.parts.map(w_))}}function x_(e){let t=e.parts.map((n,o)=>n.type==="text"?{kind:"text",id:`${e.id}-t${o}`,textSig:B(n.text),doneSig:B(!0)}:n.type==="reasoning"?{kind:"reasoning",id:`${e.id}-r${o}`,textSig:B(n.text),doneSig:B(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:ns(n.type),inputPartialSig:B(""),inputSig:B(n.input),outputSig:B(n.output),errorSig:B(n.errorText),stateSig:B(n.state),approvalSig:B(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",feedback:e.feedback??null,partsSig:B(t)}}var y_=new Set(["completed","failed","canceled"]);function S_(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 k_(e){return e.role==="assistant"&&e.status!=null&&!y_.has(e.status)&&S_(e)}function Nr(e){return e.filter(t=>!k_(t)).map(x_)}function us(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(C_)}}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 at(e){return e.role==="assistant"&&e.status!=="streaming"&&_o(e)}function ps(e){return e.canceled===!0&&at(e)}function w_(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,textSig:B(e.text),doneSig:B(e.done)}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartialSig:B(e.inputPartial),inputSig:B(e.input),outputSig:B(e.output),errorSig:B(e.error),stateSig:B(e.state),approvalSig:B(e.approval)}:e}function C_(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 ms=Z.scope("reducer"),uo=class{constructor(t){j(this,"messagesSig",t);j(this,"active",null);j(this,"openTextParts",new Map);j(this,"partSeq",0)}attach(t){this.active=t,this.openTextParts.clear()}detach(){this.active=null,this.openTextParts.clear()}ensureTextPart(t,n,o){let a=`${n}:${o}`,i=this.openTextParts.get(a);if(i)return i;let l={kind:n,id:`${o}#${this.partSeq++}`,textSig:B(""),doneSig:B(!1)};return this.openTextParts.set(a,l),dn(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":dn(n,{kind:"step-start",id:`ss-${this.partSeq++}`});return;case"finish":ms.debug("finish",{reason:t.finishReason,canContinue:t.canContinue}),n.status="complete",t.finishReason&&(n.finishReason=t.finishReason),this.bumpDone(n);return;case"error":ms.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":T_(n,t);return;case"file":dn(n,{kind:"file",url:t.url,mediaType:t.mediaType});return;case"source-url":fs(n,{kind:"source",sourceId:t.sourceId,url:t.url,title:t.title});return;case"source-document":fs(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 Pt(e,t,n){let o=e.partsSig.value.find(i=>i.kind==="tool"&&i.toolCallId===t);if(o)return o;let a={kind:"tool",toolCallId:t,toolName:n??"tool",inputPartialSig:B(""),inputSig:B(void 0),outputSig:B(void 0),errorSig:B(void 0),stateSig:B("input-streaming"),approvalSig:B(void 0)};return dn(e,a),a}function dn(e,t){e.partsSig.value=[...e.partsSig.value,t]}function fs(e,t){e.partsSig.value.some(n=>n.kind==="source"&&n.sourceId===t.sourceId)||dn(e,t)}function T_(e,t){switch(t.type){case"tool-input-start":Pt(e,t.toolCallId,t.toolName);return;case"tool-input-delta":{let n=Pt(e,t.toolCallId);n.inputPartialSig.value+=t.inputTextDelta;return}case"tool-input-available":{let n=Pt(e,t.toolCallId,t.toolName);n.inputSig.value=t.input,n.stateSig.value="input-available";return}case"tool-approval-request":{let n=Pt(e,t.toolCallId,t.toolName);n.approvalSig.value={id:t.approvalId},n.stateSig.value="approval-requested";return}case"tool-output-available":{let n=Pt(e,t.toolCallId);n.outputSig.value=t.output,n.stateSig.value="output-available";return}case"tool-output-error":{let n=Pt(e,t.toolCallId);n.errorSig.value=t.errorText,n.stateSig.value="output-error";return}case"tool-output-denied":{let n=Pt(e,t.toolCallId);n.stateSig.value="output-denied";return}default:return}}var gs=Z.scope("feedback:audio"),po=class{constructor(){j(this,"ctx",null);j(this,"master",null);j(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){gs.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 a=n.currentTime,i=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=a+s*i;d.gain.setValueAtTime(1e-4,u),d.gain.exponentialRampToValueAtTime(t.peakGain,u+.005),d.gain.exponentialRampToValueAtTime(1e-4,u+i),c.connect(d).connect(o),c.start(u),c.stop(u+i+.01)})}async playUrl(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let a=await this.getBuffer(t);if(!a)return;let i=n.createBufferSource();i.buffer=a,i.connect(o),i.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,a=fetch(t).then(i=>i.ok?i.arrayBuffer():Promise.reject(new Error(`fetch ${i.status}`))).then(i=>o.decodeAudioData(i)).then(i=>(this.buffers.set(t,i),i)).catch(i=>(gs.warn("audio fetch/decode failed",{url:t,err:i}),this.buffers.delete(t),null));return this.buffers.set(t,a),a}};var hs={messageReceived:10,messageSent:0,error:[20,40,20],voiceStart:10,voiceStop:0},vs={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 _t=null,mo=0;function E_(){return typeof navigator<"u"&&typeof navigator.vibrate=="function"}function R_(){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 bs(e){if(!(e===0||Array.isArray(e)&&e.every(t=>t===0))){if(E_())try{navigator.vibrate(e);return}catch{}if(_t||(_t=R_()),!!_t)try{_t.label.click()}catch{}}}function Ps(){mo++;let e=!1;return()=>{e||(e=!0,mo=Math.max(0,mo-1),mo===0&&_t&&(_t.input.remove(),_t.label.remove(),_t=null))}}var A_=Z.scope("feedback"),I_=100,fo=class{constructor(t,n){j(this,"mutedSig",B(!1));j(this,"audio",new po);j(this,"releaseHaptics");j(this,"sound");j(this,"haptics");j(this,"lastPlayed",new Map);j(this,"reducedMotionMq",null);this.sound=t,this.haptics=n,this.releaseHaptics=Ps(),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<I_}playSound(t){let n=this.sound.events?.[t];if(n===!1)return;if(typeof n=="string"){this.audio.playUrl(n).catch(a=>A_.warn("audio play failed",{err:a,url:n}));return}let o=vs[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?hs[t]:n;bs(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 xt(e,t){return e instanceof qe&&e.status===429?t.errorRateLimited:t.errorGeneric}var L_=0;function r(e,t,n,o,a,i){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:--L_,__i:-1,__u:0,__source:a,__self:i};if(typeof e=="function"&&(l=e.defaultProps))for(s in l)c[s]===void 0&&(c[s]=l[s]);return ee.vnode&&ee.vnode(d),d}var O={fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24"},_n=`${x.cssPrefix}-icon-dir`,M_=()=>r("svg",{...O,"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"})}),Qe=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M18 6 6 18M6 6l12 12"})}),xs=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M12 5v14M5 12h14"})}),ys=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:[r("path",{d:"m22 2-7 20-4-9-9-4Z"}),r("path",{d:"M22 2 11 13"})]}),Ss=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M12 19V5M5 12l7-7 7 7"})}),ks=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:r("path",{d:"M3 20V4l18 8-18 8Z"})}),Ut=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:r("path",{d:"m9 18 6-6-6-6"})}),ws=()=>r("svg",{...O,"aria-hidden":"true",children:r("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),Cs=()=>r("svg",{...O,"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"})}),Ts=()=>r("svg",{...O,"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"})]}),Es=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M3 8V3h5M21 8V3h-5M3 16v5h5M21 16v5h-5"})}),Rs=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M8 3v5H3M16 3v5h5M8 21v-5H3M16 21v-5h5"})}),As=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M3 3h7v2H5v5H3zM21 3h-7v2h5v5h2zM3 21h7v-2H5v-5H3zM21 21h-7v-2h5v-5h2z"})}),Is=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M10 3v5H3M14 3v5h7M10 21v-5H3M14 21v-5h7"})}),Ls=()=>r("svg",{...O,"aria-hidden":"true",viewBox:"0 0 10 10",children:r("path",{d:"M9 1L1 9M9 5L5 9M9 9H9",strokeWidth:"1.5"})}),Ms=()=>r("svg",{...O,"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"})]}),Ns=()=>r("svg",{...O,"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"})}),Ds=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM22 9l-6 6M16 9l6 6"})}),Os=()=>r("svg",{...O,"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"})]}),$s=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:r("path",{d:"m5 6 6 6-6 6M13 6l6 6-6 6"})}),yt=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M20 6 9 17l-5-5"})}),Fs=()=>r("svg",{...O,"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"})]}),Bs=()=>r("svg",{...O,"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"})]}),un=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),Hs=()=>r("svg",{...O,"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",{...O,"aria-hidden":"true",children:r("path",{d:"m6 9 6 6 6-6"})}),zs=()=>r("svg",{...O,"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"})]}),N_=()=>r("svg",{...O,"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",{...O,"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"})}),Or=()=>r("svg",{...O,"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"})]}),D_=()=>r("svg",{...O,"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"})]}),O_=()=>r("svg",{...O,"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"})]}),$_=()=>r("svg",{...O,"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"})]}),F_=()=>r("svg",{...O,"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"})]}),$r=()=>r("svg",{...O,"aria-hidden":"true",children:[r("circle",{cx:"11",cy:"11",r:"7"}),r("path",{d:"m21 21-4.3-4.3"})]}),Us=()=>r("svg",{...O,"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"})]}),Vs=()=>r("svg",{...O,"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"})]}),qs=()=>r("svg",{...O,"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"})]}),pn=()=>r("svg",{...O,"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",{...O,"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"})]}),Gs=()=>r("svg",{...O,"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"})}),Ks=()=>r("svg",{...O,"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"})]}),B_=()=>r("svg",{...O,"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"})]}),H_=()=>r("svg",{...O,"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"})]}),z_=()=>r("svg",{...O,"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"})]}),U_=()=>r("svg",{...O,"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"})]}),js=()=>r("svg",{...O,"aria-hidden":"true",children:[r("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2"}),r("path",{d:"M5 15a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2"})]}),Xs=()=>r("svg",{...O,"aria-hidden":"true",children:[r("path",{d:"M7 10v11H4a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z"}),r("path",{d:"M7 10l4-7a2.5 2.5 0 0 1 2.5 2.5V8h5a2 2 0 0 1 2 2.3l-1.2 8A2 2 0 0 1 17.3 20H7"})]}),Ys=()=>r("svg",{...O,"aria-hidden":"true",children:[r("path",{d:"M17 14V3h3a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1z"}),r("path",{d:"M17 14l-4 7a2.5 2.5 0 0 1-2.5-2.5V16h-5a2 2 0 0 1-2-2.3l1.2-8A2 2 0 0 1 6.7 4H17"})]}),Js=()=>r("svg",{...O,"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"})}),Qs=()=>r("svg",{...O,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M12 7v5l3 2"})]}),Zs=()=>r("svg",{...O,"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"})]}),el=()=>r("svg",{...O,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m15 9-6 6M9 9l6 6"})]}),tl={chat:M_,message:Dr,bubbles:pn,spark:N_,wand:D_,bot:O_,help:Or,lifebuoy:F_,headset:$_,search:B_,sparkles:H_,concierge:z_,wave:U_};var L=x.cssPrefix,S={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`,messageFeedback:`${L}-message-feedback`,feedbackUp:`${L}-feedback-up`,feedbackDown:`${L}-feedback-down`,messageCopy:`${L}-message-copy`,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`,toolAskQuestions:`${L}-tool-ask-questions`,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 nl({onToggle:e,launcher:t,strings:n,leaving:o,edgeTab:a}){let i=t.variant!=="circle"&&!!t.label;return r("button",{type:"button",class:`${ho}-fab`,"data-variant":t.variant,"data-size":t.size,"data-edge-tab":a?"true":void 0,"data-leaving":o?"true":void 0,"data-testid":S.launcher,onClick:e,"aria-label":n.launcherOpen,children:[V_(t.icon),i?r("span",{class:`${ho}-fab-label`,children:Re(n,t.label??"")}):null]})}function V_(e){let t=tl[e];return t?r(t,{}):r(q_,{source:e})}function q_({source:e}){return r("span",{ref:t=>{t&&W_(t,e)},"aria-hidden":"true"})}function W_(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 ol({callout:e,launcherPosition:t,strings:n,closeLabel:o,onDismiss:a}){let[i,l]=R(!1);return T(()=>{let s=setTimeout(()=>l(!0),e.delayMs);return()=>clearTimeout(s)},[e.delayMs]),T(()=>{if(!i||e.autoDismissMs<=0)return;let s=setTimeout(a,e.autoDismissMs);return()=>clearTimeout(s)},[i,e.autoDismissMs,a]),i?r("div",{class:`${ho}-callout`,role:"status","data-shape":e.shape,"data-position":G_(e.position,t),"data-animated":e.animated?"true":void 0,"data-testid":S.callout,children:[r("span",{children:Re(n,e.text)}),r("button",{type:"button",class:`${ho}-callout-close`,onClick:a,"aria-label":o,title:o,"data-testid":S.calloutDismiss,children:r(Qe,{})})]}):null}function G_(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:a,strings:i}){let l=x.cssPrefix,s=D(null);if(T(()=>{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"}`,h=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()},_=m=>{let C=s.current;if(!C||m.pointerId!==C.pointerId||!e)return;let v=(m.clientX-C.startX)*C.dirX,P=(m.clientY-C.startY)*C.dirY;e.style.setProperty(`--${l}-widget-w`,`${C.startW+v}px`),e.style.setProperty(`--${l}-widget-h`,`${C.startH+P}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();a({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":i.resizeHandle,title:i.resizeHandle,onPointerDown:h,onPointerMove:_,onPointerUp:f,onPointerCancel:f,"data-testid":S.resizeGrip,children:r(Ls,{})})}var St=x.cssPrefix,K_=`.${St}-header, .${St}-back-header, .${St}-home-hero`,j_='button, a, input, textarea, select, [role="tab"], [contenteditable]',rl=56;function bo(e,t){T(()=>{if(!t||!e)return;let n=c=>Number.parseFloat(c)||0,o=(c,d)=>Math.min(d,Math.max(-d,c)),a=null,i=c=>{let d=c.target;if(!(d instanceof Element)||!d.closest(K_)||d.closest(j_))return;let u=e.getBoundingClientRect();a={id:c.pointerId,x:c.clientX,y:c.clientY,dx:n(e.style.getPropertyValue(`--${St}-modal-dx`)),dy:n(e.style.getPropertyValue(`--${St}-modal-dy`)),maxX:(window.innerWidth+u.width)/2-rl,maxY:(window.innerHeight+u.height)/2-rl},e.dataset.dragging="true",c.preventDefault()},l=c=>{if(!a||c.pointerId!==a.id)return;let d=o(a.dx+c.clientX-a.x,a.maxX),u=o(a.dy+c.clientY-a.y,a.maxY);e.style.setProperty(`--${St}-modal-dx`,`${d}px`),e.style.setProperty(`--${St}-modal-dy`,`${u}px`)},s=c=>{!a||c.pointerId!==a.id||(a=null,delete e.dataset.dragging)};return e.addEventListener("pointerdown",i),window.addEventListener("pointermove",l),window.addEventListener("pointerup",s),window.addEventListener("pointercancel",s),()=>{e.removeEventListener("pointerdown",i),window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),window.removeEventListener("pointercancel",s)}},[e,t])}function mn(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 mn("close",e,t)?n.includes("close"):!1}function al(e,t){return e==="inline"&&t==="fullscreen"?"exit-fullscreen":"close"}var X_='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(X_)].filter(s=>s.offsetParent!==null||s===document.activeElement);if(o.length===0){n.preventDefault();return}let a=o[0],i=o[o.length-1];if(!a||!i)return;let l=e.getRootNode().activeElement;n.shiftKey&&l===a?(n.preventDefault(),i.focus()):!n.shiftKey&&l===i&&(n.preventDefault(),a.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 Fr=x.cssPrefix;function il({agent:e,strings:t}){let n=e.status??"online",o=Re(t,e.name),a=e.title?Re(t,e.title):null;return r("div",{class:`${Fr}-agent`,children:[r("div",{class:`${Fr}-agent-avatar`,"data-status":n,children:e.avatar?r("img",{src:e.avatar,alt:""}):r("span",{children:yo(o)})}),r("div",{class:`${Fr}-agent-meta`,children:[r("strong",{children:o}),a?r("span",{children:a}):null]})]})}var sl=Z.scope("attachments");function So(e,t,n){let o=J_(e),a=[],i=[],l=eu(n.accept),s=t.reduce((d,u)=>d+u.size,0),c=t.length;for(let d of o){let u=Y_(d,c,s,n,l);if(u){i.push({file:d,reason:u});continue}a.push(Z_(d)),s+=d.size,c+=1}return(a.length||i.length)&&sl.debug("ingest",{accepted:a.length,rejected:i.map(d=>({name:d.file.name,reason:d.reason}))}),{accepted:a,rejected:i}}function Br(e){try{URL.revokeObjectURL(e.previewUrl)}catch(t){sl.debug("revokeObjectURL failed",{error:t})}}function Y_(e,t,n,o,a){return t>=o.maxCount?"count":n+e.size>o.maxBytes?"bytes":tu(e,a)?null:"mime"}function J_(e){return e?Array.isArray(e)?e.filter(t=>t instanceof File):[...e].map(t=>t instanceof File?t:Q_(t)).filter(t=>t!==null):[]}function Q_(e){let t=e;return!t?.getAsFile||t.kind!=="file"?null:t.getAsFile()}function Z_(e){return{file:e,id:Ve(),mediaType:e.type||"application/octet-stream",name:e.name||"pasted-file",previewUrl:URL.createObjectURL(e),size:e.size}}function eu(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 tu(e,t){if(t.length===0)return!0;let[n="*",o="*"]=(e.type||"").toLowerCase().split("/"),a=(e.name||"").toLowerCase();return t.some(i=>i.kind==="ext"?a.endsWith(i.ext):(i.type==="*"||i.type===n)&&(i.subtype==="*"||i.subtype===o))}var fn=x.cssPrefix;function ll({attachment:e,onRemove:t}){let n=e.mediaType.startsWith("image/");return r("span",{class:`${fn}-attachment-chip`,title:e.name,"data-testid":xe(S.attachmentChip,e.id),children:[n?r("img",{class:`${fn}-attachment-thumb`,src:e.previewUrl,alt:""}):r("span",{class:`${fn}-attachment-thumb`,"aria-hidden":"true",children:r(zs,{})}),r("span",{class:`${fn}-attachment-name`,children:e.name}),r("button",{type:"button",class:`${fn}-attachment-remove`,onClick:t,"aria-label":`Remove ${e.name}`,"data-testid":xe(S.attachmentRemove,e.id),children:r(Qe,{})})]})}var Hr={isSupported:!1,start:()=>{},stop:()=>{}};function zr(e,t,n){return e==="disabled"?Hr:e==="server"?au(n):nu(t)}function nu(e){let t=ou();if(!t)return Hr;let n=null;return{isSupported:!0,start(o,a){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 h=s.results[u];h&&(c+=h[0].transcript,h.isFinal&&(d=!0))}o(c,d)});let i=()=>{n=null,a()};n.addEventListener("end",i),n.addEventListener("error",i),n.start()},stop(){n?.stop()}}}function ou(){let e=globalThis;return e.SpeechRecognition??e.webkitSpeechRecognition}var ru=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus","audio/mp4"];function au(e){if(typeof MediaRecorder>"u"||!navigator?.mediaDevices?.getUserMedia)return Hr;let t=null,n=null,o=[],a=()=>{for(let i of n?.getTracks()??[])i.stop();n=null};return{isSupported:!0,async start(i,l){try{n=await navigator.mediaDevices.getUserMedia({audio:!0});let s=iu();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";a();let d=new Blob(o,{type:c});o=[];try{let{text:u}=await e(d,c);u&&i(u,!0)}catch{}finally{l()}}),t.start()}catch{a(),l()}},stop(){t?.stop()}}}function iu(){for(let e of ru)if(MediaRecorder.isTypeSupported(e))return e}var He=x.cssPrefix,kt=Z.scope("composer");function Vt(e){return e.reduce((t,n)=>t+n.size,0)}var su={arrowUp:Ss,paperPlane:ys,send:ks,chevron:Ut};function cl({options:e,transport:t,feedback:n,bus:o,isStreaming:a,onSend:i,onStop:l,attachApiRef:s}){let c=e.strings,[d,u]=R(""),[h,_]=R([]),[f,m]=R(!1),C=D(null),v=D(null),P=e.features.files,w=e.features.voice,[b,A]=R(()=>zr(w,e.locale,(k,G)=>t.transcribe(k,G)));T(()=>{f||w==="disabled"||A(zr(w,e.locale,(k,G)=>t.transcribe(k,G)))},[e.locale,w,t,f]),T(()=>{let k=C.current;if(!k)return;let G=k.getRootNode(),ne="activeElement"in G?G.activeElement:null;ne&&k.closest(`.${He}-panel`)?.contains(ne)||k.focus({preventScroll:!0})},[]),T(()=>{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 F=D(h);F.current=h,T(()=>()=>F.current.forEach(Br),[]),T(()=>{if(s)return s.current={attachFromDrop:k=>{let G=So(k,F.current,e.attachments);G.accepted.length!==0&&(kt.info("attach (drop)",{count:G.accepted.length,totalBytes:Vt(G.accepted)}),o.emit("attach",{count:G.accepted.length,totalBytes:Vt(G.accepted)}),_(ne=>[...ne,...G.accepted]))}},()=>{s.current&&(s.current=null)}},[s,e.attachments]),T(()=>{let k=C.current;if(!k)return;let G=k.closest(`.${He}-panel`);if(!G)return;let ne=ve=>{let _e=ve.clipboardData;if(!_e)return;let Me=ve.target?.closest?.("input, textarea, [contenteditable]:not([contenteditable='false'])");if(Me&&Me!==k)return;if(P){let Ne=So(_e.items,F.current,e.attachments);if(Ne.accepted.length>0){ve.preventDefault(),kt.info("attach (paste)",{count:Ne.accepted.length,totalBytes:Vt(Ne.accepted)}),o.emit("attach",{count:Ne.accepted.length,totalBytes:Vt(Ne.accepted)}),_(ue=>[...ue,...Ne.accepted]);return}}if(Me===k)return;let be=_e.getData("text/plain");be&&(ve.preventDefault(),u(Ne=>Ne+be),k.focus())};return G.addEventListener("paste",ne),()=>G.removeEventListener("paste",ne)},[P,e.attachments,He]);let te=()=>{let k=d.trim();!k&&h.length===0||a||(i(k,h),u(""),_([]))},M=k=>{k.key!=="Enter"||k.shiftKey||k.isComposing||(k.preventDefault(),a?l():te())},Y=k=>{let G=k.target,ne=So(G.files,h,e.attachments);ne.accepted.length>0&&(kt.info("attach (file picker)",{count:ne.accepted.length,totalBytes:Vt(ne.accepted)}),o.emit("attach",{count:ne.accepted.length,totalBytes:Vt(ne.accepted)}),_(ve=>[...ve,...ne.accepted])),G.value=""},X=k=>{kt.info("removeAttachment",{id:k}),o.emit("removeAttachment",{id:k}),_(G=>{let ne=G.find(ve=>ve.id===k);return ne&&Br(ne),G.filter(ve=>ve.id!==k)})},H=D(null),z=()=>{if(b.isSupported){if(f){let k=H.current?Date.now()-H.current:0;kt.info("voiceStop",{durationMs:k}),o.emit("voiceStop",{durationMs:k}),b.stop(),m(!1),n.play("voiceStop"),H.current=null;return}H.current=Date.now(),kt.info("voiceStart"),o.emit("voiceStart",void 0),m(!0),n.play("voiceStart"),b.start((k,G)=>u(ne=>G?`${ne}${k} `:ne),()=>{if(m(!1),H.current){let k=Date.now()-H.current;kt.debug("voiceStop (auto)",{durationMs:k}),o.emit("voiceStop",{durationMs:k}),H.current=null}})}},V=su[e.composer.sendButton.icon];return r("div",{class:`${He}-composer`,"data-testid":S.composer,children:[h.length>0?r("div",{class:`${He}-attachments`,children:h.map(k=>r(ll,{attachment:k,onRemove:()=>X(k.id)},k.id))}):null,r("div",{class:`${He}-composer-row`,children:[r("div",{class:`${He}-composer-actions`,children:[P?r("button",{type:"button",class:`${He}-icon-btn`,onClick:()=>v.current?.click(),"aria-label":c.attach,"data-testid":S.composerAttach,children:r(Cs,{})}):null,b.isSupported?r("button",{type:"button",class:`${He}-icon-btn`,onClick:z,"aria-label":f?c.micStop:c.micStart,"aria-pressed":f,"data-recording":f?"true":void 0,"data-testid":S.composerVoice,children:r(Ts,{})}):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":S.composerInput}),a?r("button",{type:"button",class:`${He}-send`,onClick:l,"aria-label":c.stop,"data-testid":S.composerStop,children:r(ws,{})}):r("button",{type:"button",class:`${He}-send`,"data-shape":e.composer.sendButton.shape,"data-variant":e.composer.sendButton.variant,onClick:te,disabled:!d.trim()&&h.length===0,"aria-label":c.send,"data-testid":S.composerSend,children:r(V,{})})]}),r("input",{ref:v,type:"file",multiple:!0,accept:e.attachments.accept,onChange:Y,class:`${He}-sr-only`,"data-testid":S.composerFileInput})]})}var lu=x.cssPrefix;function dl({visible:e,strings:t}){return e?r("div",{class:`${lu}-dropzone`,role:"status","aria-live":"polite",children:t.dropZone}):null}function ko({containerRef:e,onDrop:t}){let[n,o]=R(!1);return T(()=>{let a=e.current;if(!a)return;let i=0,l=u=>{i+=1,u.dataTransfer?.types.includes("Files")&&(u.preventDefault(),o(!0))},s=()=>{i-=1,!(i>0)&&(i=0,o(!1))},c=u=>{u.dataTransfer?.types.includes("Files")&&u.preventDefault()},d=u=>{i=0,o(!1),u.dataTransfer&&(u.preventDefault(),t(u.dataTransfer.items))};return a.addEventListener("dragenter",l),a.addEventListener("dragleave",s),a.addEventListener("dragover",c),a.addEventListener("drop",d),()=>{a.removeEventListener("dragenter",l),a.removeEventListener("dragleave",s),a.removeEventListener("dragover",c),a.removeEventListener("drop",d)}},[e,t]),{visible:n}}function _l({itemCount:e,initialFocusIndex:t}){let[n,o]=R(!1),a=D(null),i=D(null),[l,s]=R(-1),c=$(()=>{o(!1),s(-1),a.current?.focus()},[]),d=$(()=>o(_=>!_),[]);T(()=>{if(!n)return;let _=f=>{let m=i.current,C=a.current;if(!m||!C)return;let v=f.composedPath();v.includes(m)||v.includes(C)||(o(!1),s(-1))};return document.addEventListener("click",_,!0),()=>document.removeEventListener("click",_,!0)},[n]),T(()=>{if(!n||e===0)return;let _=t?.()??0,f=_<0||_>=e?0:_;s(f)},[n,e,t]),T(()=>{if(!n||l<0)return;i.current?.querySelectorAll("[role='menuitem']")?.[l]?.focus()},[n,l]);let u=$(_=>{(_.key==="ArrowDown"||_.key==="Enter"||_.key===" ")&&(_.preventDefault(),o(!0))},[]),h=$(_=>{if(e!==0)switch(_.key){case"Escape":_.preventDefault(),c();return;case"ArrowDown":_.preventDefault(),s(f=>(f+1)%e);return;case"ArrowUp":_.preventDefault(),s(f=>(f-1+e)%e);return;case"Home":_.preventDefault(),s(0);return;case"End":_.preventDefault(),s(e-1)}},[e,c]);return{open:n,focusIndex:l,triggerRef:a,menuRef:i,toggle:d,close:c,onTriggerKey:u,onMenuKey:h}}function ul({items:e,triggerLabel:t}){let n=x.cssPrefix,o=_l({itemCount:e.length}),a=s=>{s.disabled||(s.onSelect?.(),s.keepOpen||o.close())},i=(s,c)=>s.onSelectValue?.(c),l=(s,c)=>{let d=c.segments;if(!d?.length)return;let u=Math.max(0,d.findIndex(_=>_.value===c.value)),h=-1;if(s.key==="ArrowRight"||s.key==="Enter"||s.key===" ")h=(u+1)%d.length;else if(s.key==="ArrowLeft")h=(u-1+d.length)%d.length;else return;s.preventDefault(),s.stopPropagation(),i(c,d[h].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(Ms,{})}),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":`${S.langSegment}-${c.value}`,onClick:()=>i(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:()=>a(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(yt,{})}):null]},s.id))}):null]})}var Ur=x.cssPrefix;function cu(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 du={normal:"large",large:"small",small:"normal"};function _u(e){return e==="light"?r(Ws,{}):e==="dark"?r(Gs,{}):r(Ks,{})}function uu(e){return(e.split("-")[0]??e).toUpperCase()}function Ze({panelProps:e,variant:t}){let{options:n,panelSize:o,feedback:a,onClose:i,onClear:l,onExpand:s,onFullscreen:c,onSoundToggle:d}=e,{onToggleHistory:u,onLocaleChange:h,onThemeChange:_,onTextSizeChange:f}=e,m=n.strings,C=n.mode,v=t==="chat",P=J(()=>a.mutedSig.value).value,w=new Set(n.actions),b=k=>w.has(k),A=typeof matchMedia=="function"&&matchMedia("(max-width: 640px)").matches,F=k=>A?!1:mn(k,C,o),te=n.themeMode,M={auto:m.themeAuto,light:m.themeLight,dark:m.themeDark},Y=n.textSize,X={small:m.textSizeSmall,normal:m.textSizeNormal,large:m.textSizeLarge},H=[];if(v&&b("clear")&&H.push({id:"clear",icon:r(Hs,{}),label:m.newConversation,onSelect:l}),b("expand")&&F("expand")){let k=o==="expanded";H.push({id:"expand",icon:k?r(Rs,{}):r(Es,{}),label:k?m.collapse:m.expand,type:"switch",on:k,onSelect:s})}if(b("fullscreen")&&F("fullscreen")){let k=o==="fullscreen";H.push({id:"fullscreen",icon:k?r(Is,{}):r(As,{}),label:k?m.exitFullscreen:m.fullscreen,type:"switch",on:k,onSelect:c})}v&&b("sound")&&H.push({id:"sound",icon:P?r(Ds,{}):r(Ns,{}),label:P?m.soundOff:m.soundOn,type:"switch",on:!P,onSelect:d}),b("theme")&&H.push({id:"theme",icon:_u(te),label:`${m.theme}: ${M[te]}`,onSelect:()=>_(cu(te)),keepOpen:!0}),b("textSize")&&H.push({id:"textSize",icon:r(Os,{}),label:`${m.textSize}: ${X[Y]}`,onSelect:()=>f(du[Y]),keepOpen:!0}),b("language")&&n.availableLocales.length>1&&H.push({id:"language",icon:r(Bs,{}),label:m.language,segments:n.availableLocales.map(k=>({value:k,label:uu(k),lang:k})),value:n.locale,onSelectValue:h});let z=!!i&&Po(C,o,n.actions),V=v&&b("history");return r("div",{class:`${Ur}-header-actions`,children:[V?r("button",{type:"button",class:`${Ur}-icon-btn`,onClick:u,"aria-label":m.history,title:m.history,"data-testid":S.actionHistory,children:r(Fs,{})}):null,H.length>0?r(ul,{items:H,triggerLabel:m.moreActions}):null,z?r("button",{type:"button",class:`${Ur}-icon-btn`,onClick:i,"aria-label":m.close,title:m.close,"data-testid":S.actionClose,children:r(Qe,{})}):null]})}var pu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,mu=/^https?:\/\/[^\s.]+\.[^\s]+$/i,fu=/^[+]?[\d\s().-]{6,}$/;function qt(e,t){return e.replace(/\{(\w+)\}/g,(n,o)=>String(t[o]??`{${o}}`))}function gu(e){return Array.isArray(e)?e.length:e&&e.trim()?1:0}function hu(e,t,n){let o=e.required??!0,a=e.validation;if(e.type==="multiselect"){let l=gu(t);return o&&l===0?n.formRequired:l===0?void 0:a?.minSelections!=null&&l<a.minSelections?qt(n.formChooseAtLeast,{min:a.minSelections}):a?.maxSelections!=null&&l>a.maxSelections?qt(n.formChooseAtMost,{max:a.maxSelections}):void 0}let i=typeof t=="string"?t.trim():"";if(!i)return o?n.formRequired:void 0;switch(e.type){case"email":if(!pu.test(i))return n.formInvalidEmail;break;case"url":if(!mu.test(i))return n.formInvalidUrl;break;case"tel":if(!fu.test(i))return n.formInvalidTel;break;case"number":{let l=Number(i);if(!Number.isFinite(l))return n.formInvalidNumber;if(a?.min!=null&&l<a.min)return qt(n.formNumberTooSmall,{min:a.min});if(a?.max!=null&&l>a.max)return qt(n.formNumberTooLarge,{max:a.max});break}default:break}if(a?.minLength!=null&&i.length<a.minLength)return qt(n.formTooShort,{min:a.minLength});if(a?.maxLength!=null&&i.length>a.maxLength)return qt(n.formTooLong,{max:a.maxLength});if(a?.pattern)try{if(!new RegExp(a.pattern).test(i))return n.formPatternMismatch}catch{}}function pl(e,t,n){let o={};for(let a of e){let i=hu(a,t[a.name],n);i&&(o[a.name]=i)}return o}function ml(e){let t={};for(let[n,o]of Object.entries(e)){let a=Array.isArray(o)?o.join(", "):o;a&&a.trim()&&(t[n]=a.trim())}return t}var de=x.cssPrefix,wo="__other__";function Co({fields:e,strings:t,submitLabel:n,onSubmit:o,skipLabel:a,onSkip:i,footerHint:l,submitOnEnter:s,disabled:c,rootTestId:d,submitTestId:u,skipTestId:h}){let[_,f]=R(()=>xu(e)),[m,C]=R({}),[v,P]=R({}),w=M=>{v[M]&&P(Y=>({...Y,[M]:""}))},b=(M,Y)=>{f(X=>({...X,[M]:Y})),w(M)},A=(M,Y)=>{C(X=>({...X,[M]:Y})),w(M)},F=M=>{if(M.preventDefault(),c)return;let Y=yu(e,_,m),X=pl(e,Y,t);if(Object.keys(X).length>0){P(X);return}o(ml(Y))},te=M=>{!s||M.key!=="Enter"||M.shiftKey||M.isComposing||M.target?.tagName==="TEXTAREA"&&F(M)};return r("form",{class:`${de}-form`,onSubmit:F,onKeyDown:te,"data-testid":d,noValidate:!0,children:[e.map(M=>r(vu,{field:M,value:_[M.name],otherText:m[M.name]??"",error:v[M.name],disabled:c,strings:t,onChange:Y=>b(M.name,Y),onOtherChange:Y=>A(M.name,Y)},M.name)),r("div",{class:`${de}-form-actions`,children:[l?r("span",{class:`${de}-form-hint`,children:l}):null,a&&i?r("button",{type:"button",class:`${de}-form-skip`,onClick:i,disabled:c,"data-testid":h,children:a}):null,r("button",{type:"submit",class:`${de}-form-submit`,disabled:c,"data-testid":u,children:n})]})]})}function vu({field:e,value:t,otherText:n,error:o,disabled:a,strings:i,onChange:l,onOtherChange:s}){let c=xe(S.formField,e.name),d=bu({field:e,value:t,otherText:n,disabled:a,strings:i,onChange:l,onOtherChange:s,fieldTid:c});return r("label",{class:`${de}-field`,"data-field":e.name,"data-invalid":o?"true":void 0,children:[r("span",{class:`${de}-field-label`,children:[e.label,e.required??!0?r("span",{class:`${de}-field-req`,"aria-hidden":"true",children:" *"}):null]}),d,e.validationHint&&!o?r("span",{class:`${de}-field-hint`,children:e.validationHint}):null,o?r("span",{class:`${de}-field-error`,role:"alert",children:o}):null]})}function bu(e){let{field:t,value:n,otherText:o,disabled:a,strings:i,onChange:l,onOtherChange:s,fieldTid:c}=e,d=typeof n=="string"?n:"";switch(t.type){case"textarea":return r("textarea",{class:`${de}-field-input`,rows:3,value:d,placeholder:t.placeholder,disabled:a,onInput:u=>l(u.target.value),"data-testid":c});case"select":return r("select",{class:`${de}-field-input`,value:d,disabled:a,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===wo;return r("div",{class:`${de}-field-choices`,role:"radiogroup","data-testid":c,children:[(t.options??[]).map(h=>r("label",{class:`${de}-choice`,children:[r("input",{type:"radio",name:`${de}-${t.name}`,checked:d===h.value,disabled:a,onChange:()=>l(h.value)}),r("span",{children:h.label??h.value})]},h.value)),t.allowOther?r("label",{class:`${de}-choice`,children:[r("input",{type:"radio",name:`${de}-${t.name}`,checked:d===wo,disabled:a,onChange:()=>l(wo)}),r("span",{children:i.formOther})]}):null,u?r("input",{class:`${de}-field-input`,value:o,placeholder:t.placeholder??i.formOtherPlaceholder,disabled:a,onInput:h=>s(h.target.value)}):null]})}case"checkbox":return r("label",{class:`${de}-choice`,children:[r("input",{type:"checkbox",checked:d==="true",disabled:a,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:[],h=(_,f)=>l(f?[...u,_]:u.filter(m=>m!==_));return r("div",{class:`${de}-field-choices`,"data-testid":c,children:[(t.options??[]).map(_=>r("label",{class:`${de}-choice`,children:[r("input",{type:"checkbox",checked:u.includes(_.value),disabled:a,onChange:f=>h(_.value,f.target.checked)}),r("span",{children:_.label??_.value})]},_.value)),t.allowOther||(t.options??[]).length===0?r("textarea",{class:`${de}-field-input`,rows:2,value:o,placeholder:t.placeholder??i.formOtherPlaceholder,disabled:a,onInput:_=>s(_.target.value)}):null]})}default:return r("input",{class:`${de}-field-input`,type:Pu(t.type),value:d,placeholder:t.placeholder,disabled:a,onInput:u=>l(u.target.value),"data-testid":c})}}function Pu(e){switch(e){case"number":case"email":case"tel":case"url":case"date":case"time":return e;default:return"text"}}function xu(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 yu(e,t,n){let o={...t};for(let a of e){let i=n[a.name]?.trim();if(a.type==="radio"&&a.allowOther&&t[a.name]===wo)o[a.name]=i??"";else if(a.type==="multiselect"&&i){let l=i.split(/[,\n;]+/).map(c=>c.trim()).filter(Boolean),s=Array.isArray(t[a.name])?t[a.name]:[];o[a.name]=[...s,...l]}}return o}var et=x.cssPrefix;function Vr({form:e,strings:t,onSubmit:n,onSkip:o}){return r("div",{class:`${et}-form-gate`,"data-testid":S.formGate,children:[e.title?r("h3",{class:`${et}-form-gate-title`,children:e.title}):null,e.description?r("p",{class:`${et}-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:S.formSubmit,skipTestId:S.formSkip})]})}function fl({marker:e,strings:t,onFill:n}){let o=e.outcome==="skipped",a=o?t.formSkipped:t.formSubmitted,i=e.title?r(oe,{children:[r("span",{children:e.title}),r("span",{class:`${et}-sr-only`,children:a})]}):r("span",{children:a}),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:`${et}-form-done`,"data-outcome":e.outcome,"data-testid":S.formDone,children:[r("summary",{class:`${et}-form-done-summary`,"data-testid":S.formDoneToggle,children:[r(yt,{}),i,r(Ut,{})]}),r("dl",{class:`${et}-form-answers`,"data-testid":S.formAnswers,children:Object.entries(s).map(([d,u])=>r("div",{class:`${et}-form-answer`,children:[r("dt",{children:c(d)}),r("dd",{children:u})]},d))})]})}return r("div",{class:`${et}-form-done`,"data-outcome":e.outcome,"data-testid":S.formDone,role:"status",children:[o?r($s,{}):r(yt,{}),i,o&&e.form?.reopenable&&n?r("button",{type:"button",class:`${et}-form-done-fill`,"data-testid":S.formFill,onClick:n,children:t.formFillOut}):null]})}function gl(e){if(!e)return!1;let t=e.startsWith("tool:")?e.slice(5):e;return t==="ask-user-questions"||t==="ask_user_questions"}var Gr=1,vl=2,bl=4,Pl=8,xl=16;function Su(e){switch(e){case Gr:return"href";case vl:return"src";case bl:return"class";case Pl:return"checked";case xl:return"start"}}var ku=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}},wu=ku;var hl=24;function jr(e){let t=new Uint32Array(hl);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(hl),indent:"",indent_len:0,table_state:0}}function yl(e){e.pending.length>0&&Ce(e,`
11
+ ${a}`:a;continue}o.startsWith("id:")&&(n=o.slice(3).trim())}if(!t||t==="[DONE]")return null;try{let o=JSON.parse(t);return Qi.trace("chunk",{type:o.type,eventId:n}),{chunk:o,eventId:n}}catch(o){return Qi.trace("frame parse failed",{err:o,payload:t.slice(0,200)}),null}}function d_(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 es=e=>e&&Object.keys(e).length>0?e:void 0;function ts(e,t){let n=es(e),o=es(t);if(!n&&!o)return;let a={};return n&&(a.user=n),o&&(a.page=o),d_(JSON.stringify(a))}function so(e){if(!e)return;let t=Date.parse(e);return Number.isFinite(t)?t:void 0}function __(e){return`tool-${e.startsWith("tool:")?e.slice(5):e}`}function ns(e){return e.startsWith("tool-")?e.slice(5):e}var Be={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",messageFeedback:"/pai/message-feedback",bootstrap:"/pai/bootstrap",content:"/pai/content",submitForm:"/pai/submit-form"},os="context";function rs(e){let t=e.messages.map(i=>({id:i.serverMessageId??i.id,parts:m_(i),role:i.role,createdAt:i.createdAt!==void 0?new Date(i.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 a=e.tools?.map(p_).filter(i=>i!==null);return a?.length&&(n.data={tools:a}),n}function u_(e){return e.state==="output-available"||e.state==="output-error"||e.state==="output-denied"||e.approval?.approved!==void 0}function p_(e){return typeof e=="string"?e?{code:e}:null:e?.code?e:null}function m_(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"&&u_(n)){let o={type:__(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=Z.scope("transport"),as=3,cs=400,f_=6e4,is=1e4,ss=3,g_=new Set([408,425,429,500,502,503,504]);function ls(e){return cs*2**e+Math.floor(Math.random()*250)}function h_(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 Lr(e,t){return new Promise(n=>{if(t?.aborted)return n();let o=setTimeout(i,e),a=()=>i();t?.addEventListener("abort",a,{once:!0});function i(){clearTimeout(o),t?.removeEventListener("abort",a),n()}})}var lo=class{constructor(t){j(this,"opts",t);j(this,"visitorId");j(this,"conversationId");j(this,"resumeStatus");j(this,"userContext");j(this,"pageContext");j(this,"locale");j(this,"conversationsCache",new Map);j(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:io};this.visitorId&&(t.visitorId=this.visitorId),this.conversationId&&(t.conversationId=this.conversationId),this.locale&&(t.locale=this.locale);let n=ts(this.userContext,this.pageContext);return n&&(t[os]=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,a]of Object.entries(this.envelope()))n.searchParams.has(o)||n.searchParams.set(o,a);return n.toString()}async handshake(t){Q.debug("handshake \u2192",{visitorId:t.visitorId,conversationId:t.conversationId,locale:t.locale});let n=await this.postJson(Be.handshake,t,"handshake");return Q.debug("handshake \u2190",{visitorId:n.visitorId,conversationId:n.conversationId,hasWelcome:!!n.welcome,hasConfig:!!n.config,rebind:n.rebind}),b_(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.${v_(n)}`),o.append("mimeType",n);let a=await this.postForm(this.transcribePath,o,"transcribe");return Q.debug("transcribe \u2190",{textLen:a.text.length}),a}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 a={at:Date.now(),result:this.fetchConversations(t).then(i=>(a.value=i,i)).catch(i=>{throw this.conversationsCache.delete(n),i})};return this.conversationsCache.set(n,a),a.result}async fetchConversations(t){let n=new URL(this.url(Be.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"),a=o.conversations??[];return Q.debug("listConversations \u2190",{count:a.length,nextCursor:o.nextCursor}),{conversations:a.map(i=>({conversationId:i.conversationId,title:i.title,lastMessageAt:i.lastMessageAt,preview:i.preview,canContinue:i.canContinue,hasUnread:i.hasUnread})),nextCursor:o.nextCursor}}async loadConversation(t){let n=new URL(this.url(Be.listMessages));n.searchParams.set("conversationId",t),Q.debug("loadConversation \u2192",{conversationId:t,visitorId:this.visitorId});let o=await this.getJson(n.toString(),"loadConversation"),a=o.messages??[];return Q.debug("loadConversation \u2190",{conversationId:o.conversationId,canContinue:o.canContinue,messageCount:a.length,hasSuggestions:!!o.suggestions}),{conversationId:o.conversationId,canContinue:o.canContinue??!0,messages:a,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(Be.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<f_)return Q.debug("listContent \u2192 cache",t),o.result;let a=this.fetchContent(t).catch(i=>{throw this.contentCache.delete(n),i});return this.contentCache.set(n,{at:Date.now(),result:a}),a}async fetchContent(t){let n=new URL(this.dataUrl(Be.content));for(let[i,l]of Object.entries(t))l!==void 0&&n.searchParams.set(i,Array.isArray(l)?l.join(","):String(l));Q.debug("listContent \u2192",t);let o=await this.getJson(n.toString(),"listContent"),a=(o.items??[]).map(i=>Ua(i,this.locale));return Q.debug("listContent \u2190",{count:a.length,total:o.pagination?.total}),{...o,items:a}}async bootstrap(t){let n=new URL(this.dataUrl(Be.bootstrap));t&&n.searchParams.set("conversationId",t),Q.debug("bootstrap \u2192",{conversationId:t??this.conversationId});let o=await this.getJson(n.toString(),"bootstrap"),a=o.forms??[],i=o.formSubmissions??[];return Q.debug("bootstrap \u2190",{forms:a.length,formSubmissions:i.length}),{forms:a,formSubmissions:i}}async saveUserPrefs(t){Q.debug("saveUserPrefs \u2192",{visitorId:this.visitorId,conversationId:this.conversationId,settingsKeys:Object.keys(t)});let n=await this.postJson(Be.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??Be.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})}}async submitFeedback(t){Q.debug("submitFeedback \u2192",{messageId:t.messageId,value:t.value});try{await this.postJson(Be.messageFeedback,{messageId:t.messageId,set:{feedback:t.value}},"submitFeedback")}catch(n){Q.debug("submitFeedback 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),a=()=>t.abort();return{iter:o,cancel:a,detach:a}}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 a=1;a<=as&&!t.signal.aborted;a++){if((!o||a>1)&&(await Lr(cs*a,t.signal),t.signal.aborted))return;let i;try{i=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:a,err:c});continue}if(i.status===204||!i.ok){Q.debug("resume \u2192 no in-flight stream",{status:i.status});return}if(!(i.headers.get("content-type")??"").includes("text/event-stream")){let c=await i.json().then(d=>d.status).catch(()=>{});if(Q.debug("resume \u2192 no live stream (status response)",{status:c,attempt:a}),c==="pending"&&a<as)continue;this.resumeStatus=c==="needs-generation"?"needs-generation":"completed";return}this.resumeStatus="live";let s=n.size;if(yield*this.drain(Ir(i,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 qe("stream incomplete after resume attempts","server")}async*drain(t,n,o){try{for await(let a of t){if(o.signal.aborted)return!0;if(a.eventId){if(n.has(a.eventId))continue;n.add(a.eventId)}if(yield a,a.chunk.type==="finish"||a.chunk.type==="error")return!0}}catch(a){if(o.signal.aborted)return!0;if(a instanceof qe&&a.status!==void 0)throw a;Q.debug("stream segment dropped",{err:a})}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(Be.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(Be.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*Ir(o,n)}resumeUrl(t){let n=new URL(this.withEnvelopeQuery(Be.streamResume));return n.searchParams.set("resumeAt",String(t)),n.toString()}async postJson(t,n,o){let a=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(a,o)}async postForm(t,n,o){let a=await this.fetchImpl(this.url(t),{method:"POST",credentials:"omit",headers:this.opts.auth.headers(),body:this.appendEnvelope(n)});return this.assertOk(a,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[a,i]=t(),l;try{l=await this.fetchImpl(a,i)}catch(c){if(o>=ss)throw new qe(`${n} failed: network error`,"network",void 0,c);Q.debug("request network error \u2014 retrying",{label:n,attempt:o}),await Lr(ls(o));continue}if(l.ok||!g_.has(l.status)||o>=ss)return l;let s=h_(l.headers)??ls(o);Q.debug("request retryable status \u2014 retrying",{label:n,status:l.status,attempt:o,wait:s}),await Lr(s)}}async assertOk(t,n){if(!t.ok)throw new qe(`${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 v_(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 b_(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.visitorId=="string"&&typeof t.conversationId=="string"}function ds(e,t){let n=e?[{kind:"text",id:"t0",textSig:B(e),doneSig:B(!0)}]:[];return{id:Ve(),role:"user",createdAt:Date.now(),status:"complete",attachments:t,partsSig:B(n)}}function cn(){return{id:Ve(),role:"assistant",createdAt:Date.now(),status:"streaming",partsSig:B([])}}function _s(e){let t=Ve();return P_({id:t,role:e.role,createdAt:Date.now(),status:"complete",ephemeral:!0,parts:[{kind:"text",id:`${t}-t0`,text:e.text,done:!0}]})}function P_(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,feedback:e.feedback,partsSig:B(e.parts.map(w_))}}function x_(e){let t=e.parts.map((n,o)=>n.type==="text"?{kind:"text",id:`${e.id}-t${o}`,textSig:B(n.text),doneSig:B(!0)}:n.type==="reasoning"?{kind:"reasoning",id:`${e.id}-r${o}`,textSig:B(n.text),doneSig:B(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:ns(n.type),inputPartialSig:B(""),inputSig:B(n.input),outputSig:B(n.output),errorSig:B(n.errorText),stateSig:B(n.state),approvalSig:B(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",feedback:e.feedback??null,partsSig:B(t)}}var y_=new Set(["completed","failed","canceled"]);function S_(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 k_(e){return e.role==="assistant"&&e.status!=null&&!y_.has(e.status)&&S_(e)}function Nr(e){return e.filter(t=>!k_(t)).map(x_)}function us(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(C_)}}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 at(e){return e.role==="assistant"&&e.status!=="streaming"&&_o(e)}function ps(e){return e.canceled===!0&&at(e)}function w_(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,textSig:B(e.text),doneSig:B(e.done)}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartialSig:B(e.inputPartial),inputSig:B(e.input),outputSig:B(e.output),errorSig:B(e.error),stateSig:B(e.state),approvalSig:B(e.approval)}:e}function C_(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 ms=Z.scope("reducer"),uo=class{constructor(t){j(this,"messagesSig",t);j(this,"active",null);j(this,"openTextParts",new Map);j(this,"partSeq",0)}attach(t){this.active=t,this.openTextParts.clear()}detach(){this.active=null,this.openTextParts.clear()}ensureTextPart(t,n,o){let a=`${n}:${o}`,i=this.openTextParts.get(a);if(i)return i;let l={kind:n,id:`${o}#${this.partSeq++}`,textSig:B(""),doneSig:B(!1)};return this.openTextParts.set(a,l),dn(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":dn(n,{kind:"step-start",id:`ss-${this.partSeq++}`});return;case"finish":ms.debug("finish",{reason:t.finishReason,canContinue:t.canContinue}),n.status="complete",t.finishReason&&(n.finishReason=t.finishReason),this.bumpDone(n);return;case"error":ms.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":T_(n,t);return;case"file":dn(n,{kind:"file",url:t.url,mediaType:t.mediaType});return;case"source-url":fs(n,{kind:"source",sourceId:t.sourceId,url:t.url,title:t.title});return;case"source-document":fs(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 Pt(e,t,n){let o=e.partsSig.value.find(i=>i.kind==="tool"&&i.toolCallId===t);if(o)return o;let a={kind:"tool",toolCallId:t,toolName:n??"tool",inputPartialSig:B(""),inputSig:B(void 0),outputSig:B(void 0),errorSig:B(void 0),stateSig:B("input-streaming"),approvalSig:B(void 0)};return dn(e,a),a}function dn(e,t){e.partsSig.value=[...e.partsSig.value,t]}function fs(e,t){e.partsSig.value.some(n=>n.kind==="source"&&n.sourceId===t.sourceId)||dn(e,t)}function T_(e,t){switch(t.type){case"tool-input-start":Pt(e,t.toolCallId,t.toolName);return;case"tool-input-delta":{let n=Pt(e,t.toolCallId);n.inputPartialSig.value+=t.inputTextDelta;return}case"tool-input-available":{let n=Pt(e,t.toolCallId,t.toolName);n.inputSig.value=t.input,n.stateSig.value="input-available";return}case"tool-approval-request":{let n=Pt(e,t.toolCallId,t.toolName);n.approvalSig.value={id:t.approvalId},n.stateSig.value="approval-requested";return}case"tool-output-available":{let n=Pt(e,t.toolCallId);n.outputSig.value=t.output,n.stateSig.value="output-available";return}case"tool-output-error":{let n=Pt(e,t.toolCallId);n.errorSig.value=t.errorText,n.stateSig.value="output-error";return}case"tool-output-denied":{let n=Pt(e,t.toolCallId);n.stateSig.value="output-denied";return}default:return}}var gs=Z.scope("feedback:audio"),po=class{constructor(){j(this,"ctx",null);j(this,"master",null);j(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){gs.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 a=n.currentTime,i=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=a+s*i;d.gain.setValueAtTime(1e-4,u),d.gain.exponentialRampToValueAtTime(t.peakGain,u+.005),d.gain.exponentialRampToValueAtTime(1e-4,u+i),c.connect(d).connect(o),c.start(u),c.stop(u+i+.01)})}async playUrl(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let a=await this.getBuffer(t);if(!a)return;let i=n.createBufferSource();i.buffer=a,i.connect(o),i.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,a=fetch(t).then(i=>i.ok?i.arrayBuffer():Promise.reject(new Error(`fetch ${i.status}`))).then(i=>o.decodeAudioData(i)).then(i=>(this.buffers.set(t,i),i)).catch(i=>(gs.warn("audio fetch/decode failed",{url:t,err:i}),this.buffers.delete(t),null));return this.buffers.set(t,a),a}};var hs={messageReceived:10,messageSent:0,error:[20,40,20],voiceStart:10,voiceStop:0},vs={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 _t=null,mo=0;function E_(){return typeof navigator<"u"&&typeof navigator.vibrate=="function"}function R_(){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 bs(e){if(!(e===0||Array.isArray(e)&&e.every(t=>t===0))){if(E_())try{navigator.vibrate(e);return}catch{}if(_t||(_t=R_()),!!_t)try{_t.label.click()}catch{}}}function Ps(){mo++;let e=!1;return()=>{e||(e=!0,mo=Math.max(0,mo-1),mo===0&&_t&&(_t.input.remove(),_t.label.remove(),_t=null))}}var A_=Z.scope("feedback"),I_=100,fo=class{constructor(t,n){j(this,"mutedSig",B(!1));j(this,"audio",new po);j(this,"releaseHaptics");j(this,"sound");j(this,"haptics");j(this,"lastPlayed",new Map);j(this,"reducedMotionMq",null);this.sound=t,this.haptics=n,this.releaseHaptics=Ps(),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<I_}playSound(t){let n=this.sound.events?.[t];if(n===!1)return;if(typeof n=="string"){this.audio.playUrl(n).catch(a=>A_.warn("audio play failed",{err:a,url:n}));return}let o=vs[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?hs[t]:n;bs(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 xt(e,t){return e instanceof qe&&e.status===429?t.errorRateLimited:t.errorGeneric}var L_=0;function r(e,t,n,o,a,i){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:--L_,__i:-1,__u:0,__source:a,__self:i};if(typeof e=="function"&&(l=e.defaultProps))for(s in l)c[s]===void 0&&(c[s]=l[s]);return ee.vnode&&ee.vnode(d),d}var O={fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24"},_n=`${x.cssPrefix}-icon-dir`,M_=()=>r("svg",{...O,"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"})}),Qe=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M18 6 6 18M6 6l12 12"})}),xs=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M12 5v14M5 12h14"})}),ys=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:[r("path",{d:"m22 2-7 20-4-9-9-4Z"}),r("path",{d:"M22 2 11 13"})]}),Ss=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M12 19V5M5 12l7-7 7 7"})}),ks=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:r("path",{d:"M3 20V4l18 8-18 8Z"})}),Ut=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:r("path",{d:"m9 18 6-6-6-6"})}),ws=()=>r("svg",{...O,"aria-hidden":"true",children:r("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),Cs=()=>r("svg",{...O,"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"})}),Ts=()=>r("svg",{...O,"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"})]}),Es=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M3 8V3h5M21 8V3h-5M3 16v5h5M21 16v5h-5"})}),Rs=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M8 3v5H3M16 3v5h5M8 21v-5H3M16 21v-5h5"})}),As=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M3 3h7v2H5v5H3zM21 3h-7v2h5v5h2zM3 21h7v-2H5v-5H3zM21 21h-7v-2h5v-5h2z"})}),Is=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M10 3v5H3M14 3v5h7M10 21v-5H3M14 21v-5h7"})}),Ls=()=>r("svg",{...O,"aria-hidden":"true",viewBox:"0 0 10 10",children:r("path",{d:"M9 1L1 9M9 5L5 9M9 9H9",strokeWidth:"1.5"})}),Ms=()=>r("svg",{...O,"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"})]}),Ns=()=>r("svg",{...O,"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"})}),Ds=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM22 9l-6 6M16 9l6 6"})}),Os=()=>r("svg",{...O,"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"})]}),$s=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:r("path",{d:"m5 6 6 6-6 6M13 6l6 6-6 6"})}),yt=()=>r("svg",{...O,"aria-hidden":"true",children:r("path",{d:"M20 6 9 17l-5-5"})}),Fs=()=>r("svg",{...O,"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"})]}),Bs=()=>r("svg",{...O,"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"})]}),un=()=>r("svg",{...O,class:_n,"aria-hidden":"true",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),Hs=()=>r("svg",{...O,"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",{...O,"aria-hidden":"true",children:r("path",{d:"m6 9 6 6 6-6"})}),zs=()=>r("svg",{...O,"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"})]}),N_=()=>r("svg",{...O,"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",{...O,"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"})}),Or=()=>r("svg",{...O,"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"})]}),D_=()=>r("svg",{...O,"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"})]}),O_=()=>r("svg",{...O,"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"})]}),$_=()=>r("svg",{...O,"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"})]}),F_=()=>r("svg",{...O,"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"})]}),$r=()=>r("svg",{...O,"aria-hidden":"true",children:[r("circle",{cx:"11",cy:"11",r:"7"}),r("path",{d:"m21 21-4.3-4.3"})]}),Us=()=>r("svg",{...O,"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"})]}),Vs=()=>r("svg",{...O,"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"})]}),qs=()=>r("svg",{...O,"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"})]}),pn=()=>r("svg",{...O,"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",{...O,"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"})]}),Gs=()=>r("svg",{...O,"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"})}),Ks=()=>r("svg",{...O,"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"})]}),B_=()=>r("svg",{...O,"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"})]}),H_=()=>r("svg",{...O,"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"})]}),z_=()=>r("svg",{...O,"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"})]}),U_=()=>r("svg",{...O,"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"})]}),js=()=>r("svg",{...O,"aria-hidden":"true",children:[r("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2"}),r("path",{d:"M5 15a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2"})]}),Xs=()=>r("svg",{...O,"aria-hidden":"true",children:[r("path",{d:"M7 10v11H4a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z"}),r("path",{d:"M7 10l4-7a2.5 2.5 0 0 1 2.5 2.5V8h5a2 2 0 0 1 2 2.3l-1.2 8A2 2 0 0 1 17.3 20H7"})]}),Ys=()=>r("svg",{...O,"aria-hidden":"true",children:[r("path",{d:"M17 14V3h3a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1z"}),r("path",{d:"M17 14l-4 7a2.5 2.5 0 0 1-2.5-2.5V16h-5a2 2 0 0 1-2-2.3l1.2-8A2 2 0 0 1 6.7 4H17"})]}),Js=()=>r("svg",{...O,"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"})}),Qs=()=>r("svg",{...O,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M12 7v5l3 2"})]}),Zs=()=>r("svg",{...O,"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"})]}),el=()=>r("svg",{...O,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m15 9-6 6M9 9l6 6"})]}),tl={chat:M_,message:Dr,bubbles:pn,spark:N_,wand:D_,bot:O_,help:Or,lifebuoy:F_,headset:$_,search:B_,sparkles:H_,concierge:z_,wave:U_};var L=x.cssPrefix,S={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`,messageFeedback:`${L}-message-feedback`,feedbackUp:`${L}-feedback-up`,feedbackDown:`${L}-feedback-down`,messageCopy:`${L}-message-copy`,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`,toolAskQuestions:`${L}-tool-ask-questions`,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 nl({onToggle:e,launcher:t,strings:n,leaving:o,edgeTab:a}){let i=t.variant!=="circle"&&!!t.label;return r("button",{type:"button",class:`${ho}-fab`,"data-variant":t.variant,"data-size":t.size,"data-edge-tab":a?"true":void 0,"data-leaving":o?"true":void 0,"data-testid":S.launcher,onClick:e,"aria-label":n.launcherOpen,children:[V_(t.icon),i?r("span",{class:`${ho}-fab-label`,children:Re(n,t.label??"")}):null]})}function V_(e){let t=tl[e];return t?r(t,{}):r(q_,{source:e})}function q_({source:e}){return r("span",{ref:t=>{t&&W_(t,e)},"aria-hidden":"true"})}function W_(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 ol({callout:e,launcherPosition:t,strings:n,closeLabel:o,onDismiss:a}){let[i,l]=R(!1);return T(()=>{let s=setTimeout(()=>l(!0),e.delayMs);return()=>clearTimeout(s)},[e.delayMs]),T(()=>{if(!i||e.autoDismissMs<=0)return;let s=setTimeout(a,e.autoDismissMs);return()=>clearTimeout(s)},[i,e.autoDismissMs,a]),i?r("div",{class:`${ho}-callout`,role:"status","data-shape":e.shape,"data-position":G_(e.position,t),"data-animated":e.animated?"true":void 0,"data-testid":S.callout,children:[r("span",{children:Re(n,e.text)}),r("button",{type:"button",class:`${ho}-callout-close`,onClick:a,"aria-label":o,title:o,"data-testid":S.calloutDismiss,children:r(Qe,{})})]}):null}function G_(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:a,strings:i}){let l=x.cssPrefix,s=D(null);if(T(()=>{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"}`,h=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()},_=m=>{let C=s.current;if(!C||m.pointerId!==C.pointerId||!e)return;let v=(m.clientX-C.startX)*C.dirX,P=(m.clientY-C.startY)*C.dirY;e.style.setProperty(`--${l}-widget-w`,`${C.startW+v}px`),e.style.setProperty(`--${l}-widget-h`,`${C.startH+P}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();a({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":i.resizeHandle,title:i.resizeHandle,onPointerDown:h,onPointerMove:_,onPointerUp:f,onPointerCancel:f,"data-testid":S.resizeGrip,children:r(Ls,{})})}var St=x.cssPrefix,K_=`.${St}-header, .${St}-back-header, .${St}-home-hero`,j_='button, a, input, textarea, select, [role="tab"], [contenteditable]',rl=56;function bo(e,t){T(()=>{if(!t||!e)return;let n=c=>Number.parseFloat(c)||0,o=(c,d)=>Math.min(d,Math.max(-d,c)),a=null,i=c=>{let d=c.target;if(!(d instanceof Element)||!d.closest(K_)||d.closest(j_))return;let u=e.getBoundingClientRect();a={id:c.pointerId,x:c.clientX,y:c.clientY,dx:n(e.style.getPropertyValue(`--${St}-modal-dx`)),dy:n(e.style.getPropertyValue(`--${St}-modal-dy`)),maxX:(window.innerWidth+u.width)/2-rl,maxY:(window.innerHeight+u.height)/2-rl},e.dataset.dragging="true",c.preventDefault()},l=c=>{if(!a||c.pointerId!==a.id)return;let d=o(a.dx+c.clientX-a.x,a.maxX),u=o(a.dy+c.clientY-a.y,a.maxY);e.style.setProperty(`--${St}-modal-dx`,`${d}px`),e.style.setProperty(`--${St}-modal-dy`,`${u}px`)},s=c=>{!a||c.pointerId!==a.id||(a=null,delete e.dataset.dragging)};return e.addEventListener("pointerdown",i),window.addEventListener("pointermove",l),window.addEventListener("pointerup",s),window.addEventListener("pointercancel",s),()=>{e.removeEventListener("pointerdown",i),window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),window.removeEventListener("pointercancel",s)}},[e,t])}function mn(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 mn("close",e,t)?n.includes("close"):!1}function al(e,t){return e==="inline"&&t==="fullscreen"?"exit-fullscreen":"close"}var X_='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(X_)].filter(s=>s.offsetParent!==null||s===document.activeElement);if(o.length===0){n.preventDefault();return}let a=o[0],i=o[o.length-1];if(!a||!i)return;let l=e.getRootNode().activeElement;n.shiftKey&&l===a?(n.preventDefault(),i.focus()):!n.shiftKey&&l===i&&(n.preventDefault(),a.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 Fr=x.cssPrefix;function il({agent:e,strings:t}){let n=e.status??"online",o=Re(t,e.name),a=e.title?Re(t,e.title):null;return r("div",{class:`${Fr}-agent`,children:[r("div",{class:`${Fr}-agent-avatar`,"data-status":n,children:e.avatar?r("img",{src:e.avatar,alt:""}):r("span",{children:yo(o)})}),r("div",{class:`${Fr}-agent-meta`,children:[r("strong",{children:o}),a?r("span",{children:a}):null]})]})}var sl=Z.scope("attachments");function So(e,t,n){let o=J_(e),a=[],i=[],l=eu(n.accept),s=t.reduce((d,u)=>d+u.size,0),c=t.length;for(let d of o){let u=Y_(d,c,s,n,l);if(u){i.push({file:d,reason:u});continue}a.push(Z_(d)),s+=d.size,c+=1}return(a.length||i.length)&&sl.debug("ingest",{accepted:a.length,rejected:i.map(d=>({name:d.file.name,reason:d.reason}))}),{accepted:a,rejected:i}}function Br(e){try{URL.revokeObjectURL(e.previewUrl)}catch(t){sl.debug("revokeObjectURL failed",{error:t})}}function Y_(e,t,n,o,a){return t>=o.maxCount?"count":n+e.size>o.maxBytes?"bytes":tu(e,a)?null:"mime"}function J_(e){return e?Array.isArray(e)?e.filter(t=>t instanceof File):[...e].map(t=>t instanceof File?t:Q_(t)).filter(t=>t!==null):[]}function Q_(e){let t=e;return!t?.getAsFile||t.kind!=="file"?null:t.getAsFile()}function Z_(e){return{file:e,id:Ve(),mediaType:e.type||"application/octet-stream",name:e.name||"pasted-file",previewUrl:URL.createObjectURL(e),size:e.size}}function eu(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 tu(e,t){if(t.length===0)return!0;let[n="*",o="*"]=(e.type||"").toLowerCase().split("/"),a=(e.name||"").toLowerCase();return t.some(i=>i.kind==="ext"?a.endsWith(i.ext):(i.type==="*"||i.type===n)&&(i.subtype==="*"||i.subtype===o))}var fn=x.cssPrefix;function ll({attachment:e,onRemove:t}){let n=e.mediaType.startsWith("image/");return r("span",{class:`${fn}-attachment-chip`,title:e.name,"data-testid":xe(S.attachmentChip,e.id),children:[n?r("img",{class:`${fn}-attachment-thumb`,src:e.previewUrl,alt:""}):r("span",{class:`${fn}-attachment-thumb`,"aria-hidden":"true",children:r(zs,{})}),r("span",{class:`${fn}-attachment-name`,children:e.name}),r("button",{type:"button",class:`${fn}-attachment-remove`,onClick:t,"aria-label":`Remove ${e.name}`,"data-testid":xe(S.attachmentRemove,e.id),children:r(Qe,{})})]})}var Hr={isSupported:!1,start:()=>{},stop:()=>{}};function zr(e,t,n){return e==="disabled"?Hr:e==="server"?au(n):nu(t)}function nu(e){let t=ou();if(!t)return Hr;let n=null;return{isSupported:!0,start(o,a){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 h=s.results[u];h&&(c+=h[0].transcript,h.isFinal&&(d=!0))}o(c,d)});let i=()=>{n=null,a()};n.addEventListener("end",i),n.addEventListener("error",i),n.start()},stop(){n?.stop()}}}function ou(){let e=globalThis;return e.SpeechRecognition??e.webkitSpeechRecognition}var ru=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus","audio/mp4"];function au(e){if(typeof MediaRecorder>"u"||!navigator?.mediaDevices?.getUserMedia)return Hr;let t=null,n=null,o=[],a=()=>{for(let i of n?.getTracks()??[])i.stop();n=null};return{isSupported:!0,async start(i,l){try{n=await navigator.mediaDevices.getUserMedia({audio:!0});let s=iu();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";a();let d=new Blob(o,{type:c});o=[];try{let{text:u}=await e(d,c);u&&i(u,!0)}catch{}finally{l()}}),t.start()}catch{a(),l()}},stop(){t?.stop()}}}function iu(){for(let e of ru)if(MediaRecorder.isTypeSupported(e))return e}var He=x.cssPrefix,kt=Z.scope("composer");function Vt(e){return e.reduce((t,n)=>t+n.size,0)}var su={arrowUp:Ss,paperPlane:ys,send:ks,chevron:Ut};function cl({options:e,transport:t,feedback:n,bus:o,isStreaming:a,onSend:i,onStop:l,attachApiRef:s}){let c=e.strings,[d,u]=R(""),[h,_]=R([]),[f,m]=R(!1),C=D(null),v=D(null),P=e.features.files,w=e.features.voice,[b,A]=R(()=>zr(w,e.locale,(k,G)=>t.transcribe(k,G)));T(()=>{f||w==="disabled"||A(zr(w,e.locale,(k,G)=>t.transcribe(k,G)))},[e.locale,w,t,f]),T(()=>{let k=C.current;if(!k)return;let G=k.getRootNode(),ne="activeElement"in G?G.activeElement:null;ne&&k.closest(`.${He}-panel`)?.contains(ne)||k.focus({preventScroll:!0})},[]),T(()=>{let k=C.current;if(k){if(d.length===0){k.style.height="";return}k.style.height="auto",k.style.height=`${Math.min(Math.max(k.scrollHeight,40),160)}px`}},[d]);let F=D(h);F.current=h,T(()=>()=>F.current.forEach(Br),[]),T(()=>{if(s)return s.current={attachFromDrop:k=>{let G=So(k,F.current,e.attachments);G.accepted.length!==0&&(kt.info("attach (drop)",{count:G.accepted.length,totalBytes:Vt(G.accepted)}),o.emit("attach",{count:G.accepted.length,totalBytes:Vt(G.accepted)}),_(ne=>[...ne,...G.accepted]))}},()=>{s.current&&(s.current=null)}},[s,e.attachments]),T(()=>{let k=C.current;if(!k)return;let G=k.closest(`.${He}-panel`);if(!G)return;let ne=ve=>{let _e=ve.clipboardData;if(!_e)return;let Me=ve.target?.closest?.("input, textarea, [contenteditable]:not([contenteditable='false'])");if(Me&&Me!==k)return;if(P){let Ne=So(_e.items,F.current,e.attachments);if(Ne.accepted.length>0){ve.preventDefault(),kt.info("attach (paste)",{count:Ne.accepted.length,totalBytes:Vt(Ne.accepted)}),o.emit("attach",{count:Ne.accepted.length,totalBytes:Vt(Ne.accepted)}),_(ue=>[...ue,...Ne.accepted]);return}}if(Me===k)return;let be=_e.getData("text/plain");be&&(ve.preventDefault(),u(Ne=>Ne+be),k.focus())};return G.addEventListener("paste",ne),()=>G.removeEventListener("paste",ne)},[P,e.attachments,He]);let te=()=>{let k=d.trim();!k&&h.length===0||a||(i(k,h),u(""),_([]))},M=k=>{k.key!=="Enter"||k.shiftKey||k.isComposing||(k.preventDefault(),a?l():te())},Y=k=>{let G=k.target,ne=So(G.files,h,e.attachments);ne.accepted.length>0&&(kt.info("attach (file picker)",{count:ne.accepted.length,totalBytes:Vt(ne.accepted)}),o.emit("attach",{count:ne.accepted.length,totalBytes:Vt(ne.accepted)}),_(ve=>[...ve,...ne.accepted])),G.value=""},X=k=>{kt.info("removeAttachment",{id:k}),o.emit("removeAttachment",{id:k}),_(G=>{let ne=G.find(ve=>ve.id===k);return ne&&Br(ne),G.filter(ve=>ve.id!==k)})},H=D(null),z=()=>{if(b.isSupported){if(f){let k=H.current?Date.now()-H.current:0;kt.info("voiceStop",{durationMs:k}),o.emit("voiceStop",{durationMs:k}),b.stop(),m(!1),n.play("voiceStop"),H.current=null;return}H.current=Date.now(),kt.info("voiceStart"),o.emit("voiceStart",void 0),m(!0),n.play("voiceStart"),b.start((k,G)=>u(ne=>G?`${ne}${k} `:ne),()=>{if(m(!1),H.current){let k=Date.now()-H.current;kt.debug("voiceStop (auto)",{durationMs:k}),o.emit("voiceStop",{durationMs:k}),H.current=null}})}},V=su[e.composer.sendButton.icon];return r("div",{class:`${He}-composer`,"data-testid":S.composer,children:[h.length>0?r("div",{class:`${He}-attachments`,children:h.map(k=>r(ll,{attachment:k,onRemove:()=>X(k.id)},k.id))}):null,r("div",{class:`${He}-composer-row`,children:[r("div",{class:`${He}-composer-actions`,children:[P?r("button",{type:"button",class:`${He}-icon-btn`,onClick:()=>v.current?.click(),"aria-label":c.attach,"data-testid":S.composerAttach,children:r(Cs,{})}):null,b.isSupported?r("button",{type:"button",class:`${He}-icon-btn`,onClick:z,"aria-label":f?c.micStop:c.micStart,"aria-pressed":f,"data-recording":f?"true":void 0,"data-testid":S.composerVoice,children:r(Ts,{})}):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":S.composerInput}),a?r("button",{type:"button",class:`${He}-send`,onClick:l,"aria-label":c.stop,"data-testid":S.composerStop,children:r(ws,{})}):r("button",{type:"button",class:`${He}-send`,"data-shape":e.composer.sendButton.shape,"data-variant":e.composer.sendButton.variant,onClick:te,disabled:!d.trim()&&h.length===0,"aria-label":c.send,"data-testid":S.composerSend,children:r(V,{})})]}),r("input",{ref:v,type:"file",multiple:!0,accept:e.attachments.accept,onChange:Y,class:`${He}-sr-only`,"data-testid":S.composerFileInput})]})}var lu=x.cssPrefix;function dl({visible:e,strings:t}){return e?r("div",{class:`${lu}-dropzone`,role:"status","aria-live":"polite",children:t.dropZone}):null}function ko({containerRef:e,onDrop:t}){let[n,o]=R(!1);return T(()=>{let a=e.current;if(!a)return;let i=0,l=u=>{i+=1,u.dataTransfer?.types.includes("Files")&&(u.preventDefault(),o(!0))},s=()=>{i-=1,!(i>0)&&(i=0,o(!1))},c=u=>{u.dataTransfer?.types.includes("Files")&&u.preventDefault()},d=u=>{i=0,o(!1),u.dataTransfer&&(u.preventDefault(),t(u.dataTransfer.items))};return a.addEventListener("dragenter",l),a.addEventListener("dragleave",s),a.addEventListener("dragover",c),a.addEventListener("drop",d),()=>{a.removeEventListener("dragenter",l),a.removeEventListener("dragleave",s),a.removeEventListener("dragover",c),a.removeEventListener("drop",d)}},[e,t]),{visible:n}}function _l({itemCount:e,initialFocusIndex:t}){let[n,o]=R(!1),a=D(null),i=D(null),[l,s]=R(-1),c=$(()=>{o(!1),s(-1),a.current?.focus()},[]),d=$(()=>o(_=>!_),[]);T(()=>{if(!n)return;let _=f=>{let m=i.current,C=a.current;if(!m||!C)return;let v=f.composedPath();v.includes(m)||v.includes(C)||(o(!1),s(-1))};return document.addEventListener("click",_,!0),()=>document.removeEventListener("click",_,!0)},[n]),T(()=>{if(!n||e===0)return;let _=t?.()??0,f=_<0||_>=e?0:_;s(f)},[n,e,t]),T(()=>{if(!n||l<0)return;i.current?.querySelectorAll("[role='menuitem']")?.[l]?.focus()},[n,l]);let u=$(_=>{(_.key==="ArrowDown"||_.key==="Enter"||_.key===" ")&&(_.preventDefault(),o(!0))},[]),h=$(_=>{if(e!==0)switch(_.key){case"Escape":_.preventDefault(),c();return;case"ArrowDown":_.preventDefault(),s(f=>(f+1)%e);return;case"ArrowUp":_.preventDefault(),s(f=>(f-1+e)%e);return;case"Home":_.preventDefault(),s(0);return;case"End":_.preventDefault(),s(e-1)}},[e,c]);return{open:n,focusIndex:l,triggerRef:a,menuRef:i,toggle:d,close:c,onTriggerKey:u,onMenuKey:h}}function ul({items:e,triggerLabel:t}){let n=x.cssPrefix,o=_l({itemCount:e.length}),a=s=>{s.disabled||(s.onSelect?.(),s.keepOpen||o.close())},i=(s,c)=>s.onSelectValue?.(c),l=(s,c)=>{let d=c.segments;if(!d?.length)return;let u=Math.max(0,d.findIndex(_=>_.value===c.value)),h=-1;if(s.key==="ArrowRight"||s.key==="Enter"||s.key===" ")h=(u+1)%d.length;else if(s.key==="ArrowLeft")h=(u-1+d.length)%d.length;else return;s.preventDefault(),s.stopPropagation(),i(c,d[h].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(Ms,{})}),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":`${S.langSegment}-${c.value}`,onClick:()=>i(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:()=>a(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(yt,{})}):null]},s.id))}):null]})}var Ur=x.cssPrefix;function cu(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 du={normal:"large",large:"small",small:"normal"};function _u(e){return e==="light"?r(Ws,{}):e==="dark"?r(Gs,{}):r(Ks,{})}function uu(e){return(e.split("-")[0]??e).toUpperCase()}function Ze({panelProps:e,variant:t}){let{options:n,panelSize:o,feedback:a,onClose:i,onClear:l,onExpand:s,onFullscreen:c,onSoundToggle:d}=e,{onToggleHistory:u,onLocaleChange:h,onThemeChange:_,onTextSizeChange:f}=e,m=n.strings,C=n.mode,v=t==="chat",P=J(()=>a.mutedSig.value).value,w=new Set(n.actions),b=k=>w.has(k),A=typeof matchMedia=="function"&&matchMedia("(max-width: 640px)").matches,F=k=>A?!1:mn(k,C,o),te=n.themeMode,M={auto:m.themeAuto,light:m.themeLight,dark:m.themeDark},Y=n.textSize,X={small:m.textSizeSmall,normal:m.textSizeNormal,large:m.textSizeLarge},H=[];if(v&&b("clear")&&H.push({id:"clear",icon:r(Hs,{}),label:m.newConversation,onSelect:l}),b("expand")&&F("expand")){let k=o==="expanded";H.push({id:"expand",icon:k?r(Rs,{}):r(Es,{}),label:k?m.collapse:m.expand,type:"switch",on:k,onSelect:s})}if(b("fullscreen")&&F("fullscreen")){let k=o==="fullscreen";H.push({id:"fullscreen",icon:k?r(Is,{}):r(As,{}),label:k?m.exitFullscreen:m.fullscreen,type:"switch",on:k,onSelect:c})}v&&b("sound")&&H.push({id:"sound",icon:P?r(Ds,{}):r(Ns,{}),label:P?m.soundOff:m.soundOn,type:"switch",on:!P,onSelect:d}),b("theme")&&H.push({id:"theme",icon:_u(te),label:`${m.theme}: ${M[te]}`,onSelect:()=>_(cu(te)),keepOpen:!0}),b("textSize")&&H.push({id:"textSize",icon:r(Os,{}),label:`${m.textSize}: ${X[Y]}`,onSelect:()=>f(du[Y]),keepOpen:!0}),b("language")&&n.availableLocales.length>1&&H.push({id:"language",icon:r(Bs,{}),label:m.language,segments:n.availableLocales.map(k=>({value:k,label:uu(k),lang:k})),value:n.locale,onSelectValue:h});let z=!!i&&Po(C,o,n.actions),V=v&&b("history");return r("div",{class:`${Ur}-header-actions`,children:[V?r("button",{type:"button",class:`${Ur}-icon-btn`,onClick:u,"aria-label":m.history,title:m.history,"data-testid":S.actionHistory,children:r(Fs,{})}):null,H.length>0?r(ul,{items:H,triggerLabel:m.moreActions}):null,z?r("button",{type:"button",class:`${Ur}-icon-btn`,onClick:i,"aria-label":m.close,title:m.close,"data-testid":S.actionClose,children:r(Qe,{})}):null]})}var pu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,mu=/^https?:\/\/[^\s.]+\.[^\s]+$/i,fu=/^[+]?[\d\s().-]{6,}$/;function qt(e,t){return e.replace(/\{(\w+)\}/g,(n,o)=>String(t[o]??`{${o}}`))}function gu(e){return Array.isArray(e)?e.length:e&&e.trim()?1:0}function hu(e,t,n){let o=e.required??!0,a=e.validation;if(e.type==="multiselect"){let l=gu(t);return o&&l===0?n.formRequired:l===0?void 0:a?.minSelections!=null&&l<a.minSelections?qt(n.formChooseAtLeast,{min:a.minSelections}):a?.maxSelections!=null&&l>a.maxSelections?qt(n.formChooseAtMost,{max:a.maxSelections}):void 0}let i=typeof t=="string"?t.trim():"";if(!i)return o?n.formRequired:void 0;switch(e.type){case"email":if(!pu.test(i))return n.formInvalidEmail;break;case"url":if(!mu.test(i))return n.formInvalidUrl;break;case"tel":if(!fu.test(i))return n.formInvalidTel;break;case"number":{let l=Number(i);if(!Number.isFinite(l))return n.formInvalidNumber;if(a?.min!=null&&l<a.min)return qt(n.formNumberTooSmall,{min:a.min});if(a?.max!=null&&l>a.max)return qt(n.formNumberTooLarge,{max:a.max});break}default:break}if(a?.minLength!=null&&i.length<a.minLength)return qt(n.formTooShort,{min:a.minLength});if(a?.maxLength!=null&&i.length>a.maxLength)return qt(n.formTooLong,{max:a.maxLength});if(a?.pattern)try{if(!new RegExp(a.pattern).test(i))return n.formPatternMismatch}catch{}}function pl(e,t,n){let o={};for(let a of e){let i=hu(a,t[a.name],n);i&&(o[a.name]=i)}return o}function ml(e){let t={};for(let[n,o]of Object.entries(e)){let a=Array.isArray(o)?o.join(", "):o;a&&a.trim()&&(t[n]=a.trim())}return t}var de=x.cssPrefix,wo="__other__";function Co({fields:e,strings:t,submitLabel:n,onSubmit:o,skipLabel:a,onSkip:i,footerHint:l,submitOnEnter:s,disabled:c,rootTestId:d,submitTestId:u,skipTestId:h}){let[_,f]=R(()=>xu(e)),[m,C]=R({}),[v,P]=R({}),w=M=>{v[M]&&P(Y=>({...Y,[M]:""}))},b=(M,Y)=>{f(X=>({...X,[M]:Y})),w(M)},A=(M,Y)=>{C(X=>({...X,[M]:Y})),w(M)},F=M=>{if(M.preventDefault(),c)return;let Y=yu(e,_,m),X=pl(e,Y,t);if(Object.keys(X).length>0){P(X);return}o(ml(Y))},te=M=>{!s||M.key!=="Enter"||M.shiftKey||M.isComposing||M.target?.tagName==="TEXTAREA"&&F(M)};return r("form",{class:`${de}-form`,onSubmit:F,onKeyDown:te,"data-testid":d,noValidate:!0,children:[e.map(M=>r(vu,{field:M,value:_[M.name],otherText:m[M.name]??"",error:v[M.name],disabled:c,strings:t,onChange:Y=>b(M.name,Y),onOtherChange:Y=>A(M.name,Y)},M.name)),r("div",{class:`${de}-form-actions`,children:[l?r("span",{class:`${de}-form-hint`,children:l}):null,a&&i?r("button",{type:"button",class:`${de}-form-skip`,onClick:i,disabled:c,"data-testid":h,children:a}):null,r("button",{type:"submit",class:`${de}-form-submit`,disabled:c,"data-testid":u,children:n})]})]})}function vu({field:e,value:t,otherText:n,error:o,disabled:a,strings:i,onChange:l,onOtherChange:s}){let c=xe(S.formField,e.name),d=bu({field:e,value:t,otherText:n,disabled:a,strings:i,onChange:l,onOtherChange:s,fieldTid:c});return r("label",{class:`${de}-field`,"data-field":e.name,"data-invalid":o?"true":void 0,children:[r("span",{class:`${de}-field-label`,children:[e.label,e.required??!0?r("span",{class:`${de}-field-req`,"aria-hidden":"true",children:" *"}):null]}),d,e.validationHint&&!o?r("span",{class:`${de}-field-hint`,children:e.validationHint}):null,o?r("span",{class:`${de}-field-error`,role:"alert",children:o}):null]})}function bu(e){let{field:t,value:n,otherText:o,disabled:a,strings:i,onChange:l,onOtherChange:s,fieldTid:c}=e,d=typeof n=="string"?n:"";switch(t.type){case"textarea":return r("textarea",{class:`${de}-field-input`,rows:3,value:d,placeholder:t.placeholder,disabled:a,onInput:u=>l(u.target.value),"data-testid":c});case"select":return r("select",{class:`${de}-field-input`,value:d,disabled:a,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===wo;return r("div",{class:`${de}-field-choices`,role:"radiogroup","data-testid":c,children:[(t.options??[]).map(h=>r("label",{class:`${de}-choice`,children:[r("input",{type:"radio",name:`${de}-${t.name}`,checked:d===h.value,disabled:a,onChange:()=>l(h.value)}),r("span",{children:h.label??h.value})]},h.value)),t.allowOther?r("label",{class:`${de}-choice`,children:[r("input",{type:"radio",name:`${de}-${t.name}`,checked:d===wo,disabled:a,onChange:()=>l(wo)}),r("span",{children:i.formOther})]}):null,u?r("input",{class:`${de}-field-input`,value:o,placeholder:t.placeholder??i.formOtherPlaceholder,disabled:a,onInput:h=>s(h.target.value)}):null]})}case"checkbox":return r("label",{class:`${de}-choice`,children:[r("input",{type:"checkbox",checked:d==="true",disabled:a,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:[],h=(_,f)=>l(f?[...u,_]:u.filter(m=>m!==_));return r("div",{class:`${de}-field-choices`,"data-testid":c,children:[(t.options??[]).map(_=>r("label",{class:`${de}-choice`,children:[r("input",{type:"checkbox",checked:u.includes(_.value),disabled:a,onChange:f=>h(_.value,f.target.checked)}),r("span",{children:_.label??_.value})]},_.value)),t.allowOther||(t.options??[]).length===0?r("textarea",{class:`${de}-field-input`,rows:2,value:o,placeholder:t.placeholder??i.formOtherPlaceholder,disabled:a,onInput:_=>s(_.target.value)}):null]})}default:return r("input",{class:`${de}-field-input`,type:Pu(t.type),value:d,placeholder:t.placeholder,disabled:a,onInput:u=>l(u.target.value),"data-testid":c})}}function Pu(e){switch(e){case"number":case"email":case"tel":case"url":case"date":case"time":return e;default:return"text"}}function xu(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 yu(e,t,n){let o={...t};for(let a of e){let i=n[a.name]?.trim();if(a.type==="radio"&&a.allowOther&&t[a.name]===wo)o[a.name]=i??"";else if(a.type==="multiselect"&&i){let l=i.split(/[,\n;]+/).map(c=>c.trim()).filter(Boolean),s=Array.isArray(t[a.name])?t[a.name]:[];o[a.name]=[...s,...l]}}return o}var et=x.cssPrefix;function Vr({form:e,strings:t,onSubmit:n,onSkip:o}){return r("div",{class:`${et}-form-gate`,"data-testid":S.formGate,children:[e.title?r("h3",{class:`${et}-form-gate-title`,children:e.title}):null,e.description?r("p",{class:`${et}-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:S.formSubmit,skipTestId:S.formSkip})]})}function fl({marker:e,strings:t,onFill:n}){let o=e.outcome==="skipped",a=o?t.formSkipped:t.formSubmitted,i=e.title?r(oe,{children:[r("span",{children:e.title}),r("span",{class:`${et}-sr-only`,children:a})]}):r("span",{children:a}),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:`${et}-form-done`,"data-outcome":e.outcome,"data-testid":S.formDone,children:[r("summary",{class:`${et}-form-done-summary`,"data-testid":S.formDoneToggle,children:[r(yt,{}),i,r(Ut,{})]}),r("dl",{class:`${et}-form-answers`,"data-testid":S.formAnswers,children:Object.entries(s).map(([d,u])=>r("div",{class:`${et}-form-answer`,children:[r("dt",{children:c(d)}),r("dd",{children:u})]},d))})]})}return r("div",{class:`${et}-form-done`,"data-outcome":e.outcome,"data-testid":S.formDone,role:"status",children:[o?r($s,{}):r(yt,{}),i,o&&e.form?.reopenable&&n?r("button",{type:"button",class:`${et}-form-done-fill`,"data-testid":S.formFill,onClick:n,children:t.formFillOut}):null]})}function gl(e){if(!e)return!1;let t=e.startsWith("tool:")?e.slice(5):e;return t==="ask-user-questions"||t==="ask_user_questions"}var Gr=1,vl=2,bl=4,Pl=8,xl=16;function Su(e){switch(e){case Gr:return"href";case vl:return"src";case bl:return"class";case Pl:return"checked";case xl:return"start"}}var ku=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}},wu=ku;var hl=24;function jr(e){let t=new Uint32Array(hl);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(hl),indent:"",indent_len:0,table_state:0}}function yl(e){e.pending.length>0&&Ce(e,`
12
12
  `)}function re(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 ae(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 Cu(e,t,n){for(;n<=e.len;){if(e.tokens[n]===t)return n;n+=1}return-1}function wt(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 a=e.blockquote_idx+1;a<=e.len;a+=1)if(e.tokens[a]===25){if(e.indent_len<e.spaces[a]){o=-1;break}o=a}else e.tokens[a]===t&&(n=a);return o===-1?n===-1?(wt(e,e.blockquote_idx),ae(e,t),!0):(wt(e,n),!1):(wt(e,o),ae(e,t),!0)}function Wr(e,t){ae(e,25),e.spaces[e.len]=e.indent_len+t,it(e),e.token=103}function it(e){e.indent="",e.indent_len=0,e.pending=""}function Kr(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 Tu(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 Eu(e){return Kr(e)||Tu(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 a=To(e,e.indent_len);e.indent_len=0,e.token=e.tokens[e.len],a>0&&Ce(e," ".repeat(a))}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),it(e),e.pending=n;continue}wt(e,e.blockquote_idx),it(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),ae(e,wu(e.pending.length)),it(e);continue}break;case">":{let i=Cu(e,20,e.blockquote_idx+1);i===-1?(wt(e,e.blockquote_idx),e.blockquote_idx+=1,e.fence_start=0,ae(e,20)):e.blockquote_idx=i,it(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),it(e),e.hr_chars=0;continue}e.hr_chars=0}if(e.pending[0]!=="_"&&e.pending[1]===" "){qr(e,23),Wr(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):(ae(e,2),it(e),e.fence_start=0,Ce(e,o));continue;case`