loopat 0.1.48 → 0.1.49
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/package.json +3 -2
- package/server/src/api-v1.ts +8 -0
- package/web/dist/assets/{Editor-CeZLgps-.js → Editor-BnfYQQzs.js} +1 -1
- package/web/dist/assets/{Markdown-CnZpm-Uk.js → Markdown-D0eu-WNR.js} +1 -1
- package/web/dist/assets/{index-C7az8Kc1.js → index-CoiEN2FX.js} +3 -3
- package/web/dist/index.html +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Editor-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Editor-BnfYQQzs.js","assets/jsx-runtime-DAYmCNe8.js","assets/CodeEditor-JV36Z3V5.js","assets/w3c-keyname-DXh_HxYD.js","assets/Terminal-Vi3Ufhgi.js","assets/Terminal-BrP-ENHg.css","assets/Markdown-D0eu-WNR.js","assets/lib-B8L80SIn.js","assets/MilkdownEditor-t_CG4MJj.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
import{i as e,n as t,o as n,r,t as i}from"./jsx-runtime-DAYmCNe8.js";import{c as a,g as o,h as s,l as c,p as l,s as u,t as d}from"./lib-B8L80SIn.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var f=r((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),p=r(((e,t)=>{t.exports=f()})),m=r((e=>{var n=t();function r(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function i(){}var a={d:{f:i,r:function(){throw Error(r(522))},D:i,C:i,L:i,m:i,X:i,S:i,M:i},p:0,findDOMNode:null},o=Symbol.for(`react.portal`);function s(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:o,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var c=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=a,e.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(r(299));return s(e,t,null,n)},e.flushSync=function(e){var t=c.T,n=a.p;try{if(c.T=null,a.p=2,e)return e()}finally{c.T=t,a.p=n,a.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,a.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&a.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin),i=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?a.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:i,fetchPriority:o}):n===`script`&&a.d.X(e,{crossOrigin:r,integrity:i,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=l(t.as,t.crossOrigin);a.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??a.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin);a.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=l(t.as,t.crossOrigin);a.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else a.d.m(e)},e.requestFormReset=function(e){a.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return c.H.useFormState(e,t,n)},e.useFormStatus=function(){return c.H.useHostTransitionStatus()},e.version=`19.2.6`})),h=r(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=m()})),g=r((e=>{var n=p(),r=t(),i=h();function a(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function o(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function s(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function c(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function u(e){if(s(e)!==e)throw Error(a(188))}function d(e){var t=e.alternate;if(!t){if(t=s(e),t===null)throw Error(a(188));return t===e?e:null}for(var n=e,r=t;;){var i=n.return;if(i===null)break;var o=i.alternate;if(o===null){if(r=i.return,r!==null){n=r;continue}break}if(i.child===o.child){for(o=i.child;o;){if(o===n)return u(i),e;if(o===r)return u(i),t;o=o.sibling}throw Error(a(188))}if(n.return!==r.return)n=i,r=o;else{for(var c=!1,l=i.child;l;){if(l===n){c=!0,n=i,r=o;break}if(l===r){c=!0,r=i,n=o;break}l=l.sibling}if(!c){for(l=o.child;l;){if(l===n){c=!0,n=o,r=i;break}if(l===r){c=!0,r=o,n=i;break}l=l.sibling}if(!c)throw Error(a(189))}}if(n.alternate!==r)throw Error(a(190))}if(n.tag!==3)throw Error(a(188));return n.stateNode.current===n?e:t}function f(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=f(e),t!==null)return t;e=e.sibling}return null}var m=Object.assign,g=Symbol.for(`react.element`),_=Symbol.for(`react.transitional.element`),v=Symbol.for(`react.portal`),y=Symbol.for(`react.fragment`),b=Symbol.for(`react.strict_mode`),x=Symbol.for(`react.profiler`),S=Symbol.for(`react.consumer`),C=Symbol.for(`react.context`),w=Symbol.for(`react.forward_ref`),T=Symbol.for(`react.suspense`),E=Symbol.for(`react.suspense_list`),D=Symbol.for(`react.memo`),O=Symbol.for(`react.lazy`),k=Symbol.for(`react.activity`),A=Symbol.for(`react.memo_cache_sentinel`),j=Symbol.iterator;function M(e){return typeof e!=`object`||!e?null:(e=j&&e[j]||e[`@@iterator`],typeof e==`function`?e:null)}var N=Symbol.for(`react.client.reference`);function P(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===N?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case y:return`Fragment`;case x:return`Profiler`;case b:return`StrictMode`;case T:return`Suspense`;case E:return`SuspenseList`;case k:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case v:return`Portal`;case C:return e.displayName||`Context`;case S:return(e._context.displayName||`Context`)+`.Consumer`;case w:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case D:return t=e.displayName||null,t===null?P(e.type)||`Memo`:t;case O:t=e._payload,e=e._init;try{return P(e(t))}catch{}}return null}var F=Array.isArray,I=r.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,L=i.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,R={pending:!1,data:null,method:null,action:null},z=[],B=-1;function V(e){return{current:e}}function H(e){0>B||(e.current=z[B],z[B]=null,B--)}function U(e,t){B++,z[B]=e.current,e.current=t}var W=V(null),G=V(null),ee=V(null),K=V(null);function te(e,t){switch(U(ee,t),U(G,e),U(W,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?qd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=qd(t),e=Jd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}H(W),U(W,e)}function ne(){H(W),H(G),H(ee)}function re(e){e.memoizedState!==null&&U(K,e);var t=W.current,n=Jd(t,e.type);t!==n&&(U(G,e),U(W,n))}function ie(e){G.current===e&&(H(W),H(G)),K.current===e&&(H(K),ip._currentValue=R)}var ae,oe;function se(e){if(ae===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);ae=t&&t[1]||``,oe=-1<e.stack.indexOf(`
|
|
3
3
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
4
4
|
`+ae+e+oe}var ce=!1;function le(e,t){if(!e||ce)return``;ce=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,`props`,{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,`name`,{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
|
|
@@ -53,7 +53,7 @@ Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}
|
|
|
53
53
|
|
|
54
54
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
55
55
|
|
|
56
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return w.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},oc=`DialogDescriptionWarning`,sc=({contentRef:e,descriptionId:t})=>{let n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${ic(oc).contentName}}.`;return w.useEffect(()=>{let r=e.current?.getAttribute(`aria-describedby`);t&&r&&(document.getElementById(t)||console.warn(n))},[n,e,t]),null},cc=Ns,lc=zs,uc=Vs,dc=Gs,fc=Xs,pc=Qs,mc=ec;function hc(e){let[t,n]=w.useState(void 0);return ta(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}else n(void 0)},[e]),t}var gc=[`top`,`right`,`bottom`,`left`],_c=Math.min,vc=Math.max,yc=Math.round,bc=Math.floor,xc=e=>({x:e,y:e}),Sc={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Cc(e,t,n){return vc(e,_c(t,n))}function wc(e,t){return typeof e==`function`?e(t):e}function Tc(e){return e.split(`-`)[0]}function Ec(e){return e.split(`-`)[1]}function Dc(e){return e===`x`?`y`:`x`}function Oc(e){return e===`y`?`height`:`width`}function kc(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function Ac(e){return Dc(kc(e))}function jc(e,t,n){n===void 0&&(n=!1);let r=Ec(e),i=Ac(e),a=Oc(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Bc(o)),[o,Bc(o)]}function Mc(e){let t=Bc(e);return[Nc(e),t,Nc(t)]}function Nc(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var Pc=[`left`,`right`],Fc=[`right`,`left`],Ic=[`top`,`bottom`],Lc=[`bottom`,`top`];function Rc(e,t,n){switch(e){case`top`:case`bottom`:return n?t?Fc:Pc:t?Pc:Fc;case`left`:case`right`:return t?Ic:Lc;default:return[]}}function zc(e,t,n,r){let i=Ec(e),a=Rc(Tc(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Nc)))),a}function Bc(e){let t=Tc(e);return Sc[t]+e.slice(t.length)}function Vc(e){return{top:0,right:0,bottom:0,left:0,...e}}function Hc(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Vc(e)}function Uc(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function Wc(e,t,n){let{reference:r,floating:i}=e,a=kc(t),o=Ac(t),s=Oc(o),c=Tc(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch(Ec(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}async function Gc(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=wc(t,e),p=Hc(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Uc(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=Uc(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var Kc=50,qc=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Gc},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Wc(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<Kc&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=Wc(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},Jc=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=wc(e,t)||{};if(l==null)return{};let d=Hc(u),f={x:n,y:r},p=Ac(i),m=Oc(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=_c(d[_],T),D=_c(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=Cc(O,A,k),M=!c.arrow&&Ec(i)!=null&&A!==j&&a.reference[m]/2-(A<O?E:D)-h[m]/2<0,N=M?A<O?A-O:A-k:0;return{[p]:f[p]+N,data:{[p]:j,centerOffset:A-j-N,...M&&{alignmentOffset:N}},reset:M}}}),Yc=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=wc(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Tc(r),_=kc(o),v=Tc(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Bc(o)]:Mc(o)),x=p!==`none`;!d&&x&&b.push(...zc(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=jc(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==kc(t))||T.every(e=>kc(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=kc(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}};function Xc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Zc(e){return gc.some(t=>e[t]>=0)}var Qc=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=wc(e,t);switch(i){case`referenceHidden`:{let e=Xc(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:Zc(e)}}}case`escaped`:{let e=Xc(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:Zc(e)}}}default:return{}}}}},$c=new Set([`left`,`top`]);async function el(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Tc(n),s=Ec(n),c=kc(n)===`y`,l=$c.has(o)?-1:1,u=a&&c?-1:1,d=wc(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var tl=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await el(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},nl=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=wc(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=kc(Tc(i)),p=Dc(f),m=u[p],h=u[f];if(o){let e=p===`y`?`top`:`left`,t=p===`y`?`bottom`:`right`,n=m+d[e],r=m-d[t];m=Cc(n,m,r)}if(s){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=h+d[e],r=h-d[t];h=Cc(n,h,r)}let g=c.fn({...t,[p]:m,[f]:h});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:o,[f]:s}}}}}},rl=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=wc(e,t),u={x:n,y:r},d=kc(i),f=Dc(d),p=u[f],m=u[d],h=wc(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=$c.has(Tc(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},il=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){var n,r;let{placement:i,rects:a,platform:o,elements:s}=t,{apply:c=()=>{},...l}=wc(e,t),u=await o.detectOverflow(t,l),d=Tc(i),f=Ec(i),p=kc(i)===`y`,{width:m,height:h}=a.floating,g,_;d===`top`||d===`bottom`?(g=d,_=f===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?`start`:`end`)?`left`:`right`):(_=d,g=f===`end`?`top`:`bottom`);let v=h-u.top-u.bottom,y=m-u.left-u.right,b=_c(h-u[g],v),x=_c(m-u[_],y),S=!t.middlewareData.shift,C=b,w=x;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(w=y),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(C=v),S&&!f){let e=vc(u.left,0),t=vc(u.right,0),n=vc(u.top,0),r=vc(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:vc(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:vc(u.top,u.bottom))}await c({...t,availableWidth:w,availableHeight:C});let T=await o.getDimensions(s.floating);return m!==T.width||h!==T.height?{reset:{rects:!0}}:{}}}};function al(){return typeof window<`u`}function ol(e){return ll(e)?(e.nodeName||``).toLowerCase():`#document`}function sl(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function cl(e){return((ll(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function ll(e){return al()?e instanceof Node||e instanceof sl(e).Node:!1}function ul(e){return al()?e instanceof Element||e instanceof sl(e).Element:!1}function dl(e){return al()?e instanceof HTMLElement||e instanceof sl(e).HTMLElement:!1}function fl(e){return!al()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof sl(e).ShadowRoot}function pl(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=wl(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function ml(e){return/^(table|td|th)$/.test(ol(e))}function hl(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var gl=/transform|translate|scale|rotate|perspective|filter/,_l=/paint|layout|strict|content/,vl=e=>!!e&&e!==`none`,yl;function bl(e){let t=ul(e)?wl(e):e;return vl(t.transform)||vl(t.translate)||vl(t.scale)||vl(t.rotate)||vl(t.perspective)||!Sl()&&(vl(t.backdropFilter)||vl(t.filter))||gl.test(t.willChange||``)||_l.test(t.contain||``)}function xl(e){let t=El(e);for(;dl(t)&&!Cl(t);){if(bl(t))return t;if(hl(t))return null;t=El(t)}return null}function Sl(){return yl??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),yl}function Cl(e){return/^(html|body|#document)$/.test(ol(e))}function wl(e){return sl(e).getComputedStyle(e)}function Tl(e){return ul(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function El(e){if(ol(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||fl(e)&&e.host||cl(e);return fl(t)?t.host:t}function Dl(e){let t=El(e);return Cl(t)?e.ownerDocument?e.ownerDocument.body:e.body:dl(t)&&pl(t)?t:Dl(t)}function Ol(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Dl(e),i=r===e.ownerDocument?.body,a=sl(r);if(i){let e=kl(a);return t.concat(a,a.visualViewport||[],pl(r)?r:[],e&&n?Ol(e):[])}else return t.concat(r,Ol(r,[],n))}function kl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Al(e){let t=wl(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=dl(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=yc(n)!==a||yc(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function jl(e){return ul(e)?e:e.contextElement}function Ml(e){let t=jl(e);if(!dl(t))return xc(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Al(t),o=(a?yc(n.width):n.width)/r,s=(a?yc(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var Nl=xc(0);function Pl(e){let t=sl(e);return!Sl()||!t.visualViewport?Nl:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Fl(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==sl(e)?!1:t}function Il(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=jl(e),o=xc(1);t&&(r?ul(r)&&(o=Ml(r)):o=Ml(e));let s=Fl(a,n,r)?Pl(a):xc(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=sl(a),t=r&&ul(r)?sl(r):r,n=e,i=kl(n);for(;i&&r&&t!==n;){let e=Ml(i),t=i.getBoundingClientRect(),r=wl(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=sl(i),i=kl(n)}}return Uc({width:u,height:d,x:c,y:l})}function Ll(e,t){let n=Tl(e).scrollLeft;return t?t.left+n:Il(cl(e)).left+n}function Rl(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Ll(e,n),y:n.top+t.scrollTop}}function zl(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=cl(r),s=t?hl(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=xc(1),u=xc(0),d=dl(r);if((d||!d&&!a)&&((ol(r)!==`body`||pl(o))&&(c=Tl(r)),d)){let e=Il(r);l=Ml(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?Rl(o,c):xc(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function Bl(e){return Array.from(e.getClientRects())}function Vl(e){let t=cl(e),n=Tl(e),r=e.ownerDocument.body,i=vc(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=vc(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+Ll(e),s=-n.scrollTop;return wl(r).direction===`rtl`&&(o+=vc(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var Hl=25;function Ul(e,t){let n=sl(e),r=cl(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=Sl();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=Ll(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=Hl&&(a-=o)}else l<=Hl&&(a+=l);return{width:a,height:o,x:s,y:c}}function Wl(e,t){let n=Il(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=dl(e)?Ml(e):xc(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Gl(e,t,n){let r;if(t===`viewport`)r=Ul(e,n);else if(t===`document`)r=Vl(cl(e));else if(ul(t))r=Wl(t,n);else{let n=Pl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Uc(r)}function Kl(e,t){let n=El(e);return n===t||!ul(n)||Cl(n)?!1:wl(n).position===`fixed`||Kl(n,t)}function ql(e,t){let n=t.get(e);if(n)return n;let r=Ol(e,[],!1).filter(e=>ul(e)&&ol(e)!==`body`),i=null,a=wl(e).position===`fixed`,o=a?El(e):e;for(;ul(o)&&!Cl(o);){let t=wl(o),n=bl(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||pl(o)&&!n&&Kl(e,o))?r=r.filter(e=>e!==o):i=t,o=El(o)}return t.set(e,r),r}function Jl(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?hl(t)?[]:ql(t,this._c):[].concat(n),r],o=Gl(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=Gl(t,a[e],i);s=vc(n.top,s),c=_c(n.right,c),l=_c(n.bottom,l),u=vc(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Yl(e){let{width:t,height:n}=Al(e);return{width:t,height:n}}function Xl(e,t,n){let r=dl(t),i=cl(t),a=n===`fixed`,o=Il(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=xc(0);function l(){c.x=Ll(i)}if(r||!r&&!a)if((ol(t)!==`body`||pl(i))&&(s=Tl(t)),r){let e=Il(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?Rl(i,s):xc(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function Zl(e){return wl(e).position===`static`}function Ql(e,t){if(!dl(e)||wl(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return cl(e)===n&&(n=n.ownerDocument.body),n}function $l(e,t){let n=sl(e);if(hl(e))return n;if(!dl(e)){let t=El(e);for(;t&&!Cl(t);){if(ul(t)&&!Zl(t))return t;t=El(t)}return n}let r=Ql(e,t);for(;r&&ml(r)&&Zl(r);)r=Ql(r,t);return r&&Cl(r)&&Zl(r)&&!bl(r)?n:r||xl(e)||n}var eu=async function(e){let t=this.getOffsetParent||$l,n=this.getDimensions,r=await n(e.floating);return{reference:Xl(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function tu(e){return wl(e).direction===`rtl`}var nu={convertOffsetParentRelativeRectToViewportRelativeRect:zl,getDocumentElement:cl,getClippingRect:Jl,getOffsetParent:$l,getElementRects:eu,getClientRects:Bl,getDimensions:Yl,getScale:Ml,isElement:ul,isRTL:tu};function ru(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function iu(e,t){let n=null,r,i=cl(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=bc(d),h=bc(i.clientWidth-(u+f)),g=bc(i.clientHeight-(d+p)),_=bc(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:vc(0,_c(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!ru(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function au(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=jl(e),u=i||a?[...l?Ol(l):[],...t?Ol(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?iu(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?Il(e):null;c&&g();function g(){let t=Il(e);h&&!ru(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var ou=tl,su=nl,cu=Yc,lu=il,uu=Qc,du=Jc,fu=rl,pu=(e,t,n)=>{let r=new Map,i={platform:nu,...n},a={...i.platform,_c:r};return qc(e,t,{...i,platform:a})},mu=typeof document<`u`?w.useLayoutEffect:function(){};function hu(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!hu(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!hu(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function gu(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function _u(e,t){let n=gu(e);return Math.round(t*n)/n}function vu(e){let t=w.useRef(e);return mu(()=>{t.current=e}),t}function yu(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=w.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=w.useState(r);hu(f,r)||p(r);let[m,h]=w.useState(null),[g,_]=w.useState(null),v=w.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=w.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=w.useRef(null),C=w.useRef(null),T=w.useRef(u),E=c!=null,D=vu(c),O=vu(i),k=vu(l),A=w.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),pu(S.current,C.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!hu(T.current,t)&&(T.current=t,_t.flushSync(()=>{d(t)}))})},[f,t,n,O,k]);mu(()=>{l===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let j=w.useRef(!1);mu(()=>(j.current=!0,()=>{j.current=!1}),[]),mu(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(D.current)return D.current(b,x,A);A()}},[b,x,A,D,E]);let M=w.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),N=w.useMemo(()=>({reference:b,floating:x}),[b,x]),P=w.useMemo(()=>{let e={position:n,left:0,top:0};if(!N.floating)return e;let t=_u(N.floating,u.x),r=_u(N.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...gu(N.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,N.floating,u.x,u.y]);return w.useMemo(()=>({...u,update:A,refs:M,elements:N,floatingStyles:P}),[u,A,M,N,P])}var bu=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:du({element:r.current,padding:i}).fn(n):r?du({element:r,padding:i}).fn(n):{}}}},xu=(e,t)=>{let n=ou(e);return{name:n.name,fn:n.fn,options:[e,t]}},Su=(e,t)=>{let n=su(e);return{name:n.name,fn:n.fn,options:[e,t]}},Cu=(e,t)=>({fn:fu(e).fn,options:[e,t]}),wu=(e,t)=>{let n=cu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Tu=(e,t)=>{let n=lu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eu=(e,t)=>{let n=uu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Du=(e,t)=>{let n=bu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ou=`Arrow`,ku=w.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,q.jsx)(Gi.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,q.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})});ku.displayName=Ou;var Au=ku,ju=`Popper`,[Mu,Nu]=Qi(ju),[Pu,Fu]=Mu(ju),Iu=e=>{let{__scopePopper:t,children:n}=e,[r,i]=w.useState(null);return(0,q.jsx)(Pu,{scope:t,anchor:r,onAnchorChange:i,children:n})};Iu.displayName=ju;var Lu=`PopperAnchor`,Ru=w.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=Fu(Lu,n),o=w.useRef(null),s=Ii(t,o),c=w.useRef(null);return w.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,q.jsx)(Gi.div,{...i,ref:s})});Ru.displayName=Lu;var zu=`PopperContent`,[Bu,Vu]=Mu(zu),Hu=w.forwardRef((e,t)=>{let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=Fu(zu,n),[_,v]=w.useState(null),y=Ii(t,e=>v(e)),[b,x]=w.useState(null),S=hc(b),C=S?.width??0,T=S?.height??0,E=r+(a===`center`?``:`-`+a),D=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},O=Array.isArray(l)?l:[l],k=O.length>0,A={padding:D,boundary:O.filter(Ku),altBoundary:k},{refs:j,floatingStyles:M,placement:N,isPositioned:P,middlewareData:F}=yu({strategy:`fixed`,placement:E,whileElementsMounted:(...e)=>au(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[xu({mainAxis:i+T,alignmentAxis:o}),c&&Su({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Cu():void 0,...A}),c&&wu({...A}),Tu({...A,apply:({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)}}),b&&Du({element:b,padding:s}),qu({arrowWidth:C,arrowHeight:T}),f&&Eu({strategy:`referenceHidden`,...A})]}),[I,L]=Ju(N),R=Da(m);ta(()=>{P&&R?.()},[P,R]);let z=F.arrow?.x,B=F.arrow?.y,V=F.arrow?.centerOffset!==0,[H,U]=w.useState();return ta(()=>{_&&U(window.getComputedStyle(_).zIndex)},[_]),(0,q.jsx)(`div`,{ref:j.setFloating,"data-radix-popper-content-wrapper":``,style:{...M,transform:P?M.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:H,"--radix-popper-transform-origin":[F.transformOrigin?.x,F.transformOrigin?.y].join(` `),...F.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,q.jsx)(Bu,{scope:n,placedSide:I,onArrowChange:x,arrowX:z,arrowY:B,shouldHideArrow:V,children:(0,q.jsx)(Gi.div,{"data-side":I,"data-align":L,...h,ref:y,style:{...h.style,animation:P?void 0:`none`}})})})});Hu.displayName=zu;var Uu=`PopperArrow`,Wu={top:`bottom`,right:`left`,bottom:`top`,left:`right`},Gu=w.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=Vu(Uu,n),a=Wu[i.placedSide];return(0,q.jsx)(`span`,{ref:i.onArrowChange,style:{position:`absolute`,left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:``,right:`0 0`,bottom:`center 0`,left:`100% 0`}[i.placedSide],transform:{top:`translateY(100%)`,right:`translateY(50%) rotate(90deg) translateX(-50%)`,bottom:`rotate(180deg)`,left:`translateY(50%) rotate(-90deg) translateX(50%)`}[i.placedSide],visibility:i.shouldHideArrow?`hidden`:void 0},children:(0,q.jsx)(Au,{...r,ref:t,style:{...r.style,display:`block`}})})});Gu.displayName=Uu;function Ku(e){return e!==null}var qu=e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=Ju(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}});function Ju(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var Yu=Iu,Xu=Ru,Zu=Hu,Qu=Gu,$u=`Popover`,[ed,td]=Qi($u,[Nu]),nd=Nu(),[rd,id]=ed($u),ad=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=nd(t),c=w.useRef(null),[l,u]=w.useState(!1),[d,f]=ra({prop:r,defaultProp:i??!1,onChange:a,caller:$u});return(0,q.jsx)(Yu,{...s,children:(0,q.jsx)(rd,{scope:t,contentId:pa(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:w.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:w.useCallback(()=>u(!0),[]),onCustomAnchorRemove:w.useCallback(()=>u(!1),[]),modal:o,children:n})})};ad.displayName=$u;var od=`PopoverAnchor`,sd=w.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=id(od,n),a=nd(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return w.useEffect(()=>(o(),()=>s()),[o,s]),(0,q.jsx)(Xu,{...a,...r,ref:t})});sd.displayName=od;var cd=`PopoverTrigger`,ld=w.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=id(cd,n),a=nd(n),o=Ii(t,i.triggerRef),s=(0,q.jsx)(Gi.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":wd(i.open),...r,ref:o,onClick:ea(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,q.jsx)(Xu,{asChild:!0,...a,children:s})});ld.displayName=cd;var ud=`PopoverPortal`,[dd,fd]=ed(ud,{forceMount:void 0}),pd=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=id(ud,t);return(0,q.jsx)(dd,{scope:t,forceMount:n,children:(0,q.jsx)(sa,{present:n||a.open,children:(0,q.jsx)(ao,{asChild:!0,container:i,children:r})})})};pd.displayName=ud;var md=`PopoverContent`,hd=w.forwardRef((e,t)=>{let n=fd(md,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=id(md,e.__scopePopover);return(0,q.jsx)(sa,{present:r||a.open,children:a.modal?(0,q.jsx)(_d,{...i,ref:t}):(0,q.jsx)(vd,{...i,ref:t})})});hd.displayName=md;var gd=Li(`PopoverContent.RemoveScroll`),_d=w.forwardRef((e,t)=>{let n=id(md,e.__scopePopover),r=w.useRef(null),i=Ii(t,r),a=w.useRef(!1);return w.useEffect(()=>{let e=r.current;if(e)return Ds(e)},[]),(0,q.jsx)(vs,{as:gd,allowPinchZoom:!0,children:(0,q.jsx)(yd,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ea(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:ea(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:ea(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),vd=w.forwardRef((e,t)=>{let n=id(md,e.__scopePopover),r=w.useRef(!1),i=w.useRef(!1);return(0,q.jsx)(yd,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})}),yd=w.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,disableOutsidePointerEvents:o,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=id(md,n),p=nd(n);return so(),(0,q.jsx)(Ka,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,q.jsx)(Fa,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,q.jsx)(Zu,{"data-state":wd(f.open),role:`dialog`,id:f.contentId,...p,...d,ref:t,style:{...d.style,"--radix-popover-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-popover-content-available-width":`var(--radix-popper-available-width)`,"--radix-popover-content-available-height":`var(--radix-popper-available-height)`,"--radix-popover-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-popover-trigger-height":`var(--radix-popper-anchor-height)`}})})})}),bd=`PopoverClose`,xd=w.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=id(bd,n);return(0,q.jsx)(Gi.button,{type:`button`,...r,ref:t,onClick:ea(e.onClick,()=>i.onOpenChange(!1))})});xd.displayName=bd;var Sd=`PopoverArrow`,Cd=w.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=nd(n);return(0,q.jsx)(Qu,{...i,...r,ref:t})});Cd.displayName=Sd;function wd(e){return e?`open`:`closed`}var Td=ad,Ed=ld,Dd=pd,Od=hd,kd=xd,[Ad,jd]=Qi(`Tooltip`,[Nu]),Md=Nu(),Nd=`TooltipProvider`,Pd=700,Fd=`tooltip.open`,[Id,Ld]=Ad(Nd),Rd=e=>{let{__scopeTooltip:t,delayDuration:n=Pd,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=w.useRef(!0),s=w.useRef(!1),c=w.useRef(0);return w.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,q.jsx)(Id,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:w.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:w.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:w.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};Rd.displayName=Nd;var zd=`Tooltip`,[Bd,Vd]=Ad(zd),Hd=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Ld(zd,e.__scopeTooltip),l=Md(t),[u,d]=w.useState(null),f=pa(),p=w.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=w.useRef(!1),[_,v]=ra({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(Fd))):c.onClose(),a?.(e)},caller:zd}),y=w.useMemo(()=>_?g.current?`delayed-open`:`instant-open`:`closed`,[_]),b=w.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,v(!0)},[v]),x=w.useCallback(()=>{window.clearTimeout(p.current),p.current=0,v(!1)},[v]),S=w.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,v(!0),p.current=0},h)},[h,v]);return w.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,q.jsx)(Yu,{...l,children:(0,q.jsx)(Bd,{scope:t,contentId:f,open:_,stateAttribute:y,trigger:u,onTriggerChange:d,onTriggerEnter:w.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:w.useCallback(()=>{m?x():(window.clearTimeout(p.current),p.current=0)},[x,m]),onOpen:b,onClose:x,disableHoverableContent:m,children:n})})};Hd.displayName=zd;var Ud=`TooltipTrigger`,Wd=w.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Vd(Ud,n),a=Ld(Ud,n),o=Md(n),s=Ii(t,w.useRef(null),i.onTriggerChange),c=w.useRef(!1),l=w.useRef(!1),u=w.useCallback(()=>c.current=!1,[]);return w.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,q.jsx)(Xu,{asChild:!0,...o,children:(0,q.jsx)(Gi.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:ea(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:ea(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:ea(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:ea(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:ea(e.onBlur,i.onClose),onClick:ea(e.onClick,i.onClose)})})});Wd.displayName=Ud;var Gd=`TooltipPortal`,[Kd,qd]=Ad(Gd,{forceMount:void 0}),Jd=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=Vd(Gd,t);return(0,q.jsx)(Kd,{scope:t,forceMount:n,children:(0,q.jsx)(sa,{present:n||a.open,children:(0,q.jsx)(ao,{asChild:!0,container:i,children:r})})})};Jd.displayName=Gd;var Yd=`TooltipContent`,Xd=w.forwardRef((e,t)=>{let n=qd(Yd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=Vd(Yd,e.__scopeTooltip);return(0,q.jsx)(sa,{present:r||o.open,children:o.disableHoverableContent?(0,q.jsx)(tf,{side:i,...a,ref:t}):(0,q.jsx)(Zd,{side:i,...a,ref:t})})}),Zd=w.forwardRef((e,t)=>{let n=Vd(Yd,e.__scopeTooltip),r=Ld(Yd,e.__scopeTooltip),i=w.useRef(null),a=Ii(t,i),[o,s]=w.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=w.useCallback(()=>{s(null),d(!1)},[d]),p=w.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=of(r,af(r,n.getBoundingClientRect())),a=sf(t.getBoundingClientRect());s(lf([...i,...a])),d(!0)},[d]);return w.useEffect(()=>()=>f(),[f]),w.useEffect(()=>{if(c&&u){let e=e=>p(e,u),t=e=>p(e,c);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),w.useEffect(()=>{if(o){let e=e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!cf(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,q.jsx)(tf,{...e,ref:a})}),[Qd,$d]=Ad(zd,{isInside:!1}),ef=Vi(`TooltipContent`),tf=w.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=Vd(Yd,n),l=Md(n),{onClose:u}=c;return w.useEffect(()=>(document.addEventListener(Fd,u),()=>document.removeEventListener(Fd,u)),[u]),w.useEffect(()=>{if(c.trigger){let e=e=>{e.target?.contains(c.trigger)&&u()};return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[c.trigger,u]),(0,q.jsx)(Fa,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,q.jsxs)(Zu,{"data-state":c.stateAttribute,...l,...s,ref:t,style:{...s.style,"--radix-tooltip-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-tooltip-content-available-width":`var(--radix-popper-available-width)`,"--radix-tooltip-content-available-height":`var(--radix-popper-available-height)`,"--radix-tooltip-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-tooltip-trigger-height":`var(--radix-popper-anchor-height)`},children:[(0,q.jsx)(ef,{children:r}),(0,q.jsx)(Qd,{scope:n,isInside:!0,children:(0,q.jsx)(Xi,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});Xd.displayName=Yd;var nf=`TooltipArrow`,rf=w.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Md(n);return $d(nf,n).isInside?null:(0,q.jsx)(Qu,{...i,...r,ref:t})});rf.displayName=nf;function af(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}function of(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function sf(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function cf(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}function lf(e){let t=e.slice();return t.sort((e,t)=>e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:+(e.y>t.y)),uf(t)}function uf(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var df=Rd,ff=Hd,pf=Wd,mf=Jd,hf=Xd,gf=rf;function _f(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=_f(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function vf(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=_f(e))&&(r&&(r+=` `),r+=t);return r}var yf=(e,t)=>{let n=Array(e.length+t.length);for(let t=0;t<e.length;t++)n[t]=e[t];for(let r=0;r<t.length;r++)n[e.length+r]=t[r];return n},bf=(e,t)=>({classGroupId:e,validator:t}),xf=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),Sf=`-`,Cf=[],wf=`arbitrary..`,Tf=e=>{let t=Of(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:e=>{if(e.startsWith(`[`)&&e.endsWith(`]`))return Df(e);let n=e.split(Sf);return Ef(n,+(n[0]===``&&n.length>1),t)},getConflictingClassGroupIds:(e,t)=>{if(t){let t=r[e],i=n[e];return t?i?yf(i,t):t:i||Cf}return n[e]||Cf}}},Ef=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;let r=e[t],i=n.nextPart.get(r);if(i){let n=Ef(e,t+1,i);if(n)return n}let a=n.validators;if(a===null)return;let o=t===0?e.join(Sf):e.slice(t).join(Sf),s=a.length;for(let e=0;e<s;e++){let t=a[e];if(t.validator(o))return t.classGroupId}},Df=e=>e.slice(1,-1).indexOf(`:`)===-1?void 0:(()=>{let t=e.slice(1,-1),n=t.indexOf(`:`),r=t.slice(0,n);return r?wf+r:void 0})(),Of=e=>{let{theme:t,classGroups:n}=e;return kf(n,t)},kf=(e,t)=>{let n=xf();for(let r in e){let i=e[r];Af(i,n,r,t)}return n},Af=(e,t,n,r)=>{let i=e.length;for(let a=0;a<i;a++){let i=e[a];jf(i,t,n,r)}},jf=(e,t,n,r)=>{if(typeof e==`string`){Mf(e,t,n);return}if(typeof e==`function`){Nf(e,t,n,r);return}Pf(e,t,n,r)},Mf=(e,t,n)=>{let r=e===``?t:Ff(t,e);r.classGroupId=n},Nf=(e,t,n,r)=>{if(If(e)){Af(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(bf(n,e))},Pf=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e<a;e++){let[a,o]=i[e];Af(o,Ff(t,a),n,r)}},Ff=(e,t)=>{let n=e,r=t.split(Sf),i=r.length;for(let e=0;e<i;e++){let t=r[e],i=n.nextPart.get(t);i||(i=xf(),n.nextPart.set(t,i)),n=i}return n},If=e=>`isThemeGetter`in e&&e.isThemeGetter===!0,Lf=e=>{if(e<1)return{get:()=>void 0,set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null),i=(i,a)=>{n[i]=a,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(e){let t=n[e];if(t!==void 0)return t;if((t=r[e])!==void 0)return i(e,t),t},set(e,t){e in n?n[e]=t:i(e,t)}}},Rf=`!`,zf=`:`,Bf=[],Vf=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),Hf=e=>{let{prefix:t,experimentalParseClassName:n}=e,r=e=>{let t=[],n=0,r=0,i=0,a,o=e.length;for(let s=0;s<o;s++){let o=e[s];if(n===0&&r===0){if(o===zf){t.push(e.slice(i,s)),i=s+1;continue}if(o===`/`){a=s;continue}}o===`[`?n++:o===`]`?n--:o===`(`?r++:o===`)`&&r--}let s=t.length===0?e:e.slice(i),c=s,l=!1;s.endsWith(Rf)?(c=s.slice(0,-1),l=!0):s.startsWith(Rf)&&(c=s.slice(1),l=!0);let u=a&&a>i?a-i:void 0;return Vf(t,l,c,u)};if(t){let e=t+zf,n=r;r=t=>t.startsWith(e)?n(t.slice(e.length)):Vf(Bf,!1,t,void 0,!0)}if(n){let e=r;r=t=>n({className:t,parseClassName:e})}return r},Uf=e=>{let t=new Map;return e.orderSensitiveModifiers.forEach((e,n)=>{t.set(e,1e6+n)}),e=>{let n=[],r=[];for(let i=0;i<e.length;i++){let a=e[i],o=a[0]===`[`,s=t.has(a);o||s?(r.length>0&&(r.sort(),n.push(...r),r=[]),n.push(a)):r.push(a)}return r.length>0&&(r.sort(),n.push(...r)),n}},Wf=e=>({cache:Lf(e.cacheSize),parseClassName:Hf(e),sortModifiers:Uf(e),...Tf(e)}),Gf=/\s+/,Kf=(e,t)=>{let{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:a}=t,o=[],s=e.trim().split(Gf),c=``;for(let e=s.length-1;e>=0;--e){let t=s[e],{isExternal:l,modifiers:u,hasImportantModifier:d,baseClassName:f,maybePostfixModifierPosition:p}=n(t);if(l){c=t+(c.length>0?` `+c:c);continue}let m=!!p,h=r(m?f.substring(0,p):f);if(!h){if(!m){c=t+(c.length>0?` `+c:c);continue}if(h=r(f),!h){c=t+(c.length>0?` `+c:c);continue}m=!1}let g=u.length===0?``:u.length===1?u[0]:a(u).join(`:`),_=d?g+Rf:g,v=_+h;if(o.indexOf(v)>-1)continue;o.push(v);let y=i(h,m);for(let e=0;e<y.length;++e){let t=y[e];o.push(_+t)}c=t+(c.length>0?` `+c:c)}return c},qf=(...e)=>{let t=0,n,r,i=``;for(;t<e.length;)(n=e[t++])&&(r=Jf(n))&&(i&&(i+=` `),i+=r);return i},Jf=e=>{if(typeof e==`string`)return e;let t,n=``;for(let r=0;r<e.length;r++)e[r]&&(t=Jf(e[r]))&&(n&&(n+=` `),n+=t);return n},Yf=(e,...t)=>{let n,r,i,a,o=o=>(n=Wf(t.reduce((e,t)=>t(e),e())),r=n.cache.get,i=n.cache.set,a=s,s(o)),s=e=>{let t=r(e);if(t)return t;let a=Kf(e,n);return i(e,a),a};return a=o,(...e)=>a(qf(...e))},Xf=[],Zf=e=>{let t=t=>t[e]||Xf;return t.isThemeGetter=!0,t},Qf=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,$f=/^\((?:(\w[\w-]*):)?(.+)\)$/i,ep=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,tp=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,np=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,rp=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,ip=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,ap=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,op=e=>ep.test(e),sp=e=>!!e&&!Number.isNaN(Number(e)),cp=e=>!!e&&Number.isInteger(Number(e)),lp=e=>e.endsWith(`%`)&&sp(e.slice(0,-1)),up=e=>tp.test(e),dp=()=>!0,fp=e=>np.test(e)&&!rp.test(e),pp=()=>!1,mp=e=>ip.test(e),hp=e=>ap.test(e),gp=e=>!J(e)&&!Y(e),_p=e=>Mp(e,Ip,pp),J=e=>Qf.test(e),vp=e=>Mp(e,Lp,fp),yp=e=>Mp(e,Rp,sp),bp=e=>Mp(e,Bp,dp),xp=e=>Mp(e,zp,pp),Sp=e=>Mp(e,Pp,pp),Cp=e=>Mp(e,Fp,hp),wp=e=>Mp(e,Vp,mp),Y=e=>$f.test(e),Tp=e=>Np(e,Lp),Ep=e=>Np(e,zp),Dp=e=>Np(e,Pp),Op=e=>Np(e,Ip),kp=e=>Np(e,Fp),Ap=e=>Np(e,Vp,!0),jp=e=>Np(e,Bp,!0),Mp=(e,t,n)=>{let r=Qf.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},Np=(e,t,n=!1)=>{let r=$f.exec(e);return r?r[1]?t(r[1]):n:!1},Pp=e=>e===`position`||e===`percentage`,Fp=e=>e===`image`||e===`url`,Ip=e=>e===`length`||e===`size`||e===`bg-size`,Lp=e=>e===`length`,Rp=e=>e===`number`,zp=e=>e===`family-name`,Bp=e=>e===`number`||e===`weight`,Vp=e=>e===`shadow`,Hp=Yf(()=>{let e=Zf(`color`),t=Zf(`font`),n=Zf(`text`),r=Zf(`font-weight`),i=Zf(`tracking`),a=Zf(`leading`),o=Zf(`breakpoint`),s=Zf(`container`),c=Zf(`spacing`),l=Zf(`radius`),u=Zf(`shadow`),d=Zf(`inset-shadow`),f=Zf(`text-shadow`),p=Zf(`drop-shadow`),m=Zf(`blur`),h=Zf(`perspective`),g=Zf(`aspect`),_=Zf(`ease`),v=Zf(`animate`),y=()=>[`auto`,`avoid`,`all`,`avoid-page`,`page`,`left`,`right`,`column`],b=()=>[`center`,`top`,`bottom`,`left`,`right`,`top-left`,`left-top`,`top-right`,`right-top`,`bottom-right`,`right-bottom`,`bottom-left`,`left-bottom`],x=()=>[...b(),Y,J],S=()=>[`auto`,`hidden`,`clip`,`visible`,`scroll`],C=()=>[`auto`,`contain`,`none`],w=()=>[Y,J,c],T=()=>[op,`full`,`auto`,...w()],E=()=>[cp,`none`,`subgrid`,Y,J],D=()=>[`auto`,{span:[`full`,cp,Y,J]},cp,Y,J],O=()=>[cp,`auto`,Y,J],k=()=>[`auto`,`min`,`max`,`fr`,Y,J],A=()=>[`start`,`end`,`center`,`between`,`around`,`evenly`,`stretch`,`baseline`,`center-safe`,`end-safe`],j=()=>[`start`,`end`,`center`,`stretch`,`center-safe`,`end-safe`],M=()=>[`auto`,...w()],N=()=>[op,`auto`,`full`,`dvw`,`dvh`,`lvw`,`lvh`,`svw`,`svh`,`min`,`max`,`fit`,...w()],P=()=>[op,`screen`,`full`,`dvw`,`lvw`,`svw`,`min`,`max`,`fit`,...w()],F=()=>[op,`screen`,`full`,`lh`,`dvh`,`lvh`,`svh`,`min`,`max`,`fit`,...w()],I=()=>[e,Y,J],L=()=>[...b(),Dp,Sp,{position:[Y,J]}],R=()=>[`no-repeat`,{repeat:[``,`x`,`y`,`space`,`round`]}],z=()=>[`auto`,`cover`,`contain`,Op,_p,{size:[Y,J]}],B=()=>[lp,Tp,vp],V=()=>[``,`none`,`full`,l,Y,J],H=()=>[``,sp,Tp,vp],U=()=>[`solid`,`dashed`,`dotted`,`double`],W=()=>[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],G=()=>[sp,lp,Dp,Sp],ee=()=>[``,`none`,m,Y,J],K=()=>[`none`,sp,Y,J],te=()=>[`none`,sp,Y,J],ne=()=>[sp,Y,J],re=()=>[op,`full`,...w()];return{cacheSize:500,theme:{animate:[`spin`,`ping`,`pulse`,`bounce`],aspect:[`video`],blur:[up],breakpoint:[up],color:[dp],container:[up],"drop-shadow":[up],ease:[`in`,`out`,`in-out`],font:[gp],"font-weight":[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`],"inset-shadow":[up],leading:[`none`,`tight`,`snug`,`normal`,`relaxed`,`loose`],perspective:[`dramatic`,`near`,`normal`,`midrange`,`distant`,`none`],radius:[up],shadow:[up],spacing:[`px`,sp],text:[up],"text-shadow":[up],tracking:[`tighter`,`tight`,`normal`,`wide`,`wider`,`widest`]},classGroups:{aspect:[{aspect:[`auto`,`square`,op,J,Y,g]}],container:[`container`],columns:[{columns:[sp,J,Y,s]}],"break-after":[{"break-after":y()}],"break-before":[{"break-before":y()}],"break-inside":[{"break-inside":[`auto`,`avoid`,`avoid-page`,`avoid-column`]}],"box-decoration":[{"box-decoration":[`slice`,`clone`]}],box:[{box:[`border`,`content`]}],display:[`block`,`inline-block`,`inline`,`flex`,`inline-flex`,`table`,`inline-table`,`table-caption`,`table-cell`,`table-column`,`table-column-group`,`table-footer-group`,`table-header-group`,`table-row-group`,`table-row`,`flow-root`,`grid`,`inline-grid`,`contents`,`list-item`,`hidden`],sr:[`sr-only`,`not-sr-only`],float:[{float:[`right`,`left`,`none`,`start`,`end`]}],clear:[{clear:[`left`,`right`,`both`,`none`,`start`,`end`]}],isolation:[`isolate`,`isolation-auto`],"object-fit":[{object:[`contain`,`cover`,`fill`,`none`,`scale-down`]}],"object-position":[{object:x()}],overflow:[{overflow:S()}],"overflow-x":[{"overflow-x":S()}],"overflow-y":[{"overflow-y":S()}],overscroll:[{overscroll:C()}],"overscroll-x":[{"overscroll-x":C()}],"overscroll-y":[{"overscroll-y":C()}],position:[`static`,`fixed`,`absolute`,`relative`,`sticky`],inset:[{inset:T()}],"inset-x":[{"inset-x":T()}],"inset-y":[{"inset-y":T()}],start:[{"inset-s":T(),start:T()}],end:[{"inset-e":T(),end:T()}],"inset-bs":[{"inset-bs":T()}],"inset-be":[{"inset-be":T()}],top:[{top:T()}],right:[{right:T()}],bottom:[{bottom:T()}],left:[{left:T()}],visibility:[`visible`,`invisible`,`collapse`],z:[{z:[cp,`auto`,Y,J]}],basis:[{basis:[op,`full`,`auto`,s,...w()]}],"flex-direction":[{flex:[`row`,`row-reverse`,`col`,`col-reverse`]}],"flex-wrap":[{flex:[`nowrap`,`wrap`,`wrap-reverse`]}],flex:[{flex:[sp,op,`auto`,`initial`,`none`,J]}],grow:[{grow:[``,sp,Y,J]}],shrink:[{shrink:[``,sp,Y,J]}],order:[{order:[cp,`first`,`last`,`none`,Y,J]}],"grid-cols":[{"grid-cols":E()}],"col-start-end":[{col:D()}],"col-start":[{"col-start":O()}],"col-end":[{"col-end":O()}],"grid-rows":[{"grid-rows":E()}],"row-start-end":[{row:D()}],"row-start":[{"row-start":O()}],"row-end":[{"row-end":O()}],"grid-flow":[{"grid-flow":[`row`,`col`,`dense`,`row-dense`,`col-dense`]}],"auto-cols":[{"auto-cols":k()}],"auto-rows":[{"auto-rows":k()}],gap:[{gap:w()}],"gap-x":[{"gap-x":w()}],"gap-y":[{"gap-y":w()}],"justify-content":[{justify:[...A(),`normal`]}],"justify-items":[{"justify-items":[...j(),`normal`]}],"justify-self":[{"justify-self":[`auto`,...j()]}],"align-content":[{content:[`normal`,...A()]}],"align-items":[{items:[...j(),{baseline:[``,`last`]}]}],"align-self":[{self:[`auto`,...j(),{baseline:[``,`last`]}]}],"place-content":[{"place-content":A()}],"place-items":[{"place-items":[...j(),`baseline`]}],"place-self":[{"place-self":[`auto`,...j()]}],p:[{p:w()}],px:[{px:w()}],py:[{py:w()}],ps:[{ps:w()}],pe:[{pe:w()}],pbs:[{pbs:w()}],pbe:[{pbe:w()}],pt:[{pt:w()}],pr:[{pr:w()}],pb:[{pb:w()}],pl:[{pl:w()}],m:[{m:M()}],mx:[{mx:M()}],my:[{my:M()}],ms:[{ms:M()}],me:[{me:M()}],mbs:[{mbs:M()}],mbe:[{mbe:M()}],mt:[{mt:M()}],mr:[{mr:M()}],mb:[{mb:M()}],ml:[{ml:M()}],"space-x":[{"space-x":w()}],"space-x-reverse":[`space-x-reverse`],"space-y":[{"space-y":w()}],"space-y-reverse":[`space-y-reverse`],size:[{size:N()}],"inline-size":[{inline:[`auto`,...P()]}],"min-inline-size":[{"min-inline":[`auto`,...P()]}],"max-inline-size":[{"max-inline":[`none`,...P()]}],"block-size":[{block:[`auto`,...F()]}],"min-block-size":[{"min-block":[`auto`,...F()]}],"max-block-size":[{"max-block":[`none`,...F()]}],w:[{w:[s,`screen`,...N()]}],"min-w":[{"min-w":[s,`screen`,`none`,...N()]}],"max-w":[{"max-w":[s,`screen`,`none`,`prose`,{screen:[o]},...N()]}],h:[{h:[`screen`,`lh`,...N()]}],"min-h":[{"min-h":[`screen`,`lh`,`none`,...N()]}],"max-h":[{"max-h":[`screen`,`lh`,...N()]}],"font-size":[{text:[`base`,n,Tp,vp]}],"font-smoothing":[`antialiased`,`subpixel-antialiased`],"font-style":[`italic`,`not-italic`],"font-weight":[{font:[r,jp,bp]}],"font-stretch":[{"font-stretch":[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`,lp,J]}],"font-family":[{font:[Ep,xp,t]}],"font-features":[{"font-features":[J]}],"fvn-normal":[`normal-nums`],"fvn-ordinal":[`ordinal`],"fvn-slashed-zero":[`slashed-zero`],"fvn-figure":[`lining-nums`,`oldstyle-nums`],"fvn-spacing":[`proportional-nums`,`tabular-nums`],"fvn-fraction":[`diagonal-fractions`,`stacked-fractions`],tracking:[{tracking:[i,Y,J]}],"line-clamp":[{"line-clamp":[sp,`none`,Y,yp]}],leading:[{leading:[a,...w()]}],"list-image":[{"list-image":[`none`,Y,J]}],"list-style-position":[{list:[`inside`,`outside`]}],"list-style-type":[{list:[`disc`,`decimal`,`none`,Y,J]}],"text-alignment":[{text:[`left`,`center`,`right`,`justify`,`start`,`end`]}],"placeholder-color":[{placeholder:I()}],"text-color":[{text:I()}],"text-decoration":[`underline`,`overline`,`line-through`,`no-underline`],"text-decoration-style":[{decoration:[...U(),`wavy`]}],"text-decoration-thickness":[{decoration:[sp,`from-font`,`auto`,Y,vp]}],"text-decoration-color":[{decoration:I()}],"underline-offset":[{"underline-offset":[sp,`auto`,Y,J]}],"text-transform":[`uppercase`,`lowercase`,`capitalize`,`normal-case`],"text-overflow":[`truncate`,`text-ellipsis`,`text-clip`],"text-wrap":[{text:[`wrap`,`nowrap`,`balance`,`pretty`]}],indent:[{indent:w()}],"vertical-align":[{align:[`baseline`,`top`,`middle`,`bottom`,`text-top`,`text-bottom`,`sub`,`super`,Y,J]}],whitespace:[{whitespace:[`normal`,`nowrap`,`pre`,`pre-line`,`pre-wrap`,`break-spaces`]}],break:[{break:[`normal`,`words`,`all`,`keep`]}],wrap:[{wrap:[`break-word`,`anywhere`,`normal`]}],hyphens:[{hyphens:[`none`,`manual`,`auto`]}],content:[{content:[`none`,Y,J]}],"bg-attachment":[{bg:[`fixed`,`local`,`scroll`]}],"bg-clip":[{"bg-clip":[`border`,`padding`,`content`,`text`]}],"bg-origin":[{"bg-origin":[`border`,`padding`,`content`]}],"bg-position":[{bg:L()}],"bg-repeat":[{bg:R()}],"bg-size":[{bg:z()}],"bg-image":[{bg:[`none`,{linear:[{to:[`t`,`tr`,`r`,`br`,`b`,`bl`,`l`,`tl`]},cp,Y,J],radial:[``,Y,J],conic:[cp,Y,J]},kp,Cp]}],"bg-color":[{bg:I()}],"gradient-from-pos":[{from:B()}],"gradient-via-pos":[{via:B()}],"gradient-to-pos":[{to:B()}],"gradient-from":[{from:I()}],"gradient-via":[{via:I()}],"gradient-to":[{to:I()}],rounded:[{rounded:V()}],"rounded-s":[{"rounded-s":V()}],"rounded-e":[{"rounded-e":V()}],"rounded-t":[{"rounded-t":V()}],"rounded-r":[{"rounded-r":V()}],"rounded-b":[{"rounded-b":V()}],"rounded-l":[{"rounded-l":V()}],"rounded-ss":[{"rounded-ss":V()}],"rounded-se":[{"rounded-se":V()}],"rounded-ee":[{"rounded-ee":V()}],"rounded-es":[{"rounded-es":V()}],"rounded-tl":[{"rounded-tl":V()}],"rounded-tr":[{"rounded-tr":V()}],"rounded-br":[{"rounded-br":V()}],"rounded-bl":[{"rounded-bl":V()}],"border-w":[{border:H()}],"border-w-x":[{"border-x":H()}],"border-w-y":[{"border-y":H()}],"border-w-s":[{"border-s":H()}],"border-w-e":[{"border-e":H()}],"border-w-bs":[{"border-bs":H()}],"border-w-be":[{"border-be":H()}],"border-w-t":[{"border-t":H()}],"border-w-r":[{"border-r":H()}],"border-w-b":[{"border-b":H()}],"border-w-l":[{"border-l":H()}],"divide-x":[{"divide-x":H()}],"divide-x-reverse":[`divide-x-reverse`],"divide-y":[{"divide-y":H()}],"divide-y-reverse":[`divide-y-reverse`],"border-style":[{border:[...U(),`hidden`,`none`]}],"divide-style":[{divide:[...U(),`hidden`,`none`]}],"border-color":[{border:I()}],"border-color-x":[{"border-x":I()}],"border-color-y":[{"border-y":I()}],"border-color-s":[{"border-s":I()}],"border-color-e":[{"border-e":I()}],"border-color-bs":[{"border-bs":I()}],"border-color-be":[{"border-be":I()}],"border-color-t":[{"border-t":I()}],"border-color-r":[{"border-r":I()}],"border-color-b":[{"border-b":I()}],"border-color-l":[{"border-l":I()}],"divide-color":[{divide:I()}],"outline-style":[{outline:[...U(),`none`,`hidden`]}],"outline-offset":[{"outline-offset":[sp,Y,J]}],"outline-w":[{outline:[``,sp,Tp,vp]}],"outline-color":[{outline:I()}],shadow:[{shadow:[``,`none`,u,Ap,wp]}],"shadow-color":[{shadow:I()}],"inset-shadow":[{"inset-shadow":[`none`,d,Ap,wp]}],"inset-shadow-color":[{"inset-shadow":I()}],"ring-w":[{ring:H()}],"ring-w-inset":[`ring-inset`],"ring-color":[{ring:I()}],"ring-offset-w":[{"ring-offset":[sp,vp]}],"ring-offset-color":[{"ring-offset":I()}],"inset-ring-w":[{"inset-ring":H()}],"inset-ring-color":[{"inset-ring":I()}],"text-shadow":[{"text-shadow":[`none`,f,Ap,wp]}],"text-shadow-color":[{"text-shadow":I()}],opacity:[{opacity:[sp,Y,J]}],"mix-blend":[{"mix-blend":[...W(),`plus-darker`,`plus-lighter`]}],"bg-blend":[{"bg-blend":W()}],"mask-clip":[{"mask-clip":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]},`mask-no-clip`],"mask-composite":[{mask:[`add`,`subtract`,`intersect`,`exclude`]}],"mask-image-linear-pos":[{"mask-linear":[sp]}],"mask-image-linear-from-pos":[{"mask-linear-from":G()}],"mask-image-linear-to-pos":[{"mask-linear-to":G()}],"mask-image-linear-from-color":[{"mask-linear-from":I()}],"mask-image-linear-to-color":[{"mask-linear-to":I()}],"mask-image-t-from-pos":[{"mask-t-from":G()}],"mask-image-t-to-pos":[{"mask-t-to":G()}],"mask-image-t-from-color":[{"mask-t-from":I()}],"mask-image-t-to-color":[{"mask-t-to":I()}],"mask-image-r-from-pos":[{"mask-r-from":G()}],"mask-image-r-to-pos":[{"mask-r-to":G()}],"mask-image-r-from-color":[{"mask-r-from":I()}],"mask-image-r-to-color":[{"mask-r-to":I()}],"mask-image-b-from-pos":[{"mask-b-from":G()}],"mask-image-b-to-pos":[{"mask-b-to":G()}],"mask-image-b-from-color":[{"mask-b-from":I()}],"mask-image-b-to-color":[{"mask-b-to":I()}],"mask-image-l-from-pos":[{"mask-l-from":G()}],"mask-image-l-to-pos":[{"mask-l-to":G()}],"mask-image-l-from-color":[{"mask-l-from":I()}],"mask-image-l-to-color":[{"mask-l-to":I()}],"mask-image-x-from-pos":[{"mask-x-from":G()}],"mask-image-x-to-pos":[{"mask-x-to":G()}],"mask-image-x-from-color":[{"mask-x-from":I()}],"mask-image-x-to-color":[{"mask-x-to":I()}],"mask-image-y-from-pos":[{"mask-y-from":G()}],"mask-image-y-to-pos":[{"mask-y-to":G()}],"mask-image-y-from-color":[{"mask-y-from":I()}],"mask-image-y-to-color":[{"mask-y-to":I()}],"mask-image-radial":[{"mask-radial":[Y,J]}],"mask-image-radial-from-pos":[{"mask-radial-from":G()}],"mask-image-radial-to-pos":[{"mask-radial-to":G()}],"mask-image-radial-from-color":[{"mask-radial-from":I()}],"mask-image-radial-to-color":[{"mask-radial-to":I()}],"mask-image-radial-shape":[{"mask-radial":[`circle`,`ellipse`]}],"mask-image-radial-size":[{"mask-radial":[{closest:[`side`,`corner`],farthest:[`side`,`corner`]}]}],"mask-image-radial-pos":[{"mask-radial-at":b()}],"mask-image-conic-pos":[{"mask-conic":[sp]}],"mask-image-conic-from-pos":[{"mask-conic-from":G()}],"mask-image-conic-to-pos":[{"mask-conic-to":G()}],"mask-image-conic-from-color":[{"mask-conic-from":I()}],"mask-image-conic-to-color":[{"mask-conic-to":I()}],"mask-mode":[{mask:[`alpha`,`luminance`,`match`]}],"mask-origin":[{"mask-origin":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]}],"mask-position":[{mask:L()}],"mask-repeat":[{mask:R()}],"mask-size":[{mask:z()}],"mask-type":[{"mask-type":[`alpha`,`luminance`]}],"mask-image":[{mask:[`none`,Y,J]}],filter:[{filter:[``,`none`,Y,J]}],blur:[{blur:ee()}],brightness:[{brightness:[sp,Y,J]}],contrast:[{contrast:[sp,Y,J]}],"drop-shadow":[{"drop-shadow":[``,`none`,p,Ap,wp]}],"drop-shadow-color":[{"drop-shadow":I()}],grayscale:[{grayscale:[``,sp,Y,J]}],"hue-rotate":[{"hue-rotate":[sp,Y,J]}],invert:[{invert:[``,sp,Y,J]}],saturate:[{saturate:[sp,Y,J]}],sepia:[{sepia:[``,sp,Y,J]}],"backdrop-filter":[{"backdrop-filter":[``,`none`,Y,J]}],"backdrop-blur":[{"backdrop-blur":ee()}],"backdrop-brightness":[{"backdrop-brightness":[sp,Y,J]}],"backdrop-contrast":[{"backdrop-contrast":[sp,Y,J]}],"backdrop-grayscale":[{"backdrop-grayscale":[``,sp,Y,J]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[sp,Y,J]}],"backdrop-invert":[{"backdrop-invert":[``,sp,Y,J]}],"backdrop-opacity":[{"backdrop-opacity":[sp,Y,J]}],"backdrop-saturate":[{"backdrop-saturate":[sp,Y,J]}],"backdrop-sepia":[{"backdrop-sepia":[``,sp,Y,J]}],"border-collapse":[{border:[`collapse`,`separate`]}],"border-spacing":[{"border-spacing":w()}],"border-spacing-x":[{"border-spacing-x":w()}],"border-spacing-y":[{"border-spacing-y":w()}],"table-layout":[{table:[`auto`,`fixed`]}],caption:[{caption:[`top`,`bottom`]}],transition:[{transition:[``,`all`,`colors`,`opacity`,`shadow`,`transform`,`none`,Y,J]}],"transition-behavior":[{transition:[`normal`,`discrete`]}],duration:[{duration:[sp,`initial`,Y,J]}],ease:[{ease:[`linear`,`initial`,_,Y,J]}],delay:[{delay:[sp,Y,J]}],animate:[{animate:[`none`,v,Y,J]}],backface:[{backface:[`hidden`,`visible`]}],perspective:[{perspective:[h,Y,J]}],"perspective-origin":[{"perspective-origin":x()}],rotate:[{rotate:K()}],"rotate-x":[{"rotate-x":K()}],"rotate-y":[{"rotate-y":K()}],"rotate-z":[{"rotate-z":K()}],scale:[{scale:te()}],"scale-x":[{"scale-x":te()}],"scale-y":[{"scale-y":te()}],"scale-z":[{"scale-z":te()}],"scale-3d":[`scale-3d`],skew:[{skew:ne()}],"skew-x":[{"skew-x":ne()}],"skew-y":[{"skew-y":ne()}],transform:[{transform:[Y,J,``,`none`,`gpu`,`cpu`]}],"transform-origin":[{origin:x()}],"transform-style":[{transform:[`3d`,`flat`]}],translate:[{translate:re()}],"translate-x":[{"translate-x":re()}],"translate-y":[{"translate-y":re()}],"translate-z":[{"translate-z":re()}],"translate-none":[`translate-none`],accent:[{accent:I()}],appearance:[{appearance:[`none`,`auto`]}],"caret-color":[{caret:I()}],"color-scheme":[{scheme:[`normal`,`dark`,`light`,`light-dark`,`only-dark`,`only-light`]}],cursor:[{cursor:[`auto`,`default`,`pointer`,`wait`,`text`,`move`,`help`,`not-allowed`,`none`,`context-menu`,`progress`,`cell`,`crosshair`,`vertical-text`,`alias`,`copy`,`no-drop`,`grab`,`grabbing`,`all-scroll`,`col-resize`,`row-resize`,`n-resize`,`e-resize`,`s-resize`,`w-resize`,`ne-resize`,`nw-resize`,`se-resize`,`sw-resize`,`ew-resize`,`ns-resize`,`nesw-resize`,`nwse-resize`,`zoom-in`,`zoom-out`,Y,J]}],"field-sizing":[{"field-sizing":[`fixed`,`content`]}],"pointer-events":[{"pointer-events":[`auto`,`none`]}],resize:[{resize:[`none`,``,`y`,`x`]}],"scroll-behavior":[{scroll:[`auto`,`smooth`]}],"scroll-m":[{"scroll-m":w()}],"scroll-mx":[{"scroll-mx":w()}],"scroll-my":[{"scroll-my":w()}],"scroll-ms":[{"scroll-ms":w()}],"scroll-me":[{"scroll-me":w()}],"scroll-mbs":[{"scroll-mbs":w()}],"scroll-mbe":[{"scroll-mbe":w()}],"scroll-mt":[{"scroll-mt":w()}],"scroll-mr":[{"scroll-mr":w()}],"scroll-mb":[{"scroll-mb":w()}],"scroll-ml":[{"scroll-ml":w()}],"scroll-p":[{"scroll-p":w()}],"scroll-px":[{"scroll-px":w()}],"scroll-py":[{"scroll-py":w()}],"scroll-ps":[{"scroll-ps":w()}],"scroll-pe":[{"scroll-pe":w()}],"scroll-pbs":[{"scroll-pbs":w()}],"scroll-pbe":[{"scroll-pbe":w()}],"scroll-pt":[{"scroll-pt":w()}],"scroll-pr":[{"scroll-pr":w()}],"scroll-pb":[{"scroll-pb":w()}],"scroll-pl":[{"scroll-pl":w()}],"snap-align":[{snap:[`start`,`end`,`center`,`align-none`]}],"snap-stop":[{snap:[`normal`,`always`]}],"snap-type":[{snap:[`none`,`x`,`y`,`both`]}],"snap-strictness":[{snap:[`mandatory`,`proximity`]}],touch:[{touch:[`auto`,`none`,`manipulation`]}],"touch-x":[{"touch-pan":[`x`,`left`,`right`]}],"touch-y":[{"touch-pan":[`y`,`up`,`down`]}],"touch-pz":[`touch-pinch-zoom`],select:[{select:[`none`,`text`,`all`,`auto`]}],"will-change":[{"will-change":[`auto`,`scroll`,`contents`,`transform`,Y,J]}],fill:[{fill:[`none`,...I()]}],"stroke-w":[{stroke:[sp,Tp,vp,yp]}],stroke:[{stroke:[`none`,...I()]}],"forced-color-adjust":[{"forced-color-adjust":[`auto`,`none`]}]},conflictingClassGroups:{overflow:[`overflow-x`,`overflow-y`],overscroll:[`overscroll-x`,`overscroll-y`],inset:[`inset-x`,`inset-y`,`inset-bs`,`inset-be`,`start`,`end`,`top`,`right`,`bottom`,`left`],"inset-x":[`right`,`left`],"inset-y":[`top`,`bottom`],flex:[`basis`,`grow`,`shrink`],gap:[`gap-x`,`gap-y`],p:[`px`,`py`,`ps`,`pe`,`pbs`,`pbe`,`pt`,`pr`,`pb`,`pl`],px:[`pr`,`pl`],py:[`pt`,`pb`],m:[`mx`,`my`,`ms`,`me`,`mbs`,`mbe`,`mt`,`mr`,`mb`,`ml`],mx:[`mr`,`ml`],my:[`mt`,`mb`],size:[`w`,`h`],"font-size":[`leading`],"fvn-normal":[`fvn-ordinal`,`fvn-slashed-zero`,`fvn-figure`,`fvn-spacing`,`fvn-fraction`],"fvn-ordinal":[`fvn-normal`],"fvn-slashed-zero":[`fvn-normal`],"fvn-figure":[`fvn-normal`],"fvn-spacing":[`fvn-normal`],"fvn-fraction":[`fvn-normal`],"line-clamp":[`display`,`overflow`],rounded:[`rounded-s`,`rounded-e`,`rounded-t`,`rounded-r`,`rounded-b`,`rounded-l`,`rounded-ss`,`rounded-se`,`rounded-ee`,`rounded-es`,`rounded-tl`,`rounded-tr`,`rounded-br`,`rounded-bl`],"rounded-s":[`rounded-ss`,`rounded-es`],"rounded-e":[`rounded-se`,`rounded-ee`],"rounded-t":[`rounded-tl`,`rounded-tr`],"rounded-r":[`rounded-tr`,`rounded-br`],"rounded-b":[`rounded-br`,`rounded-bl`],"rounded-l":[`rounded-tl`,`rounded-bl`],"border-spacing":[`border-spacing-x`,`border-spacing-y`],"border-w":[`border-w-x`,`border-w-y`,`border-w-s`,`border-w-e`,`border-w-bs`,`border-w-be`,`border-w-t`,`border-w-r`,`border-w-b`,`border-w-l`],"border-w-x":[`border-w-r`,`border-w-l`],"border-w-y":[`border-w-t`,`border-w-b`],"border-color":[`border-color-x`,`border-color-y`,`border-color-s`,`border-color-e`,`border-color-bs`,`border-color-be`,`border-color-t`,`border-color-r`,`border-color-b`,`border-color-l`],"border-color-x":[`border-color-r`,`border-color-l`],"border-color-y":[`border-color-t`,`border-color-b`],translate:[`translate-x`,`translate-y`,`translate-none`],"translate-none":[`translate`,`translate-x`,`translate-y`,`translate-z`],"scroll-m":[`scroll-mx`,`scroll-my`,`scroll-ms`,`scroll-me`,`scroll-mbs`,`scroll-mbe`,`scroll-mt`,`scroll-mr`,`scroll-mb`,`scroll-ml`],"scroll-mx":[`scroll-mr`,`scroll-ml`],"scroll-my":[`scroll-mt`,`scroll-mb`],"scroll-p":[`scroll-px`,`scroll-py`,`scroll-ps`,`scroll-pe`,`scroll-pbs`,`scroll-pbe`,`scroll-pt`,`scroll-pr`,`scroll-pb`,`scroll-pl`],"scroll-px":[`scroll-pr`,`scroll-pl`],"scroll-py":[`scroll-pt`,`scroll-pb`],touch:[`touch-x`,`touch-y`,`touch-pz`],"touch-x":[`touch`],"touch-y":[`touch`],"touch-pz":[`touch`]},conflictingClassGroupModifiers:{"font-size":[`leading`]},orderSensitiveModifiers:[`*`,`**`,`after`,`backdrop`,`before`,`details-content`,`file`,`first-letter`,`first-line`,`marker`,`placeholder`,`selection`]}});function X(...e){return Hp(vf(e))}function Up({delayDuration:e=0,...t}){return(0,q.jsx)(df,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Wp({...e}){return(0,q.jsx)(ff,{"data-slot":`tooltip`,...e})}function Gp({...e}){return(0,q.jsx)(pf,{"data-slot":`tooltip-trigger`,...e})}function Kp({className:e,sideOffset:t=4,children:n,...r}){return(0,q.jsx)(mf,{children:(0,q.jsxs)(hf,{"data-slot":`tooltip-content`,sideOffset:t,className:X(`z-50 overflow-hidden rounded-md bg-gray-900 px-3 py-1.5 text-xs text-gray-100 shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...r,children:[n,(0,q.jsx)(gf,{className:`fill-gray-900`})]})})}var Z=(e,t)=>fetch(e,{credentials:`include`,...t}),qp=null;function Jp(){return qp||=Z(`/api/health`).then(e=>e.json()).then(e=>typeof e?.workspace==`string`?e.workspace:`loopat`).catch(()=>`loopat`),qp}async function Yp(){let e=await Z(`/api/auth/me`);return e.ok?(await e.json()).user??null:null}async function Xp(e,t){let n=await Z(`/api/auth/login`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({username:e,password:t})}),r=await n.json().catch(()=>({}));return n.ok?{user:r.user}:{error:r.error??`login failed (${n.status})`}}async function Zp(e){let t=await Z(`/api/auth/register`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{user:n.user,publicKey:n.publicKey,personalRepo:n.personalRepo??null,needsImport:!!n.needsImport}:{error:n.error??`register failed (${t.status})`}}async function Qp(e){let t=await Z(`/api/personal/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:e})}),n=await t.json().catch(()=>({}));return t.ok?{ok:n.ok!==!1,repos:Array.isArray(n.repos)?n.repos:[],login:n.login,error:n.error}:{ok:!1,repos:[],error:n?.error??`request failed`}}async function $p(){let e=await Z(`/api/personal/status`);return e.ok?await e.json():null}async function em(){let e=await Z(`/api/onboarding`);return e.ok?await e.json():null}async function tm(e){let t=await Z(`/api/onboarding/submit`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({values:e})}),n=await t.json().catch(()=>({}));return t.ok?n:{error:n.error??`submit failed (${t.status})`}}async function nm(e){let t=await Z(`/api/personal/crypt-key`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({password:e})}),n=await t.json().catch(()=>({}));return t.ok?typeof n.cryptKey==`string`?{ok:!0,cryptKey:n.cryptKey}:{ok:!1,error:`missing cryptKey in response`}:{ok:!1,error:n.error??`request failed (${t.status})`,wrongPassword:t.status===403}}async function rm(e,t=!1){let n=await Z(`/api/personal/delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({password:e,force:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0,synced:r.synced,dataLost:r.dataLost}:{ok:!1,error:r.error??`delete failed (${n.status})`,wrongPassword:n.status===403,syncFailed:r.syncFailed,uncommitted:r.uncommitted,unpushed:r.unpushed,hasRemote:r.hasRemote}}async function im(e){let t=await Z(`/api/personal/pull`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({force:e?.force??!1})}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`pull failed (${t.status})`,conflict:n.conflict,files:n.files,needsStash:n.needsStash}}async function am(){let e=await Z(`/api/personal/push`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,message:t.message}:{ok:!1,error:t.error??`push failed (${e.status})`,conflict:t.conflict,files:t.files,needsPull:t.needsPull}}async function om(e,t){let n={};e&&(n.repoUrl=e),t&&(n.cryptKey=t);let r=await Z(`/api/personal/import`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,autoInitialized:!!i.autoInitialized,cryptKey:typeof i.cryptKey==`string`?i.cryptKey:null}:{ok:!1,error:i.error??`import failed (${r.status})`,needsCryptKey:!!i.needsCryptKey,notClean:!!i.notClean,secretsExposed:!!i.secretsExposed,exposedFiles:Array.isArray(i.exposedFiles)?i.exposedFiles:[]}}async function sm(e,t,n,r){let i={token:e};t&&(i.repoName=t),n&&(i.cryptKey=n),r&&(i.baseUrl=r);let a=await Z(`/api/personal/github`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}),o=await a.json().catch(()=>({}));return a.ok?{ok:!0,repo:typeof o.repo==`string`?o.repo:void 0,created:!!o.created,autoInitialized:!!o.autoInitialized,cryptKey:typeof o.cryptKey==`string`?o.cryptKey:null}:{ok:!1,error:o.error??`github setup failed (${a.status})`,needsCryptKey:!!o.needsCryptKey}}async function cm(){await Z(`/api/auth/logout`,{method:`POST`}).catch(()=>{})}async function lm(e=`active`){let t=await Z(`/api/loops`+(e===`all`?`?archived=all`:e===`archived`?`?archived=true`:``));return t.ok?(await t.json()).loops:[]}async function um(e){if(e.knowledgeRw||e.mountAllLoops){let t={title:e.title,repo:e.repo,profiles:e.profiles,vault:e.vault};return e.knowledgeRw&&(t.knowledge_rw=!0),e.mountAllLoops&&(t.mount_all_loops=!0),await(await Z(`/api/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json()}let t=await Z(`/api/v1/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({title:e.title,profiles:e.profiles,vault:e.vault,repo:e.repo})});if(!t.ok)throw Error(`createLoop failed (${t.status})`);let n=await t.json();return{id:n.id.startsWith(`loop_`)?n.id.slice(5):n.id,title:n.title,createdAt:n.created_at,createdBy:n.created_by,archived:n.archived,repo:n.repo??void 0,config:{profiles:n.profiles,vault:n.vault}}}async function dm(){let e=await Z(`/api/profiles`);return e.ok?(await e.json()).profiles??[]:[]}async function fm(){let e=await Z(`/api/personal/default-profiles`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.default_profiles)?t.default_profiles:[]}async function pm(e){let t=await Z(`/api/loop-stats?profiles=${encodeURIComponent(e.join(`,`))}`);return t.ok?await t.json():null}async function mm(){let e=await Z(`/api/vaults`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.vaults)?t.vaults:[]}async function hm(e){return(await Z(`/api/loops/${e}/viewed`,{method:`POST`})).ok}async function gm(e,t){let n=await Z(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({archived:t})});return n.ok?await n.json():null}async function _m(e,t){let n=await Z(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({public:t})});return n.ok?await n.json():null}async function vm(e,t){let n=await Z(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({title:t})});return n.ok?await n.json():null}async function ym(e){let t=await Z(`/api/loops/${e}/request-drive`,{method:`POST`});return t.ok?await t.json():null}async function bm(e){let t=await Z(`/api/loops/${e}/drive`,{method:`POST`});return t.ok?await t.json():null}async function xm(e){let t=await Z(`/api/loops/${e}/distill`,{method:`POST`});return t.ok?await t.json():null}async function Sm(e){let t=await Z(`/api/loops/${e}`);return t.ok?await t.json():null}async function Cm(e){let t=await Z(`/api/loops/${e}/strip-thinking`,{method:`POST`});return t.ok?await t.json():{stripped:0,sessionsTouched:0}}async function wm(e,t=``){return(await(await Z(`/api/loops/${e}/files?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Tm(e,t=``){return(await(await Z(`/api/loops/${e}/files/tree?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Em(e,t){let n=await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Dm(e,t,n){return(await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).ok}async function Om(e,t){return(await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function km(e,t){return(await Z(`/api/loops/${e}/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).ok}async function Am(e,t){let n=new FormData;n.append(`file`,t);let r=await Z(`/api/loops/${e}/upload`,{method:`POST`,body:n}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,path:i.path}:{ok:!1,error:i.error??`upload failed`}}async function jm(e){let t=await Z(`/api/loops/${e}/context`);return t.ok?(await t.json()).mounts??[]:[]}async function Mm(e,t=``){let n=await Z(`/api/workspace/files?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).entries??[]:[]}async function Nm(e){let t=await Z(`/api/workspace/files?vault=${e}&flat=1`);return t.ok?(await t.json()).entries??[]:[]}async function Pm(e,t){let n=await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Fm(e,t,n){return await(await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).json()}async function Im(){let e=await Z(`/api/notes/save`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,message:t.message}:{ok:!1,conflict:t.conflict,files:t.files,needsPull:t.needsPull,error:t.error??`save failed (${e.status})`}}async function Lm(){let e=await(await Z(`/api/notes/behind`)).json().catch(()=>({}));return typeof e.behind==`number`?e.behind:0}async function Rm(){let e=await(await Z(`/api/notes/refresh`,{method:`POST`})).json().catch(()=>({}));return{ok:!!e.ok,diverged:e.diverged,error:e.error}}async function zm(e,t){return await(await Z(`/api/workspace/file?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Bm(e,t){return await(await Z(`/api/workspace/folder?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Vm(e,t){return await(await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`DELETE`})).json()}async function Hm(e,t){let n=await Z(`/api/workspace/backlinks?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).backlinks??[]:[]}async function Um(){let e=await Z(`/api/context/repos`);return e.ok?{repos:(await e.json()).repos??[]}:{repos:[]}}async function Wm(e){let t=await Z(`/api/context/repos`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`http ${t.status}`}}async function Gm(e){let t=await Z(`/api/loops/${e}/chat-history`);return t.ok?(await t.json()).map(e=>e.text):[]}async function Km(e,t){await Z(`/api/loops/${e}/chat-history`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t})})}function qm(e){return typeof e==`string`?`/api/sync/${e}`:`/api/sync/repos/${encodeURIComponent(e.repo)}`}async function Jm(e){let t=await Z(`${qm(e)}/status`);return t.ok?await t.json():null}async function Ym(e){let t=await Z(`${qm(e)}/pull`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function Xm(e){let t=await Z(`${qm(e)}/push`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function Zm(e=`default`){let t=await Z(`/api/kanban/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function Qm(e,t,n){let r=await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),i=await r.json().catch(()=>({}));return r.ok?{cid:i.cid}:{error:i.error??`add failed`}}async function $m(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/toggle`,{method:`PATCH`})).ok}async function eh(e,t,n,r){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(r)})).ok}async function th(e,t,n,r){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/block`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({block:r})})).ok}async function nh(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`DELETE`})).ok}async function rh(e,t,n,r,i){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/move`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:r,toIndex:i})})).ok}async function ih(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({filename:t,title:n})})).ok}async function ah(){let e=await Z(`/api/kanban/boards`);return e.ok?(await e.json()).boards:[`default`]}async function oh(e){return(await Z(`/api/kanban/boards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).ok}async function sh(e,t){return(await Z(`/api/kanban/boards/${encodeURIComponent(e)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})})).ok}async function ch(e=`default`){let t=await Z(`/api/kanban/config/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function lh(e,t){return(await Z(`/api/kanban/config/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({columns:t})})).ok}async function uh(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:n})})).ok}async function dh(e,t){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function fh(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/color`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({color:n})})).ok}async function ph(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/reorder`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({cids:n})})).ok}async function mh(e,t,n){let r=await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/assign-driver`,{method:`POST`});return r.ok?await r.json():{ok:!1}}async function hh(e,t,n,r){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/link-loop`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({loopId:r})})).ok}async function gh(){let e=await Z(`/api/topics`);return e.ok?(await e.json()).topics:[]}async function _h(){let e=await Z(`/api/providers`);return e.ok?await e.json():{providers:{},default:``}}async function vh(e,t,n,r,i){let a={baseUrl:e,model:n};t?a.apiKey=t:r&&i&&(a.provider=r,a.source=i);let o=await Z(`/api/providers/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(a)}),s=await o.json().catch(()=>({}));return o.ok?s:{ok:!1,error:s.error??`test failed (${o.status})`}}async function yh(){let e=await Z(`/api/version`);return e.ok?await e.json():{branch:`unknown`,commit:`unknown`}}async function bh(){let e=await Z(`/api/admin/system`);return e.ok?await e.json():null}async function xh(){return await(await Z(`/api/admin/system/check`,{method:`POST`})).json()}async function Sh(){return await(await Z(`/api/admin/system/pull`,{method:`POST`})).json()}function Ch(){return{commit:`2dba74d59651291167a9577f98be30e01ffe7323`,time:`2026-06-03T00:58:14.018Z`}}async function wh(e){let t=await Z(`/api/loops/${e}/git-status`);return t.ok?await t.json():{unstaged:[],staged:[]}}async function Th(e,t,n){let r=await Z(`/api/loops/${e}/git-diff?path=${encodeURIComponent(t)}&staged=${n?`1`:`0`}`);return r.ok?(await r.json()).diff??null:null}async function Eh(e,t,n=!1){return(await Z(`/api/loops/${e}/git-stage`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({files:t,unstage:n})})).ok}async function Dh(e,t){return(await Z(`/api/loops/${e}/git-discard`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({file:t})})).ok}async function Oh(e,t){let n=await Z(`/api/loops/${e}/git-commit`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`commit failed`}}async function kh(e,t=50){let n=await Z(`/api/loops/${e}/git-log?limit=${t}`);return n.ok?(await n.json()).commits??[]:[]}async function Ah(){let e=await Z(`/api/settings/personal/disk`);return e.ok?await e.json():null}async function jh(e){let t=await Z(`/api/settings/personal/disk`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`save failed (${t.status})`}}async function Mh(e,t,n=`default`){let r=await Z(`/api/settings/personal/value`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e,value:t,vault:n})}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0}:{ok:!1,error:i.error??`write failed (${r.status})`}}async function Nh(){return await(await Z(`/api/settings/workspace`)).json()}async function Ph(e){return(await Z(`/api/settings/workspace`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Fh(){let e=await Z(`/api/settings/token-usage/daily`);return e.ok?await e.json():{}}async function Ih(){let e=await Z(`/api/settings/token-usage/loops`);return e.ok?await e.json():[]}async function Lh(){let e=await Z(`/api/admin/presets`);return e.ok?await e.json():{providerPresets:[],miseToolPresets:[]}}async function Rh(e){return(await Z(`/api/admin/presets`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function zh(){let e=await Z(`/api/admin/users`);return e.ok?(await e.json()).users??[]:[]}async function Bh(e){let t=await Z(`/api/admin/users/${encodeURIComponent(e)}/activate`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`activate failed (${t.status})`}}async function Vh(e,t){let n=await Z(`/api/admin/users/${encodeURIComponent(e)}/role`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({role:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`role change failed (${n.status})`}}async function Hh(e){let t=await Z(`/api/admin/users/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function Uh(){let e=await Z(`/api/serve/config`);return e.ok?await e.json():{serveEnabled:!0,domain:`nip.io`,ip:`127.0.0.1`,baseUrl:`.127.0.0.1.nip.io`,withPort:!1,https:!1,displayPort:7788,serveDynamicEnabled:!1,serveDynamicDomain:``,serveDynamicPortRange:`10000-20000`,serveDynamicUdpEnabled:!1,serveDynamicStaticEnabled:!1,serveEphemeralEnabled:!1,serveEphemeralDomain:``}}async function Wh(e){let t=await Z(`/api/loops/${e}/share/current-port`);return t.ok?await t.json():{port:null}}async function Gh(e){return(await Z(`/api/serve/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Kh(){let e=await Z(`/api/serve/available-port`);return e.ok?await e.json():{port:null,error:`request failed`}}async function qh(e,t){let n=await Z(`/api/serve/check-port?port=${e}&loopId=${t||``}`);return n.ok?await n.json():{available:!1,reason:`request failed`}}async function Jh(e,t){let n=new URLSearchParams({alias:e});t&&n.set(`loopId`,t);let r=await Z(`/api/serve/alias-check?${n}`);return r.ok?await r.json():{available:!1,reason:`check failed`}}async function Yh(){let e=await Z(`/api/chat/conversations`);return e.ok?(await e.json()).conversations??[]:[]}async function Xh(){let e=await Z(`/api/chat/users`);return e.ok?(await e.json()).users??[]:[]}async function Zh(e,t){let n=await Z(`/api/chat/channels`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e,topic:t})}),r=await n.json().catch(()=>({}));return n.ok?{conv:r.conv}:{error:r.error??`create failed (${n.status})`}}async function Qh(e){let t=await Z(`/api/chat/channels/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function $h(e){let t=await Z(`/api/chat/dm/${encodeURIComponent(e)}`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{conv:n.conv}:{error:n.error??`open DM failed (${t.status})`}}async function eg(e,t={}){let n=new URLSearchParams;t.before&&n.set(`before`,String(t.before)),t.limit&&n.set(`limit`,String(t.limit));let r=await Z(`/api/chat/conversations/${encodeURIComponent(e)}/messages?${n.toString()}`);return r.ok?(await r.json()).messages??[]:[]}async function tg(e){let t=await Z(`/api/chat/threads/${e}`);return t.ok?await t.json():null}async function ng(e,t,n=null){let r=await Z(`/api/chat/conversations/${encodeURIComponent(e)}/messages`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n==null?{text:t}:{text:t,parentId:n})}),i=await r.json().catch(()=>({}));return r.ok?{message:i.message}:{error:i.error??`send failed (${r.status})`}}async function rg(e,t){return(await Z(`/api/chat/conversations/${encodeURIComponent(e)}/read`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({lastReadId:t})})).ok}async function ig(e,t){let n=await Z(`/api/chat/threads/${e}/spawn-loop`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t?{title:t}:{})}),r=await n.json().catch(()=>({}));return n.ok?{loopId:r.loopId,seedPrompt:r.seedPrompt,messageCount:r.messageCount}:{error:r.error??`spawn failed (${n.status})`}}async function ag(e,t,n){let r=await Z(`/api/mcp-setup/parse`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({server:e,pastedUrl:t,loopId:n})}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,set:i.set??[]}:{ok:!1,error:i.error??`failed (${r.status})`}}async function og(){let e=await Z(`/api/a2a`);return e.ok?await e.json():null}async function sg(e){return(await Z(`/api/a2a`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function cg(){let e=await Z(`/api/a2a/key`,{method:`POST`});return e.ok?(await e.json().catch(()=>({}))).token??null:null}async function lg(e){let t=await Z(`/api/mcp-servers${e?`?loopId=${encodeURIComponent(e)}`:``}`);return t.ok?await t.json():{servers:[]}}async function ug(e,t){let n=await Z(`/api/mcp-auth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({serverName:e,loopId:t})}),r=await n.json().catch(()=>({}));return n.ok?{authorizationUrl:r.authorizationUrl}:{error:r.error??`start failed`}}async function dg(e){return(await Z(`/api/envs/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}async function fg(e){let t=await Z(`/api/loops/${encodeURIComponent(e)}/restart-session`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{restarted:!!n.restarted}:{restarted:!1,error:n.error??`restart failed (${t.status})`}}async function pg(){let e=await Z(`/api/tiers`);return e.ok?await e.json():null}async function mg(e,t){let n=await Z(`/api/tiers/${encodeURIComponent(e)}/settings`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`save failed (${n.status})`}}async function hg(e){let t=await Z(`/api/tiers/${encodeURIComponent(e)}/mise-config`);return t.ok?await t.json():{content:``,exists:!1,error:`fetch failed (${t.status})`}}async function gg(e,t){let n=await Z(`/api/tiers/${encodeURIComponent(e)}/mise-config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`save failed (${n.status})`}}async function _g(){let e=await Z(`/api/plugins/available`);return e.ok?(await e.json()).plugins??[]:[]}async function vg(){let e=await Z(`/api/plugins/browse`);return e.ok?(await e.json()).plugins??[]:[]}async function yg(){let e=await Z(`/api/marketplaces`);return e.ok?(await e.json()).marketplaces??[]:[]}async function bg(){let e=await Z(`/api/plugins/refresh`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,added:t.added}:{ok:!1,error:t.error??`refresh failed (${e.status})`}}async function xg(e){let t=await Z(`/api/admin/profiles`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`create failed (${t.status})`}}async function Sg(e){let t=await Z(`/api/admin/profiles/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function Cg(){let e=await Z(`/api/v1/me/tokens`);return e.ok?(await e.json().catch(()=>({tokens:[]}))).tokens??[]:[]}async function wg(e){let t=await Z(`/api/v1/me/tokens`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({label:e})});return t.ok?await t.json().catch(()=>null):null}async function Tg(e){return(await Z(`/api/v1/me/tokens/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}function Eg(){let[e,t]=(0,w.useState)([]),[n,r]=(0,w.useState)(!0),[i,a]=(0,w.useState)(!1),[o,s]=(0,w.useState)(!1),[c,l]=(0,w.useState)(``),[u,d]=(0,w.useState)(null),[f,p]=(0,w.useState)(null),[m,h]=(0,w.useState)(!0),g=(0,w.useCallback)(async()=>{r(!0),t(await lm(i?`all`:`active`)),r(!1)},[i]);(0,w.useEffect)(()=>{let e=!1;return Yp().then(t=>{e||(p(t),h(!1))}),()=>{e=!0}},[]),(0,w.useEffect)(()=>{g()},[i,f]);let _=(0,w.useCallback)(async e=>{let n=await um(e);return t(e=>[n,...e]),n},[]),v=(0,w.useCallback)(async(e,n)=>{let r=await gm(e,n);r&&t(t=>!i&&r.archived?t.filter(t=>t.id!==e):t.map(t=>t.id===e?r:t))},[i]),y=(0,w.useCallback)(async(e,n)=>{let r=await _m(e,n);r&&t(t=>t.map(t=>t.id===e?r:t))},[]),b=(0,w.useCallback)(async(e,n)=>{let r=await vm(e,n);return r?(t(t=>t.map(t=>t.id===e?r:t)),r):null},[]),x=(0,w.useCallback)(async e=>{let n=await ym(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),S=(0,w.useCallback)(async e=>{let n=await bm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),C=(0,w.useCallback)(async(e,t)=>{let n=await Xp(e,t);return n.user&&p(n.user),{error:n.error}},[]),T=(0,w.useCallback)(async e=>{let t=await Zp(e);return t.user&&t.user.status===`active`&&p(t.user),{error:t.error,user:t.user,publicKey:t.publicKey,personalRepo:t.personalRepo,needsImport:t.needsImport}},[]),E=(0,w.useCallback)(async()=>{await cm(),p(null)},[]);return{loops:e,loopsLoading:n,showArchived:i,setShowArchived:a,refresh:g,createLoop:_,setLoopArchived:v,setLoopPublic:y,setLoopTitle:b,requestDrive:x,takeDrive:S,newLoopDialogOpen:o,newLoopDialogTitle:c,kanbanCreateCtx:u,setNewLoopDialogOpen:(0,w.useCallback)((e,t,n)=>{s(e),l(t??``),d(n??null)},[]),currentUser:f,authLoading:m,login:C,register:T,logout:E}}var Dg=(0,w.createContext)(null);function Og(){let e=(0,w.useContext)(Dg);if(!e)throw Error(`useWorkspace outside provider`);return e}function kg({onClose:e,onCreate:t,initialTitle:n}){let[r,i]=(0,w.useState)(n??``),[a,o]=(0,w.useState)(``),[s,c]=(0,w.useState)(new Set),[l,u]=(0,w.useState)([]),[d,f]=(0,w.useState)(`default`),[p,m]=(0,w.useState)([]),[h,g]=(0,w.useState)([]),[_,v]=(0,w.useState)([]),[y,b]=(0,w.useState)(null),[x,S]=(0,w.useState)(!1),[C,T]=(0,w.useState)(!1),E=(0,w.useRef)(null);(0,w.useEffect)(()=>{Um().then(e=>m(e.repos)),Promise.all([dm(),fm()]).then(([e,t])=>{g(e),u(t);let n=new Set(e.map(e=>e.name));c(new Set(t.filter(e=>n.has(e)&&e!==`base`)))}),mm().then(e=>{v(e),e.includes(`default`)?f(`default`):e.length>0&&f(e[0])}),E.current?.focus()},[]);function D(){let e=new Set(h.map(e=>e.name));c(new Set(l.filter(t=>e.has(t)&&t!==`base`)))}(0,w.useEffect)(()=>{S(!0);let e=setTimeout(()=>{pm([...s]).then(b).finally(()=>S(!1))},120);return()=>clearTimeout(e)},[s]);let O=(()=>{let e=new Set(l.filter(e=>e!==`base`));if(e.size!==s.size)return!0;for(let t of e)if(!s.has(t))return!0;return!1})(),k=h.find(e=>e.name===`base`),A=h.filter(e=>e.name!==`base`);function j(e){c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:e,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[480px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5 max-h-[85vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,q.jsx)(`div`,{className:`text-base font-semibold text-gray-900 mb-4`,children:`New loop`}),(0,q.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),!C){T(!0);try{await t({title:r.trim()||`untitled`,repo:a||void 0,profiles:s.size>0?[...s]:void 0,vault:d||void 0})}finally{T(!1)}}},className:`flex flex-col gap-4`,children:[(0,q.jsxs)(Ag,{label:`Repo`,hint:`Sets the workdir. Optional — leave (none) for an empty workdir.`,children:[(0,q.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value),className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 bg-white`,children:[(0,q.jsx)(`option`,{value:``,children:`(none — empty workdir)`}),p.map(e=>(0,q.jsxs)(`option`,{value:e.name,children:[e.name,e.git?` · ${e.git}`:``]},e.name))]}),p.length===0&&(0,q.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`No repos in the roster. Add them on the Context → Repos page.`})]}),(0,q.jsxs)(Ag,{label:`Profiles`,hint:`Each profile contributes plugins + a CLAUDE.md fragment. Empty = base + personal only.`,children:[(0,q.jsxs)(`div`,{className:`border border-gray-300 rounded p-2 max-h-44 overflow-y-auto bg-white flex flex-col gap-1`,children:[k&&(0,q.jsxs)(`label`,{className:`flex items-start gap-2 px-1.5 py-1 rounded text-sm text-gray-500 cursor-not-allowed bg-gray-50`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:!0,disabled:!0,className:`mt-0.5`}),(0,q.jsxs)(`span`,{className:`flex-1`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:`base`}),(0,q.jsx)(`span`,{className:`ml-1 text-[11px] text-gray-400`,children:`(always on)`}),k.description&&(0,q.jsx)(`span`,{className:`block text-[11px] text-gray-400 mt-0.5`,children:k.description})]})]}),A.map(e=>{let t=s.has(e.name),n=l.includes(e.name);return(0,q.jsxs)(`label`,{className:`flex items-start gap-2 px-1.5 py-1 rounded text-sm cursor-pointer hover:bg-gray-50 ${t?`bg-blue-50`:``}`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>j(e.name),className:`mt-0.5`}),(0,q.jsxs)(`span`,{className:`flex-1`,children:[(0,q.jsx)(`span`,{className:`font-medium text-gray-900`,children:e.name}),n&&(0,q.jsx)(`span`,{className:`ml-1.5 px-1 py-px text-[10px] rounded bg-gray-200 text-gray-600`,title:`In your default_profiles (personal config)`,children:`default`}),e.description&&(0,q.jsx)(`span`,{className:`block text-[11px] text-gray-500 mt-0.5`,children:e.description})]})]},e.name)}),A.length===0&&!k&&(0,q.jsxs)(`div`,{className:`text-[11px] text-gray-400 p-1.5`,children:[`No profiles yet. Add them under`,` `,(0,q.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`knowledge/.loopat/profiles/<name>/.claude/`}),` `,`in your knowledge repo.`]})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between mt-1`,children:[(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:s.size>0?`Selected: ${[...s].join(`, `)}`:`No profiles selected (base + personal only)`}),O&&l.length>0&&(0,q.jsx)(`button`,{type:`button`,onClick:D,className:`text-[11px] text-gray-500 hover:text-gray-900 underline`,title:`Restore default_profiles from your personal config`,children:`reset to defaults`})]}),(0,q.jsx)(`div`,{className:`mt-1.5 px-1.5 py-1 text-[11px] text-gray-600 bg-gray-50 border border-gray-200 rounded`,children:x&&!y?(0,q.jsx)(`span`,{className:`text-gray-400`,children:`computing…`}):y?(0,q.jsxs)(`span`,{title:`Totals across team + selected profiles + their plugins (deduped by name)`,children:[(0,q.jsxs)(`span`,{className:y.plugins>0?``:`text-gray-400`,children:[y.plugins,` plugins`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.skills>0?``:`text-gray-400`,children:[y.skills,` skills`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.agents>0?``:`text-gray-400`,children:[y.agents,` agents`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.hooks>0?``:`text-gray-400`,children:[y.hooks,` hooks`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.mcpServers>0?``:`text-gray-400`,children:[y.mcpServers,` MCP servers`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.toolchain>0?``:`text-gray-400`,title:`mise.toml [tools] entries, deduped across team + selected profiles`,children:[y.toolchain,` toolchain`]}),x&&(0,q.jsx)(`span`,{className:`ml-1.5 text-gray-400`,children:`·`}),x&&(0,q.jsx)(`span`,{className:`ml-1 text-gray-400`,children:`updating…`})]}):(0,q.jsx)(`span`,{className:`text-gray-400`,children:`—`})})]}),(0,q.jsxs)(Ag,{label:`Vault`,hint:`Which credential set to inject. Only this vault is visible inside the loop.`,children:[(0,q.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 bg-white`,children:[_.length===0&&(0,q.jsx)(`option`,{value:`default`,children:`default`}),_.map(e=>(0,q.jsx)(`option`,{value:e,children:e},e))]}),_.length===0&&(0,q.jsxs)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:[`No vaults yet — using default. Create more under`,` `,(0,q.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`personal/.loopat/vaults/<name>/`}),` `,`to isolate prod / test credentials.`]})]}),(0,q.jsx)(Ag,{label:`Name`,hint:`Optional — defaults to 'untitled'.`,children:(0,q.jsx)(`input`,{ref:E,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`refactor-gateway`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2 pt-3 border-t border-gray-100`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:e,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,q.jsx)(`button`,{type:`submit`,disabled:C,className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:C?`creating…`:`create`})]})]})]})})}function Ag({label:e,hint:t,children:n}){return(0,q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,q.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,q.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var jg=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,Mg=vf,Ng=((e,t)=>n=>{if(t?.variants==null)return Mg(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=jg(t)||jg(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return Mg(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)})(`inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function Pg({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,q.jsx)(r?Ri:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:X(Ng({variant:t,size:n,className:e})),...i})}function Fg({...e}){return(0,q.jsx)(cc,{"data-slot":`dialog`,...e})}function Ig({...e}){return(0,q.jsx)(lc,{"data-slot":`dialog-portal`,...e})}function Lg({className:e,...t}){return(0,q.jsx)(uc,{"data-slot":`dialog-overlay`,className:X(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function Rg({className:e,children:t,showCloseButton:n=!0,...r}){return(0,q.jsxs)(Ig,{"data-slot":`dialog-portal`,children:[(0,q.jsx)(Lg,{}),(0,q.jsxs)(dc,{"data-slot":`dialog-content`,className:X(`fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-white p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,e),...r,children:[t,n&&(0,q.jsxs)(mc,{"data-slot":`dialog-close`,className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,q.jsx)(ht,{}),(0,q.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function zg({className:e,...t}){return(0,q.jsx)(`div`,{"data-slot":`dialog-header`,className:X(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function Bg({className:e,...t}){return(0,q.jsx)(fc,{"data-slot":`dialog-title`,className:X(`text-lg leading-none font-semibold`,e),...t})}function Vg({className:e,...t}){return(0,q.jsx)(pc,{"data-slot":`dialog-description`,className:X(`text-sm text-muted-foreground`,e),...t})}function Hg({open:e,onClose:t}){let[n,r]=(0,w.useState)({branch:`…`,commit:`…`}),i=Ch();return(0,w.useEffect)(()=>{e&&yh().then(e=>r(e))},[e]),(0,q.jsx)(Fg,{open:e,onOpenChange:e=>!e&&t(),children:(0,q.jsxs)(Rg,{className:`sm:max-w-sm bg-white`,children:[(0,q.jsx)(zg,{children:(0,q.jsxs)(Bg,{className:`text-center`,children:[(0,q.jsx)(`img`,{src:`/logo.png`,alt:`loopat`,className:`w-full max-w-[240px] mx-auto mb-2`}),`loopat`]})}),(0,q.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,q.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,q.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Server`}),(0,q.jsxs)(`div`,{className:`font-mono text-gray-700`,children:[n.branch,`@`,n.commit.slice(0,7)]})]}),(0,q.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,q.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Build`}),(0,q.jsx)(`div`,{className:`font-mono text-gray-700`,children:i.commit.slice(0,7)}),(0,q.jsx)(`div`,{className:`font-mono text-gray-400 text-xs mt-0.5`,children:new Date(i.time).toLocaleString()})]})]})]})})}function Ug(e){let t=[];for(let n of e.effectTasks)try{n()}catch(e){t.push(e)}if(t.length>0){if(t.length===1)throw t[0];for(let e of t)console.error(e);throw AggregateError(t,`Errors during commit`)}}function Wg(e){let t=[];for(let n of e.cells)if(n?.type===`effect`&&(n.deps=null,n.cleanup))try{n.cleanup?.()}catch(e){t.push(e)}finally{n.cleanup=void 0}if(t.length>0){if(t.length===1)throw t[0];for(let e of t)console.error(e);throw AggregateError(t,`Errors during cleanup`)}}var Gg=typeof process<`u`&&!1,Kg=null;function qg(e,t){e.currentIndex=0;let n=Kg;Kg=e;try{if(t(),e.isFirstRender=!1,e.cells.length!==e.currentIndex)throw Error(`Rendered ${e.currentIndex} hooks but expected ${e.cells.length}. Hooks must be called in the exact same order in every render.`)}finally{Kg=n}}function Jg(){if(!Kg)throw Error(`No resource fiber available`);return Kg}function Yg(e){return Gg?Kg?.devStrictMode?Kg.isFirstRender?`child`:`root`:e?`root`:null:null}function Xg(e,t){let n=e[Zg];if(!n)throw Error(`ResourceElement.type is not a valid Resource`);return n(t)}var Zg=Symbol(`fnSymbol`);function Qg(e,t,n=void 0,r=Yg(!1)){return{type:e,root:t,markDirty:n,devStrictMode:r,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function $g(e){if(!e.isMounted)throw Error(`Tried to unmount a fiber that is already unmounted`);e.isMounted=!1,Wg(e)}function e_(e,t){let n={effectTasks:[],props:t,output:void 0};return qg(e,()=>{e.renderContext=n;try{n.output=Xg(e.type,t)}finally{e.renderContext=void 0}}),n}function t_(e,t){e.isMounted=!0,Gg&&e.isNeverMounted&&e.devStrictMode===`root`&&(e.isNeverMounted=!1,Ug(t),Wg(e)),e.isNeverMounted=!1,Ug(t)}var n_=e=>({version:0,committedVersion:0,dispatchUpdate:e,changelog:[],dirtyCells:[]}),r_=e=>{for(let t of e.dirtyCells)t.dirty=!1,t.queue.clear(),t.current=t.workInProgress;e.committedVersion=e.version,e.changelog.length=0,e.dirtyCells.length=0},i_=(e,t)=>{let n=e.version>t;if(e.version=t,n){for(let t of e.dirtyCells)t.dirty=!1,t.queue.clear(),t.workInProgress=t.current;if(e.dirtyCells.length=0,t===e.committedVersion)e.changelog.length=0;else{if(e.committedVersion>t)throw Error(`Version is less than committed version`);for(;e.committedVersion+e.changelog.length>t;)e.changelog.pop();e.changelog.forEach(e=>e()),r_(e)}}},a_=(e,t)=>{t.dirty||(t.dirty=!0,e.markDirty?.(),e.root.dirtyCells.push(t))},o_=()=>{if(!Gg)return null;let e=(0,w.useRef)(0),t=e.current===0;return(0,w.useState)(()=>e.current++),e.current===2?t?`child`:`root`:null};function s_(e){let t=(0,w.useMemo)(()=>n_(e=>r(e)),[]),[n,r]=(0,w.useReducer)((e,n)=>(i_(t,e),e+ +!!n()),0);i_(t,n);let i=o_(),a=(0,w.useMemo)(()=>(e.key,Qg(e.type,t,void 0,i)),[e.type,e.key,t,i]),o=e_(a,e.props);return(0,w.useLayoutEffect)(()=>()=>$g(a),[a]),(0,w.useLayoutEffect)(()=>{r_(t),t_(a,o)}),o.output}function c_(e){let t=e=>({type:t,props:e});return t[Zg]=e,t}function l_(e,t){return{...t,key:e}}var u_=(e,t)=>{let n=Jg(),r=n.currentIndex++;if(!n.isFirstRender&&r>=n.cells.length)throw Error(`Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render.`);let i=n.cells[r];if(i||(i=t(),n.cells[r]=i),i.type!==e)throw Error(`Hook order changed between renders`);return i},d_=e=>{Jg().renderContext.effectTasks.push(e)},f_=(e,t)=>{if(e.renderContext)throw Error(`Resource updated during render`);if(e.isNeverMounted)throw Error(`Resource updated before mount`);e.root.dispatchUpdate(()=>{let n=t();return n?(n(),e.root.changelog.push(n),!0):!1})};function p_(e,t,n,r){let i=u_(`reducer`,()=>{let t=Jg(),a=r?r(n):n;return Gg&&t.devStrictMode&&r&&r(n),{type:`reducer`,queue:new Set,dirty:!1,workInProgress:a,current:a,reducer:e,dispatch:n=>{let r={action:n,hasEagerState:!1,eagerState:void 0};f_(t,()=>t.root.dirtyCells.length===0&&!r.hasEagerState&&(r.eagerState=e(i.workInProgress,n),r.hasEagerState=!0,Object.is(i.current,r.eagerState))?null:()=>{a_(t,i),i.queue.add(r)})}}}),a=Jg(),o=e===i.reducer;i.reducer=e;for(let t of i.queue)(!t.hasEagerState||!o)&&(t.eagerState=e(i.workInProgress,t.action),t.hasEagerState=!0),Gg&&a.devStrictMode&&e(i.workInProgress,t.action),i.workInProgress=t.eagerState;if(i.queue.clear(),t){let e=t(i.workInProgress);Object.is(e,i.workInProgress)||(a_(a,i),i.workInProgress=e)}return[i.workInProgress,i.dispatch]}function m_(e,t,n){return p_(e,void 0,t,n)}function h_(e,t,n,r){return p_(e,t,n,r)}var g_=(e,t)=>typeof t==`function`?t(e):t,__=e=>typeof e==`function`?e():e;function v_(e){return m_(g_,e,__)}var y_=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0},b_=()=>({type:`effect`,cleanup:void 0,deps:null});function x_(e,t){let n=u_(`effect`,b_);if(!(t&&n.deps&&y_(n.deps,t))){if(n.deps!==null&&!!t!=!!n.deps)throw Error(`tapEffect called with and without dependencies across re-renders`);d_(()=>{let r=[];try{n.cleanup?.()}catch(e){r.push(e)}finally{n.cleanup=void 0}try{let t=e();if(t!==void 0&&typeof t!=`function`)throw Error(`An effect function must either return a cleanup function or nothing. Received: ${typeof t}`);n.cleanup=t}catch(e){r.push(e)}if(n.deps=t,r.length>0){if(r.length===1)throw r[0];for(let e of r)console.error(e);throw AggregateError(r,`Errors during commit`)}})}}function S_(e){let[t]=v_(()=>({current:e}));return t}function C_(e,t){let[n]=v_(e);return n}var w_=()=>{throw Error(`Memo reducer should not be called`)},T_=(e,t)=>{let n=Jg(),[r]=h_(w_,r=>{if(r&&y_(r.deps,t))return r;let i=e();return Gg&&n.devStrictMode&&e(),{value:i,deps:t}},null);return r.value},E_=(e,t)=>T_(()=>e,t);function D_(e){let t=S_(e);x_(()=>{t.current=e});let n=Jg();return E_(((...e)=>{if(Gg&&n.renderContext)throw Error(`tapEffectEvent cannot be called during render`);return t.current(...e)}),[n])}function O_(e,t){let n=Jg(),r=S_(0),i=T_(()=>(e.key,Qg(e.type,n.root,()=>{r.current++,n.markDirty?.()})),[e.type,e.key,n]),a=t?T_(()=>e_(i,e.props),[i,...t,r.current]):e_(i,e.props);return x_(()=>()=>$g(i),[i]),x_(()=>{t_(i,a)},[i,a]),a.output}function k_(e,t){let n=S_(0),r=n.current,i=C_(Jg,[]),a=C_(()=>()=>{n.current++,i.markDirty?.()},[]),o=C_(()=>new Map,[]),s=t?E_(e,t):e,c=T_(()=>{let e=s(),t=new Set,n=[],r=0;for(let s=0;s<e.length;s++){let c=e[s],l=c.key;if(l===void 0)throw Error(`tapResources did not provide a key for array at index ${s}`);if(t.has(l))throw Error(`Duplicate key ${l} in tapResources`);t.add(l);let u=o.get(l);if(!u){let e=Qg(c.type,i.root,a),t=e_(e,c.props);u={fiber:e,next:t},r++,o.set(l,u),n.push(t.output)}else if(u.fiber.type!==c.type){let e=Qg(c.type,i.root,a),t=e_(e,c.props);u.next=[e,t],n.push(t.output)}else u.next=e_(u.fiber,c.props),n.push(u.next.output)}if(o.size>n.length-r)for(let e of o.keys())t.has(e)||(o.get(e).next=`delete`);return n},[s,r]);return x_(()=>()=>{for(let e of o.keys()){let t=o.get(e).fiber;$g(t)}},[]),x_(()=>{for(let[e,t]of o.entries())t.next===`delete`?(t.fiber.isMounted&&$g(t.fiber),o.delete(e)):Array.isArray(t.next)?($g(t.fiber),t.fiber=t.next[0],t_(t.fiber,t.next[1])):t_(t.fiber,t.next)},[c]),c}var A_=50,j_={schedulers:new Set([]),isScheduled:!1},M_=class{_task;_isDirty=!1;constructor(e){this._task=e}get isDirty(){return this._isDirty}markDirty(){this._isDirty=!0,j_.schedulers.add(this),N_()}runTask(){this._isDirty=!1,this._task()}},N_=()=>{j_.isScheduled||(j_.isScheduled=!0,F_())},P_=()=>{try{let e=[],t=0;for(let n of j_.schedulers)if(j_.schedulers.delete(n),n.isDirty){if(t++,t>A_)throw Error(`Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside tapEffect.`);try{n.runTask()}catch(t){e.push(t)}}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e,`Errors occurred during flushSync`)}}finally{j_.schedulers.clear(),j_.isScheduled=!1}},F_=(()=>{if(typeof MessageChannel<`u`){let e=new MessageChannel;return e.port1.onmessage=P_,()=>e.port2.postMessage(null)}return()=>setTimeout(P_,0)})(),I_=e=>{let t=j_;j_={schedulers:new Set([]),isScheduled:!0};try{let t=e();return P_(),t}finally{j_=t}},L_=e=>{let t=C_(()=>new M_(()=>l(null)),[]),n=C_(()=>[],[]),r=T_(()=>(e.key,Qg(e.type,n_(e=>{!t.isDirty&&!e()||(n.push(e),t.markDirty())}))),[e.type,e.key]);i_(r.root,r.root.committedVersion);let i=e_(r,e.props),a=S_(!1),o=S_(e.props),s=S_(i.output),c=C_(()=>new Set,[]),l=D_(e=>{if(e===null&&(i_(r.root,2),i_(r.root,1),n.forEach(e=>{Gg&&r.devStrictMode&&e(),e()}),Gg&&r.devStrictMode&&e_(r,o.current),e=e_(r,o.current)),t.isDirty)throw Error(`Scheduler is dirty, this should never happen`);r_(r.root),n.length=0,a.current&&t_(r,e),!(t.isDirty||s.current===e.output)&&(s.current=e.output,c.forEach(e=>e()))});return x_(()=>(a.current=!0,()=>{a.current=!1,$g(r)}),[r]),x_(()=>{o.current=i.props,r_(r.root),t_(r,i),!(t.isDirty||s.current===i.output)&&(s.current=i.output,c.forEach(e=>e()))}),T_(()=>({getValue:()=>s.current,subscribe:e=>(c.add(e),()=>c.delete(e))}),[])},R_=Symbol(`tap.Context`),z_=e=>({[R_]:e}),B_=(e,t,n)=>{let r=e[R_];e[R_]=t;try{return n()}finally{e[R_]=r}},V_=e=>e[R_],H_=Symbol(`assistant-ui.store.clientIndex`),U_=e=>e[H_],W_=z_([]),G_=()=>V_(W_),K_=(e,t)=>{let n=G_();return B_(W_,T_(()=>[...n,e],[n,e]),t)},q_=new Set([`$$typeof`,`nodeType`,`then`]),J_=(e,t)=>{if(e===Symbol.toStringTag)return t;if(typeof e!=`symbol`){if(e===`toJSON`)return()=>t;if(!q_.has(e))return!1}},Y_=class{getOwnPropertyDescriptor(e,t){let n=this.get(e,t);if(n!==void 0)return{value:n,writable:!1,enumerable:!0,configurable:!1}}set(){return!1}setPrototypeOf(){return!1}defineProperty(){return!1}deleteProperty(){return!1}preventExtensions(){return!1}},X_=e=>{let t=c_(e);return e=>{let n=t(e);return e.key===void 0?n:l_(e.key,n)}},Z_=Symbol(`assistant-ui.store.getValue`),Q_=e=>{let t=e[Z_];if(!t)throw Error(`Client scope contains a non-client resource. Ensure your Derived get() returns a client created with tapClientResource(), not a plain resource.`);return t.getState?.()},$_=new Map;function ev(e){let t=$_.get(e);return t||(t=function(...t){if(!this||typeof this!=`object`)throw Error(`Method "${String(e)}" called without proper context. This may indicate the function was called incorrectly.`);let n=this[Z_];if(!n)throw Error(`Method "${String(e)}" called on invalid client proxy. Ensure you are calling this method on a valid client instance.`);let r=n[e];if(!r)throw Error(`Method "${String(e)}" is not implemented.`);if(typeof r!=`function`)throw Error(`"${String(e)}" is not a function.`);return r(...t)},$_.set(e,t)),t}var tv=class extends Y_{outputRef;index;boundFns;cachedReceiver;constructor(e,t){super(),this.outputRef=e,this.index=t}get(e,t,n){if(t===Z_)return this.outputRef.current;if(t===H_)return this.index;let r=J_(t,`ClientProxy`);if(r!==!1)return r;let i=this.outputRef.current[t];if(typeof i==`function`){this.cachedReceiver!==n&&(this.boundFns=new Map,this.cachedReceiver=n);let e=this.boundFns.get(t);return e||(e=ev(t).bind(n),this.boundFns.set(t,e)),e}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,t){return t===Z_||t===H_?!0:t in this.outputRef.current}},nv=X_(e=>{let t=S_(null),n=G_().length,r=T_(()=>new Proxy({},new tv(t,n)),[n]),i=K_(r,()=>O_(e));return t.current||=i,x_(()=>{t.current=i}),{methods:r,state:i.getState?.(),key:e.key}}),rv=e=>O_(nv(e)),iv=Symbol(`assistant-ui.store.proxiedAssistantState`),av=e=>e===`on`||e===`subscribe`||typeof e==`symbol`,ov=e=>{class t extends Y_{get(t,n){let r=J_(n,`AssistantState`);if(r!==!1)return r;let i=n;if(!av(i))return Q_(e[i]())}ownKeys(){return Object.keys(e).filter(e=>!av(e))}has(t,n){return!av(n)&&n in e}}return new Proxy({},new t)},sv=e=>e[iv],cv=()=>()=>{},lv=e=>{let t=(()=>{throw Error(e)});return t.source=null,t.query=null,t},uv=new Proxy({},new class extends Y_{get(e,t){if(t===`subscribe`||t===`on`)return cv;if(t===iv)return dv;let n=J_(t,`DefaultAssistantClient`);return n===!1?lv(`You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.`):n}ownKeys(){return[`subscribe`,`on`,iv]}has(e,t){return t===`subscribe`||t===`on`||t===iv}}),dv=ov(uv),fv=()=>new Proxy({},{get(e,t){let n=J_(t,`AssistantClient`);return n===!1?lv(`The current scope does not have a "${String(t)}" property.`):n}}),pv=(0,w.createContext)(uv),mv=()=>(0,w.useContext)(pv),hv=({value:e,children:t})=>(0,q.jsx)(pv.Provider,{value:e,children:t}),gv=c_(e=>null),_v=Symbol(`assistant-ui.transform-scopes`);function vv(e,t){let n=e;if(n[_v])throw Error(`transformScopes is already attached to this resource`);n[_v]=t}function yv(e){return e[_v]}function bv(e,t){let n={...e},r=new Set,i=!0;for(;i;){i=!1;for(let e of Object.values(n)){if(e.type===gv||r.has(e.type))continue;r.add(e.type);let a=yv(e.type);if(a){a(n,t),i=!0;break}}}let a={},o={};for(let[e,t]of Object.entries(n))t.type===gv?o[e]=t:a[e]=t;return{rootClients:a,derivedClients:o}}var xv=e=>T_(()=>e,[...Object.entries(e).flat()]),Sv=(e,t)=>{let{rootClients:n,derivedClients:r}=bv(e,t);return{rootClients:xv(n),derivedClients:xv(r)}},Cv=e=>typeof e==`string`?{scope:e.split(`.`)[0],event:e}:{scope:e.scope,event:e.event},wv=c_(()=>C_(()=>{let e=new Map,t=new Set,n=new Set;return{on(n,r){let i=r;if(n===`*`)return t.add(i),()=>t.delete(i);let a=e.get(n);return a||(a=new Set,e.set(n,a)),a.add(i),()=>{a.delete(i),a.size===0&&e.delete(n)}},emit(n,r,i){let a=e.get(n);!a&&t.size===0||queueMicrotask(()=>{let e=[];if(a)for(let t of a)try{t(r,i)}catch(t){e.push(t)}if(t.size>0){let a={event:n,payload:r};for(let n of t)try{n(a,i)}catch(t){e.push(t)}}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e,`Errors occurred during event emission`)}})},subscribe(e){return n.add(e),()=>n.delete(e)},notifySubscribers(){for(let e of n)try{e()}catch(e){console.error(`NotificationManager: subscriber callback error`,e)}}}},[])),Tv=z_(null),Ev=(e,t)=>B_(Tv,e,t),Dv=()=>{let e=V_(Tv);if(!e)throw Error(`AssistantTapContext is not available`);return e},Ov=()=>Dv().clientRef,kv=()=>{let{emit:e}=Dv(),t=G_();return D_((n,r)=>{e(n,r,t)})},Av=e=>T_(()=>e,e),jv=c_(({element:e,emit:t,clientRef:n})=>{let{methods:r,state:i}=Ev({clientRef:n,emit:t},()=>rv(e));return T_(()=>({state:i,methods:r}),[r,i])}),Mv=c_(({element:e,notifications:t,clientRef:n,name:r})=>{let i=L_(jv({element:e,emit:t.emit,clientRef:n}));return x_(()=>i.subscribe(t.notifySubscribers),[i,t]),T_(()=>{let e=()=>i.getValue().methods;return Object.defineProperties(e,{source:{value:`root`,writable:!1},query:{value:{},writable:!1},name:{value:r,configurable:!0}}),e},[i,r])}),Nv=c_(()=>T_(()=>({clients:[],subscribe:void 0,on:void 0}),[])),Pv=c_(({clients:e,clientRef:t})=>{let n=O_(wv());x_(()=>t.parent.subscribe(n.notifySubscribers),[t,n]);let r=Av(k_(()=>Object.keys(e).map(r=>l_(r,Mv({element:e[r],notifications:n,clientRef:t,name:r}))),[e,n,t]));return T_(()=>({clients:r,subscribe:n.subscribe,on:function(e,r){if(!this)throw Error(`const { on } = useAui() is not supported. Use aui.on() instead.`);let{scope:i,event:a}=Cv(e);if(i!==`*`&&this[i].source===null)throw Error(`Scope "${i}" is not available. Use { scope: "*", event: "${a}" } to listen globally.`);let o=n.on(a,(e,t)=>{if(i===`*`){r(e);return}let n=this[i]();n===t[U_(n)]&&r(e)});if(i!==`*`&&t.parent[i].source===null)return o;let s=t.parent.on(e,r);return()=>{o(),s()}}}),[r,n,t])}),Fv=(e,t,n)=>{if(`source`in e&&`query`in e)return e;if(n.dep===e)return n.meta;let r=e.getMeta(t.current);return n.meta=r,n.dep=e,r},Iv=c_(({element:e,clientRef:t,name:n})=>{let r=D_(()=>e.props);return T_(()=>{let e=()=>r().get(t.current),i={};return Object.defineProperties(e,{source:{get:()=>Fv(r(),t,i).source},query:{get:()=>Fv(r(),t,i).query},name:{value:n,configurable:!0}}),e},[t,n])}),Lv=c_(({clients:e,clientRef:t})=>Av(k_(()=>Object.keys(e).map(n=>l_(n,Iv({element:e[n],clientRef:t,name:n}))),[e,t]))),Rv=c_(({parent:e,clients:t})=>{let{rootClients:n,derivedClients:r}=Sv(t,e),i=S_({parent:e,current:null}).current;x_(()=>{i.current=s});let a=O_(Object.keys(n).length>0?Pv({clients:n,clientRef:i}):Nv()),o=O_(Lv({clients:r,clientRef:i})),s=T_(()=>{let t=e===uv?fv():e,n=Object.create(t);Object.assign(n,{subscribe:a.subscribe??e.subscribe,on:a.on??e.on,[iv]:ov(n)});for(let e of a.clients)n[e.name]=e;for(let e of o)n[e.name]=e;return n},[e,a,o]);return i.current===null&&(i.current=s),s});function zv(e,{parent:t}={parent:mv()}){if(e)return s_(Rv({parent:t??uv,clients:e}));if(t===null)throw Error(`received null parent, this usage is not allowed`);return t}var Q=e=>{let t=zv(),n=sv(t),r=(0,w.useSyncExternalStore)(t.subscribe,()=>e(n),()=>e(n));if(r===n)throw Error(`You tried to return the entire AssistantState. This is not supported due to technical limitations.`);return(0,w.useDebugValue)(r),r},Bv=w.createContext(!0);function Vv(){throw Error(`A function wrapped in useEffectEvent can't be called during rendering.`)}var Hv=`use`in w.default?()=>{try{return w.use(Bv)}catch{return!1}}:()=>!1;function Uv(e){let t=w.useRef(Vv);return w.useInsertionEffect(()=>{t.current=e},[e]),(...e)=>{Hv()&&Vv();let n=t.current;return n(...e)}}var Wv=(e,t)=>{let n=zv(),r=Uv(t),{scope:i,event:a}=Cv(e);(0,w.useEffect)(()=>n.on({scope:i,event:a},r),[n,i,a,r])},Gv=e=>{let t=zv(),n=(0,w.useRef)(!1),r=n.current?null:e(t);return Q(()=>n.current?e(t):r),()=>(n.current=!0,e(t))},Kv=Object.freeze({});function qv({getItemState:e,children:t}){return Jv(t(Gv(e)))}var Jv=e=>{let t=typeof e==`object`&&e&&`type`in e?e:null,n=t?.type,r=t?.key;return(0,w.useMemo)(()=>t,[n,r,typeof t?.props==`object`&&t.props!=null&&Object.entries(t.props).length===0?Kv:t?.props])??e},Yv=({children:e,condition:t})=>Q(t)?e:null;Yv.displayName=`AuiIf`;var Xv=X_(e=>{if(e.key===void 0)throw Error(`tapClientResource: Element has no key`);return O_(nv(e))});function Zv(e,t){let n=k_(()=>e().map(e=>Xv(e)),t),r=T_(()=>Object.keys(n),[n]),i=T_(()=>n.reduce((e,t,n)=>(e[t.key]=n,e),{}),[n]);return{state:T_(()=>n.map(e=>e.state),[n]),get:e=>{if(`index`in e){if(e.index<0||e.index>=r.length)throw Error(`tapClientLookup: Index ${e.index} out of bounds (length: ${r.length})`);return n[e.index].methods}let t=i[e.key];if(t===void 0)throw Error(`tapClientLookup: Key "${e.key}" not found`);return n[t].methods}}}var Qv=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},$v=(e=>e?Qv(e):Qv),ey=e=>e;function ty(e,t=ey){let n=w.useSyncExternalStore(e.subscribe,w.useCallback(()=>t(e.getState()),[e,t]),w.useCallback(()=>t(e.getInitialState()),[e,t]));return w.useDebugValue(n),n}var ny=e=>{let t=$v(e),n=e=>ty(t,e);return Object.assign(n,t),n},ry=(e=>e?ny(e):ny),iy=r(((e,t)=>{var n=typeof Buffer<`u`,r=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,i=/"(?: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 a(e,t,a){a==null&&typeof t==`object`&&t&&(a=t,t=void 0),n&&Buffer.isBuffer(e)&&(e=e.toString()),e&&e.charCodeAt(0)===65279&&(e=e.slice(1));let s=JSON.parse(e,t);if(typeof s!=`object`||!s)return s;let c=a&&a.protoAction||`error`,l=a&&a.constructorAction||`error`;if(c===`ignore`&&l===`ignore`)return s;if(c!==`ignore`&&l!==`ignore`){if(r.test(e)===!1&&i.test(e)===!1)return s}else if(c!==`ignore`&&l===`ignore`){if(r.test(e)===!1)return s}else if(i.test(e)===!1)return s;return o(s,{protoAction:c,constructorAction:l,safe:a&&a.safe})}function o(e,{protoAction:t=`error`,constructorAction:n=`error`,safe:r}={}){let i=[e];for(;i.length;){let e=i;i=[];for(let a of e){if(t!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`__proto__`)){if(r===!0)return null;if(t===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.__proto__}if(n!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`constructor`)&&a.constructor!==null&&typeof a.constructor==`object`&&Object.prototype.hasOwnProperty.call(a.constructor,`prototype`)){if(r===!0)return null;if(n===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.constructor}for(let e in a){let t=a[e];t&&typeof t==`object`&&i.push(t)}}}return e}function s(e,t,n){let{stackTraceLimit:r}=Error;Error.stackTraceLimit=0;try{return a(e,t,n)}finally{Error.stackTraceLimit=r}}function c(e,t){let{stackTraceLimit:n}=Error;Error.stackTraceLimit=0;try{return a(e,t,{safe:!0})}catch{return}finally{Error.stackTraceLimit=n}}t.exports=s,t.exports.default=s,t.exports.parse=s,t.exports.safeParse=c,t.exports.scan=o}));function ay(e){let t=[`ROOT`],n=-1,r=null,i=[],a;function o(){a!==void 0&&(i.push(JSON.parse(`"${a}"`)),a=void 0)}function s(e,i,a){switch(e){case`"`:n=i,t.pop(),t.push(a),t.push(`INSIDE_STRING`),o();break;case`f`:case`t`:case`n`:n=i,r=i,t.pop(),t.push(a),t.push(`INSIDE_LITERAL`);break;case`-`:t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),o();break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=i,t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),o();break;case`{`:n=i,t.pop(),t.push(a),t.push(`INSIDE_OBJECT_START`),o();break;case`[`:n=i,t.pop(),t.push(a),t.push(`INSIDE_ARRAY_START`),o();break}}function c(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_COMMA`);break;case`}`:n=r,t.pop(),a=i.pop();break}}function l(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),a=(Number(a)+1).toString();break;case`]`:n=r,t.pop(),a=i.pop();break}}for(let o=0;o<e.length;o++){let u=e[o];switch(t[t.length-1]){case`ROOT`:s(u,o,`FINISH`);break;case`INSIDE_OBJECT_START`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`),a=``;break;case`}`:n=o,t.pop(),a=i.pop();break}break;case`INSIDE_OBJECT_AFTER_COMMA`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`),a=``;break}break;case`INSIDE_OBJECT_KEY`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_KEY`);break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`),a+=u;break;default:a+=u;break}break;case`INSIDE_OBJECT_AFTER_KEY`:switch(u){case`:`:t.pop(),t.push(`INSIDE_OBJECT_BEFORE_VALUE`);break}break;case`INSIDE_OBJECT_BEFORE_VALUE`:s(u,o,`INSIDE_OBJECT_AFTER_VALUE`);break;case`INSIDE_OBJECT_AFTER_VALUE`:c(u,o);break;case`INSIDE_STRING`:switch(u){case`"`:t.pop(),n=o,a=i.pop();break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`);break;default:n=o}break;case`INSIDE_ARRAY_START`:switch(u){case`]`:n=o,t.pop(),a=i.pop();break;default:n=o,a=`0`,s(u,o,`INSIDE_ARRAY_AFTER_VALUE`);break}break;case`INSIDE_ARRAY_AFTER_VALUE`:switch(u){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),a=(Number(a)+1).toString();break;case`]`:n=o,t.pop(),a=i.pop();break;default:n=o;break}break;case`INSIDE_ARRAY_AFTER_COMMA`:s(u,o,`INSIDE_ARRAY_AFTER_VALUE`);break;case`INSIDE_STRING_ESCAPE`:t.pop(),t[t.length-1]===`INSIDE_STRING`?n=o:t[t.length-1]===`INSIDE_OBJECT_KEY`&&(a+=u);break;case`INSIDE_NUMBER`:switch(u){case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=o;break;case`e`:case`E`:case`-`:case`.`:break;case`,`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&c(u,o);break;case`}`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&c(u,o);break;case`]`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o);break;default:t.pop(),a=i.pop();break}break;case`INSIDE_LITERAL`:{let i=e.substring(r,o+1);!`false`.startsWith(i)&&!`true`.startsWith(i)&&!`null`.startsWith(i)?(t.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`?c(u,o):t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o)):n=o;break}}}let u=e.slice(0,n+1);for(let n=t.length-1;n>=0;n--)switch(t[n]){case`INSIDE_STRING`:u+=`"`;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`:u+=`}`;break;case`INSIDE_ARRAY_START`:case`INSIDE_ARRAY_AFTER_COMMA`:case`INSIDE_ARRAY_AFTER_VALUE`:u+=`]`;break;case`INSIDE_LITERAL`:{let t=e.substring(r,e.length);`true`.startsWith(t)?u+=`true`.slice(t.length):`false`.startsWith(t)?u+=`false`.slice(t.length):`null`.startsWith(t)&&(u+=`null`.slice(t.length))}}return[u,i]}var oy=n(iy(),1),sy=Symbol(`aui.parse-partial-json-object.meta`),cy=e=>e?.[sy],ly=e=>{if(e.length===0)return{[sy]:{state:`partial`,partialPath:[]}};try{let t=oy.default.parse(e);if(typeof t!=`object`||!t)throw Error(`argsText is expected to be an object`);return t[sy]={state:`complete`,partialPath:[]},t}catch{try{let[t,n]=ay(e),r=oy.default.parse(t);if(typeof r!=`object`||!r)throw Error(`argsText is expected to be an object`);return r[sy]={state:`partial`,partialPath:n},r}catch{return}}},uy=(e,t,n)=>{if(typeof e!=`object`||!e)return t.state;if(t.state===`complete`)return`complete`;if(n.length===0)return t.state;let[r,...i]=n;if(!Object.hasOwn(e,r))return`partial`;let[a,...o]=t.partialPath;if(r!==a)return`complete`;let s=e[r];return uy(s,{state:`partial`,partialPath:o},i)},dy=(e,t)=>{let n=cy(e);if(!n)throw Error(`unable to determine object state`);return uy(e,n,t.map(String))};async function*fy(){let e=this.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)break;yield n}}finally{e.releaseLock()}}function py(e){return e[Symbol.asyncIterator]??=fy,e}var my=()=>{let e,t,n=new Promise((n,r)=>{e=n,t=r});if(!e||!t)throw Error(`Failed to create promise`);return{promise:n,resolve:e,reject:t}},hy=()=>{let e=[],t=!1,n,r,i=i=>{i.promise||=i.reader.read().then(({done:a,value:o})=>{i.promise=void 0,a?(e.splice(e.indexOf(i),1),t&&e.length===0&&n.close()):n.enqueue(o),r?.resolve(),r=void 0}).catch(t=>{console.error(t),e.forEach(e=>{e.reader.cancel()}),e.length=0,n.error(t),r?.reject(t),r=void 0})};return{readable:new ReadableStream({start(e){n=e},pull(){return r=my(),e.forEach(e=>{i(e)}),r.promise},cancel(){e.forEach(e=>{e.reader.cancel()}),e.length=0}}),isSealed(){return t},seal(){t=!0,e.length===0&&n.close()},addStream(n){if(t)throw Error(`Cannot add streams after the run callback has settled.`);let r={reader:n.getReader()};e.push(r),i(r)},enqueue(e){this.addStream(new ReadableStream({start(t){t.enqueue(e),t.close()}}))}}},gy=class{_controller;_isClosed=!1;constructor(e){this._controller=e}append(e){return this._controller.enqueue({type:`text-delta`,path:[],textDelta:e}),this}close(){this._isClosed||(this._isClosed=!0,this._controller.enqueue({type:`part-finish`,path:[]}),this._controller.close())}},_y=e=>new ReadableStream({start(t){return e.start?.(new gy(t))},pull(t){return e.pull?.(new gy(t))},cancel(t){return e.cancel?.(t)}}),vy=()=>{let e;return[_y({start(t){e=t}}),e]},yy=class{_controller;_isClosed=!1;_mergeTask;constructor(e){this._controller=e;let t=_y({start:e=>{this._argsTextController=e}}),n=!1;this._mergeTask=t.pipeTo(new WritableStream({write:e=>{switch(e.type){case`text-delta`:n=!0,this._controller.enqueue(e);break;case`part-finish`:n||this._controller.enqueue({type:`text-delta`,textDelta:`{}`,path:[]}),this._controller.enqueue({type:`tool-call-args-text-finish`,path:[]});break;default:throw Error(`Unexpected chunk type: ${e.type}`)}}}))}get argsText(){return this._argsTextController}_argsTextController;async setResponse(e){this._argsTextController.close(),await Promise.resolve(),this._controller.enqueue({type:`result`,path:[],...e.artifact===void 0?{}:{artifact:e.artifact},result:e.result,isError:e.isError??!1,...e.modelContent===void 0?{}:{modelContent:e.modelContent},...e.messages===void 0?{}:{messages:e.messages}})}async close(){this._isClosed||(this._isClosed=!0,this._argsTextController.close(),await this._mergeTask,this._controller.enqueue({type:`part-finish`,path:[]}),this._controller.close())}},by=e=>new ReadableStream({start(t){return e.start?.(new yy(t))},pull(t){return e.pull?.(new yy(t))},cancel(t){return e.cancel?.(t)}}),xy=()=>{let e;return[by({start(t){e=t}}),e]},Sy=class{value=-1;up(){return++this.value}},Cy=class extends TransformStream{constructor(e){super({transform(t,n){n.enqueue({...t,path:[e,...t.path]})}})}};TransformStream;var wy=class extends TransformStream{constructor(e){let t=new Sy,n=new Map;super({transform(r,i){r.type===`part-start`&&r.path.length===0&&n.set(t.up(),e.up());let[a,...o]=r.path;if(a===void 0){i.enqueue(r);return}let s=n.get(a);if(s===void 0)throw Error(`Path not found`);i.enqueue({...r,path:[s,...o]})}})}},Ty=class extends TransformStream{constructor(e){super();let t=e(super.readable);Object.defineProperty(this,`readable`,{value:t,writable:!1})}},Ey=class extends TransformStream{constructor(){let e=[];super({transform(t,n){if(t.type===`part-start`){if(t.path.length!==0){n.error(Error(`Nested parts are not supported`));return}e.push(t.part),n.enqueue(t);return}if(t.type===`text-delta`||t.type===`result`||t.type===`part-finish`||t.type===`tool-call-args-text-finish`){if(t.path.length!==1){n.error(Error(`${t.type} chunks must have a path of length 1`));return}let r=t.path[0];if(r<0||r>=e.length){n.error(Error(`Invalid path index: ${r}`));return}let i=e[r];n.enqueue({...t,meta:i});return}n.enqueue(t)}})}},Dy=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},Oy=Dy(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),ky=class e{_state;_parentId;constructor(e){this._state=e||{merger:hy(),contentCounter:new Sy}}get __internal_isClosed(){return this._state.merger.isSealed()}__internal_getReadable(){return this._state.merger.readable}__internal_subscribeToClose(e){this._state.closeSubscriber=e}_addPart(e,t){this._state.append&&(this._state.append.controller.close(),this._state.append=void 0),this.enqueue({type:`part-start`,part:e,path:[]}),this._state.merger.addStream(t.pipeThrough(new Cy(this._state.contentCounter.value)))}merge(e){this._state.merger.addStream(e.pipeThrough(new wy(this._state.contentCounter)))}appendText(e){this._state.append?.kind!==`text`&&(this._state.append={kind:`text`,controller:this.addTextPart()}),this._state.append.controller.append(e)}appendReasoning(e){this._state.append?.kind!==`reasoning`&&(this._state.append={kind:`reasoning`,controller:this.addReasoningPart()}),this._state.append.controller.append(e)}addTextPart(){let[e,t]=vy();return this._addPart({type:`text`},e),t}addReasoningPart(){let[e,t]=vy();return this._addPart({type:`reasoning`},e),t}addToolCallPart(e){let t=typeof e==`string`?{toolName:e}:e,n=t.toolName,r=t.toolCallId??Oy(),[i,a]=xy();return this._addPart({type:`tool-call`,toolName:n,toolCallId:r,...this._parentId&&{parentId:this._parentId}},i),t.argsText!==void 0&&(a.argsText.append(t.argsText),a.argsText.close()),t.args!==void 0&&(a.argsText.append(JSON.stringify(t.args)),a.argsText.close()),t.response!==void 0&&a.setResponse(t.response),a}_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())}appendFile(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}appendData(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}enqueue(e){this._state.merger.enqueue(e),e.type===`part-start`&&e.path.length===0&&this._state.contentCounter.up()}withParentId(t){let n=new e(this._state);return n._parentId=t,n}close(){this._state.append?.controller?.close(),this._state.merger.seal(),this._state.closeSubscriber?.()}};function Ay(e){let t=new ky;return(async()=>{try{await e(t)}catch(e){throw t.__internal_isClosed||t.enqueue({type:`error`,path:[],error:String(e)}),e}finally{t.__internal_isClosed||t.close()}})(),t.__internal_getReadable()}function jy(){let{resolve:e,promise:t}=my(),n;return[Ay(r=>(n=r,n.__internal_subscribeToClose(e),t)),n]}var My=c_(e=>({getState:()=>e})),Ny=c_(e=>{let[t]=v_(()=>({suggestions:(e??[]).map(e=>typeof e==`string`?{title:e,label:``,prompt:e}:{title:e.title,label:e.label,prompt:e.prompt})})),n=Zv(()=>t.suggestions.map((e,t)=>l_(t,My(e))),[t.suggestions]);return{getState:()=>t,suggestion:({index:e})=>n.get({index:e})}}),Py=Object.freeze({type:`complete`}),Fy=c_(({parts:e,getMessagePart:t})=>{let[n,r]=v_(!0),i=T_(()=>e[e.length-1]?.status??Py,[e]),a=T_(()=>({parts:e,collapsed:n,status:i}),[e,n,i]);return{getState:()=>a,setCollapsed:r,part:t}}),Iy=e=>Array.from(e).map(e=>e.getModelContext()).sort((e,t)=>(t.priority??0)-(e.priority??0)).reduce((e,t)=>{if(t.system&&(e.system?e.system+=`\n\n${t.system}`:e.system=t.system),t.tools)for(let[n,r]of Object.entries(t.tools)){let t=e.tools?.[n];if(t&&t!==r)throw Error(`You tried to define a tool with the name ${n}, but it already exists.`);e.tools||={},e.tools[n]=r}return t.config&&(e.config={...e.config,...t.config}),t.callSettings&&(e.callSettings={...e.callSettings,...t.callSettings}),e},{}),Ly=class{_providers=new Set;getModelContext(){return Iy(this._providers)}registerModelContextProvider(e){this._providers.add(e);let t=e.subscribe?.(()=>{this.notifySubscribers()});return this.notifySubscribers(),()=>{this._providers.delete(e),t?.(),this.notifySubscribers()}}_subscribers=new Set;notifySubscribers(){for(let e of this._subscribers)e()}subscribe(e){return this._subscribers.add(e),()=>this._subscribers.delete(e)}},Ry=1,zy=c_(()=>{let[e]=v_(()=>({version:Ry+1})),t=T_(()=>new Ly,[]);return{getState:()=>e,getModelContext:()=>t.getModelContext(),subscribe:e=>t.subscribe(e),register:e=>t.registerModelContextProvider(e)}}),By=c_(({toolkit:e,mcpApp:t})=>{let n=k_(()=>t?[l_(`mcpApp`,t)]:[],[t])[0],[r,i]=v_(()=>({tools:{}})),a=T_(()=>({tools:r.tools,mcpApp:n}),[r,n]),o=Ov(),s=E_((e,t)=>(i(n=>({tools:{...n.tools,[e]:[...n.tools[e]??[],t]}})),()=>{i(n=>({tools:{...n.tools,[e]:n.tools[e]?.filter(e=>e!==t)??[]}}))}),[]);return x_(()=>{if(!e)return;let t=[];for(let[n,r]of Object.entries(e))r.render&&t.push(s(n,r.render));let n=Object.entries(e).reduce((e,[t,n])=>{let{render:r,...i}=n;return e[t]=i,e},{});return t.push(o.current.modelContext().register({getModelContext:()=>({tools:n})})),()=>{t.forEach(e=>e())}},[e,s,o]),{getState:()=>a,setToolUI:s}});vv(By,(e,t)=>{!e.modelContext&&t.modelContext.source===null&&(e.modelContext=zy())});var Vy=c_(()=>{let[e,t]=v_(()=>({renderers:{},fallbacks:[]}));return{getState:()=>e,setDataUI:E_((e,n)=>(t(t=>({...t,renderers:{...t.renderers,[e]:[...t.renderers[e]??[],n]}})),()=>{t(t=>({...t,renderers:{...t.renderers,[e]:t.renderers[e]?.filter(e=>e!==n)??[]}}))}),[]),setFallbackDataUI:E_(e=>(t(t=>({...t,fallbacks:[...t.fallbacks,e]})),()=>{t(t=>({...t,fallbacks:t.fallbacks.filter(t=>t!==e)}))}),[])}}),Hy=Symbol.for(`aui.tool-response`),Uy=class e{get[Hy](){return!0}artifact;result;isError;modelContent;messages;constructor(e){e.artifact!==void 0&&(this.artifact=e.artifact),this.result=e.result,this.isError=e.isError??!1,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&&Hy in e}static toResponse(t){return t instanceof e?t:new e({result:t===void 0?`<no result>`:t})}};function Wy(e,t,n){try{let r=e();if(typeof r==`object`&&r&&`then`in r)return r.then(t,n);t(r)}catch(e){n(e)}}function Gy(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}var Ky=class{resolve;reject;disposed=!1;fieldPath;constructor(e,t,n){this.resolve=e,this.reject=t,this.fieldPath=n}update(e){if(!this.disposed)try{if(dy(e,this.fieldPath)===`complete`){let t=Gy(e,this.fieldPath);t!==void 0&&(this.resolve(t),this.dispose())}}catch(e){this.reject(e),this.dispose()}}dispose(){this.disposed=!0}},qy=class{controller;disposed=!1;fieldPath;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=Gy(e,this.fieldPath);t!==void 0&&this.controller.enqueue(t),dy(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Jy=class{controller;disposed=!1;fieldPath;lastValue=void 0;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=Gy(e,this.fieldPath);if(t!==void 0&&typeof t==`string`){let e=t.substring(this.lastValue?.length||0);this.lastValue=t,this.controller.enqueue(e)}dy(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Yy=class{controller;disposed=!1;fieldPath;processedIndexes=new Set;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=Gy(e,this.fieldPath);if(!Array.isArray(t))return;for(let n=0;n<t.length;n++)this.processedIndexes.has(n)||dy(e,[...this.fieldPath,n])===`complete`&&(this.controller.enqueue(t[n]),this.processedIndexes.add(n));dy(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Xy=class{argTextDeltas;handles=new Set;args=ly(``);constructor(e){this.argTextDeltas=e,this.processStream()}async processStream(){try{let e=``,t=this.argTextDeltas.getReader();for(;;){let{value:n,done:r}=await t.read();if(r)break;e+=n;let i=ly(e);if(i!==void 0){this.args=i;for(let e of this.handles)e.update(i)}}}catch(e){console.error(`Error processing argument stream:`,e);for(let e of this.handles)e.dispose()}}get(...e){return new Promise((t,n)=>{let r=new Ky(t,n,e);if(this.args&&dy(this.args,e)===`complete`){let n=Gy(this.args,e);if(n!==void 0){t(n);return}}this.handles.add(r),r.update(this.args)})}streamValues(...e){let t=e;return py(new ReadableStream({start:e=>{let n=new qy(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof qy){e.dispose(),this.handles.delete(e);break}}}))}streamText(...e){let t=e;return py(new ReadableStream({start:e=>{let n=new Jy(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Jy){e.dispose(),this.handles.delete(e);break}}}))}forEach(...e){let t=e;return py(new ReadableStream({start:e=>{let n=new Yy(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Yy){e.dispose(),this.handles.delete(e);break}}}))}},Zy=class{promise;constructor(e){this.promise=e}get(){return this.promise}},Qy=class{args;response;writable;resolve;argsText=``;constructor(){let e=new TransformStream;this.writable=e.writable,this.args=new Xy(e.readable);let{promise:t,resolve:n}=my();this.resolve=n,this.response=new Zy(t)}async appendArgsTextDelta(e){let t=this.writable.getWriter();try{await t.write(e)}catch(e){console.warn(e)}finally{t.releaseLock()}this.argsText+=e}setResponse(e){this.resolve(e)}result={get:async()=>(await this.response.get()).result}},$y=class extends Ty{constructor(e){let t=new Map,n=new Map;super(r=>{let i=new TransformStream({transform(r,i){switch((r.type!==`part-finish`||r.meta.type!==`tool-call`)&&i.enqueue(r),r.type){case`part-start`:if(r.part.type===`tool-call`){let t=new Qy;n.set(r.part.toolCallId,t),e.streamCall({reader:t,toolCallId:r.part.toolCallId,toolName:r.part.toolName})}break;case`text-delta`:if(r.meta.type===`tool-call`){let e=r.meta.toolCallId,t=n.get(e);if(!t)throw Error(`No controller found for tool call`);t.appendArgsTextDelta(r.textDelta)}break;case`result`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:e}=r.meta,t=n.get(e);if(!t)throw Error(`No controller found for tool call`);t.setResponse(new Uy({result:r.result,artifact:r.artifact,isError:r.isError,modelContent:r.modelContent}));break}case`tool-call-args-text-finish`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:a,toolName:o}=r.meta,s=n.get(a);if(!s)throw Error(`No controller found for tool call`);let c=!1,l=Wy(()=>{let t;try{t=oy.default.parse(s.argsText)}catch(e){throw Error(`Function parameter parsing failed. ${JSON.stringify(e.message)}`)}let n=e.execute({toolCallId:a,toolName:o,args:t});return n!==void 0&&(c=!0,e.onExecutionStart?.(a,o)),n},t=>{if(c&&e.onExecutionEnd?.(a,o),t===void 0)return;let n=new Uy({artifact:t.artifact,result:t.result,isError:t.isError,messages:t.messages,modelContent:t.modelContent});s.setResponse(n),i.enqueue({type:`result`,path:r.path,...n})},t=>{c&&e.onExecutionEnd?.(a,o);let n=new Uy({result:String(t),isError:!0});s.setResponse(n),i.enqueue({type:`result`,path:r.path,...n})});l&&t.set(a,l);break}case`part-finish`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:e}=r.meta,a=t.get(e);a?a.then(()=>{t.delete(e),n.delete(e),i.enqueue(r)}):i.enqueue(r)}}},async flush(){await Promise.all(t.values())}});return r.pipeThrough(new Ey).pipeThrough(i)})}},eb=e=>typeof e==`object`&&!!e&&`~standard`in e&&e[`~standard`].version===1;function tb(e,t,n,r){let i=e?.[n.toolName];return i?.execute?(async e=>{if(t.aborted)return new Uy({result:`Tool execution was cancelled.`,isError:!0});let a=e;if(eb(i.parameters)){let e=i.parameters[`~standard`].validate(n.args);e instanceof Promise&&(e=await e),e.issues&&(a=i.experimental_onSchemaValidationError??(()=>{throw Error(`Function parameter validation failed. ${JSON.stringify(e.issues)}`)}))}let o=new Promise(e=>{let n=()=>{queueMicrotask(()=>{queueMicrotask(()=>{e(new Uy({result:`Tool execution was cancelled.`,isError:!0}))})})};t.aborted?n():t.addEventListener(`abort`,n,{once:!0})}),s=(async()=>{let e=await a(n.args,{toolCallId:n.toolCallId,abortSignal:t,human:e=>r(n.toolCallId,e)}),o=Uy.toResponse(e);if(i.toModelOutput&&!o.isError&&o.modelContent===void 0)try{let e=await i.toModelOutput({toolCallId:n.toolCallId,input:n.args,output:o.result});return new Uy({result:o.result,artifact:o.artifact,isError:o.isError,messages:o.messages,modelContent:e})}catch(e){console.warn(`[assistant-stream] tool "${n.toolName}" toModelOutput threw; falling back to default projection.`,e)}return o})();return Promise.race([s,o])})(i.execute):void 0}function nb(e,t,n,r,i){e?.[r.toolName]?.streamCall?.(n,{toolCallId:r.toolCallId,abortSignal:t,human:e=>i(r.toolCallId,e)})}function rb(e,t,n,r){let i=typeof e==`function`?e:()=>e,a=typeof t==`function`?t:()=>t;return new $y({execute:e=>tb(i(),a(),e,n),streamCall:({reader:e,...t})=>nb(i(),a(),e,t,n),onExecutionStart:r?.onExecutionStart,onExecutionEnd:r?.onExecutionEnd})}var ib=e=>{let[,t]=v_(e.getState);return x_(()=>(t(e.getState()),e.subscribe(()=>{t(e.getState())})),[e]),e.getState()},ab=c_(({runtime:e})=>{let t=ib(e);return{getState:()=>t,remove:e.remove,__internal_getRuntime:()=>e}}),ob=c_(({runtime:e})=>{let t=ib(e);return{getState:()=>t,addToolResult:t=>e.addToolResult(t),resumeToolCall:t=>e.resumeToolCall(t),__internal_getRuntime:()=>e}}),sb=c_(({runtime:e,index:t})=>O_(ab({runtime:T_(()=>e.getAttachmentByIndex(t),[e,t])}))),cb=c_(({threadIdRef:e,messageIdRef:t,runtime:n})=>{let r=ib(n),i=kv();x_(()=>{let r=[];for(let a of[`send`,`attachmentAdd`]){let o=n.unstable_on(a,()=>{i(`composer.${a}`,{threadId:e.current,...t&&{messageId:t.current}})});r.push(o)}return r.push(n.unstable_on(`attachmentAddError`,n=>{i(`composer.attachmentAddError`,{threadId:e.current,...t&&{messageId:t.current},...n.attachmentId&&{attachmentId:n.attachmentId},reason:n.reason,message:n.message})})),()=>{for(let e of r)e()}},[n,i,e,t]);let a=Zv(()=>r.attachments.map((e,t)=>l_(e.id,sb({runtime:n,index:t}))),[r.attachments,n]),o=T_(()=>({text:r.text,role:r.role,attachments:a.state,runConfig:r.runConfig,isEditing:r.isEditing,canCancel:r.canCancel,canSend:r.canSend,attachmentAccept:r.attachmentAccept,isEmpty:r.isEmpty,type:r.type??`thread`,dictation:r.dictation,quote:r.quote,queue:[]}),[r,a.state]);return{getState:()=>o,setText:n.setText,setRole:n.setRole,setRunConfig:n.setRunConfig,addAttachment:n.addAttachment,reset:n.reset,clearAttachments:n.clearAttachments,send:n.send,cancel:n.cancel,beginEdit:n.beginEdit??(()=>{throw Error(`beginEdit is not supported in this runtime`)}),startDictation:n.startDictation,stopDictation:n.stopDictation,setQuote:n.setQuote,attachment:e=>`id`in e?a.get({key:e.id}):a.get(e),queueItem:()=>{throw Error(`Queue is not supported in this runtime`)},__internal_getRuntime:()=>n}}),lb=c_(({runtime:e,index:t})=>O_(ab({runtime:T_(()=>e.getAttachmentByIndex(t),[e,t])}))),ub=c_(({runtime:e,index:t})=>O_(ob({runtime:T_(()=>e.getMessagePartByIndex(t),[e,t])}))),db=c_(({runtime:e,threadIdRef:t})=>{let n=ib(e),[r,i]=v_(!1),[a,o]=v_(!1),s=T_(()=>({get current(){return e.getState().id}}),[e]),c=rv(cb({runtime:e.composer,threadIdRef:t,messageIdRef:s})),l=Zv(()=>n.content.map((t,n)=>l_(`toolCallId`in t&&t.toolCallId!=null?`toolCallId-${t.toolCallId}`:`index-${n}`,ub({runtime:e,index:n}))),[n.content,e]),u=Zv(()=>(n.attachments??[]).map((t,n)=>l_(t.id,lb({runtime:e,index:n}))),[n.attachments,e]),d=T_(()=>({...n,parts:l.state,composer:c.state,isCopied:r,isHovering:a}),[n,l.state,c.state,r,a]);return{getState:()=>d,composer:()=>c.methods,reload:t=>e.reload(t),speak:()=>e.speak(),stopSpeaking:()=>e.stopSpeaking(),submitFeedback:t=>e.submitFeedback(t),switchToBranch:t=>e.switchToBranch(t),getCopyText:()=>e.unstable_getCopyText(),part:e=>`index`in e?l.get({index:e.index}):l.get({key:`toolCallId-${e.toolCallId}`}),attachment:e=>`id`in e?u.get({key:e.id}):u.get(e),setIsCopied:i,setIsHovering:o,__internal_getRuntime:()=>e}}),fb=c_(({runtime:e,id:t,threadIdRef:n})=>O_(db({runtime:T_(()=>e.getMessageById(t),[e,t]),threadIdRef:n}))),pb=c_(({runtime:e})=>{let t=ib(e),n=kv();x_(()=>{let t=[];for(let r of[`runStart`,`runEnd`,`initialize`,`modelContextUpdate`]){let i=e.unstable_on(r,()=>{let t=e.getState()?.threadId||`unknown`;n(`thread.${r}`,{threadId:t})});t.push(i)}return()=>{for(let e of t)e()}},[e,n]);let r=T_(()=>({get current(){return e.getState().threadId}}),[e]),i=rv(cb({runtime:e.composer,threadIdRef:r})),a=Zv(()=>t.messages.map(t=>l_(t.id,fb({runtime:e,id:t.id,threadIdRef:r}))),[t.messages,e,r]),o=T_(()=>({isEmpty:a.state.length===0&&!t.isLoading,isDisabled:t.isDisabled,isLoading:t.isLoading,isRunning:t.isRunning,capabilities:t.capabilities,state:t.state,suggestions:t.suggestions,extras:t.extras,speech:t.speech,voice:t.voice,composer:i.state,messages:a.state}),[t,a,i.state]);return{getState:()=>o,composer:()=>i.methods,append:e.append,startRun:e.startRun,resumeRun:e.resumeRun,cancelRun:e.cancelRun,getModelContext:e.getModelContext,export:e.export,import:e.import,reset:e.reset,stopSpeaking:e.stopSpeaking,connectVoice:e.connectVoice,disconnectVoice:e.disconnectVoice,getVoiceVolume:e.getVoiceVolume,subscribeVoiceVolume:e.subscribeVoiceVolume,muteVoice:e.muteVoice,unmuteVoice:e.unmuteVoice,message:e=>`id`in e?a.get({key:e.id}):a.get(e),__internal_getRuntime:()=>e}}),mb=c_(({runtime:e})=>{let t=ib(e),n=kv();return x_(()=>{let t=[];for(let r of[`switchedTo`,`switchedAway`]){let i=e.unstable_on(r,()=>{n(`threadListItem.${r}`,{threadId:e.getState().id})});t.push(i)}return()=>{for(let e of t)e()}},[e,n]),{getState:()=>t,switchTo:e.switchTo,rename:e.rename,archive:e.archive,unarchive:e.unarchive,delete:e.delete,generateTitle:e.generateTitle,initialize:e.initialize,detach:e.detach,__internal_getRuntime:()=>e}}),hb=c_(({runtime:e,id:t})=>O_(mb({runtime:T_(()=>e.getItemById(t),[e,t])}))),gb=c_(({runtime:e,__internal_assistantRuntime:t})=>{let n=ib(e),r=rv(pb({runtime:e.main})),i=Zv(()=>Object.keys(n.threadItems).map(t=>l_(t,hb({runtime:e,id:t}))),[n.threadItems,e]),a=T_(()=>({mainThreadId:n.mainThreadId,newThreadId:n.newThreadId??null,isLoading:n.isLoading,isLoadingMore:n.isLoadingMore,hasMore:n.hasMore,threadIds:n.threadIds,archivedThreadIds:n.archivedThreadIds,threadItems:i.state,main:r.state}),[n,i.state,r.state]);return{getState:()=>a,thread:()=>r.methods,item:e=>{if(e===`main`)return i.get({key:a.mainThreadId});if(`id`in e)return i.get({key:e.id});let{index:t,archived:n=!1}=e,r=n?a.archivedThreadIds[t]:a.threadIds[t];return i.get({key:r})},switchToThread:async t=>{await e.switchToThread(t)},switchToNewThread:async()=>{await e.switchToNewThread()},getLoadThreadsPromise:()=>e.getLoadThreadsPromise(),reload:()=>e.reload(),loadMore:()=>e.loadMore(),__internal_getAssistantRuntime:()=>t}}),_b=c_(e=>{let t=Ov();return x_(()=>e.registerModelContextProvider(t.current.modelContext()),[e,t]),O_(gb({runtime:e.threads,__internal_assistantRuntime:e}))}),vb=(e,t)=>{e.thread??=gv({source:`threads`,query:{type:`main`},get:e=>e.threads().thread(`main`)}),e.threadListItem??=gv({source:`threads`,query:{type:`main`},get:e=>e.threads().item(`main`)}),e.composer??=gv({source:`thread`,query:{},get:e=>e.threads().thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=zy()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=Ny())},yb=({index:e,children:t})=>(0,q.jsx)(hv,{value:zv({message:gv({source:`thread`,query:{type:`index`,index:e},get:t=>t.thread().message({index:e})}),composer:gv({source:`message`,query:{},get:t=>t.thread().message({index:e}).composer()})}),children:t}),bb=({index:e,children:t})=>(0,q.jsx)(hv,{value:zv({part:gv({source:`message`,query:{type:`index`,index:e},get:t=>t.message().part({index:e})})}),children:t}),xb=c_(({text:e,isRunning:t})=>{let n=T_(()=>({type:`text`,text:e,status:t?{type:`running`}:{type:`complete`}}),[e,t]);return{getState:()=>n,addToolResult:()=>{throw Error(`Not supported`)},resumeToolCall:()=>{throw Error(`Not supported`)}}}),Sb=({text:e,isRunning:t=!1,children:n})=>(0,q.jsx)(hv,{value:zv({part:xb({text:e,isRunning:t})}),children:n}),Cb=({startIndex:e,endIndex:t,children:n})=>{let r=Q(e=>e.message.parts).slice(e,t+1),i=zv();return(0,q.jsx)(hv,{value:zv({chainOfThought:Fy({parts:r,getMessagePart:({index:t})=>{if(t<0||t>=r.length)throw Error(`ChainOfThought part index ${t} is out of bounds (0..${r.length-1})`);return i.message().part({index:e+t})}})}),children:n})},wb=Symbol(`skip-update`);function Tb(e,t){if(e===void 0&&t===void 0)return!0;if(e===void 0||t===void 0)return!1;for(let n of Object.keys(e)){let r=e[n],i=t[n];if(!Object.is(r,i))return!1}return!0}var Eb=class{_subscribers=new Set;subscribe(e){return this._subscribers.add(e),()=>this._subscribers.delete(e)}waitForUpdate(){return new Promise(e=>{let t=this.subscribe(()=>{t(),e()})})}_notifySubscribers(){let e=[];for(let t of this._subscribers)try{t()}catch(t){e.push(t)}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e)}}},Db=class{_subscriptions=new Set;_connection;get isConnected(){return!!this._connection}notifySubscribers(e){for(let t of this._subscriptions)t(e)}_updateConnection(){if(this._subscriptions.size>0){if(this._connection)return;this._connection=this._connect()}else this._connection?.(),this._connection=void 0}subscribe(e){return this._subscriptions.add(e),this._updateConnection(),()=>{this._subscriptions.delete(e),this._updateConnection()}}},Ob=class extends Db{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e;let t=e.getState();if(t===wb)throw Error(`Entry not available in the store`);this._previousState=t}_previousState;getState=()=>(this.isConnected||this._syncState(),this._previousState);_syncState(){let e=this.binding.getState();return e===wb||Tb(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){return this.binding.subscribe(()=>{this._syncState()&&this.notifySubscribers()})}},kb=class extends Db{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}_previousStateDirty=!0;_previousState;getState=()=>{if(!this.isConnected||this._previousStateDirty){let e=this.binding.getState();e!==wb&&(this._previousState=e),this._previousStateDirty=!1}if(this._previousState===void 0)throw Error(`Entry not available in the store`);return this._previousState};_connect(){return this.binding.subscribe(()=>{this._previousStateDirty=!0,this.notifySubscribers()})}},Ab=class extends Db{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}getState(){return this.binding.getState()}outerSubscribe(e){return this.binding.subscribe(e)}_connect(){let e=()=>{this.notifySubscribers()},t=this.binding.getState(),n=t?.subscribe(e),r=this.outerSubscribe(()=>{let r=this.binding.getState();r!==t&&(t=r,n?.(),n=r?.subscribe(e),e())});return()=>{r?.(),n?.()}}},jb=class extends Db{config;constructor(e){super(),this.config=e}getState(){return this.config.binding.getState()}outerSubscribe(e){return this.config.binding.subscribe(e)}_connect(){let e=e=>{this.notifySubscribers(e)},t=this.config.binding.getState(),n=t?.unstable_on(this.config.event,e),r=this.outerSubscribe(()=>{let r=this.config.binding.getState();r!==t&&(t=r,n?.(),n=r?.unstable_on(this.config.event,e))});return()=>{r?.(),n?.()}}},Mb=class{_contextProvider=new Ly;registerModelContextProvider(e){return this._contextProvider.registerModelContextProvider(e)}getModelContextProvider(){return this._contextProvider}},Nb=e=>e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
56
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return w.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},oc=`DialogDescriptionWarning`,sc=({contentRef:e,descriptionId:t})=>{let n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${ic(oc).contentName}}.`;return w.useEffect(()=>{let r=e.current?.getAttribute(`aria-describedby`);t&&r&&(document.getElementById(t)||console.warn(n))},[n,e,t]),null},cc=Ns,lc=zs,uc=Vs,dc=Gs,fc=Xs,pc=Qs,mc=ec;function hc(e){let[t,n]=w.useState(void 0);return ta(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}else n(void 0)},[e]),t}var gc=[`top`,`right`,`bottom`,`left`],_c=Math.min,vc=Math.max,yc=Math.round,bc=Math.floor,xc=e=>({x:e,y:e}),Sc={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Cc(e,t,n){return vc(e,_c(t,n))}function wc(e,t){return typeof e==`function`?e(t):e}function Tc(e){return e.split(`-`)[0]}function Ec(e){return e.split(`-`)[1]}function Dc(e){return e===`x`?`y`:`x`}function Oc(e){return e===`y`?`height`:`width`}function kc(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function Ac(e){return Dc(kc(e))}function jc(e,t,n){n===void 0&&(n=!1);let r=Ec(e),i=Ac(e),a=Oc(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Bc(o)),[o,Bc(o)]}function Mc(e){let t=Bc(e);return[Nc(e),t,Nc(t)]}function Nc(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var Pc=[`left`,`right`],Fc=[`right`,`left`],Ic=[`top`,`bottom`],Lc=[`bottom`,`top`];function Rc(e,t,n){switch(e){case`top`:case`bottom`:return n?t?Fc:Pc:t?Pc:Fc;case`left`:case`right`:return t?Ic:Lc;default:return[]}}function zc(e,t,n,r){let i=Ec(e),a=Rc(Tc(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Nc)))),a}function Bc(e){let t=Tc(e);return Sc[t]+e.slice(t.length)}function Vc(e){return{top:0,right:0,bottom:0,left:0,...e}}function Hc(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Vc(e)}function Uc(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function Wc(e,t,n){let{reference:r,floating:i}=e,a=kc(t),o=Ac(t),s=Oc(o),c=Tc(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch(Ec(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}async function Gc(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=wc(t,e),p=Hc(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Uc(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=Uc(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var Kc=50,qc=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Gc},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Wc(l,r,c),f=r,p=0,m={};for(let n=0;n<a.length;n++){let h=a[n];if(!h)continue;let{name:g,fn:_}=h,{x:v,y,data:b,reset:x}=await _({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:m,rects:l,platform:s,elements:{reference:e,floating:t}});u=v??u,d=y??d,m[g]={...m[g],...b},x&&p<Kc&&(p++,typeof x==`object`&&(x.placement&&(f=x.placement),x.rects&&(l=x.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):x.rects),{x:u,y:d}=Wc(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},Jc=e=>({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=wc(e,t)||{};if(l==null)return{};let d=Hc(u),f={x:n,y:r},p=Ac(i),m=Oc(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=_c(d[_],T),D=_c(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=Cc(O,A,k),M=!c.arrow&&Ec(i)!=null&&A!==j&&a.reference[m]/2-(A<O?E:D)-h[m]/2<0,N=M?A<O?A-O:A-k:0;return{[p]:f[p]+N,data:{[p]:j,centerOffset:A-j-N,...M&&{alignmentOffset:N}},reset:M}}}),Yc=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=wc(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=Tc(r),_=kc(o),v=Tc(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Bc(o)]:Mc(o)),x=p!==`none`;!d&&x&&b.push(...zc(o,m,p,y));let S=[o,...b],C=await s.detectOverflow(t,h),w=[],T=i.flip?.overflows||[];if(l&&w.push(C[g]),u){let e=jc(r,a,y);w.push(C[e[0]],C[e[1]])}if(T=[...T,{placement:r,overflows:w}],!w.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(!(u===`alignment`&&_!==kc(t))||T.every(e=>kc(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=kc(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}};function Xc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Zc(e){return gc.some(t=>e[t]>=0)}var Qc=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=wc(e,t);switch(i){case`referenceHidden`:{let e=Xc(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:Zc(e)}}}case`escaped`:{let e=Xc(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:Zc(e)}}}default:return{}}}}},$c=new Set([`left`,`top`]);async function el(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Tc(n),s=Ec(n),c=kc(n)===`y`,l=$c.has(o)?-1:1,u=a&&c?-1:1,d=wc(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var tl=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await el(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},nl=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=wc(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=kc(Tc(i)),p=Dc(f),m=u[p],h=u[f];if(o){let e=p===`y`?`top`:`left`,t=p===`y`?`bottom`:`right`,n=m+d[e],r=m-d[t];m=Cc(n,m,r)}if(s){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=h+d[e],r=h-d[t];h=Cc(n,h,r)}let g=c.fn({...t,[p]:m,[f]:h});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[p]:o,[f]:s}}}}}},rl=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=wc(e,t),u={x:n,y:r},d=kc(i),f=Dc(d),p=u[f],m=u[d],h=wc(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=$c.has(Tc(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}},il=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){var n,r;let{placement:i,rects:a,platform:o,elements:s}=t,{apply:c=()=>{},...l}=wc(e,t),u=await o.detectOverflow(t,l),d=Tc(i),f=Ec(i),p=kc(i)===`y`,{width:m,height:h}=a.floating,g,_;d===`top`||d===`bottom`?(g=d,_=f===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?`start`:`end`)?`left`:`right`):(_=d,g=f===`end`?`top`:`bottom`);let v=h-u.top-u.bottom,y=m-u.left-u.right,b=_c(h-u[g],v),x=_c(m-u[_],y),S=!t.middlewareData.shift,C=b,w=x;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(w=y),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(C=v),S&&!f){let e=vc(u.left,0),t=vc(u.right,0),n=vc(u.top,0),r=vc(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:vc(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:vc(u.top,u.bottom))}await c({...t,availableWidth:w,availableHeight:C});let T=await o.getDimensions(s.floating);return m!==T.width||h!==T.height?{reset:{rects:!0}}:{}}}};function al(){return typeof window<`u`}function ol(e){return ll(e)?(e.nodeName||``).toLowerCase():`#document`}function sl(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function cl(e){return((ll(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function ll(e){return al()?e instanceof Node||e instanceof sl(e).Node:!1}function ul(e){return al()?e instanceof Element||e instanceof sl(e).Element:!1}function dl(e){return al()?e instanceof HTMLElement||e instanceof sl(e).HTMLElement:!1}function fl(e){return!al()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof sl(e).ShadowRoot}function pl(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=wl(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function ml(e){return/^(table|td|th)$/.test(ol(e))}function hl(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var gl=/transform|translate|scale|rotate|perspective|filter/,_l=/paint|layout|strict|content/,vl=e=>!!e&&e!==`none`,yl;function bl(e){let t=ul(e)?wl(e):e;return vl(t.transform)||vl(t.translate)||vl(t.scale)||vl(t.rotate)||vl(t.perspective)||!Sl()&&(vl(t.backdropFilter)||vl(t.filter))||gl.test(t.willChange||``)||_l.test(t.contain||``)}function xl(e){let t=El(e);for(;dl(t)&&!Cl(t);){if(bl(t))return t;if(hl(t))return null;t=El(t)}return null}function Sl(){return yl??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),yl}function Cl(e){return/^(html|body|#document)$/.test(ol(e))}function wl(e){return sl(e).getComputedStyle(e)}function Tl(e){return ul(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function El(e){if(ol(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||fl(e)&&e.host||cl(e);return fl(t)?t.host:t}function Dl(e){let t=El(e);return Cl(t)?e.ownerDocument?e.ownerDocument.body:e.body:dl(t)&&pl(t)?t:Dl(t)}function Ol(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Dl(e),i=r===e.ownerDocument?.body,a=sl(r);if(i){let e=kl(a);return t.concat(a,a.visualViewport||[],pl(r)?r:[],e&&n?Ol(e):[])}else return t.concat(r,Ol(r,[],n))}function kl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Al(e){let t=wl(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=dl(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=yc(n)!==a||yc(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function jl(e){return ul(e)?e:e.contextElement}function Ml(e){let t=jl(e);if(!dl(t))return xc(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Al(t),o=(a?yc(n.width):n.width)/r,s=(a?yc(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var Nl=xc(0);function Pl(e){let t=sl(e);return!Sl()||!t.visualViewport?Nl:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Fl(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==sl(e)?!1:t}function Il(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=jl(e),o=xc(1);t&&(r?ul(r)&&(o=Ml(r)):o=Ml(e));let s=Fl(a,n,r)?Pl(a):xc(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=sl(a),t=r&&ul(r)?sl(r):r,n=e,i=kl(n);for(;i&&r&&t!==n;){let e=Ml(i),t=i.getBoundingClientRect(),r=wl(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=sl(i),i=kl(n)}}return Uc({width:u,height:d,x:c,y:l})}function Ll(e,t){let n=Tl(e).scrollLeft;return t?t.left+n:Il(cl(e)).left+n}function Rl(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Ll(e,n),y:n.top+t.scrollTop}}function zl(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=cl(r),s=t?hl(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=xc(1),u=xc(0),d=dl(r);if((d||!d&&!a)&&((ol(r)!==`body`||pl(o))&&(c=Tl(r)),d)){let e=Il(r);l=Ml(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?Rl(o,c):xc(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function Bl(e){return Array.from(e.getClientRects())}function Vl(e){let t=cl(e),n=Tl(e),r=e.ownerDocument.body,i=vc(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=vc(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+Ll(e),s=-n.scrollTop;return wl(r).direction===`rtl`&&(o+=vc(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var Hl=25;function Ul(e,t){let n=sl(e),r=cl(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=Sl();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=Ll(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=Hl&&(a-=o)}else l<=Hl&&(a+=l);return{width:a,height:o,x:s,y:c}}function Wl(e,t){let n=Il(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=dl(e)?Ml(e):xc(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Gl(e,t,n){let r;if(t===`viewport`)r=Ul(e,n);else if(t===`document`)r=Vl(cl(e));else if(ul(t))r=Wl(t,n);else{let n=Pl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Uc(r)}function Kl(e,t){let n=El(e);return n===t||!ul(n)||Cl(n)?!1:wl(n).position===`fixed`||Kl(n,t)}function ql(e,t){let n=t.get(e);if(n)return n;let r=Ol(e,[],!1).filter(e=>ul(e)&&ol(e)!==`body`),i=null,a=wl(e).position===`fixed`,o=a?El(e):e;for(;ul(o)&&!Cl(o);){let t=wl(o),n=bl(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||pl(o)&&!n&&Kl(e,o))?r=r.filter(e=>e!==o):i=t,o=El(o)}return t.set(e,r),r}function Jl(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?hl(t)?[]:ql(t,this._c):[].concat(n),r],o=Gl(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e<a.length;e++){let n=Gl(t,a[e],i);s=vc(n.top,s),c=_c(n.right,c),l=_c(n.bottom,l),u=vc(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Yl(e){let{width:t,height:n}=Al(e);return{width:t,height:n}}function Xl(e,t,n){let r=dl(t),i=cl(t),a=n===`fixed`,o=Il(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=xc(0);function l(){c.x=Ll(i)}if(r||!r&&!a)if((ol(t)!==`body`||pl(i))&&(s=Tl(t)),r){let e=Il(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?Rl(i,s):xc(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function Zl(e){return wl(e).position===`static`}function Ql(e,t){if(!dl(e)||wl(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return cl(e)===n&&(n=n.ownerDocument.body),n}function $l(e,t){let n=sl(e);if(hl(e))return n;if(!dl(e)){let t=El(e);for(;t&&!Cl(t);){if(ul(t)&&!Zl(t))return t;t=El(t)}return n}let r=Ql(e,t);for(;r&&ml(r)&&Zl(r);)r=Ql(r,t);return r&&Cl(r)&&Zl(r)&&!bl(r)?n:r||xl(e)||n}var eu=async function(e){let t=this.getOffsetParent||$l,n=this.getDimensions,r=await n(e.floating);return{reference:Xl(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function tu(e){return wl(e).direction===`rtl`}var nu={convertOffsetParentRelativeRectToViewportRelativeRect:zl,getDocumentElement:cl,getClippingRect:Jl,getOffsetParent:$l,getElementRects:eu,getClientRects:Bl,getDimensions:Yl,getScale:Ml,isElement:ul,isRTL:tu};function ru(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function iu(e,t){let n=null,r,i=cl(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=bc(d),h=bc(i.clientWidth-(u+f)),g=bc(i.clientHeight-(d+p)),_=bc(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:vc(0,_c(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!ru(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function au(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=jl(e),u=i||a?[...l?Ol(l):[],...t?Ol(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?iu(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?Il(e):null;c&&g();function g(){let t=Il(e);h&&!ru(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var ou=tl,su=nl,cu=Yc,lu=il,uu=Qc,du=Jc,fu=rl,pu=(e,t,n)=>{let r=new Map,i={platform:nu,...n},a={...i.platform,_c:r};return qc(e,t,{...i,platform:a})},mu=typeof document<`u`?w.useLayoutEffect:function(){};function hu(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!hu(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!hu(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function gu(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function _u(e,t){let n=gu(e);return Math.round(t*n)/n}function vu(e){let t=w.useRef(e);return mu(()=>{t.current=e}),t}function yu(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=w.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=w.useState(r);hu(f,r)||p(r);let[m,h]=w.useState(null),[g,_]=w.useState(null),v=w.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=w.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=w.useRef(null),C=w.useRef(null),T=w.useRef(u),E=c!=null,D=vu(c),O=vu(i),k=vu(l),A=w.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),pu(S.current,C.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!hu(T.current,t)&&(T.current=t,_t.flushSync(()=>{d(t)}))})},[f,t,n,O,k]);mu(()=>{l===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let j=w.useRef(!1);mu(()=>(j.current=!0,()=>{j.current=!1}),[]),mu(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(D.current)return D.current(b,x,A);A()}},[b,x,A,D,E]);let M=w.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),N=w.useMemo(()=>({reference:b,floating:x}),[b,x]),P=w.useMemo(()=>{let e={position:n,left:0,top:0};if(!N.floating)return e;let t=_u(N.floating,u.x),r=_u(N.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...gu(N.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,N.floating,u.x,u.y]);return w.useMemo(()=>({...u,update:A,refs:M,elements:N,floatingStyles:P}),[u,A,M,N,P])}var bu=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:du({element:r.current,padding:i}).fn(n):r?du({element:r,padding:i}).fn(n):{}}}},xu=(e,t)=>{let n=ou(e);return{name:n.name,fn:n.fn,options:[e,t]}},Su=(e,t)=>{let n=su(e);return{name:n.name,fn:n.fn,options:[e,t]}},Cu=(e,t)=>({fn:fu(e).fn,options:[e,t]}),wu=(e,t)=>{let n=cu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Tu=(e,t)=>{let n=lu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eu=(e,t)=>{let n=uu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Du=(e,t)=>{let n=bu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ou=`Arrow`,ku=w.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,q.jsx)(Gi.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,q.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})});ku.displayName=Ou;var Au=ku,ju=`Popper`,[Mu,Nu]=Qi(ju),[Pu,Fu]=Mu(ju),Iu=e=>{let{__scopePopper:t,children:n}=e,[r,i]=w.useState(null);return(0,q.jsx)(Pu,{scope:t,anchor:r,onAnchorChange:i,children:n})};Iu.displayName=ju;var Lu=`PopperAnchor`,Ru=w.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=Fu(Lu,n),o=w.useRef(null),s=Ii(t,o),c=w.useRef(null);return w.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,q.jsx)(Gi.div,{...i,ref:s})});Ru.displayName=Lu;var zu=`PopperContent`,[Bu,Vu]=Mu(zu),Hu=w.forwardRef((e,t)=>{let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=Fu(zu,n),[_,v]=w.useState(null),y=Ii(t,e=>v(e)),[b,x]=w.useState(null),S=hc(b),C=S?.width??0,T=S?.height??0,E=r+(a===`center`?``:`-`+a),D=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},O=Array.isArray(l)?l:[l],k=O.length>0,A={padding:D,boundary:O.filter(Ku),altBoundary:k},{refs:j,floatingStyles:M,placement:N,isPositioned:P,middlewareData:F}=yu({strategy:`fixed`,placement:E,whileElementsMounted:(...e)=>au(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[xu({mainAxis:i+T,alignmentAxis:o}),c&&Su({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Cu():void 0,...A}),c&&wu({...A}),Tu({...A,apply:({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)}}),b&&Du({element:b,padding:s}),qu({arrowWidth:C,arrowHeight:T}),f&&Eu({strategy:`referenceHidden`,...A})]}),[I,L]=Ju(N),R=Da(m);ta(()=>{P&&R?.()},[P,R]);let z=F.arrow?.x,B=F.arrow?.y,V=F.arrow?.centerOffset!==0,[H,U]=w.useState();return ta(()=>{_&&U(window.getComputedStyle(_).zIndex)},[_]),(0,q.jsx)(`div`,{ref:j.setFloating,"data-radix-popper-content-wrapper":``,style:{...M,transform:P?M.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:H,"--radix-popper-transform-origin":[F.transformOrigin?.x,F.transformOrigin?.y].join(` `),...F.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,q.jsx)(Bu,{scope:n,placedSide:I,onArrowChange:x,arrowX:z,arrowY:B,shouldHideArrow:V,children:(0,q.jsx)(Gi.div,{"data-side":I,"data-align":L,...h,ref:y,style:{...h.style,animation:P?void 0:`none`}})})})});Hu.displayName=zu;var Uu=`PopperArrow`,Wu={top:`bottom`,right:`left`,bottom:`top`,left:`right`},Gu=w.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=Vu(Uu,n),a=Wu[i.placedSide];return(0,q.jsx)(`span`,{ref:i.onArrowChange,style:{position:`absolute`,left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:``,right:`0 0`,bottom:`center 0`,left:`100% 0`}[i.placedSide],transform:{top:`translateY(100%)`,right:`translateY(50%) rotate(90deg) translateX(-50%)`,bottom:`rotate(180deg)`,left:`translateY(50%) rotate(-90deg) translateX(50%)`}[i.placedSide],visibility:i.shouldHideArrow?`hidden`:void 0},children:(0,q.jsx)(Au,{...r,ref:t,style:{...r.style,display:`block`}})})});Gu.displayName=Uu;function Ku(e){return e!==null}var qu=e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=Ju(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}});function Ju(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var Yu=Iu,Xu=Ru,Zu=Hu,Qu=Gu,$u=`Popover`,[ed,td]=Qi($u,[Nu]),nd=Nu(),[rd,id]=ed($u),ad=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=nd(t),c=w.useRef(null),[l,u]=w.useState(!1),[d,f]=ra({prop:r,defaultProp:i??!1,onChange:a,caller:$u});return(0,q.jsx)(Yu,{...s,children:(0,q.jsx)(rd,{scope:t,contentId:pa(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:w.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:w.useCallback(()=>u(!0),[]),onCustomAnchorRemove:w.useCallback(()=>u(!1),[]),modal:o,children:n})})};ad.displayName=$u;var od=`PopoverAnchor`,sd=w.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=id(od,n),a=nd(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return w.useEffect(()=>(o(),()=>s()),[o,s]),(0,q.jsx)(Xu,{...a,...r,ref:t})});sd.displayName=od;var cd=`PopoverTrigger`,ld=w.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=id(cd,n),a=nd(n),o=Ii(t,i.triggerRef),s=(0,q.jsx)(Gi.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":wd(i.open),...r,ref:o,onClick:ea(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,q.jsx)(Xu,{asChild:!0,...a,children:s})});ld.displayName=cd;var ud=`PopoverPortal`,[dd,fd]=ed(ud,{forceMount:void 0}),pd=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=id(ud,t);return(0,q.jsx)(dd,{scope:t,forceMount:n,children:(0,q.jsx)(sa,{present:n||a.open,children:(0,q.jsx)(ao,{asChild:!0,container:i,children:r})})})};pd.displayName=ud;var md=`PopoverContent`,hd=w.forwardRef((e,t)=>{let n=fd(md,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=id(md,e.__scopePopover);return(0,q.jsx)(sa,{present:r||a.open,children:a.modal?(0,q.jsx)(_d,{...i,ref:t}):(0,q.jsx)(vd,{...i,ref:t})})});hd.displayName=md;var gd=Li(`PopoverContent.RemoveScroll`),_d=w.forwardRef((e,t)=>{let n=id(md,e.__scopePopover),r=w.useRef(null),i=Ii(t,r),a=w.useRef(!1);return w.useEffect(()=>{let e=r.current;if(e)return Ds(e)},[]),(0,q.jsx)(vs,{as:gd,allowPinchZoom:!0,children:(0,q.jsx)(yd,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ea(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:ea(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:ea(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),vd=w.forwardRef((e,t)=>{let n=id(md,e.__scopePopover),r=w.useRef(!1),i=w.useRef(!1);return(0,q.jsx)(yd,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})}),yd=w.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,disableOutsidePointerEvents:o,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=id(md,n),p=nd(n);return so(),(0,q.jsx)(Ka,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,q.jsx)(Fa,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,q.jsx)(Zu,{"data-state":wd(f.open),role:`dialog`,id:f.contentId,...p,...d,ref:t,style:{...d.style,"--radix-popover-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-popover-content-available-width":`var(--radix-popper-available-width)`,"--radix-popover-content-available-height":`var(--radix-popper-available-height)`,"--radix-popover-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-popover-trigger-height":`var(--radix-popper-anchor-height)`}})})})}),bd=`PopoverClose`,xd=w.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=id(bd,n);return(0,q.jsx)(Gi.button,{type:`button`,...r,ref:t,onClick:ea(e.onClick,()=>i.onOpenChange(!1))})});xd.displayName=bd;var Sd=`PopoverArrow`,Cd=w.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=nd(n);return(0,q.jsx)(Qu,{...i,...r,ref:t})});Cd.displayName=Sd;function wd(e){return e?`open`:`closed`}var Td=ad,Ed=ld,Dd=pd,Od=hd,kd=xd,[Ad,jd]=Qi(`Tooltip`,[Nu]),Md=Nu(),Nd=`TooltipProvider`,Pd=700,Fd=`tooltip.open`,[Id,Ld]=Ad(Nd),Rd=e=>{let{__scopeTooltip:t,delayDuration:n=Pd,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=w.useRef(!0),s=w.useRef(!1),c=w.useRef(0);return w.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,q.jsx)(Id,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:w.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:w.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:w.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};Rd.displayName=Nd;var zd=`Tooltip`,[Bd,Vd]=Ad(zd),Hd=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Ld(zd,e.__scopeTooltip),l=Md(t),[u,d]=w.useState(null),f=pa(),p=w.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=w.useRef(!1),[_,v]=ra({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(Fd))):c.onClose(),a?.(e)},caller:zd}),y=w.useMemo(()=>_?g.current?`delayed-open`:`instant-open`:`closed`,[_]),b=w.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,v(!0)},[v]),x=w.useCallback(()=>{window.clearTimeout(p.current),p.current=0,v(!1)},[v]),S=w.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,v(!0),p.current=0},h)},[h,v]);return w.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,q.jsx)(Yu,{...l,children:(0,q.jsx)(Bd,{scope:t,contentId:f,open:_,stateAttribute:y,trigger:u,onTriggerChange:d,onTriggerEnter:w.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:w.useCallback(()=>{m?x():(window.clearTimeout(p.current),p.current=0)},[x,m]),onOpen:b,onClose:x,disableHoverableContent:m,children:n})})};Hd.displayName=zd;var Ud=`TooltipTrigger`,Wd=w.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Vd(Ud,n),a=Ld(Ud,n),o=Md(n),s=Ii(t,w.useRef(null),i.onTriggerChange),c=w.useRef(!1),l=w.useRef(!1),u=w.useCallback(()=>c.current=!1,[]);return w.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,q.jsx)(Xu,{asChild:!0,...o,children:(0,q.jsx)(Gi.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:ea(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:ea(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:ea(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:ea(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:ea(e.onBlur,i.onClose),onClick:ea(e.onClick,i.onClose)})})});Wd.displayName=Ud;var Gd=`TooltipPortal`,[Kd,qd]=Ad(Gd,{forceMount:void 0}),Jd=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=Vd(Gd,t);return(0,q.jsx)(Kd,{scope:t,forceMount:n,children:(0,q.jsx)(sa,{present:n||a.open,children:(0,q.jsx)(ao,{asChild:!0,container:i,children:r})})})};Jd.displayName=Gd;var Yd=`TooltipContent`,Xd=w.forwardRef((e,t)=>{let n=qd(Yd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=Vd(Yd,e.__scopeTooltip);return(0,q.jsx)(sa,{present:r||o.open,children:o.disableHoverableContent?(0,q.jsx)(tf,{side:i,...a,ref:t}):(0,q.jsx)(Zd,{side:i,...a,ref:t})})}),Zd=w.forwardRef((e,t)=>{let n=Vd(Yd,e.__scopeTooltip),r=Ld(Yd,e.__scopeTooltip),i=w.useRef(null),a=Ii(t,i),[o,s]=w.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=w.useCallback(()=>{s(null),d(!1)},[d]),p=w.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=of(r,af(r,n.getBoundingClientRect())),a=sf(t.getBoundingClientRect());s(lf([...i,...a])),d(!0)},[d]);return w.useEffect(()=>()=>f(),[f]),w.useEffect(()=>{if(c&&u){let e=e=>p(e,u),t=e=>p(e,c);return c.addEventListener(`pointerleave`,e),u.addEventListener(`pointerleave`,t),()=>{c.removeEventListener(`pointerleave`,e),u.removeEventListener(`pointerleave`,t)}}},[c,u,p,f]),w.useEffect(()=>{if(o){let e=e=>{let t=e.target,n={x:e.clientX,y:e.clientY},r=c?.contains(t)||u?.contains(t),i=!cf(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,q.jsx)(tf,{...e,ref:a})}),[Qd,$d]=Ad(zd,{isInside:!1}),ef=Vi(`TooltipContent`),tf=w.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=Vd(Yd,n),l=Md(n),{onClose:u}=c;return w.useEffect(()=>(document.addEventListener(Fd,u),()=>document.removeEventListener(Fd,u)),[u]),w.useEffect(()=>{if(c.trigger){let e=e=>{e.target?.contains(c.trigger)&&u()};return window.addEventListener(`scroll`,e,{capture:!0}),()=>window.removeEventListener(`scroll`,e,{capture:!0})}},[c.trigger,u]),(0,q.jsx)(Fa,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,q.jsxs)(Zu,{"data-state":c.stateAttribute,...l,...s,ref:t,style:{...s.style,"--radix-tooltip-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-tooltip-content-available-width":`var(--radix-popper-available-width)`,"--radix-tooltip-content-available-height":`var(--radix-popper-available-height)`,"--radix-tooltip-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-tooltip-trigger-height":`var(--radix-popper-anchor-height)`},children:[(0,q.jsx)(ef,{children:r}),(0,q.jsx)(Qd,{scope:n,isInside:!0,children:(0,q.jsx)(Xi,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});Xd.displayName=Yd;var nf=`TooltipArrow`,rf=w.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Md(n);return $d(nf,n).isInside?null:(0,q.jsx)(Qu,{...i,...r,ref:t})});rf.displayName=nf;function af(e,t){let n=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(n,r,i,a)){case a:return`left`;case i:return`right`;case n:return`top`;case r:return`bottom`;default:throw Error(`unreachable`)}}function of(e,t,n=5){let r=[];switch(t){case`top`:r.push({x:e.x-n,y:e.y+n},{x:e.x+n,y:e.y+n});break;case`bottom`:r.push({x:e.x-n,y:e.y-n},{x:e.x+n,y:e.y-n});break;case`left`:r.push({x:e.x+n,y:e.y-n},{x:e.x+n,y:e.y+n});break;case`right`:r.push({x:e.x-n,y:e.y-n},{x:e.x-n,y:e.y+n});break}return r}function sf(e){let{top:t,right:n,bottom:r,left:i}=e;return[{x:i,y:t},{x:n,y:t},{x:n,y:r},{x:i,y:r}]}function cf(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;e<t.length;a=e++){let o=t[e],s=t[a],c=o.x,l=o.y,u=s.x,d=s.y;l>r!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}function lf(e){let t=e.slice();return t.sort((e,t)=>e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:+(e.y>t.y)),uf(t)}function uf(e){if(e.length<=1)return e.slice();let t=[];for(let n=0;n<e.length;n++){let r=e[n];for(;t.length>=2;){let e=t[t.length-1],n=t[t.length-2];if((e.x-n.x)*(r.y-n.y)>=(e.y-n.y)*(r.x-n.x))t.pop();else break}t.push(r)}t.pop();let n=[];for(let t=e.length-1;t>=0;t--){let r=e[t];for(;n.length>=2;){let e=n[n.length-1],t=n[n.length-2];if((e.x-t.x)*(r.y-t.y)>=(e.y-t.y)*(r.x-t.x))n.pop();else break}n.push(r)}return n.pop(),t.length===1&&n.length===1&&t[0].x===n[0].x&&t[0].y===n[0].y?t:t.concat(n)}var df=Rd,ff=Hd,pf=Wd,mf=Jd,hf=Xd,gf=rf;function _f(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=_f(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function vf(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=_f(e))&&(r&&(r+=` `),r+=t);return r}var yf=(e,t)=>{let n=Array(e.length+t.length);for(let t=0;t<e.length;t++)n[t]=e[t];for(let r=0;r<t.length;r++)n[e.length+r]=t[r];return n},bf=(e,t)=>({classGroupId:e,validator:t}),xf=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),Sf=`-`,Cf=[],wf=`arbitrary..`,Tf=e=>{let t=Of(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:e=>{if(e.startsWith(`[`)&&e.endsWith(`]`))return Df(e);let n=e.split(Sf);return Ef(n,+(n[0]===``&&n.length>1),t)},getConflictingClassGroupIds:(e,t)=>{if(t){let t=r[e],i=n[e];return t?i?yf(i,t):t:i||Cf}return n[e]||Cf}}},Ef=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;let r=e[t],i=n.nextPart.get(r);if(i){let n=Ef(e,t+1,i);if(n)return n}let a=n.validators;if(a===null)return;let o=t===0?e.join(Sf):e.slice(t).join(Sf),s=a.length;for(let e=0;e<s;e++){let t=a[e];if(t.validator(o))return t.classGroupId}},Df=e=>e.slice(1,-1).indexOf(`:`)===-1?void 0:(()=>{let t=e.slice(1,-1),n=t.indexOf(`:`),r=t.slice(0,n);return r?wf+r:void 0})(),Of=e=>{let{theme:t,classGroups:n}=e;return kf(n,t)},kf=(e,t)=>{let n=xf();for(let r in e){let i=e[r];Af(i,n,r,t)}return n},Af=(e,t,n,r)=>{let i=e.length;for(let a=0;a<i;a++){let i=e[a];jf(i,t,n,r)}},jf=(e,t,n,r)=>{if(typeof e==`string`){Mf(e,t,n);return}if(typeof e==`function`){Nf(e,t,n,r);return}Pf(e,t,n,r)},Mf=(e,t,n)=>{let r=e===``?t:Ff(t,e);r.classGroupId=n},Nf=(e,t,n,r)=>{if(If(e)){Af(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(bf(n,e))},Pf=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e<a;e++){let[a,o]=i[e];Af(o,Ff(t,a),n,r)}},Ff=(e,t)=>{let n=e,r=t.split(Sf),i=r.length;for(let e=0;e<i;e++){let t=r[e],i=n.nextPart.get(t);i||(i=xf(),n.nextPart.set(t,i)),n=i}return n},If=e=>`isThemeGetter`in e&&e.isThemeGetter===!0,Lf=e=>{if(e<1)return{get:()=>void 0,set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null),i=(i,a)=>{n[i]=a,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(e){let t=n[e];if(t!==void 0)return t;if((t=r[e])!==void 0)return i(e,t),t},set(e,t){e in n?n[e]=t:i(e,t)}}},Rf=`!`,zf=`:`,Bf=[],Vf=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),Hf=e=>{let{prefix:t,experimentalParseClassName:n}=e,r=e=>{let t=[],n=0,r=0,i=0,a,o=e.length;for(let s=0;s<o;s++){let o=e[s];if(n===0&&r===0){if(o===zf){t.push(e.slice(i,s)),i=s+1;continue}if(o===`/`){a=s;continue}}o===`[`?n++:o===`]`?n--:o===`(`?r++:o===`)`&&r--}let s=t.length===0?e:e.slice(i),c=s,l=!1;s.endsWith(Rf)?(c=s.slice(0,-1),l=!0):s.startsWith(Rf)&&(c=s.slice(1),l=!0);let u=a&&a>i?a-i:void 0;return Vf(t,l,c,u)};if(t){let e=t+zf,n=r;r=t=>t.startsWith(e)?n(t.slice(e.length)):Vf(Bf,!1,t,void 0,!0)}if(n){let e=r;r=t=>n({className:t,parseClassName:e})}return r},Uf=e=>{let t=new Map;return e.orderSensitiveModifiers.forEach((e,n)=>{t.set(e,1e6+n)}),e=>{let n=[],r=[];for(let i=0;i<e.length;i++){let a=e[i],o=a[0]===`[`,s=t.has(a);o||s?(r.length>0&&(r.sort(),n.push(...r),r=[]),n.push(a)):r.push(a)}return r.length>0&&(r.sort(),n.push(...r)),n}},Wf=e=>({cache:Lf(e.cacheSize),parseClassName:Hf(e),sortModifiers:Uf(e),...Tf(e)}),Gf=/\s+/,Kf=(e,t)=>{let{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:a}=t,o=[],s=e.trim().split(Gf),c=``;for(let e=s.length-1;e>=0;--e){let t=s[e],{isExternal:l,modifiers:u,hasImportantModifier:d,baseClassName:f,maybePostfixModifierPosition:p}=n(t);if(l){c=t+(c.length>0?` `+c:c);continue}let m=!!p,h=r(m?f.substring(0,p):f);if(!h){if(!m){c=t+(c.length>0?` `+c:c);continue}if(h=r(f),!h){c=t+(c.length>0?` `+c:c);continue}m=!1}let g=u.length===0?``:u.length===1?u[0]:a(u).join(`:`),_=d?g+Rf:g,v=_+h;if(o.indexOf(v)>-1)continue;o.push(v);let y=i(h,m);for(let e=0;e<y.length;++e){let t=y[e];o.push(_+t)}c=t+(c.length>0?` `+c:c)}return c},qf=(...e)=>{let t=0,n,r,i=``;for(;t<e.length;)(n=e[t++])&&(r=Jf(n))&&(i&&(i+=` `),i+=r);return i},Jf=e=>{if(typeof e==`string`)return e;let t,n=``;for(let r=0;r<e.length;r++)e[r]&&(t=Jf(e[r]))&&(n&&(n+=` `),n+=t);return n},Yf=(e,...t)=>{let n,r,i,a,o=o=>(n=Wf(t.reduce((e,t)=>t(e),e())),r=n.cache.get,i=n.cache.set,a=s,s(o)),s=e=>{let t=r(e);if(t)return t;let a=Kf(e,n);return i(e,a),a};return a=o,(...e)=>a(qf(...e))},Xf=[],Zf=e=>{let t=t=>t[e]||Xf;return t.isThemeGetter=!0,t},Qf=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,$f=/^\((?:(\w[\w-]*):)?(.+)\)$/i,ep=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,tp=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,np=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,rp=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,ip=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,ap=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,op=e=>ep.test(e),sp=e=>!!e&&!Number.isNaN(Number(e)),cp=e=>!!e&&Number.isInteger(Number(e)),lp=e=>e.endsWith(`%`)&&sp(e.slice(0,-1)),up=e=>tp.test(e),dp=()=>!0,fp=e=>np.test(e)&&!rp.test(e),pp=()=>!1,mp=e=>ip.test(e),hp=e=>ap.test(e),gp=e=>!J(e)&&!Y(e),_p=e=>Mp(e,Ip,pp),J=e=>Qf.test(e),vp=e=>Mp(e,Lp,fp),yp=e=>Mp(e,Rp,sp),bp=e=>Mp(e,Bp,dp),xp=e=>Mp(e,zp,pp),Sp=e=>Mp(e,Pp,pp),Cp=e=>Mp(e,Fp,hp),wp=e=>Mp(e,Vp,mp),Y=e=>$f.test(e),Tp=e=>Np(e,Lp),Ep=e=>Np(e,zp),Dp=e=>Np(e,Pp),Op=e=>Np(e,Ip),kp=e=>Np(e,Fp),Ap=e=>Np(e,Vp,!0),jp=e=>Np(e,Bp,!0),Mp=(e,t,n)=>{let r=Qf.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},Np=(e,t,n=!1)=>{let r=$f.exec(e);return r?r[1]?t(r[1]):n:!1},Pp=e=>e===`position`||e===`percentage`,Fp=e=>e===`image`||e===`url`,Ip=e=>e===`length`||e===`size`||e===`bg-size`,Lp=e=>e===`length`,Rp=e=>e===`number`,zp=e=>e===`family-name`,Bp=e=>e===`number`||e===`weight`,Vp=e=>e===`shadow`,Hp=Yf(()=>{let e=Zf(`color`),t=Zf(`font`),n=Zf(`text`),r=Zf(`font-weight`),i=Zf(`tracking`),a=Zf(`leading`),o=Zf(`breakpoint`),s=Zf(`container`),c=Zf(`spacing`),l=Zf(`radius`),u=Zf(`shadow`),d=Zf(`inset-shadow`),f=Zf(`text-shadow`),p=Zf(`drop-shadow`),m=Zf(`blur`),h=Zf(`perspective`),g=Zf(`aspect`),_=Zf(`ease`),v=Zf(`animate`),y=()=>[`auto`,`avoid`,`all`,`avoid-page`,`page`,`left`,`right`,`column`],b=()=>[`center`,`top`,`bottom`,`left`,`right`,`top-left`,`left-top`,`top-right`,`right-top`,`bottom-right`,`right-bottom`,`bottom-left`,`left-bottom`],x=()=>[...b(),Y,J],S=()=>[`auto`,`hidden`,`clip`,`visible`,`scroll`],C=()=>[`auto`,`contain`,`none`],w=()=>[Y,J,c],T=()=>[op,`full`,`auto`,...w()],E=()=>[cp,`none`,`subgrid`,Y,J],D=()=>[`auto`,{span:[`full`,cp,Y,J]},cp,Y,J],O=()=>[cp,`auto`,Y,J],k=()=>[`auto`,`min`,`max`,`fr`,Y,J],A=()=>[`start`,`end`,`center`,`between`,`around`,`evenly`,`stretch`,`baseline`,`center-safe`,`end-safe`],j=()=>[`start`,`end`,`center`,`stretch`,`center-safe`,`end-safe`],M=()=>[`auto`,...w()],N=()=>[op,`auto`,`full`,`dvw`,`dvh`,`lvw`,`lvh`,`svw`,`svh`,`min`,`max`,`fit`,...w()],P=()=>[op,`screen`,`full`,`dvw`,`lvw`,`svw`,`min`,`max`,`fit`,...w()],F=()=>[op,`screen`,`full`,`lh`,`dvh`,`lvh`,`svh`,`min`,`max`,`fit`,...w()],I=()=>[e,Y,J],L=()=>[...b(),Dp,Sp,{position:[Y,J]}],R=()=>[`no-repeat`,{repeat:[``,`x`,`y`,`space`,`round`]}],z=()=>[`auto`,`cover`,`contain`,Op,_p,{size:[Y,J]}],B=()=>[lp,Tp,vp],V=()=>[``,`none`,`full`,l,Y,J],H=()=>[``,sp,Tp,vp],U=()=>[`solid`,`dashed`,`dotted`,`double`],W=()=>[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],G=()=>[sp,lp,Dp,Sp],ee=()=>[``,`none`,m,Y,J],K=()=>[`none`,sp,Y,J],te=()=>[`none`,sp,Y,J],ne=()=>[sp,Y,J],re=()=>[op,`full`,...w()];return{cacheSize:500,theme:{animate:[`spin`,`ping`,`pulse`,`bounce`],aspect:[`video`],blur:[up],breakpoint:[up],color:[dp],container:[up],"drop-shadow":[up],ease:[`in`,`out`,`in-out`],font:[gp],"font-weight":[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`],"inset-shadow":[up],leading:[`none`,`tight`,`snug`,`normal`,`relaxed`,`loose`],perspective:[`dramatic`,`near`,`normal`,`midrange`,`distant`,`none`],radius:[up],shadow:[up],spacing:[`px`,sp],text:[up],"text-shadow":[up],tracking:[`tighter`,`tight`,`normal`,`wide`,`wider`,`widest`]},classGroups:{aspect:[{aspect:[`auto`,`square`,op,J,Y,g]}],container:[`container`],columns:[{columns:[sp,J,Y,s]}],"break-after":[{"break-after":y()}],"break-before":[{"break-before":y()}],"break-inside":[{"break-inside":[`auto`,`avoid`,`avoid-page`,`avoid-column`]}],"box-decoration":[{"box-decoration":[`slice`,`clone`]}],box:[{box:[`border`,`content`]}],display:[`block`,`inline-block`,`inline`,`flex`,`inline-flex`,`table`,`inline-table`,`table-caption`,`table-cell`,`table-column`,`table-column-group`,`table-footer-group`,`table-header-group`,`table-row-group`,`table-row`,`flow-root`,`grid`,`inline-grid`,`contents`,`list-item`,`hidden`],sr:[`sr-only`,`not-sr-only`],float:[{float:[`right`,`left`,`none`,`start`,`end`]}],clear:[{clear:[`left`,`right`,`both`,`none`,`start`,`end`]}],isolation:[`isolate`,`isolation-auto`],"object-fit":[{object:[`contain`,`cover`,`fill`,`none`,`scale-down`]}],"object-position":[{object:x()}],overflow:[{overflow:S()}],"overflow-x":[{"overflow-x":S()}],"overflow-y":[{"overflow-y":S()}],overscroll:[{overscroll:C()}],"overscroll-x":[{"overscroll-x":C()}],"overscroll-y":[{"overscroll-y":C()}],position:[`static`,`fixed`,`absolute`,`relative`,`sticky`],inset:[{inset:T()}],"inset-x":[{"inset-x":T()}],"inset-y":[{"inset-y":T()}],start:[{"inset-s":T(),start:T()}],end:[{"inset-e":T(),end:T()}],"inset-bs":[{"inset-bs":T()}],"inset-be":[{"inset-be":T()}],top:[{top:T()}],right:[{right:T()}],bottom:[{bottom:T()}],left:[{left:T()}],visibility:[`visible`,`invisible`,`collapse`],z:[{z:[cp,`auto`,Y,J]}],basis:[{basis:[op,`full`,`auto`,s,...w()]}],"flex-direction":[{flex:[`row`,`row-reverse`,`col`,`col-reverse`]}],"flex-wrap":[{flex:[`nowrap`,`wrap`,`wrap-reverse`]}],flex:[{flex:[sp,op,`auto`,`initial`,`none`,J]}],grow:[{grow:[``,sp,Y,J]}],shrink:[{shrink:[``,sp,Y,J]}],order:[{order:[cp,`first`,`last`,`none`,Y,J]}],"grid-cols":[{"grid-cols":E()}],"col-start-end":[{col:D()}],"col-start":[{"col-start":O()}],"col-end":[{"col-end":O()}],"grid-rows":[{"grid-rows":E()}],"row-start-end":[{row:D()}],"row-start":[{"row-start":O()}],"row-end":[{"row-end":O()}],"grid-flow":[{"grid-flow":[`row`,`col`,`dense`,`row-dense`,`col-dense`]}],"auto-cols":[{"auto-cols":k()}],"auto-rows":[{"auto-rows":k()}],gap:[{gap:w()}],"gap-x":[{"gap-x":w()}],"gap-y":[{"gap-y":w()}],"justify-content":[{justify:[...A(),`normal`]}],"justify-items":[{"justify-items":[...j(),`normal`]}],"justify-self":[{"justify-self":[`auto`,...j()]}],"align-content":[{content:[`normal`,...A()]}],"align-items":[{items:[...j(),{baseline:[``,`last`]}]}],"align-self":[{self:[`auto`,...j(),{baseline:[``,`last`]}]}],"place-content":[{"place-content":A()}],"place-items":[{"place-items":[...j(),`baseline`]}],"place-self":[{"place-self":[`auto`,...j()]}],p:[{p:w()}],px:[{px:w()}],py:[{py:w()}],ps:[{ps:w()}],pe:[{pe:w()}],pbs:[{pbs:w()}],pbe:[{pbe:w()}],pt:[{pt:w()}],pr:[{pr:w()}],pb:[{pb:w()}],pl:[{pl:w()}],m:[{m:M()}],mx:[{mx:M()}],my:[{my:M()}],ms:[{ms:M()}],me:[{me:M()}],mbs:[{mbs:M()}],mbe:[{mbe:M()}],mt:[{mt:M()}],mr:[{mr:M()}],mb:[{mb:M()}],ml:[{ml:M()}],"space-x":[{"space-x":w()}],"space-x-reverse":[`space-x-reverse`],"space-y":[{"space-y":w()}],"space-y-reverse":[`space-y-reverse`],size:[{size:N()}],"inline-size":[{inline:[`auto`,...P()]}],"min-inline-size":[{"min-inline":[`auto`,...P()]}],"max-inline-size":[{"max-inline":[`none`,...P()]}],"block-size":[{block:[`auto`,...F()]}],"min-block-size":[{"min-block":[`auto`,...F()]}],"max-block-size":[{"max-block":[`none`,...F()]}],w:[{w:[s,`screen`,...N()]}],"min-w":[{"min-w":[s,`screen`,`none`,...N()]}],"max-w":[{"max-w":[s,`screen`,`none`,`prose`,{screen:[o]},...N()]}],h:[{h:[`screen`,`lh`,...N()]}],"min-h":[{"min-h":[`screen`,`lh`,`none`,...N()]}],"max-h":[{"max-h":[`screen`,`lh`,...N()]}],"font-size":[{text:[`base`,n,Tp,vp]}],"font-smoothing":[`antialiased`,`subpixel-antialiased`],"font-style":[`italic`,`not-italic`],"font-weight":[{font:[r,jp,bp]}],"font-stretch":[{"font-stretch":[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`,lp,J]}],"font-family":[{font:[Ep,xp,t]}],"font-features":[{"font-features":[J]}],"fvn-normal":[`normal-nums`],"fvn-ordinal":[`ordinal`],"fvn-slashed-zero":[`slashed-zero`],"fvn-figure":[`lining-nums`,`oldstyle-nums`],"fvn-spacing":[`proportional-nums`,`tabular-nums`],"fvn-fraction":[`diagonal-fractions`,`stacked-fractions`],tracking:[{tracking:[i,Y,J]}],"line-clamp":[{"line-clamp":[sp,`none`,Y,yp]}],leading:[{leading:[a,...w()]}],"list-image":[{"list-image":[`none`,Y,J]}],"list-style-position":[{list:[`inside`,`outside`]}],"list-style-type":[{list:[`disc`,`decimal`,`none`,Y,J]}],"text-alignment":[{text:[`left`,`center`,`right`,`justify`,`start`,`end`]}],"placeholder-color":[{placeholder:I()}],"text-color":[{text:I()}],"text-decoration":[`underline`,`overline`,`line-through`,`no-underline`],"text-decoration-style":[{decoration:[...U(),`wavy`]}],"text-decoration-thickness":[{decoration:[sp,`from-font`,`auto`,Y,vp]}],"text-decoration-color":[{decoration:I()}],"underline-offset":[{"underline-offset":[sp,`auto`,Y,J]}],"text-transform":[`uppercase`,`lowercase`,`capitalize`,`normal-case`],"text-overflow":[`truncate`,`text-ellipsis`,`text-clip`],"text-wrap":[{text:[`wrap`,`nowrap`,`balance`,`pretty`]}],indent:[{indent:w()}],"vertical-align":[{align:[`baseline`,`top`,`middle`,`bottom`,`text-top`,`text-bottom`,`sub`,`super`,Y,J]}],whitespace:[{whitespace:[`normal`,`nowrap`,`pre`,`pre-line`,`pre-wrap`,`break-spaces`]}],break:[{break:[`normal`,`words`,`all`,`keep`]}],wrap:[{wrap:[`break-word`,`anywhere`,`normal`]}],hyphens:[{hyphens:[`none`,`manual`,`auto`]}],content:[{content:[`none`,Y,J]}],"bg-attachment":[{bg:[`fixed`,`local`,`scroll`]}],"bg-clip":[{"bg-clip":[`border`,`padding`,`content`,`text`]}],"bg-origin":[{"bg-origin":[`border`,`padding`,`content`]}],"bg-position":[{bg:L()}],"bg-repeat":[{bg:R()}],"bg-size":[{bg:z()}],"bg-image":[{bg:[`none`,{linear:[{to:[`t`,`tr`,`r`,`br`,`b`,`bl`,`l`,`tl`]},cp,Y,J],radial:[``,Y,J],conic:[cp,Y,J]},kp,Cp]}],"bg-color":[{bg:I()}],"gradient-from-pos":[{from:B()}],"gradient-via-pos":[{via:B()}],"gradient-to-pos":[{to:B()}],"gradient-from":[{from:I()}],"gradient-via":[{via:I()}],"gradient-to":[{to:I()}],rounded:[{rounded:V()}],"rounded-s":[{"rounded-s":V()}],"rounded-e":[{"rounded-e":V()}],"rounded-t":[{"rounded-t":V()}],"rounded-r":[{"rounded-r":V()}],"rounded-b":[{"rounded-b":V()}],"rounded-l":[{"rounded-l":V()}],"rounded-ss":[{"rounded-ss":V()}],"rounded-se":[{"rounded-se":V()}],"rounded-ee":[{"rounded-ee":V()}],"rounded-es":[{"rounded-es":V()}],"rounded-tl":[{"rounded-tl":V()}],"rounded-tr":[{"rounded-tr":V()}],"rounded-br":[{"rounded-br":V()}],"rounded-bl":[{"rounded-bl":V()}],"border-w":[{border:H()}],"border-w-x":[{"border-x":H()}],"border-w-y":[{"border-y":H()}],"border-w-s":[{"border-s":H()}],"border-w-e":[{"border-e":H()}],"border-w-bs":[{"border-bs":H()}],"border-w-be":[{"border-be":H()}],"border-w-t":[{"border-t":H()}],"border-w-r":[{"border-r":H()}],"border-w-b":[{"border-b":H()}],"border-w-l":[{"border-l":H()}],"divide-x":[{"divide-x":H()}],"divide-x-reverse":[`divide-x-reverse`],"divide-y":[{"divide-y":H()}],"divide-y-reverse":[`divide-y-reverse`],"border-style":[{border:[...U(),`hidden`,`none`]}],"divide-style":[{divide:[...U(),`hidden`,`none`]}],"border-color":[{border:I()}],"border-color-x":[{"border-x":I()}],"border-color-y":[{"border-y":I()}],"border-color-s":[{"border-s":I()}],"border-color-e":[{"border-e":I()}],"border-color-bs":[{"border-bs":I()}],"border-color-be":[{"border-be":I()}],"border-color-t":[{"border-t":I()}],"border-color-r":[{"border-r":I()}],"border-color-b":[{"border-b":I()}],"border-color-l":[{"border-l":I()}],"divide-color":[{divide:I()}],"outline-style":[{outline:[...U(),`none`,`hidden`]}],"outline-offset":[{"outline-offset":[sp,Y,J]}],"outline-w":[{outline:[``,sp,Tp,vp]}],"outline-color":[{outline:I()}],shadow:[{shadow:[``,`none`,u,Ap,wp]}],"shadow-color":[{shadow:I()}],"inset-shadow":[{"inset-shadow":[`none`,d,Ap,wp]}],"inset-shadow-color":[{"inset-shadow":I()}],"ring-w":[{ring:H()}],"ring-w-inset":[`ring-inset`],"ring-color":[{ring:I()}],"ring-offset-w":[{"ring-offset":[sp,vp]}],"ring-offset-color":[{"ring-offset":I()}],"inset-ring-w":[{"inset-ring":H()}],"inset-ring-color":[{"inset-ring":I()}],"text-shadow":[{"text-shadow":[`none`,f,Ap,wp]}],"text-shadow-color":[{"text-shadow":I()}],opacity:[{opacity:[sp,Y,J]}],"mix-blend":[{"mix-blend":[...W(),`plus-darker`,`plus-lighter`]}],"bg-blend":[{"bg-blend":W()}],"mask-clip":[{"mask-clip":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]},`mask-no-clip`],"mask-composite":[{mask:[`add`,`subtract`,`intersect`,`exclude`]}],"mask-image-linear-pos":[{"mask-linear":[sp]}],"mask-image-linear-from-pos":[{"mask-linear-from":G()}],"mask-image-linear-to-pos":[{"mask-linear-to":G()}],"mask-image-linear-from-color":[{"mask-linear-from":I()}],"mask-image-linear-to-color":[{"mask-linear-to":I()}],"mask-image-t-from-pos":[{"mask-t-from":G()}],"mask-image-t-to-pos":[{"mask-t-to":G()}],"mask-image-t-from-color":[{"mask-t-from":I()}],"mask-image-t-to-color":[{"mask-t-to":I()}],"mask-image-r-from-pos":[{"mask-r-from":G()}],"mask-image-r-to-pos":[{"mask-r-to":G()}],"mask-image-r-from-color":[{"mask-r-from":I()}],"mask-image-r-to-color":[{"mask-r-to":I()}],"mask-image-b-from-pos":[{"mask-b-from":G()}],"mask-image-b-to-pos":[{"mask-b-to":G()}],"mask-image-b-from-color":[{"mask-b-from":I()}],"mask-image-b-to-color":[{"mask-b-to":I()}],"mask-image-l-from-pos":[{"mask-l-from":G()}],"mask-image-l-to-pos":[{"mask-l-to":G()}],"mask-image-l-from-color":[{"mask-l-from":I()}],"mask-image-l-to-color":[{"mask-l-to":I()}],"mask-image-x-from-pos":[{"mask-x-from":G()}],"mask-image-x-to-pos":[{"mask-x-to":G()}],"mask-image-x-from-color":[{"mask-x-from":I()}],"mask-image-x-to-color":[{"mask-x-to":I()}],"mask-image-y-from-pos":[{"mask-y-from":G()}],"mask-image-y-to-pos":[{"mask-y-to":G()}],"mask-image-y-from-color":[{"mask-y-from":I()}],"mask-image-y-to-color":[{"mask-y-to":I()}],"mask-image-radial":[{"mask-radial":[Y,J]}],"mask-image-radial-from-pos":[{"mask-radial-from":G()}],"mask-image-radial-to-pos":[{"mask-radial-to":G()}],"mask-image-radial-from-color":[{"mask-radial-from":I()}],"mask-image-radial-to-color":[{"mask-radial-to":I()}],"mask-image-radial-shape":[{"mask-radial":[`circle`,`ellipse`]}],"mask-image-radial-size":[{"mask-radial":[{closest:[`side`,`corner`],farthest:[`side`,`corner`]}]}],"mask-image-radial-pos":[{"mask-radial-at":b()}],"mask-image-conic-pos":[{"mask-conic":[sp]}],"mask-image-conic-from-pos":[{"mask-conic-from":G()}],"mask-image-conic-to-pos":[{"mask-conic-to":G()}],"mask-image-conic-from-color":[{"mask-conic-from":I()}],"mask-image-conic-to-color":[{"mask-conic-to":I()}],"mask-mode":[{mask:[`alpha`,`luminance`,`match`]}],"mask-origin":[{"mask-origin":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]}],"mask-position":[{mask:L()}],"mask-repeat":[{mask:R()}],"mask-size":[{mask:z()}],"mask-type":[{"mask-type":[`alpha`,`luminance`]}],"mask-image":[{mask:[`none`,Y,J]}],filter:[{filter:[``,`none`,Y,J]}],blur:[{blur:ee()}],brightness:[{brightness:[sp,Y,J]}],contrast:[{contrast:[sp,Y,J]}],"drop-shadow":[{"drop-shadow":[``,`none`,p,Ap,wp]}],"drop-shadow-color":[{"drop-shadow":I()}],grayscale:[{grayscale:[``,sp,Y,J]}],"hue-rotate":[{"hue-rotate":[sp,Y,J]}],invert:[{invert:[``,sp,Y,J]}],saturate:[{saturate:[sp,Y,J]}],sepia:[{sepia:[``,sp,Y,J]}],"backdrop-filter":[{"backdrop-filter":[``,`none`,Y,J]}],"backdrop-blur":[{"backdrop-blur":ee()}],"backdrop-brightness":[{"backdrop-brightness":[sp,Y,J]}],"backdrop-contrast":[{"backdrop-contrast":[sp,Y,J]}],"backdrop-grayscale":[{"backdrop-grayscale":[``,sp,Y,J]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[sp,Y,J]}],"backdrop-invert":[{"backdrop-invert":[``,sp,Y,J]}],"backdrop-opacity":[{"backdrop-opacity":[sp,Y,J]}],"backdrop-saturate":[{"backdrop-saturate":[sp,Y,J]}],"backdrop-sepia":[{"backdrop-sepia":[``,sp,Y,J]}],"border-collapse":[{border:[`collapse`,`separate`]}],"border-spacing":[{"border-spacing":w()}],"border-spacing-x":[{"border-spacing-x":w()}],"border-spacing-y":[{"border-spacing-y":w()}],"table-layout":[{table:[`auto`,`fixed`]}],caption:[{caption:[`top`,`bottom`]}],transition:[{transition:[``,`all`,`colors`,`opacity`,`shadow`,`transform`,`none`,Y,J]}],"transition-behavior":[{transition:[`normal`,`discrete`]}],duration:[{duration:[sp,`initial`,Y,J]}],ease:[{ease:[`linear`,`initial`,_,Y,J]}],delay:[{delay:[sp,Y,J]}],animate:[{animate:[`none`,v,Y,J]}],backface:[{backface:[`hidden`,`visible`]}],perspective:[{perspective:[h,Y,J]}],"perspective-origin":[{"perspective-origin":x()}],rotate:[{rotate:K()}],"rotate-x":[{"rotate-x":K()}],"rotate-y":[{"rotate-y":K()}],"rotate-z":[{"rotate-z":K()}],scale:[{scale:te()}],"scale-x":[{"scale-x":te()}],"scale-y":[{"scale-y":te()}],"scale-z":[{"scale-z":te()}],"scale-3d":[`scale-3d`],skew:[{skew:ne()}],"skew-x":[{"skew-x":ne()}],"skew-y":[{"skew-y":ne()}],transform:[{transform:[Y,J,``,`none`,`gpu`,`cpu`]}],"transform-origin":[{origin:x()}],"transform-style":[{transform:[`3d`,`flat`]}],translate:[{translate:re()}],"translate-x":[{"translate-x":re()}],"translate-y":[{"translate-y":re()}],"translate-z":[{"translate-z":re()}],"translate-none":[`translate-none`],accent:[{accent:I()}],appearance:[{appearance:[`none`,`auto`]}],"caret-color":[{caret:I()}],"color-scheme":[{scheme:[`normal`,`dark`,`light`,`light-dark`,`only-dark`,`only-light`]}],cursor:[{cursor:[`auto`,`default`,`pointer`,`wait`,`text`,`move`,`help`,`not-allowed`,`none`,`context-menu`,`progress`,`cell`,`crosshair`,`vertical-text`,`alias`,`copy`,`no-drop`,`grab`,`grabbing`,`all-scroll`,`col-resize`,`row-resize`,`n-resize`,`e-resize`,`s-resize`,`w-resize`,`ne-resize`,`nw-resize`,`se-resize`,`sw-resize`,`ew-resize`,`ns-resize`,`nesw-resize`,`nwse-resize`,`zoom-in`,`zoom-out`,Y,J]}],"field-sizing":[{"field-sizing":[`fixed`,`content`]}],"pointer-events":[{"pointer-events":[`auto`,`none`]}],resize:[{resize:[`none`,``,`y`,`x`]}],"scroll-behavior":[{scroll:[`auto`,`smooth`]}],"scroll-m":[{"scroll-m":w()}],"scroll-mx":[{"scroll-mx":w()}],"scroll-my":[{"scroll-my":w()}],"scroll-ms":[{"scroll-ms":w()}],"scroll-me":[{"scroll-me":w()}],"scroll-mbs":[{"scroll-mbs":w()}],"scroll-mbe":[{"scroll-mbe":w()}],"scroll-mt":[{"scroll-mt":w()}],"scroll-mr":[{"scroll-mr":w()}],"scroll-mb":[{"scroll-mb":w()}],"scroll-ml":[{"scroll-ml":w()}],"scroll-p":[{"scroll-p":w()}],"scroll-px":[{"scroll-px":w()}],"scroll-py":[{"scroll-py":w()}],"scroll-ps":[{"scroll-ps":w()}],"scroll-pe":[{"scroll-pe":w()}],"scroll-pbs":[{"scroll-pbs":w()}],"scroll-pbe":[{"scroll-pbe":w()}],"scroll-pt":[{"scroll-pt":w()}],"scroll-pr":[{"scroll-pr":w()}],"scroll-pb":[{"scroll-pb":w()}],"scroll-pl":[{"scroll-pl":w()}],"snap-align":[{snap:[`start`,`end`,`center`,`align-none`]}],"snap-stop":[{snap:[`normal`,`always`]}],"snap-type":[{snap:[`none`,`x`,`y`,`both`]}],"snap-strictness":[{snap:[`mandatory`,`proximity`]}],touch:[{touch:[`auto`,`none`,`manipulation`]}],"touch-x":[{"touch-pan":[`x`,`left`,`right`]}],"touch-y":[{"touch-pan":[`y`,`up`,`down`]}],"touch-pz":[`touch-pinch-zoom`],select:[{select:[`none`,`text`,`all`,`auto`]}],"will-change":[{"will-change":[`auto`,`scroll`,`contents`,`transform`,Y,J]}],fill:[{fill:[`none`,...I()]}],"stroke-w":[{stroke:[sp,Tp,vp,yp]}],stroke:[{stroke:[`none`,...I()]}],"forced-color-adjust":[{"forced-color-adjust":[`auto`,`none`]}]},conflictingClassGroups:{overflow:[`overflow-x`,`overflow-y`],overscroll:[`overscroll-x`,`overscroll-y`],inset:[`inset-x`,`inset-y`,`inset-bs`,`inset-be`,`start`,`end`,`top`,`right`,`bottom`,`left`],"inset-x":[`right`,`left`],"inset-y":[`top`,`bottom`],flex:[`basis`,`grow`,`shrink`],gap:[`gap-x`,`gap-y`],p:[`px`,`py`,`ps`,`pe`,`pbs`,`pbe`,`pt`,`pr`,`pb`,`pl`],px:[`pr`,`pl`],py:[`pt`,`pb`],m:[`mx`,`my`,`ms`,`me`,`mbs`,`mbe`,`mt`,`mr`,`mb`,`ml`],mx:[`mr`,`ml`],my:[`mt`,`mb`],size:[`w`,`h`],"font-size":[`leading`],"fvn-normal":[`fvn-ordinal`,`fvn-slashed-zero`,`fvn-figure`,`fvn-spacing`,`fvn-fraction`],"fvn-ordinal":[`fvn-normal`],"fvn-slashed-zero":[`fvn-normal`],"fvn-figure":[`fvn-normal`],"fvn-spacing":[`fvn-normal`],"fvn-fraction":[`fvn-normal`],"line-clamp":[`display`,`overflow`],rounded:[`rounded-s`,`rounded-e`,`rounded-t`,`rounded-r`,`rounded-b`,`rounded-l`,`rounded-ss`,`rounded-se`,`rounded-ee`,`rounded-es`,`rounded-tl`,`rounded-tr`,`rounded-br`,`rounded-bl`],"rounded-s":[`rounded-ss`,`rounded-es`],"rounded-e":[`rounded-se`,`rounded-ee`],"rounded-t":[`rounded-tl`,`rounded-tr`],"rounded-r":[`rounded-tr`,`rounded-br`],"rounded-b":[`rounded-br`,`rounded-bl`],"rounded-l":[`rounded-tl`,`rounded-bl`],"border-spacing":[`border-spacing-x`,`border-spacing-y`],"border-w":[`border-w-x`,`border-w-y`,`border-w-s`,`border-w-e`,`border-w-bs`,`border-w-be`,`border-w-t`,`border-w-r`,`border-w-b`,`border-w-l`],"border-w-x":[`border-w-r`,`border-w-l`],"border-w-y":[`border-w-t`,`border-w-b`],"border-color":[`border-color-x`,`border-color-y`,`border-color-s`,`border-color-e`,`border-color-bs`,`border-color-be`,`border-color-t`,`border-color-r`,`border-color-b`,`border-color-l`],"border-color-x":[`border-color-r`,`border-color-l`],"border-color-y":[`border-color-t`,`border-color-b`],translate:[`translate-x`,`translate-y`,`translate-none`],"translate-none":[`translate`,`translate-x`,`translate-y`,`translate-z`],"scroll-m":[`scroll-mx`,`scroll-my`,`scroll-ms`,`scroll-me`,`scroll-mbs`,`scroll-mbe`,`scroll-mt`,`scroll-mr`,`scroll-mb`,`scroll-ml`],"scroll-mx":[`scroll-mr`,`scroll-ml`],"scroll-my":[`scroll-mt`,`scroll-mb`],"scroll-p":[`scroll-px`,`scroll-py`,`scroll-ps`,`scroll-pe`,`scroll-pbs`,`scroll-pbe`,`scroll-pt`,`scroll-pr`,`scroll-pb`,`scroll-pl`],"scroll-px":[`scroll-pr`,`scroll-pl`],"scroll-py":[`scroll-pt`,`scroll-pb`],touch:[`touch-x`,`touch-y`,`touch-pz`],"touch-x":[`touch`],"touch-y":[`touch`],"touch-pz":[`touch`]},conflictingClassGroupModifiers:{"font-size":[`leading`]},orderSensitiveModifiers:[`*`,`**`,`after`,`backdrop`,`before`,`details-content`,`file`,`first-letter`,`first-line`,`marker`,`placeholder`,`selection`]}});function X(...e){return Hp(vf(e))}function Up({delayDuration:e=0,...t}){return(0,q.jsx)(df,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Wp({...e}){return(0,q.jsx)(ff,{"data-slot":`tooltip`,...e})}function Gp({...e}){return(0,q.jsx)(pf,{"data-slot":`tooltip-trigger`,...e})}function Kp({className:e,sideOffset:t=4,children:n,...r}){return(0,q.jsx)(mf,{children:(0,q.jsxs)(hf,{"data-slot":`tooltip-content`,sideOffset:t,className:X(`z-50 overflow-hidden rounded-md bg-gray-900 px-3 py-1.5 text-xs text-gray-100 shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...r,children:[n,(0,q.jsx)(gf,{className:`fill-gray-900`})]})})}var Z=(e,t)=>fetch(e,{credentials:`include`,...t}),qp=null;function Jp(){return qp||=Z(`/api/health`).then(e=>e.json()).then(e=>typeof e?.workspace==`string`?e.workspace:`loopat`).catch(()=>`loopat`),qp}async function Yp(){let e=await Z(`/api/auth/me`);return e.ok?(await e.json()).user??null:null}async function Xp(e,t){let n=await Z(`/api/auth/login`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({username:e,password:t})}),r=await n.json().catch(()=>({}));return n.ok?{user:r.user}:{error:r.error??`login failed (${n.status})`}}async function Zp(e){let t=await Z(`/api/auth/register`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{user:n.user,publicKey:n.publicKey,personalRepo:n.personalRepo??null,needsImport:!!n.needsImport}:{error:n.error??`register failed (${t.status})`}}async function Qp(e){let t=await Z(`/api/personal/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({token:e})}),n=await t.json().catch(()=>({}));return t.ok?{ok:n.ok!==!1,repos:Array.isArray(n.repos)?n.repos:[],login:n.login,error:n.error}:{ok:!1,repos:[],error:n?.error??`request failed`}}async function $p(){let e=await Z(`/api/personal/status`);return e.ok?await e.json():null}async function em(){let e=await Z(`/api/onboarding`);return e.ok?await e.json():null}async function tm(e){let t=await Z(`/api/onboarding/submit`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({values:e})}),n=await t.json().catch(()=>({}));return t.ok?n:{error:n.error??`submit failed (${t.status})`}}async function nm(e){let t=await Z(`/api/personal/crypt-key`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({password:e})}),n=await t.json().catch(()=>({}));return t.ok?typeof n.cryptKey==`string`?{ok:!0,cryptKey:n.cryptKey}:{ok:!1,error:`missing cryptKey in response`}:{ok:!1,error:n.error??`request failed (${t.status})`,wrongPassword:t.status===403}}async function rm(e,t=!1){let n=await Z(`/api/personal/delete`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({password:e,force:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0,synced:r.synced,dataLost:r.dataLost}:{ok:!1,error:r.error??`delete failed (${n.status})`,wrongPassword:n.status===403,syncFailed:r.syncFailed,uncommitted:r.uncommitted,unpushed:r.unpushed,hasRemote:r.hasRemote}}async function im(e){let t=await Z(`/api/personal/pull`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({force:e?.force??!1})}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`pull failed (${t.status})`,conflict:n.conflict,files:n.files,needsStash:n.needsStash}}async function am(){let e=await Z(`/api/personal/push`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,message:t.message}:{ok:!1,error:t.error??`push failed (${e.status})`,conflict:t.conflict,files:t.files,needsPull:t.needsPull}}async function om(e,t){let n={};e&&(n.repoUrl=e),t&&(n.cryptKey=t);let r=await Z(`/api/personal/import`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,autoInitialized:!!i.autoInitialized,cryptKey:typeof i.cryptKey==`string`?i.cryptKey:null}:{ok:!1,error:i.error??`import failed (${r.status})`,needsCryptKey:!!i.needsCryptKey,notClean:!!i.notClean,secretsExposed:!!i.secretsExposed,exposedFiles:Array.isArray(i.exposedFiles)?i.exposedFiles:[]}}async function sm(e,t,n,r){let i={token:e};t&&(i.repoName=t),n&&(i.cryptKey=n),r&&(i.baseUrl=r);let a=await Z(`/api/personal/github`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(i)}),o=await a.json().catch(()=>({}));return a.ok?{ok:!0,repo:typeof o.repo==`string`?o.repo:void 0,created:!!o.created,autoInitialized:!!o.autoInitialized,cryptKey:typeof o.cryptKey==`string`?o.cryptKey:null}:{ok:!1,error:o.error??`github setup failed (${a.status})`,needsCryptKey:!!o.needsCryptKey}}async function cm(){await Z(`/api/auth/logout`,{method:`POST`}).catch(()=>{})}async function lm(e=`active`){let t=await Z(`/api/loops`+(e===`all`?`?archived=all`:e===`archived`?`?archived=true`:``));return t.ok?(await t.json()).loops:[]}async function um(e){if(e.knowledgeRw||e.mountAllLoops){let t={title:e.title,repo:e.repo,profiles:e.profiles,vault:e.vault};return e.knowledgeRw&&(t.knowledge_rw=!0),e.mountAllLoops&&(t.mount_all_loops=!0),await(await Z(`/api/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json()}let t=await Z(`/api/v1/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({title:e.title,profiles:e.profiles,vault:e.vault,repo:e.repo})});if(!t.ok)throw Error(`createLoop failed (${t.status})`);let n=await t.json();return{id:n.id.startsWith(`loop_`)?n.id.slice(5):n.id,title:n.title,createdAt:n.created_at,createdBy:n.created_by,archived:n.archived,repo:n.repo??void 0,config:{profiles:n.profiles,vault:n.vault}}}async function dm(){let e=await Z(`/api/profiles`);return e.ok?(await e.json()).profiles??[]:[]}async function fm(){let e=await Z(`/api/personal/default-profiles`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.default_profiles)?t.default_profiles:[]}async function pm(e){let t=await Z(`/api/loop-stats?profiles=${encodeURIComponent(e.join(`,`))}`);return t.ok?await t.json():null}async function mm(){let e=await Z(`/api/vaults`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.vaults)?t.vaults:[]}async function hm(e){return(await Z(`/api/loops/${e}/viewed`,{method:`POST`})).ok}async function gm(e,t){let n=await Z(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({archived:t})});return n.ok?await n.json():null}async function _m(e,t){let n=await Z(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({public:t})});return n.ok?await n.json():null}async function vm(e,t){let n=await Z(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({title:t})});return n.ok?await n.json():null}async function ym(e){let t=await Z(`/api/loops/${e}/request-drive`,{method:`POST`});return t.ok?await t.json():null}async function bm(e){let t=await Z(`/api/loops/${e}/drive`,{method:`POST`});return t.ok?await t.json():null}async function xm(e){let t=await Z(`/api/loops/${e}/distill`,{method:`POST`});return t.ok?await t.json():null}async function Sm(e){let t=await Z(`/api/loops/${e}`);return t.ok?await t.json():null}async function Cm(e){let t=await Z(`/api/loops/${e}/strip-thinking`,{method:`POST`});return t.ok?await t.json():{stripped:0,sessionsTouched:0}}async function wm(e,t=``){return(await(await Z(`/api/loops/${e}/files?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Tm(e,t=``){return(await(await Z(`/api/loops/${e}/files/tree?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Em(e,t){let n=await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Dm(e,t,n){return(await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).ok}async function Om(e,t){return(await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function km(e,t){return(await Z(`/api/loops/${e}/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).ok}async function Am(e,t){let n=new FormData;n.append(`file`,t);let r=await Z(`/api/loops/${e}/upload`,{method:`POST`,body:n}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,path:i.path}:{ok:!1,error:i.error??`upload failed`}}async function jm(e){let t=await Z(`/api/loops/${e}/context`);return t.ok?(await t.json()).mounts??[]:[]}async function Mm(e,t=``){let n=await Z(`/api/workspace/files?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).entries??[]:[]}async function Nm(e){let t=await Z(`/api/workspace/files?vault=${e}&flat=1`);return t.ok?(await t.json()).entries??[]:[]}async function Pm(e,t){let n=await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Fm(e,t,n){return await(await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).json()}async function Im(){let e=await Z(`/api/notes/save`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,message:t.message}:{ok:!1,conflict:t.conflict,files:t.files,needsPull:t.needsPull,error:t.error??`save failed (${e.status})`}}async function Lm(){let e=await(await Z(`/api/notes/behind`)).json().catch(()=>({}));return typeof e.behind==`number`?e.behind:0}async function Rm(){let e=await(await Z(`/api/notes/refresh`,{method:`POST`})).json().catch(()=>({}));return{ok:!!e.ok,diverged:e.diverged,error:e.error}}async function zm(e,t){return await(await Z(`/api/workspace/file?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Bm(e,t){return await(await Z(`/api/workspace/folder?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Vm(e,t){return await(await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`DELETE`})).json()}async function Hm(e,t){let n=await Z(`/api/workspace/backlinks?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).backlinks??[]:[]}async function Um(){let e=await Z(`/api/context/repos`);return e.ok?{repos:(await e.json()).repos??[]}:{repos:[]}}async function Wm(e){let t=await Z(`/api/context/repos`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`http ${t.status}`}}async function Gm(e){let t=await Z(`/api/loops/${e}/chat-history`);return t.ok?(await t.json()).map(e=>e.text):[]}async function Km(e,t){await Z(`/api/loops/${e}/chat-history`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t})})}function qm(e){return typeof e==`string`?`/api/sync/${e}`:`/api/sync/repos/${encodeURIComponent(e.repo)}`}async function Jm(e){let t=await Z(`${qm(e)}/status`);return t.ok?await t.json():null}async function Ym(e){let t=await Z(`${qm(e)}/pull`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function Xm(e){let t=await Z(`${qm(e)}/push`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function Zm(e=`default`){let t=await Z(`/api/kanban/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function Qm(e,t,n){let r=await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),i=await r.json().catch(()=>({}));return r.ok?{cid:i.cid}:{error:i.error??`add failed`}}async function $m(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/toggle`,{method:`PATCH`})).ok}async function eh(e,t,n,r){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(r)})).ok}async function th(e,t,n,r){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/block`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({block:r})})).ok}async function nh(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`DELETE`})).ok}async function rh(e,t,n,r,i){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/move`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:r,toIndex:i})})).ok}async function ih(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({filename:t,title:n})})).ok}async function ah(){let e=await Z(`/api/kanban/boards`);return e.ok?(await e.json()).boards:[`default`]}async function oh(e){return(await Z(`/api/kanban/boards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).ok}async function sh(e,t){return(await Z(`/api/kanban/boards/${encodeURIComponent(e)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})})).ok}async function ch(e=`default`){let t=await Z(`/api/kanban/config/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function lh(e,t){return(await Z(`/api/kanban/config/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({columns:t})})).ok}async function uh(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:n})})).ok}async function dh(e,t){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function fh(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/color`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({color:n})})).ok}async function ph(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/reorder`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({cids:n})})).ok}async function mh(e,t,n){let r=await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/assign-driver`,{method:`POST`});return r.ok?await r.json():{ok:!1}}async function hh(e,t,n,r){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/link-loop`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({loopId:r})})).ok}async function gh(){let e=await Z(`/api/topics`);return e.ok?(await e.json()).topics:[]}async function _h(){let e=await Z(`/api/providers`);return e.ok?await e.json():{providers:{},default:``}}async function vh(e,t,n,r,i){let a={baseUrl:e,model:n};t?a.apiKey=t:r&&i&&(a.provider=r,a.source=i);let o=await Z(`/api/providers/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(a)}),s=await o.json().catch(()=>({}));return o.ok?s:{ok:!1,error:s.error??`test failed (${o.status})`}}async function yh(){let e=await Z(`/api/version`);return e.ok?await e.json():{branch:`unknown`,commit:`unknown`}}async function bh(){let e=await Z(`/api/admin/system`);return e.ok?await e.json():null}async function xh(){return await(await Z(`/api/admin/system/check`,{method:`POST`})).json()}async function Sh(){return await(await Z(`/api/admin/system/pull`,{method:`POST`})).json()}function Ch(){return{commit:`f315176099b0deffa0c4bc8cf1a72dc4721d63a7`,time:`2026-06-03T04:23:59.834Z`}}async function wh(e){let t=await Z(`/api/loops/${e}/git-status`);return t.ok?await t.json():{unstaged:[],staged:[]}}async function Th(e,t,n){let r=await Z(`/api/loops/${e}/git-diff?path=${encodeURIComponent(t)}&staged=${n?`1`:`0`}`);return r.ok?(await r.json()).diff??null:null}async function Eh(e,t,n=!1){return(await Z(`/api/loops/${e}/git-stage`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({files:t,unstage:n})})).ok}async function Dh(e,t){return(await Z(`/api/loops/${e}/git-discard`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({file:t})})).ok}async function Oh(e,t){let n=await Z(`/api/loops/${e}/git-commit`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`commit failed`}}async function kh(e,t=50){let n=await Z(`/api/loops/${e}/git-log?limit=${t}`);return n.ok?(await n.json()).commits??[]:[]}async function Ah(){let e=await Z(`/api/settings/personal/disk`);return e.ok?await e.json():null}async function jh(e){let t=await Z(`/api/settings/personal/disk`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`save failed (${t.status})`}}async function Mh(e,t,n=`default`){let r=await Z(`/api/settings/personal/value`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e,value:t,vault:n})}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0}:{ok:!1,error:i.error??`write failed (${r.status})`}}async function Nh(){return await(await Z(`/api/settings/workspace`)).json()}async function Ph(e){return(await Z(`/api/settings/workspace`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Fh(){let e=await Z(`/api/settings/token-usage/daily`);return e.ok?await e.json():{}}async function Ih(){let e=await Z(`/api/settings/token-usage/loops`);return e.ok?await e.json():[]}async function Lh(){let e=await Z(`/api/admin/presets`);return e.ok?await e.json():{providerPresets:[],miseToolPresets:[]}}async function Rh(e){return(await Z(`/api/admin/presets`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function zh(){let e=await Z(`/api/admin/users`);return e.ok?(await e.json()).users??[]:[]}async function Bh(e){let t=await Z(`/api/admin/users/${encodeURIComponent(e)}/activate`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`activate failed (${t.status})`}}async function Vh(e,t){let n=await Z(`/api/admin/users/${encodeURIComponent(e)}/role`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({role:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`role change failed (${n.status})`}}async function Hh(e){let t=await Z(`/api/admin/users/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function Uh(){let e=await Z(`/api/serve/config`);return e.ok?await e.json():{serveEnabled:!0,domain:`nip.io`,ip:`127.0.0.1`,baseUrl:`.127.0.0.1.nip.io`,withPort:!1,https:!1,displayPort:7788,serveDynamicEnabled:!1,serveDynamicDomain:``,serveDynamicPortRange:`10000-20000`,serveDynamicUdpEnabled:!1,serveDynamicStaticEnabled:!1,serveEphemeralEnabled:!1,serveEphemeralDomain:``}}async function Wh(e){let t=await Z(`/api/loops/${e}/share/current-port`);return t.ok?await t.json():{port:null}}async function Gh(e){return(await Z(`/api/serve/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Kh(){let e=await Z(`/api/serve/available-port`);return e.ok?await e.json():{port:null,error:`request failed`}}async function qh(e,t){let n=await Z(`/api/serve/check-port?port=${e}&loopId=${t||``}`);return n.ok?await n.json():{available:!1,reason:`request failed`}}async function Jh(e,t){let n=new URLSearchParams({alias:e});t&&n.set(`loopId`,t);let r=await Z(`/api/serve/alias-check?${n}`);return r.ok?await r.json():{available:!1,reason:`check failed`}}async function Yh(){let e=await Z(`/api/chat/conversations`);return e.ok?(await e.json()).conversations??[]:[]}async function Xh(){let e=await Z(`/api/chat/users`);return e.ok?(await e.json()).users??[]:[]}async function Zh(e,t){let n=await Z(`/api/chat/channels`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e,topic:t})}),r=await n.json().catch(()=>({}));return n.ok?{conv:r.conv}:{error:r.error??`create failed (${n.status})`}}async function Qh(e){let t=await Z(`/api/chat/channels/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function $h(e){let t=await Z(`/api/chat/dm/${encodeURIComponent(e)}`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{conv:n.conv}:{error:n.error??`open DM failed (${t.status})`}}async function eg(e,t={}){let n=new URLSearchParams;t.before&&n.set(`before`,String(t.before)),t.limit&&n.set(`limit`,String(t.limit));let r=await Z(`/api/chat/conversations/${encodeURIComponent(e)}/messages?${n.toString()}`);return r.ok?(await r.json()).messages??[]:[]}async function tg(e){let t=await Z(`/api/chat/threads/${e}`);return t.ok?await t.json():null}async function ng(e,t,n=null){let r=await Z(`/api/chat/conversations/${encodeURIComponent(e)}/messages`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n==null?{text:t}:{text:t,parentId:n})}),i=await r.json().catch(()=>({}));return r.ok?{message:i.message}:{error:i.error??`send failed (${r.status})`}}async function rg(e,t){return(await Z(`/api/chat/conversations/${encodeURIComponent(e)}/read`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({lastReadId:t})})).ok}async function ig(e,t){let n=await Z(`/api/chat/threads/${e}/spawn-loop`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t?{title:t}:{})}),r=await n.json().catch(()=>({}));return n.ok?{loopId:r.loopId,seedPrompt:r.seedPrompt,messageCount:r.messageCount}:{error:r.error??`spawn failed (${n.status})`}}async function ag(e,t,n){let r=await Z(`/api/mcp-setup/parse`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({server:e,pastedUrl:t,loopId:n})}),i=await r.json().catch(()=>({}));return r.ok?{ok:!0,set:i.set??[]}:{ok:!1,error:i.error??`failed (${r.status})`}}async function og(){let e=await Z(`/api/a2a`);return e.ok?await e.json():null}async function sg(e){return(await Z(`/api/a2a`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function cg(){let e=await Z(`/api/a2a/key`,{method:`POST`});return e.ok?(await e.json().catch(()=>({}))).token??null:null}async function lg(e){let t=await Z(`/api/mcp-servers${e?`?loopId=${encodeURIComponent(e)}`:``}`);return t.ok?await t.json():{servers:[]}}async function ug(e,t){let n=await Z(`/api/mcp-auth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({serverName:e,loopId:t})}),r=await n.json().catch(()=>({}));return n.ok?{authorizationUrl:r.authorizationUrl}:{error:r.error??`start failed`}}async function dg(e){return(await Z(`/api/envs/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}async function fg(e){let t=await Z(`/api/loops/${encodeURIComponent(e)}/restart-session`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{restarted:!!n.restarted}:{restarted:!1,error:n.error??`restart failed (${t.status})`}}async function pg(){let e=await Z(`/api/tiers`);return e.ok?await e.json():null}async function mg(e,t){let n=await Z(`/api/tiers/${encodeURIComponent(e)}/settings`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`save failed (${n.status})`}}async function hg(e){let t=await Z(`/api/tiers/${encodeURIComponent(e)}/mise-config`);return t.ok?await t.json():{content:``,exists:!1,error:`fetch failed (${t.status})`}}async function gg(e,t){let n=await Z(`/api/tiers/${encodeURIComponent(e)}/mise-config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:t})}),r=await n.json().catch(()=>({}));return n.ok?{ok:!0}:{ok:!1,error:r.error??`save failed (${n.status})`}}async function _g(){let e=await Z(`/api/plugins/available`);return e.ok?(await e.json()).plugins??[]:[]}async function vg(){let e=await Z(`/api/plugins/browse`);return e.ok?(await e.json()).plugins??[]:[]}async function yg(){let e=await Z(`/api/marketplaces`);return e.ok?(await e.json()).marketplaces??[]:[]}async function bg(){let e=await Z(`/api/plugins/refresh`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{ok:!0,added:t.added}:{ok:!1,error:t.error??`refresh failed (${e.status})`}}async function xg(e){let t=await Z(`/api/admin/profiles`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`create failed (${t.status})`}}async function Sg(e){let t=await Z(`/api/admin/profiles/${encodeURIComponent(e)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0}:{ok:!1,error:n.error??`delete failed (${t.status})`}}async function Cg(){let e=await Z(`/api/v1/me/tokens`);return e.ok?(await e.json().catch(()=>({tokens:[]}))).tokens??[]:[]}async function wg(e){let t=await Z(`/api/v1/me/tokens`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({label:e})});return t.ok?await t.json().catch(()=>null):null}async function Tg(e){return(await Z(`/api/v1/me/tokens/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}function Eg(){let[e,t]=(0,w.useState)([]),[n,r]=(0,w.useState)(!0),[i,a]=(0,w.useState)(!1),[o,s]=(0,w.useState)(!1),[c,l]=(0,w.useState)(``),[u,d]=(0,w.useState)(null),[f,p]=(0,w.useState)(null),[m,h]=(0,w.useState)(!0),g=(0,w.useCallback)(async()=>{r(!0),t(await lm(i?`all`:`active`)),r(!1)},[i]);(0,w.useEffect)(()=>{let e=!1;return Yp().then(t=>{e||(p(t),h(!1))}),()=>{e=!0}},[]),(0,w.useEffect)(()=>{g()},[i,f]);let _=(0,w.useCallback)(async e=>{let n=await um(e);return t(e=>[n,...e]),n},[]),v=(0,w.useCallback)(async(e,n)=>{let r=await gm(e,n);r&&t(t=>!i&&r.archived?t.filter(t=>t.id!==e):t.map(t=>t.id===e?r:t))},[i]),y=(0,w.useCallback)(async(e,n)=>{let r=await _m(e,n);r&&t(t=>t.map(t=>t.id===e?r:t))},[]),b=(0,w.useCallback)(async(e,n)=>{let r=await vm(e,n);return r?(t(t=>t.map(t=>t.id===e?r:t)),r):null},[]),x=(0,w.useCallback)(async e=>{let n=await ym(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),S=(0,w.useCallback)(async e=>{let n=await bm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),C=(0,w.useCallback)(async(e,t)=>{let n=await Xp(e,t);return n.user&&p(n.user),{error:n.error}},[]),T=(0,w.useCallback)(async e=>{let t=await Zp(e);return t.user&&t.user.status===`active`&&p(t.user),{error:t.error,user:t.user,publicKey:t.publicKey,personalRepo:t.personalRepo,needsImport:t.needsImport}},[]),E=(0,w.useCallback)(async()=>{await cm(),p(null)},[]);return{loops:e,loopsLoading:n,showArchived:i,setShowArchived:a,refresh:g,createLoop:_,setLoopArchived:v,setLoopPublic:y,setLoopTitle:b,requestDrive:x,takeDrive:S,newLoopDialogOpen:o,newLoopDialogTitle:c,kanbanCreateCtx:u,setNewLoopDialogOpen:(0,w.useCallback)((e,t,n)=>{s(e),l(t??``),d(n??null)},[]),currentUser:f,authLoading:m,login:C,register:T,logout:E}}var Dg=(0,w.createContext)(null);function Og(){let e=(0,w.useContext)(Dg);if(!e)throw Error(`useWorkspace outside provider`);return e}function kg({onClose:e,onCreate:t,initialTitle:n}){let[r,i]=(0,w.useState)(n??``),[a,o]=(0,w.useState)(``),[s,c]=(0,w.useState)(new Set),[l,u]=(0,w.useState)([]),[d,f]=(0,w.useState)(`default`),[p,m]=(0,w.useState)([]),[h,g]=(0,w.useState)([]),[_,v]=(0,w.useState)([]),[y,b]=(0,w.useState)(null),[x,S]=(0,w.useState)(!1),[C,T]=(0,w.useState)(!1),E=(0,w.useRef)(null);(0,w.useEffect)(()=>{Um().then(e=>m(e.repos)),Promise.all([dm(),fm()]).then(([e,t])=>{g(e),u(t);let n=new Set(e.map(e=>e.name));c(new Set(t.filter(e=>n.has(e)&&e!==`base`)))}),mm().then(e=>{v(e),e.includes(`default`)?f(`default`):e.length>0&&f(e[0])}),E.current?.focus()},[]);function D(){let e=new Set(h.map(e=>e.name));c(new Set(l.filter(t=>e.has(t)&&t!==`base`)))}(0,w.useEffect)(()=>{S(!0);let e=setTimeout(()=>{pm([...s]).then(b).finally(()=>S(!1))},120);return()=>clearTimeout(e)},[s]);let O=(()=>{let e=new Set(l.filter(e=>e!==`base`));if(e.size!==s.size)return!0;for(let t of e)if(!s.has(t))return!0;return!1})(),k=h.find(e=>e.name===`base`),A=h.filter(e=>e.name!==`base`);function j(e){c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:e,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[480px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5 max-h-[85vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,q.jsx)(`div`,{className:`text-base font-semibold text-gray-900 mb-4`,children:`New loop`}),(0,q.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),!C){T(!0);try{await t({title:r.trim()||`untitled`,repo:a||void 0,profiles:s.size>0?[...s]:void 0,vault:d||void 0})}finally{T(!1)}}},className:`flex flex-col gap-4`,children:[(0,q.jsxs)(Ag,{label:`Repo`,hint:`Sets the workdir. Optional — leave (none) for an empty workdir.`,children:[(0,q.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value),className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 bg-white`,children:[(0,q.jsx)(`option`,{value:``,children:`(none — empty workdir)`}),p.map(e=>(0,q.jsxs)(`option`,{value:e.name,children:[e.name,e.git?` · ${e.git}`:``]},e.name))]}),p.length===0&&(0,q.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`No repos in the roster. Add them on the Context → Repos page.`})]}),(0,q.jsxs)(Ag,{label:`Profiles`,hint:`Each profile contributes plugins + a CLAUDE.md fragment. Empty = base + personal only.`,children:[(0,q.jsxs)(`div`,{className:`border border-gray-300 rounded p-2 max-h-44 overflow-y-auto bg-white flex flex-col gap-1`,children:[k&&(0,q.jsxs)(`label`,{className:`flex items-start gap-2 px-1.5 py-1 rounded text-sm text-gray-500 cursor-not-allowed bg-gray-50`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:!0,disabled:!0,className:`mt-0.5`}),(0,q.jsxs)(`span`,{className:`flex-1`,children:[(0,q.jsx)(`span`,{className:`font-medium`,children:`base`}),(0,q.jsx)(`span`,{className:`ml-1 text-[11px] text-gray-400`,children:`(always on)`}),k.description&&(0,q.jsx)(`span`,{className:`block text-[11px] text-gray-400 mt-0.5`,children:k.description})]})]}),A.map(e=>{let t=s.has(e.name),n=l.includes(e.name);return(0,q.jsxs)(`label`,{className:`flex items-start gap-2 px-1.5 py-1 rounded text-sm cursor-pointer hover:bg-gray-50 ${t?`bg-blue-50`:``}`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>j(e.name),className:`mt-0.5`}),(0,q.jsxs)(`span`,{className:`flex-1`,children:[(0,q.jsx)(`span`,{className:`font-medium text-gray-900`,children:e.name}),n&&(0,q.jsx)(`span`,{className:`ml-1.5 px-1 py-px text-[10px] rounded bg-gray-200 text-gray-600`,title:`In your default_profiles (personal config)`,children:`default`}),e.description&&(0,q.jsx)(`span`,{className:`block text-[11px] text-gray-500 mt-0.5`,children:e.description})]})]},e.name)}),A.length===0&&!k&&(0,q.jsxs)(`div`,{className:`text-[11px] text-gray-400 p-1.5`,children:[`No profiles yet. Add them under`,` `,(0,q.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`knowledge/.loopat/profiles/<name>/.claude/`}),` `,`in your knowledge repo.`]})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between mt-1`,children:[(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:s.size>0?`Selected: ${[...s].join(`, `)}`:`No profiles selected (base + personal only)`}),O&&l.length>0&&(0,q.jsx)(`button`,{type:`button`,onClick:D,className:`text-[11px] text-gray-500 hover:text-gray-900 underline`,title:`Restore default_profiles from your personal config`,children:`reset to defaults`})]}),(0,q.jsx)(`div`,{className:`mt-1.5 px-1.5 py-1 text-[11px] text-gray-600 bg-gray-50 border border-gray-200 rounded`,children:x&&!y?(0,q.jsx)(`span`,{className:`text-gray-400`,children:`computing…`}):y?(0,q.jsxs)(`span`,{title:`Totals across team + selected profiles + their plugins (deduped by name)`,children:[(0,q.jsxs)(`span`,{className:y.plugins>0?``:`text-gray-400`,children:[y.plugins,` plugins`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.skills>0?``:`text-gray-400`,children:[y.skills,` skills`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.agents>0?``:`text-gray-400`,children:[y.agents,` agents`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.hooks>0?``:`text-gray-400`,children:[y.hooks,` hooks`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.mcpServers>0?``:`text-gray-400`,children:[y.mcpServers,` MCP servers`]}),(0,q.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,q.jsxs)(`span`,{className:y.toolchain>0?``:`text-gray-400`,title:`mise.toml [tools] entries, deduped across team + selected profiles`,children:[y.toolchain,` toolchain`]}),x&&(0,q.jsx)(`span`,{className:`ml-1.5 text-gray-400`,children:`·`}),x&&(0,q.jsx)(`span`,{className:`ml-1 text-gray-400`,children:`updating…`})]}):(0,q.jsx)(`span`,{className:`text-gray-400`,children:`—`})})]}),(0,q.jsxs)(Ag,{label:`Vault`,hint:`Which credential set to inject. Only this vault is visible inside the loop.`,children:[(0,q.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 bg-white`,children:[_.length===0&&(0,q.jsx)(`option`,{value:`default`,children:`default`}),_.map(e=>(0,q.jsx)(`option`,{value:e,children:e},e))]}),_.length===0&&(0,q.jsxs)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:[`No vaults yet — using default. Create more under`,` `,(0,q.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`personal/.loopat/vaults/<name>/`}),` `,`to isolate prod / test credentials.`]})]}),(0,q.jsx)(Ag,{label:`Name`,hint:`Optional — defaults to 'untitled'.`,children:(0,q.jsx)(`input`,{ref:E,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`refactor-gateway`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2 pt-3 border-t border-gray-100`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:e,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,q.jsx)(`button`,{type:`submit`,disabled:C,className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:C?`creating…`:`create`})]})]})]})})}function Ag({label:e,hint:t,children:n}){return(0,q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,q.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,q.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var jg=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,Mg=vf,Ng=((e,t)=>n=>{if(t?.variants==null)return Mg(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=jg(t)||jg(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return Mg(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)})(`inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40`,outline:`border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function Pg({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,q.jsx)(r?Ri:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:X(Ng({variant:t,size:n,className:e})),...i})}function Fg({...e}){return(0,q.jsx)(cc,{"data-slot":`dialog`,...e})}function Ig({...e}){return(0,q.jsx)(lc,{"data-slot":`dialog-portal`,...e})}function Lg({className:e,...t}){return(0,q.jsx)(uc,{"data-slot":`dialog-overlay`,className:X(`fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function Rg({className:e,children:t,showCloseButton:n=!0,...r}){return(0,q.jsxs)(Ig,{"data-slot":`dialog-portal`,children:[(0,q.jsx)(Lg,{}),(0,q.jsxs)(dc,{"data-slot":`dialog-content`,className:X(`fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-white p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,e),...r,children:[t,n&&(0,q.jsxs)(mc,{"data-slot":`dialog-close`,className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,q.jsx)(ht,{}),(0,q.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function zg({className:e,...t}){return(0,q.jsx)(`div`,{"data-slot":`dialog-header`,className:X(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function Bg({className:e,...t}){return(0,q.jsx)(fc,{"data-slot":`dialog-title`,className:X(`text-lg leading-none font-semibold`,e),...t})}function Vg({className:e,...t}){return(0,q.jsx)(pc,{"data-slot":`dialog-description`,className:X(`text-sm text-muted-foreground`,e),...t})}function Hg({open:e,onClose:t}){let[n,r]=(0,w.useState)({branch:`…`,commit:`…`}),i=Ch();return(0,w.useEffect)(()=>{e&&yh().then(e=>r(e))},[e]),(0,q.jsx)(Fg,{open:e,onOpenChange:e=>!e&&t(),children:(0,q.jsxs)(Rg,{className:`sm:max-w-sm bg-white`,children:[(0,q.jsx)(zg,{children:(0,q.jsxs)(Bg,{className:`text-center`,children:[(0,q.jsx)(`img`,{src:`/logo.png`,alt:`loopat`,className:`w-full max-w-[240px] mx-auto mb-2`}),`loopat`]})}),(0,q.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,q.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,q.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Server`}),(0,q.jsxs)(`div`,{className:`font-mono text-gray-700`,children:[n.branch,`@`,n.commit.slice(0,7)]})]}),(0,q.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,q.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Build`}),(0,q.jsx)(`div`,{className:`font-mono text-gray-700`,children:i.commit.slice(0,7)}),(0,q.jsx)(`div`,{className:`font-mono text-gray-400 text-xs mt-0.5`,children:new Date(i.time).toLocaleString()})]})]})]})})}function Ug(e){let t=[];for(let n of e.effectTasks)try{n()}catch(e){t.push(e)}if(t.length>0){if(t.length===1)throw t[0];for(let e of t)console.error(e);throw AggregateError(t,`Errors during commit`)}}function Wg(e){let t=[];for(let n of e.cells)if(n?.type===`effect`&&(n.deps=null,n.cleanup))try{n.cleanup?.()}catch(e){t.push(e)}finally{n.cleanup=void 0}if(t.length>0){if(t.length===1)throw t[0];for(let e of t)console.error(e);throw AggregateError(t,`Errors during cleanup`)}}var Gg=typeof process<`u`&&!1,Kg=null;function qg(e,t){e.currentIndex=0;let n=Kg;Kg=e;try{if(t(),e.isFirstRender=!1,e.cells.length!==e.currentIndex)throw Error(`Rendered ${e.currentIndex} hooks but expected ${e.cells.length}. Hooks must be called in the exact same order in every render.`)}finally{Kg=n}}function Jg(){if(!Kg)throw Error(`No resource fiber available`);return Kg}function Yg(e){return Gg?Kg?.devStrictMode?Kg.isFirstRender?`child`:`root`:e?`root`:null:null}function Xg(e,t){let n=e[Zg];if(!n)throw Error(`ResourceElement.type is not a valid Resource`);return n(t)}var Zg=Symbol(`fnSymbol`);function Qg(e,t,n=void 0,r=Yg(!1)){return{type:e,root:t,markDirty:n,devStrictMode:r,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function $g(e){if(!e.isMounted)throw Error(`Tried to unmount a fiber that is already unmounted`);e.isMounted=!1,Wg(e)}function e_(e,t){let n={effectTasks:[],props:t,output:void 0};return qg(e,()=>{e.renderContext=n;try{n.output=Xg(e.type,t)}finally{e.renderContext=void 0}}),n}function t_(e,t){e.isMounted=!0,Gg&&e.isNeverMounted&&e.devStrictMode===`root`&&(e.isNeverMounted=!1,Ug(t),Wg(e)),e.isNeverMounted=!1,Ug(t)}var n_=e=>({version:0,committedVersion:0,dispatchUpdate:e,changelog:[],dirtyCells:[]}),r_=e=>{for(let t of e.dirtyCells)t.dirty=!1,t.queue.clear(),t.current=t.workInProgress;e.committedVersion=e.version,e.changelog.length=0,e.dirtyCells.length=0},i_=(e,t)=>{let n=e.version>t;if(e.version=t,n){for(let t of e.dirtyCells)t.dirty=!1,t.queue.clear(),t.workInProgress=t.current;if(e.dirtyCells.length=0,t===e.committedVersion)e.changelog.length=0;else{if(e.committedVersion>t)throw Error(`Version is less than committed version`);for(;e.committedVersion+e.changelog.length>t;)e.changelog.pop();e.changelog.forEach(e=>e()),r_(e)}}},a_=(e,t)=>{t.dirty||(t.dirty=!0,e.markDirty?.(),e.root.dirtyCells.push(t))},o_=()=>{if(!Gg)return null;let e=(0,w.useRef)(0),t=e.current===0;return(0,w.useState)(()=>e.current++),e.current===2?t?`child`:`root`:null};function s_(e){let t=(0,w.useMemo)(()=>n_(e=>r(e)),[]),[n,r]=(0,w.useReducer)((e,n)=>(i_(t,e),e+ +!!n()),0);i_(t,n);let i=o_(),a=(0,w.useMemo)(()=>(e.key,Qg(e.type,t,void 0,i)),[e.type,e.key,t,i]),o=e_(a,e.props);return(0,w.useLayoutEffect)(()=>()=>$g(a),[a]),(0,w.useLayoutEffect)(()=>{r_(t),t_(a,o)}),o.output}function c_(e){let t=e=>({type:t,props:e});return t[Zg]=e,t}function l_(e,t){return{...t,key:e}}var u_=(e,t)=>{let n=Jg(),r=n.currentIndex++;if(!n.isFirstRender&&r>=n.cells.length)throw Error(`Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render.`);let i=n.cells[r];if(i||(i=t(),n.cells[r]=i),i.type!==e)throw Error(`Hook order changed between renders`);return i},d_=e=>{Jg().renderContext.effectTasks.push(e)},f_=(e,t)=>{if(e.renderContext)throw Error(`Resource updated during render`);if(e.isNeverMounted)throw Error(`Resource updated before mount`);e.root.dispatchUpdate(()=>{let n=t();return n?(n(),e.root.changelog.push(n),!0):!1})};function p_(e,t,n,r){let i=u_(`reducer`,()=>{let t=Jg(),a=r?r(n):n;return Gg&&t.devStrictMode&&r&&r(n),{type:`reducer`,queue:new Set,dirty:!1,workInProgress:a,current:a,reducer:e,dispatch:n=>{let r={action:n,hasEagerState:!1,eagerState:void 0};f_(t,()=>t.root.dirtyCells.length===0&&!r.hasEagerState&&(r.eagerState=e(i.workInProgress,n),r.hasEagerState=!0,Object.is(i.current,r.eagerState))?null:()=>{a_(t,i),i.queue.add(r)})}}}),a=Jg(),o=e===i.reducer;i.reducer=e;for(let t of i.queue)(!t.hasEagerState||!o)&&(t.eagerState=e(i.workInProgress,t.action),t.hasEagerState=!0),Gg&&a.devStrictMode&&e(i.workInProgress,t.action),i.workInProgress=t.eagerState;if(i.queue.clear(),t){let e=t(i.workInProgress);Object.is(e,i.workInProgress)||(a_(a,i),i.workInProgress=e)}return[i.workInProgress,i.dispatch]}function m_(e,t,n){return p_(e,void 0,t,n)}function h_(e,t,n,r){return p_(e,t,n,r)}var g_=(e,t)=>typeof t==`function`?t(e):t,__=e=>typeof e==`function`?e():e;function v_(e){return m_(g_,e,__)}var y_=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0},b_=()=>({type:`effect`,cleanup:void 0,deps:null});function x_(e,t){let n=u_(`effect`,b_);if(!(t&&n.deps&&y_(n.deps,t))){if(n.deps!==null&&!!t!=!!n.deps)throw Error(`tapEffect called with and without dependencies across re-renders`);d_(()=>{let r=[];try{n.cleanup?.()}catch(e){r.push(e)}finally{n.cleanup=void 0}try{let t=e();if(t!==void 0&&typeof t!=`function`)throw Error(`An effect function must either return a cleanup function or nothing. Received: ${typeof t}`);n.cleanup=t}catch(e){r.push(e)}if(n.deps=t,r.length>0){if(r.length===1)throw r[0];for(let e of r)console.error(e);throw AggregateError(r,`Errors during commit`)}})}}function S_(e){let[t]=v_(()=>({current:e}));return t}function C_(e,t){let[n]=v_(e);return n}var w_=()=>{throw Error(`Memo reducer should not be called`)},T_=(e,t)=>{let n=Jg(),[r]=h_(w_,r=>{if(r&&y_(r.deps,t))return r;let i=e();return Gg&&n.devStrictMode&&e(),{value:i,deps:t}},null);return r.value},E_=(e,t)=>T_(()=>e,t);function D_(e){let t=S_(e);x_(()=>{t.current=e});let n=Jg();return E_(((...e)=>{if(Gg&&n.renderContext)throw Error(`tapEffectEvent cannot be called during render`);return t.current(...e)}),[n])}function O_(e,t){let n=Jg(),r=S_(0),i=T_(()=>(e.key,Qg(e.type,n.root,()=>{r.current++,n.markDirty?.()})),[e.type,e.key,n]),a=t?T_(()=>e_(i,e.props),[i,...t,r.current]):e_(i,e.props);return x_(()=>()=>$g(i),[i]),x_(()=>{t_(i,a)},[i,a]),a.output}function k_(e,t){let n=S_(0),r=n.current,i=C_(Jg,[]),a=C_(()=>()=>{n.current++,i.markDirty?.()},[]),o=C_(()=>new Map,[]),s=t?E_(e,t):e,c=T_(()=>{let e=s(),t=new Set,n=[],r=0;for(let s=0;s<e.length;s++){let c=e[s],l=c.key;if(l===void 0)throw Error(`tapResources did not provide a key for array at index ${s}`);if(t.has(l))throw Error(`Duplicate key ${l} in tapResources`);t.add(l);let u=o.get(l);if(!u){let e=Qg(c.type,i.root,a),t=e_(e,c.props);u={fiber:e,next:t},r++,o.set(l,u),n.push(t.output)}else if(u.fiber.type!==c.type){let e=Qg(c.type,i.root,a),t=e_(e,c.props);u.next=[e,t],n.push(t.output)}else u.next=e_(u.fiber,c.props),n.push(u.next.output)}if(o.size>n.length-r)for(let e of o.keys())t.has(e)||(o.get(e).next=`delete`);return n},[s,r]);return x_(()=>()=>{for(let e of o.keys()){let t=o.get(e).fiber;$g(t)}},[]),x_(()=>{for(let[e,t]of o.entries())t.next===`delete`?(t.fiber.isMounted&&$g(t.fiber),o.delete(e)):Array.isArray(t.next)?($g(t.fiber),t.fiber=t.next[0],t_(t.fiber,t.next[1])):t_(t.fiber,t.next)},[c]),c}var A_=50,j_={schedulers:new Set([]),isScheduled:!1},M_=class{_task;_isDirty=!1;constructor(e){this._task=e}get isDirty(){return this._isDirty}markDirty(){this._isDirty=!0,j_.schedulers.add(this),N_()}runTask(){this._isDirty=!1,this._task()}},N_=()=>{j_.isScheduled||(j_.isScheduled=!0,F_())},P_=()=>{try{let e=[],t=0;for(let n of j_.schedulers)if(j_.schedulers.delete(n),n.isDirty){if(t++,t>A_)throw Error(`Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside tapEffect.`);try{n.runTask()}catch(t){e.push(t)}}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e,`Errors occurred during flushSync`)}}finally{j_.schedulers.clear(),j_.isScheduled=!1}},F_=(()=>{if(typeof MessageChannel<`u`){let e=new MessageChannel;return e.port1.onmessage=P_,()=>e.port2.postMessage(null)}return()=>setTimeout(P_,0)})(),I_=e=>{let t=j_;j_={schedulers:new Set([]),isScheduled:!0};try{let t=e();return P_(),t}finally{j_=t}},L_=e=>{let t=C_(()=>new M_(()=>l(null)),[]),n=C_(()=>[],[]),r=T_(()=>(e.key,Qg(e.type,n_(e=>{!t.isDirty&&!e()||(n.push(e),t.markDirty())}))),[e.type,e.key]);i_(r.root,r.root.committedVersion);let i=e_(r,e.props),a=S_(!1),o=S_(e.props),s=S_(i.output),c=C_(()=>new Set,[]),l=D_(e=>{if(e===null&&(i_(r.root,2),i_(r.root,1),n.forEach(e=>{Gg&&r.devStrictMode&&e(),e()}),Gg&&r.devStrictMode&&e_(r,o.current),e=e_(r,o.current)),t.isDirty)throw Error(`Scheduler is dirty, this should never happen`);r_(r.root),n.length=0,a.current&&t_(r,e),!(t.isDirty||s.current===e.output)&&(s.current=e.output,c.forEach(e=>e()))});return x_(()=>(a.current=!0,()=>{a.current=!1,$g(r)}),[r]),x_(()=>{o.current=i.props,r_(r.root),t_(r,i),!(t.isDirty||s.current===i.output)&&(s.current=i.output,c.forEach(e=>e()))}),T_(()=>({getValue:()=>s.current,subscribe:e=>(c.add(e),()=>c.delete(e))}),[])},R_=Symbol(`tap.Context`),z_=e=>({[R_]:e}),B_=(e,t,n)=>{let r=e[R_];e[R_]=t;try{return n()}finally{e[R_]=r}},V_=e=>e[R_],H_=Symbol(`assistant-ui.store.clientIndex`),U_=e=>e[H_],W_=z_([]),G_=()=>V_(W_),K_=(e,t)=>{let n=G_();return B_(W_,T_(()=>[...n,e],[n,e]),t)},q_=new Set([`$$typeof`,`nodeType`,`then`]),J_=(e,t)=>{if(e===Symbol.toStringTag)return t;if(typeof e!=`symbol`){if(e===`toJSON`)return()=>t;if(!q_.has(e))return!1}},Y_=class{getOwnPropertyDescriptor(e,t){let n=this.get(e,t);if(n!==void 0)return{value:n,writable:!1,enumerable:!0,configurable:!1}}set(){return!1}setPrototypeOf(){return!1}defineProperty(){return!1}deleteProperty(){return!1}preventExtensions(){return!1}},X_=e=>{let t=c_(e);return e=>{let n=t(e);return e.key===void 0?n:l_(e.key,n)}},Z_=Symbol(`assistant-ui.store.getValue`),Q_=e=>{let t=e[Z_];if(!t)throw Error(`Client scope contains a non-client resource. Ensure your Derived get() returns a client created with tapClientResource(), not a plain resource.`);return t.getState?.()},$_=new Map;function ev(e){let t=$_.get(e);return t||(t=function(...t){if(!this||typeof this!=`object`)throw Error(`Method "${String(e)}" called without proper context. This may indicate the function was called incorrectly.`);let n=this[Z_];if(!n)throw Error(`Method "${String(e)}" called on invalid client proxy. Ensure you are calling this method on a valid client instance.`);let r=n[e];if(!r)throw Error(`Method "${String(e)}" is not implemented.`);if(typeof r!=`function`)throw Error(`"${String(e)}" is not a function.`);return r(...t)},$_.set(e,t)),t}var tv=class extends Y_{outputRef;index;boundFns;cachedReceiver;constructor(e,t){super(),this.outputRef=e,this.index=t}get(e,t,n){if(t===Z_)return this.outputRef.current;if(t===H_)return this.index;let r=J_(t,`ClientProxy`);if(r!==!1)return r;let i=this.outputRef.current[t];if(typeof i==`function`){this.cachedReceiver!==n&&(this.boundFns=new Map,this.cachedReceiver=n);let e=this.boundFns.get(t);return e||(e=ev(t).bind(n),this.boundFns.set(t,e)),e}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,t){return t===Z_||t===H_?!0:t in this.outputRef.current}},nv=X_(e=>{let t=S_(null),n=G_().length,r=T_(()=>new Proxy({},new tv(t,n)),[n]),i=K_(r,()=>O_(e));return t.current||=i,x_(()=>{t.current=i}),{methods:r,state:i.getState?.(),key:e.key}}),rv=e=>O_(nv(e)),iv=Symbol(`assistant-ui.store.proxiedAssistantState`),av=e=>e===`on`||e===`subscribe`||typeof e==`symbol`,ov=e=>{class t extends Y_{get(t,n){let r=J_(n,`AssistantState`);if(r!==!1)return r;let i=n;if(!av(i))return Q_(e[i]())}ownKeys(){return Object.keys(e).filter(e=>!av(e))}has(t,n){return!av(n)&&n in e}}return new Proxy({},new t)},sv=e=>e[iv],cv=()=>()=>{},lv=e=>{let t=(()=>{throw Error(e)});return t.source=null,t.query=null,t},uv=new Proxy({},new class extends Y_{get(e,t){if(t===`subscribe`||t===`on`)return cv;if(t===iv)return dv;let n=J_(t,`DefaultAssistantClient`);return n===!1?lv(`You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.`):n}ownKeys(){return[`subscribe`,`on`,iv]}has(e,t){return t===`subscribe`||t===`on`||t===iv}}),dv=ov(uv),fv=()=>new Proxy({},{get(e,t){let n=J_(t,`AssistantClient`);return n===!1?lv(`The current scope does not have a "${String(t)}" property.`):n}}),pv=(0,w.createContext)(uv),mv=()=>(0,w.useContext)(pv),hv=({value:e,children:t})=>(0,q.jsx)(pv.Provider,{value:e,children:t}),gv=c_(e=>null),_v=Symbol(`assistant-ui.transform-scopes`);function vv(e,t){let n=e;if(n[_v])throw Error(`transformScopes is already attached to this resource`);n[_v]=t}function yv(e){return e[_v]}function bv(e,t){let n={...e},r=new Set,i=!0;for(;i;){i=!1;for(let e of Object.values(n)){if(e.type===gv||r.has(e.type))continue;r.add(e.type);let a=yv(e.type);if(a){a(n,t),i=!0;break}}}let a={},o={};for(let[e,t]of Object.entries(n))t.type===gv?o[e]=t:a[e]=t;return{rootClients:a,derivedClients:o}}var xv=e=>T_(()=>e,[...Object.entries(e).flat()]),Sv=(e,t)=>{let{rootClients:n,derivedClients:r}=bv(e,t);return{rootClients:xv(n),derivedClients:xv(r)}},Cv=e=>typeof e==`string`?{scope:e.split(`.`)[0],event:e}:{scope:e.scope,event:e.event},wv=c_(()=>C_(()=>{let e=new Map,t=new Set,n=new Set;return{on(n,r){let i=r;if(n===`*`)return t.add(i),()=>t.delete(i);let a=e.get(n);return a||(a=new Set,e.set(n,a)),a.add(i),()=>{a.delete(i),a.size===0&&e.delete(n)}},emit(n,r,i){let a=e.get(n);!a&&t.size===0||queueMicrotask(()=>{let e=[];if(a)for(let t of a)try{t(r,i)}catch(t){e.push(t)}if(t.size>0){let a={event:n,payload:r};for(let n of t)try{n(a,i)}catch(t){e.push(t)}}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e,`Errors occurred during event emission`)}})},subscribe(e){return n.add(e),()=>n.delete(e)},notifySubscribers(){for(let e of n)try{e()}catch(e){console.error(`NotificationManager: subscriber callback error`,e)}}}},[])),Tv=z_(null),Ev=(e,t)=>B_(Tv,e,t),Dv=()=>{let e=V_(Tv);if(!e)throw Error(`AssistantTapContext is not available`);return e},Ov=()=>Dv().clientRef,kv=()=>{let{emit:e}=Dv(),t=G_();return D_((n,r)=>{e(n,r,t)})},Av=e=>T_(()=>e,e),jv=c_(({element:e,emit:t,clientRef:n})=>{let{methods:r,state:i}=Ev({clientRef:n,emit:t},()=>rv(e));return T_(()=>({state:i,methods:r}),[r,i])}),Mv=c_(({element:e,notifications:t,clientRef:n,name:r})=>{let i=L_(jv({element:e,emit:t.emit,clientRef:n}));return x_(()=>i.subscribe(t.notifySubscribers),[i,t]),T_(()=>{let e=()=>i.getValue().methods;return Object.defineProperties(e,{source:{value:`root`,writable:!1},query:{value:{},writable:!1},name:{value:r,configurable:!0}}),e},[i,r])}),Nv=c_(()=>T_(()=>({clients:[],subscribe:void 0,on:void 0}),[])),Pv=c_(({clients:e,clientRef:t})=>{let n=O_(wv());x_(()=>t.parent.subscribe(n.notifySubscribers),[t,n]);let r=Av(k_(()=>Object.keys(e).map(r=>l_(r,Mv({element:e[r],notifications:n,clientRef:t,name:r}))),[e,n,t]));return T_(()=>({clients:r,subscribe:n.subscribe,on:function(e,r){if(!this)throw Error(`const { on } = useAui() is not supported. Use aui.on() instead.`);let{scope:i,event:a}=Cv(e);if(i!==`*`&&this[i].source===null)throw Error(`Scope "${i}" is not available. Use { scope: "*", event: "${a}" } to listen globally.`);let o=n.on(a,(e,t)=>{if(i===`*`){r(e);return}let n=this[i]();n===t[U_(n)]&&r(e)});if(i!==`*`&&t.parent[i].source===null)return o;let s=t.parent.on(e,r);return()=>{o(),s()}}}),[r,n,t])}),Fv=(e,t,n)=>{if(`source`in e&&`query`in e)return e;if(n.dep===e)return n.meta;let r=e.getMeta(t.current);return n.meta=r,n.dep=e,r},Iv=c_(({element:e,clientRef:t,name:n})=>{let r=D_(()=>e.props);return T_(()=>{let e=()=>r().get(t.current),i={};return Object.defineProperties(e,{source:{get:()=>Fv(r(),t,i).source},query:{get:()=>Fv(r(),t,i).query},name:{value:n,configurable:!0}}),e},[t,n])}),Lv=c_(({clients:e,clientRef:t})=>Av(k_(()=>Object.keys(e).map(n=>l_(n,Iv({element:e[n],clientRef:t,name:n}))),[e,t]))),Rv=c_(({parent:e,clients:t})=>{let{rootClients:n,derivedClients:r}=Sv(t,e),i=S_({parent:e,current:null}).current;x_(()=>{i.current=s});let a=O_(Object.keys(n).length>0?Pv({clients:n,clientRef:i}):Nv()),o=O_(Lv({clients:r,clientRef:i})),s=T_(()=>{let t=e===uv?fv():e,n=Object.create(t);Object.assign(n,{subscribe:a.subscribe??e.subscribe,on:a.on??e.on,[iv]:ov(n)});for(let e of a.clients)n[e.name]=e;for(let e of o)n[e.name]=e;return n},[e,a,o]);return i.current===null&&(i.current=s),s});function zv(e,{parent:t}={parent:mv()}){if(e)return s_(Rv({parent:t??uv,clients:e}));if(t===null)throw Error(`received null parent, this usage is not allowed`);return t}var Q=e=>{let t=zv(),n=sv(t),r=(0,w.useSyncExternalStore)(t.subscribe,()=>e(n),()=>e(n));if(r===n)throw Error(`You tried to return the entire AssistantState. This is not supported due to technical limitations.`);return(0,w.useDebugValue)(r),r},Bv=w.createContext(!0);function Vv(){throw Error(`A function wrapped in useEffectEvent can't be called during rendering.`)}var Hv=`use`in w.default?()=>{try{return w.use(Bv)}catch{return!1}}:()=>!1;function Uv(e){let t=w.useRef(Vv);return w.useInsertionEffect(()=>{t.current=e},[e]),(...e)=>{Hv()&&Vv();let n=t.current;return n(...e)}}var Wv=(e,t)=>{let n=zv(),r=Uv(t),{scope:i,event:a}=Cv(e);(0,w.useEffect)(()=>n.on({scope:i,event:a},r),[n,i,a,r])},Gv=e=>{let t=zv(),n=(0,w.useRef)(!1),r=n.current?null:e(t);return Q(()=>n.current?e(t):r),()=>(n.current=!0,e(t))},Kv=Object.freeze({});function qv({getItemState:e,children:t}){return Jv(t(Gv(e)))}var Jv=e=>{let t=typeof e==`object`&&e&&`type`in e?e:null,n=t?.type,r=t?.key;return(0,w.useMemo)(()=>t,[n,r,typeof t?.props==`object`&&t.props!=null&&Object.entries(t.props).length===0?Kv:t?.props])??e},Yv=({children:e,condition:t})=>Q(t)?e:null;Yv.displayName=`AuiIf`;var Xv=X_(e=>{if(e.key===void 0)throw Error(`tapClientResource: Element has no key`);return O_(nv(e))});function Zv(e,t){let n=k_(()=>e().map(e=>Xv(e)),t),r=T_(()=>Object.keys(n),[n]),i=T_(()=>n.reduce((e,t,n)=>(e[t.key]=n,e),{}),[n]);return{state:T_(()=>n.map(e=>e.state),[n]),get:e=>{if(`index`in e){if(e.index<0||e.index>=r.length)throw Error(`tapClientLookup: Index ${e.index} out of bounds (length: ${r.length})`);return n[e.index].methods}let t=i[e.key];if(t===void 0)throw Error(`tapClientLookup: Key "${e.key}" not found`);return n[t].methods}}}var Qv=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},$v=(e=>e?Qv(e):Qv),ey=e=>e;function ty(e,t=ey){let n=w.useSyncExternalStore(e.subscribe,w.useCallback(()=>t(e.getState()),[e,t]),w.useCallback(()=>t(e.getInitialState()),[e,t]));return w.useDebugValue(n),n}var ny=e=>{let t=$v(e),n=e=>ty(t,e);return Object.assign(n,t),n},ry=(e=>e?ny(e):ny),iy=r(((e,t)=>{var n=typeof Buffer<`u`,r=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,i=/"(?: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 a(e,t,a){a==null&&typeof t==`object`&&t&&(a=t,t=void 0),n&&Buffer.isBuffer(e)&&(e=e.toString()),e&&e.charCodeAt(0)===65279&&(e=e.slice(1));let s=JSON.parse(e,t);if(typeof s!=`object`||!s)return s;let c=a&&a.protoAction||`error`,l=a&&a.constructorAction||`error`;if(c===`ignore`&&l===`ignore`)return s;if(c!==`ignore`&&l!==`ignore`){if(r.test(e)===!1&&i.test(e)===!1)return s}else if(c!==`ignore`&&l===`ignore`){if(r.test(e)===!1)return s}else if(i.test(e)===!1)return s;return o(s,{protoAction:c,constructorAction:l,safe:a&&a.safe})}function o(e,{protoAction:t=`error`,constructorAction:n=`error`,safe:r}={}){let i=[e];for(;i.length;){let e=i;i=[];for(let a of e){if(t!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`__proto__`)){if(r===!0)return null;if(t===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.__proto__}if(n!==`ignore`&&Object.prototype.hasOwnProperty.call(a,`constructor`)&&a.constructor!==null&&typeof a.constructor==`object`&&Object.prototype.hasOwnProperty.call(a.constructor,`prototype`)){if(r===!0)return null;if(n===`error`)throw SyntaxError(`Object contains forbidden prototype property`);delete a.constructor}for(let e in a){let t=a[e];t&&typeof t==`object`&&i.push(t)}}}return e}function s(e,t,n){let{stackTraceLimit:r}=Error;Error.stackTraceLimit=0;try{return a(e,t,n)}finally{Error.stackTraceLimit=r}}function c(e,t){let{stackTraceLimit:n}=Error;Error.stackTraceLimit=0;try{return a(e,t,{safe:!0})}catch{return}finally{Error.stackTraceLimit=n}}t.exports=s,t.exports.default=s,t.exports.parse=s,t.exports.safeParse=c,t.exports.scan=o}));function ay(e){let t=[`ROOT`],n=-1,r=null,i=[],a;function o(){a!==void 0&&(i.push(JSON.parse(`"${a}"`)),a=void 0)}function s(e,i,a){switch(e){case`"`:n=i,t.pop(),t.push(a),t.push(`INSIDE_STRING`),o();break;case`f`:case`t`:case`n`:n=i,r=i,t.pop(),t.push(a),t.push(`INSIDE_LITERAL`);break;case`-`:t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),o();break;case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=i,t.pop(),t.push(a),t.push(`INSIDE_NUMBER`),o();break;case`{`:n=i,t.pop(),t.push(a),t.push(`INSIDE_OBJECT_START`),o();break;case`[`:n=i,t.pop(),t.push(a),t.push(`INSIDE_ARRAY_START`),o();break}}function c(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_COMMA`);break;case`}`:n=r,t.pop(),a=i.pop();break}}function l(e,r){switch(e){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),a=(Number(a)+1).toString();break;case`]`:n=r,t.pop(),a=i.pop();break}}for(let o=0;o<e.length;o++){let u=e[o];switch(t[t.length-1]){case`ROOT`:s(u,o,`FINISH`);break;case`INSIDE_OBJECT_START`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`),a=``;break;case`}`:n=o,t.pop(),a=i.pop();break}break;case`INSIDE_OBJECT_AFTER_COMMA`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_KEY`),a=``;break}break;case`INSIDE_OBJECT_KEY`:switch(u){case`"`:t.pop(),t.push(`INSIDE_OBJECT_AFTER_KEY`);break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`),a+=u;break;default:a+=u;break}break;case`INSIDE_OBJECT_AFTER_KEY`:switch(u){case`:`:t.pop(),t.push(`INSIDE_OBJECT_BEFORE_VALUE`);break}break;case`INSIDE_OBJECT_BEFORE_VALUE`:s(u,o,`INSIDE_OBJECT_AFTER_VALUE`);break;case`INSIDE_OBJECT_AFTER_VALUE`:c(u,o);break;case`INSIDE_STRING`:switch(u){case`"`:t.pop(),n=o,a=i.pop();break;case`\\`:t.push(`INSIDE_STRING_ESCAPE`);break;default:n=o}break;case`INSIDE_ARRAY_START`:switch(u){case`]`:n=o,t.pop(),a=i.pop();break;default:n=o,a=`0`,s(u,o,`INSIDE_ARRAY_AFTER_VALUE`);break}break;case`INSIDE_ARRAY_AFTER_VALUE`:switch(u){case`,`:t.pop(),t.push(`INSIDE_ARRAY_AFTER_COMMA`),a=(Number(a)+1).toString();break;case`]`:n=o,t.pop(),a=i.pop();break;default:n=o;break}break;case`INSIDE_ARRAY_AFTER_COMMA`:s(u,o,`INSIDE_ARRAY_AFTER_VALUE`);break;case`INSIDE_STRING_ESCAPE`:t.pop(),t[t.length-1]===`INSIDE_STRING`?n=o:t[t.length-1]===`INSIDE_OBJECT_KEY`&&(a+=u);break;case`INSIDE_NUMBER`:switch(u){case`0`:case`1`:case`2`:case`3`:case`4`:case`5`:case`6`:case`7`:case`8`:case`9`:n=o;break;case`e`:case`E`:case`-`:case`.`:break;case`,`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&c(u,o);break;case`}`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`&&c(u,o);break;case`]`:t.pop(),a=i.pop(),t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o);break;default:t.pop(),a=i.pop();break}break;case`INSIDE_LITERAL`:{let i=e.substring(r,o+1);!`false`.startsWith(i)&&!`true`.startsWith(i)&&!`null`.startsWith(i)?(t.pop(),t[t.length-1]===`INSIDE_OBJECT_AFTER_VALUE`?c(u,o):t[t.length-1]===`INSIDE_ARRAY_AFTER_VALUE`&&l(u,o)):n=o;break}}}let u=e.slice(0,n+1);for(let n=t.length-1;n>=0;n--)switch(t[n]){case`INSIDE_STRING`:u+=`"`;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`:u+=`}`;break;case`INSIDE_ARRAY_START`:case`INSIDE_ARRAY_AFTER_COMMA`:case`INSIDE_ARRAY_AFTER_VALUE`:u+=`]`;break;case`INSIDE_LITERAL`:{let t=e.substring(r,e.length);`true`.startsWith(t)?u+=`true`.slice(t.length):`false`.startsWith(t)?u+=`false`.slice(t.length):`null`.startsWith(t)&&(u+=`null`.slice(t.length))}}return[u,i]}var oy=n(iy(),1),sy=Symbol(`aui.parse-partial-json-object.meta`),cy=e=>e?.[sy],ly=e=>{if(e.length===0)return{[sy]:{state:`partial`,partialPath:[]}};try{let t=oy.default.parse(e);if(typeof t!=`object`||!t)throw Error(`argsText is expected to be an object`);return t[sy]={state:`complete`,partialPath:[]},t}catch{try{let[t,n]=ay(e),r=oy.default.parse(t);if(typeof r!=`object`||!r)throw Error(`argsText is expected to be an object`);return r[sy]={state:`partial`,partialPath:n},r}catch{return}}},uy=(e,t,n)=>{if(typeof e!=`object`||!e)return t.state;if(t.state===`complete`)return`complete`;if(n.length===0)return t.state;let[r,...i]=n;if(!Object.hasOwn(e,r))return`partial`;let[a,...o]=t.partialPath;if(r!==a)return`complete`;let s=e[r];return uy(s,{state:`partial`,partialPath:o},i)},dy=(e,t)=>{let n=cy(e);if(!n)throw Error(`unable to determine object state`);return uy(e,n,t.map(String))};async function*fy(){let e=this.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)break;yield n}}finally{e.releaseLock()}}function py(e){return e[Symbol.asyncIterator]??=fy,e}var my=()=>{let e,t,n=new Promise((n,r)=>{e=n,t=r});if(!e||!t)throw Error(`Failed to create promise`);return{promise:n,resolve:e,reject:t}},hy=()=>{let e=[],t=!1,n,r,i=i=>{i.promise||=i.reader.read().then(({done:a,value:o})=>{i.promise=void 0,a?(e.splice(e.indexOf(i),1),t&&e.length===0&&n.close()):n.enqueue(o),r?.resolve(),r=void 0}).catch(t=>{console.error(t),e.forEach(e=>{e.reader.cancel()}),e.length=0,n.error(t),r?.reject(t),r=void 0})};return{readable:new ReadableStream({start(e){n=e},pull(){return r=my(),e.forEach(e=>{i(e)}),r.promise},cancel(){e.forEach(e=>{e.reader.cancel()}),e.length=0}}),isSealed(){return t},seal(){t=!0,e.length===0&&n.close()},addStream(n){if(t)throw Error(`Cannot add streams after the run callback has settled.`);let r={reader:n.getReader()};e.push(r),i(r)},enqueue(e){this.addStream(new ReadableStream({start(t){t.enqueue(e),t.close()}}))}}},gy=class{_controller;_isClosed=!1;constructor(e){this._controller=e}append(e){return this._controller.enqueue({type:`text-delta`,path:[],textDelta:e}),this}close(){this._isClosed||(this._isClosed=!0,this._controller.enqueue({type:`part-finish`,path:[]}),this._controller.close())}},_y=e=>new ReadableStream({start(t){return e.start?.(new gy(t))},pull(t){return e.pull?.(new gy(t))},cancel(t){return e.cancel?.(t)}}),vy=()=>{let e;return[_y({start(t){e=t}}),e]},yy=class{_controller;_isClosed=!1;_mergeTask;constructor(e){this._controller=e;let t=_y({start:e=>{this._argsTextController=e}}),n=!1;this._mergeTask=t.pipeTo(new WritableStream({write:e=>{switch(e.type){case`text-delta`:n=!0,this._controller.enqueue(e);break;case`part-finish`:n||this._controller.enqueue({type:`text-delta`,textDelta:`{}`,path:[]}),this._controller.enqueue({type:`tool-call-args-text-finish`,path:[]});break;default:throw Error(`Unexpected chunk type: ${e.type}`)}}}))}get argsText(){return this._argsTextController}_argsTextController;async setResponse(e){this._argsTextController.close(),await Promise.resolve(),this._controller.enqueue({type:`result`,path:[],...e.artifact===void 0?{}:{artifact:e.artifact},result:e.result,isError:e.isError??!1,...e.modelContent===void 0?{}:{modelContent:e.modelContent},...e.messages===void 0?{}:{messages:e.messages}})}async close(){this._isClosed||(this._isClosed=!0,this._argsTextController.close(),await this._mergeTask,this._controller.enqueue({type:`part-finish`,path:[]}),this._controller.close())}},by=e=>new ReadableStream({start(t){return e.start?.(new yy(t))},pull(t){return e.pull?.(new yy(t))},cancel(t){return e.cancel?.(t)}}),xy=()=>{let e;return[by({start(t){e=t}}),e]},Sy=class{value=-1;up(){return++this.value}},Cy=class extends TransformStream{constructor(e){super({transform(t,n){n.enqueue({...t,path:[e,...t.path]})}})}};TransformStream;var wy=class extends TransformStream{constructor(e){let t=new Sy,n=new Map;super({transform(r,i){r.type===`part-start`&&r.path.length===0&&n.set(t.up(),e.up());let[a,...o]=r.path;if(a===void 0){i.enqueue(r);return}let s=n.get(a);if(s===void 0)throw Error(`Path not found`);i.enqueue({...r,path:[s,...o]})}})}},Ty=class extends TransformStream{constructor(e){super();let t=e(super.readable);Object.defineProperty(this,`readable`,{value:t,writable:!1})}},Ey=class extends TransformStream{constructor(){let e=[];super({transform(t,n){if(t.type===`part-start`){if(t.path.length!==0){n.error(Error(`Nested parts are not supported`));return}e.push(t.part),n.enqueue(t);return}if(t.type===`text-delta`||t.type===`result`||t.type===`part-finish`||t.type===`tool-call-args-text-finish`){if(t.path.length!==1){n.error(Error(`${t.type} chunks must have a path of length 1`));return}let r=t.path[0];if(r<0||r>=e.length){n.error(Error(`Invalid path index: ${r}`));return}let i=e[r];n.enqueue({...t,meta:i});return}n.enqueue(t)}})}},Dy=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},Oy=Dy(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),ky=class e{_state;_parentId;constructor(e){this._state=e||{merger:hy(),contentCounter:new Sy}}get __internal_isClosed(){return this._state.merger.isSealed()}__internal_getReadable(){return this._state.merger.readable}__internal_subscribeToClose(e){this._state.closeSubscriber=e}_addPart(e,t){this._state.append&&(this._state.append.controller.close(),this._state.append=void 0),this.enqueue({type:`part-start`,part:e,path:[]}),this._state.merger.addStream(t.pipeThrough(new Cy(this._state.contentCounter.value)))}merge(e){this._state.merger.addStream(e.pipeThrough(new wy(this._state.contentCounter)))}appendText(e){this._state.append?.kind!==`text`&&(this._state.append={kind:`text`,controller:this.addTextPart()}),this._state.append.controller.append(e)}appendReasoning(e){this._state.append?.kind!==`reasoning`&&(this._state.append={kind:`reasoning`,controller:this.addReasoningPart()}),this._state.append.controller.append(e)}addTextPart(){let[e,t]=vy();return this._addPart({type:`text`},e),t}addReasoningPart(){let[e,t]=vy();return this._addPart({type:`reasoning`},e),t}addToolCallPart(e){let t=typeof e==`string`?{toolName:e}:e,n=t.toolName,r=t.toolCallId??Oy(),[i,a]=xy();return this._addPart({type:`tool-call`,toolName:n,toolCallId:r,...this._parentId&&{parentId:this._parentId}},i),t.argsText!==void 0&&(a.argsText.append(t.argsText),a.argsText.close()),t.args!==void 0&&(a.argsText.append(JSON.stringify(t.args)),a.argsText.close()),t.response!==void 0&&a.setResponse(t.response),a}_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())}appendFile(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}appendData(e){this._addPart(this._withParentIdOption(e),this._finishedPartStream())}enqueue(e){this._state.merger.enqueue(e),e.type===`part-start`&&e.path.length===0&&this._state.contentCounter.up()}withParentId(t){let n=new e(this._state);return n._parentId=t,n}close(){this._state.append?.controller?.close(),this._state.merger.seal(),this._state.closeSubscriber?.()}};function Ay(e){let t=new ky;return(async()=>{try{await e(t)}catch(e){throw t.__internal_isClosed||t.enqueue({type:`error`,path:[],error:String(e)}),e}finally{t.__internal_isClosed||t.close()}})(),t.__internal_getReadable()}function jy(){let{resolve:e,promise:t}=my(),n;return[Ay(r=>(n=r,n.__internal_subscribeToClose(e),t)),n]}var My=c_(e=>({getState:()=>e})),Ny=c_(e=>{let[t]=v_(()=>({suggestions:(e??[]).map(e=>typeof e==`string`?{title:e,label:``,prompt:e}:{title:e.title,label:e.label,prompt:e.prompt})})),n=Zv(()=>t.suggestions.map((e,t)=>l_(t,My(e))),[t.suggestions]);return{getState:()=>t,suggestion:({index:e})=>n.get({index:e})}}),Py=Object.freeze({type:`complete`}),Fy=c_(({parts:e,getMessagePart:t})=>{let[n,r]=v_(!0),i=T_(()=>e[e.length-1]?.status??Py,[e]),a=T_(()=>({parts:e,collapsed:n,status:i}),[e,n,i]);return{getState:()=>a,setCollapsed:r,part:t}}),Iy=e=>Array.from(e).map(e=>e.getModelContext()).sort((e,t)=>(t.priority??0)-(e.priority??0)).reduce((e,t)=>{if(t.system&&(e.system?e.system+=`\n\n${t.system}`:e.system=t.system),t.tools)for(let[n,r]of Object.entries(t.tools)){let t=e.tools?.[n];if(t&&t!==r)throw Error(`You tried to define a tool with the name ${n}, but it already exists.`);e.tools||={},e.tools[n]=r}return t.config&&(e.config={...e.config,...t.config}),t.callSettings&&(e.callSettings={...e.callSettings,...t.callSettings}),e},{}),Ly=class{_providers=new Set;getModelContext(){return Iy(this._providers)}registerModelContextProvider(e){this._providers.add(e);let t=e.subscribe?.(()=>{this.notifySubscribers()});return this.notifySubscribers(),()=>{this._providers.delete(e),t?.(),this.notifySubscribers()}}_subscribers=new Set;notifySubscribers(){for(let e of this._subscribers)e()}subscribe(e){return this._subscribers.add(e),()=>this._subscribers.delete(e)}},Ry=1,zy=c_(()=>{let[e]=v_(()=>({version:Ry+1})),t=T_(()=>new Ly,[]);return{getState:()=>e,getModelContext:()=>t.getModelContext(),subscribe:e=>t.subscribe(e),register:e=>t.registerModelContextProvider(e)}}),By=c_(({toolkit:e,mcpApp:t})=>{let n=k_(()=>t?[l_(`mcpApp`,t)]:[],[t])[0],[r,i]=v_(()=>({tools:{}})),a=T_(()=>({tools:r.tools,mcpApp:n}),[r,n]),o=Ov(),s=E_((e,t)=>(i(n=>({tools:{...n.tools,[e]:[...n.tools[e]??[],t]}})),()=>{i(n=>({tools:{...n.tools,[e]:n.tools[e]?.filter(e=>e!==t)??[]}}))}),[]);return x_(()=>{if(!e)return;let t=[];for(let[n,r]of Object.entries(e))r.render&&t.push(s(n,r.render));let n=Object.entries(e).reduce((e,[t,n])=>{let{render:r,...i}=n;return e[t]=i,e},{});return t.push(o.current.modelContext().register({getModelContext:()=>({tools:n})})),()=>{t.forEach(e=>e())}},[e,s,o]),{getState:()=>a,setToolUI:s}});vv(By,(e,t)=>{!e.modelContext&&t.modelContext.source===null&&(e.modelContext=zy())});var Vy=c_(()=>{let[e,t]=v_(()=>({renderers:{},fallbacks:[]}));return{getState:()=>e,setDataUI:E_((e,n)=>(t(t=>({...t,renderers:{...t.renderers,[e]:[...t.renderers[e]??[],n]}})),()=>{t(t=>({...t,renderers:{...t.renderers,[e]:t.renderers[e]?.filter(e=>e!==n)??[]}}))}),[]),setFallbackDataUI:E_(e=>(t(t=>({...t,fallbacks:[...t.fallbacks,e]})),()=>{t(t=>({...t,fallbacks:t.fallbacks.filter(t=>t!==e)}))}),[])}}),Hy=Symbol.for(`aui.tool-response`),Uy=class e{get[Hy](){return!0}artifact;result;isError;modelContent;messages;constructor(e){e.artifact!==void 0&&(this.artifact=e.artifact),this.result=e.result,this.isError=e.isError??!1,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&&Hy in e}static toResponse(t){return t instanceof e?t:new e({result:t===void 0?`<no result>`:t})}};function Wy(e,t,n){try{let r=e();if(typeof r==`object`&&r&&`then`in r)return r.then(t,n);t(r)}catch(e){n(e)}}function Gy(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}var Ky=class{resolve;reject;disposed=!1;fieldPath;constructor(e,t,n){this.resolve=e,this.reject=t,this.fieldPath=n}update(e){if(!this.disposed)try{if(dy(e,this.fieldPath)===`complete`){let t=Gy(e,this.fieldPath);t!==void 0&&(this.resolve(t),this.dispose())}}catch(e){this.reject(e),this.dispose()}}dispose(){this.disposed=!0}},qy=class{controller;disposed=!1;fieldPath;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=Gy(e,this.fieldPath);t!==void 0&&this.controller.enqueue(t),dy(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Jy=class{controller;disposed=!1;fieldPath;lastValue=void 0;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=Gy(e,this.fieldPath);if(t!==void 0&&typeof t==`string`){let e=t.substring(this.lastValue?.length||0);this.lastValue=t,this.controller.enqueue(e)}dy(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Yy=class{controller;disposed=!1;fieldPath;processedIndexes=new Set;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=Gy(e,this.fieldPath);if(!Array.isArray(t))return;for(let n=0;n<t.length;n++)this.processedIndexes.has(n)||dy(e,[...this.fieldPath,n])===`complete`&&(this.controller.enqueue(t[n]),this.processedIndexes.add(n));dy(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},Xy=class{argTextDeltas;handles=new Set;args=ly(``);constructor(e){this.argTextDeltas=e,this.processStream()}async processStream(){try{let e=``,t=this.argTextDeltas.getReader();for(;;){let{value:n,done:r}=await t.read();if(r)break;e+=n;let i=ly(e);if(i!==void 0){this.args=i;for(let e of this.handles)e.update(i)}}}catch(e){console.error(`Error processing argument stream:`,e);for(let e of this.handles)e.dispose()}}get(...e){return new Promise((t,n)=>{let r=new Ky(t,n,e);if(this.args&&dy(this.args,e)===`complete`){let n=Gy(this.args,e);if(n!==void 0){t(n);return}}this.handles.add(r),r.update(this.args)})}streamValues(...e){let t=e;return py(new ReadableStream({start:e=>{let n=new qy(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof qy){e.dispose(),this.handles.delete(e);break}}}))}streamText(...e){let t=e;return py(new ReadableStream({start:e=>{let n=new Jy(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Jy){e.dispose(),this.handles.delete(e);break}}}))}forEach(...e){let t=e;return py(new ReadableStream({start:e=>{let n=new Yy(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof Yy){e.dispose(),this.handles.delete(e);break}}}))}},Zy=class{promise;constructor(e){this.promise=e}get(){return this.promise}},Qy=class{args;response;writable;resolve;argsText=``;constructor(){let e=new TransformStream;this.writable=e.writable,this.args=new Xy(e.readable);let{promise:t,resolve:n}=my();this.resolve=n,this.response=new Zy(t)}async appendArgsTextDelta(e){let t=this.writable.getWriter();try{await t.write(e)}catch(e){console.warn(e)}finally{t.releaseLock()}this.argsText+=e}setResponse(e){this.resolve(e)}result={get:async()=>(await this.response.get()).result}},$y=class extends Ty{constructor(e){let t=new Map,n=new Map;super(r=>{let i=new TransformStream({transform(r,i){switch((r.type!==`part-finish`||r.meta.type!==`tool-call`)&&i.enqueue(r),r.type){case`part-start`:if(r.part.type===`tool-call`){let t=new Qy;n.set(r.part.toolCallId,t),e.streamCall({reader:t,toolCallId:r.part.toolCallId,toolName:r.part.toolName})}break;case`text-delta`:if(r.meta.type===`tool-call`){let e=r.meta.toolCallId,t=n.get(e);if(!t)throw Error(`No controller found for tool call`);t.appendArgsTextDelta(r.textDelta)}break;case`result`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:e}=r.meta,t=n.get(e);if(!t)throw Error(`No controller found for tool call`);t.setResponse(new Uy({result:r.result,artifact:r.artifact,isError:r.isError,modelContent:r.modelContent}));break}case`tool-call-args-text-finish`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:a,toolName:o}=r.meta,s=n.get(a);if(!s)throw Error(`No controller found for tool call`);let c=!1,l=Wy(()=>{let t;try{t=oy.default.parse(s.argsText)}catch(e){throw Error(`Function parameter parsing failed. ${JSON.stringify(e.message)}`)}let n=e.execute({toolCallId:a,toolName:o,args:t});return n!==void 0&&(c=!0,e.onExecutionStart?.(a,o)),n},t=>{if(c&&e.onExecutionEnd?.(a,o),t===void 0)return;let n=new Uy({artifact:t.artifact,result:t.result,isError:t.isError,messages:t.messages,modelContent:t.modelContent});s.setResponse(n),i.enqueue({type:`result`,path:r.path,...n})},t=>{c&&e.onExecutionEnd?.(a,o);let n=new Uy({result:String(t),isError:!0});s.setResponse(n),i.enqueue({type:`result`,path:r.path,...n})});l&&t.set(a,l);break}case`part-finish`:{if(r.meta.type!==`tool-call`)break;let{toolCallId:e}=r.meta,a=t.get(e);a?a.then(()=>{t.delete(e),n.delete(e),i.enqueue(r)}):i.enqueue(r)}}},async flush(){await Promise.all(t.values())}});return r.pipeThrough(new Ey).pipeThrough(i)})}},eb=e=>typeof e==`object`&&!!e&&`~standard`in e&&e[`~standard`].version===1;function tb(e,t,n,r){let i=e?.[n.toolName];return i?.execute?(async e=>{if(t.aborted)return new Uy({result:`Tool execution was cancelled.`,isError:!0});let a=e;if(eb(i.parameters)){let e=i.parameters[`~standard`].validate(n.args);e instanceof Promise&&(e=await e),e.issues&&(a=i.experimental_onSchemaValidationError??(()=>{throw Error(`Function parameter validation failed. ${JSON.stringify(e.issues)}`)}))}let o=new Promise(e=>{let n=()=>{queueMicrotask(()=>{queueMicrotask(()=>{e(new Uy({result:`Tool execution was cancelled.`,isError:!0}))})})};t.aborted?n():t.addEventListener(`abort`,n,{once:!0})}),s=(async()=>{let e=await a(n.args,{toolCallId:n.toolCallId,abortSignal:t,human:e=>r(n.toolCallId,e)}),o=Uy.toResponse(e);if(i.toModelOutput&&!o.isError&&o.modelContent===void 0)try{let e=await i.toModelOutput({toolCallId:n.toolCallId,input:n.args,output:o.result});return new Uy({result:o.result,artifact:o.artifact,isError:o.isError,messages:o.messages,modelContent:e})}catch(e){console.warn(`[assistant-stream] tool "${n.toolName}" toModelOutput threw; falling back to default projection.`,e)}return o})();return Promise.race([s,o])})(i.execute):void 0}function nb(e,t,n,r,i){e?.[r.toolName]?.streamCall?.(n,{toolCallId:r.toolCallId,abortSignal:t,human:e=>i(r.toolCallId,e)})}function rb(e,t,n,r){let i=typeof e==`function`?e:()=>e,a=typeof t==`function`?t:()=>t;return new $y({execute:e=>tb(i(),a(),e,n),streamCall:({reader:e,...t})=>nb(i(),a(),e,t,n),onExecutionStart:r?.onExecutionStart,onExecutionEnd:r?.onExecutionEnd})}var ib=e=>{let[,t]=v_(e.getState);return x_(()=>(t(e.getState()),e.subscribe(()=>{t(e.getState())})),[e]),e.getState()},ab=c_(({runtime:e})=>{let t=ib(e);return{getState:()=>t,remove:e.remove,__internal_getRuntime:()=>e}}),ob=c_(({runtime:e})=>{let t=ib(e);return{getState:()=>t,addToolResult:t=>e.addToolResult(t),resumeToolCall:t=>e.resumeToolCall(t),__internal_getRuntime:()=>e}}),sb=c_(({runtime:e,index:t})=>O_(ab({runtime:T_(()=>e.getAttachmentByIndex(t),[e,t])}))),cb=c_(({threadIdRef:e,messageIdRef:t,runtime:n})=>{let r=ib(n),i=kv();x_(()=>{let r=[];for(let a of[`send`,`attachmentAdd`]){let o=n.unstable_on(a,()=>{i(`composer.${a}`,{threadId:e.current,...t&&{messageId:t.current}})});r.push(o)}return r.push(n.unstable_on(`attachmentAddError`,n=>{i(`composer.attachmentAddError`,{threadId:e.current,...t&&{messageId:t.current},...n.attachmentId&&{attachmentId:n.attachmentId},reason:n.reason,message:n.message})})),()=>{for(let e of r)e()}},[n,i,e,t]);let a=Zv(()=>r.attachments.map((e,t)=>l_(e.id,sb({runtime:n,index:t}))),[r.attachments,n]),o=T_(()=>({text:r.text,role:r.role,attachments:a.state,runConfig:r.runConfig,isEditing:r.isEditing,canCancel:r.canCancel,canSend:r.canSend,attachmentAccept:r.attachmentAccept,isEmpty:r.isEmpty,type:r.type??`thread`,dictation:r.dictation,quote:r.quote,queue:[]}),[r,a.state]);return{getState:()=>o,setText:n.setText,setRole:n.setRole,setRunConfig:n.setRunConfig,addAttachment:n.addAttachment,reset:n.reset,clearAttachments:n.clearAttachments,send:n.send,cancel:n.cancel,beginEdit:n.beginEdit??(()=>{throw Error(`beginEdit is not supported in this runtime`)}),startDictation:n.startDictation,stopDictation:n.stopDictation,setQuote:n.setQuote,attachment:e=>`id`in e?a.get({key:e.id}):a.get(e),queueItem:()=>{throw Error(`Queue is not supported in this runtime`)},__internal_getRuntime:()=>n}}),lb=c_(({runtime:e,index:t})=>O_(ab({runtime:T_(()=>e.getAttachmentByIndex(t),[e,t])}))),ub=c_(({runtime:e,index:t})=>O_(ob({runtime:T_(()=>e.getMessagePartByIndex(t),[e,t])}))),db=c_(({runtime:e,threadIdRef:t})=>{let n=ib(e),[r,i]=v_(!1),[a,o]=v_(!1),s=T_(()=>({get current(){return e.getState().id}}),[e]),c=rv(cb({runtime:e.composer,threadIdRef:t,messageIdRef:s})),l=Zv(()=>n.content.map((t,n)=>l_(`toolCallId`in t&&t.toolCallId!=null?`toolCallId-${t.toolCallId}`:`index-${n}`,ub({runtime:e,index:n}))),[n.content,e]),u=Zv(()=>(n.attachments??[]).map((t,n)=>l_(t.id,lb({runtime:e,index:n}))),[n.attachments,e]),d=T_(()=>({...n,parts:l.state,composer:c.state,isCopied:r,isHovering:a}),[n,l.state,c.state,r,a]);return{getState:()=>d,composer:()=>c.methods,reload:t=>e.reload(t),speak:()=>e.speak(),stopSpeaking:()=>e.stopSpeaking(),submitFeedback:t=>e.submitFeedback(t),switchToBranch:t=>e.switchToBranch(t),getCopyText:()=>e.unstable_getCopyText(),part:e=>`index`in e?l.get({index:e.index}):l.get({key:`toolCallId-${e.toolCallId}`}),attachment:e=>`id`in e?u.get({key:e.id}):u.get(e),setIsCopied:i,setIsHovering:o,__internal_getRuntime:()=>e}}),fb=c_(({runtime:e,id:t,threadIdRef:n})=>O_(db({runtime:T_(()=>e.getMessageById(t),[e,t]),threadIdRef:n}))),pb=c_(({runtime:e})=>{let t=ib(e),n=kv();x_(()=>{let t=[];for(let r of[`runStart`,`runEnd`,`initialize`,`modelContextUpdate`]){let i=e.unstable_on(r,()=>{let t=e.getState()?.threadId||`unknown`;n(`thread.${r}`,{threadId:t})});t.push(i)}return()=>{for(let e of t)e()}},[e,n]);let r=T_(()=>({get current(){return e.getState().threadId}}),[e]),i=rv(cb({runtime:e.composer,threadIdRef:r})),a=Zv(()=>t.messages.map(t=>l_(t.id,fb({runtime:e,id:t.id,threadIdRef:r}))),[t.messages,e,r]),o=T_(()=>({isEmpty:a.state.length===0&&!t.isLoading,isDisabled:t.isDisabled,isLoading:t.isLoading,isRunning:t.isRunning,capabilities:t.capabilities,state:t.state,suggestions:t.suggestions,extras:t.extras,speech:t.speech,voice:t.voice,composer:i.state,messages:a.state}),[t,a,i.state]);return{getState:()=>o,composer:()=>i.methods,append:e.append,startRun:e.startRun,resumeRun:e.resumeRun,cancelRun:e.cancelRun,getModelContext:e.getModelContext,export:e.export,import:e.import,reset:e.reset,stopSpeaking:e.stopSpeaking,connectVoice:e.connectVoice,disconnectVoice:e.disconnectVoice,getVoiceVolume:e.getVoiceVolume,subscribeVoiceVolume:e.subscribeVoiceVolume,muteVoice:e.muteVoice,unmuteVoice:e.unmuteVoice,message:e=>`id`in e?a.get({key:e.id}):a.get(e),__internal_getRuntime:()=>e}}),mb=c_(({runtime:e})=>{let t=ib(e),n=kv();return x_(()=>{let t=[];for(let r of[`switchedTo`,`switchedAway`]){let i=e.unstable_on(r,()=>{n(`threadListItem.${r}`,{threadId:e.getState().id})});t.push(i)}return()=>{for(let e of t)e()}},[e,n]),{getState:()=>t,switchTo:e.switchTo,rename:e.rename,archive:e.archive,unarchive:e.unarchive,delete:e.delete,generateTitle:e.generateTitle,initialize:e.initialize,detach:e.detach,__internal_getRuntime:()=>e}}),hb=c_(({runtime:e,id:t})=>O_(mb({runtime:T_(()=>e.getItemById(t),[e,t])}))),gb=c_(({runtime:e,__internal_assistantRuntime:t})=>{let n=ib(e),r=rv(pb({runtime:e.main})),i=Zv(()=>Object.keys(n.threadItems).map(t=>l_(t,hb({runtime:e,id:t}))),[n.threadItems,e]),a=T_(()=>({mainThreadId:n.mainThreadId,newThreadId:n.newThreadId??null,isLoading:n.isLoading,isLoadingMore:n.isLoadingMore,hasMore:n.hasMore,threadIds:n.threadIds,archivedThreadIds:n.archivedThreadIds,threadItems:i.state,main:r.state}),[n,i.state,r.state]);return{getState:()=>a,thread:()=>r.methods,item:e=>{if(e===`main`)return i.get({key:a.mainThreadId});if(`id`in e)return i.get({key:e.id});let{index:t,archived:n=!1}=e,r=n?a.archivedThreadIds[t]:a.threadIds[t];return i.get({key:r})},switchToThread:async t=>{await e.switchToThread(t)},switchToNewThread:async()=>{await e.switchToNewThread()},getLoadThreadsPromise:()=>e.getLoadThreadsPromise(),reload:()=>e.reload(),loadMore:()=>e.loadMore(),__internal_getAssistantRuntime:()=>t}}),_b=c_(e=>{let t=Ov();return x_(()=>e.registerModelContextProvider(t.current.modelContext()),[e,t]),O_(gb({runtime:e.threads,__internal_assistantRuntime:e}))}),vb=(e,t)=>{e.thread??=gv({source:`threads`,query:{type:`main`},get:e=>e.threads().thread(`main`)}),e.threadListItem??=gv({source:`threads`,query:{type:`main`},get:e=>e.threads().item(`main`)}),e.composer??=gv({source:`thread`,query:{},get:e=>e.threads().thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=zy()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=Ny())},yb=({index:e,children:t})=>(0,q.jsx)(hv,{value:zv({message:gv({source:`thread`,query:{type:`index`,index:e},get:t=>t.thread().message({index:e})}),composer:gv({source:`message`,query:{},get:t=>t.thread().message({index:e}).composer()})}),children:t}),bb=({index:e,children:t})=>(0,q.jsx)(hv,{value:zv({part:gv({source:`message`,query:{type:`index`,index:e},get:t=>t.message().part({index:e})})}),children:t}),xb=c_(({text:e,isRunning:t})=>{let n=T_(()=>({type:`text`,text:e,status:t?{type:`running`}:{type:`complete`}}),[e,t]);return{getState:()=>n,addToolResult:()=>{throw Error(`Not supported`)},resumeToolCall:()=>{throw Error(`Not supported`)}}}),Sb=({text:e,isRunning:t=!1,children:n})=>(0,q.jsx)(hv,{value:zv({part:xb({text:e,isRunning:t})}),children:n}),Cb=({startIndex:e,endIndex:t,children:n})=>{let r=Q(e=>e.message.parts).slice(e,t+1),i=zv();return(0,q.jsx)(hv,{value:zv({chainOfThought:Fy({parts:r,getMessagePart:({index:t})=>{if(t<0||t>=r.length)throw Error(`ChainOfThought part index ${t} is out of bounds (0..${r.length-1})`);return i.message().part({index:e+t})}})}),children:n})},wb=Symbol(`skip-update`);function Tb(e,t){if(e===void 0&&t===void 0)return!0;if(e===void 0||t===void 0)return!1;for(let n of Object.keys(e)){let r=e[n],i=t[n];if(!Object.is(r,i))return!1}return!0}var Eb=class{_subscribers=new Set;subscribe(e){return this._subscribers.add(e),()=>this._subscribers.delete(e)}waitForUpdate(){return new Promise(e=>{let t=this.subscribe(()=>{t(),e()})})}_notifySubscribers(){let e=[];for(let t of this._subscribers)try{t()}catch(t){e.push(t)}if(e.length>0){if(e.length===1)throw e[0];for(let t of e)console.error(t);throw AggregateError(e)}}},Db=class{_subscriptions=new Set;_connection;get isConnected(){return!!this._connection}notifySubscribers(e){for(let t of this._subscriptions)t(e)}_updateConnection(){if(this._subscriptions.size>0){if(this._connection)return;this._connection=this._connect()}else this._connection?.(),this._connection=void 0}subscribe(e){return this._subscriptions.add(e),this._updateConnection(),()=>{this._subscriptions.delete(e),this._updateConnection()}}},Ob=class extends Db{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e;let t=e.getState();if(t===wb)throw Error(`Entry not available in the store`);this._previousState=t}_previousState;getState=()=>(this.isConnected||this._syncState(),this._previousState);_syncState(){let e=this.binding.getState();return e===wb||Tb(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){return this.binding.subscribe(()=>{this._syncState()&&this.notifySubscribers()})}},kb=class extends Db{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}_previousStateDirty=!0;_previousState;getState=()=>{if(!this.isConnected||this._previousStateDirty){let e=this.binding.getState();e!==wb&&(this._previousState=e),this._previousStateDirty=!1}if(this._previousState===void 0)throw Error(`Entry not available in the store`);return this._previousState};_connect(){return this.binding.subscribe(()=>{this._previousStateDirty=!0,this.notifySubscribers()})}},Ab=class extends Db{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}getState(){return this.binding.getState()}outerSubscribe(e){return this.binding.subscribe(e)}_connect(){let e=()=>{this.notifySubscribers()},t=this.binding.getState(),n=t?.subscribe(e),r=this.outerSubscribe(()=>{let r=this.binding.getState();r!==t&&(t=r,n?.(),n=r?.subscribe(e),e())});return()=>{r?.(),n?.()}}},jb=class extends Db{config;constructor(e){super(),this.config=e}getState(){return this.config.binding.getState()}outerSubscribe(e){return this.config.binding.subscribe(e)}_connect(){let e=e=>{this.notifySubscribers(e)},t=this.config.binding.getState(),n=t?.unstable_on(this.config.event,e),r=this.outerSubscribe(()=>{let r=this.config.binding.getState();r!==t&&(t=r,n?.(),n=r?.unstable_on(this.config.event,e))});return()=>{r?.(),n?.()}}},Mb=class{_contextProvider=new Ly;registerModelContextProvider(e){return this._contextProvider.registerModelContextProvider(e)}getModelContextProvider(){return this._contextProvider}},Nb=e=>e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
57
57
|
|
|
58
58
|
`),Pb=Dy(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),Fb=`__optimistic__`,Ib=()=>`${Fb}${Pb()}`,Lb=Symbol(`autoStatus`),Rb=Object.freeze(Object.assign({type:`running`},{[Lb]:!0})),zb=Object.freeze(Object.assign({type:`complete`,reason:`unknown`},{[Lb]:!0})),Bb=Object.freeze(Object.assign({type:`requires-action`,reason:`tool-calls`},{[Lb]:!0})),Vb=Object.freeze(Object.assign({type:`requires-action`,reason:`interrupt`},{[Lb]:!0})),Hb=e=>e[Lb]===!0,Ub=(e,t,n,r,i)=>e&&i?Object.assign({type:`incomplete`,reason:`error`,error:i},{[Lb]:!0}):e&&t?Rb:n?Vb:r?Bb:zb,Wb=(e,t)=>{if(e.startsWith(`data-`))return{type:`data`,name:e.substring(5),data:t}},Gb=(e,t,n)=>{let{role:r,id:i,createdAt:a,attachments:o,status:s,metadata:c}=e,l={id:i??t,createdAt:a??new Date},u=typeof e.content==`string`?[{type:`text`,text:e.content}]:e.content,d=({image:e,...t})=>e.match(/^data:image\/(png|jpeg|jpg|gif|webp);base64,(.*)$/)?{...t,image:e}:(console.warn(`Invalid image data format detected`),null);if(r!==`user`&&o?.length)throw Error(`attachments are only supported for user messages`);if(r!==`assistant`&&s)throw Error(`status is only supported for assistant messages`);if(r!==`assistant`&&c?.steps)throw Error(`metadata.steps is only supported for assistant messages`);switch(r){case`assistant`:return{...l,role:r,content:u.map(e=>{let t=e.type;switch(t){case`text`:case`reasoning`:return e.text.trim().length===0?null:e;case`file`:case`source`:return e;case`image`:return d(e);case`data`:return e;case`tool-call`:{let{parentId:t,messages:n,...r}=e,i={...r,toolCallId:e.toolCallId??`tool-${Pb()}`,...t!==void 0&&{parentId:t},...n!==void 0&&{messages:n}};return e.args?{...i,args:e.args,argsText:e.argsText??JSON.stringify(e.args)}:{...i,args:ly(e.argsText??``)??{},argsText:e.argsText??``}}default:{let n=Wb(t,e.data);if(n)return n;throw Error(`Unsupported assistant message part type: ${t}`)}}}).filter(e=>!!e),status:s??n,metadata:{unstable_state:c?.unstable_state??null,unstable_annotations:c?.unstable_annotations??[],unstable_data:c?.unstable_data??[],custom:c?.custom??{},steps:c?.steps??[],...c?.timing&&{timing:c.timing},...c?.submittedFeedback&&{submittedFeedback:c.submittedFeedback}}};case`user`:return{...l,role:r,content:u.map(e=>{let t=e.type;switch(t){case`text`:case`image`:case`audio`:case`file`:case`data`:return e;default:{let n=Wb(t,e.data);if(n)return n;throw Error(`Unsupported user message part type: ${t}`)}}}),attachments:(o??[]).map(e=>({...e,content:e.content.map(e=>Wb(e.type,e.data)??e)})),metadata:{custom:c?.custom??{}}};case`system`:if(u.length!==1||u[0].type!==`text`)throw Error(`System messages must have exactly one text message part.`);return{...l,role:r,content:u,metadata:{custom:c?.custom??{}}};default:throw Error(`Unknown message role: ${r}`)}},Kb={fromArray:e=>{let t=e.map(e=>Gb(e,Pb(),Ub(!1,!1,!1,!1,void 0)));return{messages:t.map((e,n)=>({parentId:n>0?t[n-1].id:null,message:e}))}},fromBranchableArray:(e,t)=>{let n=Ub(!1,!1,!1,!1,void 0);return{...t?.headId===void 0?void 0:{headId:t.headId},messages:e.map(({message:e,parentId:t})=>{if(!e.id)throw Error(`ExportedMessageRepository.fromBranchableArray: Each message must have an 'id' field set.`);return{parentId:t,message:Gb(e,e.id,n)}})}}},qb=e=>e.next?qb(e.next):`current`in e?e:null,Jb=class{func;_value=null;constructor(e){this.func=e}get value(){return this._value===null&&(this._value=this.func()),this._value}dirty(){this._value=null}},Yb=class{messages=new Map;head=null;root={children:[],next:null};updateLevels(e,t){e.level=t;for(let n of e.children){let e=this.messages.get(n);e&&this.updateLevels(e,t+1)}}performOp(e,t,n){let r=t.prev??this.root,i=e??this.root;if(!(n===`relink`&&r===i)){if(n!==`link`&&(r.children=r.children.filter(e=>e!==t.current.id),r.next===t)){let e=r.children.at(-1),t=e?this.messages.get(e):null;if(t===void 0)throw Error(`MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.`);r.next=t}if(n!==`cut`){for(let n=e;n;n=n.prev)if(n.current.id===t.current.id)throw Error(`MessageRepository(performOp/link): 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.`);i.children=[...i.children,t.current.id],(qb(t)===this.head||i.next===null)&&(i.next=t),t.prev=e;let n=e?e.level+1:0;this.updateLevels(t,n)}}}_messages=new Jb(()=>{let e=Array((this.head?.level??-1)+1);for(let t=this.head;t;t=t.prev)e[t.level]=t.current;return e});get headId(){return this.head?.current.id??null}getMessages(e){if(e===void 0||e===this.head?.current.id)return this._messages.value;let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(getMessages): Head message not found. This is likely an internal bug in assistant-ui.`);let n=Array(t.level+1);for(let e=t;e;e=e.prev)n[e.level]=e.current;return n}addOrUpdateMessage(e,t){let n=this.messages.get(t.id),r=e?this.messages.get(e):null;if(r===void 0)throw Error(`MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.`);if(n){n.current=t,this.performOp(r,n,`relink`),this._messages.dirty();return}let i={prev:r,current:t,next:null,children:[],level:r?r.level+1:0};this.messages.set(t.id,i),this.performOp(r,i,`link`),this.head===r&&(this.head=i),this._messages.dirty()}getMessage(e){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui.`);return{parentId:t.prev?.current.id??null,message:t.current,index:t.level}}appendOptimisticMessage(e,t){let n;do n=Ib();while(this.messages.has(n));return this.addOrUpdateMessage(e,Gb(t,n,{type:`running`})),n}deleteMessage(e,t){let n=this.messages.get(e);if(!n)throw Error(`MessageRepository(deleteMessage): Message not found. This is likely an internal bug in assistant-ui.`);let r=t===void 0?n.prev:t===null?null:this.messages.get(t);if(r===void 0)throw Error(`MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.`);for(let e of n.children){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.`);this.performOp(r,t,`relink`)}this.performOp(null,n,`cut`),this.messages.delete(e),this.head===n&&(this.head=qb(r??this.root)),this._messages.dirty()}getBranches(e){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.`);let{children:n}=t.prev??this.root;return n}switchToBranch(e){let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.`);let n=t.prev??this.root;n.next=t,this.head=qb(t),this._messages.dirty()}resetHead(e){if(e===null){this.clear();return}let t=this.messages.get(e);if(!t)throw Error(`MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.`);if(t.children.length>0){let e=t=>{for(let n of t.children){let t=this.messages.get(n);t&&(e(t),this.messages.delete(n))}};e(t),t.children=[],t.next=null}this.head=t;for(let e=t;e;e=e.prev)e.prev?e.prev.next=e:this.root.next=e;this._messages.dirty()}clear(){this.messages.clear(),this.head=null,this.root={children:[],next:null},this._messages.dirty()}export(){let e=[];for(let[,t]of this.messages)e.push({message:t.current,parentId:t.prev?.current.id??null});return{headId:this.head?.current.id??null,messages:e}}import({headId:e,messages:t}){for(let{message:e,parentId:n}of t)this.addOrUpdateMessage(n,e);this.resetHead(e??t.at(-1)?.message.id??null)}};function Xb(e,t){if(t===`*`)return!0;let n=t.split(`,`).map(e=>e.trim().toLowerCase()),r=`.${e.name.split(`.`).pop().toLowerCase()}`,i=e.type.toLowerCase();for(let e of n){if(e.startsWith(`.`)&&e===r||e.includes(`/`)&&e===i)return!0;if(e.endsWith(`/*`)){let t=e.split(`/`)[0];if(i.startsWith(`${t}/`))return!0}}return!1}function Zb(e,t){return e.length===t.length?e.every((e,n)=>e.id===t[n].id):!1}function Qb(e){let t=Pb();return e.type===`image`?{id:t,type:`image`,name:e.filename??`image`,content:[e],status:{type:`complete`}}:e.type===`file`?{id:t,type:`document`,name:e.filename??`document`,contentType:e.mimeType,content:[e],status:{type:`complete`}}:e.type===`audio`?{id:t,type:`audio`,name:`audio.${e.audio.format}`,contentType:`audio/${e.audio.format}`,content:[e],status:{type:`complete`}}:{id:t,type:`data`,name:e.name,content:[e],status:{type:`complete`}}}function $b(e){let t=[];for(let n of e)n.type!==`text`&&t.push(Qb(n));return t}var ex=e=>e.status.type===`complete`,tx=class extends Eb{isEditing=!0;get attachmentAccept(){return this.getAttachmentAdapter()?.accept??`*`}_attachments=[];get attachments(){return this._attachments}setAttachments(e){this._attachments=e,this._notifySubscribers()}get isEmpty(){return!this.text.trim()&&!this.attachments.length}_text=``;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(e){this._quote!==e&&(this._quote=e,this._notifySubscribers())}setText(e){if(this._text!==e){if(this._text=e,this._dictation){this._dictationBaseText=e,this._currentInterimText=``;let{status:t,inputDisabled:n}=this._dictation;this._dictation=n?{status:t,inputDisabled:n}:{status:t}}this._notifySubscribers()}}setRole(e){this._role!==e&&(this._role=e,this._notifySubscribers())}setRunConfig(e){this._runConfig!==e&&(this._runConfig=e,this._notifySubscribers())}_emptyTextAndAttachments(){this._attachments=[],this._text=``,this._notifySubscribers()}async _onClearAttachments(){let e=this.getAttachmentAdapter();if(e){let t=this._attachments.filter(e=>!ex(e));await Promise.all(t.map(t=>e.remove(t)))}}async reset(){if(this._attachments.length===0&&this._text===``&&this._role===`user`&&Object.keys(this._runConfig).length===0&&this._quote===void 0)return;this._role=`user`,this._runConfig={},this._quote=void 0;let e=this._onClearAttachments();this._emptyTextAndAttachments(),await e}async clearAttachments(){let e=this._onClearAttachments();this.setAttachments([]),await e}async send(e){if(!this.canSend)return;this._dictationSession&&(this._dictationSession.cancel(),this._cleanupDictation());let t=this.getAttachmentAdapter(),n=this.attachments.length>0?Promise.all(this.attachments.map(async e=>{if(ex(e))return e;if(!t)throw Error(`Attachments are not supported`);return await t.send(e)})):[],r=this.text,i=this._quote;this._quote=void 0,this._emptyTextAndAttachments();let a={createdAt:new Date,role:this.role,content:r?[{type:`text`,text:r}]:[],attachments:await n,runConfig:this.runConfig,metadata:{custom:{...i?{quote:i}:{}}}};this.handleSend(a,e),this._notifyEventSubscribers(`send`,{})}cancel(){this.handleCancel()}async addAttachment(e){if(!(e instanceof File)){let t=this.getAttachmentAdapter();if(t&&!Xb({name:e.name,type:e.contentType??``},t.accept)){let n=`File type ${e.contentType||`unknown`} is not accepted. Accepted types: ${t.accept}`,r=Error(n);throw this._safeEmitAttachmentAddError(`not-accepted`,n,void 0,r),r}let n={id:e.id??Pb(),type:e.type??`document`,name:e.name,contentType:e.contentType,content:e.content,status:{type:`complete`}};this._attachments=[...this._attachments,n],this._notifySubscribers(),this._notifyEventSubscribers(`attachmentAdd`,{});return}let t=e=>{let t=this._attachments.findIndex(t=>t.id===e.id);t===-1?this._attachments=[...this._attachments,e]:this._attachments=[...this._attachments.slice(0,t),e,...this._attachments.slice(t+1)],this._notifySubscribers()},n=this.getAttachmentAdapter();if(!n){let e=`Attachments are not supported`,t=Error(e);throw this._safeEmitAttachmentAddError(`no-adapter`,e,void 0,t),t}if(!Xb({name:e.name,type:e.type},n.accept)){let t=`File type ${e.type||`unknown`} is not accepted. Accepted types: ${n.accept}`,r=Error(t);throw this._safeEmitAttachmentAddError(`not-accepted`,t,void 0,r),r}let r;try{let i=n.add({file:e});if(Symbol.asyncIterator in i)for await(let e of i)r=e,t(e);else r=await i,t(r)}catch(e){throw r&&t({...r,status:{type:`incomplete`,reason:`error`}}),this._safeEmitAttachmentAddError(`adapter-error`,e instanceof Error?e.message:String(e),r?.id,e instanceof Error?e:void 0),e}r?.status.type===`incomplete`&&r.status.reason===`error`?this._safeEmitAttachmentAddError(`adapter-error`,`Attachment upload did not complete successfully.`,r?.id):this._notifyEventSubscribers(`attachmentAdd`,{})}_safeEmitAttachmentAddError(e,t,n,r){try{this._notifyEventSubscribers(`attachmentAddError`,{reason:e,message:t,...n!==void 0&&{attachmentId:n},...r!==void 0&&{error:r}})}catch(e){console.error(`[assistant-ui] attachmentAddError subscriber threw:`,e)}}async removeAttachment(e){let t=this._attachments.findIndex(t=>t.id===e);if(t===-1)throw Error(`Attachment not found`);let n=this._attachments[t];if(!ex(n)){let e=this.getAttachmentAdapter();if(!e)throw Error(`Attachments are not supported`);await e.remove(n)}this._attachments=this._attachments.filter(t=>t.id!==e),this._notifySubscribers()}_dictation;_dictationSession;_dictationUnsubscribes=[];_dictationBaseText=``;_currentInterimText=``;_dictationSessionIdCounter=0;_activeDictationSessionId;_isCleaningDictation=!1;get dictation(){return this._dictation}_isActiveSession(e,t){return this._activeDictationSessionId===e&&this._dictationSession===t}startDictation(){let e=this.getDictationAdapter();if(!e)throw Error(`Dictation adapter not configured`);if(this._dictationSession){for(let e of this._dictationUnsubscribes)e();this._dictationUnsubscribes=[],this._dictationSession.stop().catch(()=>{}),this._dictationSession=void 0}let t=e.disableInputDuringDictation??!1;this._dictationBaseText=this._text,this._currentInterimText=``;let n=e.listen();this._dictationSession=n;let r=++this._dictationSessionIdCounter;this._activeDictationSessionId=r,this._dictation={status:n.status,inputDisabled:t},this._notifySubscribers();let i=n.onSpeech(e=>{if(!this._isActiveSession(r,n))return;let t=e.isFinal!==!1,i=this._dictationBaseText&&!this._dictationBaseText.endsWith(` `)&&e.transcript?` `:``;if(t){if(this._dictationBaseText=this._dictationBaseText+i+e.transcript,this._currentInterimText=``,this._text=this._dictationBaseText,this._dictation){let{transcript:e,...t}=this._dictation;this._dictation=t}this._notifySubscribers()}else this._currentInterimText=i+e.transcript,this._text=this._dictationBaseText+this._currentInterimText,this._dictation&&={...this._dictation,transcript:e.transcript},this._notifySubscribers()});this._dictationUnsubscribes.push(i);let a=n.onSpeechStart(()=>{this._isActiveSession(r,n)&&(this._dictation={status:{type:`running`},inputDisabled:t,...this._dictation?.transcript&&{transcript:this._dictation.transcript}},this._notifySubscribers())});this._dictationUnsubscribes.push(a);let o=n.onSpeechEnd(()=>{this._cleanupDictation({sessionId:r})});this._dictationUnsubscribes.push(o);let s=setInterval(()=>{this._isActiveSession(r,n)&&n.status.type===`ended`&&this._cleanupDictation({sessionId:r})},100);this._dictationUnsubscribes.push(()=>clearInterval(s))}stopDictation(){if(!this._dictationSession)return;let e=this._dictationSession,t=this._activeDictationSessionId;e.stop().finally(()=>{this._cleanupDictation({sessionId:t})})}_cleanupDictation(e){if(!(e?.sessionId!==void 0&&e.sessionId!==this._activeDictationSessionId||this._isCleaningDictation)){this._isCleaningDictation=!0;try{for(let e of this._dictationUnsubscribes)e();this._dictationUnsubscribes=[],this._dictationSession=void 0,this._activeDictationSessionId=void 0,this._dictation=void 0,this._dictationBaseText=``,this._currentInterimText=``,this._notifySubscribers()}finally{this._isCleaningDictation=!1}}}_eventSubscribers=new Map;_notifyEventSubscribers(e,t){let n=this._eventSubscribers.get(e);if(n)for(let e of n)e(t)}unstable_on(e,t){let n=t,r=this._eventSubscribers.get(e);return r||(r=new Set,this._eventSubscribers.set(e,r)),r.add(n),()=>{this._eventSubscribers.get(e)?.delete(n)}}},nx=class extends tx{runtime;_canCancel=!1;get canCancel(){return this._canCancel}get canSend(){return!this.isEmpty&&!this.runtime.isSendDisabled}getAttachmentAdapter(){return this.runtime.adapters?.attachments}getDictationAdapter(){return this.runtime.adapters?.dictation}constructor(e){super(),this.runtime=e,this.connect()}connect(){let e=this.runtime.isSendDisabled;return this.runtime.subscribe(()=>{let t=!1;this.canCancel!==this.runtime.capabilities.cancel&&(this._canCancel=this.runtime.capabilities.cancel,t=!0),e!==this.runtime.isSendDisabled&&(e=this.runtime.isSendDisabled,t=!0),t&&this._notifySubscribers()})}async handleSend(e,t){this.runtime.append({...e,parentId:this.runtime.messages.at(-1)?.id??null,sourceId:null,startRun:t?.startRun})}async handleCancel(){this.runtime.cancelRun()}},rx=class extends tx{runtime;endEditCallback;get canCancel(){return!0}get canSend(){return!this.isEmpty}getAttachmentAdapter(){return this.runtime.adapters?.attachments}getDictationAdapter(){return this.runtime.adapters?.dictation}_previousText;_previousAttachments;_nonTextPassthrough;_parentId;_sourceId;constructor(e,t,{parentId:n,message:r}){super(),this.runtime=e,this.endEditCallback=t,this._parentId=n,this._sourceId=r.id,this._previousText=Nb(r),this.setText(this._previousText),this.setRole(r.role),r.role===`user`?(this._previousAttachments=[...r.attachments??[],...$b(r.content)],this._nonTextPassthrough=[]):(this._previousAttachments=r.attachments??[],this._nonTextPassthrough=r.content.filter(e=>e.type!==`text`)),this.setAttachments(this._previousAttachments),this.setRunConfig({...e.composer.runConfig})}get parentId(){return this._parentId}get sourceId(){return this._sourceId}async handleSend(e,t){let n=Nb(e),r=!Zb(e.attachments??[],this._previousAttachments);if(n!==this._previousText||r||t?.startRun){let n=this._nonTextPassthrough.length>0?[...e.content,...this._nonTextPassthrough]:e.content;this.runtime.append({...e,content:n,parentId:this._parentId,sourceId:this._sourceId,startRun:t?.startRun})}this.handleCancel()}handleCancel(){this.endEditCallback(),this._notifySubscribers()}},ix=class{_contextProvider;_subscriptions=new Set;_isInitialized=!1;repository=new Yb;_voiceMessages=[];_voiceGeneration=0;_cachedMergedMessages=null;_cachedVoiceGeneration=-1;_cachedMergedBase=null;_markVoiceMessagesDirty(){this._voiceGeneration++,this._cachedMergedMessages=null}_getBaseMessages(){return this.repository.getMessages()}get messages(){if(this._voiceMessages.length===0)return this._getBaseMessages();let e=this._getBaseMessages();return(this._cachedVoiceGeneration!==this._voiceGeneration||this._cachedMergedBase!==e)&&(this._cachedMergedMessages=[...e,...this._voiceMessages],this._cachedVoiceGeneration=this._voiceGeneration,this._cachedMergedBase=e),this._cachedMergedMessages}get state(){let e;for(let t of this.messages)t.role===`assistant`&&(e=t);return e?.metadata.unstable_state??null}composer=new nx(this);constructor(e){this._contextProvider=e}getModelContext(){return this._contextProvider.getModelContext()}_editComposers=new Map;getEditComposer(e){return this._editComposers.get(e)}beginEdit(e){if(this._editComposers.has(e))throw Error(`Edit already in progress`);this._editComposers.set(e,new rx(this,()=>this._editComposers.delete(e),this.repository.getMessage(e))),this._notifySubscribers()}getMessageById(e){try{return this.repository.getMessage(e)}catch{let t=this.repository.getMessages(),n=this._voiceMessages.findIndex(t=>t.id===e);return n===-1?void 0:{parentId:n>0?this._voiceMessages[n-1].id:t.at(-1)?.id??null,message:this._voiceMessages[n],index:t.length+n}}}getBranches(e){return this._voiceMessages.some(t=>t.id===e)?[]:this.repository.getBranches(e)}switchToBranch(e){this.repository.switchToBranch(e),this._notifySubscribers()}_notifySubscribers(){for(let e of this._subscriptions)e()}_notifyEventSubscribers(e,t){let n=this._eventSubscribers.get(e);if(n)for(let e of n)e(t)}subscribe(e){return this._subscriptions.add(e),()=>this._subscriptions.delete(e)}submitFeedback({messageId:e,type:t}){let n=this.adapters?.feedback;if(!n)throw Error(`Feedback adapter not configured`);let{message:r,parentId:i}=this.repository.getMessage(e);if(n.submit({message:r,type:t}),r.role===`assistant`){let e={...r,metadata:{...r.metadata,submittedFeedback:{type:t}}};this.repository.addOrUpdateMessage(i,e)}this._notifySubscribers()}_stopSpeaking;speech;speak(e){let t=this.adapters?.speech;if(!t)throw Error(`Speech adapter not configured`);let{message:n}=this.repository.getMessage(e);this._stopSpeaking?.();let r=t.speak(Nb(n)),i=r.subscribe(()=>{r.status.type===`ended`?(this._stopSpeaking=void 0,this.speech=void 0):this.speech={messageId:e,status:r.status},this._notifySubscribers()});this.speech={messageId:e,status:r.status},this._notifySubscribers(),this._stopSpeaking=()=>{r.cancel(),i(),this.speech=void 0,this._stopSpeaking=void 0}}stopSpeaking(){if(!this._stopSpeaking)throw Error(`No message is being spoken`);this._stopSpeaking(),this._notifySubscribers()}_voiceSession;_voiceUnsubs=[];voice;_voiceVolume=0;_voiceVolumeSubscribers=new Set;getVoiceVolume=()=>this._voiceVolume;subscribeVoiceVolume=e=>(this._voiceVolumeSubscribers.add(e),()=>this._voiceVolumeSubscribers.delete(e));connectVoice(){let e=this.adapters?.voice;if(!e)throw Error(`Voice adapter not configured`);this.disconnectVoice();let t=e.connect({});this._voiceSession=t;let n=[],r=`listening`;this.voice={status:t.status,isMuted:t.isMuted,mode:r},this._voiceVolume=0,this._notifySubscribers(),n.push(t.onStatusChange(e=>{e.type===`ended`?(this._finishVoiceAssistantMessage(),this._voiceSession=void 0,this.voice=void 0):this.voice={status:e,isMuted:t.isMuted,mode:r},this._notifySubscribers()})),n.push(t.onModeChange(e=>{r=e,this.voice&&(this.voice={...this.voice,mode:e},this._notifySubscribers())})),n.push(t.onVolumeChange(e=>{this._voiceVolume=e;for(let e of this._voiceVolumeSubscribers)e()})),n.push(t.onTranscript(e=>{this._handleVoiceTranscript(e)})),this._voiceUnsubs=n}_currentAssistantMsg=null;_handleVoiceTranscript(e){if(this.ensureInitialized(),e.role===`user`)this._finishVoiceAssistantMessage(),this._currentAssistantMsg=null,e.isFinal&&(this._voiceMessages.push({id:Pb(),role:`user`,content:[{type:`text`,text:e.text}],metadata:{custom:{}},createdAt:new Date,status:{type:`complete`,reason:`unknown`},attachments:[]}),this._markVoiceMessagesDirty(),this._notifySubscribers());else{if(!this._currentAssistantMsg)this._currentAssistantMsg={id:Pb(),role:`assistant`,content:[{type:`text`,text:e.text}],metadata:{unstable_state:this.state,unstable_annotations:[],unstable_data:[],steps:[],custom:{}},status:{type:`running`},createdAt:new Date},this._voiceMessages.push(this._currentAssistantMsg);else{let t=this._voiceMessages.indexOf(this._currentAssistantMsg);if(t===-1)return;let n={...this._currentAssistantMsg,content:[{type:`text`,text:e.text}],...e.isFinal?{status:{type:`complete`,reason:`stop`}}:{}};this._voiceMessages[t]=n,this._currentAssistantMsg=n}e.isFinal&&(this._currentAssistantMsg=null),this._markVoiceMessagesDirty(),this._notifySubscribers()}}_finishVoiceAssistantMessage(){let e=this._voiceMessages.at(-1);if(e?.role===`assistant`&&e.status.type===`running`){let t=this._voiceMessages.length-1;this._voiceMessages[t]={...e,status:{type:`complete`,reason:`stop`}},this._markVoiceMessagesDirty(),this._notifySubscribers()}}disconnectVoice(){this._finishVoiceAssistantMessage(),this._currentAssistantMsg=null;for(let e of this._voiceUnsubs)e();this._voiceUnsubs=[],this._voiceSession?.disconnect(),this._voiceSession=void 0,this.voice=void 0,this._voiceVolume=0;for(let e of this._voiceVolumeSubscribers)e();this._voiceMessages=[],this._markVoiceMessagesDirty(),this._notifySubscribers()}muteVoice(){if(!this._voiceSession)throw Error(`No active voice session`);this._voiceSession.mute(),this.voice={...this.voice,isMuted:!0},this._notifySubscribers()}unmuteVoice(){if(!this._voiceSession)throw Error(`No active voice session`);this._voiceSession.unmute(),this.voice={...this.voice,isMuted:!1},this._notifySubscribers()}ensureInitialized(){this._isInitialized||(this._isInitialized=!0,this._notifyEventSubscribers(`initialize`,{}))}export(){return this.repository.export()}import(e){this.ensureInitialized(),this.repository.clear(),this.repository.import(e),this._notifySubscribers()}reset(e){this.import(Kb.fromArray(e??[]))}_eventSubscribers=new Map;unstable_on(e,t){let n=t;if(e===`modelContextUpdate`)return this._contextProvider.subscribe?.(()=>n({}))??(()=>{});let r=this._eventSubscribers.get(e);return r||(r=new Set,this._eventSubscribers.set(e,r)),r.add(n),()=>{this._eventSubscribers.get(e)?.delete(n)}}},ax=class{_core;_threadListBinding;get path(){return this._core.path}constructor(e,t){this._core=e,this._threadListBinding=t,this.__internal_bindMethods()}__internal_bindMethods(){this.switchTo=this.switchTo.bind(this),this.rename=this.rename.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(){let e=this._core.getState();return this._threadListBinding.switchToThread(e.id)}rename(e){let t=this._core.getState();return this._threadListBinding.rename(t.id,e)}archive(){let e=this._core.getState();return this._threadListBinding.archive(e.id)}unarchive(){let e=this._core.getState();return this._threadListBinding.unarchive(e.id)}delete(){let e=this._core.getState();return this._threadListBinding.delete(e.id)}initialize(){let e=this._core.getState();return this._threadListBinding.initialize(e.id)}generateTitle(){let e=this._core.getState();return this._threadListBinding.generateTitle(e.id)}unstable_on(e,t){let n=this._core.getState().isMain,r=this._core.getState().id;return this.subscribe(()=>{let i=this._core.getState(),a=i.isMain,o=i.id;n===a&&r===o||(n=a,r=o,!(e===`switchedTo`&&!a)&&(e===`switchedAway`&&a||t({})))})}subscribe(e){return this._core.subscribe(e)}detach(){let e=this._core.getState();this._threadListBinding.detach(e.id)}__internal_getRuntime(){return this}},ox=Symbol(`innerMessage`),sx=Symbol(`innerMessages`),cx=[],lx=(e,t)=>{ox in e||(e[ox]=t)},ux=e=>{let t=`messages`in e?e.messages:e,n=t[sx]||t[ox];return n?Array.isArray(n)?n:(t[sx]=[n],t[sx]):cx},dx=class{_core;get path(){return this._core.path}constructor(e){this._core=e,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(e){return this._core.subscribe(e)}},fx=class extends dx{_composerApi;constructor(e,t){super(e),this._composerApi=t}remove(){let e=this._composerApi.getState();if(!e)throw Error(`Composer is not available`);return e.removeAttachment(this.getState().id)}},px=class extends fx{get source(){return`thread-composer`}},mx=class extends fx{get source(){return`edit-composer`}},hx=class extends dx{get source(){return`message`}remove(){throw Error(`Message attachments cannot be removed`)}},gx=Object.freeze([]),_x=Object.freeze({}),vx=e=>Object.freeze({type:`thread`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,attachments:e?.attachments??gx,text:e?.text??``,role:e?.role??`user`,runConfig:e?.runConfig??_x,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,value:e?.text??``}),yx=e=>Object.freeze({type:`edit`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,text:e?.text??``,role:e?.role??`user`,attachments:e?.attachments??gx,runConfig:e?.runConfig??_x,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,parentId:e?.parentId??null,sourceId:e?.sourceId??null,value:e?.text??``}),bx=class{_core;get path(){return this._core.path}constructor(e){this._core=e}__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.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(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setText(e)}setRunConfig(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setRunConfig(e)}addAttachment(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);return t.addAttachment(e)}reset(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);return e.reset()}clearAttachments(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);return e.clearAttachments()}send(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.send(e)}cancel(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);e.cancel()}setRole(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setRole(e)}startDictation(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);e.startDictation()}stopDictation(){let e=this._core.getState();if(!e)throw Error(`Composer is not available`);e.stopDictation()}setQuote(e){let t=this._core.getState();if(!t)throw Error(`Composer is not available`);t.setQuote(e)}subscribe(e){return this._core.subscribe(e)}_eventSubscriptionSubjects=new Map;unstable_on(e,t){let n=this._eventSubscriptionSubjects.get(e);return n||(n=new jb({event:e,binding:this._core}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},xx=class extends bx{get path(){return this._core.path}get type(){return`thread`}_getState;constructor(e){let t=new kb({path:e.path,getState:()=>vx(e.getState()),subscribe:t=>e.subscribe(t)});super({path:e.path,getState:()=>e.getState(),subscribe:e=>t.subscribe(e)}),this._getState=t.getState.bind(t),this.__internal_bindMethods()}getState(){return this._getState()}getAttachmentByIndex(e){return new px(new Ob({path:{...this.path,attachmentSource:`thread-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`thread-composer`}:wb},subscribe:e=>this._core.subscribe(e)}),this._core)}},Sx=class extends bx{_beginEdit;get path(){return this._core.path}get type(){return`edit`}_getState;constructor(e,t){let n=new kb({path:e.path,getState:()=>yx(e.getState()),subscribe:t=>e.subscribe(t)});super({path:e.path,getState:()=>e.getState(),subscribe:e=>n.subscribe(e)}),this._beginEdit=t,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(e){return new mx(new Ob({path:{...this.path,attachmentSource:`edit-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`edit-composer`}:wb},subscribe:e=>this._core.subscribe(e)}),this._core)}},Cx=class{contentBinding;messageApi;threadApi;get path(){return this.contentBinding.path}constructor(e,t,n){this.contentBinding=e,this.messageApi=t,this.threadApi=n,this.__internal_bindMethods()}__internal_bindMethods(){this.addToolResult=this.addToolResult.bind(this),this.resumeToolCall=this.resumeToolCall.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this.contentBinding.getState()}addToolResult(e){let t=this.contentBinding.getState();if(!t)throw Error(`Message part is not available`);if(t.type!==`tool-call`)throw Error(`Tried to add tool result to non-tool message part`);if(!this.messageApi)throw Error(`Message API is not available. This is likely a bug in assistant-ui.`);if(!this.threadApi)throw Error(`Thread API is not available`);let n=this.messageApi.getState();if(!n)throw Error(`Message is not available`);let r=t.toolName,i=t.toolCallId,a=Uy.toResponse(e);this.threadApi.getState().addToolResult({messageId:n.id,toolName:r,toolCallId:i,result:a.result,artifact:a.artifact,isError:a.isError})}resumeToolCall(e){let t=this.contentBinding.getState();if(!t)throw Error(`Message part is not available`);if(t.type!==`tool-call`)throw Error(`Tried to resume tool call on non-tool message part`);if(!this.threadApi)throw Error(`Thread API is not available`);let n=t.toolCallId;this.threadApi.getState().resumeToolCall({toolCallId:n,payload:e})}subscribe(e){return this.contentBinding.subscribe(e)}},wx=Object.freeze({type:`complete`}),Tx=(e,t,n)=>{if(e.role!==`assistant`)return wx;if(n.type===`tool-call`)return n.result?wx:e.status;let r=t===Math.max(0,e.content.length-1);return e.status.type===`requires-action`?wx:r?e.status:wx},Ex=(e,t)=>{let n=e.content[t];if(!n)return wb;let r=Tx(e,t,n);return Object.freeze({...n,[ox]:n[ox],status:r})},Dx=class{_core;_threadBinding;get path(){return this._core.path}constructor(e,t){this._core=e,this._threadBinding=t,this.composer=new Sx(new Ab({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.composer`,composerSource:`edit`},getState:this._getEditComposerRuntimeCore,subscribe:e=>this._threadBinding.subscribe(e)}),()=>this._threadBinding.getState().beginEdit(this._core.getState().id)),this.__internal_bindMethods()}__internal_bindMethods(){this.reload=this.reload.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()}reload(e={}){let t=this._getEditComposerRuntimeCore(),n=t??this._threadBinding.getState().composer,r=t??n,{runConfig:i=r.runConfig}=e,a=this._core.getState();if(a.role!==`assistant`)throw Error(`Can only reload assistant messages`);this._threadBinding.getState().startRun({parentId:a.parentId,sourceId:a.id,runConfig:i})}speak(){let e=this._core.getState();return this._threadBinding.getState().speak(e.id)}stopSpeaking(){let e=this._core.getState();if(this._threadBinding.getState().speech?.messageId===e.id)this._threadBinding.getState().stopSpeaking();else throw Error(`Message is not being spoken`)}submitFeedback({type:e}){let t=this._core.getState();this._threadBinding.getState().submitFeedback({messageId:t.id,type:e})}switchToBranch({position:e,branchId:t}){let n=this._core.getState();if(t&&e)throw Error(`May not specify both branchId and position`);if(!t&&!e)throw Error(`Must specify either branchId or position`);let r=this._threadBinding.getState().getBranches(n.id),i=t;if(e===`previous`?i=r[n.branchNumber-2]:e===`next`&&(i=r[n.branchNumber]),!i)throw Error(`Branch not found`);this._threadBinding.getState().switchToBranch(i)}unstable_getCopyText(){return Nb(this.getState())}subscribe(e){return this._core.subscribe(e)}getMessagePartByIndex(e){if(e<0)throw Error(`Message part index must be >= 0`);return new Cx(new Ob({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.content[${e}]`,messagePartSelector:{type:`index`,index:e}},getState:()=>Ex(this.getState(),e),subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getMessagePartByToolCallId(e){return new Cx(new Ob({path:{...this.path,ref:this.path.ref+`${this.path.ref}.content[toolCallId=${JSON.stringify(e)}]`,messagePartSelector:{type:`toolCallId`,toolCallId:e}},getState:()=>{let t=this._core.getState(),n=t.content.findIndex(t=>t.type===`tool-call`&&t.toolCallId===e);return n===-1?wb:Ex(t,n)},subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getAttachmentByIndex(e){return new hx(new Ob({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.attachments[${e}]`,attachmentSource:`message`,attachmentSelector:{type:`index`,index:e}},getState:()=>{let t=this.getState().attachments?.[e];return t?{...t,source:`message`}:wb},subscribe:e=>this._core.subscribe(e)}))}},Ox=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{},...e.stream?{stream:e.stream}:{}}),kx=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{}}),Ax=(e,t)=>typeof t==`string`?{createdAt:new Date,parentId:e.at(-1)?.id??null,sourceId:null,runConfig:{},role:`user`,content:[{type:`text`,text:t}],attachments:[],metadata:{custom:{}}}:{createdAt:t.createdAt??new Date,parentId:t.parentId??e.at(-1)?.id??null,sourceId:t.sourceId??null,role:t.role??`user`,content:t.content,attachments:t.attachments??[],metadata:t.metadata??{custom:{}},runConfig:t.runConfig??{},startRun:t.startRun},jx=(e,t)=>{let n=e.messages.at(-1);return Object.freeze({threadId:t.id,metadata:t,capabilities:e.capabilities,isDisabled:e.isDisabled,isLoading:e.isLoading,isRunning:e.isRunning??(n?.role===`assistant`?n.status.type===`running`:!1),messages:e.messages,state:e.state,suggestions:e.suggestions,extras:e.extras,speech:e.speech,voice:e.voice})},Mx=class{get path(){return this._threadBinding.path}get __internal_threadBinding(){return this._threadBinding}_threadBinding;constructor(e,t){let n=new Ob({path:e.path,getState:()=>jx(e.getState(),t.getState()),subscribe:n=>{let r=e.subscribe(n),i=t.subscribe(n);return()=>{r(),i()}}});this._threadBinding={path:e.path,getState:()=>e.getState(),getStateState:()=>n.getState(),outerSubscribe:t=>e.outerSubscribe(t),subscribe:t=>e.subscribe(t)},this.composer=new xx(new Ab({path:{...this.path,ref:`${this.path.ref}.composer`,composerSource:`thread`},getState:()=>this._threadBinding.getState().composer,subscribe:e=>this._threadBinding.subscribe(e)})),this.__internal_bindMethods()}__internal_bindMethods(){this.append=this.append.bind(this),this.resumeRun=this.resumeRun.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.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(e){this._threadBinding.getState().append(Ax(this._threadBinding.getState().messages,e))}subscribe(e){return this._threadBinding.subscribe(e)}getModelContext(){return this._threadBinding.getState().getModelContext()}startRun(e){return this._threadBinding.getState().startRun(kx(e))}resumeRun(e){return this._threadBinding.getState().resumeRun(Ox(e))}exportExternalState(){return this._threadBinding.getState().exportExternalState()}importExternalState(e){this._threadBinding.getState().importExternalState(e)}cancelRun(){this._threadBinding.getState().cancelRun()}stopSpeaking(){return this._threadBinding.getState().stopSpeaking()}connectVoice(){this._threadBinding.getState().connectVoice()}disconnectVoice(){this._threadBinding.getState().disconnectVoice()}getVoiceVolume(){return this._threadBinding.getState().getVoiceVolume()}subscribeVoiceVolume(e){return this._threadBinding.getState().subscribeVoiceVolume(e)}muteVoice(){this._threadBinding.getState().muteVoice()}unmuteVoice(){this._threadBinding.getState().unmuteVoice()}export(){return this._threadBinding.getState().export()}import(e){this._threadBinding.getState().import(e)}reset(e){this._threadBinding.getState().reset(e)}getMessageByIndex(e){if(e<0)throw Error(`Message index must be >= 0`);return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[${e}]`,messageSelector:{type:`index`,index:e}},()=>{let t=this._threadBinding.getState().messages,n=t[e];if(n)return{message:n,parentId:t[e-1]?.id??null,index:e}})}getMessageById(e){return this._getMessageRuntime({...this.path,ref:`${this.path.ref}.messages[messageId=${JSON.stringify(e)}]`,messageSelector:{type:`messageId`,messageId:e}},()=>this._threadBinding.getState().getMessageById(e))}_getMessageRuntime(e,t){return new Dx(new Ob({path:e,getState:()=>{let{message:e,parentId:n,index:r}=t()??{},{messages:i,speech:a}=this._threadBinding.getState();if(!e||n===void 0||r===void 0)return wb;let o=this._threadBinding.getState().getBranches(e.id);return{...e,[ox]:e[ox],index:r,isLast:i.at(-1)?.id===e.id,parentId:n,branchNumber:o.indexOf(e.id)+1,branchCount:o.length,speech:a?.messageId===e.id?a:void 0}},subscribe:e=>this._threadBinding.subscribe(e)}),this._threadBinding)}_eventSubscriptionSubjects=new Map;unstable_on(e,t){let n=this._eventSubscriptionSubjects.get(e);return n||(n=new jb({event:e,binding:this._threadBinding}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},Nx=Promise.resolve(),Px=e=>({mainThreadId:e.mainThreadId,newThreadId:e.newThreadId,threadIds:e.threadIds,archivedThreadIds:e.archivedThreadIds,isLoading:e.isLoading,isLoadingMore:e.isLoadingMore??!1,hasMore:e.hasMore??!1,threadItems:e.threadItems}),Fx=(e,t)=>{if(t===void 0)return wb;let n=e.getItemById(t);return n?{id:n.id,remoteId:n.remoteId,externalId:n.externalId,title:n.title,status:n.status,custom:n.custom,isMain:n.id===e.mainThreadId}:wb},Ix=class{_core;_runtimeFactory;_getState;constructor(e,t=Mx){this._core=e,this._runtimeFactory=t;let n=new kb({path:{},getState:()=>Px(e),subscribe:t=>e.subscribe(t)});this._getState=n.getState.bind(n),this._mainThreadListItemRuntime=new ax(new Ob({path:{ref:`threadItems[main]`,threadSelector:{type:`main`}},getState:()=>Fx(this._core,this._core.mainThreadId),subscribe:e=>this._core.subscribe(e)}),this._core),this.main=new t(new Ab({path:{ref:`threads.main`,threadSelector:{type:`main`}},getState:()=>e.getMainThreadRuntimeCore(),subscribe:t=>e.subscribe(t)}),this._mainThreadListItemRuntime),this.__internal_bindMethods()}__internal_bindMethods(){this.switchToThread=this.switchToThread.bind(this),this.switchToNewThread=this.switchToNewThread.bind(this),this.getLoadThreadsPromise=this.getLoadThreadsPromise.bind(this),this.reload=this.reload.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(e){return this._core.switchToThread(e)}switchToNewThread(){return this._core.switchToNewThread()}getLoadThreadsPromise(){return this._core.getLoadThreadsPromise()}reload(){return this._core.reload?.()??Nx}loadMore(){return this._core.loadMore?.()??Nx}getState(){return this._getState()}subscribe(e){return this._core.subscribe(e)}_mainThreadListItemRuntime;main;get mainItem(){return this._mainThreadListItemRuntime}getById(e){return new this._runtimeFactory(new Ab({path:{ref:`threads[threadId=${JSON.stringify(e)}]`,threadSelector:{type:`threadId`,threadId:e}},getState:()=>this._core.getThreadRuntimeCore(e),subscribe:e=>this._core.subscribe(e)}),this.mainItem)}getItemByIndex(e){return new ax(new Ob({path:{ref:`threadItems[${e}]`,threadSelector:{type:`index`,index:e}},getState:()=>Fx(this._core,this._core.threadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getArchivedItemByIndex(e){return new ax(new Ob({path:{ref:`archivedThreadItems[${e}]`,threadSelector:{type:`archiveIndex`,index:e}},getState:()=>Fx(this._core,this._core.archivedThreadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getItemById(e){return new ax(new Ob({path:{ref:`threadItems[threadId=${e}]`,threadSelector:{type:`threadId`,threadId:e}},getState:()=>Fx(this._core,e),subscribe:e=>this._core.subscribe(e)}),this._core)}},Lx=class{_core;threads;_thread;constructor(e){this._core=e,this.threads=new Ix(e.threads),this._thread=this.threads.main,this.__internal_bindMethods()}__internal_bindMethods(){this.registerModelContextProvider=this.registerModelContextProvider.bind(this)}get thread(){return this._thread}registerModelContextProvider(e){return this._core.registerModelContextProvider(e)}},Rx=c_(e=>O_(_b(e)));vv(Rx,(e,t)=>{vb(e,t),!e.tools&&t.tools.source===null&&(e.tools=By({})),!e.dataRenderers&&t.dataRenderers.source===null&&(e.dataRenderers=Vy())});var zx=(0,w.createContext)(null),Bx=()=>(0,w.useContext)(zx);function Vx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Hx(e,t=0){return t>100?!1:e===null||typeof e==`string`||typeof e==`boolean`?!0:typeof e==`number`?!Number.isNaN(e)&&Number.isFinite(e):Array.isArray(e)?e.every(e=>Hx(e,t+1)):Vx(e)?Object.entries(e).every(([e,n])=>typeof e==`string`&&Hx(n,t+1)):!1}var Ux=100,Wx=(e,t,n)=>{if(e===t)return!0;if(n>Ux||e==null||t==null)return!1;if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:e.every((e,r)=>Wx(e,t[r],n+1));if(Array.isArray(t)||!Vx(e)||!Vx(t))return!1;let r=Object.keys(e),i=Object.keys(t);return r.length===i.length?r.every(r=>Object.hasOwn(t,r)&&Wx(e[r],t[r],n+1)):!1},Gx=(e,t)=>!Hx(e)||!Hx(t)?!1:Wx(e,t,0),Kx=e=>{try{return JSON.parse(e),!0}catch{return!1}},qx=e=>{try{return JSON.parse(e)}catch{return}},Jx=(e,t)=>{let n=qx(e),r=qx(t);return n===void 0||r===void 0?!1:Gx(n,r)};function Yx({state:e,getTools:t,onResult:n,setToolStatuses:r}){let i=(0,w.useRef)({}),a=(0,w.useRef)(new Map),o=(0,w.useRef)(new AbortController),s=(0,w.useRef)(0),c=(0,w.useRef)(new Set),l=(0,w.useRef)([]),u=(0,w.useRef)(new Map),d=(0,w.useRef)(new Set),f=(0,w.useRef)(0),p=e=>u.current.get(e)??e,m=e=>d.current.has(e)?(d.current.delete(e),u.current.delete(e),!0):!1,h=()=>{let e=t();if(e)return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=t.execute,r=t.streamCall,i=t.toModelOutput;return[e,{...t,...n!==void 0&&{execute:(...[e,t])=>n(e,{...t,toolCallId:p(t.toolCallId)})},...r!==void 0&&{streamCall:(...[e,t])=>r(e,{...t,toolCallId:p(t.toolCallId)})},...i!==void 0&&{toModelOutput:e=>i({...e,toolCallId:p(e.toolCallId)})}}]}))},[g]=(0,w.useState)(()=>{let[e,t]=jy(),f=rb(h,()=>o.current?.signal??new AbortController().signal,(e,t)=>{let n=p(e);return new Promise((e,i)=>{let o=a.current.get(n);o&&o.reject(Error(`Human input request was superseded by a new request`)),a.current.set(n,{resolve:e,reject:i}),r(e=>({...e,[n]:{type:`interrupt`,payload:{type:`human`,payload:t}}}))})},{onExecutionStart:e=>{if(d.current.has(e))return;c.current.add(e);let t=p(e);s.current++,r(e=>({...e,[t]:{type:`executing`}}))},onExecutionEnd:e=>{let t=c.current.delete(e);if(d.current.has(e)){t&&(s.current--,s.current===0&&(l.current.forEach(e=>e()),l.current=[]));return}if(!t)return;let n=p(e);s.current--,r(e=>{let t={...e};return delete t[n],t}),s.current===0&&(l.current.forEach(e=>e()),l.current=[])}});return e.pipeThrough(f).pipeThrough(new Ey).pipeTo(new WritableStream({write(e){if(e.type===`result`){if(m(e.meta.toolCallId))return;let t=p(e.meta.toolCallId);if(t!==e.meta.toolCallId&&u.current.delete(e.meta.toolCallId),i.current[t]?.hasResult)return;n({type:`add-tool-result`,toolCallId:t,toolName:e.meta.toolName,result:e.result,isError:e.isError,...e.artifact!==void 0&&{artifact:e.artifact},...e.modelContent!==void 0&&{modelContent:e.modelContent}})}}})),t}),_=(0,w.useRef)(new Set),v=(0,w.useRef)(!0);(0,w.useEffect)(()=>{let n=({controller:e,streamToolCallId:t})=>({argsText:``,hasResult:!1,argsComplete:!1,streamToolCallId:t,controller:e}),r=(e,t)=>(i.current[e]=t,t),a=(e,t,n)=>r(e,{...t,...n}),o=e=>{let n=t()?.[e];return n?.execute!==void 0||n?.streamCall!==void 0},s=({toolName:t,argsText:n,hasResult:r})=>r?!0:(o(t)||!e.isRunning)&&Kx(n),l=({toolCallId:e,toolName:t,state:i})=>{d.current.add(i.streamToolCallId),i.controller.argsText.close();let a=`${e}:rewrite:${f.current++}`;return u.current.set(a,e),r(e,{...n({controller:g.addToolCallPart({toolName:t,toolCallId:a}),streamToolCallId:a}),hasResult:i.hasResult})},p=e=>{e.forEach(e=>{e.content.forEach(e=>{if(e.type===`tool-call`){if(v.current)_.current.add(e.toolCallId);else{if(_.current.has(e.toolCallId))return;let t=i.current[e.toolCallId];if(!t){if(e.result!==void 0){e.messages&&p(e.messages);return}u.current.set(e.toolCallId,e.toolCallId);let i=g.addToolCallPart({toolName:e.toolName,toolCallId:e.toolCallId});t=r(e.toolCallId,n({controller:i,streamToolCallId:e.toolCallId}))}if(e.argsText!==t.argsText){let n=!0;if(t.argsComplete)Jx(t.argsText,e.argsText)&&(t=a(e.toolCallId,t,{argsText:e.argsText}),n=!1),n&&(!t.hasResult&&!c.current.has(t.streamToolCallId)||(t=a(e.toolCallId,t,{argsText:e.argsText}),n=!1)),n&&(t=l({toolCallId:e.toolCallId,toolName:e.toolName,state:t}));else if(!e.argsText.startsWith(t.argsText)){if(Kx(t.argsText)&&Kx(e.argsText)&&Jx(t.argsText,e.argsText)){let r=s({toolName:e.toolName,argsText:e.argsText,hasResult:e.result!==void 0});r&&t.controller.argsText.close(),t=a(e.toolCallId,t,{argsText:e.argsText,argsComplete:r}),n=!1}n&&(t=l({toolCallId:e.toolCallId,toolName:e.toolName,state:t}))}if(n){let n=e.argsText.slice(t.argsText.length);t.controller.argsText.append(n);let r=s({toolName:e.toolName,argsText:e.argsText,hasResult:e.result!==void 0});r&&t.controller.argsText.close(),t=a(e.toolCallId,t,{argsText:e.argsText,argsComplete:r})}}t.argsComplete||s({toolName:e.toolName,argsText:e.argsText,hasResult:e.result!==void 0})&&(t.controller.argsText.close(),t=a(e.toolCallId,t,{argsText:e.argsText,argsComplete:!0})),e.result!==void 0&&!t.hasResult&&(a(e.toolCallId,t,{hasResult:!0,argsComplete:!0}),t.controller.setResponse(new Uy({result:e.result,artifact:e.artifact,isError:e.isError,...e.modelContent===void 0?{}:{modelContent:e.modelContent}})),t.controller.close())}e.messages&&p(e.messages)}})})};p(e.messages),v.current&&=!1},[e,g,t]);let y=()=>(a.current.forEach(({reject:e})=>{e(Error(`Tool execution aborted`))}),a.current.clear(),o.current.abort(),o.current=new AbortController,s.current===0?Promise.resolve():new Promise(e=>{l.current.push(e)}));return{reset:()=>{v.current=!0,_.current.clear(),i.current={},y().finally(()=>{c.current.clear(),u.current.clear(),d.current.clear(),f.current=0})},abort:y,resume:(e,t)=>{let n=a.current.get(e);if(n)a.current.delete(e),r(t=>({...t,[e]:{type:`executing`}})),n.resolve(t);else throw Error(`Tool call ${e} is not waiting for human input`)}}}var Xx=Object.freeze([]),Zx=`DEFAULT_THREAD_ID`,Qx=Object.freeze([Zx]),$x=Object.freeze({id:Zx,remoteId:void 0,externalId:void 0,status:`regular`}),eS=Promise.resolve(),tS=Object.freeze({[Zx]:$x}),nS=class{threadFactory;_mainThreadId=Zx;_threads=Qx;_archivedThreads=Xx;_threadData=tS;adapter={};get isLoading(){return this.adapter.isLoading??!1}get newThreadId(){}get threadIds(){return this._threads}get archivedThreadIds(){return this._archivedThreads}get threadItems(){return this._threadData}getLoadThreadsPromise(){return eS}_mainThread;get mainThreadId(){return this._mainThreadId}constructor(e={},t){this.threadFactory=t,this.__internal_setAdapter(e,!0)}getMainThreadRuntimeCore(){return this._mainThread}getThreadRuntimeCore(){throw Error(`Method not implemented.`)}getItemById(e){return this._threadData[e]}__internal_setAdapter(e,t=!1){let n=this.adapter;this.adapter=e;let r=e.threadId??Zx,i=e.threads??Xx,a=e.archivedThreads??Xx,o=n.threadId??Zx,s=n.threads??Xx,c=n.archivedThreads??Xx;!t&&o===r&&s===i&&c===a||((s!==i||c!==a||o!==r)&&(this._threadData={...tS,...Object.fromEntries(e.threads?.map(e=>[e.id,{...e,remoteId:e.remoteId,externalId:e.externalId,status:`regular`}])??[]),...Object.fromEntries(e.archivedThreads?.map(e=>[e.id,{...e,remoteId:e.remoteId,externalId:e.externalId,status:`archived`}])??[])}),s!==i&&(this._threads=this.adapter.threads?.map(e=>e.id)??Xx),c!==a&&(this._archivedThreads=this.adapter.archivedThreads?.map(e=>e.id)??Xx),(t||o!==r)&&(this._mainThreadId=r,this._mainThread=this.threadFactory()),this._threadData[this._mainThreadId]||(this._threadData={...this._threadData,[this._mainThreadId]:{id:this._mainThreadId,remoteId:void 0,externalId:void 0,status:`regular`}}),this._notifySubscribers())}async switchToThread(e){if(this._mainThreadId===e)return;let t=this.adapter.onSwitchToThread;if(!t)throw Error(`External store adapter does not support switching to thread`);await t(e)}async switchToNewThread(){let e=this.adapter.onSwitchToNewThread;if(!e)throw Error(`External store adapter does not support switching to new thread`);await e()}async rename(e,t){let n=this.adapter.onRename;if(!n)throw Error(`External store adapter does not support renaming`);await n(e,t)}async detach(){}async archive(e){let t=this.adapter.onArchive;if(!t)throw Error(`External store adapter does not support archiving`);await t(e)}async unarchive(e){let t=this.adapter.onUnarchive;if(!t)throw Error(`External store adapter does not support unarchiving`);await t(e)}async delete(e){let t=this.adapter.onDelete;if(!t)throw Error(`External store adapter does not support deleting`);await t(e)}initialize(e){return Promise.resolve({remoteId:e,externalId:void 0})}generateTitle(){throw Error(`Method not implemented.`)}_subscriptions=new Set;subscribe(e){return this._subscriptions.add(e),()=>this._subscriptions.delete(e)}_notifySubscribers(){for(let e of this._subscriptions)e()}},rS=class{cache=new WeakMap;convertMessages(e,t){return e.map((e,n)=>{let r=t(this.cache.get(e),e,n);return this.cache.set(e,r),r})}},iS=Object.freeze([]),aS=(e,t)=>{let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0},oS=(e,t)=>e&&t[t.length-1]?.role!==`assistant`,sS=class extends ix{_assistantOptimisticId=null;_capabilities={switchToBranch:!1,switchBranchDuringRun:!1,edit:!1,reload:!1,cancel:!1,unstable_copy:!1,speech:!1,dictation:!1,voice:!1,attachments:!1,feedback:!1,queue:!1};get capabilities(){return this._capabilities}_messages;isDisabled;isSendDisabled;get isLoading(){return this._store.isLoading??!1}get isRunning(){return this._store.isRunning}_getBaseMessages(){return this._messages}get state(){return this._store.state??super.state}get adapters(){return this._store.adapters}suggestions=[];extras=void 0;_converter=new rS;_store;beginEdit(e){if(!this._store.onEdit)throw Error(`Runtime does not support editing.`);super.beginEdit(e)}constructor(e,t){super(e),this.__internal_setAdapter(t)}__internal_setAdapter(e){if(this._store===e)return;let t=e.isRunning??!1;this.isDisabled=e.isDisabled??!1,this.isSendDisabled=e.isSendDisabled??!1;let n=this._store;this._store=e,this.extras!==e.extras&&(this.extras=e.extras);let r=e.suggestions??iS;aS(this.suggestions,r)||(this.suggestions=r);let i={switchToBranch:this._store.setMessages!==void 0,switchBranchDuringRun:!1,edit:this._store.onEdit!==void 0,reload:this._store.onReload!==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:!1};aS(this._capabilities,i)||(this._capabilities=i);let a;if(e.messageRepository){if(n&&n.isRunning===e.isRunning&&n.messageRepository===e.messageRepository){this._notifySubscribers();return}this.repository.clear(),this._assistantOptimisticId=null,this.repository.import(e.messageRepository),a=this.repository.getMessages()}else if(e.messages){if(n){if(n.convertMessage!==e.convertMessage)this._converter=new rS;else if(n.isRunning===e.isRunning&&n.messages===e.messages){this._notifySubscribers();return}}a=e.convertMessage?this._converter.convertMessages(e.messages,(n,r,i)=>{if(!e.convertMessage)return r;let a=Ub(i===(e.messages?.length??0)-1,t,!1,!1,void 0);if(n&&(n.role!==`assistant`||!Hb(n.status)||n.status===a))return n;let o=Gb(e.convertMessage(r,i),i.toString(),a);return lx(o,r),o}):e.messages;for(let e=0;e<a.length;e++){let t=a[e],n=a[e-1];this.repository.addOrUpdateMessage(n?.id??null,t)}}else throw Error(`ExternalStoreAdapter must provide either 'messages' or 'messageRepository'`);a.length>0&&this.ensureInitialized(),(n?.isRunning??!1)!==(e.isRunning??!1)&&(e.isRunning?this._notifyEventSubscribers(`runStart`,{}):this._notifyEventSubscribers(`runEnd`,{})),this._assistantOptimisticId&&=(this.repository.deleteMessage(this._assistantOptimisticId),null),oS(t,a)&&(this._assistantOptimisticId=this.repository.appendOptimisticMessage(a.at(-1)?.id??null,{role:`assistant`,content:[]})),this.repository.resetHead(this._assistantOptimisticId??a.at(-1)?.id??null),this._messages=this.repository.getMessages(),this._notifySubscribers()}switchToBranch(e){if(!this._store.setMessages)throw Error(`Runtime does not support switching branches.`);this._store.isRunning||(this.repository.switchToBranch(e),this.updateMessages(this.repository.getMessages()))}async append(e){if(e.parentId!==(this.messages.at(-1)?.id??null)){if(!this._store.onEdit)throw Error(`Runtime does not support editing messages.`);await this._store.onEdit(e)}else await this._store.onNew(e)}async startRun(e){if(!this._store.onReload)throw Error(`Runtime does not support reloading messages.`);await this._store.onReload(e.parentId,e)}async resumeRun(e){if(!this._store.onResume)throw Error(`Runtime does not support resuming runs.`);await this._store.onResume(e)}exportExternalState(){if(!this._store.onExportExternalState)throw Error(`Runtime does not support exporting external states.`);return this._store.onExportExternalState()}importExternalState(e){if(!this._store.onLoadExternalState)throw Error(`Runtime does not support importing external states.`);this._store.onLoadExternalState(e)}cancelRun(){if(!this._store.onCancel)throw Error(`Runtime does not support cancelling runs.`);this._store.onCancel(),this._assistantOptimisticId&&=(this.repository.deleteMessage(this._assistantOptimisticId),null);let e=this.repository.getMessages(),t=e[e.length-1];t?.role===`user`&&t.id===e.at(-1)?.id?(this.repository.deleteMessage(t.id),this.composer.text.trim()||this.composer.setText(Nb(t)),e=this.repository.getMessages()):this._notifySubscribers(),setTimeout(()=>{this.updateMessages(e)},0)}addToolResult(e){if(!this._store.onAddToolResult&&!this._store.onAddToolResult)throw Error(`Runtime does not support tool results.`);this._store.onAddToolResult?.(e)}resumeToolCall(e){if(!this._store.onResumeToolCall)throw Error(`Runtime does not support resuming tool calls.`);this._store.onResumeToolCall(e)}reset(e){let t=new Yb;t.import(Kb.fromArray(e??[])),this.updateMessages(t.getMessages())}import(e){this._assistantOptimisticId=null,super.import(e),this._store.onImport&&this._store.onImport(this.repository.getMessages())}updateMessages=e=>{this._store.convertMessage===void 0?this._store.setMessages?.(e):this._store.setMessages?.(e.flatMap(ux))}},cS=e=>e.adapters?.threadList??{},lS=class extends Mb{threads;constructor(e){super(),this.threads=new nS(cS(e),()=>new sS(this._contextProvider,e))}setAdapter(e){this.threads.__internal_setAdapter(cS(e)),this.threads.getMainThreadRuntimeCore().__internal_setAdapter(e)}},uS=e=>{let[t]=(0,w.useState)(()=>new lS(e));(0,w.useEffect)(()=>{t.setAdapter(e)});let{modelContext:n}=Bx()??{};return(0,w.useEffect)(()=>{if(n)return t.registerModelContextProvider(n)},[n,t]),(0,w.useMemo)(()=>new Lx(t),[t])},dS=e=>e._core?.RenderComponent,fS=(0,w.memo)(({runtime:e,aui:t=null,children:n})=>{let r=zv({threads:Rx(e)},{parent:t}),i=dS(e);return(0,q.jsxs)(hv,{value:r,children:[i&&(0,q.jsx)(i,{}),n]})}),pS=(e,t)=>e.Message===t.Message&&e.EditComposer===t.EditComposer&&e.UserEditComposer===t.UserEditComposer&&e.AssistantEditComposer===t.AssistantEditComposer&&e.SystemEditComposer===t.SystemEditComposer&&e.UserMessage===t.UserMessage&&e.AssistantMessage===t.AssistantMessage&&e.SystemMessage===t.SystemMessage,mS=()=>null,hS=(e,t,n)=>{switch(t){case`user`:return n?e.UserEditComposer??e.EditComposer??e.UserMessage??e.Message:e.UserMessage??e.Message;case`assistant`:return n?e.AssistantEditComposer??e.EditComposer??e.AssistantMessage??e.Message:e.AssistantMessage??e.Message;case`system`:return n?e.SystemEditComposer??e.EditComposer??e.SystemMessage??e.Message:e.SystemMessage??e.Message??mS;default:throw Error(`Unknown message role: ${t}`)}},gS=({components:e})=>(0,q.jsx)(hS(e,Q(e=>e.message.role),Q(e=>e.message.composer.isEditing)),{}),_S=(0,w.memo)(({index:e,components:t})=>(0,q.jsx)(yb,{index:e,children:(0,q.jsx)(gS,{components:t})}),(e,t)=>e.index===t.index&&pS(e.components,t.components));_S.displayName=`ThreadPrimitive.MessageByIndex`;var vS=({children:e})=>{let t=Q(e=>e.thread.messages.length);return(0,w.useMemo)(()=>t===0?null:Array.from({length:t},(t,n)=>(0,q.jsx)(yb,{index:n,children:(0,q.jsx)(qv,{getItemState:e=>e.thread().message({index:n}).getState(),children:t=>e({get message(){return t()}})})},n)),[t,e])},yS=({components:e,children:t})=>e?(0,q.jsx)(vS,{children:()=>(0,q.jsx)(gS,{components:e})}):(0,q.jsx)(vS,{children:t});yS.displayName=`ThreadPrimitive.Messages`;var bS=(0,w.memo)(yS,(e,t)=>e.children||t.children?e.children===t.children:pS(e.components,t.components)),xS=e=>{let t=e.message.metadata;if(!(!t||typeof t!=`object`))return t.custom?.quote},SS=`ui://`,CS=e=>!!e?.startsWith(SS),wS=e=>Symbol.iterator in e,TS=e=>`entries`in e,ES=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},DS=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function OS(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:wS(e)&&wS(t)?TS(e)&&TS(t)?ES(e,t):DS(e,t):ES({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function kS(e){let t=w.useRef(void 0);return n=>{let r=e(n);return OS(t.current,r)?t.current:t.current=r}}var AS=e=>{let t=-1;return{startGroup:e=>{t===-1&&(t=e)},endGroup:(n,r)=>{t!==-1&&(r.push({type:e,startIndex:t,endIndex:n}),t=-1)},finalize:(n,r)=>{t!==-1&&r.push({type:e,startIndex:t,endIndex:n})}}},jS=(e,t)=>{let n=[];if(t){let t=AS(`chainOfThoughtGroup`);for(let r=0;r<e.length;r++){let i=e[r];i===`tool-call`||i===`reasoning`?t.startGroup(r):(t.endGroup(r-1,n),n.push({type:`single`,index:r}))}t.finalize(e.length-1,n)}else{let t=AS(`toolGroup`),r=AS(`reasoningGroup`);for(let i=0;i<e.length;i++){let a=e[i];a===`tool-call`?(r.endGroup(i-1,n),t.startGroup(i)):a===`reasoning`?(t.endGroup(i-1,n),r.startGroup(i)):(t.endGroup(i-1,n),r.endGroup(i-1,n),n.push({type:`single`,index:i}))}t.finalize(e.length-1,n),r.finalize(e.length-1,n)}return n},MS=e=>{let t=Q(kS(e=>e.message.parts.map(e=>e.type)));return(0,w.useMemo)(()=>t.length===0?[]:jS(t,e),[t,e])},NS=({Fallback:e,...t})=>{let n=Q(n=>{let r=n.tools.tools[t.toolName]??e;return Array.isArray(r)?r[0]??e:r});return n?(0,q.jsx)(n,{...t}):null},PS=(e,t,n)=>e.renderers[t]?.[0]||(e.fallbacks[0]??n),FS=({Fallback:e,...t})=>{let n=Q(n=>PS(n.dataRenderers,t.name,e));return n?(0,q.jsx)(n,{...t}):null},IS={Text:()=>null,Reasoning:()=>null,Source:()=>null,Image:()=>null,File:()=>null,Unstable_Audio:()=>null,ToolGroup:({children:e})=>e,ReasoningGroup:({children:e})=>e},LS=({components:{Text:e=IS.Text,Reasoning:t=IS.Reasoning,Image:n=IS.Image,Source:r=IS.Source,File:i=IS.File,Unstable_Audio:a=IS.Unstable_Audio,tools:o={},data:s}={}})=>{let c=zv(),l=Q(e=>e.part),u=l.type;if(u===`tool-call`){let e=c.part().addToolResult,t=c.part().resumeToolCall;if(`Override`in o)return(0,q.jsx)(o.Override,{...l,addResult:e,resume:t});let n=o.by_name?.[l.toolName]??o.Fallback;return(0,q.jsx)(NS,{...l,Fallback:n,addResult:e,resume:t})}if(l.status?.type===`requires-action`)throw Error(`Encountered unexpected requires-action status`);switch(u){case`text`:return(0,q.jsx)(e,{...l});case`reasoning`:return(0,q.jsx)(t,{...l});case`source`:return(0,q.jsx)(r,{...l});case`image`:return(0,q.jsx)(n,{...l});case`file`:return(0,q.jsx)(i,{...l});case`audio`:return(0,q.jsx)(a,{...l});case`data`:{let e=s?.by_name?.[l.name]??s?.Fallback;return(0,q.jsx)(FS,{...l,Fallback:e})}default:return console.warn(`Unknown message part type: ${u}`),null}},RS=(0,w.memo)(({index:e,components:t})=>(0,q.jsx)(bb,{index:e,children:(0,q.jsx)(LS,{components:t})}),(e,t)=>e.index===t.index&&e.components?.Text===t.components?.Text&&e.components?.Reasoning===t.components?.Reasoning&&e.components?.Source===t.components?.Source&&e.components?.Image===t.components?.Image&&e.components?.File===t.components?.File&&e.components?.Unstable_Audio===t.components?.Unstable_Audio&&e.components?.tools===t.components?.tools&&e.components?.data===t.components?.data&&e.components?.ToolGroup===t.components?.ToolGroup&&e.components?.ReasoningGroup===t.components?.ReasoningGroup);RS.displayName=`MessagePrimitive.PartByIndex`;var zS=({status:e,component:t})=>(0,q.jsx)(Sb,{text:``,isRunning:e.type===`running`,children:(0,q.jsx)(t,{type:`text`,text:``,status:e})}),BS=Object.freeze({type:`complete`}),VS=Object.freeze({type:`running`}),HS=(0,w.memo)(({components:e})=>{let t=Q(e=>e.message.status??BS);return e?.Empty?(0,q.jsx)(e.Empty,{status:t}):t.type===`running`?(0,q.jsx)(zS,{status:t,component:e?.Text??IS.Text}):null},(e,t)=>e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),US=(0,w.memo)(({components:e,enabled:t})=>Q(e=>{if(!t||e.message.parts.length===0)return!1;let n=e.message.parts[e.message.parts.length-1];return n?.type!==`text`&&n?.type!==`reasoning`})?(0,q.jsx)(HS,{components:e}):null,(e,t)=>e.enabled===t.enabled&&e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),WS=(0,w.memo)(({Quote:e})=>{let t=Q(xS);return t?(0,q.jsx)(e,{text:t.text,messageId:t.messageId}):null});function GS(e,t){let n=e.tools[t.toolName];return(Array.isArray(n)?n[0]??null:n??null)||(CS(t.mcp?.app?.resourceUri)&&e.mcpApp?e.mcpApp.render:null)}var KS=()=>{let e=zv(),t=Q(e=>e.part),n=Q(e=>e.part.type===`tool-call`?GS(e.tools,e.part):null);return!n||t.type!==`tool-call`?null:(0,q.jsx)(n,{...t,addResult:e.part().addToolResult,resume:e.part().resumeToolCall})},qS=()=>{let e=Q(e=>e.part),t=Q(e=>e.part.type===`data`?PS(e.dataRenderers,e.part.name,void 0)??null:null);return!t||e.type!==`data`?null:(0,q.jsx)(t,{...e})},JS=()=>{let e=Q(e=>e.part.type);return e===`tool-call`?(0,q.jsx)(KS,{}):e===`data`?(0,q.jsx)(qS,{}):null},YS=Object.freeze({type:`text`,text:``,status:VS}),XS=({index:e,children:t})=>{let n=zv(),r=Q(e=>e.dataRenderers);return(0,q.jsx)(bb,{index:e,children:(0,q.jsx)(qv,{getItemState:t=>t.message().part({index:e}).getState(),children:i=>t({get part(){let t=i();if(t.type===`tool-call`){let r=GS(n.tools().getState(),t)!==null,i=n.message().part({index:e});return{...t,toolUI:r?(0,q.jsx)(KS,{}):null,addResult:i.addToolResult,resume:i.resumeToolCall}}if(t.type===`data`){let e=PS(r,t.name,void 0)!==void 0;return{...t,dataRendererUI:e?(0,q.jsx)(qS,{}):null}}return t}})})})},ZS=({children:e})=>{let t=Q(e=>e.message.parts.length),n=Q(e=>(e.message.status?.type??`complete`)===`running`);return t===0?t===0&&n?(0,q.jsx)(Sb,{text:``,isRunning:!0,children:e({part:YS})}):null:(0,q.jsx)(q.Fragment,{children:Array.from({length:t},(t,n)=>(0,q.jsx)(XS,{index:n,children:t=>e(t)??(0,q.jsx)(JS,{})},n))})},QS=({components:e,unstable_showEmptyOnNonTextEnd:t=!0,children:n})=>n?(0,q.jsx)(ZS,{children:n}):(0,q.jsx)($S,{components:e,unstable_showEmptyOnNonTextEnd:t});QS.displayName=`MessagePrimitive.Parts`;var $S=({components:e,unstable_showEmptyOnNonTextEnd:t})=>{let n=Q(e=>e.message.parts.length),r=MS(!!e?.ChainOfThought),i=(0,w.useMemo)(()=>n===0?(0,q.jsx)(HS,{components:e}):r.map(t=>{if(t.type===`single`)return(0,q.jsx)(RS,{index:t.index,components:e},t.index);if(t.type===`chainOfThoughtGroup`){let n=e?.ChainOfThought;return n?(0,q.jsx)(Cb,{startIndex:t.startIndex,endIndex:t.endIndex,children:(0,q.jsx)(n,{})},`chainOfThought-${t.startIndex}`):null}else if(t.type===`toolGroup`)return(0,q.jsx)(e?.ToolGroup??IS.ToolGroup,{startIndex:t.startIndex,endIndex:t.endIndex,children:Array.from({length:t.endIndex-t.startIndex+1},(n,r)=>(0,q.jsx)(RS,{index:t.startIndex+r,components:e},r))},`tool-${t.startIndex}`);else return(0,q.jsx)(e?.ReasoningGroup??IS.ReasoningGroup,{startIndex:t.startIndex,endIndex:t.endIndex,children:Array.from({length:t.endIndex-t.startIndex+1},(n,r)=>(0,q.jsx)(RS,{index:t.startIndex+r,components:e},r))},`reasoning-${t.startIndex}`)}),[r,e,n]);return(0,q.jsxs)(q.Fragment,{children:[e?.Quote&&(0,q.jsx)(WS,{Quote:e.Quote}),i,(0,q.jsx)(US,{components:e,enabled:t})]})},eC=Object.freeze([]),tC=e=>e==null?eC:typeof e==`string`?[e]:e,nC=e=>{let t=e.nextChildIdx++;return e.nodeKey===``?String(t):`${e.nodeKey}.${t}`},rC=e=>{let t={key:``,nodeKey:``,indices:[],children:[],nextChildIdx:0},n=[t],r=()=>{let e=n.pop();n[n.length-1].children.push({type:`group`,key:e.key,nodeKey:e.nodeKey,indices:e.indices,children:e.children})};for(let t=0;t<e.length;t++){let i=e[t],a=0;for(;a<n.length-1&&a<i.length&&n[a+1].key===i[a];)a++;for(;n.length-1>a;)r();for(;n.length-1<i.length;){let e=n[n.length-1];n.push({key:i[n.length-1],nodeKey:nC(e),indices:[],children:[],nextChildIdx:0})}let o=n[n.length-1];o.children.push({type:`part`,index:t,nodeKey:nC(o)});for(let e=1;e<n.length;e++)n[e].indices.push(t)}for(;n.length>1;)r();return t.children},iC=Object.freeze({type:`complete`}),aC=()=>{throw 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 skip it.")},oC=(e,t,n)=>{if(e.type===`part`)return(0,q.jsx)(XS,{index:e.index,children:({part:e})=>n({part:e,children:(0,q.jsx)(aC,{})})},e.nodeKey);let r=t[e.indices.at(-1)]?.status??iC;return(0,q.jsx)(w.Fragment,{children:n({part:{type:e.key,status:r,indices:e.indices},children:(0,q.jsx)(q.Fragment,{children:e.children.map(e=>oC(e,t,n))})})},e.nodeKey)},sC=({groupBy:e,children:t})=>{let n=Q(kS(e=>e.message.parts));return(0,q.jsx)(q.Fragment,{children:(0,w.useMemo)(()=>rC(n.map((t,r)=>tC(e(t,r,n)))),[n,e]).map(e=>oC(e,n,t))})};sC.displayName=`MessagePrimitive.GroupedParts`;var cC=()=>{let e=zv(),t=Q(e=>!e.composer.canSend||e.thread.isRunning&&!e.thread.capabilities.queue);return{send:(0,w.useCallback)(t=>{e.composer().send(t)},[e]),disabled:t}},lC=()=>{let e=zv(),t=Q(e=>!e.composer.canCancel);return{cancel:(0,w.useCallback)(()=>{e.composer().cancel()},[e]),disabled:t}},uC=e=>{let{cloud:t,initialMessages:n,maxSteps:r,adapters:i,unstable_humanToolNames:a,...o}=e;return{localRuntimeOptions:{cloud:t,initialMessages:n,maxSteps:r,adapters:i,unstable_humanToolNames:a},otherOptions:o}},dC=e=>{let t=new Map,n=()=>{let n=0;for(let e of t.values())n+=e;e(n)};return{register:()=>{let e=Symbol();return t.set(e,0),{setHeight:r=>{t.get(e)!==r&&(t.set(e,r),n())},unregister:()=>{t.delete(e),n()}}}}},fC=(e={})=>{let t=new Set,n=dC(e=>{a.setState({height:{...a.getState().height,viewport:e}})}),r=dC(e=>{a.setState({height:{...a.getState().height,inset:e}})}),i=(e,t)=>(a.setState({element:{...a.getState().element,[e]:t}}),()=>{a.getState().element[e]===t&&a.setState({element:{...a.getState().element,[e]:null}})}),a=ry(()=>({isAtBottom:!0,scrollToBottom:({behavior:e=`auto`}={})=>{for(let n of t)n({behavior:e})},onScrollToBottom:e=>(t.add(e),()=>{t.delete(e)}),turnAnchor:e.turnAnchor??`bottom`,topAnchorMessageClamp:{tallerThan:e.topAnchorMessageClamp?.tallerThan??`10em`,visibleHeight:e.topAnchorMessageClamp?.visibleHeight??`6em`},height:{viewport:0,inset:0},element:{viewport:null,anchor:null,target:null},targetConfig:null,topAnchorTurn:null,registerViewport:n.register,registerContentInset:r.register,registerViewportElement:e=>i(`viewport`,e),registerAnchorElement:e=>i(`anchor`,e),registerAnchorTargetElement:(e,t)=>(a.setState({element:{...a.getState().element,target:e},targetConfig:e&&t?t:null}),()=>{a.getState().element.target===e&&a.setState({element:{...a.getState().element,target:null},targetConfig:null})}),setTopAnchorTurn:e=>{a.setState({topAnchorTurn:e})}}));return a};function pC(e,t){function n(n){let r=(0,w.useContext)(e);if(!n?.optional&&!r)throw Error(`This component must be used within ${t}.`);return r}return n}function mC(e,t){function n(n){let r=e(n);return r?r[t]:null}function r(e){let t=!1,r;typeof e==`function`?r=e:e&&typeof e==`object`&&(t=!!e.optional,r=e.selector);let i=n({optional:t});return i?r?i(r):i():null}return{[t]:r,[`${t}Store`]:n}}var hC=(0,w.createContext)(null),{useThreadViewport:gC,useThreadViewportStore:_C}=mC(pC(hC,`ThreadPrimitive.Viewport`),`useThreadViewport`),vC=e=>e,yC=e=>{let t=_C({optional:!0}),[n]=(0,w.useState)(()=>fC(e));return(0,w.useEffect)(()=>t?.getState().onScrollToBottom(()=>{n.getState().scrollToBottom()}),[t,n]),(0,w.useEffect)(()=>{if(t)return n.subscribe(e=>{t.getState().isAtBottom!==e.isAtBottom&&vC(t).setState({isAtBottom:e.isAtBottom})})},[n,t]),n},bC=({children:e,options:t={}})=>{let n=yC(t),[r]=(0,w.useState)(()=>({useThreadViewport:n}));return(0,q.jsx)(hC.Provider,{value:r,children:e})},xC=()=>((0,w.useEffect)(()=>{},[zv()]),null),SC=(0,w.memo)(({children:e,aui:t,runtime:n})=>(0,q.jsxs)(fS,{runtime:n,aui:t??null,children:[(0,q.jsx)(xC,{}),(0,q.jsx)(bC,{children:e})]}));function CC(e){let t=zv(),n=Q(()=>t.composer.source?t.composer().__internal_getRuntime?.()??null:null);if(!n&&!e?.optional)throw Error(`ComposerRuntime is not available`);return n}var wC=Symbol.for(`react.lazy`),TC=w.use;function EC(e){return typeof e==`object`&&!!e&&`then`in e}function DC(e){return typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===wC&&`_payload`in e&&EC(e._payload)}function OC(e){let t=kC(e),n=w.forwardRef((e,n)=>{let{children:r,...i}=e;DC(r)&&typeof TC==`function`&&(r=TC(r._payload));let a=w.Children.toArray(r),o=a.find(jC);if(o){let e=o.props.children,r=a.map(t=>t===o?w.Children.count(e)>1?w.Children.only(null):w.isValidElement(e)?e.props.children:null:t);return(0,q.jsx)(t,{...i,ref:n,children:w.isValidElement(e)?w.cloneElement(e,void 0,r):null})}return(0,q.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function kC(e){let t=w.forwardRef((e,t)=>{let{children:n,...r}=e;if(DC(n)&&typeof TC==`function`&&(n=TC(n._payload)),w.isValidElement(n)){let e=NC(n),i=MC(r,n.props);return n.type!==w.Fragment&&(i.ref=t?Fi(t,e):e),w.cloneElement(n,i)}return w.Children.count(n)>1?w.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var AC=Symbol(`radix.slottable`);function jC(e){return w.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===AC}function MC(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function NC(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var PC=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=OC(`Primitive.${t}`),r=w.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,q.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),FC=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`];function IC(e){let t=(0,w.forwardRef)(({render:t,asChild:n,children:r,...i},a)=>{let o=e;if(t&&(0,w.isValidElement)(t)){let e=r===void 0?t.props.children:r;return(0,q.jsx)(o,{...i,asChild:!0,ref:a,children:(0,w.cloneElement)(t,void 0,e)})}return(0,q.jsx)(o,{...i,asChild:n,ref:a,children:r})});return t.displayName=typeof e==`string`?e:e.displayName??e.name??`Component`,t}function LC(e){let t=PC[e],n=IC(t);return n.displayName=`Primitive.${e}`,n}var RC=FC.reduce((e,t)=>(e[t]=LC(t),e),{}),zC=(e,t,n=[])=>{let r=(0,w.forwardRef)((e,r)=>{let i={},a={};Object.keys(e).forEach(t=>{n.includes(t)?i[t]=e[t]:a[t]=e[t]});let o=t(i)??void 0;return(0,q.jsx)(RC.button,{...a,type:`button`,ref:r,disabled:a.disabled||!o,onClick:ea(a.onClick,o)})});return r.displayName=e,r},BC=()=>{let{disabled:e,send:t}=cC(),n=(0,w.useCallback)(()=>t(),[t]);return e?null:n},VC=zC(`ComposerPrimitive.Send`,BC),HC=(0,w.forwardRef)(({onSubmit:e,...t},n)=>{let r=BC(),i=e=>{e.preventDefault(),r&&r()};return(0,q.jsx)(RC.form,{...t,ref:n,onSubmit:ea(e,i)})});HC.displayName=`ComposerPrimitive.Root`;function UC(){return UC=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},UC.apply(null,arguments)}function WC(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var GC=w.useLayoutEffect,KC=function(e){var t=w.useRef(e);return GC(function(){t.current=e}),t},qC=function(e,t){if(typeof e==`function`){e(t);return}e.current=t},JC=function(e,t){var n=w.useRef();return w.useCallback(function(r){e.current=r,n.current&&qC(n.current,null),n.current=t,t&&qC(t,r)},[t])},YC={"min-height":`0`,"max-height":`none`,height:`0`,visibility:`hidden`,overflow:`hidden`,position:`absolute`,"z-index":`-1000`,top:`0`,right:`0`,display:`block`},XC=function(e){Object.keys(YC).forEach(function(t){e.style.setProperty(t,YC[t],`important`)})},ZC=null,QC=function(e,t){var n=e.scrollHeight;return t.sizingStyle.boxSizing===`border-box`?n+t.borderSize:n-t.paddingSize};function $C(e,t,n,r){n===void 0&&(n=1),r===void 0&&(r=1/0),ZC||(ZC=document.createElement(`textarea`),ZC.setAttribute(`tabindex`,`-1`),ZC.setAttribute(`aria-hidden`,`true`),XC(ZC)),ZC.parentNode===null&&document.body.appendChild(ZC);var i=e.paddingSize,a=e.borderSize,o=e.sizingStyle,s=o.boxSizing;Object.keys(o).forEach(function(e){var t=e;ZC.style[t]=o[t]}),XC(ZC),ZC.value=t;var c=QC(ZC,e);ZC.value=t,c=QC(ZC,e),ZC.value=`x`;var l=ZC.scrollHeight-i,u=l*n;s===`border-box`&&(u=u+i+a),c=Math.max(u,c);var d=l*r;return s===`border-box`&&(d=d+i+a),c=Math.min(d,c),[c,l]}var ew=function(){},tw=function(e,t){return e.reduce(function(e,n){return e[n]=t[n],e},{})},nw=[`borderBottomWidth`,`borderLeftWidth`,`borderRightWidth`,`borderTopWidth`,`boxSizing`,`fontFamily`,`fontSize`,`fontStyle`,`fontWeight`,`letterSpacing`,`lineHeight`,`paddingBottom`,`paddingLeft`,`paddingRight`,`paddingTop`,`tabSize`,`textIndent`,`textRendering`,`textTransform`,`width`,`wordBreak`,`wordSpacing`,`scrollbarGutter`],rw=!!document.documentElement.currentStyle,iw=function(e){var t=window.getComputedStyle(e);if(t===null)return null;var n=tw(nw,t),r=n.boxSizing;return r===``?null:(rw&&r===`border-box`&&(n.width=parseFloat(n.width)+parseFloat(n.borderRightWidth)+parseFloat(n.borderLeftWidth)+parseFloat(n.paddingRight)+parseFloat(n.paddingLeft)+`px`),{sizingStyle:n,paddingSize:parseFloat(n.paddingBottom)+parseFloat(n.paddingTop),borderSize:parseFloat(n.borderBottomWidth)+parseFloat(n.borderTopWidth)})};function aw(e,t,n){var r=KC(n);w.useLayoutEffect(function(){var n=function(e){return r.current(e)};if(e)return e.addEventListener(t,n),function(){return e.removeEventListener(t,n)}},[])}var ow=function(e,t){aw(document.body,`reset`,function(n){e.current.form===n.target&&t(n)})},sw=function(e){aw(window,`resize`,e)},cw=function(e){aw(document.fonts,`loadingdone`,e)},lw=[`cacheMeasurements`,`maxRows`,`minRows`,`onChange`,`onHeightChange`],uw=w.forwardRef(function(e,t){var n=e.cacheMeasurements,r=e.maxRows,i=e.minRows,a=e.onChange,o=a===void 0?ew:a,s=e.onHeightChange,c=s===void 0?ew:s,l=WC(e,lw),u=l.value!==void 0,d=w.useRef(null),f=JC(d,t),p=w.useRef(0),m=w.useRef(),h=function(){var e=d.current,t=n&&m.current?m.current:iw(e);if(t){m.current=t;var a=$C(t,e.value||e.placeholder||`x`,i,r),o=a[0],s=a[1];p.current!==o&&(p.current=o,e.style.setProperty(`height`,o+`px`,`important`),c(o,{rowHeight:s}))}};return w.useLayoutEffect(h),ow(d,function(){if(!u){var e=d.current.value;requestAnimationFrame(function(){var t=d.current;t&&e!==t.value&&h()})}}),sw(h),cw(h),w.createElement(`textarea`,UC({},l,{onChange:function(e){u||h(),o(e)},ref:f}))}),dw=e=>{let t=Da(e),n=gC(e=>e.onScrollToBottom);(0,w.useEffect)(()=>n(t),[n,t])},fw=(0,w.createContext)(null),pw=()=>(0,w.useContext)(fw),mw=({children:e})=>{let t=(0,w.useRef)(new Map),n=(0,w.useRef)([]),r=(0,w.useCallback)(()=>{let e=Array.from(t.current.entries());e.sort((e,t)=>t[1]-e[1]),n.current=e.map(([e])=>e)},[]),i=(0,w.useCallback)((e,n)=>{let i=n?.priority??0;return t.current.set(e,i),r(),()=>{t.current.delete(e),r()}},[r]),a=(0,w.useCallback)(()=>n.current,[]),o=(0,w.useMemo)(()=>({register:i,getPlugins:a}),[i,a]);return(0,q.jsx)(fw.Provider,{value:o,children:e})},hw=(0,w.createContext)(null),gw=(0,w.createContext)(null),_w=()=>(0,w.useContext)(hw),vw=()=>()=>{},yw=()=>null,bw=()=>{let e=_w();return(0,w.useSyncExternalStore)(e?e.subscribeAria:vw,e?e.getActiveAria:yw,e?e.getActiveAria:yw)};function xw(){let e=(0,w.useRef)(new Set);return{notify:(0,w.useCallback)(()=>{for(let t of e.current)t()},[]),subscribe:(0,w.useCallback)(t=>(e.current.add(t),()=>{e.current.delete(t)}),[])}}var Sw=({children:e})=>{let t=(0,w.useRef)(new Map),n=(0,w.useRef)(new Set),{notify:r,subscribe:i}=xw(),a=(0,w.useCallback)(e=>{let{char:i}=e;if(t.current.has(i))return()=>{};let a=new Map(t.current);a.set(i,e),t.current=a,r();for(let t of n.current)t.added(e);return()=>{let e=new Map(t.current);e.delete(i),t.current=e,r();for(let e of n.current)e.removed(i)}},[r]),o=(0,w.useCallback)(()=>t.current,[]),s=(0,w.useCallback)(e=>(n.current.add(e),()=>{n.current.delete(e)}),[]),c=(0,w.useRef)(null),l=(0,w.useRef)(null),{notify:u,subscribe:d}=xw(),f=(0,w.useCallback)((e,t)=>{if(t===null){if(l.current!==e)return;c.current=null,l.current=null,u();return}let n=c.current;l.current===e&&n!==null&&n.popoverId===t.popoverId&&n.highlightedItemId===t.highlightedItemId||(c.current=t,l.current=e,u())},[u]),p=(0,w.useCallback)(()=>c.current,[]),m=(0,w.useMemo)(()=>({register:a,getTriggers:o,subscribe:i,subscribeLifecycle:s,getActiveAria:p,subscribeAria:d}),[a,o,i,s,p,d]),h=(0,w.useMemo)(()=>({setActiveAria:f}),[f]);return(0,q.jsx)(hw.Provider,{value:m,children:(0,q.jsx)(gw.Provider,{value:h,children:e})})},Cw=({children:e})=>pw()?(0,q.jsx)(Sw,{children:e}):(0,q.jsx)(mw,{children:(0,q.jsx)(Sw,{children:e})});Cw.displayName=`ComposerPrimitive.TriggerPopoverRoot`;var ww=(0,w.forwardRef)(({autoFocus:e=!1,asChild:t,render:n,disabled:r,onChange:i,onKeyDown:a,onPaste:o,onSelect:s,submitOnEnter:c,submitMode:l,cancelOnEscape:u=!0,unstable_focusOnRunStart:d=!0,unstable_focusOnScrollToBottom:f=!0,unstable_focusOnThreadSwitched:p=!0,addAttachmentOnPaste:m=!0,...h},g)=>{let _=zv(),v=pw(),y=bw(),b=l??(c===!1?`none`:`enter`),x=Q(e=>e.composer.isEditing?e.composer.text:``),S=Q(e=>e.thread.isDisabled||e.composer.dictation?.inputDisabled)||r,C=(0,w.useRef)(null),T=Ii(g,C),E=(0,w.useRef)(!1);Oa(e=>{if(!C.current?.contains(e.target))return;if(v){for(let t of v.getPlugins())if(t.handleKeyDown(e))return}if(!u)return;let t=_.composer();t.getState().canCancel&&(t.cancel(),e.preventDefault())});let D=e=>{if(!S&&!e.nativeEvent.isComposing){if(v){for(let t of v.getPlugins())if(t.handleKeyDown(e))return}if(e.key===`Enter`){let t=_.thread().getState(),n=t.capabilities.queue;if(e.shiftKey&&(e.ctrlKey||e.metaKey)&&n&&b!==`none`&&_.composer().getState().canSend){e.preventDefault(),_.composer().send({steer:!0});return}if(e.shiftKey||t.isRunning&&!n)return;let r=!1;b===`ctrlEnter`?r=e.ctrlKey||e.metaKey:b===`enter`&&(r=!0),r&&(e.preventDefault(),C.current?.closest(`form`)?.requestSubmit())}}},O=async e=>{if(!m)return;let t=_.thread().getState().capabilities,n=Array.from(e.clipboardData?.files||[]);if(t.attachments&&n.length>0)try{e.preventDefault(),await Promise.all(n.map(e=>_.composer().addAttachment(e)))}catch(e){console.error(`Error adding attachment:`,e)}},k=e&&!S,A=(0,w.useCallback)(()=>{let e=C.current;!e||!k||(e.focus({preventScroll:!0}),e.setSelectionRange(e.value.length,e.value.length))},[k]);(0,w.useEffect)(()=>A(),[A]),dw(()=>{_.composer().getState().type===`thread`&&f&&A()}),(0,w.useEffect)(()=>{if(!(_.composer().getState().type!==`thread`||!d))return _.on(`thread.runStart`,A)},[d,A,_]),(0,w.useEffect)(()=>{if(!(_.composer().getState().type!==`thread`||!p))return _.on(`threadListItem.switchedTo`,A)},[p,A,_]);let j=y?{"aria-controls":y.popoverId,"aria-expanded":!0,"aria-haspopup":`listbox`,"aria-activedescendant":y.highlightedItemId}:{},M={name:`input`,value:x,...h,...j,ref:T,disabled:S,onChange:ea(i,e=>{if(!_.composer().getState().isEditing)return;let t=e.nativeEvent.isComposing===!0;E.current&&!t&&(E.current=!1);let n=t||E.current;if(I_(()=>{_.composer().setText(e.target.value)}),n)return;let r=e.target.selectionStart??e.target.value.length;if(v)for(let e of v.getPlugins())e.setCursorPosition(r)}),onKeyDown:ea(a,D),onCompositionStart:ea(h.onCompositionStart,()=>{E.current=!0}),onCompositionEnd:ea(h.onCompositionEnd,e=>{if(E.current=!1,!_.composer().getState().isEditing)return;let t=e.target;I_(()=>{_.composer().setText(t.value)});let n=t.selectionStart??t.value.length;if(v)for(let e of v.getPlugins())e.setCursorPosition(n)}),onSelect:ea(s,e=>{if(E.current)return;let t=e.target,n=t.selectionStart??t.value.length;if(v)for(let e of v.getPlugins())e.setCursorPosition(n)}),onPaste:ea(o,O)};if(n&&(0,w.isValidElement)(n)){let e=h.children===void 0?n.props.children:h.children;return(0,q.jsx)(Ri,{...M,children:(0,w.cloneElement)(n,void 0,e)})}return(0,q.jsx)(t?Ri:uw,{...M})});ww.displayName=`ComposerPrimitive.Input`;var Tw=zC(`ComposerPrimitive.Cancel`,()=>{let{disabled:e,cancel:t}=lC();return e?null:t}),Ew=()=>Q(e=>{if(e.part.type!==`text`&&e.part.type!==`reasoning`)throw Error(`MessagePartText can only be used inside text or reasoning message parts.`);return e.part}),Dw=(0,w.createContext)(null),Ow=e=>({useSmoothStatus:ry(()=>e)}),kw=({children:e})=>{let t=jw({optional:!0}),n=zv(),[r]=(0,w.useState)(()=>Ow(n.part().getState().status));return t?e:(0,q.jsx)(Dw.Provider,{value:r,children:e})},Aw=e=>{let t=(0,w.forwardRef)((t,n)=>(0,q.jsx)(kw,{children:(0,q.jsx)(e,{...t,ref:n})}));return t.displayName=e.displayName,t};function jw(e){let t=(0,w.useContext)(Dw);if(!e?.optional&&!t)throw Error(`This component must be used within a SmoothContextProvider.`);return t}var{useSmoothStatus:Mw,useSmoothStatusStore:Nw}=mC(jw,`useSmoothStatus`),Pw=class{currentText;setText;animationFrameId=null;lastUpdateTime=Date.now();targetText=``;constructor(e,t){this.currentText=e,this.setText=t}start(){this.animationFrameId===null&&(this.lastUpdateTime=Date.now(),this.animate())}stop(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}animate=()=>{let e=Date.now(),t=e-this.lastUpdateTime,n=this.targetText.length-this.currentText.length,r=Math.min(5,250/n),i=0;for(;t>=r&&i<n;)i++,t-=r;i===n?this.animationFrameId=null:this.animationFrameId=requestAnimationFrame(this.animate),i!==0&&(this.currentText=this.targetText.slice(0,this.currentText.length+i),this.lastUpdateTime=e-t,this.setText(this.currentText))}},Fw=Object.freeze({type:`running`}),Iw=(e,t=!1)=>{let{text:n}=e,r=Q(e=>e.message.id),i=(0,w.useRef)(r),[a,o]=(0,w.useState)(e.status.type===`running`?``:n),s=Nw({optional:!0}),c=Da(t=>{if(o(t),s){let n=a!==t||e.status.type===`running`?Fw:e.status;vC(s).setState(n,!0)}});(0,w.useEffect)(()=>{if(s){let r=t&&(a!==n||e.status.type===`running`)?Fw:e.status;vC(s).setState(r,!0)}},[s,t,n,a,e.status]);let[l]=(0,w.useState)(new Pw(a,c));return(0,w.useEffect)(()=>{if(!t){l.stop();return}if(i.current!==r||!n.startsWith(l.targetText)){i.current=r,e.status.type===`running`?(c(``),l.currentText=``,l.targetText=n,l.start()):(c(n),l.currentText=n,l.targetText=n,l.stop());return}l.targetText=n,l.start()},[c,l,r,t,n,e.status.type]),(0,w.useEffect)(()=>()=>{l.stop()},[l]),(0,w.useMemo)(()=>t?{type:`text`,text:a,status:n===a?e.status:Fw}:e,[t,a,e,n])},Lw=(0,w.forwardRef)(({smooth:e=!0,component:t=`span`,...n},r)=>{let{text:i,status:a}=Iw(Ew(),e);return(0,q.jsx)(t,{"data-status":a.type,...n,ref:r,children:i})});Lw.displayName=`MessagePartPrimitive.Text`;var Rw=()=>Q(e=>{if(e.part.type!==`image`)throw Error(`MessagePartImage can only be used inside image message parts.`);return e.part}),zw=(0,w.forwardRef)((e,t)=>{let{image:n}=Rw();return(0,q.jsx)(RC.img,{src:n,...e,ref:t})});zw.displayName=`MessagePartPrimitive.Image`;var Bw=({children:e})=>Q(e=>e.part.status.type===`running`)?e:null;Bw.displayName=`MessagePartPrimitive.InProgress`;var Vw=e=>{let t=(0,w.useRef)(void 0);return(0,w.useCallback)(n=>{t.current&&=(t.current(),void 0),n&&(t.current=e(n))},[e])},Hw=(e,t)=>{let n=e.trim().match(/^(\d+(?:\.\d+)?|\.\d+)(em|px|rem)$/);if(!n)return 1/0;let r=Number(n[1]),i=n[2];return i===`px`?r:i===`em`?r*(parseFloat(getComputedStyle(t).fontSize)||16):i===`rem`?r*(parseFloat(getComputedStyle(document.documentElement).fontSize)||16):1/0},Uw=e=>e.dataset.messageId,Ww=()=>{let e=document.createElement(`div`);return e.dataset.auiTopAnchorReserve=``,e.style.height=`0px`,e.style.flexShrink=`0`,e.style.pointerEvents=`none`,e.setAttribute(`aria-hidden`,`true`),e},Gw=(e,t)=>{let n=`${t}px`;return e.style.height===n?!1:(e.style.height=n,!0)},Kw=e=>{let t=window.devicePixelRatio||1;return Math.round(e*t)/t},qw=()=>{let e=zv(),t=Q(()=>e.message());return Vw((0,w.useCallback)(e=>{let n=()=>{t.setIsHovering(!0)},r=()=>{t.setIsHovering(!1)};return e.addEventListener(`mouseenter`,n),e.addEventListener(`mouseleave`,r),e.matches(`:hover`)&&queueMicrotask(()=>t.setIsHovering(!0)),()=>{e.removeEventListener(`mouseenter`,n),e.removeEventListener(`mouseleave`,r),t.setIsHovering(!1)}},[t]))},Jw=()=>{let e=gC(e=>e.topAnchorTurn?.anchorId);return Q(t=>t.message.role===`user`&&t.message.index>0&&t.message.index===t.thread.messages.length-2&&t.thread.messages.at(-1)?.role===`assistant`&&(t.message.id===e||t.thread.isRunning))},Yw=()=>{let e=gC(e=>e.topAnchorTurn?.targetId);return Q(t=>t.message.isLast&&t.message.role===`assistant`&&t.message.index>=1&&t.thread.messages.at(t.message.index-1)?.role===`user`&&(t.message.id===e||t.thread.isRunning))},Xw=(e,t)=>Vw((0,w.useCallback)(n=>{if(e)return t.getState().registerAnchorElement(n)},[e,t])),Zw=({active:e,threadViewportStore:t})=>Vw((0,w.useCallback)(n=>{if(!e)return;let r=t.getState(),i=r.topAnchorMessageClamp;return r.registerAnchorTargetElement(n,{tallerThan:Hw(i.tallerThan,n),visibleHeight:Hw(i.visibleHeight,n)})},[e,t])),Qw=({forwardedRef:e,...t})=>{let n=Ii(e,qw()),r=Q(e=>e.message.id);return(0,q.jsx)(RC.div,{...t,ref:n,"data-message-id":r})},$w=({forwardedRef:e,threadViewportStore:t,...n})=>{let r=qw(),i=Jw(),a=Yw(),o=Ii(e,r,Xw(i,t),Zw({active:a,threadViewportStore:t})),s=Q(e=>e.message.id);return(0,q.jsx)(RC.div,{...n,ref:o,"data-message-id":s,"data-aui-top-anchor-user":i?``:void 0,"data-aui-top-anchor-target":a?``:void 0})},eT=(0,w.forwardRef)((e,t)=>{let n=_C();return n.getState().turnAnchor===`top`?(0,q.jsx)($w,{...e,forwardedRef:t,threadViewportStore:n}):(0,q.jsx)(Qw,{...e,forwardedRef:t})});eT.displayName=`MessagePrimitive.Root`;var tT={...IS,Text:()=>(0,q.jsxs)(`p`,{style:{whiteSpace:`pre-line`},children:[(0,q.jsx)(Lw,{}),(0,q.jsx)(Bw,{children:(0,q.jsx)(`span`,{style:{fontFamily:`revert`},children:` ●`})})]}),Image:()=>(0,q.jsx)(zw,{})},nT=e=>{if(`children`in e)return(0,q.jsx)(QS,{children:e.children});let{components:t,...n}=e;return(0,q.jsx)(QS,{components:t?{Text:t.Text??tT.Text,Image:t.Image??tT.Image,Reasoning:t.Reasoning??IS.Reasoning,Source:t.Source??IS.Source,File:t.File??IS.File,Unstable_Audio:t.Unstable_Audio??IS.Unstable_Audio,...`ChainOfThought`in t?{ChainOfThought:t.ChainOfThought}:{tools:t.tools,data:t.data,ToolGroup:t.ToolGroup??IS.ToolGroup,ReasoningGroup:t.ReasoningGroup??IS.ReasoningGroup},Empty:t.Empty,Quote:t.Quote}:tT,...n})};nT.displayName=`MessagePrimitive.Parts`;var rT=(0,w.forwardRef)((e,t)=>(0,q.jsx)(RC.div,{...e,ref:t}));rT.displayName=`ThreadPrimitive.Root`;var iT=e=>{let t=Da(e);return Vw((0,w.useCallback)(e=>{let n=new ResizeObserver(()=>{t()}),r=new MutationObserver(e=>{e.some(e=>e.type!==`attributes`||e.attributeName!==`style`)&&t()});return n.observe(e),r.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),()=>{n.disconnect(),r.disconnect()}},[t]))},aT=({autoScroll:e,scrollToBottomOnRunStart:t=!0,scrollToBottomOnInitialize:n=!0,scrollToBottomOnThreadSwitch:r=!0})=>{let i=(0,w.useRef)(null),a=_C();e===void 0&&(e=a.getState().turnAnchor!==`top`);let o=(0,w.useRef)(0),s=(0,w.useRef)(null),c=(0,w.useCallback)(e=>{let t=i.current;t&&(s.current=e,t.scrollTo({top:t.scrollHeight,behavior:e}))},[]),l=(0,w.useCallback)(()=>{let e=a.getState();return e.turnAnchor===`top`&&e.element.viewport===i.current&&e.element.anchor!==null},[a]),u=()=>{let e=i.current;if(!e)return;let t=a.getState().isAtBottom,n=Math.abs(e.scrollHeight-e.scrollTop-e.clientHeight)<1||e.scrollHeight<=e.clientHeight;!n&&o.current<e.scrollTop||(n&&(s.current=null),(n||s.current===null)&&n!==t&&vC(a).setState({isAtBottom:n})),o.current=e.scrollTop},d=iT(()=>{let t=s.current;t&&l()?s.current=null:t?c(t):e&&a.getState().isAtBottom&&c(`instant`),u()}),f=Vw(e=>(e.addEventListener(`scroll`,u),()=>{e.removeEventListener(`scroll`,u)}));return dw(({behavior:e})=>{c(e)}),Wv(`thread.runStart`,()=>{t&&a.getState().turnAnchor!==`top`&&(s.current=`auto`,requestAnimationFrame(()=>{c(`auto`)}))}),Wv(`thread.initialize`,()=>{n&&(s.current=`instant`,requestAnimationFrame(()=>{c(`instant`)}))}),Wv(`threadListItem.switchedTo`,()=>{r&&(s.current=`instant`,requestAnimationFrame(()=>{c(`instant`)}))}),Ii(d,f,i)},oT=(e,t)=>Vw((0,w.useCallback)(n=>{if(!e)return;let r=e(),i=()=>{let e=t?t(n):n.offsetHeight;r.setHeight(e)},a=new ResizeObserver(i);return a.observe(n),i(),()=>{a.disconnect(),r.unregister()}},[e,t])),sT=e=>{let t=0,n=e;for(;n;)t+=n.offsetTop,n=n.offsetParent;return t},cT=(e,t)=>{let n=0,r=e;for(;r&&r!==t;)n+=r.offsetTop,r=r.offsetParent;return r===t?n:sT(e)-sT(t)},lT=({viewport:e,anchor:t,tallerThan:n,visibleHeight:r})=>{let i=cT(t,e),a=t.offsetHeight;return i+Math.max(0,a-(a<=n?a:r))},uT=({scrollHeight:e,...t})=>{let{viewport:n}=t,r=lT(t)+n.clientHeight;return Math.max(0,r-e)},dT=({viewport:e,reserve:t,...n})=>uT({viewport:e,...n,scrollHeight:e.scrollHeight-t.offsetHeight}),fT=e=>{let t=new ResizeObserver(e),n=new MutationObserver(e),r=null,i=null,a=null,o=()=>{t.disconnect(),n.disconnect(),r=null,i=null,a=null};return{target:(e,s,c)=>{r===e&&i===s&&a===c||(o(),t.observe(e),t.observe(s),t.observe(c),n.observe(c,{childList:!0,subtree:!0,characterData:!0}),r=e,i=s,a=c)},disconnect:o}},pT=e=>{let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},cancel:()=>{t!==null&&(cancelAnimationFrame(t),t=null)}}},mT=e=>{let t=null,n;function r(){let r=e.getState(),{viewport:o,anchor:s,target:c}=r.element,l=r.targetConfig;if(r.turnAnchor!==`top`||!o||!s||!c||!l){a.disconnect(),t&&(Gw(t,0),t.remove());return}if(t??=Ww(),(t.parentElement!==c.parentElement||t.previousElementSibling!==c)&&c.after(t),a.target(o,s,c),Gw(t,dT({viewport:o,anchor:s,reserve:t,...l}))){i.schedule();return}let u=Uw(s);if(u!==void 0&&n===u)return;let d=Kw(lT({viewport:o,anchor:s,...l}));Math.abs(o.scrollTop-d)>1&&o.scrollTo({top:d,behavior:`smooth`}),u!==void 0&&(n=u)}let i=pT(r),a=fT(i.schedule);i.schedule();let o=e.subscribe(i.schedule);return()=>{i.cancel(),o(),a.disconnect(),t?.remove()}},hT=e=>{let t=_C();(0,w.useLayoutEffect)(()=>{if(e)return mT(t)},[e,t])},gT=({isRunning:e,messages:t})=>{if(!e)return null;let n=t.at(-1),r=t.at(-2);return r?.role!==`user`||n?.role!==`assistant`?null:{anchorId:r.id,targetId:n.id}},_T=e=>gT(e)?.anchorId,vT=e=>gT(e)?.targetId,yT=()=>oT(gC(e=>e.registerViewport),(0,w.useCallback)(e=>e.clientHeight,[])),bT=()=>Vw(gC(e=>e.registerViewportElement)),xT=e=>{let t=_C(),n=Q(t=>{if(e)return _T(t.thread)}),r=Q(t=>{if(e)return vT(t.thread)}),i=(0,w.useMemo)(()=>!n||!r?null:{anchorId:n,targetId:r},[n,r]);(0,w.useLayoutEffect)(()=>{if(!i)return;let e=t.getState(),n=e.topAnchorTurn;n?.anchorId===i.anchorId&&n.targetId===i.targetId||e.setTopAnchorTurn(i)},[i,t]);let a=(0,w.useCallback)(()=>{t.getState().setTopAnchorTurn(null)},[t]);Wv(`thread.initialize`,a),Wv(`threadListItem.switchedTo`,a)},ST=(0,w.forwardRef)(({autoScroll:e,scrollToBottomOnRunStart:t,scrollToBottomOnInitialize:n,scrollToBottomOnThreadSwitch:r,children:i,...a},o)=>{let s=aT({autoScroll:e,scrollToBottomOnRunStart:t,scrollToBottomOnInitialize:n,scrollToBottomOnThreadSwitch:r}),c=yT(),l=bT(),u=_C().getState().turnAnchor===`top`;xT(u),hT(u);let d=Ii(o,s,c,l);return(0,q.jsx)(RC.div,{...a,ref:d,children:i})});ST.displayName=`ThreadPrimitive.ViewportScrollable`;var CT=(0,w.forwardRef)(({turnAnchor:e,topAnchorMessageClamp:t,...n},r)=>(0,q.jsx)(bC,{options:{turnAnchor:e,topAnchorMessageClamp:t},children:(0,q.jsx)(ST,{...n,ref:r})}));CT.displayName=`ThreadPrimitive.Viewport`;var wT=e({AssistantRuntimeImpl:()=>Lx,BaseAssistantRuntimeCore:()=>Mb,CompositeContextProvider:()=>Ly,DefaultThreadComposerRuntimeCore:()=>nx,MessageRepository:()=>Yb,ThreadRuntimeImpl:()=>Mx,fromThreadMessageLike:()=>Gb,generateId:()=>Pb,getAutoStatus:()=>Ub,splitLocalRuntimeOptions:()=>uC,useComposerInputPluginRegistryOptional:()=>pw,useSmooth:()=>Iw,useSmoothStatus:()=>Mw,useToolInvocations:()=>Yx,withSmoothContextProvider:()=>Aw});function TT(e,t){let n=getComputedStyle(e);return t*parseFloat(n.fontSize)}function ET(e,t){let n=getComputedStyle(e.ownerDocument.body);return t*parseFloat(n.fontSize)}function DT(e){return e/100*window.innerHeight}function OT(e){return e/100*window.innerWidth}function kT(e){switch(typeof e){case`number`:return[e,`px`];case`string`:{let t=parseFloat(e);return e.endsWith(`%`)?[t,`%`]:e.endsWith(`px`)?[t,`px`]:e.endsWith(`rem`)?[t,`rem`]:e.endsWith(`em`)?[t,`em`]:e.endsWith(`vh`)?[t,`vh`]:e.endsWith(`vw`)?[t,`vw`]:[t,`%`]}}}function AT({groupSize:e,panelElement:t,styleProp:n}){let r,[i,a]=kT(n);switch(a){case`%`:r=i/100*e;break;case`px`:r=i;break;case`rem`:r=ET(t,i);break;case`em`:r=TT(t,i);break;case`vh`:r=DT(i);break;case`vw`:r=OT(i);break}return r}function jT(e){return parseFloat(e.toFixed(3))}function MT({group:e}){let{orientation:t,panels:n}=e;return n.reduce((e,n)=>(e+=t===`horizontal`?n.element.offsetWidth:n.element.offsetHeight,e),0)}function NT(e){let{panels:t}=e,n=MT({group:e});return n===0?t.map(e=>({groupResizeBehavior:e.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:e.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:e.panelConstraints.disabled,minSize:0,maxSize:100,panelId:e.id})):t.map(e=>{let{element:t,panelConstraints:r}=e,i=0;r.collapsedSize!==void 0&&(i=jT(AT({groupSize:n,panelElement:t,styleProp:r.collapsedSize})/n*100));let a;r.defaultSize!==void 0&&(a=jT(AT({groupSize:n,panelElement:t,styleProp:r.defaultSize})/n*100));let o=0;r.minSize!==void 0&&(o=jT(AT({groupSize:n,panelElement:t,styleProp:r.minSize})/n*100));let s=100;return r.maxSize!==void 0&&(s=jT(AT({groupSize:n,panelElement:t,styleProp:r.maxSize})/n*100)),{groupResizeBehavior:r.groupResizeBehavior,collapsedSize:i,collapsible:r.collapsible===!0,defaultSize:a,disabled:r.disabled,minSize:o,maxSize:s,panelId:e.id}})}function PT(e,t=`Assertion error`){if(!e)throw Error(t)}function FT(e,t){return Array.from(t).sort(e===`horizontal`?IT:LT)}function IT(e,t){let n=e.element.offsetLeft-t.element.offsetLeft;return n===0?e.element.offsetWidth-t.element.offsetWidth:n}function LT(e,t){let n=e.element.offsetTop-t.element.offsetTop;return n===0?e.element.offsetHeight-t.element.offsetHeight:n}function RT(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.ELEMENT_NODE}function zT(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function BT({orientation:e,rects:t,targetRect:n}){let r={x:n.x+n.width/2,y:n.y+n.height/2},i,a=Number.MAX_VALUE;for(let n of t){let{x:t,y:o}=zT(r,n),s=e===`horizontal`?t:o;s<a&&(a=s,i=n)}return PT(i,`No rect found`),i}var VT;function HT(){return VT===void 0&&(VT=typeof matchMedia==`function`?!!matchMedia(`(pointer:coarse)`).matches:!1),VT}function UT(e){let{element:t,orientation:n,panels:r,separators:i}=e,a=FT(n,Array.from(t.children).filter(RT).map(e=>({element:e}))).map(({element:e})=>e),o=[],s=!1,c=!1,l=-1,u=-1,d=0,f,p=[];{let e=-1;for(let t of a)t.hasAttribute(`data-panel`)&&(e++,t.hasAttribute(`data-disabled`)||(d++,l===-1&&(l=e),u=e))}if(d>1){let t=-1;for(let d of a)if(d.hasAttribute(`data-panel`)){t++;let i=r.find(e=>e.element===d);if(i){if(f){let r=f.element.getBoundingClientRect(),a=d.getBoundingClientRect(),m;if(c){let e=n===`horizontal`?new DOMRect(r.right,r.top,0,r.height):new DOMRect(r.left,r.bottom,r.width,0),t=n===`horizontal`?new DOMRect(a.left,a.top,0,a.height):new DOMRect(a.left,a.top,a.width,0);switch(p.length){case 0:m=[e,t];break;case 1:{let i=p[0];m=[i,BT({orientation:n,rects:[r,a],targetRect:i.element.getBoundingClientRect()})===r?t:e];break}default:m=p;break}}else m=p.length?p:[n===`horizontal`?new DOMRect(r.right,a.top,a.left-r.right,a.height):new DOMRect(a.left,r.bottom,a.width,a.top-r.bottom)];for(let n of m){let r=`width`in n?n:n.element.getBoundingClientRect(),a=HT()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(r.width<a){let e=a-r.width;r=new DOMRect(r.x-e/2,r.y,r.width+e,r.height)}if(r.height<a){let e=a-r.height;r=new DOMRect(r.x,r.y-e/2,r.width,r.height+e)}!s&&!(t<=l||t>u)&&o.push({group:e,groupSize:MT({group:e}),panels:[f,i],separator:`width`in n?void 0:n,rect:r}),s=!1}}c=!1,f=i,p=[]}}else if(d.hasAttribute(`data-separator`)){d.ariaDisabled!==null&&(s=!0);let e=i.find(e=>e.element===d);e?p.push(e):(f=void 0,p=[])}else c=!0}return o}var WT=class{#e={};addListener(e,t){let n=this.#e[e];return n===void 0?this.#e[e]=[t]:n.includes(t)||n.push(t),()=>{this.removeListener(e,t)}}emit(e,t){let n=this.#e[e];if(n!==void 0)if(n.length===1)n[0].call(null,t);else{let e=!1,r=null,i=Array.from(n);for(let n=0;n<i.length;n++){let a=i[n];try{a.call(null,t)}catch(t){r===null&&(e=!0,r=t)}}if(e)throw r}}removeAllListeners(){this.#e={}}removeListener(e,t){let n=this.#e[e];if(n!==void 0){let e=n.indexOf(t);e>=0&&n.splice(e,1)}}},GT=new Map,KT=new WT;function qT(e){GT=new Map(GT),GT.delete(e)}function JT(e,t){for(let[t]of GT)if(t.id===e)return t}function YT(e,t){for(let[t,n]of GT)if(t.id===e)return n;if(t)throw Error(`Could not find data for Group with id ${e}`)}function XT(){return GT}function ZT(e,t){return KT.addListener(`groupChange`,n=>{n.group.id===e&&t(n)})}function QT(e,t){let n=GT.get(e);GT=new Map(GT),GT.set(e,t),KT.emit(`groupChange`,{group:e,prev:n,next:t})}function $T(e,t,n){let r,i={x:1/0,y:1/0};for(let a of t){let t=zT(n,a.rect);switch(e){case`horizontal`:t.x<=i.x&&(r=a,i=t);break;case`vertical`:t.y<=i.y&&(r=a,i=t);break}}return r?{distance:i,hitRegion:r}:void 0}function eE(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function tE(e,t){if(e===t)throw Error(`Cannot compare node with itself`);let n={a:sE(e),b:sE(t)},r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();PT(r,`Stacking order can only be calculated for elements with a common ancestor`);let i={a:oE(aE(n.a)),b:oE(aE(n.b))};if(i.a===i.b){let e=r.childNodes,t={a:n.a.at(-1),b:n.b.at(-1)},i=e.length;for(;i--;){let n=e[i];if(n===t.a)return 1;if(n===t.b)return-1}}return Math.sign(i.a-i.b)}var nE=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function rE(e){let t=getComputedStyle(cE(e)??e).display;return t===`flex`||t===`inline-flex`}function iE(e){let t=getComputedStyle(e);return!!(t.position===`fixed`||t.zIndex!==`auto`&&(t.position!==`static`||rE(e))||+t.opacity<1||`transform`in t&&t.transform!==`none`||`webkitTransform`in t&&t.webkitTransform!==`none`||`mixBlendMode`in t&&t.mixBlendMode!==`normal`||`filter`in t&&t.filter!==`none`||`webkitFilter`in t&&t.webkitFilter!==`none`||`isolation`in t&&t.isolation===`isolate`||nE.test(t.willChange)||t.webkitOverflowScrolling===`touch`)}function aE(e){let t=e.length;for(;t--;){let n=e[t];if(PT(n,`Missing node`),iE(n))return n}return null}function oE(e){return e&&Number(getComputedStyle(e).zIndex)||0}function sE(e){let t=[];for(;e;)t.push(e),e=cE(e);return t}function cE(e){let{parentNode:t}=e;return eE(t)?t.host:t}function lE(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function uE({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!RT(n)||n.contains(e)||e.contains(n))return!0;if(tE(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(lE(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function dE(e,t){let n=[];return t.forEach((t,r)=>{if(r.disabled)return;let i=UT(r),a=$T(r.orientation,i,{x:e.clientX,y:e.clientY});a&&a.distance.x<=0&&a.distance.y<=0&&uE({groupElement:r.element,hitRegion:a.hitRegion.rect,pointerEventTarget:e.target})&&n.push(a.hitRegion)}),n}function fE(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function pE(e,t,n=0){return Math.abs(jT(e)-jT(t))<=n}function mE(e,t){return pE(e,t)?0:e>t?1:-1}function hE({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){let{collapsedSize:i=0,collapsible:a,disabled:o,maxSize:s=100,minSize:c=0}=t;if(o&&!e)return n;if(mE(r,c)<0)if(a){let e=(i+c)/2;r=mE(r,e)<0?i:c}else r=c;return r=Math.min(s,r),r=jT(r),r}function gE({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:a}){if(pE(e,0))return t;let o=a===`imperative-api`,s=Object.values(t),c=Object.values(i),l=[...s],[u,d]=r;PT(u!=null,`Invalid first pivot index`),PT(d!=null,`Invalid second pivot index`);let f=0;switch(a){case`keyboard`:{let t=e<0?d:u,r=n[t];PT(r,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(PT(n!=null,`Previous layout not found for panel index ${t}`),pE(n,i)){let t=o-n;mE(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}{let t=e<0?u:d,r=n[t];PT(r,`No panel constraints found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(PT(n!=null,`Previous layout not found for panel index ${t}`),pE(n,o)){let t=n-i;mE(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}break;default:{let t=e<0?d:u,r=n[t];PT(r,`Panel constraints not found for index ${t}`);let i=s[t],{collapsible:a,collapsedSize:o,minSize:c}=r;if(a&&mE(i,c)<0)if(e>0){let t=c-o,n=t/2;mE(i+e,c)<0&&(e=mE(e,n)<=0?0:t)}else{let t=c-o,n=100-t/2;mE(i-e,c)<0&&(e=mE(100+e,n)>0?0:-t)}break}}{let t=e<0?1:-1,r=e<0?d:u,i=0;for(;;){let e=s[r];PT(e!=null,`Previous layout not found for panel index ${r}`);let a=hE({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:e,size:100})-e;if(i+=a,r+=t,r<0||r>=n.length)break}let a=Math.min(Math.abs(e),Math.abs(i));e=e<0?0-a:a}{let t=e<0?u:d;for(;t>=0&&t<n.length;){let r=Math.abs(e)-Math.abs(f),i=s[t];PT(i!=null,`Previous layout not found for panel index ${t}`);let a=i-r,c=hE({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:i,size:a});if(!pE(i,c)&&(f+=i-c,l[t]=c,f.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?t--:t++}}if(fE(c,l))return i;{let t=e<0?d:u,r=s[t];PT(r!=null,`Previous layout not found for panel index ${t}`);let i=r+f,a=hE({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:r,size:i});if(l[t]=a,!pE(a,i)){let t=i-a,r=e<0?d:u;for(;r>=0&&r<n.length;){let i=l[r];PT(i!=null,`Previous layout not found for panel index ${r}`);let a=i+t,s=hE({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:i,size:a});if(pE(i,s)||(t-=s-i,l[r]=s),pE(t,0))break;e>0?r--:r++}}}if(!pE(Object.values(l).reduce((e,t)=>t+e,0),100,.1))return i;let p=Object.keys(i);return l.reduce((e,t,n)=>(e[p[n]]=t,e),{})}function _E(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(t[n]===void 0||mE(e[n],t[n])!==0)return!1;return!0}function vE({layout:e,panelConstraints:t}){let n=Object.values(e),r=[...n],i=r.reduce((e,t)=>e+t,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(e=>`${e}%`).join(`, `)}`);if(!pE(i,100)&&r.length>0)for(let e=0;e<t.length;e++){let t=r[e];PT(t!=null,`No layout data found for index ${e}`),r[e]=100/i*t}let a=0;for(let e=0;e<t.length;e++){let i=n[e];PT(i!=null,`No layout data found for index ${e}`);let o=r[e];PT(o!=null,`No layout data found for index ${e}`);let s=hE({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:i,size:o});o!=s&&(a+=o-s,r[e]=s)}if(!pE(a,0))for(let e=0;e<t.length;e++){let n=r[e];PT(n!=null,`No layout data found for index ${e}`);let i=n+a,o=hE({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:n,size:i});if(n!==o&&(a-=o-n,r[e]=o,pE(a,0)))break}let o=Object.keys(e);return r.reduce((e,t,n)=>(e[o[n]]=t,e),{})}function yE({groupId:e,panelId:t}){let n=()=>{let t=XT();for(let[n,{defaultLayoutDeferred:r,derivedPanelConstraints:i,layout:a,groupSize:o,separatorToPanels:s}]of t)if(n.id===e)return{defaultLayoutDeferred:r,derivedPanelConstraints:i,group:n,groupSize:o,layout:a,separatorToPanels:s};throw Error(`Group ${e} not found`)},r=()=>{let e=n().derivedPanelConstraints.find(e=>e.panelId===t);if(e!==void 0)return e;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{let e=n().group.panels.find(e=>e.id===t);if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},a=()=>{let e=n().layout[t];if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},o=({nextSize:e,panels:n,prevLayout:r,derivedPanelConstraints:i})=>{let o=a(),s=n.findIndex(e=>e.id===t),c=s===0,l=s===n.length-1;if(l&&e<o&&(c||n.slice(0,s).every((e,t)=>{let n=i[t];return n?.collapsible&&pE(n.collapsedSize,r[n.panelId])}))){let e=n.slice(0,s).reduce((e,t)=>e+r[t.id],0);return{...r,[t]:jT(100-e)}}return gE({delta:l?o-e:e-o,initialLayout:r,panelConstraints:i,pivotIndices:l?[s-1,s]:[s,s+1],prevLayout:r,trigger:`imperative-api`})},s=e=>{if(e===a())return;let{defaultLayoutDeferred:t,derivedPanelConstraints:r,group:i,groupSize:s,layout:c,separatorToPanels:l}=n(),u=vE({layout:o({nextSize:e,panels:i.panels,prevLayout:c,derivedPanelConstraints:r}),panelConstraints:r});_E(c,u)||QT(i,{defaultLayoutDeferred:t,derivedPanelConstraints:r,groupSize:s,layout:u,separatorToPanels:l})};return{collapse:()=>{let{collapsible:e,collapsedSize:t}=r(),{mutableValues:n}=i(),o=a();e&&o!==t&&(n.expandToSize=o,s(t))},expand:()=>{let{collapsible:e,collapsedSize:t,minSize:n}=r(),{mutableValues:o}=i(),c=a();if(e&&c===t){let e=o.expandToSize??n;e===0&&(e=1),s(e)}},getSize:()=>{let{group:e}=n(),t=a(),{element:r}=i();return{asPercentage:t,inPixels:e.orientation===`horizontal`?r.offsetWidth:r.offsetHeight}},isCollapsed:()=>{let{collapsible:e,collapsedSize:t}=r(),n=a();return e&&pE(t,n)},resize:e=>{let{group:t}=n(),{element:r}=i(),a=MT({group:t});s(jT(AT({groupSize:a,panelElement:r,styleProp:e})/a*100))}}}function bE(e){e.defaultPrevented||dE(e,XT()).forEach(t=>{if(t.separator&&!t.separator.disableDoubleClick){let n=t.panels.find(e=>e.panelConstraints.defaultSize!==void 0);if(n){let r=n.panelConstraints.defaultSize,i=yE({groupId:t.group.id,panelId:n.id});i&&r!==void 0&&(i.resize(r),e.preventDefault())}}})}function xE(e){let t=XT();for(let[n]of t)if(n.separators.some(t=>t.element===e))return n;throw Error(`Could not find parent Group for separator element`)}function SE({groupId:e}){let t=()=>{let t=XT();for(let[n,r]of t)if(n.id===e)return{group:n,...r};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){let{defaultLayoutDeferred:e,layout:n}=t();return e?{}:n},setLayout(e){let{defaultLayoutDeferred:n,derivedPanelConstraints:r,group:i,groupSize:a,layout:o,separatorToPanels:s}=t(),c=vE({layout:e,panelConstraints:r});return n?o:(_E(o,c)||QT(i,{defaultLayoutDeferred:n,derivedPanelConstraints:r,groupSize:a,layout:c,separatorToPanels:s}),c)}}}function CE(e,t){let n=xE(e),r=YT(n.id,!0),i=n.separators.find(t=>t.element===e);PT(i,`Matching separator not found`);let a=r.separatorToPanels.get(i);PT(a,`Matching panels not found`);let o=a.map(e=>n.panels.indexOf(e)),s=SE({groupId:n.id}).getLayout(),c=vE({layout:gE({delta:t,initialLayout:s,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:s,trigger:`keyboard`}),panelConstraints:r.derivedPanelConstraints});_E(s,c)||QT(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels})}function wE(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=xE(t);if(!n.disabled)switch(e.key){case`ArrowDown`:e.preventDefault(),n.orientation===`vertical`&&CE(t,5);break;case`ArrowLeft`:e.preventDefault(),n.orientation===`horizontal`&&CE(t,-5);break;case`ArrowRight`:e.preventDefault(),n.orientation===`horizontal`&&CE(t,5);break;case`ArrowUp`:e.preventDefault(),n.orientation===`vertical`&&CE(t,-5);break;case`End`:e.preventDefault(),CE(t,100);break;case`Enter`:{e.preventDefault();let n=xE(t),{derivedPanelConstraints:r,layout:i,separatorToPanels:a}=YT(n.id,!0),o=n.separators.find(e=>e.element===t);PT(o,`Matching separator not found`);let s=a.get(o);PT(s,`Matching panels not found`);let c=s[0],l=r.find(e=>e.panelId===c.id);if(PT(l,`Panel metadata not found`),l.collapsible){let e=i[c.id];CE(t,(l.collapsedSize===e?n.mutableState.expandedPanelSizes[c.id]??l.minSize:l.collapsedSize)-e)}break}case`F6`:{e.preventDefault();let n=xE(t).separators.map(e=>e.element),r=Array.from(n).findIndex(t=>t===e.currentTarget);PT(r!==null,`Index not found`),n[e.shiftKey?r>0?r-1:n.length-1:r+1<n.length?r+1:0].focus({preventScroll:!0});break}case`Home`:e.preventDefault(),CE(t,-100);break}}var TE={cursorFlags:0,state:`inactive`},EE=new WT;function DE(){return TE}function OE(e){return EE.addListener(`change`,e)}function kE(e){let t=TE,n={...TE};n.cursorFlags=e,TE=n,EE.emit(`change`,{prev:t,next:n})}function AE(e){let t=TE;TE=e,EE.emit(`change`,{prev:t,next:e})}function jE(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=XT(),n=dE(e,t),r=new Map,i=!1;n.forEach(e=>{e.separator&&(i||(i=!0,e.separator.element.focus({focusVisible:!1,preventScroll:!0})));let n=t.get(e.group);n&&r.set(e.group,n.layout)}),AE({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:`active`}),n.length&&e.preventDefault()}var ME=e=>e,NE=()=>{},PE=1,FE=2,IE=4,LE=8,RE=3,zE=12,BE;function VE(){return BE===void 0&&(BE=!1,typeof window<`u`&&(window.navigator.userAgent.includes(`Chrome`)||window.navigator.userAgent.includes(`Firefox`))&&(BE=!0)),BE}function HE({cursorFlags:e,groups:t,state:n}){let r=0,i=0;switch(n){case`active`:case`hover`:t.forEach(e=>{if(!e.mutableState.disableCursor)switch(e.orientation){case`horizontal`:r++;break;case`vertical`:i++;break}})}if(!(r===0&&i===0)){switch(n){case`active`:if(e&&VE()){let t=(e&PE)!==0,n=(e&FE)!==0,r=(e&IE)!==0,i=(e&LE)!==0;if(t)return r?`se-resize`:i?`ne-resize`:`e-resize`;if(n)return r?`sw-resize`:i?`nw-resize`:`w-resize`;if(r)return`s-resize`;if(i)return`n-resize`}break}return VE()?r>0&&i>0?`move`:r>0?`ew-resize`:`ns-resize`:r>0&&i>0?`grab`:r>0?`col-resize`:`row-resize`}}var UE=new WeakMap;function WE(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=UE.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(n):e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]));let r=DE();switch(r.state){case`active`:case`hover`:{let e=HE({cursorFlags:r.cursorFlags,groups:r.hitRegions.map(e=>e.group),state:r.state}),i=`*, *:hover {cursor: ${e} !important; }`;if(t===i)return;t=i,e?n.cssRules.length===0?n.insertRule(i):n.replaceSync(i):n.cssRules.length===1&&n.deleteRule(0);break}case`inactive`:t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}UE.set(e,{prevStyle:t,styleSheet:n})}function GE({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:a,prevCursorFlags:o}){let s=0;n.forEach(e=>{let{group:n,groupSize:o}=e,{orientation:c,panels:l}=n,{disableCursor:u}=n.mutableState,d=0;d=a?c===`horizontal`?(t.clientX-a.x)/o*100:(t.clientY-a.y)/o*100:c===`horizontal`?t.clientX<0?-100:100:t.clientY<0?-100:100;let f=r.get(n),p=i.get(n);if(!f||!p)return;let{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:_,separatorToPanels:v}=p;if(h&&_&&v){let t=gE({delta:d,initialLayout:f,panelConstraints:h,pivotIndices:e.panels.map(e=>l.indexOf(e)),prevLayout:_,trigger:`mouse-or-touch`});if(_E(t,_)){if(d!==0&&!u)switch(c){case`horizontal`:s|=d<0?PE:FE;break;case`vertical`:s|=d<0?IE:LE;break}}else QT(e.group,{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:t,separatorToPanels:v})}});let c=0;t.movementX===0?c|=o&RE:c|=s&RE,t.movementY===0?c|=o&zE:c|=s&zE,kE(c),WE(e)}function KE(e){let t=XT(),n=DE();switch(n.state){case`active`:GE({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function qE(e){if(e.defaultPrevented)return;let t=DE(),n=XT();switch(t.state){case`active`:if(e.buttons===0){AE({cursorFlags:0,state:`inactive`}),t.hitRegions.forEach(e=>{let t=YT(e.group.id,!0);QT(e.group,t)});return}for(let n of t.hitRegions)if(n.separator){let{element:t}=n.separator;t.hasPointerCapture?.(e.pointerId)||t.setPointerCapture?.(e.pointerId)}GE({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break;default:{let r=dE(e,n);r.length===0?t.state!==`inactive`&&AE({cursorFlags:0,state:`inactive`}):AE({cursorFlags:0,hitRegions:r,state:`hover`}),WE(e.currentTarget);break}}}function JE(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(DE().state){case`hover`:AE({cursorFlags:0,state:`inactive`})}}function YE(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=DE();switch(t.state){case`active`:AE({cursorFlags:0,state:`inactive`}),t.hitRegions.length>0&&(WE(e.currentTarget),t.hitRegions.forEach(e=>{let t=YT(e.group.id,!0);QT(e.group,t)}),e.preventDefault())}}function XE(e){let t=0,n=0,r={};for(let i of e)if(i.defaultSize!==void 0){t++;let e=jT(i.defaultSize);n+=e,r[i.panelId]=e}else r[i.panelId]=void 0;let i=e.length-t;if(i!==0){let t=jT((100-n)/i);for(let n of e)n.defaultSize===void 0&&(r[n.panelId]=t)}return r}function ZE(e,t,n){if(!n[0])return;let r=e.panels.find(e=>e.element===t);if(!r||!r.onResize)return;let i=MT({group:e}),a=e.orientation===`horizontal`?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,s={asPercentage:jT(a/i*100),inPixels:a};r.mutableValues.prevSize=s,r.onResize(s,r.id,o)}function QE(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function $E({group:e,nextGroupSize:t,prevGroupSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,a=0,o=!1,s=new Map,c=[];for(let l of e.panels){let e=r[l.id]??0;switch(l.panelConstraints.groupResizeBehavior){case`preserve-pixel-size`:{o=!0;let r=jT(e/100*n/t*100);s.set(l.id,r),i+=r;break}default:c.push(l.id),a+=e;break}}if(!o||c.length===0)return r;let l=100-i,u={...r};if(s.forEach((e,t)=>{u[t]=e}),a>0)for(let e of c)u[e]=jT((r[e]??0)/a*l);else{let e=jT(l/c.length);for(let t of c)u[t]=e}return u}function eD(e,t){let n=e.map(e=>e.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;return!0}var tD=new Map;function nD(e){let t=!0;PT(e.element.ownerDocument.defaultView,`Cannot register an unmounted Group`);let n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,a=new n(n=>{for(let r of n){let{borderBoxSize:n,target:i}=r;if(i===e.element){if(t){let t=MT({group:e});if(t===0)return;let n=YT(e.id);if(!n)return;let r=NT(e),i=n.defaultLayoutDeferred?XE(r):n.layout,a=vE({layout:$E({group:e,nextGroupSize:t,prevGroupSize:n.groupSize,prevLayout:i}),panelConstraints:r});if(!n.defaultLayoutDeferred&&_E(n.layout,a)&&QE(n.derivedPanelConstraints,r)&&n.groupSize===t)return;QT(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:r,groupSize:t,layout:a,separatorToPanels:n.separatorToPanels})}}else ZE(e,i,n)}});a.observe(e.element),e.panels.forEach(e=>{PT(!r.has(e.id),`Panel ids must be unique; id "${e.id}" was used more than once`),r.add(e.id),e.onResize&&a.observe(e.element)});let o=MT({group:e}),s=NT(e),c=e.panels.map(({id:e})=>e).join(`,`),l=e.mutableState.defaultLayout;l&&(eD(e.panels,l)||(l=void 0));let u=vE({layout:e.mutableState.layouts[c]??l??XE(s),panelConstraints:s}),d=e.element.ownerDocument;tD.set(d,(tD.get(d)??0)+1);let f=new Map;return UT(e).forEach(e=>{e.separator&&f.set(e.separator,e.panels)}),QT(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:s,groupSize:o,layout:u,separatorToPanels:f}),e.separators.forEach(e=>{PT(!i.has(e.id),`Separator ids must be unique; id "${e.id}" was used more than once`),i.add(e.id),e.element.addEventListener(`keydown`,wE)}),tD.get(d)===1&&(d.addEventListener(`dblclick`,bE,!0),d.addEventListener(`pointerdown`,jE,!0),d.addEventListener(`pointerleave`,KE),d.addEventListener(`pointermove`,qE),d.addEventListener(`pointerout`,JE),d.addEventListener(`pointerup`,YE,!0)),function(){t=!1,tD.set(d,Math.max(0,(tD.get(d)??0)-1)),qT(e),e.separators.forEach(e=>{e.element.removeEventListener(`keydown`,wE)}),tD.get(d)||(d.removeEventListener(`dblclick`,bE,!0),d.removeEventListener(`pointerdown`,jE,!0),d.removeEventListener(`pointerleave`,KE),d.removeEventListener(`pointermove`,qE),d.removeEventListener(`pointerout`,JE),d.removeEventListener(`pointerup`,YE,!0)),a.disconnect()}}function rD(){let[e,t]=(0,w.useState)({});return[e,(0,w.useCallback)(()=>t({}),[])]}function iD(e){let t=(0,w.useId)();return`${e??t}`}var aD=typeof window<`u`?w.useLayoutEffect:w.useEffect;function oD(e){let t=(0,w.useRef)(e);return aD(()=>{t.current=e},[e]),(0,w.useCallback)((...e)=>t.current?.(...e),[t])}function sD(...e){return oD(t=>{e.forEach(e=>{if(e)switch(typeof e){case`function`:e(t);break;case`object`:e.current=t;break}})})}function cD(e){let t=(0,w.useRef)({...e});return aD(()=>{for(let n in e)t.current[n]=e[n]},[e]),t.current}var lD=(0,w.createContext)(null);function uD(e,t){let n=(0,w.useRef)({getLayout:()=>({}),setLayout:ME});(0,w.useImperativeHandle)(t,()=>n.current,[]),aD(()=>{Object.assign(n.current,SE({groupId:e}))})}function dD({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:a,groupRef:o,id:s,onLayoutChange:c,onLayoutChanged:l,orientation:u=`horizontal`,resizeTargetMinimumSize:d={coarse:20,fine:10},style:f,...p}){let m=(0,w.useRef)({onLayoutChange:{},onLayoutChanged:{}}),h=oD(e=>{_E(m.current.onLayoutChange,e)||(m.current.onLayoutChange=e,c?.(e))}),g=oD(e=>{_E(m.current.onLayoutChanged,e)||(m.current.onLayoutChanged=e,l?.(e))}),_=iD(s),v=(0,w.useRef)(null),[y,b]=rD(),x=(0,w.useRef)({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),S=sD(v,a);uD(_,o);let C=oD((e,t)=>{let r=DE(),i=JT(e),a=YT(e);if(a){let e=!1;switch(r.state){case`active`:e=r.hitRegions.some(e=>e.group===i);break}return{flexGrow:a.layout[t]??1,pointerEvents:e?`none`:void 0}}if(n?.[t])return{flexGrow:n?.[t]}}),T=cD({defaultLayout:n,disableCursor:r}),E=(0,w.useMemo)(()=>({get disableCursor(){return!!T.disableCursor},getPanelStyles:C,id:_,orientation:u,registerPanel:e=>{let t=x.current;return t.panels=FT(u,[...t.panels,e]),b(),()=>{t.panels=t.panels.filter(t=>t!==e),b()}},registerSeparator:e=>{let t=x.current;return t.separators=FT(u,[...t.separators,e]),b(),()=>{t.separators=t.separators.filter(t=>t!==e),b()}},updatePanelProps:(e,{disabled:t})=>{let n=x.current.panels.find(t=>t.id===e);n&&(n.panelConstraints.disabled=t);let r=JT(_),i=YT(_);r&&i&&QT(r,{...i,derivedPanelConstraints:NT(r)})},updateSeparatorProps:(e,{disabled:t,disableDoubleClick:n})=>{let r=x.current.separators.find(t=>t.id===e);r&&(r.disabled=t,r.disableDoubleClick=n)}}),[C,_,b,u,T]),D=(0,w.useRef)(null);return aD(()=>{let e=v.current;if(e===null)return;let t=x.current,n;if(T.defaultLayout!==void 0&&Object.keys(T.defaultLayout).length===t.panels.length){n={};for(let e of t.panels){let t=T.defaultLayout[e.id];t!==void 0&&(n[e.id]=t)}}let r={disabled:!!i,element:e,id:_,mutableState:{defaultLayout:n,disableCursor:!!T.disableCursor,expandedPanelSizes:x.current.lastExpandedPanelSizes,layouts:x.current.layouts},orientation:u,panels:t.panels,resizeTargetMinimumSize:t.resizeTargetMinimumSize,separators:t.separators};D.current=r;let a=nD(r),{defaultLayoutDeferred:o,derivedPanelConstraints:s,layout:c}=YT(r.id,!0);!o&&s.length>0&&(h(c),g(c));let l=ZT(_,e=>{let{defaultLayoutDeferred:t,derivedPanelConstraints:n,layout:i}=e.next;if(t||n.length===0)return;let a=r.panels.map(({id:e})=>e).join(`,`);r.mutableState.layouts[a]=i,n.forEach(t=>{if(t.collapsible){let{layout:n}=e.prev??{};if(n){let e=pE(t.collapsedSize,i[t.panelId]),a=pE(t.collapsedSize,n[t.panelId]);e&&!a&&(r.mutableState.expandedPanelSizes[t.panelId]=n[t.panelId])}}});let o=DE().state!==`active`;h(i),o&&g(i)});return()=>{D.current=null,a(),l()}},[i,_,g,h,u,y,T]),(0,w.useEffect)(()=>{let e=D.current;e&&(e.mutableState.defaultLayout=n,e.mutableState.disableCursor=!!r)}),(0,q.jsx)(lD.Provider,{value:E,children:(0,q.jsx)(`div`,{...p,className:t,"data-group":!0,"data-testid":_,id:_,ref:S,style:{height:`100%`,width:`100%`,overflow:`hidden`,...f,display:`flex`,flexDirection:u===`horizontal`?`row`:`column`,flexWrap:`nowrap`,touchAction:u===`horizontal`?`pan-y`:`pan-x`},children:e})})}dD.displayName=`Group`;function fD(){let e=(0,w.useContext)(lD);return PT(e,`Group Context not found; did you render a Panel or Separator outside of a Group?`),e}function pD(e,t){let{id:n}=fD(),r=(0,w.useRef)({collapse:NE,expand:NE,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:NE});(0,w.useImperativeHandle)(t,()=>r.current,[]),aD(()=>{Object.assign(r.current,yE({groupId:n,panelId:e}))})}function mD({children:e,className:t,collapsedSize:n=`0%`,collapsible:r=!1,defaultSize:i,disabled:a,elementRef:o,groupResizeBehavior:s=`preserve-relative-size`,id:c,maxSize:l=`100%`,minSize:u=`0%`,onResize:d,panelRef:f,style:p,...m}){let h=!!c,g=iD(c),_=cD({disabled:a}),v=(0,w.useRef)(null),y=sD(v,o),{getPanelStyles:b,id:x,orientation:S,registerPanel:C,updatePanelProps:T}=fD(),E=d!==null,D=oD((e,t,n)=>{d?.(e,c,n)});aD(()=>{let e=v.current;if(e!==null)return C({element:e,id:g,idIsStable:h,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:E?D:void 0,panelConstraints:{groupResizeBehavior:s,collapsedSize:n,collapsible:r,defaultSize:i,disabled:_.disabled,maxSize:l,minSize:u}})},[s,n,r,i,E,g,h,l,u,D,C,_]),(0,w.useEffect)(()=>{T(g,{disabled:a})},[a,g,T]),pD(g,f);let O=()=>{let e=b(x,g);if(e)return JSON.stringify(e)},k=(0,w.useSyncExternalStore)(e=>ZT(x,e),O,O),A;return A=k?JSON.parse(k):i===void 0?{flexGrow:1}:{flexGrow:void 0,flexShrink:void 0,flexBasis:i},(0,q.jsx)(`div`,{...m,"data-disabled":a||void 0,"data-panel":!0,"data-testid":g,id:g,ref:y,style:{...hD,display:`flex`,flexBasis:0,flexShrink:1,overflow:`visible`,...A},children:(0,q.jsx)(`div`,{className:t,style:{maxHeight:`100%`,maxWidth:`100%`,flexGrow:1,overflow:`auto`,...p,touchAction:S===`horizontal`?`pan-y`:`pan-x`},children:e})})}mD.displayName=`Panel`;var hD={minHeight:0,maxHeight:`100%`,height:`auto`,minWidth:0,maxWidth:`100%`,width:`auto`,border:`none`,borderWidth:0,padding:0,margin:0};function gD({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,a,o=e[n],s=t.find(e=>e.panelId===n);if(s){let c=s.maxSize,l=s.collapsible?s.collapsedSize:s.minSize,u=[r,r+1];a=vE({layout:gE({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=vE({layout:gE({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:o}}function _D({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:a,style:o,...s}){let c=iD(a),l=cD({disabled:n,disableDoubleClick:r}),[u,d]=(0,w.useState)({}),[f,p]=(0,w.useState)(`inactive`),[m,h]=(0,w.useState)(!1),g=(0,w.useRef)(null),_=sD(g,i),{disableCursor:v,id:y,orientation:b,registerSeparator:x,updateSeparatorProps:S}=fD(),C=b===`horizontal`?`vertical`:`horizontal`;aD(()=>{let e=g.current;if(e!==null){let t={disabled:l.disabled,disableDoubleClick:l.disableDoubleClick,element:e,id:c},n=x(t),r=OE(e=>{p(e.next.state!==`inactive`&&e.next.hitRegions.some(e=>e.separator===t)?e.next.state:`inactive`)}),i=ZT(y,e=>{let{derivedPanelConstraints:n,layout:r,separatorToPanels:i}=e.next,a=i.get(t);if(a){let e=a[0],t=a.indexOf(e);d(gD({layout:r,panelConstraints:n,panelId:e.id,panelIndex:t}))}});return()=>{r(),i(),n()}}},[y,c,x,l]),(0,w.useEffect)(()=>{S(c,{disabled:n,disableDoubleClick:r})},[n,r,c,S]);let T;n&&!v&&(T=`not-allowed`);let E;if(n)E=`disabled`;else switch(f){case`active`:E=`active`;break;default:E=m?`focus`:f}return(0,q.jsx)(`div`,{...s,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":C,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":E,"data-testid":c,id:c,onBlur:()=>h(!1),onFocus:()=>h(!0),ref:_,role:`separator`,style:{flexBasis:`auto`,cursor:T,...o,flexGrow:0,flexShrink:0,touchAction:`none`},tabIndex:n?void 0:0})}_D.displayName=`Separator`;function vD(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var yD=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,bD=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,xD={};function SD(e,t){return((t||xD).jsx?bD:yD).test(e)}var CD=/[ \t\n\f\r]/g;function wD(e){return typeof e==`object`?e.type===`text`?TD(e.value):!1:TD(e)}function TD(e){return e.replace(CD,``)===``}var ED=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};ED.prototype.normal={},ED.prototype.property={},ED.prototype.space=void 0;function DD(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new ED(n,r,t)}function OD(e){return e.toLowerCase()}var kD=class{constructor(e,t){this.attribute=t,this.property=e}};kD.prototype.attribute=``,kD.prototype.booleanish=!1,kD.prototype.boolean=!1,kD.prototype.commaOrSpaceSeparated=!1,kD.prototype.commaSeparated=!1,kD.prototype.defined=!1,kD.prototype.mustUseProperty=!1,kD.prototype.number=!1,kD.prototype.overloadedBoolean=!1,kD.prototype.property=``,kD.prototype.spaceSeparated=!1,kD.prototype.space=void 0;var AD=e({boolean:()=>MD,booleanish:()=>ND,commaOrSpaceSeparated:()=>LD,commaSeparated:()=>ID,number:()=>$,overloadedBoolean:()=>PD,spaceSeparated:()=>FD}),jD=0,MD=RD(),ND=RD(),PD=RD(),$=RD(),FD=RD(),ID=RD(),LD=RD();function RD(){return 2**++jD}var zD=Object.keys(AD),BD=class extends kD{constructor(e,t,n,r){let i=-1;if(super(e,t),VD(this,`space`,r),typeof n==`number`)for(;++i<zD.length;){let e=zD[i];VD(this,zD[i],(n&AD[e])===AD[e])}}};BD.prototype.defined=!0;function VD(e,t,n){n&&(e[t]=n)}function HD(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new BD(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[OD(r)]=r,n[OD(a.attribute)]=r}return new ED(t,n,e.space)}var UD=HD({properties:{ariaActiveDescendant:null,ariaAtomic:ND,ariaAutoComplete:null,ariaBusy:ND,ariaChecked:ND,ariaColCount:$,ariaColIndex:$,ariaColSpan:$,ariaControls:FD,ariaCurrent:null,ariaDescribedBy:FD,ariaDetails:null,ariaDisabled:ND,ariaDropEffect:FD,ariaErrorMessage:null,ariaExpanded:ND,ariaFlowTo:FD,ariaGrabbed:ND,ariaHasPopup:null,ariaHidden:ND,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:FD,ariaLevel:$,ariaLive:null,ariaModal:ND,ariaMultiLine:ND,ariaMultiSelectable:ND,ariaOrientation:null,ariaOwns:FD,ariaPlaceholder:null,ariaPosInSet:$,ariaPressed:ND,ariaReadOnly:ND,ariaRelevant:null,ariaRequired:ND,ariaRoleDescription:FD,ariaRowCount:$,ariaRowIndex:$,ariaRowSpan:$,ariaSelected:ND,ariaSetSize:$,ariaSort:null,ariaValueMax:$,ariaValueMin:$,ariaValueNow:$,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function WD(e,t){return t in e?e[t]:t}function GD(e,t){return WD(e,t.toLowerCase())}var KD=HD({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:ID,acceptCharset:FD,accessKey:FD,action:null,allow:null,allowFullScreen:MD,allowPaymentRequest:MD,allowUserMedia:MD,alt:null,as:null,async:MD,autoCapitalize:null,autoComplete:FD,autoFocus:MD,autoPlay:MD,blocking:FD,capture:null,charSet:null,checked:MD,cite:null,className:FD,cols:$,colSpan:null,content:null,contentEditable:ND,controls:MD,controlsList:FD,coords:$|ID,crossOrigin:null,data:null,dateTime:null,decoding:null,default:MD,defer:MD,dir:null,dirName:null,disabled:MD,download:PD,draggable:ND,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:MD,formTarget:null,headers:FD,height:$,hidden:PD,high:$,href:null,hrefLang:null,htmlFor:FD,httpEquiv:FD,id:null,imageSizes:null,imageSrcSet:null,inert:MD,inputMode:null,integrity:null,is:null,isMap:MD,itemId:null,itemProp:FD,itemRef:FD,itemScope:MD,itemType:FD,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:MD,low:$,manifest:null,max:null,maxLength:$,media:null,method:null,min:null,minLength:$,multiple:MD,muted:MD,name:null,nonce:null,noModule:MD,noValidate:MD,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:MD,optimum:$,pattern:null,ping:FD,placeholder:null,playsInline:MD,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:MD,referrerPolicy:null,rel:FD,required:MD,reversed:MD,rows:$,rowSpan:$,sandbox:FD,scope:null,scoped:MD,seamless:MD,selected:MD,shadowRootClonable:MD,shadowRootDelegatesFocus:MD,shadowRootMode:null,shape:null,size:$,sizes:null,slot:null,span:$,spellCheck:ND,src:null,srcDoc:null,srcLang:null,srcSet:null,start:$,step:null,style:null,tabIndex:$,target:null,title:null,translate:null,type:null,typeMustMatch:MD,useMap:null,value:ND,width:$,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:FD,axis:null,background:null,bgColor:null,border:$,borderColor:null,bottomMargin:$,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:MD,declare:MD,event:null,face:null,frame:null,frameBorder:null,hSpace:$,leftMargin:$,link:null,longDesc:null,lowSrc:null,marginHeight:$,marginWidth:$,noResize:MD,noHref:MD,noShade:MD,noWrap:MD,object:null,profile:null,prompt:null,rev:null,rightMargin:$,rules:null,scheme:null,scrolling:ND,standby:null,summary:null,text:null,topMargin:$,valueType:null,version:null,vAlign:null,vLink:null,vSpace:$,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:MD,disableRemotePlayback:MD,prefix:null,property:null,results:$,security:null,unselectable:null},space:`html`,transform:GD}),qD=HD({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`,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:LD,accentHeight:$,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:$,amplitude:$,arabicForm:null,ascent:$,attributeName:null,attributeType:null,azimuth:$,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:$,by:null,calcMode:null,capHeight:$,className:FD,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:$,diffuseConstant:$,direction:null,display:null,dur:null,divisor:$,dominantBaseline:null,download:MD,dx:null,dy:null,edgeMode:null,editable:null,elevation:$,enableBackground:null,end:null,event:null,exponent:$,externalResourcesRequired:null,fill:null,fillOpacity:$,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:ID,g2:ID,glyphName:ID,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:$,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:$,horizOriginX:$,horizOriginY:$,id:null,ideographic:$,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:$,k:$,k1:$,k2:$,k3:$,k4:$,kernelMatrix:LD,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:$,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:$,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:$,overlineThickness:$,paintOrder:null,panose1:null,path:null,pathLength:$,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:FD,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:$,pointsAtY:$,pointsAtZ:$,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:LD,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:LD,rev:LD,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:LD,requiredFeatures:LD,requiredFonts:LD,requiredFormats:LD,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:$,specularExponent:$,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:$,strikethroughThickness:$,string:null,stroke:null,strokeDashArray:LD,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:$,strokeOpacity:$,strokeWidth:null,style:null,surfaceScale:$,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:LD,tabIndex:$,tableValues:null,target:null,targetX:$,targetY:$,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:LD,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:$,underlineThickness:$,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:$,values:null,vAlphabetic:$,vMathematical:$,vectorEffect:null,vHanging:$,vIdeographic:$,version:null,vertAdvY:$,vertOriginX:$,vertOriginY:$,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:$,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:`svg`,transform:WD}),JD=HD({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:`xlink`,transform(e,t){return`xlink:`+t.slice(5).toLowerCase()}}),YD=HD({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:GD}),XD=HD({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),ZD={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`},QD=/[A-Z]/g,$D=/-[a-z]/g,eO=/^data[-\w.:]+$/i;function tO(e,t){let n=OD(t),r=t,i=kD;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&eO.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace($D,rO);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!$D.test(e)){let n=e.replace(QD,nO);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=BD}return new i(r,t)}function nO(e){return`-`+e.toLowerCase()}function rO(e){return e.charAt(1).toUpperCase()}var iO=DD([UD,KD,JD,YD,XD],`html`),aO=DD([UD,qD,JD,YD,XD],`svg`);function oO(e){return e.join(` `).trim()}var sO=r(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=`
|
|
59
59
|
`,d=`/`,f=`*`,p=``,m=`comment`,h=`declaration`;function g(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var l=1,g=1;function v(e){var t=e.match(r);t&&(l+=t.length);var n=e.lastIndexOf(u);g=~n?e.length-n:g+e.length}function y(){var e={line:l,column:g};return function(t){return t.position=new b(e),C(),t}}function b(e){this.start=e,this.end={line:l,column:g},this.source=t.source}b.prototype.content=e;function x(n){var r=Error(t.source+`:`+l+`:`+g+`: `+n);if(r.reason=n,r.filename=t.source,r.line=l,r.column=g,r.source=e,!t.silent)throw r}function S(t){var n=t.exec(e);if(n){var r=n[0];return v(r),e=e.slice(r.length),n}}function C(){S(i)}function w(e){var t;for(e||=[];t=T();)t!==!1&&e.push(t);return e}function T(){var t=y();if(!(d!=e.charAt(0)||f!=e.charAt(1))){for(var n=2;p!=e.charAt(n)&&(f!=e.charAt(n)||d!=e.charAt(n+1));)++n;if(n+=2,p===e.charAt(n-1))return x(`End of comment missing`);var r=e.slice(2,n-2);return g+=2,v(r),e=e.slice(n),g+=2,t({type:m,comment:r})}}function E(){var e=y(),t=S(a);if(t){if(T(),!S(o))return x(`property missing ':'`);var r=S(s),i=e({type:h,property:_(t[0].replace(n,p)),value:r?_(r[0].replace(n,p)):p});return S(c),i}}function D(){var e=[];w(e);for(var t;t=E();)t!==!1&&(e.push(t),w(e));return e}return C(),D()}function _(e){return e?e.replace(l,p):p}t.exports=g})),cO=r((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,`__esModule`,{value:!0}),e.default=r;var n=t(sO());function r(e,t){let r=null;if(!e||typeof e!=`string`)return r;let i=(0,n.default)(e),a=typeof t==`function`;return i.forEach(e=>{if(e.type!==`declaration`)return;let{property:n,value:i}=e;a?t(n,i,e):i&&(r||={},r[n]=i)}),r}})),lO=r((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.camelCase=void 0;var t=/^--[a-zA-Z0-9_-]+$/,n=/-([a-z])/g,r=/^[^-]+$/,i=/^-(webkit|moz|ms|o|khtml)-/,a=/^-(ms)-/,o=function(e){return!e||r.test(e)||t.test(e)},s=function(e,t){return t.toUpperCase()},c=function(e,t){return`${t}-`};e.camelCase=function(e,t){return t===void 0&&(t={}),o(e)?e:(e=e.toLowerCase(),e=t.reactCompat?e.replace(a,c):e.replace(i,c),e.replace(n,s))}})),uO=r(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(cO()),r=lO();function i(e,t){var i={};return!e||typeof e!=`string`||(0,n.default)(e,function(e,n){e&&n&&(i[(0,r.camelCase)(e,t)]=n)}),i}i.default=i,t.exports=i})),dO=pO(`end`),fO=pO(`start`);function pO(e){return t;function t(t){let n=t&&t.position&&t.position[e]||{};if(typeof n.line==`number`&&n.line>0&&typeof n.column==`number`&&n.column>0)return{line:n.line,column:n.column,offset:typeof n.offset==`number`&&n.offset>-1?n.offset:void 0}}}function mO(e){let t=fO(e),n=dO(e);if(t&&n)return{start:t,end:n}}var hO=n(uO(),1),gO={}.hasOwnProperty,_O=new Map,vO=/[A-Z]/g,yO=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),bO=new Set([`td`,`th`]),xO=`https://github.com/syntax-tree/hast-util-to-jsx-runtime`;function SO(e,t){if(!t||t.Fragment===void 0)throw TypeError("Expected `Fragment` in options");let n=t.filePath||void 0,r;if(t.development){if(typeof t.jsxDEV!=`function`)throw TypeError("Expected `jsxDEV` in options when `development: true`");r=NO(n,t.jsxDEV)}else{if(typeof t.jsx!=`function`)throw TypeError("Expected `jsx` in production options");if(typeof t.jsxs!=`function`)throw TypeError("Expected `jsxs` in production options");r=MO(n,t.jsx,t.jsxs)}let i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||`react`,evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space===`svg`?aO:iO,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=CO(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function CO(e,t,n){if(t.type===`element`)return wO(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return TO(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return DO(e,t,n);if(t.type===`mdxjsEsm`)return EO(e,t);if(t.type===`root`)return OO(e,t,n);if(t.type===`text`)return kO(e,t)}function wO(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=aO,e.schema=i),e.ancestors.push(t);let a=zO(e,t.tagName,!1),o=PO(e,t),s=IO(e,t);return yO.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!wD(e):!0})),AO(e,o,a,t),jO(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function TO(e,t){if(t.data&&t.data.estree&&e.evaluater){let n=t.data.estree.body[0];return n.type,e.evaluater.evaluateExpression(n.expression)}BO(e,t.position)}function EO(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);BO(e,t.position)}function DO(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=aO,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:zO(e,t.name,!0),o=FO(e,t),s=IO(e,t);return AO(e,o,a,t),jO(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function OO(e,t,n){let r={};return jO(r,IO(e,t)),e.create(t,e.Fragment,r,n)}function kO(e,t){return t.value}function AO(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function jO(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function MO(e,t,n){return r;function r(e,r,i,a){let o=Array.isArray(i.children)?n:t;return a?o(r,i,a):o(r,i)}}function NO(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=fO(n);return t(r,i,a,o,{columnNumber:s?s.column-1:void 0,fileName:e,lineNumber:s?s.line:void 0},void 0)}}function PO(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&gO.call(t.properties,i)){let a=LO(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&bO.has(t.tagName)?r=o:n[i]=o}}if(r){let t=n.style||={};t[e.stylePropertyNameCase===`css`?`text-align`:`textAlign`]=r}return n}function FO(e,t){let n={};for(let r of t.attributes)if(r.type===`mdxJsxExpressionAttribute`)if(r.data&&r.data.estree&&e.evaluater){let t=r.data.estree.body[0];t.type;let i=t.expression;i.type;let a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else BO(e,t.position);else{let i=r.name,a;if(r.value&&typeof r.value==`object`)if(r.value.data&&r.value.data.estree&&e.evaluater){let t=r.value.data.estree.body[0];t.type,a=e.evaluater.evaluateExpression(t.expression)}else BO(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function IO(e,t){let n=[],r=-1,i=e.passKeys?new Map:_O;for(;++r<t.children.length;){let a=t.children[r],o;if(e.passKeys){let e=a.type===`element`?a.tagName:a.type===`mdxJsxFlowElement`||a.type===`mdxJsxTextElement`?a.name:void 0;if(e){let t=i.get(e)||0;o=e+`-`+t,i.set(e,t+1)}}let s=CO(e,a,o);s!==void 0&&n.push(s)}return n}function LO(e,t,n){let r=tO(e.schema,t);if(!(n==null||typeof n==`number`&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?vD(n):oO(n)),r.property===`style`){let t=typeof n==`object`?n:RO(e,String(n));return e.stylePropertyNameCase===`css`&&(t=VO(t)),[`style`,t]}return[e.elementAttributeNameCase===`react`&&r.space?ZD[r.property]||r.property:r.attribute,n]}}function RO(e,t){try{return(0,hO.default)(t,{reactCompat:!0})}catch(t){if(e.ignoreInvalidStyle)return{};let n=t,r=new o("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:n,ruleId:`style`,source:`hast-util-to-jsx-runtime`});throw r.file=e.filePath||void 0,r.url=xO+`#cannot-parse-style-attribute`,r}}function zO(e,t,n){let r;if(!n)r={type:`Literal`,value:t};else if(t.includes(`.`)){let e=t.split(`.`),n=-1,i;for(;++n<e.length;){let t=SD(e[n])?{type:`Identifier`,name:e[n]}:{type:`Literal`,value:e[n]};i=i?{type:`MemberExpression`,object:i,property:t,computed:!!(n&&t.type===`Literal`),optional:!1}:t}r=i}else r=SD(t)&&!/^[a-z]/.test(t)?{type:`Identifier`,name:t}:{type:`Literal`,value:t};if(r.type===`Literal`){let t=r.value;return gO.call(e.components,t)?e.components[t]:t}if(e.evaluater)return e.evaluater.evaluateExpression(r);BO(e)}function BO(e,t){let n=new o("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:`mdx-estree`,source:`hast-util-to-jsx-runtime`});throw n.file=e.filePath||void 0,n.url=xO+`#cannot-handle-mdx-estrees-without-createevaluater`,n}function VO(e){let t={},n;for(n in e)gO.call(e,n)&&(t[HO(n)]=e[n]);return t}function HO(e){let t=e.replace(vO,UO);return t.slice(0,3)===`ms-`&&(t=`-`+t),t}function UO(e){return`-`+e.toLowerCase()}var WO={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`]};function GO(e){let t=[],n=-1,r=0,i=0;for(;++n<e.length;){let a=e.charCodeAt(n),o=``;if(a===37&&s(e.charCodeAt(n+1))&&s(e.charCodeAt(n+2)))i=2;else if(a<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(a))||(o=String.fromCharCode(a));else if(a>55295&&a<57344){let t=e.charCodeAt(n+1);a<56320&&t>56319&&t<57344?(o=String.fromCharCode(a,t),i=1):o=`�`}else o=String.fromCharCode(a);o&&=(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,``),i&&=(n+=i,0)}return t.join(``)+e.slice(r)}function KO(e,t){let n={type:`element`,tagName:`blockquote`,properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function qO(e,t){let n={type:`element`,tagName:`br`,properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:`text`,value:`
|
|
@@ -87,7 +87,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(
|
|
|
87
87
|
`),r=(0,w.useMemo)(()=>{try{if(t)return hP.highlight(e,{language:t,ignoreIllegals:!0}).value;{let t=hP.highlightAuto(e);if(t.language)return t.value}}catch{}return null},[e,t]);return(0,q.jsx)(`div`,{className:`overflow-hidden rounded-md font-mono text-xs leading-5`,style:{border:`1px solid var(--cm-code-border)`,backgroundColor:`var(--cm-code-bg)`},children:(0,q.jsx)(`div`,{className:`max-h-80 overflow-auto`,children:r?(0,q.jsxs)(`div`,{className:`flex`,children:[(0,q.jsx)(`div`,{className:`shrink-0 text-right text-[9px] select-none`,style:{color:`var(--cm-gutter)`,borderRight:`1px solid var(--cm-border)`,minWidth:`3rem`},children:n.map((e,t)=>(0,q.jsx)(`div`,{className:`pr-3 py-px`,children:t+1},t))}),(0,q.jsx)(`pre`,{className:`flex-1 pl-2 py-px whitespace-pre-wrap break-all`,dangerouslySetInnerHTML:{__html:r}})]}):n.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex`,children:[(0,q.jsx)(`span`,{className:`w-12 shrink-0 text-right pr-3 py-px text-[9px] select-none border-r`,style:{color:`var(--cm-gutter)`,borderColor:`var(--cm-border)`},children:t+1}),(0,q.jsx)(`span`,{className:`pl-2 py-px whitespace-pre-wrap break-all`,style:{color:`var(--cm-text)`},children:e})]},t))})})}function eF({command:e,output:t}){return(0,q.jsxs)(`div`,{className:`overflow-hidden rounded-md bg-[#0d1117] border border-gray-700 text-xs`,children:[e&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-gray-700/50 px-3 py-1.5 text-green-400 font-mono`,children:[(0,q.jsx)(`span`,{className:`select-none text-gray-500 text-[10px]`,children:`$`}),(0,q.jsx)(`span`,{className:`whitespace-pre-wrap break-all font-medium`,children:e})]}),t!==void 0&&(0,q.jsx)(`pre`,{className:`max-h-64 overflow-auto px-3 py-2 text-gray-300 whitespace-pre-wrap font-mono leading-relaxed`,children:t||(0,q.jsx)(`span`,{className:`text-gray-500 italic`,children:`(no output)`})})]})}function tF({toolName:e,args:t,result:n,status:r=`complete`,elapsedSeconds:i,taskState:a,toolCallId:o}){let s=HP(e),c=s.icon,l=WP(e,t),[u,d]=(0,w.useState)(!1),f=r===`complete`,p=r===`running`,m=r===`requires-action`,h=VP[r],g=_P(),{permissionPrompt:_,answerPermission:v,openFile:y}=jP(),b=m||_?.toolUseId===o,x=u||b,S=BP(p,i),C=f&&n?GP(n):null,T=C!==null,E=e===`Bash`,D=e===`TodoWrite`,O=e===`Agent`||e===`Task`,k=e===`Write`,A=e===`Edit`||e===`ApplyPatch`,j=Object.keys(t).length>0,M=t.content??``,N=t.old_string??``,P=t.new_string??``,F=A&&N&&P,I=UP(t.file_path||t.filePath||``),L=!!(y&&I&&f),R=(0,w.useMemo)(()=>{let e=I.includes(`.`)?I.split(`.`).pop()?.toLowerCase()??``:``;return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,rs:`rust`,go:`go`,rb:`ruby`,swift:`swift`,java:`java`,c:`c`,cpp:`cpp`,cs:`csharp`,kt:`kotlin`,json:`json`,yaml:`yaml`,yml:`yaml`,toml:`ini`,xml:`xml`,html:`xml`,htm:`xml`,svg:`xml`,css:`css`,scss:`scss`,less:`less`,sql:`sql`,sh:`bash`,bash:`bash`,zsh:`bash`,fish:`bash`,md:`markdown`,dockerfile:`dockerfile`,proto:`protobuf`,php:`php`,lua:`lua`,r:`r`,scala:`scala`}[e]||(e&&e.length<=5?e:``)},[I]),z=D?Array.isArray(t.todos)?t.todos:[]:null,B=x?null:k&&M?XP(M,200):A&&(T||F)?{type:`edit`,oldStr:N,newStr:P,diff:C}:null;return(0,q.jsxs)(FA,{open:x,onOpenChange:d,className:X(`group/tool my-1.5 overflow-hidden rounded-lg border border-gray-100 bg-gray-50/60 border-l-[3px]`,s.borderClass,p&&`animate-pulse`),children:[(0,q.jsxs)(IA,{className:`flex w-full flex-col text-left text-sm transition-colors hover:bg-gray-50`,children:[(0,q.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 md:gap-2 px-2 md:px-3 py-1.5`,children:[(0,q.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,q.jsx)(`span`,{className:`font-medium text-gray-700 text-xs`,children:e}),l&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px] text-gray-500`,children:l})]}),b?(0,q.jsx)(`span`,{className:`ml-auto shrink-0 rounded px-1.5 py-px text-[10px] font-medium bg-amber-100 text-amber-700`,children:`Action needed`}):p?(0,q.jsx)(`span`,{className:`ml-auto shrink-0 rounded px-1.5 py-px text-[10px] font-medium tabular-nums bg-sky-100 text-sky-700`,children:zP(S)}):(0,q.jsx)(`span`,{className:X(`ml-auto shrink-0 rounded px-1.5 py-px text-[10px] font-medium`,h.className),children:h.label}),(0,q.jsx)(H,{className:X(`h-3.5 w-3.5 shrink-0 text-gray-300 transition-transform`,u&&`rotate-180`)})]}),B&&(0,q.jsx)(`div`,{className:`border-t border-gray-100 px-2 md:px-3 py-1.5`,children:typeof B==`string`?(0,q.jsx)(`pre`,{className:`font-mono text-[10px] leading-relaxed text-gray-500 whitespace-pre-wrap break-all line-clamp-3`,children:B}):B.type===`edit`?B.diff&&n?(0,q.jsx)(JP,{text:n,lang:R,maxLines:8}):(0,q.jsx)(`div`,{className:`opacity-70`,children:(0,q.jsx)(QP,{oldStr:B.oldStr,newStr:B.newStr,maxLen:20,lang:R})}):null})]}),(0,q.jsx)(LA,{className:X(`overflow-hidden`,`data-[state=open]:animate-collapsible-down`,`data-[state=closed]:animate-collapsible-up`),children:(0,q.jsxs)(`div`,{className:X(`border-t border-gray-100 px-2 md:px-3 py-2`,g&&`max-h-[60vh] overflow-y-auto`),children:[b&&_&&(0,q.jsx)(RP,{toolName:_.toolName,title:_.title,displayName:_.displayName,onAllow:()=>v(_.toolUseId,!0),onDeny:()=>v(_.toolUseId,!1)}),L&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>y(I),className:`inline-flex items-center gap-1 mb-2 px-2 py-1 rounded text-[11px] border border-gray-200 bg-white hover:bg-gray-50 text-gray-600 hover:text-gray-900 transition-colors`,children:[(0,q.jsx)(le,{className:`h-3 w-3`}),`Open in Editor`]}),k&&f&&M&&(0,q.jsx)(YP,{content:M,lang:R}),A&&f&&T&&n&&(0,q.jsx)(JP,{text:n,lang:R}),A&&f&&!T&&F&&(0,q.jsx)(QP,{oldStr:N,newStr:P,lang:R}),E&&(l||n!==void 0)&&(0,q.jsx)(eF,{command:l,output:n}),D&&z&&z.length>0&&(0,q.jsx)(yP,{todos:z}),O&&(0,q.jsx)(IP,{args:t,result:n,status:r,taskState:a,elapsedSeconds:S,toolCallId:o}),!k&&!E&&!D&&!O&&!(A&&(T||F))&&n!==void 0&&(0,q.jsx)($P,{text:typeof n==`string`?n:JSON.stringify(n,null,2),lang:R}),p&&!b&&!n&&!j&&!O&&!(D&&z&&z.length>0)&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs text-gray-400`,children:[(0,q.jsx)(Ae,{className:`h-3 w-3 animate-spin`}),`Working...`]}),r===`incomplete`&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-red-500`,children:[(0,q.jsx)(te,{className:`h-3.5 w-3.5`}),`Tool call failed`]})]})})]})}var nF=class extends w.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary:`+this.props.name+`]`,e.message,e.stack,t)}render(){return this.state.error?(0,q.jsxs)(`div`,{className:`rounded border border-red-200 bg-red-50 p-3 text-xs text-red-700`,children:[(0,q.jsxs)(`b`,{children:[`Error in `,this.props.name,`:`]}),` `,this.state.error.message]}):this.props.children}};function rF(e){if(!e)return``;let t=e.match(/(\d{13})/);return t?new Date(parseInt(t[1],10)).toLocaleTimeString():``}function iF({content:e}){let t=e.trim();if(!(t.startsWith(`{`)||t.startsWith(`[`))||!(t.endsWith(`}`)||t.endsWith(`]`)))return null;try{let e=JSON.parse(t),n=JSON.stringify(e,null,2);return(0,q.jsxs)(`div`,{className:`my-2`,children:[(0,q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm text-gray-500`,children:[(0,q.jsx)(`svg`,{className:`h-4 w-4`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,q.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z`})}),(0,q.jsx)(`span`,{className:`font-medium`,children:`JSON`})]}),(0,q.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-gray-600/30 bg-gray-900`,children:(0,q.jsx)(`pre`,{className:`overflow-x-auto p-4`,children:(0,q.jsx)(`code`,{className:`block whitespace-pre font-mono text-sm text-gray-200`,children:n})})})]})}catch{return null}}function aF(e){let t=!1,n=!1;for(let r of e)r?.type===`tool-call`&&(n=!0,r?.status?.type===`running`&&(t=!0));return t?`blink-green`:n?`green`:`gray`}function oF(){let e=Q(e=>e.message.id),{toolProgressMap:t,taskMap:n,thinkingOpen:r,setThinkingOpen:i}=jP(),a=Q(e=>e.message.content),o=Q(e=>{let t=e.message.content;return Array.isArray(t)?t.filter(e=>e.type===`text`).map(e=>e.text??``).join(``):``}),s=rF(e);if(!(Array.isArray(a)&&a.some(e=>e?.type===`text`&&(e.text??``).length>0||e?.type===`tool-call`||e?.type===`reasoning`||e?.type===`image`||e?.type===`file`)))return null;let c=Array.isArray(a)?aF(a):`gray`,l=(Array.isArray(a)?a.find(e=>e?.type===`text`||e?.type===`tool-call`):null)?.type===`text`?`top-[6px]`:`top-[17px]`,u=(0,q.jsx)(sC,{groupBy:e=>e.type===`reasoning`?[`group-chainOfThought`,`group-reasoning`]:null,children:({part:e,children:s})=>{switch(e.type){case`group-chainOfThought`:return(0,q.jsx)(`div`,{"data-slot":`chain-of-thought`,children:s});case`group-reasoning`:{let t=e.status.type===`running`,n=e.indices?.reduce((e,t)=>e+(a[t]?.text?.length??0),0)??0,o=n>0?`Thinking · ${n.toLocaleString()} chars`:`Thinking`;return(0,q.jsxs)(FA,{open:t?!0:r,onOpenChange:i,className:`group/think my-1 overflow-hidden rounded-md border border-gray-100 bg-gray-50/50`,children:[(0,q.jsxs)(IA,{className:`flex w-full items-center gap-1.5 px-2 py-1 text-left text-xs transition-colors hover:bg-gray-100/50`,children:[(0,q.jsx)(z,{className:`h-3 w-3 shrink-0 text-gray-400`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:o}),t&&(0,q.jsx)(`span`,{className:`shrink-0 rounded px-1 py-px text-[10px] font-medium text-gray-400`,children:`thinking`}),(0,q.jsx)(H,{className:X(`ml-auto h-3 w-3 shrink-0 text-gray-300 transition-transform`,(t||r)&&`rotate-180`)})]}),(0,q.jsx)(LA,{className:X(`overflow-hidden`,`data-[state=open]:animate-collapsible-down`,`data-[state=closed]:animate-collapsible-up`),children:(0,q.jsx)(`div`,{className:`border-t border-gray-100 px-3 py-2`,children:(0,q.jsx)(`div`,{className:`max-h-64 overflow-y-auto text-[12px] text-gray-500 leading-relaxed`,children:s})})})]})}case`text`:{let e=iF({content:o});return e?(0,q.jsx)(`div`,{children:e}):(0,q.jsx)(EA,{})}case`reasoning`:return(0,q.jsx)(EA,{});case`tool-call`:{let r=e.args??{},i=e.result,a=e.status?.type??`complete`,o=e.toolCallId,s=e.toolName??`Unknown`,c=o?t.get(o):void 0,l=o?Array.from(n.values()).find(e=>e.tool_use_id===o):void 0;return(0,q.jsx)(nF,{name:`ToolRenderer:`+s,children:(0,q.jsx)(tF,{toolName:s,args:r,result:i,status:a,elapsedSeconds:c?.elapsed_time_seconds,taskState:l,toolCallId:o})})}default:return null}}});return(0,q.jsxs)(eT,{"data-role":`assistant`,className:`relative pl-6 md:pl-8`,children:[(0,q.jsx)(`div`,{className:`absolute left-[5px] -top-2 -bottom-2 w-[2px] bg-gray-200`}),(0,q.jsx)(`div`,{className:X(`absolute left-[3px] z-10 h-[6px] w-[6px] rounded-full`,l,c===`gray`&&`bg-gray-300`,c===`green`&&`bg-green-500`,c===`blink-green`&&`animate-[blink-green_2s_ease-in-out_infinite]`)}),(0,q.jsx)(`div`,{className:`w-full text-[13px] md:text-sm text-gray-700`,children:u}),s&&(0,q.jsx)(`div`,{className:`mt-1 flex items-center gap-2 text-[11px] text-gray-400`,children:(0,q.jsx)(`span`,{children:s})})]})}var sF=[`Thinking`,`Processing`,`Analyzing`,`Working`,`Computing`,`Reasoning`];function cF(e){let t=Math.floor(e/60),n=e%60;return t<1?`${n}s`:`${t}m ${n}s`}function lF(e){return e<0&&(e=0),e<1e3?String(Math.round(e)):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function uF({isLoading:e,getTokenCount:t,getWaitingForResponse:n}){let{thinkingBudget:r,turnGeneration:i,turnStartedAt:a}=jP(),[o,s]=(0,w.useState)(0),[c,l]=(0,w.useState)(0),[u,d]=(0,w.useState)(``);if((0,w.useEffect)(()=>{if(!e){s(0),l(0),d(``);return}let t=a??Date.now(),n=setInterval(()=>{s(Math.floor((Date.now()-t)/1e3))},250),r=setInterval(()=>{d(e=>e.length>=3?``:e+`.`)},400);return()=>{clearInterval(n),clearInterval(r)}},[e,i,a]),(0,w.useEffect)(()=>{if(!e)return;let n,r=()=>{let e=t();l(t=>{if(Math.abs(e-t)<.5)return e;let n=e-t,r=Math.max(1,Math.ceil(Math.abs(n)/8));return t+Math.sign(n)*Math.min(r,Math.abs(n))}),n=requestAnimationFrame(r)};return n=requestAnimationFrame(r),()=>cancelAnimationFrame(n)},[e,t]),!e)return null;let f=sF[Math.floor(o/3)%sF.length],p=n()?`↑`:`↓`,m=r===null?null:r>=32e3?`think-hard`:r>=16e3?`think`:null;return(0,q.jsxs)(`div`,{className:`relative mb-1.5 pl-6 md:pl-8`,children:[(0,q.jsx)(`div`,{className:`absolute left-[3px] top-1/2 -translate-y-1/2 z-10 h-[6px] w-[6px] animate-[morph_2s_ease-in-out_infinite] bg-blue-500 shadow-[0_0_6px_rgba(59,130,246,0.4)]`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 md:gap-3 text-xs text-gray-500 py-1`,children:[(0,q.jsxs)(`span`,{className:`font-medium text-gray-600`,children:[f,(0,q.jsx)(`span`,{className:`inline-block w-4 tabular-nums`,children:u})]}),m&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,q.jsx)(`span`,{className:`rounded bg-blue-50 px-1.5 py-0.5 text-[10px] font-medium text-blue-600`,children:m})]}),(0,q.jsx)(`span`,{className:`tabular-nums text-gray-500 ml-auto mr-1`,children:cF(o)}),(0,q.jsxs)(`span`,{className:`tabular-nums text-gray-600 font-medium`,children:[p,lF(c),` tk`]})]})]})}function dF({...e}){return(0,q.jsx)(Td,{"data-slot":`popover`,...e})}function fF({...e}){return(0,q.jsx)(Ed,{"data-slot":`popover-trigger`,...e})}function pF({className:e,align:t=`center`,sideOffset:n=8,children:r,...i}){return(0,q.jsx)(Dd,{children:(0,q.jsx)(Od,{"data-slot":`popover-content`,align:t,sideOffset:n,className:X(`z-50 w-72 rounded-xl border border-gray-200 bg-white p-0 shadow-xl outline-none`,`data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,`data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95`,`data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2`,`data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...i,children:r})})}function mF({...e}){return(0,q.jsx)(kd,{"data-slot":`popover-close`,...e})}var hF=[{id:`bypassPermissions`,label:`YOLO`,description:`Sandboxed — safe to proceed freely`,icon:gt,color:`text-green-600`,activeBg:`bg-green-50`,activeBorder:`border-green-200`,activeHover:`hover:bg-green-100`},{id:`auto`,label:`Auto`,description:`Fully automatic, minimal prompts`,icon:tt,color:`text-amber-600`,activeBg:`bg-amber-50`,activeBorder:`border-amber-200`,activeHover:`hover:bg-amber-100`},{id:`dontAsk`,label:`Don't Ask`,description:`Skip most confirmations`,icon:de,color:`text-blue-600`,activeBg:`bg-blue-50`,activeBorder:`border-blue-200`,activeHover:`hover:bg-blue-100`},{id:`acceptEdits`,label:`Accept Edits`,description:`Auto-approve file edits, ask for rest`,icon:He,color:`text-yellow-600`,activeBg:`bg-yellow-50`,activeBorder:`border-yellow-200`,activeHover:`hover:bg-yellow-100`},{id:`plan`,label:`Plan`,description:`Plan first, then implement step by step`,icon:re,color:`text-purple-600`,activeBg:`bg-purple-50`,activeBorder:`border-purple-200`,activeHover:`hover:bg-purple-100`},{id:`default`,label:`Default`,description:`Ask before each edit (safest)`,icon:$e,color:`text-gray-600`,activeBg:`bg-gray-50`,activeBorder:`border-gray-200`,activeHover:`hover:bg-gray-100`}];function gF({mode:e,onChange:t,className:n=``}){let[r,i]=(0,w.useState)(!1),a=hF.find(t=>t.id===e)??hF[0],o=a.icon;return(0,q.jsxs)(dF,{open:r,onOpenChange:i,children:[(0,q.jsx)(fF,{asChild:!0,children:(0,q.jsxs)(`button`,{type:`button`,className:X(`flex h-8 items-center gap-1 rounded-lg border px-1.5 text-[10px] transition-all`,e===`bypassPermissions`?`border-gray-200 bg-gray-50 text-gray-500 hover:bg-gray-100`:`${a.activeBorder} ${a.activeBg} ${a.color} ${a.activeHover}`,n),title:`Mode: ${a.label}`,"aria-label":`Select permission mode`,children:[(0,q.jsx)(o,{className:X(`h-3 w-3`,a.color)}),(0,q.jsx)(`span`,{className:`hidden font-medium sm:inline`,children:a.label})]})}),(0,q.jsxs)(pF,{className:`w-56`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200 p-3`,children:[(0,q.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900`,children:`Permission Mode`}),(0,q.jsx)(mF,{asChild:!0,children:(0,q.jsx)(`button`,{type:`button`,className:`rounded p-1 hover:bg-gray-100`,"aria-label":`Close`,children:(0,q.jsx)(ht,{className:`h-4 w-4 text-gray-500`})})})]}),(0,q.jsx)(`div`,{className:`py-1`,children:hF.map(n=>{let r=n.icon,a=n.id===e;return(0,q.jsx)(`button`,{type:`button`,onClick:()=>{t(n.id),i(!1)},className:X(`w-full px-4 py-2.5 text-left transition-colors hover:bg-gray-50`,a&&`bg-gray-50`),children:(0,q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,q.jsx)(r,{className:X(`h-4 w-4`,n.color)}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:X(`text-sm font-medium`,a?`text-gray-900`:`text-gray-700`),children:n.label}),a&&(0,q.jsx)(`span`,{className:`rounded bg-blue-100 px-1.5 py-0.5 text-[9px] text-blue-700`,children:`Active`})]}),(0,q.jsx)(`p`,{className:`text-xs text-gray-500`,children:n.description})]})]})},n.id)})})]})]})}function _F(){let{provider:e,selectProvider:t,thinkingBlockCount:n,loopId:r}=jP(),[i,a]=(0,w.useState)(null),[o,s]=(0,w.useState)(!1),[c,l]=(0,w.useState)(``),[u,d]=(0,w.useState)(0),f=(0,w.useRef)(null),p=(0,w.useRef)(null);(0,w.useEffect)(()=>{_h().then(a)},[]);let m=e?.name||`default`,h=e?.model||``,g=(0,w.useMemo)(()=>{if(!i)return[];let e=[];for(let[t,n]of Object.entries(i.providers))if(!(n.enabled===!1||!n.hasKey))for(let r of n.models??[]){if(r.enabled===!1)continue;let i=c.toLowerCase().trim();i&&!r.id.toLowerCase().includes(i)&&!t.toLowerCase().includes(i)||e.push({provName:t,modelId:r.id,source:n.source})}return e},[i,c]);(0,w.useEffect)(()=>{d(0)},[c,o]),(0,w.useEffect)(()=>{p.current&&p.current.children[u]?.scrollIntoView({block:`nearest`})},[u]),(0,w.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`k`&&(e.preventDefault(),s(e=>!e)),e.key===`Escape`&&o&&s(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o]);let _=(0,w.useMemo)(()=>{let e=new Map;return g.forEach((t,n)=>{let r=e.get(t.provName)??{source:t.source,models:[]};r.models.push({modelId:t.modelId,idx:n}),e.set(t.provName,r)}),e},[g]),v=e=>e.toLowerCase().startsWith(`claude`),y=(0,w.useCallback)(async e=>{if(s(!1),!(e.provName===m&&e.modelId===h)){if(v(h)!==v(e.modelId)&&n>0&&r){let e=`Switching between Claude and non-Claude models makes the ${n} existing thinking block${n===1?``:`s`} in this conversation fail signature validation.\n\nClick OK to remove them from the AI's context (chat history stays). Cancel to keep the current provider.`;if(!window.confirm(e))return;await Cm(r)}t(e.provName,e.source,e.modelId)}},[m,h,n,r,t]);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`flex items-center gap-1 rounded-md border border-gray-200 bg-gray-50 px-1.5 py-0.5 text-[10px] text-gray-500 hover:bg-gray-100 transition-colors`,title:`Select model (Ctrl+K)`,"aria-label":`Select model`,children:[(0,q.jsx)(oe,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{className:`font-medium text-gray-700 truncate max-w-16 md:max-w-24`,children:m}),h&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`hidden md:inline text-gray-400`,children:`/`}),(0,q.jsx)(`span`,{className:`hidden md:inline font-mono truncate max-w-20`,children:h})]}),(0,q.jsx)(H,{className:`h-2.5 w-2.5 text-gray-400`})]}),o&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/20`,onClick:()=>s(!1)}),(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[15vh]`,onClick:()=>s(!1),children:(0,q.jsxs)(`div`,{className:`w-[480px] max-h-[60vh] bg-white rounded-xl shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),d(e=>Math.min(e+1,g.length-1))):e.key===`ArrowUp`?(e.preventDefault(),d(e=>Math.max(e-1,0))):e.key===`Enter`?(e.preventDefault(),g[u]&&y(g[u])):e.key===`Escape`&&s(!1)},children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,q.jsx)(Ye,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,q.jsx)(`input`,{ref:f,autoFocus:!0,type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`Search models...`,className:`flex-1 text-sm outline-none text-gray-900 placeholder:text-gray-400`}),(0,q.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] bg-gray-100 text-gray-400 font-mono`,children:`esc`})]}),(0,q.jsxs)(`div`,{ref:p,className:`flex-1 overflow-y-auto py-2`,role:`listbox`,children:[Array.from(_.entries()).map(([e,t])=>(0,q.jsxs)(`div`,{className:`mb-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 py-1`,children:[(0,q.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e}),(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded px-1 py-0 text-[8px] font-medium ${t.source===`personal`?`bg-violet-100 text-violet-600`:`bg-gray-100 text-gray-400`}`,children:[t.source===`personal`?(0,q.jsx)(ft,{className:`h-2 w-2`}):(0,q.jsx)(Ce,{className:`h-2 w-2`}),t.source]})]}),t.models.map(t=>{let n=t.idx===u,r=e===m&&t.modelId===h;return(0,q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n,onClick:()=>y(g[t.idx]),onMouseEnter:()=>d(t.idx),className:`w-full px-6 py-1.5 text-left flex items-center gap-2 transition-colors ${n?`bg-blue-50`:``}`,children:[(0,q.jsx)(`span`,{className:`font-mono text-[12px] flex-1 truncate ${r?`text-blue-700 font-medium`:n?`text-gray-900`:`text-gray-600`}`,children:t.modelId}),r&&(0,q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-blue-500 shrink-0`})]},t.modelId)})]},e)),g.length===0&&(0,q.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:c?`No models match your search`:`No models available`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2 border-t border-gray-100 text-[10px] text-gray-400 shrink-0`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(F,{className:`h-3 w-3`}),(0,q.jsx)(M,{className:`h-3 w-3`}),`navigate`]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(ae,{className:`h-3 w-3`}),`select`]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-gray-100 font-mono text-[9px]`,children:`esc`}),`close`]})]})]})})]})]})}function vF({onPick:e}){let{availableSlashCommands:t}=jP(),[n,r]=(0,w.useState)(!1),[i,a]=(0,w.useState)(``),[o,s]=(0,w.useState)(0),c=(0,w.useMemo)(()=>{let e=new Map;for(let n of t){let t=n.name.indexOf(`:`);if(t<0)continue;let r=n.name.slice(0,t),i=n.name.slice(t+1),a=e.get(r)??{plugin:r,skills:[]};a.skills.push({name:i,description:n.description}),e.set(r,a)}return[...e.values()].sort((e,t)=>e.plugin.localeCompare(t.plugin))},[t]),l=(0,w.useMemo)(()=>c.reduce((e,t)=>e+t.skills.length,0),[c]),u=(0,w.useMemo)(()=>{let e=i.toLowerCase().trim(),t=[];for(let n of c)for(let r of n.skills)e&&!`${n.plugin}:${r.name}`.toLowerCase().includes(e)&&!r.description.toLowerCase().includes(e)||t.push({plugin:n.plugin,skill:r.name,description:r.description});return t},[c,i]);if((0,w.useEffect)(()=>{s(0)},[i,n]),(0,w.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&r(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),l===0)return null;let d=(t,n)=>{r(!1),e(`/${t}:${n} `)};return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>r(!0),className:`flex items-center gap-1 rounded-md border border-gray-200 bg-gray-50 px-1.5 py-0.5 text-[10px] text-gray-500 hover:bg-gray-100 transition-colors`,title:`${l} plugin skill${l===1?``:`s`} available`,"aria-label":`Show plugins`,children:[(0,q.jsx)(`span`,{className:`text-sm leading-none`,"aria-hidden":`true`,children:`🧩`}),(0,q.jsx)(`span`,{className:`font-medium text-gray-700`,children:l})]}),n&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/20`,onClick:()=>r(!1)}),(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[15vh]`,onClick:()=>r(!1),children:(0,q.jsxs)(`div`,{className:`w-[560px] max-h-[60vh] bg-white rounded-xl shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),onKeyDown:e=>{if(e.key===`ArrowDown`)e.preventDefault(),s(e=>Math.min(e+1,u.length-1));else if(e.key===`ArrowUp`)e.preventDefault(),s(e=>Math.max(e-1,0));else if(e.key===`Enter`){e.preventDefault();let t=u[o];t&&d(t.plugin,t.skill)}},children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,q.jsx)(Ye,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,q.jsx)(`input`,{autoFocus:!0,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Search plugins...`,className:`flex-1 text-sm outline-none text-gray-900 placeholder:text-gray-400`}),(0,q.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[u.length,` / `,l]}),(0,q.jsx)(`kbd`,{className:`hidden sm:inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] bg-gray-100 text-gray-400 font-mono`,children:`esc`})]}),(0,q.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-2`,role:`listbox`,children:[(()=>{let e=new Map;return u.forEach((t,n)=>{let r=e.get(t.plugin)??[];r.push({skill:t.skill,description:t.description,idx:n}),e.set(t.plugin,r)}),Array.from(e.entries()).map(([e,t])=>(0,q.jsxs)(`div`,{className:`mb-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 py-1`,children:[(0,q.jsx)(`span`,{className:`text-xs leading-none`,"aria-hidden":`true`,children:`🧩`}),(0,q.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e})]}),t.map(({skill:t,description:n,idx:r})=>{let i=r===o;return(0,q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":i,onClick:()=>d(e,t),onMouseEnter:()=>s(r),className:`w-full px-6 py-1.5 text-left flex flex-col gap-0.5 transition-colors ${i?`bg-blue-50`:``}`,children:[(0,q.jsxs)(`span`,{className:`font-mono text-[12px] text-gray-900`,children:[`/`,e,`:`,t]}),n&&(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500 line-clamp-2`,children:n})]},t)})]},e))})(),u.length===0&&(0,q.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:i?`No skills match your search`:`No plugins available`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2 border-t border-gray-100 text-[10px] text-gray-400 shrink-0`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(F,{className:`h-3 w-3`}),(0,q.jsx)(M,{className:`h-3 w-3`}),`navigate`]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(ae,{className:`h-3 w-3`}),`insert`]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-gray-100 font-mono text-[9px]`,children:`esc`}),`close`]})]})]})})]})]})}function yF({onClose:e,loopId:t}){let[n,r]=(0,w.useState)([]),[i,a]=(0,w.useState)(!0),[o,s]=(0,w.useState)(null),[c,l]=(0,w.useState)(null),[u,d]=(0,w.useState)(null),f=(0,w.useCallback)(async()=>{a(!0),r((await lg(t)).servers),a(!1)},[t]);(0,w.useEffect)(()=>{f()},[f]);let p=async e=>{if(o)return;s(e),l(null);let n=await ug(e,t);if(s(null),n.error||!n.authorizationUrl){l(n.error??`start failed`);return}window.location.href=n.authorizationUrl},m=async e=>{o||(s(e),await dg(e),s(null),f())},h=async(e,n)=>{let r=await ag(e,n,t);return r.ok?(await f(),null):r.error};return(0,q.jsxs)(`div`,{className:`text-sm`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-gray-200`,children:[(0,q.jsx)(`div`,{className:`text-[13px] font-medium text-gray-700`,children:`MCP servers`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`button`,{onClick:f,className:`p-1 text-gray-400 hover:text-gray-700 rounded`,title:`reload`,children:(0,q.jsx)(Ke,{size:12,className:i?`animate-spin`:``})}),(0,q.jsx)(`button`,{onClick:e,className:`p-1 text-gray-400 hover:text-gray-700 rounded`,title:`close`,children:(0,q.jsx)(ht,{size:14})})]})]}),c&&(0,q.jsx)(`div`,{className:`mx-3 mt-3 rounded px-3 py-2 text-[12px] bg-red-50 text-red-800 border border-red-200`,children:c}),u&&(0,q.jsx)(`div`,{className:`mx-3 mt-3 rounded px-3 py-2 text-[12px] bg-blue-50 text-blue-800 border border-blue-200`,children:u}),(0,q.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto`,children:i&&n.length===0?(0,q.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400`,children:`loading…`}):n.length===0?(0,q.jsxs)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:[`No MCP servers in this loop's merged settings.json. Add servers to team/personal/profile `,(0,q.jsx)(`code`,{className:`bg-gray-100 px-1 rounded font-mono text-[11px]`,children:`settings.json`}),`'s`,(0,q.jsx)(`code`,{className:`bg-gray-100 px-1 rounded font-mono text-[11px]`,children:`mcpServers`}),`.`]}):n.map(e=>(0,q.jsx)(bF,{server:e,busy:o===e.name||e.authTokenEnv!==null&&o===e.authTokenEnv,onConnect:()=>p(e.name),onForget:e.authTokenEnv?()=>m(e.authTokenEnv):void 0,onParseSetup:t=>h(e.name,t)},e.name))}),(0,q.jsx)(`div`,{className:`border-t border-gray-200 px-3 py-2 flex items-center justify-end text-[11px]`,children:(0,q.jsxs)(`button`,{onClick:async()=>{d(null);let e=await fg(t);e.error?l(e.error):d(e.restarted?`Loop SDK session restarted. Send a message to re-spawn with new MCP tokens.`:`No active SDK session — next message will spawn fresh.`)},className:`text-gray-600 hover:text-gray-900 flex items-center gap-1`,title:`Restart the SDK session so newly-connected MCPs take effect. Conversation history is preserved.`,children:[(0,q.jsx)(qe,{size:10}),` Reload session`]})})]})}function bF({server:e,busy:t,onConnect:n,onForget:r,onParseSetup:i}){let a=e.type===`http`||e.type===`sse`,o=a&&e.oauthSupport===`dcr`&&!!e.authTokenEnv,s=!!e.setupResource,[c,l]=(0,w.useState)(!1),[u,d]=(0,w.useState)(``),[f,p]=(0,w.useState)(!1),[m,h]=(0,w.useState)(null);return(0,q.jsxs)(`div`,{className:`border-b border-gray-50 last:border-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50`,children:[(0,q.jsx)(`span`,{className:`text-[14px] text-gray-300 leading-none`,children:e.authed?`●`:o?`○`:`·`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,q.jsx)(`span`,{className:`font-medium text-gray-700 text-[13px]`,children:e.name}),(0,q.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase`,children:e.type})]}),e.url&&(0,q.jsx)(`div`,{className:`text-[11px] text-gray-400 font-mono truncate`,children:e.url})]}),(0,q.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1`,children:[e.authed&&(0,q.jsxs)(`span`,{className:`text-[11px] text-green-700 inline-flex items-center gap-1`,children:[(0,q.jsx)(V,{size:11}),` authed`]}),o&&(0,q.jsxs)(`button`,{onClick:n,disabled:t,className:`inline-flex items-center gap-1 text-[11px] px-2 h-6 rounded ${e.authed?`text-gray-600 hover:bg-gray-100 border border-gray-200`:`text-amber-700 bg-amber-50 hover:bg-amber-100 border border-amber-200`} disabled:opacity-50`,title:e.authed?`Re-run OAuth and overwrite the existing token`:`Run OAuth to obtain a token`,children:[e.authed?(0,q.jsx)(Oe,{size:10}):(0,q.jsx)(ct,{size:10}),t?`…`:e.authed?`re-auth`:`auth`]}),e.authed&&r&&(0,q.jsxs)(`button`,{onClick:r,disabled:t,className:`inline-flex items-center gap-1 text-[11px] px-1.5 h-6 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100 disabled:opacity-50`,title:`Delete the env file backing this server's token`,children:[(0,q.jsx)(ut,{size:10}),` forget`]}),s&&(0,q.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`inline-flex items-center gap-1 text-[11px] px-2 h-6 rounded ${e.authed?`text-gray-600 hover:bg-gray-100 border border-gray-200`:`text-amber-700 bg-amber-50 hover:bg-amber-100 border border-amber-200`}`,title:`Paste your MCP URL from the provider's page to set this server's secrets`,children:[(0,q.jsx)(Ee,{size:10}),e.authed?`re-setup`:`setup`]}),!s&&!o&&!e.authed&&a&&(e.oauthSupport===`manual`?(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500 italic`,title:`This provider requires admin to register an OAuth app (no DCR). Loopat doesn't support manual client_id setup.`,children:`manual setup`}):e.oauthSupport===`none`?(0,q.jsx)(`span`,{className:`text-[11px] text-gray-400`,title:`No OAuth metadata — server is public or uses non-OAuth auth (e.g. API key).`,children:`no oauth`}):e.oauthSupport===`unreachable`?(0,q.jsx)(`span`,{className:`text-[11px] text-red-500`,title:`Probe failed — server unreachable or returned malformed metadata.`,children:`unreachable`}):e.authTokenEnv===null?(0,q.jsx)(`span`,{className:`text-[11px] text-gray-400 italic`,title:"No Bearer ${VAR} template in Authorization header — loopat can't determine which env to write.",children:`no bearer template`}):null),!a&&(0,q.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:`stdio`})]})]}),c&&s&&(0,q.jsxs)(`div`,{className:`px-3 pb-2.5 pt-0.5 bg-gray-50/60`,children:[(0,q.jsxs)(`div`,{className:`text-[11px] text-gray-500 mb-1.5`,children:[`到`,` `,(0,q.jsxs)(`a`,{href:e.setupResource,target:`_blank`,rel:`noreferrer`,className:`text-blue-600 hover:text-blue-800 inline-flex items-center gap-0.5`,children:[`这个页面 `,(0,q.jsx)(le,{size:9})]}),` `,`复制你的 MCP URL,粘贴到下面 —— 会自动解析出`,` `,(e.requiredEnvs??[]).join(`、`)||`所需密钥`,` 并存进你的 vault。`]}),(0,q.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`https://…?key=…`,rows:2,spellCheck:!1,className:`w-full px-2 py-1 rounded border border-gray-300 text-[11px] font-mono focus:outline-none focus:border-gray-500 resize-none`}),m&&(0,q.jsx)(`div`,{className:`text-[11px] text-red-600 mt-1`,children:m}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,q.jsx)(`button`,{onClick:async()=>{p(!0),h(null);let e=await i(u.trim());p(!1),e?h(e):(l(!1),d(``))},disabled:!u.trim()||f,className:`text-[11px] px-2.5 h-6 rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:f?`解析中…`:`解析并保存`}),(0,q.jsx)(`button`,{onClick:()=>{l(!1),d(``),h(null)},className:`text-[11px] text-gray-500 hover:text-gray-800`,children:`取消`})]})]})]})}var xF=[{id:`think`,name:`Think`,description:`Extended thinking (16k token budget)`,icon:z,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:16e3},{id:`think-hard`,name:`Think Hard`,description:`Deep thinking (32k token budget)`,icon:gt,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:32e3},{id:`ultrathink`,name:`Ultrathink`,description:`Maximum thinking (no budget limit)`,icon:tt,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:null},{id:`plan`,name:`Permission`,description:`Cycle permission mode`,icon:Je,group:`quick`,action:`toggle`,prefix:``,toggleKey:`permissionMode`},{id:`goal`,name:`Goal`,description:`Set goal (/goal <text>), mark done (/goal done), clear (/goal clear)`,icon:at,group:`quick`,action:`agent`,prefix:``},{id:`usage`,name:`Context Usage`,description:`Show context window token usage`,icon:B,group:`quick`,action:`command`,prefix:``,commandKey:`getContextUsage`},{id:`clear`,name:`Clear Context`,description:`Reset AI conversation (history kept)`,icon:ce,group:`quick`,action:`command`,prefix:``,commandKey:`clearContext`},{id:`mcp`,name:`MCP Servers`,description:`Show MCP servers + tools available to this loop`,icon:Re,group:`quick`,action:`command`,prefix:``,commandKey:`openMcpPanel`}],SF=[{id:`quick`,label:`Quick actions`},{id:`plugin`,label:`Plugin commands`},{id:`skill`,label:`Skills`}],CF=new Set(xF.map(e=>e.id));function wF(){let e=Q(e=>e.composer.text),t=CC(),{permissionMode:n,setPermissionMode:r,clearContext:i,setMaxThinkingTokens:a,getContextUsage:o,availableSlashCommands:s,suppressSlashRef:c,loopId:l}=jP(),[u,d]=(0,w.useState)(!1),[f,p]=(0,w.useState)(0),[m,h]=(0,w.useState)(``),[g,_]=(0,w.useState)(!1),v=(0,w.useRef)(null),y=(0,w.useMemo)(()=>{let e=s.filter(e=>!CF.has(e.name)).map(e=>{let t=e.name.includes(`:`),n=t?e.name.split(`:`,1)[0]:void 0;return{id:e.name,name:e.name,description:e.description||(t?`from ${n} plugin`:`skill`),icon:t?Ge:ot,group:t?`plugin`:`skill`,action:`agent`,prefix:``,pluginName:n}});return[...xF,...e]},[s]),b=typeof e==`string`?e.trimStart():e,x=typeof b==`string`&&b.startsWith(`/`)&&!b.includes(` `);x&&c.current&&(x=!1);let S=x?b.slice(1).toLowerCase():``,C=(0,w.useMemo)(()=>y.filter(e=>!S||e.id.toLowerCase().includes(S)||e.name.toLowerCase().includes(S)),[y,S]),T=(0,w.useMemo)(()=>{let e={quick:0,plugin:1,skill:2};return[...C].sort((t,n)=>t.group===n.group?t.group===`plugin`&&t.pluginName!==n.pluginName?(t.pluginName??``).localeCompare(n.pluginName??``):t.id.localeCompare(n.id):e[t.group]-e[n.group])},[C]),E=(0,w.useMemo)(()=>{let e=new Map;for(let t of T){let n=e.get(t.group)??[];n.push(t),e.set(t.group,n)}return e},[T]);(0,w.useEffect)(()=>{x?(d(!0),h(S),p(0)):d(!1)},[x,S]);let D=(0,w.useCallback)(e=>{if(e.action===`toggle`&&e.toggleKey===`permissionMode`){let e=[`bypassPermissions`,`auto`,`dontAsk`,`acceptEdits`,`plan`,`default`],i=e[(e.indexOf(n)+1)%e.length];r(i),t.setText(``)}else e.action===`command`?e.commandKey===`clearContext`?(i(),t.setText(``)):e.commandKey===`setMaxThinkingTokens`?(a(e.tokens??null),t.setText(``)):e.commandKey===`getContextUsage`?(o(),t.setText(``)):e.commandKey===`openMcpPanel`&&(_(!0),t.setText(``)):e.action===`agent`&&t.setText(`/${e.id} `);d(!1)},[t,n,r,i,a,o]);(0,w.useEffect)(()=>{if(!u)return;let e=e=>{e.key===`ArrowDown`?(e.preventDefault(),e.stopImmediatePropagation(),p(e=>Math.min(e+1,T.length-1))):e.key===`ArrowUp`?(e.preventDefault(),e.stopImmediatePropagation(),p(e=>Math.max(e-1,0))):e.key===`Enter`&&T.length>0?(e.preventDefault(),e.stopImmediatePropagation(),D(T[f])):e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),t.setText(``))};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},[u,T,f,t,D]),(0,w.useEffect)(()=>{if(!v.current)return;let e=v.current.querySelector(`[data-slash-idx="${f}"]`);e&&e.scrollIntoView({block:`nearest`})},[f]);let O=-1;return g&&(!u||T.length===0)?(0,q.jsx)(`div`,{className:`relative`,children:(0,q.jsx)(`div`,{className:`absolute bottom-0 left-0 mb-1 w-[28rem] rounded-lg border border-gray-200 bg-white shadow-lg z-20`,children:(0,q.jsx)(yF,{onClose:()=>_(!1),loopId:l})})}):!u||T.length===0?null:(0,q.jsxs)(`div`,{className:`relative`,children:[g&&(0,q.jsx)(`div`,{className:`absolute bottom-0 left-0 mb-1 w-[28rem] rounded-lg border border-gray-200 bg-white shadow-lg z-30`,children:(0,q.jsx)(yF,{onClose:()=>_(!1),loopId:l})}),(0,q.jsx)(`div`,{className:`absolute bottom-0 left-0 mb-1 w-72 rounded-lg border border-gray-200 bg-white shadow-lg z-20`,children:(0,q.jsx)(`div`,{ref:v,className:`max-h-72 overflow-y-auto py-1`,children:SF.map(e=>{let t=E.get(e.id);return!t||t.length===0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`px-3 pt-2 pb-1`,children:(0,q.jsx)(`p`,{className:`text-[10px] font-medium text-gray-400 uppercase tracking-wider`,children:e.label})}),t.map(e=>{O+=1;let t=O,r=e.icon,i=t===f,a=e.toggleKey===`permissionMode`&&n!==`bypassPermissions`||e.isActive;return(0,q.jsxs)(`button`,{type:`button`,"data-slash-idx":t,onMouseEnter:()=>p(t),onMouseDown:t=>{t.preventDefault(),D(e)},className:`w-full flex items-center gap-2.5 px-3 py-1.5 text-left transition-colors ${i?`bg-blue-50`:`hover:bg-gray-50`}`,children:[(0,q.jsx)(r,{className:`h-4 w-4 flex-shrink-0 ${a?`text-blue-600`:`text-gray-400`}`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[`/`,e.id]}),e.action===`toggle`&&a&&(0,q.jsx)(`span`,{className:`rounded bg-blue-100 px-1 py-0.5 text-[9px] text-blue-600`,children:`ON`})]}),(0,q.jsx)(`p`,{className:`text-xs text-gray-500 truncate`,children:e.description})]})]},e.id)})]},e.id)})})})]})}function TF({used:e,total:t}){if(!t||t<=0)return null;let n=Math.min(100,e/t*100),r=2*Math.PI*10,i=r-n/100*r;return(0,q.jsxs)(Wp,{children:[(0,q.jsx)(Gp,{asChild:!0,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-gray-500`,children:[(0,q.jsxs)(`svg`,{width:`24`,height:`24`,viewBox:`0 0 24 24`,className:`-rotate-90 transform`,children:[(0,q.jsx)(`circle`,{cx:`12`,cy:`12`,r:10,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`text-gray-300`}),(0,q.jsx)(`circle`,{cx:`12`,cy:`12`,r:10,fill:`none`,stroke:n<50?`var(--color-blue-500)`:n<75?`var(--color-amber-500)`:`var(--color-red-500)`,strokeWidth:`2`,strokeDasharray:r,strokeDashoffset:i,strokeLinecap:`round`})]}),(0,q.jsxs)(`span`,{children:[n.toFixed(0),`%`]})]})}),(0,q.jsx)(Kp,{children:(0,q.jsx)(`div`,{className:`text-xs`,children:(0,q.jsxs)(`p`,{children:[e.toLocaleString(),` / `,t.toLocaleString(),` tokens`]})})})]})}function EF({loopId:e,onPick:t,onClose:n}){let[r,i]=(0,w.useState)([]),[a,o]=(0,w.useState)([]),[s,c]=(0,w.useState)(!0),[l,u]=(0,w.useState)(``),[d,f]=(0,w.useState)(0),[p,m]=(0,w.useState)(new Set),[h,g]=(0,w.useState)({}),_=(0,w.useRef)(null),v=(0,w.useRef)(null);(0,w.useEffect)(()=>{c(!0),Promise.all([wm(e,`workdir`).catch(()=>[]),Tm(e,`workdir`).catch(()=>[])]).then(([e,t])=>{i(e),o(t),c(!1)})},[e]);let y=l.trim().length>0,b=(0,w.useMemo)(()=>{let e=l.trim().toLowerCase();return e?a.filter(t=>t.type===`file`&&(t.path.toLowerCase().includes(e)||t.name.toLowerCase().includes(e))):[]},[a,l]),x=(0,w.useMemo)(()=>{if(y)return[];let e=[];function t(n,r){for(let i of n)e.push({entry:i,depth:r}),i.type===`dir`&&p.has(i.path)&&h[i.path]&&t(h[i.path],r+1)}return t(r,0),e},[r,y,p,h]);(0,w.useEffect)(()=>{f(0)},[l]),(0,w.useEffect)(()=>{v.current&&v.current.children[d]?.scrollIntoView({block:`nearest`})},[d]);let S=(0,w.useCallback)(async t=>{if(p.has(t.path))m(e=>{let n=new Set(e);return n.delete(t.path),n});else{if(!h[t.path]){let n=await wm(e,t.path).catch(()=>[]);g(e=>({...e,[t.path]:n}))}m(e=>new Set(e).add(t.path))}},[p,h,e]),C=(0,w.useCallback)(e=>{if(e.type===`dir`){S(e);return}t(e.path)},[S,t]);return(0,_t.createPortal)((0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/20`,onClick:n}),(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[15vh]`,onClick:n,children:(0,q.jsxs)(`div`,{className:`w-[420px] max-w-[calc(100vw-2rem)] max-h-[60vh] bg-white rounded-xl shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),onKeyDown:e=>{if(e.key===`Escape`){e.preventDefault(),n();return}if(y)e.key===`ArrowDown`?(e.preventDefault(),f(e=>Math.min(e+1,b.length-1))):e.key===`ArrowUp`?(e.preventDefault(),f(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),b[d]&&t(b[d].path));else if(e.key===`ArrowDown`)e.preventDefault(),f(e=>Math.min(e+1,x.length-1));else if(e.key===`ArrowUp`)e.preventDefault(),f(e=>Math.max(e-1,0));else if(e.key===`ArrowRight`||e.key===`ArrowLeft`){e.preventDefault();let t=x[d];if(!t||t.entry.type!==`dir`)return;let n=p.has(t.entry.path);(e.key===`ArrowRight`&&!n||e.key===`ArrowLeft`&&n)&&S(t.entry)}else e.key===`Enter`&&(e.preventDefault(),x[d]&&C(x[d].entry))},children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,q.jsx)(Ye,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,q.jsx)(`input`,{ref:_,autoFocus:!0,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search files...`,className:`flex-1 text-sm outline-none text-gray-900 placeholder:text-gray-400`})]}),(0,q.jsx)(`div`,{ref:v,className:`flex-1 overflow-y-auto py-2`,role:`listbox`,children:s?(0,q.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`Loading...`}):y?b.length===0?(0,q.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`No files match your search`}):b.map((e,n)=>(0,q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n===d,onClick:()=>t(e.path),onMouseEnter:()=>f(n),className:X(`w-full px-6 py-1.5 text-left flex items-center gap-2 transition-colors text-[12px]`,n===d&&`bg-blue-50`),children:[(0,q.jsx)(me,{size:12,className:`text-blue-400 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate font-mono text-gray-700`,children:e.path})]},e.path)):r.length===0?(0,q.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`No files found`}):x.map(({entry:e,depth:t},n)=>{let r=e.type===`dir`,i=p.has(e.path);return(0,q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n===d,onClick:()=>C(e),onMouseEnter:()=>f(n),className:X(`w-full text-left flex items-center gap-1.5 px-2 py-1 text-[12px] transition-colors`,n===d&&`bg-blue-50`),style:{paddingLeft:12+t*16},children:[r?(0,q.jsxs)(q.Fragment,{children:[i?(0,q.jsx)(H,{size:11,className:`text-gray-300 shrink-0`}):(0,q.jsx)(U,{size:11,className:`text-gray-300 shrink-0`}),(0,q.jsx)(ve,{size:13,className:`text-amber-500 shrink-0`})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`w-[11px] shrink-0`}),(0,q.jsx)(me,{size:13,className:`text-blue-400 shrink-0`})]}),(0,q.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path)})}),(0,q.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2 border-t border-gray-100 text-[10px] text-gray-400 shrink-0`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(F,{className:`h-3 w-3`}),(0,q.jsx)(M,{className:`h-3 w-3`}),`navigate`]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(ae,{className:`h-3 w-3`}),`select`]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-gray-100 font-mono text-[9px]`,children:`esc`}),`close`]})]})]})})]}),document.body)}var DF=2e5,OF=500;function kF({pickedFile:e,editorSelection:t}){let n=Q(e=>e.thread.isRunning),r=Q(e=>typeof e.composer.text==`string`&&e.composer.text.trim().length>0),i=Q(e=>e.composer.text),{provider:a,permissionMode:o,setPermissionMode:s,enqueueMessage:c,queue:l,clearQueue:u,removeFromQueue:d,loopId:f,contextTokens:p,cumulativeTokens:m,getStreamingTokenCount:h,getWaitingForResponse:g,suppressSlashRef:_,goal:v,setGoal:y,goalStatus:b,completeGoal:x}=jP(),S=a?.contextWindow??DF,C=zv(),[T,E]=(0,w.useState)(!1),[D,O]=(0,w.useState)([]),[k,A]=(0,w.useState)(!1),j=[...T&&e?[e]:[],...D],M=()=>E(e=>!e),N=e=>{O(t=>t.includes(e)?t:[...t,e]),A(!1)},P=e=>{O(t=>t.filter(t=>t!==e))},I=e=>{let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e},L=(0,w.useRef)(``),R=(0,w.useRef)([]),[z,B]=(0,w.useState)(!1);(0,w.useEffect)(()=>{let n=!1;async function r(){if(j.length===0){L.current=``,R.current=[];return}B(!0);let r=[],i=[];for(let a of j){if(n)return;try{let n=await Em(f,a);if(n&&n.content){let o=a.includes(`.`)?a.split(`.`).pop()??``:``,s=a===e?t:null,c=n.content,l=a;if(s){let e=n.content.split(`
|
|
88
88
|
`),t=Math.max(0,s.from-1),r=Math.min(e.length,s.to);c=e.slice(t,r).join(`
|
|
89
89
|
`),l=`${a} (${s.from}-${s.to})`}let u=c.replace(/```/g,"```");r.push(`\n# File: ${l}\n\`\`\`${o}\n${u}\n\`\`\`\n`),i.push({path:l,content:c})}}catch{}}n||(L.current=r.join(``),R.current=i,B(!1))}return r(),()=>{n=!0}},[j.join(`,`),f,e,t?.from,t?.to]);let V=e=>{let t=L.current;return t?`${t}\n${e}`:e},[H,U]=(0,w.useState)([]),[W,G]=(0,w.useState)(-1),K=(0,w.useRef)(``),te=(0,w.useRef)(``);te.current=typeof i==`string`?i:``,(0,w.useEffect)(()=>{f&&Gm(f).then(e=>{U(e),G(-1)})},[f]);let ne=e=>{if(!e.trim()||!f)return;let t=e.trim();U(e=>{if(e[e.length-1]===t)return e;let n=[...e,t];return n.length>OF&&n.splice(0,n.length-OF),n}),G(-1),Km(f,t).catch(()=>{})},re=()=>{let e=typeof i==`string`?i.trim():``;if(e){if(ne(e),L.current)try{sessionStorage.setItem(`loopat:pendingFileContext`,L.current)}catch{}c(V(e)),C.composer().setText(``)}};return(0,q.jsxs)(HC,{className:`relative flex w-full flex-col`,onSubmit:()=>{let e=te.current.trim();if(e&&(ne(e),L.current))try{sessionStorage.setItem(`loopat:pendingFileContext`,L.current)}catch{}},children:[(0,q.jsx)(uF,{isLoading:n,getTokenCount:h,getWaitingForResponse:g}),l.length>0&&(0,q.jsx)(`div`,{className:`mb-1.5 space-y-1 px-2`,children:l.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 bg-gray-50 border border-gray-200 rounded-md px-2.5 py-1.5`,children:[(0,q.jsxs)(`span`,{className:`text-xs text-gray-600 line-clamp-3 break-words whitespace-pre-wrap min-w-0`,children:[(0,q.jsxs)(`span`,{className:`text-gray-400 mr-1.5 shrink-0`,children:[t+1,`.`]}),e]}),(0,q.jsx)(`button`,{onClick:()=>d(t),className:`text-gray-400 hover:text-gray-600 shrink-0 p-0.5 rounded hover:bg-gray-100 transition-colors`,title:`Remove from queue`,children:(0,q.jsx)(ht,{className:`h-3.5 w-3.5`})})]},t))}),j.length>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 mb-1 flex-wrap`,children:[j.map(n=>(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-blue-200 bg-blue-50 px-2 py-0.5 text-[11px] text-blue-700`,children:[(0,q.jsx)(me,{size:11,className:`shrink-0`}),(0,q.jsx)(`span`,{className:`truncate max-w-[160px]`,children:I(n)}),n!==e&&(0,q.jsx)(`button`,{onClick:()=>P(n),className:`ml-0.5 hover:text-blue-900`,children:(0,q.jsx)(ht,{size:11})}),n===e&&T&&(0,q.jsx)(`span`,{className:`text-[9px] text-blue-400 ml-0.5`,children:t?`(${t.from}-${t.to})`:`editor`})]},n)),z&&(0,q.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:`loading...`})]}),v&&(0,q.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-2 px-2 py-1.5 rounded-lg border group ${b===`completed`?`border-green-200 bg-green-50`:`border-amber-200 bg-amber-50`}`,children:[b===`completed`?(0,q.jsx)(ee,{className:`h-3.5 w-3.5 text-green-600 shrink-0`}):(0,q.jsx)(at,{className:`h-3.5 w-3.5 text-amber-600 shrink-0`}),(0,q.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0 ${b===`completed`?`text-green-800 line-through`:`text-amber-800`}`,children:v}),b===`active`&&(0,q.jsx)(`button`,{onClick:()=>x?.(),className:`shrink-0 px-1.5 py-0.5 rounded text-[10px] font-medium text-amber-700 hover:bg-amber-200 opacity-0 group-hover:opacity-100 transition-opacity`,title:`Mark goal as complete`,children:`Done`}),(0,q.jsx)(`button`,{onClick:()=>y?.(null),className:`shrink-0 p-0.5 rounded hover:bg-amber-200/50 opacity-0 group-hover:opacity-100 transition-opacity`,title:`Clear goal`,children:(0,q.jsx)(ht,{className:`h-3 w-3 ${b===`completed`?`text-green-500`:`text-amber-600`}`})})]}),(0,q.jsxs)(`div`,{"data-slot":`composer-shell`,className:`flex w-full flex-col gap-2 rounded-2xl border border-gray-200 bg-white p-2.5 shadow-sm`,children:[(0,q.jsx)(wF,{}),(0,q.jsx)(ww,{placeholder:`Send a message...`,className:`max-h-32 min-h-10 w-full resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`,rows:1,autoFocus:!0,"aria-label":`Message input`,onKeyDown:e=>{if(!(e.nativeEvent.isComposing||e.keyCode===229)){if(e.key===`c`&&e.ctrlKey&&!e.altKey&&!e.metaKey&&!e.shiftKey&&!/windows/i.test(navigator.userAgent)){let t=e.target;if(t.selectionStart===t.selectionEnd&&te.current.trim().length>0){e.preventDefault(),C.composer().setText(``);return}}if(e.key!==`ArrowUp`&&e.key!==`ArrowDown`&&(_.current=!1),e.key===`Enter`&&!e.nativeEvent.isComposing&&!e.shiftKey&&n){e.preventDefault(),re();return}if(e.key===`ArrowUp`&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey){if(H.length===0)return;if(e.preventDefault(),_.current=!0,W===-1)K.current=te.current,G(H.length-1),C.composer().setText(H[H.length-1]);else if(W>0){let e=W-1;G(e),C.composer().setText(H[e])}return}if(e.key===`ArrowDown`&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey){if(W===-1)return;if(e.preventDefault(),_.current=!0,W<H.length-1){let e=W+1;G(e),C.composer().setText(H[e])}else G(-1),C.composer().setText(K.current);return}}}}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-0.5 border-t border-gray-100 pt-2 overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-0.5 min-w-0`,children:[(0,q.jsx)(TF,{used:Math.min(p,S),total:S}),(0,q.jsx)(_F,{}),(0,q.jsx)(vF,{onPick:e=>{let t=te.current,n=t.length===0||t.endsWith(` `)?`${t}${e}`:`${t} ${e}`;C.composer().setText(n)}}),e&&(0,q.jsxs)(`button`,{type:`button`,onClick:M,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${T?`bg-blue-50 text-blue-600 border border-blue-200`:`text-gray-400 hover:text-gray-600 hover:bg-gray-100`}`,title:T?`Remove editor file from context`:`Include editor file in context`,children:[(0,q.jsx)(me,{size:12}),I(e)]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>A(e=>!e),className:`inline-flex items-center justify-center rounded-md border border-gray-200 bg-gray-50 w-[21px] h-[21px] mt-px text-gray-500 hover:bg-gray-100 transition-colors`,title:`Add file to context`,children:(0,q.jsx)(pe,{size:12})}),k&&(0,q.jsx)(EF,{loopId:f,onPick:N,onClose:()=>A(!1)})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 shrink-0`,children:[(0,q.jsx)(gF,{mode:o,onChange:s}),r&&(n?(0,q.jsx)(Pg,{type:`button`,variant:`default`,size:`icon`,onClick:re,className:`h-8 w-8 rounded-lg bg-amber-500 hover:bg-amber-600 text-white`,"aria-label":`Enqueue message`,title:`Enqueue message`,children:(0,q.jsx)(ke,{className:`h-4 w-4`})}):(0,q.jsx)(VC,{asChild:!0,children:(0,q.jsx)(Pg,{type:`button`,variant:`default`,size:`icon`,className:`h-8 w-8 rounded-lg bg-gray-800 hover:bg-gray-900 text-white`,"aria-label":`Send message`,children:(0,q.jsx)(F,{className:`h-4 w-4`})})})),(0,q.jsx)(Yv,{condition:e=>e.thread.isRunning,children:(0,q.jsx)(Tw,{asChild:!0,children:(0,q.jsx)(Pg,{type:`button`,variant:`default`,size:`icon`,className:`h-8 w-8 rounded-lg bg-red-500 hover:bg-red-600 text-white`,"aria-label":`Stop generating`,children:(0,q.jsx)(nt,{className:`h-3 w-3 fill-current`})})})})]})]})]})]})}function AF({questions:e,toolUseId:t,onAnswers:n,onDismiss:r,disabled:i=!1}){let[a,o]=(0,w.useState)({}),[s,c]=(0,w.useState)({}),[l,u]=(0,w.useState)(!1),[d,f]=(0,w.useState)(0),p=Array.isArray(e)?e.filter(e=>e!=null&&typeof e.question==`string`&&e.question.length>0&&Array.isArray(e.options)):[];if(p.length===0)return null;let m=(e,t)=>{i||l||(c(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),o(n=>({...n,[e]:t})))},h=(e,t)=>{i||l||(c(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),o(n=>{let r=(n[e]??``).split(`,`).filter(Boolean),i=r.indexOf(t);return i>=0?r.splice(i,1):r.push(t),{...n,[e]:r.join(`,`)}}))},g=(e,t)=>{i||l||(c(n=>({...n,[e]:t})),o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}))},_=e=>s[e.question]?.trim()||a[e.question]||``,v=p.every(e=>{let t=_(e);return t!==void 0&&t!==``}),y=e=>{let t=_(e);return t!==void 0&&t!==``},b=()=>{if(!v||!t||!n||l)return;u(!0);let e={};for(let t of p)e[t.question]=_(t);n(t,e)},x=()=>{i||l||(u(!0),r?.(t||``))},S=()=>{f(e=>Math.min(e+1,p.length-1))},C=(e,t)=>e.header?e.header:`Question ${t+1}`,T=p[d],E=a[T.question]??``,D=new Set(E.split(`,`).filter(Boolean)),O=Array.isArray(T.options)?T.options:[],k=s[T.question]??``;return(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-violet-600 font-medium`,children:[(0,q.jsx)(K,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{children:p.length>1?`Question ${d+1} of ${p.length}`:`Question`})]}),(0,q.jsx)(`button`,{type:`button`,onClick:x,disabled:i||l,className:`flex items-center justify-center h-5 w-5 rounded text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:(0,q.jsx)(ht,{className:`h-3.5 w-3.5`})})]}),p.length>1&&(0,q.jsx)(`div`,{className:`flex gap-1 border-b border-gray-200`,children:p.map((e,t)=>{let n=y(e);return(0,q.jsxs)(`button`,{type:`button`,disabled:i||l,onClick:()=>f(t),className:X(`flex items-center gap-1 px-2.5 py-1.5 text-[11px] font-medium transition-colors border-b-2 -mb-[1px] whitespace-nowrap`,t===d?`border-violet-500 text-violet-700`:`border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300`,(i||l)&&`cursor-default opacity-70`),children:[n&&(0,q.jsx)(V,{className:`h-3 w-3 text-emerald-500`}),C(e,t)]},t)})}),(0,q.jsxs)(`div`,{className:`overflow-y-auto max-h-[260px] space-y-1.5`,children:[T.header&&(0,q.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wide text-gray-400`,children:T.header}),(0,q.jsx)(`p`,{className:`text-[12px] text-gray-800 font-medium`,children:T.question}),(0,q.jsx)(`div`,{className:`space-y-1`,children:O.map((e,t)=>{let n=typeof e?.label==`string`?e.label:``,r=typeof e?.description==`string`?e.description:``;if(!n)return null;let a=T.multiSelect?D.has(n):E===n;return(0,q.jsx)(`button`,{type:`button`,disabled:i||l,onClick:()=>T.multiSelect?h(T.question,n):m(T.question,n),className:X(`w-full text-left px-3 py-2 rounded-md border text-[12px] transition-colors`,a?`border-violet-400 bg-violet-50 text-violet-900`:`border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-50`,(i||l)&&`cursor-default opacity-70`),children:(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[T.multiSelect?(0,q.jsx)(`span`,{className:X(`h-3.5 w-3.5 rounded border flex-shrink-0 flex items-center justify-center`,a?`border-violet-500 bg-violet-500`:`border-gray-300`),children:a&&(0,q.jsx)(`svg`,{className:`h-2.5 w-2.5 text-white`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,q.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:3,d:`M5 13l4 4L19 7`})})}):(0,q.jsx)(`span`,{className:X(`h-3.5 w-3.5 rounded-full border flex-shrink-0`,a?`border-violet-500 bg-violet-500`:`border-gray-300`),children:a&&(0,q.jsx)(`span`,{className:`block h-1.5 w-1.5 rounded-full bg-white m-0.5`})}),(0,q.jsx)(`span`,{children:n}),r&&(0,q.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[`— `,r]})]})},t)})}),(0,q.jsx)(`input`,{type:`text`,value:k,onChange:e=>g(T.question,e.target.value),placeholder:`Or type your own answer...`,disabled:i||l,className:X(`w-full px-3 py-1.5 rounded-md border text-[12px] outline-none transition-colors`,k?`border-violet-300 bg-violet-50/50 text-violet-900 placeholder:text-violet-300`:`border-gray-200 bg-white text-gray-700 placeholder:text-gray-300 hover:border-gray-300 focus:border-violet-300`,(i||l)&&`cursor-default opacity-70`)})]}),!l&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between pt-1`,children:[p.length>1&&d<p.length-1?(0,q.jsxs)(`button`,{type:`button`,disabled:i,onClick:S,className:`inline-flex items-center gap-1 rounded-lg px-3 py-1.5 text-[11px] font-medium text-gray-500 hover:text-gray-700 hover:bg-gray-100 transition-colors`,children:[`Next`,(0,q.jsx)(U,{className:`h-3 w-3`})]}):(0,q.jsx)(`div`,{}),(0,q.jsxs)(`button`,{type:`button`,disabled:!v||i,onClick:b,className:X(`inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,v?`bg-gray-900 text-white hover:bg-gray-800`:`bg-gray-100 text-gray-400 cursor-not-allowed`),children:[(0,q.jsx)(Xe,{className:`h-3 w-3`}),`Submit`]})]}),l&&(0,q.jsx)(`p`,{className:`text-[11px] text-emerald-600 font-medium text-right`,children:`Submitted`})]})}var jF=()=>(0,q.jsxs)(`div`,{className:`my-auto flex grow flex-col items-center justify-center gap-3`,children:[(0,q.jsx)(`div`,{className:`h-5 w-5 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600`}),(0,q.jsx)(`p`,{className:`text-sm text-gray-400`,children:`Loading history…`})]}),MF=`loopat:composer:drafts`;function NF(e){try{let t=localStorage.getItem(MF);return t?JSON.parse(t)[e]??null:null}catch{return null}}function PF(e,t){try{let n=localStorage.getItem(MF),r=n?JSON.parse(n):{};t.trim()?r[e]=t:delete r[e],localStorage.setItem(MF,JSON.stringify(r))}catch{}}function FF({archived:e=!1,onUnarchive:t,readOnly:n=!1,repo:r,branch:i,title:a,driver:o,driverHistory:s,rfdRequestedAt:c,rfdRequestedBy:l,onTakeDrive:u,pickedFile:d,editorSelection:f}={}){let{questions:p,sendAnswers:m,loadingHistory:h,loopId:g,hasHistory:_,showHistory:v,toggleShowHistory:y,hasOlderMessages:b,loadMoreMessages:x,thinkingBudget:S,setMaxThinkingTokens:C}=jP(),[T,E]=(0,w.useState)(`normal`),D=Q(e=>e.thread.isEmpty&&!e.thread.isRunning)&&!h,O=(0,w.useRef)(null),k=(0,w.useRef)(null),[A,j]=(0,w.useState)(!1),N=(0,w.useCallback)(()=>{let e=k.current;e&&e.scrollTo({top:e.scrollHeight,behavior:`smooth`})},[]),P=(0,w.useRef)(_);P.current=_;let F=(0,w.useRef)(v);F.current=v;let I=(0,w.useRef)(b);I.current=b;let[L,R]=(0,w.useState)(!1),z=(0,w.useRef)({oldScrollTop:0,oldScrollHeight:0,active:!1}),B=(0,w.useCallback)(()=>{let e=k.current;e&&(z.current={oldScrollTop:e.scrollTop,oldScrollHeight:e.scrollHeight,active:!0}),y()},[y]),V=(0,w.useRef)({oldScrollTop:0,oldScrollHeight:0,active:!1}),H=(0,w.useCallback)(()=>{let e=k.current;e&&(V.current={oldScrollTop:e.scrollTop,oldScrollHeight:e.scrollHeight,active:!0}),W(!0),x()},[x]),[U,W]=(0,w.useState)(!1),G=(0,w.useRef)(!1);G.current=U;let ee=CC(),K=Q(e=>e.composer.text),te=(0,w.useRef)(K);te.current=K,(0,w.useEffect)(()=>{let e=NF(g);e&&ee.setText(e)},[]),(0,w.useEffect)(()=>()=>{PF(g,te.current)},[g]),(0,w.useEffect)(()=>{if(!K)return;let e=setTimeout(()=>{PF(g,K)},300);return()=>clearTimeout(e)},[K,g]);let[ne,re]=(0,w.useState)(K);(0,w.useEffect)(()=>{ne&&!K&&PF(g,``),re(K)},[K,g]);let ie=(0,w.useRef)(null),ae=(0,w.useRef)(!1),oe=(0,w.useRef)(h);oe.current=h;let se=(0,w.useRef)(h);(0,w.useEffect)(()=>{let e=O.current,t=e?.parentElement;if(!e||!t)return;k.current=t;let n=()=>t.scrollTop+t.clientHeight>=t.scrollHeight-120,r=!1,i=null,a=e=>{e.deltaY<0&&(r=!0,i&&clearTimeout(i),i=setTimeout(()=>{i=null,n()&&(r=!1)},200))},o=()=>{!i&&n()?r=!1:n()||(r=!0),j(t.scrollTop+t.clientHeight<t.scrollHeight-200),R(t.scrollTop<20&&P.current),t.scrollTop<40&&I.current&&!G.current&&H()};t.addEventListener(`scroll`,o,{passive:!0}),t.addEventListener(`wheel`,a,{passive:!0});let s=null,c=!1,l=()=>{if(ae.current&&r||c||!ae.current&&t.scrollHeight<=t.clientHeight+10)return;let e=t.style.scrollBehavior;t.style.scrollBehavior=`auto`,t.scrollTop=t.scrollHeight,t.style.scrollBehavior=e,ae.current||(oe.current||(ae.current=!0),r=!1),c=!0,requestAnimationFrame(()=>{setTimeout(()=>{c=!1},120)})};l();let u=new ResizeObserver(()=>{s||oe.current||c||(s=setTimeout(()=>{s=null,l()},80))});return u.observe(e),()=>{u.disconnect(),s&&clearTimeout(s),i&&clearTimeout(i),t.removeEventListener(`scroll`,o),t.removeEventListener(`wheel`,a)}},[]),(0,w.useEffect)(()=>{if(se.current&&!h){let e=k.current;if(e){let t=e.style.scrollBehavior;e.style.scrollBehavior=`auto`,e.scrollTop=e.scrollHeight,e.style.scrollBehavior=t,ae.current=!0}}se.current=h},[h]),(0,w.useEffect)(()=>{if(!z.current.active)return;let e=k.current;if(!e)return;let{oldScrollTop:t,oldScrollHeight:n}=z.current;z.current.active=!1,requestAnimationFrame(()=>{e.scrollTop=t+(e.scrollHeight-n)})},[v]),(0,w.useEffect)(()=>{if(!V.current.active)return;let e=k.current;if(!e)return;let{oldScrollTop:t,oldScrollHeight:n}=V.current;V.current.active=!1,requestAnimationFrame(()=>{e.scrollTop=t+(e.scrollHeight-n)})},[b]),(0,w.useEffect)(()=>{if(!U)return;let e=setTimeout(()=>W(!1),200);return()=>clearTimeout(e)},[U,b]);let ce=p.size>0?Array.from(p.entries()):[];return(0,q.jsxs)(rT,{className:`flex h-full flex-col bg-white relative`,style:{"--thread-max-width":`44rem`},children:[(0,q.jsx)(CT,{turnAnchor:`top`,className:D?`hidden`:`relative flex-1 overflow-x-auto overflow-y-scroll scroll-smooth`,children:(0,q.jsxs)(`div`,{ref:O,className:`mx-auto flex w-full min-h-full flex-col px-2 md:px-3 pt-3 md:pt-4`,children:[h&&(0,q.jsx)(jF,{}),L&&(0,q.jsx)(`div`,{className:`flex justify-center pb-2`,children:(0,q.jsx)(`button`,{type:`button`,onClick:B,className:`rounded-full border border-gray-200 bg-white px-4 py-1.5 text-xs text-gray-500 hover:text-gray-700 hover:border-gray-300 shadow-sm transition-colors`,children:v?`Collapse earlier messages`:`View earlier messages`})}),U&&(0,q.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,q.jsx)(`span`,{className:`inline-block h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-gray-500`})}),(s??[]).length>1&&(0,q.jsx)(`div`,{className:`flex flex-col gap-1 pb-2`,children:(s??[]).slice(1).map(e=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,q.jsx)(`div`,{className:`flex-1 h-px bg-gray-200`}),(0,q.jsxs)(`span`,{className:`text-gray-600`,children:[(0,q.jsx)(`span`,{className:`text-amber-600`,children:`▸`}),` `,`driving by `,(0,q.jsx)(`span`,{className:`text-gray-900 font-medium`,children:e.driver}),` since `,new Date(e.since).toLocaleString()]}),(0,q.jsx)(`div`,{className:`flex-1 h-px bg-gray-200`})]},e.since))}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-2 pb-1`,children:[(0,q.jsx)(bS,{children:({message:e})=>e.role===`user`?(0,q.jsx)(PA,{}):(0,q.jsx)(oF,{})}),(0,q.jsx)(`div`,{ref:ie}),ce.length>0&&(0,q.jsx)(nF,{name:`QuestionsPanel`,children:(0,q.jsx)(`div`,{className:`space-y-3 w-full pt-2`,children:ce.map(([e,t])=>Array.isArray(t)&&t.length>0?(0,q.jsx)(`div`,{className:`rounded-lg border border-violet-100 bg-violet-50/30 p-4 shadow-sm`,children:(0,q.jsx)(AF,{questions:t,toolUseId:e,onAnswers:m,onDismiss:e=>m(e,{})})},e):null)})})]})]})}),(0,q.jsx)(`div`,{className:D?`flex-1 flex items-center justify-center px-2 md:px-3 pb-3 md:pb-6`:`shrink-0 z-10 bg-gradient-to-t from-white via-white to-transparent px-2 md:px-3 pt-1 md:pt-2 pb-3 md:pb-6`,children:(0,q.jsxs)(`div`,{className:D?`w-full max-w-[36rem]`:``,children:[D&&(0,q.jsxs)(`div`,{className:`mb-4 space-y-2 px-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[a&&(0,q.jsx)(`h1`,{className:`text-xl font-semibold text-gray-800`,children:a}),o&&(0,q.jsxs)(`span`,{className:`text-xs text-gray-400`,children:[`driver: `,o]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-400`,children:[r&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,q.jsx)(xe,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,q.jsxs)(`span`,{className:`font-mono truncate`,children:[r,i?(0,q.jsxs)(`span`,{className:`text-gray-300`,children:[` · `,i]}):``]})]}),(0,q.jsx)(`span`,{className:`ml-auto flex gap-0.5`,children:[{label:`Normal`,tokens:null,mode:`normal`},{label:`Think`,tokens:16e3,mode:`think`},{label:`Hard`,tokens:32e3,mode:`hard`},{label:`Ultrathink`,tokens:null,mode:`ultra`}].map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>{E(e.mode===`normal`?`normal`:e.mode===`ultra`?`ultra`:`normal`),C(e.tokens)},className:`px-1.5 py-0.5 text-[11px] rounded transition-colors `+((e.mode===`normal`?S===null&&T===`normal`:e.mode===`ultra`?S===null&&T===`ultra`:S===e.tokens)?`bg-gray-200 text-gray-700 font-medium`:`text-gray-400 hover:text-gray-600 hover:bg-gray-100`),children:e.label},e.label))})]})]}),e?(0,q.jsxs)(`div`,{className:`mx-3 md:mx-5 mb-3 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 flex items-center gap-2 text-[12px] text-amber-800`,children:[(0,q.jsx)(`span`,{children:`📦`}),(0,q.jsx)(`span`,{className:`flex-1`,children:`This loop is archived (read-only).`}),t&&(0,q.jsx)(`button`,{type:`button`,onClick:t,className:`rounded border border-amber-300 bg-white px-2 py-0.5 text-[11px] font-medium text-amber-900 hover:bg-amber-100`,children:`Unarchive`})]}):c?(0,q.jsxs)(`div`,{className:`mx-3 md:mx-5 mb-3 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 flex items-center gap-2 text-[12px] text-amber-800`,children:[(0,q.jsx)(`span`,{children:`✋`}),(0,q.jsxs)(`span`,{className:`flex-1`,children:[`Released for drive`,l?` by ${l}`:``,` — no one can write until someone takes over.`]}),u&&(0,q.jsx)(`button`,{type:`button`,onClick:u,className:`rounded bg-amber-500 px-2 py-0.5 text-[11px] font-medium text-white hover:bg-amber-600`,children:`Drive`})]}):n?null:(0,q.jsx)(kF,{pickedFile:d,editorSelection:f})]})}),A&&(0,q.jsx)(`button`,{type:`button`,onClick:N,className:`absolute bottom-40 right-4 z-20 flex h-7 w-7 items-center justify-center rounded-full bg-white border border-gray-200 shadow-sm text-gray-400 hover:text-gray-600 hover:border-gray-300 transition-all`,"aria-label":`Scroll to bottom`,children:(0,q.jsx)(M,{className:`h-3.5 w-3.5`})})]})}function IF(){let{id:e}=Yn(),[t,n]=(0,w.useState)(null);return(0,w.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{let r=await Sm(e);t||n(r??`unauthorized`)})(),()=>{t=!0}},[e]),(0,w.useEffect)(()=>{t&&typeof t==`object`&&(document.title=`${t.title} · shared`)},[t]),e?t===null?(0,q.jsx)(RF,{}):t===`unauthorized`?(0,q.jsx)(zF,{reason:`this loop is private or does not exist`}):(0,q.jsx)(LF,{meta:t}):(0,q.jsx)(zF,{reason:`missing loop id`})}function LF({meta:e}){let{runtime:t,connected:n,reconnecting:r,extra:i}=NP(e.id,``);return(0,q.jsxs)(`div`,{className:`h-full w-full flex flex-col bg-white text-gray-900`,children:[(0,q.jsxs)(`header`,{className:`h-12 shrink-0 border-b border-gray-200 bg-white flex items-center px-3 md:px-5 gap-2`,children:[(0,q.jsx)(`span`,{className:`text-lg leading-none`,children:`🧶`}),(0,q.jsx)(`span`,{className:`text-[14px] font-medium text-gray-900 truncate`,children:e.title}),(0,q.jsx)(`span`,{className:`text-[11px] px-1.5 py-0.5 rounded bg-emerald-50 text-emerald-800 border border-emerald-200`,children:`view only`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`span`,{className:`text-[11px] `+(n?`text-emerald-600`:r?`text-amber-500`:`text-red-500`),title:n?`connected`:r?`reconnecting…`:`disconnected`,children:`●`})]}),(0,q.jsx)(`main`,{className:`flex-1 min-h-0`,children:(0,q.jsx)(MP,{extra:i,children:(0,q.jsx)(SC,{runtime:t,children:(0,q.jsx)(FF,{readOnly:!0})})})})]})}function RF(){return(0,q.jsx)(`div`,{className:`h-full w-full flex items-center justify-center text-gray-400 text-sm`,children:`loading…`})}function zF({reason:e}){return(0,q.jsxs)(`div`,{className:`h-full w-full flex flex-col items-center justify-center text-gray-500 gap-2 px-4 text-center`,children:[(0,q.jsx)(`span`,{className:`text-lg`,children:`🧶`}),(0,q.jsx)(`div`,{className:`text-sm`,children:`Loop unavailable`}),(0,q.jsx)(`div`,{className:`text-xs text-gray-400`,children:e})]})}function BF(e){let[t,n]=(0,w.useState)({}),r=(0,w.useRef)(null);return(0,w.useEffect)(()=>{if(e.length===0)return;let t=location.protocol===`https:`?`wss:`:`ws:`,i=new WebSocket(`${t}//${location.host}/ws/loop-status`);return r.current=i,i.onopen=()=>{i.send(JSON.stringify({type:`subscribe`,ids:e}))},i.onmessage=e=>{try{let t=JSON.parse(e.data);(t.type===`init`||t.type===`update`)&&n(e=>({...e,...t.data}))}catch{}},()=>{i&&(i.readyState===WebSocket.CONNECTING?(i.onopen=()=>i.close(),i.onmessage=null,i.onclose=null,i.onerror=null):(i.onclose=null,i.onerror=null,i.close())),r.current=null}},[e.join(`,`)]),t}var VF=`loopat:tree:expanded:`;function HF(e){try{let t=localStorage.getItem(VF+e);return t?new Set(JSON.parse(t)):new Set}catch{return new Set}}function UF(e,t){try{localStorage.setItem(VF+e,JSON.stringify([...t]))}catch{}}function WF({treeId:e,entries:t,onPick:n,picked:r,onLoadChildren:i,getContextActions:a,onAction:o,depthOffset:s=0,renderNode:c,nodeClassName:l,reloadKey:u}){return(0,q.jsx)(q.Fragment,{children:t.map(t=>(0,q.jsx)(GF,{treeId:e,entry:t,depth:s,onPick:n,picked:r,onLoadChildren:i,getContextActions:a,onAction:o,renderNode:c,nodeClassName:l,reloadKey:u},t.path))})}function GF({treeId:e,entry:t,depth:n,onPick:r,picked:i,onLoadChildren:a,getContextActions:o,onAction:s,renderNode:c,nodeClassName:l,reloadKey:u}){let[d,f]=(0,w.useState)(()=>HF(e).has(t.path)),[p,m]=(0,w.useState)(null),[h,g]=(0,w.useState)(!1),[_,v]=(0,w.useState)(null),y=(0,w.useCallback)(()=>{let n=HF(e);n.has(t.path)?n.delete(t.path):n.add(t.path),UF(e,n),f(e=>!e)},[e,t.path]),b=(0,w.useRef)(u);(0,w.useEffect)(()=>{b.current!==u&&(m(null),b.current=u)},[u]),(0,w.useEffect)(()=>{!d||p!==null||t.type===`dir`&&(g(!0),a(t.path).then(m).finally(()=>g(!1)))},[d,t.path,a,p]);let x=e=>{e.preventDefault(),e.stopPropagation(),v({x:e.clientX,y:e.clientY})},S=8+n*12;if(t.type===`dir`)return c?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{onContextMenu:x,children:c(t,n,d,y)}),d&&p&&(0,q.jsx)(q.Fragment,{children:p.map(t=>(0,q.jsx)(GF,{treeId:e,entry:t,depth:n+1,onPick:r,picked:i,onLoadChildren:a,getContextActions:o,onAction:s,renderNode:c,nodeClassName:l,reloadKey:u},t.path))}),_&&(0,q.jsx)(KF,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{onContextMenu:x,children:(0,q.jsxs)(`button`,{type:`button`,onClick:y,className:l?l(t,n,d,!1):`w-full py-1 flex items-center gap-1.5 hover:bg-gray-50 text-left group`,style:{paddingLeft:S,paddingRight:8},children:[(0,q.jsx)(`span`,{className:`text-gray-500 w-3`,children:d?`▾`:`▸`}),(0,q.jsx)(`span`,{className:`text-gray-500`,children:d?(0,q.jsx)(ve,{size:13}):(0,q.jsx)(be,{size:13})}),(0,q.jsx)(`span`,{className:`text-[13px] text-gray-900 truncate`,children:t.name})]})}),h&&(0,q.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,style:{paddingLeft:S+12},children:`...`}),d&&p&&(0,q.jsxs)(q.Fragment,{children:[p.map(t=>(0,q.jsx)(GF,{treeId:e,entry:t,depth:n+1,onPick:r,picked:i,onLoadChildren:a,getContextActions:o,onAction:s,renderNode:c,nodeClassName:l,reloadKey:u},t.path)),p.length===0&&(0,q.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-1`,style:{paddingLeft:S+12},children:`(empty)`})]}),_&&(0,q.jsx)(KF,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]});let C=i===t.path;return c?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{onContextMenu:x,onClick:()=>r(t.path),children:c(t,n,!1,()=>{})}),_&&(0,q.jsx)(KF,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]}):(0,q.jsx)(q.Fragment,{children:(0,q.jsxs)(`div`,{className:`relative`,onContextMenu:x,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>r(t.path),className:l?l(t,n,!1,C):`w-full py-1 flex items-center gap-2 text-left `+(C?`bg-gray-100`:`hover:bg-gray-50`),style:{paddingLeft:S,paddingRight:8},children:[(0,q.jsx)(`span`,{className:`w-3 text-gray-400`,children:(0,q.jsx)(he,{size:13})}),(0,q.jsx)(`span`,{className:`text-[13px] text-gray-900 flex-1 min-w-0 truncate`,children:t.name})]}),_&&(0,q.jsx)(KF,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]})})}function KF({x:e,y:t,items:n,onAction:r,onClose:i}){return(0,w.useEffect)(()=>{let e=e=>{e.target?.closest(`[data-context-menu]`)||i()},t=e=>{e.key===`Escape`&&i()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]),(0,_t.createPortal)((0,q.jsx)(`div`,{"data-context-menu":!0,className:`fixed z-[9999] bg-white border border-gray-200 rounded-lg shadow-lg py-1 text-[12px] min-w-[140px]`,style:{left:e,top:t},onContextMenu:e=>e.preventDefault(),children:n.map(e=>(0,q.jsxs)(`button`,{onClick:()=>{r(e.action),i()},className:`w-full px-3 py-1.5 flex items-center gap-2 text-left hover:bg-gray-50 `+(e.danger?`text-red-600 hover:bg-red-50`:`text-gray-700`),children:[e.icon,e.label]},e.action))}),document.body)}var qF=[{name:`context`,section:`context`,emoji:`🧷`,hint:`knowledge / notes / personal`},{name:`workdir`,section:`workdir`,emoji:`▣`}];function JF({loopId:e,onPick:t,picked:n}){let[r,i]=(0,w.useState)(0),a=(0,w.useRef)(null),[o,s]=(0,w.useState)(``),[c,l]=(0,w.useState)(null),[u,d]=(0,w.useState)(``),f=(0,w.useCallback)(e=>{s(e??`workdir`),a.current?.click()},[]),p=async t=>{let n=t.target.files?.[0];if(!n)return;let r=await Am(e,n);r.ok||alert(`upload failed: ${r.error}`),i(e=>e+1),a.current&&(a.current.value=``),s(``)},m=async()=>{if(!c||!u.trim()){l(null);return}let t=c.path+`/`+u.trim(),n=!1;if(n=c.type===`file`?await Dm(e,t,``):await km(e,t),!n){alert(`create failed`),l(null);return}l(null),d(``),i(e=>e+1)},h=(0,w.useCallback)((t,n)=>{if(t===`upload`)f(n.path);else if(t===`new-file`||t===`new-folder`)l({type:t===`new-file`?`file`:`folder`,path:n.path}),d(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Om(e,n.path).then(e=>{if(!e){alert(`delete failed`);return}i(e=>e+1)})}},[f,e]),g=(0,w.useCallback)(e=>e.type===`dir`?[{label:`Upload here`,icon:(0,q.jsx)(dt,{size:12}),action:`upload`},{label:`New file`,icon:(0,q.jsx)(pe,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,q.jsx)(ye,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,q.jsx)(st,{size:12}),action:`delete`,danger:!0}]:[{label:`View`,icon:(0,q.jsx)(ue,{size:12}),action:`view`},{label:`Delete`,icon:(0,q.jsx)(st,{size:12}),action:`delete`,danger:!0}],[]);return(0,w.useCallback)(t=>wm(e,t).then(e=>e),[e]),(0,q.jsxs)(`aside`,{className:`flex-1 min-h-0 overflow-auto py-2 text-[13px]`,children:[(0,q.jsx)(`input`,{ref:a,type:`file`,className:`hidden`,onChange:p}),qF.map(a=>(0,q.jsx)(YF,{loopId:e,name:a.name,section:a.section,emoji:a.emoji,hint:a.hint,onPick:t,picked:n,onUpload:()=>f(a.name),onReload:()=>i(e=>e+1),reloadKey:r,getContextActions:g,onAction:h,treeId:`loop-${e}`},a.name+r)),c&&(0,q.jsx)(XF,{depth:1,type:c.type,value:u,onChange:d,onSubmit:m,onCancel:()=>l(null)})]})}function YF({loopId:e,name:t,section:n,emoji:r,hint:i,onPick:a,picked:o,onUpload:s,onReload:c,reloadKey:l,getContextActions:u,onAction:d,treeId:f}){let[p,m]=(0,w.useState)(!0),h=n===`context`?`w-full py-1.5 flex items-center gap-1.5 bg-cyan-50/50 hover:bg-cyan-50 text-left border-y border-cyan-100/70`:`w-full py-1.5 flex items-center gap-1.5 bg-emerald-50/40 hover:bg-emerald-50 text-left border-y border-emerald-100/70`,g=(0,w.useCallback)(t=>wm(e,t).then(e=>e),[e]);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:h,style:{paddingLeft:`0.5rem`,paddingRight:`0.5rem`},children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:p?`▾`:`▸`}),(0,q.jsx)(`span`,{className:`text-[12px]`,children:r}),(0,q.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider font-semibold text-gray-700`,children:t}),i&&(0,q.jsx)(`span`,{className:`text-[10px] text-gray-500 italic ml-1`,children:i}),n===`workdir`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`span`,{onClick:e=>{e.stopPropagation(),s()},className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-emerald-100/50 flex items-center gap-0.5`,title:`upload file`,children:(0,q.jsx)(dt,{size:12})})]})]}),p&&(0,q.jsx)(WF,{treeId:`${f}-${t}`,entries:[{name:t,path:t,type:`dir`}],onPick:a,picked:o,onLoadChildren:g,getContextActions:u,onAction:d,depthOffset:1,reloadKey:l})]})}function XF({depth:e,type:t,value:n,onChange:r,onSubmit:i,onCancel:a}){let o=(0,w.useRef)(null);return(0,w.useEffect)(()=>{o.current?.focus()},[]),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 py-0.5`,style:{paddingLeft:8+e*12},children:[(0,q.jsx)(`span`,{className:`text-gray-400`,children:t===`file`?`📄`:`📁`}),(0,q.jsx)(`input`,{ref:o,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&i(),e.key===`Escape`&&a()},placeholder:t===`file`?`filename.txt`:`folder-name`,className:`flex-1 px-1.5 py-0.5 text-[12px] border border-gray-300 rounded outline-none focus:border-gray-900`}),(0,q.jsx)(`button`,{onClick:i,className:`text-[10px] text-emerald-600 hover:text-emerald-800 px-1`,children:`✓`}),(0,q.jsx)(`button`,{onClick:a,className:`text-[10px] text-gray-400 hover:text-gray-600 px-1`,children:`✕`})]})}function ZF(e){let t=e.split(`
|
|
90
|
-
`),n=``,r=[],i=null,a=0,o=0;for(let e of t){if(e.startsWith(`diff `)){n=e;continue}if(e.startsWith(`+++ `)||e.startsWith(`--- `))continue;let t=e.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/);if(t){i&&r.push(i),a=parseInt(t[1],10),o=parseInt(t[3],10),i={header:e,lines:[]};continue}i&&(e.startsWith(`+`)?(i.lines.push({type:`add`,oldNum:null,newNum:o,text:e.slice(1)}),o++):e.startsWith(`-`)?(i.lines.push({type:`del`,oldNum:a,newNum:null,text:e.slice(1)}),a++):(i.lines.push({type:`ctx`,oldNum:a,newNum:o,text:e.startsWith(` `)?e.slice(1):e}),a++,o++))}return i&&r.push(i),{fileHeader:n,hunks:r}}function QF({filePath:e,diff:t,loading:n,onClose:r}){let i=null;if(t)try{i=ZF(t)}catch{}return(0,q.jsx)(Fg,{open:!0,onOpenChange:e=>{e||r()},children:(0,q.jsxs)(Rg,{className:`sm:max-w-4xl max-h-[85vh] flex flex-col bg-white p-0 gap-0`,showCloseButton:!1,children:[(0,q.jsxs)(`div`,{className:`px-4 py-2.5 border-b border-gray-200 shrink-0 flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-mono text-gray-900 truncate flex-1`,children:e}),(0,q.jsx)(`button`,{onClick:r,className:`text-gray-400 hover:text-gray-700 text-sm leading-none`,children:`✕`})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:n?(0,q.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-gray-400 gap-2`,children:[(0,q.jsx)(Ae,{className:`animate-spin`,size:16}),(0,q.jsx)(`span`,{className:`text-sm`,children:`loading diff...`})]}):i?(0,q.jsx)(`div`,{className:`text-xs font-mono leading-5`,children:i.hunks.map((e,t)=>(0,q.jsxs)(`div`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,q.jsx)(`div`,{className:`px-4 py-1 bg-blue-50/60 text-blue-700 border-b border-blue-100 sticky top-0`,children:e.header}),e.lines.map((e,t)=>{let n=e.type===`add`,r=e.type===`del`;return(0,q.jsxs)(`div`,{className:`flex `+(n?`bg-emerald-50`:r?`bg-red-50`:``),children:[(0,q.jsx)(`span`,{className:`w-14 shrink-0 text-right pr-3 py-px text-gray-300 select-none border-r border-gray-200 bg-gray-50`,children:e.oldNum??``}),(0,q.jsx)(`span`,{className:`w-14 shrink-0 text-right pr-3 py-px select-none border-r border-gray-200 `+(n?`bg-emerald-100/70 text-emerald-700`:r?`bg-red-100/70 text-red-500`:`text-gray-300 bg-gray-50`),children:e.newNum??``}),(0,q.jsxs)(`span`,{className:`pl-3 py-px whitespace-pre-wrap break-all flex-1 `+(n?`text-emerald-800`:r?`text-red-700`:`text-gray-700`),children:[(0,q.jsx)(`span`,{className:`select-none`,children:n?`+`:r?`−`:` `}),e.text]})]},t)})]},t))}):(0,q.jsx)(`div`,{className:`py-16 text-center text-sm text-gray-400`,children:`empty diff`})})]})})}var $F={A:{label:`A`,color:`text-emerald-600`},M:{label:`M`,color:`text-amber-600`},D:{label:`D`,color:`text-red-600`},R:{label:`R`,color:`text-purple-600`},"?":{label:`?`,color:`text-gray-400`}};function eI({loopId:e,onClose:t,onPickFile:n}){let[r,i]=(0,w.useState)(null),[a,o]=(0,w.useState)(!1),[s,c]=(0,w.useState)(!0),[l,u]=(0,w.useState)(!0),[d,f]=(0,w.useState)(null),[p,m]=(0,w.useState)(``),[h,g]=(0,w.useState)(``),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(null),[x,S]=(0,w.useState)([]),[C,T]=(0,w.useState)(!1),[E,D]=(0,w.useState)(!0),O=(0,w.useCallback)(async()=>{o(!0),f(null);try{i(await wh(e))}catch{f(`Failed to load git status`)}finally{o(!1)}},[e]),k=(0,w.useCallback)(async()=>{T(!0);try{S(await kh(e,50))}catch{}finally{T(!1)}},[e]);(0,w.useEffect)(()=>{O(),k()},[O,k]);let A=async()=>{r?.unstaged.length&&await Eh(e,r.unstaged.map(e=>e.path))&&O()},j=async()=>{r?.staged.length&&await Eh(e,r.staged.map(e=>e.path),!0)&&O()},M=async t=>{await Eh(e,[t])&&O()},N=async t=>{await Eh(e,[t],!0)&&O()},P=async t=>{await Dh(e,t)&&O()},F=async()=>{if(!h.trim())return;v(!0),b(null);let t=await Oh(e,h.trim());v(!1),t.ok?(g(``),O(),k()):b(t.error??`Commit failed`)},I=p.trim().toLowerCase(),L=r?r.unstaged.filter(e=>!I||e.path.toLowerCase().includes(I)):[],R=r?r.staged.filter(e=>!I||e.path.toLowerCase().includes(I)):[],z=!r||r.unstaged.length===0&&r.staged.length===0;return(0,q.jsxs)(`aside`,{className:`w-full h-full min-w-0 bg-white flex flex-col`,children:[(0,q.jsxs)(`header`,{className:`px-3 h-8 shrink-0 border-b border-gray-200 flex items-center gap-1 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{className:`tracking-wide`,children:`Git Changes`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>{O(),k()},className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,title:`refresh`,children:(0,q.jsx)(qe,{size:13,className:a||C?`animate-spin`:``})}),(0,q.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:t,title:`close`,children:`✕`})]}),(0,q.jsxs)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:[(0,q.jsx)(`textarea`,{placeholder:`Commit message...`,value:h,onChange:e=>{g(e.target.value),b(null)},rows:2,className:`w-full px-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300 resize-none mb-1.5`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`button`,{onClick:F,disabled:_||!h.trim(),className:`flex-1 flex items-center justify-center gap-1 px-2 py-1 text-[11px] rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:[(0,q.jsx)(Se,{size:12}),_?`Committing...`:`Commit`]}),r&&r.staged.length>0&&(0,q.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[r.staged.length,` staged`]})]}),y&&(0,q.jsx)(`div`,{className:`mt-1 text-[10px] text-red-500`,children:y})]}),(0,q.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:(0,q.jsx)(`input`,{type:`text`,placeholder:`Filter files...`,value:p,onChange:e=>m(e.target.value),className:`w-full px-2 py-1 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300`})}),(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto text-[13px]`,children:[(0,q.jsxs)(`div`,{className:`overflow-auto py-2`,children:[a&&!r&&(0,q.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`loading git status...`}),d&&(0,q.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-red-500`,children:d}),z&&!a&&(0,q.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`no changes`}),L.length>0&&(0,q.jsx)(nI,{title:`Unstaged Changes`,count:L.length,open:s,onToggle:()=>c(e=>!e),bulkAction:{label:`Stage all`,icon:(0,q.jsx)(We,{size:12}),onClick:A},children:L.map(t=>(0,q.jsx)(rI,{file:t,loopId:e,staged:!1,onStage:()=>M(t.path),onUnstage:()=>N(t.path),onDiscard:()=>P(t.path),onEdit:e=>n(e),onRefresh:O},t.path))}),R.length>0&&(0,q.jsx)(nI,{title:`Staged Changes`,count:R.length,open:l,onToggle:()=>u(e=>!e),bulkAction:{label:`Unstage all`,icon:(0,q.jsx)(Ie,{size:12}),onClick:j},children:R.map(t=>(0,q.jsx)(rI,{file:t,loopId:e,staged:!0,onStage:()=>M(t.path),onUnstage:()=>N(t.path),onDiscard:()=>P(t.path),onEdit:e=>n(e),onRefresh:O},t.path))})]}),(0,q.jsxs)(`div`,{className:`border-t border-gray-200`,children:[(0,q.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>D(e=>!e),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&D(e=>!e)},className:`w-full px-3 py-1.5 flex items-center gap-1.5 hover:bg-gray-50 text-left cursor-pointer select-none`,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:E?`▾`:`▸`}),(0,q.jsx)(xe,{size:12,className:`text-gray-500`}),(0,q.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:`History`}),(0,q.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,x.length,`)`]})]}),E&&(0,q.jsx)(`div`,{className:`px-2 pb-2 max-h-64 overflow-auto`,children:C?(0,q.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`loading history...`}):x.length===0?(0,q.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`no commits`}):(0,q.jsx)(tI,{commits:x})})]})]})]})}function tI({commits:e}){let t=[`bg-blue-500`,`bg-emerald-500`,`bg-purple-500`,`bg-amber-500`,`bg-pink-500`,`bg-cyan-500`],n=new Map,r=0,i=e=>(n.has(e)||(n.set(e,t[r%t.length]),r++),n.get(e));return(0,q.jsx)(`div`,{className:`space-y-0`,children:e.map((t,n)=>{let r=t.branch??t.branches[0]??null,a=r?i(r):`bg-gray-400`,o=n===0,s=new Date(t.date).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),c=new Date(t.date).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`});return(0,q.jsxs)(`div`,{className:`group/graph-row flex items-start gap-2 py-0.5 px-1.5 rounded hover:bg-gray-100 cursor-default text-[11px]`,title:`${t.subject}\n${t.author} · ${s} ${c}`,children:[(0,q.jsxs)(`div`,{className:`flex flex-col items-center shrink-0`,children:[(0,q.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${a} ring-2 ring-white ${o?`ring-blue-300`:``}`}),n<e.length-1&&(0,q.jsx)(`div`,{className:`w-0.5 h-10 ${a} opacity-10`})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400 truncate`,children:t.shortHash}),o&&(0,q.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-blue-100 text-blue-700 font-medium`,children:`HEAD`}),t.branches.slice(0,2).map(e=>(0,q.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-emerald-100 text-emerald-700 font-medium truncate max-w-[60px]`,children:e},e)),t.tags.map(e=>(0,q.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-purple-100 text-purple-700 font-medium`,children:e},e))]}),(0,q.jsx)(`div`,{className:`text-gray-700 truncate`,children:t.subject}),(0,q.jsxs)(`div`,{className:`text-gray-400 text-[10px]`,children:[t.author,` · `,s]})]})]},t.hash)})})}function nI({title:e,count:t,open:n,onToggle:r,bulkAction:i,children:a}){return(0,q.jsxs)(`div`,{className:`mb-2`,children:[(0,q.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:r,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&r()},className:`w-full px-3 py-1.5 flex items-center gap-1.5 hover:bg-gray-50 text-left group/section cursor-pointer select-none`,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:n?`▾`:`▸`}),(0,q.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:e}),(0,q.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,t,`)`]}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i.onClick()},className:`opacity-100 sm:opacity-0 sm:group-hover/section:opacity-100 transition-opacity px-1 py-0.5 rounded hover:bg-gray-200 text-gray-500 hover:text-gray-900 flex items-center gap-0.5`,title:i.label,children:i.icon})]}),n&&(0,q.jsx)(`div`,{children:a})]})}function rI({file:e,loopId:t,staged:n,onStage:r,onUnstage:i,onDiscard:a,onEdit:o,onRefresh:s}){let[c,l]=(0,w.useState)(!1),[u,d]=(0,w.useState)(null),[f,p]=(0,w.useState)(!1),[m,h]=(0,w.useState)(!1),[g,_]=(0,w.useState)(null),v=(0,w.useRef)(null);(0,w.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&_(null)};if(g)return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let y=async()=>{e.isBinary||(l(!0),u===null&&(p(!0),d(await Th(t,e.path,n)??``),p(!1)))},b=e=>{e.preventDefault(),_({x:e.clientX,y:e.clientY})},x=`workdir/${e.path}`,S=[{label:`Open in Editor`,icon:(0,q.jsx)(Ue,{size:12}),onClick:()=>{o(x),_(null)}},{label:`View Diff`,icon:(0,q.jsx)(Ye,{size:12}),onClick:()=>{y(),_(null)}},{separator:!0,label:``,onClick:()=>{}},n?{label:`Unstage`,icon:(0,q.jsx)(Ie,{size:12}),onClick:()=>{i(),_(null)}}:{label:`Stage`,icon:(0,q.jsx)(We,{size:12}),onClick:()=>{r(),_(null)}},!n&&{label:`Discard Changes`,icon:(0,q.jsx)(lt,{size:12}),onClick:()=>{h(!0),_(null)},danger:!0}].filter(Boolean),C=$F[e.status]??{label:e.status,color:`text-gray-500`},T=e.path.lastIndexOf(`/`),E=T>=0?e.path.slice(T+1):e.path,D=T>=0?e.path.slice(0,T+1):null;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`group/row relative flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50`,onContextMenu:b,children:[(0,q.jsx)(`span`,{className:`w-5 text-center text-[11px] font-mono font-semibold ${C.color}`,children:C.label}),(0,q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] font-mono`,children:[(0,q.jsx)(`span`,{className:`text-gray-900`,children:E}),D&&(0,q.jsx)(`span`,{className:`text-gray-400 ml-0.5`,children:D})]}),!e.isBinary&&(e.additions>0||e.deletions>0)&&(0,q.jsxs)(`span`,{className:`text-[11px] font-mono flex items-center gap-0.5 shrink-0`,children:[(0,q.jsxs)(`span`,{className:`text-emerald-600`,children:[`+`,e.additions]}),(0,q.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]}),(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 opacity-100 sm:opacity-0 sm:group-hover/row:opacity-100 transition-opacity shrink-0`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>o(x),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-blue-600 rounded`,title:`edit file`,children:(0,q.jsx)(Ue,{size:13})}),n&&(0,q.jsx)(`button`,{type:`button`,onClick:y,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-gray-700 rounded`,title:`view diff`,disabled:e.isBinary,children:(0,q.jsx)(Ye,{size:13})}),n?(0,q.jsx)(`button`,{type:`button`,onClick:i,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-amber-600 rounded`,title:`unstage`,children:(0,q.jsx)(Ie,{size:13})}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>h(!0),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-red-500 rounded`,title:`discard changes`,children:(0,q.jsx)(lt,{size:13})}),(0,q.jsx)(`button`,{type:`button`,onClick:r,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-emerald-600 rounded`,title:`stage`,children:(0,q.jsx)(We,{size:13})})]})]})]}),g&&(0,q.jsx)(`div`,{ref:v,className:`fixed z-50 min-w-[160px] py-1 bg-white border border-gray-200 rounded-md shadow-lg text-[12px]`,style:{left:g.x,top:g.y},children:S.map((e,t)=>e.separator?(0,q.jsx)(`div`,{className:`my-1 border-t border-gray-100`},t):(0,q.jsxs)(`button`,{onClick:e.onClick,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-gray-100 ${e.danger?`text-red-600`:`text-gray-700`}`,children:[e.icon,(0,q.jsx)(`span`,{children:e.label})]},t))}),c&&(0,q.jsx)(QF,{filePath:e.path,diff:u,loading:f,onClose:()=>l(!1)}),m&&(0,q.jsx)(Fg,{open:!0,onOpenChange:e=>{e||h(!1)},children:(0,q.jsxs)(Rg,{className:`sm:max-w-sm bg-white p-5 gap-4`,showCloseButton:!1,children:[(0,q.jsx)(zg,{children:(0,q.jsx)(Bg,{className:`text-sm`,children:`Discard changes`})}),(0,q.jsx)(`p`,{className:`text-[13px] text-gray-600 break-all font-mono`,children:e.path}),(0,q.jsx)(`p`,{className:`text-[12px] text-gray-500`,children:e.status===`?`?`This file is untracked and will be deleted.`:`This will permanently discard all changes to this file. This action cannot be undone.`}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,q.jsx)(`button`,{onClick:()=>h(!1),className:`px-3 py-1.5 text-xs rounded bg-gray-100 text-gray-700 hover:bg-gray-200`,children:`Cancel`}),(0,q.jsx)(`button`,{onClick:()=>{h(!1),a()},className:`px-3 py-1.5 text-xs rounded bg-red-600 text-white hover:bg-red-700`,children:`Discard`})]})]})})]})}function iI(e){return e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:`standard`}function aI({loop:e,open:t,onClose:n,onSaved:r}){let[i,a]=(0,w.useState)(null),[o,s]=(0,w.useState)(e.shareEnabled??!1),[c,l]=(0,w.useState)(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),[u,d]=(0,w.useState)(e.shareAlias??``),[f,p]=(0,w.useState)(e.sharePort??3e3),[m,h]=(0,w.useState)(e.shareExternalPort??1e4),[g,_]=(0,w.useState)(e.shareProtocol??`tcp`),[v,y]=(0,w.useState)(null),[b,x]=(0,w.useState)(``),[S,C]=(0,w.useState)(!1),[T,E]=(0,w.useState)(!1),[D,O]=(0,w.useState)(!1),[k,A]=(0,w.useState)(``),[j,M]=(0,w.useState)(!1),[N,P]=(0,w.useState)(``),[F,I]=(0,w.useState)(``),[L,R]=(0,w.useState)(iI(e)),[z,B]=(0,w.useState)(null),H=e.id.slice(0,8),U=!!(i&&i.serveEnabled),W=!!(i&&i.serveDynamicEnabled),ee=!!(i&&i.serveEphemeralEnabled),K=[U,W,ee].filter(Boolean).length>1,te=U&&!W&&!ee,ne=!U&&W&&!ee,re=!U&&!W&ⅇ(0,w.useEffect)(()=>{t&&(Uh().then(a),s(e.shareEnabled??!1),l(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),d(e.shareAlias??``),p(e.sharePort??3e3),h(e.shareExternalPort??1e4),_(e.shareProtocol??`tcp`),R(iI(e)),y(null),x(``),A(``),B(null))},[t,e]),(0,w.useEffect)(()=>{if(!t||!(re||K&&L===`ephemeral`)||!e.shareEnabled||e.shareMode!==`ephemeral`)return;let n=!1,r=async()=>{let t=await Wh(e.id);n||B(t.port)};r();let i=setInterval(r,3e3);return()=>{n=!0,clearInterval(i)}},[t,L,re,K,e.id,e.shareEnabled,e.shareMode]),(0,w.useEffect)(()=>{!t||!i||i.serveDynamicEnabled&&(e.shareEnabled&&e.shareExternalPort||!e.shareEnabled&&!e.shareExternalPort&&Kh().then(e=>{e.port&&h(e.port)}))},[t,i,e.shareEnabled,e.shareExternalPort]),(0,w.useEffect)(()=>{t&&Jh(H,e.id).then(e=>{e.available?O(!1):(O(!0),x(`ID "${H}" is already in use. Please set an alias.`))})},[t,H,e.id]),(0,w.useEffect)(()=>{if(!u||!t){y(null),x(``);return}let n=setTimeout(async()=>{let t=await Jh(u,e.id);y(t.available),x(t.reason??``)},300);return()=>clearTimeout(n)},[u,t,e.id]);let ae=u||H,oe=i?.https?`https`:`http`,se=i?.withPort?`:${i.displayPort}`:``,ce=i?`${oe}://${ae}${i.baseUrl}${se}`:``,le=i?.serveDynamicDomain||i?.ip||`<host-ip>`,ue=g===`static`?`http://${le}:${m}`:`tcp://${le}:${m}`,de=i?.serveEphemeralDomain||i?.ip||`<host-ip>`,fe=z?`${g===`udp`?`udp`:`tcp`}://${de}:${z}`:`(no active port — save & wait for container restart)`,pe=ne||K&&L===`direct`&&W&&!re,me=re||K&&L===`ephemeral`,he=me?fe:pe?ue:ce;(0,w.useEffect)(()=>{if(!t||!pe)return;let n=setTimeout(async()=>{M(!0);let t=await qh(m,e.id);M(!1),t.available?A(``):A(t.reason??`Port unavailable`)},400);return()=>clearTimeout(n)},[m,t,c,e.id]);let ge=async()=>{if(E(!0),pe){let t=await qh(m,e.id);if(!t.available){A(t.reason??`Port unavailable`),E(!1);return}}let t={shareEnabled:o};o?me?(t.shareMode=`ephemeral`,t.sharePort=f,t.shareProtocol=g===`static`?`tcp`:g,t.shareAlias=void 0,t.shareExternalPort=void 0):pe?(t.shareMode=`port`,t.sharePort=f,t.shareExternalPort=m,t.shareProtocol=g,t.shareAlias=void 0):(t.shareMode=c,t.shareAlias=u.trim()||void 0,c===`port`&&(t.sharePort=f),t.shareExternalPort=void 0,t.shareProtocol=void 0):(t.shareMode=void 0,t.shareAlias=void 0,t.sharePort=void 0);let i=await fetch(`/api/loops/${e.id}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(t)});if(E(!1),i.ok)P(`Saved`),await r?.(),setTimeout(()=>{P(``),n()},800);else try{I((await i.json()).error??`Save failed (${i.status})`)}catch{I(`Save failed (${i.status})`)}},_e=async()=>{try{await navigator.clipboard.writeText(he),C(!0),setTimeout(()=>C(!1),1500)}catch{window.prompt(`Copy this URL:`,he)}},ve=!T&&!k&&!j&&(me?f>=1&&f<=65535:(!pe||m>=1024)&&(!pe||f>=1||g===`static`)&&(pe||c!==`port`||!D||u.trim().length>0)&&(pe||c!==`port`||f>=1024));return i?(0,q.jsx)(Fg,{open:t,onOpenChange:e=>{e||n()},children:(0,q.jsxs)(Rg,{className:`sm:max-w-md bg-white max-h-[85vh] overflow-y-auto`,children:[(0,q.jsxs)(zg,{children:[(0,q.jsxs)(Bg,{className:`flex items-center gap-2 text-sm`,children:[(0,q.jsx)(Ce,{size:16}),`Share Artifact`]}),(0,q.jsx)(Vg,{className:`sr-only`,children:`Share this artifact via a public URL.`})]}),(0,q.jsxs)(`div`,{className:`space-y-4 text-[13px]`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-sm text-gray-700`,children:`Enable sharing`}),(0,q.jsx)(`button`,{onClick:()=>s(!o),className:`w-10 h-5 rounded-full transition-colors ${o?`bg-blue-600`:`bg-gray-300`}`,children:(0,q.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${o?`translate-x-5`:`translate-x-0.5`}`})})]}),o&&(0,q.jsxs)(q.Fragment,{children:[K&&(0,q.jsxs)(`div`,{className:`flex gap-1.5 border-b border-gray-200 pb-2`,children:[U&&(0,q.jsx)(`button`,{onClick:()=>{R(`standard`),l(`static`)},className:`px-3 py-1 text-xs rounded-t ${L===`standard`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Subdomain`}),W&&(0,q.jsx)(`button`,{onClick:()=>{R(`direct`),l(`direct`)},className:`px-3 py-1 text-xs rounded-t ${L===`direct`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Direct Port`}),ee&&(0,q.jsx)(`button`,{onClick:()=>{R(`ephemeral`),l(`ephemeral`)},className:`px-3 py-1 text-xs rounded-t ${L===`ephemeral`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Ephemeral`})]}),(te||K&&L===`standard`)&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Share mode`}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5 mt-1`,children:[(0,q.jsx)(`button`,{onClick:()=>l(`static`),className:`px-2 py-1.5 text-xs rounded border ${c===`static`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Static files`}),(0,q.jsx)(`button`,{onClick:()=>l(`port`),className:`px-2 py-1.5 text-xs rounded border ${c===`port`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Port proxy`})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:[`Alias `,D?(0,q.jsx)(`span`,{className:`text-red-500`,children:`(required)`}):`(optional)`]}),(0,q.jsx)(`input`,{value:u,onChange:e=>d(e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,``)),className:`w-full mt-1 px-2 py-1.5 text-sm border rounded outline-none focus:border-gray-300 ${D?`border-red-300 bg-red-50`:`border-gray-200`}`,placeholder:D?`Set an alias to resolve conflict`:`my-project`}),D&&(0,q.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,q.jsx)(G,{size:11}),` `,b||`ID "${H}" is already in use`]}),!D&&v===!0&&(0,q.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`}),!D&&v===!1&&(0,q.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,q.jsx)(G,{size:11}),` `,b||`Already in use`]})]}),c===`port`&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Port (1024-65535)`}),(0,q.jsx)(`input`,{type:`number`,min:1024,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`})]})]}),me&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,q.jsx)(`input`,{type:`number`,min:1,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`}),(0,q.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,q.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,q.jsx)(`button`,{onClick:()=>_(`tcp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`tcp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`TCP`}),(0,q.jsx)(`button`,{onClick:()=>_(`udp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`udp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`UDP`})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider flex items-center gap-1.5`,children:[`Current host port`,(0,q.jsx)(Ke,{size:10,className:`text-gray-300`})]}),(0,q.jsx)(`div`,{className:`mt-1 px-2 py-1.5 text-sm bg-gray-50 rounded text-gray-700`,children:z==null?(0,q.jsx)(`span`,{className:`text-gray-400 text-xs`,children:e.shareEnabled&&e.shareMode===`ephemeral`?`(container starting / not running)`:`(save to start — port assigned by kernel on restart)`}):(0,q.jsx)(`span`,{className:`font-mono`,children:z})}),(0,q.jsxs)(`p`,{className:`text-[10px] text-amber-600 mt-1 flex items-center gap-1`,children:[(0,q.jsx)(G,{size:10}),` Changes on every loop restart. Saving also restarts the container.`]})]})]}),(ne||K&&L===`direct`&&!me)&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`External port`}),(0,q.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,q.jsx)(`input`,{type:`number`,min:1024,max:65535,value:m,onChange:e=>h(parseInt(e.target.value,10)||1e4),className:`flex-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`,placeholder:`10000`}),(0,q.jsx)(`button`,{onClick:async()=>{let e=await Kh();e.port&&h(e.port)},className:`px-2 py-1.5 rounded border border-gray-200 hover:bg-gray-100 text-gray-500`,title:`Pick a random available port`,children:(0,q.jsx)(et,{size:14})})]}),(0,q.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The public port clients connect to`}),j&&(0,q.jsx)(`span`,{className:`text-[11px] text-gray-400 mt-0.5`,children:`Checking availability…`}),k&&(0,q.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,q.jsx)(G,{size:11}),` `,k]}),!j&&!k&&(0,q.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`})]}),g!==`static`&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,q.jsx)(`input`,{type:`number`,min:1,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`}),(0,q.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,q.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,q.jsx)(`button`,{onClick:()=>_(`tcp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`tcp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`TCP`}),i.serveDynamicUdpEnabled&&(0,q.jsx)(`button`,{onClick:()=>_(`udp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`udp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`UDP`}),i.serveDynamicStaticEnabled&&(0,q.jsx)(`button`,{onClick:()=>_(`static`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`static`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Static`})]})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Access URL`}),(0,q.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,q.jsx)(`code`,{className:`flex-1 px-2 py-1.5 text-xs bg-gray-50 rounded text-gray-700 truncate`,children:he}),(0,q.jsx)(`button`,{onClick:_e,className:`px-2 py-1.5 rounded hover:bg-gray-100 text-gray-500`,title:`Copy URL`,children:S?(0,q.jsx)(V,{size:14,className:`text-emerald-600`}):(0,q.jsx)(ie,{size:14})})]}),(0,q.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-1`,children:pe?`Direct TCP/UDP access — no domain needed`:`Domain suffix configured in Settings → Workspace → Workspace Serve`})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2`,children:[F&&(0,q.jsx)(`span`,{className:`text-xs text-red-500`,children:F}),N&&(0,q.jsxs)(`span`,{className:`text-xs text-emerald-600 flex items-center gap-1`,children:[(0,q.jsx)(V,{size:12}),` `,N]}),(0,q.jsx)(`button`,{onClick:n,className:`px-3 py-1.5 text-xs rounded bg-gray-100 text-gray-700 hover:bg-gray-200`,children:`Cancel`}),(0,q.jsx)(`button`,{onClick:ge,disabled:!ve,className:`px-3 py-1.5 text-xs rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40`,children:T?`Saving...`:`Save`})]})]})]})}):null}var oI=(0,w.lazy)(()=>St(()=>import(`./Editor-CeZLgps-.js`).then(e=>({default:e.Editor})),__vite__mapDeps([0,1,2,3]))),sI=(0,w.lazy)(()=>St(()=>import(`./Terminal-Vi3Ufhgi.js`).then(e=>({default:e.Terminal})),__vite__mapDeps([4,1,5])));function cI(){let{id:e}=Yn(),t=Og();if(!e)return(0,q.jsx)(yr,{to:`/loop`,replace:!0});if(!t.currentUser)return(0,q.jsx)(IF,{});let n=t.loops.find(t=>t.id===e);return t.loopsLoading?null:n?(0,q.jsxs)(`div`,{className:`h-full w-full flex min-h-0`,children:[(0,q.jsx)(lI,{currentId:e}),(0,q.jsx)(uI,{meta:n},e)]}):(0,q.jsx)(yr,{to:`/loop`,replace:!0})}function lI({currentId:e}){let t=Og(),n=Gn(),[r,i]=(0,w.useState)(`mine`),[a,o]=(0,w.useState)(``),[s,c]=(0,w.useState)(()=>localStorage.getItem(`loopat:loopsList:collapsed`)===`1`),l=_P(),u=BF((0,w.useMemo)(()=>t.loops.map(e=>e.id),[t.loops]));(0,w.useEffect)(()=>{let t=u[e];t?.status===`Done`&&t?.viewed===!1&&hm(e)},[u,e]);let d=t.currentUser?.id,f=(0,w.useMemo)(()=>{let e=a.toLowerCase().trim();return t.loops.filter(t=>{let n=t.driver??t.createdBy;return!(r===`mine`&&t.createdBy!==d&&n!==d||r===`rfd`&&!t.rfdRequestedAt||e&&!t.title.toLowerCase().includes(e)&&!t.id.toLowerCase().includes(e))})},[t.loops,r,d,a]),p=e=>{c(e),localStorage.setItem(`loopat:loopsList:collapsed`,e?`1`:`0`)},m=(0,q.jsxs)(`aside`,{className:`w-60 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,q.jsxs)(`div`,{className:`px-2 pt-1.5 pb-1 space-y-1 border-b border-gray-200`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[[`mine`,`all`,`rfd`].map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:r===e?e===`rfd`?`px-2 h-6 rounded text-[11px] flex items-center gap-1 bg-amber-600 text-white`:`px-2 h-6 rounded text-[11px] bg-gray-900 text-white`:e===`rfd`?`px-2 h-6 rounded text-[11px] flex items-center gap-1 text-amber-700 hover:bg-amber-50`:`px-2 h-6 rounded text-[11px] text-gray-500 hover:bg-gray-100`,children:e===`mine`?`mine`:e===`all`?`all`:`RFD`},e)),(0,q.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-auto pr-1`,children:f.length}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>t.setShowArchived(!t.showArchived),className:t.showArchived?`w-6 h-6 flex items-center justify-center text-gray-700 bg-gray-100 rounded`:`w-6 h-6 flex items-center justify-center text-gray-400 hover:text-gray-700 hover:bg-gray-100 rounded`,title:t.showArchived?`hide archived`:`show archived`,children:(0,q.jsx)(j,{size:13})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(!0),className:`w-6 h-6 flex items-center justify-center text-gray-400 hover:text-gray-700 hover:bg-gray-100 rounded`,title:`collapse sidebar`,children:(0,q.jsx)(Be,{size:14})})]}),(0,q.jsx)(`input`,{type:`text`,name:`loop-search`,value:a,onChange:e=>o(e.target.value),placeholder:`search loops…`,className:`w-full h-6 rounded px-1.5 text-[11px] bg-gray-100 border border-transparent focus:border-gray-300 focus:bg-white focus:outline-none text-gray-600 placeholder-gray-400`})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:[f.map(r=>{let i=e===r.id,a=r.archived===!0,o=t.currentUser?.id===r.createdBy,s=u[r.id],c=s?.status===`Done`||s?.status===`Ready`,d=s!==void 0&&!c;return(0,q.jsxs)(`div`,{className:`group/row relative flex items-stretch `+(i?`bg-gray-100`:`hover:bg-gray-50`),children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{hm(r.id),n(`/loop/${r.id}`),l&&p(!0)},className:`flex-1 min-w-0 px-3 py-1.5 flex items-center gap-2 text-left `+(a?`opacity-60`:``),children:[(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 mt-0.5 `+(a?`bg-gray-400`:d?`bg-blue-500 animate-pulse`:c&&!s?.viewed?`bg-yellow-500`:c?`bg-emerald-500`:`bg-gray-300`)}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`text-[13px] text-gray-900 truncate flex items-center gap-1.5`,children:[a&&(0,q.jsx)(j,{size:10,className:`text-gray-400 shrink-0`}),r.rfdRequestedAt&&(0,q.jsx)(`span`,{className:`shrink-0 text-[9px] px-1 rounded bg-amber-100 text-amber-800 font-medium tracking-wide`,children:`RFD`}),(0,q.jsx)(`span`,{className:`truncate`,children:r.title}),s&&(0,q.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium `+(d?`text-blue-500`:c?`text-emerald-500`:`text-gray-400`),children:s.status})]}),(0,q.jsxs)(`div`,{className:`text-[11px] text-gray-500 truncate flex items-center gap-1 mt-0.5`,children:[(0,q.jsx)(`span`,{children:r.driver??r.createdBy}),(0,q.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400`,children:r.id.slice(0,6)})]})]})]}),(0,q.jsx)(`button`,{type:`button`,disabled:!o,onClick:e=>{e.stopPropagation(),o&&t.setLoopArchived(r.id,!a)},className:(l?`opacity-100`:`opacity-0 group-hover/row:opacity-100`)+` transition-opacity w-7 flex items-center justify-center `+(o?`text-gray-400 hover:text-gray-700`:`text-gray-300 cursor-not-allowed`),title:o?a?`unarchive`:`archive (hide + read-only)`:`only ${r.createdBy} can ${a?`unarchive`:`archive`} this loop`,children:a?(0,q.jsx)(A,{size:13}):(0,q.jsx)(j,{size:13})})]},r.id)}),f.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no loops · click "+ New Loop"`})]})]});return s?(0,q.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(!1),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`expand sidebar`,children:(0,q.jsx)(Ve,{size:16})})}):l?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`collapse sidebar`,children:(0,q.jsx)(Be,{size:16})})}),(0,q.jsxs)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>p(!0),children:[(0,q.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:m})]})]}):m}function uI({meta:e}){let t=Og(),n=_P(),[r,i]=(0,w.useState)([]),[a,o]=(0,w.useState)(null),[s,c]=(0,w.useState)(null),[l,u]=(0,w.useState)([]),[d,f]=(0,w.useState)(!1),[p,m]=(0,w.useState)(null);(0,w.useEffect)(()=>{Uh().then(m)},[]);let[h,g]=(0,w.useState)(null),_=e=>{c(e),g(null),i(e=>e.includes(`editor`)?e:[...e,`editor`])},{runtime:v,connected:y,reconnecting:b,running:x,viewers:S,extra:C,queue:T,onClearQueue:E}=NP(e.id,t.currentUser?.id??``,_),D=BF((0,w.useMemo)(()=>[e.id],[e.id])),O=D[e.id]?.phase===`preparing`,k=D[e.id]?.status;(0,w.useEffect)(()=>{jm(e.id).then(u),hm(e.id),t.currentUser?.id&&localStorage.setItem(`loopat:lastLoop:${t.currentUser.id}`,e.id)},[e.id]);let A=Vn(),j=Gn(),M=A.state?.kickoff;(0,w.useEffect)(()=>{!M||!y||(C.enqueueMessage(M),j(A.pathname,{replace:!0,state:null}))},[M,y]);let N=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},P=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[e])},F=e=>{i(t=>t.filter(t=>t!==e)),o(t=>t===e?null:t)},I=r.length>0,L=r.filter(e=>e===`editor`||e===`terminal`),R=r.filter(e=>e!==`editor`&&e!==`terminal`),z=L.length>0,B=R.length>0,[V,H]=(0,w.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);return!isNaN(e)&&e>=10&&e<=90?e:55}),[U,W]=(0,w.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);return!isNaN(e)&&e>=5&&e<=50?e:18});(0,w.useEffect)(()=>{if(!B){let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);!isNaN(e)&&e>=5&&e<=50&&W(e)}if(!z&&!B){let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);!isNaN(e)&&e>=10&&e<=90&&H(e)}},[z,B]);let G=e=>{!isNaN(e.chat)&&e.chat>0&&localStorage.setItem(`loopat:chatPct`,String(Math.round(e.chat))),!isNaN(e.otherCol)&&e.otherCol>0&&localStorage.setItem(`loopat:otherPct`,String(Math.round(e.otherCol)))},ee=n=>{let r=a===n;return(0,q.jsx)(_I,{loopId:e.id,meta:e,mode:n,onClose:()=>F(n),pickedFile:s,onPickFile:_,currentUserId:t.currentUser?.id??``,isFullscreen:r,onToggleFullscreen:()=>o(r?null:n),onEditorSelection:g},n)};return(0,q.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,q.jsx)(dI,{meta:e,mounts:l,connected:y,reconnecting:b,running:x,viewers:S,queue:T,onClearQueue:E,openPanels:r,toggleMode:N,onShareWork:()=>f(!0),showShareButton:!p||p.serveEnabled||p.serveDynamicEnabled||p.serveEphemeralEnabled}),e.contextWarnings&&e.contextWarnings.length>0&&(0,q.jsxs)(`div`,{className:`shrink-0 border-b border-amber-200 bg-amber-50 px-4 py-2 text-[12px] text-amber-800 leading-relaxed`,children:[(0,q.jsx)(`span`,{className:`font-semibold`,children:`⚠ Context not fully loaded.`}),` `,`This loop's knowledge/notes couldn't be cloned — it runs with an empty context until the access is fixed (check the key has access to the repo):`,(0,q.jsx)(`ul`,{className:`mt-1 ml-4 list-disc`,children:e.contextWarnings.map((e,t)=>(0,q.jsx)(`li`,{className:`font-mono text-[11px] break-all`,children:e},t))})]}),(0,q.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col`,children:[O&&(0,q.jsx)(mI,{detail:k}),n?(0,q.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,q.jsx)(MP,{extra:C,children:(0,q.jsx)(SC,{runtime:v,children:(0,q.jsx)(FF,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})}):I?(0,q.jsxs)(dD,{orientation:`horizontal`,className:`flex-1 min-w-0 min-h-0`,onLayoutChange:G,children:[(0,q.jsx)(mD,{id:`chat`,minSize:20,defaultSize:V,className:`flex flex-col min-h-0 min-w-0`,children:(0,q.jsx)(MP,{extra:C,children:(0,q.jsx)(SC,{runtime:v,children:(0,q.jsx)(FF,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})}),(z||B)&&(0,q.jsx)(_D,{className:`relative w-4 -mx-1.5 cursor-col-resize group flex items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-px after:-translate-x-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,q.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 h-8 w-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),z&&(0,q.jsx)(mD,{id:`editorCol`,minSize:15,defaultSize:30,className:`flex flex-col min-h-0 min-w-0`,children:L.length>1?(0,q.jsx)(dD,{orientation:`vertical`,className:`flex-1 min-h-0`,children:L.map((e,t)=>(0,q.jsxs)(w.Fragment,{children:[t>0&&(0,q.jsx)(_D,{className:`relative h-4 -my-1.5 cursor-row-resize group flex items-center justify-center after:absolute after:left-0 after:right-0 after:top-1/2 after:h-px after:-translate-y-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,q.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 w-8 h-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),(0,q.jsx)(mD,{id:e,minSize:10,defaultSize:100/L.length,className:`flex flex-col min-h-0 min-w-0`,children:ee(e)})]},e))}):ee(L[0])}),z&&B&&(0,q.jsx)(_D,{className:`relative w-4 -mx-1.5 cursor-col-resize group flex items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-px after:-translate-x-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,q.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 h-8 w-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),B&&(0,q.jsx)(mD,{id:`otherCol`,minSize:15,defaultSize:U,className:`flex flex-col min-h-0 min-w-0`,children:R.length>1?(0,q.jsx)(dD,{orientation:`vertical`,className:`flex-1 min-h-0`,children:R.map((e,t)=>(0,q.jsxs)(w.Fragment,{children:[t>0&&(0,q.jsx)(_D,{className:`relative h-4 -my-1.5 cursor-row-resize group flex items-center justify-center after:absolute after:left-0 after:right-0 after:top-1/2 after:h-px after:-translate-y-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,q.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 w-8 h-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),(0,q.jsx)(mD,{id:e,minSize:10,defaultSize:100/R.length,className:`flex flex-col min-h-0 min-w-0`,children:ee(e)})]},e))}):ee(R[0])})]}):(0,q.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,q.jsx)(MP,{extra:C,children:(0,q.jsx)(SC,{runtime:v,children:(0,q.jsx)(FF,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})})]}),I&&n&&r.map(e=>(0,q.jsx)(w.Fragment,{children:ee(e)},e)),n&&(0,q.jsx)(`div`,{className:`fixed bottom-0 left-0 z-30 w-9 flex flex-col items-center gap-0.5 pb-2`,children:[`terminal`,`editor`,`workdir`,`git`].map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>P(e),className:`w-7 h-7 flex items-center justify-center rounded text-xs ${r.includes(e)?`bg-gray-200 text-gray-900`:`text-gray-400 hover:text-gray-700 hover:bg-gray-100`}`,title:e,children:e===`terminal`?`▷`:e===`editor`?`✎`:e===`workdir`?`▤`:`⑂`},e))}),(0,q.jsx)(aI,{loop:e,open:d,onClose:()=>f(!1),onSaved:async()=>{await t.refresh()}})]})}function dI({meta:e,mounts:t,connected:n,reconnecting:r,running:i,viewers:a,queue:o,onClearQueue:s,openPanels:c,toggleMode:l,onShareWork:u,showShareButton:d}){let f=_P(),p=Gn(),m=Og(),[h,g]=(0,w.useState)(f),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(!1),[x,S]=(0,w.useState)(e.title),C=m.currentUser?.id===e.createdBy,T=async()=>{if(!_){v(!0);try{let t=await xm(e.id);t&&p(`/loop/${t.id}`)}finally{v(!1)}}},E=async()=>{let t=x.trim();if(!t||t===e.title){b(!1),S(e.title);return}b(!1),await m.setLoopTitle(e.id,t)||S(e.title)},D=(e,t)=>(0,q.jsx)(`button`,{className:c.includes(t)?`px-2 py-0.5 rounded bg-gray-100 text-gray-900`:`px-2 py-0.5 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-50`,onClick:()=>l(t),children:e},t);return(0,q.jsxs)(`header`,{className:`group/header px-3 md:px-5 shrink-0 border-b border-gray-200 `+(h?`py-1.5`:`pt-3 pb-2`),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`text-gray-400 hover:text-gray-700 -ml-1 p-0.5 rounded hover:bg-gray-100`,title:h?`expand header`:`collapse header`,children:(0,q.jsx)(H,{size:14,className:`transition-transform `+(h?`-rotate-90`:``)})}),y?(0,q.jsx)(`input`,{type:`text`,value:x,autoFocus:!0,onChange:e=>S(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing?(t.preventDefault(),E()):t.key===`Escape`&&(t.preventDefault(),b(!1),S(e.title))},onBlur:E,maxLength:200,className:`text-[14px] md:text-[15px] font-medium text-gray-900 bg-white border border-blue-400 rounded px-1 py-0 outline-none min-w-[120px]`}):(0,q.jsx)(`span`,{className:`text-[14px] md:text-[15px] font-medium text-gray-900 `+(C?`cursor-pointer hover:bg-gray-100 rounded px-1 -mx-1`:``),onClick:()=>{C&&(S(e.title),b(!0))},title:C?`click to rename`:void 0,children:e.title}),(0,q.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`driver: `,(0,q.jsx)(`span`,{className:`text-gray-900`,children:e.driver??e.createdBy})]}),e.rfdRequestedAt&&(0,q.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-amber-100 text-amber-800 border border-amber-200 font-medium tracking-wide`,title:`released for drive by ${e.rfdRequestedBy??`?`} at ${e.rfdRequestedAt}`,children:`RFD`}),!n&&r&&(0,q.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`reconnecting…`}),i&&(0,q.jsx)(`span`,{className:`text-[11px] text-blue-600`,children:`running`}),a>1&&(0,q.jsxs)(`span`,{title:`people watching`,className:`text-[11px] px-1.5 py-0.5 rounded bg-emerald-50 text-emerald-800 border border-emerald-200`,children:[`👥 `,a]}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`button`,{type:`button`,onClick:T,disabled:_,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-violet-700 border-violet-300 hover:bg-violet-50 disabled:opacity-50`,title:`Spawn a child loop seeded with this loop's conversation, for sedimenting reusable insights into knowledge/`,children:[(0,q.jsx)(ge,{size:11}),_?`Distilling…`:`Distill`]}),d!==!1&&(0,q.jsxs)(`button`,{onClick:u,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border ${e.shareEnabled?`bg-blue-50 text-blue-700 border-blue-200 hover:bg-blue-100`:`bg-white text-gray-700 border-gray-300 hover:bg-gray-100`}`,title:`Share workspace artifact (static files or port forward)`,children:[(0,q.jsx)(Ce,{size:11}),`Share Artifact`]}),(0,q.jsx)(pI,{meta:e}),(0,q.jsx)(fI,{meta:e})]}),!h&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`text-xs text-gray-500 mt-1.5 flex items-center gap-2 flex-wrap`,children:[(0,q.jsxs)(`span`,{className:`font-mono`,children:[`~/.loopat/loops/`,e.id.slice(0,8),`/workdir`]}),(0,q.jsx)(`span`,{children:`·`}),(0,q.jsx)(`span`,{children:`main`}),a>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{children:`·`}),(0,q.jsxs)(`span`,{children:[a,` viewing`]})]}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,children:[D(`ℹ info`,`info`),D(`▤ workdir`,`workdir`),D(`✎ editor`,`editor`),D(`▷ terminal`,`terminal`),(0,q.jsx)(`button`,{className:c.includes(`git`)?`px-2 py-0.5 rounded bg-gray-100 text-gray-900`:`px-2 py-0.5 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-50`,onClick:()=>l(`git`),title:`git changes`,children:(0,q.jsx)(xe,{size:14})})]})]}),(0,q.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-gray-400`,children:`context:`}),t.map(e=>(0,q.jsx)(hI,{label:e.name,value:e.name===`knowledge`?`ro`:`rw`},e.path))]}),e.config?.profiles&&e.config.profiles.length>0&&(0,q.jsx)(gI,{profiles:e.config.profiles}),(0,q.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-gray-400`,children:`vault:`}),(0,q.jsx)(hI,{label:e.config?.vault??`default`,value:`loaded`})]})]})]})}function fI({meta:e}){let t=Og(),[n,r]=(0,w.useState)(!1),[i,a]=(0,w.useState)(!1),o=t.currentUser?.id===e.createdBy,s=e.public===!0;if(!t.currentUser)return null;let c=`${location.origin}/loop/${e.id}`;return o?(0,q.jsxs)(`div`,{className:`inline-flex items-center gap-1`,children:[s&&(0,q.jsxs)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(c),r(!0),setTimeout(()=>r(!1),1500)}catch{}},title:c,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] text-gray-600 hover:bg-gray-100`,children:[n?(0,q.jsx)(V,{size:11}):(0,q.jsx)(ie,{size:11}),(0,q.jsx)(`span`,{className:`hidden md:inline`,children:n?`copied`:`copy link`})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!o||i)){a(!0);try{await t.setLoopPublic(e.id,!s)}finally{a(!1)}}},disabled:i,title:s?`stop sharing`:`share publicly (anyone with the link can view)`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border disabled:opacity-50 `+(s?`bg-emerald-50 text-emerald-800 border-emerald-200 hover:bg-emerald-100`:`bg-white text-gray-700 border-gray-300 hover:bg-gray-100`),children:[s?(0,q.jsx)(Ce,{size:11}):(0,q.jsx)(je,{size:11}),s?`shared`:`share`]})]}):(0,q.jsxs)(`span`,{title:s?`this loop is shared publicly`:`this loop is private`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] `+(s?`bg-emerald-50 text-emerald-800 border border-emerald-200`:`bg-gray-100 text-gray-600`),children:[s?(0,q.jsx)(Ce,{size:11}):(0,q.jsx)(je,{size:11}),s?`public`:`private`]})}function pI({meta:e}){let t=Og(),[n,r]=(0,w.useState)(!1);if(!t.currentUser)return null;let i=e.driver??e.createdBy,a=t.currentUser.id===i;return e.rfdRequestedAt?(0,q.jsxs)(`button`,{type:`button`,disabled:n,onClick:async()=>{r(!0);try{await t.takeDrive(e.id)}finally{r(!1)}},title:`released for drive by ${e.rfdRequestedBy??`?`} — click to take over`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-amber-500 text-white border-amber-600 hover:bg-amber-600 disabled:opacity-50`,children:[(0,q.jsx)(we,{size:11}),`Drive`]}):a?(0,q.jsxs)(`button`,{type:`button`,disabled:n,onClick:async()=>{if(window.confirm(`Request For Drive: this will tear down the sandbox and release the loop so anyone else can take over. Continue?`)){r(!0);try{await t.requestDrive(e.id)}finally{r(!1)}}},title:`Release this loop so someone else can drive it`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-amber-700 border-amber-300 hover:bg-amber-50 disabled:opacity-50`,children:[(0,q.jsx)(we,{size:11}),`Request For Drive`]}):null}function mI({detail:e}){return(0,q.jsx)(`div`,{className:`absolute inset-0 z-30 flex items-center justify-center bg-white/70 backdrop-blur-sm`,children:(0,q.jsxs)(`div`,{className:`max-w-md mx-6 px-6 py-5 rounded-xl border border-blue-200 bg-white shadow-lg text-center`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 mb-2`,children:[(0,q.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border-2 border-blue-500 border-t-transparent animate-spin`}),(0,q.jsx)(`span`,{className:`text-sm font-medium text-gray-900`,children:`Preparing this loop’s sandbox…`})]}),(0,q.jsxs)(`p`,{className:`text-[12px] text-gray-600 leading-relaxed`,children:[`Installing the toolchain from `,(0,q.jsx)(`code`,{className:`font-mono text-[11px] bg-gray-100 px-1 rounded`,children:`mise.toml`}),`. Terminal and chat are paused until tools are ready — this only happens the first time.`]}),e&&e!==`Ready`&&(0,q.jsx)(`p`,{className:`mt-2 text-[11px] font-mono text-blue-700 break-words`,children:e})]})})}function hI({label:e,value:t,title:n}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-gray-100 text-[11px]`,title:n,children:[(0,q.jsxs)(`span`,{className:`text-gray-500`,children:[e,`:`]}),(0,q.jsx)(`span`,{className:`text-gray-900 font-medium`,children:t})]})}function gI({profiles:e}){let[t,n]=(0,w.useState)({});return(0,w.useEffect)(()=>{let e=!1;return dm().then(t=>{if(e)return;let r={};for(let e of t)e.description&&(r[e.name]=e.description);n(r)}).catch(()=>{}),()=>{e=!0}},[]),(0,q.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-gray-400`,children:`profiles:`}),e.map(e=>(0,q.jsx)(hI,{label:e,value:`active`,title:t[e]},e))]})}function _I({loopId:e,meta:t,mode:n,onClose:r,pickedFile:i,onPickFile:a,currentUserId:o,isFullscreen:s,onToggleFullscreen:c,onEditorSelection:l}){let u=_P(),[d,f]=(0,w.useState)(()=>{let e=localStorage.getItem(`loopat:mobilePanelPct`);return e?Math.max(20,Math.min(95,parseInt(e)||55)):55}),p=(0,w.useRef)(null),m=e=>{localStorage.setItem(`loopat:mobilePanelPct`,String(e))},h=e=>{if(p.current={startY:e,startPct:d},s){let t=Math.round(e/window.innerHeight*100),n=Math.max(20,Math.min(95,t));f(n),m(n),c?.()}},g=e=>{if(!p.current)return;let t=e-p.current.startY,n=Math.round(t/window.innerHeight*100),r=Math.max(20,Math.min(95,p.current.startPct+n));f(r),m(r)},_=()=>{p.current=null},v=e=>{e.preventDefault(),e.stopPropagation(),h(e.touches[0].clientY)},y=e=>{e.preventDefault(),g(e.touches[0].clientY)},b=e=>{e.preventDefault(),_()},x=e=>{e.pointerType!==`touch`&&(e.preventDefault(),e.target.setPointerCapture(e.pointerId),h(e.clientY))},S=e=>{e.pointerType===`touch`||!p.current||g(e.clientY)},C=e=>{e.pointerType!==`touch`&&_()},T=(0,q.jsxs)(`aside`,{className:`flex-1 min-w-0 bg-white flex flex-col`,children:[(0,q.jsxs)(`header`,{className:`px-3 h-8 shrink-0 border-b border-gray-200 flex items-center gap-1 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{className:`capitalize`,children:n}),n===`editor`&&(0,q.jsx)(`span`,{className:`ml-2 truncate text-gray-700`,children:i||`(no file)`}),(0,q.jsx)(`div`,{className:`flex-1`}),(n===`editor`||n===`terminal`)&&(0,q.jsx)(`button`,{className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,onClick:c,title:s?`restore`:`maximize`,children:s?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})}),(0,q.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:r,title:`close panel`,children:`✕`})]}),n===`info`&&(0,q.jsx)(vI,{meta:t}),n===`workdir`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(JF,{loopId:e,onPick:a,picked:i}),(0,q.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 text-[11px] text-gray-500`,children:[`⑂ `,(0,q.jsx)(`span`,{className:`text-gray-900`,children:`main`})]})]}),(0,q.jsxs)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading...`}),children:[n===`editor`&&(0,q.jsx)(oI,{loopId:e,path:i,onSelectionChange:l}),n===`terminal`&&(0,q.jsx)(`div`,{className:`flex-1 min-h-0 bg-[#1a1c20] overflow-hidden`,children:(0,q.jsx)(sI,{loopId:e,currentUserId:o})}),n===`git`&&(0,q.jsx)(eI,{loopId:e,onClose:r,onPickFile:a})]})]});return u?(0,q.jsxs)(`div`,{className:`fixed inset-x-0 top-0 z-40 bg-white rounded-b-xl shadow-xl pointer-events-auto overflow-hidden`,style:{height:s?`100vh`:`${d}vh`},children:[(0,q.jsx)(`div`,{className:`absolute inset-0 bottom-7 overflow-y-auto flex flex-col`,children:T}),(0,q.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 h-7 z-10 flex items-center justify-center cursor-row-resize active:bg-gray-50 rounded-b-xl`,style:{touchAction:`none`},onTouchStart:v,onTouchMove:y,onTouchEnd:b,onPointerDown:x,onPointerMove:S,onPointerUp:C,children:(0,q.jsx)(`div`,{className:`w-8 h-1 rounded-full bg-gray-300`})})]}):s?(0,_t.createPortal)((0,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex flex-col`,children:T}),document.body):T}function vI({meta:e}){let t=Og().currentUser?.id===e.createdBy;return(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-5 py-4 text-[13px] text-gray-900`,children:[(0,q.jsxs)(yI,{label:`basics`,children:[(0,q.jsx)(bI,{label:`title`,value:e.title}),(0,q.jsx)(bI,{label:`created`,value:new Date(e.createdAt).toLocaleString()}),(0,q.jsx)(bI,{label:`status`,value:`active`}),(0,q.jsx)(bI,{label:`driver`,value:t?`${e.createdBy} (you)`:e.createdBy}),(0,q.jsx)(bI,{label:`sharing`,value:e.public?`public — /loop/${e.id.slice(0,8)}…`:`private`})]}),(0,q.jsxs)(yI,{label:`workdir`,children:[(0,q.jsx)(bI,{label:`id`,value:e.id,mono:!0}),(0,q.jsx)(bI,{label:`path`,value:`~/.loopat/loops/${e.id.slice(0,8)}/workdir`,mono:!0}),(0,q.jsx)(bI,{label:`branch`,value:`main`,mono:!0})]}),(0,q.jsxs)(yI,{label:`context`,children:[(0,q.jsx)(bI,{label:`knowledge`,value:`all (ro)`}),(0,q.jsx)(bI,{label:`notes`,value:`all (rw)`}),(0,q.jsx)(bI,{label:`personal`,value:`${e.createdBy} (rw)`})]})]})}function yI({label:e,children:t}){return(0,q.jsxs)(`section`,{className:`mb-5`,children:[(0,q.jsx)(`h3`,{className:`text-[11px] uppercase tracking-wide text-gray-400 mb-2`,children:e}),(0,q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:t})]})}function bI({label:e,value:t,mono:n=!1}){return(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500 w-24 shrink-0`,children:e}),(0,q.jsx)(`span`,{className:n?`font-mono text-[12px] text-gray-800 truncate`:`text-[13px] text-gray-900 truncate`,children:t})]})}function xI({name:e,onClick:t,onEdit:n,size:r=`sm`}){return(0,q.jsxs)(`span`,{className:`relative inline-flex items-center group/chip`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:t,className:`inline-flex items-center rounded-full bg-sky-50 text-sky-700 border border-sky-200 hover:bg-sky-100 transition-colors font-mono `+(r===`md`?`px-2 py-0.5 text-[12px]`:`px-1.5 py-0.5 text-[10px]`),title:`#${e}`,children:[`#`,e]}),n&&(0,q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n()},className:`absolute -top-1 -right-1 z-10 w-4 h-4 rounded-full bg-white border border-gray-300 hover:border-red-400 hover:text-red-500 text-[9px] text-gray-400 opacity-0 group-hover/chip:opacity-100 transition-opacity flex items-center justify-center shadow-sm`,title:`Remove tag`,children:`×`})]})}function SI(){let{name:e}=Yn(),t=decodeURIComponent(e??``),n=Gn(),[r,i]=(0,w.useState)(null),[a,o]=(0,w.useState)(!0);return(0,w.useEffect)(()=>{let e=!1;return gh().then(n=>{e||(i(n.find(e=>e.name===t.toLowerCase())??null),o(!1))}),()=>{e=!0}},[t]),(0,q.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-white`,children:[(0,q.jsxs)(`header`,{className:`h-10 shrink-0 flex items-center gap-3 px-6 border-b border-gray-200`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>n(-1),className:`text-[11px] text-gray-500 hover:text-gray-900`,children:`← back`}),(0,q.jsx)(xI,{name:t,size:`md`}),(0,q.jsx)(`div`,{className:`flex-1`})]}),(0,q.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col overflow-auto`,children:(0,q.jsx)(`div`,{className:`px-4 md:px-8 py-4 md:py-8 mx-auto w-full max-w-[760px] flex flex-col gap-5`,children:a?(0,q.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`}):!r||r.loops.length===0?(0,q.jsxs)(`div`,{className:`text-[12px] text-gray-400 italic`,children:[`no entities tagged with `,(0,q.jsxs)(`code`,{children:[`#`,t]})]}):(0,q.jsxs)(`section`,{children:[(0,q.jsxs)(`div`,{className:`text-[12px] uppercase tracking-wider text-gray-500 mb-2 px-1`,children:[`Loops (`,r.loops.length,`)`]}),(0,q.jsx)(`div`,{className:`flex flex-col gap-1`,children:r.loops.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n(`/loop/${e.id}`),className:`w-full text-left px-3 py-2 rounded border border-gray-200 hover:border-gray-400 hover:bg-gray-50 text-[13px] text-gray-900`,children:[e.title,(0,q.jsx)(`span`,{className:`ml-2 text-[10px] font-mono text-gray-400`,children:e.id.slice(0,6)})]},e.id))})]})})})]})}var CI=(0,w.lazy)(()=>St(()=>import(`./CodeEditor-JV36Z3V5.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([2,1,3]))),wI=(0,w.lazy)(()=>St(()=>import(`./Markdown-CnZpm-Uk.js`).then(e=>({default:e.Markdown})),__vite__mapDeps([6,1,7]))),TI=(0,w.lazy)(()=>St(()=>import(`./MilkdownEditor-t_CG4MJj.js`).then(e=>({default:e.MilkdownEditor})),__vite__mapDeps([8,1,7,3]))),EI=[{id:`knowledge`,label:`Knowledge`},{id:`notes`,label:`Notes`},{id:`personal`,label:`Personal`},{id:`repos`,label:`Repos`}],DI=new Set([`knowledge`,`notes`,`personal`,`repos`]);function OI(){let{sub:e}=Yn(),[t]=Ci(),n=DI.has(e)?e:`knowledge`,r=t.get(`file`)||void 0,i=t.get(`edit`)===`1`;return(0,q.jsxs)(`div`,{className:`flex flex-col h-full w-full`,children:[(0,q.jsx)(`nav`,{className:`flex items-center gap-1 px-3 h-9 shrink-0 border-b border-gray-200 bg-white`,children:EI.map(e=>(0,q.jsx)(gi,{to:`/context/${e.id}`,className:({isActive:e})=>e?`h-7 px-2.5 rounded flex items-center gap-1.5 text-xs bg-gray-100 text-gray-900`:`h-7 px-2.5 rounded flex items-center gap-1.5 text-xs text-gray-500 hover:bg-gray-50 hover:text-gray-900`,children:(0,q.jsx)(`span`,{children:e.label})},e.id))}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0`,children:n===`repos`?(0,q.jsx)(BI,{}):(0,q.jsx)(MI,{vault:n,initialFile:r,initialEditing:i},n)})]})}var kI={knowledge:`workspace's distilled materials`,notes:`workspace · public`,personal:`yours · private`,repos:`registered code repos`};function AI({resource:e,canPush:t=!0}){let[n,r]=(0,w.useState)(null),[i,a]=(0,w.useState)(null),[o,s]=(0,w.useState)(null),c=(0,w.useCallback)(async()=>{a(`status`),r(await Jm(e)),a(null)},[e]);(0,w.useEffect)(()=>{c()},[c]);let l=async()=>{a(`pull`),s(null);let t=await Ym(e);a(null),s(t.ok?{ok:!0,text:t.message??`pulled`}:{ok:!1,text:t.error??`pull failed`}),t.ok&&c()},u=async()=>{a(`push`),s(null);let t=await Xm(e);a(null),s(t.ok?{ok:!0,text:t.message??`pushed`}:{ok:!1,text:t.error??`push failed`}),t.ok&&c()},d=n?.ahead??0,f=n?.behind??0,p=n&&!n.hasRemote;return(0,q.jsxs)(`div`,{className:`px-3 py-1.5 border-t border-gray-200 flex flex-col gap-1 text-[11px]`,children:[(0,q.jsx)(`div`,{className:`flex items-center gap-2`,children:p?(0,q.jsx)(`span`,{className:`text-gray-400`,children:`no remote`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:d>0?`text-emerald-700`:`text-gray-400`,title:`unpushed commits`,children:[`↑`,d]}),(0,q.jsxs)(`span`,{className:f>0?`text-amber-700`:`text-gray-400`,title:`unpulled commits`,children:[`↓`,f]}),n&&n.uncommitted>0&&(0,q.jsxs)(`span`,{className:`text-red-600`,title:`uncommitted changes in primary`,children:[`! `,n.uncommitted]}),(0,q.jsx)(`button`,{onClick:()=>void c(),disabled:i!==null,className:`ml-auto text-gray-400 hover:text-gray-700 disabled:opacity-50`,title:`refresh status`,children:`↻`})]})}),!p&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`button`,{onClick:l,disabled:i!==null||f===0,className:`px-1.5 h-5 rounded border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i===`pull`?`pulling…`:`pull`}),t&&(0,q.jsx)(`button`,{onClick:u,disabled:i!==null||d===0,className:`px-1.5 h-5 rounded border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i===`push`?`pushing…`:`push`}),o&&(0,q.jsx)(`span`,{className:`truncate flex-1 min-w-0 `+(o.ok?`text-emerald-700`:`text-red-600`),title:o.text,children:o.text})]})]})}function jI({onRefreshed:e}){let[t,n]=(0,w.useState)(0),[r,i]=(0,w.useState)(!1),[a,o]=(0,w.useState)(null),s=(0,w.useRef)(e);s.current=e;let c=(0,w.useCallback)(async()=>{i(!0),o(null);let e=await Rm();i(!1),e.ok?(n(0),s.current()):e.diverged?o(`你有未保存的编辑,先保存再刷新`):o(e.error??`refresh failed`)},[]);return(0,w.useEffect)(()=>{c()},[c]),(0,w.useEffect)(()=>{let e=()=>Lm().then(n).catch(()=>{});e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]),(0,q.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 flex flex-col gap-1.5 text-[11px]`,children:[t>0?(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 bg-amber-50 border border-amber-200 rounded px-2 py-1 text-amber-800`,children:[(0,q.jsxs)(`span`,{children:[`远端已更新 `,t,` 个改动`]}),(0,q.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`px-2 py-0.5 rounded bg-amber-600 text-white hover:bg-amber-700 disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}):(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-gray-400`,children:[(0,q.jsx)(`span`,{children:`已是最新`}),(0,q.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`text-gray-500 hover:text-gray-900 underline disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}),a&&(0,q.jsx)(`div`,{className:`text-amber-700`,children:a})]})}function MI({vault:e,initialFile:t,initialEditing:n}){let[r,i]=(0,w.useState)([]),[a,o]=(0,w.useState)([]),[s,c]=(0,w.useState)(t??null),[l,u]=Ci();(0,w.useEffect)(()=>{(l.get(`file`)??null)!==s&&u(s?{file:s}:{},{replace:!0})},[s,l,u]);let[d,f]=(0,w.useState)(0),[p,m]=(0,w.useState)(!1),[h,g]=(0,w.useState)(``),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(null),[x,S]=(0,w.useState)(``),C=_P(),T=(0,w.useRef)(!1);if(!T.current&&t){T.current=!0;let n=`vault-${e}`,r=t.includes(`/`)?t.substring(0,t.lastIndexOf(`/`)):``;if(r)try{let e=`loopat:tree:expanded:`+n,t=localStorage.getItem(e),i=t?JSON.parse(t):[];for(let e=r;e;e=e.includes(`/`)?e.substring(0,e.lastIndexOf(`/`)):``)i.includes(e)||i.push(e);localStorage.setItem(e,JSON.stringify(i))}catch{}}(0,w.useEffect)(()=>{Mm(e).then(e=>{i(e),c(t=>{if(t)return t;let n=e.find(e=>e.type===`file`&&e.path.endsWith(`.md`));return n?n.path:null})}),Nm(e).then(o),g(``)},[e,d]),(0,w.useEffect)(()=>{let t=!1,n=()=>{t||f(e=>e+1)};return e===`knowledge`?Ym(`knowledge`).then(e=>{e.ok&&(e.message??``).toLowerCase()!==`already up to date`&&n()}):e===`notes`?Lm().then(e=>{e>0&&Rm().then(e=>{e.ok&&n()})}):e===`personal`&&im().then(e=>{e.ok&&(e.files?.length??0)>0&&n()}),()=>{t=!0}},[e]);let E=async t=>{let n=await zm(e,t);n.ok?(m(!1),f(e=>e+1),c(t)):alert(`failed: ${n.error}`)},D=async()=>{if(!y||!x.trim()){b(null);return}let t=y.path+`/`+x.trim();if(y.type===`file`){let n=await zm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}else{let n=await Bm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}b(null),S(``),f(e=>e+1)},O=(0,w.useCallback)((t,n)=>{if(t===`view`)c(n.path);else if(t===`new-file`||t===`new-folder`)b({type:t===`new-file`?`file`:`folder`,path:n.path}),S(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Vm(e,n.path).then(e=>{e.ok?(c(e=>e===n.path?null:e),f(e=>e+1)):alert(`delete failed: ${e.error}`)})}},[e]),k=(0,w.useCallback)(t=>PI(e,t.path)?[]:t.type===`dir`?[{label:`New file`,icon:(0,q.jsx)(pe,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,q.jsx)(ye,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,q.jsx)(st,{size:12}),action:`delete`,danger:!0}]:FI(e,t.path)?[]:[{label:`View`,icon:(0,q.jsx)(ue,{size:12}),action:`view`},{label:`Delete`,icon:(0,q.jsx)(st,{size:12}),action:`delete`,danger:!0}],[e]),A=(0,w.useCallback)(t=>Mm(e,t).then(e=>e),[e]),j=(0,w.useCallback)((t,n,r,i)=>{if(t.type===`dir`)return PI(e,t.path)?`w-full py-1.5 flex items-center gap-1.5 bg-amber-50/40 hover:bg-amber-50 text-left border-y border-amber-200/60 mt-1`:`w-full py-1 flex items-center gap-1 hover:bg-gray-50 text-left`;let a=FI(e,t.path);return`w-full py-1 flex items-center gap-2 text-left `+(i?`bg-gray-100`:a?`hover:bg-amber-50/50`:`hover:bg-gray-50`)},[e]),M=h.trim().toLowerCase(),N=M.length>0,P=N?a.filter(e=>e.path.toLowerCase().includes(M)).slice(0,60):[],F=(0,q.jsxs)(`aside`,{className:`w-64 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-9 flex items-center gap-1 border-b border-gray-200`,children:[C&&(0,q.jsx)(`button`,{onClick:()=>v(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,q.jsx)(Be,{size:14})}),(0,q.jsx)(NI,{}),(0,q.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),placeholder:`search files…`,className:`flex-1 min-w-0 bg-transparent outline-none text-[12px] text-gray-700 placeholder:text-gray-400`}),(0,q.jsx)(`button`,{onClick:()=>m(!0),className:`text-gray-500 hover:text-gray-900 px-1.5 rounded hover:bg-gray-100 text-xs`,title:`new file`,children:`+`}),(0,q.jsx)(`button`,{onClick:()=>f(e=>e+1),className:`text-gray-500 hover:text-gray-900 px-1.5 rounded hover:bg-gray-100 text-xs`,title:`refresh`,children:`↻`})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:N?P.length===0?(0,q.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no matches`}):P.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{c(e.path),C&&v(!1)},className:`w-full px-3 py-1.5 flex items-center gap-2 text-left `+(s===e.path?`bg-gray-100`:`hover:bg-gray-50`),title:e.path,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:`📄`}),(0,q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-gray-900`,children:e.path})]},e.path)):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(WF,{treeId:`vault-${e}`,entries:r,onPick:e=>{c(e),C&&v(!1)},picked:s,onLoadChildren:A,getContextActions:k,onAction:O,nodeClassName:j,reloadKey:d}),r.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`empty · click + 创建第一个文件`})]})}),(0,q.jsx)(`div`,{className:`px-3 h-9 border-t border-gray-200 flex items-center text-[11px] text-gray-500`,children:kI[e]}),e===`knowledge`&&(0,q.jsx)(AI,{resource:e}),e===`notes`&&(0,q.jsx)(jI,{onRefreshed:()=>f(e=>e+1)})]});return(0,q.jsxs)(`div`,{className:`flex h-full w-full`,children:[C?(0,q.jsx)(q.Fragment,{children:_?(0,q.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>v(!1),children:[(0,q.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:F})]}):(0,q.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,q.jsx)(`button`,{type:`button`,onClick:()=>v(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`open file tree`,children:(0,q.jsx)(Ve,{size:16})})})}):F,(0,q.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white min-h-0`,children:s?(0,q.jsx)(RI,{vault:e,path:s,onSelect:c,onSaved:()=>f(e=>e+1),initialEditing:n}):(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-[13px] text-gray-400 italic`,children:`选一个文件,或点 + 新建`})}),p&&(0,q.jsx)(zI,{vault:e,onClose:()=>m(!1),onCreate:E}),y&&(0,q.jsx)(II,{type:y.type,parentPath:y.path,value:x,onChange:S,onSubmit:D,onCancel:()=>b(null)})]})}function NI(){return(0,q.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,className:`text-gray-400 shrink-0`,children:(0,q.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,d:`M11 11l3 3M7 12.5a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z`})})}function PI(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).length>0}function FI(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).includes(`/`)}function II({type:e,parentPath:t,value:n,onChange:r,onSubmit:i,onCancel:a}){return(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:a,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,q.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[e===`file`?`New file`:`New folder`,` in `,(0,q.jsx)(`span`,{className:`font-mono text-[13px]`,children:t||`root`})]}),(0,q.jsx)(`input`,{autoFocus:!0,type:`text`,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&i(),e.key===`Escape`&&a()},placeholder:e===`file`?`filename.md`:`folder-name`,className:`w-full px-3 py-2 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,q.jsx)(`button`,{onClick:a,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,q.jsx)(`button`,{onClick:()=>n.trim()&&i(),disabled:!n.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`create`})]})]})})}function LI(e){return/(^|\/)secrets\//.test(e)||e===`secrets`}function RI({vault:e,path:t,onSelect:n,onSaved:r,initialEditing:i}){let a=Og(),o=Gn(),[s,c]=(0,w.useState)(``),[l,u]=(0,w.useState)(``),[d,f]=(0,w.useState)(i??!1),[p,m]=(0,w.useState)(!1),[h,g]=(0,w.useState)([]),[_,v]=(0,w.useState)(null),[y,b]=(0,w.useState)(!1),[x,S]=(0,w.useState)(!1),[C,T]=(0,w.useState)(!1),[E,D]=(0,w.useState)(!1),O=_P(),k=(0,w.useRef)(i);(0,w.useEffect)(()=>{k.current?k.current=!1:f(!1),S(!1),v(null),T(!1),D(!1),Pm(e,t).then(e=>{let t=e?.content??``;c(t),u(t),D(!!e?.secret)}),Hm(e,t).then(g)},[e,t]);let A=LI(t)||E,j=t.endsWith(`.md`),M=e!==`knowledge`,N=!A,P=e===`notes`&&!A,F=A?l.length>0:l!==s,I=(0,w.useCallback)(async()=>{if(!(!F||p)){m(!0);try{let n=await Fm(e,t,l);if(n.ok){if(A?(c(``),u(``)):c(l),v(n.commit??null),f(!1),r(),Hm(e,t).then(g),e===`notes`){let e=await Im();e.ok||(e.conflict?alert(`Saved locally, but it conflicts with the remote (${(e.files??[]).join(`, `)}). Your edit is kept — resolve by taking the remote, or in a loop.`):alert(`Saved locally, but push to remote failed: ${e.error??`unknown`}`))}else if(e===`personal`){let e=await am();e.ok||(e.conflict?alert(`Saved locally, but it conflicts with the remote (${(e.files??[]).join(`, `)}). Your edit is kept — pull first (re-open Personal) or resolve in a loop.`):alert(`Saved locally, but push to remote failed: ${e.error??`unknown`}`))}}else alert(`save failed: ${n.error}`)}finally{m(!1)}}},[e,t,l,F,p,r,A]),L=()=>{f(!0),j&&S(!0)},R=()=>{u(s),f(!1)},z=async()=>{o(`/loop/${(await a.createLoop({title:`edit ${e}/${t}`})).id}`)},B=async()=>{o(`/loop/${(await a.createLoop({title:`distill ${t} → knowledge`,knowledgeRw:!0})).id}`)},V=e=>{n([t.replace(/[^/]+$/,``)+e+`.md`,e+`.md`,e][0].replace(/^\//,``))};return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`header`,{className:`px-3 md:px-5 h-10 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] min-w-0`,children:[(0,q.jsx)(`span`,{className:`text-gray-500 shrink-0`,children:A?`🔒`:`📄`}),(0,q.jsx)(`span`,{className:`font-mono text-[12px] text-gray-500 truncate`,children:t}),_&&!F&&!d&&(0,q.jsxs)(`span`,{className:`hidden md:inline text-[10px] text-emerald-700 font-mono`,children:[`commit `,_]})]}),(0,q.jsx)(`div`,{className:`flex items-center gap-1 md:gap-2 text-xs text-gray-500`,children:d?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{onClick:R,className:`px-2.5 h-7 rounded text-xs text-gray-600 hover:bg-gray-100`,children:`cancel`}),(0,q.jsx)(`button`,{onClick:I,disabled:!F||p,className:`px-2.5 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:p?`saving…`:`save`})]}):(0,q.jsxs)(q.Fragment,{children:[P&&(0,q.jsxs)(`button`,{onClick:B,className:`px-2.5 h-7 rounded text-xs bg-amber-100 text-amber-900 hover:bg-amber-200 flex items-center gap-1`,title:`open a loop to distill this notes file into knowledge`,children:[(0,q.jsx)(`span`,{children:`↑`}),(0,q.jsx)(`span`,{children:`distill`})]}),N&&(0,q.jsxs)(`button`,{onClick:z,className:P?`px-2.5 h-7 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-900 flex items-center gap-1`:`px-2.5 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700 flex items-center gap-1`,title:`open a new loop with AI assist for this file`,children:[(0,q.jsx)(`span`,{children:`↻`}),(0,q.jsx)(`span`,{children:`edit by loop`})]}),M&&(0,q.jsx)(`button`,{onClick:L,className:`px-2.5 h-7 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-900`,title:`direct edit (fastpath)`,children:`edit`}),O&&j&&(0,q.jsxs)(`button`,{onClick:()=>b(e=>!e),className:`px-2.5 h-7 rounded text-xs border ${y?`bg-gray-900 text-white`:`border-gray-200 hover:bg-gray-100 text-gray-900`}`,title:`toggle backlinks`,children:[`⇄ `,h.length]})]})})]}),d?A?(0,q.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{className:`text-amber-700`,children:`🔒`}),(0,q.jsx)(`span`,{children:`new value · saved encrypted`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>T(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,q.jsx)(CI,{path:t,value:l,onChange:u})})})]}):j&&!x?(0,q.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col md:flex-row`:`flex-1 min-h-0 min-w-0 flex flex-col md:flex-row`,children:[(0,q.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 border-r border-gray-200 flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{children:`source · markdown`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>S(!0),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to WYSIWYG editor`,children:`wysiwyg`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>T(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,q.jsx)(CI,{path:t,value:l,onChange:u})})})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,q.jsx)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center text-[11px] text-gray-500`,children:`preview`}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto px-6 py-4`,children:(0,q.jsx)(`div`,{className:`max-w-[760px]`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading preview...`}),children:(0,q.jsx)(wI,{text:l,onWikilink:V})})})})]})]}):j?(0,q.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{children:`wysiwyg · milkdown`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>S(!1),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to source editor`,children:`source`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>T(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,q.jsx)(TI,{value:l,onChange:u})})})]}):(0,q.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,q.jsxs)(`span`,{children:[`source · `,t.includes(`.`)?t.split(`.`).pop():`text`]}),t.endsWith(`.json`)&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>{try{u(JSON.stringify(JSON.parse(l),null,2))}catch(e){alert(`Invalid JSON: `+(e?.message??`parse error`))}},className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Format JSON`,children:`format`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>T(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,q.jsx)(CI,{path:t,value:l,onChange:u})})})]}):(0,q.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:[(0,q.jsx)(`article`,{className:`flex-1 min-h-0 overflow-auto px-4 md:px-8 py-4 md:py-6`,children:(0,q.jsx)(`div`,{className:`max-w-[760px]`,children:A?(0,q.jsxs)(`div`,{className:`font-sans text-[13px] text-gray-600 leading-relaxed`,children:[(0,q.jsx)(`div`,{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded bg-amber-50 border border-amber-200 text-amber-800 text-[12px] font-medium`,children:`encrypted · value hidden by design`}),(0,q.jsxs)(`div`,{className:`mt-3 text-[12px] text-gray-500`,children:[`Click `,(0,q.jsx)(`b`,{children:`edit`}),` to overwrite. The current value is never returned by the server, so editing means typing a new replacement — there is no decrypt-and-view.`]})]}):j?(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading...`}),children:(0,q.jsx)(wI,{text:s,onWikilink:V})}):(0,q.jsx)(`pre`,{className:`font-mono text-[12.5px] leading-relaxed whitespace-pre-wrap text-gray-900`,children:s||(0,q.jsx)(`span`,{className:`text-gray-400 italic`,children:`(empty)`})})})}),j&&!O&&(0,q.jsxs)(`aside`,{className:`w-64 shrink-0 border-l border-gray-200 bg-gray-50 overflow-auto`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,q.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length})]}),h.length===0?(0,q.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,q.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,q.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,q.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]}),O&&j&&y&&(0,q.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>b(!1),children:[(0,q.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,q.jsxs)(`div`,{className:`absolute right-0 top-0 bottom-0 w-64 max-w-[80vw] bg-gray-50 border-l border-gray-200 shadow-xl overflow-auto`,onClick:e=>e.stopPropagation(),children:[(0,q.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,q.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length}),(0,q.jsx)(`button`,{onClick:()=>b(!1),className:`ml-2 text-gray-400 hover:text-gray-700 px-1`,title:`close backlinks`,children:`✕`})]}),h.length===0?(0,q.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,q.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{n(e.path),b(!1)},className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,q.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,q.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]})]})]})]})}function zI({vault:e,onClose:t,onCreate:n}){let[r,i]=(0,w.useState)(``);return(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,q.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[`new file in `,e,`/`]}),(0,q.jsx)(`input`,{autoFocus:!0,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`loopat/new-doc.md`,className:`w-full px-3 py-2 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,q.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`relative path. directories created as needed.`}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,q.jsx)(`button`,{onClick:t,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,q.jsx)(`button`,{onClick:()=>r.trim()&&n(r.trim()),disabled:!r.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`create`})]})]})})}function BI(){let[e,t]=(0,w.useState)(null),[n,r]=(0,w.useState)([]),[i,a]=(0,w.useState)(!1),[o,s]=(0,w.useState)(null),c=(0,w.useCallback)(async()=>{let e=await Um();t(e),r(e.repos)},[]);(0,w.useEffect)(()=>{c()},[c]);let l=e!==null&&JSON.stringify(n)!==JSON.stringify(e.repos),u=()=>r(e=>[...e,{name:``,git:``}]),d=(e,t,n)=>r(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r)),f=e=>r(t=>t.filter((t,n)=>n!==e));return e?(0,q.jsx)(`article`,{className:`flex-1 min-w-0 overflow-auto p-5`,children:(0,q.jsxs)(`div`,{className:`max-w-2xl flex flex-col gap-5`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900`,children:`Repo roster`}),(0,q.jsxs)(`p`,{className:`text-[12px] text-gray-500 leading-relaxed mt-1`,children:[`Personal — saved straight to your own`,` `,(0,q.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[11px]`,children:`.loopat/config.json`}),`. Repos are cloned on demand when a loop selects one.`]})]}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`repos`}),n.length===0&&(0,q.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:`No repos yet.`}),n.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`input`,{value:e.name,onChange:e=>d(t,`name`,e.target.value),placeholder:`name`,className:`w-40 px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,q.jsx)(`input`,{value:e.git,onChange:e=>d(t,`git`,e.target.value),placeholder:`git@…/repo.git`,className:`flex-1 px-2 py-1.5 text-sm font-mono border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>f(t),className:`px-2 py-1.5 text-gray-400 hover:text-red-600`,title:`remove`,children:`✕`})]},t)),(0,q.jsx)(`button`,{type:`button`,onClick:u,className:`self-start text-[12px] text-gray-600 hover:text-gray-900 border border-gray-200 rounded px-2 py-1`,children:`+ add repo`})]}),o&&(0,q.jsx)(`div`,{className:`text-[12px] rounded px-2 py-1.5 border ${o.ok?`text-emerald-700 bg-emerald-50 border-emerald-200`:`text-red-700 bg-red-50 border-red-200`}`,children:o.text}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:async()=>{a(!0),s(null);let e=await Wm({repos:n.map(e=>({name:e.name.trim(),git:e.git.trim()})).filter(e=>e.name&&e.git)});a(!1),e.ok?(s({ok:!0,text:`Saved.`}),await c()):s({ok:!1,text:`Save failed: `+(e.error??``)})},disabled:!l||i,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:i?`Saving…`:`Save`}),l&&(0,q.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`unsaved changes`})]})]})}):(0,q.jsx)(`div`,{className:`p-6 text-sm text-gray-400`,children:`loading…`})}function VI(){var e=[...arguments];return(0,w.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var HI=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function UI(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function WI(e){return`nodeType`in e}function GI(e){return e?UI(e)?e:WI(e)?e.ownerDocument?.defaultView??window:window:window}function KI(e){let{Document:t}=GI(e);return e instanceof t}function qI(e){return UI(e)?!1:e instanceof GI(e).HTMLElement}function JI(e){return e instanceof GI(e).SVGElement}function YI(e){return e?UI(e)?e.document:WI(e)?KI(e)?e:qI(e)||JI(e)?e.ownerDocument:document:document:document}var XI=HI?w.useLayoutEffect:w.useEffect;function ZI(e){let t=(0,w.useRef)(e);return XI(()=>{t.current=e}),(0,w.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function QI(){let e=(0,w.useRef)(null);return[(0,w.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,w.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function $I(e,t){t===void 0&&(t=[e]);let n=(0,w.useRef)(e);return XI(()=>{n.current!==e&&(n.current=e)},t),n}function eL(e,t){let n=(0,w.useRef)();return(0,w.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function tL(e){let t=ZI(e),n=(0,w.useRef)(null);return[n,(0,w.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function nL(e){let t=(0,w.useRef)();return(0,w.useEffect)(()=>{t.current=e},[e]),t.current}var rL={};function iL(e,t){return(0,w.useMemo)(()=>{if(t)return t;let n=rL[e]==null?0:rL[e]+1;return rL[e]=n,e+`-`+n},[e,t])}function aL(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var oL=aL(1),sL=aL(-1);function cL(e){return`clientX`in e&&`clientY`in e}function lL(e){if(!e)return!1;let{KeyboardEvent:t}=GI(e.target);return t&&e instanceof t}function uL(e){if(!e)return!1;let{TouchEvent:t}=GI(e.target);return t&&e instanceof t}function dL(e){if(uL(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return cL(e)?{x:e.clientX,y:e.clientY}:null}var fL=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[fL.Translate.toString(e),fL.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),pL=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function mL(e){return e.matches(pL)?e:e.querySelector(pL)}var hL={display:`none`};function gL(e){let{id:t,value:n}=e;return w.createElement(`div`,{id:t,style:hL},n)}function _L(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return w.createElement(`div`,{id:t,style:{position:`fixed`,top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(100%)`,whiteSpace:`nowrap`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function vL(){let[e,t]=(0,w.useState)(``);return{announce:(0,w.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var yL=(0,w.createContext)(null);function bL(e){let t=(0,w.useContext)(yL);(0,w.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function xL(){let[e]=(0,w.useState)(()=>new Set),t=(0,w.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,w.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var SL={draggable:`
|
|
90
|
+
`),n=``,r=[],i=null,a=0,o=0;for(let e of t){if(e.startsWith(`diff `)){n=e;continue}if(e.startsWith(`+++ `)||e.startsWith(`--- `))continue;let t=e.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/);if(t){i&&r.push(i),a=parseInt(t[1],10),o=parseInt(t[3],10),i={header:e,lines:[]};continue}i&&(e.startsWith(`+`)?(i.lines.push({type:`add`,oldNum:null,newNum:o,text:e.slice(1)}),o++):e.startsWith(`-`)?(i.lines.push({type:`del`,oldNum:a,newNum:null,text:e.slice(1)}),a++):(i.lines.push({type:`ctx`,oldNum:a,newNum:o,text:e.startsWith(` `)?e.slice(1):e}),a++,o++))}return i&&r.push(i),{fileHeader:n,hunks:r}}function QF({filePath:e,diff:t,loading:n,onClose:r}){let i=null;if(t)try{i=ZF(t)}catch{}return(0,q.jsx)(Fg,{open:!0,onOpenChange:e=>{e||r()},children:(0,q.jsxs)(Rg,{className:`sm:max-w-4xl max-h-[85vh] flex flex-col bg-white p-0 gap-0`,showCloseButton:!1,children:[(0,q.jsxs)(`div`,{className:`px-4 py-2.5 border-b border-gray-200 shrink-0 flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-mono text-gray-900 truncate flex-1`,children:e}),(0,q.jsx)(`button`,{onClick:r,className:`text-gray-400 hover:text-gray-700 text-sm leading-none`,children:`✕`})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:n?(0,q.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-gray-400 gap-2`,children:[(0,q.jsx)(Ae,{className:`animate-spin`,size:16}),(0,q.jsx)(`span`,{className:`text-sm`,children:`loading diff...`})]}):i?(0,q.jsx)(`div`,{className:`text-xs font-mono leading-5`,children:i.hunks.map((e,t)=>(0,q.jsxs)(`div`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,q.jsx)(`div`,{className:`px-4 py-1 bg-blue-50/60 text-blue-700 border-b border-blue-100 sticky top-0`,children:e.header}),e.lines.map((e,t)=>{let n=e.type===`add`,r=e.type===`del`;return(0,q.jsxs)(`div`,{className:`flex `+(n?`bg-emerald-50`:r?`bg-red-50`:``),children:[(0,q.jsx)(`span`,{className:`w-14 shrink-0 text-right pr-3 py-px text-gray-300 select-none border-r border-gray-200 bg-gray-50`,children:e.oldNum??``}),(0,q.jsx)(`span`,{className:`w-14 shrink-0 text-right pr-3 py-px select-none border-r border-gray-200 `+(n?`bg-emerald-100/70 text-emerald-700`:r?`bg-red-100/70 text-red-500`:`text-gray-300 bg-gray-50`),children:e.newNum??``}),(0,q.jsxs)(`span`,{className:`pl-3 py-px whitespace-pre-wrap break-all flex-1 `+(n?`text-emerald-800`:r?`text-red-700`:`text-gray-700`),children:[(0,q.jsx)(`span`,{className:`select-none`,children:n?`+`:r?`−`:` `}),e.text]})]},t)})]},t))}):(0,q.jsx)(`div`,{className:`py-16 text-center text-sm text-gray-400`,children:`empty diff`})})]})})}var $F={A:{label:`A`,color:`text-emerald-600`},M:{label:`M`,color:`text-amber-600`},D:{label:`D`,color:`text-red-600`},R:{label:`R`,color:`text-purple-600`},"?":{label:`?`,color:`text-gray-400`}};function eI({loopId:e,onClose:t,onPickFile:n}){let[r,i]=(0,w.useState)(null),[a,o]=(0,w.useState)(!1),[s,c]=(0,w.useState)(!0),[l,u]=(0,w.useState)(!0),[d,f]=(0,w.useState)(null),[p,m]=(0,w.useState)(``),[h,g]=(0,w.useState)(``),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(null),[x,S]=(0,w.useState)([]),[C,T]=(0,w.useState)(!1),[E,D]=(0,w.useState)(!0),O=(0,w.useCallback)(async()=>{o(!0),f(null);try{i(await wh(e))}catch{f(`Failed to load git status`)}finally{o(!1)}},[e]),k=(0,w.useCallback)(async()=>{T(!0);try{S(await kh(e,50))}catch{}finally{T(!1)}},[e]);(0,w.useEffect)(()=>{O(),k()},[O,k]);let A=async()=>{r?.unstaged.length&&await Eh(e,r.unstaged.map(e=>e.path))&&O()},j=async()=>{r?.staged.length&&await Eh(e,r.staged.map(e=>e.path),!0)&&O()},M=async t=>{await Eh(e,[t])&&O()},N=async t=>{await Eh(e,[t],!0)&&O()},P=async t=>{await Dh(e,t)&&O()},F=async()=>{if(!h.trim())return;v(!0),b(null);let t=await Oh(e,h.trim());v(!1),t.ok?(g(``),O(),k()):b(t.error??`Commit failed`)},I=p.trim().toLowerCase(),L=r?r.unstaged.filter(e=>!I||e.path.toLowerCase().includes(I)):[],R=r?r.staged.filter(e=>!I||e.path.toLowerCase().includes(I)):[],z=!r||r.unstaged.length===0&&r.staged.length===0;return(0,q.jsxs)(`aside`,{className:`w-full h-full min-w-0 bg-white flex flex-col`,children:[(0,q.jsxs)(`header`,{className:`px-3 h-8 shrink-0 border-b border-gray-200 flex items-center gap-1 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{className:`tracking-wide`,children:`Git Changes`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>{O(),k()},className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,title:`refresh`,children:(0,q.jsx)(qe,{size:13,className:a||C?`animate-spin`:``})}),(0,q.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:t,title:`close`,children:`✕`})]}),(0,q.jsxs)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:[(0,q.jsx)(`textarea`,{placeholder:`Commit message...`,value:h,onChange:e=>{g(e.target.value),b(null)},rows:2,className:`w-full px-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300 resize-none mb-1.5`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`button`,{onClick:F,disabled:_||!h.trim(),className:`flex-1 flex items-center justify-center gap-1 px-2 py-1 text-[11px] rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:[(0,q.jsx)(Se,{size:12}),_?`Committing...`:`Commit`]}),r&&r.staged.length>0&&(0,q.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[r.staged.length,` staged`]})]}),y&&(0,q.jsx)(`div`,{className:`mt-1 text-[10px] text-red-500`,children:y})]}),(0,q.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:(0,q.jsx)(`input`,{type:`text`,placeholder:`Filter files...`,value:p,onChange:e=>m(e.target.value),className:`w-full px-2 py-1 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300`})}),(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto text-[13px]`,children:[(0,q.jsxs)(`div`,{className:`overflow-auto py-2`,children:[a&&!r&&(0,q.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`loading git status...`}),d&&(0,q.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-red-500`,children:d}),z&&!a&&(0,q.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`no changes`}),L.length>0&&(0,q.jsx)(nI,{title:`Unstaged Changes`,count:L.length,open:s,onToggle:()=>c(e=>!e),bulkAction:{label:`Stage all`,icon:(0,q.jsx)(We,{size:12}),onClick:A},children:L.map(t=>(0,q.jsx)(rI,{file:t,loopId:e,staged:!1,onStage:()=>M(t.path),onUnstage:()=>N(t.path),onDiscard:()=>P(t.path),onEdit:e=>n(e),onRefresh:O},t.path))}),R.length>0&&(0,q.jsx)(nI,{title:`Staged Changes`,count:R.length,open:l,onToggle:()=>u(e=>!e),bulkAction:{label:`Unstage all`,icon:(0,q.jsx)(Ie,{size:12}),onClick:j},children:R.map(t=>(0,q.jsx)(rI,{file:t,loopId:e,staged:!0,onStage:()=>M(t.path),onUnstage:()=>N(t.path),onDiscard:()=>P(t.path),onEdit:e=>n(e),onRefresh:O},t.path))})]}),(0,q.jsxs)(`div`,{className:`border-t border-gray-200`,children:[(0,q.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>D(e=>!e),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&D(e=>!e)},className:`w-full px-3 py-1.5 flex items-center gap-1.5 hover:bg-gray-50 text-left cursor-pointer select-none`,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:E?`▾`:`▸`}),(0,q.jsx)(xe,{size:12,className:`text-gray-500`}),(0,q.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:`History`}),(0,q.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,x.length,`)`]})]}),E&&(0,q.jsx)(`div`,{className:`px-2 pb-2 max-h-64 overflow-auto`,children:C?(0,q.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`loading history...`}):x.length===0?(0,q.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`no commits`}):(0,q.jsx)(tI,{commits:x})})]})]})]})}function tI({commits:e}){let t=[`bg-blue-500`,`bg-emerald-500`,`bg-purple-500`,`bg-amber-500`,`bg-pink-500`,`bg-cyan-500`],n=new Map,r=0,i=e=>(n.has(e)||(n.set(e,t[r%t.length]),r++),n.get(e));return(0,q.jsx)(`div`,{className:`space-y-0`,children:e.map((t,n)=>{let r=t.branch??t.branches[0]??null,a=r?i(r):`bg-gray-400`,o=n===0,s=new Date(t.date).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),c=new Date(t.date).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`});return(0,q.jsxs)(`div`,{className:`group/graph-row flex items-start gap-2 py-0.5 px-1.5 rounded hover:bg-gray-100 cursor-default text-[11px]`,title:`${t.subject}\n${t.author} · ${s} ${c}`,children:[(0,q.jsxs)(`div`,{className:`flex flex-col items-center shrink-0`,children:[(0,q.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${a} ring-2 ring-white ${o?`ring-blue-300`:``}`}),n<e.length-1&&(0,q.jsx)(`div`,{className:`w-0.5 h-10 ${a} opacity-10`})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400 truncate`,children:t.shortHash}),o&&(0,q.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-blue-100 text-blue-700 font-medium`,children:`HEAD`}),t.branches.slice(0,2).map(e=>(0,q.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-emerald-100 text-emerald-700 font-medium truncate max-w-[60px]`,children:e},e)),t.tags.map(e=>(0,q.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-purple-100 text-purple-700 font-medium`,children:e},e))]}),(0,q.jsx)(`div`,{className:`text-gray-700 truncate`,children:t.subject}),(0,q.jsxs)(`div`,{className:`text-gray-400 text-[10px]`,children:[t.author,` · `,s]})]})]},t.hash)})})}function nI({title:e,count:t,open:n,onToggle:r,bulkAction:i,children:a}){return(0,q.jsxs)(`div`,{className:`mb-2`,children:[(0,q.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:r,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&r()},className:`w-full px-3 py-1.5 flex items-center gap-1.5 hover:bg-gray-50 text-left group/section cursor-pointer select-none`,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:n?`▾`:`▸`}),(0,q.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:e}),(0,q.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,t,`)`]}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i.onClick()},className:`opacity-100 sm:opacity-0 sm:group-hover/section:opacity-100 transition-opacity px-1 py-0.5 rounded hover:bg-gray-200 text-gray-500 hover:text-gray-900 flex items-center gap-0.5`,title:i.label,children:i.icon})]}),n&&(0,q.jsx)(`div`,{children:a})]})}function rI({file:e,loopId:t,staged:n,onStage:r,onUnstage:i,onDiscard:a,onEdit:o,onRefresh:s}){let[c,l]=(0,w.useState)(!1),[u,d]=(0,w.useState)(null),[f,p]=(0,w.useState)(!1),[m,h]=(0,w.useState)(!1),[g,_]=(0,w.useState)(null),v=(0,w.useRef)(null);(0,w.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&_(null)};if(g)return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let y=async()=>{e.isBinary||(l(!0),u===null&&(p(!0),d(await Th(t,e.path,n)??``),p(!1)))},b=e=>{e.preventDefault(),_({x:e.clientX,y:e.clientY})},x=`workdir/${e.path}`,S=[{label:`Open in Editor`,icon:(0,q.jsx)(Ue,{size:12}),onClick:()=>{o(x),_(null)}},{label:`View Diff`,icon:(0,q.jsx)(Ye,{size:12}),onClick:()=>{y(),_(null)}},{separator:!0,label:``,onClick:()=>{}},n?{label:`Unstage`,icon:(0,q.jsx)(Ie,{size:12}),onClick:()=>{i(),_(null)}}:{label:`Stage`,icon:(0,q.jsx)(We,{size:12}),onClick:()=>{r(),_(null)}},!n&&{label:`Discard Changes`,icon:(0,q.jsx)(lt,{size:12}),onClick:()=>{h(!0),_(null)},danger:!0}].filter(Boolean),C=$F[e.status]??{label:e.status,color:`text-gray-500`},T=e.path.lastIndexOf(`/`),E=T>=0?e.path.slice(T+1):e.path,D=T>=0?e.path.slice(0,T+1):null;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`group/row relative flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50`,onContextMenu:b,children:[(0,q.jsx)(`span`,{className:`w-5 text-center text-[11px] font-mono font-semibold ${C.color}`,children:C.label}),(0,q.jsxs)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] font-mono`,children:[(0,q.jsx)(`span`,{className:`text-gray-900`,children:E}),D&&(0,q.jsx)(`span`,{className:`text-gray-400 ml-0.5`,children:D})]}),!e.isBinary&&(e.additions>0||e.deletions>0)&&(0,q.jsxs)(`span`,{className:`text-[11px] font-mono flex items-center gap-0.5 shrink-0`,children:[(0,q.jsxs)(`span`,{className:`text-emerald-600`,children:[`+`,e.additions]}),(0,q.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]}),(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 opacity-100 sm:opacity-0 sm:group-hover/row:opacity-100 transition-opacity shrink-0`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>o(x),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-blue-600 rounded`,title:`edit file`,children:(0,q.jsx)(Ue,{size:13})}),n&&(0,q.jsx)(`button`,{type:`button`,onClick:y,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-gray-700 rounded`,title:`view diff`,disabled:e.isBinary,children:(0,q.jsx)(Ye,{size:13})}),n?(0,q.jsx)(`button`,{type:`button`,onClick:i,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-amber-600 rounded`,title:`unstage`,children:(0,q.jsx)(Ie,{size:13})}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>h(!0),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-red-500 rounded`,title:`discard changes`,children:(0,q.jsx)(lt,{size:13})}),(0,q.jsx)(`button`,{type:`button`,onClick:r,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-emerald-600 rounded`,title:`stage`,children:(0,q.jsx)(We,{size:13})})]})]})]}),g&&(0,q.jsx)(`div`,{ref:v,className:`fixed z-50 min-w-[160px] py-1 bg-white border border-gray-200 rounded-md shadow-lg text-[12px]`,style:{left:g.x,top:g.y},children:S.map((e,t)=>e.separator?(0,q.jsx)(`div`,{className:`my-1 border-t border-gray-100`},t):(0,q.jsxs)(`button`,{onClick:e.onClick,className:`w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-gray-100 ${e.danger?`text-red-600`:`text-gray-700`}`,children:[e.icon,(0,q.jsx)(`span`,{children:e.label})]},t))}),c&&(0,q.jsx)(QF,{filePath:e.path,diff:u,loading:f,onClose:()=>l(!1)}),m&&(0,q.jsx)(Fg,{open:!0,onOpenChange:e=>{e||h(!1)},children:(0,q.jsxs)(Rg,{className:`sm:max-w-sm bg-white p-5 gap-4`,showCloseButton:!1,children:[(0,q.jsx)(zg,{children:(0,q.jsx)(Bg,{className:`text-sm`,children:`Discard changes`})}),(0,q.jsx)(`p`,{className:`text-[13px] text-gray-600 break-all font-mono`,children:e.path}),(0,q.jsx)(`p`,{className:`text-[12px] text-gray-500`,children:e.status===`?`?`This file is untracked and will be deleted.`:`This will permanently discard all changes to this file. This action cannot be undone.`}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,q.jsx)(`button`,{onClick:()=>h(!1),className:`px-3 py-1.5 text-xs rounded bg-gray-100 text-gray-700 hover:bg-gray-200`,children:`Cancel`}),(0,q.jsx)(`button`,{onClick:()=>{h(!1),a()},className:`px-3 py-1.5 text-xs rounded bg-red-600 text-white hover:bg-red-700`,children:`Discard`})]})]})})]})}function iI(e){return e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:`standard`}function aI({loop:e,open:t,onClose:n,onSaved:r}){let[i,a]=(0,w.useState)(null),[o,s]=(0,w.useState)(e.shareEnabled??!1),[c,l]=(0,w.useState)(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),[u,d]=(0,w.useState)(e.shareAlias??``),[f,p]=(0,w.useState)(e.sharePort??3e3),[m,h]=(0,w.useState)(e.shareExternalPort??1e4),[g,_]=(0,w.useState)(e.shareProtocol??`tcp`),[v,y]=(0,w.useState)(null),[b,x]=(0,w.useState)(``),[S,C]=(0,w.useState)(!1),[T,E]=(0,w.useState)(!1),[D,O]=(0,w.useState)(!1),[k,A]=(0,w.useState)(``),[j,M]=(0,w.useState)(!1),[N,P]=(0,w.useState)(``),[F,I]=(0,w.useState)(``),[L,R]=(0,w.useState)(iI(e)),[z,B]=(0,w.useState)(null),H=e.id.slice(0,8),U=!!(i&&i.serveEnabled),W=!!(i&&i.serveDynamicEnabled),ee=!!(i&&i.serveEphemeralEnabled),K=[U,W,ee].filter(Boolean).length>1,te=U&&!W&&!ee,ne=!U&&W&&!ee,re=!U&&!W&ⅇ(0,w.useEffect)(()=>{t&&(Uh().then(a),s(e.shareEnabled??!1),l(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),d(e.shareAlias??``),p(e.sharePort??3e3),h(e.shareExternalPort??1e4),_(e.shareProtocol??`tcp`),R(iI(e)),y(null),x(``),A(``),B(null))},[t,e]),(0,w.useEffect)(()=>{if(!t||!(re||K&&L===`ephemeral`)||!e.shareEnabled||e.shareMode!==`ephemeral`)return;let n=!1,r=async()=>{let t=await Wh(e.id);n||B(t.port)};r();let i=setInterval(r,3e3);return()=>{n=!0,clearInterval(i)}},[t,L,re,K,e.id,e.shareEnabled,e.shareMode]),(0,w.useEffect)(()=>{!t||!i||i.serveDynamicEnabled&&(e.shareEnabled&&e.shareExternalPort||!e.shareEnabled&&!e.shareExternalPort&&Kh().then(e=>{e.port&&h(e.port)}))},[t,i,e.shareEnabled,e.shareExternalPort]),(0,w.useEffect)(()=>{t&&Jh(H,e.id).then(e=>{e.available?O(!1):(O(!0),x(`ID "${H}" is already in use. Please set an alias.`))})},[t,H,e.id]),(0,w.useEffect)(()=>{if(!u||!t){y(null),x(``);return}let n=setTimeout(async()=>{let t=await Jh(u,e.id);y(t.available),x(t.reason??``)},300);return()=>clearTimeout(n)},[u,t,e.id]);let ae=u||H,oe=i?.https?`https`:`http`,se=i?.withPort?`:${i.displayPort}`:``,ce=i?`${oe}://${ae}${i.baseUrl}${se}`:``,le=i?.serveDynamicDomain||i?.ip||`<host-ip>`,ue=g===`static`?`http://${le}:${m}`:`tcp://${le}:${m}`,de=i?.serveEphemeralDomain||i?.ip||`<host-ip>`,fe=z?`${g===`udp`?`udp`:`tcp`}://${de}:${z}`:`(no active port — save & wait for container restart)`,pe=ne||K&&L===`direct`&&W&&!re,me=re||K&&L===`ephemeral`,he=me?fe:pe?ue:ce;(0,w.useEffect)(()=>{if(!t||!pe)return;let n=setTimeout(async()=>{M(!0);let t=await qh(m,e.id);M(!1),t.available?A(``):A(t.reason??`Port unavailable`)},400);return()=>clearTimeout(n)},[m,t,c,e.id]);let ge=async()=>{if(E(!0),pe){let t=await qh(m,e.id);if(!t.available){A(t.reason??`Port unavailable`),E(!1);return}}let t={shareEnabled:o};o?me?(t.shareMode=`ephemeral`,t.sharePort=f,t.shareProtocol=g===`static`?`tcp`:g,t.shareAlias=void 0,t.shareExternalPort=void 0):pe?(t.shareMode=`port`,t.sharePort=f,t.shareExternalPort=m,t.shareProtocol=g,t.shareAlias=void 0):(t.shareMode=c,t.shareAlias=u.trim()||void 0,c===`port`&&(t.sharePort=f),t.shareExternalPort=void 0,t.shareProtocol=void 0):(t.shareMode=void 0,t.shareAlias=void 0,t.sharePort=void 0);let i=await fetch(`/api/loops/${e.id}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(t)});if(E(!1),i.ok)P(`Saved`),await r?.(),setTimeout(()=>{P(``),n()},800);else try{I((await i.json()).error??`Save failed (${i.status})`)}catch{I(`Save failed (${i.status})`)}},_e=async()=>{try{await navigator.clipboard.writeText(he),C(!0),setTimeout(()=>C(!1),1500)}catch{window.prompt(`Copy this URL:`,he)}},ve=!T&&!k&&!j&&(me?f>=1&&f<=65535:(!pe||m>=1024)&&(!pe||f>=1||g===`static`)&&(pe||c!==`port`||!D||u.trim().length>0)&&(pe||c!==`port`||f>=1024));return i?(0,q.jsx)(Fg,{open:t,onOpenChange:e=>{e||n()},children:(0,q.jsxs)(Rg,{className:`sm:max-w-md bg-white max-h-[85vh] overflow-y-auto`,children:[(0,q.jsxs)(zg,{children:[(0,q.jsxs)(Bg,{className:`flex items-center gap-2 text-sm`,children:[(0,q.jsx)(Ce,{size:16}),`Share Artifact`]}),(0,q.jsx)(Vg,{className:`sr-only`,children:`Share this artifact via a public URL.`})]}),(0,q.jsxs)(`div`,{className:`space-y-4 text-[13px]`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-sm text-gray-700`,children:`Enable sharing`}),(0,q.jsx)(`button`,{onClick:()=>s(!o),className:`w-10 h-5 rounded-full transition-colors ${o?`bg-blue-600`:`bg-gray-300`}`,children:(0,q.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${o?`translate-x-5`:`translate-x-0.5`}`})})]}),o&&(0,q.jsxs)(q.Fragment,{children:[K&&(0,q.jsxs)(`div`,{className:`flex gap-1.5 border-b border-gray-200 pb-2`,children:[U&&(0,q.jsx)(`button`,{onClick:()=>{R(`standard`),l(`static`)},className:`px-3 py-1 text-xs rounded-t ${L===`standard`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Subdomain`}),W&&(0,q.jsx)(`button`,{onClick:()=>{R(`direct`),l(`direct`)},className:`px-3 py-1 text-xs rounded-t ${L===`direct`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Direct Port`}),ee&&(0,q.jsx)(`button`,{onClick:()=>{R(`ephemeral`),l(`ephemeral`)},className:`px-3 py-1 text-xs rounded-t ${L===`ephemeral`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Ephemeral`})]}),(te||K&&L===`standard`)&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Share mode`}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5 mt-1`,children:[(0,q.jsx)(`button`,{onClick:()=>l(`static`),className:`px-2 py-1.5 text-xs rounded border ${c===`static`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Static files`}),(0,q.jsx)(`button`,{onClick:()=>l(`port`),className:`px-2 py-1.5 text-xs rounded border ${c===`port`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Port proxy`})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:[`Alias `,D?(0,q.jsx)(`span`,{className:`text-red-500`,children:`(required)`}):`(optional)`]}),(0,q.jsx)(`input`,{value:u,onChange:e=>d(e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,``)),className:`w-full mt-1 px-2 py-1.5 text-sm border rounded outline-none focus:border-gray-300 ${D?`border-red-300 bg-red-50`:`border-gray-200`}`,placeholder:D?`Set an alias to resolve conflict`:`my-project`}),D&&(0,q.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,q.jsx)(G,{size:11}),` `,b||`ID "${H}" is already in use`]}),!D&&v===!0&&(0,q.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`}),!D&&v===!1&&(0,q.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,q.jsx)(G,{size:11}),` `,b||`Already in use`]})]}),c===`port`&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Port (1024-65535)`}),(0,q.jsx)(`input`,{type:`number`,min:1024,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`})]})]}),me&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,q.jsx)(`input`,{type:`number`,min:1,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`}),(0,q.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,q.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,q.jsx)(`button`,{onClick:()=>_(`tcp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`tcp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`TCP`}),(0,q.jsx)(`button`,{onClick:()=>_(`udp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`udp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`UDP`})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider flex items-center gap-1.5`,children:[`Current host port`,(0,q.jsx)(Ke,{size:10,className:`text-gray-300`})]}),(0,q.jsx)(`div`,{className:`mt-1 px-2 py-1.5 text-sm bg-gray-50 rounded text-gray-700`,children:z==null?(0,q.jsx)(`span`,{className:`text-gray-400 text-xs`,children:e.shareEnabled&&e.shareMode===`ephemeral`?`(container starting / not running)`:`(save to start — port assigned by kernel on restart)`}):(0,q.jsx)(`span`,{className:`font-mono`,children:z})}),(0,q.jsxs)(`p`,{className:`text-[10px] text-amber-600 mt-1 flex items-center gap-1`,children:[(0,q.jsx)(G,{size:10}),` Changes on every loop restart. Saving also restarts the container.`]})]})]}),(ne||K&&L===`direct`&&!me)&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`External port`}),(0,q.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,q.jsx)(`input`,{type:`number`,min:1024,max:65535,value:m,onChange:e=>h(parseInt(e.target.value,10)||1e4),className:`flex-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`,placeholder:`10000`}),(0,q.jsx)(`button`,{onClick:async()=>{let e=await Kh();e.port&&h(e.port)},className:`px-2 py-1.5 rounded border border-gray-200 hover:bg-gray-100 text-gray-500`,title:`Pick a random available port`,children:(0,q.jsx)(et,{size:14})})]}),(0,q.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The public port clients connect to`}),j&&(0,q.jsx)(`span`,{className:`text-[11px] text-gray-400 mt-0.5`,children:`Checking availability…`}),k&&(0,q.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,q.jsx)(G,{size:11}),` `,k]}),!j&&!k&&(0,q.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`})]}),g!==`static`&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,q.jsx)(`input`,{type:`number`,min:1,max:65535,value:f,onChange:e=>p(parseInt(e.target.value,10)||3e3),className:`w-full mt-1 px-2 py-1.5 text-sm border border-gray-200 rounded outline-none focus:border-gray-300`}),(0,q.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,q.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,q.jsx)(`button`,{onClick:()=>_(`tcp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`tcp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`TCP`}),i.serveDynamicUdpEnabled&&(0,q.jsx)(`button`,{onClick:()=>_(`udp`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`udp`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`UDP`}),i.serveDynamicStaticEnabled&&(0,q.jsx)(`button`,{onClick:()=>_(`static`),className:`flex-1 px-2 py-1.5 text-xs rounded border ${g===`static`?`bg-blue-50 border-blue-300 text-blue-700`:`border-gray-200 text-gray-600`}`,children:`Static`})]})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Access URL`}),(0,q.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,q.jsx)(`code`,{className:`flex-1 px-2 py-1.5 text-xs bg-gray-50 rounded text-gray-700 truncate`,children:he}),(0,q.jsx)(`button`,{onClick:_e,className:`px-2 py-1.5 rounded hover:bg-gray-100 text-gray-500`,title:`Copy URL`,children:S?(0,q.jsx)(V,{size:14,className:`text-emerald-600`}):(0,q.jsx)(ie,{size:14})})]}),(0,q.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-1`,children:pe?`Direct TCP/UDP access — no domain needed`:`Domain suffix configured in Settings → Workspace → Workspace Serve`})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2`,children:[F&&(0,q.jsx)(`span`,{className:`text-xs text-red-500`,children:F}),N&&(0,q.jsxs)(`span`,{className:`text-xs text-emerald-600 flex items-center gap-1`,children:[(0,q.jsx)(V,{size:12}),` `,N]}),(0,q.jsx)(`button`,{onClick:n,className:`px-3 py-1.5 text-xs rounded bg-gray-100 text-gray-700 hover:bg-gray-200`,children:`Cancel`}),(0,q.jsx)(`button`,{onClick:ge,disabled:!ve,className:`px-3 py-1.5 text-xs rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40`,children:T?`Saving...`:`Save`})]})]})]})}):null}var oI=(0,w.lazy)(()=>St(()=>import(`./Editor-BnfYQQzs.js`).then(e=>({default:e.Editor})),__vite__mapDeps([0,1,2,3]))),sI=(0,w.lazy)(()=>St(()=>import(`./Terminal-Vi3Ufhgi.js`).then(e=>({default:e.Terminal})),__vite__mapDeps([4,1,5])));function cI(){let{id:e}=Yn(),t=Og();if(!e)return(0,q.jsx)(yr,{to:`/loop`,replace:!0});if(!t.currentUser)return(0,q.jsx)(IF,{});let n=t.loops.find(t=>t.id===e);return t.loopsLoading?null:n?(0,q.jsxs)(`div`,{className:`h-full w-full flex min-h-0`,children:[(0,q.jsx)(lI,{currentId:e}),(0,q.jsx)(uI,{meta:n},e)]}):(0,q.jsx)(yr,{to:`/loop`,replace:!0})}function lI({currentId:e}){let t=Og(),n=Gn(),[r,i]=(0,w.useState)(`mine`),[a,o]=(0,w.useState)(``),[s,c]=(0,w.useState)(()=>localStorage.getItem(`loopat:loopsList:collapsed`)===`1`),l=_P(),u=BF((0,w.useMemo)(()=>t.loops.map(e=>e.id),[t.loops]));(0,w.useEffect)(()=>{let t=u[e];t?.status===`Done`&&t?.viewed===!1&&hm(e)},[u,e]);let d=t.currentUser?.id,f=(0,w.useMemo)(()=>{let e=a.toLowerCase().trim();return t.loops.filter(t=>{let n=t.driver??t.createdBy;return!(r===`mine`&&t.createdBy!==d&&n!==d||r===`rfd`&&!t.rfdRequestedAt||e&&!t.title.toLowerCase().includes(e)&&!t.id.toLowerCase().includes(e))})},[t.loops,r,d,a]),p=e=>{c(e),localStorage.setItem(`loopat:loopsList:collapsed`,e?`1`:`0`)},m=(0,q.jsxs)(`aside`,{className:`w-60 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,q.jsxs)(`div`,{className:`px-2 pt-1.5 pb-1 space-y-1 border-b border-gray-200`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[[`mine`,`all`,`rfd`].map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:r===e?e===`rfd`?`px-2 h-6 rounded text-[11px] flex items-center gap-1 bg-amber-600 text-white`:`px-2 h-6 rounded text-[11px] bg-gray-900 text-white`:e===`rfd`?`px-2 h-6 rounded text-[11px] flex items-center gap-1 text-amber-700 hover:bg-amber-50`:`px-2 h-6 rounded text-[11px] text-gray-500 hover:bg-gray-100`,children:e===`mine`?`mine`:e===`all`?`all`:`RFD`},e)),(0,q.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-auto pr-1`,children:f.length}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>t.setShowArchived(!t.showArchived),className:t.showArchived?`w-6 h-6 flex items-center justify-center text-gray-700 bg-gray-100 rounded`:`w-6 h-6 flex items-center justify-center text-gray-400 hover:text-gray-700 hover:bg-gray-100 rounded`,title:t.showArchived?`hide archived`:`show archived`,children:(0,q.jsx)(j,{size:13})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(!0),className:`w-6 h-6 flex items-center justify-center text-gray-400 hover:text-gray-700 hover:bg-gray-100 rounded`,title:`collapse sidebar`,children:(0,q.jsx)(Be,{size:14})})]}),(0,q.jsx)(`input`,{type:`text`,name:`loop-search`,value:a,onChange:e=>o(e.target.value),placeholder:`search loops…`,className:`w-full h-6 rounded px-1.5 text-[11px] bg-gray-100 border border-transparent focus:border-gray-300 focus:bg-white focus:outline-none text-gray-600 placeholder-gray-400`})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:[f.map(r=>{let i=e===r.id,a=r.archived===!0,o=t.currentUser?.id===r.createdBy,s=u[r.id],c=s?.status===`Done`||s?.status===`Ready`,d=s!==void 0&&!c;return(0,q.jsxs)(`div`,{className:`group/row relative flex items-stretch `+(i?`bg-gray-100`:`hover:bg-gray-50`),children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{hm(r.id),n(`/loop/${r.id}`),l&&p(!0)},className:`flex-1 min-w-0 px-3 py-1.5 flex items-center gap-2 text-left `+(a?`opacity-60`:``),children:[(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 mt-0.5 `+(a?`bg-gray-400`:d?`bg-blue-500 animate-pulse`:c&&!s?.viewed?`bg-yellow-500`:c?`bg-emerald-500`:`bg-gray-300`)}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`text-[13px] text-gray-900 truncate flex items-center gap-1.5`,children:[a&&(0,q.jsx)(j,{size:10,className:`text-gray-400 shrink-0`}),r.rfdRequestedAt&&(0,q.jsx)(`span`,{className:`shrink-0 text-[9px] px-1 rounded bg-amber-100 text-amber-800 font-medium tracking-wide`,children:`RFD`}),(0,q.jsx)(`span`,{className:`truncate`,children:r.title}),s&&(0,q.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium `+(d?`text-blue-500`:c?`text-emerald-500`:`text-gray-400`),children:s.status})]}),(0,q.jsxs)(`div`,{className:`text-[11px] text-gray-500 truncate flex items-center gap-1 mt-0.5`,children:[(0,q.jsx)(`span`,{children:r.driver??r.createdBy}),(0,q.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,q.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400`,children:r.id.slice(0,6)})]})]})]}),(0,q.jsx)(`button`,{type:`button`,disabled:!o,onClick:e=>{e.stopPropagation(),o&&t.setLoopArchived(r.id,!a)},className:(l?`opacity-100`:`opacity-0 group-hover/row:opacity-100`)+` transition-opacity w-7 flex items-center justify-center `+(o?`text-gray-400 hover:text-gray-700`:`text-gray-300 cursor-not-allowed`),title:o?a?`unarchive`:`archive (hide + read-only)`:`only ${r.createdBy} can ${a?`unarchive`:`archive`} this loop`,children:a?(0,q.jsx)(A,{size:13}):(0,q.jsx)(j,{size:13})})]},r.id)}),f.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no loops · click "+ New Loop"`})]})]});return s?(0,q.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(!1),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`expand sidebar`,children:(0,q.jsx)(Ve,{size:16})})}):l?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,q.jsx)(`button`,{type:`button`,onClick:()=>p(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`collapse sidebar`,children:(0,q.jsx)(Be,{size:16})})}),(0,q.jsxs)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>p(!0),children:[(0,q.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:m})]})]}):m}function uI({meta:e}){let t=Og(),n=_P(),[r,i]=(0,w.useState)([]),[a,o]=(0,w.useState)(null),[s,c]=(0,w.useState)(null),[l,u]=(0,w.useState)([]),[d,f]=(0,w.useState)(!1),[p,m]=(0,w.useState)(null);(0,w.useEffect)(()=>{Uh().then(m)},[]);let[h,g]=(0,w.useState)(null),_=e=>{c(e),g(null),i(e=>e.includes(`editor`)?e:[...e,`editor`])},{runtime:v,connected:y,reconnecting:b,running:x,viewers:S,extra:C,queue:T,onClearQueue:E}=NP(e.id,t.currentUser?.id??``,_),D=BF((0,w.useMemo)(()=>[e.id],[e.id])),O=D[e.id]?.phase===`preparing`,k=D[e.id]?.status;(0,w.useEffect)(()=>{jm(e.id).then(u),hm(e.id),t.currentUser?.id&&localStorage.setItem(`loopat:lastLoop:${t.currentUser.id}`,e.id)},[e.id]);let A=Vn(),j=Gn(),M=A.state?.kickoff;(0,w.useEffect)(()=>{!M||!y||(C.enqueueMessage(M),j(A.pathname,{replace:!0,state:null}))},[M,y]);let N=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},P=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[e])},F=e=>{i(t=>t.filter(t=>t!==e)),o(t=>t===e?null:t)},I=r.length>0,L=r.filter(e=>e===`editor`||e===`terminal`),R=r.filter(e=>e!==`editor`&&e!==`terminal`),z=L.length>0,B=R.length>0,[V,H]=(0,w.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);return!isNaN(e)&&e>=10&&e<=90?e:55}),[U,W]=(0,w.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);return!isNaN(e)&&e>=5&&e<=50?e:18});(0,w.useEffect)(()=>{if(!B){let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);!isNaN(e)&&e>=5&&e<=50&&W(e)}if(!z&&!B){let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);!isNaN(e)&&e>=10&&e<=90&&H(e)}},[z,B]);let G=e=>{!isNaN(e.chat)&&e.chat>0&&localStorage.setItem(`loopat:chatPct`,String(Math.round(e.chat))),!isNaN(e.otherCol)&&e.otherCol>0&&localStorage.setItem(`loopat:otherPct`,String(Math.round(e.otherCol)))},ee=n=>{let r=a===n;return(0,q.jsx)(_I,{loopId:e.id,meta:e,mode:n,onClose:()=>F(n),pickedFile:s,onPickFile:_,currentUserId:t.currentUser?.id??``,isFullscreen:r,onToggleFullscreen:()=>o(r?null:n),onEditorSelection:g},n)};return(0,q.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,q.jsx)(dI,{meta:e,mounts:l,connected:y,reconnecting:b,running:x,viewers:S,queue:T,onClearQueue:E,openPanels:r,toggleMode:N,onShareWork:()=>f(!0),showShareButton:!p||p.serveEnabled||p.serveDynamicEnabled||p.serveEphemeralEnabled}),e.contextWarnings&&e.contextWarnings.length>0&&(0,q.jsxs)(`div`,{className:`shrink-0 border-b border-amber-200 bg-amber-50 px-4 py-2 text-[12px] text-amber-800 leading-relaxed`,children:[(0,q.jsx)(`span`,{className:`font-semibold`,children:`⚠ Context not fully loaded.`}),` `,`This loop's knowledge/notes couldn't be cloned — it runs with an empty context until the access is fixed (check the key has access to the repo):`,(0,q.jsx)(`ul`,{className:`mt-1 ml-4 list-disc`,children:e.contextWarnings.map((e,t)=>(0,q.jsx)(`li`,{className:`font-mono text-[11px] break-all`,children:e},t))})]}),(0,q.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col`,children:[O&&(0,q.jsx)(mI,{detail:k}),n?(0,q.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,q.jsx)(MP,{extra:C,children:(0,q.jsx)(SC,{runtime:v,children:(0,q.jsx)(FF,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})}):I?(0,q.jsxs)(dD,{orientation:`horizontal`,className:`flex-1 min-w-0 min-h-0`,onLayoutChange:G,children:[(0,q.jsx)(mD,{id:`chat`,minSize:20,defaultSize:V,className:`flex flex-col min-h-0 min-w-0`,children:(0,q.jsx)(MP,{extra:C,children:(0,q.jsx)(SC,{runtime:v,children:(0,q.jsx)(FF,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})}),(z||B)&&(0,q.jsx)(_D,{className:`relative w-4 -mx-1.5 cursor-col-resize group flex items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-px after:-translate-x-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,q.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 h-8 w-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),z&&(0,q.jsx)(mD,{id:`editorCol`,minSize:15,defaultSize:30,className:`flex flex-col min-h-0 min-w-0`,children:L.length>1?(0,q.jsx)(dD,{orientation:`vertical`,className:`flex-1 min-h-0`,children:L.map((e,t)=>(0,q.jsxs)(w.Fragment,{children:[t>0&&(0,q.jsx)(_D,{className:`relative h-4 -my-1.5 cursor-row-resize group flex items-center justify-center after:absolute after:left-0 after:right-0 after:top-1/2 after:h-px after:-translate-y-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,q.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 w-8 h-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),(0,q.jsx)(mD,{id:e,minSize:10,defaultSize:100/L.length,className:`flex flex-col min-h-0 min-w-0`,children:ee(e)})]},e))}):ee(L[0])}),z&&B&&(0,q.jsx)(_D,{className:`relative w-4 -mx-1.5 cursor-col-resize group flex items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-px after:-translate-x-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,q.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 h-8 w-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),B&&(0,q.jsx)(mD,{id:`otherCol`,minSize:15,defaultSize:U,className:`flex flex-col min-h-0 min-w-0`,children:R.length>1?(0,q.jsx)(dD,{orientation:`vertical`,className:`flex-1 min-h-0`,children:R.map((e,t)=>(0,q.jsxs)(w.Fragment,{children:[t>0&&(0,q.jsx)(_D,{className:`relative h-4 -my-1.5 cursor-row-resize group flex items-center justify-center after:absolute after:left-0 after:right-0 after:top-1/2 after:h-px after:-translate-y-1/2 after:bg-gray-200 after:transition-colors hover:after:bg-blue-400`,children:(0,q.jsx)(`div`,{className:`absolute left-1/2 -translate-x-1/2 w-8 h-1.5 rounded-full bg-gray-300 group-hover:bg-blue-400 transition-colors`})}),(0,q.jsx)(mD,{id:e,minSize:10,defaultSize:100/R.length,className:`flex flex-col min-h-0 min-w-0`,children:ee(e)})]},e))}):ee(R[0])})]}):(0,q.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,q.jsx)(MP,{extra:C,children:(0,q.jsx)(SC,{runtime:v,children:(0,q.jsx)(FF,{archived:e.archived===!0,onUnarchive:()=>t.setLoopArchived(e.id,!1),repo:e.repo,branch:e.branch,title:e.title,driver:e.driver??e.createdBy,driverHistory:e.driverHistory,rfdRequestedAt:e.rfdRequestedAt,rfdRequestedBy:e.rfdRequestedBy,onTakeDrive:()=>t.takeDrive(e.id),pickedFile:s,editorSelection:h})})})})]}),I&&n&&r.map(e=>(0,q.jsx)(w.Fragment,{children:ee(e)},e)),n&&(0,q.jsx)(`div`,{className:`fixed bottom-0 left-0 z-30 w-9 flex flex-col items-center gap-0.5 pb-2`,children:[`terminal`,`editor`,`workdir`,`git`].map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>P(e),className:`w-7 h-7 flex items-center justify-center rounded text-xs ${r.includes(e)?`bg-gray-200 text-gray-900`:`text-gray-400 hover:text-gray-700 hover:bg-gray-100`}`,title:e,children:e===`terminal`?`▷`:e===`editor`?`✎`:e===`workdir`?`▤`:`⑂`},e))}),(0,q.jsx)(aI,{loop:e,open:d,onClose:()=>f(!1),onSaved:async()=>{await t.refresh()}})]})}function dI({meta:e,mounts:t,connected:n,reconnecting:r,running:i,viewers:a,queue:o,onClearQueue:s,openPanels:c,toggleMode:l,onShareWork:u,showShareButton:d}){let f=_P(),p=Gn(),m=Og(),[h,g]=(0,w.useState)(f),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(!1),[x,S]=(0,w.useState)(e.title),C=m.currentUser?.id===e.createdBy,T=async()=>{if(!_){v(!0);try{let t=await xm(e.id);t&&p(`/loop/${t.id}`)}finally{v(!1)}}},E=async()=>{let t=x.trim();if(!t||t===e.title){b(!1),S(e.title);return}b(!1),await m.setLoopTitle(e.id,t)||S(e.title)},D=(e,t)=>(0,q.jsx)(`button`,{className:c.includes(t)?`px-2 py-0.5 rounded bg-gray-100 text-gray-900`:`px-2 py-0.5 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-50`,onClick:()=>l(t),children:e},t);return(0,q.jsxs)(`header`,{className:`group/header px-3 md:px-5 shrink-0 border-b border-gray-200 `+(h?`py-1.5`:`pt-3 pb-2`),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`text-gray-400 hover:text-gray-700 -ml-1 p-0.5 rounded hover:bg-gray-100`,title:h?`expand header`:`collapse header`,children:(0,q.jsx)(H,{size:14,className:`transition-transform `+(h?`-rotate-90`:``)})}),y?(0,q.jsx)(`input`,{type:`text`,value:x,autoFocus:!0,onChange:e=>S(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing?(t.preventDefault(),E()):t.key===`Escape`&&(t.preventDefault(),b(!1),S(e.title))},onBlur:E,maxLength:200,className:`text-[14px] md:text-[15px] font-medium text-gray-900 bg-white border border-blue-400 rounded px-1 py-0 outline-none min-w-[120px]`}):(0,q.jsx)(`span`,{className:`text-[14px] md:text-[15px] font-medium text-gray-900 `+(C?`cursor-pointer hover:bg-gray-100 rounded px-1 -mx-1`:``),onClick:()=>{C&&(S(e.title),b(!0))},title:C?`click to rename`:void 0,children:e.title}),(0,q.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`driver: `,(0,q.jsx)(`span`,{className:`text-gray-900`,children:e.driver??e.createdBy})]}),e.rfdRequestedAt&&(0,q.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-amber-100 text-amber-800 border border-amber-200 font-medium tracking-wide`,title:`released for drive by ${e.rfdRequestedBy??`?`} at ${e.rfdRequestedAt}`,children:`RFD`}),!n&&r&&(0,q.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`reconnecting…`}),i&&(0,q.jsx)(`span`,{className:`text-[11px] text-blue-600`,children:`running`}),a>1&&(0,q.jsxs)(`span`,{title:`people watching`,className:`text-[11px] px-1.5 py-0.5 rounded bg-emerald-50 text-emerald-800 border border-emerald-200`,children:[`👥 `,a]}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`button`,{type:`button`,onClick:T,disabled:_,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-violet-700 border-violet-300 hover:bg-violet-50 disabled:opacity-50`,title:`Spawn a child loop seeded with this loop's conversation, for sedimenting reusable insights into knowledge/`,children:[(0,q.jsx)(ge,{size:11}),_?`Distilling…`:`Distill`]}),d!==!1&&(0,q.jsxs)(`button`,{onClick:u,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border ${e.shareEnabled?`bg-blue-50 text-blue-700 border-blue-200 hover:bg-blue-100`:`bg-white text-gray-700 border-gray-300 hover:bg-gray-100`}`,title:`Share workspace artifact (static files or port forward)`,children:[(0,q.jsx)(Ce,{size:11}),`Share Artifact`]}),(0,q.jsx)(pI,{meta:e}),(0,q.jsx)(fI,{meta:e})]}),!h&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`text-xs text-gray-500 mt-1.5 flex items-center gap-2 flex-wrap`,children:[(0,q.jsxs)(`span`,{className:`font-mono`,children:[`~/.loopat/loops/`,e.id.slice(0,8),`/workdir`]}),(0,q.jsx)(`span`,{children:`·`}),(0,q.jsx)(`span`,{children:`main`}),a>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{children:`·`}),(0,q.jsxs)(`span`,{children:[a,` viewing`]})]}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,children:[D(`ℹ info`,`info`),D(`▤ workdir`,`workdir`),D(`✎ editor`,`editor`),D(`▷ terminal`,`terminal`),(0,q.jsx)(`button`,{className:c.includes(`git`)?`px-2 py-0.5 rounded bg-gray-100 text-gray-900`:`px-2 py-0.5 rounded text-gray-500 hover:text-gray-900 hover:bg-gray-50`,onClick:()=>l(`git`),title:`git changes`,children:(0,q.jsx)(xe,{size:14})})]})]}),(0,q.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-gray-400`,children:`context:`}),t.map(e=>(0,q.jsx)(hI,{label:e.name,value:e.name===`knowledge`?`ro`:`rw`},e.path))]}),e.config?.profiles&&e.config.profiles.length>0&&(0,q.jsx)(gI,{profiles:e.config.profiles}),(0,q.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-gray-400`,children:`vault:`}),(0,q.jsx)(hI,{label:e.config?.vault??`default`,value:`loaded`})]})]})]})}function fI({meta:e}){let t=Og(),[n,r]=(0,w.useState)(!1),[i,a]=(0,w.useState)(!1),o=t.currentUser?.id===e.createdBy,s=e.public===!0;if(!t.currentUser)return null;let c=`${location.origin}/loop/${e.id}`;return o?(0,q.jsxs)(`div`,{className:`inline-flex items-center gap-1`,children:[s&&(0,q.jsxs)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(c),r(!0),setTimeout(()=>r(!1),1500)}catch{}},title:c,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] text-gray-600 hover:bg-gray-100`,children:[n?(0,q.jsx)(V,{size:11}):(0,q.jsx)(ie,{size:11}),(0,q.jsx)(`span`,{className:`hidden md:inline`,children:n?`copied`:`copy link`})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!o||i)){a(!0);try{await t.setLoopPublic(e.id,!s)}finally{a(!1)}}},disabled:i,title:s?`stop sharing`:`share publicly (anyone with the link can view)`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border disabled:opacity-50 `+(s?`bg-emerald-50 text-emerald-800 border-emerald-200 hover:bg-emerald-100`:`bg-white text-gray-700 border-gray-300 hover:bg-gray-100`),children:[s?(0,q.jsx)(Ce,{size:11}):(0,q.jsx)(je,{size:11}),s?`shared`:`share`]})]}):(0,q.jsxs)(`span`,{title:s?`this loop is shared publicly`:`this loop is private`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] `+(s?`bg-emerald-50 text-emerald-800 border border-emerald-200`:`bg-gray-100 text-gray-600`),children:[s?(0,q.jsx)(Ce,{size:11}):(0,q.jsx)(je,{size:11}),s?`public`:`private`]})}function pI({meta:e}){let t=Og(),[n,r]=(0,w.useState)(!1);if(!t.currentUser)return null;let i=e.driver??e.createdBy,a=t.currentUser.id===i;return e.rfdRequestedAt?(0,q.jsxs)(`button`,{type:`button`,disabled:n,onClick:async()=>{r(!0);try{await t.takeDrive(e.id)}finally{r(!1)}},title:`released for drive by ${e.rfdRequestedBy??`?`} — click to take over`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-amber-500 text-white border-amber-600 hover:bg-amber-600 disabled:opacity-50`,children:[(0,q.jsx)(we,{size:11}),`Drive`]}):a?(0,q.jsxs)(`button`,{type:`button`,disabled:n,onClick:async()=>{if(window.confirm(`Request For Drive: this will tear down the sandbox and release the loop so anyone else can take over. Continue?`)){r(!0);try{await t.requestDrive(e.id)}finally{r(!1)}}},title:`Release this loop so someone else can drive it`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-amber-700 border-amber-300 hover:bg-amber-50 disabled:opacity-50`,children:[(0,q.jsx)(we,{size:11}),`Request For Drive`]}):null}function mI({detail:e}){return(0,q.jsx)(`div`,{className:`absolute inset-0 z-30 flex items-center justify-center bg-white/70 backdrop-blur-sm`,children:(0,q.jsxs)(`div`,{className:`max-w-md mx-6 px-6 py-5 rounded-xl border border-blue-200 bg-white shadow-lg text-center`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 mb-2`,children:[(0,q.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border-2 border-blue-500 border-t-transparent animate-spin`}),(0,q.jsx)(`span`,{className:`text-sm font-medium text-gray-900`,children:`Preparing this loop’s sandbox…`})]}),(0,q.jsxs)(`p`,{className:`text-[12px] text-gray-600 leading-relaxed`,children:[`Installing the toolchain from `,(0,q.jsx)(`code`,{className:`font-mono text-[11px] bg-gray-100 px-1 rounded`,children:`mise.toml`}),`. Terminal and chat are paused until tools are ready — this only happens the first time.`]}),e&&e!==`Ready`&&(0,q.jsx)(`p`,{className:`mt-2 text-[11px] font-mono text-blue-700 break-words`,children:e})]})})}function hI({label:e,value:t,title:n}){return(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-gray-100 text-[11px]`,title:n,children:[(0,q.jsxs)(`span`,{className:`text-gray-500`,children:[e,`:`]}),(0,q.jsx)(`span`,{className:`text-gray-900 font-medium`,children:t})]})}function gI({profiles:e}){let[t,n]=(0,w.useState)({});return(0,w.useEffect)(()=>{let e=!1;return dm().then(t=>{if(e)return;let r={};for(let e of t)e.description&&(r[e.name]=e.description);n(r)}).catch(()=>{}),()=>{e=!0}},[]),(0,q.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-gray-400`,children:`profiles:`}),e.map(e=>(0,q.jsx)(hI,{label:e,value:`active`,title:t[e]},e))]})}function _I({loopId:e,meta:t,mode:n,onClose:r,pickedFile:i,onPickFile:a,currentUserId:o,isFullscreen:s,onToggleFullscreen:c,onEditorSelection:l}){let u=_P(),[d,f]=(0,w.useState)(()=>{let e=localStorage.getItem(`loopat:mobilePanelPct`);return e?Math.max(20,Math.min(95,parseInt(e)||55)):55}),p=(0,w.useRef)(null),m=e=>{localStorage.setItem(`loopat:mobilePanelPct`,String(e))},h=e=>{if(p.current={startY:e,startPct:d},s){let t=Math.round(e/window.innerHeight*100),n=Math.max(20,Math.min(95,t));f(n),m(n),c?.()}},g=e=>{if(!p.current)return;let t=e-p.current.startY,n=Math.round(t/window.innerHeight*100),r=Math.max(20,Math.min(95,p.current.startPct+n));f(r),m(r)},_=()=>{p.current=null},v=e=>{e.preventDefault(),e.stopPropagation(),h(e.touches[0].clientY)},y=e=>{e.preventDefault(),g(e.touches[0].clientY)},b=e=>{e.preventDefault(),_()},x=e=>{e.pointerType!==`touch`&&(e.preventDefault(),e.target.setPointerCapture(e.pointerId),h(e.clientY))},S=e=>{e.pointerType===`touch`||!p.current||g(e.clientY)},C=e=>{e.pointerType!==`touch`&&_()},T=(0,q.jsxs)(`aside`,{className:`flex-1 min-w-0 bg-white flex flex-col`,children:[(0,q.jsxs)(`header`,{className:`px-3 h-8 shrink-0 border-b border-gray-200 flex items-center gap-1 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{className:`capitalize`,children:n}),n===`editor`&&(0,q.jsx)(`span`,{className:`ml-2 truncate text-gray-700`,children:i||`(no file)`}),(0,q.jsx)(`div`,{className:`flex-1`}),(n===`editor`||n===`terminal`)&&(0,q.jsx)(`button`,{className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,onClick:c,title:s?`restore`:`maximize`,children:s?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})}),(0,q.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:r,title:`close panel`,children:`✕`})]}),n===`info`&&(0,q.jsx)(vI,{meta:t}),n===`workdir`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(JF,{loopId:e,onPick:a,picked:i}),(0,q.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 text-[11px] text-gray-500`,children:[`⑂ `,(0,q.jsx)(`span`,{className:`text-gray-900`,children:`main`})]})]}),(0,q.jsxs)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading...`}),children:[n===`editor`&&(0,q.jsx)(oI,{loopId:e,path:i,onSelectionChange:l}),n===`terminal`&&(0,q.jsx)(`div`,{className:`flex-1 min-h-0 bg-[#1a1c20] overflow-hidden`,children:(0,q.jsx)(sI,{loopId:e,currentUserId:o})}),n===`git`&&(0,q.jsx)(eI,{loopId:e,onClose:r,onPickFile:a})]})]});return u?(0,q.jsxs)(`div`,{className:`fixed inset-x-0 top-0 z-40 bg-white rounded-b-xl shadow-xl pointer-events-auto overflow-hidden`,style:{height:s?`100vh`:`${d}vh`},children:[(0,q.jsx)(`div`,{className:`absolute inset-0 bottom-7 overflow-y-auto flex flex-col`,children:T}),(0,q.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 h-7 z-10 flex items-center justify-center cursor-row-resize active:bg-gray-50 rounded-b-xl`,style:{touchAction:`none`},onTouchStart:v,onTouchMove:y,onTouchEnd:b,onPointerDown:x,onPointerMove:S,onPointerUp:C,children:(0,q.jsx)(`div`,{className:`w-8 h-1 rounded-full bg-gray-300`})})]}):s?(0,_t.createPortal)((0,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex flex-col`,children:T}),document.body):T}function vI({meta:e}){let t=Og().currentUser?.id===e.createdBy;return(0,q.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-5 py-4 text-[13px] text-gray-900`,children:[(0,q.jsxs)(yI,{label:`basics`,children:[(0,q.jsx)(bI,{label:`title`,value:e.title}),(0,q.jsx)(bI,{label:`created`,value:new Date(e.createdAt).toLocaleString()}),(0,q.jsx)(bI,{label:`status`,value:`active`}),(0,q.jsx)(bI,{label:`driver`,value:t?`${e.createdBy} (you)`:e.createdBy}),(0,q.jsx)(bI,{label:`sharing`,value:e.public?`public — /loop/${e.id.slice(0,8)}…`:`private`})]}),(0,q.jsxs)(yI,{label:`workdir`,children:[(0,q.jsx)(bI,{label:`id`,value:e.id,mono:!0}),(0,q.jsx)(bI,{label:`path`,value:`~/.loopat/loops/${e.id.slice(0,8)}/workdir`,mono:!0}),(0,q.jsx)(bI,{label:`branch`,value:`main`,mono:!0})]}),(0,q.jsxs)(yI,{label:`context`,children:[(0,q.jsx)(bI,{label:`knowledge`,value:`all (ro)`}),(0,q.jsx)(bI,{label:`notes`,value:`all (rw)`}),(0,q.jsx)(bI,{label:`personal`,value:`${e.createdBy} (rw)`})]})]})}function yI({label:e,children:t}){return(0,q.jsxs)(`section`,{className:`mb-5`,children:[(0,q.jsx)(`h3`,{className:`text-[11px] uppercase tracking-wide text-gray-400 mb-2`,children:e}),(0,q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:t})]})}function bI({label:e,value:t,mono:n=!1}){return(0,q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500 w-24 shrink-0`,children:e}),(0,q.jsx)(`span`,{className:n?`font-mono text-[12px] text-gray-800 truncate`:`text-[13px] text-gray-900 truncate`,children:t})]})}function xI({name:e,onClick:t,onEdit:n,size:r=`sm`}){return(0,q.jsxs)(`span`,{className:`relative inline-flex items-center group/chip`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:t,className:`inline-flex items-center rounded-full bg-sky-50 text-sky-700 border border-sky-200 hover:bg-sky-100 transition-colors font-mono `+(r===`md`?`px-2 py-0.5 text-[12px]`:`px-1.5 py-0.5 text-[10px]`),title:`#${e}`,children:[`#`,e]}),n&&(0,q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),n()},className:`absolute -top-1 -right-1 z-10 w-4 h-4 rounded-full bg-white border border-gray-300 hover:border-red-400 hover:text-red-500 text-[9px] text-gray-400 opacity-0 group-hover/chip:opacity-100 transition-opacity flex items-center justify-center shadow-sm`,title:`Remove tag`,children:`×`})]})}function SI(){let{name:e}=Yn(),t=decodeURIComponent(e??``),n=Gn(),[r,i]=(0,w.useState)(null),[a,o]=(0,w.useState)(!0);return(0,w.useEffect)(()=>{let e=!1;return gh().then(n=>{e||(i(n.find(e=>e.name===t.toLowerCase())??null),o(!1))}),()=>{e=!0}},[t]),(0,q.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-white`,children:[(0,q.jsxs)(`header`,{className:`h-10 shrink-0 flex items-center gap-3 px-6 border-b border-gray-200`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>n(-1),className:`text-[11px] text-gray-500 hover:text-gray-900`,children:`← back`}),(0,q.jsx)(xI,{name:t,size:`md`}),(0,q.jsx)(`div`,{className:`flex-1`})]}),(0,q.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col overflow-auto`,children:(0,q.jsx)(`div`,{className:`px-4 md:px-8 py-4 md:py-8 mx-auto w-full max-w-[760px] flex flex-col gap-5`,children:a?(0,q.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`}):!r||r.loops.length===0?(0,q.jsxs)(`div`,{className:`text-[12px] text-gray-400 italic`,children:[`no entities tagged with `,(0,q.jsxs)(`code`,{children:[`#`,t]})]}):(0,q.jsxs)(`section`,{children:[(0,q.jsxs)(`div`,{className:`text-[12px] uppercase tracking-wider text-gray-500 mb-2 px-1`,children:[`Loops (`,r.loops.length,`)`]}),(0,q.jsx)(`div`,{className:`flex flex-col gap-1`,children:r.loops.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n(`/loop/${e.id}`),className:`w-full text-left px-3 py-2 rounded border border-gray-200 hover:border-gray-400 hover:bg-gray-50 text-[13px] text-gray-900`,children:[e.title,(0,q.jsx)(`span`,{className:`ml-2 text-[10px] font-mono text-gray-400`,children:e.id.slice(0,6)})]},e.id))})]})})})]})}var CI=(0,w.lazy)(()=>St(()=>import(`./CodeEditor-JV36Z3V5.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([2,1,3]))),wI=(0,w.lazy)(()=>St(()=>import(`./Markdown-D0eu-WNR.js`).then(e=>({default:e.Markdown})),__vite__mapDeps([6,1,7]))),TI=(0,w.lazy)(()=>St(()=>import(`./MilkdownEditor-t_CG4MJj.js`).then(e=>({default:e.MilkdownEditor})),__vite__mapDeps([8,1,7,3]))),EI=[{id:`knowledge`,label:`Knowledge`},{id:`notes`,label:`Notes`},{id:`personal`,label:`Personal`},{id:`repos`,label:`Repos`}],DI=new Set([`knowledge`,`notes`,`personal`,`repos`]);function OI(){let{sub:e}=Yn(),[t]=Ci(),n=DI.has(e)?e:`knowledge`,r=t.get(`file`)||void 0,i=t.get(`edit`)===`1`;return(0,q.jsxs)(`div`,{className:`flex flex-col h-full w-full`,children:[(0,q.jsx)(`nav`,{className:`flex items-center gap-1 px-3 h-9 shrink-0 border-b border-gray-200 bg-white`,children:EI.map(e=>(0,q.jsx)(gi,{to:`/context/${e.id}`,className:({isActive:e})=>e?`h-7 px-2.5 rounded flex items-center gap-1.5 text-xs bg-gray-100 text-gray-900`:`h-7 px-2.5 rounded flex items-center gap-1.5 text-xs text-gray-500 hover:bg-gray-50 hover:text-gray-900`,children:(0,q.jsx)(`span`,{children:e.label})},e.id))}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0`,children:n===`repos`?(0,q.jsx)(BI,{}):(0,q.jsx)(MI,{vault:n,initialFile:r,initialEditing:i},n)})]})}var kI={knowledge:`workspace's distilled materials`,notes:`workspace · public`,personal:`yours · private`,repos:`registered code repos`};function AI({resource:e,canPush:t=!0}){let[n,r]=(0,w.useState)(null),[i,a]=(0,w.useState)(null),[o,s]=(0,w.useState)(null),c=(0,w.useCallback)(async()=>{a(`status`),r(await Jm(e)),a(null)},[e]);(0,w.useEffect)(()=>{c()},[c]);let l=async()=>{a(`pull`),s(null);let t=await Ym(e);a(null),s(t.ok?{ok:!0,text:t.message??`pulled`}:{ok:!1,text:t.error??`pull failed`}),t.ok&&c()},u=async()=>{a(`push`),s(null);let t=await Xm(e);a(null),s(t.ok?{ok:!0,text:t.message??`pushed`}:{ok:!1,text:t.error??`push failed`}),t.ok&&c()},d=n?.ahead??0,f=n?.behind??0,p=n&&!n.hasRemote;return(0,q.jsxs)(`div`,{className:`px-3 py-1.5 border-t border-gray-200 flex flex-col gap-1 text-[11px]`,children:[(0,q.jsx)(`div`,{className:`flex items-center gap-2`,children:p?(0,q.jsx)(`span`,{className:`text-gray-400`,children:`no remote`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:d>0?`text-emerald-700`:`text-gray-400`,title:`unpushed commits`,children:[`↑`,d]}),(0,q.jsxs)(`span`,{className:f>0?`text-amber-700`:`text-gray-400`,title:`unpulled commits`,children:[`↓`,f]}),n&&n.uncommitted>0&&(0,q.jsxs)(`span`,{className:`text-red-600`,title:`uncommitted changes in primary`,children:[`! `,n.uncommitted]}),(0,q.jsx)(`button`,{onClick:()=>void c(),disabled:i!==null,className:`ml-auto text-gray-400 hover:text-gray-700 disabled:opacity-50`,title:`refresh status`,children:`↻`})]})}),!p&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`button`,{onClick:l,disabled:i!==null||f===0,className:`px-1.5 h-5 rounded border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i===`pull`?`pulling…`:`pull`}),t&&(0,q.jsx)(`button`,{onClick:u,disabled:i!==null||d===0,className:`px-1.5 h-5 rounded border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i===`push`?`pushing…`:`push`}),o&&(0,q.jsx)(`span`,{className:`truncate flex-1 min-w-0 `+(o.ok?`text-emerald-700`:`text-red-600`),title:o.text,children:o.text})]})]})}function jI({onRefreshed:e}){let[t,n]=(0,w.useState)(0),[r,i]=(0,w.useState)(!1),[a,o]=(0,w.useState)(null),s=(0,w.useRef)(e);s.current=e;let c=(0,w.useCallback)(async()=>{i(!0),o(null);let e=await Rm();i(!1),e.ok?(n(0),s.current()):e.diverged?o(`你有未保存的编辑,先保存再刷新`):o(e.error??`refresh failed`)},[]);return(0,w.useEffect)(()=>{c()},[c]),(0,w.useEffect)(()=>{let e=()=>Lm().then(n).catch(()=>{});e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]),(0,q.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 flex flex-col gap-1.5 text-[11px]`,children:[t>0?(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 bg-amber-50 border border-amber-200 rounded px-2 py-1 text-amber-800`,children:[(0,q.jsxs)(`span`,{children:[`远端已更新 `,t,` 个改动`]}),(0,q.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`px-2 py-0.5 rounded bg-amber-600 text-white hover:bg-amber-700 disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}):(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-gray-400`,children:[(0,q.jsx)(`span`,{children:`已是最新`}),(0,q.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`text-gray-500 hover:text-gray-900 underline disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}),a&&(0,q.jsx)(`div`,{className:`text-amber-700`,children:a})]})}function MI({vault:e,initialFile:t,initialEditing:n}){let[r,i]=(0,w.useState)([]),[a,o]=(0,w.useState)([]),[s,c]=(0,w.useState)(t??null),[l,u]=Ci();(0,w.useEffect)(()=>{(l.get(`file`)??null)!==s&&u(s?{file:s}:{},{replace:!0})},[s,l,u]);let[d,f]=(0,w.useState)(0),[p,m]=(0,w.useState)(!1),[h,g]=(0,w.useState)(``),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(null),[x,S]=(0,w.useState)(``),C=_P(),T=(0,w.useRef)(!1);if(!T.current&&t){T.current=!0;let n=`vault-${e}`,r=t.includes(`/`)?t.substring(0,t.lastIndexOf(`/`)):``;if(r)try{let e=`loopat:tree:expanded:`+n,t=localStorage.getItem(e),i=t?JSON.parse(t):[];for(let e=r;e;e=e.includes(`/`)?e.substring(0,e.lastIndexOf(`/`)):``)i.includes(e)||i.push(e);localStorage.setItem(e,JSON.stringify(i))}catch{}}(0,w.useEffect)(()=>{Mm(e).then(e=>{i(e),c(t=>{if(t)return t;let n=e.find(e=>e.type===`file`&&e.path.endsWith(`.md`));return n?n.path:null})}),Nm(e).then(o),g(``)},[e,d]),(0,w.useEffect)(()=>{let t=!1,n=()=>{t||f(e=>e+1)};return e===`knowledge`?Ym(`knowledge`).then(e=>{e.ok&&(e.message??``).toLowerCase()!==`already up to date`&&n()}):e===`notes`?Lm().then(e=>{e>0&&Rm().then(e=>{e.ok&&n()})}):e===`personal`&&im().then(e=>{e.ok&&(e.files?.length??0)>0&&n()}),()=>{t=!0}},[e]);let E=async t=>{let n=await zm(e,t);n.ok?(m(!1),f(e=>e+1),c(t)):alert(`failed: ${n.error}`)},D=async()=>{if(!y||!x.trim()){b(null);return}let t=y.path+`/`+x.trim();if(y.type===`file`){let n=await zm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}else{let n=await Bm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}b(null),S(``),f(e=>e+1)},O=(0,w.useCallback)((t,n)=>{if(t===`view`)c(n.path);else if(t===`new-file`||t===`new-folder`)b({type:t===`new-file`?`file`:`folder`,path:n.path}),S(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Vm(e,n.path).then(e=>{e.ok?(c(e=>e===n.path?null:e),f(e=>e+1)):alert(`delete failed: ${e.error}`)})}},[e]),k=(0,w.useCallback)(t=>PI(e,t.path)?[]:t.type===`dir`?[{label:`New file`,icon:(0,q.jsx)(pe,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,q.jsx)(ye,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,q.jsx)(st,{size:12}),action:`delete`,danger:!0}]:FI(e,t.path)?[]:[{label:`View`,icon:(0,q.jsx)(ue,{size:12}),action:`view`},{label:`Delete`,icon:(0,q.jsx)(st,{size:12}),action:`delete`,danger:!0}],[e]),A=(0,w.useCallback)(t=>Mm(e,t).then(e=>e),[e]),j=(0,w.useCallback)((t,n,r,i)=>{if(t.type===`dir`)return PI(e,t.path)?`w-full py-1.5 flex items-center gap-1.5 bg-amber-50/40 hover:bg-amber-50 text-left border-y border-amber-200/60 mt-1`:`w-full py-1 flex items-center gap-1 hover:bg-gray-50 text-left`;let a=FI(e,t.path);return`w-full py-1 flex items-center gap-2 text-left `+(i?`bg-gray-100`:a?`hover:bg-amber-50/50`:`hover:bg-gray-50`)},[e]),M=h.trim().toLowerCase(),N=M.length>0,P=N?a.filter(e=>e.path.toLowerCase().includes(M)).slice(0,60):[],F=(0,q.jsxs)(`aside`,{className:`w-64 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-9 flex items-center gap-1 border-b border-gray-200`,children:[C&&(0,q.jsx)(`button`,{onClick:()=>v(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,q.jsx)(Be,{size:14})}),(0,q.jsx)(NI,{}),(0,q.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),placeholder:`search files…`,className:`flex-1 min-w-0 bg-transparent outline-none text-[12px] text-gray-700 placeholder:text-gray-400`}),(0,q.jsx)(`button`,{onClick:()=>m(!0),className:`text-gray-500 hover:text-gray-900 px-1.5 rounded hover:bg-gray-100 text-xs`,title:`new file`,children:`+`}),(0,q.jsx)(`button`,{onClick:()=>f(e=>e+1),className:`text-gray-500 hover:text-gray-900 px-1.5 rounded hover:bg-gray-100 text-xs`,title:`refresh`,children:`↻`})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:N?P.length===0?(0,q.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no matches`}):P.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{c(e.path),C&&v(!1)},className:`w-full px-3 py-1.5 flex items-center gap-2 text-left `+(s===e.path?`bg-gray-100`:`hover:bg-gray-50`),title:e.path,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:`📄`}),(0,q.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-gray-900`,children:e.path})]},e.path)):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(WF,{treeId:`vault-${e}`,entries:r,onPick:e=>{c(e),C&&v(!1)},picked:s,onLoadChildren:A,getContextActions:k,onAction:O,nodeClassName:j,reloadKey:d}),r.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`empty · click + 创建第一个文件`})]})}),(0,q.jsx)(`div`,{className:`px-3 h-9 border-t border-gray-200 flex items-center text-[11px] text-gray-500`,children:kI[e]}),e===`knowledge`&&(0,q.jsx)(AI,{resource:e}),e===`notes`&&(0,q.jsx)(jI,{onRefreshed:()=>f(e=>e+1)})]});return(0,q.jsxs)(`div`,{className:`flex h-full w-full`,children:[C?(0,q.jsx)(q.Fragment,{children:_?(0,q.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>v(!1),children:[(0,q.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:F})]}):(0,q.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,q.jsx)(`button`,{type:`button`,onClick:()=>v(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`open file tree`,children:(0,q.jsx)(Ve,{size:16})})})}):F,(0,q.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white min-h-0`,children:s?(0,q.jsx)(RI,{vault:e,path:s,onSelect:c,onSaved:()=>f(e=>e+1),initialEditing:n}):(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-[13px] text-gray-400 italic`,children:`选一个文件,或点 + 新建`})}),p&&(0,q.jsx)(zI,{vault:e,onClose:()=>m(!1),onCreate:E}),y&&(0,q.jsx)(II,{type:y.type,parentPath:y.path,value:x,onChange:S,onSubmit:D,onCancel:()=>b(null)})]})}function NI(){return(0,q.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,className:`text-gray-400 shrink-0`,children:(0,q.jsx)(`path`,{fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,d:`M11 11l3 3M7 12.5a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z`})})}function PI(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).length>0}function FI(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).includes(`/`)}function II({type:e,parentPath:t,value:n,onChange:r,onSubmit:i,onCancel:a}){return(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:a,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,q.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[e===`file`?`New file`:`New folder`,` in `,(0,q.jsx)(`span`,{className:`font-mono text-[13px]`,children:t||`root`})]}),(0,q.jsx)(`input`,{autoFocus:!0,type:`text`,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&i(),e.key===`Escape`&&a()},placeholder:e===`file`?`filename.md`:`folder-name`,className:`w-full px-3 py-2 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,q.jsx)(`button`,{onClick:a,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,q.jsx)(`button`,{onClick:()=>n.trim()&&i(),disabled:!n.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`create`})]})]})})}function LI(e){return/(^|\/)secrets\//.test(e)||e===`secrets`}function RI({vault:e,path:t,onSelect:n,onSaved:r,initialEditing:i}){let a=Og(),o=Gn(),[s,c]=(0,w.useState)(``),[l,u]=(0,w.useState)(``),[d,f]=(0,w.useState)(i??!1),[p,m]=(0,w.useState)(!1),[h,g]=(0,w.useState)([]),[_,v]=(0,w.useState)(null),[y,b]=(0,w.useState)(!1),[x,S]=(0,w.useState)(!1),[C,T]=(0,w.useState)(!1),[E,D]=(0,w.useState)(!1),O=_P(),k=(0,w.useRef)(i);(0,w.useEffect)(()=>{k.current?k.current=!1:f(!1),S(!1),v(null),T(!1),D(!1),Pm(e,t).then(e=>{let t=e?.content??``;c(t),u(t),D(!!e?.secret)}),Hm(e,t).then(g)},[e,t]);let A=LI(t)||E,j=t.endsWith(`.md`),M=e!==`knowledge`,N=!A,P=e===`notes`&&!A,F=A?l.length>0:l!==s,I=(0,w.useCallback)(async()=>{if(!(!F||p)){m(!0);try{let n=await Fm(e,t,l);if(n.ok){if(A?(c(``),u(``)):c(l),v(n.commit??null),f(!1),r(),Hm(e,t).then(g),e===`notes`){let e=await Im();e.ok||(e.conflict?alert(`Saved locally, but it conflicts with the remote (${(e.files??[]).join(`, `)}). Your edit is kept — resolve by taking the remote, or in a loop.`):alert(`Saved locally, but push to remote failed: ${e.error??`unknown`}`))}else if(e===`personal`){let e=await am();e.ok||(e.conflict?alert(`Saved locally, but it conflicts with the remote (${(e.files??[]).join(`, `)}). Your edit is kept — pull first (re-open Personal) or resolve in a loop.`):alert(`Saved locally, but push to remote failed: ${e.error??`unknown`}`))}}else alert(`save failed: ${n.error}`)}finally{m(!1)}}},[e,t,l,F,p,r,A]),L=()=>{f(!0),j&&S(!0)},R=()=>{u(s),f(!1)},z=async()=>{o(`/loop/${(await a.createLoop({title:`edit ${e}/${t}`})).id}`)},B=async()=>{o(`/loop/${(await a.createLoop({title:`distill ${t} → knowledge`,knowledgeRw:!0})).id}`)},V=e=>{n([t.replace(/[^/]+$/,``)+e+`.md`,e+`.md`,e][0].replace(/^\//,``))};return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`header`,{className:`px-3 md:px-5 h-10 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] min-w-0`,children:[(0,q.jsx)(`span`,{className:`text-gray-500 shrink-0`,children:A?`🔒`:`📄`}),(0,q.jsx)(`span`,{className:`font-mono text-[12px] text-gray-500 truncate`,children:t}),_&&!F&&!d&&(0,q.jsxs)(`span`,{className:`hidden md:inline text-[10px] text-emerald-700 font-mono`,children:[`commit `,_]})]}),(0,q.jsx)(`div`,{className:`flex items-center gap-1 md:gap-2 text-xs text-gray-500`,children:d?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{onClick:R,className:`px-2.5 h-7 rounded text-xs text-gray-600 hover:bg-gray-100`,children:`cancel`}),(0,q.jsx)(`button`,{onClick:I,disabled:!F||p,className:`px-2.5 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:p?`saving…`:`save`})]}):(0,q.jsxs)(q.Fragment,{children:[P&&(0,q.jsxs)(`button`,{onClick:B,className:`px-2.5 h-7 rounded text-xs bg-amber-100 text-amber-900 hover:bg-amber-200 flex items-center gap-1`,title:`open a loop to distill this notes file into knowledge`,children:[(0,q.jsx)(`span`,{children:`↑`}),(0,q.jsx)(`span`,{children:`distill`})]}),N&&(0,q.jsxs)(`button`,{onClick:z,className:P?`px-2.5 h-7 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-900 flex items-center gap-1`:`px-2.5 h-7 rounded text-xs bg-gray-900 text-white hover:bg-gray-700 flex items-center gap-1`,title:`open a new loop with AI assist for this file`,children:[(0,q.jsx)(`span`,{children:`↻`}),(0,q.jsx)(`span`,{children:`edit by loop`})]}),M&&(0,q.jsx)(`button`,{onClick:L,className:`px-2.5 h-7 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-900`,title:`direct edit (fastpath)`,children:`edit`}),O&&j&&(0,q.jsxs)(`button`,{onClick:()=>b(e=>!e),className:`px-2.5 h-7 rounded text-xs border ${y?`bg-gray-900 text-white`:`border-gray-200 hover:bg-gray-100 text-gray-900`}`,title:`toggle backlinks`,children:[`⇄ `,h.length]})]})})]}),d?A?(0,q.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{className:`text-amber-700`,children:`🔒`}),(0,q.jsx)(`span`,{children:`new value · saved encrypted`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>T(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,q.jsx)(CI,{path:t,value:l,onChange:u})})})]}):j&&!x?(0,q.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col md:flex-row`:`flex-1 min-h-0 min-w-0 flex flex-col md:flex-row`,children:[(0,q.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 border-r border-gray-200 flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{children:`source · markdown`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>S(!0),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to WYSIWYG editor`,children:`wysiwyg`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>T(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,q.jsx)(CI,{path:t,value:l,onChange:u})})})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,q.jsx)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center text-[11px] text-gray-500`,children:`preview`}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto px-6 py-4`,children:(0,q.jsx)(`div`,{className:`max-w-[760px]`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading preview...`}),children:(0,q.jsx)(wI,{text:l,onWikilink:V})})})})]})]}):j?(0,q.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,q.jsx)(`span`,{children:`wysiwyg · milkdown`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>S(!1),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to source editor`,children:`source`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>T(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,q.jsx)(TI,{value:l,onChange:u})})})]}):(0,q.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-7 shrink-0 border-b border-gray-200 flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,q.jsxs)(`span`,{children:[`source · `,t.includes(`.`)?t.split(`.`).pop():`text`]}),t.endsWith(`.json`)&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>{try{u(JSON.stringify(JSON.parse(l),null,2))}catch(e){alert(`Invalid JSON: `+(e?.message??`parse error`))}},className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Format JSON`,children:`format`}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{onClick:()=>T(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,q.jsx)(Fe,{size:13}):(0,q.jsx)(Me,{size:13})})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,q.jsx)(CI,{path:t,value:l,onChange:u})})})]}):(0,q.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:[(0,q.jsx)(`article`,{className:`flex-1 min-h-0 overflow-auto px-4 md:px-8 py-4 md:py-6`,children:(0,q.jsx)(`div`,{className:`max-w-[760px]`,children:A?(0,q.jsxs)(`div`,{className:`font-sans text-[13px] text-gray-600 leading-relaxed`,children:[(0,q.jsx)(`div`,{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded bg-amber-50 border border-amber-200 text-amber-800 text-[12px] font-medium`,children:`encrypted · value hidden by design`}),(0,q.jsxs)(`div`,{className:`mt-3 text-[12px] text-gray-500`,children:[`Click `,(0,q.jsx)(`b`,{children:`edit`}),` to overwrite. The current value is never returned by the server, so editing means typing a new replacement — there is no decrypt-and-view.`]})]}):j?(0,q.jsx)(w.Suspense,{fallback:(0,q.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading...`}),children:(0,q.jsx)(wI,{text:s,onWikilink:V})}):(0,q.jsx)(`pre`,{className:`font-mono text-[12.5px] leading-relaxed whitespace-pre-wrap text-gray-900`,children:s||(0,q.jsx)(`span`,{className:`text-gray-400 italic`,children:`(empty)`})})})}),j&&!O&&(0,q.jsxs)(`aside`,{className:`w-64 shrink-0 border-l border-gray-200 bg-gray-50 overflow-auto`,children:[(0,q.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,q.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length})]}),h.length===0?(0,q.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,q.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,q.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,q.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]}),O&&j&&y&&(0,q.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>b(!1),children:[(0,q.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,q.jsxs)(`div`,{className:`absolute right-0 top-0 bottom-0 w-64 max-w-[80vw] bg-gray-50 border-l border-gray-200 shadow-xl overflow-auto`,onClick:e=>e.stopPropagation(),children:[(0,q.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,q.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,q.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length}),(0,q.jsx)(`button`,{onClick:()=>b(!1),className:`ml-2 text-gray-400 hover:text-gray-700 px-1`,title:`close backlinks`,children:`✕`})]}),h.length===0?(0,q.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,q.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{n(e.path),b(!1)},className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,q.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,q.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]})]})]})]})}function zI({vault:e,onClose:t,onCreate:n}){let[r,i]=(0,w.useState)(``);return(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,q.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,q.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[`new file in `,e,`/`]}),(0,q.jsx)(`input`,{autoFocus:!0,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`loopat/new-doc.md`,className:`w-full px-3 py-2 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,q.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`relative path. directories created as needed.`}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,q.jsx)(`button`,{onClick:t,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,q.jsx)(`button`,{onClick:()=>r.trim()&&n(r.trim()),disabled:!r.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`create`})]})]})})}function BI(){let[e,t]=(0,w.useState)(null),[n,r]=(0,w.useState)([]),[i,a]=(0,w.useState)(!1),[o,s]=(0,w.useState)(null),c=(0,w.useCallback)(async()=>{let e=await Um();t(e),r(e.repos)},[]);(0,w.useEffect)(()=>{c()},[c]);let l=e!==null&&JSON.stringify(n)!==JSON.stringify(e.repos),u=()=>r(e=>[...e,{name:``,git:``}]),d=(e,t,n)=>r(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r)),f=e=>r(t=>t.filter((t,n)=>n!==e));return e?(0,q.jsx)(`article`,{className:`flex-1 min-w-0 overflow-auto p-5`,children:(0,q.jsxs)(`div`,{className:`max-w-2xl flex flex-col gap-5`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900`,children:`Repo roster`}),(0,q.jsxs)(`p`,{className:`text-[12px] text-gray-500 leading-relaxed mt-1`,children:[`Personal — saved straight to your own`,` `,(0,q.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[11px]`,children:`.loopat/config.json`}),`. Repos are cloned on demand when a loop selects one.`]})]}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`repos`}),n.length===0&&(0,q.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:`No repos yet.`}),n.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`input`,{value:e.name,onChange:e=>d(t,`name`,e.target.value),placeholder:`name`,className:`w-40 px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,q.jsx)(`input`,{value:e.git,onChange:e=>d(t,`git`,e.target.value),placeholder:`git@…/repo.git`,className:`flex-1 px-2 py-1.5 text-sm font-mono border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>f(t),className:`px-2 py-1.5 text-gray-400 hover:text-red-600`,title:`remove`,children:`✕`})]},t)),(0,q.jsx)(`button`,{type:`button`,onClick:u,className:`self-start text-[12px] text-gray-600 hover:text-gray-900 border border-gray-200 rounded px-2 py-1`,children:`+ add repo`})]}),o&&(0,q.jsx)(`div`,{className:`text-[12px] rounded px-2 py-1.5 border ${o.ok?`text-emerald-700 bg-emerald-50 border-emerald-200`:`text-red-700 bg-red-50 border-red-200`}`,children:o.text}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:async()=>{a(!0),s(null);let e=await Wm({repos:n.map(e=>({name:e.name.trim(),git:e.git.trim()})).filter(e=>e.name&&e.git)});a(!1),e.ok?(s({ok:!0,text:`Saved.`}),await c()):s({ok:!1,text:`Save failed: `+(e.error??``)})},disabled:!l||i,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:i?`Saving…`:`Save`}),l&&(0,q.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`unsaved changes`})]})]})}):(0,q.jsx)(`div`,{className:`p-6 text-sm text-gray-400`,children:`loading…`})}function VI(){var e=[...arguments];return(0,w.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var HI=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function UI(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function WI(e){return`nodeType`in e}function GI(e){return e?UI(e)?e:WI(e)?e.ownerDocument?.defaultView??window:window:window}function KI(e){let{Document:t}=GI(e);return e instanceof t}function qI(e){return UI(e)?!1:e instanceof GI(e).HTMLElement}function JI(e){return e instanceof GI(e).SVGElement}function YI(e){return e?UI(e)?e.document:WI(e)?KI(e)?e:qI(e)||JI(e)?e.ownerDocument:document:document:document}var XI=HI?w.useLayoutEffect:w.useEffect;function ZI(e){let t=(0,w.useRef)(e);return XI(()=>{t.current=e}),(0,w.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function QI(){let e=(0,w.useRef)(null);return[(0,w.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,w.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function $I(e,t){t===void 0&&(t=[e]);let n=(0,w.useRef)(e);return XI(()=>{n.current!==e&&(n.current=e)},t),n}function eL(e,t){let n=(0,w.useRef)();return(0,w.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function tL(e){let t=ZI(e),n=(0,w.useRef)(null);return[n,(0,w.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function nL(e){let t=(0,w.useRef)();return(0,w.useEffect)(()=>{t.current=e},[e]),t.current}var rL={};function iL(e,t){return(0,w.useMemo)(()=>{if(t)return t;let n=rL[e]==null?0:rL[e]+1;return rL[e]=n,e+`-`+n},[e,t])}function aL(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var oL=aL(1),sL=aL(-1);function cL(e){return`clientX`in e&&`clientY`in e}function lL(e){if(!e)return!1;let{KeyboardEvent:t}=GI(e.target);return t&&e instanceof t}function uL(e){if(!e)return!1;let{TouchEvent:t}=GI(e.target);return t&&e instanceof t}function dL(e){if(uL(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return cL(e)?{x:e.clientX,y:e.clientY}:null}var fL=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[fL.Translate.toString(e),fL.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),pL=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function mL(e){return e.matches(pL)?e:e.querySelector(pL)}var hL={display:`none`};function gL(e){let{id:t,value:n}=e;return w.createElement(`div`,{id:t,style:hL},n)}function _L(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return w.createElement(`div`,{id:t,style:{position:`fixed`,top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(100%)`,whiteSpace:`nowrap`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function vL(){let[e,t]=(0,w.useState)(``);return{announce:(0,w.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var yL=(0,w.createContext)(null);function bL(e){let t=(0,w.useContext)(yL);(0,w.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function xL(){let[e]=(0,w.useState)(()=>new Set),t=(0,w.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,w.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var SL={draggable:`
|
|
91
91
|
To pick up a draggable item, press the space bar.
|
|
92
92
|
While dragging, use the arrow keys to move the item.
|
|
93
93
|
Press space again to drop the item in its new position, or press escape to cancel.
|