pi-foreman 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +179 -2
- package/package.json +58 -4
- package/src/bootstrap.mjs +107 -0
- package/src/cli.mjs +504 -0
- package/src/config.mjs +819 -0
- package/src/docs.mjs +148 -0
- package/src/envs.mjs +621 -0
- package/src/harness.mjs +96 -0
- package/src/hub.mjs +117 -0
- package/src/projection.mjs +455 -0
- package/src/providers.mjs +622 -0
- package/src/server.mjs +1350 -0
- package/src/skills.mjs +340 -0
- package/src/stores.mjs +117 -0
- package/src/tasks/ask-peer.mjs +201 -0
- package/src/tasks/peer-tools.mjs +254 -0
- package/src/tasks/workspace-extension.mjs +108 -0
- package/web/dist/assets/chat-vendor-CpKl2eGN.css +1 -0
- package/web/dist/assets/chat-vendor-PY5rkhAV.js +43 -0
- package/web/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/web/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/web/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/web/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/web/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/web/dist/assets/icons-BRdrcGH3.js +2 -0
- package/web/dist/assets/index-C32JOM8D.js +35 -0
- package/web/dist/assets/index-D_7gqB73.css +1 -0
- package/web/dist/assets/react-vendor-DEAzPTfA.js +10 -0
- package/web/dist/index.html +17 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import{r as H,a as ad,R as et,g as na,j as C,b as ld}from"./react-vendor-DEAzPTfA.js";function Os(){return typeof window<"u"}function qn(t){return cd(t)?(t.nodeName||"").toLowerCase():"#document"}function Le(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Ot(t){var e;return(e=(cd(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function cd(t){return Os()?t instanceof Node||t instanceof Le(t).Node:!1}function yt(t){return Os()?t instanceof Element||t instanceof Le(t).Element:!1}function Ut(t){return Os()?t instanceof HTMLElement||t instanceof Le(t).HTMLElement:!1}function Ml(t){return!Os()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof Le(t).ShadowRoot}function Ls(t){const{overflow:e,overflowX:n,overflowY:r,display:s}=bt(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&s!=="inline"&&s!=="contents"}function yg(t){return/^(table|td|th)$/.test(qn(t))}function Fs(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}const bg=/transform|translate|scale|rotate|perspective|filter/,_g=/paint|layout|strict|content/,Qt=t=>!!t&&t!=="none";let li;function ra(t){const e=yt(t)?bt(t):t;return Qt(e.transform)||Qt(e.translate)||Qt(e.scale)||Qt(e.rotate)||Qt(e.perspective)||!sa()&&(Qt(e.backdropFilter)||Qt(e.filter))||bg.test(e.willChange||"")||_g.test(e.contain||"")}function vg(t){let e=an(t);for(;Ut(e)&&!_r(e);){if(ra(e))return e;if(Fs(e))return null;e=an(e)}return null}function sa(){return li==null&&(li=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),li}function _r(t){return/^(html|body|#document)$/.test(qn(t))}function bt(t){return Le(t).getComputedStyle(t)}function $s(t){return yt(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function an(t){if(qn(t)==="html")return t;const e=t.assignedSlot||t.parentNode||Ml(t)&&t.host||Ot(t);return Ml(e)?e.host:e}function ud(t){const e=an(t);return _r(e)?(t.ownerDocument||t).body:Ut(e)&&Ls(e)?e:ud(e)}function vr(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const s=ud(t),i=s===((r=t.ownerDocument)==null?void 0:r.body),o=Le(s);if(i){const a=Ji(o);return e.concat(o,o.visualViewport||[],Ls(s)?s:[],a&&n?vr(a):[])}else return e.concat(s,vr(s,[],n))}function Ji(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}const $n=Math.min,At=Math.max,us=Math.round,jr=Math.floor,Rt=t=>({x:t,y:t}),wg={left:"right",right:"left",bottom:"top",top:"bottom"};function xg(t,e,n){return At(t,$n(e,n))}function ln(t,e){return typeof t=="function"?t(e):t}function jt(t){return t.split("-")[0]}function Er(t){return t.split("-")[1]}function ia(t){return t==="x"?"y":"x"}function dd(t){return t==="y"?"height":"width"}function pt(t){const e=t[0];return e==="t"||e==="b"?"y":"x"}function hd(t){return ia(pt(t))}function Sg(t,e,n){n===void 0&&(n=!1);const r=Er(t),s=hd(t),i=dd(s);let o=s==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[i]>e.floating[i]&&(o=ds(o)),[o,ds(o)]}function Tg(t){const e=ds(t);return[Xi(t),e,Xi(e)]}function Xi(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const Pl=["left","right"],Dl=["right","left"],Cg=["top","bottom"],Ig=["bottom","top"];function kg(t,e,n){switch(t){case"top":case"bottom":return n?e?Dl:Pl:e?Pl:Dl;case"left":case"right":return e?Cg:Ig;default:return[]}}function Eg(t,e,n,r){const s=Er(t);let i=kg(jt(t),n==="start",r);return s&&(i=i.map(o=>o+"-"+s),e&&(i=i.concat(i.map(Xi)))),i}function ds(t){const e=jt(t);return wg[e]+t.slice(e.length)}function Ag(t){var e,n,r,s;return{top:(e=t.top)!=null?e:0,right:(n=t.right)!=null?n:0,bottom:(r=t.bottom)!=null?r:0,left:(s=t.left)!=null?s:0}}function Rg(t){return typeof t!="number"?Ag(t):{top:t,right:t,bottom:t,left:t}}function hs(t){const{x:e,y:n,width:r,height:s}=t;return{width:r,height:s,top:n,left:e,right:e+r,bottom:n+s,x:e,y:n}}function Ol(t,e,n){let{reference:r,floating:s}=t;const i=pt(e),o=hd(e),a=dd(o),l=jt(e),c=i==="y",u=r.x+r.width/2-s.width/2,d=r.y+r.height/2-s.height/2,f=r[a]/2-s[a]/2;let h;switch(l){case"top":h={x:u,y:r.y-s.height};break;case"bottom":h={x:u,y:r.y+r.height};break;case"right":h={x:r.x+r.width,y:d};break;case"left":h={x:r.x-s.width,y:d};break;default:h={x:r.x,y:r.y}}const p=Er(e);return p&&(h[o]+=f*(p==="end"?1:-1)*(n&&c?-1:1)),h}async function Mg(t,e){var n;e===void 0&&(e={});const{x:r,y:s,platform:i,rects:o,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:f=!1,padding:h=0}=ln(e,t),p=Rg(h),y=a[f?d==="floating"?"reference":"floating":d],g=hs(await i.getClippingRect({element:(n=await(i.isElement==null?void 0:i.isElement(y)))==null||n?y:y.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),b=d==="floating"?{x:r,y:s,width:o.floating.width,height:o.floating.height}:o.reference,v=await(i.getOffsetParent==null?void 0:i.getOffsetParent(a.floating)),w=await(i.isElement==null?void 0:i.isElement(v))&&await(i.getScale==null?void 0:i.getScale(v))||{x:1,y:1},k=hs(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:v,strategy:l}):b);return{top:(g.top-k.top+p.top)/w.y,bottom:(k.bottom-g.bottom+p.bottom)/w.y,left:(g.left-k.left+p.left)/w.x,right:(k.right-g.right+p.right)/w.x}}const Pg=50,Dg=async(t,e,n)=>{const{placement:r="bottom",strategy:s="absolute",middleware:i=[],platform:o}=n,a=o.detectOverflow?o:{...o,detectOverflow:Mg},l=await(o.isRTL==null?void 0:o.isRTL(e));let c=await o.getElementRects({reference:t,floating:e,strategy:s}),{x:u,y:d}=Ol(c,r,l),f=r,h=0;const p={};for(let m=0;m<i.length;m++){const y=i[m];if(!y)continue;const{name:g,fn:b}=y,{x:v,y:w,data:k,reset:_}=await b({x:u,y:d,initialPlacement:r,placement:f,strategy:s,middlewareData:p,rects:c,platform:a,elements:{reference:t,floating:e}});u=v??u,d=w??d,p[g]={...p[g],...k},_&&h<Pg&&(h++,typeof _=="object"&&(_.placement&&(f=_.placement),_.rects&&(c=_.rects===!0?await o.getElementRects({reference:t,floating:e,strategy:s}):_.rects),{x:u,y:d}=Ol(c,f,l)),m=-1)}return{x:u,y:d,placement:f,strategy:s,middlewareData:p}},Og=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:s,middlewareData:i,rects:o,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:u=!0,crossAxis:d=!0,fallbackPlacements:f,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:m=!0,...y}=ln(t,e);if((n=i.arrow)!=null&&n.alignmentOffset)return{};const g=jt(s),b=pt(a),v=jt(a)===a,w=await(l.isRTL==null?void 0:l.isRTL(c.floating)),k=f||(v||!m?[ds(a)]:Tg(a)),_=p!=="none";!f&&_&&k.push(...Eg(a,m,p,w));const A=[a,...k],E=await l.detectOverflow(e,y),D=[];let x=((r=i.flip)==null?void 0:r.overflows)||[];if(u&&D.push(E[g]),d){const $=Sg(s,o,w);D.push(E[$[0]],E[$[1]])}if(x=[...x,{placement:s,overflows:D}],!D.every($=>$<=0)){var M,P;const $=(((M=i.flip)==null?void 0:M.index)||0)+1,L=A[$];if(L&&(!(d==="alignment"?b!==pt(L):!1)||x.every(q=>pt(q.placement)===b?q.overflows[0]>0:!0)))return{data:{index:$,overflows:x},reset:{placement:L}};let j=(P=x.filter(V=>V.overflows[0]<=0).sort((V,q)=>V.overflows[1]-q.overflows[1])[0])==null?void 0:P.placement;if(!j)switch(h){case"bestFit":{var T;const V=(T=x.filter(q=>{if(_){const U=pt(q.placement);return U===b||U==="y"}return!0}).map(q=>[q.placement,q.overflows.filter(U=>U>0).reduce((U,S)=>U+S,0)]).sort((q,U)=>q[1]-U[1])[0])==null?void 0:T[0];V&&(j=V);break}case"initialPlacement":j=a;break}if(s!==j)return{reset:{placement:j}}}return{}}}},fd=new Set(["left","top"]);async function Lg(t,e){const{placement:n,platform:r,elements:s}=t,i=await(r.isRTL==null?void 0:r.isRTL(s.floating)),o=jt(n),a=Er(n),l=pt(n)==="y",c=fd.has(o)?-1:1,u=i&&l?-1:1,d=ln(e,t);let{mainAxis:f,crossAxis:h,alignmentAxis:p}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return a&&typeof p=="number"&&(h=a==="end"?p*-1:p),l?{x:h*u,y:f*c}:{x:f*c,y:h*u}}const Fg=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:s,y:i,placement:o,middlewareData:a}=e,l=await Lg(e,t);return o===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:s+l.x,y:i+l.y,data:{...l,placement:o}}}}},$g=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:s,platform:i}=e,{mainAxis:o=!0,crossAxis:a=!1,limiter:l={fn:b=>{let{x:v,y:w}=b;return{x:v,y:w}}},...c}=ln(t,e),u={x:n,y:r},d=await i.detectOverflow(e,c),f=pt(s),h=ia(f);let p=u[h],m=u[f];const y=(b,v)=>xg(v+d[b==="y"?"top":"left"],v,v-d[b==="y"?"bottom":"right"]);o&&(p=y(h,p)),a&&(m=y(f,m));const g=l.fn({...e,[h]:p,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:o,[f]:a}}}}}},Ng=function(t){return t===void 0&&(t={}),{options:t,fn(e){var n,r;const{x:s,y:i,placement:o,rects:a,middlewareData:l}=e,{offset:c=0,mainAxis:u=!0,crossAxis:d=!0}=ln(t,e),f={x:s,y:i},h=pt(o),p=ia(h);let m=f[p],y=f[h];const g=ln(c,e),b=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:(n=g.mainAxis)!=null?n:0,crossAxis:(r=g.crossAxis)!=null?r:0};if(u){const k=p==="y"?"height":"width",_=a.reference[p]-a.floating[k]+b.mainAxis,A=a.reference[p]+a.reference[k]-b.mainAxis;m<_?m=_:m>A&&(m=A)}if(d){var v,w;const k=p==="y"?"width":"height",_=fd.has(jt(o)),A=a.reference[h]-a.floating[k]+(_&&((v=l.offset)==null?void 0:v[h])||0)+(_?0:b.crossAxis),E=a.reference[h]+a.reference[k]+(_?0:((w=l.offset)==null?void 0:w[h])||0)-(_?b.crossAxis:0);y<A?y=A:y>E&&(y=E)}return{[p]:m,[h]:y}}}},Bg=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){const{placement:n,rects:r,platform:s,elements:i}=e,{apply:o=()=>{},...a}=ln(t,e),l=await s.detectOverflow(e,a),c=jt(n),u=Er(n),d=pt(n)==="y",{width:f,height:h}=r.floating;let p,m;c==="top"||c==="bottom"?(p=c,m=u===(await(s.isRTL==null?void 0:s.isRTL(i.floating))?"start":"end")?"left":"right"):(m=c,p=u==="end"?"top":"bottom");const y=h-l.top-l.bottom,g=f-l.left-l.right,b=$n(h-l[p],y),v=$n(f-l[m],g),w=e.middlewareData.shift,k=!w;let _=b,A=v;w!=null&&w.enabled.x&&(A=g),w!=null&&w.enabled.y&&(_=y),k&&!u&&(d?A=f-2*At(l.left,l.right):_=h-2*At(l.top,l.bottom)),await o({...e,availableWidth:A,availableHeight:_});const E=await s.getDimensions(i.floating);return f!==E.width||h!==E.height?{reset:{rects:!0}}:{}}}};function pd(t){const e=bt(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const s=Ut(t),i=s?t.offsetWidth:n,o=s?t.offsetHeight:r,a=us(n)!==i||us(r)!==o;return a&&(n=i,r=o),{width:n,height:r,$:a}}function oa(t){return yt(t)?t:t.contextElement}function Rn(t){const e=oa(t);if(!Ut(e))return Rt(1);const n=e.getBoundingClientRect(),{width:r,height:s,$:i}=pd(e);let o=(i?us(n.width):n.width)/r,a=(i?us(n.height):n.height)/s;return(!o||!Number.isFinite(o))&&(o=1),(!a||!Number.isFinite(a))&&(a=1),{x:o,y:a}}const jg=Rt(0);function md(t){const e=Le(t);return!sa()||!e.visualViewport?jg:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function zg(t,e,n){return e===void 0&&(e=!1),!!n&&e&&n===Le(t)}function cn(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const s=t.getBoundingClientRect(),i=oa(t);let o=Rt(1);e&&(r?yt(r)&&(o=Rn(r)):o=Rn(t));const a=zg(i,n,r)?md(i):Rt(0);let l=(s.left+a.x)/o.x,c=(s.top+a.y)/o.y,u=s.width/o.x,d=s.height/o.y;if(i&&r){const f=Le(i),h=yt(r)?Le(r):r;let p=f,m=Ji(p);for(;m&&h!==p;){const y=Rn(m),g=m.getBoundingClientRect(),b=bt(m),v=g.left+(m.clientLeft+parseFloat(b.paddingLeft))*y.x,w=g.top+(m.clientTop+parseFloat(b.paddingTop))*y.y;l*=y.x,c*=y.y,u*=y.x,d*=y.y,l+=v,c+=w,p=Le(m),m=Ji(p)}}return hs({width:u,height:d,x:l,y:c})}function Ns(t,e){const n=$s(t).scrollLeft;return e?e.left+n:cn(Ot(t)).left+n}function gd(t,e){const n=t.getBoundingClientRect(),r=n.left+e.scrollLeft-Ns(t,n),s=n.top+e.scrollTop;return{x:r,y:s}}function Vg(t){let{elements:e,rect:n,offsetParent:r,strategy:s}=t;const i=s==="fixed",o=Ot(r),a=e?Fs(e.floating):!1;if(r===o||a&&i)return n;let l={scrollLeft:0,scrollTop:0},c=Rt(1);const u=Rt(0),d=Ut(r);if((d||!i)&&((qn(r)!=="body"||Ls(o))&&(l=$s(r)),d)){const h=cn(r);c=Rn(r),u.x=h.x+r.clientLeft,u.y=h.y+r.clientTop}const f=o&&!d&&!i?gd(o,l):Rt(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+f.x,y:n.y*c.y-l.scrollTop*c.y+u.y+f.y}}function Ug(t){return t.getClientRects?Array.from(t.getClientRects()):[]}function qg(t){const e=$s(t),n=t.ownerDocument.body,r=At(t.scrollWidth,t.clientWidth,n.scrollWidth,n.clientWidth),s=At(t.scrollHeight,t.clientHeight,n.scrollHeight,n.clientHeight);let i=-e.scrollLeft+Ns(t);const o=-e.scrollTop;return bt(n).direction==="rtl"&&(i+=At(t.clientWidth,n.clientWidth)-r),{width:r,height:s,x:i,y:o}}const Hg=25;function Wg(t,e,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",s=Le(t),i=Ot(t),o=s.visualViewport;let a=i.clientWidth,l=i.clientHeight,c=0,u=0;if(o){const f=!sa()||e==="fixed";r?f||(c=-o.offsetLeft,u=-o.offsetTop):(a=o.width,l=o.height,f&&(c=o.offsetLeft,u=o.offsetTop))}if(Ns(i)<=0){const f=i.ownerDocument,h=f.body,p=getComputedStyle(h),m=f.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,y=Math.abs(i.clientWidth-h.clientWidth-m),g=getComputedStyle(i).scrollbarGutter==="stable both-edges"?y/2:y;g<=Hg&&(a-=g)}return{width:a,height:l,x:c,y:u}}function Gg(t,e){const n=cn(t,!0,e==="fixed"),r=n.top+t.clientTop,s=n.left+t.clientLeft,i=Rn(t),o=t.clientWidth*i.x,a=t.clientHeight*i.y,l=s*i.x,c=r*i.y;return{width:o,height:a,x:l,y:c}}function Ll(t,e,n){let r;if(e==="viewport"||e==="layoutViewport")r=Wg(t,n,e);else if(e==="document")r=qg(Ot(t));else if(yt(e))r=Gg(e,n);else{const s=md(t);r={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return hs(r)}function Kg(t,e){const n=e.get(t);if(n)return n;let r=vr(t,[],!1).filter(a=>yt(a)&&qn(a)!=="body"),s=null;const i=bt(t).position==="fixed";let o=i?an(t):t;for(;yt(o)&&!_r(o);){const a=bt(o),l=ra(o),c=s?s.position:i?"fixed":"";!l&&(c==="fixed"||c==="absolute"&&a.position==="static")?r=r.filter(d=>d!==o):s=a,o=an(o)}return e.set(t,r),r}function Qg(t){let{element:e,boundary:n,rootBoundary:r,strategy:s}=t;const o=[...n==="clippingAncestors"?Fs(e)?[]:Kg(e,this._c):[].concat(n),r],a=Ll(e,o[0],s);let l=a.top,c=a.right,u=a.bottom,d=a.left;for(let f=1;f<o.length;f++){const h=Ll(e,o[f],s);l=At(h.top,l),c=$n(h.right,c),u=$n(h.bottom,u),d=At(h.left,d)}return{width:c-d,height:u-l,x:d,y:l}}function Yg(t){const{width:e,height:n}=pd(t);return{width:e,height:n}}function Jg(t,e,n){const r=Ut(e),s=Ot(e),i=n==="fixed",o=cn(t,!0,i,e);let a={scrollLeft:0,scrollTop:0};const l=Rt(0);if((r||!i)&&((qn(e)!=="body"||Ls(s))&&(a=$s(e)),r)){const f=cn(e,!0,i,e);l.x=f.x+e.clientLeft,l.y=f.y+e.clientTop}!r&&s&&(l.x=Ns(s));const c=s&&!r&&!i?gd(s,a):Rt(0),u=o.left+a.scrollLeft-l.x-c.x,d=o.top+a.scrollTop-l.y-c.y;return{x:u,y:d,width:o.width,height:o.height}}function ci(t){return bt(t).position==="static"}function Fl(t,e){if(!Ut(t)||bt(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Ot(t)===n&&(n=n.ownerDocument.body),n}function yd(t,e){const n=Le(t);if(Fs(t))return n;if(!Ut(t)){let s=an(t);for(;s&&!_r(s);){if(yt(s)&&!ci(s))return s;s=an(s)}return n}let r=Fl(t,e);for(;r&&yg(r)&&ci(r);)r=Fl(r,e);return r&&_r(r)&&ci(r)&&!ra(r)?n:r||vg(t)||n}const Xg=async function(t){const e=this.getOffsetParent||yd,n=this.getDimensions,r=await n(t.floating);return{reference:Jg(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Zg(t){return bt(t).direction==="rtl"}const ey={convertOffsetParentRelativeRectToViewportRelativeRect:Vg,getDocumentElement:Ot,getClippingRect:Qg,getOffsetParent:yd,getElementRects:Xg,getClientRects:Ug,getDimensions:Yg,getScale:Rn,isElement:yt,isRTL:Zg};function bd(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function ty(t,e,n){let r=null,s;const i=Ot(t);function o(){var u;clearTimeout(s),(u=r)==null||u.disconnect(),r=null}function a(u,d){u===void 0&&(u=!1),d===void 0&&(d=1),o();const f=t.getBoundingClientRect(),{left:h,top:p,width:m,height:y}=f;if(u||e(),!m||!y)return;const g=jr(p),b=jr(i.clientWidth-(h+m)),v=jr(i.clientHeight-(p+y)),w=jr(h),_={rootMargin:-g+"px "+-b+"px "+-v+"px "+-w+"px",threshold:At(0,$n(1,d))||1};let A=!0;function E(D){const x=D[0].intersectionRatio;if(!bd(f,t.getBoundingClientRect()))return a();if(x!==d){if(!A)return a();x?a(!1,x):s=setTimeout(()=>{a(!1,1e-7)},1e3)}A=!1}try{r=new IntersectionObserver(E,{..._,root:i.ownerDocument})}catch{r=new IntersectionObserver(E,_)}r.observe(t)}const l=Le(t),c=()=>a(n);return l.addEventListener("resize",c),a(!0),()=>{l.removeEventListener("resize",c),o()}}function gO(t,e,n,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:i=!0,elementResize:o=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=oa(t),u=s||i?[...c?vr(c):[],...e?vr(e):[]]:[];u.forEach(g=>{s&&g.addEventListener("scroll",n),i&&g.addEventListener("resize",n)});const d=c&&a?ty(c,n,i):null;let f=-1,h=null;o&&(h=new ResizeObserver(g=>{let[b]=g;b&&b.target===c&&h&&e&&(h.unobserve(e),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var v;(v=h)==null||v.observe(e)})),n()}),c&&!l&&h.observe(c),e&&h.observe(e));let p,m=l?cn(t):null;l&&y();function y(){const g=cn(t);m&&!bd(m,g)&&n(),m=g,p=requestAnimationFrame(y)}return n(),()=>{var g;u.forEach(b=>{s&&b.removeEventListener("scroll",n),i&&b.removeEventListener("resize",n)}),d?.(),(g=h)==null||g.disconnect(),h=null,l&&cancelAnimationFrame(p)}}const ny=Fg,ry=$g,sy=Og,iy=Bg,oy=Ng,ay=(t,e,n)=>{const r=new Map,s=n??{},i={...ey,...s.platform,_c:r};return Dg(t,e,{...s,platform:i})};var ly=typeof document<"u",cy=function(){},os=ly?H.useLayoutEffect:cy;function fs(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,s;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!fs(t[r],e[r]))return!1;return!0}if(s=Object.keys(t),n=s.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,s[r]))return!1;for(r=n;r--!==0;){const i=s[r];if(!(i==="_owner"&&t.$$typeof)&&!fs(t[i],e[i]))return!1}return!0}return t!==t&&e!==e}function _d(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function $l(t,e){const n=_d(t);return Math.round(e*n)/n}function ui(t){const e=H.useRef(t);return os(()=>{e.current=t}),e}function yO(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:s,elements:{reference:i,floating:o}={},transform:a=!0,whileElementsMounted:l,open:c}=t,[u,d]=H.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[f,h]=H.useState(r);fs(f,r)||h(r);const[p,m]=H.useState(null),[y,g]=H.useState(null),b=H.useCallback(q=>{q!==_.current&&(_.current=q,m(q))},[]),v=H.useCallback(q=>{q!==A.current&&(A.current=q,g(q))},[]),w=i||p,k=o||y,_=H.useRef(null),A=H.useRef(null),E=H.useRef(u),D=l!=null,x=ui(l),M=ui(s),P=ui(c),T=H.useCallback(()=>{if(!_.current||!A.current)return;const q={placement:e,strategy:n,middleware:f};M.current&&(q.platform=M.current),ay(_.current,A.current,q).then(U=>{const S={...U,isPositioned:P.current!==!1};$.current&&!fs(E.current,S)&&(E.current=S,ad.flushSync(()=>{d(S)}))})},[f,e,n,M,P]);os(()=>{c===!1&&E.current.isPositioned&&(E.current.isPositioned=!1,d(q=>({...q,isPositioned:!1})))},[c]);const $=H.useRef(!1);os(()=>($.current=!0,()=>{$.current=!1}),[]),os(()=>{if(w&&(_.current=w),k&&(A.current=k),w&&k){if(x.current)return x.current(w,k,T);T()}},[w,k,T,x,D]);const L=H.useMemo(()=>({reference:_,floating:A,setReference:b,setFloating:v}),[b,v]),j=H.useMemo(()=>({reference:w,floating:k}),[w,k]),V=H.useMemo(()=>{const q={position:n,left:0,top:0};if(!j.floating)return q;const U=$l(j.floating,u.x),S=$l(j.floating,u.y);return a?{...q,transform:"translate("+U+"px, "+S+"px)",..._d(j.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:U,top:S}},[n,a,j.floating,u.x,u.y]);return H.useMemo(()=>({...u,update:T,refs:L,elements:j,floatingStyles:V}),[u,T,L,j,V])}const bO=(t,e)=>{const n=ny(t);return{name:n.name,fn:n.fn,options:[t,e]}},_O=(t,e)=>{const n=ry(t);return{name:n.name,fn:n.fn,options:[t,e]}},vO=(t,e)=>({fn:oy(t).fn,options:[t,e]}),wO=(t,e)=>{const n=sy(t);return{name:n.name,fn:n.fn,options:[t,e]}},xO=(t,e)=>{const n=iy(t);return{name:n.name,fn:n.fn,options:[t,e]}};let vd=(t,e=21)=>(n=e)=>{let r="",s=n|0;for(;s-- >0;)r+=t[Math.random()*t.length|0];return r};const Mt=vd("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7),uy="__error__",Zi=t=>t.startsWith(uy);function Nl(t,e){if(e==="*")return!0;const n=e.split(",").map(i=>i.trim().toLowerCase()),r=t.name.toLowerCase(),s=t.type.split(";",1)[0].trim().toLowerCase();for(const i of n){if(i.startsWith(".")&&r.endsWith(i)||i.includes("/")&&i===s)return!0;if(i.endsWith("/*")){const o=i.split("/")[0];if(s.startsWith(`${o}/`))return!0}}return!1}function dy(t){const e=Mt();return t.type==="image"?{id:e,type:"image",name:t.filename??"image",content:[t],status:{type:"complete"}}:t.type==="file"?{id:e,type:"document",name:t.filename??"document",contentType:t.mimeType,content:[t],status:{type:"complete"}}:t.type==="audio"?{id:e,type:"audio",name:`audio.${t.audio.format}`,contentType:`audio/${t.audio.format}`,content:[t],status:{type:"complete"}}:{id:e,type:"data",name:t.name,content:[t],status:{type:"complete"}}}function hy(t){const e=[];for(const n of t)n.type!=="text"&&e.push(dy(n));return e}const tt=(t,e,n)=>{const r=s=>{console.error(`[assistant-ui] ${n} listener threw an error`,s)};for(const s of t)try{const i=s(typeof e=="function"?e():e);i!==null&&(typeof i=="object"||typeof i=="function")&&"then"in i&&typeof i.then=="function"&&Promise.resolve(i).catch(r)}catch(i){r(i)}},un=t=>t.content.filter(e=>e.type==="text").map(e=>e.text).join(`
|
|
2
|
+
|
|
3
|
+
`),Ge=(t,...e)=>Object.assign(Object.create(null),t,...e);function xe(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function ps(t,e=0){return e>100?!1:t===null||typeof t=="string"||typeof t=="boolean"?!0:typeof t=="number"?!Number.isNaN(t)&&Number.isFinite(t):Array.isArray(t)?t.every(n=>ps(n,e+1)):xe(t)?Object.entries(t).every(([n,r])=>typeof n=="string"&&ps(r,e+1)):!1}const fy=100,eo=(t,e,n)=>{if(t===e)return!0;if(n>fy||t==null||e==null)return!1;if(Array.isArray(t))return!Array.isArray(e)||t.length!==e.length?!1:t.every((i,o)=>eo(i,e[o],n+1));if(Array.isArray(e)||!xe(t)||!xe(e))return!1;const r=Object.keys(t),s=Object.keys(e);return r.length!==s.length?!1:r.every(i=>Object.hasOwn(e,i)&&eo(t[i],e[i],n+1))},aa=(t,e)=>!ps(t)||!ps(e)?!1:eo(t,e,0),at=t=>t,py=new Set(["$$typeof","nodeType","then","__v_raw","__v_isRef","__v_isReactive","__v_isReadonly","__v_isShallow","__v_skip"]),dn=(t,e)=>{if(t===Symbol.toStringTag)return e;if(typeof t!="symbol"){if(t==="toJSON")return()=>e;if(!py.has(t))return!1}};var wr=class{getOwnPropertyDescriptor(t,e){const n=this.get(t,e);if(n!==void 0)return{value:n,writable:!1,enumerable:!0,configurable:!0}}set(){return!1}setPrototypeOf(){return!1}defineProperty(){return!1}deleteProperty(){return!1}preventExtensions(){return!1}};const hn=Symbol("assistant-ui.store.clientId"),to=Symbol("assistant-ui.store.instanceTag"),la=new WeakSet,wd=new Set(["call","apply","bind"]),xd=(t,e)=>{const n=new Proxy((()=>{}),{apply:()=>(e(),n),get:(r,s)=>wd.has(s)?Reflect.get(r,s):s==="source"?t.source:s==="query"?t.query:s==="name"?t.name:s===hn?ca(e()):e()[s],has:(r,s)=>s==="source"||s==="query"||s==="name"||s===hn||s in e(),ownKeys:()=>Reflect.ownKeys(e()),getOwnPropertyDescriptor:(r,s)=>{if(!(typeof s=="symbol"||!(s in e())))return{value:e()[s],writable:!1,enumerable:!0,configurable:!0}}});return la.add(n),n},Sd=(t,e)=>{const n=()=>{throw new Error(t)},r=new Proxy((()=>{}),{apply:n,get:(s,i)=>{if(wd.has(i))return Reflect.get(s,i);if(i==="source"||i==="query")return null;if(i==="name")return e;if(i===hn)return n();const o=dn(i,"AssistantClientAccessor");return o!==!1?o:n()},has:(s,i)=>i==="source"||i==="query"||i==="name",ownKeys:()=>[],getOwnPropertyDescriptor:()=>{}});return la.add(r),r},my=t=>{if(la.has(t))return!1;const e=t[hn];return e!==void 0&&e!==t},Bs=t=>t?.source!=null,no=t=>t?.source===null,ca=t=>t[hn]??t,gy=t=>t[to]??ca(t),rn=t=>t==="optional"||t==="subscribe"||t==="on"||t==="__proto__"||typeof t=="symbol",ro=t=>{const e=[];for(const n in t)rn(n)||e.push(n);return e};var yy=class extends wr{#e;constructor(t){super(),this.#e=t}get(t,e){const n=dn(e,"OptionalAssistantClient");if(n!==!1)return n;if(rn(e))return;const r=this.#e[e];return Bs(r)?r:void 0}ownKeys(){return ro(this.#e)}has(t,e){return!rn(e)&&e in this.#e}};const Td=t=>new Proxy({},new yy(t));let Mn=null;function by(t,e){t.currentIndex=0,t.wipContextDeps=null,t.wipCommitCallbacks=[];const n=Mn;Mn=t;try{if(e(),t.isFirstRender=!1,t.cells.length!==t.currentIndex)throw new Error(`Rendered ${t.currentIndex} hooks but expected ${t.cells.length}. Hooks must be called in the exact same order in every render.`)}finally{Mn=n}}function Ke(){if(!Mn)throw new Error("No resource fiber available");return Mn}function lt(){return Mn}const Ue=(()=>{try{return!1}catch{return!1}})(),_y=(t,e)=>({onError:e,version:0,committedVersion:0,dispatchUpdate:t,changelog:[],committedLog:[],unsettledCount:0,rollbackCallbacks:[]}),Cd=t=>{t.committedVersion=t.version;for(const e of t.changelog)e.logged=!1,e.settled||(e.settled=!0,t.unsettledCount--),t.committedLog.push(e);t.changelog.length=0,t.unsettledCount===0&&(t.committedLog.length=0),t.rollbackCallbacks.length=0},Bl=(t,e)=>{const n=t.version>e;if(t.version=e,n){for(let r=0;r<t.rollbackCallbacks.length;r++)t.rollbackCallbacks[r]();if(t.rollbackCallbacks.length=0,e<=t.committedVersion){const r=[];for(;t.committedVersion-r.length>e;){const s=t.committedLog.pop();if(s===void 0){if(Ue)throw new Error("tap: committed history is shorter than the replay base.");break}ua(s.fiber,s.cell),s.cell.workInProgress=s.prevState,r.push({record:s,prevState:s.prevState,eagerState:s.eagerState,hasEagerState:s.hasEagerState})}if(r.length>0){const s=t.committedVersion;js(t,()=>{for(let i=r.length-1;i>=0;i--){const o=r[i];o.record.prevState=o.prevState,o.record.eagerState=o.eagerState,o.record.hasEagerState=o.hasEagerState,t.committedLog.push(o.record)}t.committedVersion=s})}t.committedVersion=e;for(const s of t.changelog)s.logged=!1;t.changelog.length=0}else{for(;t.committedVersion+t.changelog.length>e;)t.changelog.pop().logged=!1;for(let r=0;r<t.changelog.length;r++)Id(t.changelog[r]);Cd(t)}}},Id=t=>{ua(t.fiber,t.cell),t.queued||(t.queued=!0,(t.cell.queue??=[]).push(t))},Ar=(t,e)=>{t.wipCommitCallbacks.push(e)},js=(t,e)=>{t.rollbackCallbacks.push(e)},ua=(t,e)=>{e.isDirty||(e.isDirty=!0,t.markDirty?.(),js(t.root,()=>{if(e.queue!==null){for(const n of e.queue)n.queued=!1;e.queue=null}e.workInProgress=e.current,e.isDirty=!1}))},Rr=()=>{throw new Error("Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render.")},Mr=()=>{throw new Error("Hook order changed between renders")},vy=t=>({type:t,setup:void 0,setupDeps:void 0,cleanup:void 0,deps:null,generation:0});function kd(t,e,n){const r=Ke(),s=r.currentIndex++,i=r.cells[s],o=i===void 0?vy(n):i.type===n?i:Mr();if(i===void 0&&(r.isFirstRender||Rr(),r.cells[s]=o,n==="insertion"?(r.insertionCells??=[]).push(o):r.effectCells.push(o)),o.deps!==null&&!!e!=!!o.deps)throw new Error("useEffect called with and without dependencies across re-renders");const a=r.isRefreshing;Ar(r,()=>{o.setup=t,o.setupDeps=e,a&&(o.deps=null),o.generation++})}function Dt(t,e){kd(t,e,"effect")}function fn(t){const e=Ke(),n=e.currentIndex++,r=e.cells[n];if(r===void 0){e.isFirstRender||Rr();const s={current:t};return e.cells[n]={type:"ref",ref:s},s}return r.type!=="ref"?Mr():r.ref}const da=Symbol("tap.Context.defaultValue"),wy=t=>t;let En=new Map;const tn=new Set,Ed=(t,e)=>{t[da]=e},Ad=t=>typeof t=="object"&&t!==null&&da in t,Rd=t=>typeof t=="object"&&t!==null&&"$$typeof"in t&&t.$$typeof===Symbol.for("react.context"),so=t=>Ad(t)||Rd(t),Md=t=>{if(!Ad(t)){if(Rd(t)){Ed(t,t._currentValue??t._currentValue2);return}throw new Error("A tap resource's `use()` only accepts a tap context.")}},zs=(t,e,n)=>{if(typeof t!="object"||t===null)throw new Error("useContextProvider only accepts a React context.");Md(t);const r=t,s=Ke(),i=fn(void 0),o=i.current===void 0||!Object.is(i.current.value,e);Dt(()=>{i.current={value:e}},[e]);const a=En.get(r),l=a!==void 0||En.has(r);En.set(r,{value:e,source:s});try{return xy(r,o,n)}finally{l?En.set(r,a):En.delete(r)}},xy=(t,e,n)=>{const r=tn.has(t);e?tn.add(t):tn.delete(t);try{return n()}finally{r?tn.add(t):tn.delete(t)}},Pd=t=>{Md(t);const e=t,n=Sy(e,t),r=Ke();return(r.wipContextDeps??=new Map).set(e,n.source),n.value},Sy=(t,e)=>En.get(t)??{value:wy(e)[da],source:null},Ty=(t,e,n,r)=>{if(!r)return n;let s=n;for(const[i,o]of r)o===e||o===t||(s??=new Map).set(i,o);return s},Dd=(t,e=t.wipContextDeps)=>{const n=lt();!n||!e||(n.wipContextDeps=Ty(n,t,n.wipContextDeps,e))},Od=()=>tn.size>0,ha=t=>{if(!t.contextDeps||!Od())return!1;for(const e of tn.keys())if(t.contextDeps.has(e))return!0;return!1},Cy=(t,e,n)=>{if(t.isNeverMounted)throw new Error("Resource updated before mount");let r=!1,s=!0;t.root.unsettledCount++,t.root.dispatchUpdate(()=>(r||(r=!0,n&&t.root.changelog.length===0&&!e.cell.isDirty&&!e.hasEagerState&&(e.prevState=e.cell.workInProgress,e.eagerState=n(e.cell.workInProgress,e.action),e.hasEagerState=!0,s=!Object.is(e.cell.current,e.eagerState),!s&&!e.settled&&(e.settled=!0,t.root.unsettledCount--))),s),()=>(r=!0,s=!0,Id(e),e.logged||(e.logged=!0,t.root.changelog.push(e)),!0))},Iy=(t,e,n,r,s)=>{const i=r?r(n):n;Ue&&t.devStrictMode&&r&&r(n);const o={type:"reducer",workInProgress:i,current:i,isDirty:!1,queue:null,renderQueue:null,reducer:e,dispatch:a=>{const l=lt();if(l!==null){if(l!==t)throw new Error("Cannot update a resource while rendering a different resource.");(t.renderPendingCells??=new Set).add(o),(o.renderQueue??=[]).push(a)}else{const c={fiber:t,cell:o,action:a,hasEagerState:!1,eagerState:void 0,prevState:o.current,settled:!1,queued:!1,logged:!1};Cy(t,c,s?e:void 0)}}};return o};function Ld(t,e,n,r){const s=Ke(),i=s.currentIndex++,o=s.cells[i],a=(()=>{if(o!==void 0)return o.type==="reducer"?o:Mr();s.isFirstRender||Rr();const c=Iy(s,t,e,n,r);return s.cells[i]=c,c})(),l=a.queue;if(l!==null){const c=t===a.reducer;for(let u=0;u<l.length;u++){const d=l[u];!d.hasEagerState||!c||!Object.is(d.prevState,a.workInProgress)?(d.prevState=a.workInProgress,d.eagerState=t(a.workInProgress,d.action),d.hasEagerState=!0,Ue&&s.devStrictMode&&(d.eagerState=t(a.workInProgress,d.action))):Ue&&s.devStrictMode&&t(a.workInProgress,d.action),d.queued=!1,a.workInProgress=d.eagerState}a.queue=null}if(a.reducer=t,a.renderQueue!==null){let c=a.workInProgress;for(const u of a.renderQueue)c=t(c,u);a.renderQueue=null,s.renderPendingCells?.delete(a),Object.is(c,a.workInProgress)||(ua(s,a),a.workInProgress=c)}return a.isDirty&&Ar(s,()=>{a.current=a.workInProgress,a.isDirty=!1}),[a.workInProgress,a.dispatch]}function fa(t,e,n){return Ld(t,e,n,!1)}const ky=(t,e)=>typeof e=="function"?e(t):e,Ey=t=>t===void 0?void 0:typeof t=="function"?t():t;function Fd(t){return Ld(ky,t,Ey,!0)}const Pr=(t,e)=>{Ue&&t.length!==e.length&&console.error(`The final argument passed to a hook changed size between renders. The order and size of this array must remain constant.
|
|
4
|
+
|
|
5
|
+
Previous: [${t.join(", ")}]
|
|
6
|
+
Incoming: [${e.join(", ")}]`);for(let n=0;n<t.length&&n<e.length;n++)if(!Object.is(t[n],e[n]))return!1;return!0},jl=(t,e)=>{Ar(t,()=>{e.current=e.wip,e.currentDeps=e.wipDeps,e.wipIsRefreshing=!1,e.isDirty=!1})},pa=(t,e)=>{const n=Ke(),r=n.currentIndex++;let s=n.cells[r];if(s===void 0){n.isFirstRender||Rr();const a=t();return Ue&&n.devStrictMode&&t(),s={type:"memo",current:a,currentDeps:e,wip:a,wipDeps:e,wipIsRefreshing:!1,isDirty:!1},n.cells[r]=s,a}s.type!=="memo"&&Mr();const i=s;if(i.wipIsRefreshing&&!n.isRefreshing&&(i.wip=i.current,i.wipDeps=i.currentDeps,i.wipIsRefreshing=!1,i.isDirty=!1),!n.isRefreshing&&Pr(i.wipDeps,e))return i.isDirty&&jl(n,i),i.wip;const o=t();return Ue&&n.devStrictMode&&t(),i.wip=o,i.wipDeps=e,i.wipIsRefreshing=n.isRefreshing,i.isDirty||(i.isDirty=!0,js(n.root,()=>{i.wip=i.current,i.wipDeps=i.currentDeps,i.wipIsRefreshing=!1,i.isDirty=!1})),jl(n,i),o},$d=(t,e)=>pa(()=>t,e);function Nd(t,e){kd(t,e,"insertion")}const Ay=t=>((...e)=>{if(Ue&<())throw new Error("useEffectEvent cannot be called during render");return t.current(...e)});function ma(t){const e=Ke(),n=fn(t);return n.current!==t&&Ar(e,()=>{n.current=t}),fn(Ay(n)).current}const Ry=t=>t!==null&&typeof t=="object"&&typeof t.then=="function",zl=()=>{},My=t=>{const e=t;switch(typeof e.status!="string"?(e.status="pending",t.then(n=>{e.status==="pending"&&(e.status="fulfilled",e.value=n)},n=>{e.status==="pending"&&(e.status="rejected",e.reason=n)})):e.status!=="fulfilled"&&e.status!=="rejected"&&t.then(zl,zl),e.status){case"fulfilled":return e.value;case"rejected":throw e.reason;default:throw t}},ga=t=>Ry(t)?My(t):Pd(t);let Vl=!1;const Py=t=>t+1,Dy=(t,e,n)=>()=>{try{if(Object.is(t,e()))return n.current=0,!1}catch{}return!0},Oy=(t,e,n,r)=>{const s=fn(0),i=ma(Dy(e,n,s));Dt(()=>t(()=>{i()&&r()}),[t,r]),Dt(()=>{if(i()){if(++s.current>50)throw s.current=0,new Error("Maximum update depth exceeded. The result of getSnapshot should be cached to avoid an infinite loop.");r()}},[t,e,n,r])},Bd=(t,e,n=e)=>{const r=Ke().isNeverMounted,s=r?n():e();Ue&&!Vl&&(!r||n===e)&&(Object.is(s,e())||(Vl=!0,console.error("The result of getSnapshot should be cached to avoid an infinite loop")));const[,i]=fa(Py,0);return Oy(t,s,e,i),s},jd=(t,e)=>{};let Ly=0;const zd=()=>{const t=fn(null);return t.current??=`:tap${Ly++}:`,t.current},Vd=(t,e,n)=>{const r=()=>{if(!t)return;const s=e();if(typeof t=="function"){const i=t(s);return typeof i=="function"?i:()=>t(null)}return t.current=s,()=>{t.current=null}};n==null?Dt(r):Dt(r,[...n,t])},Fy=et;function $y(t){const e=H.useRef(t);return H.useInsertionEffect(()=>{e.current=t}),H.useCallback(((...n)=>e.current(...n)),[])}const Ny=Fy.useEffectEvent??$y,Me=()=>lt()!==null,ge=et,ie=t=>Me()?Fd(t):ge.useState(t),By=(t,e,n)=>Me()?fa(t,e,n):ge.useReducer(t,e,n),X=t=>Me()?fn(t):ge.useRef(t),ye=(t,e)=>Me()?pa(t,e):ge.useMemo(t,e),mt=(t,e)=>Me()?$d(t,e):ge.useCallback(t,e),Q=(t,e)=>Me()?Dt(t,e):ge.useEffect(t,e),Ud=(t,e)=>Me()?Dt(t,e):ge.useLayoutEffect(t,e),nt=t=>Me()?ma(t):Ny(t),yn=(t,e,n)=>Me()?Bd(t,e,n):ge.useSyncExternalStore(t,e,n),jy=(t,e)=>Me()?jd():ge.useDebugValue(t,e),ct=(t,e)=>Me()?Nd(t,e):ge.useInsertionEffect(t,e),zy=()=>Me()?zd():ge.useId(),Vy=(t,e,n)=>Me()?Vd(t,e,n):ge.useImperativeHandle(t,e,n),{Activity:SO,Component:TO,Profiler:CO,PureComponent:IO,StrictMode:kO,ViewTransition:EO,act:AO,addTransitionType:RO,cache:MO,cacheSignal:PO,captureOwnerStack:DO,createFactory:OO,createRef:LO,startTransition:FO,unstable_act:$O,unstable_useCacheRefresh:NO,useActionState:BO,useOptimistic:jO,useTransition:zO,version:Uy,__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE:VO,__COMPILER_RUNTIME:UO,__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED:qO}=ge,he=t=>ge.forwardRef(t),Te=(t,e)=>ge.memo(t,e),qy=ge.Fragment,Hy=(...t)=>ge.createElement(...t),Wy=(...t)=>ge.cloneElement(...t),Vs=t=>ge.isValidElement(t);ge.Children;ge.Suspense;const ke=t=>{const e=ge.createContext(t);return Ed(e,t),e},Hn=t=>{if(Me()&&so(t))return ga(t);if(ge.use)return ge.use(t);if(so(t))return ge.useContext(t);throw new Error("React.use() requires React 19 outside a tap resource.")},Fe=t=>Me()&&so(t)?ga(t):ge.useContext(t),qd=Symbol.for("react.memo_cache_sentinel"),io=t=>new Array(t).fill(qd),Gy=(t,e)=>{const n=t.memoCache;let r=n.workInProgress;if(r===null){const o=n.current;r=o===null?[]:o.map(a=>a.slice()),n.workInProgress=r,js(t.root,()=>{n.workInProgress=null,n.refreshedIndices=null})}const s=n.index++;let i=r[s];return n.refreshedIndices?.has(s)&&!t.isRefreshing&&(n.refreshedIndices.delete(s),i=n.current?.[s]?.slice()??io(e),r[s]=i),i===void 0||t.isRefreshing?(i=io(e),r[s]=i,t.isRefreshing&&(n.refreshedIndices??=new Set).add(s)):Ue&&i.length!==e&&console.error(`Expected a constant size argument for each invocation of c(). The previous cache was allocated with size ${i.length} but size ${e} was requested.`),i},Hd=t=>Gy(Ke(),t),bn=(t,e)=>{if(t.length!==0){if(t.length===1)throw t[0];for(const n of t)console.error(n);throw new AggregateError(t,e)}},Ky=50;let Ee={schedulers:new Set,tasks:[],notifies:[],isScheduled:!1},Et=null,as;var Qy=class{_isDirty=!1;_task;onError;constructor(t,e){this._task=t,this.onError=e}get isDirty(){return this._isDirty}markDirty(){if(Et&&(Et.get(this)??0)>=Ky)throw new Error("Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside useEffect.");this._isDirty=!0,Ee.schedulers.add(this),Wd()}runTask(){Et?.set(this,(Et.get(this)??0)+1),this._isDirty=!1,this._task()}settle(){this._isDirty=!1}};const Yy=new Qy(()=>{const t=Ee.tasks.splice(0),e=[];for(const{run:n,onError:r}of t)try{n()}catch(s){if(as&&r)try{r(s)}catch(i){e.push(i)}else e.push(s)}bn(e,"Errors occurred while running scheduled tasks")}),Wd=()=>{Ee.isScheduled||(Ee.isScheduled=!0,Jy())},oo=(t=!1)=>{const e=Et,n=as,r=[];Et=new Map,as=t?r:void 0;try{for(const s of Ee.schedulers)if(Ee.schedulers.delete(s),!!s.isDirty)try{s.runTask()}catch(i){if(t&&s.onError)try{s.onError(i)}catch(o){r.push(o)}else r.push(i)}}finally{if(Et=e,as=n,Ee.schedulers.clear(),Ee.isScheduled=!1,Et===null){const s=Ee.notifies;for(;s.length>0;){const{run:i,onError:o}=s.shift();try{i()}catch(a){if(t&&o)try{o(a)}catch(l){r.push(l)}else r.push(a)}}}}bn(r,"Errors occurred during flushSync")},Jy=(()=>{if(typeof MessageChannel<"u"){let t=null,e;return()=>{if(!t){const n=new MessageChannel;n.port1.onmessage=()=>{t?.unref?.(),oo(!0)},t=n.port1,e=n.port2}t.ref?.(),e.postMessage(null)}}return()=>setTimeout(()=>oo(!0),0)})(),Ul=t=>{if(Et!==null)return Ue&&console.warn("flushTapSync was called from inside a render or commit. The flush is deferred until the current pass completes."),t();const e=Ee;Ee={schedulers:new Set,tasks:[],notifies:[],isScheduled:!0};try{const n=t();return oo(),n}finally{const n=Ee;Ee=e;for(const r of n.tasks)Ee.tasks.push(r);if(Ee.tasks.length>0&&Yy.markDirty(),n.schedulers.size>0){for(const r of n.schedulers)Ee.schedulers.add(r);Wd()}}};function Xy(t){if(t.length===0)return;let e;for(let n=0;n<t.length;n++)try{t[n]()}catch(r){(e??=[]).push(r)}e!==void 0&&bn(e,"Errors during commit")}function Zy(t){const e=t.setup,n=t.setupDeps,r=t.generation;let s;try{const i=e();if(i!==void 0&&typeof i!="function")throw new Error(`An effect function must either return a cleanup function or nothing. Received: ${typeof i}`);s=i}finally{t.generation===r?(t.cleanup=s,t.deps=n):s?.()}}const eb=t=>t.setup===void 0?!1:t.deps===null||t.setupDeps===void 0?!0:!Pr(t.deps,t.setupDeps);function ql(t,e){let n;for(const r of t)eb(r)&&(n??=[]).push(r);if(n===void 0)return e;for(const r of n)if(r.deps=null,r.cleanup!==void 0)try{r.cleanup()}catch(s){(e??=[]).push(s)}finally{r.cleanup=void 0}for(const r of n)try{Zy(r)}catch(s){(e??=[]).push(s)}return e}function Hl(t,e=!0){let n;t.insertionCells!==null&&e&&(n=ql(t.insertionCells,n)),n=ql(t.effectCells,n),n!==void 0&&bn(n,"Errors during commit")}function Wl(t){let e;for(const n of t)if(n.deps=null,n.cleanup)try{n.cleanup?.()}catch(r){(e??=[]).push(r)}finally{n.cleanup=void 0}e!==void 0&&bn(e,"Errors during cleanup")}const tb={useState:Fd,useReducer:fa,useRef:fn,useMemo:pa,useCallback:$d,useEffect:Dt,useLayoutEffect:Dt,useInsertionEffect:Nd,useEffectEvent:ma,useContext:Pd,use:ga,useSyncExternalStore:Bd,useDebugValue:jd,useId:zd,useImperativeHandle:Vd,useMemoCache:Hd},Gl=et,Yt=Gl.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE??Gl.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,zr=Yt==null?null:"H"in Yt?{get current(){return Yt.H},set current(t){Yt.H=t}}:"ReactCurrentDispatcher"in Yt?{get current(){return Yt.ReactCurrentDispatcher.current},set current(t){Yt.ReactCurrentDispatcher.current=t}}:null;function nb(t){if(!zr)return t();const e=zr.current;zr.current=tb;try{return t()}finally{zr.current=e}}function rb(t,e,n=void 0,r){return{hook:t,root:e,markDirty:n,devStrictMode:r,cells:[],effectCells:[],insertionCells:null,hostCells:null,contextDeps:null,wipContextDeps:null,wipCommitCallbacks:null,memoCache:{current:null,workInProgress:null,refreshedIndices:null,index:0},renderPendingCells:null,currentIndex:0,isRefreshing:!1,isFirstRender:!0,isMounted:!1,isReleased:!1,isNeverMounted:!0}}function Gd(t){t.wipCommitCallbacks=null,t.wipContextDeps=null,t.memoCache.workInProgress=null,t.memoCache.refreshedIndices=null}function Nn(t,e,n){try{e?(t.isReleased=!0,t.insertionCells!==null&&Wl(t.insertionCells)):t.isMounted&&(t.isMounted=!1,Wl(t.effectCells))}catch(r){(n??=[]).push(r)}if(t.hostCells!==null){for(const r of t.hostCells)if(r.fiber!==null&&(n=Nn(r.fiber,e,n)),r.fibers!==null)for(const{fiber:s}of r.fibers.values())n=Nn(s,e,n)}return n}function ya(t,e=!0){let n;e&&(n=Nn(t,!0,n)),n=Nn(t,!1,n),n!==void 0&&bn(n,"Errors during cleanup")}function Kd(t){let e;for(const n of t)n.isReleased&&(e=Nn(n,!0,e));for(const n of t)e=Nn(n,!1,e);e!==void 0&&bn(e,"Errors during cleanup")}function dr(t,e){if(t.renderPendingCells!==null){for(const i of t.renderPendingCells)i.renderQueue=null;t.renderPendingCells.clear()}let n=0,r;const s=t.isRefreshing;t.isRefreshing=s||(lt()?.isRefreshing??!1);try{do{if(++n>25)throw new Error("Too many re-renders. tap limits the number of renders to prevent an infinite loop.");t.memoCache.index=0,by(t,()=>{r=nb(()=>t.hook(...e))})}while((t.renderPendingCells?.size??0)>0)}catch(i){throw Gd(t),i}finally{t.isRefreshing=s}return Dd(t),r}function ms(t){const e=t.wipCommitCallbacks;t.wipCommitCallbacks=null;const n=Ue&&!t.isMounted&&t.devStrictMode==="root";t.isMounted=!0,t.isNeverMounted=!1,e!==null&&(t.contextDeps=t.wipContextDeps,Cd(t.root),t.memoCache.workInProgress!==null&&(t.memoCache.current=t.memoCache.workInProgress,t.memoCache.workInProgress=null,t.memoCache.refreshedIndices=null),Xy(e)),n&&(Hl(t,e!==null),ya(t,!1),t.isMounted=!0),Hl(t,!n&&e!==null)}const sb=()=>{const t=Ke();return t.devStrictMode?t.isFirstRender?"child":"root":null},ib=()=>null,ob=()=>{if(!Ue)return ib;const t=X(0);ie(()=>t.current++);const e=t.current===2,n=X(!1),r=X(!0);return r.current=!0,Q(()=>{et.version?.startsWith("18.")&&(r.current||(n.current=!0),r.current=!1)},[]),()=>e||n.current?"child":null},ab=()=>lt()?sb:ob(),lb=t=>{const e=Ke(),n=e.currentIndex++,r=e.cells[n];let s;if(r===void 0){e.isFirstRender||Rr();const i=t instanceof Map;s={type:"host",fiber:i?null:t,fibers:i?t:null},e.cells[n]=s,(e.hostCells??=[]).push(s)}else r.type!=="host"&&Mr(),s=r;return s.fibers===null&&s.fiber!==t&&Ar(e,()=>{s.fiber=t}),s},Kl=(t,e)=>{if(!(t instanceof Map))return e(t);for(const{fiber:n}of t.values())e(n)},cb=t=>{t.isReleased=!1},ub=t=>{t.isReleased=!0,t.isMounted||queueMicrotask(()=>{t.isReleased&&ya(t,!0)})},db=t=>{ct(()=>(Kl(t,cb),()=>Kl(t,ub)),[t]),Q(()=>()=>{Kd(t instanceof Map?Array.from(t.values(),({fiber:e})=>e):[t])},[t])},ba=t=>lt()?lb(t):(db(t),null),hb=()=>{const t=X(0),e=t.current,n=Ke();return{version:e,markDirty:ye(()=>()=>{t.current++,n.markDirty?.()},[n]),root:n.root}},fb=()=>{const[t]=ie(()=>_y((s,i)=>{let o=!1;r(a=>(o=!s(),o?a:a+1)),o||n(()=>s()&&i())})),[e,n]=By((s,i)=>(Bl(t,s),s+(i()?1:0)),0),[,r]=ie(0);return Bl(t,e),{root:t,version:e,markDirty:void 0}},_a=()=>{const t=ab(),e=lt()===null,n=e?t():null,{root:r,version:s,markDirty:i}=e?fb():hb();return{version:s,createFiber:mt((o,a,l)=>rb(o,r,l?()=>{l(),i?.()}:i,e?n:t()),[])}};function ce(t){return(...e)=>({hook:t,args:e})}function Re(t,e,n){return typeof e=="function"?(...r)=>Re(t,e(...r)):n?{...e,key:t,deps:n}:{...e,key:t}}const pb=(t,e)=>({fiber:t,key:e,currentDeps:null,current:null,wipDeps:null,wip:null});function ze(t){const{version:e,createFiber:n}=_a(),r=X(null),s=r.current??=pb(n(t.hook,t.key),t.key),i=ye(()=>s.fiber.hook===t.hook&&s.key===t.key&&!s.fiber.isReleased?s.fiber:n(t.hook,t.key),[s,t.hook,t.key,n]);s.wipDeps=s.currentDeps,s.wip=s.current;const o=[i,e,t.args];(lt()?.isRefreshing||ha(i)||s.currentDeps===null||!Pr(s.currentDeps,o))&&(s.wipDeps=o,s.wip={value:dr(i,t.args)});const a=s.wip,l=ba(i);return Q(()=>{if(s.currentDeps=s.wipDeps,s.current=s.wip,s.fiber=i,s.key=t.key,ms(i),l!==null)return()=>{l.fiber!==i&&ya(i,!0)}},[s,l,i,t.key,a]),a.value}const mb=(t,e,n)=>{const r=X(null),s=r.current??(r.current={currentDeps:null,current:null}),i=!n&&s.currentDeps&&Pr(s.currentDeps,e)?s.current:t();return Q(()=>{s.currentDeps=e,s.current=i}),i},Ql=(t,e)=>{const n=t.get(e);n&&(n.isDirty=!0)},gb=(t,e)=>!t.isDirty&&!ha(t.fiber)&&(t.committedElement===e||e.deps!==void 0&&t.committedDeps!==void 0&&Pr(t.committedDeps,e.deps)),yb=t=>{if(!Od())return!1;for(const{fiber:e}of t.values())if(ha(e))return!0;return!1};function va(t){const[e]=ie(()=>new Map),{version:n,createFiber:r}=_a(),s=lt()?.isRefreshing??!1,i=yb(e);let o=!1;const a=mb(()=>{const l=new Set,c=[];let u=0;for(let d=0;d<t.length;d++){const f=t[d],h=f.key;if(h===void 0)throw new Error(`useResources did not provide a key for array at index ${d}`);if(l.has(h))throw new Error(`Duplicate key ${h} in useResources`);l.add(h);let p=e.get(h);if(p)if(p.fiber.hook!==f.hook){const m=r(f.hook,f.key,()=>Ql(e,h)),y=dr(m,f.args);p.next={value:y,deps:f.deps,element:f,remount:m},o=!0}else if(!s&&gb(p,f))typeof p.next=="object"&&Gd(p.fiber),p.fiber.contextDeps&&Dd(p.fiber,p.fiber.contextDeps),p.next="skip";else{const m=dr(p.fiber,f.args);p.next={value:m,deps:f.deps,element:f}}else{const m=r(f.hook,f.key,()=>Ql(e,h));p={fiber:m,next:{value:dr(m,f.args),deps:f.deps,element:f},isDirty:!1,committedDeps:void 0,committedElement:void 0,committedValue:void 0},u++,e.set(h,p)}c.push(typeof p.next=="object"?p.next.value:p.committedValue)}if(e.size>c.length-u)for(const d of e.keys())l.has(d)||(e.get(d).next="delete",o=!0);return c},[t,e,r,n],s||i);return ba(e),Q(()=>{if(o){const l=[];for(const[c,u]of e.entries()){const d=u.next;d==="delete"?(l.push(u.fiber),e.delete(c)):d!=="skip"&&d.remount&&(l.push(u.fiber),u.fiber=d.remount)}for(const c of l)c.isReleased=!0;Kd(l)}for(const l of e.values()){const c=l.next;c==="skip"?!l.fiber.isNeverMounted&&!l.fiber.isMounted&&ms(l.fiber):c!=="delete"&&(ms(l.fiber),l.committedDeps=c.deps,l.committedElement=c.element,l.committedValue=c.value,l.isDirty=!1,l.next="skip")}},[a,e,o]),s?a.slice():a}const bb=t=>t(),_b=t=>{const{createFiber:e}=_a(),[n]=ie(()=>e(bb,void 0)),r=dr(n,[t]);ba(n);let s=!1;const i=()=>{s&&n.isMounted||(s=!0,ms(n))};return Q(i),{value:r,effects:i}},Yl=()=>()=>{},vb="You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.";var wb=class extends wr{#e;#t;#n;#r;constructor(t,e,n){super(),this.#e=t,this.#t=e,this.#n=n}get(t,e){if(e==="subscribe"||e==="on")return Yl;if(e==="optional")return this.#r??=Td(this.#n());const n=dn(e,this.#e);return n!==!1?n:Sd(this.#t(String(e)),String(e))}ownKeys(){return["subscribe","on","optional"]}getOwnPropertyDescriptor(t,e){if(e!=="optional")return super.getOwnPropertyDescriptor(t,e);const n=this.get(t,e);if(n!==void 0)return{value:n,writable:!1,enumerable:!1,configurable:!0}}has(t,e){return e==="subscribe"||e==="on"||e==="optional"}};const xb=(t,e)=>{const n=new Proxy({},new wb(t,e,()=>n));return n},Pn=xb("DefaultAssistantClient",()=>vb),Sb=()=>new Proxy({},{get(t,e){const n=dn(e,"AssistantClient");return n!==!1?n:Sd(`The current scope does not have a "${String(e)}" property.`,String(e))}}),wa=ke(Pn),Tb=()=>{},Cb=new WeakMap,Ib=t=>Cb.get(t)??Tb,xa=()=>Fe(wa),kb=(t,e)=>zs(wa,t,e),ao=Symbol("assistant-ui.transform-scopes");function Qd(t,e){const n=t;if(n[ao])throw new Error("transformScopes is already attached to this resource");n[ao]=e}function Eb(t){return t[ao]}const Sa=t=>typeof t=="string"?{scope:t.split(".")[0],event:t}:{scope:t.scope,event:t.event},Ab=et,Rb=t=>H.useMemo(()=>{const e=io(t);return e[qd]=!0,e},[]),Mb=Ab.__COMPILER_RUNTIME?.c??Rb,Pb=()=>lt()!==null,R=t=>Pb()?Hd(t):Mb(t),lo=Symbol("assistant-ui.store.clientIndex"),Db=t=>t[lo],Yd=ke([]),Us=()=>Hn(Yd),Ob=(t,e)=>{const n=R(3),r=Us();let s;return n[0]!==t||n[1]!==r?(s=[...r,t],n[0]=t,n[1]=r,n[2]=s):s=n[2],zs(Yd,s,e)},Dr=ke(null),Jl=Symbol("aui.scope-effect-unapplied"),Lb=(t,e)=>zs(Dr,t,e),Ta=()=>{const t=Hn(Dr);if(!t)throw new Error("AssistantTapContext is not available");return t},Jd=()=>Ta().clientRef,Fb=()=>Hn(Dr)?.invalidate,$b=()=>Hn(Dr)!==null,Nb=()=>{const t=R(5),e=Hn(Dr)?.markChanged;let n;t[0]!==e?(n=e?{readers:new Set,version:0}:void 0,t[0]=e,t[1]=n):n=t[1];const r=n;let s;return t[2]!==e||t[3]!==r?(s={signal:r,markChanged:e},t[2]=e,t[3]=r,t[4]=s):s=t[4],s},Bb=(t,e,n,r)=>{const s=R(8);let i;s[0]!==t||s[1]!==n||s[2]!==e?(i=()=>{if(t===void 0)return;const a=t.current;if(a===null)throw new Error("useAssistantScopeEffect ran before the client was committed. This is likely an internal bug in assistant-ui.");const l=()=>{const h=t.current?.[e];return h!==void 0&&Bs(h)?gy(h):void 0};let c=Jl,u;const d=h=>{if(u?.(),u=void 0,c=Jl,h!==void 0){const p=n();u=typeof p=="function"?p:void 0}c=h};d(l());const f=a.subscribe(()=>{const h=l();h!==c&&d(h)});return()=>{f(),u?.()}},s[0]=t,s[1]=n,s[2]=e,s[3]=i):i=s[3];let o;s[4]!==t||s[5]!==r||s[6]!==e?(o=[t,e,...r],s[4]=t,s[5]=r,s[6]=e,s[7]=o):o=s[7],Q(i,o)},Xd=(t,e,n)=>{const{clientRef:r}=Ta();Bb(r,t,e,n)},Wn=()=>{const t=R(3),{emit:e}=Ta(),n=Us();let r;return t[0]!==n||t[1]!==e?(r=(s,i)=>{e(s,i,n)},t[0]=n,t[1]=e,t[2]=r):r=t[2],nt(r)},Zd=[];let Dn=-1,Ye=null;const pn=t=>{Ye&&(t?Ye.signals.includes(t)||(Ye.signals.push(t),Ye.versions.push(t.version)):Ye.untracked=!0)},jb=t=>{Dn++;const e=Zd[Dn]??={signals:[],versions:[],untracked:!1};e.signals.length=0,e.versions.length=0,e.untracked=!1;const n=Ye;Ye=e;try{return{value:t(),signals:[...e.signals],untracked:e.untracked}}finally{Ye=n,Dn--,n&&(n.untracked||=e.untracked,e.signals.forEach(pn))}},eh=(t,e)=>t.length===e.length&&t.every(n=>e.includes(n)),zb=(t,e)=>{Dn++;const n=Zd[Dn]??={signals:[],versions:[],untracked:!1};n.signals.length=0,n.versions.length=0,n.untracked=!1;const r=Ye;Ye=n;try{const s=t(),i=e.current;if(n.untracked||n.signals.length===0)e.current=null;else if(i&&eh(i.signals,n.signals))for(let o=0;o<i.signals.length;o++)i.versions[o]=i.signals[o].version;else e.current={signals:[...n.signals],versions:[...n.versions]};return s}finally{Ye=r,Dn--,r&&(r.untracked||=n.untracked,n.signals.forEach(pn))}},th=(t,e)=>{const n=X(null),r=X(null),s=$b(),i=ye(()=>a=>{let l,c,u=!1;const d=()=>{const p=n.current,m=p?.signals??null;if(l!==void 0&&(l===null||m===null?l===m:eh(l,m)))return!1;let y=!1;if(l)for(const g of l)m?.includes(g)||g.readers.delete(f);return p===null?c??=t(f):(c?.(),c=void 0,p.signals.forEach((g,b)=>{l?.includes(g)||(y||=g.version!==p.versions[b],g.readers.add(f))})),l=m&&[...m],y};function f(){u||(a(),d())}d();const h=()=>{d()&&a()};return r.current=h,()=>{if(u=!0,c?.(),l)for(const p of l)p.readers.delete(f);r.current===h&&(r.current=null)}},[t]),o=yn(i,s?e:()=>zb(e,n),e);return Q(()=>{r.current?.()}),o},gs=Symbol("assistant-ui.store.getValue"),ys=Symbol("assistant-ui.store.signal"),nh=t=>t[ys],Vb=t=>{const e=Us().at(-1),n=e&&nh(e),r=Fb();Q(()=>{if(!(!n||!r||!t))return t(()=>r(n))},[t,n,r])},Xl=t=>{const e=t[gs];if(!e)throw new Error("Client scope contains a non-client resource. Ensure your Derived get() returns a client created with useClientResource(), not a plain resource.");return pn(nh(t)),e.getState?.()},Zl=new Map;function Ub(t){let e=Zl.get(t);return e||(e=function(...n){if(!this||typeof this!="object")throw new Error(`Method "${String(t)}" called without proper context. This may indicate the function was called incorrectly.`);const r=this[gs];if(!r)throw new Error(`Method "${String(t)}" called on invalid client proxy. Ensure you are calling this method on a valid client instance.`);const s=r[t];if(!s)throw new Error(`Method "${String(t)}" is not implemented.`);if(typeof s!="function")throw new Error(`"${String(t)}" is not a function.`);return pn(this[ys]),s(...n)},Zl.set(t,e)),e}var qb=class extends wr{boundFns;cachedReceiver;outputRef;tagRef;index;signal;self;constructor(t,e,n,r){super(),this.outputRef=t,this.tagRef=e,this.index=n,this.signal=r}get(t,e,n){if(e===gs)return this.outputRef.current;if(e===ys)return this.signal;if(e===lo)return this.index;if(e===hn)return this.self;if(e===to)return this.tagRef.current;const r=dn(e,"ClientProxy");if(r!==!1)return r;const s=this.outputRef.current[e];if(typeof s=="function"){if(n===void 0)return s;(!this.boundFns||this.cachedReceiver!==n)&&(this.boundFns=new Map,this.cachedReceiver=n);let i=this.boundFns.get(e);return i||(i=Ub(e).bind(n),this.boundFns.set(e,i)),i}return s}ownKeys(){return Object.keys(this.outputRef.current)}has(t,e){return e===gs||e===ys||e===lo||e===hn||e===to?!0:e in this.outputRef.current}};const Bn=t=>{const e=X(null),n=X(null),r=ye(()=>({}),[t.hook,t.key]),s=Us().length,{signal:i,markChanged:o}=Nb(),a=ye(()=>{const c=new qb(e,n,s,i),u=new Proxy({},c);return c.self=u,u},[s,i]),l=Ob(a,function(){return ze(t)});return e.current||(e.current=l,n.current=r),Q(()=>{const c=e.current!==l||n.current!==r;e.current=l,n.current=r,c&&i&&o(i)}),{methods:a,state:l.getState?.(),key:t.key}},rh=ce(Bn);let bs=0,co=0;const ec=t=>{bs++,co++;try{return t()}finally{co--,bs++}},Hb=t=>{let e;const n=new Map;let r=-1;const s=a=>{if(co===0)return Xl(t[a]());if(r!==bs)n.clear(),r=bs;else{const d=n.get(a);if(d)return d.signals.forEach(pn),d.untracked&&pn(void 0),d.state}const{value:l,signals:c,untracked:u}=jb(()=>Xl(t[a]()));return n.set(a,{state:l,signals:c,untracked:u}),l};class i extends wr{get(l,c){const u=dn(c,"OptionalAssistantState");if(u!==!1)return u;const d=c;if(!rn(d)&&Bs(t[d]))return s(d)}ownKeys(){return ro(t)}has(l,c){return!rn(c)&&c in t}}class o extends wr{get(l,c){const u=dn(c,"AssistantState");if(u!==!1)return u;if(c==="optional")return e??=new Proxy({},new i);const d=c;if(!rn(d))return s(d)}ownKeys(){return[...ro(t),"optional"]}has(l,c){return c==="optional"||!rn(c)&&c in t}}return new Proxy({},new o)},tc=new WeakMap,Wb=t=>{let e=tc.get(t);return e||(e=Hb(t),tc.set(t,e)),e},uo=ke(void 0),Gb=(t,e)=>{const n=Hn(uo);return zs(uo,t??n,e)},zt=(t,e)=>{if(Array.isArray(t)!==Array.isArray(e))return!1;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!Object.is(t[r],e[r]))return!1;return!0}const n=Object.keys(t);return n.length===Object.keys(e).length&&n.every(r=>Object.hasOwn(e,r)&&Object.is(t[r],e[r]))},sh=Symbol("assistant-ui.derived-hook"),Kb=t=>{t[sh]=!0},Qb=t=>t[sh]===!0,di=t=>{try{t()}catch(e){console.error("NotificationManager: subscriber callback error",e)}},nc=t=>{console.error("NotificationManager: event listener error",t)},rc=(t,e,n)=>{try{const r=t(e,n);r!==null&&(typeof r=="object"||typeof r=="function")&&typeof r.then=="function"&&Promise.resolve(r).catch(nc)}catch(r){nc(r)}},Yb=()=>{const t=new Map,e=new Set,n=new Set,r=new Set;return{on(s,i){const o=i;if(s==="*")return e.add(o),()=>e.delete(o);let a=t.get(s);return a||(a=new Set,t.set(s,a)),a.add(o),()=>{a.delete(o),a.size===0&&t.get(s)===a&&t.delete(s)}},emit(s,i,o){!t.has(s)&&e.size===0||queueMicrotask(()=>{const a=t.get(s);if(a)for(const l of a)rc(l,i,o);if(e.size>0){const l={event:s,payload:i};for(const c of e)rc(c,l,o)}})},subscribe(s){return n.add(s),()=>n.delete(s)},markChanged(s){s.version++,r.add(s)},invalidate(s){s.version++,ec(()=>{for(const i of[...s.readers])di(i)})},notifySubscribers(){ec(()=>{for(const i of n)di(i);if(r.size===0)return;const s=new Set;for(const i of r)for(const o of i.readers)s.add(o);r.clear();for(const i of s)di(i)})}}},Jb=()=>ie(Yb)[0],Xb=()=>{const[t]=ie(()=>({controller:new AbortController,generation:0}));return ct(()=>{const e=++t.generation;return()=>queueMicrotask(()=>{t.generation===e&&t.controller.abort()})},[t]),t.controller.signal},ho=t=>{const e=ye(()=>({}),[]);return e.v!==void 0&&zt(e.v,t)?e.v:(e.v=t,t)},it=t=>{const e=R(2),n=X(void 0);let r;return e[0]!==t?(r=s=>{const i=t(s);return n.current!==void 0&&zt(n.current,i)?n.current:(n.current=i,i)},e[0]=t,e[1]=r):r=e[1],r},ih=(()=>{try{return!1}catch{return!1}})(),Zb=(t,e)=>{const n={...t},r=new Set;let s=!0;for(;s;){s=!1;for(const i of Object.values(n)){if(r.has(i.hook))continue;r.add(i.hook);const o=Eb(i.hook);if(o){o(n,e),s=!0;break}}}return n},qs=t=>Qb(t.hook),e_=t=>{if(!qs(t))return{source:"root",query:{}};const e=t.args[0];return{source:e.source,query:e.query??{}}},fo=Symbol.for("aui.event-receiver-ref"),oh=(t,e)=>{const n=t===Pn?Sb():t,r=Object.create(n);Object.assign(r,e);let s;return Object.defineProperty(r,"optional",{get:()=>s??=Td(r),enumerable:!1}),r},t_=({notifications:t,clientRef:e})=>ye(()=>({subscribe:t.subscribe,on:function(n,r){if(!this)throw new Error("const { on } = useAui() is not supported. Use aui.on() instead.");const{scope:s,event:i}=Sa(n),o=n[fo];if(s!=="*"&&!o&&no(this[s]))throw new Error(`Scope "${s}" is not available. Use { scope: "*", event: "${i}" } to listen globally.`);const a=t.on(i,(c,u)=>{if(s==="*")return r(c);const d=((o??e).current??this)[s];if(!Bs(d))return;const f=ca(d);if(f===u[Db(f)])return r(c)});if(s!=="*"){if(o){if(e.parent===Pn)return a}else if(no(e.parent[s]))return a}const l=e.parent.on(n,r);return()=>{a(),l()}}}),[t,e]),ah=t=>{const e=R(5);let n;e[0]!==t?(n=e_(t),e[0]=t,e[1]=n):n=e[1];const{source:r,query:s}=n,i=ho(s);let o;return e[2]!==r||e[3]!==i?(o={source:r,query:i},e[2]=r,e[3]=i,e[4]=o):o=e[4],ho(o)},lh=t=>my(t)?()=>(pn(void 0),t):()=>t,n_=(t,e)=>{const n=R(3);let r;return n[0]!==e||n[1]!==t?(r=e?t:rh(t),n[0]=e,n[1]=t,n[2]=r):r=n[2],ze(r)},r_=(t,e)=>{const n=xa(),r=qs(e),s=n_(e,r),i=r?s:s.methods,o=ah(e),a=ye(()=>xd({name:t,...o},lh(i)),[t,o,i]);return n[t]=a,a},s_=ce(r_),i_=t=>{const e=R(2);let n;return e[0]!==t?(n=t.map(f_),e[0]=t,e[1]=n):n=e[1],va(n)},ch=(t,e)=>{const n=ho(e),r=ye(()=>({}),[]);return r.deps!==n&&(r.deps=n,r.client=t),r.client},o_=({parent:t,entries:e,clientRef:n,notifications:r})=>{const s=t_({notifications:r,clientRef:n}),i=oh(t,s),o=ye(()=>({clientRef:n,emit:r.emit,markChanged:r.markChanged,invalidate:r.invalidate}),[n,r.emit,r.markChanged,r.invalidate]),a=Lb(o,function(){return kb(i,function(){return i_(e)})});return{client:ch(i,[t,...a])}},a_=({parent:t,entries:e,destroySignal:n})=>{const r=X({parent:t,current:null}).current,{value:s,effects:i}=_b(function(){const a=Jb(),{client:l}=Gb(n,function(){return o_({parent:t,entries:e,clientRef:r,notifications:a})});return Q(()=>t.subscribe(a.notifySubscribers),[t,a]),Q(()=>a.notifySubscribers()),l});return ct(()=>{r.parent=t,r.current=s},[s,t,r]),{client:s,effects:i}},l_=(t,e,n,r)=>{const{get:s}=r.args[0],i=th(t.subscribe,()=>s(t)),o=ah(r),a=ye(()=>xd({name:n,...o},lh(i)),[n,o,i]);return e[n]=a,a},c_=(t,e)=>{if(ih){const[a]=ie(()=>e.map(([u])=>u).join(",")),l=e.find(([,u])=>!qs(u));if(l)throw new Error(`Scope "${l[0]}" is a root scope but this useAui mounted derived-only; remount with a new key to change scope kinds.`);const c=e.map(([u])=>u).join(",");if(c!==a)throw new Error(`A derived-only config mounted scopes [${a}] but now has [${c}]; remount with a new key to change the scope set.`)}const n=X({parent:t,current:null}).current,r=function(a,l){if(!this)throw new Error("const { on } = useAui() is not supported. Use aui.on() instead.");const{scope:c,event:u}=Sa(a);if(c==="*")return t.on(a,l);const d=a[fo];if(!d&&no(this[c]))throw new Error(`Scope "${c}" is not available. Use { scope: "*", event: "${u}" } to listen globally.`);return t.on({scope:c,event:u,[fo]:d??n},l)},s=oh(t,{subscribe:t.subscribe,on:r}),i=e.map(([a,l])=>l_(t,s,a,l)),o=ch(s,[t,...i]);return ct(()=>{n.parent=t,n.current=o},[o,t,n]),o},u_=(t,e)=>{const n=R(8);let r;n[0]!==e||n[1]!==t?(r=Object.entries(Zb(e,t)),n[0]=e,n[1]=t,n[2]=r):r=n[2];const s=r;let i;n[3]!==s?(i=()=>s.length===0||s.some(p_),n[3]=s,n[4]=i):i=n[4];const[o]=ie(i);let a;return n[5]!==s||n[6]!==o?(a={entries:s,rooted:o},n[5]=s,n[6]=o,n[7]=a):a=n[7],a},d_=(t,e,n,r)=>{const{entries:s,rooted:i}=u_(t,e);return i?n({parent:t,entries:s,destroySignal:r}):{client:c_(t,s)}},h_=(t,e,n)=>d_(t,e,a_,n);function Z(t){return xa()}function f_(t){const[e,n]=t;return Re(e,s_(e,n))}function p_(t){const[,e]=t;return!qs(e)}const N=t=>{const e=R(5),n=Z();let r;e[0]!==n?(r=Wb(n),e[0]=n,e[1]=r):r=e[1];const s=r;let i;e[2]!==s||e[3]!==t?(i=()=>t(s),e[2]=s,e[3]=t,e[4]=i):i=e[4];const o=th(n.subscribe,i);if(typeof o=="object"&&o!==null&&(o===s||o===s.optional))throw new Error("You tried to return the entire AssistantState. This is not supported due to technical limitations.");return jy(o),o},uh=t=>{const e=R(3),{get:n}=t,r=Z();let s;return e[0]!==r||e[1]!==n?(s=()=>n(r),e[0]=r,e[1]=n,e[2]=s):s=e[2],N(s)};Kb(uh);const Ve=ce(uh),dh=t=>{if(t.key===void 0)throw new Error("useClientLookup: Element has no key");return t.key};function _t(t){const e=R(12);let n;e[0]!==t?(n=t.map(y_),e[0]=t,e[1]=n):n=e[1];const r=va(n);let s;e[2]!==t?(s=t.reduce(g_,Object.create(null)),e[2]=t,e[3]=s):s=e[3];const i=s;let o;e[4]!==r?(o=r.map(m_),e[4]=r,e[5]=o):o=e[5];const a=o;let l;e[6]!==i||e[7]!==r?(l=u=>{if("index"in u){if(u.index<0||u.index>=r.length)throw new Error(`useClientLookup: index ${u.index} out of bounds (length: ${r.length}) (ignore if recovered)`);return r[u.index].methods}const d=i[u.key];if(d===void 0)throw new Error(`useClientLookup: key "${u.key}" not found (ignore if recovered)`);return r[d].methods},e[6]=i,e[7]=r,e[8]=l):l=e[8];let c;return e[9]!==a||e[10]!==l?(c={state:a,get:l},e[9]=a,e[10]=l,e[11]=c):c=e[11],c}function m_(t){return t.state}function g_(t,e,n){return t[dh(e)]=n,t}function y_(t){return Re(dh(t),rh(t),t.deps)}const b_=(t,e=0)=>e===0?Math.abs(t.scrollHeight-t.scrollTop-t.clientHeight)<=1||t.scrollHeight<=t.clientHeight:t.scrollHeight-e-t.scrollTop-t.clientHeight<=1||t.scrollHeight-e<=t.clientHeight,__=(t,e=0)=>e===0?t.scrollHeight>t.clientHeight+1:t.scrollHeight-e>t.clientHeight+1,sc=t=>t.nodeType===Node.ELEMENT_NODE,v_=(t,e)=>{const n=[],r=typeof ResizeObserver<"u"?new ResizeObserver(()=>e()):null;if(r){r.observe(t);for(const s of t.children)r.observe(s);n.push(()=>r.disconnect())}if(typeof MutationObserver<"u"){const s=new MutationObserver(i=>{if(r){for(const o of i)if(o.target===t){for(const a of o.addedNodes)sc(a)&&r.observe(a);for(const a of o.removedNodes)sc(a)&&r.unobserve(a)}}i.some(o=>o.type!=="attributes"||o.attributeName!=="style")&&e()});s.observe(t,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),n.push(()=>s.disconnect())}return()=>{for(const s of n)s()}},Hs="[data-message-id]",w_="[aria-expanded], summary",hi=["textarea","select","[contenteditable]:not([contenteditable='false'])","input:not([type='checkbox']):not([type='radio']):not([type='button']):not([type='submit']):not([type='reset']):not([type='image']):not([type='range']):not([type='file']):not([type='color'])"].join(", "),ic=new Set([" ","ArrowUp","ArrowDown","PageUp","PageDown","Home","End"]),x_=new Set(["ArrowUp","PageUp","Home"]),S_=t=>{const e=t.closest(w_);if(!e)return!1;if(e.tagName==="SUMMARY")return e.parentElement?.hasAttribute("open")===!1;const n=e.getAttribute("aria-haspopup");return e.getAttribute("aria-expanded")==="false"&&(n===null||n==="false")&&e.getAttribute("role")!=="combobox"},T_=t=>x_.has(t.key)||t.key===" "&&t.shiftKey,hh=(t,e)=>t.getBoundingClientRect().top-e.getBoundingClientRect().top,C_=t=>{const e=t.querySelector(Hs),n=e?.dataset.messageId;return e&&n?{id:n,offset:hh(e,t)}:null},I_=t=>{const{top:e,bottom:n}=t.getBoundingClientRect();let r=null;for(const s of t.querySelectorAll(Hs)){const i=s.getBoundingClientRect();if(i.bottom<=e)continue;if(i.top>=n)break;const o=s.dataset.messageId;if(o){if(i.top>=e)return{id:o,offset:i.top-e};r??={id:o,offset:i.top-e}}}return r},k_=(t,e)=>{for(const n of t.querySelectorAll(Hs))if(n.dataset.messageId===e)return n;return null},E_=t=>{let e=null,n=null,r=null,s=!0,i=!0,o=!1,a=!1,l=!1,c=null,u=null,d=0,f=0;const h=new Map;let p=!1,m=!1,y=0,g=0,b=0,v=0,w=null,k=null,_=null,A=0;const E=O=>{if(!e)return!1;const G=k_(e,O.id);if(!G)return!1;const se=hh(G,e)-O.offset;return A=e.scrollTop+se,Math.abs(se)>=1&&e.scrollTo({top:A,behavior:"instant"}),A=e.scrollTop,!0},D=O=>{O!==s&&(s=O,t.onAtBottomChange(O))},x=()=>{w!==null&&(cancelAnimationFrame(w),w=null)},M=()=>{l=!1,c!==null&&(cancelAnimationFrame(c),c=null)},P=()=>{l=!0,c!==null&&cancelAnimationFrame(c),c=requestAnimationFrame(()=>{c=requestAnimationFrame(()=>{c=null,l=!1})})},T=(O="auto")=>{e&&(i=!0,o=!1,a=!1,M(),r=O,_=null,e.scrollTo?.({top:e.scrollHeight,behavior:O}),y=e.scrollTop,g=e.scrollHeight,L())},$=O=>{r=O,!(typeof requestAnimationFrame>"u")&&(x(),w=requestAnimationFrame(()=>{w=null,T(O)}))},L=({preserveFollow:O=!1,insetShrank:G=!1,userScroll:se=!1}={})=>{if(!e)return;_&&Math.abs(e.scrollTop-A)>=1&&(_=null);const{autoScroll:we,holdFollow:Zn}=t.getOptions(),xt=b_(e,d),Tn=e.clientHeight,He=Math.max(0,g-Tn),Qe=Math.min(y,He),Ft=e.scrollTop<Qe&&e.scrollHeight>=g,St=se&&e.scrollHeight>=g&&e.scrollTop<y&&e.scrollTop>He,Kt=Ft||St;!Zn&&!xt&&(!we||!O&&r===null&&!o&&(Kt||G))&&(i=!1),r!==null&&!xt&&y<e.scrollTop||(xt?(__(e,d)&&(r=null,o&&a&&(o=!1),a=!1),i=!0):Kt&&(r=null,x(),i=!1),(xt||r===null)&&D(xt)),y=e.scrollTop,g=e.scrollHeight,k=C_(e)},j=()=>L({userScroll:l}),V=()=>{if(w!==null)return;const{autoScroll:O,holdFollow:G}=t.getOptions();r&&G?r=null:r?T(r):!G&&O&&i&&!o?T("instant"):_&&!E(_)&&(_=null)},q=()=>{if(!e)return;for(const we of h.values())we.measure&&(we.height=we.measure());const O=te(),{scrollHeight:G,clientHeight:se}=e;if(G===b&&se===v){O!==null&&(O&&V(),L({insetShrank:!O}));return}b=G,v=se,O===!1&&L({insetShrank:!0}),V(),L({insetShrank:O===!1})},U=()=>{r===null&&w===null||(r=null,x(),L({preserveFollow:!0}))},S=O=>{O.key!=="Enter"&&!ic.has(O.key)||O.target?.closest?.(hi)||U()},J=O=>{const G=O.target;!G?.closest?.(Hs)||G.closest(hi)||!S_(G)||(o=!0,a=!1,r=null,x())},ee=O=>O.touches?.[0]?.clientY??null,I=O=>{for(let G=O instanceof Element?O:null;G&&G!==e;G=G.parentElement)if(G.scrollTop>0&&/^(auto|scroll)$/.test(getComputedStyle(G).overflowY))return!0;return!1},de=O=>{let G=!1;if(O.type==="keydown"){const se=O;if(!ic.has(se.key)||O.target?.closest?.(hi))return;G=T_(se)}else if(O.type==="pointerdown"){if(O.target!==e)return}else if(O.type==="wheel")G=O.deltaY<0;else if(O.type==="touchmove"){const se=ee(O);G=se!==null&&u!==null&&se>u,u=se}G&&!I(O.target)?P():M(),a=!0},W=O=>{u=ee(O)},K=()=>{_=null},le=()=>{if(!p){m=!1;return}!t.getOptions().scrollToBottomOnInitialize||m||(m=!0,r===null&&$("instant"))},te=()=>{let O=f;for(const se of h.values())O+=se.height;if(d===O)return null;const G=O>d;return d=O,t.onContentInsetChange?.(O),G},fe=()=>{const O=te();if(O===null)return;const G=e!==null&&(e.scrollHeight!==b||e.clientHeight!==v);!O&&G&&L({insetShrank:!0}),(O||G)&&V(),L({insetShrank:!O}),e&&(b=e.scrollHeight,v=e.clientHeight)};return{attach:O=>{n?.(),e=O,r=null,y=O.scrollTop,g=O.scrollHeight,b=0,v=0,m=!1,i=!0,o=!1,a=!1,M(),u=null,k=null,_=null,A=O.scrollTop,D(!0);const G=v_(O,q);O.addEventListener("scroll",j),O.addEventListener("pointerdown",U),O.addEventListener("wheel",U,{passive:!0}),O.addEventListener("touchstart",U,{passive:!0}),O.addEventListener("keydown",S),O.addEventListener("click",J,!0);for(const we of["pointerdown","wheel","touchmove","keydown"])O.addEventListener(we,de,{passive:!0});O.addEventListener("touchstart",W,{passive:!0});for(const we of["pointerdown","wheel","touchstart","keydown"])O.addEventListener(we,K,{passive:!0});le(),d>0&&V();const se=()=>{if(n===se){G(),O.removeEventListener("scroll",j),O.removeEventListener("pointerdown",U),O.removeEventListener("wheel",U),O.removeEventListener("touchstart",U),O.removeEventListener("keydown",S),O.removeEventListener("click",J,!0);for(const we of["pointerdown","wheel","touchmove","keydown"])O.removeEventListener(we,de);O.removeEventListener("touchstart",W);for(const we of["pointerdown","wheel","touchstart","keydown"])O.removeEventListener(we,K);x(),M(),e===O&&(e=null),n=null}};return n=se,se},get isAtBottom(){return s},scrollToBottom:T,messagesPrepended:O=>{if(!e||t.getOptions().autoScroll&&i&&!o||r!==null)return;const G=k;if(G?.id===O&&E(G))_=I_(e)??G;else{const se=e.scrollHeight-(g-y);Math.abs(e.scrollTop-se)>=1&&e.scrollTo({top:se,behavior:"instant"})}y=e.scrollTop,g=e.scrollHeight},setContentInset:O=>{f!==O&&(f=O,fe())},registerContentInset:O=>{const G=Symbol(),se={height:0,measure:O};return h.set(G,se),{setHeight:we=>{!h.has(G)||se.height===we||(se.height=we,fe())},unregister:()=>{h.delete(G)&&fe()}}},setHasMessages:O=>{p=O,le()},runStarted:()=>{_=null,o=!1,a=!1,t.getOptions().scrollToBottomOnRunStart&&$("auto")},threadSwitched:()=>{_=null,o=!1,a=!1,M(),t.getOptions().scrollToBottomOnThreadSwitch&&$("instant")},dispose:()=>{n?.(),x()}}},ot=Symbol("skip-update"),gt=(t,...e)=>{const n=[];for(const r of t)try{r(...e)}catch(s){n.push(s)}if(n.length===1)throw n[0];if(n.length>1){for(const r of n)console.error(r);throw new AggregateError(n)}},Gn=t=>{gt(t)},Ca=(t,e)=>{try{t()}catch(n){console.error("[assistant-ui] Subscription rollback cleanup threw",n)}throw e},fh=(t,e)=>t===void 0||e===void 0?t===e:zt(t,e);var Ia=class{_subscribers=new Set;subscribe(t){return this._subscribers.add(t),()=>this._subscribers.delete(t)}waitForUpdate(){return new Promise(t=>{const e=this.subscribe(()=>{e(),t()})})}_notifySubscribers(){gt(this._subscribers)}},Ws=class{_subscriptions=new Set;_connection;get isConnected(){return!!this._connection}notifySubscribers(t,e){if(e){tt(this._subscriptions,t,e);return}gt(this._subscriptions,t)}_updateConnection(){if(this._subscriptions.size>0){if(this._connection)return;this._connection=this._connect()}else{const t=this._connection;this._connection=void 0,t?.()}}subscribe(t){this._subscriptions.add(t);try{this._updateConnection()}catch(e){throw this._subscriptions.delete(t),e}return()=>{this._subscriptions.delete(t),this._updateConnection()}}},Xe=class extends Ws{get path(){return this.binding.path}binding;constructor(t){super(),this.binding=t;const e=t.getState();if(e===ot)throw new Error("Entry not available in the store");this._previousState=e}_previousState;getState=()=>(this.isConnected||this._syncState(),this._previousState);_syncState(){const t=this.binding.getState();return t===ot||fh(t,this._previousState)?!1:(this._previousState=t,!0)}_connect(){const t=()=>{this._syncState()&&this.notifySubscribers()},e=this.binding.subscribe(t);try{return this._syncState(),e}catch(n){throw Ca(e,n)}}},ka=class extends Ws{get path(){return this.binding.path}binding;constructor(t){super(),this.binding=t}_previousStateDirty=!0;_previousState;getState=()=>{if(!this.isConnected||this._previousStateDirty){const t=this.binding.getState();t!==ot&&(this._previousState===void 0||!fh(t,this._previousState))&&(this._previousState=t),this._previousStateDirty=!1}if(this._previousState===void 0)throw new Error("Entry not available in the store");return this._previousState};_connect(){const t=()=>{this._previousStateDirty=!0,this.notifySubscribers()},e=this.binding.subscribe(t);return this._previousStateDirty=!0,e}},_s=class extends Ws{get path(){return this.binding.path}binding;constructor(t){super(),this.binding=t}getState(){return this.binding.getState()}outerSubscribe(t){return this.binding.subscribe(t)}_connect(){const t=()=>{this.notifySubscribers()};let e=this.binding.getState(),n=e?.subscribe(t);const r=()=>{const i=this.binding.getState();if(i===e)return;e=i;const o=n;n=void 0;try{o?.()}finally{n=i?.subscribe(t),t()}};let s;try{s=this.outerSubscribe(r)}catch(i){throw Ca(()=>n?.(),i)}return()=>Gn([()=>s(),()=>n?.()])}},ph=class extends Ws{config;constructor(t){super(),this.config=t}getState(){return this.config.binding.getState()}outerSubscribe(t){return this.config.binding.subscribe(t)}_connect(){const t=`Runtime event "${this.config.event}"`,e=o=>{this.notifySubscribers(o,t)};let n=this.config.binding.getState(),r=n?.unstable_on(this.config.event,e);const s=()=>{const o=this.config.binding.getState();if(o===n)return;n=o;const a=r;r=void 0;try{a?.()}finally{r=o?.unstable_on(this.config.event,e),this.config.notifyOnRebind&&e({})}};let i;try{i=this.outerSubscribe(s)}catch(o){throw Ca(()=>r?.(),o)}return()=>Gn([()=>i(),()=>r?.()])}};const mh=`
|
|
7
|
+
|
|
8
|
+
`,A_=t=>t>=55296&&t<=56319,R_=(t,e)=>{let n="";for(const{system:r}of t){const s=n?mh:"",i=e-n.length-s.length,o=i<r.length&&A_(r.charCodeAt(i-1))?i-1:i;if(o<=0||(n+=s+r.slice(0,o),r.length>o))break}return n},M_=(t,e)=>{if(e.mergeSystem){if(e.maxSystemLength!==void 0)throw new Error("Pass either maxSystemLength or mergeSystem, not both. Apply the cap inside mergeSystem instead.");return e.mergeSystem(t)}return e.maxSystemLength!==void 0?R_(t,e.maxSystemLength):t.map(n=>n.system).join(mh)},fi=t=>{if(!t.overwrite)return t;const{overwrite:e,...n}=t;return n},P_=(t,e={})=>{const n=Array.from(t).map(a=>a.getModelContext()).sort((a,l)=>(l.priority??0)-(a.priority??0)),r=Ge(),s=[],i=n.reduce((a,l)=>{const c=l.priority??0;if(l.system&&s.push({system:l.system,priority:c}),l.tools)for(const[u,d]of Object.entries(l.tools)){const f=a.tools!==void 0&&Object.hasOwn(a.tools,u)?a.tools[u]:void 0;if(f&&f!==d){const h=r[u];if(h===c){if(!d.overwrite)throw new Error(`You tried to define a tool with the name ${u}, but it already exists.`);a.tools[u]=fi(d);continue}const p=h>c?f:d,m=h>c?d:f;a.tools[u]=fi({...m,...p}),r[u]=Math.max(h,c);continue}a.tools||(a.tools=Ge()),a.tools[u]=fi(d),Object.hasOwn(r,u)||(r[u]=c)}return l.config&&(a.config={...l.config,...a.config}),l.callSettings&&(a.callSettings={...l.callSettings,...a.callSettings}),l.unstable_composerMetadata&&(a.unstable_composerMetadata={...l.unstable_composerMetadata,...a.unstable_composerMetadata}),a},{}),o=M_(s,e);return o&&(i.system=o),i};var Ea=class{_providers=new Map;_providerUnsubscribes=new Map;_getMergeOptions;constructor(t=()=>({})){this._getMergeOptions=t}getModelContext(){return P_(new Set(this._providers.values()),this._getMergeOptions())}registerModelContextProvider(t){const e=Symbol();this._providers.set(e,t);let n;try{n=t.subscribe?.(()=>{this.notifySubscribers()})}catch(s){this._providers.delete(e);try{this.notifySubscribers()}catch(i){console.error(i)}throw s}this._providerUnsubscribes.set(e,n),this.notifySubscribers();let r=!1;return()=>{if(r)return;r=!0,this._providers.delete(e);const s=this._providerUnsubscribes.get(e);this._providerUnsubscribes.delete(e);let i=!1,o;const a=l=>{try{l()}catch(c){i?console.error(c):(i=!0,o=c)}};if(s&&a(s),a(()=>this.notifySubscribers()),i)throw o}}_subscribers=new Set;notifySubscribers(){gt(this._subscribers)}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}};const D_="application/octet-stream";function O_(t,e=D_){const n=t.match(/^data:([^;,]*)(?:;[^;,]+)*;base64,([\s\S]*)$/i);return n?{mimeType:n[1]?n[1].toLowerCase():e,data:n[2].replace(/%([\da-f]{2})/gi,(r,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/[\t\n\r ]/g,"")}:null}const jn={entries:32,payloadLength:16384,logLength:65536},L_=64,F_=t=>{const e=Object.getPrototypeOf(t);return e===Object.prototype||e===null},vs=(t,e,n)=>{if(t===null)return!0;switch(typeof t){case"string":case"boolean":return!0;case"number":return Number.isFinite(t);case"object":break;default:return!1}if(n>L_||e.has(t))return!1;e.add(t);const r=Array.isArray(t)?t.every(s=>vs(s,e,n+1)):F_(t)&&Object.values(t).every(s=>vs(s,e,n+1));return e.delete(t),r},ws=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),gh=t=>t==="action"||t==="human-response";function $_(t,e=Date.now()){const{type:n,payload:r}=t;if(!gh(n))throw new Error(`Unknown tool interaction type: ${String(n)}`);if(!vs(r,new Set,0))throw new Error("A tool interaction payload must be plain JSON.");if(n==="action"&&!ws(r))throw new Error("An action interaction payload must be a JSON object.");const s=JSON.stringify(r);if(s.length>jn.payloadLength)throw new Error(`A tool interaction payload is limited to ${jn.payloadLength} characters of JSON.`);return{type:n,occurredAt:e,payload:JSON.parse(s)}}function N_(t,e){const n=[...t?.entries??[],e];let r=t?.omitted??0;for(;n.length>1&&(n.length>jn.entries||JSON.stringify(n).length>jn.logLength);)n.shift(),r+=1;return r>0?{entries:n,omitted:r}:{entries:n}}const B_=t=>{if(!ws(t))return;const{type:e,occurredAt:n,payload:r}=t;if(gh(e)&&!(typeof n!="number"||!Number.isFinite(n))&&vs(r,new Set,0))return e==="action"?ws(r)?{type:e,occurredAt:n,payload:r}:void 0:{type:e,occurredAt:n,payload:r}};function yh(t){if(!ws(t))return;const{entries:e,omitted:n}=t,r=Array.isArray(e)?e.flatMap(i=>{const o=B_(i);return o?[o]:[]}):[];let s=typeof n=="number"&&Number.isInteger(n)&&n>0?n:0;for(;r.length>1&&(r.length>jn.entries||JSON.stringify(r).length>jn.logLength);)r.shift(),s+=1;if(!(r.length===0&&s===0))return s>0?{entries:r,omitted:s}:{entries:r}}const bh=(t,e)=>{const n={text:r=>typeof r.text=="string",reasoning:r=>typeof r.text=="string"||typeof r.unstable_summary=="string",image:r=>typeof r.image=="string",file:r=>typeof r.data=="string"&&typeof r.mimeType=="string",audio:r=>xe(r.audio)&&typeof r.audio.data=="string"&&typeof r.audio.format=="string",data:r=>typeof r.name=="string",source:r=>typeof r.id=="string"&&(r.sourceType==="url"?typeof r.url=="string":r.sourceType==="document"&&typeof r.title=="string"&&typeof r.mediaType=="string"),"generative-ui":r=>xe(r.spec),"tool-call":r=>typeof r.toolCallId=="string"&&typeof r.toolName=="string"&&xe(r.args)&&typeof r.argsText=="string",...t};return r=>xe(r)&&typeof r.type=="string"&&(Object.hasOwn(n,r.type)?n[r.type](r):e(r.type))},j_=bh({},()=>!0),Vr=t=>typeof t=="string",oc={file:{filename:Vr,sourceType:t=>t==="url"||t==="id"},image:{filename:Vr},source:{title:Vr,filename:Vr}},_h=t=>{const e=t,n=typeof e.type=="string"&&Object.hasOwn(oc,e.type)?oc[e.type]:{},r=Object.entries(n).filter(([i,o])=>e[i]!==void 0&&!o(e[i])).map(([i])=>i);if(r.length===0)return t;const s={...e};for(const i of r)delete s[i];return s};bh({reasoning:t=>(t.text===void 0||typeof t.text=="string")&&(t.unstable_summary===void 0||typeof t.unstable_summary=="string")&&(typeof t.text=="string"||typeof t.unstable_summary=="string"),"tool-call":t=>typeof t.toolCallId=="string"&&typeof t.toolName=="string"&&(t.args===void 0||xe(t.args))&&(t.argsText===void 0||typeof t.argsText=="string")&&(t.args!==void 0||t.argsText!==void 0)},t=>t.startsWith("data-"));function z_(){const t=this.getReader();let e=!1,n=Promise.resolve();const r=a=>{const l=n.then(a);return n=l.then(()=>{},()=>{}),l},s=async a=>{if(!e){e=!0;try{return t.cancel(a)}finally{t.releaseLock()}}},i={next:()=>r(async()=>{if(e)return{done:!0,value:void 0};try{const a=await t.read();return a.done&&(e=!0,t.releaseLock()),a}catch(a){throw e=!0,t.releaseLock(),a}}),return:a=>r(async()=>(await s(a),{done:!0,value:a})),throw:a=>r(async()=>{throw await s(void 0),a}),[Symbol.asyncIterator](){return this}},o=Symbol.asyncDispose;return o&&Object.defineProperty(i,o,{value:async()=>{await i.return()},writable:!0,configurable:!0}),i}function pi(t){return t[Symbol.asyncIterator]??=z_,t}const V_=/[0-9a-fA-F]/;function U_(t){const e=["ROOT"];let n=-1,r=null,s=0;const i=[];let o;function a(){o!==void 0&&(i.push(JSON.parse(`"${o}"`)),o=void 0)}function l(f,h,p){switch(f){case'"':n=h,e.pop(),e.push(p),e.push("INSIDE_STRING"),a();break;case"f":case"t":case"n":n=h,r=h,e.pop(),e.push(p),e.push("INSIDE_LITERAL");break;case"-":e.pop(),e.push(p),e.push("INSIDE_NUMBER"),a();break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":n=h,e.pop(),e.push(p),e.push("INSIDE_NUMBER"),a();break;case"{":n=h,e.pop(),e.push(p),e.push("INSIDE_OBJECT_START"),a();break;case"[":n=h,e.pop(),e.push(p),e.push("INSIDE_ARRAY_START"),a()}}function c(f,h){switch(f){case",":e.pop(),e.push("INSIDE_OBJECT_AFTER_COMMA");break;case"}":n=h,e.pop(),o=i.pop()}}function u(f,h){switch(f){case",":e.pop(),e.push("INSIDE_ARRAY_AFTER_COMMA"),o=(Number(o)+1).toString();break;case"]":n=h,e.pop(),o=i.pop()}}for(let f=0;f<t.length;f++){const h=t[f];switch(e[e.length-1]){case"ROOT":l(h,f,"FINISH");break;case"INSIDE_OBJECT_START":switch(h){case'"':e.pop(),e.push("INSIDE_OBJECT_KEY"),o="";break;case"}":n=f,e.pop(),o=i.pop()}break;case"INSIDE_OBJECT_AFTER_COMMA":switch(h){case'"':e.pop(),e.push("INSIDE_OBJECT_KEY"),o=""}break;case"INSIDE_OBJECT_KEY":switch(h){case'"':e.pop(),e.push("INSIDE_OBJECT_AFTER_KEY");break;case"\\":e.push("INSIDE_STRING_ESCAPE"),o+=h;break;default:o+=h}break;case"INSIDE_OBJECT_AFTER_KEY":switch(h){case":":e.pop(),e.push("INSIDE_OBJECT_BEFORE_VALUE")}break;case"INSIDE_OBJECT_BEFORE_VALUE":l(h,f,"INSIDE_OBJECT_AFTER_VALUE");break;case"INSIDE_OBJECT_AFTER_VALUE":c(h,f);break;case"INSIDE_STRING":switch(h){case'"':e.pop(),n=f,o=i.pop();break;case"\\":e.push("INSIDE_STRING_ESCAPE");break;default:n=f}break;case"INSIDE_ARRAY_START":switch(h){case"]":n=f,e.pop(),o=i.pop();break;default:o="0",l(h,f,"INSIDE_ARRAY_AFTER_VALUE")}break;case"INSIDE_ARRAY_AFTER_VALUE":switch(h){case",":e.pop(),e.push("INSIDE_ARRAY_AFTER_COMMA"),o=(Number(o)+1).toString();break;case"]":n=f,e.pop(),o=i.pop();break;default:n=f}break;case"INSIDE_ARRAY_AFTER_COMMA":l(h,f,"INSIDE_ARRAY_AFTER_VALUE");break;case"INSIDE_STRING_ESCAPE":{e.pop();const p=e[e.length-1];h==="u"?(e.push("INSIDE_STRING_UNICODE_ESCAPE"),s=0):p==="INSIDE_STRING"&&(n=f),p==="INSIDE_OBJECT_KEY"&&(o+=h);break}case"INSIDE_STRING_UNICODE_ESCAPE":{const p=e[e.length-2];if(!V_.test(h)){e.pop(),f--;break}s++,s===4&&(e.pop(),p==="INSIDE_STRING"&&(n=f)),p==="INSIDE_OBJECT_KEY"&&(o+=h);break}case"INSIDE_NUMBER":switch(h){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":n=f;break;case"e":case"E":case"-":case"+":case".":break;case",":e.pop(),o=i.pop(),e[e.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&u(h,f),e[e.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&c(h,f);break;case"}":e.pop(),o=i.pop(),e[e.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&c(h,f);break;case"]":e.pop(),o=i.pop(),e[e.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&u(h,f);break;default:e.pop(),o=i.pop()}break;case"INSIDE_LITERAL":{const p=t.substring(r,f+1);!"false".startsWith(p)&&!"true".startsWith(p)&&!"null".startsWith(p)?(e.pop(),e[e.length-1]==="INSIDE_OBJECT_AFTER_VALUE"?c(h,f):e[e.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&u(h,f)):n=f;break}}}let d=t.slice(0,n+1);for(let f=e.length-1;f>=0;f--)switch(e[f]){case"INSIDE_STRING":d+='"';break;case"INSIDE_OBJECT_KEY":case"INSIDE_OBJECT_AFTER_KEY":case"INSIDE_OBJECT_AFTER_COMMA":case"INSIDE_OBJECT_START":case"INSIDE_OBJECT_BEFORE_VALUE":case"INSIDE_OBJECT_AFTER_VALUE":d+="}";break;case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":d+="]";break;case"INSIDE_LITERAL":{const h=t.substring(r,t.length);"true".startsWith(h)?d+="true".slice(h.length):"false".startsWith(h)?d+="false".slice(h.length):"null".startsWith(h)&&(d+="null".slice(h.length))}}return[d,i]}var Jt={exports:{}},ac;function q_(){if(ac)return Jt.exports;ac=1;const t=typeof Buffer<"u",e=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,n=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;function r(a,l,c){c==null&&l!==null&&typeof l=="object"&&(c=l,l=void 0),t&&Buffer.isBuffer(a)&&(a=a.toString()),a&&a.charCodeAt(0)===65279&&(a=a.slice(1));const u=JSON.parse(a,l);if(u===null||typeof u!="object")return u;const d=c&&c.protoAction||"error",f=c&&c.constructorAction||"error";if(d==="ignore"&&f==="ignore")return u;if(d!=="ignore"&&f!=="ignore"){if(e.test(a)===!1&&n.test(a)===!1)return u}else if(d!=="ignore"&&f==="ignore"){if(e.test(a)===!1)return u}else if(n.test(a)===!1)return u;return s(u,{protoAction:d,constructorAction:f,safe:c&&c.safe})}function s(a,{protoAction:l="error",constructorAction:c="error",safe:u}={}){let d=[a];for(;d.length;){const f=d;d=[];for(const h of f){if(l!=="ignore"&&Object.prototype.hasOwnProperty.call(h,"__proto__")){if(u===!0)return null;if(l==="error")throw new SyntaxError("Object contains forbidden prototype property");delete h.__proto__}if(c!=="ignore"&&Object.prototype.hasOwnProperty.call(h,"constructor")&&h.constructor!==null&&typeof h.constructor=="object"&&Object.prototype.hasOwnProperty.call(h.constructor,"prototype")){if(u===!0)return null;if(c==="error")throw new SyntaxError("Object contains forbidden prototype property");delete h.constructor}for(const p in h){const m=h[p];m&&typeof m=="object"&&d.push(m)}}}return a}function i(a,l,c){const{stackTraceLimit:u}=Error;Error.stackTraceLimit=0;try{return r(a,l,c)}finally{Error.stackTraceLimit=u}}function o(a,l){const{stackTraceLimit:c}=Error;Error.stackTraceLimit=0;let u;try{u=r(a,l,{safe:!0})}catch{u=void 0}finally{Error.stackTraceLimit=c}return u}return Jt.exports=i,Jt.exports.default=i,Jt.exports.parse=i,Jt.exports.safeParse=o,Jt.exports.scan=s,Jt.exports}var H_=q_();const po=na(H_),ls=Symbol("aui.parse-partial-json-object.meta"),Aa=t=>t?.[ls],hr=t=>{if(t.length===0)return{[ls]:{state:"partial",partialPath:[]}};try{const e=po.parse(t);if(typeof e!="object"||e===null)throw new Error("argsText is expected to be an object");return e[ls]={state:"complete",partialPath:[]},e}catch{try{const[e,n]=U_(t),r=po.parse(e);if(typeof r!="object"||r===null)throw new Error("argsText is expected to be an object");return r[ls]={state:"partial",partialPath:n},r}catch{return}}},vh=(t,e,n)=>{if(typeof t!="object"||t===null)return e.state;if(e.state==="complete")return"complete";if(n.length===0)return e.state;const[r,...s]=n;if(!Object.hasOwn(t,r))return"partial";const[i,...o]=e.partialPath;if(r!==i)return"complete";const a=t[r];return vh(a,{state:"partial",partialPath:o},s)},xr=(t,e)=>{const n=Aa(t);if(!n)throw new Error("unable to determine object state");return vh(t,n,e.map(String))},W_=Symbol.for("assistant-stream.json-parser-backends.v1"),G_=globalThis,K_=t=>G_[W_]?.at(-1)?.factory(t),Ur=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/,Q_=/^-?$|^-?(?:0|[1-9]\d*)(?:\.\d*)?$|^-?(?:0|[1-9]\d*)(?:\.\d+)?[eE][+-]?\d*$/,qr=/^[\t\n\r ]$/,Y_=/^[0-9a-fA-F]$/,J_={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
9
|
+
`,r:"\r",t:" "},xs=t=>typeof t=="object"&&t!==null,Sr=(t,e,n)=>{if(e==="__proto__"||e==="constructor"&&xs(n)&&Object.hasOwn(n,"prototype"))throw new Error("Unsafe argument key");t[e]=n},wh=t=>{if(Array.isArray(t))return[...t];const e={};for(const n of Object.keys(t))Sr(e,n,t[n]);return e},X_=(t,e,n,r)=>{const s=(i,o)=>{const a=r.has(i)?i:wh(i);r.add(a);const l=e[o];if(o===e.length-1)return Sr(a,l,n),xs(n)&&r.add(n),a;const c=a[l];if(!xs(c))throw new Error("Invalid incremental JSON path");return Sr(a,l,s(c,o+1)),a};return s(t,0)},lc=(t,e,n)=>{const r=hr("");for(const i of Object.keys(t))Sr(r,i,t[i]);const s=Aa(r);return s.state=e,s.partialPath=n.map(String),r},cc=t=>{const e=[t];for(;e.length>0;){const n=e.pop();for(const r of Object.keys(n)){const s=n[r];if(!xs(s))continue;const i=wh(s);Sr(n,r,i),e.push(i)}}return t};var uc=class Nt{backend;text;mode="start";root={};frames=[];token;args;publishedArgs;ownedContainers;constructor(e){this.args=e,this.publishedArgs=e}static from(e="",n=hr("")){return Nt.create(e,n,!0)}static create(e,n,r){const s=new Nt(n);e.length!==0&&(s.text={length:e.length,previous:void 0,value:e});const i=e.trimEnd().endsWith("}")?hr(e):void 0;if(i&&Aa(i)?.state==="complete")return s.args=i,s.publishedArgs=i,s.mode="complete",s;if(r)try{if(s.backend=K_({text:e,fallback:n,createSnapshot:(o,a,l)=>cc(lc(o,a,[...l]))}),s.backend)return s.publishedArgs=s.backend.currentArgs,s}catch{s.backend=void 0}return s.consumeDelta(e,!0),s.args=s.snapshot(n),s.args!==n&&(s.publishedArgs=s.mode==="fallback"?s.args:void 0),s}get currentTextLength(){return this.text?.length??0}get currentArgs(){return this.publishedArgs??=cc(this.args)}append(e){if(e.length===0)return this;if(this.backend){let s,i;try{s=this.backend.append(e),i=s?.currentArgs}catch{s=void 0}if(!s)return Nt.create(this.accumulatedText()+e,this.currentArgs,!1);const o=new Nt(this.args);return o.backend=s,o.publishedArgs=i,o.text={length:this.currentTextLength+e.length,previous:this.text,value:e},o}if(this.currentTextLength===0)return Nt.create(e,this.args,!1);if(this.mode==="complete"){const s=Nt.create(this.accumulatedText()+e,this.args,!1);return s.args===this.args&&(s.publishedArgs=this.currentArgs),s}const n=this.clone(),r=this.args;return n.consumeDelta(e),n.text={length:(this.text?.length??0)+e.length,previous:this.text,value:e},n.args=n.snapshot(r),n.publishedArgs=n.args===r?this.currentArgs:n.mode==="fallback"?n.args:void 0,n}clone(){const e=new Nt(this.args);return e.text=this.text,e.mode=this.mode,e.root=this.root,e.frames=this.frames.map(n=>({...n,path:[...n.path]})),e.token=this.token?{...this.token,..."path"in this.token&&this.token.path?{path:[...this.token.path]}:void 0}:void 0,e}snapshot(e){return this.mode==="fallback"?hr(this.accumulatedText())??e:this.mode==="start"?e:lc(this.root,this.mode==="complete"?"complete":"partial",this.partialPath())}accumulatedText(){const e=[];for(let n=this.text;n;n=n.previous)e.push(n.value);return e.reverse().join("")}partialPath(){return this.mode==="complete"?[]:this.token&&(this.token.kind==="number"||this.token.kind==="string"&&this.token.role==="value")?this.token.path:this.frames.at(-1)?.path??[]}isFallback(){return this.mode==="fallback"}consumeDelta(e,n=!1){if(!this.isFallback()){this.ownedContainers=n?new Set([this.root]):new Set;for(const r of e)if(this.consumeCharacter(r),this.isFallback())break;!this.isFallback()&&this.token?.kind==="string"&&this.token.role==="value"?this.writeValue(this.token.path,this.token.value):!this.isFallback()&&this.token?.kind==="number"&&Ur.test(this.token.value)&&this.writeValue(this.token.path,Number(this.token.value)),this.ownedContainers=void 0}}consumeCharacter(e){let n=!0;for(;n&&this.mode!=="fallback";){if(n=!1,this.token){n=this.consumeToken(e);continue}if(this.mode==="complete"){qr.test(e)||(this.mode="fallback");continue}if(this.mode==="start"){if(qr.test(e))continue;if(e!=="{"){this.mode="fallback";continue}this.mode="parsing",this.frames.push({kind:"object",path:[],state:"first-key-or-end"});continue}const r=this.frames.at(-1);if(!r){this.mode="fallback";continue}r.kind==="object"?this.consumeObjectCharacter(r,e):this.consumeArrayCharacter(r,e)}}consumeObjectCharacter(e,n){if(!qr.test(n))switch(e.state){case"first-key-or-end":n==="}"?this.closeContainer():n==='"'?(e.state="key",this.startKeyString()):this.mode="fallback";break;case"key":n==='"'?this.startKeyString():this.mode="fallback";break;case"colon":n===":"?e.state="value":this.mode="fallback";break;case"value":this.startValue(n,[...e.path,e.key]);break;case"comma-or-end":n===","?(e.state="key",e.key=void 0):n==="}"?this.closeContainer():this.mode="fallback"}}consumeArrayCharacter(e,n){if(!qr.test(n))switch(e.state){case"first-value-or-end":n==="]"?this.closeContainer():(e.state="value",this.startValue(n,[...e.path,e.index]));break;case"value":this.startValue(n,[...e.path,e.index]);break;case"comma-or-end":n===","?(e.index+=1,e.state="value"):n==="]"?this.closeContainer():this.mode="fallback"}}startValue(e,n){if(e==="{")this.writeValue(n,{}),this.frames.push({kind:"object",path:n,state:"first-key-or-end"});else if(e==="[")this.writeValue(n,[]),this.frames.push({kind:"array",path:n,state:"first-value-or-end",index:0});else if(e==='"')this.writeValue(n,""),this.startValueString(n);else if(e==="t"||e==="f"||e==="n"){const r=e==="t"?"true":e==="f"?"false":"null";this.writeValue(n,r==="true"?!0:r==="false"?!1:null),this.token={kind:"literal",value:r,offset:1}}else e==="-"||e>="0"&&e<="9"?(this.token={kind:"number",path:n,value:e},Ur.test(e)&&this.writeValue(n,Number(e))):this.mode="fallback"}startKeyString(){this.token={kind:"string",role:"key",value:"",escape:"none",unicode:""}}startValueString(e){this.token={kind:"string",role:"value",path:e,value:"",escape:"none",unicode:""}}consumeToken(e){const n=this.token;return n.kind==="string"?this.consumeString(n,e):n.kind==="number"?this.consumeNumber(n,e):this.consumeLiteral(n,e)}consumeString(e,n){if(e.escape==="unicode")return Y_.test(n)?(e.unicode+=n,e.unicode.length===4&&(e.value+=String.fromCharCode(Number.parseInt(e.unicode,16)),e.escape="none",e.unicode=""),!1):(this.mode="fallback",!1);if(e.escape==="single"){if(n==="u")return e.escape="unicode",!1;const r=J_[n];return r===void 0?this.mode="fallback":(e.value+=r,e.escape="none"),!1}if(n==="\\")return e.escape="single",!1;if(n.charCodeAt(0)<32)return this.mode="fallback",!1;if(n!=='"')return e.value+=n,!1;if(this.token=void 0,e.role==="key"){const r=this.frames.at(-1);if(!r||r.kind!=="object")return this.mode="fallback",!1;if(e.value==="__proto__"||e.value==="prototype"&&r.path.at(-1)==="constructor")return this.mode="fallback",!1;r.key=e.value,r.state="colon"}else this.writeValue(e.path,e.value),this.finishValue();return!1}consumeNumber(e,n){if(n>="0"&&n<="9"||n==="e"||n==="E"||n==="+"||n==="-"||n==="."){const r=e.value+n;return Q_.test(r)?(e.value=r,Ur.test(e.value)&&this.writeValue(e.path,Number(e.value)),!1):(this.mode="fallback",!1)}return Ur.test(e.value)?(this.token=void 0,this.finishValue(),!0):(this.mode="fallback",!1)}consumeLiteral(e,n){return n!==e.value[e.offset]?(this.mode="fallback",!1):(e.offset+=1,e.offset===e.value.length&&(this.token=void 0,this.finishValue()),!1)}finishValue(){const e=this.frames.at(-1);if(!e||e.state!=="value"){this.mode="fallback";return}e.state="comma-or-end"}closeContainer(){this.frames.pop(),this.frames.length===0?this.mode="complete":this.finishValue()}writeValue(e,n){try{this.root=X_(this.root,e,n,this.ownedContainers??new Set)}catch{this.mode="fallback"}}};const Z_=vd("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7),ev=(t,e)=>new ReadableStream({start(n){return t.start?.(e(n))},pull(n){return t.pull?.(e(n))},cancel(n){return t.cancel?.(n)}}),tv=(t,e)=>{let n;return[ev({start(r){n=r},cancel(r){return e?.(n,r)}},t),n]};var xh=class{value=-1;up(){return++this.value}},nv=class extends TransformStream{constructor(t){super({transform(e,n){const r=s=>n.enqueue({...e,path:[s,...e.path]});return typeof t=="number"?r(t):t.value!==void 0?r(t.value):t.promise.then(r)}})}};(class extends TransformStream{constructor(t){super({transform(e,n){const{path:[r,...s]}=e;if(t!==r)throw new Error(`Path mismatch: expected ${t}, got ${r}`);n.enqueue({...e,path:s})}})}});const rv=t=>{const e=new xh,n=new Map;return r=>{r.type==="part-start"&&r.path.length===0&&n.set(e.up(),t());const[s,...i]=r.path;if(s===void 0)return r;const o=n.get(s);if(o===void 0)throw new Error("Path not found");return{...r,path:[o,...i]}}},sn=()=>{let t,e;const n=new Promise((r,s)=>{t=r,e=s});if(!t||!e)throw new Error("Failed to create promise");return{promise:n,resolve:t,reject:e}},sv=()=>{const t=new Set;let e=[];const n=new Set;let r=0,s=0,i,o=0;const a=new Set,l=new xh;let c=!1,u=!1,d=!1,f,h,p,m=0,y,g;const b=T=>{for(const $ of T.holds)$.reached.resolve();T.holds=[]},v=()=>{h=void 0;for(const T of a)T.reference.value=-1,T.resolve(-1);if(a.clear(),!g){const T=[...t];t.clear(),e=[],n.clear(),r=0;for(const $ of T)$.written&&($.written.onWrite=void 0),$.orderedFinish?.delivered.resolve(),b($);g=Promise.all(T.map(async $=>{try{await $.reader.cancel().catch(()=>{}),await $.pipeTask}finally{$.reader.releaseLock()}})).then(()=>{})}return g},w=T=>{u||d||(d=!0,console.error(T),v(),f.error(T),y?.reject(T),y=void 0)},k=T=>{T.written&&T.delivered>=T.written.count&&(T.idleAt=s)},_=T=>{T.delivered<T.written.count-1||(T.inBusy||(T.inBusy=!0,n.add(T)),i&&s>T.idleAt&&(T.gate=T.gate?Promise.all([T.gate,i]).then(()=>{}):i))},A=T=>{t.delete(T),n.delete(T),T.written&&(T.written.onWrite=void 0,r--)},E=T=>{T.promise||(T.promise=T.reader.read().then(async({done:$,value:L})=>{if(!(u||d)){if($)T.orderedFinish?.delivered.resolve(),A(T),T.reader.releaseLock(),b(T),c&&t.size===0&&m===0&&f.close();else{if(T.gate&&(await T.gate,T.gate=void 0,u||d))return;for(;T.holds[0]&&T.delivered>=T.holds[0].writtenBefore;)if(await T.holds[0].flushed,T.holds.shift(),u||d)return;if(L.type==="part-finish"&&T.orderedFinish&&(await T.orderedFinish.previous(),u||d))return;f.enqueue(T.pathMapper?.(L)??L),T.delivered++,k(T);for(const j of T.holds)T.delivered>=j.writtenBefore&&j.reached.resolve();L.type==="part-finish"&&T.orderedFinish?.delivered.resolve()}T.promise=void 0,$||e.push(T),y?.resolve(),y=void 0}}).catch($=>{T.promise=void 0,w($)}))},D=new ReadableStream({start(T){f=T},pull(){y=sn();const T=e;e=[],T.length>1&&T.sort(($,L)=>$.seq-L.seq);for(const $ of T)E($);return y.promise},async cancel(){u=!0;const T=v();y?.resolve(),y=void 0,await T}}),x=(T,$)=>{const L={writtenBefore:T.written.count,reached:sn(),flushed:$};return T.delivered>=L.writtenBefore&&L.reached.resolve(),T.holds.push(L),L.reached.promise},M=(T,$)=>{const L=T.type==="part-start"||T.type==="step-finish"||T.type==="message-finish"||T.type==="error";if((t.size>0||L)&&(h=void 0),!h){const j=[];h=j,m++;const V=p,q=L&&r>0,U=V||q?sn():void 0,S=[];if(U&&q)for(const J of n)J.delivered<J.written.count?S.push(x(J,U.promise)):(n.delete(J),J.inBusy=!1);U&&(p=U.promise),q&&(s++,i=U.promise),Promise.resolve().then(async()=>{if(V&&await V,S.length>0&&await Promise.all(S),m--,h===j&&(h=void 0),!(u||d)){for(const{chunk:J,partIndex:ee}of j){if(J.type==="part-start"&&J.path.length===0){const I=l.up();ee&&(a.delete(ee),ee.reference.value=I,ee.resolve(I))}f.enqueue(J)}c&&t.size===0&&m===0&&f.close(),y?.resolve(),y=void 0}}).catch(w).finally(()=>{U&&(U.resolve(),p===U.promise&&(p=void 0))})}h.push({chunk:T,partIndex:$}),L&&(h=void 0)};return{readable:D,isSealed(){return c},isCancelled(){return u},isErrored(){return d},seal(){c||u||d||(c=!0,t.size===0&&m===0&&f.close())},addStream:(T,$,L)=>{const j=$?.catch(()=>{});if(u||d){T.cancel().catch(()=>{});return}if(c)throw T.cancel().catch(()=>{}),new Error("Cannot add streams after the run callback has settled.");h=void 0;const V={seq:o++,reader:T.getReader(),pipeTask:j,orderedFinish:L?.orderedFinish,written:L?.written,delivered:0,idleAt:s,inBusy:!1,gate:p,holds:[],pathMapper:L?.pathTransform==="merge"?rv(()=>l.up()):void 0};t.add(V);const{written:q}=V;q&&(r++,q.onWrite=()=>_(V),q.count>0&&(V.inBusy=!0,n.add(V))),E(V)},enqueuePartStart(T){if(u||d)return{value:-1,promise:Promise.resolve(-1)};if(c)throw new Error("Cannot add streams after the run callback has settled.");const $=sn(),L={value:void 0,promise:$.promise},j={reference:L,resolve:$.resolve};return a.add(j),M(T,j),L},enqueue(T){if(!(u||d)){if(c)throw new Error("Cannot add streams after the run callback has settled.");M(T)}}}},Sh=t=>t instanceof TypeError,Je=(t,e,n)=>{try{t.enqueue(e)}catch(r){if(!Sh(r))throw r;n?.(r)}},Ss=t=>{try{t.close()}catch(e){if(!Sh(e))throw e}};var mo=class{_controller;_strict;_isClosed=!1;_ignoreAppends=!1;_warnedDropped=!1;constructor(t,e={}){this._controller=t,this._strict=e.strict??!0}append(t,e){if(this._ignoreAppends)return this;const n={type:"text-delta",path:[],textDelta:t,...e!=null&&{providerMetadata:e}};if(this._isClosed){if(this._strict)throw new TypeError("Cannot append to a closed TextStreamController");return Je(this._controller,n,this._warnDroppedAfterClose),this}return Je(this._controller,n),this}_warnDroppedAfterClose=t=>{this._warnedDropped||(this._warnedDropped=!0,console.error(`Dropped text delta for closed stream: ${String(t)}`))};close(t){this._isClosed||(this._isClosed=!0,Je(this._controller,{type:"part-finish",path:[],...t!=null&&{providerMetadata:t}}),Ss(this._controller))}__internal_close(){this._isClosed||(this._ignoreAppends=!0,this.close())}__internal_truncate(){this._isClosed||(this._ignoreAppends=!0,this._isClosed=!0,Ss(this._controller))}};const dc=Symbol.for("aui.tool-response"),go="<no result>";var Pt=class yo{get[dc](){return!0}artifact;result;isError;isPreliminary;modelContent;messages;constructor(e){e.artifact!==void 0&&(this.artifact=e.artifact);const n=e.result;this.result=n===void 0?go:n,this.isError=e.isError??!1,e.isPreliminary&&(this.isPreliminary=!0),e.modelContent!==void 0&&(this.modelContent=e.modelContent),e.messages!==void 0&&(this.messages=e.messages)}static[Symbol.hasInstance](e){return typeof e=="object"&&e!==null&&dc in e}static toResponse(e){return e instanceof yo?e:new yo({result:e===void 0?go:e})}},iv=class{_isClosed=!1;_hasArgsText=!1;_argsTextState="open";_controller;_argsTextController;_options;constructor(t,e={}){this._controller=t,this._options=e,this._argsTextController=new mo({enqueue:n=>{if(this._argsTextState!=="open")throw new TypeError("Cannot append to finished tool-call args");if(n.type==="text-delta"){this._hasArgsText=!0,this._controller.enqueue(n);return}this._argsTextState="finishing",queueMicrotask(()=>this._finishArgsText())},close:()=>{}},{strict:this._options.strict})}_finishArgsText(){this._argsTextState==="finishing"&&(this._argsTextState="finished",this._hasArgsText||Je(this._controller,{type:"text-delta",textDelta:"{}",path:[]}),Je(this._controller,{type:"tool-call-args-text-finish",path:[]}))}get argsText(){return this._argsTextController}async setResponse(t){if(this._isClosed)return;const e=t.result;Je(this._controller,{type:"result",path:[],...t.artifact!==void 0?{artifact:t.artifact}:{},result:e===void 0?go:e,isError:t.isError??!1,...t.isPreliminary?{isPreliminary:!0}:{},...t.modelContent!==void 0?{modelContent:t.modelContent}:{},...t.messages!==void 0?{messages:t.messages}:{}}),t.isPreliminary?(this._argsTextController.close(),this._finishArgsText()):await this.close()}setApproval(t){Je(this._controller,{type:"tool-call-approval",path:[],approval:t})}async close(){this._isClosed||(this._isClosed=!0,this._options.onClose?.(),this._argsTextController.close(),this._finishArgsText(),Je(this._controller,{type:"part-finish",path:[]}),Ss(this._controller))}__internal_truncate(){this._isClosed||(this._isClosed=!0,this._finishArgsText(),this._argsTextController.__internal_truncate(),this._argsTextState="finished",Ss(this._controller))}};const mi=t=>{const e={count:0,onWrite:void 0},[n,r]=tv(s=>t({get desiredSize(){return s.desiredSize},enqueue(i){s.enqueue(i),e.count++,e.onWrite?.()},close(){s.close()},error(i){s.error(i)}}));return[n,r,e]};var ov=class Th{_state;_parentId;constructor(e,n={}){this._state=e||{strict:n.strict??!0,merger:sv(),openInputs:new Set,lastToolCallFinish:Promise.resolve()}}get __internal_isClosed(){return this._state.merger.isSealed()||this._state.merger.isCancelled()||this._state.merger.isErrored()}get __internal_isCancelled(){return this._state.merger.isCancelled()}__internal_getReadable(){return this._state.merger.readable}__internal_endOpenInputs(){this._state.append=void 0;for(const e of this._state.openInputs)e();this._state.openInputs.clear()}__internal_subscribeToClose(e){this._state.closeSubscriber=e}_addTransformedStream(e,n,r){if(e.locked)throw new TypeError("Cannot merge a stream that is already locked to a reader.");const s=e.pipeTo(n.writable).catch(async i=>{throw await n.writable.abort(i).catch(()=>{}),i});return this._state.merger.addStream(n.readable,s,r),s}_trackOpenInput(e,n){const{openInputs:r}=this._state;r.add(n);const s=()=>r.delete(n);e.then(s,s)}_addPart(e,n,r,s,i){this._state.append&&(this._state.append.controller.close(),this._state.append=void 0);const o=this._state.merger.enqueuePartStart({type:"part-start",part:e,path:[]}),a=this._addTransformedStream(n,new nv(o),{orderedFinish:i,written:r});s&&this._trackOpenInput(a,s)}merge(e){this._addTransformedStream(e,new TransformStream,{pathTransform:"merge"})}appendText(e){(this._state.append?.kind!=="text"||this._state.append.parentId!==this._parentId)&&(this._state.append={kind:"text",parentId:this._parentId,controller:this.addTextPart()}),this._state.append.controller.append(e)}appendReasoning(e,n){(n!==void 0||this._state.append?.kind!=="reasoning"||this._state.append.parentId!==this._parentId)&&(this._state.append={kind:"reasoning",parentId:this._parentId,controller:this.addReasoningPart(n)}),!(n!==void 0&&e.length===0)&&this._state.append.controller.append(e)}addTextPart(e){const[n,r,s]=mi(i=>new mo(i,{strict:this._state.strict}));return this._addPart(this._withParentIdOption({type:"text",...e}),n,s,()=>r.__internal_close()),r}addReasoningPart(e){const[n,r,s]=mi(i=>new mo(i,{strict:this._state.strict}));return this._addPart(this._withParentIdOption({type:"reasoning",...e}),n,s,()=>r.__internal_close()),r}addToolCallPart(e){const n=typeof e=="string"?{toolName:e}:e,r=n.toolName,s=n.toolCallId??Z_(),i=sn();let o=Promise.resolve();const[a,l,c]=mi(u=>new iv(u,{strict:this._state.strict,onClose:()=>{o=this._state.lastToolCallFinish,this._state.lastToolCallFinish=i.promise}}));return this._addPart({type:"tool-call",toolName:r,toolCallId:s,...n.providerExecuted&&{providerExecuted:!0},...this._parentId&&{parentId:this._parentId}},a,c,()=>l.__internal_truncate(),{previous:()=>o,delivered:i}),n.argsText!==void 0&&(l.argsText.append(n.argsText),l.argsText.close()),n.args!==void 0&&(l.argsText.append(JSON.stringify(n.args)),l.argsText.close()),n.response!==void 0&&l.setResponse(n.response),l}_finishedPartStream(){return new ReadableStream({start(e){e.enqueue({type:"part-finish",path:[]}),e.close()}})}_withParentIdOption(e){return this._parentId?{...e,parentId:this._parentId}:e}appendSource(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream(),{count:1,onWrite:void 0})}appendFile(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream(),{count:1,onWrite:void 0})}appendData(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream(),{count:1,onWrite:void 0})}enqueue(e){this._state.merger.enqueue(e)}withParentId(e){const n=new Th(this._state);return n._parentId=e,n}close(){this._state.append?.controller?.close(),this._state.merger.seal(),this._state.closeSubscriber?.()}};function av(t,e={}){const n=new ov(void 0,e);return(async()=>{try{await t(n)}catch(s){n.__internal_isClosed?n.__internal_isCancelled||console.error(s):(n.enqueue({type:"error",path:[],error:String(s)}),n.__internal_endOpenInputs())}finally{n.__internal_isClosed||n.close()}})(),n.__internal_getReadable()}function lv(t={}){const{resolve:e,promise:n}=sn();let r;return[av(s=>(r=s,r.__internal_subscribeToClose(e),n),t),r]}var Ch=class extends TransformStream{constructor(){const t=[];super({transform(e,n){if(e.type==="part-start"){if(e.path.length!==0){n.error(new Error("Nested parts are not supported"));return}t.push(e.part),n.enqueue(e);return}if(e.type==="text-delta"||e.type==="result"||e.type==="part-finish"||e.type==="tool-call-args-text-finish"||e.type==="tool-call-approval"){if(e.path.length!==1){n.error(new Error(`${e.type} chunks must have a path of length 1`));return}const r=e.path[0];if(r<0||r>=t.length){n.error(new Error(`Invalid path index: ${r}`));return}const s=t[r];n.enqueue({...e,meta:s});return}n.enqueue(e)}})}};const gi=(t,e,n)=>{if(t?.startsWith("data-"))return{type:"data",name:t.substring(5),data:e,...typeof n=="string"&&{id:n}}},rr=t=>typeof t=="string",Hr=t=>j_(t)?_h(t):null,zn=(t,e,n)=>{const{role:r,id:s,createdAt:i,attachments:o,status:a,metadata:l}=t,c={id:s??e,createdAt:i??new Date},u=typeof t.content=="string"?[{type:"text",text:t.content}]:t.content,d=({image:f,...h})=>typeof f!="string"?null:O_(f)?.mimeType.startsWith("image/")||/^(https:\/\/|blob:)/i.test(f)?_h({...h,image:f}):(console.warn("Invalid image data format detected"),null);if(r!=="user"&&o?.length)throw new Error("attachments are only supported for user messages");if(r!=="assistant"&&a)throw new Error("status is only supported for assistant messages");if(r!=="assistant"&&l?.steps)throw new Error("metadata.steps is only supported for assistant messages");switch(r){case"assistant":return{...c,role:r,content:u.map(h=>{const p=h.type;switch(p){case"text":return!rr(h.text)||!h.text.trim()?null:h;case"reasoning":{const m=rr(h.text)?h.text:"",y=rr(h.unstable_summary)?h.unstable_summary:void 0,g=typeof h.unstable_redacted=="boolean"?h.unstable_redacted:void 0;if(g!==!0&&!m.trim()&&!y?.trim())return null;if(m===h.text&&y===h.unstable_summary&&g===h.unstable_redacted)return h;const{unstable_summary:b,unstable_redacted:v,...w}=h;return{...w,text:m,...y!==void 0&&{unstable_summary:y},...g!==void 0&&{unstable_redacted:g}}}case"file":case"source":return Hr(h);case"image":return d(h);case"data":return Hr(h);case"generative-ui":return h;case"tool-call":{const{parentId:m,messages:y,unstable_interactions:g,...b}=h,v=yh(g),w={...b,toolCallId:h.toolCallId||`tool-${Mt()}`,...m!==void 0&&{parentId:m},...y!==void 0&&{messages:y},...v!==void 0&&{unstable_interactions:v}};return h.args?{...w,args:h.args,argsText:h.argsText??JSON.stringify(h.args)}:{...w,args:hr(h.argsText??"")??{},argsText:h.argsText??""}}case"audio":throw new Error(`Unsupported assistant message part type: ${p}`);default:{const m=p,y=gi(m,h.data,h.id);if(y)return y;throw new Error(`Unsupported assistant message part type: ${m}`)}}}).filter(h=>!!h),status:a??n,metadata:{...l?.runId!==void 0&&{runId:l.runId},unstable_state:l?.unstable_state??null,unstable_annotations:l?.unstable_annotations??[],unstable_data:l?.unstable_data??[],custom:l?.custom??{},steps:l?.steps??[],...l?.timing&&{timing:l.timing},...l?.submittedFeedback&&{submittedFeedback:l.submittedFeedback},...l?.isOptimistic&&{isOptimistic:!0},...l?.modality&&{modality:l.modality}}};case"user":return{...c,role:r,content:u.filter(h=>h.type!=="text"||rr(h.text)).map(h=>{const p=h.type;switch(p){case"file":case"image":case"audio":case"data":return Hr(h);case"text":return h;case"reasoning":case"source":case"generative-ui":case"tool-call":throw new Error(`Unsupported user message part type: ${p}`);default:{const m=p,y=gi(m,h.data,h.id);if(y)return y;throw new Error(`Unsupported user message part type: ${m}`)}}}).filter(h=>h!==null),attachments:(o??[]).map(h=>({...h,content:(h.content??[]).map(p=>{const m=gi(p.type,p.data,"id"in p?p.id:void 0);return m||Hr(p)}).filter(p=>p!==null)})),metadata:{custom:l?.custom??{},...l?.isOptimistic&&{isOptimistic:!0},...l?.modality&&{modality:l.modality}}};case"system":if(u.length!==1||u[0].type!=="text")throw new Error("System messages must have exactly one text message part.");const[f]=u;return{...c,role:r,content:rr(f.text)?[f]:[{...f,text:""}],metadata:{custom:l?.custom??{}}};default:throw new Error(`Unknown message role: ${r}`)}},mn=Symbol("innerMessage"),yi=Symbol("innerMessages"),cv=[],hc=(t,e)=>{mn in t||(t[mn]=e)},uv=t=>{const e="messages"in t&&!("type"in t&&t.type==="tool-call")?t.messages:t,n=e[yi]||e[mn];return n?Array.isArray(n)?n:(e[yi]=[n],e[yi]):cv},dv="__external_store_fallback_",hv=(t,e)=>{const n=new Set,r=[];for(let s=t.length-1;s>=0;s--){const i=t[s];if(n.has(i.id)){e(i.id);continue}n.add(i.id),r.push(i)}return r.length===t.length?t:r.reverse()},Ze=Object.freeze({type:"complete"}),Ra=Object.freeze({type:"running"}),fv=Object.freeze({cancelled:Object.freeze({type:"incomplete",reason:"cancelled"}),length:Object.freeze({type:"incomplete",reason:"length"}),"content-filter":Object.freeze({type:"incomplete",reason:"content-filter"}),other:Object.freeze({type:"incomplete",reason:"other"}),error:Object.freeze({type:"incomplete",reason:"error"})}),Ih=t=>{const e=t.status;if(!e||typeof e!="object")return;const{type:n}=e;if(n==="running")return Ra;if(n==="complete")return Ze;if(n!=="incomplete")return;const{reason:r}=e;return fv[r==="cancelled"||r==="length"||r==="content-filter"||r==="other"||r==="error"?r:"other"]},kh=t=>t.interrupt!=null||t.approval!=null&&t.approval.approved===void 0&&t.approval.resolution===void 0,Eh=(t,e,n)=>{if(t.role!=="assistant")return Ze;if(n.type==="tool-call")return n.result===void 0||n.isPreliminary||kh(n)?t.status:Ze;if(t.status.type==="running"){const s=Ih(n);if(s)return s}const r=e===Math.max(0,t.content.length-1);return t.status.type==="requires-action"?Ze:r?t.status:Ze},Ah=t=>t.type==="tool-call"&&t.result===void 0,pv=t=>{if(t.type!=="tool-call"||t.result!==void 0)return!1;const e=t.messages?.at(-1);return e?.role==="assistant"&&e.status.type==="running"},Rh=t=>t.type==="tool-call"&&kh(t),_n=Symbol("autoStatus"),fc=Object.freeze(Object.assign({type:"running"},{[_n]:!0})),mv=Object.freeze(Object.assign({type:"complete",reason:"unknown"},{[_n]:!0})),gv=Object.freeze(Object.assign({type:"incomplete",reason:"cancelled"},{[_n]:!0})),yv=Object.freeze(Object.assign({type:"requires-action",reason:"tool-calls"},{[_n]:!0})),bv=Object.freeze(Object.assign({type:"requires-action",reason:"interrupt"},{[_n]:!0})),_v=t=>t[_n]===!0,Ma=(t,e,n,r,s,i,o)=>t&&s!==void 0&&s!==null?Object.assign({type:"incomplete",reason:"error",error:s},{[_n]:!0}):t&&e?fc:n?bv:o&&!i?fc:r?yv:i?gv:mv,pc=t=>Ma(!1,!1,typeof t!="string"&&t.some(Rh),typeof t!="string"&&t.some(Ah)),mc=(t,e,n)=>Ma(e,n,typeof t!="string"&&t.some(Rh),typeof t!="string"&&t.some(Ah),void 0,void 0,typeof t!="string"&&t.some(pv)),Mh={fromArray:t=>{const e=t.map(n=>zn(n,n.id??Mt(),pc(n.content)));return{messages:e.map((n,r)=>({parentId:r>0?e[r-1].id:null,message:n}))}},fromBranchableArray:(t,e)=>({...e?.headId!==void 0?{headId:e.headId}:void 0,messages:t.map(({message:n,parentId:r})=>{if(!n.id)throw new Error("ExportedMessageRepository.fromBranchableArray: Each message must have an 'id' field set.");return{parentId:r,message:zn(n,n.id,pc(n.content))}})})},Wr=t=>{let e=t;for(;e.next;)e=e.next;return"current"in e?e:null},vv=(t,e)=>{const n=new Set(t.map(o=>o.message.id)),r=new Set,s=new Map,i=[];for(const o of t){const{parentId:a}=o;if(a!==null&&n.has(a)&&!r.has(a)&&!e(a)){const l=s.get(a);l?l.push(o):s.set(a,[o]);continue}for(let l=i.push(o)-1;l<i.length;l++){const{id:c}=i[l].message;if(r.has(c))continue;r.add(c);const u=s.get(c);u&&(s.delete(c),i.push(...u))}}for(const o of s.values())i.push(...o);return i};var wv=class{_value=null;func;constructor(t){this.func=t}get value(){return this._value===null&&(this._value=this.func()),this._value}dirty(){this._value=null}},Gs=class{messages=new Map;head=null;root={children:[],next:null};updateLevels(t,e){const n=[{message:t,level:e}];for(;n.length>0;){const r=n.pop();r.message.level=r.level;for(const s of r.message.children){const i=this.messages.get(s);i&&n.push({message:i,level:r.level+1})}}}selectPathTo(t){for(let e=t;e;e=e.prev)(e.prev??this.root).next=e}performOp(t,e,n){const r=e.prev??this.root,s=t??this.root;if(!(n==="relink"&&r===s)){if(n==="relink"){for(let i=t;i;i=i.prev)if(i.current.id===e.current.id)throw new Error("MessageRepository(performOp/relink): A message with the same id already exists in the parent tree. This error occurs if the same message id is found multiple times. This is likely an internal bug in assistant-ui.")}if(n!=="link"&&(r.children=r.children.filter(i=>i!==e.current.id),r.next===e)){const i=r.children.at(-1),o=i?this.messages.get(i):null;if(o===void 0)throw new Error("MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.");r.next=o}if(n!=="cut"){s.children=[...s.children,e.current.id],e.prev=t,Wr(e)===this.head?this.selectPathTo(e):s.next===null&&(s.next=e,this.head===s&&(this.head=Wr(e)));const i=t?t.level+1:0;this.updateLevels(e,i)}}}_messages=new wv(()=>{const t=new Array((this.head?.level??-1)+1);for(let e=this.head;e;e=e.prev)t[e.level]=e.current;return t});get headId(){return this.head?.current.id??null}get canonicalHeadId(){let t=this.head;for(;t?.current.metadata?.isOptimistic;)t=t.prev;return t?.current.id??null}getMessages(t){if(t===void 0||t===this.head?.current.id)return this._messages.value;const e=this.messages.get(t);if(!e)throw new Error("MessageRepository(getMessages): Head message not found. This is likely an internal bug in assistant-ui.");const n=new Array(e.level+1);for(let r=e;r;r=r.prev)n[r.level]=r.current;return n}addOrUpdateMessage(t,e){const n=this.messages.get(e.id),r=t?this.messages.get(t):null;if(r===void 0)throw new Error("MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.");if(n){this.performOp(r,n,"relink"),n.current=e,this._messages.dirty();return}const s={prev:r,current:e,next:null,children:[],level:r?r.level+1:0};this.messages.set(e.id,s),this.performOp(r,s,"link"),this.head===r&&(this.head=s,this.selectPathTo(s)),this._messages.dirty()}getMessage(t){const e=this.messages.get(t);if(!e)throw new Error("MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui.");return{parentId:e.prev?.current.id??null,message:e.current,index:e.level}}deleteMessage(t,e){const n=this.messages.get(t);if(!n)throw new Error("MessageRepository(deleteMessage): Message not found. This is likely an internal bug in assistant-ui.");const r=e===void 0?n.prev:e===null?null:this.messages.get(e);if(r===void 0)throw new Error("MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.");for(let s=r;s;s=s.prev)if(s===n)throw new Error("MessageRepository(deleteMessage): Replacement is the deleted message or one of its descendants. This is likely an internal bug in assistant-ui.");for(const s of n.children){const i=this.messages.get(s);if(!i)throw new Error("MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.");this.performOp(r,i,"relink")}this.performOp(null,n,"cut"),this.messages.delete(t),this.head===n&&(this.head=Wr(r??this.root)),this._messages.dirty()}hasChildren(t){return(this.messages.get(t)?.children.length??0)>0}getBranches(t){const e=this.messages.get(t);if(!e)throw new Error("MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.");const{children:n}=e.prev??this.root;return n}evictOffBranchOptimisticMessages(t,e){if(!t)return;const n=new Set;for(let s=e;s;s=s.prev)n.add(s.current.id);const r=[];for(let s=t;s&&!n.has(s.current.id);s=s.prev)s.current.metadata?.isOptimistic&&r.push(s.current.id);for(const s of r)this.messages.has(s)&&this.deleteMessage(s)}switchToBranch(t){const e=this.messages.get(t);if(!e)throw new Error("MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.");const n=this.head;this.selectPathTo(e),this.head=Wr(e),this.evictOffBranchOptimisticMessages(n,this.head),this._messages.dirty()}setHead(t,e){if(t===null){this.clear();return}const n=this.messages.get(t);if(!n)throw new Error(`MessageRepository(${e?"resetHead":"import"}): Branch not found. This is likely an internal bug in assistant-ui.`);const r=this.head;if(e&&n.children.length>0){const s=[...n.children];for(;s.length>0;){const i=s.pop(),o=this.messages.get(i);if(o){for(const a of o.children)s.push(a);this.messages.delete(i)}}n.children=[],n.next=null}this.head=n,this.selectPathTo(n),this.evictOffBranchOptimisticMessages(r,this.head),this._messages.dirty()}resetHead(t){this.setHead(t,!0)}clear(){this.messages.clear(),this.head=null,this.root={children:[],next:null},this._messages.dirty()}export(){const t=[],e=[...this.root.children].reverse();for(;e.length>0;){const n=this.messages.get(e.pop());if(!n)continue;for(let s=n.children.length-1;s>=0;s--)e.push(n.children[s]);if(n.current.metadata?.isOptimistic)continue;let r=n.prev;for(;r&&r.current.metadata?.isOptimistic;)r=r.prev;t.push({message:n.current,parentId:r?.current.id??null})}return{headId:this.exportedHeadId(),messages:t}}exportedHeadId(){let t=this.head;for(;t?.current.metadata?.isOptimistic;)t=t.prev;if(t===this.head)return t?.current.id??null;for(;;){const e=this.exportedChild(t??this.root);if(!e)return t?.current.id??null;t=e}}exportedChild(t){const e=t.next;if(e){if(!e.current.metadata?.isOptimistic)return e;const s=this.exportedChild(e);if(s)return s}const n=e?t.children.indexOf(e.current.id):t.children.length,r=[...t.children.slice(0,n).reverse(),...t.children.slice(n+1).reverse()];for(const s of r){const i=this.messages.get(s);if(!i)continue;if(!i.current.metadata?.isOptimistic)return i;const o=this.exportedChild(i);if(o)return o}return null}snapshot(){const t=new Map(this.messages),e=this.head,n=this.root,r=n.children.slice(),s=n.next,i=Array.from(t.values(),o=>({node:o,prev:o.prev,next:o.next,current:o.current,level:o.level,children:o.children.slice()}));return()=>{for(const{node:o,...a}of i)Object.assign(o,a);n.children=r,n.next=s,this.root=n,this.messages=t,this.head=e,this._messages.dirty()}}import({headId:t,messages:e}){if(e.length===0){this.setHead(t??null,!1);return}const n=this.snapshot();try{const r=vv(e,i=>this.messages.has(i));for(const{message:i,parentId:o}of r)this.addOrUpdateMessage(o,i);const s=t??r.at(-1)?.message.id??null;this.setHead(s,!1)}catch(r){throw n(),r}}};const Ph=t=>{new Gs().import(t)},xv=(t,e)=>{Ph(e),t.clear(),t.import(e)},gc=new WeakMap,vn=t=>{const e=gc.get(t);if(e)return e;const n=new Map,r=t.map(i=>{const o=i.type==="tool-call"?i.toolCallId:"id"in i?i.id:void 0;if(!o)return;const a=`${i.type}:${o}`;return n.set(a,(n.get(a)??0)+1),a}),s=t.map((i,o)=>{const a=r[o];return a&&n.get(a)===1?a:`${i.type}@${o}`});return gc.set(t,s),s},bo=t=>t.isComposing||t.keyCode===229,yc=new WeakMap,Dh=(t,e)=>{let n=yc.get(t);return n||(n=new Set(t.map(r=>r.id)),yc.set(t,n)),n.has(e)},Sv=t=>{const e=new Map;return t.map(n=>{const r=JSON.stringify([n.title,n.label,n.prompt]),s=e.get(r)??0;return e.set(r,s+1),s===0?r:`${r}:${s}`})};var bc=class{cache=new WeakMap;convertMessages(t,e){return t.map((n,r)=>{const s=e(this.cache.get(n),n,r);return this.cache.set(n,s),s})}};const Gr=(t,e)=>{if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0},Tv="ui://",Cv=t=>!!t?.startsWith(Tv),Iv=t=>t.display==="text"||t.display!=="questions"&&t.allowFreeform===!0,_c={"allow-once":!0,"allow-always":!0,"reject-once":!1,"reject-always":!1},kv=(t,e)=>{const n=t.questions??[];if(n.length===0)throw new Error(`Tool approval "${t.id}" has display "questions" but declares no questions`);const r=new Set;for(const s of n){if(r.has(s.id))throw new Error(`Tool approval "${t.id}" declares question "${s.id}" more than once`);r.add(s.id)}for(const s of Object.keys(e))if(!r.has(s))throw new Error(`Tool approval "${t.id}" has no question with id "${s}"`);for(const s of n){const i=Object.hasOwn(e,s.id)?e[s.id]:void 0,o=i?.optionIds??[],a=i?.text;if(!Array.isArray(o)||a!==void 0&&typeof a!="string")throw new Error(`Question "${s.id}" takes optionIds as an array and text as a string`);if(o.length===0&&(a===void 0||a.trim()===""))throw new Error(`Tool approval "${t.id}" is missing an answer to question "${s.id}"`);if(o.length>1&&!s.multiple)throw new Error(`Question "${s.id}" takes one option, not ${o.length}`);if(new Set(o).size!==o.length)throw new Error(`Question "${s.id}" lists an option more than once`);for(const l of o)if(!s.options?.some(c=>c.id===l))throw new Error(`Question "${s.id}" has no option with id "${l}"`);if(a!==void 0&&(s.options?.length??0)>0&&!s.allowFreeform)throw new Error(`Question "${s.id}" does not accept a typed answer; it must declare allowFreeform`)}},Ev=(t,e)=>{const n=e.reason;if("answers"in e){if("approved"in e||"optionId"in e||"text"in e)throw new Error(`Tool approval "${t.id}" takes its answers alone, without approved, optionId or text`);return kv(t,e.answers),{approvalId:t.id,approved:!0,answers:e.answers,...n!=null&&{reason:n}}}if("approved"in e&&e.approved===!1&&!("optionId"in e)&&e.text===void 0)return{approvalId:t.id,approved:!1,...n!=null&&{reason:n}};throw new Error(`Tool approval "${t.id}" asks questions; respond with answers, or with approved: false to dismiss it`)},Av=(t,e)=>{if(t.display==="questions")return Ev(t,e);if("answers"in e)throw new Error(`Tool approval "${t.id}" asks no questions; answers only resolve a display "questions" request`);const n=e.text;if(n!==void 0&&!Iv(t))throw new Error(`Tool approval "${t.id}" does not accept a free-form answer; the request must declare display "text" or allowFreeform`);let r,s;if("optionId"in e){const i=t.options?.find(o=>o.id===e.optionId);if(!i)throw new Error(`Tool approval has no option with id "${e.optionId}"`);if("approved"in e)r=e.approved;else{if(!Object.hasOwn(_c,i.kind))throw new Error(`Tool approval option "${i.id}" has a custom kind "${i.kind}"; respond with an explicit approved value instead`);r=_c[i.kind]}s=i.id}else if("approved"in e)r=e.approved;else{if(t.display!=="text"&&t.display!=="select")throw new Error(`Tool approval "${t.id}" is a decision, not a question; respond with an explicit approved value, optionally alongside the answer`);r=!0}return{approvalId:t.id,approved:r,...s!==void 0&&{optionId:s},...n!==void 0&&{text:n},...e.reason!=null&&{reason:e.reason}}},Rv=t=>"content"in t&&!("lastModified"in t),ht=t=>t.status.type==="complete";var bi=class{_generation=0;begin(){return this._generation++,this.current()}current(){const t=this._generation;return{isCurrent:()=>t===this._generation}}invalidate(){this._generation++}};function*_o(t,e){const n=[{type:"messages",values:t,index:0}];let r;const s=i=>{if(!r){r=new WeakSet;for(const o of n)o.type==="messages"&&r.add(o.values)}return r.has(i.values)?!1:(r.add(i.values),n.push(i),!0)};for(;n.length>0;){const i=n[n.length-1];if(i.index>=i.values.length){n.pop(),i.type==="messages"&&r?.delete(i.values);continue}if(i.type==="messages"){const a=i.values[i.index++];if(a?.role!=="assistant"||!Array.isArray(a.content))continue;n.push({type:"content",values:a.content,messageId:a.id,index:0});continue}const o=i.values[i.index++];!o||o.type!=="tool-call"||(yield{part:o,messageId:i.messageId},o.messages?.length&&e?.shouldDescend?.(o)!==!1&&s({type:"messages",values:o.messages,index:0}))}}var Oh=class{_contextProvider=new Ea;registerModelContextProvider(t){return this._contextProvider.registerModelContextProvider(t)}getModelContextProvider(){return this._contextProvider}},Lh=class{get path(){return this._core.path}_core;constructor(t){this._core=t,this.__internal_bindMethods()}__internal_bindMethods(){this.getState=this.getState.bind(this),this.remove=this.remove.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this._core.getState()}subscribe(t){return this._core.subscribe(t)}},Fh=class extends Lh{_composerApi;constructor(t,e){super(t),this._composerApi=e}remove(){const t=this._composerApi.getState();if(!t)throw new Error("Composer is not available");return t.removeAttachment(this.getState().id)}},Mv=class extends Fh{get source(){return"thread-composer"}},Pv=class extends Fh{get source(){return"edit-composer"}},Dv=class extends Lh{get source(){return"message"}remove(){throw new Error("Message attachments cannot be removed")}};const On=Object.freeze([]),$h=Object.freeze({}),Ov=t=>Object.freeze({type:"thread",isEditing:t?.isEditing??!1,canCancel:t?.canCancel??!1,canSend:t?.canSend??!1,isEmpty:t?.isEmpty??!0,attachments:t?.attachments??On,text:t?.text??"",role:t?.role??"user",runConfig:t?.runConfig??$h,attachmentAccept:t?.attachmentAccept??"",dictation:t?.dictation,lastDictationEnd:t?.lastDictationEnd,quote:t?.quote,queue:t?.queue??On,submission:t?.submission,inTransit:t?.inTransit??On,value:t?.text??""}),Lv=t=>Object.freeze({type:"edit",isEditing:t?.isEditing??!1,canCancel:t?.canCancel??!1,canSend:t?.canSend??!1,isEmpty:t?.isEmpty??!0,text:t?.text??"",role:t?.role??"user",attachments:t?.attachments??On,runConfig:t?.runConfig??$h,attachmentAccept:t?.attachmentAccept??"",dictation:t?.dictation,lastDictationEnd:t?.lastDictationEnd,quote:t?.quote,queue:t?.queue??On,submission:t?.submission,inTransit:t?.inTransit??On,parentId:t?.parentId??null,sourceId:t?.sourceId??null,value:t?.text??""});var Nh=class{get path(){return this._core.path}_core;constructor(t){this._core=t}__internal_bindMethods(){this.setText=this.setText.bind(this),this.setRunConfig=this.setRunConfig.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.addAttachment=this.addAttachment.bind(this),this.reset=this.reset.bind(this),this.clearAttachments=this.clearAttachments.bind(this),this.send=this.send.bind(this),this.cancel=this.cancel.bind(this),this.steerQueueItem=this.steerQueueItem.bind(this),this.moveQueueItem=this.moveQueueItem.bind(this),this.removeQueueItem=this.removeQueueItem.bind(this),this.setRole=this.setRole.bind(this),this.getAttachmentByIndex=this.getAttachmentByIndex.bind(this),this.startDictation=this.startDictation.bind(this),this.stopDictation=this.stopDictation.bind(this),this.setQuote=this.setQuote.bind(this),this.unstable_on=this.unstable_on.bind(this)}setText(t,e){const n=this._core.getState();if(!n)throw new Error("Composer is not available");n.setText(t,e)}setRunConfig(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setRunConfig(t)}addAttachment(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");return e.addAttachment(t)}reset(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");return t.reset()}clearAttachments(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");return t.clearAttachments()}send(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.send(t)}cancel(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");t.cancel()}steerQueueItem(t){this.moveQueueItem(t,{lane:"steer",insertAfter:null})}moveQueueItem(t,e){const n=this._core.getState();if(!n)throw new Error("Composer is not available");n.moveQueueItem(t,e)}removeQueueItem(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.removeQueueItem(t)}setRole(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setRole(t)}startDictation(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");t.startDictation()}stopDictation(){const t=this._core.getState();if(!t)throw new Error("Composer is not available");t.stopDictation()}setQuote(t){const e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setQuote(t)}subscribe(t){return this._core.subscribe(t)}_eventSubscriptionSubjects=new Map;unstable_on(t,e){let n=this._eventSubscriptionSubjects.get(t);return n||(n=new ph({event:t,binding:this._core}),this._eventSubscriptionSubjects.set(t,n)),n.subscribe(e)}},Fv=class extends Nh{get path(){return this._core.path}get type(){return"thread"}_getState;constructor(t){const e=new ka({path:t.path,getState:()=>Ov(t.getState()),subscribe:n=>t.subscribe(n)});super({path:t.path,getState:()=>t.getState(),subscribe:n=>e.subscribe(n)}),this._getState=e.getState.bind(e),this.__internal_bindMethods()}getState(){return this._getState()}getAttachmentByIndex(t){return new Mv(new Xe({path:{...this.path,attachmentSource:"thread-composer",attachmentSelector:{type:"index",index:t},ref:`${this.path.ref}.attachments[${t}]`},getState:()=>{const e=this.getState().attachments[t];return e?{...e,source:"thread-composer"}:ot},subscribe:e=>this._core.subscribe(e)}),this._core)}},$v=class extends Nh{get path(){return this._core.path}get type(){return"edit"}_getState;_beginEdit;constructor(t,e){const n=new ka({path:t.path,getState:()=>Lv(t.getState()),subscribe:r=>t.subscribe(r)});super({path:t.path,getState:()=>t.getState(),subscribe:r=>n.subscribe(r)}),this._beginEdit=e,this._getState=n.getState.bind(n),this.__internal_bindMethods()}__internal_bindMethods(){super.__internal_bindMethods(),this.beginEdit=this.beginEdit.bind(this)}getState(){return this._getState()}beginEdit(){this._beginEdit()}getAttachmentByIndex(t){return new Pv(new Xe({path:{...this.path,attachmentSource:"edit-composer",attachmentSelector:{type:"index",index:t},ref:`${this.path.ref}.attachments[${t}]`},getState:()=>{const e=this.getState().attachments[t];return e?{...e,source:"edit-composer"}:ot},subscribe:e=>this._core.subscribe(e)}),this._core)}},Nv=class extends TransformStream{constructor(t){super();const e=t(super.readable);Object.defineProperty(this,"readable",{value:e,writable:!1})}};function Bv(t,e,n){let r;try{const s=t();if(typeof s=="object"&&s!==null&&"then"in s)return s.then(e,n);r=s}catch(s){n(s);return}e(r)}function Tr(t,e){let n=t;for(const r of e){if(n==null||!Object.hasOwn(n,r))return;n=n[r]}return n}var jv=class{resolve;reject;disposed=!1;fieldPath;get isDisposed(){return this.disposed}constructor(t,e,n){this.resolve=t,this.reject=e,this.fieldPath=n}update(t){if(!this.disposed)try{if(xr(t,this.fieldPath)==="complete"){const e=Tr(t,this.fieldPath);e!==void 0&&(this.resolve(e),this.dispose())}}catch(e){this.reject(e),this.dispose()}}end(t){if(!this.disposed)try{const e=Tr(t,this.fieldPath);this.resolve(e)}catch(e){this.reject(e)}finally{this.dispose()}}error(t){this.disposed||(this.reject(t),this.dispose())}dispose(){this.disposed=!0}},zv=class{controller;disposed=!1;fieldPath;get isDisposed(){return this.disposed}constructor(t,e){this.controller=t,this.fieldPath=e}update(t){if(!this.disposed)try{const e=Tr(t,this.fieldPath);e!==void 0&&this.controller.enqueue(e),xr(t,this.fieldPath)==="complete"&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}end(){this.disposed||(this.controller.close(),this.dispose())}error(t){this.disposed||(this.controller.error(t),this.dispose())}dispose(){this.disposed=!0}},Vv=class{controller;disposed=!1;fieldPath;lastValue=void 0;get isDisposed(){return this.disposed}constructor(t,e){this.controller=t,this.fieldPath=e}update(t){if(!this.disposed)try{const e=Tr(t,this.fieldPath);if(typeof e=="string"&&e!==this.lastValue){const n=e.substring(this.lastValue?.length||0);this.lastValue=e,this.controller.enqueue(n)}xr(t,this.fieldPath)==="complete"&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}end(){this.disposed||(this.controller.close(),this.dispose())}error(t){this.disposed||(this.controller.error(t),this.dispose())}dispose(){this.disposed=!0}},Uv=class{controller;disposed=!1;fieldPath;nextIndex=0;get isDisposed(){return this.disposed}constructor(t,e){this.controller=t,this.fieldPath=e}update(t){if(!this.disposed)try{const e=Tr(t,this.fieldPath);if(!Array.isArray(e))return;for(;this.nextIndex<e.length;this.nextIndex++){const n=[...this.fieldPath,this.nextIndex];if(xr(t,n)!=="complete")break;this.controller.enqueue(e[this.nextIndex])}xr(t,this.fieldPath)==="complete"&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}end(){this.disposed||(this.controller.close(),this.dispose())}error(t){this.disposed||(this.controller.error(t),this.dispose())}dispose(){this.disposed=!0}},qv=class{argTextDeltas;handles=new Set;accumulatedText="";parser;args=void 0;finished=!1;failure=void 0;constructor(t){this.argTextDeltas=t,this.processStream()}async processStream(){try{const t=this.argTextDeltas.getReader();for(;;){const{value:e,done:n}=await t.read();if(n)break;this.accumulatedText+=e,this.handles.size!==0&&this.parseCurrentArgs(e)&&this.updateHandles()}}catch(t){this.failure={reason:t}}finally{this.finished=!0;for(const t of this.handles)this.settleHandle(t);this.handles.clear()}}settleHandle(t){this.failure?t.error(this.failure.reason):t.end(this.args)}parseCurrentArgs(t){if(this.parser?.currentTextLength===this.accumulatedText.length)return!1;const e=this.args;return this.parser?t!==void 0&&this.parser.currentTextLength+t.length===this.accumulatedText.length?this.parser=this.parser.append(t):this.parser=uc.from(this.accumulatedText,this.args):this.parser=uc.from(this.accumulatedText,this.args),this.args=this.parser.currentArgs,this.args!==e}updateHandles(){for(const t of this.handles)t.update(this.args),t.isDisposed&&this.handles.delete(t)}activateHandle(t){if(this.parseCurrentArgs(),t.update(this.args),!t.isDisposed){if(this.finished){this.settleHandle(t);return}this.handles.add(t)}}get(...t){return new Promise((e,n)=>{const r=new jv(e,n,t);this.activateHandle(r)})}streamValues(...t){const e=t;let n;const r=new ReadableStream({start:s=>{n=new zv(s,e),this.activateHandle(n)},cancel:()=>{n&&(n.dispose(),this.handles.delete(n))}});return pi(r)}streamText(...t){const e=t;let n;const r=new ReadableStream({start:s=>{n=new Vv(s,e),this.activateHandle(n)},cancel:()=>{n&&(n.dispose(),this.handles.delete(n))}});return pi(r)}forEach(...t){const e=t;let n;const r=new ReadableStream({start:s=>{n=new Uv(s,e),this.activateHandle(n)},cancel:()=>{n&&(n.dispose(),this.handles.delete(n))}});return pi(r)}},Hv=class{promise;constructor(t){this.promise=t}get(){return this.promise}},Wv=class{args;response;writable;resolve;argsText="";constructor(){const t=new TransformStream;this.writable=t.writable,this.args=new qv(t.readable);const{promise:e,resolve:n}=sn();this.resolve=n,this.response=new Hv(e)}async appendArgsTextDelta(t){const e=this.writable.getWriter();try{await e.write(t)}catch(n){console.warn(n)}finally{e.releaseLock()}this.argsText+=t}async finishArgsText(){const t=this.writable.getWriter();try{await t.close()}catch(e){console.warn(e)}finally{t.releaseLock()}}setResponse(t){this.resolve(t)}result={get:async()=>(await this.response.get()).result}};const Gv=Symbol.for("assistant-stream.tool-execution-id"),_i=(t,e,n,r,s)=>{try{const i=e?.(n,r,s);Promise.resolve(i).catch(o=>{console.error(`[assistant-stream] ${t} callback threw an error`,o)})}catch(i){console.error(`[assistant-stream] ${t} callback threw an error`,i)}},sr=t=>t.join(","),vi=(t,e)=>{const n={...t};return Object.defineProperty(n,Gv,{value:e,enumerable:!0}),n};var Kv=class extends Nv{constructor(t){const e=t,n=new Map,r=new Map,s=new Set,i=new Set,o=new Set,a=new Map,l=new Map,c=new Map;let u=!1,d=0;const f=(p,m,y)=>{const g=m?n.get(m):void 0,b=()=>{m&&(n.delete(m),r.delete(m),s.delete(m),i.delete(m),o.delete(m),a.delete(sr(p.path)))};g?g.then(()=>{b(),Je(y,p)}):(b(),y.enqueue(p))},h=p=>{for(const[m,y]of[...l]){l.delete(m),!i.has(m)&&!s.has(m)&&y();const g=c.get(m);g&&(c.delete(m),f(g,m,p))}};super(p=>{const m=new TransformStream({async transform(y,g){const b=a.get(sr(y.path));switch(y.type==="step-start"&&(u=!0),(y.type==="step-finish"||y.type==="message-finish")&&(u=!1,h(g)),(y.type!=="part-finish"||y.meta.type!=="tool-call")&&g.enqueue(b?vi(y,b):y),y.type){case"part-start":{const v=d;if(d+=1,y.part.type==="tool-call"){const w=new Wv,k=Symbol();a.set(String(v),k),r.set(k,w),y.part.providerExecuted&&o.add(k);const _=e.streamCall({reader:w,toolCallId:y.part.toolCallId,toolName:y.part.toolName,executionId:k});_&&Promise.resolve(_).catch(A=>{console.error("[assistant-stream] streamCall callback threw an error",A)})}break}case"text-delta":if(y.meta.type==="tool-call"){const v=a.get(sr(y.path)),w=v?r.get(v):void 0;if(!w)throw new Error("No controller found for tool call");await w.appendArgsTextDelta(y.textDelta)}break;case"result":{if(y.meta.type!=="tool-call")break;const v=a.get(sr(y.path)),w=v?r.get(v):void 0;if(!w)throw new Error("No controller found for tool call");if(s.add(v),y.isPreliminary)break;w.setResponse(new Pt({result:y.result,artifact:y.artifact,isError:y.isError,modelContent:y.modelContent,messages:y.messages}));break}case"tool-call-args-text-finish":{if(y.meta.type!=="tool-call")break;const{toolCallId:v,toolName:w}=y.meta,k=a.get(sr(y.path)),_=k?r.get(k):void 0;if(!_)throw new Error("No controller found for tool call");if(await _.finishArgsText(),s.has(k)||i.has(k)||o.has(k))break;const A=()=>{let E=!1;const D=Bv(()=>{let x;try{x=po.parse(_.argsText)}catch(P){throw new Error(`Function parameter parsing failed. ${JSON.stringify(P.message)}`)}const M=e.execute({toolCallId:v,toolName:w,args:x,executionId:k});return M!==void 0&&(E=!0,_i("onExecutionStart",e.onExecutionStart,v,w,k)),M},x=>{if(E&&_i("onExecutionEnd",e.onExecutionEnd,v,w,k),x===void 0)return;const M=new Pt({artifact:x.artifact,result:x.result,isError:x.isError,messages:x.messages,modelContent:x.modelContent});_.setResponse(M),Je(g,vi({type:"result",path:y.path,...M},k))},x=>{E&&_i("onExecutionEnd",e.onExecutionEnd,v,w,k);const M=new Pt({result:String(x),isError:!0});_.setResponse(M),Je(g,vi({type:"result",path:y.path,...M},k))});D&&n.set(k,D)};u?l.set(k,A):A();break}case"tool-call-approval":if(y.meta.type!=="tool-call"||!b)break;i.add(b);break;case"part-finish":if(y.meta.type!=="tool-call")break;if(b&&l.has(b)){c.set(b,y);break}f(y,b,g)}},async flush(y){h(y),await Promise.all(n.values())}});return p.pipeThrough(new Ch).pipeThrough(m)})}};const Bh=Symbol.for("assistant-stream.tool-execution-id"),Ts=Symbol("assistant-stream.tool-aborted"),Qv=t=>typeof t=="object"&&t!==null&&"~standard"in t&&t["~standard"].version===1,Yv=t=>typeof t?.then=="function",vc=async(t,e,n=!1)=>{let r;const s=new Promise(i=>{r=()=>{n?queueMicrotask(()=>queueMicrotask(()=>i(Ts))):i(Ts)},e.aborted?r():e.addEventListener("abort",r,{once:!0})});try{return await Promise.race([t,s])}finally{e.removeEventListener("abort",r)}},Kr=()=>new Pt({result:"Tool execution was cancelled.",isError:!0}),Jv=t=>new Pt({result:`Tool "${t}" is disabled.`,isError:!0});function Xv(t,e,n,r){const s=t?.[n.toolName];return s?.disabled&&(s.type==="frontend"||s.execute||s.streamCall)?Promise.resolve(Jv(n.toolName)):s?.execute?(async o=>{if(e.aborted)return Kr();let a=o,l=n.args;if(Qv(s.parameters)){const d=s.parameters["~standard"].validate(n.args),f=Yv(d)?await vc(d,e):d;if(f===Ts)return Kr();f.issues?a=s.experimental_onSchemaValidationError??(()=>{throw new Error(`Function parameter validation failed. ${JSON.stringify(f.issues)}`)}):l=f.value}if(e.aborted)return Kr();const c=(async()=>{const d={toolCallId:n.toolCallId,abortSignal:e,human:p=>r(n.toolCallId,p,n.executionId),[Bh]:n.executionId},f=await a(l,d),h=Pt.toResponse(f);if(s.toModelOutput&&!h.isError&&h.modelContent===void 0)try{const p=await s.toModelOutput({toolCallId:n.toolCallId,input:l,output:h.result});return new Pt({result:h.result,artifact:h.artifact,isError:h.isError,messages:h.messages,modelContent:p})}catch(p){console.warn(`[assistant-stream] tool "${n.toolName}" toModelOutput threw; falling back to default projection.`,p)}return h})(),u=await vc(c,e,!0);return u===Ts?Kr():u})(s.execute):void 0}function Zv(t,e,n,r,s){const i={toolCallId:r.toolCallId,abortSignal:e,human:a=>s(r.toolCallId,a,r.executionId),[Bh]:r.executionId},o=t?.[r.toolName];if(!o?.disabled)return o?.streamCall?.(n,i)}function ew(t,e,n,r){const s=typeof t=="function"?t:()=>t,i=typeof e=="function"?e:()=>e,o=r,a=n,l={execute:c=>Xv(s(),i(),c,a),streamCall:({reader:c,...u})=>Zv(s(),i(),c,u,a),onExecutionStart:o?.onExecutionStart,onExecutionEnd:o?.onExecutionEnd};return new Kv(l)}var wc=class{get path(){return this.contentBinding.path}contentBinding;messageApi;threadApi;interactionState;interactionMessageId;interactionThreadId;interactionCore;constructor(t,e,n){this.contentBinding=t,this.messageApi=e,this.threadApi=n,this.interactionState=t.getState(),this.interactionMessageId=this.interactionState.type==="tool-call"?e?.getState().id:void 0,this.interactionThreadId=this.interactionState.type==="tool-call"?this.threadApi?.getStateState?.().threadId:void 0,this.interactionCore=this.interactionState.type==="tool-call"?n?.getState():void 0,this.__internal_bindMethods()}__internal_bindMethods(){this.addToolResult=this.addToolResult.bind(this),this.resumeToolCall=this.resumeToolCall.bind(this),this.respondToToolApproval=this.respondToToolApproval.bind(this),this.unstable_recordInteraction=this.unstable_recordInteraction.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this.contentBinding.getState()}getInteractionCore(){const t=this.interactionThreadId!==void 0&&this.threadApi?.getStateState?.().threadId===this.interactionThreadId?this.threadApi.getState():this.interactionCore;if(!t)throw new Error("Thread API is not available");return t}addToolResult(t){const e=this.interactionState;if(e.type!=="tool-call")throw new Error("Tried to add tool result to non-tool message part");if(!this.messageApi)throw new Error("Message API is not available. This is likely a bug in assistant-ui.");if(!this.threadApi)throw new Error("Thread API is not available");const n=this.interactionMessageId;if(n===void 0)throw new Error("Message is not available");const r=e.toolName,s=e.toolCallId,i=Pt.toResponse(t);this.getInteractionCore().addToolResult({messageId:n,toolName:r,toolCallId:s,result:i.result,isError:i.isError,...i.artifact!==void 0&&{artifact:i.artifact},...i.modelContent!==void 0&&{modelContent:i.modelContent}})}resumeToolCall(t){const e=this.interactionState;if(e.type!=="tool-call")throw new Error("Tried to resume tool call on non-tool message part");if(!this.threadApi)throw new Error("Thread API is not available");this.getInteractionCore().resumeToolCall({toolCallId:e.toolCallId,payload:t}),this.unstable_recordInteraction({type:"human-response",payload:t}).catch(()=>{})}respondToToolApproval(t){const e=this.interactionState;if(e.type!=="tool-call")throw new Error("Tried to respond to tool approval on non-tool message part");if(!this.threadApi)throw new Error("Thread API is not available");const n=this.getInteractionCore(),r=this.interactionMessageId===void 0?void 0:n.getMessageById(this.interactionMessageId)?.message.content.find(i=>i.type==="tool-call"&&i.toolCallId===e.toolCallId),s=r?.type==="tool-call"?r.approval:void 0;if(!s||s.approved!==void 0||s.resolution!==void 0)throw new Error("Tool call has no pending approval");return n.respondToToolApproval(Av(s,t))}async unstable_recordInteraction(t){const e=this.interactionState;if(e.type!=="tool-call")throw new Error("Tried to record interaction on non-tool message part");const n=this.interactionMessageId;if(n===void 0)throw new Error("Message is not available");const r=this.getInteractionCore();if(!r.unstable_recordToolInteraction)throw new Error("Runtime does not support recording tool interactions.");await r.unstable_recordToolInteraction({messageId:n,toolCallId:e.toolCallId,interaction:$_(t)})}subscribe(t){return this.contentBinding.subscribe(t)}};const tw=["critical","warning","info"],nw=["inline","toast","silent","dev-only"],rw=t=>{if(typeof t!="object"||t===null)return!1;const e=t;return!(typeof e.code!="string"||typeof e.message!="string"||"statusCode"in e&&e.statusCode!==void 0&&typeof e.statusCode!="number"||"severity"in e&&e.severity!==void 0&&(typeof e.severity!="string"||!tw.includes(e.severity))||"display"in e&&e.display!==void 0&&(typeof e.display!="string"||!nw.includes(e.display)))},jh=Symbol.for("assistant-ui.message-not-sent");var wi=class extends Error{[jh]=!0;constructor(t="The message was not sent."){super(t),this.name="MessageNotSentError"}};const Pa=t=>typeof t=="object"&&t!==null&&jh in t,ir=t=>{if(rw(t))return t;if(t instanceof Error)return{code:"unknown",message:t.message};if(typeof t=="string")return{code:"unknown",message:t};try{return{code:"unknown",message:`[${typeof t}] ${String(t)}`}}catch{return{code:"unknown",message:`[${typeof t}]`}}},Ks=(t,e)=>{Promise.resolve(e).catch(n=>{Pa(n)||console.error(`[assistant-ui] ${t} failed`,n)})},xc=(t,e)=>{const n=t.content[e];if(!n)return ot;const r=Eh(t,e,n);return Object.freeze({...n,[mn]:n[mn],status:r})};var sw=class{get path(){return this._core.path}_core;_threadBinding;constructor(t,e){this._core=t,this._threadBinding=e,this.composer=new $v(new _s({path:{...this.path,ref:`${this.path.ref}.composer`,composerSource:"edit"},getState:this._getEditComposerRuntimeCore,subscribe:n=>this._threadBinding.subscribe(n)}),()=>this._threadBinding.getState().beginEdit(this._core.getState().id)),this.__internal_bindMethods()}__internal_bindMethods(){this.reload=this.reload.bind(this),this.delete=this.delete.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.getMessagePartByIndex=this.getMessagePartByIndex.bind(this),this.getMessagePartByToolCallId=this.getMessagePartByToolCallId.bind(this),this.getAttachmentByIndex=this.getAttachmentByIndex.bind(this),this.unstable_getCopyText=this.unstable_getCopyText.bind(this),this.speak=this.speak.bind(this),this.stopSpeaking=this.stopSpeaking.bind(this),this.submitFeedback=this.submitFeedback.bind(this),this.switchToBranch=this.switchToBranch.bind(this)}composer;_getEditComposerRuntimeCore=()=>this._threadBinding.getState().getEditComposer(this._core.getState().id);getState(){return this._core.getState()}delete(){const t=this._core.getState();return this._threadBinding.getState().deleteMessage(t.id)}reload(t={}){const e=this._getEditComposerRuntimeCore(),n=e??this._threadBinding.getState().composer,r=e??n,{runConfig:s=r.runConfig}=t,i=this._core.getState();if(i.role!=="assistant")throw new Error("Can only reload assistant messages");Ks("Message reload",this._threadBinding.getState().startRun({parentId:i.parentId,sourceId:i.id,runConfig:s}))}speak(){const t=this._core.getState();return this._threadBinding.getState().speak(t.id)}stopSpeaking(){const t=this._core.getState();if(this._threadBinding.getState().speech?.messageId===t.id)this._threadBinding.getState().stopSpeaking();else throw new Error("Message is not being spoken")}submitFeedback({type:t,comment:e}){const n=this._core.getState();this._threadBinding.getState().submitFeedback({messageId:n.id,type:t,...e!==void 0?{comment:e}:void 0})}switchToBranch({position:t,branchId:e}){const n=this._core.getState();if(e&&t)throw new Error("May not specify both branchId and position");if(!e&&!t)throw new Error("Must specify either branchId or position");const r=this._threadBinding.getState().getBranches(n.id);let s=e;if(t==="previous"?s=r[n.branchNumber-2]:t==="next"&&(s=r[n.branchNumber]),!s)throw new Error("Branch not found");this._threadBinding.getState().switchToBranch(s)}unstable_getCopyText(){return un(this.getState())}subscribe(t){return this._core.subscribe(t)}getMessagePartByIndex(t){if(t<0)throw new Error("Message part index must be >= 0");return new wc(new Xe({path:{...this.path,ref:`${this.path.ref}.content[${t}]`,messagePartSelector:{type:"index",index:t}},getState:()=>xc(this.getState(),t),subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getMessagePartByToolCallId(t){return new wc(new Xe({path:{...this.path,ref:`${this.path.ref}.content[toolCallId=${JSON.stringify(t)}]`,messagePartSelector:{type:"toolCallId",toolCallId:t}},getState:()=>{const e=this._core.getState(),n=e.content.findIndex(r=>r.type==="tool-call"&&r.toolCallId===t);return n===-1?ot:xc(e,n)},subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getAttachmentByIndex(t){return new Dv(new Xe({path:{...this.path,ref:`${this.path.ref}.attachments[${t}]`,attachmentSource:"message",attachmentSelector:{type:"index",index:t}},getState:()=>{const e=this.getState().attachments?.[t];return e?{...e,source:"message"}:ot},subscribe:e=>this._core.subscribe(e)}))}};const iw=(t,e)=>typeof e=="string"?{createdAt:new Date,parentId:t.at(-1)?.id??null,sourceId:null,runConfig:{},role:"user",content:[{type:"text",text:e}],attachments:[],metadata:{custom:{}}}:{createdAt:e.createdAt??new Date,parentId:e.parentId===void 0?t.at(-1)?.id??null:e.parentId,sourceId:e.sourceId??null,role:e.role??"user",content:e.content,attachments:e.attachments??[],metadata:e.metadata??{custom:{}},runConfig:e.runConfig??{},startRun:e.startRun},ow=t=>({parentId:t.parentId??null,sourceId:t.sourceId??null,runConfig:t.runConfig??{},...t.stream?{stream:t.stream}:{}}),aw=t=>({parentId:t.parentId??null,sourceId:t.sourceId??null,runConfig:t.runConfig??{}}),Qs=t=>{if(t.isRunning!==void 0)return t.isRunning;const e=t.messages.at(-1);return e?.role==="assistant"&&e.status.type==="running"},lw=(t,e)=>Object.freeze({threadId:e.id,metadata:e,capabilities:t.capabilities,isDisabled:t.isDisabled,isSendDisabled:t.isSendDisabled,isLoading:t.isLoading,hasEarlier:t.hasEarlier??!1,isLoadingEarlier:t.isLoadingEarlier??!1,isRunning:Qs(t),canResume:t.canResume??!1,messages:t.messages,state:t.state,suggestions:t.suggestions,extras:t.extras,speech:t.speech,voice:t.voice});var zh=class{get path(){return this._threadBinding.path}get __internal_threadBinding(){return this._threadBinding}_threadBinding;_stateBinding;constructor(t,e){const n=new Xe({path:t.path,getState:()=>lw(t.getState(),e.getState()),subscribe:r=>{const s=t.subscribe(r),i=e.subscribe(r);return()=>Gn([s,i])}});this._stateBinding=n,this._threadBinding={path:t.path,getState:()=>t.getState(),getStateState:()=>n.getState(),outerSubscribe:r=>t.outerSubscribe(r),subscribe:r=>t.subscribe(r)},this.composer=new Fv(new _s({path:{...this.path,ref:`${this.path.ref}.composer`,composerSource:"thread"},getState:()=>this._threadBinding.getState().composer,subscribe:r=>this._threadBinding.subscribe(r)})),this.__internal_bindMethods()}__internal_bindMethods(){this.append=this.append.bind(this),this.deleteMessage=this.deleteMessage.bind(this),this.resumeRun=this.resumeRun.bind(this),this.loadEarlier=this.loadEarlier.bind(this),this.importExternalState=this.importExternalState.bind(this),this.exportExternalState=this.exportExternalState.bind(this),this.startRun=this.startRun.bind(this),this.cancelRun=this.cancelRun.bind(this),this.unstable_notifySessionReset=this.unstable_notifySessionReset.bind(this),this.stopSpeaking=this.stopSpeaking.bind(this),this.connectVoice=this.connectVoice.bind(this),this.disconnectVoice=this.disconnectVoice.bind(this),this.muteVoice=this.muteVoice.bind(this),this.unmuteVoice=this.unmuteVoice.bind(this),this.getVoiceVolume=this.getVoiceVolume.bind(this),this.subscribeVoiceVolume=this.subscribeVoiceVolume.bind(this),this.export=this.export.bind(this),this.import=this.import.bind(this),this.reset=this.reset.bind(this),this.getMessageByIndex=this.getMessageByIndex.bind(this),this.getMessageById=this.getMessageById.bind(this),this.subscribe=this.subscribe.bind(this),this.unstable_on=this.unstable_on.bind(this),this.getModelContext=this.getModelContext.bind(this),this.getState=this.getState.bind(this)}composer;getState(){return this._threadBinding.getStateState()}append(t){Ks("Message append",this._threadBinding.getState().append(iw(this._threadBinding.getState().messages,t)))}deleteMessage(t){return this._threadBinding.getState().deleteMessage(t)}subscribe(t){return this._stateBinding.subscribe(t)}getModelContext(){return this._threadBinding.getState().getModelContext()}startRun(t){return this._threadBinding.getState().startRun(aw(t))}resumeRun(t){return this._threadBinding.getState().resumeRun(ow(t))}exportExternalState(){return this._threadBinding.getState().exportExternalState()}importExternalState(t){this._threadBinding.getState().importExternalState(t)}cancelRun(){this._threadBinding.getState().cancelRun()}loadEarlier(){return this._threadBinding.getState().loadEarlier?.()??Promise.resolve()}unstable_notifySessionReset(){this._threadBinding.getState().unstable_notifySessionReset()}stopSpeaking(){return this._threadBinding.getState().stopSpeaking()}connectVoice(){this._threadBinding.getState().connectVoice()}disconnectVoice(){this._threadBinding.getState().disconnectVoice()}getVoiceVolume(){return this._threadBinding.getState().getVoiceVolume()}subscribeVoiceVolume(t){return this._threadBinding.getState().subscribeVoiceVolume(t)}muteVoice(){this._threadBinding.getState().muteVoice()}unmuteVoice(){this._threadBinding.getState().unmuteVoice()}export(){return this._threadBinding.getState().export()}import(t){this._threadBinding.getState().import(t)}reset(t){this._threadBinding.getState().reset(t)}getMessageByIndex(t){if(t<0)throw new Error("Message index must be >= 0");return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[${t}]`,messageSelector:{type:"index",index:t}},()=>{const e=this._threadBinding.getState().messages,n=e[t];if(n)return{message:n,parentId:e[t-1]?.id??null,index:t}})}getMessageById(t){return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[messageId=${JSON.stringify(t)}]`,messageSelector:{type:"messageId",messageId:t}},()=>this._threadBinding.getState().getMessageById(t))}_getMessageRuntime(t,e){return new sw(new Xe({path:t,getState:()=>{const{message:n,parentId:r,index:s}=e()??{},{messages:i,speech:o}=this._threadBinding.getState();if(!n||r===void 0||s===void 0)return ot;const a=this._threadBinding.getState().getBranches(n.id);return{...n,[mn]:n[mn],index:s,isLast:i.at(-1)?.id===n.id,parentId:r,branchNumber:a.indexOf(n.id)+1,branchCount:a.length,speech:o?.messageId===n.id?o:void 0}},subscribe:n=>this._threadBinding.subscribe(n)}),this._threadBinding)}_eventSubscriptionSubjects=new Map;unstable_on(t,e){let n=this._eventSubscriptionSubjects.get(t);return n||(n=new ph({event:t,binding:this._threadBinding,notifyOnRebind:t==="modelContextUpdate"}),this._eventSubscriptionSubjects.set(t,n)),n.subscribe(e)}};const Cr=Object.freeze([]);var cw=class{operations=new Set;uploading=new Map;start(){const t={cancelled:!1,attachmentIds:new Set};return this.operations.add(t),t}accept(t,e){if(t.cancelled)return!1;t.attachmentIds.add(e.id);const n=this.uploading.get(e.id);return n?.operation!==t&&(n||e.status.type==="running")&&this.uploading.set(e.id,{operation:t,waiters:n?.waiters??new Set}),e.status.type!=="running"&&this.settle(e.id,t),!0}finish(t){this.operations.delete(t);for(const e of t.attachmentIds)this.settle(e,t)}isCancelled(t){return t.cancelled}cancel(t){for(const e of[...this.operations])e.attachmentIds.has(t)&&(e.cancelled=!0,this.operations.delete(e));this.settle(t)}cancelAll(t){for(const e of[...this.operations])t&&[...e.attachmentIds].some(n=>t.has(n))||(e.cancelled=!0,this.operations.delete(e));for(const e of[...this.uploading.keys()])t?.has(e)||this.settle(e)}whenSendable(t){const e=this.uploading.get(t);if(e)return new Promise(n=>e.waiters.add(n))}settle(t,e){const n=this.uploading.get(t);if(n&&!(e&&n.operation!==e)){this.uploading.delete(t);for(const r of n.waiters)r()}}};const uw=async(t,e)=>{if(Symbol.asyncIterator in t){let n,r=!1;for await(const s of t){if(n===void 0&&(n=s.id),s.id!==n){r||(console.warn("[assistant-ui] AttachmentAdapter.add() yielded multiple attachment ids; only the first id is accepted"),r=!0);continue}if(!e(s))break}}else e(await t)};var dw=class{entries=new WeakMap;removals=new WeakMap;beginRemoval(t){const e=this.removals.get(t);return e?.phase==="pending"?!1:(e?e.phase="pending":this.removals.set(t,{phase:"pending",dispatched:!1,retried:!1,abandoned:!1}),!0)}abandonRemoval(t){const e=this.removals.get(t);e&&(e.abandoned=!0),this.removals.delete(t)}isRemoved(t){return this.removals.has(t)}shouldRemoveOnClear(t){const e=this.removals.get(t);return!e||e.dispatched&&e.retried&&e.phase==="failed"}isRemovalPending(t){return this.removals.get(t)?.phase==="pending"}async remove(t,e,n){const r=this.removals.get(t);try{if(!ht(t)){if(!e)throw new Error("Attachments are not supported");await e.remove(t)}r.phase="complete"}catch(s){throw r.phase="failed",n?.(s,s instanceof Error?s.message:String(s)),this.retryDispatched(r),s}}dispatchRemoval(t,e){const n=this.removals.get(t);n&&(n.dispatched=!0,n.retry=e,this.retryDispatched(n))}retryDispatched(t){t.abandoned||!t.dispatched||t.phase!=="failed"||t.retried||!t.retry||(t.retried=!0,t.retry())}restore(t){const e=this.removals.get(t);if(!e||e.dispatched||e.phase!=="failed")return t;const n={...t},r=this.entries.get(t);return r&&this.entries.set(n,r),n}restoreUnsent(t){const e=this.removals.get(t);if(!(e?.dispatched||e?.phase==="complete"))return this.restore(t)}adoptFrom(t,e){const n=t.removals.get(e);n&&this.removals.set(e,n);const r=t.entries.get(e);r&&this.entries.set(e,r)}isSameRemoval(t,e){const n=this.removals.get(t);return n!==void 0&&n===this.removals.get(e)}reconcileFailures(t,e,n){const r=new Map;return n.forEach((s,i)=>{s.status==="rejected"&&r.set(e[i].id,s.reason)}),t.map(s=>{if(!r.has(s.id)||ht(s)||this.isRemoved(s))return s;const i=r.get(s.id);return this.transfer(s,{...s,status:{type:"incomplete",reason:"error",message:i instanceof Error?i.message:String(i)}})})}async send(t,e,n){if(ht(t))return t;const r=this.entries.get(t)??{};if(r.result)return r.result;if(!e)throw new Error("Attachments are not supported");this.entries.set(t,r);const s=await e.send(t,n?{signal:n}:void 0);return r.result=s,s}transfer(t,e){const n=this.entries.get(t);n&&this.entries.set(e,n);const r=this.removals.get(t);return r&&this.removals.set(e,r),e}};const hw=(t,e,n=()=>!0)=>{const r=new Set,s=new Set;for(const i of t){const o=e(i)?.find(a=>!i.known.has(a)&&!r.has(a)&&n(i,a));o!==void 0&&(r.add(o),s.add(i))}return{landed:s,claimed:r}},fw=(t,e)=>t.filter(n=>!e.landed.has(n)).map(n=>({...n,known:new Set([...n.known,...e.claimed])}));var pw=class{_host;constructor(t){this._host=t}rebase(t){if(!this._dictation)return;this._dictationBaseText=t,this._currentInterimText="";const{status:e,inputDisabled:n}=this._dictation;this._dictation=n?{status:e,inputDisabled:n}:{status:e}}cancel(){if(!this._dictationSession)return;const t=this._activeDictationSessionId;this._cancellingSessionId=t;let e={reason:"cancelled"};try{this._dictationSession.cancel()}catch(n){e={reason:"error",error:ir(n)},console.error("[assistant-ui] Dictation session cancel threw",n)}finally{this._cleanupDictation({sessionId:t,end:e})}}_dictation;_dictationSession;_stoppingDictationSession;_dictationUnsubscribes=[];_dictationBaseText="";_currentInterimText="";_dictationSessionIdCounter=0;_activeDictationSessionId;_isCleaningDictation=!1;_lastDictationEnd;_cancellingSessionId;get dictation(){return this._dictation}get lastDictationEnd(){return this._lastDictationEnd}_isActiveSession(t,e){return this._activeDictationSessionId===t&&this._dictationSession===e}startDictation(){const t=this._host.getAdapter();if(!t)throw new Error("Dictation adapter not configured");if(this._dictationSession){const i=this._dictationSession;this._cleanupDictation({notify:!1}),this._stopDictationSession(i)}const e=t.disableInputDuringDictation??!1;this._dictationBaseText=this._host.getText(),this._currentInterimText="";const n=++this._dictationSessionIdCounter;this._activeDictationSessionId=n;const r=[],s=()=>{for(const i of r.splice(0))try{i()}catch(o){console.error("[assistant-ui] Dictation cleanup threw",o)}};this._lastDictationEnd=void 0;try{const i=t.listen();if(this._activeDictationSessionId!==n){this._stopDictationSession(i);return}this._dictationSession=i,this._dictation={status:i.status,inputDisabled:e};try{this._host.notify()}catch(l){console.error("[assistant-ui] Dictation start notification threw",l)}if(!this._isActiveSession(n,i))return;const o=l=>(r.push(l),this._isActiveSession(n,i)?!0:(s(),!1));if(!o(i.onSpeech(l=>{if(!this._isActiveSession(n,i))return;const c=l.isFinal!==!1,u=this._dictationBaseText&&!this._dictationBaseText.endsWith(" ")&&l.transcript?" ":"";if(c){if(this._dictationBaseText=this._dictationBaseText+u+l.transcript,this._currentInterimText="",this._host.setText(this._dictationBaseText),this._dictation){const{transcript:d,...f}=this._dictation;this._dictation=f}this._host.notify()}else this._currentInterimText=u+l.transcript,this._host.setText(this._dictationBaseText+this._currentInterimText),this._dictation&&(this._dictation={...this._dictation,transcript:l.transcript}),this._host.notify()}))||!o(i.onSpeechStart(()=>{this._isActiveSession(n,i)&&(this._dictation={status:{type:"running"},inputDisabled:e,...this._dictation?.transcript&&{transcript:this._dictation.transcript}},this._host.notify())}))||!o(i.onSpeechEnd(()=>{this._cancellingSessionId!==n&&this._cleanupDictation({sessionId:n,end:{reason:"stopped"}})})))return;const a=setInterval(()=>{this._isActiveSession(n,i)&&i.status.type==="ended"&&this._cleanupDictation({sessionId:n,end:{reason:"stopped"}})},100);if(!o(()=>clearInterval(a)))return;this._dictationUnsubscribes.push(...r.splice(0))}catch(i){if(s(),this._activeDictationSessionId===n){const o=this._dictationSession;this._cleanupDictation({sessionId:n,end:{reason:"error",error:ir(i)}});try{o?.cancel()}catch(a){console.error("[assistant-ui] Dictation session cancel threw",a)}}throw i}}stopDictation(){if(!this._dictationSession)return;const t=this._dictationSession;if(this._stoppingDictationSession===t)return;this._stoppingDictationSession=t;const e=this._activeDictationSessionId,n=r=>this._cleanupDictation({sessionId:e,end:r});this._stopDictationSession(t,n)}_stopDictationSession(t,e=()=>{}){let n;try{n=t.stop()}catch(r){console.error("[assistant-ui] Dictation session stop threw",r),e({reason:"error",error:ir(r)});return}n.then(()=>e({reason:"stopped"}),r=>{console.error("[assistant-ui] Dictation session stop rejected",r),e({reason:"error",error:ir(r)})})}_cleanupDictation(t){if(t?.sessionId!==void 0&&t.sessionId!==this._activeDictationSessionId||this._isCleaningDictation||this._activeDictationSessionId===void 0)return;this._isCleaningDictation=!0;const e=n=>{try{n()}catch(r){console.error("[assistant-ui] Dictation cleanup threw",r)}};try{let n=t?.end;n!==void 0&&(e(()=>{const s=this._dictationSession?.status;s?.type==="ended"&&(n=s.error===void 0?{reason:s.reason}:{reason:s.reason,error:ir(s.error)})}),this._lastDictationEnd=n),this._cancellingSessionId=void 0;const r=this._dictationUnsubscribes;this._dictationUnsubscribes=[],this._dictationSession=void 0,this._stoppingDictationSession=void 0,this._activeDictationSessionId=void 0,this._dictation=void 0,this._dictationBaseText="",this._currentInterimText="";for(const s of r)e(s);t?.notify!==!1&&e(()=>this._host.notify())}finally{this._isCleaningDictation=!1}}},vo=class extends Ia{isEditing=!0;enrichWithComposerMetadata(t,e){return e?{...t,metadata:{...t.metadata,custom:{...t.metadata?.custom,...e}}}:t}get attachmentAccept(){return this.getAttachmentAdapter()?.accept??"*"}_attachments=[];get attachments(){return this._attachments}setAttachments(t){this._attachments=t,this._notifySubscribers()}get isEmpty(){return!this.text.trim()&&!this.sendableAttachments.length}get sendableAttachments(){return this.attachments.filter(t=>!this._attachmentSends.isRemoved(t))}_text="";_dictationSessionController=new pw({getAdapter:()=>this.getDictationAdapter(),getText:()=>this._text,setText:t=>this._writeText(t,"user"),notify:()=>this._notifySubscribers()});get text(){return this._text}_role="user";get role(){return this._role}_runConfig={};get runConfig(){return this._runConfig}_quote=void 0;get quote(){return this._quote}setQuote(t){this._quote!==t&&(this._quote=t,this._notifySubscribers())}setText(t,e){this._text!==t&&(this._writeText(t,e?.origin??"external"),this._rebaseDictation(t),this._notifySubscribers())}_pendingTextChanges=[];_isFlushingTextChanges=!1;_notifyDepth=0;_writeText(t,e){this._text!==t&&(this._text=t,this._pendingTextChanges.push({text:t,origin:e}))}_notifySubscribers(){this._notifyDepth++;try{super._notifySubscribers()}finally{--this._notifyDepth===0&&this._flushTextChanges()}}_flushTextChanges(){if(!this._isFlushingTextChanges){this._isFlushingTextChanges=!0;for(let t=this._pendingTextChanges.shift();t;t=this._pendingTextChanges.shift())this._notifyEventSubscribers("textChange",t);this._isFlushingTextChanges=!1}}_rebaseDictation(t){this._dictationSessionController.rebase(t)}setRole(t){this._role!==t&&(this._role=t,this._notifySubscribers())}setRunConfig(t){this._runConfig!==t&&(this._runConfig=t,this._notifySubscribers())}_submission;_submissionSend;_inTransit=[];_inTransitSubmissions=[];_sendGeneration=0;_draftEpoch=0;_attachmentAddOperations=new cw;_attachmentSends=new dw;get submission(){return this._submission}get inTransit(){return this._inTransitSubmissions}get isSubmitting(){return this._submission!==void 0}get detachesDraftOnSend(){return!0}threadMessageIds(t){}settleInTransit(){if(this._inTransit.length===0)return;const t=hw(this._inTransit,e=>this.threadMessageIds(e.submission.role));t.landed.size!==0&&(this._setInTransit(fw(this._inTransit,t)),this._notifySubscribers())}_setInTransit(t){this._inTransit=t,this._inTransitSubmissions=t.map(e=>e.submission)}_leaveTransit(t){const e=this._inTransit.filter(n=>n.submission!==t);return e.length===this._inTransit.length?!1:(this._setInTransit(e),!0)}_cancelAttachmentAdd(t){this._attachmentAddOperations.cancel(t)}_cancelAllAttachmentAdds(){this._attachmentAddOperations.cancelAll()}_emptyTextAndAttachments(){this._attachments=[],this._writeText("","reset"),this._rebaseDictation(""),this._notifySubscribers()}_draftUploadsToRemove(){return this._attachments.filter(t=>!ht(t)&&this._attachmentSends.shouldRemoveOnClear(t))}async _onClearAttachments(t){const e=this.getAttachmentAdapter();e&&await Promise.all(t.map(n=>(this._attachmentSends.beginRemoval(n),this._attachmentSends.remove(n,e))))}async reset(){this._cancelAllAttachmentAdds(),this._draftEpoch++,this._sendGeneration++;const t=this._discardSubmission();if(this._attachments.length===0&&this._text===""&&this._role==="user"&&Object.keys(this._runConfig).length===0&&this._quote===void 0){await t;return}this._role="user",this._runConfig={},this._quote=void 0;const e=this._onClearAttachments(this._draftUploadsToRemove());this._emptyTextAndAttachments(),await Promise.all([e,t])}async clearAttachments(){this._draftEpoch++,this._attachmentAddOperations.cancelAll(this.detachesDraftOnSend?new Set(this._submission?.attachments.map(n=>n.id)):void 0);const t=this._draftUploadsToRemove();if(this.isSubmitting)for(const n of this._attachments)this._attachmentSends.beginRemoval(n);const e=this._onClearAttachments(t);this.setAttachments([]),await e}async send(t){if(!this.canSend||this.isSubmitting)return;this._dictationSessionController.cancel();const e=this.sendableAttachments;if(!this.text.trim()&&e.length===0)return;const n={id:Mt(),role:this.role,text:this.text,quote:this._quote,attachments:e},r={options:t,runConfig:this.runConfig},s=e.filter(ht),i=s.length===e.length;if(i||(this._submission=n,this._submissionSend={...r,controller:new AbortController}),this.detachesDraftOnSend){const a=new Set(e);this._attachments=this._attachments.filter(l=>!a.has(l)),this._writeText("","send"),this._rebaseDictation(""),this._quote=void 0}const o=++this._sendGeneration;if(this._notifySubscribers(),i){this._dispatch(o,n,s,r,!1);return}await this._prepareSubmission(o)}async _prepareSubmission(t){const e=this.getAttachmentAdapter(),n=(this._submission?.attachments??[]).flatMap(u=>{const d=this._attachmentAddOperations.whenSendable(u.id);return d?[d]:[]});if(n.length>0&&(await Promise.all(n),t!==this._sendGeneration))return;const r=this._submission,s=this._submissionSend;if(!r||!s)return;const i=r.attachments.filter(u=>!this._attachmentSends.isRemoved(u));for(const u of i)this._cancelAttachmentAdd(u.id);const o=await Promise.allSettled(i.map(u=>this._attachmentSends.send(u,e,s.controller.signal)));if(t!==this._sendGeneration)return;const a=o.find(u=>u.status==="rejected");if(a){this._returnSubmissionToDraft(i,o,a.reason);return}const l=o.flatMap((u,d)=>this._attachmentSends.isRemoved(i[d])||u.status==="rejected"?[]:[u.value]),c=this._submission??r;if(!c.text.trim()&&l.length===0){this._endSubmission(),this._returnToDraft(c);return}this._dispatch(t,c,l,s,!0)}_dispatch(t,e,n,r,s){const i={createdAt:new Date,role:e.role,content:e.text?[{type:"text",text:e.text}]:[],attachments:n,runConfig:r.runConfig,metadata:{custom:{...e.quote?{quote:e.quote}:{}}}},o={...e,attachments:n},a=new Map(e.attachments.filter(h=>!this._attachmentSends.isRemoved(h)).map((h,p)=>[h,n[p]])),l={...e,attachments:e.attachments.map(h=>a.get(h)??h)},c=this.queue.length;if(s){if(this._submission=void 0,this._submissionSend=void 0,!this.detachesDraftOnSend){const p=new Map(e.attachments.map((m,y)=>[m.id,l.attachments[y]]));this._attachments=this._attachments.map(m=>p.get(m.id)??m)}const h=this.threadMessageIds(e.role);h&&this._setInTransit([...this._inTransit,{submission:o,known:new Set(h)}])}const u=this.cleanupOwner,d=u._draftEpoch;let f;try{f=this.handleSend(i,r.options)}catch(h){console.error("[assistant-ui] Failed to send the message",h),this._leaveTransit(o),t===this._sendGeneration?this._returnToDraft(l):this._notifySubscribers();return}if(f&&f.catch(h=>{const p=this._leaveTransit(o);t===this._sendGeneration&&Pa(h)?this._returnToDraft(l):p&&this._notifySubscribers()}),s)for(const h of e.attachments)ht(h)||this._attachmentSends.dispatchRemoval(h,()=>void this._retrySubmittedRemoval(h,u,d));this._notifyEventSubscribers("send",{chars:e.text.length,attachments:n.length}),s&&(this.queue.length>c&&this._leaveTransit(o),this._notifySubscribers(),this.settleInTransit())}_returnSubmissionToDraft(t,e,n){const r=this._submission;if(!r)return;const s=this._attachmentSends.reconcileFailures(r.attachments,t,e);this._endSubmission(),this._returnToDraft({...r,attachments:s}),console.error("[assistant-ui] Failed to send attachments",n)}_endSubmission(){this._sendGeneration++,this._submission=void 0,this._submissionSend=void 0}__internal_dispose(){this._cancelAllAttachmentAdds(),this._submission&&(this._submissionSend?.controller.abort(),this._endSubmission(),this._notifySubscribers())}cancelSubmission(){const t=this._submission;t&&(this._submissionSend?.controller.abort(),this._endSubmission(),this._returnToDraft(t))}_returnToDraft(t){if(this.detachesDraftOnSend){const e=t.attachments.flatMap(r=>{const s=this._attachmentSends.restoreUnsent(r);return s?[s]:[]});this._attachments=[...e,...this._attachments];const n=[t.text,this._text].filter(Boolean).join(`
|
|
10
|
+
`);this._writeText(n,"return"),this._rebaseDictation(n),this._quote=this._quote??t.quote}else{const e=new Map(t.attachments.flatMap(n=>{const r=this._attachmentSends.restoreUnsent(n);return r?[[n.id,r]]:[]}));this._attachments=this._attachments.flatMap(n=>{const r=this._attachmentSends.restoreUnsent(n);return r?[e.get(n.id)??r]:[]})}this._notifySubscribers()}async _discardSubmission(){const t=this._submission;if(!t)return;this._submissionSend?.controller.abort(),this._endSubmission(),this._notifySubscribers();const e=this.getAttachmentAdapter();if(!e)return;const n=new Set(this._attachments.map(r=>r.id));await Promise.all(t.attachments.filter(r=>!ht(r)&&!n.has(r.id)&&!this._attachmentSends.isRemovalPending(r)).map(async r=>e.remove(r)))}restoreDraft(t){return this._text.trim()||this._quote!==void 0||this._attachments.length>0?!1:(this._writeText(t.text,"return"),this._rebaseDictation(t.text),this._quote=t.quote,this._attachments=t.attachments??[],this._notifySubscribers(),!0)}retractDraft(t){const e=t.attachments!==void 0?this._attachments===t.attachments:this._attachments.length===0;this._text!==t.text||this._quote!==t.quote||!e||(this._writeText("","send"),this._rebaseDictation(""),this._quote=void 0,this._attachments=[],this._notifySubscribers())}cancel(){this.detachesDraftOnSend||(this._dictationSessionController.cancel(),this.isSubmitting&&(this._submissionSend?.controller.abort(),this._endSubmission(),this._notifySubscribers())),this.handleCancel()}get queue(){return Cr}moveQueueItem(t,e){}removeQueueItem(t){}async addAttachment(t){if(Rv(t)){const i=this.getAttachmentAdapter();if(i&&!Nl({name:t.name,type:t.contentType??""},i.accept)){const a=`File type ${t.contentType||"unknown"} is not accepted. Accepted types: ${i.accept}`,l=new Error(a);throw this._safeEmitAttachmentAddError("not-accepted",a,void 0,l,t.contentType),l}const o={id:t.id??Mt(),type:t.type??"document",name:t.name,contentType:t.contentType,content:t.content,status:{type:"complete"}};this._attachments=[...this._attachments,o],this._notifySubscribers(),this._notifyEventSubscribers("attachmentAdd",{...o.contentType?{contentType:o.contentType}:void 0});return}const e=this.getAttachmentAdapter();if(!e){const i="Attachments are not supported",o=new Error(i);throw this._safeEmitAttachmentAddError("no-adapter",i,void 0,o,t.type),o}if(!Nl({name:t.name,type:t.type},e.accept)){const i=`File type ${t.type||"unknown"} is not accepted. Accepted types: ${e.accept}`,o=new Error(i);throw this._safeEmitAttachmentAddError("not-accepted",i,void 0,o,t.type),o}const n=this._attachmentAddOperations.start(),r=i=>{if(!this._attachmentAddOperations.accept(n,i))return!1;const o=this._submission,a=o?.attachments.some(c=>c.id===i.id)??!1;o&&a&&(this._submission={...o,attachments:o.attachments.map(c=>c.id===i.id?this._attachmentSends.transfer(c,i):c)});const l=this._attachments.findIndex(c=>c.id===i.id);return l!==-1?this._attachments=[...this._attachments.slice(0,l),i,...this._attachments.slice(l+1)]:a||(this._attachments=[...this._attachments,i]),this._notifySubscribers(),!0};let s;try{await uw(e.add({file:t}),i=>(s=i,r(i)))}catch(i){if(this._attachmentAddOperations.isCancelled(n))return;throw s&&r({...s,status:{type:"incomplete",reason:"error",message:i instanceof Error?i.message:String(i)}}),this._safeEmitAttachmentAddError("adapter-error",i instanceof Error?i.message:String(i),s?.id,i instanceof Error?i:void 0,s?.contentType||t.type),i}finally{this._attachmentAddOperations.finish(n)}this._attachmentAddOperations.isCancelled(n)||(s?.status.type==="incomplete"&&s.status.reason==="error"?this._safeEmitAttachmentAddError("adapter-error",s.status.message??"Attachment upload did not complete successfully.",s.id,void 0,s.contentType||t.type):this._notifyEventSubscribers("attachmentAdd",{...s?.contentType?{contentType:s.contentType}:t.type?{contentType:t.type}:void 0}))}_safeEmitAttachmentAddError(t,e,n,r,s){try{this._notifyEventSubscribers("attachmentAddError",{reason:t,message:e,...n!==void 0&&{attachmentId:n},...r!==void 0&&{error:r},...s?{contentType:s}:void 0})}catch(i){console.error("[assistant-ui] attachmentAddError subscriber threw:",i)}}async removeAttachment(t){const e=this._attachments.find(s=>s.id===t)??this._submission?.attachments.find(s=>s.id===t);if(!e)throw new Error("Attachment not found");const n=this.getAttachmentAdapter();if(!ht(e)&&!n)throw new Error("Attachments are not supported");if(!this._attachmentSends.beginRemoval(e))return;this._cancelAttachmentAdd(t),this._notifySubscribers(),await this._attachmentSends.remove(e,n,(s,i)=>{const o=l=>this._attachmentSends.transfer(l,{...l,status:{type:"incomplete",reason:"error",message:i}}),a=this._submission;a&&(this._submission={...a,attachments:a.attachments.map(l=>!ht(l)&&this._attachmentSends.isSameRemoval(l,e)?o(l):l)}),this._attachments.some(l=>this._attachmentSends.isSameRemoval(l,e))&&(this._attachments=this._attachments.map(l=>!ht(l)&&this._attachmentSends.isSameRemoval(l,e)?o(l):l),this._submission||(this._attachments=this._attachments.map(l=>this._attachmentSends.isSameRemoval(l,e)?this._attachmentSends.restore(l):l))),this._notifySubscribers()});const r=this._submission;r&&(this._submission={...r,attachments:r.attachments.filter(s=>!this._attachmentSends.isSameRemoval(s,e))}),this._attachments.some(s=>this._attachmentSends.isSameRemoval(s,e))&&(this._attachments=this._attachments.filter(s=>!this._attachmentSends.isSameRemoval(s,e))),this._notifySubscribers()}get cleanupOwner(){return this}_adoptCleanupFailure(t,e,n){this._draftEpoch===n&&(this._attachments.some(r=>r.id===e.id)||(this._attachmentSends.adoptFrom(t,e),this._attachments=[e,...this._attachments],this._notifySubscribers()))}async _retrySubmittedRemoval(t,e,n){this._attachmentSends.beginRemoval(t),await this._attachmentSends.remove(t,this.getAttachmentAdapter(),(r,s)=>{console.error("[assistant-ui] Failed to remove sent attachment",r);const i=this._attachmentSends.transfer(t,{...t,status:{type:"incomplete",reason:"error",message:s}});e._adoptCleanupFailure(this._attachmentSends,i,n)}).catch(()=>{})}get dictation(){return this._dictationSessionController.dictation}get lastDictationEnd(){return this._dictationSessionController.lastDictationEnd}startDictation(){this._dictationSessionController.startDictation()}stopDictation(){this._dictationSessionController.stopDictation()}_eventSubscribers=new Map;_notifyEventSubscribers(t,e){const n=this._eventSubscribers.get(t);n&&tt(n,e,`Composer runtime "${t}"`)}unstable_on(t,e){const n=e;let r=this._eventSubscribers.get(t);return r||(r=new Set,this._eventSubscribers.set(t,r)),r.add(n),()=>{this._eventSubscribers.get(t)?.delete(n)}}};const Sc=t=>t.capabilities?.cancel?Qs(t):!1;var Vh=class extends vo{get canCancel(){return this.isSubmitting||Sc(this.runtime)}get canSend(){if(this.runtime.isDisabled||this.isEmpty||this.runtime.isSendDisabled||this.isSubmitting)return!1;const t=this.runtime.voice;return t?t.canSendText&&this.role==="user"&&this.sendableAttachments.length===0:!0}addAttachment(t){return this.runtime.isDisabled?Promise.resolve():super.addAttachment(t)}startDictation(){this.runtime.isDisabled||super.startDictation()}cancel(){if(!this.isSubmitting){super.cancel();return}this.cancelSubmission(),Sc(this.runtime)&&super.cancel()}threadMessageIds(t){return this.runtime.messages.filter(e=>e.role===t).map(e=>e.id)}_queueCache;get queue(){const t=this.runtime.getSteerQueueItems?.()??Cr,e=this.runtime.getQueueItems?.()??Cr,n=this._queueCache;if(n&&n.steer===t&&n.queue===e)return n.flat;const r=t.length===0?e:e.length===0?t:[...t,...e];return this._queueCache={steer:t,queue:e,flat:r},r}moveQueueItem(t,e){this.runtime.moveQueueItem?.(t,e)}removeQueueItem(t){this.runtime.removeQueueItem?.(t)}getAttachmentAdapter(){return this.runtime.adapters?.attachments}getDictationAdapter(){return this.runtime.adapters?.dictation}runtime;constructor(t){super(),this.runtime=t,this.connect()}connect(){let t=!1,e=this.runtime.isDisabled,n=this.runtime.isSendDisabled,r=this.runtime.voice?.canSendText,s=this.queue;return this.runtime.subscribe(()=>{this.settleInTransit();let i=!1;const o=this.canCancel;t!==o&&(t=o,i=!0),e!==this.runtime.isDisabled&&(e=this.runtime.isDisabled,i=!0),n!==this.runtime.isSendDisabled&&(n=this.runtime.isSendDisabled,i=!0);const a=this.runtime.voice?.canSendText;r!==a&&(r=a,i=!0),s!==this.queue&&(s=this.queue,i=!0),i&&this._notifySubscribers()})}async handleSend(t,e){return this.runtime.append({...t,parentId:this.runtime.messages.at(-1)?.id??null,sourceId:null,startRun:e?.startRun,steer:e?.steer})}async handleCancel(){this.runtime.cancelRun()}},mw=class extends vo{get canCancel(){return!0}get detachesDraftOnSend(){return!1}get cleanupOwner(){return this.runtime.composer instanceof vo?this.runtime.composer:this}get canSend(){return!this.runtime.isDisabled&&!this.isEmpty&&!this.runtime.voice&&!this.isSubmitting}addAttachment(t){return this.runtime.isDisabled?Promise.resolve():super.addAttachment(t)}startDictation(){this.runtime.isDisabled||super.startDictation()}getAttachmentAdapter(){return this.runtime.adapters?.attachments}getDictationAdapter(){return this.runtime.adapters?.dictation}_nonTextPassthrough;_parentId;_sourceId;runtime;endEditCallback;onMessageNotSent;_ended=!1;constructor(t,e,{parentId:n,message:r,onMessageNotSent:s}){super(),this.runtime=t,this.onMessageNotSent=s;let i=t.voice!==void 0,o=t.isDisabled;const a=t.subscribe(()=>{const c=t.voice!==void 0,u=t.isDisabled;c===i&&u===o||(i=c,o=u,this._notifySubscribers())});this.endEditCallback=()=>{a(),e()},this._parentId=n,this._sourceId=r.id,this.setText(un(r)),this.setRole(r.role);let l;r.role==="user"?(l=[...r.attachments??[],...hy(r.content)],this._nonTextPassthrough=[]):(l=r.attachments??[],this._nonTextPassthrough=r.content.filter(c=>c.type!=="text")),this.setAttachments(l),this.setQuote(r.metadata.custom.quote),this.setRunConfig({...t.composer.runConfig})}get parentId(){return this._parentId}get sourceId(){return this._sourceId}async handleSend(t,e){const n=this._nonTextPassthrough.length>0?[...t.content,...this._nonTextPassthrough]:t.content,r={...t,content:n,parentId:this._parentId,sourceId:this._sourceId,startRun:e?.startRun},s=this.runtime.append(r);this.handleCancel();try{await s}catch(i){throw Pa(i)&&this.onMessageNotSent?.(r),i}}handleCancel(){this._ended||(this._ended=!0,this.reset().catch(t=>{console.error("[assistant-ui] Failed to clear cancelled edit",t)}),this.endEditCallback(),this._notifySubscribers())}};function gw(t){const e=t.metadata;if(!e||typeof e!="object")return;const n=e.custom;if(!n||typeof n!="object")return;const r=n.interactables;return Array.isArray(r)?r:void 0}function yw(t){return`update_${t.replace(/[^a-zA-Z0-9_-]/g,"_")}`}const xi=t=>{if(!xe(t))return;const e=t.id;return typeof e=="string"||typeof e=="number"?e:void 0};function Da(t,e,n=[]){if(!xe(t)||!xe(e))return e;const r={...t,...e},[s,...i]=n;return s!==void 0&&Object.hasOwn(e,s)&&(r[s]=Da(t[s],e[s],i)),r}function bw(t,e,n,r){let s=Array.isArray(e.set)?[...e.set]:[...t];if(e.clear===!0&&(s=[]),Array.isArray(e.remove)&&e.remove.length>0){const o=new Set(e.remove);s=s.filter(a=>{const l=xi(a);return l!==void 0?!o.has(l):!o.has(a)})}const i=e.update;if(Array.isArray(i)&&i.length>0){const o=new Map;for(const l of i){const c=xi(l);c!==void 0&&!Number.isNaN(c)&&!o.has(c)&&o.set(c,l)}const a=r?.[0]==="update"?{patch:i[Number(r[1])],rest:r.slice(2)}:void 0;s=s.map(l=>{const c=xi(l);if(c===void 0||!xe(l))return l;const u=o.get(c);return u?a&&u===a.patch?Da(l,u,a.rest):{...l,...u}:l})}if(Array.isArray(e.add)&&e.add.length>0){const o=n?e.add.map(a=>{if(!xe(a)||a.id!==void 0)return a;const l=n();return l===void 0?a:{...a,id:l}}):e.add;s=[...s,...o]}return s}function Si(t,e,n){if(!xe(t)||!xe(e))return e;const r=xe(n?.arrayBaseline)?n.arrayBaseline:t,s=n?.partialPath,i=Object.entries(t);for(const[o,a]of Object.entries(e)){const l=r[o],c=s?.[0]===o?s.slice(1):void 0;if(Array.isArray(l)&&xe(a)){const u=n?.idFactory&&(n.idKeyedFields===void 0||n.idKeyedFields.has(o))?()=>n.idFactory?.(o):void 0;i.push([o,bw(l,a,u,c)])}else c?i.push([o,Da(t[o],a,c)]):i.push([o,a])}return Object.fromEntries(i)}function _w(t,e){if(!xe(t)||!xe(e))return;for(const s of Object.keys(t))if(!Object.hasOwn(e,s))return;const n=[];for(const[s,i]of Object.entries(e))(!Object.hasOwn(t,s)||!aa(t[s],i))&&n.push([s,i]);const r=n.length;if(!(r===0||r===Object.keys(e).length))return Object.fromEntries(n)}const vw=t=>{if(!t||typeof t!="object")return;const e=t;return e.type==="tool-call"?e:void 0},Oa=t=>{if(typeof t=="string"&&t.startsWith("{"))try{t=JSON.parse(t)}catch{return}return xe(t)?t:void 0},ww=(t,e,n)=>t.toolCallId===e&&(t.toolName===n||Oa(t.result)?.interactable===n),xw=(t,e)=>{if(!t.args||typeof t.args!="object")return!1;const n=Oa(t.result);if(n?.success===!1)return!1;if(typeof n?.id=="string")return n.id===e;const r=t.args.id;return r===e||r===void 0},Sw=t=>{const e=Oa(t)?.addedItemIds;if(!xe(e))return;const n=new Map;for(const[r,s]of Object.entries(e)){if(!Array.isArray(s))continue;const i=s.filter(o=>typeof o=="string");i.length>0&&n.set(r,i)}if(n.size!==0)return r=>n.get(r)?.shift()},Tc=new WeakMap;function Tw(t,e,n){let r=Tc.get(t);r||(r=new Map,Tc.set(t,r));let s=r.get(n);s||(s=new Map,r.set(n,s));const i=s.get(e);if(i)return i;const o=yw(n),a=[],l=()=>a[a.length-1];for(const c of t){if(c.role==="user"){const u=gw(c)?.find(d=>d.id===e);if(!u)continue;if(u.partial){const d=l();d&&a.push({state:Si(d.state,u.state),origin:"user-edit"})}else a.push({state:u.state,origin:"user-edit"});continue}if(c.role==="assistant")for(const u of c.content??[]){const d=vw(u);if(d){if(ww(d,e,n))d.args&&typeof d.args=="object"&&a.push({state:d.args,origin:"create",toolCallId:e});else if(d.toolName===o&&xw(d,e)){const f=l();if(f){const{id:h,...p}=d.args,m=Sw(d.result);a.push({state:m?Si(f.state,p,{idFactory:m}):Si(f.state,p),origin:"update",toolCallId:d.toolCallId})}}}}}return s.set(e,a),a}function Cw(t,e,n){const r=Tw(t,e,n),s=r[r.length-1];return s?{state:s.state}:void 0}function Iw(t,e){if(!t)return;const{interactables:n,...r}=t,s={...r};if(Array.isArray(n)){const i=[];for(const o of n){const a=Cw(e,o.id,o.name);if(!a){i.push({id:o.id,name:o.name,state:o.state});continue}if(aa(o.state,a.state))continue;const l=_w(a.state,o.state);i.push(l?{id:o.id,name:o.name,state:l,partial:!0}:{id:o.id,name:o.name,state:o.state})}i.length&&(s.interactables=i)}return Object.keys(s).length?s:void 0}const Vn=new WeakMap,fr=t=>{let e=Vn.get(t);return e||(e=new AbortController,Vn.set(t,e)),e.signal},Cc=new WeakMap,Uh=t=>{let e=Cc.get(t);return e||(e=new AbortController,Cc.set(t,e)),e},wo=t=>Uh(t).signal,kw=t=>{const e=Vn.get(t);e?.signal.aborted||(Vn.delete(t),e?.abort())},Qr=(t,e)=>{try{t()}catch(n){console.error(`[assistant-ui] ${e} cleanup threw while discarding a thread runtime`,n)}},Ew=t=>{t.voice&&Qr(()=>t.disconnectVoice(),"Voice"),t.composer.dictation&&Qr(()=>t.composer.stopDictation(),"Dictation");const e=t.__internal_getEditComposers?.()??t.messages.map(n=>t.getEditComposer(n.id));for(const n of e)n?.dictation&&Qr(()=>n.stopDictation(),"Dictation");t.speech&&Qr(()=>t.stopSpeaking(),"Speech")},qh=t=>{const e=Vn.get(t)??new AbortController;Vn.set(t,e),e.abort(),Uh(t).abort(),Ew(t)};var Aw=class{voiceMessages=[];voiceGeneration=0;_cachedMergedMessages=null;_cachedVoiceGeneration=-1;_cachedMergedBase=null;host;constructor(t){this.host=t}markMessagesDirty(){this.voiceGeneration++,this._cachedMergedMessages=null}dropMessage(t,e){const n=this.voiceMessages.findIndex(r=>r.id===t);n!==-1&&(this.voiceMessages.splice(n,1),this.host.markVoiceMessagesDirty(),e&&this.host.notify())}getMessages(){if(this.voiceMessages.length===0)return this.host.getBaseMessages();const t=this.host.getBaseMessages();if(this._cachedVoiceGeneration!==this.voiceGeneration||this._cachedMergedBase!==t){const e=new Set(t.map(n=>n.id));this._cachedMergedMessages=[...t,...this.voiceMessages.filter(n=>!e.has(n.id))],this._cachedVoiceGeneration=this.voiceGeneration,this._cachedMergedBase=t}return this._cachedMergedMessages}replaceAssistantMessage(t,e){this._currentAssistantMsg===t&&(this._currentAssistantMsg=e)}isVoiceMessage(t){return t!==null&&this.voiceMessages.some(e=>e.id===t)}_voiceSession;_voiceUnsubs=[];voice;_voiceVolume=0;_voiceVolumeSubscribers=new Set;getVoiceVolume=()=>this._voiceVolume;subscribeVoiceVolume=t=>(this._voiceVolumeSubscribers.add(t),()=>this._voiceVolumeSubscribers.delete(t));_toVoiceSessionState(t,e,n){return{status:e,isMuted:t.isMuted,mode:n,canSendText:e.type==="running"&&t.sendText!==void 0}}isRunActive(){if(this.host.isRunning())return!0;const t=this.host.getBaseMessages().at(-1);return t?.role==="assistant"&&(t.status.type==="running"||t.status.type==="requires-action")}getVoiceCommitBarrier(){if(!this.host.isLoading())return;const t=this.host.captureGeneration();return(async()=>{for(;this.host.isLoading()&&!t.aborted;)await new Promise(e=>{const n=()=>{r(),t.removeEventListener("abort",n),e()},r=this.host.subscribe(n);t.addEventListener("abort",n)})})()}connectVoice(){const t=this.host.adapter();if(!t)throw new Error("Voice adapter not configured");if(this.host.isRunActive())throw new Error("Cannot start a voice session while a run is in progress or paused on a pending tool action");const e=this._voiceSession!==void 0;try{this._disconnectVoice(!1)}catch(i){console.error("[assistant-ui] Voice cleanup threw before reconnect",i)}if(this._voiceSession!==void 0)return;let n;try{n=t.connect({})}catch(i){throw e&&this._voiceSession===void 0&&this.host.onDisconnected(),i}if(n.status.type==="ended"){try{n.disconnect()}finally{e&&this._voiceSession===void 0&&this.host.onDisconnected()}return}this._voiceSession=n;const r=[];this._voiceUnsubs=r;const s=()=>{if(this._voiceSession===n&&this._voiceUnsubs===r)return!1;try{gt(r.splice(0))}catch(i){console.error("[assistant-ui] Detached voice setup cleanup threw",i)}return!0};try{let i="listening";if(this.voice=this._toVoiceSessionState(n,n.status,i),this._voiceVolume=0,this.host.notify(),s()||(r.push(n.onStatusChange(o=>{if(this._voiceSession===n)if(o.type==="ended"){this._voiceSession=void 0,this.voice=void 0,this._voiceVolume=0;try{gt([()=>this._finishVoiceAssistantMessage(!1),()=>{this._voiceSession===void 0&&this.host.onDisconnected()},()=>tt(this._voiceVolumeSubscribers,void 0,"Voice volume"),()=>this.host.notify()])}finally{s()}}else this.voice=this._toVoiceSessionState(n,o,i),this.host.notify()})),s())||(r.push(n.onModeChange(o=>{this._voiceSession===n&&(i=o,this.voice&&(this.voice={...this.voice,mode:o},this.host.notify()))})),s())||(r.push(n.onVolumeChange(o=>{this._voiceSession===n&&(this._voiceVolume=o,tt(this._voiceVolumeSubscribers,void 0,"Voice volume"))})),s()))return;r.push(n.onTranscript(o=>{this._voiceSession===n&&this._handleVoiceTranscript(o)})),s()||this.host.onConnected()}catch(i){if(this._voiceSession===n&&this._voiceUnsubs===r){try{this._disconnectVoice(!1)}catch(o){console.error("[assistant-ui] Voice rollback cleanup threw",o)}e&&this._voiceSession===void 0&&this.host.onDisconnected()}else s();throw i}}_currentAssistantMsg=null;_observeVoiceCommit(t){new Promise(e=>e(t())).catch(e=>{console.error("[assistant-ui] Voice message commit failed",e)})}_handleVoiceTranscript(t){const e=this._voiceSession;if(this.host.ensureInitialized(),this._voiceSession===e)if(t.role==="user"){if(this._finishVoiceAssistantMessage(),this._voiceSession!==e)return;this._currentAssistantMsg=null,t.isFinal&&this._observeVoiceCommit(()=>this._commitVoiceUserMessage({id:Mt(),role:"user",content:[{type:"text",text:t.text}],metadata:{modality:"voice",custom:{}},createdAt:new Date,attachments:[]}))}else{const n=t.isFinal?{type:"complete",reason:"stop"}:{type:"running"};if(!this._currentAssistantMsg)this._currentAssistantMsg={id:Mt(),role:"assistant",content:[{type:"text",text:t.text}],metadata:{unstable_state:this.host.state(),unstable_annotations:[],unstable_data:[],steps:[],modality:"voice",custom:{}},status:n,createdAt:new Date},this.voiceMessages.push(this._currentAssistantMsg);else{const r=this.voiceMessages.indexOf(this._currentAssistantMsg);if(r===-1)return;const s={...this._currentAssistantMsg,content:[{type:"text",text:t.text}],status:n};this.voiceMessages[r]=s,this._currentAssistantMsg=s}if(t.isFinal){const r=this._currentAssistantMsg;this._observeVoiceCommit(()=>this.host.commitVoiceMessage(r)),this._currentAssistantMsg=null}this.host.markVoiceMessagesDirty(),this.host.notify()}}_commitVoiceUserMessage(t){this.voiceMessages.push(t);try{return this.host.commitVoiceMessage(t)}finally{this.host.markVoiceMessagesDirty(),this.host.notify()}}async appendToVoiceSession(t){const e=this._voiceSession;if(!this.voice?.canSendText||!e?.sendText)throw new Error("Cannot send a text message while a voice session is connected");const n=t.content.filter(i=>i.type==="text");if(t.role!=="user"||t.sourceId!=null||t.parentId!==this.host.resolveAppendParent(this.host.messages().at(-1)?.id??null)||t.attachments?.length||n.length!==t.content.length||!n.some(i=>i.text.trim()))throw new Error("Only a plain text user message can be sent while a voice session is connected");const r=this.host.enrichAppendMetadata(t);this.host.ensureInitialized();const s=this.host.captureGeneration();try{await e.sendText(un(t))}catch(i){if(s.aborted)return;const o=new wi;throw o.cause=i,o}if(!s.aborted){if(this._voiceSession!==e)throw new wi("The voice session ended before the typed message was recorded");if(this._finishVoiceAssistantMessage(!1),this._voiceSession!==e)throw new wi("The voice session ended before the typed message was recorded");this._currentAssistantMsg=null,await this._commitVoiceUserMessage({id:Mt(),role:"user",content:n,metadata:{custom:{...r.metadata?.custom}},createdAt:t.createdAt,attachments:[]})}}_finishVoiceAssistantMessage(t=!0){const e=this.voiceMessages.at(-1);if(e?.role==="assistant"&&e.status.type==="running"){const n=this.voiceMessages.length-1;this.voiceMessages[n]={...e,status:{type:"complete",reason:"stop"}},this._observeVoiceCommit(()=>this.host.commitVoiceMessage(this.voiceMessages[n])),this._currentAssistantMsg=null,this.host.markVoiceMessagesDirty(),t&&this.host.notify()}}disconnectVoice(){this._disconnectVoice(!0)}_disconnectVoice(t){this._finishVoiceAssistantMessage(!1),this._currentAssistantMsg=null;const e=this._voiceUnsubs.splice(0);this._voiceUnsubs=[];const n=this._voiceSession;this._voiceSession=void 0,this.voice=void 0,this._voiceVolume=0;const r=this.host.stopSpeakingForVoiceMessage();this.voiceMessages=[],this.host.markVoiceMessagesDirty();try{gt([...e,...r?[r]:[],...n?[()=>n.disconnect()]:[],()=>tt(this._voiceVolumeSubscribers,void 0,"Voice volume"),()=>this.host.notify()])}finally{t&&n&&this._voiceSession===void 0&&this.host.onDisconnected()}}muteVoice(){if(!this._voiceSession)throw new Error("No active voice session");this._voiceSession.mute(),this.voice={...this.voice,isMuted:!0},this.host.notify()}unmuteVoice(){if(!this._voiceSession)throw new Error("No active voice session");this._voiceSession.unmute(),this.voice={...this.voice,isMuted:!1},this.host.notify()}},Rw=class extends Ia{_isInitialized=!1;repository=new Gs;_voiceController=new Aw({adapter:()=>this.adapters?.voice,isRunning:()=>this.isRunning===!0,isRunActive:()=>this._isRunActive(),isLoading:()=>this.isLoading,getBaseMessages:()=>this._getBaseMessages(),messages:()=>this.messages,state:()=>this.state,notify:()=>this._notifySubscribers(),subscribe:t=>this.subscribe(t),captureGeneration:()=>fr(this),ensureInitialized:()=>this.ensureInitialized(),commitVoiceMessage:t=>this._commitVoiceMessage(t),markVoiceMessagesDirty:()=>this._markVoiceMessagesDirty(),onConnected:()=>this._onVoiceConnected(),onDisconnected:()=>this._onVoiceDisconnected(),enrichAppendMetadata:t=>this.enrichAppendMetadata(t),resolveAppendParent:t=>this._resolveAppendParent(t),stopSpeakingForVoiceMessage:()=>this.speech&&this._isVoiceMessage(this.speech.messageId)?this._stopSpeaking:void 0});get _voiceMessages(){return this._voiceController.voiceMessages}set _voiceMessages(t){this._voiceController.voiceMessages=t}get _voiceGeneration(){return this._voiceController.voiceGeneration}set _voiceGeneration(t){this._voiceController.voiceGeneration=t}_markVoiceMessagesDirty(){this._voiceController.markMessagesDirty()}_getBaseMessages(){return this.repository.getMessages()}_commitVoiceMessage(t){}_onMessageMetadataChanged(t,e){}_dropVoiceMessage(t,e){this._voiceController.dropMessage(t,e)}get messages(){return this._voiceController.getMessages()}get state(){let t;for(const e of this.messages)e.role==="assistant"&&(t=e);return t?.metadata.unstable_state??null}composer=new Vh(this);_contextProvider;constructor(t){super(),this._contextProvider=t,wo(this).addEventListener("abort",()=>{this.composer.__internal_dispose();for(const e of this._editComposers.values())e.__internal_dispose()})}getModelContext(){return this._contextProvider.getModelContext()}enrichAppendMetadata(t,e=t.parentId){if(t.role!=="user")return t;const n=this.messages,r=e===null?-1:n.findIndex(i=>i.id===e),s=Iw(this.getModelContext().unstable_composerMetadata,n.slice(0,r+1));return s?{...t,metadata:{...t.metadata,custom:{...t.metadata?.custom,...s}}}:t}_editComposers=new Map;_editAttempts=new WeakMap;getEditComposer(t){return this._editComposers.get(t)}__internal_getEditComposers(){return this._editComposers.values()}_isVoiceMessage(t){return this._voiceController.isVoiceMessage(t)}_resolveAppendParent(t){return this._isVoiceMessage(t)?this._getBaseMessages().at(-1)?.id??null:t}beginEdit(t){if(this.voice)throw new Error("Cannot edit a message while a voice session is connected");if(this._isVoiceMessage(t))throw new Error("Voice transcript messages cannot be edited");if(this._editComposers.has(t))throw new Error("Edit already in progress");const e=this.repository.getMessage(t),n=this.repository,r=fr(this),s={};this._editAttempts.set(e.message,s);const i=(o,a)=>{const l=new mw(this,()=>this._editComposers.delete(t),{parentId:e.parentId,message:o,onMessageNotSent:c=>{const u=this.getMessageById(t);r.aborted||this.repository!==n||this._editAttempts.get(e.message)!==s||this._editComposers.has(t)||u?.message!==e.message||u.parentId!==e.parentId||!this.messages.includes(e.message)||this.voice||i(zn(c,t,{type:"complete",reason:"unknown"}),c.runConfig??{})}});l.setRunConfig(a),this._editComposers.set(t,l),this._notifySubscribers()};i(e.message,{...this.composer.runConfig})}getMessageById(t){try{return this.repository.getMessage(t)}catch{const e=this.repository.getMessages(),n=this._voiceMessages.findIndex(r=>r.id===t);return n!==-1?{parentId:n>0?this._voiceMessages[n-1].id:e.at(-1)?.id??null,message:this._voiceMessages[n],index:e.length+n}:void 0}}getBranches(t){return this._voiceMessages.some(e=>e.id===t)?[]:this.repository.getBranches(t)}switchToBranch(t){this.repository.switchToBranch(t),this._notifySubscribers()}_notifyEventSubscribers(t,e){const n=this._eventSubscribers.get(t);n&&tt(n,e,`Thread runtime "${t}"`)}_notifyToolApprovalAnswered(t,e,n,r){this._notifyEventSubscribers("toolApprovalAnswered",{messageId:t,toolCallId:e,toolName:n,approved:r})}submitFeedback({messageId:t,type:e,comment:n}){const r=this.adapters?.feedback,s=this.getMessageById(t);if(!s)throw new Error(`Message not found: ${t}`);const{message:i,parentId:o}=s,a=n?.trim(),l={type:e,...a?{comment:a}:void 0};if(r?.submit({message:i,...l}),i.role==="assistant"){const c={...i,metadata:{...i.metadata,submittedFeedback:l}},u=this._voiceMessages.findIndex(d=>d.id===t);u===-1?(this.repository.addOrUpdateMessage(o,c),this._onMessageMetadataChanged(i,c)):(this._voiceMessages[u]=c,this._voiceController.replaceAssistantMessage(i,c),this._markVoiceMessagesDirty())}this._notifySubscribers()}_stopSpeaking;_replacingSpeech=!1;speech;speak(t){const e=this.adapters?.speech;if(!e)throw new Error("Speech adapter not configured");const n=this.getMessageById(t);if(!n)throw new Error(`Message not found: ${t}`);const{message:r}=n;if(this._replacingSpeech)return;const s=this._stopSpeaking;let i;try{this._replacingSpeech=!0;try{s?.()}finally{this._replacingSpeech=!1}i=e.speak(un(r))}catch(u){if(s&&!this._stopSpeaking)try{this._notifySubscribers()}catch(d){console.error("[assistant-ui] Speech rollback notification threw",d)}throw u}let o;const a=()=>{this._stopSpeaking=void 0,this.speech=void 0;const u=o;o=void 0,u?.()},l=()=>{if(this._stopSpeaking===l)try{a()}finally{i.cancel()}},c=()=>{this._stopSpeaking===l&&(i.status.type==="ended"?gt([a,()=>this._notifySubscribers()]):(this.speech={messageId:t,status:i.status},this._notifySubscribers()))};this._stopSpeaking=l;try{if(o=i.subscribe(c),this._stopSpeaking!==l){o();return}c()}catch(u){if(this._stopSpeaking===l)try{gt([l,()=>this._notifySubscribers()])}catch(d){console.error("[assistant-ui] Speech rollback cleanup threw",d)}throw u}}stopSpeaking(){if(!this._stopSpeaking)throw new Error("No message is being spoken");gt([this._stopSpeaking,()=>this._notifySubscribers()])}get voice(){return this._voiceController.voice}set voice(t){this._voiceController.voice=t}getVoiceVolume=()=>this._voiceController.getVoiceVolume();subscribeVoiceVolume=t=>this._voiceController.subscribeVoiceVolume(t);_onVoiceConnected(){}_onVoiceDisconnected(){}_isRunActive(){return this._voiceController.isRunActive()}_getVoiceCommitBarrier(){return this._voiceController.getVoiceCommitBarrier()}connectVoice(){this._voiceController.connectVoice()}async _appendToVoiceSession(t){return this._voiceController.appendToVoiceSession(t)}disconnectVoice(){this._voiceController.disconnectVoice()}muteVoice(){this._voiceController.muteVoice()}unmuteVoice(){this._voiceController.unmuteVoice()}ensureInitialized(){return this._isInitialized?!1:(this._isInitialized=!0,this._notifyEventSubscribers("initialize",{}),!0)}export(){return this.repository.export()}_beforeImportNotify(){}import(t){this.ensureInitialized(),xv(this.repository,t),this._beforeImportNotify(),this._notifySubscribers()}reset(t){this.import(Mh.fromArray(t??[]))}_eventSubscribers=new Map;unstable_on(t,e){const n=e;if(t==="modelContextUpdate")return this._contextProvider.subscribe?.(()=>tt([n],{},`Thread runtime "${t}"`))??(()=>{});let r=this._eventSubscribers.get(t);return r||(r=new Set,this._eventSubscribers.set(t,r)),r.add(n),t==="initialize"&&this._isInitialized&&queueMicrotask(()=>{r.has(n)&&tt([n],{},`Thread runtime "${t}"`)}),()=>{this._eventSubscribers.get(t)?.delete(n)}}},Yr=class{get path(){return this._core.path}_core;_threadListBinding;constructor(t,e){this._core=t,this._threadListBinding=e,this.__internal_bindMethods()}__internal_bindMethods(){this.switchTo=this.switchTo.bind(this),this.rename=this.rename.bind(this),this.updateCustom=this.updateCustom.bind(this),this.archive=this.archive.bind(this),this.unarchive=this.unarchive.bind(this),this.delete=this.delete.bind(this),this.initialize=this.initialize.bind(this),this.generateTitle=this.generateTitle.bind(this),this.subscribe=this.subscribe.bind(this),this.unstable_on=this.unstable_on.bind(this),this.getState=this.getState.bind(this),this.detach=this.detach.bind(this)}getState(){return this._core.getState()}switchTo(t){const e=this._core.getState();return this._threadListBinding.switchToThread(e.id,t)}rename(t){const e=this._core.getState();return this._threadListBinding.rename(e.id,t)}updateCustom(t){const e=this._core.getState();if(!this._threadListBinding.updateCustom)throw new Error("Thread list runtime does not support updating custom metadata");return this._threadListBinding.updateCustom(e.id,t)}archive(){const t=this._core.getState();return this._threadListBinding.archive(t.id)}unarchive(){const t=this._core.getState();return this._threadListBinding.unarchive(t.id)}delete(){const t=this._core.getState();return this._threadListBinding.delete(t.id)}initialize(){const t=this._core.getState();return this._threadListBinding.initialize(t.id)}generateTitle(t){const e=this._core.getState();return this._threadListBinding.generateTitle(e.id,t)}unstable_on(t,e){let n=this._core.getState().isMain,r=this._core.getState().id;return this.subscribe(()=>{const s=this._core.getState(),i=s.isMain,o=s.id;n===i&&r===o||(n=i,r=o,!(t==="switchedTo"&&!i)&&(t==="switchedAway"&&i||tt([e],{},`Thread list item "${t}"`)))})}subscribe(t){return this._core.subscribe(t)}detach(){const t=this._core.getState();this._threadListBinding.detach(t.id)}__internal_getRuntime(){return this}};const Ti=Promise.resolve(),Mw=()=>{},Pw=t=>({canUnarchive:t.canUnarchive??!0,mainThreadId:t.mainThreadId,newThreadId:t.newThreadId,threadIds:t.threadIds,archivedThreadIds:t.archivedThreadIds,isLoading:t.isLoading,loadError:t.loadError,switchError:t.switchError,isLoadingMore:t.isLoadingMore??!1,hasMore:t.hasMore??!1,threadItems:t.threadItems}),Jr=(t,e)=>{if(e===void 0)return ot;const n=t.getItemById(e);return n?{id:n.id,remoteId:n.remoteId,externalId:n.externalId,title:n.title,status:n.status,lastMessageAt:n.lastMessageAt,custom:n.custom,isMain:n.id===t.mainThreadId,isRunning:t.unstable_isThreadRunning?.(n.id)??!1}:ot};var Dw=class{_getState;_stateBinding;_core;_runtimeFactory;constructor(t,e=zh){this._core=t,this._runtimeFactory=e;const n=new ka({path:{},getState:()=>Pw(t),subscribe:r=>t.subscribe(r)});this._getState=n.getState.bind(n),this._stateBinding=n,this._mainThreadListItemRuntime=new Yr(new Xe({path:{ref:"threadItems[main]",threadSelector:{type:"main"}},getState:()=>Jr(this._core,this._core.mainThreadId),subscribe:r=>this._core.subscribe(r)}),this._core),this.main=new e(new _s({path:{ref:"threads.main",threadSelector:{type:"main"}},getState:()=>t.getMainThreadRuntimeCore(),subscribe:r=>t.subscribe(r)}),this._mainThreadListItemRuntime),this.__internal_bindMethods()}__internal_bindMethods(){this.switchToThread=this.switchToThread.bind(this),this.switchToNewThread=this.switchToNewThread.bind(this),this.unstable_subscribeThreadEvents=this.unstable_subscribeThreadEvents.bind(this),this.getLoadThreadsPromise=this.getLoadThreadsPromise.bind(this),this.reload=this.reload.bind(this),this.reloadMainThread=this.reloadMainThread.bind(this),this.loadMore=this.loadMore.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.getById=this.getById.bind(this),this.getItemById=this.getItemById.bind(this),this.getItemByIndex=this.getItemByIndex.bind(this),this.getArchivedItemByIndex=this.getArchivedItemByIndex.bind(this)}switchToThread(t,e){return this._core.switchToThread(t,e)}switchToNewThread(){return this._core.switchToNewThread()}unstable_subscribeThreadEvents(t){return this._core.unstable_subscribeThreadEvents?.(t)??Mw}getLoadThreadsPromise(){return this._core.getLoadThreadsPromise()}reload(){return this._core.reload?.()??Ti}reloadMainThread(){return this._core.reloadMainThread?.()??Ti}loadMore(){return this._core.loadMore?.()??Ti}getState(){return this._getState()}subscribe(t){return this._stateBinding.subscribe(t)}_mainThreadListItemRuntime;main;get mainItem(){return this._mainThreadListItemRuntime}_createItemStateBinding(t){return new Xe({path:{ref:`threadItems[threadId=${t}]`,threadSelector:{type:"threadId",threadId:t}},getState:()=>Jr(this._core,t),subscribe:e=>this._core.subscribe(e)})}getById(t){return new this._runtimeFactory(new _s({path:{ref:`threads[threadId=${JSON.stringify(t)}]`,threadSelector:{type:"threadId",threadId:t}},getState:()=>this._core.getThreadRuntimeCore(t),subscribe:e=>this._core.subscribe(e)}),this._createItemStateBinding(t))}getItemByIndex(t){return new Yr(new Xe({path:{ref:`threadItems[${t}]`,threadSelector:{type:"index",index:t}},getState:()=>Jr(this._core,this._core.threadIds[t]),subscribe:e=>this._core.subscribe(e)}),this._core)}getArchivedItemByIndex(t){return new Yr(new Xe({path:{ref:`archivedThreadItems[${t}]`,threadSelector:{type:"archiveIndex",index:t}},getState:()=>Jr(this._core,this._core.archivedThreadIds[t]),subscribe:e=>this._core.subscribe(e)}),this._core)}getItemById(t){return new Yr(this._createItemStateBinding(t),this._core)}},Hh=class{threads;_thread;_core;constructor(t){this._core=t,this.threads=new Dw(t.threads),this._thread=this.threads.main,this.__internal_bindMethods()}__internal_bindMethods(){this.registerModelContextProvider=this.registerModelContextProvider.bind(this)}get thread(){return this._thread}registerModelContextProvider(t){return this._core.registerModelContextProvider(t)}};const Wh=new WeakMap,Ow=t=>{const e=t.__internal_setDispatchTransform;e&&Wh.get(e)?.bindNext()},Ic=t=>{const e=t.__internal_setDispatchTransform;return e?Wh.get(e)?.getCurrent():void 0},Xt=Object.freeze([]),Ln="DEFAULT_THREAD_ID",kc=Object.freeze([Ln]),Lw=Object.freeze({id:Ln,remoteId:void 0,externalId:void 0,status:"regular"}),Fw=Promise.resolve(),$w=Object.freeze(Ge({[Ln]:Lw}));var Nw=class extends Ia{_mainThreadId=Ln;_threads=kc;_archivedThreads=Xt;_threadData=$w;adapter={};get isLoading(){return this.adapter.isLoading??!1}get canUnarchive(){return!!this.adapter.onUnarchive}get newThreadId(){}get threadIds(){return this._threads}get archivedThreadIds(){return this._archivedThreads}get threadItems(){return this._threadData}getLoadThreadsPromise(){return Fw}_mainThread;get mainThreadId(){return this._mainThreadId}threadFactory;constructor(t={},e){super(),this.threadFactory=e,this.__internal_setAdapter(t,!0)}getMainThreadRuntimeCore(){return this._mainThread}getThreadRuntimeCore(){throw new Error("Method not implemented.")}getItemById(t){return Object.hasOwn(this._threadData,t)?this._threadData[t]:void 0}__internal_setAdapter(t,e=!1){const n=this.adapter;this.adapter=t;const r=t.threadId??Ln,s=t.threads??Xt,i=t.archivedThreads??Xt,o=n.threadId??Ln,a=n.threads??Xt,l=n.archivedThreads??Xt;!e&&(n.isLoading??!1)===(t.isLoading??!1)&&!!n.onUnarchive==!!t.onUnarchive&&o===r&&a===s&&l===i||((a!==s||l!==i||o!==r)&&(this._threadData=Ge(Object.fromEntries(t.threads?.map(c=>[c.id,{...c,remoteId:c.remoteId,externalId:c.externalId,status:"regular"}])??[]),Object.fromEntries(t.archivedThreads?.map(c=>[c.id,{...c,remoteId:c.remoteId,externalId:c.externalId,status:"archived"}])??[]))),(a!==s||this._threads===kc&&o!==r)&&(this._threads=this.adapter.threads?.map(c=>c.id)??Xt),l!==i&&(this._archivedThreads=this.adapter.archivedThreads?.map(c=>c.id)??Xt),(e||o!==r)&&(e||qh(this._mainThread),this._mainThreadId=r,this._mainThread=this.threadFactory()),Object.hasOwn(this._threadData,this._mainThreadId)||(this._threadData=Ge(this._threadData,{[this._mainThreadId]:{id:this._mainThreadId,remoteId:void 0,externalId:void 0,status:"regular"}})),this._notifySubscribers())}async reloadMainThread(){this._mainThread.unstable_refetchThread&&await this._mainThread.unstable_refetchThread()}async switchToThread(t,e){if(this._mainThreadId===t)return;const n=this.adapter.onSwitchToThread;if(!n)throw new Error("External store adapter does not support switching to thread");await n(t)}async switchToNewThread(){const t=this.adapter.onSwitchToNewThread;if(!t)throw new Error("External store adapter does not support switching to new thread");await t()}async rename(t,e){const n=this.adapter.onRename;if(!n)throw new Error("External store adapter does not support renaming");await n(t,e)}async updateCustom(t,e){const n=this.adapter.onUpdateCustom;if(!n)throw new Error("External store adapter does not support updating custom metadata");await n(t,e)}async detach(){}async archive(t){const e=this.adapter.onArchive;if(!e)throw new Error("External store adapter does not support archiving");await e(t)}async unarchive(t){const e=this.adapter.onUnarchive;if(!e)throw new Error("External store adapter does not support unarchiving");await e(t)}async delete(t){const e=this.adapter.onDelete;if(!e)throw new Error("External store adapter does not support deleting");await e(t)}initialize(t){return Promise.resolve({remoteId:t,externalId:void 0})}generateTitle(){throw new Error("Method not implemented.")}};const Bw=Symbol.for("assistant-stream.tool-execution-id"),xo=Promise.resolve(),or=t=>{try{return JSON.parse(t),!0}catch{return!1}},Ec=t=>{try{return JSON.parse(t)}catch{return}},Ci=(t,e)=>{const n=Ec(t),r=Ec(e);return n===void 0||r===void 0?!1:aa(n,r)},ar=t=>t.result!==void 0&&t.isPreliminary!==!0,Ii=t=>t[Bw];var jw=class{_getTools;_callbacks;_isClientToolCall;_entries=new Map;_humanInput=new Map;_executing=new Set;_discardedToolCallIds=new Set;_settledResolvers=[];_statuses=new Map;_ac=new AbortController;_retiredAc;_pendingRestore=!0;_lastSnapshot=null;_isRunning=!1;_controller;_pipelineDead=!1;_pipelineRestartUsed=!1;constructor(t,e,n){this._getTools=t,this._callbacks=e,this._isClientToolCall=n,this._initPipeline()}_initPipeline(){const[t,e]=lv();this._controller=e;const r=ew(()=>this._getWrappedTools(),()=>this._ac.signal,(s,i,o)=>this._onHumanInput(s,i,o),{onExecutionStart:(s,i,o)=>this._onExecutionStart(s,o),onExecutionEnd:(s,i,o)=>this._onExecutionEnd(s,o)});t.pipeThrough(r).pipeThrough(new Ch).pipeTo(new WritableStream({write:s=>{try{if(s.type!=="result")return;this._handleResultChunk(s)}catch(i){console.error("[ToolInvocationTracker] result chunk handling failed",i)}}})).catch(s=>{console.error("[ToolInvocationTracker] stream pipeline failed; will attempt single restart on next setState",s),this._pipelineDead=!0})}setState(t){try{if(this._pipelineDead){if(this._pipelineRestartUsed)return;this._pipelineRestartUsed=!0,this._pipelineDead=!1;const n=new Set;for(const[s,i]of this._entries)i.executionId&&this._executing.has(i.executionId)&&n.add(s);this._demoteEntriesToRestored(),this._executing.clear(),this._humanInput.size===0?this._ac.abort():this._retiredAc=this._ac,this._ac=new AbortController;const r=new Map(this._statuses);for(const s of n)this._humanInput.has(s)||r.delete(s);r.size!==this._statuses.size&&(this._statuses=r,this._invokeOnStatusesChange()),this._resolveSettledResolvers(),this._initPipeline()}if(this._lastSnapshot&&this._lastSnapshot.messages===t.messages&&this._lastSnapshot.isRunning===t.isRunning&&this._lastSnapshot.isLoading===t.isLoading&&(t.isRunning||![...this._entries.values()].some(n=>n.controller&&n.ownershipDeferred)))return;t.isLoading===!0&&(this._pendingRestore=!0);const e=this._isRunning;this._isRunning=t.isRunning;try{this._processMessages(t.messages,t.discardedToolCallIds)}catch(n){throw this._isRunning=e,n}this._lastSnapshot=t,this._pendingRestore=!1}catch(e){console.error("[ToolInvocationTracker] setState failed; snapshot dropped",e)}}reset(){try{this._pendingRestore=!0,this._entries.clear(),this._discardedToolCallIds.clear(),this._lastSnapshot=null,this.abort(),this._statuses.size>0&&(this._statuses=new Map,this._invokeOnStatusesChange())}catch(t){console.error("[ToolInvocationTracker] reset failed",t)}}abort(t){try{if(this._humanInput.forEach(({executionId:n,reject:r},s)=>{try{r(new Error("Tool execution aborted"))}catch{}this._endHumanRequest(s,n)}),this._humanInput.clear(),t?.discardPending)for(const[n,r]of this._entries)r.controller&&(r.hasResult||r.executeStarted||(this._discardedToolCallIds.add(n),r.skipExecute=!0,r.discarded=!0));if(this._retiredAc?.abort(),this._retiredAc=void 0,this._ac.abort(),this._ac=new AbortController,this._executing.size===0)return xo;const e=new Set(this._executing);return new Promise(n=>{this._settledResolvers.push({executionIds:e,resolve:n})})}catch(e){return console.error("[ToolInvocationTracker] abort failed",e),xo}}_endHumanRequest(t,e){if(this._executing.has(e)){this._setStatus(t,{type:"executing"});return}const n=this._entries.get(t)?.executionId;(n===void 0||n===e)&&this._deleteStatus(t)}_rejectHumanInput(t,e){const n=this._humanInput.get(t);if(n){this._humanInput.delete(t),this._endHumanRequest(t,n.executionId);try{n.reject(e)}catch{}}}resume(t,e){try{const n=this._humanInput.get(t);return n?(this._humanInput.delete(t),this._endHumanRequest(t,n.executionId),n.resolve(e),!0):!1}catch(n){return console.error("[ToolInvocationTracker] resume failed",n),!1}}getStatuses(){return this._statuses}_getWrappedTools(){const t=this._getTools();if(t)return Object.fromEntries(Object.entries(t).map(([e,n])=>{const r=n.execute,s=n.streamCall;return r===void 0&&s===void 0?[e,n]:[e,{...n,...r!==void 0&&{execute:(...[i,o])=>{const a=Ii(o),l=this._captureExecution(o.toolCallId,a);return!l||l.skipExecute?new Promise(()=>{}):(l.executeStarted=!0,r(i,o))}},...s!==void 0&&{streamCall:(...[i,o])=>{const a=Ii(o),l=this._captureExecution(o.toolCallId,a);if(!(!l||l.discarded))return s(i,o)}}}]}))}_captureExecution(t,e){if(e===void 0)return;const n=this._entries.get(t);if(n?.controller)return n.executionId===void 0&&(n.executionId=e),n.executionId===e?n:void 0}_onHumanInput(t,e,n){return new Promise((r,s)=>{const i=this._entries.get(t);if(!i?.controller||i.executionId!==n){s(new Error("Tool execution aborted"));return}const o=this._humanInput.get(t);if(o)try{o.reject(new Error("Human input request was superseded by a new request"))}catch{}this._humanInput.set(t,{executionId:n,resolve:r,reject:s}),this._setStatus(t,{type:"interrupt",payload:{type:"human",payload:e}})})}_onExecutionStart(t,e){this._captureExecution(t,e)&&(this._entries.get(t).skipExecute||(this._executing.add(e),this._humanInput.get(t)?.executionId!==e&&this._setStatus(t,{type:"executing"})))}_onExecutionEnd(t,e){if(e===void 0||!this._executing.delete(e))return;this._entries.get(t)?.executionId===e&&this._deleteStatus(t);const n=[];this._settledResolvers.forEach(({executionIds:r,resolve:s})=>{if([...r].some(i=>this._executing.has(i))){n.push({executionIds:r,resolve:s});return}try{s()}catch{}}),this._settledResolvers.length=0,this._settledResolvers.push(...n)}_handleResultChunk(t){const e=t.meta.toolCallId,n=Ii(t),r=this._entries.get(e);!r||r.executionId!==n||r?.hasResult||r.skipExecute||this._invokeOnResult({type:"add-tool-result",toolCallId:e,toolName:t.meta.toolName,result:t.result,isError:t.isError,...t.artifact!==void 0&&{artifact:t.artifact},...t.modelContent!==void 0&&{modelContent:t.modelContent}})}_invokeOnResult(t){try{this._callbacks.onResult(t)}catch(e){console.error("[ToolInvocationTracker] onResult callback threw; result dropped",e)}}_invokeOnStatusesChange(){try{this._callbacks.onStatusesChange(this._statuses)}catch(t){console.error("[ToolInvocationTracker] onStatusesChange callback threw; status change not propagated",t)}}_setStatus(t,e){const n=new Map(this._statuses);n.set(t,e),this._statuses=n,this._invokeOnStatusesChange()}_deleteStatus(t){if(!this._statuses.has(t))return;const e=new Map(this._statuses);e.delete(t),this._statuses=e,this._invokeOnStatusesChange()}_resolveSettledResolvers(){const t=this._settledResolvers.splice(0);for(const{resolve:e}of t)try{e()}catch{}}_warnProviderOwnedSkip(t,e){}_resolveDeferredOwnership(t,e){if(!t.controller||!t.ownershipDeferred||this._isRunning)return;if(e.result!==void 0){t.ownershipDeferred=!1;return}const n=this._isClientToolCall?.(e);n!==!1&&(t.ownershipDeferred=!1,n===!0&&(t.clientOwned=!0))}_shouldCloseArgsStream({argsText:t,hasResult:e,clientOwned:n,ownershipDeferred:r}){return e?!0:or(t)?n||!this._isRunning&&!r:!1}_startActiveEntry(t,e,n,r,s,i,o){const a={toolName:e,controller:this._controller.addToolCallPart({toolName:e,toolCallId:t,...o&&{providerExecuted:!0}}),argsText:"",hasResult:!1,skipExecute:n,discarded:r,argsComplete:!1,clientOwned:s,ownershipDeferred:i};return this._entries.set(t,a),a}_demoteEntriesToRestored(){for(const[t,e]of this._entries)if(e.controller){if(!e.argsComplete&&!e.hasResult){this._entries.delete(t);continue}this._entries.set(t,{toolName:e.toolName,argsText:e.argsText,hasResult:e.hasResult})}}_processArgsText(t,e){if(!t.controller)return;const n=e.result!==void 0;if(e.argsText!==t.argsText){let r=!0;if(t.argsComplete)Ci(t.argsText,e.argsText)?(t.argsText=e.argsText,r=!1):(t.argsText=e.argsText,r=!1,this._rejectHumanInput(e.toolCallId,new Error("Tool call arguments changed while waiting for human input")));else if(!e.argsText.startsWith(t.argsText))if(or(t.argsText)&&or(e.argsText)&&Ci(t.argsText,e.argsText)){const s=this._shouldCloseArgsStream({argsText:e.argsText,hasResult:n,clientOwned:t.clientOwned,ownershipDeferred:t.ownershipDeferred});s&&t.controller.argsText.close(),t.argsText=e.argsText,t.argsComplete=s,r=!1}else r=!1;if(r&&t.controller){const s=e.argsText.slice(t.argsText.length);t.controller.argsText.append(s);const i=this._shouldCloseArgsStream({argsText:e.argsText,hasResult:n,clientOwned:t.clientOwned,ownershipDeferred:t.ownershipDeferred});i&&t.controller.argsText.close(),t.argsText=e.argsText,t.argsComplete=i}}!t.argsComplete&&t.controller&&this._shouldCloseArgsStream({argsText:t.argsText,hasResult:n,clientOwned:t.clientOwned,ownershipDeferred:t.ownershipDeferred})&&(t.controller.argsText.close(),t.argsComplete=!0)}_processMessages(t,e){const n=this._pendingRestore;for(const{part:r}of _o(t)){const s=this._entries.get(r.toolCallId);if(n){s?.controller||this._entries.set(r.toolCallId,{toolName:r.toolName,argsText:r.argsText,hasResult:ar(r)});continue}let i=s;const o=this._discardedToolCallIds.has(r.toolCallId);if(ar(r)&&this._discardedToolCallIds.delete(r.toolCallId),i&&!i.controller){if(i.hasResult||!(r.argsText!==i.argsText&&!(or(i.argsText)&&or(r.argsText)&&Ci(i.argsText,r.argsText)))&&!ar(r))continue;this._entries.delete(r.toolCallId),i=void 0}if(!i){const a=o||e?.has(r.toolCallId)===!0;a&&!ar(r)&&this._discardedToolCallIds.add(r.toolCallId);const l=this._isClientToolCall?.(r),c=r.result===void 0&&l===!1&&this._isRunning;c&&this._warnProviderOwnedSkip(r.toolName,r.toolCallId),i=this._startActiveEntry(r.toolCallId,r.toolName,r.result!==void 0||c||a,a,l===!0,l===void 0||!this._isRunning&&l===!1,r.providerExecuted===!0)}if(r.result!==void 0&&(i.skipExecute=!0),r.approval!==void 0&&(i.skipExecute=!0),r.providerExecuted===!0&&(i.skipExecute=!0),this._resolveDeferredOwnership(i,r),this._processArgsText(i,r),r.result!==void 0&&!i.hasResult){const{controller:a}=i;if(!a)continue;i.argsComplete=!0,a.setResponse(new Pt({result:r.result,artifact:r.artifact,isError:r.isError,isPreliminary:r.isPreliminary,...r.modelContent!==void 0?{modelContent:r.modelContent}:{}})),ar(r)&&(i.hasResult=!0,a.close())}}}},zw=class{pending;get isLoading(){return this.pending!==void 0}load(t,e,n){if(this.pending)return this.pending;if(!t)return Promise.resolve();const r=Promise.resolve().then(()=>t()).catch(e).finally(()=>{this.pending=void 0,n(!1)});return this.pending=r,n(!0),r}};const Vw=Object.freeze([]),Ac=new WeakMap,Rc=(t,e)=>t?.type===e?.type&&t?.comment===e?.comment,ki=new WeakMap,Ei=(t,e)=>{Promise.resolve(e).catch(n=>{console.error(`[ExternalStoreThreadRuntimeCore] ${t} callback rejected`,n)})},Uw=(t,e)=>t&&e[e.length-1]?.role!=="assistant";var qw=class extends Rw{_capabilities={switchToBranch:!1,switchBranchDuringRun:!1,edit:!1,delete:!1,reload:!1,refetchThread:!1,cancel:!1,unstable_copy:!1,speech:!1,dictation:!1,voice:!1,attachments:!1,feedback:!1,queue:!1,answerToolCall:!1};get capabilities(){return this._capabilities}_messages;isDisabled;isSendDisabled;get isLoading(){return this._store.isLoading??!1}_pendingResume;_clearPendingResume(t){!t||this._pendingResume!==t||(this._pendingResume=void 0,this._notifySubscribers())}get canResume(){return!!this._store.canResume&&!!this._store.onResume&&!this._pendingResume&&!this.isDisabled&&!Qs(this)&&!this.isLoading&&!this.voice}get hasEarlier(){return this._store.hasEarlier===!0&&this._store.onLoadEarlier!==void 0}_loadEarlier=new zw;get isLoadingEarlier(){return this._loadEarlier.isLoading}loadEarlier(){const t=this._store.onLoadEarlier;return this._loadEarlier.load(this.hasEarlier?t:void 0,e=>{console.error("[ExternalStoreThreadRuntimeCore] onLoadEarlier callback rejected",e)},()=>this._notifySubscribers())}get isRunning(){return this._hasExecutingTools(this._store)?!0:this._store.isRunning}_getBaseMessages(){return this._messages}_beforeImportNotify(){this._syncRepositoryMessages()}get state(){return this._store.state??super.state}get adapters(){return this._store.adapters}get unstable_refetchThread(){if(this._store.onRefetchThread)return()=>this._store.onRefetchThread()}suggestions=[];extras=void 0;_converter=new bc;_createdAtById=new Map;_submittedFeedback=new Map;_pendingDeleteEvictions=new Map;_pendingDeleteWindows=new Set;_openDeleteWindow(t){const e=this.repository.getMessages(),n=e.findIndex(s=>s.id===t)+1,r={prefix:new Set(e.slice(0,n).map(s=>s.id)),suffix:new Set(e.slice(n).map(s=>s.id))};if(r.suffix.size===0)return r;this._pendingDeleteWindows.add(r);for(const[s,i]of this._pendingDeleteEvictions)r.prefix.has(s)||(i.calls.size>0?i.reloaded=!0:this._pendingDeleteEvictions.delete(s));return r}_closeDeleteWindows(t){for(const e of this._pendingDeleteWindows)[...e.suffix].every(n=>!t.has(n))&&this._pendingDeleteWindows.delete(e)}_optimistic=null;_errorMessageIdsByRepository=new WeakMap;_completedHostSnapshots=0;get _errorMessageIds(){let t=this._errorMessageIdsByRepository.get(this.repository);return t||(t=new Set(this.repository.export().messages.map(({message:e})=>e.id).filter(Zi)),this._errorMessageIdsByRepository.set(this.repository,t)),t}_storeMessages=[];_importedMessageIds;_runStartLeases=new bi;_runCancellationLeases=new bi;_cancelRunResyncLeases=new bi;_cancelledToolTurn=null;_cancelledRunIds=new Set;_pendingCancelResyncs=new Set;_movedLeaf;_store;_getInitializePromise;__internal_setGetInitializePromise(t){this._getInitializePromise=t}_queueDispatchTransform=t=>{const e=this._transformedQueue&&Ic(this._transformedQueue);if(e&&wo(this).aborted&&e!==this._queueDispatchTransform)return e(t);const n=e?void 0:Ac.get(t),r=n&&!wo(n).aborted?n:this;r._pendingDeleteWindows.clear(),r._settleCancelResyncs();const s=r.messages.at(-1)?.id??null;return r.enrichAppendMetadata({...t,parentId:s},s)};_transformedQueue;_toolInvocations=null;_toolStatuses=new Map;_effectiveIsRunning=!1;_inTrackerUpdate=!1;_pendingRunningRefresh=!1;_onMessageMetadataChanged(t,e){if(this._storeMessages=this._storeMessages.map(i=>i.id===e.id?e:i),e.id.startsWith("__external_store_fallback_"))return;const n=this._submittedFeedback.get(e.id),r=n&&Rc(t.metadata.submittedFeedback,n.feedback)?n.external:t.metadata.submittedFeedback,s=e.metadata.submittedFeedback;s&&this._submittedFeedback.set(e.id,{feedback:s,external:r,source:n?.message===t?n.source:t,message:e})}_applySubmittedFeedback(t){if(this._submittedFeedback.size===0)return t;for(const e of this._submittedFeedback.keys())try{this.repository.getMessage(e)}catch{this._submittedFeedback.delete(e)}return t.map(e=>{const n=this._submittedFeedback.get(e.id);if(!n)return e;if(e.role!=="assistant"||!Rc(e.metadata.submittedFeedback,n.external))return this._submittedFeedback.delete(e.id),e;if(n.source===e)return n.message;const r={...e,metadata:{...e.metadata,submittedFeedback:n.feedback}};return n.source=e,n.message=r,r})}_runTrackerUpdate(t){this._inTrackerUpdate=!0;try{t()}finally{this._inTrackerUpdate=!1}this._pendingRunningRefresh&&(this._pendingRunningRefresh=!1,this._refreshEffectiveIsRunning())}_refreshEffectiveIsRunning(){this._effectiveIsRunning!==this._getEffectiveIsRunning(this._store)&&this._updateStoreSnapshot(this._store,!1)}_hasExecutingTools(t){if(t.unstable_enableToolInvocations!==!0||this._toolInvocations===null)return!1;for(const e of this._toolStatuses.values())if(e.type==="executing")return!0;return!1}_getEffectiveIsRunning(t){return(t.isRunning??!1)||this._hasExecutingTools(t)}beginEdit(t){if(!this._store.onEdit)throw new Error("Runtime does not support editing.");super.beginEdit(t)}constructor(t,e){super(t),this.__internal_setAdapter(e)}__internal_setAdapter(t){if(this._store===t){const e=t.unstable_enableToolInvocations?ki.get(this.repository):void 0;e&&e.host!==this&&this._runTrackerUpdate(()=>this._claimToolInvocations(e));return}this._updateStoreSnapshot(t)}_evictPlaceholder(){if(this._optimistic){try{this.repository.getMessage(this._optimistic.message.id)}catch{return}this.repository.deleteMessage(this._optimistic.message.id)}}_updateStoreSnapshot(t,e=!0,n=!1){const r=this._effectiveIsRunning;this.isDisabled=t.isDisabled??!1,this.isSendDisabled=t.isSendDisabled??!1;const s=this._store;this._store=t;const i=this._getEffectiveIsRunning(t),o=t.unstable_messageRepositoryInstance,a=o!==void 0&&o!==this.repository;if(a){this.repository=o,this._createdAtById.clear(),this._cancelledToolTurn=null,this._cancelledRunIds.clear(),this._pendingResume=void 0,this._pendingDeleteEvictions.clear(),this._pendingDeleteWindows.clear(),this._submittedFeedback.clear(),this._movedLeaf=void 0;const b=this.repository.getMessages(),v=b.at(-1);this._optimistic=v?.metadata.isOptimistic?{message:v,parentId:b.at(-2)?.id??null}:null}s?.queue!==t.queue&&(this._transformedQueue=void 0,t.queue?.__internal_setDispatchTransform?.(this._queueDispatchTransform),t.queue?.__internal_setDispatchTransform&&(this._transformedQueue=t.queue)),this.extras!==t.extras&&(this.extras=t.extras);const l=t.suggestions??Vw;zt(this.suggestions,l)||(this.suggestions=l);const c={switchToBranch:this._store.setMessages!==void 0,switchBranchDuringRun:!1,edit:this._store.onEdit!==void 0,delete:this._store.onDelete!==void 0||this._store.setMessages!==void 0,reload:this._store.onReload!==void 0,refetchThread:this._store.onRefetchThread!==void 0,cancel:this._store.onCancel!==void 0,speech:this._store.adapters?.speech!==void 0,dictation:this._store.adapters?.dictation!==void 0,voice:this._store.adapters?.voice!==void 0,unstable_copy:this._store.unstable_capabilities?.copy!==!1,attachments:!!this._store.adapters?.attachments,feedback:!!this._store.adapters?.feedback,queue:this._store.queue!==void 0,answerToolCall:this._store.onAddToolResult!==void 0||this._store.onResumeToolCall!==void 0||this._store.onRespondToToolApproval!==void 0||this._store.unstable_enableToolInvocations===!0};zt(this._capabilities,c)||(this._capabilities=c);let u,d=!1,f=!1;if(t.messageRepository){if(this._importedMessageIds=void 0,!n&&s&&!a&&s.isRunning===t.isRunning&&s.messageRepository===t.messageRepository&&r===i){e&&this._pendingDeleteWindows.size>0&&this._closeDeleteWindows(new Set(t.messageRepository.messages.map(({message:w})=>w.id))),this._notifySubscribers();return}const b=t.messageRepository.messages;e&&this._pendingDeleteWindows.size>0&&this._closeDeleteWindows(new Set(b.map(({message:w})=>w.id)));const v=t.messageRepository.headId??b.at(-1)?.message.id??null;if(this._evictPlaceholder(),s&&!n&&!a&&s.messageRepository===t.messageRepository)this.repository.import({headId:v,messages:[]}),u=this.repository.getMessages();else{const w=new Set(b.map(({message:_})=>_.id)),k=this._applySubmittedFeedback(b.map(({message:_})=>_));for(let _=0;_<b.length;_++)this.repository.addOrUpdateMessage(b[_].parentId,k[_]);for(const{message:_}of this.repository.export().messages)w.has(_.id)||this.repository.deleteMessage(_.id);this._pendingDeleteEvictions.clear(),this.repository.import({headId:v,messages:[]}),u=this.repository.getMessages()}}else if(t.messages){if(s){if(s.convertMessage!==t.convertMessage)this._converter=new bc;else if(!n&&!a&&s.isRunning===t.isRunning&&s.messages===t.messages&&r===i){e&&this._pendingDeleteWindows.size>0&&this._closeDeleteWindows(new Set(this._storeMessages.map(_=>_.id))),this._notifySubscribers();return}}u=t.convertMessage?this._converter.convertMessages(t.messages,(_,A,E)=>{if(!t.convertMessage)return A;const D=E===(t.messages?.length??0)-1,x=`${dv}${E}`;if(_&&(_.role!=="assistant"||!_v(_.status)||_.status===mc(_.content,D,i))){if(_.id.startsWith("__external_store_fallback_")&&_.id!==x){const T={..._,id:x};return hc(T,A),T}return _}let M=t.convertMessage(A,E);if(M.createdAt==null&&M.id!=null){const T=this._createdAtById.get(M.id)??new Date;this._createdAtById.set(M.id,T),M={...M,createdAt:T}}const P=zn(M,x,mc(M.content,D,i));return hc(P,A),P}):t.messages,u=hv(u,_=>{console.warn(`ExternalStoreThreadRuntimeCore: duplicate message id "${_}" in the provided messages array; keeping the last occurrence.`)}),u=this._applySubmittedFeedback(u);const b=this._importedMessageIds;d=b!==void 0&&Gr(b,u.map(_=>_.id)),d||(f=b!==void 0,this._importedMessageIds=void 0);const v=new Set(u.map(_=>_.id)),w=new Map;for(let _=1;_<u.length;_++){const A=u[_].id,E=u[_-1].id;let D;try{D=this.repository.getMessage(A).parentId}catch{continue}if(D===E)continue;const x=this.repository.getMessages(A),M=x.findIndex(P=>P.id===E);if(M!==-1)for(let P=M+1;P<x.length-1;P++){const T=x[P];v.has(T.id)||w.set(T.id,T)}}for(let _=0;_<u.length;_++){const A=u[_],E=u[_-1];this.repository.addOrUpdateMessage(E?.id??null,A)}for(const[_,A]of w)this._evictDeletedMessage(_,A,!1);const k=this._errorMessageIds;for(const _ of k)v.has(_)||this.repository.hasChildren(_)||(k.delete(_),this._evictDeletedMessage(_,void 0,!1));for(const _ of u)Zi(_.id)&&k.add(_.id);if(this._pendingDeleteEvictions.size>0&&s?.messages!==t.messages||e&&this._pendingDeleteWindows.size>0){const _=new Set(u.map(A=>A.id));if(e&&this._closeDeleteWindows(_),s?.messages!==t.messages){for(const[A,E]of this._pendingDeleteEvictions)if(!E.reloaded){if(_.has(A)){E.calls.size===0&&this._pendingDeleteEvictions.delete(A);continue}this._pendingDeleteEvictions.delete(A);try{this.repository.getMessage(A)}catch{continue}this.repository.deleteMessage(A)}}}}else throw new Error("ExternalStoreAdapter must provide either 'messages' or 'messageRepository'");this._storeMessages=u,u.length>0&&this.ensureInitialized();const h=this._movedLeaf;if(h)if(h.generation.aborted||!h.resyncLease.isCurrent()||this.composer.text!==h.draft.text)this._movedLeaf=void 0;else{const b=u.findIndex(v=>v.id===h.id);b!==-1&&(un(u[b])!==h.draft.text?this._movedLeaf=void 0:b<u.length-1&&(this.composer.retractDraft(h.draft),this._movedLeaf=void 0))}this._effectiveIsRunning=i;const p=this._completedHostSnapshots;if(r!==i){if(i){const b=this._cancelledToolTurn;if(b?.lease.isCurrent()){const v=u.at(-1);v?.role==="assistant"&&b.messageIds.has(v.id)?this._cancelledToolTurn=null:(v?.role==="assistant"?u.at(-2)?.id??null:v?.id??null)===b.parentId&&(b.parentOpen=!1)}this._notifyEventSubscribers("runStart",{})}else this._notifyEventSubscribers("runEnd",{});if(this._completedHostSnapshots!==p)return}let m=null;if(Uw(i,u)){const b=u.at(-1)?.id??null;f&&this.repository.resetHead(b),this._optimistic?.parentId!==b&&(this._optimistic={parentId:b,message:zn({role:"assistant",content:[],metadata:{isOptimistic:!0}},Mt(),{type:"running"})}),m=this._optimistic.message.id,this.repository.addOrUpdateMessage(b,this._optimistic.message)}m===null&&(this._optimistic=null);const y=m??u.at(-1)?.id??null;t.messageRepository||d?this.repository.import({headId:y,messages:[]}):this.repository.resetHead(y);const g=this.repository.getMessages();if((!this._messages||!Gr(this._messages,g))&&(this._messages=g),this._voiceMessages.length>0){const b=new Set(this._messages.map(w=>w.id)),v=this._voiceMessages.filter(w=>!b.has(w.id));v.length!==this._voiceMessages.length&&(this._voiceMessages=v,this._markVoiceMessagesDirty())}e&&(a&&this._runTrackerUpdate(()=>this._toolInvocations?.reset()),this._runTrackerUpdate(()=>this._driveToolInvocations()),this._completedHostSnapshots++),this._notifySubscribers()}_claimToolInvocations(t){if(this._toolInvocations=t.tracker,t.host!==this){t.host._toolInvocations===t.tracker&&(t.host._toolInvocations=null),t.host=this;const e=t.tracker.getStatuses();(e.size>0||this._toolStatuses.size>0)&&this._applyToolStatuses(e)}return t.tracker}_driveToolInvocations(){if(!this._store.unstable_enableToolInvocations){this._toolInvocations&&(this._toolInvocations.reset(),this._toolInvocations=null,this._toolStatuses=new Map,this._store.setToolStatuses?.({}));return}let t=ki.get(this.repository);t||(t=this._createToolInvocations(),ki.set(this.repository,t));const e=this._claimToolInvocations(t),n=this._getDiscardedToolCallIds();e.setState({messages:this._messages,isRunning:this._getEffectiveIsRunning(this._store),...n&&{discardedToolCallIds:n},...this._store.isLoading!==void 0&&{isLoading:this._store.isLoading}})}_getDiscardedToolCallIds(){const t=this._cancelledToolTurn;if(!t&&this._cancelledRunIds.size===0)return;const e=new Set;for(let n=0;n<this._messages.length;n++){const r=this._messages[n];if(r.role!=="assistant"||r.metadata.isOptimistic)continue;const s=r.metadata.runId;if(s===void 0||!this._cancelledRunIds.has(s)){if(!t)continue;if(!t.messageIds.has(r.id)){if(!t.parentOpen||(this._messages[n-1]?.id??null)!==t.parentId)continue;t.messageIds.add(r.id)}}for(const{part:i}of _o([r]))e.add(i.toolCallId)}return e}_createToolInvocations(){const t={host:this,tracker:new jw(()=>t.host.getModelContext().tools,{onResult:e=>t.host._dispatchToolResult(e),onStatusesChange:e=>t.host._applyToolStatuses(e)},e=>t.host._store.unstable_isClientToolCall?.(e))};return t}_dispatchToolResult(t){try{const e=this._findMessageIdForToolCall(t.toolCallId);if(e===void 0)return;Ei("onAddToolResult",this._store.onAddToolResult?.({messageId:e,toolCallId:t.toolCallId,toolName:t.toolName,result:t.result,isError:t.isError,...t.artifact!==void 0&&{artifact:t.artifact},...t.modelContent!==void 0&&{modelContent:t.modelContent}}))}catch(e){console.error("[ExternalStoreThreadRuntimeCore] onAddToolResult dispatch failed",e)}}_applyToolStatuses(t){const e=this._hasExecutingTools(this._store);this._toolStatuses=t;try{this._store.setToolStatuses?.(Object.fromEntries(t))}finally{e!==this._hasExecutingTools(this._store)&&(this._inTrackerUpdate?this._pendingRunningRefresh=!0:this._updateStoreSnapshot(this._store))}}_toolCallToMessageId=new Map;_messagesForToolCallIndex=null;_findMessageIdForToolCall(t){if(this._messagesForToolCallIndex!==this._messages){this._toolCallToMessageId.clear();for(const{part:e,messageId:n}of _o(this._messages))this._toolCallToMessageId.set(e.toolCallId,n);this._messagesForToolCallIndex=this._messages}return this._toolCallToMessageId.get(t)}switchToBranch(t){if(!this._store.setMessages)throw new Error("Runtime does not support switching branches.");if(this._getEffectiveIsRunning(this._store))return;const e=this._store.unstable_onBranchChange,n=this._pendingResume,r=e||n?this.repository.canonicalHeadId:null;this.repository.switchToBranch(t),this._pendingDeleteWindows.clear();for(const[s,i]of this._pendingDeleteEvictions)i.calls.size>0?i.reloaded=!0:this._pendingDeleteEvictions.delete(s);this.updateMessages(this.repository.getMessages()),n&&this.repository.canonicalHeadId!==r&&this._clearPendingResume(n),e&&this._notifyBranchChange(r,e)}_notifyBranchChange(t,e){const n=this.repository.canonicalHeadId;n!==t&&e({headId:n,visibleMessageIds:this.repository.getMessages().map(r=>r.id)})}async append(t){let e={...t,parentId:this._resolveAppendParent(t.parentId)};if(this.voice)return this._pendingDeleteWindows.clear(),this._appendToVoiceSession(e);if(this._isVoiceMessage(e.sourceId))throw new Error("Voice transcript messages cannot be edited");const n=e.sourceId!=null||e.parentId!==(this._getBaseMessages().at(-1)?.id??null),r=!n&&this._store.queue&&this._store.queue===this._transformedQueue?void 0:this.enrichAppendMetadata(e),s=fr(this);this.ensureInitialized();const i=this._getInitializePromise?.();if(!n&&this._store.queue&&(i&&await i,s.aborted))return;const o=n?void 0:this._store.queue;if((!o||o!==this._transformedQueue)&&(e=r??this.enrichAppendMetadata(e)),o){o===this._transformedQueue&&(Ic(o)||Ac.set(e,this),o.__internal_setDispatchTransform?.(this._queueDispatchTransform),Ow(o)),e.steer??this._getEffectiveIsRunning(this._store)?o.steer(e):o.enqueue(e);return}if(i?.catch(()=>{}),e.startRun??e.role==="user"){const a=this._toolInvocations?.abort({discardPending:!0});a&&a!==xo&&await a}if(!s.aborted)if(n||this._pendingDeleteWindows.clear(),this._settleCancelResyncs(),n){if(!this._store.onEdit)throw new Error("Runtime does not support editing messages.");const a=this._openDeleteWindow(e.parentId);try{await this._store.onEdit(e)}catch(l){throw this._pendingDeleteWindows.delete(a),l}}else await this._store.onNew(e)}_commitVoiceMessage(t){const e=fr(this);if(e.aborted){this._dropVoiceMessage(t.id,!1);return}const n=this._getVoiceCommitBarrier();if(!n){this._store.onVoiceTranscript?.(t);return}const r=this.repository;return n.then(()=>{if(e.aborted||this.repository!==r){this._dropVoiceMessage(t.id,!0);return}this._store.onVoiceTranscript?.(t)})}async deleteMessage(t){if(this._store.onDelete){const n=this.repository.getMessages().find(o=>o.id===t),r=Symbol();let s=this._pendingDeleteEvictions.get(t);if(n){let o=!1;for(const a of this._pendingDeleteWindows)if(!a.prefix.has(t)){o=!0;break}(!s||t.startsWith("__external_store_fallback_")&&s.message!==n)&&(s={calls:new Set,reloaded:o,message:n}),o&&(s.reloaded=!0),s.calls.add(r),this._pendingDeleteEvictions.set(t,s)}let i=!1;try{await this._store.onDelete(t),i=!0}finally{s&&this._pendingDeleteEvictions.get(t)===s&&s.calls.delete(r)&&(s.reloaded&&i?(s.reloaded=!1,this._storeMessages.some(o=>o.id===t)||(this._pendingDeleteEvictions.delete(t),this._evictDeletedMessage(t,s.message))):s.reloaded&&s.calls.size===0&&this._pendingDeleteEvictions.delete(t))}return}if(!this._store.setMessages)throw new Error("Runtime does not support deleting messages.");this._getEffectiveIsRunning(this._store)&&await this._toolInvocations?.abort();const e=this.repository.getMessages();if(e.findIndex(n=>n.id===t)===-1)throw new Error("Message not found.");this._pendingDeleteEvictions.clear(),this.updateMessages(e.filter(n=>n.id!==t)),this._evictDeletedMessage(t)}_evictDeletedMessage(t,e,n=!0){if(!(t.startsWith("__external_store_fallback_")&&!e)){try{const r=this.repository.getMessage(t).message;if(t.startsWith("__external_store_fallback_")&&r!==e)return}catch{return}this.repository.deleteMessage(t),n&&this._publishRepositoryMessages()}}_publishRepositoryMessages(){this._syncRepositoryMessages(),this._notifySubscribers()}_syncRepositoryMessages(){const t=this.repository.getMessages();Gr(this._messages,t)||(this._messages=t)}getQueueItems(){return this._store?.queue?.items??Cr}getSteerQueueItems(){return this._store?.queue?.steerItems??Cr}moveQueueItem(t,e){this._store?.queue?.move(t,e)}removeQueueItem(t){this._store?.queue?.remove(t)}_restoreMovedLeafForRun(t){const e=this._movedLeaf;e?.id===t&&e.resyncLease.isCurrent()&&!e.generation.aborted&&this._storeMessages.some(n=>n.id===e.id)&&(this._cancelRunResyncLeases.invalidate(),this._movedLeaf=void 0,this.composer.retractDraft(e.draft),this._updateStoreSnapshot(this._store,!1,!0))}async startRun(t){if(!this._store.onReload)throw new Error("Runtime does not support reloading messages.");if(this.voice)throw new Error("Cannot start a run while a voice session is connected");if(this._isVoiceMessage(t.sourceId))throw new Error("Voice transcript messages cannot be reloaded");this._restoreMovedLeafForRun(t.parentId),this._runStartLeases.begin(),this._cancelledToolTurn?.parentId===t.parentId&&(this._cancelledToolTurn.parentOpen=!1);const e=this._openDeleteWindow(t.parentId),n=this._runCancellationLeases.current();try{if(await this._toolInvocations?.abort({discardPending:!0}),!n.isCurrent()){this._pendingDeleteWindows.delete(e);return}await this._store.onReload(t.parentId,t)}catch(r){throw this._pendingDeleteWindows.delete(e),r}}async resumeRun(t){if(!this._store.onResume)throw new Error("Runtime does not support resuming runs.");if(this.voice)throw new Error("Cannot start a run while a voice session is connected");if(this._isVoiceMessage(t.sourceId))throw new Error("Voice transcript messages cannot be reloaded");const e=this._store;if(this._pendingResume)return this._pendingResume;const n=async()=>{this._pendingDeleteWindows.clear(),this._restoreMovedLeafForRun(t.parentId),this._runStartLeases.begin(),this._cancelledToolTurn=null,await e.onResume(t)};if(e.canResume!==!0)return n();let r;const s=new Promise((i,o)=>{r=()=>{try{i(n())}catch(a){o(a)}}}).finally(()=>{this._clearPendingResume(s)});return this._pendingResume=s,this._notifySubscribers(),r(),s}exportExternalState(){if(!this._store.onExportExternalState)throw new Error("Runtime does not support exporting external states.");return this._store.onExportExternalState()}importExternalState(t){if(!this._store.onLoadExternalState)throw new Error("Runtime does not support importing external states.");this._pendingDeleteWindows.clear(),this._cancelRunResyncLeases.invalidate(),this._cancelledToolTurn=null,this._cancelledRunIds.clear();const e=this._pendingResume;this._runTrackerUpdate(()=>this._toolInvocations?.reset()),this._store.onLoadExternalState(t),this._clearPendingResume(e)}unstable_notifySessionReset(){this._cancelRunResyncLeases.invalidate(),this._cancelledToolTurn=null,this._cancelledRunIds.clear(),this._clearPendingResume(this._pendingResume),this._runTrackerUpdate(()=>this._toolInvocations?.reset()),this._store.queue?.__internal_notifyCancelled?.()}cancelRun(){if(!this._store.onCancel)throw new Error("Runtime does not support cancelling runs.");this._pendingDeleteWindows.clear();const t=this._getEffectiveIsRunning(this._store);this._runCancellationLeases.invalidate();const e=fr(this),n=this._cancelRunResyncLeases.current();if(this._store.activeRunId!==void 0&&this._cancelledRunIds.add(this._store.activeRunId),t){const u=this._storeMessages.filter(f=>!f.metadata.isOptimistic),d=u.at(-1);this._cancelledToolTurn={messageIds:new Set(d?.role==="assistant"?[d.id]:[]),parentId:d?.role==="assistant"?u.at(-2)?.id??null:d?.id??null,parentOpen:!0,lease:this._runStartLeases.current()}}this._toolInvocations?.abort({discardPending:!0}),this._store.queue?.__internal_notifyCancelled?.(),Ei("onCancel",this._store.onCancel()),this.dropEmptyOptimisticHead();const r=this.repository.getMessages(),s=r[r.length-1],i=s?.id??null,o=this._runStartLeases.current(),a=t&&this._store.setMessages!==void 0&&s?.role==="user"&&s.id===r.at(-1)?.id&&s.content.every(u=>u.type==="text")?s:void 0;let l;if(a){const u={text:un(a),attachments:a.attachments,quote:a.metadata.custom.quote};this.composer.restoreDraft(u)&&(this.repository.deleteMessage(a.id),l={id:a.id,draft:u,resyncLease:n,generation:e},this._movedLeaf=l)}this._publishRepositoryMessages();const c=()=>{if(e.aborted||!n.isCurrent())return;if(this._getEffectiveIsRunning(this._store)&&(!o.isCurrent()||(this.repository.getMessages().at(-2)?.id??null)!==i)||this.dropEmptyOptimisticHead(),l){const d=this.repository.getMessages();this._movedLeaf===l&&d.at(-1)?.id===l.id&&this.composer.text===l.draft.text&&this.repository.deleteMessage(l.id)}this._publishRepositoryMessages();const u=this._messages.filter(d=>d.id!==this._optimistic?.message.id);Gr(u,this._storeMessages)||this.updateMessages(u)};this._pendingCancelResyncs.add(c),setTimeout(()=>{this._pendingCancelResyncs.delete(c),c()},0)}_settleCancelResyncs(){for(const t of this._pendingCancelResyncs)t()}dropEmptyOptimisticHead(){const t=this.repository.getMessages().at(-1);t&&t.metadata.isOptimistic&&t.content.length===0&&this.repository.deleteMessage(t.id)}addToolResult(t){if(!this._store.onAddToolResult)throw new Error("Runtime does not support tool results.");Ei("onAddToolResult",this._store.onAddToolResult(t))}resumeToolCall(t){if(!(this._toolInvocations?.resume(t.toolCallId,t.payload)??!1)){if(this._store.onResumeToolCall){this._store.onResumeToolCall(t);return}throw new Error(`Tool call ${t.toolCallId} is not waiting for resume.`)}}respondToToolApproval(t){if(!this._store.onRespondToToolApproval)throw new Error("Runtime does not support tool approvals.");const e=this.messages.findLast(r=>r.role==="assistant"&&r.content.some(s=>s.type==="tool-call"&&s.approval?.id===t.approvalId)),n=e?.content.find(r=>r.type==="tool-call"&&r.approval?.id===t.approvalId);try{return Promise.resolve(this._store.onRespondToToolApproval(t)).then(()=>{e&&n?.type==="tool-call"&&this._notifyToolApprovalAnswered(e.id,n.toolCallId,n.toolName,t.approved)})}catch(r){return Promise.reject(r)}}async unstable_recordToolInteraction(t){if(!this._store.unstable_onRecordToolInteraction)throw new Error("Runtime does not support recording tool interactions.");await this._store.unstable_onRecordToolInteraction(t)}reset(t){const e=this._pendingResume;this._pendingDeleteWindows.clear(),this._cancelRunResyncLeases.invalidate(),this._cancelledToolTurn=null,this._cancelledRunIds.clear(),this._submittedFeedback.clear(),this._importedMessageIds=void 0;const n=new Gs;n.import(Mh.fromArray(t??[])),this.updateMessages(n.getMessages()),this._clearPendingResume(e)}import(t){if(!this._store.onImport)throw new Error("Runtime does not support importing messages.");Ph(t);const e=this._pendingResume;this._pendingDeleteWindows.clear(),this._cancelRunResyncLeases.invalidate(),this._cancelledToolTurn=null,this._cancelledRunIds.clear(),this._submittedFeedback.clear(),super.import(t),this._clearPendingResume(e);const n=this.repository.getMessages();this._importedMessageIds=n.map(r=>r.id),this._store.onImport(n)}updateMessages=t=>{this._storeMessages=t,this._store.convertMessage!==void 0?this._store.setMessages?.(t.flatMap(uv)):this._store.setMessages?.(t)}};const Mc=t=>t.adapters?.threadList??{};var Hw=class extends Oh{threads;_adapter;constructor(t){super(),this._adapter=t,this.threads=new Nw(Mc(t),()=>new qw(this._contextProvider,this._adapter))}setAdapter(t){this._adapter=t,this.threads.__internal_setAdapter(Mc(t)),this.threads.getMainThreadRuntimeCore().__internal_setAdapter(t)}};const La=(t,e,n)=>{const r=t.toolUIs[e.toolName]?.[0]?.render??null;return r||n||(Cv(e.mcp?.app?.resourceUri)&&t.mcpApp?t.mcpApp.render:null)},Pc=String.raw`"(?:[^"\\\u0000-\u001f]|\\(?:["\\/bfnrt]|u[\da-fA-F]{4})){1,1024}"`,Ww=new RegExp(String.raw`:([\w-]{1,64})(?:\[([^\]\n]{1,1024})\](?:\{name=([^}\n]{1,1024})\})?|\{label=(${Pc})(?: name=(${Pc}))?\})`,"gu"),Fa={serialize(t){if(t.label.includes("]")||t.id!==t.label&&t.id.includes("}")){const n=t.id!==t.label?` name=${JSON.stringify(t.id)}`:"";return`:${t.type}{label=${JSON.stringify(t.label)}${n}}`}const e=t.id!==t.label?`{name=${t.id}}`:"";return`:${t.type}[${t.label}]${e}`},parse(t){const e=[];let n=0;for(const r of t.matchAll(Ww)){r.index>n&&e.push({kind:"text",text:t.slice(n,r.index)});const s=r[4]===void 0?r[2]:JSON.parse(r[4]),i=r[5]===void 0?r[3]??s:JSON.parse(r[5]);e.push({kind:"mention",type:r[1],label:s,id:i}),n=r.index+r[0].length}return n<t.length&&e.push({kind:"text",text:t.slice(n)}),e}},Gw=Fa,Kw=()=>{const t=R(4),[e,n]=ie(Yw);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=(l,c)=>(n(u=>{const d=Ge(u.renderers);return d[l]=[...d[l]??[],c],{...u,renderers:d}}),()=>{n(u=>{const d=Ge(u.renderers),f=d[l]?.filter(h=>h!==c)??[];return f.length>0?d[l]=f:delete d[l],{...u,renderers:d}})}),t[0]=r):r=t[0];const s=r;let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=l=>(n(c=>({...c,fallbacks:[...c.fallbacks,l]})),()=>{n(c=>({...c,fallbacks:c.fallbacks.filter(u=>u!==l)}))}),t[1]=i):i=t[1];const o=i;let a;return t[2]!==e?(a={getState:()=>e,setDataUI:s,setFallbackDataUI:o},t[2]=e,t[3]=a):a=t[3],a},Qw=ce(Kw);function Yw(){return{renderers:Ge(),fallbacks:[]}}const Jw=()=>()=>{},Xw=()=>yn(Jw,ex,tx),Zw=(t,e)=>{(Xw()?Q:Ud)(t,e)};function ex(){return!1}function tx(){return typeof document>"u"}const nx=(t,e)=>t.length===e.length&&t.every((n,r)=>Object.is(n,e[r])),Gh=(t,e)=>{const[n]=ie(()=>({pending:void 0}));Q(()=>{const r=n.pending;n.pending=void 0;let s;return r!==void 0&&nx(r.deps,e)?s=r:(r?.cleanup?.(),s={deps:e,cleanup:t()}),()=>{n.pending=s,queueMicrotask(()=>{n.pending===s&&(n.pending=void 0,s.cleanup?.())})}},e)},So=[],rx={modelName:void 0,toolNames:So},sx=(t,e)=>t===e||zt(t,e),Xr=(t,e)=>{const n=t.getModelContext(),r=n.config?.modelName,s=n.tools?Object.keys(n.tools).sort():So,i=s.length?s:So;return r===e.modelName&&sx(i,e.toolNames)?e:{modelName:r,toolNames:i}},ix=(t={})=>{const e=X(t);ct(()=>{e.current=t});const n=ye(()=>new Ea(()=>e.current),[]),{maxSystemLength:r,mergeSystem:s}=t,i=X({maxSystemLength:r,mergeSystem:s});Q(()=>{const l=i.current;l.maxSystemLength===r&&l.mergeSystem===s||(i.current={maxSystemLength:r,mergeSystem:s},n.notifySubscribers())},[n,r,s]);const[o,a]=ie(()=>Xr(n,rx));return Q(()=>(a(l=>Xr(n,l)),n.subscribe(()=>{a(l=>Xr(n,l))})),[n]),{getState:()=>Xr(n,o),getModelContext:()=>n.getModelContext(),subscribe:l=>n.subscribe(l),register:l=>n.registerModelContextProvider(l)}},Kh=ce(ix),ox=(t,e)=>{if(!(e.status?.type==="running"||e.status?.type==="requires-action")){const r=t.complete;return typeof r!="function"?r??null:r({args:e.args,result:e.result})}const n=t.running;return typeof n!="function"?n??null:n({args:e.args})},ax=t=>t.display!==void 0?t.display==="standalone":t.type==="human",lx=t=>function(n){return ox(t,n)},Qh=t=>{const e=R(16),{toolkit:n,mcpApp:r}=t;let s;e[0]!==r?(s=r?[Re("mcpApp",r)]:[],e[0]=r,e[1]=s):s=e[1];const i=va(s)[0],[o,a]=ie(ux);let l;e[2]!==i||e[3]!==o?(l={toolUIs:o,mcpApp:i},e[2]=i,e[3]=o,e[4]=l):l=e[4];const c=l,u=Jd();let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=(b,v,w)=>{const k={render:v,renderText:w?.renderText,standalone:w?.standalone??!1};return a(_=>{const A=Ge(_);return A[b]=[...A[b]??[],k],A}),()=>{a(_=>{const A=_[b]?.filter(D=>D!==k)??[],E=Ge(_);return A.length>0?(E[b]=A,E):(delete E[b],E)})}},e[5]=d):d=e[5];const f=d;let h,p;e[6]!==n?(h=()=>{if(!n)return;const b=[];for(const[v,w]of Object.entries(n)){const k="render"in w?w.render:void 0,_="renderText"in w?w.renderText:void 0,A=k??(_?lx(_):void 0);A&&b.push(f(v,A,{standalone:ax(w),renderText:_}))}return()=>Gn(b)},p=[n,f],e[6]=n,e[7]=h,e[8]=p):(h=e[7],p=e[8]),Q(h,p);let m;e[9]!==u||e[10]!==n?(m=()=>{if(!n)return;const b=Object.entries(n).reduce(dx,Ge());return u.current.modelContext().register({getModelContext:()=>({tools:b})})},e[9]=u,e[10]=n,e[11]=m):m=e[11];let y;e[12]!==n?(y=[n],e[12]=n,e[13]=y):y=e[13],Xd("modelContext",m,y);let g;return e[14]!==c?(g={getState:()=>c,setToolUI:f},e[14]=c,e[15]=g):g=e[15],g},cx=ce(Qh);Qd(Qh,(t,e)=>{!t.modelContext&&e.modelContext.source===null&&(t.modelContext=Kh())});function ux(){return Ge()}function dx(t,e){const[n,r]=e;if(r.type==="mcp")return t;const{display:s,render:i,renderText:o,...a}=r;return t[n]=a,t}const wn=(t,e)=>(Vb(e?.live?t.subscribe:void 0),yn(t.subscribe,t.getState,t.getServerSnapshot)),hx=Symbol.for("assistant-ui.silent-runtime-action"),fx=t=>typeof t=="object"&&t!==null&&hx in t,Yh=(t,e)=>{const n=e();return n.catch(r=>{fx(r)||console.error(`[assistant-ui] ${t} failed:`,r)}),n},px=t=>{const e=R(9),{runtime:n}=t,r=wn(n);let s;e[0]!==r?(s=()=>r,e[0]=r,e[1]=s):s=e[1];let i,o;e[2]!==n?(i=()=>Yh("attachment remove",n.remove),o=()=>n,e[2]=n,e[3]=i,e[4]=o):(i=e[3],o=e[4]);let a;return e[5]!==s||e[6]!==i||e[7]!==o?(a={getState:s,remove:i,__internal_getRuntime:o},e[5]=s,e[6]=i,e[7]=o,e[8]=a):a=e[8],a},Jh=ce(px),mx=({item:t,onMove:e,onRemove:n})=>({getState:()=>t,steer:()=>e({lane:"steer",insertAfter:null}),move:e,remove:n}),gx=ce(mx),yx=t=>{const e=R(5),{runtime:n,index:r}=t;let s;e[0]!==r||e[1]!==n?(s=n.getAttachmentByIndex(r),e[0]=r,e[1]=n,e[2]=s):s=e[2];const i=s;let o;return e[3]!==i?(o=Jh({runtime:i}),e[3]=i,e[4]=o):o=e[4],ze(o)},bx=ce(yx),Xh=(t,e,n)=>({text:t.text,role:t.role,attachments:e,runConfig:t.runConfig,isEditing:t.isEditing,canCancel:t.canCancel,canSend:t.canSend,attachmentAccept:t.attachmentAccept,isEmpty:t.isEmpty,type:t.type??"thread",dictation:t.dictation,lastDictationEnd:t.lastDictationEnd,quote:t.quote,queue:n,submission:t.submission,inTransit:t.inTransit}),_x=(t,e,n)=>{let r,s;return()=>{const i=t.getState();return i===e?n:(i!==r&&(r=i,s=Xh(i,n.attachments,n.queue)),s)}},vx=t=>{const e=R(56),{threadIdRef:n,messageIdRef:r,runtime:s,isSuggestion:i}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={live:!0},e[0]=o):o=e[0];const a=wn(s,o),l=Wn(),c=X(!1);let u,d;e[1]!==l||e[2]!==r||e[3]!==s||e[4]!==n?(u=()=>{const P=[],T=s.unstable_on("send",L=>{const j=c.current;c.current=!1,l("composer.send",{threadId:n.current,...r&&{messageId:r.current},chars:L.chars,attachments:L.attachments,...j?{suggestion:!0}:void 0})});P.push(T);const $=s.unstable_on("attachmentAdd",L=>{l("composer.attachmentAdd",{threadId:n.current,...r&&{messageId:r.current},...L.contentType?{contentType:L.contentType}:void 0})});return P.push($),P.push(s.unstable_on("attachmentAddError",L=>{l("composer.attachmentAddError",{threadId:n.current,...r&&{messageId:r.current},...L.attachmentId&&{attachmentId:L.attachmentId},reason:L.reason,message:L.message,...L.contentType?{contentType:L.contentType}:void 0})})),P.push(s.unstable_on("textChange",L=>{l("composer.textChange",{threadId:n.current,...r&&{messageId:r.current},text:L.text,origin:L.origin})})),()=>Gn(P)},d=[s,l,n,r],e[1]=l,e[2]=r,e[3]=s,e[4]=n,e[5]=u,e[6]=d):(u=e[5],d=e[6]),Q(u,d);let f;if(e[7]!==s||e[8]!==a.attachments){let P;e[10]!==s?(P=(T,$)=>Re(T.id,bx({runtime:s,index:$}),[s,$]),e[10]=s,e[11]=P):P=e[11],f=a.attachments.map(P),e[7]=s,e[8]=a.attachments,e[9]=f}else f=e[9];const h=_t(f),p=a.queue;let m;if(e[12]!==p||e[13]!==s){let P;e[15]!==s?(P=T=>Re(T.id,gx({item:T,onMove:$=>s.moveQueueItem(T.id,$),onRemove:()=>s.removeQueueItem(T.id)})),e[15]=s,e[16]=P):P=e[16],m=p.map(P),e[12]=p,e[13]=s,e[14]=m}else m=e[14];const y=_t(m);let g;e[17]!==h.state||e[18]!==p||e[19]!==a?(g=Xh(a,h.state,p),e[17]=h.state,e[18]=p,e[19]=a,e[20]=g):g=e[20];const b=g;let v;e[21]!==s||e[22]!==a||e[23]!==b?(v=_x(s,a,b),e[21]=s,e[22]=a,e[23]=b,e[24]=v):v=e[24];const w=v;let k;e[25]!==i||e[26]!==s?(k=P=>{const T=s.getState();c.current=T.canSend&&(i?.(T.text)??!1),s.send(P)},e[25]=i,e[26]=s,e[27]=k):k=e[27];let _;e[28]!==l||e[29]!==r||e[30]!==s||e[31]!==n?(_=()=>{!r&&s.getState().canCancel&&l("composer.cancel",{threadId:n.current}),s.cancel()},e[28]=l,e[29]=r,e[30]=s,e[31]=n,e[32]=_):_=e[32];const A=s.beginEdit??wx;let E;e[33]!==h?(E=P=>"id"in P?h.get({key:P.id}):h.get(P),e[33]=h,e[34]=E):E=e[34];let D;e[35]!==y?(D=P=>"id"in P?y.get({key:P.id}):y.get(P),e[35]=y,e[36]=D):D=e[36];let x;e[37]!==s?(x=()=>s,e[37]=s,e[38]=x):x=e[38];let M;return e[39]!==w||e[40]!==s.addAttachment||e[41]!==s.clearAttachments||e[42]!==s.reset||e[43]!==s.setQuote||e[44]!==s.setRole||e[45]!==s.setRunConfig||e[46]!==s.setText||e[47]!==s.startDictation||e[48]!==s.stopDictation||e[49]!==A||e[50]!==E||e[51]!==D||e[52]!==x||e[53]!==k||e[54]!==_?(M={getState:w,setText:s.setText,setRole:s.setRole,setRunConfig:s.setRunConfig,addAttachment:s.addAttachment,reset:s.reset,clearAttachments:s.clearAttachments,send:k,cancel:_,beginEdit:A,startDictation:s.startDictation,stopDictation:s.stopDictation,setQuote:s.setQuote,attachment:E,queueItem:D,__internal_getRuntime:x},e[39]=w,e[40]=s.addAttachment,e[41]=s.clearAttachments,e[42]=s.reset,e[43]=s.setQuote,e[44]=s.setRole,e[45]=s.setRunConfig,e[46]=s.setText,e[47]=s.startDictation,e[48]=s.stopDictation,e[49]=A,e[50]=E,e[51]=D,e[52]=x,e[53]=k,e[54]=_,e[55]=M):M=e[55],M},Zh=ce(vx);function wx(){throw new Error("beginEdit is not supported in this runtime")}const ef=t=>({get current(){return t()}}),xx=t=>{const e=R(17),{runtime:n}=t,r=wn(n);let s;e[0]!==r?(s=()=>r,e[0]=r,e[1]=s):s=e[1];let i,o,a;e[2]!==n?(i=d=>n.addToolResult(d),o=d=>n.resumeToolCall(d),a=d=>n.respondToToolApproval(d),e[2]=n,e[3]=i,e[4]=o,e[5]=a):(i=e[3],o=e[4],a=e[5]);let l;e[6]!==n.unstable_recordInteraction?(l=n.unstable_recordInteraction&&{unstable_recordInteraction:d=>n.unstable_recordInteraction(d)},e[6]=n.unstable_recordInteraction,e[7]=l):l=e[7];let c;e[8]!==n?(c=()=>n,e[8]=n,e[9]=c):c=e[9];let u;return e[10]!==s||e[11]!==i||e[12]!==o||e[13]!==a||e[14]!==l||e[15]!==c?(u={getState:s,addToolResult:i,resumeToolCall:o,respondToToolApproval:a,...l,__internal_getRuntime:c},e[10]=s,e[11]=i,e[12]=o,e[13]=a,e[14]=l,e[15]=c,e[16]=u):u=e[16],u},Sx=ce(xx),Tx={run_stale:"stale",run_in_progress:"in-progress"},Cx=t=>t.content.every(e=>(e.type==="text"||e.type==="reasoning")&&e.text.trim()===""),tf=t=>{if(t.role!=="assistant")return;const e=t.status;if(e?.type!=="incomplete"||e.reason!=="error")return;const n=e.error;if(typeof n!="object"||n===null||Array.isArray(n))return;const r=n.code,s=typeof r=="string"?Tx[r]:void 0;return s==="stale"&&!Cx(t)?void 0:s},Ix=t=>{const e=R(5),{runtime:n,index:r}=t;let s;e[0]!==r||e[1]!==n?(s=n.getAttachmentByIndex(r),e[0]=r,e[1]=n,e[2]=s):s=e[2];const i=s;let o;return e[3]!==i?(o=Jh({runtime:i}),e[3]=i,e[4]=o):o=e[4],ze(o)},kx=ce(Ix),Ex=t=>{const e=R(5),{runtime:n,index:r}=t;let s;e[0]!==r||e[1]!==n?(s=n.getMessagePartByIndex(r),e[0]=r,e[1]=n,e[2]=s):s=e[2];const i=s;let o;return e[3]!==i?(o=Sx({runtime:i}),e[3]=i,e[4]=o):o=e[4],ze(o)},Ax=ce(Ex),Rx=t=>{const e=R(81),{runtime:n,threadIdRef:r,threadId:s,isLast:i}=t,o=wn(n),a=Wn(),[l,c]=ie(!1),[u,d]=ie(!1);let f;e[0]!==n?(f=ef(()=>n.getState().id),e[0]=n,e[1]=f):f=e[1];const h=f,p=X(o.status);let m;e[2]!==a||e[3]!==n||e[4]!==s?(m=O=>{a(O,{threadId:s,messageId:n.getState().id})},e[2]=a,e[3]=n,e[4]=s,e[5]=m):m=e[5];const y=m;let g,b;e[6]!==a||e[7]!==o.id||e[8]!==o.status||e[9]!==s?(g=()=>{const O=o.status,G=p.current;p.current=O,O?.type==="incomplete"&&O.reason==="error"&&(G?.type!=="incomplete"||G.reason!=="error")&&a("message.error",{threadId:s,messageId:o.id,reason:"error"})},b=[o.status,o.id,a,s],e[6]=a,e[7]=o.id,e[8]=o.status,e[9]=s,e[10]=g,e[11]=b):(g=e[10],b=e[11]),Q(g,b);let v;e[12]!==h||e[13]!==n.composer||e[14]!==r?(v=Zh({runtime:n.composer,threadIdRef:r,messageIdRef:h}),e[12]=h,e[13]=n.composer,e[14]=r,e[15]=v):v=e[15];const w=Bn(v);let k;if(e[16]!==n||e[17]!==o.content){let O;e[19]!==n?(O=(G,se)=>Re(G,Ax({runtime:n,index:se}),[n,se]),e[19]=n,e[20]=O):O=e[20],k=vn(o.content).map(O),e[16]=n,e[17]=o.content,e[18]=k}else k=e[18];const _=_t(k);let A;e[21]!==o.attachments?(A=o.attachments??[],e[21]=o.attachments,e[22]=A):A=e[22];let E;if(e[23]!==n||e[24]!==A){let O;e[26]!==n?(O=(G,se)=>Re(G.id,kx({runtime:n,index:se}),[n,se]),e[26]=n,e[27]=O):O=e[27],E=A.map(O),e[23]=n,e[24]=A,e[25]=E}else E=e[25];const D=_t(E),x=o;let M;e[28]!==i?(M=i===!1?{isLast:i}:{},e[28]=i,e[29]=M):M=e[29];const P=o;let T;e[30]!==P?(T=tf(P),e[30]=P,e[31]=T):T=e[31];let $;e[32]!==w.state||e[33]!==l||e[34]!==u||e[35]!==_.state||e[36]!==M||e[37]!==T||e[38]!==x?($={...x,...M,runState:T,parts:_.state,composer:w.state,isCopied:l,isHovering:u},e[32]=w.state,e[33]=l,e[34]=u,e[35]=_.state,e[36]=M,e[37]=T,e[38]=x,e[39]=$):$=e[39];const L=$;let j;e[40]!==L?(j=()=>L,e[40]=L,e[41]=j):j=e[41];let V;e[42]!==w.methods?(V=()=>w.methods,e[42]=w.methods,e[43]=V):V=e[43];let q;e[44]!==n?(q=()=>n.delete(),e[44]=n,e[45]=q):q=e[45];let U,S;e[46]!==y||e[47]!==n?(U=O=>(y("message.reload"),n.reload(O)),S=()=>(y("message.speak"),n.speak()),e[46]=y,e[47]=n,e[48]=U,e[49]=S):(U=e[48],S=e[49]);let J,ee;e[50]!==n?(J=()=>n.stopSpeaking(),ee=O=>n.submitFeedback(O),e[50]=n,e[51]=J,e[52]=ee):(J=e[51],ee=e[52]);let I;e[53]!==y||e[54]!==n?(I=O=>(y("message.branchSwitched"),n.switchToBranch(O)),e[53]=y,e[54]=n,e[55]=I):I=e[55];let de;e[56]!==n?(de=()=>n.unstable_getCopyText(),e[56]=n,e[57]=de):de=e[57];let W;e[58]!==_||e[59]!==o.content?(W=O=>{if("index"in O)return _.get({index:O.index});{const G=o.content.findIndex(se=>se.type==="tool-call"&&se.toolCallId===O.toolCallId);return _.get({index:G})}},e[58]=_,e[59]=o.content,e[60]=W):W=e[60];let K;e[61]!==D?(K=O=>"id"in O?D.get({key:O.id}):D.get(O),e[61]=D,e[62]=K):K=e[62];let le;e[63]!==y?(le=O=>{O&&y("message.copied"),c(O)},e[63]=y,e[64]=le):le=e[64];let te;e[65]!==n?(te=()=>n,e[65]=n,e[66]=te):te=e[66];let fe;return e[67]!==j||e[68]!==V||e[69]!==q||e[70]!==U||e[71]!==S||e[72]!==J||e[73]!==ee||e[74]!==I||e[75]!==de||e[76]!==W||e[77]!==K||e[78]!==le||e[79]!==te?(fe={getState:j,composer:V,delete:q,reload:U,speak:S,stopSpeaking:J,submitFeedback:ee,switchToBranch:I,getCopyText:de,part:W,attachment:K,setIsCopied:le,setIsHovering:d,__internal_getRuntime:te},e[67]=j,e[68]=V,e[69]=q,e[70]=U,e[71]=S,e[72]=J,e[73]=ee,e[74]=I,e[75]=de,e[76]=W,e[77]=K,e[78]=le,e[79]=te,e[80]=fe):fe=e[80],fe},Mx=ce(Rx),Px=t=>{const e=R(7),{type:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=[],e[0]=r):r=e[0];let s;e[1]===Symbol.for("react.memo_cache_sentinel")?(s={},e[1]=s):s=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=[],e[2]=i):i=e[2];let o;e[3]!==n?(o={isEditing:!1,isEmpty:!0,text:"",attachmentAccept:"*",attachments:r,role:"user",runConfig:s,canCancel:!1,canSend:!1,type:n,dictation:void 0,quote:void 0,queue:i,submission:void 0,inTransit:void 0},e[3]=n,e[4]=o):o=e[4];const a=o;let l;return e[5]!==a?(l={getState:()=>a,setText:Ox,setRole:Lx,setRunConfig:Fx,addAttachment:$x,clearAttachments:Nx,attachment:Bx,reset:jx,send:zx,cancel:Vx,startDictation:Ux,stopDictation:qx,beginEdit:Hx,setQuote:Wx,queueItem:Gx},e[5]=a,e[6]=l):l=e[6],l},Dx=ce(Px);function Ox(){throw new Error("Not supported")}function Lx(){throw new Error("Not supported")}function Fx(){throw new Error("Not supported")}function $x(){throw new Error("Not supported")}function Nx(){throw new Error("Not supported")}function Bx(){throw new Error("Not supported")}function jx(){throw new Error("Not supported")}function zx(){throw new Error("Not supported")}function Vx(){throw new Error("Not supported")}function Ux(){throw new Error("Not supported")}function qx(){throw new Error("Not supported")}function Hx(){throw new Error("Not supported")}function Wx(){throw new Error("Not supported")}function Gx(){throw new Error("Not supported")}const Kx=t=>{const e=R(8),{part:n,isMessageRunning:r}=t;let s;e[0]!==r||e[1]!==n?(s=r?Ih(n)??Ze:Ze,e[0]=r,e[1]=n,e[2]=s):s=e[2];let i;e[3]!==n||e[4]!==s?(i={...n,status:s},e[3]=n,e[4]=s,e[5]=i):i=e[5];const o=i;let a;return e[6]!==o?(a={getState:()=>o,addToolResult:e1,resumeToolCall:t1,respondToToolApproval:n1,unstable_recordInteraction:r1},e[6]=o,e[7]=a):a=e[7],a},Qx=ce(Kx),Yx=({attachment:t})=>({getState:()=>t,remove:()=>{throw new Error("Not supported")}}),Jx=ce(Yx),Xx=t=>{const e=R(41),{message:n,index:r,isLast:s,branchNumber:i,branchCount:o,submission:a}=t,l=s===void 0?!0:s,c=i===void 0?1:i,u=o===void 0?1:o,[d,f]=ie(!1),[h,p]=ie(!1),m=n.role==="assistant"&&n.status.type==="running";let y,g;if(e[0]!==m||e[1]!==n.content){const U=vn(n.content);y=_t,g=n.content.map((S,J)=>Re(U[J],Qx({part:S,isMessageRunning:m}),[S,m])),e[0]=m,e[1]=n.content,e[2]=y,e[3]=g}else y=e[2],g=e[3];const b=y(g);let v;e[4]!==n.attachments||e[5]!==a?.attachments?(v=a?.attachments??n.attachments??[],e[4]=n.attachments,e[5]=a?.attachments,e[6]=v):v=e[6];let w;e[7]!==v?(w=v.map(s1),e[7]=v,e[8]=w):w=e[8];const k=_t(w);let _;e[9]===Symbol.for("react.memo_cache_sentinel")?(_=Dx({type:"edit"}),e[9]=_):_=e[9];const A=Bn(_),E=A.state,D=b.state;let x;e[10]!==n?(x=tf(n),e[10]=n,e[11]=x):x=e[11];let M;e[12]!==u||e[13]!==c||e[14]!==E||e[15]!==r||e[16]!==d||e[17]!==h||e[18]!==l||e[19]!==n||e[20]!==b.state||e[21]!==a||e[22]!==x?(M={...n,parts:D,composer:E,parentId:null,index:r,isLast:l,branchNumber:c,branchCount:u,speech:void 0,isCopied:d,isHovering:h,submission:a,runState:x},e[12]=u,e[13]=c,e[14]=E,e[15]=r,e[16]=d,e[17]=h,e[18]=l,e[19]=n,e[20]=b.state,e[21]=a,e[22]=x,e[23]=M):M=e[23];const P=M;let T;e[24]!==P?(T=()=>P,e[24]=P,e[25]=T):T=e[25];let $;e[26]!==A.methods?($=()=>A.methods,e[26]=A.methods,e[27]=$):$=e[27];let L;e[28]!==n.content||e[29]!==b?(L=U=>"index"in U?b.get({index:U.index}):b.get({index:n.content.findIndex(S=>S.type==="tool-call"&&S.toolCallId===U.toolCallId)}),e[28]=n.content,e[29]=b,e[30]=L):L=e[30];let j;e[31]!==k?(j=U=>"id"in U?k.get({key:U.id}):k.get(U),e[31]=k,e[32]=j):j=e[32];let V;e[33]!==n?(V=()=>un(n),e[33]=n,e[34]=V):V=e[34];let q;return e[35]!==T||e[36]!==$||e[37]!==L||e[38]!==j||e[39]!==V?(q={getState:T,composer:$,part:L,attachment:j,delete:i1,reload:o1,speak:a1,stopSpeaking:l1,submitFeedback:c1,switchToBranch:u1,getCopyText:V,setIsCopied:f,setIsHovering:p},e[35]=T,e[36]=$,e[37]=L,e[38]=j,e[39]=V,e[40]=q):q=e[40],q},Zx=ce(Xx);function e1(){throw new Error("Not supported")}function t1(){throw new Error("Not supported")}function n1(){throw new Error("Not supported")}async function r1(){}function s1(t){return Re(t.id,Jx({attachment:t}),[t])}function i1(){throw new Error("Not supported in ThreadMessageProvider")}function o1(){throw new Error("Not supported in ThreadMessageProvider")}function a1(){throw new Error("Not supported in ThreadMessageProvider")}function l1(){throw new Error("Not supported in ThreadMessageProvider")}function c1(){throw new Error("Not supported in ThreadMessageProvider")}function u1(){throw new Error("Not supported in ThreadMessageProvider")}const d1=t=>zn({role:t.role,content:t.role==="system"||t.text?[{type:"text",text:t.text}]:[],attachments:[],metadata:{custom:{...t.quote?{quote:t.quote}:{}}}},t.id,{type:"complete",reason:"unknown"}),h1=t=>{const e=ye(()=>({}),[]),n=e.state,r=[];t.suggestions.forEach(i=>{const o=n?.suggestions[r.length];r.push(o&&zt(o,i)?o:i)});const s=n&&zt(r,n.suggestions)?n:{suggestions:r};return e.state=s,s},f1=t=>({getState:()=>t}),p1=ce(f1),m1=t=>{const e=R(9),n=h1(t);let r;e[0]!==n.suggestions?(r=n.suggestions.map(b1),e[0]=n.suggestions,e[1]=r):r=e[1];const s=_t(r);let i;e[2]!==n?(i=()=>n,e[2]=n,e[3]=i):i=e[3];let o;e[4]!==s?(o=l=>{const{index:c}=l;return s.get({index:c})},e[4]=s,e[5]=o):o=e[5];let a;return e[6]!==i||e[7]!==o?(a={getState:i,suggestion:o},e[6]=i,e[7]=o,e[8]=a):a=e[8],a},g1=t=>{const e=R(4);let n;e[0]!==t?(n=t.map(_1),e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r={suggestions:n},e[2]=n,e[3]=r):r=e[3],m1(r)},y1=ce(g1);function b1(t,e){return Re(e,p1(t),[t])}function _1(t){return{title:t.title??t.prompt,label:t.label??"",prompt:t.prompt}}const v1=t=>"reason"in t?t.reason:void 0,w1=t=>"error"in t?t.error:void 0,x1=32,nf=new WeakMap,rf=t=>nf.get(t)??t.id,S1=(t,e,n)=>"status"in t&&t.status?Eh(t,e,n):Ze,T1=()=>{let t=[],e=new Map;return n=>{const r=[],s=new Map;let i=!0;const o=(l,c,u,d)=>{if(!(u>x1))for(const[f,h]of l.entries())for(const[p,m]of h.content.entries()){if(m.type!=="tool-call"||m.messages===void 0)continue;const y=m.messages,g=S1(h,p,m),b=v1(g),v=w1(g),w=`${d}${f}.${p}`,k=e.get(w),_=k?.part===m&&k.statusType===g.type&&k.statusReason===b&&Object.is(k.statusError,v)&&k.messages===y&&k.task.messageId===h.id&&k.task.parentTaskId===c&&k.task.depth===u?k.task:{id:m.toolCallId,toolName:m.toolName,args:m.args,result:m.result,...m.isError===void 0?void 0:{isError:m.isError},status:g,timing:m.timing,messageId:h.id,parentTaskId:c,depth:u,messages:y};_!==k?.task&&(i=!1,nf.set(_,w)),r.push(_),s.set(w,{task:_,part:m,statusType:g.type,statusReason:b,statusError:v,messages:y}),o(y,_.id,u+1,`${w}.`)}};o(n,null,0,"");const a=i&&r.length===t.length&&r.every((l,c)=>l===t[c])?t:r;return t=a,e=s,a}},C1=({task:t})=>({getState:()=>t}),I1=ce(C1),k1=t=>{const e=R(8),{runtime:n,id:r,threadIdRef:s,threadId:i,isLast:o}=t;let a;e[0]!==r||e[1]!==n?(a=n.getMessageById(r),e[0]=r,e[1]=n,e[2]=a):a=e[2];const l=a;let c;return e[3]!==o||e[4]!==l||e[5]!==i||e[6]!==s?(c=Mx({runtime:l,threadIdRef:s,threadId:i,isLast:o}),e[3]=o,e[4]=l,e[5]=i,e[6]=s,e[7]=c):c=e[7],ze(c)},E1=ce(k1),A1=(t,e)=>{const n=R(31),r=Wn();let s,i;n[0]!==r||n[1]!==t?(s=()=>{const g=[];for(const b of["runStart","runEnd","initialize","modelContextUpdate"]){const v=t.unstable_on(b,()=>{const w=t.getState()?.threadId||"unknown";r(`thread.${b}`,{threadId:w})});g.push(v)}return g.push(t.unstable_on("historyWriteError",b=>{const v=t.getState()?.threadId||"unknown";r("thread.historyWriteError",{threadId:v,operation:b.operation,messageIds:b.messageIds,message:b.message})}),t.unstable_on("toolApprovalAnswered",b=>{const v=t.getState()?.threadId||"unknown";r("thread.toolApprovalAnswered",{threadId:v,...b})})),()=>Gn(g)},i=[t,r],n[0]=r,n[1]=t,n[2]=s,n[3]=i):(s=n[2],i=n[3]),Q(s,i);let o;n[4]!==t?(o=ef(()=>t.getState().threadId),n[4]=t,n[5]=o):o=n[5];const a=o;let l;n[6]!==r||n[7]!==t?(l=g=>{r(g,{threadId:t.getState().threadId})},n[6]=r,n[7]=t,n[8]=l):l=n[8];const c=l;let u;n[9]!==t?(u=g=>t.getState().suggestions.some(b=>b.prompt===g),n[9]=t,n[10]=u):u=n[10];const d=u;let f;n[11]!==r||n[12]!==d||n[13]!==t?(f=g=>{const b=typeof g=="string"?{content:[{type:"text",text:g}]}:g;if((b.role??"user")==="user"){const v=b.content.map(O1).join("");r("composer.send",{threadId:t.getState().threadId,chars:v.length,attachments:b.attachments?.length??0,...d(v)?{suggestion:!0}:void 0})}t.append(g)},n[11]=r,n[12]=d,n[13]=t,n[14]=f):f=n[14];let h;n[15]!==c||n[16]!==e||n[17]!==t?(h=()=>{e&&c("thread.cancelRun"),t.cancelRun()},n[15]=c,n[16]=e,n[17]=t,n[18]=h):h=n[18];let p;n[19]!==t?(p=()=>t.loadEarlier(),n[19]=t,n[20]=p):p=n[20];let m;n[21]!==c||n[22]!==t?(m=()=>{t.connectVoice(),c("thread.voiceStarted")},n[21]=c,n[22]=t,n[23]=m):m=n[23];let y;return n[24]!==d||n[25]!==f||n[26]!==h||n[27]!==p||n[28]!==m||n[29]!==a?(y={threadIdRef:a,isSuggestion:d,append:f,cancelRun:h,loadEarlier:p,connectVoice:m},n[24]=d,n[25]=f,n[26]=h,n[27]=p,n[28]=m,n[29]=a,n[30]=y):y=n[30],y};function Ai(t){return()=>t}const R1=(t,e)=>n=>{if("id"in n){const r=t.find(s=>s.id===n.id);return e.get({key:r?rf(r):n.id})}return e.get(n)},M1=t=>e=>"id"in e?t.get({key:e.id}):t.get(e),P1=t=>{const e=R(94),{runtime:n}=t,r=wn(n),{threadIdRef:s,isSuggestion:i,append:o,cancelRun:a,loadEarlier:l,connectVoice:c}=A1(n,r.isRunning);let u;e[0]!==i||e[1]!==n.composer||e[2]!==s?(u=Zh({runtime:n.composer,threadIdRef:s,isSuggestion:i}),e[0]=i,e[1]=n.composer,e[2]=s,e[3]=u):u=e[3];const d=Bn(u);let f;e[4]!==r.suggestions?(f=y1(r.suggestions),e[4]=r.suggestions,e[5]=f):f=e[5];const h=Bn(f);let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=T1(),e[6]=p):p=e[6];const m=p;let y;e[7]!==r.messages?(y=m(r.messages),e[7]=r.messages,e[8]=y):y=e[8];const g=y;let b;e[9]!==g?(b=g.map(L1),e[9]=g,e[10]=b):b=e[10];const v=_t(b),w=d.state.submission,k=d.state.inTransit;let _;e[11]!==k?(_=k??[],e[11]=k,e[12]=_):_=e[12];let A;e[13]!==w?(A=w?[w]:[],e[13]=w,e[14]=A):A=e[14];let E;e[15]!==_||e[16]!==A?(E=[..._,...A],e[15]=_,e[16]=A,e[17]=E):E=e[17];const D=E;let x;e[18]!==D?(x=D.map(d1),e[18]=D,e[19]=x):x=e[19];const M=x,P=r.messages.length-1;let T;if(e[20]!==P||e[21]!==D||e[22]!==M||e[23]!==n||e[24]!==r.messages||e[25]!==r.threadId||e[26]!==s){let St;e[28]!==P||e[29]!==D.length||e[30]!==n||e[31]!==r.threadId||e[32]!==s?(St=(Tt,Ct)=>{const Br=Ct===P&&D.length>0?!1:void 0;return Re(Tt.id,E1({runtime:n,id:Tt.id,threadIdRef:s,threadId:r.threadId,isLast:Br}),[n,Tt.id,s,r.threadId,Br])},e[28]=P,e[29]=D.length,e[30]=n,e[31]=r.threadId,e[32]=s,e[33]=St):St=e[33];const Kt=r.messages.map(St);let Cn;e[34]!==D||e[35]!==M||e[36]!==r.messages.length?(Cn=D.map((Tt,Ct)=>Re(Tt.id,Zx({message:M[Ct],submission:Tt,index:r.messages.length+Ct,isLast:Ct===D.length-1}),[M[Ct],Tt,r.messages.length,Ct,D.length])),e[34]=D,e[35]=M,e[36]=r.messages.length,e[37]=Cn):Cn=e[37],T=[...Kt,...Cn],e[20]=P,e[21]=D,e[22]=M,e[23]=n,e[24]=r.messages,e[25]=r.threadId,e[26]=s,e[27]=T}else T=e[27];const $=_t(T),L=$.state.length===0&&!r.isLoading,j=r.canResume??!1;let V;e[38]!==d.state||e[39]!==$.state||e[40]!==r.capabilities||e[41]!==r.extras||e[42]!==r.hasEarlier||e[43]!==r.isDisabled||e[44]!==r.isLoading||e[45]!==r.isLoadingEarlier||e[46]!==r.isRunning||e[47]!==r.isSendDisabled||e[48]!==r.speech||e[49]!==r.state||e[50]!==r.suggestions||e[51]!==r.voice||e[52]!==L||e[53]!==j||e[54]!==g?(V={isEmpty:L,isDisabled:r.isDisabled,isSendDisabled:r.isSendDisabled,isLoading:r.isLoading,hasEarlier:r.hasEarlier,isLoadingEarlier:r.isLoadingEarlier,isRunning:r.isRunning,canResume:j,capabilities:r.capabilities,state:r.state,suggestions:r.suggestions,extras:r.extras,speech:r.speech,voice:r.voice,composer:d.state,messages:$.state,tasks:g},e[38]=d.state,e[39]=$.state,e[40]=r.capabilities,e[41]=r.extras,e[42]=r.hasEarlier,e[43]=r.isDisabled,e[44]=r.isLoading,e[45]=r.isLoadingEarlier,e[46]=r.isRunning,e[47]=r.isSendDisabled,e[48]=r.speech,e[49]=r.state,e[50]=r.suggestions,e[51]=r.voice,e[52]=L,e[53]=j,e[54]=g,e[55]=V):V=e[55];const q=V;let U;e[56]!==q?(U=()=>q,e[56]=q,e[57]=U):U=e[57];let S;e[58]!==d.methods?(S=Ai(d.methods),e[58]=d.methods,e[59]=S):S=e[59];let J;e[60]!==h.methods?(J=Ai(h.methods),e[60]=h.methods,e[61]=J):J=e[61];let ee;e[62]!==v||e[63]!==g?(ee=R1(g,v),e[62]=v,e[63]=g,e[64]=ee):ee=e[64];const I=n.deleteMessage,de=n.startRun,W=n.resumeRun,K=n.importExternalState,le=n.getModelContext,te=n.export,fe=n.import,O=n.reset,G=n.stopSpeaking,se=n.disconnectVoice,we=n.getVoiceVolume,Zn=n.subscribeVoiceVolume,xt=n.muteVoice,Tn=n.unmuteVoice;let He;e[65]!==$?(He=M1($),e[65]=$,e[66]=He):He=e[66];let Qe;e[67]!==n?(Qe=Ai(n),e[67]=n,e[68]=Qe):Qe=e[68];let Ft;return e[69]!==o||e[70]!==a||e[71]!==c||e[72]!==l||e[73]!==n.deleteMessage||e[74]!==n.disconnectVoice||e[75]!==n.export||e[76]!==n.getModelContext||e[77]!==n.getVoiceVolume||e[78]!==n.import||e[79]!==n.importExternalState||e[80]!==n.muteVoice||e[81]!==n.reset||e[82]!==n.resumeRun||e[83]!==n.startRun||e[84]!==n.stopSpeaking||e[85]!==n.subscribeVoiceVolume||e[86]!==n.unmuteVoice||e[87]!==U||e[88]!==S||e[89]!==J||e[90]!==ee||e[91]!==He||e[92]!==Qe?(Ft={getState:U,composer:S,suggestions:J,task:ee,append:o,deleteMessage:I,startRun:de,resumeRun:W,importExternalState:K,cancelRun:a,loadEarlier:l,getModelContext:le,export:te,import:fe,reset:O,stopSpeaking:G,connectVoice:c,disconnectVoice:se,getVoiceVolume:we,subscribeVoiceVolume:Zn,muteVoice:xt,unmuteVoice:Tn,message:He,__internal_getRuntime:Qe},e[69]=o,e[70]=a,e[71]=c,e[72]=l,e[73]=n.deleteMessage,e[74]=n.disconnectVoice,e[75]=n.export,e[76]=n.getModelContext,e[77]=n.getVoiceVolume,e[78]=n.import,e[79]=n.importExternalState,e[80]=n.muteVoice,e[81]=n.reset,e[82]=n.resumeRun,e[83]=n.startRun,e[84]=n.stopSpeaking,e[85]=n.subscribeVoiceVolume,e[86]=n.unmuteVoice,e[87]=U,e[88]=S,e[89]=J,e[90]=ee,e[91]=He,e[92]=Qe,e[93]=Ft):Ft=e[93],Ft},D1=ce(P1);function O1(t){return t.type==="text"?t.text:""}function L1(t){return Re(rf(t),I1({task:t}),[t])}const F1=t=>{const e=R(4),n=Wn(),r=X(t);let s,i;e[0]!==n||e[1]!==t?(s=()=>{const o=r.current;o!==t&&(r.current=t,n("threads.selectionChanged",{threadId:t,previousThreadId:o}))},i=[t,n],e[0]=n,e[1]=t,e[2]=s,e[3]=i):(s=e[2],i=e[3]),Q(s,i)},$1=(t,e,n)=>{const r=R(8),s=e,i=Wn(),o=e&&s;let a;r[0]!==o||r[1]!==t?(a={isMain:o,threadId:t},r[0]=o,r[1]=t,r[2]=a):a=r[2];const l=X(a);let c,u;r[3]!==i||r[4]!==e||r[5]!==t?(c=()=>{const d=l.current;d.isMain===e&&d.threadId===t||(l.current={isMain:e,threadId:t},i(e?"threadListItem.switchedTo":"threadListItem.switchedAway",{threadId:t}))},u=[e,t,i],r[3]=i,r[4]=e,r[5]=t,r[6]=c,r[7]=u):(c=r[6],u=r[7]),Q(c,u)},kt=(t,e)=>Yh(`thread list ${t}`,e),N1=t=>{const e=R(27),{runtime:n,mainThreadIsRunning:r}=t,s=r===void 0?!1:r,i=wn(n);let o;e:{const b=i.isRunning||i.isMain&&s;if(b===i.isRunning){o=i;break e}let v;e[0]!==b||e[1]!==i?(v={...i,isRunning:b},e[0]=b,e[1]=i,e[2]=v):v=e[2],o=v}const a=o;$1(i.id,i.isMain);let l;e[3]!==a?(l=()=>a,e[3]=a,e[4]=l):l=e[4];let c,u,d,f,h,p,m;e[5]!==n?(u=b=>kt("switch",()=>n.switchTo(b)),d=b=>kt("rename",()=>n.rename(b)),f=b=>kt("update custom metadata",()=>n.updateCustom(b)),h=()=>kt("archive",()=>n.archive()),p=()=>kt("unarchive",()=>n.unarchive()),m=()=>kt("delete",()=>n.delete()),c=b=>kt("generate title",()=>n.generateTitle(b)),e[5]=n,e[6]=c,e[7]=u,e[8]=d,e[9]=f,e[10]=h,e[11]=p,e[12]=m):(c=e[6],u=e[7],d=e[8],f=e[9],h=e[10],p=e[11],m=e[12]);let y;e[13]!==n?(y=()=>n,e[13]=n,e[14]=y):y=e[14];let g;return e[15]!==n.detach||e[16]!==n.initialize||e[17]!==c||e[18]!==y||e[19]!==l||e[20]!==u||e[21]!==d||e[22]!==f||e[23]!==h||e[24]!==p||e[25]!==m?(g={getState:l,switchTo:u,rename:d,updateCustom:f,archive:h,unarchive:p,delete:m,generateTitle:c,initialize:n.initialize,detach:n.detach,__internal_getRuntime:y},e[15]=n.detach,e[16]=n.initialize,e[17]=c,e[18]=y,e[19]=l,e[20]=u,e[21]=d,e[22]=f,e[23]=h,e[24]=p,e[25]=m,e[26]=g):g=e[26],g},B1=ce(N1),j1=(t,e)=>{const[n]=ie(()=>({committed:void 0,unmounted:!1,waiters:new Set,delayed:new WeakMap}));return Q(()=>{if(n.committed={state:t},!Object.is(t,e()))return;const r=[...n.waiters];n.waiters.clear();for(const s of r)s()}),Q(()=>(n.unmounted=!1,()=>{n.unmounted=!0,n.committed=void 0;const r=[...n.waiters];n.waiters.clear();for(const s of r)s()}),[n]),mt(r=>{const s=n.delayed.get(r);if(s)return s;const i=r.then(o=>new Promise(a=>{const l=n.committed;if(n.unmounted||l!==void 0&&Object.is(l.state,e())){a(o);return}const c=()=>{clearTimeout(u),n.waiters.delete(c),a(o)},u=setTimeout(c,100);n.waiters.add(c)}));return n.delayed.set(r,i),i},[n,e])},z1=t=>{const e=R(6),{runtime:n,id:r,mainThreadIsRunning:s}=t;let i;e[0]!==r||e[1]!==n?(i=n.getItemById(r),e[0]=r,e[1]=n,e[2]=i):i=e[2];const o=i;let a;return e[3]!==s||e[4]!==o?(a=B1({runtime:o,mainThreadIsRunning:s}),e[3]=s,e[4]=o,e[5]=a):a=e[5],ze(a)},V1=ce(z1),U1=(t,e)=>{const n=R(23),r=Wn();let s,i;n[0]!==r||n[1]!==t?(s=()=>t.unstable_subscribeThreadEvents(h=>{const{threadId:p,type:m}=h;p!==t.getState().mainThreadId&&r(`thread.${m}`,{threadId:p})}),i=[t,r],n[0]=r,n[1]=t,n[2]=s,n[3]=i):(s=n[2],i=n[3]),Q(s,i);let o,a;n[4]!==t?(o=(h,p)=>kt("switch",()=>t.switchToThread(h,p)),a=()=>kt("create",()=>t.switchToNewThread()),n[4]=t,n[5]=o,n[6]=a):(o=n[5],a=n[6]);let l,c;n[7]!==e||n[8]!==t?(l=()=>e(t.getLoadThreadsPromise()),c=()=>e(t.reload()),n[7]=e,n[8]=t,n[9]=l,n[10]=c):(l=n[9],c=n[10]);let u;n[11]!==t?(u=()=>t.reloadMainThread(),n[11]=t,n[12]=u):u=n[12];let d;n[13]!==e||n[14]!==t?(d=()=>e(t.loadMore()),n[13]=e,n[14]=t,n[15]=d):d=n[15];let f;return n[16]!==o||n[17]!==a||n[18]!==l||n[19]!==c||n[20]!==u||n[21]!==d?(f={switchToThread:o,switchToNewThread:a,getLoadThreadsPromise:l,reload:c,reloadMainThread:u,loadMore:d},n[16]=o,n[17]=a,n[18]=l,n[19]=c,n[20]=u,n[21]=d,n[22]=f):f=n[22],f};function Dc(t){return()=>t}const q1=t=>{const e=R(39),{runtime:n,__internal_assistantRuntime:r}=t,s=wn(n),i=j1(s,n.getState);F1(s.mainThreadId);const o=U1(n,i);let a;e[0]!==n.main?(a=D1({runtime:n.main}),e[0]=n.main,e[1]=a):a=e[1];const l=Bn(a);let c;e[2]!==l.state||e[3]!==n||e[4]!==s.threadItems?(c=Object.keys(s.threadItems).map(D=>Re(D,V1({runtime:n,id:D,mainThreadIsRunning:l.state.isRunning}),[n,D,l.state.isRunning])),e[2]=l.state,e[3]=n,e[4]=s.threadItems,e[5]=c):c=e[5];const u=_t(c),d=s.newThreadId??null;let f;e[6]!==l.state||e[7]!==s.archivedThreadIds||e[8]!==s.canUnarchive||e[9]!==s.hasMore||e[10]!==s.isLoading||e[11]!==s.isLoadingMore||e[12]!==s.loadError||e[13]!==s.mainThreadId||e[14]!==s.switchError||e[15]!==s.threadIds||e[16]!==d||e[17]!==u.state?(f={canUnarchive:s.canUnarchive,mainThreadId:s.mainThreadId,newThreadId:d,isLoading:s.isLoading,loadError:s.loadError,switchError:s.switchError,isLoadingMore:s.isLoadingMore,hasMore:s.hasMore,threadIds:s.threadIds,archivedThreadIds:s.archivedThreadIds,threadItems:u.state,main:l.state},e[6]=l.state,e[7]=s.archivedThreadIds,e[8]=s.canUnarchive,e[9]=s.hasMore,e[10]=s.isLoading,e[11]=s.isLoadingMore,e[12]=s.loadError,e[13]=s.mainThreadId,e[14]=s.switchError,e[15]=s.threadIds,e[16]=d,e[17]=u.state,e[18]=f):f=e[18];const h=f;let p;e[19]!==h?(p=()=>h,e[19]=h,e[20]=p):p=e[20];let m;e[21]!==l.methods?(m=Dc(l.methods),e[21]=l.methods,e[22]=m):m=e[22];let y;e[23]!==h||e[24]!==u?(y=D=>{if(D==="main")return u.get({key:h.mainThreadId});if("id"in D)return u.get({key:D.id});const{index:x,archived:M}=D,P=M!==void 0&&M?h.archivedThreadIds[x]:h.threadIds[x];return u.get({key:P})},e[23]=h,e[24]=u,e[25]=y):y=e[25];const g=o.switchToThread,b=o.switchToNewThread,v=o.getLoadThreadsPromise,w=o.reload,k=o.reloadMainThread,_=o.loadMore;let A;e[26]!==r?(A=Dc(r),e[26]=r,e[27]=A):A=e[27];let E;return e[28]!==o.getLoadThreadsPromise||e[29]!==o.loadMore||e[30]!==o.reload||e[31]!==o.reloadMainThread||e[32]!==o.switchToNewThread||e[33]!==o.switchToThread||e[34]!==A||e[35]!==p||e[36]!==m||e[37]!==y?(E={getState:p,thread:m,item:y,switchToThread:g,switchToNewThread:b,getLoadThreadsPromise:v,reload:w,reloadMainThread:k,loadMore:_,__internal_getAssistantRuntime:A},e[28]=o.getLoadThreadsPromise,e[29]=o.loadMore,e[30]=o.reload,e[31]=o.reloadMainThread,e[32]=o.switchToNewThread,e[33]=o.switchToThread,e[34]=A,e[35]=p,e[36]=m,e[37]=y,e[38]=E):E=e[38],E},H1=ce(q1),W1=(t,e)=>{t.thread??=Ve({source:"threads",query:{type:"main"},get:n=>n.threads.thread("main")}),t.threadListItem??=Ve({source:"threads",query:{type:"main"},get:n=>n.threads.item("main")}),t.composer??=Ve({source:"thread",query:{},get:n=>n.threads.thread("main").composer()}),!t.modelContext&&e.modelContext.source===null&&(t.modelContext=Kh()),!t.suggestions&&e.suggestions.source===null&&(t.suggestions=Ve({source:"thread",query:{},get:n=>n.thread.suggestions()}))},sf=t=>{const e=R(7),n=Jd();let r;e[0]!==n||e[1]!==t?(r=()=>t.registerModelContextProvider(n.current.modelContext()),e[0]=n,e[1]=t,e[2]=r):r=e[2];let s;e[3]!==t?(s=[t],e[3]=t,e[4]=s):s=e[4],Xd("modelContext",r,s);let i;return e[5]!==t?(i=H1({runtime:t.threads,__internal_assistantRuntime:t}),e[5]=t,e[6]=i):i=e[6],ze(i)},G1=ce(sf),K1=(t,e)=>{W1(t,e),!t.tools&&e.tools.source===null&&(t.tools=cx({})),!t.dataRenderers&&e.dataRenderers.source===null&&(t.dataRenderers=Qw())};Qd(sf,K1);const Q1=at({}),Oc=({effects:t})=>{"use no memo";return Zw(t),null},vt=he(function(e,n){"use no memo";const{config:r,children:s}=e,i="extends"in e,o="value"in e,a=xa();if(ih){if(i&&o)throw new Error("AuiProvider: pass either `extends` or `value`, not both.");if(i&&e.extends===void 0)throw new Error("AuiProvider: `extends` must be a client or null, not undefined.");if(i&&!r)throw new Error("AuiProvider: `extends` requires a `config`.");if(o&&r)throw new Error("AuiProvider: pass either `value` or `config`, not both.");if(!o&&!r)throw new Error("AuiProvider: a `config` is required.");if(!i&&!o&&a!==Pn)throw new Error("A parent AuiProvider exists — pass extends={aui} to inherit it or extends={null} to isolate.")}const l=i?e.extends??Pn:o?e.value??Pn:a,c=Xb(),{client:u,effects:d}=h_(l,r??Q1,c);return Vy(n,()=>u,[u]),C.jsx(uo.Provider,{value:c,children:C.jsxs(wa.Provider,{value:u,children:[C.jsx(Oc,{effects:Ib(l)}),d&&C.jsx(Oc,{effects:d}),s]})})}),Y1=t=>{const e=Z(),n=X(!1),r=n.current?null:t(e);return N(()=>n.current?t(e):r),()=>(n.current=!0,t(e))},J1=Object.freeze({});function qt(t){const e=R(3),{getItemState:n,children:r}=t,s=Y1(n);let i;return e[0]!==r||e[1]!==s?(i=r(s),e[0]=r,e[1]=s,e[2]=i):i=e[2],X1(i)}const X1=t=>{const e=typeof t=="object"&&t!=null&&"type"in t?t:null,n=e?.type,r=e?.key,s=typeof e?.props=="object"&&e.props!=null&&Object.entries(e.props).length===0?J1:e?.props;return ye(()=>e,[n,r,s])??t},Z1=(t,e)=>{const n=R(11),r=Z(),s=nt(e);let i;n[0]!==t?(i=Sa(t),n[0]=t,n[1]=i):i=n[1];const{scope:o,event:a}=i;let l;n[2]!==r||n[3]!==s||n[4]!==a||n[5]!==o?(l=()=>r.on({scope:o,event:a},s),n[2]=r,n[3]=s,n[4]=a,n[5]=o,n[6]=l):l=n[6];let c;n[7]!==r||n[8]!==a||n[9]!==o?(c=[r,o,a],n[7]=r,n[8]=a,n[9]=o,n[10]=c):c=n[10],Q(l,c)},eS=t=>t._core?.RenderComponent,tS=({runtime:t,aui:e,config:n,children:r})=>{"use no memo";const s=eS(t),i=at({...n,threads:G1(t)});return C.jsxs(vt,{extends:e,config:i,children:[s&&C.jsx(s,{}),r]})},nS=Te(t=>{const e=R(5),{runtime:n,aui:r,config:s,children:i}=t,o=r===void 0?null:r;let a;return e[0]!==o||e[1]!==i||e[2]!==s||e[3]!==n?(a=C.jsx(tS,{runtime:n,aui:o,config:s,children:i}),e[0]=o,e[1]=i,e[2]=s,e[3]=n,e[4]=a):a=e[4],a}),rS=ke(null),sS=()=>Fe(rS),of=t=>{const e=R(6),{index:n,children:r}=t,s=Z();let i;e[0]!==n?(i=at({attachment:Ve({source:"message",query:{type:"index",index:n},get:l=>l.message.attachment({index:n})})}),e[0]=n,e[1]=i):i=e[1];const o=i;let a;return e[2]!==s||e[3]!==r||e[4]!==o?(a=C.jsx(vt,{extends:s,config:o,children:r}),e[2]=s,e[3]=r,e[4]=o,e[5]=a):a=e[5],a},af=t=>{const e=R(6),{index:n,children:r}=t,s=Z();let i;e[0]!==n?(i=at({attachment:Ve({source:"composer",query:{type:"index",index:n},get:l=>l.composer.attachment({index:n})})}),e[0]=n,e[1]=i):i=e[1];const o=i;let a;return e[2]!==s||e[3]!==r||e[4]!==o?(a=C.jsx(vt,{extends:s,config:o,children:r}),e[2]=s,e[3]=r,e[4]=o,e[5]=a):a=e[5],a},lf=t=>{const e=R(6),{index:n,children:r}=t,s=Z();let i;e[0]!==n?(i=at({message:Ve({source:"thread",query:{type:"index",index:n},get:l=>l.thread.message({index:n})}),composer:Ve({source:"message",query:{},get:l=>l.thread.message({index:n}).composer()})}),e[0]=n,e[1]=i):i=e[1];const o=i;let a;return e[2]!==s||e[3]!==r||e[4]!==o?(a=C.jsx(vt,{extends:s,config:o,children:r}),e[2]=s,e[3]=r,e[4]=o,e[5]=a):a=e[5],a},$a=t=>{const e=R(6),{index:n,children:r}=t,s=Z();let i;e[0]!==n?(i=at({part:Ve({source:"message",query:{type:"index",index:n},get:l=>l.message.part({index:n})})}),e[0]=n,e[1]=i):i=e[1];const o=i;let a;return e[2]!==s||e[3]!==r||e[4]!==o?(a=C.jsx(vt,{extends:s,config:o,children:r}),e[2]=s,e[3]=r,e[4]=o,e[5]=a):a=e[5],a},iS=t=>{const e=R(7),{text:n,isRunning:r}=t;let s;e[0]!==r?(s=r?{type:"running"}:{type:"complete"},e[0]=r,e[1]=s):s=e[1];let i;e[2]!==s||e[3]!==n?(i={type:"text",text:n,status:s},e[2]=s,e[3]=n,e[4]=i):i=e[4];const o=i;let a;return e[5]!==o?(a={getState:()=>o,addToolResult:aS,resumeToolCall:lS,respondToToolApproval:cS,unstable_recordInteraction:uS},e[5]=o,e[6]=a):a=e[6],a},oS=ce(iS),Na=t=>{const e=R(7),{text:n,isRunning:r,children:s}=t,i=r===void 0?!1:r,o=Z();let a;e[0]!==i||e[1]!==n?(a=at({part:oS({text:n,isRunning:i})}),e[0]=i,e[1]=n,e[2]=a):a=e[2];const l=a;let c;return e[3]!==o||e[4]!==s||e[5]!==l?(c=C.jsx(vt,{extends:o,config:l,children:s}),e[3]=o,e[4]=s,e[5]=l,e[6]=c):c=e[6],c};function aS(){throw new Error("Not supported")}function lS(){throw new Error("Not supported")}function cS(){throw new Error("Not supported")}async function uS(){throw new Error("Not supported")}const dS=t=>{for(const e of t)if(e?.status.type==="running")return Ra;return t.at(-1)?.status??Ze},hS=(t,e)=>{const n={running:0,complete:0,incomplete:0,requiresAction:0};let r=Ze,s=!1,i,o,a=!0;for(const c of e){const u=t[c]?.timing;switch(u&&(i=Math.min(i??u.startedAt,u.startedAt),u.completedAt===void 0?a=!1:o=Math.max(o??u.completedAt,u.completedAt)),r=t[c]?.status??Ze,r.type){case"running":n.running++,s=!0;break;case"complete":n.complete++;break;case"incomplete":n.incomplete++;break;case"requires-action":n.requiresAction++}}const l=i===void 0?void 0:!s&&a&&o!==void 0?{startedAt:i,completedAt:o}:{startedAt:i};return{status:s?Ra:r,counts:n,...l&&{timing:l}}},fS=t=>{const e=R(11),{parts:n,getMessagePart:r}=t,[s,i]=ie(!0);let o;e[0]!==n?(o=dS(n),e[0]=n,e[1]=o):o=e[1];const a=o;let l;e[2]!==s||e[3]!==n||e[4]!==a?(l={parts:n,collapsed:s,status:a},e[2]=s,e[3]=n,e[4]=a,e[5]=l):l=e[5];const c=l;let u;e[6]!==c?(u=()=>c,e[6]=c,e[7]=u):u=e[7];let d;return e[8]!==r||e[9]!==u?(d={getState:u,setCollapsed:i,part:r},e[8]=r,e[9]=u,e[10]=d):d=e[10],d},pS=ce(fS),mS=ke(null),gS=t=>{const e=R(13),{startIndex:n,endIndex:r,children:s}=t,i=N(yS).slice(n,r+1);let o;e[0]!==r||e[1]!==n?(o=p=>vn(p.message.parts).slice(n,r+1),e[0]=r,e[1]=n,e[2]=o):o=e[2];const a=N(it(o));let l;e[3]!==a||e[4]!==n?(l={partKeys:a,startIndex:n},e[3]=a,e[4]=n,e[5]=l):l=e[5];const c=l,u=Z(),d=at({chainOfThought:pS({parts:i,getMessagePart:p=>{const{index:m}=p;if(m<0||m>=i.length)throw new Error(`ChainOfThought part index ${m} is out of bounds (0..${i.length-1})`);return u.message.part({index:n+m})}})});let f;e[6]!==s||e[7]!==d||e[8]!==u?(f=C.jsx(vt,{extends:u,config:d,children:s}),e[6]=s,e[7]=d,e[8]=u,e[9]=f):f=e[9];let h;return e[10]!==c||e[11]!==f?(h=C.jsx(mS.Provider,{value:c,children:f}),e[10]=c,e[11]=f,e[12]=h):h=e[12],h};function yS(t){return t.message.parts}const cf=t=>{const e=R(6),{index:n,children:r}=t,s=Z();let i;e[0]!==n?(i=at({suggestion:Ve({source:"suggestions",query:{index:n},get:l=>l.suggestions.suggestion({index:n})})}),e[0]=n,e[1]=i):i=e[1];const o=i;let a;return e[2]!==s||e[3]!==r||e[4]!==o?(a=C.jsx(vt,{extends:s,config:o,children:r}),e[2]=s,e[3]=r,e[4]=o,e[5]=a):a=e[5],a},bS=t=>{const e=R(6),{index:n,children:r}=t,s=Z();let i;e[0]!==n?(i=at({queueItem:Ve({source:"composer",query:{type:"index",index:n},get:l=>l.composer.queueItem({index:n})})}),e[0]=n,e[1]=i):i=e[1];const o=i;let a;return e[2]!==s||e[3]!==r||e[4]!==o?(a=C.jsx(vt,{extends:s,config:o,children:r}),e[2]=s,e[3]=r,e[4]=o,e[5]=a):a=e[5],a};var _S=class{thread;history;lastHistory;session=0;copied=new Map;failedIds=new Set;interactions=new Map;overlaid=new WeakMap;pending=!1;inFlight=new WeakSet;timer;waiters=[];warned=!1;signature(t){try{return JSON.stringify({role:t.role,content:t.content,attachments:t.role==="user"?t.attachments:void 0,status:t.role==="assistant"?t.status:void 0,metadata:t.metadata})??t}catch{return t}}branch(){return(this.thread?.messages??[]).filter(t=>!t.metadata.isOptimistic&&!t.id.startsWith("__external_store_fallback_")&&!Zi(t.id)&&!(t.role==="assistant"&&t.status.type==="running")).map(t=>{const e=this.interactions.get(t.id);if(!e)return t;const n=this.overlaid.get(t);if(n&&n.logs.size===e.size&&[...e].every(([s,i])=>n.logs.get(s)===i))return n.message;const r={...t,content:t.content.map(s=>{if(s.type!=="tool-call")return s;const i=e.get(s.toolCallId);return i?{...s,unstable_interactions:i}:s})};return this.overlaid.set(t,{logs:new Map(e),message:r}),r})}seed(){for(const t of this.branch())!this.copied.has(t.id)&&!this.failedIds.has(t.id)&&this.copied.set(t.id,this.signature(t))}attach(t,e){e!==this.lastHistory&&(this.copied.clear(),this.failedIds.clear(),this.interactions.clear(),this.overlaid=new WeakMap,this.lastHistory=e,this.session+=1),this.thread=t,this.history=e,this.seed();const n=t.unstable_on("runStart",()=>this.seed()),r=t.unstable_on("runEnd",()=>this.schedule());return()=>{n(),r(),this.timer!==void 0&&clearTimeout(this.timer),this.timer=void 0,this.pending=!1;const s=new Error("History copy was detached.");for(const i of this.waiters.splice(0))i.reject(s);this.thread=void 0,this.history=void 0}}recordInteraction=async t=>{const e=this.thread,n=e?.messages.find(o=>o.id===t.messageId),r=n?.content.find(o=>o.type==="tool-call"&&o.toolCallId===t.toolCallId);if(!e||!n||r?.type!=="tool-call")throw new Error("Tool call is not available.");const s=Qs(e);s||this.seed();let i=this.interactions.get(n.id);i||(i=new Map,this.interactions.set(n.id,i)),i.set(t.toolCallId,N_(i.get(t.toolCallId)??yh(r.unstable_interactions),t.interaction)),s||await this.schedule(!0)};schedule(t=!1){this.pending=!0;const e=t?new Promise((n,r)=>{this.waiters.push({resolve:n,reject:r})}):Promise.resolve();return this.history&&!this.inFlight.has(this.history)&&this.timer===void 0&&(this.timer=setTimeout(()=>{this.timer=void 0,this.flush()},0)),e}async flush(){if(!this.pending||!this.history)return;const t=this.history,e=this.session;this.pending=!1,this.inFlight.add(t);const n=this.waiters.splice(0),r=this.branch(),s=r.map(i=>[i.id,this.signature(i)]).filter(([i,o])=>this.copied.get(i)!==o);try{if(s.length>0&&(await t.unstable_copy?.(r,s.map(([i])=>i)),e===this.session))for(const[i,o]of s)this.copied.set(i,o),this.failedIds.delete(i);for(const i of n)i.resolve()}catch(i){if(e===this.session)for(const[o]of s)this.failedIds.add(o);this.warned||(this.warned=!0,console.warn("[useExternalStoreRuntime] Failed to copy history.",i));for(const o of n)o.reject(i)}finally{this.inFlight.delete(t),this.pending&&this.schedule()}}};const vS=ke(!1),wS=()=>Fe(vS),xS=(t,e,n)=>{ct(()=>{if(t)return;const r=++e.generation;return()=>queueMicrotask(()=>{e.generation===r&&qh(n.threads.getMainThreadRuntimeCore())})},[t,e,n]),Gh(()=>()=>{kw(n.threads.getMainThreadRuntimeCore())},[n])},SS=(t,e,n,r)=>{const s=R(6);let i,o;s[0]!==t||s[1]!==e||s[2]!==n||s[3]!==r?(i=()=>{if(!(!t||!e))return n.attach(r.threads.getMainThreadRuntimeCore(),e)},o=[t,e,n,r],s[0]=t,s[1]=e,s[2]=n,s[3]=r,s[4]=i,s[5]=o):(i=s[4],o=s[5]),Gh(i,o)},TS=(t,e)=>{const n=R(4);let r,s;n[0]!==t||n[1]!==e?(r=()=>{if(t)return e.registerModelContextProvider(t)},s=[t,e],n[0]=t,n[1]=e,n[2]=r,n[3]=s):(r=n[2],s=n[3]),Q(r,s)},CS=t=>()=>new Hh(t),HO=t=>{const e=R(13),{modelContext:n,feedback:r,history:s}=sS()??{},[i]=ie(IS),o=!!s?.unstable_copy&&!t.unstable_persistsHistory&&!t.adapters?.threadList;let a;e:{let y;e[0]!==r||e[1]!==t?(y=r&&!t.adapters?.feedback?{...t,adapters:{...t.adapters,feedback:r}}:t,e[0]=r,e[1]=t,e[2]=y):y=e[2];const g=y;if(!o||t.unstable_onRecordToolInteraction){a=g;break e}let b;e[3]!==i.recordInteraction||e[4]!==g?(b={...g,unstable_onRecordToolInteraction:i.recordInteraction},e[3]=i.recordInteraction,e[4]=g,e[5]=b):b=e[5],a=b}const l=a;let c;e[6]!==l?(c=()=>new Hw(l),e[6]=l,e[7]=c):c=e[7];const[u]=ie(c),d=wS(),[f]=ie(kS);xS(d,f,u);let h;e[8]!==l||e[9]!==u?(h=()=>{u.setAdapter(l)},e[8]=l,e[9]=u,e[10]=h):h=e[10],Q(h),SS(o,s,i,u),TS(n,u);let p;e[11]!==u?(p=CS(u),e[11]=u,e[12]=p):p=e[12];const[m]=ie(p);return m};function IS(){return new _S}function kS(){return{generation:0}}const ES=new Map,AS=t=>ES.get(t)?.()??Promise.resolve(),uf=t=>{const e=R(6),{id:n,children:r}=t,s=Z();let i;e[0]!==n?(i=at({message:Ve({source:"thread",query:{type:"id",id:n},get:l=>l.thread.message({id:n})}),composer:Ve({source:"message",query:{},get:l=>l.thread.message({id:n}).composer()})}),e[0]=n,e[1]=i):i=e[1];const o=i;let a;return e[2]!==s||e[3]!==r||e[4]!==o?(a=C.jsx(vt,{extends:s,config:o,children:r}),e[2]=s,e[3]=r,e[4]=o,e[5]=a):a=e[5],a},Ba=(t,e)=>t.Message===e.Message&&t.EditComposer===e.EditComposer&&t.UserEditComposer===e.UserEditComposer&&t.AssistantEditComposer===e.AssistantEditComposer&&t.SystemEditComposer===e.SystemEditComposer&&t.UserMessage===e.UserMessage&&t.AssistantMessage===e.AssistantMessage&&t.SystemMessage===e.SystemMessage,Lc=()=>null,RS=(t,e,n)=>{switch(e){case"user":return n?t.UserEditComposer??t.EditComposer??t.UserMessage??t.Message:t.UserMessage??t.Message;case"assistant":return n?t.AssistantEditComposer??t.EditComposer??t.AssistantMessage??t.Message:t.AssistantMessage??t.Message;case"system":return n?t.SystemEditComposer??t.EditComposer??t.SystemMessage??t.Message??Lc:t.SystemMessage??t.Message??Lc;default:throw new Error(`Unknown message role: ${e}`)}},ja=t=>{const e=R(6),{components:n}=t,r=N(PS),s=N(DS);let i;e[0]!==n||e[1]!==s||e[2]!==r?(i=RS(n,r,s),e[0]=n,e[1]=s,e[2]=r,e[3]=i):i=e[3];const o=i;let a;return e[4]!==o?(a=C.jsx(o,{}),e[4]=o,e[5]=a):a=e[5],a},df=Te(t=>{const e=R(5),{index:n,components:r}=t;let s;e[0]!==r?(s=C.jsx(ja,{components:r}),e[0]=r,e[1]=s):s=e[1];let i;return e[2]!==n||e[3]!==s?(i=C.jsx(lf,{index:n,children:s}),e[2]=n,e[3]=s,e[4]=i):i=e[4],i},(t,e)=>t.index===e.index&&Ba(t.components,e.components));df.displayName="ThreadPrimitive.MessageByIndex";const hf=Te(t=>{const e=R(7),{messageId:n,components:r}=t;let s;if(e[0]!==n?(s=a=>Dh(a.thread.messages,n),e[0]=n,e[1]=s):s=e[1],!N(s))return null;let i;e[2]!==r?(i=C.jsx(ja,{components:r}),e[2]=r,e[3]=i):i=e[3];let o;return e[4]!==n||e[5]!==i?(o=C.jsx(uf,{id:n,children:i}),e[4]=n,e[5]=i,e[6]=o):o=e[6],o},(t,e)=>t.messageId===e.messageId&&Ba(t.components,e.components));hf.displayName="ThreadPrimitive.Unstable_MessageById";const Fc=({children:t})=>{const e=N(it(n=>n.thread.messages.map(r=>r.id)));return ye(()=>e.length===0?null:e.map((n,r)=>C.jsx(lf,{index:r,children:C.jsx(qt,{getItemState:s=>s.thread.message({index:r}).getState(),children:s=>t({get message(){return s()}})})},n)),[e,t])},ff=t=>{const e=R(4),{components:n,children:r}=t;if(n){let i;return e[0]!==n?(i=C.jsx(Fc,{children:()=>C.jsx(ja,{components:n})}),e[0]=n,e[1]=i):i=e[1],i}let s;return e[2]!==r?(s=C.jsx(Fc,{children:r}),e[2]=r,e[3]=s):s=e[3],s};ff.displayName="ThreadPrimitive.Messages";const MS=Te(ff,(t,e)=>t.children||e.children?t.children===e.children:Ba(t.components,e.components));function PS(t){return t.message.role}function DS(t){return t.message.composer.isEditing}const pf=t=>{const e=t.message.metadata;if(!(!e||typeof e!="object"))return e.custom?.quote};var OS=class extends Error{componentName;constructor(t,e=`Component "${t}" is not in the generative-ui allowlist.`){super(e),this.name="GenerativeUIRenderError",this.componentName=t}};const LS=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),mf=t=>t==null?[]:Array.isArray(t)?t:[t],$c=(t,...e)=>{},FS=64,To=(t,e,n,r,s=0)=>{if(s>FS)return $c(),null;if(t==null)return null;if(typeof t=="string"||typeof t=="number")return t;if(Array.isArray(t))return t.map((u,d)=>To(u,e,n,`${r}/${d}`,s+1));if(!LS(t)||!("component"in t)||typeof t.component!="string")return $c(`[generative-ui] Skipping malformed node at ${r}:`,t),null;const{component:i,props:o,children:a,key:l}=t,c=Object.hasOwn(e,i)?e[i]:void 0;if(!c){if(n)return C.jsx(n,{component:i,props:o},l??r);throw new OS(i)}return Hy(c,{...o??{},key:l??r},...mf(a).map((u,d)=>To(u,e,n,`${r}/${d}`,s+1)))},za=t=>{const e=R(11),{spec:n,components:r,Fallback:s}=t,i=n?.root;let o;e[0]!==i?(o=mf(i),e[0]=i,e[1]=o):o=e[1];const a=o;let l;if(e[2]!==s||e[3]!==r||e[4]!==a){let u;e[6]!==s||e[7]!==r?(u=(d,f)=>To(d,r,s,`${f}`),e[6]=s,e[7]=r,e[8]=u):u=e[8],l=a.map(u),e[2]=s,e[3]=r,e[4]=a,e[5]=l}else l=e[5];let c;return e[9]!==l?(c=C.jsx(C.Fragment,{children:l}),e[9]=l,e[10]=c):c=e[10],c};za.displayName="GenerativeUIRender";const gf=t=>{const e=R(4),{components:n,spec:r,Fallback:s}=t,i=N($S),o=r??i;if(!o)return null;let a;return e[0]!==s||e[1]!==n||e[2]!==o?(a=C.jsx(za,{spec:o,components:n,Fallback:s}),e[0]=s,e[1]=n,e[2]=o,e[3]=a):a=e[3],a};gf.displayName="MessagePrimitive.GenerativeUI";function $S(t){const e=t.part;return e?.type==="generative-ui"?e.spec:void 0}const Ri=t=>{let e=-1;return{startGroup:n=>{e===-1&&(e=n)},endGroup:(n,r)=>{e!==-1&&(r.push({type:t,startIndex:e,endIndex:n}),e=-1)},finalize:(n,r)=>{e!==-1&&r.push({type:t,startIndex:e,endIndex:n})}}},NS=(t,e,n)=>{const r=[];if(e){const s=Ri("chainOfThoughtGroup");for(let i=0;i<t.length;i++){const o=t[i];o==="tool-call"||o==="reasoning"?s.startGroup(i):(s.endGroup(i-1,r),r.push({type:"single",index:i}))}s.finalize(t.length-1,r)}else{const s=Ri("toolGroup"),i=Ri("reasoningGroup");for(let o=0;o<t.length;o++){const a=t[o];a==="tool-call"?(i.endGroup(o-1,r),s.startGroup(o)):a==="reasoning"?(s.endGroup(o-1,r),i.startGroup(o)):(s.endGroup(o-1,r),i.endGroup(o-1,r),r.push({type:"single",index:o}))}s.finalize(t.length-1,r),i.finalize(t.length-1,r)}if(n){const s=new Set;for(const i of r){if(i.type==="single")continue;const o=n[i.startIndex];o?.includes(":")&&!s.has(o)&&(s.add(o),i.idKey=`id:${o}`)}}return r},BS=t=>{const e=R(10),n=N(it(t0)),r=N(it(n0));let s;e:{if(n.length===0){let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=[],e[0]=a):a=e[0];let l;e[1]!==r?(l={ranges:a,partIds:r},e[1]=r,e[2]=l):l=e[2],s=l;break e}let i;e[3]!==n||e[4]!==r||e[5]!==t?(i=NS(n,t,r),e[3]=n,e[4]=r,e[5]=t,e[6]=i):i=e[6];let o;e[7]!==r||e[8]!==i?(o={ranges:i,partIds:r},e[7]=r,e[8]=i,e[9]=o):o=e[9],s=o}return s},jS=t=>{const e=R(11);let n,r,s;e[0]!==t?({ByName:n,Fallback:r,...s}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=s):(n=e[1],r=e[2],s=e[3]);let i;e[4]!==n||e[5]!==r||e[6]!==s?(i=l=>La(l.tools,s,n)??r,e[4]=n,e[5]=r,e[6]=s,e[7]=i):i=e[7];const o=N(i);if(!o)return null;let a;return e[8]!==o||e[9]!==s?(a=C.jsx(o,{...s}),e[8]=o,e[9]=s,e[10]=a):a=e[10],a},Va=(t,e,n)=>{const r=t.renderers[e]?.[0];return r||(t.fallbacks[0]??n)},zS=t=>{const e=R(9);let n,r;e[0]!==t?({Fallback:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let s;e[3]!==n||e[4]!==r.name?(s=a=>Va(a.dataRenderers,r.name,n),e[3]=n,e[4]=r.name,e[5]=s):s=e[5];const i=N(s);if(!i)return null;let o;return e[6]!==i||e[7]!==r?(o=C.jsx(i,{...r}),e[6]=i,e[7]=r,e[8]=o):o=e[8],o},ft={Text:()=>null,Reasoning:()=>null,Source:()=>null,Image:()=>null,File:()=>null,Unstable_Audio:()=>null,ToolGroup:({children:t})=>t,ReasoningGroup:({children:t})=>t},yf=t=>{const e=R(54),{components:n}=t;let r;e[0]!==n?(r=n===void 0?{}:n,e[0]=n,e[1]=r):r=e[1];const{Text:s,Reasoning:i,Image:o,Source:a,File:l,Unstable_Audio:c,tools:u,data:d,generativeUI:f}=r,h=s===void 0?ft.Text:s,p=i===void 0?ft.Reasoning:i,m=o===void 0?ft.Image:o,y=a===void 0?ft.Source:a,g=l===void 0?ft.File:l,b=c===void 0?ft.Unstable_Audio:c;let v;e[2]!==u?(v=u===void 0?{}:u,e[2]=u,e[3]=v):v=e[3];const w=v,k=Z(),_=N(r0),A=_.type;if(A==="tool-call"){const E=k.part.addToolResult,D=k.part.resumeToolCall,x=k.part.respondToToolApproval,M=k.part.unstable_recordInteraction;if("Override"in w){let j;e[4]!==M?(j=M&&{unstable_recordInteraction:M},e[4]=M,e[5]=j):j=e[5];let V;return e[6]!==E||e[7]!==_||e[8]!==x||e[9]!==D||e[10]!==j||e[11]!==w.Override?(V=C.jsx(w.Override,{..._,addResult:E,resume:D,respondToApproval:x,...j}),e[6]=E,e[7]=_,e[8]=x,e[9]=D,e[10]=j,e[11]=w.Override,e[12]=V):V=e[12],V}let P;e[13]!==_.toolName||e[14]!==w.by_name?(P=w.by_name&&Object.hasOwn(w.by_name,_.toolName)?w.by_name[_.toolName]:void 0,e[13]=_.toolName,e[14]=w.by_name,e[15]=P):P=e[15];const T=P;let $;e[16]!==M?($=M&&{unstable_recordInteraction:M},e[16]=M,e[17]=$):$=e[17];let L;return e[18]!==T||e[19]!==E||e[20]!==_||e[21]!==x||e[22]!==D||e[23]!==$||e[24]!==w.Fallback?(L=C.jsx(jS,{..._,ByName:T,Fallback:w.Fallback,addResult:E,resume:D,respondToApproval:x,...$}),e[18]=T,e[19]=E,e[20]=_,e[21]=x,e[22]=D,e[23]=$,e[24]=w.Fallback,e[25]=L):L=e[25],L}if(_.status?.type==="requires-action")throw new Error("Encountered unexpected requires-action status");switch(A){case"text":{let E;return e[26]!==h||e[27]!==_?(E=C.jsx(h,{..._}),e[26]=h,e[27]=_,e[28]=E):E=e[28],E}case"reasoning":{let E;return e[29]!==p||e[30]!==_?(E=C.jsx(p,{..._}),e[29]=p,e[30]=_,e[31]=E):E=e[31],E}case"source":{let E;return e[32]!==y||e[33]!==_?(E=C.jsx(y,{..._}),e[32]=y,e[33]=_,e[34]=E):E=e[34],E}case"image":{let E;return e[35]!==m||e[36]!==_?(E=C.jsx(m,{..._}),e[35]=m,e[36]=_,e[37]=E):E=e[37],E}case"file":{let E;return e[38]!==g||e[39]!==_?(E=C.jsx(g,{..._}),e[38]=g,e[39]=_,e[40]=E):E=e[40],E}case"audio":{let E;return e[41]!==b||e[42]!==_?(E=C.jsx(b,{..._}),e[41]=b,e[42]=_,e[43]=E):E=e[43],E}case"data":{let E;e[44]!==d||e[45]!==_.name?(E=(d?.by_name&&Object.hasOwn(d.by_name,_.name)?d.by_name[_.name]:void 0)??d?.Fallback,e[44]=d,e[45]=_.name,e[46]=E):E=e[46];const D=E;let x;return e[47]!==D||e[48]!==_?(x=C.jsx(zS,{..._,Fallback:D}),e[47]=D,e[48]=_,e[49]=x):x=e[49],x}case"generative-ui":{if(!f?.components)return null;const E=_;let D;return e[50]!==f.Fallback||e[51]!==f.components||e[52]!==E.spec?(D=C.jsx(za,{spec:E.spec,components:f.components,Fallback:f.Fallback}),e[50]=f.Fallback,e[51]=f.components,e[52]=E.spec,e[53]=D):D=e[53],D}default:return console.warn(`Unknown message part type: ${A}`),null}},pr=Te(t=>{const e=R(5),{index:n,components:r}=t;let s;e[0]!==r?(s=C.jsx(yf,{components:r}),e[0]=r,e[1]=s):s=e[1];let i;return e[2]!==n||e[3]!==s?(i=C.jsx($a,{index:n,children:s}),e[2]=n,e[3]=s,e[4]=i):i=e[4],i},(t,e)=>t.index===e.index&&t.components?.Text===e.components?.Text&&t.components?.Reasoning===e.components?.Reasoning&&t.components?.Source===e.components?.Source&&t.components?.Image===e.components?.Image&&t.components?.File===e.components?.File&&t.components?.Unstable_Audio===e.components?.Unstable_Audio&&t.components?.tools===e.components?.tools&&t.components?.data===e.components?.data&&t.components?.generativeUI===e.components?.generativeUI&&t.components?.ToolGroup===e.components?.ToolGroup&&t.components?.ReasoningGroup===e.components?.ReasoningGroup);pr.displayName="MessagePrimitive.PartByIndex";const VS=t=>{const e=R(6),{status:n,component:r}=t,s=n.type==="running";let i;e[0]!==r||e[1]!==n?(i=C.jsx(r,{type:"text",text:"",status:n}),e[0]=r,e[1]=n,e[2]=i):i=e[2];let o;return e[3]!==s||e[4]!==i?(o=C.jsx(Na,{text:"",isRunning:s,children:i}),e[3]=s,e[4]=i,e[5]=o):o=e[5],o},US=Object.freeze({type:"complete"}),qS=Object.freeze({type:"running"}),HS=t=>{const e=R(6),{components:n}=t,r=N(s0);if(n?.Empty){let o;return e[0]!==n.Empty||e[1]!==r?(o=C.jsx(n.Empty,{status:r}),e[0]=n.Empty,e[1]=r,e[2]=o):o=e[2],o}if(r.type!=="running")return null;const s=n?.Text??ft.Text;let i;return e[3]!==r||e[4]!==s?(i=C.jsx(VS,{status:r,component:s}),e[3]=r,e[4]=s,e[5]=i):i=e[5],i},bf=Te(HS,(t,e)=>t.components?.Empty===e.components?.Empty&&t.components?.Text===e.components?.Text),WS=t=>{const e=R(4),{components:n,enabled:r}=t;let s;if(e[0]!==r?(s=o=>{if(!r||o.message.parts.length===0)return!1;const a=o.message.parts[o.message.parts.length-1];return a?.type!=="text"&&a?.type!=="reasoning"},e[0]=r,e[1]=s):s=e[1],!N(s))return null;let i;return e[2]!==n?(i=C.jsx(bf,{components:n}),e[2]=n,e[3]=i):i=e[3],i},GS=Te(WS,(t,e)=>t.enabled===e.enabled&&t.components?.Empty===e.components?.Empty&&t.components?.Text===e.components?.Text),KS=t=>{const e=R(4),{Quote:n}=t,r=N(pf);if(!r)return null;let s;return e[0]!==n||e[1]!==r.messageId||e[2]!==r.text?(s=C.jsx(n,{text:r.text,messageId:r.messageId}),e[0]=n,e[1]=r.messageId,e[2]=r.text,e[3]=s):s=e[3],s},QS=Te(KS),_f=()=>{const t=R(9),e=Z(),n=N(i0),r=N(o0),s=e.part.unstable_recordInteraction;if(!r||n.type!=="tool-call")return null;let i;t[0]!==s?(i=s&&{unstable_recordInteraction:s},t[0]=s,t[1]=i):i=t[1];let o;return t[2]!==r||t[3]!==e.part.addToolResult||t[4]!==e.part.respondToToolApproval||t[5]!==e.part.resumeToolCall||t[6]!==n||t[7]!==i?(o=C.jsx(r,{...n,addResult:e.part.addToolResult,resume:e.part.resumeToolCall,respondToApproval:e.part.respondToToolApproval,...i}),t[2]=r,t[3]=e.part.addToolResult,t[4]=e.part.respondToToolApproval,t[5]=e.part.resumeToolCall,t[6]=n,t[7]=i,t[8]=o):o=t[8],o},vf=()=>{const t=R(3),e=N(a0),n=N(l0);if(!n||e.type!=="data")return null;const r=e;let s;return t[0]!==n||t[1]!==r?(s=C.jsx(n,{...r}),t[0]=n,t[1]=r,t[2]=s):s=t[2],s},wf=()=>{const t=R(2),e=N(c0);if(e==="tool-call"){let n;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=C.jsx(_f,{}),t[0]=n):n=t[0],n}if(e==="data"){let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=C.jsx(vf,{}),t[1]=n):n=t[1],n}return null},YS=Object.freeze({type:"text",text:"",status:qS}),JS=({children:t})=>{const e=Z(),n=N(r=>r.dataRenderers);return C.jsx(qt,{getItemState:r=>r.part.getState(),children:r=>t({get part(){const s=r();if(s.type==="tool-call"){const i=e.tools.getState(),o=La(i,s)!==null,a=e.part;return{...s,toolUI:o?C.jsx(_f,{}):null,addResult:a.addToolResult,resume:a.resumeToolCall,respondToApproval:a.respondToToolApproval,...a.unstable_recordInteraction&&{unstable_recordInteraction:a.unstable_recordInteraction}}}if(s.type==="data"){const i=Va(n,s.name,void 0)!==void 0;return{...s,dataRendererUI:i?C.jsx(vf,{}):null}}return s}})})},xf=t=>{const e=R(5),{index:n,children:r}=t;let s;e[0]!==r?(s=C.jsx(JS,{children:r}),e[0]=r,e[1]=s):s=e[1];let i;return e[2]!==n||e[3]!==s?(i=C.jsx($a,{index:n,children:s}),e[2]=n,e[3]=s,e[4]=i):i=e[4],i},XS=t=>{const e=R(11),{children:n}=t,r=N(it(u0)),s=r.length,i=N(d0),o=s===0&&i;if(s===0){if(!o)return null;let c;e[0]!==n?(c=n({part:YS}),e[0]=n,e[1]=c):c=e[1];let u;return e[2]!==c?(u=C.jsx(Na,{text:"",isRunning:!0,children:c}),e[2]=c,e[3]=u):u=e[3],u}let a;if(e[4]!==n||e[5]!==r){let c;e[7]!==n?(c=(u,d)=>C.jsx(xf,{index:d,children:f=>n(f)??C.jsx(wf,{})},u),e[7]=n,e[8]=c):c=e[8],a=r.map(c),e[4]=n,e[5]=r,e[6]=a}else a=e[6];let l;return e[9]!==a?(l=C.jsx(C.Fragment,{children:a}),e[9]=a,e[10]=l):l=e[10],l},Co=t=>{const e=R(5),{components:n,unstable_showEmptyOnNonTextEnd:r,children:s}=t,i=r===void 0?!0:r;if(s){let a;return e[0]!==s?(a=C.jsx(XS,{children:s}),e[0]=s,e[1]=a):a=e[1],a}let o;return e[2]!==n||e[3]!==i?(o=C.jsx(ZS,{components:n,unstable_showEmptyOnNonTextEnd:i}),e[2]=n,e[3]=i,e[4]=o):o=e[4],o};Co.displayName="MessagePrimitive.Parts";const ZS=t=>{const e=R(18),{components:n,unstable_showEmptyOnNonTextEnd:r}=t,s=N(h0),i=!!n?.ChainOfThought,{ranges:o,partIds:a}=BS(i);let l;e:{if(s===0){let p;e[0]!==n?(p=C.jsx(bf,{components:n}),e[0]=n,e[1]=p):p=e[1],l=p;break e}let h;if(e[2]!==n||e[3]!==o||e[4]!==a){let p;e[6]!==n||e[7]!==a?(p=m=>{if(m.type==="single")return C.jsx(pr,{index:m.index,components:n},a[m.index]);const y=JSON.stringify([m.type,m.idKey??m.startIndex]);if(m.type==="chainOfThoughtGroup"){const g=n?.ChainOfThought;return g?C.jsx(gS,{startIndex:m.startIndex,endIndex:m.endIndex,children:C.jsx(g,{})},y):null}else if(m.type==="toolGroup"){const g=n?.ToolGroup??ft.ToolGroup;return C.jsx(g,{startIndex:m.startIndex,endIndex:m.endIndex,children:Array.from({length:m.endIndex-m.startIndex+1},(b,v)=>{const w=m.startIndex+v;return C.jsx(pr,{index:w,components:n},a[w])})},y)}else{const g=n?.ReasoningGroup??ft.ReasoningGroup;return C.jsx(g,{startIndex:m.startIndex,endIndex:m.endIndex,children:Array.from({length:m.endIndex-m.startIndex+1},(b,v)=>{const w=m.startIndex+v;return C.jsx(pr,{index:w,components:n},a[w])})},y)}},e[6]=n,e[7]=a,e[8]=p):p=e[8],h=o.map(p),e[2]=n,e[3]=o,e[4]=a,e[5]=h}else h=e[5];l=h}const c=l;let u;e[9]!==n?(u=n?.Quote&&C.jsx(QS,{Quote:n.Quote}),e[9]=n,e[10]=u):u=e[10];let d;e[11]!==n||e[12]!==r?(d=C.jsx(GS,{components:n,enabled:r}),e[11]=n,e[12]=r,e[13]=d):d=e[13];let f;return e[14]!==c||e[15]!==u||e[16]!==d?(f=C.jsxs(C.Fragment,{children:[u,c,d]}),e[14]=c,e[15]=u,e[16]=d,e[17]=f):f=e[17],f};function e0(t){return t.type}function t0(t){return t.message.parts.map(e0)}function n0(t){return vn(t.message.parts)}function r0(t){return t.part}function s0(t){return t.message.status??US}function i0(t){return t.part}function o0(t){return t.part.type==="tool-call"?La(t.tools,t.part):null}function a0(t){return t.part}function l0(t){return t.part.type==="data"?Va(t.dataRenderers,t.part.name,void 0)??null:null}function c0(t){return t.part.type}function u0(t){return vn(t.message.parts)}function d0(t){return(t.message.status?.type??"complete")==="running"}function h0(t){return t.message.parts.length}const f0=Symbol.for("@assistant-ui/groupBy.memoKey"),Nc=t=>{const e=t.nextChildIdx++;return t.nodeKey===""?String(e):`${t.nodeKey}.${e}`},Bc=(t,e)=>{if(!(e===void 0||t.claimed.has(e)))return t.claimed.add(e),`id:${e}`},p0=(t,e)=>{const n={key:"",nodeKey:"",indices:[],children:[],nextChildIdx:0,claimed:new Set},r=[n],s=()=>{const i=r.pop(),o=r[r.length-1],a=e?.[i.indices[0]];o.children.push({type:"group",key:i.key,nodeKey:i.nodeKey,idKey:Bc(o,a?.includes(":")?a:void 0),indices:i.indices,children:i.children})};for(let i=0;i<t.length;i++){const o=t[i];let a=0;for(;a<r.length-1&&a<o.length&&r[a+1].key===o[a];)a++;for(;r.length-1>a;)s();for(;r.length-1<o.length;){const c=r[r.length-1];r.push({key:o[r.length-1],nodeKey:Nc(c),indices:[],children:[],nextChildIdx:0,claimed:new Set})}const l=r[r.length-1];l.children.push({type:"part",index:i,nodeKey:Nc(l),idKey:Bc(l,e?.[i])});for(let c=1;c<r.length;c++)r[c].indices.push(i)}for(;r.length>1;)s();return n.children},m0=(t,e,n)=>{if(!n)return!1;switch(t){case"never":return!1;case"always":return!0;case"empty":return e.length===0;case"no-text":{const r=e[e.length-1];return r===void 0||r.type!=="text"&&r.type!=="reasoning"}}},Sf=()=>{throw new Error("MessagePrimitive.GroupedParts: rendered `children` under a leaf part. `children` is only meaningful for `group-…` cases — add a matching case for the part type or return `null` to use registered UIs.")},Ua=(t,e,n)=>{if(t.type==="part")return C.jsx(xf,{index:t.index,children:({part:a})=>n({part:a,children:C.jsx(Sf,{})})??C.jsx(wf,{})},t.idKey?`part-${t.idKey}`:`part-${t.index}`);const{status:r,counts:s,timing:i}=hS(e,t.indices),o={type:t.key,status:r,counts:s,indices:t.indices,...i&&{timing:i}};return C.jsx(qy,{children:n({part:o,children:C.jsx(C.Fragment,{children:t.children.map(a=>Ua(a,e,n))})})},JSON.stringify([t.key,t.idKey??t.nodeKey]))};function Tf({groupBy:t,indicator:e="no-text",children:n}){const r=N(it(l=>l.message.parts)),s=N(l=>l.tools.toolUIs),i=N(l=>e==="never"?!1:l.message.status?.type==="running"),o=t[f0]??t,a=ye(()=>{const l={toolUIs:s};return p0(r.map(c=>t(c,l)??[]),vn(r))},[r,o,s]);return C.jsxs(C.Fragment,{children:[a.map(l=>Ua(l,r,n)),m0(e,r,i)&&n({part:{type:"indicator"},children:C.jsx(Sf,{})})]})}Tf.displayName="MessagePrimitive.GroupedParts";const g0=new WeakMap,y0=t=>g0.get(t),b0=t=>t.length===1?{type:"part",index:t[0],nodeKey:"0",idKey:void 0}:{type:"group",key:"group-row",nodeKey:"0",idKey:void 0,indices:t,children:t.map((e,n)=>({type:"part",index:e,nodeKey:`0.${n}`,idKey:void 0}))},_0=t=>{const e=R(7),{row:n,children:r}=t,s=N(it(S0));if(n.indices.some(o=>o>=s.length))return null;let i;if(e[0]!==r||e[1]!==s||e[2]!==n){const o=y0(n)??b0(n.indices);let a;e[4]!==r||e[5]!==n?(a=l=>r({type:"part",row:n,part:l.part,children:l.children}),e[4]=r,e[5]=n,e[6]=a):a=e[6],i=Ua(o,s,a),e[0]=r,e[1]=s,e[2]=n,e[3]=i}else i=e[3];return i},v0=({row:t,children:e})=>C.jsx(qt,{getItemState:n=>n.message.getState(),children:n=>e({type:"message",row:t,get message(){return n()}})}),w0=({row:t,children:e})=>C.jsx(qt,{getItemState:n=>n.message.getState(),children:n=>e({type:"turn-end",row:t,get message(){return n()}})}),x0=t=>{const e=R(8),{row:n,children:r}=t;let s;if(e[0]!==n.messageId?(s=a=>Dh(a.thread.messages,n.messageId),e[0]=n.messageId,e[1]=s):s=e[1],!N(s))return null;let i;e[2]!==r||e[3]!==n?(i=n.type==="message"?C.jsx(v0,{row:n,children:r}):n.type==="part"?C.jsx(_0,{row:n,children:r}):C.jsx(w0,{row:n,children:r}),e[2]=r,e[3]=n,e[4]=i):i=e[4];let o;return e[5]!==n.messageId||e[6]!==i?(o=C.jsx(uf,{id:n.messageId,children:i}),e[5]=n.messageId,e[6]=i,e[7]=o):o=e[7],o},Cf=Te(x0,(t,e)=>t.row===e.row&&t.children===e.children);Cf.displayName="ThreadPrimitive.Row";function S0(t){return t.message.parts}const T0=t=>{const e=R(5),{children:n}=t,r=N(pf);if(!r)return null;let s;e[0]!==n||e[1]!==r?(s=n(r),e[0]=n,e[1]=r,e[2]=s):s=e[2];let i;return e[3]!==s?(i=C.jsx(C.Fragment,{children:s}),e[3]=s,e[4]=i):i=e[4],i},If=Te(T0);If.displayName="MessagePrimitive.Quote";const kf=(t,e)=>{switch(e.type){case"image":return t?.Image??t?.Attachment;case"document":return t?.Document??t?.Attachment;case"file":return t?.File??t?.Attachment;default:return t?.Attachment}},C0=t=>{const e=R(5),{components:n}=t,r=N(I0);if(!r)return null;let s;e[0]!==r||e[1]!==n?(s=kf(n,r),e[0]=r,e[1]=n,e[2]=s):s=e[2];const i=s;if(!i)return null;let o;return e[3]!==i?(o=C.jsx(i,{}),e[3]=i,e[4]=o):o=e[4],o},Ef=Te(t=>{const e=R(5),{index:n,components:r}=t;let s;e[0]!==r?(s=C.jsx(C0,{components:r}),e[0]=r,e[1]=s):s=e[1];let i;return e[2]!==n||e[3]!==s?(i=C.jsx(of,{index:n,children:s}),e[2]=n,e[3]=s,e[4]=i):i=e[4],i},(t,e)=>t.index===e.index&&t.components?.Image===e.components?.Image&&t.components?.Document===e.components?.Document&&t.components?.File===e.components?.File&&t.components?.Attachment===e.components?.Attachment);Ef.displayName="MessagePrimitive.AttachmentByIndex";const jc=({children:t})=>{const e=N(it(n=>n.message.role!=="user"?[]:(n.message.submission?.attachments??n.message.attachments??[]).map(r=>r.id)));return ye(()=>e.map((n,r)=>C.jsx(of,{index:r,children:C.jsx(qt,{getItemState:s=>s.message.attachment({index:r}).getState(),children:s=>t({get attachment(){return s()}})})},n)),[e,t])},Af=t=>{const e=R(4),{components:n,children:r}=t;if(n){let i;return e[0]!==n?(i=C.jsx(jc,{children:o=>{const{attachment:a}=o,l=kf(n,a);return l?C.jsx(l,{}):null}}),e[0]=n,e[1]=i):i=e[1],i}let s;return e[2]!==r?(s=C.jsx(jc,{children:r}),e[2]=r,e[3]=s):s=e[3],s};Af.displayName="MessagePrimitive.Attachments";function I0(t){return t.attachment}const Rf=(t,e)=>{switch(e.type){case"image":return t?.Image??t?.Attachment;case"document":return t?.Document??t?.Attachment;case"file":return t?.File??t?.Attachment;default:return t?.Attachment}},k0=t=>{const e=R(5),{components:n}=t,r=N(E0);if(!r)return null;let s;e[0]!==r||e[1]!==n?(s=Rf(n,r),e[0]=r,e[1]=n,e[2]=s):s=e[2];const i=s;if(!i)return null;let o;return e[3]!==i?(o=C.jsx(i,{}),e[3]=i,e[4]=o):o=e[4],o},Mf=Te(t=>{const e=R(5),{index:n,components:r}=t;let s;e[0]!==r?(s=C.jsx(k0,{components:r}),e[0]=r,e[1]=s):s=e[1];let i;return e[2]!==n||e[3]!==s?(i=C.jsx(af,{index:n,children:s}),e[2]=n,e[3]=s,e[4]=i):i=e[4],i},(t,e)=>t.index===e.index&&t.components?.Image===e.components?.Image&&t.components?.Document===e.components?.Document&&t.components?.File===e.components?.File&&t.components?.Attachment===e.components?.Attachment);Mf.displayName="ComposerPrimitive.AttachmentByIndex";const zc=({children:t})=>{const e=N(it(n=>n.composer.attachments.map(r=>r.id)));return ye(()=>e.map((n,r)=>C.jsx(af,{index:r,children:C.jsx(qt,{getItemState:s=>s.composer.attachment({index:r}).getState(),children:s=>t({get attachment(){return s()}})})},n)),[e,t])},Pf=t=>{const e=R(4),{components:n,children:r}=t;if(n){let i;return e[0]!==n?(i=C.jsx(zc,{children:o=>{const{attachment:a}=o,l=Rf(n,a);return l?C.jsx(l,{}):null}}),e[0]=n,e[1]=i):i=e[1],i}let s;return e[2]!==r?(s=C.jsx(zc,{children:r}),e[2]=r,e[3]=s):s=e[3],s};Pf.displayName="ComposerPrimitive.Attachments";function E0(t){return t.attachment}const A0=({children:t})=>{const e=N(it(n=>n.composer.queue.map(r=>r.id)));return ye(()=>e.map((n,r)=>C.jsx(bS,{index:r,children:C.jsx(qt,{getItemState:s=>s.composer.queueItem({index:r}).getState(),children:s=>t({get queueItem(){return s()}})})},n)),[e,t])},Df=Te(A0);Df.displayName="ComposerPrimitive.Queue";const qa=t=>{const{children:e}=t;return N(R0)?e:null};qa.displayName="MessagePartPrimitive.InProgress";function R0(t){return t.part.status.type==="running"}const Of=t=>{const e=R(2),{components:n}=t,r=n.Suggestion;let s;return e[0]!==r?(s=C.jsx(r,{}),e[0]=r,e[1]=s):s=e[1],s},Lf=Te(t=>{const e=R(5),{index:n,components:r}=t;let s;e[0]!==r?(s=C.jsx(Of,{components:r}),e[0]=r,e[1]=s):s=e[1];let i;return e[2]!==n||e[3]!==s?(i=C.jsx(cf,{index:n,children:s}),e[2]=n,e[3]=s,e[4]=i):i=e[4],i},(t,e)=>t.index===e.index&&t.components.Suggestion===e.components.Suggestion);Lf.displayName="ThreadPrimitive.SuggestionByIndex";const Vc=({children:t})=>{const e=N(it(n=>Sv(n.suggestions.suggestions)));return ye(()=>e.length===0?null:e.map((n,r)=>C.jsx(cf,{index:r,children:C.jsx(qt,{getItemState:s=>s.suggestions.suggestion({index:r}).getState(),children:s=>t({get suggestion(){return s()}})})},n)),[e,t])},Ff=t=>{const e=R(4),{components:n,children:r}=t;if(n){let i;return e[0]!==n?(i=C.jsx(Vc,{children:()=>C.jsx(Of,{components:n})}),e[0]=n,e[1]=i):i=e[1],i}let s;return e[2]!==r?(s=C.jsx(Vc,{children:r}),e[2]=r,e[3]=s):s=e[3],s};Ff.displayName="ThreadPrimitive.Suggestions";const M0=Te(Ff,(t,e)=>t.children||e.children?t.children===e.children:t.components.Suggestion===e.components.Suggestion),P0=t=>{const e=R(3);let n;return e[0]!==t.dictation||e[1]!==t.editing?(n=r=>{if(t.editing===!0&&!r.composer.isEditing||t.editing===!1&&r.composer.isEditing)return!1;const s=r.composer.dictation!=null;return!(t.dictation===!0&&!s||t.dictation===!1&&s)},e[0]=t.dictation,e[1]=t.editing,e[2]=n):n=e[2],N(n)},$f=t=>{const e=R(3);let n,r;return e[0]!==t?({children:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),P0(r)?n:null};$f.displayName="ComposerPrimitive.If";const D0=t=>t.thread.isDisabled||!t.composer.canSend||t.thread.isRunning&&!t.thread.capabilities.queue&&t.thread.voice===void 0,O0=t=>t.thread.isDisabled||t.thread.isRunning||t.thread.voice!==void 0||!t.thread.canResume||t.composer.type!=="thread"||!t.composer.isEmpty,L0=t=>!t.composer.canCancel,F0=t=>t.composer.isEditing||t.optional.message?.submission!==void 0||t.optional.thread?.isDisabled===!0||t.optional.thread?.voice!==void 0||t.optional.thread?.capabilities.edit===!1,$0=t=>t.thread.isRunning||t.thread.isDisabled||t.thread.voice!==void 0||t.message.role!=="assistant"||!t.thread.capabilities.reload,N0=t=>t.message.runState!=="in-progress",B0=t=>t.thread.isRunning||t.thread.isDisabled||t.thread.voice!==void 0||t.message.role!=="assistant"||!t.message.isLast||!t.thread.capabilities.reload||t.message.runState!=="stale",Nf=t=>(t.message.role!=="assistant"||t.message.status?.type!=="running")&&t.message.parts.some(e=>e.type==="text"&&e.text.length>0),j0=t=>!Nf(t),z0=t=>t.optional.thread?.capabilities.speech!==!0||!Nf(t),Bf=t=>t.isSendDisabled?"blocked":t.voice!==void 0?t.voice.canSendText?"now":"blocked":t.isRunning?t.capabilities.queue?"queued":"blocked":"now",V0=(t,e)=>t.thread.isDisabled||e&&Bf(t.thread)==="blocked",U0=t=>{if(t.message.status?.type!=="incomplete"||t.message.status.reason!=="error")return;const e=t.message.status.error;return typeof e=="string"?e:typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"?e.message:e??"An error occurred"},q0=()=>{const t=R(5),e=Z(),n=N(D0);let r;t[0]!==e?(r=o=>{e.composer.send(o)},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={send:s,disabled:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i},H0=()=>{const t=R(5),e=Z(),n=N(O0);let r;t[0]!==e?(r=()=>{Ks("Resume",e.thread().resumeRun({parentId:e.thread().getState().messages.at(-1)?.id??null}))},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={resume:s,disabled:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i},W0=()=>{const t=R(5),e=Z(),n=N(L0);let r;t[0]!==e?(r=()=>{e.composer.cancel()},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==s||t[3]!==n?(i={cancel:s,disabled:n},t[2]=s,t[3]=n,t[4]=i):i=t[4],i},G0=()=>{const t=R(5),e=Z(),n=N(K0);let r;t[0]!==e?(r=()=>{e.composer.startDictation()},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={startDictation:s,disabled:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i};function K0(t){return t.thread.isDisabled||t.composer.dictation!=null||!t.thread.capabilities.dictation||!t.composer.isEditing}const Q0=()=>{const t=R(5),e=Z(),n=N(Y0);let r;t[0]!==e?(r=o=>e.composer.addAttachment(o),t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==s||t[3]!==n?(i={addAttachment:s,disabled:n},t[2]=s,t[3]=n,t[4]=i):i=t[4],i};function Y0(t){return t.thread.isDisabled||!t.composer.isEditing}const J0=t=>{const e=R(20);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const{copiedDuration:r,copyToClipboard:s}=n,i=r===void 0?3e3:r,o=Z(),a=N(j0),l=N(X0),c=N(Z0),u=N(eT),d=N(tT),f=X(void 0),h=X(void 0),p=X(0),m=X(l);let y,g;e[2]!==l?(y=()=>{m.current=l},g=[l],e[2]=l,e[3]=y,e[4]=g):(y=e[3],g=e[4]),ct(y,g);let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=()=>()=>{p.current=p.current+1,f.current!==void 0&&(clearTimeout(f.current),f.current=void 0,h.current?.(!1),h.current=void 0)},e[5]=b):b=e[5];let v;e[6]!==o.message||e[7]!==l?(v=[o.message,l],e[6]=o.message,e[7]=l,e[8]=v):v=e[8],Q(b,v);let w;e[9]!==o.message||e[10]!==d||e[11]!==i||e[12]!==s||e[13]!==u||e[14]!==l?(w=()=>{if(!s)return;const E=u?d:o.message.getCopyText();if(!E)return;const D=p.current,x=l,M=o.message.setIsCopied;let P;try{P=s(E)}catch{return}Promise.resolve(P).then(()=>{D!==p.current||x!==m.current||(f.current!==void 0&&clearTimeout(f.current),h.current=M,M(!0),f.current=setTimeout(()=>{if(f.current=void 0,x!==m.current){M(!1),h.current=void 0;return}M(!1),h.current=void 0},i))},nT)},e[9]=o.message,e[10]=d,e[11]=i,e[12]=s,e[13]=u,e[14]=l,e[15]=w):w=e[15];const k=w,_=a||!s;let A;return e[16]!==k||e[17]!==c||e[18]!==_?(A={copy:k,disabled:_,isCopied:c},e[16]=k,e[17]=c,e[18]=_,e[19]=A):A=e[19],A};function X0(t){return t.message.id}function Z0(t){return t.message.isCopied}function eT(t){return t.composer.isEditing}function tT(t){return t.composer.text}function nT(){}const rT=()=>{const t=R(5),e=Z(),n=N(F0);let r;t[0]!==e?(r=()=>{e.composer.beginEdit()},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={edit:s,disabled:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i},sT=()=>{const t=R(5),e=Z(),n=N($0);let r;t[0]!==e?(r=()=>{e.message.reload()},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={reload:s,disabled:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i},iT=()=>{const t=R(5),e=Z(),n=N(B0);let r;t[0]!==e?(r=()=>{const o=e.thread(),{id:a}=e.message.getState(),l=o.getState().messages,c=l.findIndex(d=>d.id===a),u=c>0?l[c-1].id:null;Ks("Resume",(async()=>{await o.deleteMessage(a),o.startRun({parentId:u})})())},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={resume:s,disabled:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i},oT=()=>{const t=R(6),e=Z(),n=N(N0),[r,s]=ie(!1);let i;t[0]!==e?(i=()=>{s(!0),AS(e.threadListItem.getState().id).catch(aT).finally(()=>s(!1))},t[0]=e,t[1]=i):i=t[1];const o=i,a=n||r;let l;return t[2]!==r||t[3]!==o||t[4]!==a?(l={refresh:o,disabled:a,isRefreshing:r},t[2]=r,t[3]=o,t[4]=a,t[5]=l):l=t[5],l};function aT(t){console.warn("[assistant-ui] Refreshing the run failed:",t)}const lT=()=>{const t=R(5),e=Z(),n=N(uT);let r;t[0]!==e?(r=()=>{e.message.submitFeedback({type:"positive"})},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={submit:s,isSubmitted:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i},cT=()=>{const t=R(5),e=Z(),n=N(dT);let r;t[0]!==e?(r=()=>{e.message.submitFeedback({type:"negative"})},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={submit:s,isSubmitted:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i};function uT(t){return t.message.metadata.submittedFeedback?.type==="positive"}function dT(t){return t.message.metadata.submittedFeedback?.type==="negative"}const hT=()=>{const t=R(5),e=Z(),n=N(z0);let r;t[0]!==e?(r=async()=>{e.message.speak()},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={speak:s,disabled:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i},fT=()=>{const t=R(5),e=Z(),n=N(pT);let r;t[0]!==e?(r=()=>{e.message.stopSpeaking()},t[0]=e,t[1]=r):r=t[1];const s=r;let i;return t[2]!==n||t[3]!==s?(i={stopSpeaking:s,disabled:n},t[2]=n,t[3]=s,t[4]=i):i=t[4],i};function pT(t){return t.message.speech==null}const mT=t=>{const e=R(10),{prompt:n,send:r,clearComposer:s}=t,i=s===void 0?!0:s,o=Z(),a=r??!1;let l;e[0]!==a?(l=h=>V0(h,a),e[0]=a,e[1]=l):l=e[1];const c=N(l);let u;e[2]!==o||e[3]!==i||e[4]!==n||e[5]!==a?(u=()=>{if(a){const h=Bf(o.thread.getState());if(h==="blocked")return;o.thread.append({content:[{type:"text",text:n}],runConfig:o.composer.getState().runConfig}),i&&h==="now"&&o.composer.setText("")}else if(i)o.composer.setText(n);else{const h=o.composer.getState().text;o.composer.setText([h,n].filter(gT).join(" "))}},e[2]=o,e[3]=i,e[4]=n,e[5]=a,e[6]=u):u=e[6];const d=u;let f;return e[7]!==c||e[8]!==d?(f={trigger:d,disabled:c},e[7]=c,e[8]=d,e[9]=f):f=e[9],f};function gT(t){return t.trim()}const yT=()=>N(U0),bT=t=>{const{cloud:e,scopeId:n,initialMessages:r,maxSteps:s,adapters:i,unstable_humanToolNames:o,unstable_enableMessageQueue:a,unstable_queueClearOnRewind:l,unstable_queueClearOnCancel:c,...u}=t;return{localRuntimeOptions:{cloud:e,scopeId:n,initialMessages:r,maxSteps:s,adapters:i,unstable_humanToolNames:o,unstable_enableMessageQueue:a,unstable_queueClearOnRewind:l,unstable_queueClearOnCancel:c},otherOptions:u}};function _T(t,e){function n(r){const s=Fe(t);if(!r?.optional&&!s)throw new Error(`This component must be used within ${e}.`);return s}return n}function jf(t,e){function n(s){const i=t(s);return i?i[e]:null}function r(s){let i=!1,o;typeof s=="function"?o=s:s&&typeof s=="object"&&(i=!!s.optional,o=s.selector);const a=n({optional:i});return a?o?a(o):a():null}return{[e]:r,[`${e}Store`]:n}}const zf=ke(null),vT=_T(zf,"ThreadPrimitive.Viewport"),{useThreadViewport:Ht,useThreadViewportStore:xn}=jf(vT,"useThreadViewport");let kn;const Io=()=>{if(kn)return kn;const t=()=>({apis:new Map,nextId:0,listeners:new Set});if(typeof window>"u")return kn=t(),kn;const e=window.__ASSISTANT_UI_DEVTOOLS_HOOK__;if(e)return kn=e,e;const n=t();return window.__ASSISTANT_UI_DEVTOOLS_HOOK__=n,kn=n,n},Zr=t=>{tt(Io().listeners,t,"DevTools")};var wT=class Vf{static MAX_EVENT_LOGS_PER_API=200;static register(e){const n=Io();for(const a of n.apis.values())if(a.api===e)return()=>{};const r=n.nextId++,s={api:e,logs:[]},i=e.on?.("*",a=>{const l=n.apis.get(r);l&&(l.logs.push({time:new Date,event:a.event,data:a.payload}),l.logs.length>Vf.MAX_EVENT_LOGS_PER_API&&(l.logs=l.logs.slice(-200)),Zr(r))}),o=e.subscribe?.(()=>{Zr(r)});return n.apis.set(r,s),Zr(r),()=>{const a=Io();a.apis.get(r)&&(i?.(),o?.(),a.apis.delete(r),Zr(r))}}};const Uc=t=>{let e;const n=new Set,r=(c,u)=>{const d=typeof c=="function"?c(e):c;if(!Object.is(d,e)){const f=e;e=u??(typeof d!="object"||d===null)?d:Object.assign({},e,d),n.forEach(h=>h(e,f))}},s=()=>e,a={setState:r,getState:s,getInitialState:()=>l,subscribe:c=>(n.add(c),()=>n.delete(c))},l=e=t(r,s,a);return a},xT=(t=>t?Uc(t):Uc),ST=t=>t;function TT(t,e=ST){const n=et.useSyncExternalStore(t.subscribe,et.useCallback(()=>e(t.getState()),[t,e]),()=>e(t.getInitialState()));return et.useDebugValue(n),n}const qc=t=>{const e=xT(t),n=r=>TT(e,r);return Object.assign(n,e),n},Uf=(t=>t?qc(t):qc),CT=t=>{const e=new Map,n=()=>{let r=0;for(const s of e.values())r+=s;t(r)};return{register:()=>{const r=Symbol();return e.set(r,0),{setHeight:s=>{e.get(r)!==s&&(e.set(r,s),n())},unregister:()=>{e.delete(r),n()}}}}},qf=new WeakMap,IT=t=>qf.get(t),kT=(t={})=>{const e=new Set,n=CT(o=>{i.setState({height:{...i.getState().height,viewport:o}})}),r={getOptions:()=>({autoScroll:t.turnAnchor!=="top",scrollToBottomOnInitialize:!0,scrollToBottomOnRunStart:t.turnAnchor!=="top",scrollToBottomOnThreadSwitch:!0}),controller:E_({getOptions:()=>r.getOptions(),onAtBottomChange:o=>i.setState({isAtBottom:o}),onContentInsetChange:o=>{i.setState({height:{...i.getState().height,inset:o}})}})},s=(o,a)=>(i.setState({element:{...i.getState().element,[o]:a}}),()=>{i.getState().element[o]===a&&i.setState({element:{...i.getState().element,[o]:null}})}),i=Uf(()=>({isAtBottom:!0,scrollToBottom:({behavior:o="auto"}={})=>{tt(e,()=>({behavior:o}),"Thread viewport")},onScrollToBottom:o=>(e.add(o),()=>{e.delete(o)}),turnAnchor:t.turnAnchor??"bottom",topAnchorMessageClamp:{tallerThan:t.topAnchorMessageClamp?.tallerThan??"10em",visibleHeight:t.topAnchorMessageClamp?.visibleHeight??"6em"},height:{viewport:0,inset:0},element:{viewport:null,anchor:null,target:null},targetConfig:null,topAnchorTurn:null,registerViewport:n.register,registerContentInset:r.controller.registerContentInset,registerViewportElement:o=>s("viewport",o),registerAnchorElement:o=>s("anchor",o),registerAnchorTargetElement:(o,a)=>(i.setState({element:{...i.getState().element,target:o},targetConfig:o&&a?a:null}),()=>{i.getState().element.target===o&&i.setState({element:{...i.getState().element,target:null},targetConfig:null})}),setTopAnchorTurn:o=>{i.setState({topAnchorTurn:o})}}));return qf.set(i,r),i},ko=t=>t,ET=t=>{const e=R(11);let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={optional:!0},e[0]=n):n=e[0];const r=xn(n);let s;e[1]!==t?(s=()=>kT(t),e[1]=t,e[2]=s):s=e[2];const[i]=ie(s);let o,a;e[3]!==r||e[4]!==i?(o=()=>r?.getState().onScrollToBottom(u=>{i.getState().scrollToBottom(u)}),a=[r,i],e[3]=r,e[4]=i,e[5]=o,e[6]=a):(o=e[5],a=e[6]),Q(o,a);let l,c;return e[7]!==r||e[8]!==i?(l=()=>{if(r)return i.subscribe(u=>{r.getState().isAtBottom!==u.isAtBottom&&ko(r).setState({isAtBottom:u.isAtBottom})})},c=[i,r],e[7]=r,e[8]=i,e[9]=l,e[10]=c):(l=e[9],c=e[10]),Q(l,c),i},Ha=t=>{const e=R(7),{children:n,options:r}=t;let s;e[0]!==r?(s=r===void 0?{}:r,e[0]=r,e[1]=s):s=e[1];const i=ET(s);let o;e[2]!==i?(o=()=>({useThreadViewport:i}),e[2]=i,e[3]=o):o=e[3];const[a]=ie(o);let l;return e[4]!==n||e[5]!==a?(l=C.jsx(zf.Provider,{value:a,children:n}),e[4]=n,e[5]=a,e[6]=l):l=e[6],l},AT=()=>{const t=R(3),e=Z();let n,r;return t[0]!==e?(n=()=>{try{return}catch{return}return wT.register(e)},r=[e],t[0]=e,t[1]=n,t[2]=r):(n=t[1],r=t[2]),Q(n,r),null},RT=t=>{const e=R(8),{children:n,aui:r,config:s,runtime:i}=t,o=r??null;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=C.jsx(AT,{}),e[0]=a):a=e[0];let l;e[1]!==n?(l=C.jsx(Ha,{children:n}),e[1]=n,e[2]=l):l=e[2];let c;return e[3]!==s||e[4]!==i||e[5]!==o||e[6]!==l?(c=C.jsxs(nS,{runtime:i,aui:o,config:s,children:[a,l]}),e[3]=s,e[4]=i,e[5]=o,e[6]=l,e[7]=c):c=e[7],c},WO=Te(RT),Un=typeof globalThis.window<"u"?Ud:Q;var MT=Object.defineProperty,Wa=(t,e)=>MT(t,"name",{value:e,configurable:!0});function Eo(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}Wa(Eo,"setRef");function Hf(...t){return e=>{let n=!1;const r=t.map(s=>{const i=Eo(s,e);return!n&&typeof i=="function"&&(n=!0),i});if(n)return()=>{for(let s=0;s<r.length;s++){const i=r[s];typeof i=="function"?i():Eo(t[s],null)}}}}Wa(Hf,"composeRefs");function Wt(...t){return H.useCallback(Hf(...t),t)}Wa(Wt,"useComposedRefs");var PT=Object.defineProperty,qe=(t,e)=>PT(t,"name",{value:e,configurable:!0});function Ga(t){const e=H.forwardRef((n,r)=>{let{children:s,...i}=n,o=null,a=!1;const l=[];s=Jf(s),H.Children.forEach(s,f=>{if(Qf(f)){a=!0;const h=f;let p="child"in h.props?h.props.child:h.props.children;for(;Qa(p)&&typeof Cs=="function";)p=Cs(p._payload);o=OT(h,p),l.push(o?.props?.children)}else l.push(f)}),o?o=H.cloneElement(o,void 0,l):!a&&H.Children.count(s)===1&&H.isValidElement(s)&&(o=s);const c=o?Kf(o):void 0,u=Wt(r,c);if(!o){if(s||s===0)throw new Error(a?$T(t):FT(t));return s}const d=Gf(i,o.props??{});return o.type!==H.Fragment&&(d.ref=r?u:c),H.cloneElement(o,d)});return e.displayName=`${t}.Slot`,e}qe(Ga,"createSlot");var Ka=Ga("Slot"),Wf=Symbol.for("radix.slottable");function DT(t){const e=qe(n=>"child"in n?n.children(n.child):n.children,"Slottable");return e.displayName=`${t}.Slottable`,e.__radixId=Wf,e}qe(DT,"createSlottable");var OT=qe((t,e)=>"child"in t.props?H.isValidElement(e)?H.cloneElement(e,void 0,t.props.children(e.props.children)):null:H.isValidElement(e)?e:null,"getSlottableElementFromSlottable");function Gf(t,e){const n={...e};for(const r in e){const s=t[r],i=e[r];/^on[A-Z]/.test(r)?s&&i?n[r]=(...a)=>{const l=i(...a);return s(...a),l}:s&&(n[r]=s):r==="style"?n[r]={...s,...i}:r==="className"?n[r]=[s,i].filter(Boolean).join(" "):r==="aria-describedby"&&(n[r]=Xf(i,s))}return{...t,...n}}qe(Gf,"mergeProps");function Kf(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}qe(Kf,"getElementRef");function Qf(t){return H.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Wf}qe(Qf,"isSlottable");var LT=Symbol.for("react.lazy");function Qa(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===LT&&"_payload"in t&&Yf(t._payload)}qe(Qa,"isLazyComponent");function Yf(t){return typeof t=="object"&&t!==null&&"then"in t}qe(Yf,"isPromiseLike");function Jf(t){let e=t;for(;Qa(e)&&typeof Cs=="function";)e=Cs(e._payload);return e}qe(Jf,"useUnwrappedLazy");function Xf(...t){const e=new Set;for(const n of t)if(typeof n=="string")for(const r of String(n).trim().split(/\s+/))r&&e.add(r);return e.size>0?Array.from(e).join(" "):void 0}qe(Xf,"concatAriaDescribedby");var FT=qe(t=>`${t} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),$T=qe(t=>`${t} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Cs=ld[" use ".trim().toString()],NT=Object.defineProperty,BT=(t,e)=>NT(t,"name",{value:e,configurable:!0}),jT=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Zf=jT.reduce((t,e)=>{const n=Ga(`Primitive.${e}`),r=H.forwardRef((s,i)=>{const{asChild:o,...a}=s,l=o?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),C.jsx(l,{...a,ref:i})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function ep(t,e){t&&ad.flushSync(()=>t.dispatchEvent(e))}BT(ep,"dispatchDiscreteCustomEvent");var zT=globalThis?.document?H.useLayoutEffect:()=>{},VT=Object.defineProperty,Kn=(t,e)=>VT(t,"name",{value:e,configurable:!0}),tp=!!(typeof window<"u"&&window.document&&window.document.createElement);function _e(t,e,{checkForDefaultPrevented:n=!0}={}){return Kn(function(s){if(t?.(s),n===!1||!s||!s.defaultPrevented)return e?.(s)},"handleEvent")}Kn(_e,"composeEventHandlers");function UT(t){if(!tp)throw new Error("Cannot access window outside of the DOM");return t?.ownerDocument?.defaultView??window}Kn(UT,"getOwnerWindow");function Ao(t){if(!tp)throw new Error("Cannot access document outside of the DOM");return t?.ownerDocument??document}Kn(Ao,"getOwnerDocument");function np(t,e=!1){const{activeElement:n}=Ao(t);if(!n?.nodeName)return null;if(rp(n)&&n.contentDocument)return np(n.contentDocument.body,e);if(e){const r=n.getAttribute("aria-activedescendant");if(r){const s=Ao(n).getElementById(r);if(s)return s}}return n}Kn(np,"getActiveElement");function rp(t){return t.tagName==="IFRAME"}Kn(rp,"isFrame");var qT=Object.defineProperty,HT=(t,e)=>qT(t,"name",{value:e,configurable:!0}),Hc=ld[" useInsertionEffect ".trim().toString()];function Ys(t){const e=H.useRef(t);return typeof Hc=="function"?Hc(()=>{e.current=t}):zT(()=>{e.current=t}),H.useMemo(()=>((...n)=>e.current?.(...n)),[])}HT(Ys,"useCallbackRef");var WT=Object.defineProperty,sp=(t,e)=>WT(t,"name",{value:e,configurable:!0});function ip(t,e=globalThis?.document){const n=Ys(t);H.useEffect(()=>{const r=sp(s=>{s.key==="Escape"&&n(s)},"handleKeyDown");return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}sp(ip,"useEscapeKeydown");var Ya=Zf;Ya.dispatchDiscreteCustomEvent=ep;Ya.Root=Zf;var Wc=Object.defineProperty,Or=(t,e)=>{let n={};for(var r in t)Wc(n,r,{get:t[r],enumerable:!0});return Wc(n,Symbol.toStringTag,{value:"Module"}),n};const GT=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"];function op(t,e){return Wy(t,void 0,e!==void 0?e:t.props.children)}function Ja(t,e,n){return C.jsx(Ka,{...n,children:op(t,e)})}function KT(t){const e=he((n,r)=>{const s=R(17);let i,o,a,l;s[0]!==n?({render:a,asChild:i,children:o,...l}=n,s[0]=n,s[1]=i,s[2]=o,s[3]=a,s[4]=l):(i=s[1],o=s[2],a=s[3],l=s[4]);const c=t;if(a&&Vs(a)){const f=l;let h;s[5]!==o||s[6]!==a?(h=op(a,o),s[5]=o,s[6]=a,s[7]=h):h=s[7];let p;return s[8]!==r||s[9]!==f||s[10]!==h?(p=C.jsx(c,{...f,asChild:!0,ref:r,children:h}),s[8]=r,s[9]=f,s[10]=h,s[11]=p):p=s[11],p}const u=l;let d;return s[12]!==i||s[13]!==o||s[14]!==r||s[15]!==u?(d=C.jsx(c,{...u,asChild:i,ref:r,children:o}),s[12]=i,s[13]=o,s[14]=r,s[15]=u,s[16]=d):d=s[16],d});return e.displayName=typeof t=="string"?t:t.displayName??t.name??"Component",e}function QT(t){const e=Ya[t],n=KT(e);return n.displayName=`Primitive.${t}`,n}const ve=GT.reduce((t,e)=>(t[e]=QT(e),t),{}),nn={Hidden:"hidden",Floating:"floating",Normal:"normal"},YT=t=>{const e=R(5),{hideWhenRunning:n,autohide:r,autohideFloat:s,forceVisible:i}=t;let o;return e[0]!==r||e[1]!==s||e[2]!==i||e[3]!==n?(o=a=>{if(n&&(a.thread.isRunning||a.message.runState==="in-progress"))return nn.Hidden;const l=r==="always"||r==="not-last"&&!a.message.isLast,c=i||a.message.isHovering;return l?c?s==="always"||s==="single-branch"&&a.message.branchCount<=1?nn.Floating:nn.Normal:nn.Hidden:nn.Normal},e[0]=r,e[1]=s,e[2]=i,e[3]=n,e[4]=o):o=e[4],N(o)},JT=ke(null),ap=he((t,e)=>{const n=R(18);let r,s,i,o;n[0]!==t?({hideWhenRunning:i,autohide:r,autohideFloat:s,...o}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i,n[4]=o):(r=n[1],s=n[2],i=n[3],o=n[4]);const[a,l]=ie(0);let c;n[5]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{let b=!1;return l(XT),()=>{b||(b=!0,l(ZT))}},n[5]=c):c=n[5];const u=c;let d;n[6]===Symbol.for("react.memo_cache_sentinel")?(d={acquireInteractionLock:u},n[6]=d):d=n[6];const f=d,h=a>0;let p;n[7]!==r||n[8]!==s||n[9]!==i||n[10]!==h?(p={hideWhenRunning:i,autohide:r,autohideFloat:s,forceVisible:h},n[7]=r,n[8]=s,n[9]=i,n[10]=h,n[11]=p):p=n[11];const m=YT(p);if(m===nn.Hidden)return null;let y;n[12]!==m?(y=m===nn.Floating?{"data-floating":"true"}:null,n[12]=m,n[13]=y):y=n[13];let g;return n[14]!==e||n[15]!==o||n[16]!==y?(g=C.jsx(JT.Provider,{value:f,children:C.jsx(ve.div,{...y,...o,ref:e})}),n[14]=e,n[15]=o,n[16]=y,n[17]=g):g=n[17],g});ap.displayName="ActionBarPrimitive.Root";function XT(t){return t+1}function ZT(t){return Math.max(0,t-1)}const eC=t=>{const e=R(4);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const{copiedDuration:r}=n,s=r===void 0?3e3:r;let i;e[2]!==s?(i={copiedDuration:s,copyToClipboard:tC},e[2]=s,e[3]=i):i=e[3];const{copy:o,disabled:a}=J0(i);return a?null:o},lp=he((t,e)=>{const n=R(20);let r,s,i,o;n[0]!==t?({copiedDuration:r,onClick:i,disabled:s,...o}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i,n[4]=o):(r=n[1],s=n[2],i=n[3],o=n[4]);const a=N(nC);let l;n[5]!==r?(l={copiedDuration:r},n[5]=r,n[6]=l):l=n[6];const c=eC(l);let u;n[7]!==a?(u=a?{"data-copied":"true"}:{},n[7]=a,n[8]=u):u=n[8];const d=s||!c;let f;n[9]!==c?(f=()=>{c?.()},n[9]=c,n[10]=f):f=n[10];let h;n[11]!==i||n[12]!==f?(h=_e(i,f),n[11]=i,n[12]=f,n[13]=h):h=n[13];let p;return n[14]!==e||n[15]!==o||n[16]!==u||n[17]!==d||n[18]!==h?(p=C.jsx(ve.button,{type:"button",...u,...o,ref:e,disabled:d,onClick:h}),n[14]=e,n[15]=o,n[16]=u,n[17]=d,n[18]=h,n[19]=p):p=n[19],p});lp.displayName="ActionBarPrimitive.Copy";function tC(t){return typeof navigator>"u"||!navigator.clipboard?Promise.reject(new Error("Clipboard API is unavailable")):navigator.clipboard.writeText(t)}function nC(t){return t.message.isCopied}const $e=(t,e,n=[])=>{const r=he((s,i)=>{const o=R(6),a={},l={};Object.keys(s).forEach(m=>{n.includes(m)?a[m]=s[m]:l[m]=s[m]});const c=e(a)??void 0,u=ve,d="button",f=l.disabled||!c,h=_e(l.onClick,c);let p;return o[0]!==i||o[1]!==l||o[2]!==u.button||o[3]!==f||o[4]!==h?(p=C.jsx(u.button,{type:d,...l,ref:i,disabled:f,onClick:h}),o[0]=i,o[1]=l,o[2]=u.button,o[3]=f,o[4]=h,o[5]=p):p=o[5],p});return r.displayName=t,r},rC=()=>{const{disabled:t,reload:e}=sT();return t?null:e},sC=$e("ActionBarPrimitive.Reload",rC),iC=()=>{const{disabled:t,resume:e}=iT();return t?null:e},oC=$e("ActionBarPrimitive.Resume",iC),aC=()=>{const{disabled:t,refresh:e}=oT();return t?null:e},lC=$e("ActionBarPrimitive.RefreshRun",aC),cC=()=>{const{disabled:t,edit:e}=rT();return t?null:e},uC=$e("ActionBarPrimitive.Edit",cC),dC=()=>{const{disabled:t,speak:e}=hT();return t?null:e},hC=$e("ActionBarPrimitive.Speak",dC),fC=()=>{const{disabled:t,stopSpeaking:e}=fT();return t?null:e},cp=he((t,e)=>{const n=R(10),r=fC(),s=!r;let i;n[0]!==r?(i=()=>{r?.()},n[0]=r,n[1]=i):i=n[1];let o;n[2]!==t.onClick||n[3]!==i?(o=_e(t.onClick,i),n[2]=t.onClick,n[3]=i,n[4]=o):o=n[4];let a;return n[5]!==t||n[6]!==e||n[7]!==s||n[8]!==o?(a=C.jsx(ve.button,{type:"button",disabled:s,...t,ref:e,onClick:o}),n[5]=t,n[6]=e,n[7]=s,n[8]=o,n[9]=a):a=n[9],a});cp.displayName="ActionBarPrimitive.StopSpeaking";const pC=()=>{const{submit:t}=lT();return t},up=he((t,e)=>{const n=R(18);let r,s,i;n[0]!==t?({onClick:s,disabled:r,...i}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i):(r=n[1],s=n[2],i=n[3]);const o=N(mC),a=pC();let l;n[4]!==o?(l=o?{"data-submitted":"true"}:{},n[4]=o,n[5]=l):l=n[5];const c=r||!a;let u;n[6]!==a?(u=()=>{a?.()},n[6]=a,n[7]=u):u=n[7];let d;n[8]!==s||n[9]!==u?(d=_e(s,u),n[8]=s,n[9]=u,n[10]=d):d=n[10];let f;return n[11]!==e||n[12]!==o||n[13]!==i||n[14]!==l||n[15]!==c||n[16]!==d?(f=C.jsx(ve.button,{type:"button","aria-pressed":o,...l,...i,ref:e,disabled:c,onClick:d}),n[11]=e,n[12]=o,n[13]=i,n[14]=l,n[15]=c,n[16]=d,n[17]=f):f=n[17],f});up.displayName="ActionBarPrimitive.FeedbackPositive";function mC(t){return t.message.metadata.submittedFeedback?.type==="positive"}const gC=()=>{const{submit:t}=cT();return t},dp=he((t,e)=>{const n=R(18);let r,s,i;n[0]!==t?({onClick:s,disabled:r,...i}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i):(r=n[1],s=n[2],i=n[3]);const o=N(yC),a=gC();let l;n[4]!==o?(l=o?{"data-submitted":"true"}:{},n[4]=o,n[5]=l):l=n[5];const c=r||!a;let u;n[6]!==a?(u=()=>{a?.()},n[6]=a,n[7]=u):u=n[7];let d;n[8]!==s||n[9]!==u?(d=_e(s,u),n[8]=s,n[9]=u,n[10]=d):d=n[10];let f;return n[11]!==e||n[12]!==o||n[13]!==i||n[14]!==l||n[15]!==c||n[16]!==d?(f=C.jsx(ve.button,{type:"button","aria-pressed":o,...l,...i,ref:e,disabled:c,onClick:d}),n[11]=e,n[12]=o,n[13]=i,n[14]=l,n[15]=c,n[16]=d,n[17]=f):f=n[17],f});dp.displayName="ActionBarPrimitive.FeedbackNegative";function yC(t){return t.message.metadata.submittedFeedback?.type==="negative"}const bC=t=>{const e=R(6);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const{filename:r,onExport:s}=n,i=Z(),o=N(vC);let a;e[2]!==i.message||e[3]!==r||e[4]!==s?(a=async()=>{const c=i.message.getCopyText();if(!c)return;if(s){await s(c);return}const u=new Blob([c],{type:"text/markdown"}),d=URL.createObjectURL(u),f=document.createElement("a");f.href=d,f.download=r??`message-${Date.now()}.md`,f.rel="noopener",document.body.appendChild(f),f.click(),document.body.removeChild(f),setTimeout(()=>URL.revokeObjectURL(d),4e4)},e[2]=i.message,e[3]=r,e[4]=s,e[5]=a):a=e[5];const l=a;return o?l:null},hp=he((t,e)=>{const n=R(19);let r,s,i,o,a;n[0]!==t?({filename:s,onExport:o,onClick:i,disabled:r,...a}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i,n[4]=o,n[5]=a):(r=n[1],s=n[2],i=n[3],o=n[4],a=n[5]);let l;n[6]!==s||n[7]!==o?(l={filename:s,onExport:o},n[6]=s,n[7]=o,n[8]=l):l=n[8];const c=bC(l),u=r||!c;let d;n[9]!==c?(d=()=>{c?.().catch(wC)},n[9]=c,n[10]=d):d=n[10];let f;n[11]!==i||n[12]!==d?(f=_e(i,d),n[11]=i,n[12]=d,n[13]=f):f=n[13];let h;return n[14]!==e||n[15]!==a||n[16]!==u||n[17]!==f?(h=C.jsx(ve.button,{type:"button",...a,ref:e,disabled:u,onClick:f}),n[14]=e,n[15]=a,n[16]=u,n[17]=f,n[18]=h):h=n[18],h});hp.displayName="ActionBarPrimitive.ExportMarkdown";function _C(t){return t.type==="text"&&t.text.length>0}function vC(t){return(t.message.role!=="assistant"||t.message.status?.type!=="running")&&t.message.parts.some(_C)}function wC(t){console.error("[assistant-ui] markdown export failed:",t)}var GO=Or({Copy:()=>lp,Edit:()=>uC,ExportMarkdown:()=>hp,FeedbackNegative:()=>dp,FeedbackPositive:()=>up,RefreshRun:()=>lC,Reload:()=>sC,Resume:()=>oC,Root:()=>ap,Speak:()=>hC,StopSpeaking:()=>cp});const fp=ke(null),Js=()=>Fe(fp),xC=t=>{const e=R(8),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=new Map,e[0]=r):r=e[0];const s=X(r);let i;e[1]===Symbol.for("react.memo_cache_sentinel")?(i=[],e[1]=i):i=e[1];const o=X(i);let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{const y=Array.from(s.current.entries());y.sort(SC),o.current=y.map(TC)},e[2]=a):a=e[2];const l=a;let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=(y,g)=>{const b=g?.priority??0;return s.current.set(y,b),l(),()=>{s.current.delete(y),l()}},e[3]=c):c=e[3];const u=c;let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=()=>o.current,e[4]=d):d=e[4];const f=d;let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h={register:u,getPlugins:f},e[5]=h):h=e[5];const p=h;let m;return e[6]!==n?(m=C.jsx(fp.Provider,{value:p,children:n}),e[6]=n,e[7]=m):m=e[7],m};function SC(t,e){return e[1]-t[1]}function TC(t){const[e]=t;return e}const Xa=ke(null),pp=ke(null),Za=()=>{const t=Fe(Xa);if(!t)throw new Error("useTriggerPopoverRootContext must be used within ComposerPrimitive.TriggerPopoverRoot");return t},el=()=>Fe(Xa),CC=()=>{const t=Fe(pp);if(!t)throw new Error("useTriggerPopoverAriaPublish must be used within ComposerPrimitive.TriggerPopoverRoot");return t},IC=()=>{const t=Za();return yn(t.subscribe,t.getTriggers,t.getTriggers)},kC=new Map,mp=()=>()=>{},Gc=()=>kC,EC=()=>{const t=el();return yn(t?t.subscribe:mp,t?t.getTriggers:Gc,t?t.getTriggers:Gc)},Kc=()=>null,AC=()=>{const t=el();return yn(t?t.subscribeAria:mp,t?t.getActiveAria:Kc,t?t.getActiveAria:Kc)};function Qc(){const t=R(4);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Set,t[0]=e):e=t[0];const n=X(e);let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{for(const l of n.current)l()},t[1]=r):r=t[1];const s=r;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=l=>(n.current.add(l),()=>{n.current.delete(l)}),t[2]=i):i=t[2];const o=i;let a;return t[3]===Symbol.for("react.memo_cache_sentinel")?(a={notify:s,subscribe:o},t[3]=a):a=t[3],a}const Yc=t=>{const e=R(21),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=new Map,e[0]=r):r=e[0];const s=X(r);let i;e[1]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[1]=i):i=e[1];const o=X(i),{notify:a,subscribe:l}=Qc();let c;e[2]!==a?(c=T=>{const{char:$}=T;if(s.current.has($))return RC;const L=new Map(s.current);L.set($,T),s.current=L,a();for(const j of o.current)j.added(T);return()=>{const j=new Map(s.current);j.delete($),s.current=j,a();for(const V of o.current)V.removed($)}},e[2]=a,e[3]=c):c=e[3];const u=c;let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=()=>s.current,e[4]=d):d=e[4];const f=d;let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=T=>(o.current.add(T),()=>{o.current.delete(T)}),e[5]=h):h=e[5];const p=h,m=X(null),y=X(null),{notify:g,subscribe:b}=Qc();let v;e[6]!==g?(v=(T,$)=>{if($===null){if(y.current!==T)return;m.current=null,y.current=null,g();return}const L=m.current;y.current===T&&L!==null&&L.popoverId===$.popoverId&&L.highlightedItemId===$.highlightedItemId||(m.current=$,y.current=T,g())},e[6]=g,e[7]=v):v=e[7];const w=v;let k;e[8]===Symbol.for("react.memo_cache_sentinel")?(k=()=>m.current,e[8]=k):k=e[8];const _=k;let A;e[9]!==u||e[10]!==l||e[11]!==b?(A={register:u,getTriggers:f,subscribe:l,subscribeLifecycle:p,getActiveAria:_,subscribeAria:b},e[9]=u,e[10]=l,e[11]=b,e[12]=A):A=e[12];const E=A;let D;e[13]!==w?(D={setActiveAria:w},e[13]=w,e[14]=D):D=e[14];const x=D;let M;e[15]!==x||e[16]!==n?(M=C.jsx(pp.Provider,{value:x,children:n}),e[15]=x,e[16]=n,e[17]=M):M=e[17];let P;return e[18]!==M||e[19]!==E?(P=C.jsx(Xa.Provider,{value:E,children:M}),e[18]=M,e[19]=E,e[20]=P):P=e[20],P},Ro=t=>{const e=R(4),{children:n}=t;if(Js()){let s;return e[0]!==n?(s=C.jsx(Yc,{children:n}),e[0]=n,e[1]=s):s=e[1],s}let r;return e[2]!==n?(r=C.jsx(xC,{children:C.jsx(Yc,{children:n})}),e[2]=n,e[3]=r):r=e[3],r};Ro.displayName="ComposerPrimitive.TriggerPopoverRoot";function RC(){}const Jc=/\s/u;function MC(t,e,n,r){if(r===null)return null;const{query:s,offset:i,endOffset:o}=r;return i<0||i+e.length>n||!t.startsWith(e,i)||o<i+e.length||o>t.length?null:{query:s,offset:i,endOffset:o}}function PC(t,e,n,r){if(r)return MC(t,e,n,r(t,e,n));const s=t.slice(0,n);for(let i=s.length-1;i>=0;i--){const o=s[i];if(Jc.test(o))return null;if(s.startsWith(e,i)){if(i>0&&!Jc.test(s[i-1]))continue;return{query:s.slice(i+e.length),offset:i,endOffset:n}}}return null}const DC=t=>{const e=R(8),{text:n,triggerChar:r,matcher:s}=t,[i,o]=ie(n.length),a=Math.min(i,n.length);let l;e[0]!==s||e[1]!==a||e[2]!==n||e[3]!==r?(l=PC(n,r,a,s),e[0]=s,e[1]=a,e[2]=n,e[3]=r,e[4]=l):l=e[4];const c=l,u=c?.query??"";let d;return e[5]!==u||e[6]!==c?(d={trigger:c,query:u,setCursorPosition:o},e[5]=u,e[6]=c,e[7]=d):d=e[7],d},OC=ce(DC);function LC(t){return"type"in t}const FC=t=>{const e=R(22),{navigableList:n,isSearchMode:r,activeCategoryId:s,query:i,popoverId:o,open:a,selectItem:l,selectCategory:c,goBack:u,close:d}=t,[f,h]=ie(0);let p;e[0]!==s||e[1]!==r||e[2]!==n?(p={navigableList:n,isSearchMode:r,activeCategoryId:s},e[0]=s,e[1]=r,e[2]=n,e[3]=p):p=e[3];const[m,y]=ie(p);(m.navigableList!==n||m.isSearchMode!==r||m.activeCategoryId!==s)&&(y({navigableList:n,isSearchMode:r,activeCategoryId:s}),h(0));let g;e[4]!==f||e[5]!==n.length?(g=E=>{E<0||E>=n.length||E!==f&&h(E)},e[4]=f,e[5]=n.length,e[6]=g):g=e[6];const b=nt(g);let v;e[7]!==s||e[8]!==d||e[9]!==u||e[10]!==f||e[11]!==n||e[12]!==a||e[13]!==i||e[14]!==c||e[15]!==l?(v=E=>{if(!a)return!1;switch(E.key){case"ArrowDown":return E.preventDefault(),h(D=>{const x=n.length;return x===0?0:D<x-1?D+1:0}),!0;case"ArrowUp":return E.preventDefault(),h(D=>{const x=n.length;return x===0?0:D>0?D-1:x-1}),!0;case"Enter":case"Tab":{if(E.shiftKey)return!1;E.preventDefault();const D=n[f];return D&&(LC(D)?l(D):c(D.id)),!0}case"Escape":return E.preventDefault(),d(),!0;case"Backspace":return s&&i===""?(E.preventDefault(),u(),!0):!1;default:return!1}},e[7]=s,e[8]=d,e[9]=u,e[10]=f,e[11]=n,e[12]=a,e[13]=i,e[14]=c,e[15]=l,e[16]=v):v=e[16];const w=nt(v),k=n[f],_=a&&k?`${o}-option-${k.id}`:void 0;let A;return e[17]!==w||e[18]!==b||e[19]!==f||e[20]!==_?(A={highlightedIndex:f,highlightedItemId:_,highlightIndex:b,handleKeyDown:w},e[17]=w,e[18]=b,e[19]=f,e[20]=_,e[21]=A):A=e[21],A},$C=ce(FC);function Ir(t,e){return e?t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e)||(t.description?.toLowerCase().includes(e)??!1):!0}const NC=t=>{const e=R(35),{adapter:n,query:r,open:s}=t,[i,o]=ie(null),[a,l]=ie(s);a!==s&&(l(s),s||o(null));let c;e:{if(!s||!n){let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T=[],e[0]=T):T=e[0],c=T;break e}let P;e[1]!==n?(P=n.categories(),e[1]=n,e[2]=P):P=e[2],c=P}const u=c,d=s?i:null;let f;e:{if(!d||!n){let T;e[3]===Symbol.for("react.memo_cache_sentinel")?(T=[],e[3]=T):T=e[3],f=T;break e}let P;e[4]!==n||e[5]!==d?(P=n.categoryItems(d),e[4]=n,e[5]=d,e[6]=P):P=e[6],f=P}const h=f;let p;e:{if(!s||!n||d){p=null;break e}if(!r&&u.length>0){p=null;break e}if(n.search){let T;e[7]!==n||e[8]!==r?(T=n.search(r),e[7]=n,e[8]=r,e[9]=T):T=e[9],p=T;break e}let P;if(e[10]!==n||e[11]!==u||e[12]!==r){P=[];const T=r.toLowerCase();for(const $ of u)for(const L of n.categoryItems($.id))Ir(L,T)&&P.push(L);e[10]=n,e[11]=u,e[12]=r,e[13]=P}else P=e[13];p=P}const m=p,y=m!==null;let g;e:{if(y){let T;e[14]===Symbol.for("react.memo_cache_sentinel")?(T=[],e[14]=T):T=e[14],g=T;break e}if(!r){g=u;break e}let P;if(e[15]!==u||e[16]!==r){const T=r.toLowerCase();P=u.filter($=>$.label.toLowerCase().includes(T)),e[15]=u,e[16]=r,e[17]=P}else P=e[17];g=P}const b=g;let v;e:{if(y){let T;e[18]!==m?(T=m??[],e[18]=m,e[19]=T):T=e[19],v=T;break e}if(!r){v=h;break e}let P;if(e[20]!==h||e[21]!==r){const T=r.toLowerCase();P=h.filter($=>Ir($,T)),e[20]=h,e[21]=r,e[22]=P}else P=e[22];v=P}const w=v;let k;e:{if(y){let P;e[23]!==m?(P=m??[],e[23]=m,e[24]=P):P=e[24],k=P;break e}if(d){k=w;break e}k=b}const _=k;let A;e[25]===Symbol.for("react.memo_cache_sentinel")?(A=P=>{o(P)},e[25]=A):A=e[25];const E=nt(A);let D;e[26]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{o(null)},e[26]=D):D=e[26];const x=nt(D);let M;return e[27]!==d||e[28]!==b||e[29]!==w||e[30]!==x||e[31]!==y||e[32]!==_||e[33]!==E?(M={categories:b,items:w,isSearchMode:y,activeCategoryId:d,navigableList:_,selectCategory:E,goBack:x},e[27]=d,e[28]=b,e[29]=w,e[30]=x,e[31]=y,e[32]=_,e[33]=E,e[34]=M):M=e[34],M},BC=ce(NC),jC=t=>{const e=R(15),{behavior:n,trigger:r,aui:s,setCursorPosition:i,onSelected:o}=t,a=X(null);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=m=>(a.current=m,()=>{a.current===m&&(a.current=null)}),e[0]=l):l=e[0];const c=nt(l);let u;e[1]!==s||e[2]!==n||e[3]!==o||e[4]!==i||e[5]!==r?(u=m=>{if(!r||!n)return;const y=()=>{n.kind==="directive"&&n.onInserted?.(m)};if(a.current?.(m,y)){o();return}const g=s.composer.getState().text,b=g.slice(0,r.offset),v=g.slice(r.endOffset),w=()=>{const k=n.formatter.serialize(m);s.composer.setText(b+k+(v.startsWith(" ")?v:` ${v}`),{origin:"user"}),i(b.length+k.length+1)};n.kind==="directive"?(w(),n.onInserted?.(m)):(n.removeOnExecute?(s.composer.setText(b+(v.startsWith(" ")?v.slice(1):v),{origin:"user"}),i(b.length)):w(),n.onExecute(m)),o()},e[1]=s,e[2]=n,e[3]=o,e[4]=i,e[5]=r,e[6]=u):u=e[6];const d=nt(u);let f;e[7]!==o||e[8]!==i||e[9]!==r?(f=()=>{o(),r&&i(r.offset)},e[7]=o,e[8]=i,e[9]=r,e[10]=f):f=e[10];const h=nt(f);let p;return e[11]!==h||e[12]!==c||e[13]!==d?(p={selectItem:d,close:h,registerSelectItemOverride:c},e[11]=h,e[12]=c,e[13]=d,e[14]=p):p=e[14],p},zC=ce(jC),VC=t=>{const e=R(47),{adapter:n,text:r,triggerChar:s,matcher:i,behavior:o,aui:a,popoverId:l,isLoading:c}=t;let u;e[0]!==i||e[1]!==r||e[2]!==s?(u=OC({text:r,triggerChar:s,matcher:i}),e[0]=i,e[1]=r,e[2]=s,e[3]=u):u=e[3];const d=ze(u),f=d.trigger!==null&&n!==void 0&&o!==void 0;let h;e[4]!==n||e[5]!==d.query||e[6]!==f?(h=BC({adapter:n,query:d.query,open:f}),e[4]=n,e[5]=d.query,e[6]=f,e[7]=h):h=e[7];const p=ze(h);let m;e[8]!==p?(m=()=>{p.goBack()},e[8]=p,e[9]=m):m=e[9];const y=nt(m);let g;e[10]!==a||e[11]!==o||e[12]!==d.setCursorPosition||e[13]!==d.trigger||e[14]!==y||e[15]!==s?(g=zC({behavior:o,trigger:d.trigger,aui:a,triggerChar:s,setCursorPosition:d.setCursorPosition,onSelected:y}),e[10]=a,e[11]=o,e[12]=d.setCursorPosition,e[13]=d.trigger,e[14]=y,e[15]=s,e[16]=g):g=e[16];const b=ze(g);let v;e[17]!==d.query||e[18]!==p.activeCategoryId||e[19]!==p.goBack||e[20]!==p.isSearchMode||e[21]!==p.navigableList||e[22]!==p.selectCategory||e[23]!==f||e[24]!==l||e[25]!==b.close||e[26]!==b.selectItem?(v=$C({navigableList:p.navigableList,isSearchMode:p.isSearchMode,activeCategoryId:p.activeCategoryId,query:d.query,popoverId:l,open:f,selectItem:b.selectItem,selectCategory:p.selectCategory,goBack:p.goBack,close:b.close}),e[17]=d.query,e[18]=p.activeCategoryId,e[19]=p.goBack,e[20]=p.isSearchMode,e[21]=p.navigableList,e[22]=p.selectCategory,e[23]=f,e[24]=l,e[25]=b.close,e[26]=b.selectItem,e[27]=v):v=e[27];const w=ze(v);let k;return e[28]!==d.query||e[29]!==d.setCursorPosition||e[30]!==c||e[31]!==w.handleKeyDown||e[32]!==w.highlightIndex||e[33]!==w.highlightedIndex||e[34]!==w.highlightedItemId||e[35]!==p.activeCategoryId||e[36]!==p.categories||e[37]!==p.goBack||e[38]!==p.isSearchMode||e[39]!==p.items||e[40]!==p.selectCategory||e[41]!==f||e[42]!==l||e[43]!==b.close||e[44]!==b.registerSelectItemOverride||e[45]!==b.selectItem?(k={open:f,query:d.query,activeCategoryId:p.activeCategoryId,categories:p.categories,items:p.items,highlightedIndex:w.highlightedIndex,isSearchMode:p.isSearchMode,isLoading:c,popoverId:l,highlightedItemId:w.highlightedItemId,selectCategory:p.selectCategory,goBack:p.goBack,selectItem:b.selectItem,close:b.close,highlightIndex:w.highlightIndex,handleKeyDown:w.handleKeyDown,setCursorPosition:d.setCursorPosition,registerSelectItemOverride:b.registerSelectItemOverride},e[28]=d.query,e[29]=d.setCursorPosition,e[30]=c,e[31]=w.handleKeyDown,e[32]=w.highlightIndex,e[33]=w.highlightedIndex,e[34]=w.highlightedItemId,e[35]=p.activeCategoryId,e[36]=p.categories,e[37]=p.goBack,e[38]=p.isSearchMode,e[39]=p.items,e[40]=p.selectCategory,e[41]=f,e[42]=l,e[43]=b.close,e[44]=b.registerSelectItemOverride,e[45]=b.selectItem,e[46]=k):k=e[46],k},UC=ce(VC),tl=ke(null),Qn=()=>{const t=Fe(tl);if(!t)throw new Error("useTriggerPopoverScopeContext must be used within ComposerPrimitive.TriggerPopover");return t},qC=()=>Fe(tl),gp=ke(null),yp=()=>{const t=Fe(gp);if(!t)throw new Error("TriggerPopover.Directive / TriggerPopover.Action must be rendered inside ComposerPrimitive.TriggerPopover");return t},bp=he((t,e)=>{const n=R(70);let r,s,i,o,a,l,c;n[0]!==t?({char:i,matcher:a,adapter:r,isLoading:c,"aria-label":s,children:o,...l}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i,n[4]=o,n[5]=a,n[6]=l,n[7]=c):(r=n[1],s=n[2],i=n[3],o=n[4],a=n[5],l=n[6],c=n[7]);const u=c===void 0?!1:c,d=Z(),f=N(HC),h=zy(),p=X(a);let m;n[8]!==a?(m=()=>{p.current=a},n[8]=a,n[9]=m):m=n[9],Q(m);let y;n[10]===Symbol.for("react.memo_cache_sentinel")?(y=()=>(G,se,we)=>p.current(G,se,we),n[10]=y):y=n[10];const[g]=ie(y),b=a!==void 0,v=X(null),[w,k]=ie(null),_=X(0);let A;n[11]!==i?(A=G=>(_.current=_.current+1,v.current=G,k(G),()=>{_.current=Math.max(0,_.current-1),v.current===G&&(v.current=null,k(null))}),n[11]=i,n[12]=A):A=n[12];const E=A;let D;n[13]!==E?(D={register:E},n[13]=E,n[14]=D):D=n[14];const x=D,M=w??void 0;let P;n[15]!==r||n[16]!==d||n[17]!==i||n[18]!==u||n[19]!==a||n[20]!==h||n[21]!==M||n[22]!==f?(P=UC({adapter:r,text:f,triggerChar:i,matcher:a,behavior:M,aui:d,popoverId:h,isLoading:u}),n[15]=r,n[16]=d,n[17]=i,n[18]=u,n[19]=a,n[20]=h,n[21]=M,n[22]=f,n[23]=P):P=n[23];const T=ze(P);let $;n[24]!==T?($=()=>T,n[24]=T,n[25]=$):$=n[25];const L=nt($),j=Za();let V;n[26]!==w||n[27]!==i||n[28]!==L||n[29]!==b||n[30]!==g||n[31]!==j?(V=()=>j.register({char:i,...b?{matcher:g}:{},...w?{behavior:w}:{},resource:L()}),n[26]=w,n[27]=i,n[28]=L,n[29]=b,n[30]=g,n[31]=j,n[32]=V):V=n[32];let q;n[33]!==w||n[34]!==i||n[35]!==b||n[36]!==g||n[37]!==j?(q=[j,i,b,g,w],n[33]=w,n[34]=i,n[35]=b,n[36]=g,n[37]=j,n[38]=q):q=n[38],Q(V,q);const U=Js();let S;n[39]!==L||n[40]!==U?(S=()=>{if(U)return U.register(L())},n[39]=L,n[40]=U,n[41]=S):S=n[41];let J;n[42]!==U?(J=[U],n[42]=U,n[43]=J):J=n[43],Q(S,J);const ee=w!==null&&T.open,I=CC();let de,W;n[44]!==I||n[45]!==i||n[46]!==ee?(de=()=>{if(ee)return()=>{I.setActiveAria(i,null)}},W=[I,i,ee],n[44]=I,n[45]=i,n[46]=ee,n[47]=de,n[48]=W):(de=n[47],W=n[48]),Q(de,W);let K,le;n[49]!==I||n[50]!==i||n[51]!==ee||n[52]!==h||n[53]!==T.highlightedItemId?(K=()=>{ee&&I.setActiveAria(i,{popoverId:h,highlightedItemId:T.highlightedItemId})},le=[I,i,h,ee,T.highlightedItemId],n[49]=I,n[50]=i,n[51]=ee,n[52]=h,n[53]=T.highlightedItemId,n[54]=K,n[55]=le):(K=n[54],le=n[55]),Q(K,le);let te;n[56]!==s||n[57]!==o||n[58]!==e||n[59]!==ee||n[60]!==h||n[61]!==l||n[62]!==T.highlightedItemId?(te=ee?C.jsx(ve.div,{role:"listbox",id:h,"aria-label":s??"Suggestions","aria-activedescendant":T.highlightedItemId,"data-state":"open",...l,ref:e,children:o}):o,n[56]=s,n[57]=o,n[58]=e,n[59]=ee,n[60]=h,n[61]=l,n[62]=T.highlightedItemId,n[63]=te):te=n[63];let fe;n[64]!==T||n[65]!==te?(fe=C.jsx(tl.Provider,{value:T,children:te}),n[64]=T,n[65]=te,n[66]=fe):fe=n[66];let O;return n[67]!==x||n[68]!==fe?(O=C.jsx(gp.Provider,{value:x,children:fe}),n[67]=x,n[68]=fe,n[69]=O):O=n[69],O});bp.displayName="ComposerPrimitive.TriggerPopover";function HC(t){return t.composer.text}const _p=()=>{const t=R(2),{disabled:e,send:n}=q0();let r;t[0]!==n?(r=()=>n(),t[0]=n,t[1]=r):r=t[1];const s=r;return e?null:s},WC=$e("ComposerPrimitive.Send",_p),vp=ke(null),GC=()=>Fe(vp),wp="[contenteditable]:not([contenteditable='false'])",xp=`textarea:not(:disabled), ${wp}`,KC=["a","audio[controls]","button","details","embed","iframe","input","label","select","summary","textarea","video[controls]",wp,"[tabindex]"].join(", "),QC=Uy.startsWith("18."),Sp=he((t,e)=>{const n=R(27);let r,s,i,o,a;n[0]!==t?({onSubmit:o,onMouseDown:i,compact:r,inert:s,...a}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i,n[4]=o,n[5]=a):(r=n[1],s=n[2],i=n[3],o=n[4],a=n[5]);const l=_p(),c=N(YC),[u,d]=ie(!1);let f;n[6]===Symbol.for("react.memo_cache_sentinel")?(f={setMultiline:d},n[6]=f):f=n[6];const h=f;let p;n[7]!==r?(p=M=>r?M.composer.attachments.length===0&&M.composer.quote==null&&M.composer.queue.length===0&&M.composer.dictation==null&&!M.composer.text.includes(`
|
|
11
|
+
`):!1,n[7]=r,n[8]=p):p=n[8];const m=N(p)&&!u,y=QC&&typeof s=="boolean"?s?"":void 0:s;let g;n[9]!==l?(g=M=>{M.preventDefault(),l&&l()},n[9]=l,n[10]=g):g=n[10];const b=g,v=JC,w=r?h:null,k=y,_=m?"":void 0;let A;n[11]!==b||n[12]!==o?(A=_e(o,b),n[11]=b,n[12]=o,n[13]=A):A=n[13];let E;n[14]!==i?(E=_e(i,v),n[14]=i,n[15]=E):E=n[15];let D;n[16]!==c||n[17]!==e||n[18]!==a||n[19]!==k||n[20]!==_||n[21]!==A||n[22]!==E?(D=C.jsx(ve.form,{...a,inert:k,"data-aui-composer-type":c,"data-compact":_,ref:e,onSubmit:A,onMouseDown:E}),n[16]=c,n[17]=e,n[18]=a,n[19]=k,n[20]=_,n[21]=A,n[22]=E,n[23]=D):D=n[23];let x;return n[24]!==w||n[25]!==D?(x=C.jsx(vp.Provider,{value:w,children:D}),n[24]=w,n[25]=D,n[26]=x):x=n[26],x});Sp.displayName="ComposerPrimitive.Root";function YC(t){return t.composer.type}function JC(t){if(t.button!==0)return;const e=t.target;if(!(e instanceof Element)||!t.currentTarget.contains(e))return;const n=e.closest(KC);if(n&&t.currentTarget.contains(n))return;const r=t.currentTarget.querySelector(xp);r&&(t.preventDefault(),r.focus())}const Tp=t=>{const e=R(4),n=Ys(t),r=Ht(XC);let s,i;e[0]!==n||e[1]!==r?(s=()=>r(n),i=[r,n],e[0]=n,e[1]=r,e[2]=s,e[3]=i):(s=e[2],i=e[3]),Q(s,i)};function XC(t){return t.onScrollToBottom}const ZC=()=>!1,eI=()=>{},Cp=t=>{const e=R(4);let n;e[0]!==t?(n=i=>{if(typeof window>"u"||t===null||!window.matchMedia)return eI;const o=window.matchMedia(t);return o.addEventListener("change",i),()=>o.removeEventListener("change",i)},e[0]=t,e[1]=n):n=e[1];const r=n;let s;return e[2]!==t?(s=()=>typeof window>"u"||t===null||!window.matchMedia?!1:window.matchMedia(t).matches,e[2]=t,e[3]=s):s=e[3],yn(r,s,ZC)},Ip=ke(void 0),kp=()=>Fe(Ip),Xc="[data-aui-composer-type]",Zc="[data-aui-thread-root]",Ep=t=>{const e=R(4),n=Z(),r=kp();let s;return e[0]!==n.composer||e[1]!==t||e[2]!==r?(s=i=>{const o=r?.current,a=i?.ownerDocument,l=a?.activeElement,c=i?.closest(Xc),u=n.composer.getState().type==="edit"&&o&&l&&c?.getAttribute("data-aui-composer-type")==="edit"&&c.contains(l)&&c.closest(Zc)===o,d=u?Array.from(o.querySelectorAll(xp)).filter(f=>f.closest(Zc)===o&&f.closest(Xc)?.getAttribute("data-aui-composer-type")==="thread"):[];if(t(),!(!a||!l||!u)&&!(a.activeElement!==l&&a.activeElement!==a.body)){for(const f of d)if(!(!f.isConnected||f.closest("[hidden], [inert]"))&&(f.focus({preventScroll:!0}),a.activeElement!==l&&a.activeElement!==a.body))break}},e[0]=n.composer,e[1]=t,e[2]=r,e[3]=s):s=e[3],s},tI=()=>{const t=R(2),e=kp();let n;return t[0]!==e?(n=r=>{if(!r)return!1;const s=r.ownerDocument,i=s.activeElement;if(!i||i===s.body)return!0;if(i===r)return!1;if(r.closest("[data-aui-composer-type]")?.contains(i))return!0;const o=e?.current??null;return o!==null&&o.contains(i)&&i.closest("[data-aui-thread-root]")===o},t[0]=e,t[1]=n):n=t[1],n};function nI(){return N(rI)}function rI(t){return t.composer.isEditing?t.composer.text:""}function sI(t){return!!N(iI)||!!t}function iI(t){return t.thread.isDisabled||t.composer.dictation?.inputDisabled}function oI(){const t=R(4),e=AC();if(!e){let r;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0],r}let n;return t[1]!==e.highlightedItemId||t[2]!==e.popoverId?(n={"aria-controls":e.popoverId,"aria-haspopup":"listbox","aria-activedescendant":e.highlightedItemId},t[1]=e.highlightedItemId,t[2]=e.popoverId,t[3]=n):n=t[3],n}function Mo(){return Mo=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},Mo.apply(null,arguments)}function aI(t,e){if(t==null)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(e.indexOf(r)!==-1)continue;n[r]=t[r]}return n}var lI=H.useLayoutEffect,cI=function(e){var n=et.useRef(e);return lI(function(){n.current=e}),n},eu=function(e,n){if(typeof e=="function"){e(n);return}e.current=n},uI=function(e,n){var r=et.useRef();return et.useCallback(function(s){e.current=s,r.current&&eu(r.current,null),r.current=n,n&&eu(n,s)},[n])},tu={"min-height":"0","max-height":"none",height:"0",visibility:"hidden",overflow:"hidden",position:"absolute","z-index":"-1000",top:"0",right:"0",display:"block"},dI=function(e){Object.keys(tu).forEach(function(n){e.style.setProperty(n,tu[n],"important")})},nu=dI,Ae=null,ru=function(e,n){var r=e.scrollHeight;return n.sizingStyle.boxSizing==="border-box"?r+n.borderSize:r-n.paddingSize};function hI(t,e,n,r){n===void 0&&(n=1),r===void 0&&(r=1/0),Ae||(Ae=document.createElement("textarea"),Ae.setAttribute("tabindex","-1"),Ae.setAttribute("aria-hidden","true"),nu(Ae)),Ae.parentNode===null&&document.body.appendChild(Ae);var s=t.paddingSize,i=t.borderSize,o=t.sizingStyle,a=o.boxSizing;Object.keys(o).forEach(function(f){var h=f;Ae.style[h]=o[h]}),nu(Ae),Ae.value=e;var l=ru(Ae,t);Ae.value=e,l=ru(Ae,t),Ae.value="x";var c=Ae.scrollHeight-s,u=c*n;a==="border-box"&&(u=u+s+i),l=Math.max(u,l);var d=c*r;return a==="border-box"&&(d=d+s+i),l=Math.min(d,l),[l,c]}var su=function(){},fI=function(e,n){return e.reduce(function(r,s){return r[s]=n[s],r},{})},pI=["borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","boxSizing","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textRendering","textTransform","width","wordBreak","wordSpacing","scrollbarGutter"],mI=!!document.documentElement.currentStyle,gI=function(e){var n=window.getComputedStyle(e);if(n===null)return null;var r=fI(pI,n),s=r.boxSizing;if(s==="")return null;mI&&s==="border-box"&&(r.width=parseFloat(r.width)+parseFloat(r.borderRightWidth)+parseFloat(r.borderLeftWidth)+parseFloat(r.paddingRight)+parseFloat(r.paddingLeft)+"px");var i=parseFloat(r.paddingBottom)+parseFloat(r.paddingTop),o=parseFloat(r.borderBottomWidth)+parseFloat(r.borderTopWidth);return{sizingStyle:r,paddingSize:i,borderSize:o}},yI=gI;function nl(t,e,n){var r=cI(n);H.useLayoutEffect(function(){var s=function(o){return r.current(o)};if(t)return t.addEventListener(e,s),function(){return t.removeEventListener(e,s)}},[])}var bI=function(e,n){nl(document.body,"reset",function(r){e.current.form===r.target&&n(r)})},_I=function(e){nl(window,"resize",e)},vI=function(e){nl(document.fonts,"loadingdone",e)},wI=["cacheMeasurements","maxRows","minRows","onChange","onHeightChange"],xI=function(e,n){var r=e.cacheMeasurements,s=e.maxRows,i=e.minRows,o=e.onChange,a=o===void 0?su:o,l=e.onHeightChange,c=l===void 0?su:l,u=aI(e,wI),d=u.value!==void 0,f=H.useRef(null),h=uI(f,n),p=H.useRef(0),m=H.useRef(),y=function(){var v=f.current,w=r&&m.current?m.current:yI(v);if(w){m.current=w;var k=hI(w,v.value||v.placeholder||"x",i,s),_=k[0],A=k[1];p.current!==_&&(p.current=_,v.style.setProperty("height",_+"px","important"),c(_,{rowHeight:A}))}},g=function(v){d||y(),a(v)};return H.useLayoutEffect(y),bI(f,function(){if(!d){var b=f.current.value;requestAnimationFrame(function(){var v=f.current;v&&b!==v.value&&y()})}}),_I(y),vI(y),H.createElement("textarea",Mo({},u,{onChange:g,ref:h}))},SI=H.forwardRef(xI);const TI="(pointer: coarse) and (not (any-pointer: fine))",Ap=he(({autoFocus:t=!1,asChild:e,render:n,disabled:r,onChange:s,onKeyDown:i,onPaste:o,onSelect:a,submitOnEnter:l,submitMode:c,cancelOnEscape:u=!0,unstable_focusOnRunStart:d=!0,unstable_focusOnScrollToBottom:f=!0,unstable_focusOnThreadSwitched:h=!0,unstable_insertNewlineOnTouchEnter:p=!1,addAttachmentOnPaste:m=!0,onHeightChange:y,...g},b)=>{const v=Z(),w=tI(),k=Js(),_=GC(),A=c??(l===!1?"none":"enter"),E=Cp(p?TI:null),D=p&&E&&A==="enter"?"none":A,x=nI(),M=sI(r),P=X(null),T=Ep(mt(()=>v.composer.cancel(),[v])),$=Wt(b,P),L=X(!1);ip(W=>{if(P.current?.contains(W.target)&&!bo(W)){if(k){for(const K of k.getPlugins())if(K.handleKeyDown(W))return}u&&v.composer.getState().canCancel&&(T(P.current),W.preventDefault())}});const j=W=>{if(!M&&!bo(W.nativeEvent)){if(k){for(const K of k.getPlugins())if(K.handleKeyDown(W))return}if(W.key==="Enter"){const K=v.thread.getState(),le=K.capabilities.queue;if(W.shiftKey&&(W.ctrlKey||W.metaKey)&&le&&A!=="none"&&v.composer.getState().canSend){W.preventDefault(),v.composer.send({steer:!0});return}if(W.shiftKey||K.isRunning&&!le&&K.voice===void 0)return;let te=!1;D==="ctrlEnter"?te=W.ctrlKey||W.metaKey:D==="enter"&&(te=!0),te&&(W.preventDefault(),P.current?.closest("form")?.requestSubmit())}}},V=async W=>{if(!m)return;const K=v.thread.getState().capabilities,le=Array.from(W.clipboardData?.files||[]);K.attachments&&le.length>0&&(W.preventDefault(),await Promise.all(le.map(async te=>{try{await v.composer.addAttachment(te)}catch{}})))},q=(W,K)=>{if(y?.(W,K),!_)return;const le=P.current;if(!le||le.value==="")return;const te=getComputedStyle(le),fe=te.boxSizing==="border-box"?W-parseFloat(te.paddingTop)-parseFloat(te.paddingBottom)-parseFloat(te.borderTopWidth)-parseFloat(te.borderBottomWidth):W;Math.round(fe/K.rowHeight)>1&&_.setMultiline(!0)},U=t&&!M,S=mt(()=>{const W=P.current;!W||!U||(W.focus({preventScroll:!0}),W.setSelectionRange(W.value.length,W.value.length))},[U]),J=mt(()=>{const W=P.current;!W||!w(W)||S()},[S,w]);Q(()=>S(),[S]),Tp(()=>{v.composer.getState().type==="thread"&&f&&S()}),Q(()=>{if(!(v.composer.getState().type!=="thread"||!d))return v.on("thread.runStart",J)},[d,J,v]),Q(()=>{if(!(v.composer.getState().type!=="thread"||!h||!v.optional.threads))return v.on("threads.selectionChanged",S)},[h,S,v]),Q(()=>{x===""&&_?.setMultiline(!1)},[x,_]);const ee=oI(),I={name:"input",value:x,...g,...ee,ref:$,disabled:M,onChange:_e(s,W=>{if(!v.composer.getState().isEditing)return;const K=W.nativeEvent.isComposing===!0;L.current&&!K&&(L.current=!1);const le=K||L.current;if(Ul(()=>{v.composer.setText(W.target.value,{origin:"user"})}),le)return;const te=W.target.selectionStart??W.target.value.length;if(k)for(const fe of k.getPlugins())fe.setCursorPosition(te)}),onKeyDown:_e(i,j),onCompositionStart:_e(g.onCompositionStart,()=>{L.current=!0}),onCompositionEnd:_e(g.onCompositionEnd,W=>{if(L.current=!1,!v.composer.getState().isEditing)return;const K=W.target;Ul(()=>{v.composer.setText(K.value,{origin:"user"})});const le=K.selectionStart??K.value.length;if(k)for(const te of k.getPlugins())te.setCursorPosition(le)}),onSelect:_e(a,W=>{if(L.current)return;const K=W.target,le=K.selectionStart??K.value.length;if(k)for(const te of k.getPlugins())te.setCursorPosition(le)}),onPaste:_e(o,V),..._?{onHeightChange:q}:y!==void 0?{onHeightChange:y}:{}};if(n&&Vs(n))return Ja(n,g.children,I);const de=e?Ka:SI;return C.jsx(de,{...I})});Ap.displayName="ComposerPrimitive.Input";const CI=()=>{const t=R(2),{disabled:e,resume:n}=H0();let r;t[0]!==n?(r=()=>n(),t[0]=n,t[1]=r):r=t[1];const s=r;return e?null:s},II=$e("ComposerPrimitive.Resume",CI),kI=()=>{const t=R(2),{disabled:e,cancel:n}=W0(),r=Ep(n);if(e)return null;let s;return t[0]!==r?(s=i=>r(i.detail===0?i.currentTarget:null),t[0]=r,t[1]=s):s=t[1],s},EI=$e("ComposerPrimitive.Cancel",kI),AI=t=>{const e=R(10);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const{multiple:r}=n,s=r===void 0?!0:r,{disabled:i,addAttachment:o}=Q0(),a=Z(),l=X(0);let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=()=>()=>{l.current=l.current+1},e[2]=c):c=e[2];let u;e[3]!==a.composer||e[4]!==a.optional.threadListItem?(u=[a.composer,a.optional.threadListItem],e[3]=a.composer,e[4]=a.optional.threadListItem,e[5]=u):u=e[5],ct(c,u);let d;e[6]!==o||e[7]!==a.composer||e[8]!==s?(d=()=>{const h=l.current,p=document.createElement("input");p.type="file",p.multiple=s,p.hidden=!0;const m=a.composer.getState().attachmentAccept;m!=="*"&&(p.accept=m),document.body.appendChild(p),p.onchange=async y=>{const g=y.target.files;if(!g)return;const b=Array.from(g,async v=>{try{if(l.current!==h)return;await o(v)}catch{}});document.body.removeChild(p),await Promise.all(b)},p.oncancel=()=>{(!p.files||p.files.length===0)&&document.body.removeChild(p)},p.click()},e[6]=o,e[7]=a.composer,e[8]=s,e[9]=d):d=e[9];const f=d;return i?null:f},RI=$e("ComposerPrimitive.AddAttachment",AI,["multiple"]),Rp=he(({disabled:t,asChild:e=!1,render:n,children:r,...s},i)=>{const[o,a]=ie(!1),l=Z(),c=N(g=>g.thread.isDisabled),u=t||c;Q(()=>{u&&a(!1)},[u]);const d=mt(g=>{if(g.dataTransfer.types.includes("Files")){if(g.preventDefault(),u||!l.thread.getState().capabilities.attachments){g.dataTransfer.dropEffect="none";return}a(!0)}},[u,l]),f=mt(g=>{if(g.dataTransfer.types.includes("Files")){if(g.preventDefault(),u||!l.thread.getState().capabilities.attachments){g.dataTransfer.dropEffect="none";return}o||a(!0)}},[u,o,l]),h=mt(g=>{if(u)return;g.preventDefault();const b=g.relatedTarget;b&&g.currentTarget.contains(b)||a(!1)},[u]),p=mt(async g=>{if(a(!1),!g.dataTransfer.types.includes("Files")||(g.preventDefault(),u))return;const b=Array.from(g.dataTransfer.files);!l.thread.getState().capabilities.attachments||b.length===0||await Promise.all(b.map(async v=>{try{await l.composer.addAttachment(v)}catch{}}))},[u,l]),m={...o&&!u?{"data-dragging":"true"}:null,...s,onDragEnterCapture:_e(s.onDragEnterCapture,d),onDragOverCapture:_e(s.onDragOverCapture,f),onDragLeaveCapture:_e(s.onDragLeaveCapture,h),onDropCapture:_e(s.onDropCapture,p),ref:i};if(n&&Vs(n))return Ja(n,r,m);const y=e?Ka:"div";return C.jsx(y,{...m,children:r})});Rp.displayName="ComposerPrimitive.AttachmentDropzone";const MI=()=>{const{disabled:t,startDictation:e}=G0();return t?null:e},PI=$e("ComposerPrimitive.Dictate",MI),DI=()=>{const t=R(2),e=Z(),n=N(LI);let r;t[0]!==e.composer?(r=()=>{e.composer.stopDictation()},t[0]=e.composer,t[1]=r):r=t[1];const s=r;return n?s:null},OI=$e("ComposerPrimitive.StopDictation",DI);function LI(t){return t.composer.dictation!=null}const Mp=he((t,e)=>{const n=R(7);let r,s;n[0]!==t?({children:r,...s}=t,n[0]=t,n[1]=r,n[2]=s):(r=n[1],s=n[2]);const i=N(FI);if(!i)return null;const o=r??i;let a;return n[3]!==e||n[4]!==s||n[5]!==o?(a=C.jsx(ve.span,{...s,ref:e,children:o}),n[3]=e,n[4]=s,n[5]=o,n[6]=a):a=n[6],a});Mp.displayName="ComposerPrimitive.DictationTranscript";function FI(t){return t.composer.dictation?.transcript}const Pp=he((t,e)=>{const n=R(3);if(!N($I))return null;let r;return n[0]!==e||n[1]!==t?(r=C.jsx(ve.div,{...t,ref:e}),n[0]=e,n[1]=t,n[2]=r):r=n[2],r});Pp.displayName="ComposerPrimitive.Quote";const Dp=he((t,e)=>{const n=R(7);let r,s;n[0]!==t?({children:r,...s}=t,n[0]=t,n[1]=r,n[2]=s):(r=n[1],s=n[2]);const i=N(NI);if(!i)return null;const o=r??i;let a;return n[3]!==e||n[4]!==s||n[5]!==o?(a=C.jsx(ve.span,{...s,ref:e,children:o}),n[3]=e,n[4]=s,n[5]=o,n[6]=a):a=n[6],a});Dp.displayName="ComposerPrimitive.QuoteText";const Op=he((t,e)=>{const n=R(12);let r,s;n[0]!==t?({onClick:r,...s}=t,n[0]=t,n[1]=r,n[2]=s):(r=n[1],s=n[2]);const i=Z();let o;n[3]!==i?(o=()=>{i.composer.setQuote(void 0)},n[3]=i,n[4]=o):o=n[4];const a=o;let l;n[5]!==a||n[6]!==r?(l=_e(r,a),n[5]=a,n[6]=r,n[7]=l):l=n[7];let c;return n[8]!==e||n[9]!==s||n[10]!==l?(c=C.jsx(ve.button,{type:"button",...s,ref:e,onClick:l}),n[8]=e,n[9]=s,n[10]=l,n[11]=c):c=n[11],c});Op.displayName="ComposerPrimitive.QuoteDismiss";function $I(t){return t.composer.quote}function NI(t){return t.composer.quote?.text}const Po=he((t,e)=>{const n=R(12);let r,s,i;n[0]!==t?({children:s,"aria-label":r,...i}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i):(r=n[1],s=n[2],i=n[3]);const{categories:o,activeCategoryId:a,isSearchMode:l,open:c}=Qn();if(!c||a||l)return null;const u=r??"Categories";let d;n[4]!==o||n[5]!==s?(d=s(o),n[4]=o,n[5]=s,n[6]=d):d=n[6];let f;return n[7]!==e||n[8]!==i||n[9]!==u||n[10]!==d?(f=C.jsx(ve.div,{role:"group","aria-label":u,...i,ref:e,children:d}),n[7]=e,n[8]=i,n[9]=u,n[10]=d,n[11]=f):f=n[11],f});Po.displayName="ComposerPrimitive.TriggerPopoverCategories";const Do=he((t,e)=>{const n=R(30);let r,s,i,o;n[0]!==t?({categoryId:r,onClick:s,onMouseMove:i,...o}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i,n[4]=o):(r=n[1],s=n[2],i=n[3],o=n[4]);const{selectCategory:a,highlightIndex:l,categories:c,highlightedIndex:u,activeCategoryId:d,isSearchMode:f,popoverId:h}=Qn();let p;n[5]!==r||n[6]!==a?(p=()=>{a(r)},n[5]=r,n[6]=a,n[7]=p):p=n[7];const m=p;let y;if(n[8]!==c||n[9]!==r){let x;n[11]!==r?(x=M=>M.id===r,n[11]=r,n[12]=x):x=n[12],y=c.findIndex(x),n[8]=c,n[9]=r,n[10]=y}else y=n[10];const g=y,b=!d&&!f&&g===u;let v;n[13]!==g||n[14]!==l?(v=()=>{l(g)},n[13]=g,n[14]=l,n[15]=v):v=n[15];const w=v,k=`${h}-option-${r}`,_=b?"":void 0;let A;n[16]!==m||n[17]!==s?(A=_e(s,m),n[16]=m,n[17]=s,n[18]=A):A=n[18];let E;n[19]!==w||n[20]!==i?(E=_e(i,w),n[19]=w,n[20]=i,n[21]=E):E=n[21];let D;return n[22]!==e||n[23]!==b||n[24]!==o||n[25]!==k||n[26]!==_||n[27]!==A||n[28]!==E?(D=C.jsx(ve.button,{type:"button",role:"option",id:k,"aria-selected":b,"data-highlighted":_,...o,ref:e,onClick:A,onMouseMove:E}),n[22]=e,n[23]=b,n[24]=o,n[25]=k,n[26]=_,n[27]=A,n[28]=E,n[29]=D):D=n[29],D});Do.displayName="ComposerPrimitive.TriggerPopoverCategoryItem";const Oo=he((t,e)=>{const n=R(12);let r,s,i;n[0]!==t?({children:s,"aria-label":r,...i}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i):(r=n[1],s=n[2],i=n[3]);const{items:o,activeCategoryId:a,isSearchMode:l,open:c}=Qn();if(!c||!a&&!l)return null;const u=r??"Items";let d;n[4]!==s||n[5]!==o?(d=s(o),n[4]=s,n[5]=o,n[6]=d):d=n[6];let f;return n[7]!==e||n[8]!==i||n[9]!==u||n[10]!==d?(f=C.jsx(ve.div,{role:"group","aria-label":u,...i,ref:e,children:d}),n[7]=e,n[8]=i,n[9]=u,n[10]=d,n[11]=f):f=n[11],f});Oo.displayName="ComposerPrimitive.TriggerPopoverItems";const Lo=he((t,e)=>{const n=R(30);let r,s,i,o,a;n[0]!==t?({item:s,index:r,onClick:i,onMouseMove:o,...a}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i,n[4]=o,n[5]=a):(r=n[1],s=n[2],i=n[3],o=n[4],a=n[5]);const{selectItem:l,highlightIndex:c,items:u,highlightedIndex:d,activeCategoryId:f,isSearchMode:h,popoverId:p}=Qn();let m;n[6]!==s||n[7]!==l?(m=()=>{l(s)},n[6]=s,n[7]=l,n[8]=m):m=n[8];const y=m;let g;n[9]!==r||n[10]!==s.id||n[11]!==u?(g=r??u.findIndex(M=>M.id===s.id),n[9]=r,n[10]=s.id,n[11]=u,n[12]=g):g=n[12];const b=g,v=(h||f!==null)&&b===d;let w;n[13]!==c||n[14]!==b?(w=()=>{c(b)},n[13]=c,n[14]=b,n[15]=w):w=n[15];const k=w,_=`${p}-option-${s.id}`,A=v?"":void 0;let E;n[16]!==y||n[17]!==i?(E=_e(i,y),n[16]=y,n[17]=i,n[18]=E):E=n[18];let D;n[19]!==k||n[20]!==o?(D=_e(o,k),n[19]=k,n[20]=o,n[21]=D):D=n[21];let x;return n[22]!==e||n[23]!==v||n[24]!==a||n[25]!==_||n[26]!==A||n[27]!==E||n[28]!==D?(x=C.jsx(ve.button,{type:"button",role:"option",id:_,"aria-selected":v,"data-highlighted":A,...a,ref:e,onClick:E,onMouseMove:D}),n[22]=e,n[23]=v,n[24]=a,n[25]=_,n[26]=A,n[27]=E,n[28]=D,n[29]=x):x=n[29],x});Lo.displayName="ComposerPrimitive.TriggerPopoverItem";const Fo=he((t,e)=>{const n=R(10);let r,s;n[0]!==t?({onClick:r,...s}=t,n[0]=t,n[1]=r,n[2]=s):(r=n[1],s=n[2]);const{activeCategoryId:i,isSearchMode:o,goBack:a,open:l}=Qn();if(!l||!i||o)return null;let c;n[3]!==a||n[4]!==r?(c=_e(r,a),n[3]=a,n[4]=r,n[5]=c):c=n[5];let u;return n[6]!==e||n[7]!==s||n[8]!==c?(u=C.jsx(ve.button,{type:"button",...s,ref:e,onClick:c}),n[6]=e,n[7]=s,n[8]=c,n[9]=u):u=n[9],u});Fo.displayName="ComposerPrimitive.TriggerPopoverBack";const Lp=t=>{const e=R(8),{formatter:n,onExecute:r,removeOnExecute:s}=t,{register:i}=yp(),o=X(r);let a,l;e[0]!==r?(a=()=>{o.current=r},l=[r],e[0]=r,e[1]=a,e[2]=l):(a=e[1],l=e[2]),ct(a,l);let c,u;return e[3]!==n||e[4]!==i||e[5]!==s?(c=()=>{const d={kind:"action",formatter:n??Fa,onExecute:f=>o.current(f),...s!==void 0?{removeOnExecute:s}:{}};return i(d)},u=[i,n,s],e[3]=n,e[4]=i,e[5]=s,e[6]=c,e[7]=u):(c=e[6],u=e[7]),Q(c,u),null};Lp.displayName="ComposerPrimitive.TriggerPopoverAction";const Fp=t=>{const e=R(7),{formatter:n,onInserted:r}=t,{register:s}=yp(),i=X(r);let o,a;e[0]!==r?(o=()=>{i.current=r},a=[r],e[0]=r,e[1]=o,e[2]=a):(o=e[1],a=e[2]),ct(o,a);let l,c;return e[3]!==n||e[4]!==s?(l=()=>s({kind:"directive",formatter:n??Fa,onInserted:u=>i.current?.(u)}),c=[s,n],e[3]=n,e[4]=s,e[5]=l,e[6]=c):(l=e[5],c=e[6]),Q(l,c),null};Fp.displayName="ComposerPrimitive.TriggerPopoverDirective";const iu=Object.assign(bp,{Directive:Fp,Action:Lp});var KO=Or({AddAttachment:()=>RI,AttachmentByIndex:()=>Mf,AttachmentDropzone:()=>Rp,Attachments:()=>Pf,Cancel:()=>EI,Dictate:()=>PI,DictationTranscript:()=>Mp,If:()=>$f,Input:()=>Ap,Queue:()=>Df,Quote:()=>Pp,QuoteDismiss:()=>Op,QuoteText:()=>Dp,Resume:()=>II,Root:()=>Sp,Send:()=>WC,StopDictation:()=>OI,TriggerPopover:()=>iu,TriggerPopoverBack:()=>Fo,TriggerPopoverCategories:()=>Po,TriggerPopoverCategoryItem:()=>Do,TriggerPopoverItem:()=>Lo,TriggerPopoverItems:()=>Oo,TriggerPopoverRoot:()=>Ro,Unstable_TriggerPopover:()=>iu,Unstable_TriggerPopoverBack:()=>Fo,Unstable_TriggerPopoverCategories:()=>Po,Unstable_TriggerPopoverCategoryItem:()=>Do,Unstable_TriggerPopoverItem:()=>Lo,Unstable_TriggerPopoverItems:()=>Oo,Unstable_TriggerPopoverRoot:()=>Ro,unstable_useTriggerPopoverRootContext:()=>Za,unstable_useTriggerPopoverRootContextOptional:()=>el,unstable_useTriggerPopoverScopeContext:()=>Qn,unstable_useTriggerPopoverScopeContextOptional:()=>qC,unstable_useTriggerPopoverTriggers:()=>IC,unstable_useTriggerPopoverTriggersOptional:()=>EC});const BI=Object.freeze({type:"complete"}),jI=Object.freeze({type:"text",text:"",status:BI}),$p=()=>N(zI);function zI(t){return t.part.type!=="text"&&t.part.type!=="reasoning"?jI:t.part}const Np=ke(null),VI=t=>({useSmoothStatus:Uf(()=>t)}),UI=t=>{const e=R(6),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={optional:!0},e[0]=r):r=e[0];const s=Bp(r),i=Z();let o;e[1]!==i.part?(o=()=>VI(i.part.getState().status),e[1]=i.part,e[2]=o):o=e[2];const[a]=ie(o);if(s)return n;let l;return e[3]!==n||e[4]!==a?(l=C.jsx(Np.Provider,{value:a,children:n}),e[3]=n,e[4]=a,e[5]=l):l=e[5],l},qI=t=>{const e=he((n,r)=>{const s=R(3),i=n;let o;return s[0]!==r||s[1]!==i?(o=C.jsx(UI,{children:C.jsx(t,{...i,ref:r})}),s[0]=r,s[1]=i,s[2]=o):o=s[2],o});return e.displayName=t.displayName,e};function Bp(t){const e=Fe(Np);if(!t?.optional&&!e)throw new Error("This component must be used within a SmoothContextProvider.");return e}const{useSmoothStatus:HI,useSmoothStatusStore:WI}=jf(Bp,"useSmoothStatus"),jp=250,zp=5;var GI=class{animationFrameId=null;lastUpdateTime=0;lastCommitTime=-1/0;targetText="";drainMs=jp;maxCharIntervalMs=zp;maxCharsPerFrame=1/0;minCommitMs=0;currentText;setText;constructor(t,e){this.currentText=t,this.setText=e}start(){this.animationFrameId===null&&(this.lastUpdateTime=performance.now(),this.animate())}stop(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}animate=()=>{const t=performance.now();let e=t-this.lastUpdateTime;const n=this.targetText.length-this.currentText.length,r=Math.min(this.maxCharIntervalMs,this.drainMs/n),s=Math.min(n,this.maxCharsPerFrame);let i=0;for(;e>=r&&i<s;)i++,e-=r;i===s&&s===this.maxCharsPerFrame&&(e=0),i!==n?this.animationFrameId=requestAnimationFrame(this.animate):this.animationFrameId=null,i!==0&&(this.currentText=this.targetText.slice(0,this.currentText.length+i),this.lastUpdateTime=t-e,(i===n||t-this.lastCommitTime>=this.minCommitMs)&&(this.lastCommitTime=t,this.setText(this.currentText)))}};const Mi=Object.freeze({type:"running"}),es=(t,e)=>t!==void 0&&t>0?t:e,Vp=(t,e=!1)=>{const{text:n}=t,r=Cp("(prefers-reduced-motion: reduce)"),s=typeof e=="object"&&e!==null?e:void 0,i=e!==!1&&e!==null&&!r,o=es(s?.drainMs,jp),a=es(s?.maxCharIntervalMs,zp),l=es(s?.maxCharsPerFrame,1/0),c=es(s?.minCommitMs,0),[u,d]=ie(t.status.type==="running"?"":n),f=Z(),h=N(()=>f.part),[p,m]=ie(h);(h!==p||!n.startsWith(u))&&(m(h),d(t.status.type==="running"?"":n));const y=WI({optional:!0}),g=Ys(_=>{if(d(_),y){const A=u!==_||t.status.type==="running"?Mi:t.status;ko(y).setState(A,!0)}});Q(()=>{if(y){const _=i&&(u!==n||t.status.type==="running")?Mi:t.status;ko(y).setState(_,!0)}},[y,i,n,u,t.status]);const[b]=ie(()=>new GI(u,g)),[v,w]=ie(i);i!==v&&(w(i),i&&h===p&&n.startsWith(b.currentText)&&d(b.currentText)),Q(()=>{b.drainMs=o,b.maxCharIntervalMs=a,b.maxCharsPerFrame=l,b.minCommitMs=c},[b,o,a,l,c]);const k=X(h);return Q(()=>{const _=k.current!==h;if(k.current=h,!i){b.stop(),b.currentText=n,b.targetText=n,b.lastCommitTime=-1/0;return}if(_||!n.startsWith(b.targetText)){t.status.type==="running"?(b.currentText="",b.targetText=n,b.lastCommitTime=-1/0,b.start()):(b.currentText=n,b.targetText=n,b.stop(),g(n));return}if(b.targetText=n,t.status.type!=="running"){if(b.currentText===""){b.currentText=n,b.stop(),g(n);return}b.start();return}b.start()},[b,i,n,t.status.type,h,g]),Q(()=>()=>{b.stop()},[b]),ye(()=>i?{...t,text:u,status:n===u?t.status:Mi}:t,[i,u,t,n])},KI=Object.freeze({type:"complete"}),QI=Object.freeze({type:"image",image:"",status:KI}),YI=()=>N(JI);function JI(t){return t.part.type!=="image"?QI:t.part}const rl=he(({smooth:t=!0,component:e=ve.span,render:n,...r},s)=>{const{text:i,status:o}=Vp($p(),t),a={"data-status":o.type,...r,ref:s};return n&&Vs(n)?Ja(n,i,a):C.jsx(e,{...a,children:i})});rl.displayName="MessagePartPrimitive.Text";const sl=he((t,e)=>{const n=R(4),{image:r}=YI();let s;return n[0]!==e||n[1]!==r||n[2]!==t?(s=C.jsx(ve.img,{src:r,...t,ref:e}),n[0]=e,n[1]=r,n[2]=t,n[3]=s):s=n[3],s});sl.displayName="MessagePartPrimitive.Image";const Yn=t=>{const e=R(2),n=X(void 0);let r;return e[0]!==t?(r=s=>{n.current&&(n.current(),n.current=void 0),s&&(n.current=t(s))},e[0]=t,e[1]=r):r=e[1],r},ou=(t,e)=>{const n=t.trim().match(/^(\d+(?:\.\d+)?|\.\d+)(em|px|rem)$/);if(!n)return Number.POSITIVE_INFINITY;const r=Number(n[1]),s=n[2];return s==="px"?r:s==="em"?r*(parseFloat(getComputedStyle(e).fontSize)||16):s==="rem"?r*(parseFloat(getComputedStyle(document.documentElement).fontSize)||16):Number.POSITIVE_INFINITY},XI=t=>t.dataset.messageId,ZI=()=>{const t=document.createElement("div");return t.dataset.auiTopAnchorReserve="",t.style.height="0px",t.style.flexShrink="0",t.style.pointerEvents="none",t.setAttribute("aria-hidden","true"),t},Pi=(t,e)=>{const n=`${e}px`;return t.style.height!==n?(t.style.height=n,!0):!1},au=t=>{const e=window.devicePixelRatio||1;return Math.round(t*e)/e},Up=()=>{const t=R(4),e=Z();let n;t[0]!==e.message?(n=()=>e.message,t[0]=e.message,t[1]=n):n=t[1];const r=N(n);let s;return t[2]!==r?(s=i=>{let o=!0;const a=()=>{r.setIsHovering(!0)},l=()=>{r.setIsHovering(!1)};return i.addEventListener("mouseenter",a),i.addEventListener("mouseleave",l),i.matches(":hover")&&queueMicrotask(()=>{o&&r.setIsHovering(!0)}),()=>{o=!1,i.removeEventListener("mouseenter",a),i.removeEventListener("mouseleave",l),r.setIsHovering(!1)}},t[2]=r,t[3]=s):s=t[3],Yn(s)},ek=()=>{const t=R(2),e=Ht(ok);let n;return t[0]!==e?(n=r=>r.message.role==="user"&&r.message.index>0&&r.message.index===r.thread.messages.length-2&&r.thread.messages.at(-1)?.role==="assistant"&&(r.message.id===e||r.thread.isRunning),t[0]=e,t[1]=n):n=t[1],N(n)},tk=()=>{const t=R(2),e=Ht(ak);let n;return t[0]!==e?(n=r=>r.message.isLast&&r.message.role==="assistant"&&r.message.index>=1&&r.thread.messages.at(r.message.index-1)?.role==="user"&&(r.message.id===e||r.thread.isRunning),t[0]=e,t[1]=n):n=t[1],N(n)},nk=(t,e)=>{const n=R(3);let r;return n[0]!==t||n[1]!==e?(r=s=>{if(t)return e.getState().registerAnchorElement(s)},n[0]=t,n[1]=e,n[2]=r):r=n[2],Yn(r)},rk=t=>{const e=R(3),{active:n,threadViewportStore:r}=t;let s;return e[0]!==n||e[1]!==r?(s=i=>{if(!n)return;const o=r.getState(),a=o.topAnchorMessageClamp;return o.registerAnchorTargetElement(i,{tallerThan:ou(a.tallerThan,i),visibleHeight:ou(a.visibleHeight,i)})},e[0]=n,e[1]=r,e[2]=s):s=e[2],Yn(s)},sk=t=>{const e=R(7);let n,r;e[0]!==t?({forwardedRef:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);const s=Up(),i=Wt(n,s),o=N(lk);let a;return e[3]!==o||e[4]!==r||e[5]!==i?(a=C.jsx(ve.div,{...r,ref:i,"data-message-id":o}),e[3]=o,e[4]=r,e[5]=i,e[6]=a):a=e[6],a},ik=t=>{const e=R(13);let n,r,s;e[0]!==t?({forwardedRef:n,threadViewportStore:s,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=s):(n=e[1],r=e[2],s=e[3]);const i=Up(),o=ek(),a=tk(),l=nk(o,s);let c;e[4]!==a||e[5]!==s?(c={active:a,threadViewportStore:s},e[4]=a,e[5]=s,e[6]=c):c=e[6];const u=rk(c),d=Wt(n,i,l,u),f=N(ck),h=o?"":void 0,p=a?"":void 0;let m;return e[7]!==f||e[8]!==r||e[9]!==d||e[10]!==h||e[11]!==p?(m=C.jsx(ve.div,{...r,ref:d,"data-message-id":f,"data-aui-top-anchor-user":h,"data-aui-top-anchor-target":p}),e[7]=f,e[8]=r,e[9]=d,e[10]=h,e[11]=p,e[12]=m):m=e[12],m},qp=he((t,e)=>{const n=R(7),r=xn();if(r.getState().turnAnchor==="top"){let i;return n[0]!==e||n[1]!==t||n[2]!==r?(i=C.jsx(ik,{...t,forwardedRef:e,threadViewportStore:r}),n[0]=e,n[1]=t,n[2]=r,n[3]=i):i=n[3],i}let s;return n[4]!==e||n[5]!==t?(s=C.jsx(sk,{...t,forwardedRef:e}),n[4]=e,n[5]=t,n[6]=s):s=n[6],s});qp.displayName="MessagePrimitive.Root";function ok(t){return t.topAnchorTurn?.anchorId}function ak(t){return t.topAnchorTurn?.targetId}function lk(t){return t.message.id}function ck(t){return t.message.id}const Di={...ft,Text:()=>C.jsxs("p",{style:{whiteSpace:"pre-line"},children:[C.jsx(rl,{}),C.jsx(qa,{children:C.jsx("span",{style:{fontFamily:"revert"},children:" ●"})})]}),Image:()=>C.jsx(sl,{})},$o=t=>{const e=R(10);if("children"in t){let a;return e[0]!==t.children?(a=C.jsx(Co,{children:t.children}),e[0]=t.children,e[1]=a):a=e[1],a}let n,r;e[2]!==t?({components:n,...r}=t,e[2]=t,e[3]=n,e[4]=r):(n=e[3],r=e[4]);let s;e[5]!==n?(s=n?{...n,Text:n.Text??Di.Text,Image:n.Image??Di.Image}:Di,e[5]=n,e[6]=s):s=e[6];const i=s;let o;return e[7]!==r||e[8]!==i?(o=C.jsx(Co,{components:i,...r}),e[7]=r,e[8]=i,e[9]=o):o=e[9],o};$o.displayName="MessagePrimitive.Parts";const uk=t=>{const e=R(12);let n;return e[0]!==t.assistant||e[1]!==t.copied||e[2]!==t.hasAttachments||e[3]!==t.hasBranches||e[4]!==t.hasContent||e[5]!==t.last||e[6]!==t.lastOrHover||e[7]!==t.speaking||e[8]!==t.submittedFeedback||e[9]!==t.system||e[10]!==t.user?(n=r=>{const{role:s,attachments:i,parts:o,branchCount:a,isLast:l,speech:c,isCopied:u,isHovering:d}=r.message;return!(t.hasBranches===!0&&a<2||t.user===!0&&s!=="user"||t.user===!1&&s==="user"||t.assistant===!0&&s!=="assistant"||t.assistant===!1&&s==="assistant"||t.system===!0&&s!=="system"||t.system===!1&&s==="system"||t.lastOrHover===!0&&!d&&!l||t.last!==void 0&&t.last!==l||t.copied===!0&&!u||t.copied===!1&&u||t.speaking===!0&&c==null||t.speaking===!1&&c!=null||t.hasAttachments===!0&&(s!=="user"||!i?.length)||t.hasAttachments===!1&&s==="user"&&i?.length||t.hasContent===!0&&o.length===0||t.hasContent===!1&&o.length>0||t.submittedFeedback!==void 0&&(r.message.metadata.submittedFeedback?.type??null)!==t.submittedFeedback)},e[0]=t.assistant,e[1]=t.copied,e[2]=t.hasAttachments,e[3]=t.hasBranches,e[4]=t.hasContent,e[5]=t.last,e[6]=t.lastOrHover,e[7]=t.speaking,e[8]=t.submittedFeedback,e[9]=t.system,e[10]=t.user,e[11]=n):n=e[11],N(n)},Hp=t=>{const e=R(3);let n,r;return e[0]!==t?({children:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),uk(r)?n:null};Hp.displayName="MessagePrimitive.If";const Wp=t=>{const{children:e}=t;return yT()!==void 0?e:null};Wp.displayName="MessagePrimitive.Error";const dk=t=>{const e=new Map;for(let r=0;r<t.length;r++){const s=t[r]?.parentId??r,i=e.get(s)??[];i.push(r),e.set(s,i)}const n=[];for(const[r,s]of e){const i=typeof r=="string"?r:void 0;n.push({groupKey:i,indices:s})}return n},hk=t=>{const e=R(9),n=N(bk);let r;e:{if(n.length===0){let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=[],e[0]=l):l=e[0],r=l;break e}let a;e[1]!==t||e[2]!==n?(a=t(n),e[1]=t,e[2]=n,e[3]=a):a=e[3],r=a}const s=r;let i;e[4]!==n?(i=vn(n),e[4]=n,e[5]=i):i=e[5];let o;return e[6]!==s||e[7]!==i?(o={groups:s,partKeys:i},e[6]=s,e[7]=i,e[8]=o):o=e[8],o},Bt={Text:()=>C.jsxs("p",{style:{whiteSpace:"pre-line"},children:[C.jsx(rl,{}),C.jsx(qa,{children:C.jsx("span",{style:{fontFamily:"revert"},children:" ●"})})]}),Reasoning:()=>null,Source:()=>null,Image:()=>C.jsx(sl,{}),File:()=>null,Unstable_Audio:()=>null,Group:({children:t})=>t},fk=Te(t=>{const e=R(5),{partIndex:n,components:r}=t;let s;e[0]!==r?(s=C.jsx(yf,{components:r}),e[0]=r,e[1]=s):s=e[1];let i;return e[2]!==n||e[3]!==s?(i=C.jsx($a,{index:n,children:s}),e[2]=n,e[3]=s,e[4]=i):i=e[4],i},(t,e)=>t.partIndex===e.partIndex&&t.components?.Text===e.components?.Text&&t.components?.Reasoning===e.components?.Reasoning&&t.components?.Source===e.components?.Source&&t.components?.Image===e.components?.Image&&t.components?.File===e.components?.File&&t.components?.Unstable_Audio===e.components?.Unstable_Audio&&t.components?.tools===e.components?.tools&&t.components?.data===e.components?.data),pk=t=>{const e=R(6),{status:n,component:r}=t,s=n.type==="running";let i;e[0]!==r||e[1]!==n?(i=C.jsx(r,{type:"text",text:"",status:n}),e[0]=r,e[1]=n,e[2]=i):i=e[2];let o;return e[3]!==s||e[4]!==i?(o=C.jsx(Na,{text:"",isRunning:s,children:i}),e[3]=s,e[4]=i,e[5]=o):o=e[5],o},mk=Object.freeze({type:"complete"}),gk=t=>{const e=R(6),{components:n}=t,r=N(_k);if(n?.Empty){let o;return e[0]!==n.Empty||e[1]!==r?(o=C.jsx(n.Empty,{status:r}),e[0]=n.Empty,e[1]=r,e[2]=o):o=e[2],o}const s=n?.Text??Bt.Text;let i;return e[3]!==r||e[4]!==s?(i=C.jsx(pk,{status:r,component:s}),e[3]=r,e[4]=s,e[5]=i):i=e[5],i},yk=Te(gk,(t,e)=>t.components?.Empty===e.components?.Empty&&t.components?.Text===e.components?.Text),il=t=>{const e=R(21),{groupingFunction:n,components:r}=t,s=N(vk),{groups:i,partKeys:o}=hk(n);let a;e:{if(s===0){let v;e[0]!==r?(v=C.jsx(yk,{components:r}),e[0]=r,e[1]=v):v=e[1],a=v;break e}const u=r?.Text??Bt.Text,d=r?.Reasoning??Bt.Reasoning,f=r?.Image??Bt.Image,h=r?.Source??Bt.Source,p=r?.File??Bt.File,m=r?.Unstable_Audio??Bt.Unstable_Audio;let y;e[2]!==r||e[3]!==u||e[4]!==d||e[5]!==f||e[6]!==h||e[7]!==p||e[8]!==m?(y={...r,Text:u,Reasoning:d,Image:f,Source:h,File:p,Unstable_Audio:m},e[2]=r,e[3]=u,e[4]=d,e[5]=f,e[6]=h,e[7]=p,e[8]=m,e[9]=y):y=e[9];const g=y;let b;if(e[10]!==r?.Group||e[11]!==g||e[12]!==i||e[13]!==o){let v;e[15]!==r?.Group||e[16]!==g||e[17]!==o?(v=(w,k)=>{const _=r?.Group??Bt.Group,A=o[w.indices[0]];return C.jsx(_,{groupKey:w.groupKey,indices:w.indices,children:w.indices.map(E=>C.jsx(fk,{partIndex:E,components:g},o[E]))},JSON.stringify(["group",w.groupKey??null,A?.includes(":")?`id:${A}`:k]))},e[15]=r?.Group,e[16]=g,e[17]=o,e[18]=v):v=e[18],b=i.map(v),e[10]=r?.Group,e[11]=g,e[12]=i,e[13]=o,e[14]=b}else b=e[14];a=b}const l=a;let c;return e[19]!==l?(c=C.jsx(C.Fragment,{children:l}),e[19]=l,e[20]=c):c=e[20],c};il.displayName="MessagePrimitive.Unstable_PartsGrouped";const Gp=t=>{const e=R(6);let n,r;e[0]!==t?({components:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let s;return e[3]!==n||e[4]!==r?(s=C.jsx(il,{...r,components:n,groupingFunction:dk}),e[3]=n,e[4]=r,e[5]=s):s=e[5],s};Gp.displayName="MessagePrimitive.Unstable_PartsGroupedByParentId";function bk(t){return t.message.parts}function _k(t){return t.message.status??mk}function vk(t){return t.message.parts.length}var QO=Or({AttachmentByIndex:()=>Ef,Attachments:()=>Af,Content:()=>$o,Error:()=>Wp,GenerativeUI:()=>gf,GroupedParts:()=>Tf,If:()=>Hp,PartByIndex:()=>pr,Parts:()=>$o,Quote:()=>If,Root:()=>qp,Unstable_PartsGrouped:()=>il,Unstable_PartsGroupedByParentId:()=>Gp});const wk=({autoScroll:t,scrollToBottomOnRunStart:e=!0,scrollToBottomOnInitialize:n=!0,scrollToBottomOnThreadSwitch:r=!0})=>{const s=Z(),i=X(null),o=N(p=>p.thread.messages.length>0),a=N(p=>p.thread.messages[0]?.id),l=N(p=>p.optional.threadListItem?.id),c=N(p=>p.thread.isRunning),u=xn(),d=IT(u),{controller:f}=d;ct(()=>{d.getOptions=()=>{const p=u.getState();return{autoScroll:t??p.turnAnchor!=="top",holdFollow:c&&p.turnAnchor==="top"&&p.element.viewport===i.current&&p.element.anchor!==null,scrollToBottomOnInitialize:n,scrollToBottomOnRunStart:e&&p.turnAnchor!=="top",scrollToBottomOnThreadSwitch:r}}});const h=X({threadId:l,firstMessageId:a});return Un(()=>{const p=h.current;if(h.current={threadId:l,firstMessageId:a},p.threadId!==l)return;const m=p.firstMessageId;m===void 0||m===a||s.thread.getState().messages.some((y,g)=>g>0&&y.id===m)&&f.messagesPrepended(m)},[s,f,a,l]),Un(()=>{f.setHasMessages(o)},[f,o,n]),Tp(({behavior:p})=>f.scrollToBottom(p)),Z1("thread.runStart",()=>f.runStarted()),Q(()=>{if(s.optional.threads)return s.on("threads.selectionChanged",()=>f.threadSwitched())},[s,f]),Yn(mt(p=>{i.current=p;const m=f.attach(p);return()=>{m(),i.current=null}},[f]))},lu=new WeakMap,Kp=he((t,e)=>{const n=R(9),r=Z(),s=X(null),i=Wt(e,s);let o;n[0]!==t?(o=d=>{d.key==="Escape"&&s.current&&lu.set(d.nativeEvent,s.current),t.onKeyDown?.(d)},n[0]=t,n[1]=o):o=n[1];const a=o;let l,c;n[2]!==r?(l=()=>{const d=f=>{if(f.key!=="Escape"||bo(f)||f.defaultPrevented||r.thread.source===null)return;const h=lu.get(f)??f.composedPath().find(xk);if(!(h&&h!==s.current)&&r.thread.getState().speech!=null){f.preventDefault();try{r.thread.stopSpeaking()}catch(p){const m=p;if(!(m instanceof Error)||m.message!=="No message is being spoken")throw m}}};return document.addEventListener("keydown",d),()=>{document.removeEventListener("keydown",d)}},c=[r],n[2]=r,n[3]=l,n[4]=c):(l=n[3],c=n[4]),Q(l,c);let u;return n[5]!==i||n[6]!==a||n[7]!==t?(u=C.jsx(Ip.Provider,{value:s,children:C.jsx(ve.div,{...t,"data-aui-thread-root":"",ref:i,onKeyDown:a})}),n[5]=i,n[6]=a,n[7]=t,n[8]=u):u=n[8],u});Kp.displayName="ThreadPrimitive.Root";function xk(t){return t instanceof Element&&t.hasAttribute("data-aui-thread-root")}const Qp=t=>{const{children:e}=t;return N(Sk)?e:null};Qp.displayName="ThreadPrimitive.Empty";function Sk(t){return t.thread.isEmpty}const Tk=t=>{const e=R(4);let n;return e[0]!==t.disabled||e[1]!==t.empty||e[2]!==t.running?(n=r=>!(t.empty===!0&&!r.thread.isEmpty||t.empty===!1&&r.thread.isEmpty||t.running===!0&&!r.thread.isRunning||t.running===!1&&r.thread.isRunning||t.disabled===!0&&!r.thread.isDisabled||t.disabled===!1&&r.thread.isDisabled),e[0]=t.disabled,e[1]=t.empty,e[2]=t.running,e[3]=n):n=e[3],N(n)},Yp=t=>{const e=R(3);let n,r;return e[0]!==t?({children:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),Tk(r)?n:null};Yp.displayName="ThreadPrimitive.If";const Jp=(t,e)=>{const n=R(3);let r;return n[0]!==e||n[1]!==t?(r=s=>{if(!t)return;const i=()=>e?e(s):s.offsetHeight,o=t(i),a=()=>{const u=i();o.setHeight(u)},l=new ResizeObserver(a);l.observe(s);const c=new MutationObserver(a);return c.observe(s,{attributes:!0,attributeFilter:["class","style"]}),window.addEventListener("resize",a),a(),()=>{l.disconnect(),c.disconnect(),window.removeEventListener("resize",a),o.unregister()}},n[0]=e,n[1]=t,n[2]=r):r=n[2],Yn(r)},cu=t=>{let e=0,n=t;for(;n;)e+=n.offsetTop,n=n.offsetParent;return e},Ck=(t,e)=>{let n=0,r=t;for(;r&&r!==e;)n+=r.offsetTop,r=r.offsetParent;return r===e?n:cu(t)-cu(e)},Xp=({viewport:t,anchor:e,tallerThan:n,visibleHeight:r})=>{const s=Ck(e,t),i=e.offsetHeight;return s+Math.max(0,i-(i<=n?i:r))},Ik=({scrollHeight:t,...e})=>{const{viewport:n}=e,r=Xp(e)+n.clientHeight;return Math.max(0,r-t)},kk=({viewport:t,reserve:e,...n})=>Ik({viewport:t,...n,scrollHeight:t.scrollHeight-e.offsetHeight}),Ek=t=>{const e=new ResizeObserver(t),n=new MutationObserver(t);let r=null,s=null,i=null;const o=()=>{e.disconnect(),n.disconnect(),r=null,s=null,i=null};return{target:(a,l,c)=>{r===a&&s===l&&i===c||(o(),e.observe(a),e.observe(l),e.observe(c),n.observe(c,{childList:!0,subtree:!0,characterData:!0}),r=a,s=l,i=c)},disconnect:o}},Ak=t=>{let e=null;return{schedule:()=>{e===null&&(e=requestAnimationFrame(()=>{e=null,t()}))},cancel:()=>{e!==null&&(cancelAnimationFrame(e),e=null)}}},Rk=t=>{let e=null,n,r=null,s=0,i=null,o=!1,a=null;const l=()=>{i=null,a=null},c=()=>a!==null&&Math.abs(s-a)<=1,u=()=>{const y=r;if(!y)return;const g=y.scrollTop,b=Math.max(0,y.scrollHeight-y.clientHeight);g<s&&s>b+1&&Math.abs(g-b)<=1&&c()&&!o&&(i??=s,h.schedule()),s=g},d=y=>{r!==y&&(r&&r.removeEventListener("scroll",u),r=y,o=!1,l(),y&&(y.addEventListener("scroll",u,{passive:!0}),s=y.scrollTop))};function f(){const y=t.getState(),{viewport:g,anchor:b,target:v}=y.element,w=y.targetConfig;if(d(y.turnAnchor==="top"?g:null),y.turnAnchor!=="top"||!g){p.disconnect(),l(),e&&(Pi(e,0),e.remove());return}if(!b&&!v&&!w&&y.topAnchorTurn){p.disconnect(),l(),e?.parentElement&&e.parentElement.lastElementChild!==e&&e.parentElement.append(e);return}if(!b||!v||!w){p.disconnect(),l(),e&&(Pi(e,0),e.remove());return}if(e??=ZI(),(e.parentElement!==v.parentElement||e.previousElementSibling!==v)&&v.after(e),p.target(g,b,v),Pi(e,kk({viewport:g,anchor:b,reserve:e,...w}))){h.schedule();return}const k=XI(b),_=au(Xp({viewport:g,anchor:b,...w}));if(k===void 0||k!==n)i=null,o=!1,Math.abs(g.scrollTop-_)>1&&g.scrollTo({top:_,behavior:"smooth"}),k!==void 0&&(n=k);else if(i!==null&&a!==null){const A=au(i+(_-a));i=null,o=!0,Math.abs(g.scrollTop-A)>1&&g.scrollTo({top:A,behavior:"instant"})}a=_}const h=Ak(f),p=Ek(h.schedule);h.schedule();const m=t.subscribe(h.schedule);return()=>{h.cancel(),m(),p.disconnect(),d(null),e?.remove()}},Mk=t=>{const e=R(4),n=xn();let r,s;e[0]!==t||e[1]!==n?(r=()=>{if(t)return Rk(n)},s=[t,n],e[0]=t,e[1]=n,e[2]=r,e[3]=s):(r=e[2],s=e[3]),Un(r,s)},Pk=(t,e)=>{if(!t)return!1;const n=e.findIndex(r=>r.id===t.targetId);return n<1?!1:e[n-1]?.id===t.anchorId&&e.slice(n+1).every(r=>r.role==="user")},Zp=({isRunning:t,messages:e})=>{if(!t)return null;const n=e.at(-1),r=e.at(-2);return r?.role!=="user"||n?.role!=="assistant"?null:{anchorId:r.id,targetId:n.id}},Dk=t=>Zp(t)?.anchorId,Ok=t=>Zp(t)?.targetId,Lk=()=>{const t=Ht(Nk);return Jp(t,Bk)},Fk=()=>{const t=Ht(jk);return Yn(t)},$k=t=>{const e=R(19),n=xn();let r;e[0]!==t?(r=y=>{if(t)return Dk(y.thread)},e[0]=t,e[1]=r):r=e[1];const s=N(r);let i;e[2]!==t?(i=y=>{if(t)return Ok(y.thread)},e[2]=t,e[3]=i):i=e[3];const o=N(i),a=Ht(zk);let l;e:{if(!s||!o){l=null;break e}let y;e[4]!==s||e[5]!==o?(y={anchorId:s,targetId:o},e[4]=s,e[5]=o,e[6]=y):y=e[6],l=y}const c=l;let u;e[7]!==t||e[8]!==a?(u=y=>t&&!!a&&Pk(a,y.thread.messages),e[7]=t,e[8]=a,e[9]=u):u=e[9];const d=N(u);let f,h;e[10]!==n||e[11]!==a||e[12]!==d?(f=()=>{!a||d||n.getState().setTopAnchorTurn(null)},h=[n,a,d],e[10]=n,e[11]=a,e[12]=d,e[13]=f,e[14]=h):(f=e[13],h=e[14]),Un(f,h);let p,m;e[15]!==c||e[16]!==n?(p=()=>{if(!c)return;const y=n.getState(),g=y.topAnchorTurn;g?.anchorId===c.anchorId&&g.targetId===c.targetId||y.setTopAnchorTurn(c)},m=[c,n],e[15]=c,e[16]=n,e[17]=p,e[18]=m):(p=e[17],m=e[18]),Un(p,m)},em=he((t,e)=>{const n=R(18);let r,s,i,o,a,l;n[0]!==t?({autoScroll:r,scrollToBottomOnRunStart:a,scrollToBottomOnInitialize:o,scrollToBottomOnThreadSwitch:l,children:s,...i}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i,n[4]=o,n[5]=a,n[6]=l):(r=n[1],s=n[2],i=n[3],o=n[4],a=n[5],l=n[6]);let c;n[7]!==r||n[8]!==o||n[9]!==a||n[10]!==l?(c={autoScroll:r,scrollToBottomOnRunStart:a,scrollToBottomOnInitialize:o,scrollToBottomOnThreadSwitch:l},n[7]=r,n[8]=o,n[9]=a,n[10]=l,n[11]=c):c=n[11];const u=wk(c),d=Lk(),f=Fk(),h=xn();let p;n[12]!==h?(p=h.getState(),n[12]=h,n[13]=p):p=n[13];const m=p.turnAnchor==="top";$k(m),Mk(m);const y=Wt(e,u,d,f);let g;return n[14]!==s||n[15]!==y||n[16]!==i?(g=C.jsx(ve.div,{...i,ref:y,children:s}),n[14]=s,n[15]=y,n[16]=i,n[17]=g):g=n[17],g});em.displayName="ThreadPrimitive.ViewportScrollable";const tm=he((t,e)=>{const n=R(13);let r,s,i;n[0]!==t?({turnAnchor:i,topAnchorMessageClamp:s,...r}=t,n[0]=t,n[1]=r,n[2]=s,n[3]=i):(r=n[1],s=n[2],i=n[3]);let o;n[4]!==s||n[5]!==i?(o={turnAnchor:i,topAnchorMessageClamp:s},n[4]=s,n[5]=i,n[6]=o):o=n[6];let a;n[7]!==r||n[8]!==e?(a=C.jsx(em,{...r,ref:e}),n[7]=r,n[8]=e,n[9]=a):a=n[9];let l;return n[10]!==o||n[11]!==a?(l=C.jsx(Ha,{options:o,children:a}),n[10]=o,n[11]=a,n[12]=l):l=n[12],l});tm.displayName="ThreadPrimitive.Viewport";function Nk(t){return t.registerViewport}function Bk(t){return t.clientHeight}function jk(t){return t.registerViewportElement}function zk(t){return t.topAnchorTurn}const nm=he((t,e)=>{const n=R(3),r=Ht(Vk),s=Jp(r,Uk),i=Wt(e,s);let o;return n[0]!==t||n[1]!==i?(o=C.jsx(ve.div,{...t,ref:i}),n[0]=t,n[1]=i,n[2]=o):o=n[2],o});nm.displayName="ThreadPrimitive.ViewportFooter";function Vk(t){return t.registerContentInset}function Uk(t){const e=parseFloat(getComputedStyle(t).marginTop)||0;return t.offsetHeight+e}const qk=t=>{const e=R(5);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const{behavior:r}=n,s=Ht(Wk),i=xn();let o;e[2]!==r||e[3]!==i?(o=()=>{i.getState().scrollToBottom({behavior:r})},e[2]=r,e[3]=i,e[4]=o):o=e[4];const a=o;return s?null:a},Hk=$e("ThreadPrimitive.ScrollToBottom",qk,["behavior"]);function Wk(t){return t.isAtBottom}const Gk=()=>{const t=R(2),e=Z(),n=N(Qk);let r;t[0]!==e.thread?(r=()=>{e.thread.loadEarlier()},t[0]=e.thread,t[1]=r):r=t[1];const s=r;return n?s:null},Kk=$e("ThreadPrimitive.LoadEarlier",Gk);function Qk(t){return t.thread.hasEarlier}const Yk=t=>{const e=R(4),{prompt:n,send:r,clearComposer:s,autoSend:i}=t,o=r??i??!1;let a;e[0]!==s||e[1]!==n||e[2]!==o?(a={prompt:n,send:o,clearComposer:s},e[0]=s,e[1]=n,e[2]=o,e[3]=a):a=e[3];const{disabled:l,trigger:c}=mT(a);return l?null:c},Jk=$e("ThreadPrimitive.Suggestion",Yk,["prompt","send","clearComposer","autoSend","method"]);var YO=Or({Empty:()=>Qp,If:()=>Yp,LoadEarlier:()=>Kk,MessageByIndex:()=>df,Messages:()=>MS,Root:()=>Kp,Row:()=>Cf,ScrollToBottom:()=>Hk,Suggestion:()=>Jk,SuggestionByIndex:()=>Lf,Suggestions:()=>M0,Unstable_MessageById:()=>hf,Viewport:()=>tm,ViewportFooter:()=>nm,ViewportProvider:()=>Ha});const Xk=t=>{let e=t;for(;e;){const{overflowY:n}=getComputedStyle(e);if(n==="scroll"||n==="auto")return e;e=e.parentElement}return null},No=new WeakMap,Zk=t=>{const e=No.get(t);if(e)return e.count++,e;const n=t.ownerDocument,r=getComputedStyle(n.documentElement),s=b=>b!==""&&b!=="visible",i=t===n.documentElement||t===n.scrollingElement||t===n.body&&!s(r.overflowX)&&!s(r.overflowY),o=i?n.scrollingElement??n.documentElement:t,a=o.scrollTop,l=t.style.scrollbarWidth,c=getComputedStyle(t),u=c.direction==="rtl"?"paddingLeft":"paddingRight",d=t.style[u],f=t.offsetWidth-t.clientWidth-parseFloat(c.borderLeftWidth)-parseFloat(c.borderRightWidth),h=i&&f<=0?(n.defaultView?.innerWidth??0)-n.documentElement.clientWidth:f;t.style.scrollbarWidth="none",h>0&&(t.style[u]=`${parseFloat(c[u])+h}px`);const p=()=>{t.style.scrollbarWidth=l,t.style[u]=d},m=()=>o.scrollTo({top:a,behavior:"instant"}),y=i?n:t;y.addEventListener("scroll",m);const g={count:1,restore:()=>{y.removeEventListener("scroll",m),p()}};return No.set(t,g),g},JO=(t,e)=>{const n=R(5),r=X(null);let s,i;n[0]===Symbol.for("react.memo_cache_sentinel")?(s=()=>()=>{r.current?.()},i=[],n[0]=s,n[1]=i):(s=n[0],i=n[1]),Q(s,i);let o;return n[2]!==t||n[3]!==e?(o=()=>{r.current?.();const a=Xk(t.current);if(!a){r.current=null;return}const l=Zk(a),c=setTimeout(()=>r.current?.(),e);r.current=()=>{clearTimeout(c),(l.count=l.count-1)===0&&(l.restore(),No.delete(a)),r.current=null}},n[2]=t,n[3]=e,n[4]=o):o=n[4],o};var eE=Or({AssistantRuntimeImpl:()=>Hh,BaseAssistantRuntimeCore:()=>Oh,CompositeContextProvider:()=>Ea,DefaultThreadComposerRuntimeCore:()=>Vh,MessageRepository:()=>Gs,ThreadRuntimeImpl:()=>zh,getAutoStatus:()=>Ma,splitLocalRuntimeOptions:()=>bT,useComposerInputPluginRegistryOptional:()=>Js,useSmooth:()=>Vp,useSmoothStatus:()=>HI,withSmoothContextProvider:()=>qI});const tE=(t,e,n)=>{const r=R(9);let s;r[0]!==t||r[1]!==e||r[2]!==n?(s=()=>n.empty,r[0]=t,r[1]=e,r[2]=n,r[3]=s):s=r[3];const[i,o]=ie(s);let a,l;return r[4]!==t||r[5]!==e||r[6]!==n?(a=()=>{},l=[t,e,n],r[4]=t,r[5]=e,r[6]=n,r[7]=a,r[8]=l):(a=r[7],l=r[8]),Q(a,l),i},nE=(t,e)=>{const n=Object.keys(t);return n.length!==Object.keys(e).length?!1:n.every(r=>Object.hasOwn(e,r)&&t[r]===e[r])},uu=Object.freeze({}),rE={empty:uu,read:t=>{const e=t.thread.getModelContext().tools;if(!e)return uu;const n=Object.create(null);for(const[r,s]of Object.entries(e))n[r]=s.description;return n},subscribe:(t,e)=>{const n=t.on("thread.modelContextUpdate",e),r=t.on({scope:"*",event:"threads.selectionChanged"},e);return()=>{n(),r()}},isEqual:nE};function XO(t){const e=Z(),n=t?.items,r=t?.categories,s=t?.includeModelContextTools,i=void 0,o=s!==!1,a=t?.formatter,l=t?.onInserted,c=r!==void 0||i?.category!==void 0,u=tE(e,o,rE);return{adapter:ye(()=>{const d=[];if(c){const m=(r??[]).map(g=>({id:g.id,label:g.label,items:g.items.map(du)})),y=d.length>0?[...m,{id:"tools",label:"Tools",items:d}]:m;return{categories:()=>y.map(({id:g,label:b})=>({id:g,label:b})),categoryItems:g=>y.find(b=>b.id===g)?.items??[],search:g=>{const b=g.toLowerCase();return y.flatMap(v=>v.items).filter(v=>Ir(v,b))}}}const f=(n??[]).map(du),h=new Set(f.map(m=>m.id)),p=[...f,...d.filter(m=>!h.has(m.id))];return{categories:()=>[],categoryItems:()=>[],search:m=>{const y=m.toLowerCase();return p.filter(g=>Ir(g,y))}}},[n,r,o,i,c,u]),directive:ye(()=>({formatter:a??Gw,...l?{onInserted:l}:{}}),[a,l]),...t?.iconMap?{iconMap:t.iconMap}:{},...t?.fallbackIcon?{fallbackIcon:t.fallbackIcon}:{}}}function du(t){const e=t.icon!==void 0?{...t.metadata??{},icon:t.icon}:t.metadata;return{id:t.id,type:t.type,label:t.label,...t.description!==void 0?{description:t.description}:{},...e!==void 0?{metadata:e}:{}}}function ZO(t){const{commands:e,removeOnExecute:n}=t,r=X(e),s=X(void 0),i=e.map(sE),o=iE(s.current,i)?s.current:i;Un(()=>{r.current=e,s.current=o},[e,o]);const a=ye(()=>({categories:()=>[],categoryItems:()=>[],search:c=>{const u=c.toLowerCase();return o.filter(d=>Ir(d,u))}}),[o]),l=ye(()=>({onExecute:c=>{r.current.find(u=>u.id===c.id)?.execute()},...n!==void 0?{removeOnExecute:n}:{}}),[n]);return ye(()=>({adapter:a,action:l,...t.iconMap?{iconMap:t.iconMap}:{},...t.fallbackIcon?{fallbackIcon:t.fallbackIcon}:{}}),[a,l,t.iconMap,t.fallbackIcon])}function sE(t){return{id:t.id,type:"command",label:t.label??`/${t.id}`,...t.description!==void 0?{description:t.description}:{},...t.icon!==void 0?{metadata:{icon:t.icon}}:{}}}function iE(t,e){return!t||t.length!==e.length?!1:t.every((n,r)=>{const s=e[r];return s!==void 0&&n.id===s.id&&n.label===s.label&&n.description===s.description&&n.metadata?.icon===s.metadata?.icon})}const Is=(t,e,n=0,r=!1)=>{if(Object.is(t,e))return!0;if(n>=100||typeof t!="object"||t===null||typeof e!="object"||e===null)return!1;if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let u=0;u<t.length;u++)if(!Is(t[u],e[u],n+1))return!1;return!0}if(Array.isArray(e))return!1;const s=Object.getPrototypeOf(t),i=Object.getPrototypeOf(e);if(s!==Object.prototype&&s!==null||i!==Object.prototype&&i!==null)return!1;const o=t,a=e;let l=0;for(const u in o)if(Object.hasOwn(o,u)&&!(r&&(u==="position"||u==="data"))){if(!Object.prototype.propertyIsEnumerable.call(a,u)||!Is(o[u],a[u],n+1))return!1;l++}let c=0;for(const u in a)Object.hasOwn(a,u)&&(r&&(u==="position"||u==="data")||c++);return l===c},oE=(t,e)=>!t||!e?!1:t===e?!0:Is(t.properties,e.properties,0,!0)&&Is(t.children,e.children),ol=(t,e)=>oE(t.node,e.node),e3=(t={})=>Object.fromEntries(Object.entries(t??{}).map(([e,n])=>{if(!n)return[e,n];const r=n,s=({node:i,...o})=>C.jsx(r,{...o});return[e,H.memo(s,ol)]})),al=H.createContext(null),aE=()=>H.useContext(al)!==null,lE=({children:t,fallbackPre:e,...n})=>n.node?.children.some(r=>r.type==="element"&&r.tagName==="code")??!0?C.jsx(al.Provider,{value:n,children:t}):C.jsx(e,{...n,children:t}),cE=H.memo(lE,(t,e)=>t.fallbackPre===e.fallbackPre&&ol(t,e)),uE=({node:t,...e})=>C.jsx("pre",{...e}),dE=({node:t,...e})=>C.jsx("code",{...e}),rm=({node:t,components:{Pre:e,Code:n},code:r})=>C.jsx(e,{children:C.jsx(n,{node:t,children:r})}),hE=()=>null,fE=t=>/(?:^|\s)language-([^\s]+)/.exec(t??"")?.[1]??"",pE=({node:t,components:{Pre:e,Code:n,SyntaxHighlighter:r,CodeHeader:s},language:i,code:o})=>{const a=H.useMemo(()=>({Pre:e,Code:n}),[e,n]);return C.jsxs(C.Fragment,{children:[C.jsx(s,{node:t,language:i,code:o}),C.jsx(r,{node:t,components:a,language:i,code:o})]})};var Oi={exports:{}};var hu;function mE(){return hu||(hu=1,(function(t){(function(){var e={}.hasOwnProperty;function n(){for(var i="",o=0;o<arguments.length;o++){var a=arguments[o];a&&(i=s(i,r(a)))}return i}function r(i){if(typeof i=="string"||typeof i=="number")return i;if(typeof i!="object")return"";if(Array.isArray(i))return n.apply(null,i);if(i.toString!==Object.prototype.toString&&!i.toString.toString().includes("[native code]"))return i.toString();var o="";for(var a in i)e.call(i,a)&&i[a]&&(o=s(o,a));return o}function s(i,o){return o?i?i+" "+o:i+o:i}t.exports?(n.default=n,t.exports=n):window.classNames=n})()})(Oi)),Oi.exports}var gE=mE();const sm=na(gE),im=({className:t,...e})=>({className:n,...r})=>({className:sm(t,n),...e,...r}),ks=H.createContext(null);function fu(t){const{Pre:e,preProps:n}=H.useContext(ks);return C.jsx(e,{...im(n)(t)})}function pu(t){const{Code:e,codeProps:n}=H.useContext(ks);return C.jsx(e,{...im(n)(t)})}function Bo(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e="";for(const n of t)e+=Bo(n);return e}return H.isValidElement(t)?Bo(t.props.children):""}const yE=({node:t,components:{Pre:e,Code:n,SyntaxHighlighter:r,CodeHeader:s},componentsByLanguage:i={},children:o,...a})=>{const l={Pre:e,Code:n,preProps:H.useContext(al),codeProps:a},c=fE(a.className),u=i[c]?.SyntaxHighlighter??r,d=i[c]?.CodeHeader??s;return o!=null&&typeof o!="string"?C.jsxs(ks.Provider,{value:l,children:[C.jsx(d,{node:t,language:c,code:Bo(o)}),C.jsx(rm,{node:t,components:{Pre:fu,Code:pu},code:o})]}):C.jsx(ks.Provider,{value:l,children:C.jsx(pE,{node:t,components:{Pre:fu,Code:pu,SyntaxHighlighter:u,CodeHeader:d},language:c,code:o??""})})},bE=({node:t,components:e,componentsByLanguage:n,...r})=>aE()?C.jsx(yE,{node:t,components:e,componentsByLanguage:n,...r}):C.jsx(e.Code,{...r}),_E=(t,e)=>{if(t===e)return!0;if(!t||!e)return!1;const n=Object.keys(t);if(n.length!==Object.keys(e).length)return!1;for(const r of n){if(!Object.hasOwn(e,r))return!1;const s=t[r],i=e[r];if(s!==i&&(!s||!i||s.SyntaxHighlighter!==i.SyntaxHighlighter||s.CodeHeader!==i.CodeHeader))return!1}return!0},vE=H.memo(bE,(t,e)=>t.components===e.components&&_E(t.componentsByLanguage,e.componentsByLanguage)&&ol(t,e));function wE(t,e){const n={};return(t[t.length-1]===""?[...t,""]:t).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const xE=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,SE=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,TE={};function mu(t,e){return(TE.jsx?SE:xE).test(t)}const CE=/[ \t\n\f\r]/g;function IE(t){return typeof t=="object"?t.type==="text"?gu(t.value):!1:gu(t)}function gu(t){return t.replace(CE,"")===""}class Lr{constructor(e,n,r){this.normal=n,this.property=e,r&&(this.space=r)}}Lr.prototype.normal={};Lr.prototype.property={};Lr.prototype.space=void 0;function om(t,e){const n={},r={};for(const s of t)Object.assign(n,s.property),Object.assign(r,s.normal);return new Lr(n,r,e)}function jo(t){return t.toLowerCase()}class Ne{constructor(e,n){this.attribute=n,this.property=e}}Ne.prototype.attribute="";Ne.prototype.booleanish=!1;Ne.prototype.boolean=!1;Ne.prototype.commaOrSpaceSeparated=!1;Ne.prototype.commaSeparated=!1;Ne.prototype.defined=!1;Ne.prototype.mustUseProperty=!1;Ne.prototype.number=!1;Ne.prototype.overloadedBoolean=!1;Ne.prototype.property="";Ne.prototype.spaceSeparated=!1;Ne.prototype.space=void 0;let kE=0;const ne=Sn(),Se=Sn(),zo=Sn(),B=Sn(),pe=Sn(),on=Sn(),je=Sn();function Sn(){return 2**++kE}const Vo=Object.freeze(Object.defineProperty({__proto__:null,boolean:ne,booleanish:Se,commaOrSpaceSeparated:je,commaSeparated:on,number:B,overloadedBoolean:zo,spaceSeparated:pe},Symbol.toStringTag,{value:"Module"})),Li=Object.keys(Vo);class ll extends Ne{constructor(e,n,r,s){let i=-1;if(super(e,n),yu(this,"space",s),typeof r=="number")for(;++i<Li.length;){const o=Li[i];yu(this,Li[i],(r&Vo[o])===Vo[o])}}}ll.prototype.defined=!0;function yu(t,e,n){n&&(t[e]=n)}function Jn(t){const e={},n={};for(const[r,s]of Object.entries(t.properties)){const i=new ll(r,t.transform(t.attributes||{},r),s,t.space);t.mustUseProperty&&t.mustUseProperty.includes(r)&&(i.mustUseProperty=!0),e[r]=i,n[jo(r)]=r,n[jo(i.attribute)]=r}return new Lr(e,n,t.space)}const am=Jn({properties:{ariaActiveDescendant:null,ariaAtomic:Se,ariaAutoComplete:null,ariaBusy:Se,ariaChecked:Se,ariaColCount:B,ariaColIndex:B,ariaColSpan:B,ariaControls:pe,ariaCurrent:null,ariaDescribedBy:pe,ariaDetails:null,ariaDisabled:Se,ariaDropEffect:pe,ariaErrorMessage:null,ariaExpanded:Se,ariaFlowTo:pe,ariaGrabbed:Se,ariaHasPopup:null,ariaHidden:Se,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:pe,ariaLevel:B,ariaLive:null,ariaModal:Se,ariaMultiLine:Se,ariaMultiSelectable:Se,ariaOrientation:null,ariaOwns:pe,ariaPlaceholder:null,ariaPosInSet:B,ariaPressed:Se,ariaReadOnly:Se,ariaRelevant:null,ariaRequired:Se,ariaRoleDescription:pe,ariaRowCount:B,ariaRowIndex:B,ariaRowSpan:B,ariaSelected:Se,ariaSetSize:B,ariaSort:null,ariaValueMax:B,ariaValueMin:B,ariaValueNow:B,ariaValueText:null,role:null},transform(t,e){return e==="role"?e:"aria-"+e.slice(4).toLowerCase()}});function lm(t,e){return e in t?t[e]:e}function cm(t,e){return lm(t,e.toLowerCase())}const EE=Jn({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:on,acceptCharset:pe,accessKey:pe,action:null,allow:null,allowFullScreen:ne,allowPaymentRequest:ne,allowUserMedia:ne,alpha:ne,alt:null,as:null,async:ne,autoCapitalize:null,autoComplete:pe,autoFocus:ne,autoPlay:ne,blocking:pe,capture:null,charSet:null,checked:ne,cite:null,className:pe,closedBy:null,colorSpace:null,cols:B,colSpan:B,command:null,commandFor:null,content:null,contentEditable:Se,controls:ne,controlsList:pe,coords:B|on,crossOrigin:null,data:null,dateTime:null,decoding:null,default:ne,defer:ne,dir:null,dirName:null,disabled:ne,download:zo,draggable:Se,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:ne,formTarget:null,headers:pe,height:B,hidden:zo,high:B,href:null,hrefLang:null,htmlFor:pe,httpEquiv:pe,id:null,imageSizes:null,imageSrcSet:null,inert:ne,inputMode:null,integrity:null,is:null,isMap:ne,itemId:null,itemProp:pe,itemRef:pe,itemScope:ne,itemType:pe,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:ne,low:B,manifest:null,max:null,maxLength:B,media:null,method:null,min:null,minLength:B,multiple:ne,muted:ne,name:null,nonce:null,noModule:ne,noValidate:ne,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:ne,optimum:B,pattern:null,ping:pe,placeholder:null,playsInline:ne,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:ne,referrerPolicy:null,rel:pe,required:ne,reversed:ne,rows:B,rowSpan:B,sandbox:pe,scope:null,scoped:ne,seamless:ne,selected:ne,shadowRootClonable:ne,shadowRootCustomElementRegistry:ne,shadowRootDelegatesFocus:ne,shadowRootMode:null,shadowRootSerializable:ne,shape:null,size:B,sizes:null,slot:null,span:B,spellCheck:Se,src:null,srcDoc:null,srcLang:null,srcSet:null,start:B,step:null,style:null,tabIndex:B,target:null,title:null,translate:null,type:null,typeMustMatch:ne,useMap:null,value:Se,width:B,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:pe,axis:null,background:null,bgColor:null,border:B,borderColor:null,bottomMargin:B,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:ne,declare:ne,event:null,face:null,frame:null,frameBorder:null,hSpace:B,leftMargin:B,link:null,longDesc:null,lowSrc:null,marginHeight:B,marginWidth:B,noResize:ne,noHref:ne,noShade:ne,noWrap:ne,object:null,profile:null,prompt:null,rev:null,rightMargin:B,rules:null,scheme:null,scrolling:Se,standby:null,summary:null,text:null,topMargin:B,valueType:null,version:null,vAlign:null,vLink:null,vSpace:B,allowTransparency:null,autoCorrect:null,autoSave:null,credentialless:ne,disablePictureInPicture:ne,disableRemotePlayback:ne,exportParts:on,part:pe,prefix:null,property:null,results:B,security:null,unselectable:null},space:"html",transform:cm}),AE=Jn({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",maskType:"mask-type",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:je,accentHeight:B,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:B,amplitude:B,arabicForm:null,ascent:B,attributeName:null,attributeType:null,azimuth:B,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:B,by:null,calcMode:null,capHeight:B,className:pe,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:B,diffuseConstant:B,direction:null,display:null,dur:null,divisor:B,dominantBaseline:null,download:ne,dx:null,dy:null,edgeMode:null,editable:null,elevation:B,enableBackground:null,end:null,event:null,exponent:B,externalResourcesRequired:null,fill:null,fillOpacity:B,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:on,g2:on,glyphName:on,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:B,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:B,horizOriginX:B,horizOriginY:B,id:null,ideographic:B,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:B,k:B,k1:B,k2:B,k3:B,k4:B,kernelMatrix:je,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:B,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskType:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:B,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:B,overlineThickness:B,paintOrder:null,panose1:null,path:null,pathLength:B,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:pe,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:B,pointsAtY:B,pointsAtZ:B,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:je,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:je,rev:je,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:je,requiredFeatures:je,requiredFonts:je,requiredFormats:je,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:B,specularExponent:B,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:B,strikethroughThickness:B,string:null,stroke:null,strokeDashArray:je,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:B,strokeOpacity:B,strokeWidth:null,style:null,surfaceScale:B,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:je,tabIndex:B,tableValues:null,target:null,targetX:B,targetY:B,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:je,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:B,underlineThickness:B,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:B,values:null,vAlphabetic:B,vMathematical:B,vectorEffect:null,vHanging:B,vIdeographic:B,version:null,vertAdvY:B,vertOriginX:B,vertOriginY:B,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:B,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:lm}),um=Jn({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(t,e){return"xlink:"+e.slice(5).toLowerCase()}}),dm=Jn({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:cm}),hm=Jn({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(t,e){return"xml:"+e.slice(3).toLowerCase()}}),RE={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},ME=/[A-Z]/g,bu=/-[a-z]/g,PE=/^data[-\w.:]+$/i;function DE(t,e){const n=jo(e);let r=e,s=Ne;if(n in t.normal)return t.property[t.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&PE.test(e)){if(e.charAt(4)==="-"){const i=e.slice(5).replace(bu,LE);r="data"+i.charAt(0).toUpperCase()+i.slice(1)}else{const i=e.slice(4);if(!bu.test(i)){let o=i.replace(ME,OE);o.charAt(0)!=="-"&&(o="-"+o),e="data"+o}}s=ll}return new s(r,e)}function OE(t){return"-"+t.toLowerCase()}function LE(t){return t.charAt(1).toUpperCase()}const FE=om([am,EE,um,dm,hm],"html"),cl=om([am,AE,um,dm,hm],"svg");function $E(t){return t.join(" ").trim()}var _u=/\/\*(?:[^*]|\*(?!\/))*\*\//g,NE=/\n/g,BE=/^\s*/,jE=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,zE=/^:\s*/,VE=/^((?:'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|url\((?:'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|[^)]*)\)|[^};])+)/,UE=/^[;\s]*/,qE=`
|
|
12
|
+
`,vu="/",wu="*",lr="",HE="comment",WE="declaration";function GE(t,e){if(typeof t!="string")throw new TypeError("First argument must be a string");if(!t)return[];e=e||{};var n=1,r=1;function s(p){var m=p.match(NE);m&&(n+=m.length);var y=p.lastIndexOf(qE);r=~y?p.length-y:r+p.length}function i(){var p={line:n,column:r};return function(m){return m.position=new o(p),c(),m}}function o(p){this.start=p,this.end={line:n,column:r},this.source=e.source}o.prototype.content=t;function a(p){var m=new Error(e.source+":"+n+":"+r+": "+p);if(m.reason=p,m.filename=e.source,m.line=n,m.column=r,m.source=t,!e.silent)throw m}function l(p){var m=p.exec(t);if(m){var y=m[0];return s(y),t=t.slice(y.length),m}}function c(){l(BE)}function u(p){for(var m;m=d();)p.push(m);return p}function d(){var p=i();if(!(vu!=t.charAt(0)||wu!=t.charAt(1))){for(var m=2;lr!=t.charAt(m)&&(wu!=t.charAt(m)||vu!=t.charAt(m+1));)++m;if(m+=2,lr===t.charAt(m-1))return a("End of comment missing");var y=t.slice(2,m-2);return r+=2,s(y),t=t.slice(m),r+=2,p({type:HE,comment:y})}}function f(){var p=i(),m=l(jE);if(m){if(d(),!l(zE))return a("property missing ':'");var y=l(VE),g=p({type:WE,property:m[0].replace(_u,lr).trim(),value:y?y[0].replace(_u,lr).trim():lr});return l(UE),g}}function h(){var p=[];u(p);for(var m;m=f();)p.push(m),u(p);return p}return c(),h()}function KE(t,e){let n=null;if(!t||typeof t!="string")return n;const r=GE(t),s=typeof e=="function";return r.forEach(i=>{if(i.type!=="declaration")return;const{property:o,value:a}=i;s?e(o,a,i):a&&(n=n??{},n[o]=a)}),n}const fm=pm("end"),ul=pm("start");function pm(t){return e;function e(n){const r=n&&n.position&&n.position[t]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function QE(t){const e=ul(t),n=fm(t);if(e&&n)return{start:e,end:n}}function mr(t){return!t||typeof t!="object"?"":"position"in t||"type"in t?xu(t.position):"start"in t||"end"in t?xu(t):"line"in t||"column"in t?Uo(t):""}function Uo(t){return Su(t&&t.line)+":"+Su(t&&t.column)}function xu(t){return Uo(t&&t.start)+"-"+Uo(t&&t.end)}function Su(t){return t&&typeof t=="number"?t:1}class Xs extends Error{constructor(e,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let s="",i={},o=!1;if(n&&("line"in n&&"column"in n?i={place:n}:"start"in n&&"end"in n?i={place:n}:"type"in n?i={ancestors:[n],place:n.position}:i={...n}),typeof e=="string"?s=e:!i.cause&&e&&(o=!0,s=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?i.ruleId=r:(i.source=r.slice(0,l),i.ruleId=r.slice(l+1))}if(!i.place&&i.ancestors){const l=i.ancestors[i.ancestors.length-1];l&&(i.place=l.position)}const a=i.place&&"start"in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=s,this.line=a?a.line:void 0,this.name=mr(i.place)||"1:1",this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=o&&i.cause&&typeof i.cause.stack=="string"?i.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}Object.defineProperties(Xs.prototype,{file:{configurable:!0,enumerable:!0,value:"",writable:!0},name:{configurable:!0,enumerable:!0,value:"",writable:!0},reason:{configurable:!0,enumerable:!0,value:"",writable:!0},message:{configurable:!0,enumerable:!0,value:"",writable:!0},stack:{configurable:!0,enumerable:!0,value:"",writable:!0},column:{configurable:!0,enumerable:!0,writable:!0},line:{configurable:!0,enumerable:!0,writable:!0},ancestors:{configurable:!0,enumerable:!0,writable:!0},cause:{configurable:!0,enumerable:!0,writable:!0},fatal:{configurable:!0,enumerable:!0,writable:!0},place:{configurable:!0,enumerable:!0,writable:!0},ruleId:{configurable:!0,enumerable:!0,writable:!0},source:{configurable:!0,enumerable:!0,writable:!0}});const dl={}.hasOwnProperty,YE=new Map,JE=/[A-Z]/g,XE=/-([a-z])/g,ZE=new Set(["table","tbody","thead","tfoot","tr"]),eA=new Set(["td","th"]),mm="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function tA(t,e){if(!e||e.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=e.filePath||void 0;let r;if(e.development){if(typeof e.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=cA(n,e.jsxDEV)}else{if(typeof e.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof e.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=lA(n,e.jsx,e.jsxs)}const s={Fragment:e.Fragment,ancestors:[],components:e.components||{},create:r,elementAttributeNameCase:e.elementAttributeNameCase||"react",evaluater:e.createEvaluater?e.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:e.ignoreInvalidStyle||!1,passKeys:e.passKeys!==!1,passNode:e.passNode||!1,schema:e.space==="svg"?cl:FE,stylePropertyNameCase:e.stylePropertyNameCase||"dom",tableCellAlignToStyle:e.tableCellAlignToStyle!==!1},i=gm(s,t,void 0);return i&&typeof i!="string"?i:s.create(t,s.Fragment,{children:i||void 0},void 0)}function gm(t,e,n){if(e.type==="element")return nA(t,e,n);if(e.type==="mdxFlowExpression"||e.type==="mdxTextExpression")return rA(t,e);if(e.type==="mdxJsxFlowElement"||e.type==="mdxJsxTextElement")return iA(t,e,n);if(e.type==="mdxjsEsm")return sA(t,e);if(e.type==="root")return oA(t,e,n);if(e.type==="text")return aA(t,e)}function nA(t,e,n){const r=t.schema;let s=r;e.tagName.toLowerCase()==="svg"&&r.space==="html"&&(s=cl,t.schema=s),t.ancestors.push(e);const i=bm(t,e.tagName,!1),o=uA(t,e);let a=fl(t,e);return ZE.has(e.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!IE(l):!0})),ym(t,o,i,e),hl(o,a),t.ancestors.pop(),t.schema=r,t.create(e,i,o,n)}function rA(t,e){if(e.data&&e.data.estree&&t.evaluater){const r=e.data.estree.body[0];return r.type,t.evaluater.evaluateExpression(r.expression)}kr(t,e.position)}function sA(t,e){if(e.data&&e.data.estree&&t.evaluater)return t.evaluater.evaluateProgram(e.data.estree);kr(t,e.position)}function iA(t,e,n){const r=t.schema;let s=r;e.name==="svg"&&r.space==="html"&&(s=cl,t.schema=s),t.ancestors.push(e);const i=e.name===null?t.Fragment:bm(t,e.name,!0),o=dA(t,e),a=fl(t,e);return ym(t,o,i,e),hl(o,a),t.ancestors.pop(),t.schema=r,t.create(e,i,o,n)}function oA(t,e,n){const r={};return hl(r,fl(t,e)),t.create(e,t.Fragment,r,n)}function aA(t,e){return e.value}function ym(t,e,n,r){typeof n!="string"&&n!==t.Fragment&&t.passNode&&(e.node=r)}function hl(t,e){if(e.length>0){const n=e.length>1?e:e[0];n&&(t.children=n)}}function lA(t,e,n){return r;function r(s,i,o,a){const c=Array.isArray(o.children)?n:e;return a?c(i,o,a):c(i,o)}}function cA(t,e){return n;function n(r,s,i,o){const a=Array.isArray(i.children),l=ul(r);return e(s,i,o,a,{columnNumber:l?l.column-1:void 0,fileName:t,lineNumber:l?l.line:void 0},void 0)}}function uA(t,e){const n={};let r,s;for(s in e.properties)if(s!=="children"&&dl.call(e.properties,s)){const i=hA(t,s,e.properties[s]);if(i){const[o,a]=i;t.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&eA.has(e.tagName)?r=a:n[o]=a}}if(r){const i=n.style||(n.style={});i[t.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function dA(t,e){const n={};for(const r of e.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&t.evaluater){const i=r.data.estree.body[0];i.type;const o=i.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,t.evaluater.evaluateExpression(a.argument))}else kr(t,e.position);else{const{name:s}=r;let i;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&t.evaluater){const a=r.value.data.estree.body[0];a.type,i=t.evaluater.evaluateExpression(a.expression)}else kr(t,e.position);else i=r.value===null?!0:r.value;n[s]=i}return n}function fl(t,e){const n=[];let r=-1;const s=t.passKeys?new Map:YE;for(;++r<e.children.length;){const i=e.children[r];let o;if(t.passKeys){const l=i.type==="element"?i.tagName:i.type==="mdxJsxFlowElement"||i.type==="mdxJsxTextElement"?i.name:void 0;if(l){const c=s.get(l)||0;o=l+"-"+c,s.set(l,c+1)}}const a=gm(t,i,o);a!==void 0&&n.push(a)}return n}function hA(t,e,n){if(n==null||typeof n=="number"&&Number.isNaN(n))return;const r=DE(t.schema,e);return Array.isArray(n)&&(n=r.commaSeparated?wE(n):$E(n)),r.property==="style"?["style",typeof n=="object"?t.stylePropertyNameCase==="dom"?n:pA(n):fA(t,String(n))]:[t.elementAttributeNameCase==="react"&&r.space?RE[r.property]||r.property:r.attribute,n]}function fA(t,e){const n={};try{KE(e,function(r,s){if(r&&s){let i=r;i.slice(0,2)!=="--"&&(i=i.toLowerCase(),t.stylePropertyNameCase==="dom"&&(i.slice(0,4)==="-ms-"&&(i=i.slice(1)),i=i.replace(XE,yA))),n[i]=s}})}catch(r){if(t.ignoreInvalidStyle)return{};const s=r,i=new Xs("Cannot parse `style` attribute",{ancestors:t.ancestors,cause:s,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw i.file=t.filePath||void 0,i.url=mm+"#cannot-parse-style-attribute",i}return n}function bm(t,e,n){let r;if(!n)r={type:"Literal",value:e};else if(e.includes(".")){const s=e.split(".");let i=-1,o;for(;++i<s.length;){const a=mu(s[i])?{type:"Identifier",name:s[i]}:{type:"Literal",value:s[i]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(i&&a.type==="Literal"),optional:!1}:a}r=o}else r=mu(e)&&!/^[a-z]/.test(e)?{type:"Identifier",name:e}:{type:"Literal",value:e};if(r.type==="Literal"){const s=r.value;return dl.call(t.components,s)?t.components[s]:s}if(t.evaluater)return t.evaluater.evaluateExpression(r);kr(t)}function kr(t,e){const n=new Xs("Cannot handle MDX estrees without `createEvaluater`",{ancestors:t.ancestors,place:e,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=t.filePath||void 0,n.url=mm+"#cannot-handle-mdx-estrees-without-createevaluater",n}function pA(t){const e={};let n;for(n in t)dl.call(t,n)&&(e[mA(n)]=t[n]);return e}function mA(t){if(t.slice(0,2)==="--")return t;let e=t.replace(JE,gA);return e.slice(0,3)==="ms-"&&(e="-"+e),e}function gA(t){return"-"+t.toLowerCase()}function yA(t,e){return e.toUpperCase()}const Fi={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},bA={};function Zs(t,e){const n=bA,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,s=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return _m(t,r,s)}function _m(t,e,n){if(_A(t)){if("value"in t)return t.type==="html"&&!n?"":t.value;if(e&&"alt"in t&&t.alt)return t.alt;if("children"in t)return Tu(t.children,e,n)}return Array.isArray(t)?Tu(t,e,n):""}function Tu(t,e,n){const r=[];let s=-1;for(;++s<t.length;)r[s]=_m(t[s],e,n);return r.join("")}function _A(t){return!!(t&&typeof t=="object")}const Cu=document.createElement("i");function pl(t){const e="&"+t+";";Cu.innerHTML=e;const n=Cu.textContent;return n.charCodeAt(n.length-1)===59&&t!=="semi"||n===e?!1:n}function rt(t,e,n,r){const s=t.length;let i=0,o;if(e<0?e=-e>s?0:s+e:e=e>s?s:e,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(e,n),t.splice(...o);else for(n&&t.splice(e,n);i<r.length;)o=r.slice(i,i+1e4),o.unshift(e,0),t.splice(...o),i+=1e4,e+=1e4}function We(t,e){return t.length>0?(rt(t,t.length,0,e),t):e}const Iu={}.hasOwnProperty;function vm(t){const e={};let n=-1;for(;++n<t.length;)vA(e,t[n]);return e}function vA(t,e){let n;for(n in e){const s=(Iu.call(t,n)?t[n]:void 0)||(t[n]={}),i=e[n];let o;if(i)for(o in i){Iu.call(s,o)||(s[o]=[]);const a=i[o];wA(s[o],Array.isArray(a)?a:a?[a]:[])}}}function wA(t,e){let n=-1;const r=[];for(;++n<e.length;)(e[n].add==="after"?t:r).push(e[n]);rt(t,0,0,r)}function wm(t,e){const n=Number.parseInt(t,e);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function st(t){return t.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Ce=Gt(/[A-Za-z]/),Ie=Gt(/[\dA-Za-z]/),xA=Gt(/[#-'*+\--9=?A-Z^-~]/);function Es(t){return t!==null&&(t<32||t===127)}const qo=Gt(/\d/),SA=Gt(/[\dA-Fa-f]/),xm=Gt(/[!-/:-@[-`{-~]/);function Y(t){return t!==null&&t<-2}function me(t){return t!==null&&(t<0||t===32)}function ae(t){return t===-2||t===-1||t===32}const Fr=Gt(/\p{P}|\p{S}/u),gn=Gt(/\s/);function Gt(t){return e;function e(n){return n!==null&&n>-1&&t.test(String.fromCharCode(n))}}function Xn(t){const e=[];let n=-1,r=0,s=0;for(;++n<t.length;){const i=t.charCodeAt(n);let o="";if(i===37&&Ie(t.charCodeAt(n+1))&&Ie(t.charCodeAt(n+2)))s=2;else if(i<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(i))||(o=String.fromCharCode(i));else if(i>55295&&i<57344){const a=t.charCodeAt(n+1);i<56320&&a>56319&&a<57344?(o=String.fromCharCode(i,a),s=1):o="�"}else o=String.fromCharCode(i);o&&(e.push(t.slice(r,n),encodeURIComponent(o)),r=n+s+1,o=""),s&&(n+=s,s=0)}return e.join("")+t.slice(r)}function ue(t,e,n,r){const s=r?r-1:1/0;let i=0;return o;function o(l){return ae(l)?(t.enter(n),a(l)):e(l)}function a(l){return ae(l)&&i++<s?(t.consume(l),a):(t.exit(n),e(l))}}function Sm(t,e,n,r,s,i){let o=0;return a;function a(u){return ae(u)?(t.enter(r),l(u)):c(u)}function l(u){return ae(u)&&o<i?(t.consume(u),o++,l):(t.exit(r),c(u))}function c(u){return o>=s?e(u):n(u)}}const TA={tokenize:CA};function CA(t){const e=t.attempt(this.parser.constructs.contentInitial,r,s);let n;return e;function r(a){if(a===null){t.consume(a);return}return t.enter("lineEnding"),t.consume(a),t.exit("lineEnding"),ue(t,e,"linePrefix")}function s(a){return t.enter("paragraph"),i(a)}function i(a){const l=t.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,o(a)}function o(a){if(a===null){t.exit("chunkText"),t.exit("paragraph"),t.consume(a);return}return Y(a)?(t.consume(a),t.exit("chunkText"),i):(t.consume(a),o)}}let As=class{constructor(){this.index=new Map,this.map=[]}add(e,n,r){ku(this,e,n,r,!1)}addBefore(e,n,r){ku(this,e,n,r,!0)}consume(e){if(this.map.sort(function(i,o){return i[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(e.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),e.length=this.map[n][0];r.push(e.slice()),e.length=0;let s=r.pop();for(;s;){for(const i of s)e.push(i);s=r.pop()}this.map.length=0,this.index.clear()}};function ku(t,e,n,r,s){if(n===0&&r.length===0)return;const i=t.index.get(e);if(i){i[1]+=n,s?(r.push(...i[2]),i[2]=r):i[2].push(...r);return}const o=[e,n,r];t.map.push(o),t.index.set(e,o)}const IA={tokenize:kA},Eu={tokenize:EA};function kA(t){const e=this,n=[];let r=0,s,i,o;return a;function a(v){if(r<n.length){const w=n[r];return e.containerState=w[1],t.attempt(w[0].continuation,l,c)(v)}return c(v)}function l(v){if(r++,e.containerState._closeFlow){e.containerState._closeFlow=void 0,s&&b();const w=e.events.length;let k=w,_;for(;k--;)if(e.events[k][0]==="exit"&&e.events[k][1].type==="chunkFlow"){_=e.events[k][1].end;break}g(r);let A=w;for(;A<e.events.length;)e.events[A][1].end={..._},A++;const E=new As;return E.add(k+1,0,e.events.slice(w)),E.add(w,A-w,[]),E.consume(e.events),c(v)}return a(v)}function c(v){if(r===n.length){if(!s)return f(v);if(s.currentConstruct&&s.currentConstruct.concrete)return p(v);e.interrupt=!!(s.currentConstruct&&!s._gfmTableDynamicInterruptHack)}return e.containerState={},t.check(Eu,u,d)(v)}function u(v){return s&&b(),g(r),f(v)}function d(v){return e.parser.lazy[e.now().line]=r!==n.length,o=e.now().offset,p(v)}function f(v){return e.containerState={},t.attempt(Eu,h,p)(v)}function h(v){return r++,n.push([e.currentConstruct,e.containerState]),f(v)}function p(v){if(v===null){s&&b(),g(0),t.consume(v);return}return s=s||e.parser.flow(e.now()),t.enter("chunkFlow",{_tokenizer:s,contentType:"flow",previous:i}),m(v)}function m(v){if(v===null){y(t.exit("chunkFlow"),!0),g(0),t.consume(v);return}return Y(v)?(t.consume(v),y(t.exit("chunkFlow")),r=0,e.interrupt=void 0,a):(t.consume(v),m)}function y(v,w){const k=e.sliceStream(v);if(w&&k.push(null),v.previous=i,i&&(i.next=v),i=v,s.defineSkip(v.start),s.write(k),e.parser.lazy[v.start.line]){let _=s.events.length;for(;_--;)if(s.events[_][1].start.offset<o&&(!s.events[_][1].end||s.events[_][1].end.offset>o))return;const A=e.events.length;let E=A,D,x;for(;E--;)if(e.events[E][0]==="exit"&&e.events[E][1].type==="chunkFlow"){if(D){x=e.events[E][1].end;break}D=!0}for(g(r),_=A;_<e.events.length;)e.events[_][1].end={...x},_++;const M=new As;M.add(E+1,0,e.events.slice(A)),M.add(A,_-A,[]),M.consume(e.events)}}function g(v){let w=n.length;for(;w-- >v;){const k=n[w];e.containerState=k[1],k[0].exit.call(e,t)}n.length=v}function b(){s.write([null]),i=void 0,s=void 0,e.containerState._closeFlow=void 0}}function EA(t,e,n){return ue(t,t.attempt(this.parser.constructs.document,e,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function Vt(t){if(t===null||me(t)||gn(t))return 1;if(Fr(t))return 2}function ei(t,e,n){const r=[];let s=-1;for(;++s<t.length;){const i=t[s].resolveAll;i&&!r.includes(i)&&(e=i(e,n),r.push(i))}return e}const Ho={name:"attention",resolveAll:AA,tokenize:RA};function AA(t,e){let n=-1,r;for(;++n<t.length;)if(t[n][0]==="enter"&&t[n][1].type==="attentionSequence"&&t[n][1]._close){let s=n;for(;s--;)if(t[s][0]==="exit"&&t[s][1].type==="attentionSequence"&&t[s][1]._open&&e.sliceSerialize(t[s][1]).charCodeAt(0)===e.sliceSerialize(t[n][1]).charCodeAt(0)){if((t[s][1]._close||t[n][1]._open)&&(t[n][1].end.offset-t[n][1].start.offset)%3&&!((t[s][1].end.offset-t[s][1].start.offset+t[n][1].end.offset-t[n][1].start.offset)%3))continue;const i=t[s][1].end.offset-t[s][1].start.offset>1&&t[n][1].end.offset-t[n][1].start.offset>1?2:1,o={...t[s][1].end},a={...t[n][1].start};Au(o,-i),Au(a,i);const l={type:i>1?"strongSequence":"emphasisSequence",start:o,end:{...t[s][1].end}},c={type:i>1?"strongSequence":"emphasisSequence",start:{...t[n][1].start},end:a},u={type:i>1?"strongText":"emphasisText",start:{...t[s][1].end},end:{...t[n][1].start}},d={type:i>1?"strong":"emphasis",start:{...l.start},end:{...c.end}};t[s][1].end={...l.start},t[n][1].start={...c.end},r=[],t[s][1].end.offset-t[s][1].start.offset&&(r=We(r,[["enter",t[s][1],e],["exit",t[s][1],e]])),r=We(r,[["enter",d,e],["enter",l,e],["exit",l,e],["enter",u,e]]),r=We(r,ei(e.parser.constructs.insideSpan.null,t.slice(s+1,n),e)),r=We(r,[["exit",u,e],["enter",c,e],["exit",c,e],["exit",d,e]]);let f=0;t[n][1].end.offset-t[n][1].start.offset&&(f=2,r=We(r,[["enter",t[n][1],e],["exit",t[n][1],e]])),rt(t,s-1,n-s+3,r),n=s+r.length-f-2;break}}for(n=-1;++n<t.length;)t[n][1].type==="attentionSequence"&&(t[n][1].type="data");return t}function RA(t,e){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,s=Vt(r);let i;return o;function o(l){return i=l,t.enter("attentionSequence"),a(l)}function a(l){if(l===i)return t.consume(l),a;const c=t.exit("attentionSequence"),u=Vt(l),d=!u||u===2&&s||n.includes(l)&&l!==42&&l!==95,f=!s||s===2&&u||n.includes(r)&&r!==42&&r!==95;return c._open=!!(i===42?d:d&&(s||!f)),c._close=!!(i===42?f:f&&(u||!d)),e(l)}}function Au(t,e){t.column+=e,t.offset+=e,t._bufferIndex+=e}const MA={name:"autolink",tokenize:PA};function PA(t,e,n){let r=0;return s;function s(h){return t.enter("autolink"),t.enter("autolinkMarker"),t.consume(h),t.exit("autolinkMarker"),t.enter("autolinkProtocol"),i}function i(h){return Ce(h)?(t.consume(h),o):h===64?n(h):c(h)}function o(h){return h===43||h===45||h===46||Ie(h)?(r=1,a(h)):c(h)}function a(h){return h===58?(t.consume(h),r=0,l):(h===43||h===45||h===46||Ie(h))&&r++<32?(t.consume(h),a):(r=0,c(h))}function l(h){return h===62?(t.exit("autolinkProtocol"),t.enter("autolinkMarker"),t.consume(h),t.exit("autolinkMarker"),t.exit("autolink"),e):h===null||h===32||h===60||Es(h)?n(h):(t.consume(h),l)}function c(h){return h===64?(t.consume(h),u):xA(h)?(t.consume(h),c):n(h)}function u(h){return Ie(h)?d(h):n(h)}function d(h){return h===46?(t.consume(h),r=0,u):h===62?(t.exit("autolinkProtocol").type="autolinkEmail",t.enter("autolinkMarker"),t.consume(h),t.exit("autolinkMarker"),t.exit("autolink"),e):f(h)}function f(h){if((h===45||Ie(h))&&r++<63){const p=h===45?f:d;return t.consume(h),p}return n(h)}}const $r={partial:!0,tokenize:DA};function DA(t,e,n){return r;function r(i){return ae(i)?ue(t,s,"linePrefix")(i):s(i)}function s(i){return i===null||Y(i)?e(i):n(i)}}const Tm={continuation:{tokenize:LA},exit:FA,name:"blockQuote",tokenize:OA};function OA(t,e,n){const r=this;return s;function s(o){if(o===62){const a=r.containerState;return a.open||(t.enter("blockQuote",{_container:!0}),a.open=!0),t.enter("blockQuotePrefix"),t.enter("blockQuoteMarker"),t.consume(o),t.exit("blockQuoteMarker"),i}return n(o)}function i(o){return ae(o)?(t.enter("blockQuotePrefixWhitespace"),t.consume(o),t.exit("blockQuotePrefixWhitespace"),t.exit("blockQuotePrefix"),e):(t.exit("blockQuotePrefix"),e(o))}}function LA(t,e,n){const r=this;return s;function s(o){return ae(o)?ue(t,i,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):i(o)}function i(o){return t.attempt(Tm,e,n)(o)}}function FA(t){t.exit("blockQuote")}const Cm={name:"characterEscape",tokenize:$A};function $A(t,e,n){return r;function r(i){return t.enter("characterEscape"),t.enter("escapeMarker"),t.consume(i),t.exit("escapeMarker"),s}function s(i){return xm(i)?(t.enter("characterEscapeValue"),t.consume(i),t.exit("characterEscapeValue"),t.exit("characterEscape"),e):n(i)}}const Im={name:"characterReference",tokenize:NA};function NA(t,e,n){const r=this;let s=0,i,o;return a;function a(d){return t.enter("characterReference"),t.enter("characterReferenceMarker"),t.consume(d),t.exit("characterReferenceMarker"),l}function l(d){return d===35?(t.enter("characterReferenceMarkerNumeric"),t.consume(d),t.exit("characterReferenceMarkerNumeric"),c):(t.enter("characterReferenceValue"),i=31,o=Ie,u(d))}function c(d){return d===88||d===120?(t.enter("characterReferenceMarkerHexadecimal"),t.consume(d),t.exit("characterReferenceMarkerHexadecimal"),t.enter("characterReferenceValue"),i=6,o=SA,u):(t.enter("characterReferenceValue"),i=7,o=qo,u(d))}function u(d){if(d===59&&s){const f=t.exit("characterReferenceValue");return o===Ie&&!pl(r.sliceSerialize(f))?n(d):(t.enter("characterReferenceMarker"),t.consume(d),t.exit("characterReferenceMarker"),t.exit("characterReference"),e)}return o(d)&&s++<i?(t.consume(d),u):n(d)}}const Wo={partial:!0,tokenize:BA};function BA(t,e,n){const r=this;return s;function s(o){return o===null?n(o):(t.enter("lineEnding"),t.consume(o),t.exit("lineEnding"),i)}function i(o){return r.parser.lazy[r.now().line]?n(o):e(o)}}const Ru={concrete:!0,name:"codeFenced",tokenize:jA};function jA(t,e,n){const r=this,s={partial:!0,tokenize:k};let i=0,o=0,a;return l;function l(_){return c(_)}function c(_){const A=r.events[r.events.length-1];return i=A&&A[1].type==="linePrefix"?A[2].sliceSerialize(A[1],!0).length:0,a=_,t.enter("codeFenced"),t.enter("codeFencedFence"),t.enter("codeFencedFenceSequence"),u(_)}function u(_){return _===a?(o++,t.consume(_),u):o<3?n(_):(t.exit("codeFencedFenceSequence"),ae(_)?ue(t,d,"whitespace")(_):d(_))}function d(_){return _===null||Y(_)?(t.exit("codeFencedFence"),r.interrupt?e(_):t.check(Wo,m,w)(_)):(t.enter("codeFencedFenceInfo"),t.enter("chunkString",{contentType:"string"}),f(_))}function f(_){return _===null||Y(_)?(t.exit("chunkString"),t.exit("codeFencedFenceInfo"),d(_)):ae(_)?(t.exit("chunkString"),t.exit("codeFencedFenceInfo"),ue(t,h,"whitespace")(_)):_===96&&_===a?n(_):(t.consume(_),f)}function h(_){return _===null||Y(_)?d(_):(t.enter("codeFencedFenceMeta"),t.enter("chunkString",{contentType:"string"}),p(_))}function p(_){return _===null||Y(_)?(t.exit("chunkString"),t.exit("codeFencedFenceMeta"),d(_)):_===96&&_===a?n(_):(t.consume(_),p)}function m(_){return t.attempt(s,w,y)(_)}function y(_){return t.enter("lineEnding"),t.consume(_),t.exit("lineEnding"),g}function g(_){return i>0&&ae(_)?ue(t,b,"linePrefix",i+1)(_):b(_)}function b(_){return _===null||Y(_)?t.check(Wo,m,w)(_):(t.enter("codeFlowValue"),v(_))}function v(_){return _===null||Y(_)?(t.exit("codeFlowValue"),b(_)):(t.consume(_),v)}function w(_){return t.exit("codeFenced"),e(_)}function k(_,A,E){let D=0;return x;function x(L){return _.enter("lineEnding"),_.consume(L),_.exit("lineEnding"),M}function M(L){return _.enter("codeFencedFence"),ae(L)?ue(_,P,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(L):P(L)}function P(L){return L===a?(_.enter("codeFencedFenceSequence"),T(L)):E(L)}function T(L){return L===a?(D++,_.consume(L),T):D>=o?(_.exit("codeFencedFenceSequence"),ae(L)?ue(_,$,"whitespace")(L):$(L)):E(L)}function $(L){return L===null||Y(L)?(_.exit("codeFencedFence"),A(L)):E(L)}}}const $i={name:"codeIndented",tokenize:VA},zA={partial:!0,tokenize:UA};function VA(t,e,n){return r;function r(a){return t.enter("codeIndented"),Sm(t,s,n,"linePrefix",4,4)(a)}function s(a){return a===null?o(a):Y(a)?t.attempt(zA,s,o)(a):(t.enter("codeFlowValue"),i(a))}function i(a){return a===null||Y(a)?(t.exit("codeFlowValue"),s(a)):(t.consume(a),i)}function o(a){return t.exit("codeIndented"),e(a)}}function UA(t,e,n){const r=this;return s;function s(o){return r.parser.lazy[r.now().line]?n(o):Y(o)?(t.enter("lineEnding"),t.consume(o),t.exit("lineEnding"),s):Sm(t,e,i,"linePrefix",4,4)(o)}function i(o){return Y(o)?s(o):n(o)}}const qA={name:"codeText",previous:WA,resolve:HA,tokenize:GA};function HA(t){let e=t.length-4,n=3,r,s;if((t[n][1].type==="lineEnding"||t[n][1].type==="space")&&(t[e][1].type==="lineEnding"||t[e][1].type==="space")){for(r=n;++r<e;)if(t[r][1].type==="codeTextData"){t[n][1].type="codeTextPadding",t[e][1].type="codeTextPadding",n+=2,e-=2;break}}for(r=n-1,e++;++r<=e;)s===void 0?r!==e&&t[r][1].type!=="lineEnding"&&(s=r):(r===e||t[r][1].type==="lineEnding")&&(t[s][1].type="codeTextData",r!==s+2&&(t[s][1].end=t[r-1][1].end,t.splice(s+2,r-s-2),e-=r-s-2,r=s+2),s=void 0);return t}function WA(t){return t!==96||this.events[this.events.length-1][1].type==="characterEscape"}function GA(t,e,n){let r=0,s,i;return o;function o(d){return t.enter("codeText"),t.enter("codeTextSequence"),a(d)}function a(d){return d===96?(t.consume(d),r++,a):(t.exit("codeTextSequence"),l(d))}function l(d){return d===null?n(d):d===32?(t.enter("space"),t.consume(d),t.exit("space"),l):d===96?(i=t.enter("codeTextSequence"),s=0,u(d)):Y(d)?(t.enter("lineEnding"),t.consume(d),t.exit("lineEnding"),l):(t.enter("codeTextData"),c(d))}function c(d){return d===null||d===32||d===96||Y(d)?(t.exit("codeTextData"),l(d)):(t.consume(d),c)}function u(d){return d===96?(t.consume(d),s++,u):s===r?(t.exit("codeTextSequence"),t.exit("codeText"),e(d)):(i.type="codeTextData",c(d))}}class KA{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(e,r):e>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(e,n,r){const s=n||0;this.setCursor(Math.trunc(e));const i=this.right.splice(this.right.length-s,Number.POSITIVE_INFINITY);return r&&cr(this.left,r),i.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(e){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(e)}pushMany(e){this.setCursor(Number.POSITIVE_INFINITY),cr(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),cr(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e<this.left.length){const n=this.left.splice(e,Number.POSITIVE_INFINITY);cr(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-e,Number.POSITIVE_INFINITY);cr(this.left,n.reverse())}}}function cr(t,e){let n=0;if(e.length<1e4)t.push(...e);else for(;n<e.length;)t.push(...e.slice(n,n+1e4)),n+=1e4}function km(t){const e={};let n=-1,r,s,i,o,a,l,c;const u=new KA(t);for(;++n<u.length;){for(;n in e;)n=e[n];if(r=u.get(n),n&&r[1].type==="chunkFlow"&&u.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,i=0,i<l.length&&l[i][1].type==="lineEndingBlank"&&(i+=2),i<l.length&&l[i][1].type==="content"))for(;++i<l.length&&l[i][1].type!=="content";)l[i][1].type==="chunkText"&&(l[i][1]._isInFirstContentOfListItem=!0,i++);if(r[0]==="enter")r[1].contentType&&(Object.assign(e,QA(u,n)),n=e[n],c=!0);else if(r[1]._container){for(i=n,s=void 0;i--;)if(o=u.get(i),o[1].type==="lineEnding"||o[1].type==="lineEndingBlank")o[0]==="enter"&&(s&&(u.get(s)[1].type="lineEndingBlank"),o[1].type="lineEnding",s=i);else if(!(o[1].type==="linePrefix"||o[1].type==="listItemIndent"))break;s&&(r[1].end={...u.get(s)[1].start},a=u.slice(s,n),a.unshift(r),u.splice(s,n-s+1,a))}}return rt(t,0,Number.POSITIVE_INFINITY,u.slice(0)),!c}function QA(t,e){const n=t.get(e)[1],r=t.get(e)[2];let s=e-1;const i=[];let o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));const a=o.events,l=[],c={};let u,d,f=-1,h=n,p=0,m=0;const y=[m];for(;h;){for(;t.get(++s)[1]!==h;);i.push(s),h._tokenizer||(u=r.sliceStream(h),h.next||u.push(null),d&&o.defineSkip(h.start),h._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(u),h._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=h,h=h.next}for(h=n;++f<a.length;)a[f][0]==="exit"&&a[f-1][0]==="enter"&&a[f][1].type===a[f-1][1].type&&a[f][1].start.line!==a[f][1].end.line&&(m=f+1,y.push(m),h._tokenizer=void 0,h.previous=void 0,h=h.next);for(o.events=[],h?(h._tokenizer=void 0,h.previous=void 0):y.pop(),f=y.length;f--;){const g=a.slice(y[f],y[f+1]),b=i.pop();l.push([b,b+g.length-1]),t.splice(b,2,g)}for(l.reverse(),f=-1;++f<l.length;)c[p+l[f][0]]=p+l[f][1],p+=l[f][1]-l[f][0]-1;return c}const YA={resolve:XA,tokenize:ZA},JA={partial:!0,tokenize:eR};function XA(t){return km(t),t}function ZA(t,e){let n;return r;function r(a){return t.enter("content"),n=t.enter("chunkContent",{contentType:"content"}),s(a)}function s(a){return a===null?i(a):Y(a)?t.check(JA,o,i)(a):(t.consume(a),s)}function i(a){return t.exit("chunkContent"),t.exit("content"),e(a)}function o(a){return t.consume(a),t.exit("chunkContent"),n.next=t.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,s}}function eR(t,e,n){const r=this;return s;function s(o){return t.exit("chunkContent"),t.enter("lineEnding"),t.consume(o),t.exit("lineEnding"),ue(t,i,"linePrefix")}function i(o){if(o===null||Y(o))return n(o);const a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?e(o):t.interrupt(r.parser.constructs.flow,n,e)(o)}}function Em(t,e,n,r,s,i,o,a,l){const c=l||Number.POSITIVE_INFINITY;let u=0;return d;function d(g){return g===60?(t.enter(r),t.enter(s),t.enter(i),t.consume(g),t.exit(i),f):g===null||g===32||g===41||Es(g)?n(g):(t.enter(r),t.enter(o),t.enter(a),t.enter("chunkString",{contentType:"string"}),m(g))}function f(g){return g===62?(t.enter(i),t.consume(g),t.exit(i),t.exit(s),t.exit(r),e):(t.enter(a),t.enter("chunkString",{contentType:"string"}),h(g))}function h(g){return g===62?(t.exit("chunkString"),t.exit(a),f(g)):g===null||g===60||Y(g)?n(g):(t.consume(g),g===92?p:h)}function p(g){return g===60||g===62||g===92?(t.consume(g),h):h(g)}function m(g){return!u&&(g===null||g===41||me(g))?(t.exit("chunkString"),t.exit(a),t.exit(o),t.exit(r),e(g)):u<c&&g===40?(t.consume(g),u++,m):g===41?(t.consume(g),u--,m):g===null||g===32||g===40||Es(g)?n(g):(t.consume(g),g===92?y:m)}function y(g){return g===40||g===41||g===92?(t.consume(g),m):m(g)}}function Am(t,e,n,r,s,i){const o=this;let a=0,l;return c;function c(h){return t.enter(r),t.enter(s),t.consume(h),t.exit(s),t.enter(i),u}function u(h){return a>999||h===null||h===91||h===93&&!l||h===94&&!a&&"_hiddenFootnoteSupport"in o.parser.constructs?n(h):h===93?(t.exit(i),t.enter(s),t.consume(h),t.exit(s),t.exit(r),e):Y(h)?(t.enter("lineEnding"),t.consume(h),t.exit("lineEnding"),u):(t.enter("chunkString",{contentType:"string"}),d(h))}function d(h){return h===null||h===91||h===93||Y(h)||a++>999?(t.exit("chunkString"),u(h)):(t.consume(h),l||(l=!ae(h)),h===92?f:d)}function f(h){return h===91||h===92||h===93?(t.consume(h),a++,d):d(h)}}function Rm(t,e,n,r,s,i){let o;return a;function a(f){return f===34||f===39||f===40?(t.enter(r),t.enter(s),t.consume(f),t.exit(s),o=f===40?41:f,l):n(f)}function l(f){return f===o?(t.enter(s),t.consume(f),t.exit(s),t.exit(r),e):(t.enter(i),c(f))}function c(f){return f===o?(t.exit(i),l(o)):f===null?n(f):Y(f)?(t.enter("lineEnding"),t.consume(f),t.exit("lineEnding"),ue(t,c,"linePrefix")):(t.enter("chunkString",{contentType:"string"}),u(f))}function u(f){return f===o||f===null||Y(f)?(t.exit("chunkString"),c(f)):(t.consume(f),f===92?d:u)}function d(f){return f===o||f===92?(t.consume(f),u):u(f)}}function gr(t,e){let n;return r;function r(s){return Y(s)?(t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),n=!0,r):ae(s)?ue(t,r,n?"linePrefix":"lineSuffix")(s):e(s)}}const tR={name:"definition",tokenize:rR},nR={partial:!0,tokenize:sR};function rR(t,e,n){const r=this;let s;return i;function i(h){return t.enter("definition"),o(h)}function o(h){return Am.call(r,t,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function a(h){return s=st(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),h===58?(t.enter("definitionMarker"),t.consume(h),t.exit("definitionMarker"),l):n(h)}function l(h){return me(h)?gr(t,c)(h):c(h)}function c(h){return Em(t,u,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function u(h){return t.attempt(nR,d,d)(h)}function d(h){return ae(h)?ue(t,f,"whitespace")(h):f(h)}function f(h){return h===null||Y(h)?(t.exit("definition"),r.parser.defined.push(s),e(h)):n(h)}}function sR(t,e,n){return r;function r(a){return me(a)?gr(t,s)(a):n(a)}function s(a){return Rm(t,i,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function i(a){return ae(a)?ue(t,o,"whitespace")(a):o(a)}function o(a){return a===null||Y(a)?e(a):n(a)}}const iR={name:"hardBreakEscape",tokenize:oR};function oR(t,e,n){return r;function r(i){return t.enter("hardBreakEscape"),t.consume(i),s}function s(i){return Y(i)?(t.exit("hardBreakEscape"),e(i)):n(i)}}const aR={name:"headingAtx",resolve:lR,tokenize:cR};function lR(t,e){let n=t.length-2,r=3;if(t[r][1].type==="whitespace"&&(r+=2),n-2>r&&t[n][1].type==="whitespace"&&(n-=2),t[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&t[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r){const s={type:"atxHeadingText",start:t[r][1].start,end:t[n][1].end},i={type:"chunkText",start:t[r][1].start,end:t[n][1].end,contentType:"text"};rt(t,r,n-r+1,[["enter",s,e],["enter",i,e],["exit",i,e],["exit",s,e]])}return t}function cR(t,e,n){let r=0;return s;function s(u){return t.enter("atxHeading"),i(u)}function i(u){return t.enter("atxHeadingSequence"),o(u)}function o(u){return u===35&&r++<6?(t.consume(u),o):u===null||me(u)?(t.exit("atxHeadingSequence"),a(u)):n(u)}function a(u){return u===35?(t.enter("atxHeadingSequence"),l(u)):u===null||Y(u)?(t.exit("atxHeading"),e(u)):ae(u)?ue(t,a,"whitespace")(u):(t.enter("atxHeadingText"),c(u))}function l(u){return u===35?(t.consume(u),l):(t.exit("atxHeadingSequence"),a(u))}function c(u){return u===null||u===35||me(u)?(t.exit("atxHeadingText"),a(u)):(t.consume(u),c)}}const Mm=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Go=["pre","script","style","textarea"],uR={concrete:!0,name:"htmlFlow",resolveTo:hR,tokenize:fR},dR={partial:!0,tokenize:pR};function hR(t){let e=t.length;for(;e--&&!(t[e][0]==="enter"&&t[e][1].type==="htmlFlow"););return e>1&&t[e-2][1].type==="linePrefix"&&(t[e][1].start=t[e-2][1].start,t[e+1][1].start=t[e-2][1].start,t.splice(e-2,2)),t}function fR(t,e,n){const r=this;let s,i,o,a,l;return c;function c(I){return u(I)}function u(I){return t.enter("htmlFlow"),t.enter("htmlFlowData"),t.consume(I),d}function d(I){return I===33?(t.consume(I),f):I===47?(t.consume(I),i=!0,m):I===63?(t.consume(I),s=3,r.interrupt?e:S):Ce(I)?(t.consume(I),o=String.fromCharCode(I),y):n(I)}function f(I){return I===45?(t.consume(I),s=2,h):I===91?(t.consume(I),s=5,a=0,p):Ce(I)?(t.consume(I),s=4,r.interrupt?e:S):n(I)}function h(I){return I===45?(t.consume(I),r.interrupt?e:S):n(I)}function p(I){const de="CDATA[";return I===de.charCodeAt(a++)?(t.consume(I),a===de.length?r.interrupt?e:P:p):n(I)}function m(I){return Ce(I)?(t.consume(I),o=String.fromCharCode(I),y):n(I)}function y(I){if(I===null||I===47||I===62||me(I)){const de=I===47,W=o.toLowerCase();return!de&&!i&&Go.includes(W)?(s=1,r.interrupt?e(I):P(I)):Mm.includes(o.toLowerCase())?(s=6,de?(t.consume(I),g):r.interrupt?e(I):P(I)):(s=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(I):i?b(I):v(I))}return I===45||Ie(I)?(t.consume(I),o+=String.fromCharCode(I),y):n(I)}function g(I){return I===62?(t.consume(I),r.interrupt?e:P):n(I)}function b(I){return ae(I)?(t.consume(I),b):x(I)}function v(I){return I===47?(t.consume(I),x):I===58||I===95||Ce(I)?(t.consume(I),w):ae(I)?(t.consume(I),v):x(I)}function w(I){return I===45||I===46||I===58||I===95||Ie(I)?(t.consume(I),w):k(I)}function k(I){return I===61?(t.consume(I),_):ae(I)?(t.consume(I),k):v(I)}function _(I){return I===null||I===60||I===61||I===62||I===96?n(I):I===34||I===39?(t.consume(I),l=I,A):ae(I)?(t.consume(I),_):E(I)}function A(I){return I===l?(t.consume(I),l=null,D):I===null||Y(I)?n(I):(t.consume(I),A)}function E(I){return I===null||I===34||I===39||I===47||I===60||I===61||I===62||I===96||me(I)?k(I):(t.consume(I),E)}function D(I){return I===47||I===62||ae(I)?v(I):n(I)}function x(I){return I===62?(t.consume(I),M):n(I)}function M(I){return I===null||Y(I)?P(I):ae(I)?(t.consume(I),M):n(I)}function P(I){return I===45&&s===2?(t.consume(I),j):I===60&&s===1?(t.consume(I),V):I===62&&s===4?(t.consume(I),J):I===63&&s===3?(t.consume(I),S):I===93&&s===5?(t.consume(I),U):Y(I)&&(s===6||s===7)?(t.exit("htmlFlowData"),t.check(dR,ee,T)(I)):I===null||Y(I)?(t.exit("htmlFlowData"),T(I)):(t.consume(I),P)}function T(I){return t.check(Wo,$,ee)(I)}function $(I){return t.enter("lineEnding"),t.consume(I),t.exit("lineEnding"),L}function L(I){return I===null||Y(I)?T(I):(t.enter("htmlFlowData"),P(I))}function j(I){return I===45?(t.consume(I),S):P(I)}function V(I){return I===47?(t.consume(I),o="",q):P(I)}function q(I){if(I===62){const de=o.toLowerCase();return Go.includes(de)?(t.consume(I),J):P(I)}return Ce(I)&&o.length<8?(t.consume(I),o+=String.fromCharCode(I),q):P(I)}function U(I){return I===93?(t.consume(I),S):P(I)}function S(I){return I===62?(t.consume(I),J):I===45&&s===2?(t.consume(I),S):P(I)}function J(I){return I===null||Y(I)?(t.exit("htmlFlowData"),ee(I)):(t.consume(I),J)}function ee(I){return t.exit("htmlFlow"),e(I)}}function pR(t,e,n){return r;function r(s){return t.enter("lineEnding"),t.consume(s),t.exit("lineEnding"),t.attempt($r,e,n)}}const mR={name:"htmlText",tokenize:gR};function gR(t,e,n){const r=this;let s,i,o;return a;function a(S){return t.enter("htmlText"),t.enter("htmlTextData"),t.consume(S),l}function l(S){return S===33?(t.consume(S),c):S===47?(t.consume(S),k):S===63?(t.consume(S),v):Ce(S)?(t.consume(S),E):n(S)}function c(S){return S===45?(t.consume(S),u):S===91?(t.consume(S),i=0,p):Ce(S)?(t.consume(S),b):n(S)}function u(S){return S===45?(t.consume(S),h):n(S)}function d(S){return S===null?n(S):S===45?(t.consume(S),f):Y(S)?(o=d,V(S)):(t.consume(S),d)}function f(S){return S===45?(t.consume(S),h):d(S)}function h(S){return S===62?j(S):S===45?f(S):d(S)}function p(S){const J="CDATA[";return S===J.charCodeAt(i++)?(t.consume(S),i===J.length?m:p):n(S)}function m(S){return S===null?n(S):S===93?(t.consume(S),y):Y(S)?(o=m,V(S)):(t.consume(S),m)}function y(S){return S===93?(t.consume(S),g):m(S)}function g(S){return S===62?j(S):S===93?(t.consume(S),g):m(S)}function b(S){return S===null||S===62?j(S):Y(S)?(o=b,V(S)):(t.consume(S),b)}function v(S){return S===null?n(S):S===63?(t.consume(S),w):Y(S)?(o=v,V(S)):(t.consume(S),v)}function w(S){return S===62?j(S):v(S)}function k(S){return Ce(S)?(t.consume(S),_):n(S)}function _(S){return S===45||Ie(S)?(t.consume(S),_):A(S)}function A(S){return Y(S)?(o=A,V(S)):ae(S)?(t.consume(S),A):j(S)}function E(S){return S===45||Ie(S)?(t.consume(S),E):S===47||S===62||me(S)?D(S):n(S)}function D(S){return S===47?(t.consume(S),j):S===58||S===95||Ce(S)?(t.consume(S),x):Y(S)?(o=D,V(S)):ae(S)?(t.consume(S),D):j(S)}function x(S){return S===45||S===46||S===58||S===95||Ie(S)?(t.consume(S),x):M(S)}function M(S){return S===61?(t.consume(S),P):Y(S)?(o=M,V(S)):ae(S)?(t.consume(S),M):D(S)}function P(S){return S===null||S===60||S===61||S===62||S===96?n(S):S===34||S===39?(t.consume(S),s=S,T):Y(S)?(o=P,V(S)):ae(S)?(t.consume(S),P):(t.consume(S),$)}function T(S){return S===s?(t.consume(S),s=void 0,L):S===null?n(S):Y(S)?(o=T,V(S)):(t.consume(S),T)}function $(S){return S===null||S===34||S===39||S===60||S===61||S===96?n(S):S===47||S===62||me(S)?D(S):(t.consume(S),$)}function L(S){return S===47||S===62||me(S)?D(S):n(S)}function j(S){return S===62?(t.consume(S),t.exit("htmlTextData"),t.exit("htmlText"),e):n(S)}function V(S){return t.exit("htmlTextData"),t.enter("lineEnding"),t.consume(S),t.exit("lineEnding"),q}function q(S){return ae(S)?ue(t,U,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(S):U(S)}function U(S){return t.enter("htmlTextData"),o(S)}}const ml={name:"labelEnd",resolveAll:vR,resolveTo:wR,tokenize:xR},yR={tokenize:SR},bR={tokenize:TR},_R={tokenize:CR};function vR(t){let e=-1;const n=[];for(;++e<t.length;){const r=t[e][1];if(n.push(t[e]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const s=r.type==="labelImage"?4:2;r.type="data",e+=s}}return t.length!==n.length&&rt(t,0,t.length,n),t}function wR(t,e){let n=t.length,r=0,s,i,o;for(;n--;){const u=t[n][1];if(s){if(u.type==="link"||u.type==="labelLink"&&u._inactive)break;t[n][0]==="enter"&&u.type==="labelLink"&&(u._inactive=!0)}else if(i){if(t[n][0]==="enter"&&(u.type==="labelImage"||u.type==="labelLink")&&!u._balanced&&(s=n,u.type!=="labelLink")){r=2;break}}else u.type==="labelEnd"&&(i=n)}const a={type:t[s][1].type==="labelLink"?"link":"image",start:{...t[s][1].start},end:{...t[t.length-1][1].end}},l={type:"label",start:{...t[s][1].start},end:{...t[i][1].end}},c={type:"labelText",start:{...t[s+r+2][1].end},end:{...t[i-2][1].start}};return o=[["enter",a,e],["enter",l,e]],o=We(o,t.slice(s+1,s+r+3)),o=We(o,[["enter",c,e]]),o=We(o,ei(e.parser.constructs.insideSpan.null,t.slice(s+r+4,i-3),e)),o=We(o,[["exit",c,e],t[i-2],t[i-1],["exit",l,e]]),o=We(o,t.slice(i+1)),o=We(o,[["exit",a,e]]),rt(t,s,t.length,o),t}function xR(t,e,n){const r=this,s=r._labelStarts;let i,o;if(s){for(;s.length>0&&s[s.length-1]._balanced;)s.pop();i=s[s.length-1]}return a;function a(f){return i?i._inactive?d(f):(o=r.parser.defined.includes(st(r.sliceSerialize({start:i.end,end:r.now()}))),t.enter("labelEnd"),t.enter("labelMarker"),t.consume(f),t.exit("labelMarker"),t.exit("labelEnd"),l):n(f)}function l(f){return f===40?t.attempt(yR,u,o?u:d)(f):f===91?t.attempt(bR,u,o?c:d)(f):o?u(f):d(f)}function c(f){return t.attempt(_R,u,d)(f)}function u(f){return s.pop(),e(f)}function d(f){return i._balanced=!0,n(f)}}function SR(t,e,n){return r;function r(d){return t.enter("resource"),t.enter("resourceMarker"),t.consume(d),t.exit("resourceMarker"),s}function s(d){return me(d)?gr(t,i)(d):i(d)}function i(d){return d===41?u(d):Em(t,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(d)}function o(d){return me(d)?gr(t,l)(d):u(d)}function a(d){return n(d)}function l(d){return d===34||d===39||d===40?Rm(t,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(d):u(d)}function c(d){return me(d)?gr(t,u)(d):u(d)}function u(d){return d===41?(t.enter("resourceMarker"),t.consume(d),t.exit("resourceMarker"),t.exit("resource"),e):n(d)}}function TR(t,e,n){const r=this;return s;function s(a){return Am.call(r,t,i,o,"reference","referenceMarker","referenceString")(a)}function i(a){return r.parser.defined.includes(st(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?e(a):n(a)}function o(a){return n(a)}}function CR(t,e,n){return r;function r(i){return t.enter("reference"),t.enter("referenceMarker"),t.consume(i),t.exit("referenceMarker"),s}function s(i){return i===93?(t.enter("referenceMarker"),t.consume(i),t.exit("referenceMarker"),t.exit("reference"),e):n(i)}}const IR={name:"labelStartImage",resolveAll:ml.resolveAll,tokenize:kR};function kR(t,e,n){const r=this;let s;return i;function i(l){return t.enter("labelImage"),t.enter("labelImageMarker"),t.consume(l),t.exit("labelImageMarker"),o}function o(l){return l===91?(t.enter("labelMarker"),t.consume(l),t.exit("labelMarker"),s=t.exit("labelImage"),a):n(l)}function a(l){return l===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(l):(r._labelStarts=r._labelStarts||[],r._labelStarts.push(s),e(l))}}const ER={name:"labelStartLink",resolveAll:ml.resolveAll,tokenize:AR};function AR(t,e,n){const r=this;let s;return i;function i(a){return t.enter("labelLink"),t.enter("labelMarker"),t.consume(a),t.exit("labelMarker"),s=t.exit("labelLink"),o}function o(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):(r._labelStarts=r._labelStarts||[],r._labelStarts.push(s),e(a))}}const Ni={name:"lineEnding",tokenize:RR};function RR(t,e){return n;function n(r){return t.enter("lineEnding"),t.consume(r),t.exit("lineEnding"),ue(t,e,"linePrefix")}}const cs={name:"thematicBreak",tokenize:MR};function MR(t,e,n){let r=0,s;return i;function i(c){return t.enter("thematicBreak"),o(c)}function o(c){return s=c,a(c)}function a(c){return c===s?(t.enter("thematicBreakSequence"),l(c)):r>=3&&(c===null||Y(c))?(t.exit("thematicBreak"),e(c)):n(c)}function l(c){return c===s?(t.consume(c),r++,l):(t.exit("thematicBreakSequence"),ae(c)?ue(t,a,"whitespace")(c):a(c))}}const Oe={continuation:{tokenize:LR},exit:$R,name:"list",tokenize:OR},PR={partial:!0,tokenize:NR},DR={partial:!0,tokenize:FR};function OR(t,e,n){const r=this,s=r.events[r.events.length-1];let i=s&&s[1].type==="linePrefix"?s[2].sliceSerialize(s[1],!0).length:0,o=0;return a;function a(h){const p=r.containerState.type||(h===42||h===43||h===45?"listUnordered":"listOrdered");if(p==="listUnordered"?!r.containerState.marker||h===r.containerState.marker:qo(h)){if(r.containerState.type||(r.containerState.type=p,t.enter(p,{_container:!0})),p==="listUnordered")return t.enter("listItemPrefix"),h===42||h===45?t.check(cs,n,c)(h):c(h);if(!r.interrupt||h===49)return t.enter("listItemPrefix"),t.enter("listItemValue"),l(h)}return n(h)}function l(h){return qo(h)&&++o<10?(t.consume(h),l):(!r.interrupt||o<2)&&(r.containerState.marker?h===r.containerState.marker:h===41||h===46)?(t.exit("listItemValue"),c(h)):n(h)}function c(h){return t.enter("listItemMarker"),t.consume(h),t.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||h,t.check($r,r.interrupt?n:u,t.attempt(PR,f,d))}function u(h){return r.containerState.initialBlankLine=!0,i++,f(h)}function d(h){return ae(h)?(t.enter("listItemPrefixWhitespace"),t.consume(h),t.exit("listItemPrefixWhitespace"),f):n(h)}function f(h){return r.containerState.size=i+r.sliceSerialize(t.exit("listItemPrefix"),!0).length,e(h)}}function LR(t,e,n){const r=this;return r.containerState._closeFlow=void 0,t.check($r,s,i);function s(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,ue(t,e,"listItemIndent",r.containerState.size+1)(a)}function i(a){return r.containerState.furtherBlankLines||!ae(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,t.attempt(DR,e,o)(a))}function o(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,ue(t,t.attempt(Oe,e,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function FR(t,e,n){const r=this;return ue(t,s,"listItemIndent",r.containerState.size+1);function s(i){const o=r.events[r.events.length-1];return o&&o[1].type==="listItemIndent"&&o[2].sliceSerialize(o[1],!0).length===r.containerState.size?e(i):n(i)}}function $R(t){t.exit(this.containerState.type)}function NR(t,e,n){const r=this;return ue(t,s,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function s(i){const o=r.events[r.events.length-1];return!ae(i)&&o&&o[1].type==="listItemPrefixWhitespace"?e(i):n(i)}}const Mu={name:"setextUnderline",resolveTo:BR,tokenize:jR};function BR(t,e){const n=new As;let r=t.length,s,i,o;for(;r--;)if(t[r][0]==="enter"){if(t[r][1].type==="content"){s=r;break}t[r][1].type==="paragraph"&&(i=r)}else t[r][1].type==="content"&&n.add(r,1,[]),!o&&t[r][1].type==="definition"&&(o=r);const a={type:"setextHeading",start:{...t[s][1].start},end:{...t[t.length-1][1].end}};return t[i][1].type="setextHeadingText",o?(n.add(i,0,[["enter",a,e]]),n.add(o+1,0,[["exit",t[s][1],e]]),t[s][1].end={...t[o][1].end}):t[s][1]=a,n.add(t.length,0,[["exit",a,e]]),n.consume(t),t}function jR(t,e,n){const r=this;let s;return i;function i(c){let u=r.events.length,d;for(;u--;)if(r.events[u][1].type!=="lineEnding"&&r.events[u][1].type!=="linePrefix"&&r.events[u][1].type!=="content"){d=r.events[u][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||d)?(t.enter("setextHeadingLine"),s=c,o(c)):n(c)}function o(c){return t.enter("setextHeadingLineSequence"),a(c)}function a(c){return c===s?(t.consume(c),a):(t.exit("setextHeadingLineSequence"),ae(c)?ue(t,l,"lineSuffix")(c):l(c))}function l(c){return c===null||Y(c)?(t.exit("setextHeadingLine"),e(c)):n(c)}}const zR={tokenize:VR};function VR(t){const e=this,n=t.attempt($r,r,t.attempt(this.parser.constructs.flowInitial,s,ue(t,t.attempt(this.parser.constructs.flow,s,t.attempt(YA,s)),"linePrefix")));return n;function r(i){if(i===null){t.consume(i);return}return t.enter("lineEndingBlank"),t.consume(i),t.exit("lineEndingBlank"),e.currentConstruct=void 0,n}function s(i){if(i===null){t.consume(i);return}return t.enter("lineEnding"),t.consume(i),t.exit("lineEnding"),e.currentConstruct=void 0,n}}const UR={resolveAll:Dm()},qR=Pm("string"),HR=Pm("text");function Pm(t){return{resolveAll:Dm(t==="text"?WR:void 0),tokenize:e};function e(n){const r=this,s=this.parser.constructs[t],i=n.attempt(s,o,a);return o;function o(u){return c(u)?i(u):a(u)}function a(u){if(u===null){n.consume(u);return}return n.enter("data"),n.consume(u),l}function l(u){return c(u)?(n.exit("data"),i(u)):(n.consume(u),l)}function c(u){if(u===null)return!0;const d=s[u];let f=-1;if(d)for(;++f<d.length;){const h=d[f];if(!h.previous||h.previous.call(r,r.previous))return!0}return!1}}}function Dm(t){return e;function e(n,r){let s=-1,i;for(;++s<=n.length;)i===void 0?n[s]&&n[s][1].type==="data"&&(i=s,s++):(!n[s]||n[s][1].type!=="data")&&(s!==i+2&&(n[i][1].end=n[s-1][1].end,n.splice(i+2,s-i-2),s=i+2),i=void 0);return t?t(n,r):n}}function WR(t,e){const n=new As;let r=0;for(;++r<=t.length;)if((r===t.length||t[r][1].type==="lineEnding")&&t[r-1][1].type==="data"){const s=t[r-1][1],i=e.sliceStream(s);let o=i.length,a=-1,l=0,c;for(;o--;){const u=i[o];if(typeof u=="string"){for(a=u.length;u.charCodeAt(a-1)===32;)l++,a--;if(a)break;a=-1}else if(u===-2)c=!0,l++;else if(u!==-1){o++;break}}if(e._contentTypeTextTrailing&&r===t.length&&(l=0),l){const u={type:r===t.length||c||l<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:o?a:s.start._bufferIndex+a,_index:s.start._index+o,line:s.end.line,column:s.end.column-l,offset:s.end.offset-l},end:{...s.end}};s.end={...u.start},s.start.offset===s.end.offset?Object.assign(s,u):n.add(r,0,[["enter",u,e],["exit",u,e]])}r++}return n.consume(t),t}const GR={42:Oe,43:Oe,45:Oe,48:Oe,49:Oe,50:Oe,51:Oe,52:Oe,53:Oe,54:Oe,55:Oe,56:Oe,57:Oe,62:Tm},KR={91:tR},QR={[-2]:$i,[-1]:$i,32:$i},YR={35:aR,42:cs,45:[Mu,cs],60:uR,61:Mu,95:cs,96:Ru,126:Ru},JR={38:Im,92:Cm},XR={[-5]:Ni,[-4]:Ni,[-3]:Ni,33:IR,38:Im,42:Ho,60:[MA,mR],91:ER,92:[iR,Cm],93:ml,95:Ho,96:qA},ZR={null:[Ho,UR]},e2={null:[42,95]},t2={null:[]},n2=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:e2,contentInitial:KR,disable:t2,document:GR,flow:YR,flowInitial:QR,insideSpan:ZR,string:JR,text:XR},Symbol.toStringTag,{value:"Module"}));function r2(t,e,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const s={},i=[];let o=[],a=[];const l={attempt:A(k),check:A(_),consume:b,enter:v,exit:w,interrupt:A(_,{interrupt:!0})},c={code:null,containerState:{},defineSkip:m,events:[],now:p,parser:t,previous:null,sliceSerialize:f,sliceStream:h,write:d};let u=e.tokenize.call(c,l);return e.resolveAll&&i.push(e),c;function d(M){return o=We(o,M),y(),o[o.length-1]!==null?[]:(E(e,0),c.events=ei(i,c.events,c),c.events)}function f(M,P){return i2(h(M),P)}function h(M){return s2(o,M)}function p(){const{_bufferIndex:M,_index:P,line:T,column:$,offset:L}=r;return{_bufferIndex:M,_index:P,line:T,column:$,offset:L}}function m(M){s[M.line]=M.column,x()}function y(){for(;r._index<o.length;){const M=o[r._index];if(typeof M=="string"){const P=r._index;for(r._bufferIndex<0&&(r._bufferIndex=0);r._index===P&&r._bufferIndex<M.length;)g(M.charCodeAt(r._bufferIndex))}else g(M)}}function g(M){u=u(M)}function b(M){Y(M)?(r.line++,r.column=1,r.offset+=M===-3?2:1,x()):M!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),c.previous=M}function v(M,P){const T=P||{};return T.type=M,T.start=p(),c.events.push(["enter",T,c]),a.push(T),T}function w(M){const P=a.pop();return P.end=p(),c.events.push(["exit",P,c]),P}function k(M,P){E(M,P.from)}function _(M,P){P.restore()}function A(M,P){return T;function T($,L,j){let V,q,U,S;return Array.isArray($)?ee($):"tokenize"in $?ee([$]):J($);function J(K){return le;function le(te){const fe=te!==null&&K[te],O=te!==null&&K.null,G=[...Array.isArray(fe)?fe:fe?[fe]:[],...Array.isArray(O)?O:O?[O]:[]];return ee(G)(te)}}function ee(K){return V=K,q=0,K.length===0?j:I(K[q])}function I(K){return le;function le(te){return S=D(),U=K,K.partial||(c.currentConstruct=K),K.name&&c.parser.constructs.disable.null.includes(K.name)?W():K.tokenize.call(P?Object.assign(Object.create(c),P):c,l,de,W)(te)}}function de(K){return M(U,S),L}function W(K){return S.restore(),++q<V.length?I(V[q]):j}}}function E(M,P){M.resolveAll&&!i.includes(M)&&i.push(M),M.resolve&&rt(c.events,P,c.events.length-P,M.resolve(c.events.slice(P),c)),M.resolveTo&&(c.events=M.resolveTo(c.events,c))}function D(){const M=p(),P=c.previous,T=c.currentConstruct,$=c.events.length,L=Array.from(a);return{from:$,restore:j};function j(){r=M,c.previous=P,c.currentConstruct=T,c.events.length=$,a=L,x()}}function x(){r.line in s&&r.column<2&&(r.column=s[r.line],r.offset+=s[r.line]-1)}}function s2(t,e){const n=e.start._index,r=e.start._bufferIndex,s=e.end._index,i=e.end._bufferIndex;let o;if(n===s)o=[t[n].slice(r,i)];else{if(o=t.slice(n,s),r>-1){const a=o[0];typeof a=="string"?o[0]=a.slice(r):o.shift()}i>0&&o.push(t[s].slice(0,i))}return o}function i2(t,e){let n=-1;const r=[];let s;for(;++n<t.length;){const i=t[n];let o;if(typeof i=="string")o=i;else switch(i){case-5:{o="\r";break}case-4:{o=`
|
|
13
|
+
`;break}case-3:{o=`\r
|
|
14
|
+
`;break}case-2:{o=e?" ":" ";break}case-1:{if(!e&&s)continue;o=" ";break}default:o=String.fromCharCode(i)}s=i===-2,r.push(o)}return r.join("")}function o2(t){const r={constructs:vm([n2,...(t||{}).extensions||[]]),content:s(TA),defined:[],document:s(IA),flow:s(zR),lazy:{},string:s(qR),text:s(HR)};return r;function s(i){return o;function o(a){return r2(r,i,a)}}}function a2(t){for(;!km(t););return t}const Pu=/[\0\t\n\r]/g;function l2(){let t=1,e="",n=!0,r;return s;function s(i,o,a){i=e+(typeof i=="string"?i.toString():new TextDecoder(o||void 0).decode(i));const l=[];let c=0;for(e="",n&&(i.charCodeAt(0)===65279&&c++,n=void 0);c<i.length;){Pu.lastIndex=c;const u=Pu.exec(i),d=u&&u.index!==void 0?u.index:i.length,f=i.charCodeAt(d);if(!u){e=i.slice(c);break}if(f===10&&c===d&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),c<d&&(l.push(i.slice(c,d)),t+=d-c),f){case 0:{l.push(65533),t++;break}case 9:{const h=Math.ceil(t/4)*4;for(l.push(-2);t++<h;)l.push(-1);break}case 10:{l.push(-4),t=1;break}default:r=!0,t=1}c=d+1}return a&&(r&&l.push(-5),e&&l.push(e),l.push(null)),l}}const c2=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function u2(t){return t.replace(c2,d2)}function d2(t,e,n){if(e)return e;if(n.charCodeAt(0)===35){const s=n.charCodeAt(1),i=s===120||s===88;return wm(n.slice(i?2:1),i?16:10)}return pl(n)||t}const Om={}.hasOwnProperty;function h2(t,e,n){return e&&typeof e=="object"&&(n=e,e=void 0),f2(n)(a2(o2(n).document().write(l2()(t,e,!0))))}function f2(t){const e={afterExit:[],beforeEnter:[],transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:o(St),autolinkProtocol:x,autolinkEmail:x,atxHeading:o(Tn),blockQuote:o(G),characterEscape:x,characterReference:x,codeFenced:o(se),codeFencedFenceInfo:a,codeFencedFenceMeta:a,codeIndented:o(se,a),codeText:o(we,a),codeTextData:x,data:x,codeFlowValue:x,definition:o(Zn),definitionDestinationString:a,definitionLabelString:a,definitionTitleString:a,emphasis:o(xt),hardBreakEscape:o(He),hardBreakTrailing:o(He),htmlFlow:o(Qe,a),htmlFlowData:x,htmlText:o(Qe,a),htmlTextData:x,image:o(Ft),label:a,link:o(St),listItem:o(Cn),listItemValue:h,listOrdered:o(Kt,f),listUnordered:o(Kt),paragraph:o(Tt),reference:de,referenceString:a,resourceDestinationString:a,resourceTitleString:a,setextHeading:o(Tn),strong:o(Ct),thematicBreak:o(gg)},exit:{atxHeading:c(),atxHeadingSequence:_,autolink:c(),autolinkEmail:O,autolinkProtocol:fe,blockQuote:c(),characterEscapeValue:M,characterReferenceMarkerHexadecimal:K,characterReferenceMarkerNumeric:K,characterReferenceValue:le,characterReference:te,codeFenced:c(g),codeFencedFence:y,codeFencedFenceInfo:p,codeFencedFenceMeta:m,codeFlowValue:M,codeIndented:c(b),codeText:c(j),codeTextData:M,data:M,definition:c(),definitionDestinationString:k,definitionLabelString:v,definitionTitleString:w,emphasis:c(),hardBreakEscape:c(T),hardBreakTrailing:c(T),htmlFlow:c($),htmlFlowData:M,htmlText:c(L),htmlTextData:M,image:c(q),label:S,labelText:U,lineEnding:P,link:c(V),listItem:c(),listOrdered:c(),listUnordered:c(),paragraph:c(),referenceString:W,resourceDestinationString:J,resourceTitleString:ee,resource:I,setextHeading:c(D),setextHeadingLineSequence:E,setextHeadingText:A,strong:c(),thematicBreak:c()}};Lm(e,(t||{}).mdastExtensions||[]);const n={};return r;function r(F){let z={type:"root",children:[],position:void 0};const re={stack:[z],tokenStack:[],config:e,enter:l,exit:u,buffer:a,resume:d,data:n},oe=[],Pe=[];let be=-1;for(;++be<F.length;)if(Pe.push(F[be]),F[be][1].type==="listOrdered"||F[be][1].type==="listUnordered")if(F[be][0]==="enter")oe.push(Pe.length-1);else{const De=oe.pop();i(Pe,De)}for(F=Pe,be=-1;++be<F.length;){const De=e[F[be][0]];F[be][0]==="enter"&&e.beforeEnter.length>0&&s(e.beforeEnter,{...re,sliceSerialize:F[be][2].sliceSerialize},F[be][1]),Om.call(De,F[be][1].type)&&De[F[be][1].type].call({...re,sliceSerialize:F[be][2].sliceSerialize},F[be][1]),F[be][0]==="exit"&&e.afterExit.length>0&&s(e.afterExit,{...re,sliceSerialize:F[be][2].sliceSerialize},F[be][1])}if(re.tokenStack.length>0){const De=re.tokenStack[re.tokenStack.length-1];(De[1]||Du).call(re,void 0,De[0])}for(z.position={start:$t(F.length>0?F[0][1].start:{line:1,column:1,offset:0}),end:$t(F.length>0?F[F.length-2][1].end:{line:1,column:1,offset:0})},be=-1;++be<e.transforms.length;)z=e.transforms[be](z)||z;return z}function s(F,z,re){let oe=-1;for(;++oe<F.length;)F[oe].call(z,re)}function i(F,z){const re=F.length-1;let oe=z-1,Pe=-1,be=!1,De,ut,er,tr;const nr=[];for(;++oe<=re;){const Be=F[oe];switch(Be[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{Be[0]==="enter"?Pe++:Pe--,tr=void 0;break}case"lineEndingBlank":{Be[0]==="enter"&&(De&&!tr&&!Pe&&!er&&(er=oe),tr=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:tr=void 0}if(!Pe&&Be[0]==="enter"&&Be[1].type==="listItemPrefix"||Pe===-1&&Be[0]==="exit"&&(Be[1].type==="listUnordered"||Be[1].type==="listOrdered")){if(De){let In=oe;for(ut=void 0;In--;){const It=F[In];if(It[1].type==="lineEnding"||It[1].type==="lineEndingBlank"){if(It[0]==="exit")continue;ut&&(F[ut][1].type="lineEndingBlank",be=!0),It[1].type="lineEnding",ut=In}else if(!(It[1].type==="linePrefix"||It[1].type==="blockQuotePrefix"||It[1].type==="blockQuotePrefixWhitespace"||It[1].type==="blockQuoteMarker"||It[1].type==="listItemIndent"))break}er&&(!ut||er<ut)&&(De._spread=!0),De.end=Object.assign({},ut?F[ut][1].start:Be[1].end),nr.push({at:ut||oe,event:["exit",De,Be[2]]})}if(Be[1].type==="listItemPrefix"){const In={type:"listItem",_spread:!1,start:Object.assign({},Be[1].start),end:void 0};De=In,nr.push({at:oe,event:["enter",In,Be[2]]}),er=void 0,tr=!0}}}const Rl=F.splice(z);let ai=0;for(oe=-1;++oe<Rl.length;){for(;ai<nr.length&&nr[ai].at===z+oe;)F.push(nr[ai++].event);F.push(Rl[oe])}F[z][1]._spread=be}function o(F,z){return re;function re(oe){l.call(this,F(oe),oe),z&&z.call(this,oe)}}function a(){this.stack.push({type:"fragment",children:[]})}function l(F,z,re){this.stack[this.stack.length-1].children.push(F),this.stack.push(F),this.tokenStack.push([z,re||void 0]),F.position={start:$t(z.start),end:void 0}}function c(F){return z;function z(re){F&&F.call(this,re),u.call(this,re)}}function u(F,z){const re=this.stack.pop(),oe=this.tokenStack.pop();if(!oe)throw new Error("Cannot close `"+F.type+"` ("+mr({start:F.start,end:F.end})+"): it’s not open");oe[0].type!==F.type&&(z?z.call(this,F,oe[0]):(oe[1]||Du).call(this,F,oe[0])),re.position.end=$t(F.end)}function d(){return Zs(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function h(F){if(this.data.expectingFirstListItemValue){const z=this.stack[this.stack.length-2];z.start=Number.parseInt(this.sliceSerialize(F),10),this.data.expectingFirstListItemValue=void 0}}function p(){const F=this.resume(),z=this.stack[this.stack.length-1];z.lang=F}function m(){const F=this.resume(),z=this.stack[this.stack.length-1];z.meta=F}function y(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function g(){const F=this.resume(),z=this.stack[this.stack.length-1];z.value=F.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function b(){const F=this.resume(),z=this.stack[this.stack.length-1];z.value=F.replace(/(\r?\n|\r)$/g,"")}function v(F){const z=this.resume(),re=this.stack[this.stack.length-1];re.label=z,re.identifier=st(this.sliceSerialize(F)).toLowerCase()}function w(){const F=this.resume(),z=this.stack[this.stack.length-1];z.title=F}function k(){const F=this.resume(),z=this.stack[this.stack.length-1];z.url=F}function _(F){const z=this.stack[this.stack.length-1];if(!z.depth){const re=this.sliceSerialize(F).length;z.depth=re}}function A(){this.data.setextHeadingSlurpLineEnding=!0}function E(F){const z=this.stack[this.stack.length-1];z.depth=this.sliceSerialize(F).codePointAt(0)===61?1:2}function D(){this.data.setextHeadingSlurpLineEnding=void 0}function x(F){const re=this.stack[this.stack.length-1].children;let oe=re[re.length-1];(!oe||oe.type!=="text")&&(oe=Br(),oe.position={start:$t(F.start),end:void 0},re.push(oe)),this.stack.push(oe)}function M(F){const z=this.stack.pop();z.value+=this.sliceSerialize(F),z.position.end=$t(F.end)}function P(F){const z=this.stack[this.stack.length-1];if(this.data.atHardBreak){const re=z.children[z.children.length-1];re.position.end=$t(F.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&e.canContainEols.includes(z.type)&&(x.call(this,F),M.call(this,F))}function T(){this.data.atHardBreak=!0}function $(){const F=this.resume(),z=this.stack[this.stack.length-1];z.value=F}function L(){const F=this.resume(),z=this.stack[this.stack.length-1];z.value=F}function j(){const F=this.resume(),z=this.stack[this.stack.length-1];z.value=F}function V(){const F=this.stack[this.stack.length-1];if(this.data.inReference){const z=this.data.referenceType||"shortcut";F.type+="Reference",F.referenceType=z,delete F.url,delete F.title}else delete F.identifier,delete F.label;this.data.referenceType=void 0}function q(){const F=this.stack[this.stack.length-1];if(this.data.inReference){const z=this.data.referenceType||"shortcut";F.type+="Reference",F.referenceType=z,delete F.url,delete F.title}else delete F.identifier,delete F.label;this.data.referenceType=void 0}function U(F){const z=this.sliceSerialize(F),re=this.stack[this.stack.length-2];re.label=u2(z),re.identifier=st(z).toLowerCase()}function S(){const F=this.stack[this.stack.length-1],z=this.resume(),re=this.stack[this.stack.length-1];if(this.data.inReference=!0,re.type==="link"){const oe=F.children;re.children=oe}else re.alt=z}function J(){const F=this.resume(),z=this.stack[this.stack.length-1];z.url=F}function ee(){const F=this.resume(),z=this.stack[this.stack.length-1];z.title=F}function I(){this.data.inReference=void 0}function de(){this.data.referenceType="collapsed"}function W(F){const z=this.resume(),re=this.stack[this.stack.length-1];re.label=z,re.identifier=st(this.sliceSerialize(F)).toLowerCase(),this.data.referenceType="full"}function K(F){this.data.characterReferenceType=F.type}function le(F){const z=this.sliceSerialize(F),re=this.data.characterReferenceType;let oe;re?(oe=wm(z,re==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):oe=pl(z);const Pe=this.stack[this.stack.length-1];Pe.value+=oe}function te(F){const z=this.stack.pop();z.position.end=$t(F.end)}function fe(F){M.call(this,F);const z=this.stack[this.stack.length-1];z.url=this.sliceSerialize(F)}function O(F){M.call(this,F);const z=this.stack[this.stack.length-1];z.url="mailto:"+this.sliceSerialize(F)}function G(){return{type:"blockquote",children:[],position:void 0}}function se(){return{type:"code",lang:null,meta:null,value:"",position:void 0}}function we(){return{type:"inlineCode",value:"",position:void 0}}function Zn(){return{type:"definition",identifier:"",label:null,title:null,url:"",position:void 0}}function xt(){return{type:"emphasis",children:[],position:void 0}}function Tn(){return{type:"heading",depth:0,children:[],position:void 0}}function He(){return{type:"break",position:void 0}}function Qe(){return{type:"html",value:"",position:void 0}}function Ft(){return{type:"image",title:null,url:"",alt:null,position:void 0}}function St(){return{type:"link",title:null,url:"",children:[],position:void 0}}function Kt(F){return{type:"list",ordered:F.type==="listOrdered",start:null,spread:F._spread,children:[],position:void 0}}function Cn(F){return{type:"listItem",spread:F._spread,checked:null,children:[],position:void 0}}function Tt(){return{type:"paragraph",children:[],position:void 0}}function Ct(){return{type:"strong",children:[],position:void 0}}function Br(){return{type:"text",value:"",position:void 0}}function gg(){return{type:"thematicBreak",position:void 0}}}function $t(t){return{line:t.line,column:t.column,offset:t.offset}}function Lm(t,e){let n=-1;for(;++n<e.length;){const r=e[n];Array.isArray(r)?Lm(t,r):p2(t,r)}}function p2(t,e){let n;for(n in e)if(Om.call(e,n))switch(n){case"canContainEols":{const r=e[n];r&&t[n].push(...r);break}case"transforms":{const r=e[n];r&&t[n].push(...r);break}case"afterExit":case"beforeEnter":{const r=e[n];r&&t[n].push(r);break}case"enter":case"exit":{const r=e[n];r&&Object.assign(t[n],r);break}}}function Du(t,e){throw t?new Error("Cannot close `"+t.type+"` ("+mr({start:t.start,end:t.end})+"): a different token (`"+e.type+"`, "+mr({start:e.start,end:e.end})+") is open"):new Error("Cannot close document, a token (`"+e.type+"`, "+mr({start:e.start,end:e.end})+") is still open")}function m2(t){const e=this;e.parser=n;function n(r){return h2(r,{...e.data("settings"),...t,extensions:e.data("micromarkExtensions")||[],mdastExtensions:e.data("fromMarkdownExtensions")||[]})}}function g2(t,e){const n={type:"element",tagName:"blockquote",properties:{},children:t.wrap(t.all(e),!0)};return t.patch(e,n),t.applyData(e,n)}function y2(t,e){const n={type:"element",tagName:"br",properties:{},children:[]};return t.patch(e,n),[t.applyData(e,n),{type:"text",value:`
|
|
15
|
+
`}]}function b2(t,e){const n=e.value?e.value+`
|
|
16
|
+
`:"",r={},s=e.lang?e.lang.split(/\s+/):[];s.length>0&&(r.className=["language-"+s[0]]);let i={type:"element",tagName:"code",properties:r,children:[{type:"text",value:n}]};return e.meta&&(i.data={meta:e.meta}),t.patch(e,i),i=t.applyData(e,i),i={type:"element",tagName:"pre",properties:{},children:[i]},t.patch(e,i),i}function _2(t,e){const n={type:"element",tagName:"del",properties:{},children:t.all(e)};return t.patch(e,n),t.applyData(e,n)}function v2(t,e){const n={type:"element",tagName:"em",properties:{},children:t.all(e)};return t.patch(e,n),t.applyData(e,n)}function w2(t,e){const n=typeof t.options.clobberPrefix=="string"?t.options.clobberPrefix:"user-content-",r=String(e.identifier).toUpperCase(),s=Xn(r.toLowerCase()),i=t.footnoteOrder.indexOf(r);let o,a=t.footnoteCounts.get(r);a===void 0?(a=0,t.footnoteOrder.push(r),o=t.footnoteOrder.length):o=i+1,a+=1,t.footnoteCounts.set(r,a);const l={type:"element",tagName:"a",properties:{href:"#"+n+"fn-"+s,id:n+"fnref-"+s+(a>1?"-"+a:""),dataFootnoteRef:!0,ariaDescribedBy:["footnote-label"]},children:[{type:"text",value:String(o)}]};t.patch(e,l);const c={type:"element",tagName:"sup",properties:{},children:[l]};return t.patch(e,c),t.applyData(e,c)}function x2(t,e){const n={type:"element",tagName:"h"+e.depth,properties:{},children:t.all(e)};return t.patch(e,n),t.applyData(e,n)}function S2(t,e){if(t.options.allowDangerousHtml){const n={type:"raw",value:e.value};return t.patch(e,n),t.applyData(e,n)}}function Fm(t,e){const n=e.referenceType;let r="]";if(n==="collapsed"?r+="[]":n==="full"&&(r+="["+(e.label||e.identifier)+"]"),e.type==="imageReference")return[{type:"text",value:"!["+e.alt+r}];const s=t.all(e),i=s[0];i&&i.type==="text"?i.value="["+i.value:s.unshift({type:"text",value:"["});const o=s[s.length-1];return o&&o.type==="text"?o.value+=r:s.push({type:"text",value:r}),s}function T2(t,e){const n=String(e.identifier).toUpperCase(),r=t.definitionById.get(n);if(!r)return Fm(t,e);const s={src:Xn(r.url||"")};e.alt!==null&&e.alt!==void 0&&(s.alt=e.alt),r.title!==null&&r.title!==void 0&&(s.title=r.title);const i={type:"element",tagName:"img",properties:s,children:[]};return t.patch(e,i),t.applyData(e,i)}function C2(t,e){const n={src:Xn(e.url)};e.alt!==null&&e.alt!==void 0&&(n.alt=e.alt),e.title!==null&&e.title!==void 0&&(n.title=e.title);const r={type:"element",tagName:"img",properties:n,children:[]};return t.patch(e,r),t.applyData(e,r)}function I2(t,e){const n={type:"text",value:e.value.replace(/\r?\n|\r/g," ")};t.patch(e,n);const r={type:"element",tagName:"code",properties:{},children:[n]};return t.patch(e,r),t.applyData(e,r)}function k2(t,e){const n=String(e.identifier).toUpperCase(),r=t.definitionById.get(n);if(!r)return Fm(t,e);const s={href:Xn(r.url||"")};r.title!==null&&r.title!==void 0&&(s.title=r.title);const i={type:"element",tagName:"a",properties:s,children:t.all(e)};return t.patch(e,i),t.applyData(e,i)}function E2(t,e){const n={href:Xn(e.url)};e.title!==null&&e.title!==void 0&&(n.title=e.title);const r={type:"element",tagName:"a",properties:n,children:t.all(e)};return t.patch(e,r),t.applyData(e,r)}function A2(t,e,n){const r=t.all(e),s=n?R2(n):$m(e),i={},o=[];if(typeof e.checked=="boolean"){const u=r[0];let d;u&&u.type==="element"&&u.tagName==="p"?d=u:(d={type:"element",tagName:"p",properties:{},children:[]},r.unshift(d)),d.children.length>0&&d.children.unshift({type:"text",value:" "}),d.children.unshift({type:"element",tagName:"input",properties:{type:"checkbox",checked:e.checked,disabled:!0},children:[]}),i.className=["task-list-item"]}let a=-1;for(;++a<r.length;){const u=r[a];(s||a!==0||u.type!=="element"||u.tagName!=="p")&&o.push({type:"text",value:`
|
|
17
|
+
`}),u.type==="element"&&u.tagName==="p"&&!s?o.push(...u.children):o.push(u)}const l=r[r.length-1];l&&(s||l.type!=="element"||l.tagName!=="p")&&o.push({type:"text",value:`
|
|
18
|
+
`});const c={type:"element",tagName:"li",properties:i,children:o};return t.patch(e,c),t.applyData(e,c)}function R2(t){let e=!1;if(t.type==="list"){e=t.spread||!1;const{children:n}=t;let r=-1;for(;!e&&++r<n.length;)e=$m(n[r])}return e}function $m(t){const{spread:e}=t;return e??t.children.length>1}function M2(t,e){const n={},r=t.all(e);let s=-1;for(typeof e.start=="number"&&e.start!==1&&(n.start=e.start);++s<r.length;){const o=r[s];if(o.type==="element"&&o.tagName==="li"&&o.properties&&Array.isArray(o.properties.className)&&o.properties.className.includes("task-list-item")){n.className=["contains-task-list"];break}}const i={type:"element",tagName:e.ordered?"ol":"ul",properties:n,children:t.wrap(r,!0)};return t.patch(e,i),t.applyData(e,i)}function P2(t,e){const n={type:"element",tagName:"p",properties:{},children:t.all(e)};return t.patch(e,n),t.applyData(e,n)}function D2(t,e){const n={type:"root",children:t.wrap(t.all(e))};return t.patch(e,n),t.applyData(e,n)}function O2(t,e){const n={type:"element",tagName:"strong",properties:{},children:t.all(e)};return t.patch(e,n),t.applyData(e,n)}function L2(t,e){const n=t.all(e),r=n.shift(),s=[];if(r){const o={type:"element",tagName:"thead",properties:{},children:t.wrap([r],!0)};t.patch(e.children[0],o),s.push(o)}if(n.length>0){const o={type:"element",tagName:"tbody",properties:{},children:t.wrap(n,!0)},a=ul(e.children[1]),l=fm(e.children[e.children.length-1]);a&&l&&(o.position={start:a,end:l}),s.push(o)}const i={type:"element",tagName:"table",properties:{},children:t.wrap(s,!0)};return t.patch(e,i),t.applyData(e,i)}function F2(t,e,n){const r=n?n.children:void 0,i=(r?r.indexOf(e):1)===0?"th":"td",o=n&&n.type==="table"?n.align:void 0,a=o?o.length:e.children.length;let l=-1;const c=[];for(;++l<a;){const d=e.children[l],f={},h=o?o[l]:void 0;h&&(f.align=h);let p={type:"element",tagName:i,properties:f,children:[]};d&&(p.children=t.all(d),t.patch(d,p),p=t.applyData(d,p)),c.push(p)}const u={type:"element",tagName:"tr",properties:{},children:t.wrap(c,!0)};return t.patch(e,u),t.applyData(e,u)}function $2(t,e){const n={type:"element",tagName:"td",properties:{},children:t.all(e)};return t.patch(e,n),t.applyData(e,n)}const Ou=9,Lu=32;function N2(t){const e=String(t),n=/\r?\n|\r/g;let r=n.exec(e),s=0;const i=[];for(;r;)i.push(Fu(e.slice(s,r.index),s>0,!0),r[0]),s=r.index+r[0].length,r=n.exec(e);return i.push(Fu(e.slice(s),s>0,!1)),i.join("")}function Fu(t,e,n){let r=0,s=t.length;if(e){let i=t.codePointAt(r);for(;i===Ou||i===Lu;)r++,i=t.codePointAt(r)}if(n){let i=t.codePointAt(s-1);for(;i===Ou||i===Lu;)s--,i=t.codePointAt(s-1)}return s>r?t.slice(r,s):""}function B2(t,e){const n={type:"text",value:N2(String(e.value))};return t.patch(e,n),t.applyData(e,n)}function j2(t,e){const n={type:"element",tagName:"hr",properties:{},children:[]};return t.patch(e,n),t.applyData(e,n)}const z2={blockquote:g2,break:y2,code:b2,delete:_2,emphasis:v2,footnoteReference:w2,heading:x2,html:S2,imageReference:T2,image:C2,inlineCode:I2,linkReference:k2,link:E2,listItem:A2,list:M2,paragraph:P2,root:D2,strong:O2,table:L2,tableCell:$2,tableRow:F2,text:B2,thematicBreak:j2,toml:ts,yaml:ts,definition:ts,footnoteDefinition:ts};function ts(){}const Nm=-1,ti=0,yr=1,Rs=2,gl=3,yl=4,bl=5,_l=6,Bm=7,jm=8,{defineProperty:V2}=Object,zm=typeof self=="object"?self:globalThis,$u=(t,e)=>{switch(t){case"Function":case"SharedWorker":case"Worker":case"eval":case"setInterval":case"setTimeout":throw new TypeError("unable to deserialize "+t)}return new zm[t](e)},U2=(t,e)=>{const n=(s,i)=>(t.set(i,s),s),r=s=>{if(t.has(s))return t.get(s);const[i,o]=e[s];switch(i){case ti:case Nm:return n(o,s);case yr:{const a=n([],s);for(const l of o)a.push(r(l));return a}case Rs:{const a=n({},s);for(const[l,c]of o){const u=r(l),d=r(c);u==="__proto__"?V2(a,u,{value:d,configurable:!0,enumerable:!0,writable:!0}):a[u]=d}return a}case gl:return n(new Date(o),s);case yl:{const{source:a,flags:l}=o;return n(new RegExp(a,l),s)}case bl:{const a=n(new Map,s);for(const[l,c]of o)a.set(r(l),r(c));return a}case _l:{const a=n(new Set,s);for(const l of o)a.add(r(l));return a}case Bm:{const{name:a,message:l}=o;return n(typeof zm[a]=="function"?$u(a,l):new Error(l),s)}case jm:return n(BigInt(o),s);case"BigInt":return n(Object(BigInt(o)),s);case"ArrayBuffer":return n(new Uint8Array(o).buffer,o);case"DataView":{const{buffer:a}=new Uint8Array(o);return n(new DataView(a),o)}case"-0":return-0}return n($u(i,o),s)};return r},Nu=t=>U2(new Map,t)(0),en="",{toString:q2}={},{keys:H2,is:W2}=Object,ur=t=>{const e=typeof t;if(e!=="object"||!t)return[ti,e];const n=q2.call(t).slice(8,-1);switch(n){case"Array":return[yr,en];case"Object":return[Rs,en];case"Date":return[gl,en];case"RegExp":return[yl,en];case"Map":return[bl,en];case"Set":return[_l,en];case"DataView":return[yr,n]}return n.includes("Array")?[yr,n]:t instanceof Error?[Bm,t.name||"Error"]:[Rs,n]},ns=([t,e])=>t===ti&&(e==="function"||e==="symbol"),G2=(t,e,n,r)=>{const s=(o,a)=>{const l=r.push(o)-1;return n.set(a,l),l},i=o=>{if(n.has(o))return n.get(o);let[a,l]=ur(o);switch(a){case ti:{let u=o;switch(l){case"bigint":a=jm,u=o.toString();break;case"number":if(!o&&W2(o,-0))return r.push(["-0"])-1;break;case"function":case"symbol":if(t)throw new TypeError("unable to serialize "+l);u=null;break;case"undefined":return s([Nm],o)}return s([a,u],o)}case yr:{if(l){let f=o;return l==="DataView"?f=new Uint8Array(o.buffer):l==="ArrayBuffer"&&(f=new Uint8Array(o)),s([l,[...f]],o)}const u=[],d=s([a,u],o);for(const f of o)u.push(i(f));return d}case Rs:{if(l)switch(l){case"BigInt":return s([l,o.toString()],o);case"Boolean":case"Number":case"String":return s([l,o.valueOf()],o)}if(e&&"toJSON"in o)return i(o.toJSON());const u=[],d=s([a,u],o);for(const f of H2(o))(t||!ns(ur(o[f])))&&u.push([i(f),i(o[f])]);return d}case gl:return s([a,isNaN(o.getTime())?en:o.toISOString()],o);case yl:{const{source:u,flags:d}=o;return s([a,{source:u,flags:d}],o)}case bl:{const u=[],d=s([a,u],o);for(const[f,h]of o)(t||!(ns(ur(f))||ns(ur(h))))&&u.push([i(f),i(h)]);return d}case _l:{const u=[],d=s([a,u],o);for(const f of o)(t||!ns(ur(f)))&&u.push(i(f));return d}}const{message:c}=o;return s([a,{name:l,message:c}],o)};return i},Bu=(t,{json:e,lossy:n}={})=>{const r=[];return G2(!(e||n),!!e,new Map,r)(t),r},Ms=typeof structuredClone=="function"?(t,e)=>e&&("json"in e||"lossy"in e)?Nu(Bu(t,e)):structuredClone(t):(t,e)=>Nu(Bu(t,e));function K2(t,e){const n=[{type:"text",value:"↩"}];return e>1&&n.push({type:"element",tagName:"sup",properties:{},children:[{type:"text",value:String(e)}]}),n}function Q2(t,e){return"Back to reference "+(t+1)+(e>1?"-"+e:"")}function Y2(t){const e=typeof t.options.clobberPrefix=="string"?t.options.clobberPrefix:"user-content-",n=t.options.footnoteBackContent||K2,r=t.options.footnoteBackLabel||Q2,s=t.options.footnoteLabel||"Footnotes",i=t.options.footnoteLabelTagName||"h2",o=t.options.footnoteLabelProperties||{className:["sr-only"]},a=[],l=[];let c=-1;for(;++c<t.footnoteOrder.length;){const u=t.footnoteById.get(t.footnoteOrder[c]);u&&(a[c]=t.all(u))}for(c=-1;++c<t.footnoteOrder.length;){const u=t.footnoteById.get(t.footnoteOrder[c]);if(!u)continue;const d=a[c],f=String(u.identifier).toUpperCase(),h=Xn(f.toLowerCase());let p=0;const m=[],y=t.footnoteCounts.get(f);for(;y!==void 0&&++p<=y;){m.length>0&&m.push({type:"text",value:" "});let v=typeof n=="string"?n:n(c,p);typeof v=="string"&&(v={type:"text",value:v}),m.push({type:"element",tagName:"a",properties:{href:"#"+e+"fnref-"+h+(p>1?"-"+p:""),dataFootnoteBackref:"",ariaLabel:typeof r=="string"?r:r(c,p),className:["data-footnote-backref"]},children:Array.isArray(v)?v:[v]})}const g=d[d.length-1];if(g&&g.type==="element"&&g.tagName==="p"){const v=g.children[g.children.length-1];v&&v.type==="text"?v.value+=" ":g.children.push({type:"text",value:" "}),g.children.push(...m)}else d.push(...m);const b={type:"element",tagName:"li",properties:{id:e+"fn-"+h},children:t.wrap(d,!0)};t.patch(u,b),l.push(b)}if(l.length!==0)return{type:"element",tagName:"section",properties:{dataFootnotes:!0,className:["footnotes"]},children:[{type:"element",tagName:i,properties:{...Ms(o),id:"footnote-label"},children:[{type:"text",value:s}]},{type:"text",value:`
|
|
19
|
+
`},{type:"element",tagName:"ol",properties:{},children:t.wrap(l,!0)},{type:"text",value:`
|
|
20
|
+
`}]}}const ni=(function(t){if(t==null)return eM;if(typeof t=="function")return ri(t);if(typeof t=="object")return Array.isArray(t)?J2(t):X2(t);if(typeof t=="string")return Z2(t);throw new Error("Expected function, string, or object as test")});function J2(t){const e=[];let n=-1;for(;++n<t.length;)e[n]=ni(t[n]);return ri(r);function r(...s){let i=-1;for(;++i<e.length;)if(e[i].apply(this,s))return!0;return!1}}function X2(t){const e=t;return ri(n);function n(r){const s=r;let i;for(i in t)if(s[i]!==e[i])return!1;return!0}}function Z2(t){return ri(e);function e(n){return n&&n.type===t}}function ri(t){return e;function e(n,r,s){return!!(tM(n)&&t.call(this,n,typeof r=="number"?r:void 0,s||void 0))}}function eM(){return!0}function tM(t){return t!==null&&typeof t=="object"&&"type"in t}const Vm=[],nM=!0,br=!1,Ko="skip";function Qo(t,e,n,r){if(!t||typeof t!="object")throw new Error("Unexpected value `"+t+"` for `tree`, expected node");let s=!0,i,o,a,l;if(typeof n=="function"||n&&typeof n=="object"?(i=e,o=n,r&&(s=!1)):(o=e,n&&(s=!1)),typeof o=="function")a=o;else if(o&&typeof o=="object"){if(!(o.enter===null||o.enter===void 0))if(typeof o.enter=="function")a=o.enter;else throw new Error("Unexpected value `"+o.enter+"` for `visitors.enter`, expected optional visitor");if(typeof o.exit=="function")l=o.exit;else throw new Error("Unexpected value `"+o.exit+"` for `visitors.exit`, expected visitor (pass a visitor directly if you only want an enter visitor)")}else throw new Error("Unexpected value `"+o+"` for `enter` or `visitors`, expected visitor or object with visitors");const c=ni(i),u=s?1:-1;d(t,void 0,[])();function d(f,h,p){const m=f&&typeof f=="object"?f:{};if(typeof m.type=="string"){const g=typeof m.tagName=="string"?m.tagName:typeof m.name=="string"?m.name:void 0;Object.defineProperty(y,"name",{value:"node ("+(f.type+(g?"<"+g+">":""))+")"})}return y;function y(){const g=!i||c(f,h,p[p.length-1]||void 0);let b=Vm;if(a&&g&&(b=ju(a(f,p,h)),b[0]===br))return b;if("children"in f&&f.children){const v=f;if(v.children&&b[0]!==Ko){let w=(s?-1:v.children.length)+u;const k=[...p,v];for(;w>-1&&w<v.children.length;){const _=v.children[w],A=d(_,w,k)();if(A[0]===br)return A;w=typeof A[1]=="number"?A[1]:w+u}}}if(l&&g){const v=ju(l(f,p,h));if(v[0]===Ko)throw new Error("Unexpected value `"+v[0]+"` from `exit`, expected `CONTINUE`, `EXIT`, index, or nothing");if(v[0]===br||typeof v[1]=="number")return v}return b}}}function ju(t){return Array.isArray(t)?t:typeof t=="number"?[nM,t]:t==null?Vm:[t]}function si(t,e,n,r){let s,i,o;i=e,o=n,typeof i=="function"?Qo(t,s,Yo(i),o):Qo(t,s,rM(i),o)}function rM(t){return!t||typeof t!="object"?t:{enter:typeof t.enter=="function"?Yo(t.enter):t.enter,exit:typeof t.exit=="function"?Yo(t.exit):t.exit}}function Yo(t){return e;function e(n,r,s){return t(n,s,r[r.length-1])}}const Jo={}.hasOwnProperty,sM={};function iM(t,e){const n=e||sM,r=new Map,s=new Map,i=new Map,o={...z2,...n.handlers},a={all:c,applyData:aM,definitionById:r,footnoteById:s,footnoteCounts:i,footnoteOrder:[],handlers:o,one:l,options:n,patch:oM,wrap:cM};return si(t,function(u){if(u.type==="definition"||u.type==="footnoteDefinition"){const d=String(u.identifier).toUpperCase();u.type==="definition"?r.has(d)||r.set(d,u):s.has(d)||s.set(d,u)}}),a;function l(u,d){const{type:f}=u,h=a.handlers[f];if(Jo.call(a.handlers,f)&&h)return h(a,u,d);if(a.options.passThrough&&a.options.passThrough.includes(f)){if("children"in u){const{children:m,...y}=u;return{...Ms(y),children:a.all(u)}}return Ms(u)}return(a.options.unknownHandler||lM)(a,u,d)}function c(u){const d=[];if("children"in u){const f=u.children;let h=-1;for(;++h<f.length;){const p=a.one(f[h],u);if(p){if(h&&f[h-1].type==="break"&&(!Array.isArray(p)&&p.type==="text"&&(p.value=zu(p.value)),!Array.isArray(p)&&p.type==="element")){const m=p.children[0];m&&m.type==="text"&&(m.value=zu(m.value))}Array.isArray(p)?d.push(...p):d.push(p)}}}return d}}function oM(t,e){t.position&&(e.position=QE(t))}function aM(t,e){let n=e;if(t&&t.data){const{hChildren:r,hName:s,hProperties:i}=t.data;if(typeof s=="string")if(n.type==="element")n.tagName=s;else{const o="children"in n?n.children:[n];n={type:"element",tagName:s,properties:{},children:o}}n.type==="element"&&i&&Object.assign(n.properties,Ms(i)),"children"in n&&n.children&&r!==null&&r!==void 0&&(n.children=r)}return n}function lM(t,e){const n=e.data||{},r="value"in e&&!(Jo.call(n,"hProperties")||Jo.call(n,"hChildren"))?{type:"text",value:e.value}:{type:"element",tagName:"div",properties:{},children:t.all(e)};return t.patch(e,r),t.applyData(e,r)}function cM(t,e){const n=[];let r=-1;for(e&&n.push({type:"text",value:`
|
|
21
|
+
`});++r<t.length;)r&&n.push({type:"text",value:`
|
|
22
|
+
`}),n.push(t[r]);return e&&t.length>0&&n.push({type:"text",value:`
|
|
23
|
+
`}),n}function zu(t){let e=0,n=t.charCodeAt(e);for(;n===9||n===32;)e++,n=t.charCodeAt(e);return t.slice(e)}function Vu(t,e){const n=iM(t,e),r=n.one(t,void 0),s=Y2(n),i=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return s&&i.children.push({type:"text",value:`
|
|
24
|
+
`},s),i}function uM(t,e){return t&&"run"in t?async function(n,r){const s=Vu(n,{file:r,...e});await t.run(s,r)}:function(n,r){return Vu(n,{file:r,...t||e})}}function Uu(t){if(t)throw t}var Bi,qu;function dM(){if(qu)return Bi;qu=1;var t=Object.prototype.hasOwnProperty,e=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=function(c){return typeof Array.isArray=="function"?Array.isArray(c):e.call(c)==="[object Array]"},i=function(c){if(!c||e.call(c)!=="[object Object]")return!1;var u=t.call(c,"constructor"),d=c.constructor&&c.constructor.prototype&&t.call(c.constructor.prototype,"isPrototypeOf");if(c.constructor&&!u&&!d)return!1;var f;for(f in c);return typeof f>"u"||t.call(c,f)},o=function(c,u){n&&u.name==="__proto__"?n(c,u.name,{enumerable:!0,configurable:!0,value:u.newValue,writable:!0}):c[u.name]=u.newValue},a=function(c,u){if(u==="__proto__")if(t.call(c,u)){if(r)return r(c,u).value}else return;return c[u]};return Bi=function l(){var c,u,d,f,h,p,m=arguments[0],y=1,g=arguments.length,b=!1;for(typeof m=="boolean"&&(b=m,m=arguments[1]||{},y=2),(m==null||typeof m!="object"&&typeof m!="function")&&(m={});y<g;++y)if(c=arguments[y],c!=null)for(u in c)d=a(m,u),f=a(c,u),m!==f&&(b&&f&&(i(f)||(h=s(f)))?(h?(h=!1,p=d&&s(d)?d:[]):p=d&&i(d)?d:{},o(m,{name:u,newValue:l(b,p,f)})):typeof f<"u"&&o(m,{name:u,newValue:f}));return m},Bi}var hM=dM();const ji=na(hM);function Xo(t){if(typeof t!="object"||t===null)return!1;const e=Object.getPrototypeOf(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}function fM(){const t=[],e={run:n,use:r};return e;function n(...s){let i=-1;const o=s.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...s);function a(l,...c){const u=t[++i];let d=-1;if(l){o(l);return}for(;++d<s.length;)(c[d]===null||c[d]===void 0)&&(c[d]=s[d]);s=c,u?pM(u,a)(...c):o(null,...c)}}function r(s){if(typeof s!="function")throw new TypeError("Expected `middelware` to be a function, not "+s);return t.push(s),e}}function pM(t,e){let n;return r;function r(...o){const a=t.length>o.length;let l;a&&o.push(s);try{l=t.apply(this,o)}catch(c){const u=c;if(a&&n)throw u;return s(u)}a||(l&&l.then&&typeof l.then=="function"?l.then(i,s):l instanceof Error?s(l):i(l))}function s(o,...a){n||(n=!0,e(o,...a))}function i(o){s(null,o)}}const dt={basename:mM,dirname:gM,extname:yM,join:bM,sep:"/"};function mM(t,e){if(e!==void 0&&typeof e!="string")throw new TypeError('"ext" argument must be a string');Nr(t);let n=0,r=-1,s=t.length,i;if(e===void 0||e.length===0||e.length>t.length){for(;s--;)if(t.codePointAt(s)===47){if(i){n=s+1;break}}else r<0&&(i=!0,r=s+1);return r<0?"":t.slice(n,r)}if(e===t)return"";let o=-1,a=e.length-1;for(;s--;)if(t.codePointAt(s)===47){if(i){n=s+1;break}}else o<0&&(i=!0,o=s+1),a>-1&&(t.codePointAt(s)===e.codePointAt(a--)?a<0&&(r=s):(a=-1,r=o));return n===r?r=o:r<0&&(r=t.length),t.slice(n,r)}function gM(t){if(Nr(t),t.length===0)return".";let e=-1,n=t.length,r;for(;--n;)if(t.codePointAt(n)===47){if(r){e=n;break}}else r||(r=!0);return e<0?t.codePointAt(0)===47?"/":".":e===1&&t.codePointAt(0)===47?"//":t.slice(0,e)}function yM(t){Nr(t);let e=t.length,n=-1,r=0,s=-1,i=0,o;for(;e--;){const a=t.codePointAt(e);if(a===47){if(o){r=e+1;break}continue}n<0&&(o=!0,n=e+1),a===46?s<0?s=e:i!==1&&(i=1):s>-1&&(i=-1)}return s<0||n<0||i===0||i===1&&s===n-1&&s===r+1?"":t.slice(s,n)}function bM(...t){let e=-1,n;for(;++e<t.length;)Nr(t[e]),t[e]&&(n=n===void 0?t[e]:n+"/"+t[e]);return n===void 0?".":_M(n)}function _M(t){Nr(t);const e=t.codePointAt(0)===47;let n=vM(t,!e);return n.length===0&&!e&&(n="."),n.length>0&&t.codePointAt(t.length-1)===47&&(n+="/"),e?"/"+n:n}function vM(t,e){let n="",r=0,s=-1,i=0,o=-1,a,l;for(;++o<=t.length;){if(o<t.length)a=t.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(s===o-1||i===1))if(s!==o-1&&i===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),s=o,i=0;continue}}else if(n.length>0){n="",r=0,s=o,i=0;continue}}e&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+t.slice(s+1,o):n=t.slice(s+1,o),r=o-s-1;s=o,i=0}else a===46&&i>-1?i++:i=-1}return n}function Nr(t){if(typeof t!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}const wM={cwd:xM};function xM(){return"/"}function Zo(t){return!!(t!==null&&typeof t=="object"&&"href"in t&&t.href&&"protocol"in t&&t.protocol&&t.auth===void 0)}function SM(t){if(typeof t=="string")t=new URL(t);else if(!Zo(t)){const e=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+t+"`");throw e.code="ERR_INVALID_ARG_TYPE",e}if(t.protocol!=="file:"){const e=new TypeError("The URL must be of scheme file");throw e.code="ERR_INVALID_URL_SCHEME",e}return TM(t)}function TM(t){if(t.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const e=t.pathname;let n=-1;for(;++n<e.length;)if(e.codePointAt(n)===37&&e.codePointAt(n+1)===50){const r=e.codePointAt(n+2);if(r===70||r===102){const s=new TypeError("File URL path must not include encoded / characters");throw s.code="ERR_INVALID_FILE_URL_PATH",s}}return decodeURIComponent(e)}const zi=["history","path","basename","stem","extname","dirname"];class Um{constructor(e){let n;e?Zo(e)?n={path:e}:typeof e=="string"||CM(e)?n={value:e}:n=e:n={},this.cwd="cwd"in n?"":wM.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<zi.length;){const i=zi[r];i in n&&n[i]!==void 0&&n[i]!==null&&(this[i]=i==="history"?[...n[i]]:n[i])}let s;for(s in n)zi.includes(s)||(this[s]=n[s])}get basename(){return typeof this.path=="string"?dt.basename(this.path):void 0}set basename(e){Ui(e,"basename"),Vi(e,"basename"),this.path=dt.join(this.dirname||"",e)}get dirname(){return typeof this.path=="string"?dt.dirname(this.path):void 0}set dirname(e){Hu(this.basename,"dirname"),this.path=dt.join(e||"",this.basename)}get extname(){return typeof this.path=="string"?dt.extname(this.path):void 0}set extname(e){if(Vi(e,"extname"),Hu(this.dirname,"extname"),e){if(e.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(e.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=dt.join(this.dirname,this.stem+(e||""))}get path(){return this.history[this.history.length-1]}set path(e){Zo(e)&&(e=SM(e)),Ui(e,"path"),this.path!==e&&this.history.push(e)}get stem(){return typeof this.path=="string"?dt.basename(this.path,this.extname):void 0}set stem(e){Ui(e,"stem"),Vi(e,"stem"),this.path=dt.join(this.dirname||"",e+(this.extname||""))}fail(e,n,r){const s=this.message(e,n,r);throw s.fatal=!0,s}info(e,n,r){const s=this.message(e,n,r);return s.fatal=void 0,s}message(e,n,r){const s=new Xs(e,n,r);return this.path&&(s.name=this.path+":"+s.name,s.file=this.path),s.fatal=!1,this.messages.push(s),s}toString(e){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(e||void 0).decode(this.value)}}function Vi(t,e){if(t&&t.includes(dt.sep))throw new Error("`"+e+"` cannot be a path: did not expect `"+dt.sep+"`")}function Ui(t,e){if(!t)throw new Error("`"+e+"` cannot be empty")}function Hu(t,e){if(!t)throw new Error("Setting `"+e+"` requires `path` to be set too")}function CM(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}const IM=(function(t){const r=this.constructor.prototype,s=r[t],i=function(){return s.apply(i,arguments)};return Object.setPrototypeOf(i,r),i}),kM={}.hasOwnProperty;class vl extends IM{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=fM()}copy(){const e=new vl;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];e.use(...r)}return e.data(ji(!0,{},this.namespace)),e}data(e,n){return typeof e=="string"?arguments.length===2?(Wi("data",this.frozen),this.namespace[e]=n,this):kM.call(this.namespace,e)&&this.namespace[e]||void 0:e?(Wi("data",this.frozen),this.namespace=e,this):this.namespace}freeze(){if(this.frozen)return this;const e=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const s=n.call(e,...r);typeof s=="function"&&this.transformers.use(s)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(e){this.freeze();const n=rs(e),r=this.parser||this.Parser;return qi("parse",r),r(String(n),n)}process(e,n){const r=this;return this.freeze(),qi("process",this.parser||this.Parser),Hi("process",this.compiler||this.Compiler),n?s(void 0,n):new Promise(s);function s(i,o){const a=rs(e),l=r.parse(a);r.run(l,a,function(u,d,f){if(u||!d||!f)return c(u);const h=d,p=r.stringify(h,f);RM(p)?f.value=p:f.result=p,c(u,f)});function c(u,d){u||!d?o(u):i?i(d):n(void 0,d)}}}processSync(e){let n=!1,r;return this.freeze(),qi("processSync",this.parser||this.Parser),Hi("processSync",this.compiler||this.Compiler),this.process(e,s),Gu("processSync","process",n),r;function s(i,o){n=!0,Uu(i),r=o}}run(e,n,r){Wu(e),this.freeze();const s=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?i(void 0,r):new Promise(i);function i(o,a){const l=rs(n);s.run(e,l,c);function c(u,d,f){const h=d||e;u?a(u):o?o(h):r(void 0,h,f)}}}runSync(e,n){let r=!1,s;return this.run(e,n,i),Gu("runSync","run",r),s;function i(o,a){Uu(o),s=a,r=!0}}stringify(e,n){this.freeze();const r=rs(n),s=this.compiler||this.Compiler;return Hi("stringify",s),Wu(e),s(e,r)}use(e,...n){const r=this.attachers,s=this.namespace;if(Wi("use",this.frozen),e!=null)if(typeof e=="function")l(e,n);else if(typeof e=="object")Array.isArray(e)?a(e):o(e);else throw new TypeError("Expected usable value, not `"+e+"`");return this;function i(c){if(typeof c=="function")l(c,[]);else if(typeof c=="object")if(Array.isArray(c)){const[u,...d]=c;l(u,d)}else o(c);else throw new TypeError("Expected usable value, not `"+c+"`")}function o(c){if(!("plugins"in c)&&!("settings"in c))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(c.plugins),c.settings&&(s.settings=ji(!0,s.settings,c.settings))}function a(c){let u=-1;if(c!=null)if(Array.isArray(c))for(;++u<c.length;){const d=c[u];i(d)}else throw new TypeError("Expected a list of plugins, not `"+c+"`")}function l(c,u){let d=-1,f=-1;for(;++d<r.length;)if(r[d][0]===c){f=d;break}if(f===-1)r.push([c,...u]);else if(u.length>0){let[h,...p]=u;const m=r[f][1];Xo(m)&&Xo(h)&&(h=ji(!0,m,h)),r[f]=[c,h,...p]}}}}const EM=new vl().freeze();function qi(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `parser`")}function Hi(t,e){if(typeof e!="function")throw new TypeError("Cannot `"+t+"` without `compiler`")}function Wi(t,e){if(e)throw new Error("Cannot call `"+t+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Wu(t){if(!Xo(t)||typeof t.type!="string")throw new TypeError("Expected node, got `"+t+"`")}function Gu(t,e,n){if(!n)throw new Error("`"+t+"` finished async. Use `"+e+"` instead")}function rs(t){return AM(t)?t:new Um(t)}function AM(t){return!!(t&&typeof t=="object"&&"message"in t&&"messages"in t)}function RM(t){return typeof t=="string"||MM(t)}function MM(t){return!!(t&&typeof t=="object"&&"byteLength"in t&&"byteOffset"in t)}const PM="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",Ku=[],Qu={allowDangerousHtml:!0},DM=/^(https?|ircs?|mailto|xmpp)$/i,OM=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function LM(t){const e=FM(t),n=$M(t);return NM(e.runSync(e.parse(n),n),t)}function FM(t){const e=t.rehypePlugins||Ku,n=t.remarkPlugins||Ku,r=t.remarkRehypeOptions?{...t.remarkRehypeOptions,...Qu}:Qu;return EM().use(m2).use(n).use(uM,r).use(e)}function $M(t){const e=t.children||"",n=new Um;return typeof e=="string"&&(n.value=e),n}function NM(t,e){const n=e.allowedElements,r=e.allowElement,s=e.components,i=e.disallowedElements,o=e.skipHtml,a=e.unwrapDisallowed,l=e.urlTransform||BM;for(const u of OM)Object.hasOwn(e,u.from)&&(""+u.from+(u.to?"use `"+u.to+"` instead":"remove it")+PM+u.id,void 0);return si(t,c),tA(t,{Fragment:C.Fragment,components:s,ignoreInvalidStyle:!0,jsx:C.jsx,jsxs:C.jsxs,passKeys:!0,passNode:!0});function c(u,d,f){if(u.type==="raw"&&f&&typeof d=="number")return o?f.children.splice(d,1):f.children[d]={type:"text",value:u.value},d;if(u.type==="element"){let h;for(h in Fi)if(Object.hasOwn(Fi,h)&&Object.hasOwn(u.properties,h)){const p=u.properties[h],m=Fi[h];(m===null||m.includes(u.tagName))&&(u.properties[h]=l(String(p||""),h,u))}}if(u.type==="element"){let h=n?!n.includes(u.tagName):i?i.includes(u.tagName):!1;if(!h&&r&&typeof d=="number"&&(h=!r(u,d,f)),h&&f&&typeof d=="number")return a&&u.children?f.children.splice(d,1,...u.children):f.children.splice(d,1),d}}}function BM(t){const e=t.indexOf(":"),n=t.indexOf("?"),r=t.indexOf("#"),s=t.indexOf("/");return e===-1||s!==-1&&e>s||n!==-1&&e>n||r!==-1&&e>r||DM.test(t.slice(0,e))?t:""}const{useSmooth:jM,useSmoothStatus:zM,withSmoothContextProvider:VM}=eE,wl=H.createContext(null),UM=t=>{const e=H.useContext(wl);return C.jsx(vE,{...e,...t})},qM=t=>{const{components:e}=H.useContext(wl);return C.jsx(cE,{...t,fallbackPre:e.Pre})},xl=H.memo(({text:t,...e})=>C.jsx(LM,{...e,children:t}));xl.displayName="MarkdownRenderer";const HM=({text:t,...e})=>{const n=H.useDeferredValue(t);return C.jsx(xl,{text:n,...e})},Yu=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ps=(t,e,n=1)=>{if(Object.is(t,e))return!0;if(n<=0)return!1;if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!Ps(t[r],e[r],n-1))return!1;return!0}if(Yu(t)&&Yu(e)){const r=Object.keys(t);return r.length===Object.keys(e).length&&r.every(s=>Object.hasOwn(e,s)&&Ps(t[s],e[s],n-1))}return!1};function WM(t,e){const n=H.useRef(t);return Ps(t,n.current,e)||(n.current=t),n.current}function Ju(t){const e=H.useRef(t),n=(i,o)=>i[o],r=Object.keys(t),s=Object.keys(e.current);return r.length===s.length&&r.every(i=>Object.hasOwn(e.current,i)&&Ps(n(t,i),n(e.current,i)))||(e.current=t),e.current}const GM=({components:t,componentsByLanguage:e,smooth:n=!0,defer:r=!1,preprocess:s,...i})=>{const o=$p(),{text:a}=jM(o,n),l=H.useMemo(()=>s?s(a):a,[s,a]),{pre:c=uE,code:u=dE,SyntaxHighlighter:d=rm,CodeHeader:f=hE}=t??{},h=H.useMemo(()=>({Pre:c,Code:u,SyntaxHighlighter:d,CodeHeader:f}),[c,u,d,f]),p=WM(H.useMemo(()=>({components:h,componentsByLanguage:e}),[h,e]),3),m=Ju(H.useMemo(()=>{const{pre:b,code:v,SyntaxHighlighter:w,CodeHeader:k,..._}=t??{};return{..._,pre:qM,code:UM}},[t])),y=r?HM:xl,g=Ju(i);return C.jsx(wl.Provider,{value:p,children:C.jsx(y,{text:l,components:m,...g})})},qm=H.forwardRef(({className:t,containerProps:e,containerComponent:n="div",...r},s)=>{const i=zM();return C.jsx(n,{"data-status":i.type,...e,className:sm(t,e?.className),ref:s,children:C.jsx(GM,{...r})})});qm.displayName="MarkdownTextPrimitive";const n3=VM(qm);function Xu(t,e){const n=String(t);if(typeof e!="string")throw new TypeError("Expected character");let r=0,s=n.indexOf(e);for(;s!==-1;)r++,s=n.indexOf(e,s+e.length);return r}function KM(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function QM(t,e,n){const s=ni((n||{}).ignore||[]),i=YM(e);let o=-1;for(;++o<i.length;)Qo(t,a);function a(c,u,d){if(c.type==="text"&&typeof d=="number")return l(c,u,d);if(s(c,d,u[u.length-1]))return Ko}function l(c,u,d){const f=u[u.length-1],h=i[o][0],p=i[o][1];let m=0,y=!1,g=[];h.lastIndex=0;let b=h.exec(c.value);for(;b;){const w=b.index,k={index:b.index,input:b.input,stack:[...u,c]};let _=p(...b,k);if(typeof _=="string"&&(_=_.length>0?{type:"text",value:_}:void 0),_!==!1){if(m!==w&&v({type:"text",value:c.value.slice(m,w)}),Array.isArray(_))for(const A of _)v(A);else _&&v(_);m=w+b[0].length,y=!0}if(_===!1||b[0].length===0){const A=c.value.codePointAt(w)||0;h.lastIndex=w+(/[uv]/.test(h.flags)&&A>65535?2:1)}if(!h.global)break;b=h.exec(c.value)}return y?(m<c.value.length&&v({type:"text",value:c.value.slice(m)}),f.children.splice(d,1,...g)):g=[c],d+g.length;function v(w){const k=g[g.length-1];k&&k.type==="text"&&w.type==="text"?k.value+=w.value:g.push(w)}}}function YM(t){if(!Array.isArray(t))throw new TypeError("Expected find and replace tuple or list of tuples");const e=[],n=!t[0]||Array.isArray(t[0])?t:[t];let r=-1;for(;++r<n.length;){const s=n[r];e.push([JM(s[0]),XM(s[1])])}return e}function JM(t){return typeof t=="string"?new RegExp(KM(t),"g"):t}function XM(t){return typeof t=="function"?t:function(){return t}}const Gi="phrasing",Ki=["autolink","link","image","label"];function ZM(){return{transforms:[oP],enter:{literalAutolink:tP,literalAutolinkEmail:Qi,literalAutolinkHttp:Qi,literalAutolinkWww:Qi},exit:{literalAutolink:iP,literalAutolinkEmail:sP,literalAutolinkHttp:nP,literalAutolinkWww:rP}}}function eP(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:Gi,notInConstruct:Ki},{character:".",before:"[Ww]{3}",inConstruct:Gi,notInConstruct:Ki},{character:":",before:"[PSps]",after:"\\/",inConstruct:Gi,notInConstruct:Ki}]}}function tP(t){this.enter({type:"link",title:null,url:"",children:[],position:void 0},t)}function Qi(t){this.config.enter.autolinkProtocol.call(this,t)}function nP(t){this.config.exit.autolinkProtocol.call(this,t)}function rP(t){this.config.exit.data.call(this,t);const e=this.stack[this.stack.length-1];e.type,e.url="http://"+this.sliceSerialize(t)}function sP(t){this.config.exit.autolinkEmail.call(this,t)}function iP(t){this.exit(t)}function oP(t){QM(t,[[/(?<![\da-z])(https?:\/\/|www(?=\.))([\w-]*\.[\w\-.]*)([^\t\n\r ]*)/gi,aP],[/(?<![\w+\-.@])xmpp:([\w+\-.]+)@([\w-]+(?:\.[\w-]+)+)(\/(?:[\w\-/]|\.(?=[\dA-Za-z]))*)?/g,uP],[/(?<![\w+\-.@])mailto:([\w+\-.]+)@([\w-]+(?:\.[\w-]+)+)/g,cP],[/(?<![\w+\-.]|(?:^|[^\d@A-Za-z])(?:mailto|xmpp):)([\w+\-.]+)@([\w-]+(?:\.[\w-]+)+)/g,lP]],{ignore:["link","linkReference"]})}function aP(t,e,n,r,s){if(!fP(s))return!1;let i="";if(/^w/i.test(e)&&(n=e+n,e="",i="http://"),Fr(n.charCodeAt(0))||!dP(n))return!1;const o=hP(n+r),a={type:"link",title:null,url:i+e+o[0],children:[{type:"text",value:e+o[0],position:void 0}],position:void 0};return o[1]?[a,{type:"text",value:o[1],position:void 0}]:a}function lP(t,e,n){return/[\d\-_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+n,children:[{type:"text",value:e+"@"+n,position:void 0}],position:void 0}}function cP(t,e,n){if(/[\d\-_]$/.test(n))return!1;const r="mailto:"+e+"@"+n;return{type:"link",title:null,url:r,children:[{type:"text",value:r,position:void 0}],position:void 0}}function uP(t,e,n,r,s){if(/[\d\-_]$/.test(n)||r&&(!/[A-Za-z]$/.test(r)||s.input.charAt(s.index+t.length)==="@"))return!1;const i="xmpp:"+e+"@"+n+(r||"");return{type:"link",title:null,url:i,children:[{type:"text",value:i,position:void 0}],position:void 0}}function dP(t){const e=t.split(".");return!(e.length<2||e[e.length-1]&&(/_/.test(e[e.length-1])||!/[\dA-Za-z]/.test(e[e.length-1]))||e[e.length-2]&&(/_/.test(e[e.length-2])||!/[\dA-Za-z]/.test(e[e.length-2])))}function hP(t){let e=t.length;for(;e>0;){const o=t.charCodeAt(e-1);if(o===33||o===34||o===38||o===39||o===41||o===44||o===46||o===58||o===59||o===60||o===62||o===63||o===93||o===125)e--;else break}if(e===t.length)return[t,void 0];let n=t.slice(e);t=t.slice(0,e);let r=n.indexOf(")");const s=Xu(t,"(");let i=Xu(t,")");for(;r!==-1&&s>i;)t+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),i++;return[t,n]}function fP(t){const e=t.input.charCodeAt(t.index-1);return t.index===0||gn(e)||Fr(e)}Hm.peek=xP;function pP(){this.buffer()}function mP(t){this.enter({type:"footnoteReference",identifier:"",label:""},t)}function gP(){this.buffer()}function yP(t){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},t)}function bP(t){const e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=st(this.sliceSerialize(t)).toLowerCase(),n.label=e}function _P(t){this.exit(t)}function vP(t){const e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=st(this.sliceSerialize(t)).toLowerCase(),n.label=e}function wP(t){this.exit(t)}function xP(){return"["}function Hm(t,e,n,r){const s=n.createTracker(r);let i=s.move("[^");const o=n.enter("footnoteReference"),a=n.enter("reference");return i+=s.move(n.safe(n.associationId(t),{after:"]",before:i})),a(),o(),i+=s.move("]"),i}function SP(){return{enter:{gfmFootnoteCallString:pP,gfmFootnoteCall:mP,gfmFootnoteDefinitionLabelString:gP,gfmFootnoteDefinition:yP},exit:{gfmFootnoteCallString:bP,gfmFootnoteCall:_P,gfmFootnoteDefinitionLabelString:vP,gfmFootnoteDefinition:wP}}}function TP(t){let e=!1;return t&&t.firstLineBlank&&(e=!0),{handlers:{footnoteDefinition:n,footnoteReference:Hm},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,s,i,o){const a=i.createTracker(o);let l=a.move("[^");const c=i.enter("footnoteDefinition"),u=i.enter("label");return l+=a.move(i.safe(i.associationId(r),{before:l,after:"]"})),u(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((e?`
|
|
25
|
+
`:" ")+i.indentLines(i.containerFlow(r,a.current()),e?Wm:CP))),c(),l}}function CP(t,e,n){return e===0?t:Wm(t,e,n)}function Wm(t,e,n){return(n?"":" ")+t}const IP=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];Sl.attention=MP;Sl.peek=PP;function kP(){return{canContainEols:["delete"],enter:{strikethrough:AP},exit:{strikethrough:RP}}}function EP(){return{handlers:{delete:Sl},unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:IP}]}}function AP(t){this.enter({type:"delete",children:[],position:void 0},t)}function RP(t){this.exit(t)}function Sl(t,e,n,r){const s=n.createTracker(r),i=n.stack.includes("strikethrough")?"~":"~~",o=n.enter("strikethrough");let a=s.move(i);return a+=n.containerPhrasing(t,{...s.current(),before:a,after:"~"}),a+=s.move(i),o(),a}function MP(){return{construct:"strikethrough",markers:["~"],sizes:[2,1]}}function PP(){return"~"}function DP(t){return t.length}function OP(t,e){const n=e||{},r=(n.align||[]).concat(),s=n.stringLength||DP,i=[],o=[],a=[],l=[];let c=0,u=-1;for(;++u<t.length;){const m=[],y=[];let g=-1;for(t[u].length>c&&(c=t[u].length);++g<t[u].length;){const b=LP(t[u][g]);if(n.alignDelimiters!==!1){const v=s(b);y[g]=v,(l[g]===void 0||v>l[g])&&(l[g]=v)}m.push(b)}o[u]=m,a[u]=y}let d=-1;if(typeof r=="object"&&"length"in r)for(;++d<c;)i[d]=Zu(r[d]);else{const m=Zu(r);for(;++d<c;)i[d]=m}d=-1;const f=[],h=[];for(;++d<c;){const m=i[d];let y="",g="";m===99?(y=":",g=":"):m===108?y=":":m===114&&(g=":");let b=n.alignDelimiters===!1?1:Math.max(1,l[d]-y.length-g.length);const v=y+"-".repeat(b)+g;n.alignDelimiters!==!1&&(b=y.length+b+g.length,b>l[d]&&(l[d]=b),h[d]=b),f[d]=v}o.splice(1,0,f),a.splice(1,0,h),u=-1;const p=[];for(;++u<o.length;){const m=o[u],y=a[u],g=n.fillRows===!1?Math.max(1,o[u===1?0:u].length):c;d=-1;const b=[];for(;++d<g;){const v=m[d]||"";let w="",k="";if(n.alignDelimiters!==!1){const _=l[d]-(y[d]||0),A=i[d];if(A===114)w=" ".repeat(_);else if(A===99){const E=_/2;_%2?(w=" ".repeat(E+.5),k=" ".repeat(E-.5)):(w=" ".repeat(E),k=w)}else k=" ".repeat(_)}n.delimiterStart!==!1&&!d&&b.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&v==="")&&(n.delimiterStart!==!1||d)&&b.push(" "),n.alignDelimiters!==!1&&b.push(w),b.push(v),n.alignDelimiters!==!1&&b.push(k),n.padding!==!1&&b.push(" "),(n.delimiterEnd!==!1||d!==g-1)&&b.push("|")}p.push(n.delimiterEnd===!1?b.join("").replace(/ +$/,""):b.join(""))}return p.join(`
|
|
26
|
+
`)}function LP(t){return t==null?"":String(t)}function Zu(t){const e=typeof t=="string"?t.codePointAt(0):0;return e===67||e===99?99:e===76||e===108?108:e===82||e===114?114:0}const FP=ni(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function $P(t,e,n,r){const s=n.enter("blockquote"),i=n.createTracker(r);i.move("> "),i.shift(2);const o=n.indentLines(n.containerFlow(t,i.current()),NP);return s(),o}function NP(t,e,n){return">"+(n?"":" ")+t}function BP(t,e){return ed(t,e.inConstruct,!0)&&!ed(t,e.notInConstruct,!1)}function ed(t,e,n){if(typeof e=="string"&&(e=[e]),!e||e.length===0)return n;let r=-1;for(;++r<e.length;)if(t.includes(e[r]))return!0;return!1}function td(t,e,n,r){let s=-1;for(;++s<n.unsafe.length;){const i=n.unsafe[s];if(i.character===`
|
|
27
|
+
`&&!i.before&&!i.after&&BP(n.stack,i))return/[\t ]/.test(r.before)?"":" "}return`\\
|
|
28
|
+
`}function jP(t,e){const n=String(t);let r=n.indexOf(e),s=r,i=0,o=0;if(typeof e!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===s?++i>o&&(o=i):i=1,s=r+e.length,r=n.indexOf(e,s);return o}function zP(t,e){return!!(e.options.fences===!1&&t.value&&!t.lang&&/[^\n\r ]/.test(t.value)&&!/^[\t ]*(?:[\n\r]|$)|(?:^|[\n\r])[\t ]*$/.test(t.value))}function VP(t){const e=t.options.fence||"`";if(e!=="`"&&e!=="~")throw new Error("Cannot serialize code with `"+e+"` for `options.fence`, expected `` ` `` or `~`");return e}function UP(t,e,n,r){const s=VP(n),i=t.value||"";if(zP(t,n)){const d=n.enter("codeIndented"),f=n.indentLines(i,qP);return d(),f}const o=n.createTracker(r),a=s.repeat(Math.max(jP(i,s)+1,3)),l=n.enter("codeFenced"),c=s==="`"?"GraveAccent":"Tilde";let u=o.move(a);if(t.lang){const d=n.enter(`codeFencedLang${c}`);u+=o.move(n.safe(t.lang,{before:u,after:" ",encode:["`"],...o.current()})),d()}if(t.lang&&t.meta){const d=n.enter(`codeFencedMeta${c}`);u+=o.move(" "),u+=o.move(n.safe(t.meta,{before:u,after:`
|
|
29
|
+
`,encode:["`"],...o.current()})),d()}return u+=o.move(`
|
|
30
|
+
`),i&&(u+=o.move(i+`
|
|
31
|
+
`)),u+=o.move(a),l(),u}function qP(t,e,n){return(n?"":" ")+t}function Tl(t){const e=t.options.quote||'"';if(e!=='"'&&e!=="'")throw new Error("Cannot serialize title with `"+e+"` for `options.quote`, expected `\"`, or `'`");return e}function HP(t,e,n,r){const s=Tl(n),i=s==='"'?"Quote":"Apostrophe",o=n.enter("definition");let a=n.enter("label");const l=n.createTracker(r);let c=l.move("[");return c+=l.move(n.safe(n.associationId(t),{before:c,after:"]",...l.current()})),c+=l.move("]: "),a(),!t.url||/^<|[\0- \u007F]/.test(t.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(t.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":`
|
|
32
|
+
`,...l.current()}))),a(),t.title&&(a=n.enter(`title${i}`),c+=l.move(" "+s),c+=l.move(n.safe(t.title,{before:c,after:s,...l.current()})),c+=l.move(s),a()),o(),c}function WP(t){const e=t.options.emphasis||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize emphasis with `"+e+"` for `options.emphasis`, expected `*`, or `_`");return e}function Ds(t){const e=t.codePointAt(0);return e===void 0?"":String.fromCodePoint(e)}function Fn(t){const e=t.codePointAt(t.length-2);return e!==void 0&&e>65535?t.slice(-2):t.slice(-1)}function Gm(t){return"&#x"+t.toString(16).toUpperCase()+";"}function nd(t,e,n){const r=Vt(t),s=Vt(e);return r===void 0?s===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:s===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?s===void 0?{inside:!1,outside:!1}:s===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:s===void 0?{inside:!1,outside:!1}:s===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}function GP(t){if(t.charCodeAt(0)!==60)return;const e=t.charCodeAt(1);if(e===33){const a=t.charCodeAt(2);return a===45?2:a===91?5:Ce(a)?4:void 0}if(e===63)return 3;const n=e===47,r=n?2:1;let s=r,i=t.charCodeAt(s);if(!Ce(i))return;for(;i===45||Ie(i);)i=t.charCodeAt(++s);const o=t.slice(r,s).toLowerCase();return!n&&i!==47&&Go.includes(o)?1:Mm.includes(o)?6:7}const Km=new Map([["*",!1],["_",!0]]);function KP(t,e,n){const r=new Set;for(const i of t){const o=n.get(i);if(o&&i.attention&&e.some(a=>a.attention===i.attention))for(const a of o.tokens)r.add(a.attention)}const s=[];for(const i of t)i.attention&&r.delete(i.attention)&&s.push(i.attention);return s.reverse(),s}function Qm(t,e,n){const r=[],s=new Map,i=new Map;let o=0;for(;o<t.length;){if(!t[o].attention){o++;continue}const a=t[o].value.charAt(0),l=Km.get(a);let c=o+1;for(;c<t.length&&t[c].attention&&t[c].value.charAt(0)===a;)c++;const u=o?t[o-1].value:e,d=Vt(u.charCodeAt(u.length-1)),f=Vt((c<t.length?t[c].value:n).charCodeAt(0)),h=!f||f===2&&!!d,p=!d||d===2&&!!f,m={tokens:t.slice(o,c),markers:[],start:0,end:0,open:l?h&&(!!d||!p):h,close:l?p&&(!!f||!h):p,split:l!==void 0};for(const y of m.tokens){s.set(y,[...m.tokens]),i.set(y,m);let g=y.value.length;for(;g--;)m.markers.push(y)}m.end=m.markers.length,r.push(m),o=c}for(YP(r,s),o=-1;++o<t.length;){const a=s.get(t[o]);if(a)return{attention:KP(t,a,i),index:o}}}function ss(t,e){const n=t[e?0:t.length-1];if(!n||n.attention)return;const r=e?Ds(n.value):Fn(n.value),s=Gm(r.codePointAt(0));if(e)n.value=s+n.value.slice(r.length);else{let i=n.value.slice(0,n.value.length-r.length),o=0;for(;i.charCodeAt(i.length-1-o)===92;)o++;o%2&&(i+="\\"),n.value=i+s}}function QP(t,e,n,r,s){for(const i of n.attention){const o=e.get(i)||i.sequences[0];for(const a of i.sequences){if(a===o)continue;const l=new Map(e);l.set(i,a);const c=ii(t,l,r,s),u=Qm(c,r,s);if(!u||u.index>n.index)return{chosen:l,mistake:u,tokens:c}}}}function YP(t,e){const n=new Map;for(const r of t){const s=r.tokens[0].value.charAt(0);let i=n.get(s);i||(i=[],n.set(s,i));let o=r.close?i.length:0;for(;o--&&r.start<r.end;){const a=i[o],l=a.end-a.start,c=r.end-r.start;if(r.split?(a.close||r.open)&&c%3&&!((l+c)%3):l!==a.markers.length||l!==c)continue;const u=r.split?l>1&&c>1?2:1:c,d=a.markers.slice(a.end-u,a.end),f=r.markers.slice(r.start,r.start+u),h=d[0],p=f[0];if(h===d[u-1]&&h.value.length===u&&p===f[u-1]&&p.value.length===u&&h.attention===p.attention)e.delete(h),e.delete(p);else{const m=[...new Set([...d,...f])];for(const y of m){const g=e.get(y);g&&g.push(...m)}}a.end-=u,r.start+=u,a.start===a.end&&i.splice(o,1),o=i.length}r.open&&r.start<r.end&&i.push(r)}}function JP(t,e,n){if(e.length===0)throw new Error("Cannot serialize `"+t+"` as attention without markers, expected one or more markers");if(n.length===0)throw new Error("Cannot serialize `"+t+"` as attention without sizes, expected one or more sizes");for(const s of n)if(!Number.isSafeInteger(s)||s<1)throw new Error("Cannot serialize `"+t+"` as attention with `"+s+"` as size, expected positive integer");const r=[];for(const s of e){if(s.length!==1)throw new Error("Cannot serialize `"+t+"` as attention with `"+s+"` as marker, expected a single ascii character");if(!xm(s.charCodeAt(0)))throw new Error("Cannot serialize `"+t+"` as attention with `"+s+"` as marker, expected ascii punctuation");for(const i of n)r.push(s.repeat(i))}return r}function XP(t,e,n){const r=e.indexStack,s=t.children||[],i=[];let o=-1,a=n.before;r.push(-1);let l=e.createTracker(n);for(;++o<s.length;){const c=s[o];let u;if(r[r.length-1]=o,o+1<s.length){let h=e.handle.handlers[s[o+1].type];h&&h.peek&&(h=h.peek),u=h?Ds(h(s[o+1],t,e,{before:"",after:"",...l.current()})):""}else u=n.after;const d=i[i.length-1];typeof d=="string"&&(a==="\r"||a===`
|
|
33
|
+
`)&&c.type==="html"&&GP(c.value)!==7&&(i[i.length-1]=d.replace(/(\r?\n|\r)$/," "),a=" ",l=e.createTracker(n),l.move(oi(i,n.before,n.after)));const f=e.handle.handlers[c.type];if(f&&f.attention){const h=Cl(c,f.attention,e,l);if(!h)continue;i.push(h),a=Fn(h.sequences[0])}else{const h=e.handle(c,t,e,{...l.current(),after:u,before:a});if(!h)continue;l.move(h),i.push(h),a=Fn(h)}}return r.pop(),i}function Cl(t,e,n,r){const{construct:s,markers:i,sizes:o}=e(t,n),a=JP(t.type,i,o),l=a[0],c=n.enter(s),u=n.createTracker(r.current());u.move(l);const d=XP(t,n,{...u.current(),before:l,after:l});if(c(),d.length!==0)return r.move(l),r.move(oi(d,l,l)),r.move(l),{children:d,sequences:a}}function rd(t,e,n,r){let s=ii(t,e,n,r),i=Qm(s,n,r);for(;i;){const o=QP(t,e,i,n,r);if(!o)return;e=o.chosen,s=o.tokens,i=o.mistake}return s}function Ym(t,e,n,r){let s=n,i=-1;for(;++i<t.length;){const o=t[i];if(typeof o=="string"){s="";continue}const a=i===t.length-1?r:"",l=o.sequences.find(function(c){const u=c.charAt(0);return u!==s.charAt(0)&&u!==a.charAt(0)||t.length===1&&Km.has(u)&&c.length>n.length})||o.sequences[0];l!==o.sequences[0]&&e.set(o,l),Ym(o.children,e,l,l),s=l}}function ii(t,e,n,r){const s=[];let i,o=Fn(n),a=-1;for(;++a<t.length;){const l=t[a];if(typeof l=="string"){const v={value:l,attention:void 0};i&&i===Ds(l)&&ss([v],!0),i=void 0,s.push(v),v.value&&(o=Fn(v.value));continue}const c=e.get(l)||l.sequences[0],u=c.charAt(0),d=t[a+1],f=o,h=Ds(d===void 0?r:typeof d=="string"?d:e.get(d)||d.sequences[0]),p=ii(l.children,e,c,c),m=p[0].value,y=nd(f.charCodeAt(f.length-1),m.charCodeAt(0),u);y.inside&&ss(p,!0);const g=Fn(p[p.length-1].value),b=nd(h.charCodeAt(0),g.charCodeAt(g.length-1),u);b.inside&&ss(p,!1),y.outside&&f!==`
|
|
34
|
+
`&&f!=="\r"&&ss(s,!1),b.outside&&(i=h),s.push({value:c,attention:l},...p,{value:c,attention:l}),o=c.charAt(c.length-1)}return s}function oi(t,e,n){const r=new Map;Ym(t,r,e,n);const s=(r.size>0?rd(t,r,e,n):void 0)||rd(t,new Map,e,n)||ii(t,new Map,e,n);let i="";for(const o of s)i+=o.value;return i}Il.attention=Jm;Il.peek=ZP;function Il(t,e,n,r){const s=n.enter("phrasing"),i=Cl(t,Jm,n,n.createTracker(r)),o=i?oi([i],r.before,r.after):"";return s(),o}function Jm(t,e){return{construct:"emphasis",markers:WP(e)==="*"?["*","_"]:["_","*"],sizes:[1]}}function ZP(t,e,n){return n.options.emphasis||"*"}function eD(t,e){let n=!1;return si(t,function(r){if("value"in r&&/\r?\n|\r/.test(r.value)||r.type==="break")return n=!0,br}),!!((!t.depth||t.depth<3)&&Zs(t)&&(e.options.setext||n))}function tD(t,e,n,r){const s=Math.max(Math.min(6,t.depth||1),1),i=n.createTracker(r);if(eD(t,n)){const d=n.enter("headingSetext"),f=n.enter("phrasing"),h=n.containerPhrasing(t,{...i.current(),before:`
|
|
35
|
+
`,after:`
|
|
36
|
+
`});return f(),d(),h+`
|
|
37
|
+
`+(s===1?"=":"-").repeat(h.length-(Math.max(h.lastIndexOf("\r"),h.lastIndexOf(`
|
|
38
|
+
`))+1))}const o="#".repeat(s),a=n.enter("headingAtx"),l=n.enter("phrasing");i.move(o+" ");let c=n.containerPhrasing(t,{before:"# ",after:`
|
|
39
|
+
`,...i.current()});const u=c.charCodeAt(0);return(u===9||u===32)&&(c=Gm(u)+c.slice(1)),c=c?o+" "+c:o,n.options.closeAtx&&(c+=" "+o),l(),a(),c}Xm.peek=nD;function Xm(t){return t.value||""}function nD(){return"<"}Zm.peek=rD;function Zm(t,e,n,r){const s=Tl(n),i=s==='"'?"Quote":"Apostrophe",o=n.enter("image");let a=n.enter("label");const l=n.createTracker(r);let c=l.move("![");return c+=l.move(n.safe(t.alt,{before:c,after:"]",...l.current()})),c+=l.move("]("),a(),!t.url&&t.title||/^<|[\0- \u007F]/.test(t.url)?(a=n.enter("destinationLiteral"),c+=l.move("<"),c+=l.move(n.safe(t.url,{before:c,after:">",...l.current()})),c+=l.move(">")):(a=n.enter("destinationRaw"),c+=l.move(n.safe(t.url,{before:c,after:t.title?" ":")",...l.current()}))),a(),t.title&&(a=n.enter(`title${i}`),c+=l.move(" "+s),c+=l.move(n.safe(t.title,{before:c,after:s,...l.current()})),c+=l.move(s),a()),c+=l.move(")"),o(),c}function rD(){return"!"}eg.peek=sD;function eg(t,e,n,r){const s=t.referenceType,i=n.enter("imageReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("![");const c=n.safe(t.alt,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),o();const u=n.stack;n.stack=u.filter(function(f){return f!=="phrasing"}),o=n.enter("reference");const d=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return o(),n.stack=u,i(),s==="full"||!c||c!==d?l+=a.move(d+"]"):s==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function sD(){return"!"}tg.peek=iD;function tg(t,e,n){let r=t.value||"",s="`",i=-1;for(;new RegExp("(^|[^`])"+s+"([^`]|$)").test(r);)s+="`";for(/[^\n\r ]/.test(r)&&(/^[\n\r ]/.test(r)&&/[\n\r ]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++i<n.unsafe.length;){const o=n.unsafe[i],a=n.compilePattern(o);if(!o.atBreak)continue;let l;for(;l=a.exec(r);){let c=l.index;r.charCodeAt(c)===10&&r.charCodeAt(c-1)===13&&c--,r=r.slice(0,c)+" "+r.slice(l.index+1)}}return s+r+s}function iD(){return"`"}function ng(t,e){const n=Zs(t);return!!(!e.options.resourceLink&&t.url&&!t.title&&t.children&&t.children.length===1&&t.children[0].type==="text"&&(n===t.url||"mailto:"+n===t.url)&&/^[a-z][+\-.a-z]+:/i.test(t.url)&&!/[\0- <>\u007F]/.test(t.url))}rg.peek=oD;function rg(t,e,n,r){const s=Tl(n),i=s==='"'?"Quote":"Apostrophe",o=n.createTracker(r);if(ng(t,n)){const p=n.stack;n.stack=p.filter(function(g){return g!=="phrasing"});const m=n.enter("autolink");let y=o.move("<");return y+=o.move(n.containerPhrasing(t,{before:y,after:">",...o.current()})),y+=o.move(">"),m(),n.stack=p,y}const a=n.enter("link");let l=n.enter("label"),c=o.move("[");const u=n.containerPhrasing(t,{before:c,after:"](",...o.current()});c+=o.move(u),l(),c+=o.move("](");const d=/^<|[\0- \u007F]/.test(t.url),f=r.before.charAt(r.before.length-1);let h=t.title||void 0;if(!h&&!d&&(f===`
|
|
40
|
+
`||f==="\r")){let p=0;for(;p<u.length&&u.charCodeAt(p)!==93;)p+=u.charCodeAt(p)===92?2:1;u.charCodeAt(p+1)===58&&(h="")}return!t.url&&typeof h=="string"||d?(l=n.enter("destinationLiteral"),c+=o.move("<"),c+=o.move(n.safe(t.url,{before:c,after:">",...o.current()})),c+=o.move(">")):(l=n.enter("destinationRaw"),c+=o.move(n.safe(t.url,{before:c,after:typeof h=="string"?" ":")",...o.current()}))),l(),typeof h=="string"&&(l=n.enter(`title${i}`),c+=o.move(" "+s),c+=o.move(n.safe(h,{before:c,after:s,...o.current()})),c+=o.move(s),l()),c+=o.move(")"),a(),c}function oD(t,e,n){return ng(t,n)?"<":"["}sg.peek=aD;function sg(t,e,n,r){const s=t.referenceType,i=n.enter("linkReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("[");const c=n.containerPhrasing(t,{before:l,after:"]",...a.current()});l+=a.move(c+"]["),o();const u=n.stack;n.stack=u.filter(function(f){return f!=="phrasing"}),o=n.enter("reference");const d=n.safe(n.associationId(t),{before:l,after:"]",...a.current()});return o(),n.stack=u,i(),s==="full"||!c||c!==d?l+=a.move(d+"]"):s==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function aD(){return"["}function kl(t){const e=t.options.bullet||"*";if(e!=="*"&&e!=="+"&&e!=="-")throw new Error("Cannot serialize items with `"+e+"` for `options.bullet`, expected `*`, `+`, or `-`");return e}function lD(t){const e=kl(t),n=t.options.bulletOther;if(!n)return e==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===e)throw new Error("Expected `bullet` (`"+e+"`) and `bulletOther` (`"+n+"`) to be different");return n}function cD(t){const e=t.options.bulletOrdered||".";if(e!=="."&&e!==")")throw new Error("Cannot serialize items with `"+e+"` for `options.bulletOrdered`, expected `.` or `)`");return e}function ig(t){const e=t.options.rule||"*";if(e!=="*"&&e!=="-"&&e!=="_")throw new Error("Cannot serialize rules with `"+e+"` for `options.rule`, expected `*`, `-`, or `_`");return e}function uD(t,e,n,r){const s=n.enter("list"),i=n.bulletCurrent;let o=t.ordered?cD(n):kl(n);const a=t.ordered?o==="."?")":".":lD(n);let l=e&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!t.ordered){const u=t.children?t.children[0]:void 0;if((o==="*"||o==="-")&&u&&(!u.children||!u.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),ig(n)===o&&u){let d=-1;for(;++d<t.children.length;){const f=t.children[d];if(f&&f.type==="listItem"&&f.children&&f.children[0]&&f.children[0].type==="thematicBreak"){l=!0;break}}}}l&&(o=a),n.bulletCurrent=o;const c=n.containerFlow(t,r);return n.bulletLastUsed=o,n.bulletCurrent=i,s(),c}function dD(t){const e=t.options.listItemIndent||"one";if(e!=="tab"&&e!=="one"&&e!=="mixed")throw new Error("Cannot serialize items with `"+e+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return e}function hD(t,e,n,r){const s=dD(n);let i=n.bulletCurrent||kl(n);e&&e.type==="list"&&e.ordered&&(i=(typeof e.start=="number"&&e.start>-1?e.start:1)+(n.options.incrementListMarker===!1?0:e.children.indexOf(t))+i);let o=i.length+1;(s==="tab"||s==="mixed"&&(e&&e.type==="list"&&e.spread||t.spread))&&(o=Math.ceil(o/4)*4);const a=n.createTracker(r);a.move(i+" ".repeat(o-i.length)),a.shift(o);const l=n.enter("listItem"),c=n.indentLines(n.containerFlow(t,a.current()),u);return l(),c;function u(d,f,h){return f?(h?"":" ".repeat(o))+d:(h?i:i+" ".repeat(o-i.length))+d}}function fD(t,e,n,r){const s=n.enter("paragraph"),i=n.enter("phrasing"),o=n.containerPhrasing(t,r);return i(),s(),o}function pD(t,e,n,r){if(!t.children.some(function(a){return FP(a)}))return n.containerFlow(t,r);const i=n.enter("phrasing"),o=n.containerPhrasing(t,r);return i(),o}function mD(t){const e=t.options.strong||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize strong with `"+e+"` for `options.strong`, expected `*`, or `_`");return e}El.attention=og;El.peek=gD;function El(t,e,n,r){const s=n.enter("phrasing"),i=Cl(t,og,n,n.createTracker(r)),o=i?oi([i],r.before,r.after):"";return s(),o}function og(t,e){return{construct:"strong",markers:mD(e)==="*"?["*","_"]:["_","*"],sizes:[2]}}function gD(t,e,n){return n.options.strong||"*"}function yD(t,e,n,r){const s=e?e.children:[],i=n.indexStack[n.indexStack.length-1];return n.safe(t.value,{...r,afterNode:s[i+1],beforeNode:s[i-1]})}function bD(t){const e=t.options.ruleRepetition||3;if(e<3)throw new Error("Cannot serialize rules with repetition `"+e+"` for `options.ruleRepetition`, expected `3` or more");return e}function _D(t,e,n){const r=(ig(n)+(n.options.ruleSpaces?" ":"")).repeat(bD(n));return n.options.ruleSpaces?r.slice(0,-1):r}const ea={blockquote:$P,break:td,code:UP,definition:HP,emphasis:Il,hardBreak:td,heading:tD,html:Xm,image:Zm,imageReference:eg,inlineCode:tg,link:rg,linkReference:sg,list:uD,listItem:hD,paragraph:fD,root:pD,strong:El,text:yD,thematicBreak:_D};function vD(){return{enter:{table:wD,tableData:sd,tableHeader:sd,tableRow:SD},exit:{codeText:TD,table:xD,tableData:Yi,tableHeader:Yi,tableRow:Yi}}}function wD(t){const e=t._align;this.enter({type:"table",align:e.map(function(n){return n==="none"?null:n}),children:[],position:void 0},t),this.data.inTable=!0}function xD(t){this.exit(t),this.data.inTable=void 0}function SD(t){this.enter({type:"tableRow",children:[],position:void 0},t)}function Yi(t){this.exit(t)}function sd(t){this.enter({type:"tableCell",children:[],position:void 0},t)}function TD(t){let e=this.resume();this.data.inTable&&(e=e.replace(/\\([\\|])/g,CD));const n=this.stack[this.stack.length-1];n.type,n.value=e,this.exit(t)}function CD(t,e){return e==="|"?e:t}function ID(t){const e=t||{},{tableCellPadding:n,tablePipeAlign:r,stringLength:s}=e,i=n?" ":"|";return{handlers:{inlineCode:f,table:o,tableCell:l,tableRow:a},join:[kD],unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
41
|
+
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}]};function o(h,p,m,y){const g=u(h,m,y),b=g[0];if(b){let v=h.align?h.align.length:0,w=-1;if(!v)for(;++w<g.length;)g[w].length>v&&(v=g[w].length);for(;b.length<v;)b.push("")}return c(g,h.align)}function a(h,p,m,y){const g=d(h,m,y),b=c([g]);return b.slice(0,b.indexOf(`
|
|
42
|
+
`))}function l(h,p,m,y){const g=m.enter("tableCell"),b=m.enter("phrasing"),v=m.containerPhrasing(h,{...y,before:i,after:i});return b(),g(),v}function c(h,p){return OP(h,{align:p,alignDelimiters:r,fillRows:!1,padding:n,stringLength:s})}function u(h,p,m){const{children:y}=h;let g=-1;const b=[],v=p.enter("table");for(;++g<y.length;)b[g]=d(y[g],p,m);return v(),b}function d(h,p,m){const{children:y}=h;let g=-1;const b=[],v=p.enter("tableRow");for(;++g<y.length;)b[g]=l(y[g],h,p,m);return v(),b}function f(h,p,m){const y=ea.inlineCode(h,p,m);if(!m.stack.includes("tableCell"))return y;const g=[];let b=0,v=y.indexOf("|");for(;v!==-1;){let w=v;for(;w>b&&y.charCodeAt(w-1)===92;)w--;g.push(y.slice(b,v)),(v-w)%2===0&&g.push("\\"),b=v,v=y.indexOf("|",v+1)}return g.push(y.slice(b)),g.join("")}}function kD(t,e,n,r){if(t.type==="table"&&n.type==="listItem"&&n.spread===!1&&(e.type==="definition"||e.type==="heading"&&ED(e,r)||e.type==="paragraph"||e.type==="table"))return 1}function ED(t,e){let n=!1;return si(t,function(r){if(r.type==="break"||"value"in r&&/\r?\n|\r/.test(r.value))return n=!0,br}),!!((!t.depth||t.depth<3)&&Zs(t)&&(e.options.setext||n))}function AD(){return{exit:{taskListCheckValueChecked:id,taskListCheckValueUnchecked:id,paragraph:MD}}}function RD(){return{handlers:{paragraph:PD},join:[DD]}}function id(t){const e=this.stack[this.stack.length-2];e.type,e.checked=t.type==="taskListCheckValueChecked"}function MD(t){const e=this.stack[this.stack.length-2];if(e&&e.type==="listItem"&&typeof e.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const s=e.children;let i=-1,o;for(;++i<s.length;){const a=s[i];if(a.type==="paragraph"){o=a;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start={...r.position.start}))}}this.exit(t)}function PD(t,e,n,r){if(!e||e.type!=="listItem"||ag(e)!==t)return ea.paragraph(t,e,n,r);const s="["+(e.checked?"x":" ")+"] ",i=n.createTracker(r);i.move(s);const o=ea.paragraph(t.children.length>0?t:{type:"paragraph",children:[{type:"text",value:" "}]},e,n,{...r,...i.current()});return s+o}function DD(t,e,n){if(!(t.type==="definition"&&n.type==="listItem"))return;const r=ag(n);if(r&&n.children.indexOf(t)<n.children.indexOf(r))return 0}function ag(t){if(typeof t.checked=="boolean")for(const e of t.children){if(e.type==="paragraph")return e;if(e.type!=="definition")return}}function OD(){return[ZM(),SP(),kP(),vD(),AD()]}function LD(t){return{extensions:[eP(),TP(t),EP(),ID(t),RD()]}}const FD={tokenize:VD,partial:!0},lg={tokenize:UD,partial:!0},cg={tokenize:qD,partial:!0},ug={tokenize:HD,partial:!0},$D={tokenize:WD,partial:!0},dg={name:"wwwAutolink",tokenize:jD,previous:fg},hg={name:"protocolAutolink",tokenize:zD,previous:pg},Lt={name:"emailAutolink",tokenize:BD,previous:mg},wt={};function ND(){return{text:wt}}let Zt=48;for(;Zt<123;)wt[Zt]=Lt,Zt++,Zt===58?Zt=65:Zt===91&&(Zt=97);wt[43]=Lt;wt[45]=Lt;wt[46]=Lt;wt[95]=Lt;wt[72]=[Lt,hg];wt[104]=[Lt,hg];wt[87]=[Lt,dg];wt[119]=[Lt,dg];function BD(t,e,n){const r=this;let s,i;return o;function o(d){return!ta(d)||!mg.call(r,r.previous)||Al(r.events)?n(d):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),a(d))}function a(d){return ta(d)?(t.consume(d),a):d===64?(t.consume(d),l):n(d)}function l(d){return d===46?t.check($D,u,c)(d):d===45||d===95||Ie(d)?(i=!0,t.consume(d),l):u(d)}function c(d){return t.consume(d),s=!0,l}function u(d){return i&&s&&Ce(r.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),e(d)):n(d)}}function jD(t,e,n){const r=this;return s;function s(o){return o!==87&&o!==119||!fg.call(r,r.previous)||Al(r.events)?n(o):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(FD,t.attempt(lg,t.attempt(cg,i),n),n)(o))}function i(o){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),e(o)}}function zD(t,e,n){const r=this;let s="",i=!1;return o;function o(d){return(d===72||d===104)&&pg.call(r,r.previous)&&!Al(r.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),s+=String.fromCodePoint(d),t.consume(d),a):n(d)}function a(d){if(Ce(d)&&s.length<5)return s+=String.fromCodePoint(d),t.consume(d),a;if(d===58){const f=s.toLowerCase();if(f==="http"||f==="https")return t.consume(d),l}return n(d)}function l(d){return d===47?(t.consume(d),i?c:(i=!0,l)):n(d)}function c(d){return d===null||Es(d)||me(d)||gn(d)||Fr(d)?n(d):t.attempt(lg,t.attempt(cg,u),n)(d)}function u(d){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),e(d)}}function VD(t,e,n){let r=0;return s;function s(o){return(o===87||o===119)&&r<3?(r++,t.consume(o),s):o===46&&r===3?(t.consume(o),i):n(o)}function i(o){return o===null?n(o):e(o)}}function UD(t,e,n){let r,s,i;return o;function o(c){return c===46||c===95?t.check(ug,l,a)(c):c===null||me(c)||gn(c)||c!==45&&Fr(c)?l(c):(i=!0,t.consume(c),o)}function a(c){return c===95?r=!0:(s=r,r=void 0),t.consume(c),o}function l(c){return s||r||!i?n(c):e(c)}}function qD(t,e){let n=0,r=0;return s;function s(o){return o===40?(n++,t.consume(o),s):o===41&&r<n?i(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?t.check(ug,e,i)(o):o===null||me(o)||gn(o)?e(o):(t.consume(o),s)}function i(o){return o===41&&r++,t.consume(o),s}}function HD(t,e,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(t.consume(a),r):a===38?(t.consume(a),i):a===93?(t.consume(a),s):a===60||a===null||me(a)||gn(a)?e(a):n(a)}function s(a){return a===null||a===40||a===91||me(a)||gn(a)?e(a):r(a)}function i(a){return Ce(a)?o(a):n(a)}function o(a){return a===59?(t.consume(a),r):Ce(a)?(t.consume(a),o):n(a)}}function WD(t,e,n){return r;function r(i){return t.consume(i),s}function s(i){return Ie(i)?n(i):e(i)}}function fg(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||me(t)}function pg(t){return!Ce(t)}function mg(t){return!(t===47||ta(t))}function ta(t){return t===43||t===45||t===46||t===95||Ie(t)}function Al(t){let e=t.length,n=!1;for(;e--;){const r=t[e][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return t.length>0&&!n&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const GD={tokenize:tO,partial:!0};function KD(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:XD,continuation:{tokenize:ZD},exit:eO}},text:{91:{name:"gfmFootnoteCall",tokenize:JD},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:QD,resolveTo:YD}}}}function QD(t,e,n){const r=this;let s=r.events.length;const i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;s--;){const l=r.events[s][1];if(l.type==="labelImage"){o=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!o||!o._balanced)return n(l);const c=st(r.sliceSerialize({start:o.end,end:r.now()}));return c.codePointAt(0)!==94||!i.includes(c.slice(1))?n(l):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(l),t.exit("gfmFootnoteCallLabelMarker"),e(l))}}function YD(t,e){let n=t.length;for(;n--;)if(t[n][1].type==="labelImage"&&t[n][0]==="enter"){t[n][1];break}t[n+1][1].type="data",t[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},t[n+3][1].start),end:Object.assign({},t[t.length-1][1].end)},s={type:"gfmFootnoteCallMarker",start:Object.assign({},t[n+3][1].end),end:Object.assign({},t[n+3][1].end)};s.end.column++,s.end.offset++,s.end._bufferIndex++;const i={type:"gfmFootnoteCallString",start:Object.assign({},s.end),end:Object.assign({},t[t.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},i.start),end:Object.assign({},i.end)},a=[t[n+1],t[n+2],["enter",r,e],t[n+3],t[n+4],["enter",s,e],["exit",s,e],["enter",i,e],["enter",o,e],["exit",o,e],["exit",i,e],t[t.length-2],t[t.length-1],["exit",r,e]];return t.splice(n,t.length-n+1,...a),t}function JD(t,e,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i=0,o;return a;function a(d){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(d),t.exit("gfmFootnoteCallLabelMarker"),l}function l(d){return d!==94?n(d):(t.enter("gfmFootnoteCallMarker"),t.consume(d),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",c)}function c(d){if(i>999||d===93&&!o||d===null||d===91||me(d))return n(d);if(d===93){t.exit("chunkString");const f=t.exit("gfmFootnoteCallString");return s.includes(st(r.sliceSerialize(f)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(d),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),e):n(d)}return me(d)||(o=!0),i++,t.consume(d),d===92?u:c}function u(d){return d===91||d===92||d===93?(t.consume(d),i++,c):c(d)}}function XD(t,e,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i,o=0,a;return l;function l(p){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(p),t.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(p){return p===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(p),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",u):n(p)}function u(p){if(o>999||p===93&&!a||p===null||p===91||me(p))return n(p);if(p===93){t.exit("chunkString");const m=t.exit("gfmFootnoteDefinitionLabelString");return i=st(r.sliceSerialize(m)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(p),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),f}return me(p)||(a=!0),o++,t.consume(p),p===92?d:u}function d(p){return p===91||p===92||p===93?(t.consume(p),o++,u):u(p)}function f(p){return p===58?(t.enter("definitionMarker"),t.consume(p),t.exit("definitionMarker"),s.includes(i)||s.push(i),ue(t,h,"gfmFootnoteDefinitionWhitespace")):n(p)}function h(p){return e(p)}}function ZD(t,e,n){return t.check($r,e,t.attempt(GD,e,n))}function eO(t){t.exit("gfmFootnoteDefinition")}function tO(t,e,n){const r=this;return ue(t,s,"gfmFootnoteDefinitionIndent",5);function s(i){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?e(i):n(i)}}function nO(t){let n=(t||{}).singleTilde;const r={name:"strikethrough",tokenize:i,resolveAll:s};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function s(o,a){let l=-1;for(;++l<o.length;)if(o[l][0]==="enter"&&o[l][1].type==="strikethroughSequenceTemporary"&&o[l][1]._close){let c=l;for(;c--;)if(o[c][0]==="exit"&&o[c][1].type==="strikethroughSequenceTemporary"&&o[c][1]._open&&o[l][1].end.offset-o[l][1].start.offset===o[c][1].end.offset-o[c][1].start.offset){o[l][1].type="strikethroughSequence",o[c][1].type="strikethroughSequence";const u={type:"strikethrough",start:Object.assign({},o[c][1].start),end:Object.assign({},o[l][1].end)},d={type:"strikethroughText",start:Object.assign({},o[c][1].end),end:Object.assign({},o[l][1].start)},f=[["enter",u,a],["enter",o[c][1],a],["exit",o[c][1],a],["enter",d,a]],h=a.parser.constructs.insideSpan.null;h&&rt(f,f.length,0,ei(h,o.slice(c+1,l),a)),rt(f,f.length,0,[["exit",d,a],["enter",o[l][1],a],["exit",o[l][1],a],["exit",u,a]]),rt(o,c-1,l-c+3,f),l=c+f.length-2;break}}for(l=-1;++l<o.length;)o[l][1].type==="strikethroughSequenceTemporary"&&(o[l][1].type="data");return o}function i(o,a,l){const c=this.previous,u=this.events;let d=0;return f;function f(p){return c===126&&u[u.length-1][1].type!=="characterEscape"?l(p):(o.enter("strikethroughSequenceTemporary"),h(p))}function h(p){const m=Vt(c);if(p===126)return d>1?l(p):(o.consume(p),d++,h);if(d<2&&!n)return l(p);const y=o.exit("strikethroughSequenceTemporary"),g=Vt(p);return y._open=!g||g===2&&!!m,y._close=!m||m===2&&!!g,a(p)}}}class rO{constructor(){this.map=[],this.index=new Map}add(e,n,r){sO(this,e,n,r)}consume(e){if(this.map.sort(function(i,o){return i[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(e.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),e.length=this.map[n][0];r.push(e.slice()),e.length=0;let s=r.pop();for(;s;){for(const i of s)e.push(i);s=r.pop()}this.map.length=0,this.index.clear()}}function sO(t,e,n,r){if(n===0&&r.length===0)return;const s=t.index.get(e);if(s){s[1]+=n,s[2].push(...r);return}const i=[e,n,r];t.map.push(i),t.index.set(e,i)}function iO(t,e){let n=!1;const r=[];for(;e<t.length;){const s=t[e];if(n){if(s[0]==="enter")s[1].type==="tableContent"&&r.push(t[e+1][1].type==="tableDelimiterMarker"?"left":"none");else if(s[1].type==="tableContent"){if(t[e-1][1].type==="tableDelimiterMarker"){const i=r.length-1;r[i]=r[i]==="left"?"center":"right"}}else if(s[1].type==="tableDelimiterRow")break}else s[0]==="enter"&&s[1].type==="tableDelimiterRow"&&(n=!0);e+=1}return r}function oO(){return{flow:{null:{name:"table",tokenize:aO,resolveAll:lO}}}}function aO(t,e,n){const r=this;let s=0,i=0,o;return a;function a(x){let M=r.events.length-1;for(;M>-1;){const{type:$}=r.events[M][1];if($==="lineEnding"||$==="linePrefix")M--;else break}const P=M>-1?r.events[M][1].type:null,T=P==="tableHead"||P==="tableRow"?_:l;return T===_&&r.parser.lazy[r.now().line]?n(x):T(x)}function l(x){return t.enter("tableHead"),t.enter("tableRow"),c(x)}function c(x){return x===124||(o=!0,i+=1),u(x)}function u(x){return x===null?n(x):Y(x)?i>1?(i=0,r.interrupt=!0,t.exit("tableRow"),t.enter("lineEnding"),t.consume(x),t.exit("lineEnding"),h):n(x):ae(x)?ue(t,u,"whitespace")(x):(i+=1,o&&(o=!1,s+=1),x===124?(t.enter("tableCellDivider"),t.consume(x),t.exit("tableCellDivider"),o=!0,u):(t.enter("data"),d(x)))}function d(x){return x===null||x===124||me(x)?(t.exit("data"),u(x)):(t.consume(x),x===92?f:d)}function f(x){return x===92||x===124?(t.consume(x),d):d(x)}function h(x){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(x):(t.enter("tableDelimiterRow"),o=!1,ae(x)?ue(t,p,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(x):p(x))}function p(x){return x===45||x===58?y(x):x===124?(o=!0,t.enter("tableCellDivider"),t.consume(x),t.exit("tableCellDivider"),m):k(x)}function m(x){return ae(x)?ue(t,y,"whitespace")(x):y(x)}function y(x){return x===58?(i+=1,o=!0,t.enter("tableDelimiterMarker"),t.consume(x),t.exit("tableDelimiterMarker"),g):x===45?(i+=1,g(x)):x===null||Y(x)?w(x):k(x)}function g(x){return x===45?(t.enter("tableDelimiterFiller"),b(x)):k(x)}function b(x){return x===45?(t.consume(x),b):x===58?(o=!0,t.exit("tableDelimiterFiller"),t.enter("tableDelimiterMarker"),t.consume(x),t.exit("tableDelimiterMarker"),v):(t.exit("tableDelimiterFiller"),v(x))}function v(x){return ae(x)?ue(t,w,"whitespace")(x):w(x)}function w(x){return x===124?p(x):x===null||Y(x)?!o||s!==i?k(x):(t.exit("tableDelimiterRow"),t.exit("tableHead"),e(x)):k(x)}function k(x){return n(x)}function _(x){return t.enter("tableRow"),A(x)}function A(x){return x===124?(t.enter("tableCellDivider"),t.consume(x),t.exit("tableCellDivider"),A):x===null||Y(x)?(t.exit("tableRow"),e(x)):ae(x)?ue(t,A,"whitespace")(x):(t.enter("data"),E(x))}function E(x){return x===null||x===124||me(x)?(t.exit("data"),A(x)):(t.consume(x),x===92?D:E)}function D(x){return x===92||x===124?(t.consume(x),E):E(x)}}function lO(t,e){let n=-1,r=!0,s=0,i=[0,0,0,0],o=[0,0,0,0],a=!1,l=0,c,u,d;const f=new rO;for(;++n<t.length;){const h=t[n],p=h[1];h[0]==="enter"?p.type==="tableHead"?(a=!1,l!==0&&(od(f,e,l,c,u),u=void 0,l=0),c={type:"table",start:Object.assign({},p.start),end:Object.assign({},p.end)},f.add(n,0,[["enter",c,e]])):p.type==="tableRow"||p.type==="tableDelimiterRow"?(r=!0,d=void 0,i=[0,0,0,0],o=[0,n+1,0,0],a&&(a=!1,u={type:"tableBody",start:Object.assign({},p.start),end:Object.assign({},p.end)},f.add(n,0,[["enter",u,e]])),s=p.type==="tableDelimiterRow"?2:u?3:1):s&&(p.type==="data"||p.type==="tableDelimiterMarker"||p.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(i[1]!==0&&(o[0]=o[1],d=is(f,e,i,s,void 0,d),i=[0,0,0,0]),o[2]=n)):p.type==="tableCellDivider"&&(r?r=!1:(i[1]!==0&&(o[0]=o[1],d=is(f,e,i,s,void 0,d)),i=o,o=[i[1],n,0,0])):p.type==="tableHead"?(a=!0,l=n):p.type==="tableRow"||p.type==="tableDelimiterRow"?(l=n,i[1]!==0?(o[0]=o[1],d=is(f,e,i,s,n,d)):o[1]!==0&&(d=is(f,e,o,s,n,d)),s=0):s&&(p.type==="data"||p.type==="tableDelimiterMarker"||p.type==="tableDelimiterFiller")&&(o[3]=n)}for(l!==0&&od(f,e,l,c,u),f.consume(e.events),n=-1;++n<e.events.length;){const h=e.events[n];h[0]==="enter"&&h[1].type==="table"&&(h[1]._align=iO(e.events,n))}return t}function is(t,e,n,r,s,i){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(i.end=Object.assign({},An(e.events,n[0])),t.add(n[0],0,[["exit",i,e]]));const l=An(e.events,n[1]);if(i={type:o,start:Object.assign({},l),end:Object.assign({},l)},t.add(n[1],0,[["enter",i,e]]),n[2]!==0){const c=An(e.events,n[2]),u=An(e.events,n[3]),d={type:a,start:Object.assign({},c),end:Object.assign({},u)};if(t.add(n[2],0,[["enter",d,e]]),r!==2){const f=e.events[n[2]],h=e.events[n[3]];if(f[1].end=Object.assign({},h[1].end),f[1].type="chunkText",f[1].contentType="text",n[3]>n[2]+1){const p=n[2]+1,m=n[3]-n[2]-1;t.add(p,m,[])}}t.add(n[3]+1,0,[["exit",d,e]])}return s!==void 0&&(i.end=Object.assign({},An(e.events,s)),t.add(s,0,[["exit",i,e]]),i=void 0),i}function od(t,e,n,r,s){const i=[],o=An(e.events,n);s&&(s.end=Object.assign({},o),i.push(["exit",s,e])),r.end=Object.assign({},o),i.push(["exit",r,e]),t.add(n+1,0,i)}function An(t,e){const n=t[e],r=n[0]==="enter"?"start":"end";return n[1][r]}const cO={name:"tasklistCheck",tokenize:dO};function uO(){return{text:{91:cO}}}function dO(t,e,n){const r=this;return s;function s(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(t.enter("taskListCheck"),t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),i)}function i(l){return me(l)?(t.enter("taskListCheckValueUnchecked"),t.consume(l),t.exit("taskListCheckValueUnchecked"),o):l===88||l===120?(t.enter("taskListCheckValueChecked"),t.consume(l),t.exit("taskListCheckValueChecked"),o):n(l)}function o(l){return l===93?(t.enter("taskListCheckMarker"),t.consume(l),t.exit("taskListCheckMarker"),t.exit("taskListCheck"),a):n(l)}function a(l){return Y(l)?e(l):ae(l)?t.check({tokenize:hO},e,n)(l):n(l)}}function hO(t,e,n){return ue(t,r,"whitespace");function r(s){return s===null?n(s):e(s)}}function fO(t){return vm([ND(),KD(),nO(t),oO(),uO()])}const pO={};function r3(t){const e=this,n=t||pO,r=e.data(),s=r.micromarkExtensions||(r.micromarkExtensions=[]),i=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);s.push(fO(n)),i.push(OD()),o.push(LD(n))}export{vO as A,e3 as B,r3 as C,aE as D,JO as E,N as F,LM as G,QO as H,GO as I,YO as J,XO as K,KO as L,n3 as M,HO as N,WO as O,yt as a,Ml as b,bt as c,qn as d,cd as e,_r as f,Le as g,an as h,Ut as i,Ls as j,ZO as k,yO as l,ln as m,Rg as n,hd as o,Er as p,dd as q,xg as r,jt as s,wO as t,Z as u,xO as v,pt as w,gO as x,bO as y,_O as z};
|
|
43
|
+
//# sourceMappingURL=chat-vendor-PY5rkhAV.js.map
|