loopat 0.1.42 → 0.1.43
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 +1 -1
- package/server/src/loop-status.ts +33 -1
- package/server/src/session.ts +9 -2
- package/server/src/term.ts +10 -2
- package/web/dist/assets/{Editor-BJwSRhKT.js → Editor-0dvlktuX.js} +1 -1
- package/web/dist/assets/{Markdown-DVBIITE2.js → Markdown-B7OaedKV.js} +1 -1
- package/web/dist/assets/{MilkdownEditor-DOK-C67j.js → MilkdownEditor-DOe3xJcb.js} +1 -1
- package/web/dist/assets/index-D-WGDCY6.css +1 -0
- package/web/dist/assets/{index-DEEXxNtl.js → index-DLZro4Ds.js} +32 -32
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-CZiZcXZf.css +0 -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-0dvlktuX.js","assets/jsx-runtime-Bt-cYkS5.js","assets/CodeEditor-DtHZtsPs.js","assets/w3c-keyname-BOAvb0qz.js","assets/Terminal-trnCVajY.js","assets/Terminal-BrP-ENHg.css","assets/Markdown-B7OaedKV.js","assets/MilkdownEditor-DOe3xJcb.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-Bt-cYkS5.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 a=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}}}})),o=r(((e,t)=>{t.exports=a()})),s=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.7`})),c=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=s()})),l=r((e=>{var n=o(),r=t(),i=c();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 s(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function l(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 u(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 d(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 f(e){if(l(e)!==e)throw Error(a(188))}function p(e){var t=e.alternate;if(!t){if(t=l(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 f(i),e;if(o===r)return f(i),t;o=o.sibling}throw Error(a(188))}if(n.return!==r.return)n=i,r=o;else{for(var s=!1,c=i.child;c;){if(c===n){s=!0,n=i,r=o;break}if(c===r){s=!0,r=i,n=o;break}c=c.sibling}if(!s){for(c=o.child;c;){if(c===n){s=!0,n=o,r=i;break}if(c===r){s=!0,r=o,n=i;break}c=c.sibling}if(!s)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 m(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=m(e),t!==null)return t;e=e.sibling}return null}var h=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 ee=V(null),W=V(null),te=V(null),ne=V(null);function G(e,t){switch(U(te,t),U(W,e),U(ee,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(ee),U(ee,e)}function re(){H(ee),H(W),H(te)}function ie(e){e.memoizedState!==null&&U(ne,e);var t=ee.current,n=Jd(t,e.type);t!==n&&(U(W,e),U(ee,n))}function ae(e){W.current===e&&(H(ee),H(W)),ne.current===e&&(H(ne),ip._currentValue=R)}var oe,se;function ce(e){if(oe===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);oe=t&&t[1]||``,se=-1<e.stack.indexOf(`
|
|
3
3
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
4
4
|
`+oe+e+se}var le=!1;function ue(e,t){if(!e||le)return``;le=!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 _.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},$s=`DialogDescriptionWarning`,ec=({contentRef:e,descriptionId:t})=>{let n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Zs($s).contentName}}.`;return _.useEffect(()=>{let r=e.current?.getAttribute(`aria-describedby`);t&&r&&(document.getElementById(t)||console.warn(n))},[n,e,t]),null},tc=Es,nc=Ms,rc=Ps,ic=Rs,ac=Us,oc=Gs,sc=qs;function cc(e){let[t,n]=_.useState(void 0);return Ji(()=>{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 lc=[`top`,`right`,`bottom`,`left`],uc=Math.min,dc=Math.max,fc=Math.round,pc=Math.floor,mc=e=>({x:e,y:e}),hc={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function gc(e,t,n){return dc(e,uc(t,n))}function _c(e,t){return typeof e==`function`?e(t):e}function vc(e){return e.split(`-`)[0]}function yc(e){return e.split(`-`)[1]}function bc(e){return e===`x`?`y`:`x`}function xc(e){return e===`y`?`height`:`width`}function Sc(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function Cc(e){return bc(Sc(e))}function wc(e,t,n){n===void 0&&(n=!1);let r=yc(e),i=Cc(e),a=xc(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Nc(o)),[o,Nc(o)]}function Tc(e){let t=Nc(e);return[Ec(e),t,Ec(t)]}function Ec(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var Dc=[`left`,`right`],Oc=[`right`,`left`],kc=[`top`,`bottom`],Ac=[`bottom`,`top`];function jc(e,t,n){switch(e){case`top`:case`bottom`:return n?t?Oc:Dc:t?Dc:Oc;case`left`:case`right`:return t?kc:Ac;default:return[]}}function Mc(e,t,n,r){let i=yc(e),a=jc(vc(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Ec)))),a}function Nc(e){let t=vc(e);return hc[t]+e.slice(t.length)}function Pc(e){return{top:0,right:0,bottom:0,left:0,...e}}function Fc(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Pc(e)}function Ic(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 Lc(e,t,n){let{reference:r,floating:i}=e,a=Sc(t),o=Cc(t),s=xc(o),c=vc(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(yc(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 Rc(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}=_c(t,e),p=Fc(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Ic(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=Ic(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 zc=50,Bc=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Rc},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Lc(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<zc&&(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}=Lc(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},Vc=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}=_c(e,t)||{};if(l==null)return{};let d=Fc(u),f={x:n,y:r},p=Cc(i),m=xc(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=uc(d[_],T),D=uc(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=gc(O,A,k),M=!c.arrow&&yc(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}}}),Hc=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}=_c(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=vc(r),_=Sc(o),v=vc(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Nc(o)]:Tc(o)),x=p!==`none`;!d&&x&&b.push(...Mc(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=wc(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`&&_!==Sc(t))||T.every(e=>Sc(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=Sc(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 Uc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Wc(e){return lc.some(t=>e[t]>=0)}var Gc=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=_c(e,t);switch(i){case`referenceHidden`:{let e=Uc(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:Wc(e)}}}case`escaped`:{let e=Uc(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:Wc(e)}}}default:return{}}}}},Kc=new Set([`left`,`top`]);async function qc(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=vc(n),s=yc(n),c=Sc(n)===`y`,l=Kc.has(o)?-1:1,u=a&&c?-1:1,d=_c(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 Jc=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 qc(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}}}}},Yc=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}=_c(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Sc(vc(i)),p=bc(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=gc(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=gc(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}}}}}},Xc=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}=_c(e,t),u={x:n,y:r},d=Sc(i),f=bc(d),p=u[f],m=u[d],h=_c(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=Kc.has(vc(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}}}},Zc=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}=_c(e,t),u=await o.detectOverflow(t,l),d=vc(i),f=yc(i),p=Sc(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=uc(h-u[g],v),x=uc(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=dc(u.left,0),t=dc(u.right,0),n=dc(u.top,0),r=dc(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:dc(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:dc(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 Qc(){return typeof window<`u`}function $c(e){return nl(e)?(e.nodeName||``).toLowerCase():`#document`}function el(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function tl(e){return((nl(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function nl(e){return Qc()?e instanceof Node||e instanceof el(e).Node:!1}function rl(e){return Qc()?e instanceof Element||e instanceof el(e).Element:!1}function il(e){return Qc()?e instanceof HTMLElement||e instanceof el(e).HTMLElement:!1}function al(e){return!Qc()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof el(e).ShadowRoot}function ol(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=_l(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function sl(e){return/^(table|td|th)$/.test($c(e))}function cl(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var ll=/transform|translate|scale|rotate|perspective|filter/,ul=/paint|layout|strict|content/,dl=e=>!!e&&e!==`none`,fl;function pl(e){let t=rl(e)?_l(e):e;return dl(t.transform)||dl(t.translate)||dl(t.scale)||dl(t.rotate)||dl(t.perspective)||!hl()&&(dl(t.backdropFilter)||dl(t.filter))||ll.test(t.willChange||``)||ul.test(t.contain||``)}function ml(e){let t=yl(e);for(;il(t)&&!gl(t);){if(pl(t))return t;if(cl(t))return null;t=yl(t)}return null}function hl(){return fl??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),fl}function gl(e){return/^(html|body|#document)$/.test($c(e))}function _l(e){return el(e).getComputedStyle(e)}function vl(e){return rl(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function yl(e){if($c(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||al(e)&&e.host||tl(e);return al(t)?t.host:t}function bl(e){let t=yl(e);return gl(t)?e.ownerDocument?e.ownerDocument.body:e.body:il(t)&&ol(t)?t:bl(t)}function xl(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=bl(e),i=r===e.ownerDocument?.body,a=el(r);if(i){let e=Sl(a);return t.concat(a,a.visualViewport||[],ol(r)?r:[],e&&n?xl(e):[])}else return t.concat(r,xl(r,[],n))}function Sl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Cl(e){let t=_l(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=il(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=fc(n)!==a||fc(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function wl(e){return rl(e)?e:e.contextElement}function Tl(e){let t=wl(e);if(!il(t))return mc(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Cl(t),o=(a?fc(n.width):n.width)/r,s=(a?fc(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var El=mc(0);function Dl(e){let t=el(e);return!hl()||!t.visualViewport?El:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ol(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==el(e)?!1:t}function kl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=wl(e),o=mc(1);t&&(r?rl(r)&&(o=Tl(r)):o=Tl(e));let s=Ol(a,n,r)?Dl(a):mc(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=el(a),t=r&&rl(r)?el(r):r,n=e,i=Sl(n);for(;i&&r&&t!==n;){let e=Tl(i),t=i.getBoundingClientRect(),r=_l(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=el(i),i=Sl(n)}}return Ic({width:u,height:d,x:c,y:l})}function Al(e,t){let n=vl(e).scrollLeft;return t?t.left+n:kl(tl(e)).left+n}function jl(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Al(e,n),y:n.top+t.scrollTop}}function Ml(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=tl(r),s=t?cl(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=mc(1),u=mc(0),d=il(r);if((d||!d&&!a)&&(($c(r)!==`body`||ol(o))&&(c=vl(r)),d)){let e=kl(r);l=Tl(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?jl(o,c):mc(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 Nl(e){return Array.from(e.getClientRects())}function Pl(e){let t=tl(e),n=vl(e),r=e.ownerDocument.body,i=dc(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=dc(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+Al(e),s=-n.scrollTop;return _l(r).direction===`rtl`&&(o+=dc(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var Fl=25;function Il(e,t){let n=el(e),r=tl(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=hl();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=Al(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<=Fl&&(a-=o)}else l<=Fl&&(a+=l);return{width:a,height:o,x:s,y:c}}function Ll(e,t){let n=kl(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=il(e)?Tl(e):mc(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Rl(e,t,n){let r;if(t===`viewport`)r=Il(e,n);else if(t===`document`)r=Pl(tl(e));else if(rl(t))r=Ll(t,n);else{let n=Dl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Ic(r)}function zl(e,t){let n=yl(e);return n===t||!rl(n)||gl(n)?!1:_l(n).position===`fixed`||zl(n,t)}function Bl(e,t){let n=t.get(e);if(n)return n;let r=xl(e,[],!1).filter(e=>rl(e)&&$c(e)!==`body`),i=null,a=_l(e).position===`fixed`,o=a?yl(e):e;for(;rl(o)&&!gl(o);){let t=_l(o),n=pl(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||ol(o)&&!n&&zl(e,o))?r=r.filter(e=>e!==o):i=t,o=yl(o)}return t.set(e,r),r}function Vl(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?cl(t)?[]:Bl(t,this._c):[].concat(n),r],o=Rl(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=Rl(t,a[e],i);s=dc(n.top,s),c=uc(n.right,c),l=uc(n.bottom,l),u=dc(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Hl(e){let{width:t,height:n}=Cl(e);return{width:t,height:n}}function Ul(e,t,n){let r=il(t),i=tl(t),a=n===`fixed`,o=kl(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=mc(0);function l(){c.x=Al(i)}if(r||!r&&!a)if(($c(t)!==`body`||ol(i))&&(s=vl(t)),r){let e=kl(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?jl(i,s):mc(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 Wl(e){return _l(e).position===`static`}function Gl(e,t){if(!il(e)||_l(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return tl(e)===n&&(n=n.ownerDocument.body),n}function Kl(e,t){let n=el(e);if(cl(e))return n;if(!il(e)){let t=yl(e);for(;t&&!gl(t);){if(rl(t)&&!Wl(t))return t;t=yl(t)}return n}let r=Gl(e,t);for(;r&&sl(r)&&Wl(r);)r=Gl(r,t);return r&&gl(r)&&Wl(r)&&!pl(r)?n:r||ml(e)||n}var ql=async function(e){let t=this.getOffsetParent||Kl,n=this.getDimensions,r=await n(e.floating);return{reference:Ul(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Jl(e){return _l(e).direction===`rtl`}var Yl={convertOffsetParentRelativeRectToViewportRelativeRect:Ml,getDocumentElement:tl,getClippingRect:Vl,getOffsetParent:Kl,getElementRects:ql,getClientRects:Nl,getDimensions:Hl,getScale:Tl,isElement:rl,isRTL:Jl};function Xl(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Zl(e,t){let n=null,r,i=tl(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=pc(d),h=pc(i.clientWidth-(u+f)),g=pc(i.clientHeight-(d+p)),_=pc(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:dc(0,uc(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&&!Xl(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 Ql(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=wl(e),u=i||a?[...l?xl(l):[],...t?xl(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?Zl(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?kl(e):null;c&&g();function g(){let t=kl(e);h&&!Xl(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 $l=Jc,eu=Yc,tu=Hc,nu=Zc,ru=Gc,iu=Vc,au=Xc,ou=(e,t,n)=>{let r=new Map,i={platform:Yl,...n},a={...i.platform,_c:r};return Bc(e,t,{...i,platform:a})},su=typeof document<`u`?_.useLayoutEffect:function(){};function cu(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(!cu(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)&&!cu(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function lu(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function uu(e,t){let n=lu(e);return Math.round(t*n)/n}function du(e){let t=_.useRef(e);return su(()=>{t.current=e}),t}function fu(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]=_.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=_.useState(r);cu(f,r)||p(r);let[m,h]=_.useState(null),[g,v]=_.useState(null),y=_.useCallback(e=>{e!==C.current&&(C.current=e,h(e))},[]),b=_.useCallback(e=>{e!==w.current&&(w.current=e,v(e))},[]),x=a||m,S=o||g,C=_.useRef(null),w=_.useRef(null),T=_.useRef(u),E=c!=null,D=du(c),O=du(i),k=du(l),A=_.useCallback(()=>{if(!C.current||!w.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),ou(C.current,w.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!cu(T.current,t)&&(T.current=t,dt.flushSync(()=>{d(t)}))})},[f,t,n,O,k]);su(()=>{l===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let j=_.useRef(!1);su(()=>(j.current=!0,()=>{j.current=!1}),[]),su(()=>{if(x&&(C.current=x),S&&(w.current=S),x&&S){if(D.current)return D.current(x,S,A);A()}},[x,S,A,D,E]);let M=_.useMemo(()=>({reference:C,floating:w,setReference:y,setFloating:b}),[y,b]),N=_.useMemo(()=>({reference:x,floating:S}),[x,S]),P=_.useMemo(()=>{let e={position:n,left:0,top:0};if(!N.floating)return e;let t=uu(N.floating,u.x),r=uu(N.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...lu(N.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,N.floating,u.x,u.y]);return _.useMemo(()=>({...u,update:A,refs:M,elements:N,floatingStyles:P}),[u,A,M,N,P])}var pu=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?{}:iu({element:r.current,padding:i}).fn(n):r?iu({element:r,padding:i}).fn(n):{}}}},mu=(e,t)=>{let n=$l(e);return{name:n.name,fn:n.fn,options:[e,t]}},hu=(e,t)=>{let n=eu(e);return{name:n.name,fn:n.fn,options:[e,t]}},gu=(e,t)=>({fn:au(e).fn,options:[e,t]}),_u=(e,t)=>{let n=tu(e);return{name:n.name,fn:n.fn,options:[e,t]}},vu=(e,t)=>{let n=nu(e);return{name:n.name,fn:n.fn,options:[e,t]}},yu=(e,t)=>{let n=ru(e);return{name:n.name,fn:n.fn,options:[e,t]}},bu=(e,t)=>{let n=pu(e);return{name:n.name,fn:n.fn,options:[e,t]}},xu=`Arrow`,Su=_.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,K.jsx)(zi.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,K.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})});Su.displayName=xu;var Cu=Su,wu=`Popper`,[Tu,Eu]=Ki(wu),[Du,Ou]=Tu(wu),ku=e=>{let{__scopePopper:t,children:n}=e,[r,i]=_.useState(null);return(0,K.jsx)(Du,{scope:t,anchor:r,onAnchorChange:i,children:n})};ku.displayName=wu;var Au=`PopperAnchor`,ju=_.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=Ou(Au,n),o=_.useRef(null),s=Ai(t,o),c=_.useRef(null);return _.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,K.jsx)(zi.div,{...i,ref:s})});ju.displayName=Au;var Mu=`PopperContent`,[Nu,Pu]=Tu(Mu),Fu=_.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=Ou(Mu,n),[v,y]=_.useState(null),b=Ai(t,e=>y(e)),[x,S]=_.useState(null),C=cc(x),w=C?.width??0,T=C?.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(zu),altBoundary:k},{refs:j,floatingStyles:M,placement:N,isPositioned:P,middlewareData:F}=fu({strategy:`fixed`,placement:E,whileElementsMounted:(...e)=>Ql(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[mu({mainAxis:i+T,alignmentAxis:o}),c&&hu({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?gu():void 0,...A}),c&&_u({...A}),vu({...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`)}}),x&&bu({element:x,padding:s}),Bu({arrowWidth:w,arrowHeight:T}),f&&yu({strategy:`referenceHidden`,...A})]}),[I,L]=Vu(N),R=ba(m);Ji(()=>{P&&R?.()},[P,R]);let z=F.arrow?.x,B=F.arrow?.y,V=F.arrow?.centerOffset!==0,[H,U]=_.useState();return Ji(()=>{v&&U(window.getComputedStyle(v).zIndex)},[v]),(0,K.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,K.jsx)(Nu,{scope:n,placedSide:I,onArrowChange:S,arrowX:z,arrowY:B,shouldHideArrow:V,children:(0,K.jsx)(zi.div,{"data-side":I,"data-align":L,...h,ref:b,style:{...h.style,animation:P?void 0:`none`}})})})});Fu.displayName=Mu;var Iu=`PopperArrow`,Lu={top:`bottom`,right:`left`,bottom:`top`,left:`right`},Ru=_.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=Pu(Iu,n),a=Lu[i.placedSide];return(0,K.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,K.jsx)(Cu,{...r,ref:t,style:{...r.style,display:`block`}})})});Ru.displayName=Iu;function zu(e){return e!==null}var Bu=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]=Vu(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 Vu(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var Hu=ku,Uu=ju,Wu=Fu,Gu=Ru,Ku=`Popover`,[qu,Ju]=Ki(Ku,[Eu]),Yu=Eu(),[Xu,Zu]=qu(Ku),Qu=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=Yu(t),c=_.useRef(null),[l,u]=_.useState(!1),[d,f]=Xi({prop:r,defaultProp:i??!1,onChange:a,caller:Ku});return(0,K.jsx)(Hu,{...s,children:(0,K.jsx)(Xu,{scope:t,contentId:oa(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:_.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:_.useCallback(()=>u(!0),[]),onCustomAnchorRemove:_.useCallback(()=>u(!1),[]),modal:o,children:n})})};Qu.displayName=Ku;var $u=`PopoverAnchor`,ed=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Zu($u,n),a=Yu(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return _.useEffect(()=>(o(),()=>s()),[o,s]),(0,K.jsx)(Uu,{...a,...r,ref:t})});ed.displayName=$u;var td=`PopoverTrigger`,nd=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Zu(td,n),a=Yu(n),o=Ai(t,i.triggerRef),s=(0,K.jsx)(zi.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":_d(i.open),...r,ref:o,onClick:q(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,K.jsx)(Uu,{asChild:!0,...a,children:s})});nd.displayName=td;var rd=`PopoverPortal`,[id,ad]=qu(rd,{forceMount:void 0}),od=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=Zu(rd,t);return(0,K.jsx)(id,{scope:t,forceMount:n,children:(0,K.jsx)(ea,{present:n||a.open,children:(0,K.jsx)(Qa,{asChild:!0,container:i,children:r})})})};od.displayName=rd;var sd=`PopoverContent`,cd=_.forwardRef((e,t)=>{let n=ad(sd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=Zu(sd,e.__scopePopover);return(0,K.jsx)(ea,{present:r||a.open,children:a.modal?(0,K.jsx)(ud,{...i,ref:t}):(0,K.jsx)(dd,{...i,ref:t})})});cd.displayName=sd;var ld=ji(`PopoverContent.RemoveScroll`),ud=_.forwardRef((e,t)=>{let n=Zu(sd,e.__scopePopover),r=_.useRef(null),i=Ai(t,r),a=_.useRef(!1);return _.useEffect(()=>{let e=r.current;if(e)return bs(e)},[]),(0,K.jsx)(ds,{as:ld,allowPinchZoom:!0,children:(0,K.jsx)(fd,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:q(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:q(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:q(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),dd=_.forwardRef((e,t)=>{let n=Zu(sd,e.__scopePopover),r=_.useRef(!1),i=_.useRef(!1);return(0,K.jsx)(fd,{...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()}})}),fd=_.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=Zu(sd,n),p=Yu(n);return eo(),(0,K.jsx)(za,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,K.jsx)(Oa,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,K.jsx)(Wu,{"data-state":_d(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)`}})})})}),pd=`PopoverClose`,md=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Zu(pd,n);return(0,K.jsx)(zi.button,{type:`button`,...r,ref:t,onClick:q(e.onClick,()=>i.onOpenChange(!1))})});md.displayName=pd;var hd=`PopoverArrow`,gd=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Yu(n);return(0,K.jsx)(Gu,{...i,...r,ref:t})});gd.displayName=hd;function _d(e){return e?`open`:`closed`}var vd=Qu,yd=nd,bd=od,xd=cd,Sd=md,[Cd,wd]=Ki(`Tooltip`,[Eu]),Td=Eu(),Ed=`TooltipProvider`,Dd=700,Od=`tooltip.open`,[kd,Ad]=Cd(Ed),jd=e=>{let{__scopeTooltip:t,delayDuration:n=Dd,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=_.useRef(!0),s=_.useRef(!1),c=_.useRef(0);return _.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,K.jsx)(kd,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:_.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:_.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:_.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};jd.displayName=Ed;var Md=`Tooltip`,[Nd,Pd]=Cd(Md),Fd=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Ad(Md,e.__scopeTooltip),l=Td(t),[u,d]=_.useState(null),f=oa(),p=_.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=_.useRef(!1),[v,y]=Xi({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(Od))):c.onClose(),a?.(e)},caller:Md}),b=_.useMemo(()=>v?g.current?`delayed-open`:`instant-open`:`closed`,[v]),x=_.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,y(!0)},[y]),S=_.useCallback(()=>{window.clearTimeout(p.current),p.current=0,y(!1)},[y]),C=_.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,y(!0),p.current=0},h)},[h,y]);return _.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,K.jsx)(Hu,{...l,children:(0,K.jsx)(Nd,{scope:t,contentId:f,open:v,stateAttribute:b,trigger:u,onTriggerChange:d,onTriggerEnter:_.useCallback(()=>{c.isOpenDelayedRef.current?C():x()},[c.isOpenDelayedRef,C,x]),onTriggerLeave:_.useCallback(()=>{m?S():(window.clearTimeout(p.current),p.current=0)},[S,m]),onOpen:x,onClose:S,disableHoverableContent:m,children:n})})};Fd.displayName=Md;var Id=`TooltipTrigger`,Ld=_.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Pd(Id,n),a=Ad(Id,n),o=Td(n),s=Ai(t,_.useRef(null),i.onTriggerChange),c=_.useRef(!1),l=_.useRef(!1),u=_.useCallback(()=>c.current=!1,[]);return _.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,K.jsx)(Uu,{asChild:!0,...o,children:(0,K.jsx)(zi.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:q(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:q(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:q(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:q(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:q(e.onBlur,i.onClose),onClick:q(e.onClick,i.onClose)})})});Ld.displayName=Id;var Rd=`TooltipPortal`,[zd,Bd]=Cd(Rd,{forceMount:void 0}),Vd=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=Pd(Rd,t);return(0,K.jsx)(zd,{scope:t,forceMount:n,children:(0,K.jsx)(ea,{present:n||a.open,children:(0,K.jsx)(Qa,{asChild:!0,container:i,children:r})})})};Vd.displayName=Rd;var Hd=`TooltipContent`,Ud=_.forwardRef((e,t)=>{let n=Bd(Hd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=Pd(Hd,e.__scopeTooltip);return(0,K.jsx)(ea,{present:r||o.open,children:o.disableHoverableContent?(0,K.jsx)(Jd,{side:i,...a,ref:t}):(0,K.jsx)(Wd,{side:i,...a,ref:t})})}),Wd=_.forwardRef((e,t)=>{let n=Pd(Hd,e.__scopeTooltip),r=Ad(Hd,e.__scopeTooltip),i=_.useRef(null),a=Ai(t,i),[o,s]=_.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=_.useCallback(()=>{s(null),d(!1)},[d]),p=_.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=Qd(r,Zd(r,n.getBoundingClientRect())),a=$d(t.getBoundingClientRect());s(tf([...i,...a])),d(!0)},[d]);return _.useEffect(()=>()=>f(),[f]),_.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]),_.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=!ef(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,K.jsx)(Jd,{...e,ref:a})}),[Gd,Kd]=Cd(Md,{isInside:!1}),qd=Fi(`TooltipContent`),Jd=_.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=Pd(Hd,n),l=Td(n),{onClose:u}=c;return _.useEffect(()=>(document.addEventListener(Od,u),()=>document.removeEventListener(Od,u)),[u]),_.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,K.jsx)(Oa,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,K.jsxs)(Wu,{"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,K.jsx)(qd,{children:r}),(0,K.jsx)(Gd,{scope:n,isInside:!0,children:(0,K.jsx)(Wi,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});Ud.displayName=Hd;var Yd=`TooltipArrow`,Xd=_.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Td(n);return Kd(Yd,n).isInside?null:(0,K.jsx)(Gu,{...i,...r,ref:t})});Xd.displayName=Yd;function Zd(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 Qd(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 $d(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 ef(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 tf(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)),nf(t)}function nf(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 rf=jd,af=Fd,of=Ld,sf=Vd,cf=Ud,lf=Xd;function uf(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=uf(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function df(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=uf(e))&&(r&&(r+=` `),r+=t);return r}var ff=(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},pf=(e,t)=>({classGroupId:e,validator:t}),mf=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),hf=`-`,gf=[],_f=`arbitrary..`,vf=e=>{let t=xf(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:e=>{if(e.startsWith(`[`)&&e.endsWith(`]`))return bf(e);let n=e.split(hf);return yf(n,+(n[0]===``&&n.length>1),t)},getConflictingClassGroupIds:(e,t)=>{if(t){let t=r[e],i=n[e];return t?i?ff(i,t):t:i||gf}return n[e]||gf}}},yf=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;let r=e[t],i=n.nextPart.get(r);if(i){let n=yf(e,t+1,i);if(n)return n}let a=n.validators;if(a===null)return;let o=t===0?e.join(hf):e.slice(t).join(hf),s=a.length;for(let e=0;e<s;e++){let t=a[e];if(t.validator(o))return t.classGroupId}},bf=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?_f+r:void 0})(),xf=e=>{let{theme:t,classGroups:n}=e;return Sf(n,t)},Sf=(e,t)=>{let n=mf();for(let r in e){let i=e[r];Cf(i,n,r,t)}return n},Cf=(e,t,n,r)=>{let i=e.length;for(let a=0;a<i;a++){let i=e[a];wf(i,t,n,r)}},wf=(e,t,n,r)=>{if(typeof e==`string`){Tf(e,t,n);return}if(typeof e==`function`){Ef(e,t,n,r);return}Df(e,t,n,r)},Tf=(e,t,n)=>{let r=e===``?t:Of(t,e);r.classGroupId=n},Ef=(e,t,n,r)=>{if(kf(e)){Cf(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(pf(n,e))},Df=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e<a;e++){let[a,o]=i[e];Cf(o,Of(t,a),n,r)}},Of=(e,t)=>{let n=e,r=t.split(hf),i=r.length;for(let e=0;e<i;e++){let t=r[e],i=n.nextPart.get(t);i||(i=mf(),n.nextPart.set(t,i)),n=i}return n},kf=e=>`isThemeGetter`in e&&e.isThemeGetter===!0,Af=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)}}},jf=`!`,Mf=`:`,Nf=[],Pf=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),Ff=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===Mf){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(jf)?(c=s.slice(0,-1),l=!0):s.startsWith(jf)&&(c=s.slice(1),l=!0);let u=a&&a>i?a-i:void 0;return Pf(t,l,c,u)};if(t){let e=t+Mf,n=r;r=t=>t.startsWith(e)?n(t.slice(e.length)):Pf(Nf,!1,t,void 0,!0)}if(n){let e=r;r=t=>n({className:t,parseClassName:e})}return r},If=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}},Lf=e=>({cache:Af(e.cacheSize),parseClassName:Ff(e),sortModifiers:If(e),postfixLookupClassGroupIds:Rf(e),...vf(e)}),Rf=e=>{let t=Object.create(null),n=e.postfixLookupClassGroups;if(n)for(let e=0;e<n.length;e++)t[n[e]]=!0;return t},zf=/\s+/,Bf=(e,t)=>{let{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:a,postfixLookupClassGroupIds:o}=t,s=[],c=e.trim().split(zf),l=``;for(let e=c.length-1;e>=0;--e){let t=c[e],{isExternal:u,modifiers:d,hasImportantModifier:f,baseClassName:p,maybePostfixModifierPosition:m}=n(t);if(u){l=t+(l.length>0?` `+l:l);continue}let h=!!m,g;if(h){g=r(p.substring(0,m));let e=g&&o[g]?r(p):void 0;e&&e!==g&&(g=e,h=!1)}else g=r(p);if(!g){if(!h){l=t+(l.length>0?` `+l:l);continue}if(g=r(p),!g){l=t+(l.length>0?` `+l:l);continue}h=!1}let _=d.length===0?``:d.length===1?d[0]:a(d).join(`:`),v=f?_+jf:_,y=v+g;if(s.indexOf(y)>-1)continue;s.push(y);let b=i(g,h);for(let e=0;e<b.length;++e){let t=b[e];s.push(v+t)}l=t+(l.length>0?` `+l:l)}return l},Vf=(...e)=>{let t=0,n,r,i=``;for(;t<e.length;)(n=e[t++])&&(r=Hf(n))&&(i&&(i+=` `),i+=r);return i},Hf=e=>{if(typeof e==`string`)return e;let t,n=``;for(let r=0;r<e.length;r++)e[r]&&(t=Hf(e[r]))&&(n&&(n+=` `),n+=t);return n},Uf=(e,...t)=>{let n,r,i,a,o=o=>(n=Lf(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=Bf(e,n);return i(e,a),a};return a=o,(...e)=>a(Vf(...e))},Wf=[],Gf=e=>{let t=t=>t[e]||Wf;return t.isThemeGetter=!0,t},Kf=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,qf=/^\((?:(\w[\w-]*):)?(.+)\)$/i,Jf=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,Yf=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Xf=/\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$/,Zf=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Qf=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,$f=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,ep=e=>Jf.test(e),tp=e=>!!e&&!Number.isNaN(Number(e)),np=e=>!!e&&Number.isInteger(Number(e)),rp=e=>e.endsWith(`%`)&&tp(e.slice(0,-1)),ip=e=>Yf.test(e),ap=()=>!0,op=e=>Xf.test(e)&&!Zf.test(e),sp=()=>!1,cp=e=>Qf.test(e),lp=e=>$f.test(e),up=e=>!J(e)&&!Y(e),dp=e=>e.startsWith(`@container`)&&(e[10]===`/`&&e[11]!==void 0||e[11]===`s`&&e[16]!==void 0&&e.startsWith(`-size/`,10)||e[11]===`n`&&e[18]!==void 0&&e.startsWith(`-normal/`,10)),fp=e=>Dp(e,jp,sp),J=e=>Kf.test(e),pp=e=>Dp(e,Mp,op),mp=e=>Dp(e,Np,tp),hp=e=>Dp(e,Fp,ap),gp=e=>Dp(e,Pp,sp),_p=e=>Dp(e,kp,sp),vp=e=>Dp(e,Ap,lp),yp=e=>Dp(e,Ip,cp),Y=e=>qf.test(e),bp=e=>Op(e,Mp),xp=e=>Op(e,Pp),Sp=e=>Op(e,kp),Cp=e=>Op(e,jp),wp=e=>Op(e,Ap),Tp=e=>Op(e,Ip,!0),Ep=e=>Op(e,Fp,!0),Dp=(e,t,n)=>{let r=Kf.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},Op=(e,t,n=!1)=>{let r=qf.exec(e);return r?r[1]?t(r[1]):n:!1},kp=e=>e===`position`||e===`percentage`,Ap=e=>e===`image`||e===`url`,jp=e=>e===`length`||e===`size`||e===`bg-size`,Mp=e=>e===`length`,Np=e=>e===`number`,Pp=e=>e===`family-name`,Fp=e=>e===`number`||e===`weight`,Ip=e=>e===`shadow`,Lp=Uf(()=>{let e=Gf(`color`),t=Gf(`font`),n=Gf(`text`),r=Gf(`font-weight`),i=Gf(`tracking`),a=Gf(`leading`),o=Gf(`breakpoint`),s=Gf(`container`),c=Gf(`spacing`),l=Gf(`radius`),u=Gf(`shadow`),d=Gf(`inset-shadow`),f=Gf(`text-shadow`),p=Gf(`drop-shadow`),m=Gf(`blur`),h=Gf(`perspective`),g=Gf(`aspect`),_=Gf(`ease`),v=Gf(`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=()=>[ep,`full`,`auto`,...w()],E=()=>[np,`none`,`subgrid`,Y,J],D=()=>[`auto`,{span:[`full`,np,Y,J]},np,Y,J],O=()=>[np,`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=()=>[ep,`auto`,`full`,`dvw`,`dvh`,`lvw`,`lvh`,`svw`,`svh`,`min`,`max`,`fit`,...w()],P=()=>[ep,`screen`,`full`,`dvw`,`lvw`,`svw`,`min`,`max`,`fit`,...w()],F=()=>[ep,`screen`,`full`,`lh`,`dvh`,`lvh`,`svh`,`min`,`max`,`fit`,...w()],I=()=>[e,Y,J],L=()=>[...b(),Sp,_p,{position:[Y,J]}],R=()=>[`no-repeat`,{repeat:[``,`x`,`y`,`space`,`round`]}],z=()=>[`auto`,`cover`,`contain`,Cp,fp,{size:[Y,J]}],B=()=>[rp,bp,pp],V=()=>[``,`none`,`full`,l,Y,J],H=()=>[``,tp,bp,pp],U=()=>[`solid`,`dashed`,`dotted`,`double`],ee=()=>[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],W=()=>[tp,rp,Sp,_p],te=()=>[``,`none`,m,Y,J],ne=()=>[`none`,tp,Y,J],G=()=>[`none`,tp,Y,J],re=()=>[tp,Y,J],ie=()=>[ep,`full`,...w()];return{cacheSize:500,theme:{animate:[`spin`,`ping`,`pulse`,`bounce`],aspect:[`video`],blur:[ip],breakpoint:[ip],color:[ap],container:[ip],"drop-shadow":[ip],ease:[`in`,`out`,`in-out`],font:[up],"font-weight":[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`],"inset-shadow":[ip],leading:[`none`,`tight`,`snug`,`normal`,`relaxed`,`loose`],perspective:[`dramatic`,`near`,`normal`,`midrange`,`distant`,`none`],radius:[ip],shadow:[ip],spacing:[`px`,tp],text:[ip],"text-shadow":[ip],tracking:[`tighter`,`tight`,`normal`,`wide`,`wider`,`widest`]},classGroups:{aspect:[{aspect:[`auto`,`square`,ep,J,Y,g]}],container:[`container`],"container-type":[{"@container":[``,`normal`,`size`,Y,J]}],"container-named":[dp],columns:[{columns:[tp,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:[np,`auto`,Y,J]}],basis:[{basis:[ep,`full`,`auto`,s,...w()]}],"flex-direction":[{flex:[`row`,`row-reverse`,`col`,`col-reverse`]}],"flex-wrap":[{flex:[`nowrap`,`wrap`,`wrap-reverse`]}],flex:[{flex:[tp,ep,`auto`,`initial`,`none`,J]}],grow:[{grow:[``,tp,Y,J]}],shrink:[{shrink:[``,tp,Y,J]}],order:[{order:[np,`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,bp,pp]}],"font-smoothing":[`antialiased`,`subpixel-antialiased`],"font-style":[`italic`,`not-italic`],"font-weight":[{font:[r,Ep,hp]}],"font-stretch":[{"font-stretch":[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`,rp,J]}],"font-family":[{font:[xp,gp,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":[tp,`none`,Y,mp]}],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:[tp,`from-font`,`auto`,Y,pp]}],"text-decoration-color":[{decoration:I()}],"underline-offset":[{"underline-offset":[tp,`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()}],"tab-size":[{tab:[np,Y,J]}],"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`]},np,Y,J],radial:[``,Y,J],conic:[np,Y,J]},wp,vp]}],"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":[tp,Y,J]}],"outline-w":[{outline:[``,tp,bp,pp]}],"outline-color":[{outline:I()}],shadow:[{shadow:[``,`none`,u,Tp,yp]}],"shadow-color":[{shadow:I()}],"inset-shadow":[{"inset-shadow":[`none`,d,Tp,yp]}],"inset-shadow-color":[{"inset-shadow":I()}],"ring-w":[{ring:H()}],"ring-w-inset":[`ring-inset`],"ring-color":[{ring:I()}],"ring-offset-w":[{"ring-offset":[tp,pp]}],"ring-offset-color":[{"ring-offset":I()}],"inset-ring-w":[{"inset-ring":H()}],"inset-ring-color":[{"inset-ring":I()}],"text-shadow":[{"text-shadow":[`none`,f,Tp,yp]}],"text-shadow-color":[{"text-shadow":I()}],opacity:[{opacity:[tp,Y,J]}],"mix-blend":[{"mix-blend":[...ee(),`plus-darker`,`plus-lighter`]}],"bg-blend":[{"bg-blend":ee()}],"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":[tp]}],"mask-image-linear-from-pos":[{"mask-linear-from":W()}],"mask-image-linear-to-pos":[{"mask-linear-to":W()}],"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":W()}],"mask-image-t-to-pos":[{"mask-t-to":W()}],"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":W()}],"mask-image-r-to-pos":[{"mask-r-to":W()}],"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":W()}],"mask-image-b-to-pos":[{"mask-b-to":W()}],"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":W()}],"mask-image-l-to-pos":[{"mask-l-to":W()}],"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":W()}],"mask-image-x-to-pos":[{"mask-x-to":W()}],"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":W()}],"mask-image-y-to-pos":[{"mask-y-to":W()}],"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":W()}],"mask-image-radial-to-pos":[{"mask-radial-to":W()}],"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":[tp]}],"mask-image-conic-from-pos":[{"mask-conic-from":W()}],"mask-image-conic-to-pos":[{"mask-conic-to":W()}],"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:te()}],brightness:[{brightness:[tp,Y,J]}],contrast:[{contrast:[tp,Y,J]}],"drop-shadow":[{"drop-shadow":[``,`none`,p,Tp,yp]}],"drop-shadow-color":[{"drop-shadow":I()}],grayscale:[{grayscale:[``,tp,Y,J]}],"hue-rotate":[{"hue-rotate":[tp,Y,J]}],invert:[{invert:[``,tp,Y,J]}],saturate:[{saturate:[tp,Y,J]}],sepia:[{sepia:[``,tp,Y,J]}],"backdrop-filter":[{"backdrop-filter":[``,`none`,Y,J]}],"backdrop-blur":[{"backdrop-blur":te()}],"backdrop-brightness":[{"backdrop-brightness":[tp,Y,J]}],"backdrop-contrast":[{"backdrop-contrast":[tp,Y,J]}],"backdrop-grayscale":[{"backdrop-grayscale":[``,tp,Y,J]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[tp,Y,J]}],"backdrop-invert":[{"backdrop-invert":[``,tp,Y,J]}],"backdrop-opacity":[{"backdrop-opacity":[tp,Y,J]}],"backdrop-saturate":[{"backdrop-saturate":[tp,Y,J]}],"backdrop-sepia":[{"backdrop-sepia":[``,tp,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:[tp,`initial`,Y,J]}],ease:[{ease:[`linear`,`initial`,_,Y,J]}],delay:[{delay:[tp,Y,J]}],animate:[{animate:[`none`,v,Y,J]}],backface:[{backface:[`hidden`,`visible`]}],perspective:[{perspective:[h,Y,J]}],"perspective-origin":[{"perspective-origin":x()}],rotate:[{rotate:ne()}],"rotate-x":[{"rotate-x":ne()}],"rotate-y":[{"rotate-y":ne()}],"rotate-z":[{"rotate-z":ne()}],scale:[{scale:G()}],"scale-x":[{"scale-x":G()}],"scale-y":[{"scale-y":G()}],"scale-z":[{"scale-z":G()}],"scale-3d":[`scale-3d`],skew:[{skew:re()}],"skew-x":[{"skew-x":re()}],"skew-y":[{"skew-y":re()}],transform:[{transform:[Y,J,``,`none`,`gpu`,`cpu`]}],"transform-origin":[{origin:x()}],"transform-style":[{transform:[`3d`,`flat`]}],translate:[{translate:ie()}],"translate-x":[{"translate-x":ie()}],"translate-y":[{"translate-y":ie()}],"translate-z":[{"translate-z":ie()}],"translate-none":[`translate-none`],zoom:[{zoom:[np,Y,J]}],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`]}],"scrollbar-thumb-color":[{"scrollbar-thumb":I()}],"scrollbar-track-color":[{"scrollbar-track":I()}],"scrollbar-gutter":[{"scrollbar-gutter":[`auto`,`stable`,`both`]}],"scrollbar-w":[{scrollbar:[`auto`,`thin`,`none`]}],"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:[tp,bp,pp,mp]}],stroke:[{stroke:[`none`,...I()]}],"forced-color-adjust":[{"forced-color-adjust":[`auto`,`none`]}]},conflictingClassGroups:{"container-named":[`container-type`],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`]},postfixLookupClassGroups:[`container-type`],orderSensitiveModifiers:[`*`,`**`,`after`,`backdrop`,`before`,`details-content`,`file`,`first-letter`,`first-line`,`marker`,`placeholder`,`selection`]}});function X(...e){return Lp(df(e))}function Rp({delayDuration:e=0,...t}){return(0,K.jsx)(rf,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function zp({...e}){return(0,K.jsx)(af,{"data-slot":`tooltip`,...e})}function Bp({...e}){return(0,K.jsx)(of,{"data-slot":`tooltip-trigger`,...e})}function Vp({className:e,sideOffset:t=4,children:n,...r}){return(0,K.jsx)(sf,{children:(0,K.jsxs)(cf,{"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,K.jsx)(lf,{className:`fill-gray-900`})]})})}var Z=(e,t)=>fetch(e,{credentials:`include`,...t}),Hp=null;function Up(){return Hp||=Z(`/api/health`).then(e=>e.json()).then(e=>typeof e?.workspace==`string`?e.workspace:`loopat`).catch(()=>`loopat`),Hp}async function Wp(){let e=await Z(`/api/auth/me`);return e.ok?(await e.json()).user??null:null}async function Gp(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 Kp(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 Jp(){let e=await Z(`/api/personal/status`);return e.ok?await e.json():null}async function Yp(){let e=await Z(`/api/onboarding`);return e.ok?await e.json():null}async function Xp(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 Zp(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 Qp(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 $p(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 em(){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 tm(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 nm(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 rm(){await Z(`/api/auth/logout`,{method:`POST`}).catch(()=>{})}async function im(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 am(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 om(){let e=await Z(`/api/profiles`);return e.ok?(await e.json()).profiles??[]:[]}async function sm(){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 cm(e){let t=await Z(`/api/loop-stats?profiles=${encodeURIComponent(e.join(`,`))}`);return t.ok?await t.json():null}async function lm(){let e=await Z(`/api/vaults`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.vaults)?t.vaults:[]}async function um(e){return(await Z(`/api/loops/${e}/viewed`,{method:`POST`})).ok}async function dm(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 fm(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 pm(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 mm(e){let t=await Z(`/api/loops/${e}/request-drive`,{method:`POST`});return t.ok?await t.json():null}async function hm(e){let t=await Z(`/api/loops/${e}/drive`,{method:`POST`});return t.ok?await t.json():null}async function gm(e){let t=await Z(`/api/loops/${e}/distill`,{method:`POST`});return t.ok?await t.json():null}async function _m(e){let t=await Z(`/api/loops/${e}`);return t.ok?await t.json():null}async function vm(e){let t=await Z(`/api/loops/${e}/strip-thinking`,{method:`POST`});return t.ok?await t.json():{stripped:0,sessionsTouched:0}}async function ym(e,t=``){return(await(await Z(`/api/loops/${e}/files?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function bm(e,t=``){return(await(await Z(`/api/loops/${e}/files/tree?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function xm(e,t){let n=await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Sm(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 Cm(e,t){return(await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function wm(e,t){return(await Z(`/api/loops/${e}/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).ok}async function Tm(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 Em(e){let t=await Z(`/api/loops/${e}/context`);return t.ok?(await t.json()).mounts??[]:[]}async function Dm(e,t=``){let n=await Z(`/api/workspace/files?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).entries??[]:[]}async function Om(e){let t=await Z(`/api/workspace/files?vault=${e}&flat=1`);return t.ok?(await t.json()).entries??[]:[]}async function km(e,t){let n=await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Am(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 jm(){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 Mm(){let e=await(await Z(`/api/notes/behind`)).json().catch(()=>({}));return typeof e.behind==`number`?e.behind:0}async function Nm(){let e=await(await Z(`/api/notes/refresh`,{method:`POST`})).json().catch(()=>({}));return{ok:!!e.ok,diverged:e.diverged,error:e.error}}async function Pm(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 Fm(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 Im(e,t){return await(await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`DELETE`})).json()}async function Lm(e,t){let n=await Z(`/api/workspace/backlinks?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).backlinks??[]:[]}async function Rm(){let e=await Z(`/api/context/repos`);if(!e.ok)return{notes:null,repos:[]};let t=await e.json();return{notes:t.notes??null,repos:t.repos??[]}}async function zm(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}`,savedLocally:n.savedLocally}}async function Bm(e){let t=await Z(`/api/loops/${e}/chat-history`);return t.ok?(await t.json()).map(e=>e.text):[]}async function Vm(e,t){await Z(`/api/loops/${e}/chat-history`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t})})}function Hm(e){return typeof e==`string`?`/api/sync/${e}`:`/api/sync/repos/${encodeURIComponent(e.repo)}`}async function Um(e){let t=await Z(`${Hm(e)}/status`);return t.ok?await t.json():null}async function Wm(e){let t=await Z(`${Hm(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 Gm(e){let t=await Z(`${Hm(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 Km(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 Jm(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/toggle`,{method:`PATCH`})).ok}async function Ym(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 Xm(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 Zm(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`DELETE`})).ok}async function Qm(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 $m(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 eh(){let e=await Z(`/api/kanban/boards`);return e.ok?(await e.json()).boards:[`default`]}async function th(e){return(await Z(`/api/kanban/boards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).ok}async function nh(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 rh(e=`default`){let t=await Z(`/api/kanban/config/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function ih(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 ah(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 oh(e,t){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function sh(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 ch(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 lh(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 uh(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 dh(){let e=await Z(`/api/topics`);return e.ok?(await e.json()).topics:[]}async function fh(){let e=await Z(`/api/providers`);return e.ok?await e.json():{providers:{},default:``}}async function ph(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 mh(){let e=await Z(`/api/version`);return e.ok?await e.json():{branch:`unknown`,commit:`unknown`}}async function hh(){let e=await Z(`/api/admin/system`);return e.ok?await e.json():null}async function gh(){return await(await Z(`/api/admin/system/check`,{method:`POST`})).json()}async function _h(){return await(await Z(`/api/admin/system/pull`,{method:`POST`})).json()}function vh(){return{commit:`df3c7badf2f06d3a3d25382f2872b8f3969972a2`,time:`2026-06-02T10:07:32.352Z`}}async function yh(e){let t=await Z(`/api/loops/${e}/git-status`);return t.ok?await t.json():{unstaged:[],staged:[]}}async function bh(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 xh(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 Sh(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 Ch(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 wh(e,t=50){let n=await Z(`/api/loops/${e}/git-log?limit=${t}`);return n.ok?(await n.json()).commits??[]:[]}async function Th(){let e=await Z(`/api/settings/personal/disk`);return e.ok?await e.json():null}async function Eh(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 Dh(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 Oh(){return await(await Z(`/api/settings/workspace`)).json()}async function kh(e){return(await Z(`/api/settings/workspace`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Ah(){let e=await Z(`/api/settings/token-usage/daily`);return e.ok?await e.json():{}}async function jh(){let e=await Z(`/api/settings/token-usage/loops`);return e.ok?await e.json():[]}async function Mh(){let e=await Z(`/api/admin/presets`);return e.ok?await e.json():{providerPresets:[],miseToolPresets:[]}}async function Nh(e){return(await Z(`/api/admin/presets`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Ph(){let e=await Z(`/api/admin/users`);return e.ok?(await e.json()).users??[]:[]}async function Fh(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 Ih(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 Lh(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 Rh(){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 zh(e){let t=await Z(`/api/loops/${e}/share/current-port`);return t.ok?await t.json():{port:null}}async function Bh(e){return(await Z(`/api/serve/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Vh(){let e=await Z(`/api/serve/available-port`);return e.ok?await e.json():{port:null,error:`request failed`}}async function Hh(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 Uh(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 Wh(){let e=await Z(`/api/chat/conversations`);return e.ok?(await e.json()).conversations??[]:[]}async function Gh(){let e=await Z(`/api/chat/users`);return e.ok?(await e.json()).users??[]:[]}async function Kh(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 Jh(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 Yh(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 Xh(e){let t=await Z(`/api/chat/threads/${e}`);return t.ok?await t.json():null}async function Zh(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 Qh(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 $h(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 eg(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 tg(){let e=await Z(`/api/a2a`);return e.ok?await e.json():null}async function ng(e){return(await Z(`/api/a2a`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function rg(){let e=await Z(`/api/a2a/key`,{method:`POST`});return e.ok?(await e.json().catch(()=>({}))).token??null:null}async function ig(e){let t=await Z(`/api/mcp-servers${e?`?loopId=${encodeURIComponent(e)}`:``}`);return t.ok?await t.json():{servers:[]}}async function ag(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 og(e){return(await Z(`/api/envs/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}async function sg(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 cg(){let e=await Z(`/api/tiers`);return e.ok?await e.json():null}async function lg(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 ug(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 dg(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 fg(){let e=await Z(`/api/plugins/available`);return e.ok?(await e.json()).plugins??[]:[]}async function pg(){let e=await Z(`/api/plugins/browse`);return e.ok?(await e.json()).plugins??[]:[]}async function mg(){let e=await Z(`/api/marketplaces`);return e.ok?(await e.json()).marketplaces??[]:[]}async function hg(){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 gg(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 _g(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 vg(){let e=await Z(`/api/v1/me/tokens`);return e.ok?(await e.json().catch(()=>({tokens:[]}))).tokens??[]:[]}async function yg(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 bg(e){return(await Z(`/api/v1/me/tokens/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}function xg(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!0),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!0),g=(0,_.useCallback)(async()=>{r(!0),t(await im(i?`all`:`active`)),r(!1)},[i]);(0,_.useEffect)(()=>{let e=!1;return Wp().then(t=>{e||(p(t),h(!1))}),()=>{e=!0}},[]),(0,_.useEffect)(()=>{g()},[i,f]);let v=(0,_.useCallback)(async e=>{let n=await am(e);return t(e=>[n,...e]),n},[]),y=(0,_.useCallback)(async(e,n)=>{let r=await dm(e,n);r&&t(t=>!i&&r.archived?t.filter(t=>t.id!==e):t.map(t=>t.id===e?r:t))},[i]),b=(0,_.useCallback)(async(e,n)=>{let r=await fm(e,n);r&&t(t=>t.map(t=>t.id===e?r:t))},[]),x=(0,_.useCallback)(async(e,n)=>{let r=await pm(e,n);return r?(t(t=>t.map(t=>t.id===e?r:t)),r):null},[]),S=(0,_.useCallback)(async e=>{let n=await mm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),C=(0,_.useCallback)(async e=>{let n=await hm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),w=(0,_.useCallback)(async(e,t)=>{let n=await Gp(e,t);return n.user&&p(n.user),{error:n.error}},[]),T=(0,_.useCallback)(async e=>{let t=await Kp(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,_.useCallback)(async()=>{await rm(),p(null)},[]);return{loops:e,loopsLoading:n,showArchived:i,setShowArchived:a,refresh:g,createLoop:v,setLoopArchived:y,setLoopPublic:b,setLoopTitle:x,requestDrive:S,takeDrive:C,newLoopDialogOpen:o,newLoopDialogTitle:c,kanbanCreateCtx:u,setNewLoopDialogOpen:(0,_.useCallback)((e,t,n)=>{s(e),l(t??``),d(n??null)},[]),currentUser:f,authLoading:m,login:w,register:T,logout:E}}var Sg=(0,_.createContext)(null);function Cg(){let e=(0,_.useContext)(Sg);if(!e)throw Error(`useWorkspace outside provider`);return e}function wg({onClose:e,onCreate:t,initialTitle:n}){let[r,i]=(0,_.useState)(n??``),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(new Set),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(`default`),[p,m]=(0,_.useState)([]),[h,g]=(0,_.useState)([]),[v,y]=(0,_.useState)([]),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(!1),[w,T]=(0,_.useState)(!1),E=(0,_.useRef)(null);(0,_.useEffect)(()=>{Rm().then(e=>m(e.repos)),Promise.all([om(),sm()]).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`)))}),lm().then(e=>{y(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,_.useEffect)(()=>{C(!0);let e=setTimeout(()=>{cm([...s]).then(x).finally(()=>C(!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,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:e,children:(0,K.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,K.jsx)(`div`,{className:`text-base font-semibold text-gray-900 mb-4`,children:`New loop`}),(0,K.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),!w){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,K.jsxs)(Tg,{label:`Repo`,hint:`Sets the workdir. Optional — leave (none) for an empty workdir.`,children:[(0,K.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,K.jsx)(`option`,{value:``,children:`(none — empty workdir)`}),p.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.name,e.git?` · ${e.git}`:``]},e.name))]}),p.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`No repos in the roster. Add them on the Context → Repos page.`})]}),(0,K.jsxs)(Tg,{label:`Profiles`,hint:`Each profile contributes plugins + a CLAUDE.md fragment. Empty = base + personal only.`,children:[(0,K.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,K.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,K.jsx)(`input`,{type:`checkbox`,checked:!0,disabled:!0,className:`mt-0.5`}),(0,K.jsxs)(`span`,{className:`flex-1`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:`base`}),(0,K.jsx)(`span`,{className:`ml-1 text-[11px] text-gray-400`,children:`(always on)`}),k.description&&(0,K.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,K.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,K.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>j(e.name),className:`mt-0.5`}),(0,K.jsxs)(`span`,{className:`flex-1`,children:[(0,K.jsx)(`span`,{className:`font-medium text-gray-900`,children:e.name}),n&&(0,K.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,K.jsx)(`span`,{className:`block text-[11px] text-gray-500 mt-0.5`,children:e.description})]})]},e.name)}),A.length===0&&!k&&(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-400 p-1.5`,children:[`No profiles yet. Add them under`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`knowledge/.loopat/profiles/<name>/.claude/`}),` `,`in your knowledge repo.`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between mt-1`,children:[(0,K.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,K.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,K.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:S&&!b?(0,K.jsx)(`span`,{className:`text-gray-400`,children:`computing…`}):b?(0,K.jsxs)(`span`,{title:`Totals across team + selected profiles + their plugins (deduped by name)`,children:[(0,K.jsxs)(`span`,{className:b.plugins>0?``:`text-gray-400`,children:[b.plugins,` plugins`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.skills>0?``:`text-gray-400`,children:[b.skills,` skills`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.agents>0?``:`text-gray-400`,children:[b.agents,` agents`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.hooks>0?``:`text-gray-400`,children:[b.hooks,` hooks`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.mcpServers>0?``:`text-gray-400`,children:[b.mcpServers,` MCP servers`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.toolchain>0?``:`text-gray-400`,title:`mise.toml [tools] entries, deduped across team + selected profiles`,children:[b.toolchain,` toolchain`]}),S&&(0,K.jsx)(`span`,{className:`ml-1.5 text-gray-400`,children:`·`}),S&&(0,K.jsx)(`span`,{className:`ml-1 text-gray-400`,children:`updating…`})]}):(0,K.jsx)(`span`,{className:`text-gray-400`,children:`—`})})]}),(0,K.jsxs)(Tg,{label:`Vault`,hint:`Which credential set to inject. Only this vault is visible inside the loop.`,children:[(0,K.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:[v.length===0&&(0,K.jsx)(`option`,{value:`default`,children:`default`}),v.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),v.length===0&&(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:[`No vaults yet — using default. Create more under`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`personal/.loopat/vaults/<name>/`}),` `,`to isolate prod / test credentials.`]})]}),(0,K.jsx)(Tg,{label:`Name`,hint:`Optional — defaults to 'untitled'.`,children:(0,K.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,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2 pt-3 border-t border-gray-100`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:e,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,K.jsx)(`button`,{type:`submit`,disabled:w,className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:w?`creating…`:`create`})]})]})]})})}function Tg({label:e,hint:t,children:n}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var Eg=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,Dg=df,Og=((e,t)=>n=>{if(t?.variants==null)return Dg(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=Eg(t)||Eg(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 Dg(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 kg({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,K.jsx)(r?Mi:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:X(Og({variant:t,size:n,className:e})),...i})}function Ag({...e}){return(0,K.jsx)(tc,{"data-slot":`dialog`,...e})}function jg({...e}){return(0,K.jsx)(nc,{"data-slot":`dialog-portal`,...e})}function Mg({className:e,...t}){return(0,K.jsx)(rc,{"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 Ng({className:e,children:t,showCloseButton:n=!0,...r}){return(0,K.jsxs)(jg,{"data-slot":`dialog-portal`,children:[(0,K.jsx)(Mg,{}),(0,K.jsxs)(ic,{"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,K.jsxs)(sc,{"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,K.jsx)(lt,{}),(0,K.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function Pg({className:e,...t}){return(0,K.jsx)(`div`,{"data-slot":`dialog-header`,className:X(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function Fg({className:e,...t}){return(0,K.jsx)(ac,{"data-slot":`dialog-title`,className:X(`text-lg leading-none font-semibold`,e),...t})}function Ig({className:e,...t}){return(0,K.jsx)(oc,{"data-slot":`dialog-description`,className:X(`text-sm text-muted-foreground`,e),...t})}function Lg({open:e,onClose:t}){let[n,r]=(0,_.useState)({branch:`…`,commit:`…`}),i=vh();return(0,_.useEffect)(()=>{e&&mh().then(e=>r(e))},[e]),(0,K.jsx)(Ag,{open:e,onOpenChange:e=>!e&&t(),children:(0,K.jsxs)(Ng,{className:`sm:max-w-sm bg-white`,children:[(0,K.jsx)(Pg,{children:(0,K.jsxs)(Fg,{className:`text-center`,children:[(0,K.jsx)(`img`,{src:`/logo.png`,alt:`loopat`,className:`w-full max-w-[240px] mx-auto mb-2`}),`loopat`]})}),(0,K.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,K.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,K.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Server`}),(0,K.jsxs)(`div`,{className:`font-mono text-gray-700`,children:[n.branch,`@`,n.commit.slice(0,7)]})]}),(0,K.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,K.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Build`}),(0,K.jsx)(`div`,{className:`font-mono text-gray-700`,children:i.commit.slice(0,7)}),(0,K.jsx)(`div`,{className:`font-mono text-gray-400 text-xs mt-0.5`,children:new Date(i.time).toLocaleString()})]})]})]})})}function Rg(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 Bg(e){let t=e=>({type:t,props:e});return t[zg]=e,t}function Vg(e,t){return{...t,key:e}}var Hg=typeof process<`u`&&!1,Ug=null;function Wg(e,t){e.currentIndex=0;let n=Ug;Ug=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{Ug=n}}function Gg(){if(!Ug)throw Error(`No resource fiber available`);return Ug}function Kg(e){return Hg?Ug?.devStrictMode?Ug.isFirstRender?`child`:`root`:e?`root`:null:null}var qg=e=>({version:0,committedVersion:0,dispatchUpdate:e,changelog:[],dirtyCells:[]}),Jg=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},Yg=(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()),Jg(e)}}},Xg=(e,t)=>{t.dirty||(t.dirty=!0,e.markDirty?.(),e.root.dirtyCells.push(t))},Zg=(e,t)=>{let n=Gg(),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},Qg=e=>{Gg().renderContext.effectTasks.push(e)},$g=(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 e_(e,t,n,r){let i=Zg(`reducer`,()=>{let t=Gg(),a=r?r(n):n;return Hg&&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};$g(t,()=>t.root.dirtyCells.length===0&&!r.hasEagerState&&(r.eagerState=e(i.workInProgress,n),r.hasEagerState=!0,Object.is(i.current,r.eagerState))?null:()=>{Xg(t,i),i.queue.add(r)})}}}),a=Gg(),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),Hg&&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)||(Xg(a,i),i.workInProgress=e)}return[i.workInProgress,i.dispatch]}function t_(e,t,n){return e_(e,void 0,t,n)}function n_(e,t,n,r){return e_(e,t,n,r)}var r_=(e,t)=>typeof t==`function`?t(e):t,i_=e=>typeof e==`function`?e():e;function a_(e){return t_(r_,e,i_)}var o_=(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},s_=()=>({type:`effect`,cleanup:void 0,deps:null});function c_(e,t){let n=Zg(`effect`,s_);if(!(t&&n.deps&&o_(n.deps,t))){if(n.deps!==null&&!!t!=!!n.deps)throw Error(`tapEffect called with and without dependencies across re-renders`);Qg(()=>{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 l_(e){let[t]=a_(()=>({current:e}));return t}function u_(e,t){let[n]=a_(e);return n}var d_=()=>{throw Error(`Memo reducer should not be called`)},f_=(e,t)=>{let n=Gg(),[r]=n_(d_,r=>{if(r&&o_(r.deps,t))return r;let i=e();return Hg&&n.devStrictMode&&e(),{value:i,deps:t}},null);return r.value},p_=(e,t)=>f_(()=>e,t);function m_(e){let t=l_(e);c_(()=>{t.current=e});let n=Gg();return p_(((...e)=>{if(Hg&&n.renderContext)throw Error(`tapEffectEvent cannot be called during render`);return t.current(...e)}),[n])}function h_(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 g_(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`)}}function __(e,t,n=void 0,r=Kg(!1)){return{type:e,root:t,markDirty:n,devStrictMode:r,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function v_(e){if(!e.isMounted)throw Error(`Tried to unmount a fiber that is already unmounted`);e.isMounted=!1,g_(e)}function y_(e,t){let n={effectTasks:[],props:t,output:void 0};return Wg(e,()=>{e.renderContext=n;try{n.output=Rg(e.type,t)}finally{e.renderContext=void 0}}),n}function b_(e,t){e.isMounted=!0,Hg&&e.isNeverMounted&&e.devStrictMode===`root`&&(e.isNeverMounted=!1,h_(t),g_(e)),e.isNeverMounted=!1,h_(t)}function x_(e,t){let n=Gg(),r=l_(0),i=f_(()=>(e.key,__(e.type,n.root,()=>{r.current++,n.markDirty?.()})),[e.type,e.key,n]),a=t?f_(()=>y_(i,e.props),[i,...t,r.current]):y_(i,e.props);return c_(()=>()=>v_(i),[i]),c_(()=>{b_(i,a)},[i,a]),a.output}function S_(e,t){let n=l_(0),r=n.current,i=u_(Gg,[]),a=u_(()=>()=>{n.current++,i.markDirty?.()},[]),o=u_(()=>new Map,[]),s=t?p_(e,t):e,c=f_(()=>{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=__(c.type,i.root,a),t=y_(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=__(c.type,i.root,a),t=y_(e,c.props);u.next=[e,t],n.push(t.output)}else u.next=y_(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 c_(()=>()=>{for(let e of o.keys()){let t=o.get(e).fiber;v_(t)}},[]),c_(()=>{for(let[e,t]of o.entries())t.next===`delete`?(t.fiber.isMounted&&v_(t.fiber),o.delete(e)):Array.isArray(t.next)?(v_(t.fiber),t.fiber=t.next[0],b_(t.fiber,t.next[1])):b_(t.fiber,t.next)},[c]),c}var C_=50,w_={schedulers:new Set([]),isScheduled:!1},T_=class{_task;_isDirty=!1;constructor(e){this._task=e}get isDirty(){return this._isDirty}markDirty(){this._isDirty=!0,w_.schedulers.add(this),E_()}runTask(){this._isDirty=!1,this._task()}},E_=()=>{w_.isScheduled||(w_.isScheduled=!0,O_())},D_=()=>{try{let e=[],t=0;for(let n of w_.schedulers)if(w_.schedulers.delete(n),n.isDirty){if(t++,t>C_)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{w_.schedulers.clear(),w_.isScheduled=!1}},O_=(()=>{if(typeof MessageChannel<`u`){let e=new MessageChannel;return e.port1.onmessage=D_,()=>e.port2.postMessage(null)}return()=>setTimeout(D_,0)})(),k_=e=>{let t=w_;w_={schedulers:new Set([]),isScheduled:!0};try{let t=e();return D_(),t}finally{w_=t}},A_=e=>{let t=u_(()=>new T_(()=>l(null)),[]),n=u_(()=>[],[]),r=f_(()=>(e.key,__(e.type,qg(e=>{!t.isDirty&&!e()||(n.push(e),t.markDirty())}))),[e.type,e.key]);Yg(r.root,r.root.committedVersion);let i=y_(r,e.props),a=l_(!1),o=l_(e.props),s=l_(i.output),c=u_(()=>new Set,[]),l=m_(e=>{if(e===null&&(Yg(r.root,2),Yg(r.root,1),n.forEach(e=>{Hg&&r.devStrictMode&&e(),e()}),Hg&&r.devStrictMode&&y_(r,o.current),e=y_(r,o.current)),t.isDirty)throw Error(`Scheduler is dirty, this should never happen`);Jg(r.root),n.length=0,a.current&&b_(r,e),!(t.isDirty||s.current===e.output)&&(s.current=e.output,c.forEach(e=>e()))});return c_(()=>(a.current=!0,()=>{a.current=!1,v_(r)}),[r]),c_(()=>{o.current=i.props,Jg(r.root),b_(r,i),!(t.isDirty||s.current===i.output)&&(s.current=i.output,c.forEach(e=>e()))}),f_(()=>({getValue:()=>s.current,subscribe:e=>(c.add(e),()=>c.delete(e))}),[])},j_=Symbol(`tap.Context`),M_=e=>({[j_]:e}),N_=(e,t,n)=>{let r=e[j_];e[j_]=t;try{return n()}finally{e[j_]=r}},P_=e=>e[j_],F_=Bg(()=>{let[e,t]=a_(()=>({renderers:{},fallbacks:[]}));return{getState:()=>e,setDataUI:p_((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:p_(e=>(t(t=>({...t,fallbacks:[...t.fallbacks,e]})),()=>{t(t=>({...t,fallbacks:t.fallbacks.filter(t=>t!==e)}))}),[])}}),I_=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},{}),L_=class{_providers=new Set;getModelContext(){return I_(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)}},R_=[],z_={modelName:void 0,toolNames:R_},B_=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]),V_=(e,t)=>{let n=e.getModelContext(),r=n.config?.modelName,i=n.tools?Object.keys(n.tools).sort():R_,a=i.length?i:R_;return r===t.modelName&&B_(a,t.toolNames)?t:{modelName:r,toolNames:a}},H_=Bg(()=>{let e=f_(()=>new L_,[]),[t,n]=a_(()=>V_(e,z_));return c_(()=>(n(t=>V_(e,t)),e.subscribe(()=>{n(t=>V_(e,t))})),[e]),{getState:()=>V_(e,t),getModelContext:()=>e.getModelContext(),subscribe:t=>e.subscribe(t),register:t=>e.registerModelContextProvider(t)}}),U_=e=>e.display===void 0?e.type===`human`:e.display===`standalone`,W_=Symbol(`assistant-ui.store.clientIndex`),G_=e=>e[W_],K_=M_([]),q_=()=>P_(K_),J_=(e,t)=>{let n=q_();return N_(K_,f_(()=>[...n,e],[n,e]),t)},Y_=new Set([`$$typeof`,`nodeType`,`then`]),X_=(e,t)=>{if(e===Symbol.toStringTag)return t;if(typeof e!=`symbol`){if(e===`toJSON`)return()=>t;if(!Y_.has(e))return!1}},Z_=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}},Q_=e=>{let t=Bg(e);return e=>{let n=t(e);return e.key===void 0?n:Vg(e.key,n)}},$_=Symbol(`assistant-ui.store.getValue`),ev=e=>{let t=e[$_];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?.()},tv=new Map;function nv(e){let t=tv.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[$_];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)},tv.set(e,t)),t}var rv=class extends Z_{outputRef;index;boundFns;cachedReceiver;constructor(e,t){super(),this.outputRef=e,this.index=t}get(e,t,n){if(t===$_)return this.outputRef.current;if(t===W_)return this.index;let r=X_(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=nv(t).bind(n),this.boundFns.set(t,e)),e}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,t){return t===$_||t===W_?!0:t in this.outputRef.current}},iv=Q_(e=>{let t=l_(null),n=q_().length,r=f_(()=>new Proxy({},new rv(t,n)),[n]),i=J_(r,()=>x_(e));return t.current||=i,c_(()=>{t.current=i}),{methods:r,state:i.getState?.(),key:e.key}}),av=e=>x_(iv(e)),ov=Symbol(`assistant-ui.store.proxiedAssistantState`),sv=e=>e===`on`||e===`subscribe`||typeof e==`symbol`,cv=e=>{class t extends Z_{get(t,n){let r=X_(n,`AssistantState`);if(r!==!1)return r;let i=n;if(!sv(i))return ev(e[i]())}ownKeys(){return Object.keys(e).filter(e=>!sv(e))}has(t,n){return!sv(n)&&n in e}}return new Proxy({},new t)},lv=e=>e[ov],uv=()=>()=>{},dv=e=>{let t=(()=>{throw Error(e)});return t.source=null,t.query=null,t},fv=new Proxy({},new class extends Z_{get(e,t){if(t===`subscribe`||t===`on`)return uv;if(t===ov)return pv;let n=X_(t,`DefaultAssistantClient`);return n===!1?dv(`You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.`):n}ownKeys(){return[`subscribe`,`on`,ov]}has(e,t){return t===`subscribe`||t===`on`||t===ov}}),pv=cv(fv),mv=()=>new Proxy({},{get(e,t){let n=X_(t,`AssistantClient`);return n===!1?dv(`The current scope does not have a "${String(t)}" property.`):n}}),hv=(0,_.createContext)(fv),gv=()=>(0,_.useContext)(hv),_v=({value:e,children:t})=>(0,K.jsx)(hv.Provider,{value:e,children:t}),vv=Bg(e=>null),yv=Symbol(`assistant-ui.transform-scopes`);function bv(e,t){let n=e;if(n[yv])throw Error(`transformScopes is already attached to this resource`);n[yv]=t}function xv(e){return e[yv]}var Sv=e=>typeof e==`string`?{scope:e.split(`.`)[0],event:e}:{scope:e.scope,event:e.event},Cv=M_(null),wv=(e,t)=>N_(Cv,e,t),Tv=()=>{let e=P_(Cv);if(!e)throw Error(`AssistantTapContext is not available`);return e},Ev=()=>Tv().clientRef,Dv=()=>{let{emit:e}=Tv(),t=q_();return m_((n,r)=>{e(n,r,t)})};function Ov(e,t){let n={...e},r=new Set,i=!0;for(;i;){i=!1;for(let e of Object.values(n)){if(e.type===vv||r.has(e.type))continue;r.add(e.type);let a=xv(e.type);if(a){a(n,t),i=!0;break}}}let a={},o={};for(let[e,t]of Object.entries(n))t.type===vv?o[e]=t:a[e]=t;return{rootClients:a,derivedClients:o}}var kv=e=>f_(()=>e,[...Object.entries(e).flat()]),Av=(e,t)=>{let{rootClients:n,derivedClients:r}=Ov(e,t);return{rootClients:kv(n),derivedClients:kv(r)}},jv=Bg(()=>u_(()=>{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)}}}},[])),Mv=()=>{if(!Hg)return null;let e=(0,_.useRef)(0),t=e.current===0;return(0,_.useState)(()=>e.current++),e.current===2?t?`child`:`root`:null};function Nv(e){let t=(0,_.useMemo)(()=>qg(e=>r(e)),[]),[n,r]=(0,_.useReducer)((e,n)=>(Yg(t,e),e+ +!!n()),0);Yg(t,n);let i=Mv(),a=(0,_.useMemo)(()=>(e.key,__(e.type,t,void 0,i)),[e.type,e.key,t,i]),o=y_(a,e.props);return(0,_.useLayoutEffect)(()=>()=>v_(a),[a]),(0,_.useLayoutEffect)(()=>{Jg(t),b_(a,o)}),o.output}var Pv=e=>f_(()=>e,e),Fv=Bg(({element:e,emit:t,clientRef:n})=>{let{methods:r,state:i}=wv({clientRef:n,emit:t},()=>av(e));return f_(()=>({state:i,methods:r}),[r,i])}),Iv=Bg(({element:e,notifications:t,clientRef:n,name:r})=>{let i=A_(Fv({element:e,emit:t.emit,clientRef:n}));return c_(()=>i.subscribe(t.notifySubscribers),[i,t]),f_(()=>{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])}),Lv=Bg(()=>f_(()=>({clients:[],subscribe:void 0,on:void 0}),[])),Rv=Bg(({clients:e,clientRef:t})=>{let n=x_(jv());c_(()=>t.parent.subscribe(n.notifySubscribers),[t,n]);let r=Pv(S_(()=>Object.keys(e).map(r=>Vg(r,Iv({element:e[r],notifications:n,clientRef:t,name:r}))),[e,n,t]));return f_(()=>({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}=Sv(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[G_(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])}),zv=Bg(({element:e,clientRef:t,name:n})=>{let r=l_(e.props);return r.current=e.props,f_(()=>{let e=()=>r.current.get(t.current);return Object.defineProperties(e,{source:{value:r.current.source},query:{value:r.current.query},name:{value:n,configurable:!0}}),e},[t,n])}),Bv=(e,t)=>{let n;try{let e={};for(let n of Object.keys(t.query).sort())e[n]=t.query[n];n=JSON.stringify(e)}catch{n=String(t.query)}return`${e}::${t.source}::${n}`},Vv=Bg(({clients:e,clientRef:t})=>Pv(S_(()=>Object.keys(e).map(n=>{let r=n,i=e[r];return Vg(Bv(r,i.props),zv({element:i,clientRef:t,name:r}))}),[e,t]))),Hv=Bg(({parent:e,clients:t})=>{let{rootClients:n,derivedClients:r}=Av(t,e),i=l_({parent:e,current:null}).current;c_(()=>{i.current=s});let a=x_(Object.keys(n).length>0?Rv({clients:n,clientRef:i}):Lv()),o=x_(Vv({clients:r,clientRef:i})),s=f_(()=>{let t=e===fv?mv():e,n=Object.create(t);Object.assign(n,{subscribe:a.subscribe??e.subscribe,on:a.on??e.on,[ov]:cv(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 Uv(e,{parent:t}={parent:gv()}){if(e)return Nv(Hv({parent:t??fv,clients:e}));if(t===null)throw Error(`received null parent, this usage is not allowed`);return t}var Q=e=>{let t=Uv(),n=lv(t),r=(0,_.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,_.useDebugValue)(r),r},Wv=({children:e,condition:t})=>Q(t)?e:null;Wv.displayName=`AuiIf`;var Gv=e=>{let t=Uv(),n=(0,_.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,_.useMemo)(()=>t,[n,r,typeof t?.props==`object`&&t.props!=null&&Object.entries(t.props).length===0?Kv:t?.props])??e},Yv=_.createContext(!0);function Xv(){throw Error(`A function wrapped in useEffectEvent can't be called during rendering.`)}var Zv=`use`in _.default?()=>{try{return _.use(Yv)}catch{return!1}}:()=>!1;function Qv(e){let t=_.useRef(Xv);return _.useInsertionEffect(()=>{t.current=e},[e]),(...e)=>{Zv()&&Xv();let n=t.current;return n(...e)}}var $v=(e,t)=>{let n=Uv(),r=Qv(t),{scope:i,event:a}=Sv(e);(0,_.useEffect)(()=>n.on({scope:i,event:a},r),[n,i,a])},ey=Q_(e=>{if(e.key===void 0)throw Error(`tapClientResource: Element has no key`);return x_(iv(e))});function ty(e,t){let n=S_(()=>e().map(e=>ey(e)),t),r=f_(()=>Object.keys(n),[n]),i=f_(()=>n.reduce((e,t,n)=>(e[t.key]=n,e),{}),[n]);return{state:f_(()=>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 ny=Bg(({toolkit:e,mcpApp:t})=>{let n=S_(()=>t?[Vg(`mcpApp`,t)]:[],[t])[0],[r,i]=a_(()=>({})),a=f_(()=>({toolUIs:r,mcpApp:n,tools:Object.fromEntries(Object.entries(r).map(([e,t])=>[e,t.map(e=>e.render)]))}),[r,n]),o=Ev(),s=p_((e,t,n)=>{let r={render:t,standalone:n?.standalone??!1};return i(t=>({...t,[e]:[...t[e]??[],r]})),()=>{i(t=>{let n=t[e]?.filter(e=>e!==r)??[];if(n.length>0)return{...t,[e]:n};let{[e]:i,...a}=t;return a})}},[]);return c_(()=>{if(!e)return;let t=[];for(let[n,r]of Object.entries(e))r.render&&t.push(s(n,r.render,{standalone:U_(r)}));let n=Object.entries(e).reduce((e,[t,n])=>{let{render:r,display:i,...a}=n;return e[t]=a,e},{});return t.push(o.current.modelContext().register({getModelContext:()=>({tools:n})})),()=>{t.forEach(e=>e())}},[e,s,o]),{getState:()=>a,setToolUI:s}});bv(ny,(e,t)=>{!e.modelContext&&t.modelContext.source===null&&(e.modelContext=H_())});var ry=e=>{let[,t]=a_(e.getState);return c_(()=>(t(e.getState()),e.subscribe(()=>{t(e.getState())})),[e]),e.getState()},iy=Bg(({runtime:e})=>{let t=ry(e);return{getState:()=>t,remove:e.remove,__internal_getRuntime:()=>e}}),ay=Bg(({runtime:e,index:t})=>x_(iy({runtime:f_(()=>e.getAttachmentByIndex(t),[e,t])}))),oy=Bg(({threadIdRef:e,messageIdRef:t,runtime:n})=>{let r=ry(n),i=Dv();c_(()=>{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=ty(()=>r.attachments.map((e,t)=>Vg(e.id,ay({runtime:n,index:t}))),[r.attachments,n]),o=f_(()=>({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}}),sy=Bg(({runtime:e})=>{let t=ry(e);return{getState:()=>t,addToolResult:t=>e.addToolResult(t),resumeToolCall:t=>e.resumeToolCall(t),respondToToolApproval:t=>e.respondToToolApproval(t),__internal_getRuntime:()=>e}}),cy=Bg(({runtime:e,index:t})=>x_(iy({runtime:f_(()=>e.getAttachmentByIndex(t),[e,t])}))),ly=Bg(({runtime:e,index:t})=>x_(sy({runtime:f_(()=>e.getMessagePartByIndex(t),[e,t])}))),uy=Bg(({runtime:e,threadIdRef:t})=>{let n=ry(e),[r,i]=a_(!1),[a,o]=a_(!1),s=f_(()=>({get current(){return e.getState().id}}),[e]),c=av(oy({runtime:e.composer,threadIdRef:t,messageIdRef:s})),l=ty(()=>n.content.map((t,n)=>Vg(`toolCallId`in t&&t.toolCallId!=null?`toolCallId-${t.toolCallId}`:`index-${n}`,ly({runtime:e,index:n}))),[n.content,e]),u=ty(()=>(n.attachments??[]).map((t,n)=>Vg(t.id,cy({runtime:e,index:n}))),[n.attachments,e]),d=f_(()=>({...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}}),dy=Bg(({runtime:e,id:t,threadIdRef:n})=>x_(uy({runtime:f_(()=>e.getMessageById(t),[e,t]),threadIdRef:n}))),fy=Bg(({runtime:e})=>{let t=ry(e),n=Dv();c_(()=>{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=f_(()=>({get current(){return e.getState().threadId}}),[e]),i=av(oy({runtime:e.composer,threadIdRef:r})),a=ty(()=>t.messages.map(t=>Vg(t.id,dy({runtime:e,id:t.id,threadIdRef:r}))),[t.messages,e,r]),o=f_(()=>({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}}),py=Bg(({runtime:e})=>{let t=ry(e),n=Dv();return c_(()=>{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}}),my=Bg(({runtime:e,id:t})=>x_(py({runtime:f_(()=>e.getItemById(t),[e,t])}))),hy=Bg(({runtime:e,__internal_assistantRuntime:t})=>{let n=ry(e),r=av(fy({runtime:e.main})),i=ty(()=>Object.keys(n.threadItems).map(t=>Vg(t,my({runtime:e,id:t}))),[n.threadItems,e]),a=f_(()=>({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,n)=>{await e.switchToThread(t,n)},switchToNewThread:async()=>{await e.switchToNewThread()},getLoadThreadsPromise:()=>e.getLoadThreadsPromise(),reload:()=>e.reload(),loadMore:()=>e.loadMore(),__internal_getAssistantRuntime:()=>t}}),gy=Bg(e=>({getState:()=>e})),_y=Bg(e=>{let[t]=a_(()=>({suggestions:(e??[]).map(e=>typeof e==`string`?{title:e,label:``,prompt:e}:{title:e.title,label:e.label,prompt:e.prompt})})),n=ty(()=>t.suggestions.map((e,t)=>Vg(t,gy(e))),[t.suggestions]);return{getState:()=>t,suggestion:({index:e})=>n.get({index:e})}}),vy=Bg(e=>{let t=Ev();return c_(()=>e.registerModelContextProvider(t.current.modelContext()),[e,t]),x_(hy({runtime:e.threads,__internal_assistantRuntime:e}))}),yy=(e,t)=>{e.thread??=vv({source:`threads`,query:{type:`main`},get:e=>e.threads().thread(`main`)}),e.threadListItem??=vv({source:`threads`,query:{type:`main`},get:e=>e.threads().item(`main`)}),e.composer??=vv({source:`thread`,query:{},get:e=>e.threads().thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=H_()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=_y())},by=Bg(e=>x_(vy(e)));bv(by,(e,t)=>{yy(e,t),!e.tools&&t.tools.source===null&&(e.tools=ny({})),!e.dataRenderers&&t.dataRenderers.source===null&&(e.dataRenderers=F_())});var xy=e=>e._core?.RenderComponent,Sy=(0,_.memo)(({runtime:e,aui:t=null,children:n})=>{let r=Uv({threads:by(e)},{parent:t}),i=xy(e);return(0,K.jsxs)(_v,{value:r,children:[i&&(0,K.jsx)(i,{}),n]})}),Cy=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},wy=(e=>e?Cy(e):Cy),Ty=e=>e;function Ey(e,t=Ty){let n=_.useSyncExternalStore(e.subscribe,_.useCallback(()=>t(e.getState()),[e,t]),_.useCallback(()=>t(e.getInitialState()),[e,t]));return _.useDebugValue(n),n}var Dy=e=>{let t=wy(e),n=e=>Ey(t,e);return Object.assign(n,t),n},Oy=(e=>e?Dy(e):Dy),ky=()=>{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}},Ay=()=>{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=ky(),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()}}))}}},jy=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())}},My=e=>new ReadableStream({start(t){return e.start?.(new jy(t))},pull(t){return e.pull?.(new jy(t))},cancel(t){return e.cancel?.(t)}}),Ny=()=>{let e;return[My({start(t){e=t}}),e]},Py=class{_controller;_isClosed=!1;_mergeTask;constructor(e){this._controller=e;let t=My({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())}},Fy=e=>new ReadableStream({start(t){return e.start?.(new Py(t))},pull(t){return e.pull?.(new Py(t))},cancel(t){return e.cancel?.(t)}}),Iy=()=>{let e;return[Fy({start(t){e=t}}),e]},Ly=class{value=-1;up(){return++this.value}},Ry=class extends TransformStream{constructor(e){super({transform(t,n){n.enqueue({...t,path:[e,...t.path]})}})}};TransformStream;var zy=class extends TransformStream{constructor(e){let t=new Ly,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]})}})}},By=class extends TransformStream{constructor(e){super();let t=e(super.readable);Object.defineProperty(this,"readable",{value:t,writable:!1})}},Vy=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)}})}},Hy=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},Uy=Hy(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),Wy=class e{_state;_parentId;constructor(e){this._state=e||{merger:Ay(),contentCounter:new Ly}}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 Ry(this._state.contentCounter.value)))}merge(e){this._state.merger.addStream(e.pipeThrough(new zy(this._state.contentCounter)))}appendText(e){(this._state.append?.kind!==`text`||this._state.append.parentId!==this._parentId)&&(this._state.append={kind:`text`,parentId:this._parentId,controller:this.addTextPart()}),this._state.append.controller.append(e)}appendReasoning(e){(this._state.append?.kind!==`reasoning`||this._state.append.parentId!==this._parentId)&&(this._state.append={kind:`reasoning`,parentId:this._parentId,controller:this.addReasoningPart()}),this._state.append.controller.append(e)}addTextPart(){let[e,t]=Ny();return this._addPart(this._withParentIdOption({type:`text`}),e),t}addReasoningPart(){let[e,t]=Ny();return this._addPart(this._withParentIdOption({type:`reasoning`}),e),t}addToolCallPart(e){let t=typeof e==`string`?{toolName:e}:e,n=t.toolName,r=t.toolCallId??Uy(),[i,a]=Iy();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 Gy(e){let t=new Wy;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 Ky(){let{resolve:e,promise:t}=ky(),n;return[Gy(r=>(n=r,n.__internal_subscribeToClose(e),t)),n]}function qy(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 Jy=n(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}))(),1),Yy=Symbol(`aui.parse-partial-json-object.meta`),Xy=e=>e?.[Yy],Zy=e=>{if(e.length===0)return{[Yy]:{state:`partial`,partialPath:[]}};try{let t=Jy.default.parse(e);if(typeof t!=`object`||!t)throw Error(`argsText is expected to be an object`);return t[Yy]={state:`complete`,partialPath:[]},t}catch{try{let[t,n]=qy(e),r=Jy.default.parse(t);if(typeof r!=`object`||!r)throw Error(`argsText is expected to be an object`);return r[Yy]={state:`partial`,partialPath:n},r}catch{return}}},Qy=(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 Qy(s,{state:`partial`,partialPath:o},i)},$y=(e,t)=>{let n=Xy(e);if(!n)throw Error(`unable to determine object state`);return Qy(e,n,t.map(String))};async function*eb(){let e=this.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)break;yield n}}finally{e.releaseLock()}}function tb(e){return e[Symbol.asyncIterator]??=eb,e}var nb=Symbol.for(`aui.tool-response`),rb=class e{get[nb](){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&&nb in e}static toResponse(t){return t instanceof e?t:new e({result:t===void 0?`<no result>`:t})}};function ib(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 ab(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}var ob=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($y(e,this.fieldPath)===`complete`){let t=ab(e,this.fieldPath);t!==void 0&&(this.resolve(t),this.dispose())}}catch(e){this.reject(e),this.dispose()}}dispose(){this.disposed=!0}},sb=class{controller;disposed=!1;fieldPath;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=ab(e,this.fieldPath);t!==void 0&&this.controller.enqueue(t),$y(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},cb=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=ab(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)}$y(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},lb=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=ab(e,this.fieldPath);if(!Array.isArray(t))return;for(let n=0;n<t.length;n++)this.processedIndexes.has(n)||$y(e,[...this.fieldPath,n])===`complete`&&(this.controller.enqueue(t[n]),this.processedIndexes.add(n));$y(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},ub=class{argTextDeltas;handles=new Set;args=Zy(``);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=Zy(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 ob(t,n,e);if(this.args&&$y(this.args,e)===`complete`){let n=ab(this.args,e);if(n!==void 0){t(n);return}}this.handles.add(r),r.update(this.args)})}streamValues(...e){let t=e;return tb(new ReadableStream({start:e=>{let n=new sb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof sb){e.dispose(),this.handles.delete(e);break}}}))}streamText(...e){let t=e;return tb(new ReadableStream({start:e=>{let n=new cb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof cb){e.dispose(),this.handles.delete(e);break}}}))}forEach(...e){let t=e;return tb(new ReadableStream({start:e=>{let n=new lb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof lb){e.dispose(),this.handles.delete(e);break}}}))}},db=class{promise;constructor(e){this.promise=e}get(){return this.promise}},fb=class{args;response;writable;resolve;argsText=``;constructor(){let e=new TransformStream;this.writable=e.writable,this.args=new ub(e.readable);let{promise:t,resolve:n}=ky();this.resolve=n,this.response=new db(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}},pb=class extends By{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 fb;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 rb({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=ib(()=>{let t;try{t=Jy.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 rb({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 rb({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 Vy).pipeThrough(i)})}},mb=e=>typeof e==`object`&&!!e&&`~standard`in e&&e[`~standard`].version===1;function hb(e,t,n,r){let i=e?.[n.toolName];return i?.execute?(async e=>{if(t.aborted)return new rb({result:`Tool execution was cancelled.`,isError:!0});let a=e;if(mb(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 rb({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=rb.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 rb({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 gb(e,t,n,r,i){e?.[r.toolName]?.streamCall?.(n,{toolCallId:r.toolCallId,abortSignal:t,human:e=>i(r.toolCallId,e)})}function _b(e,t,n,r){let i=typeof e==`function`?e:()=>e,a=typeof t==`function`?t:()=>t;return new pb({execute:e=>hb(i(),a(),e,n),streamCall:({reader:e,...t})=>gb(i(),a(),e,t,n),onExecutionStart:r?.onExecutionStart,onExecutionEnd:r?.onExecutionEnd})}var vb=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({attachment:vv({source:`message`,query:{type:`index`,index:e},get:t=>t.message().attachment({index:e})})}),children:t}),yb=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({attachment:vv({source:`composer`,query:{type:`index`,index:e},get:t=>t.composer().attachment({index:e})})}),children:t}),bb=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({message:vv({source:`thread`,query:{type:`index`,index:e},get:t=>t.thread().message({index:e})}),composer:vv({source:`message`,query:{},get:t=>t.thread().message({index:e}).composer()})}),children:t}),xb=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({part:vv({source:`message`,query:{type:`index`,index:e},get:t=>t.message().part({index:e})})}),children:t}),Sb=Bg(({text:e,isRunning:t})=>{let n=f_(()=>({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`)},respondToToolApproval:()=>{throw Error(`Not supported`)}}}),Cb=({text:e,isRunning:t=!1,children:n})=>(0,K.jsx)(_v,{value:Uv({part:Sb({text:e,isRunning:t})}),children:n}),wb=Object.freeze({type:`complete`}),Tb=Bg(({parts:e,getMessagePart:t})=>{let[n,r]=a_(!0),i=f_(()=>e[e.length-1]?.status??wb,[e]),a=f_(()=>({parts:e,collapsed:n,status:i}),[e,n,i]);return{getState:()=>a,setCollapsed:r,part:t}}),Eb=({startIndex:e,endIndex:t,children:n})=>{let r=Q(e=>e.message.parts).slice(e,t+1),i=Uv();return(0,K.jsx)(_v,{value:Uv({chainOfThought:Tb({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})},Db=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({suggestion:vv({source:`suggestions`,query:{index:e},get:t=>t.suggestions().suggestion({index:e})})}),children:t}),Ob=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({queueItem:vv({source:`composer`,query:{index:e},get:t=>t.composer().queueItem({index:e})})}),children:t}),kb=Symbol(`innerMessage`),Ab=Symbol(`innerMessages`),jb=[],Mb=(e,t)=>{kb in e||(e[kb]=t)},Nb=e=>{let t=`messages`in e?e.messages:e,n=t[Ab]||t[kb];return n?Array.isArray(n)?n:(t[Ab]=[n],t[Ab]):jb},Pb=Symbol(`skip-update`);function Fb(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 Ib=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)}}},Lb=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()}}},Rb=class extends Lb{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e;let t=e.getState();if(t===Pb)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===Pb||Fb(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){return this.binding.subscribe(()=>{this._syncState()&&this.notifySubscribers()})}},zb=class extends Lb{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!==Pb&&(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()})}},Bb=class extends Lb{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?.()}}},Vb=class extends Lb{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?.()}}},Hb=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)}},Ub=class extends Hb{_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)}},Wb=class extends Ub{get source(){return`thread-composer`}},Gb=class extends Ub{get source(){return`edit-composer`}},Kb=class extends Hb{get source(){return`message`}remove(){throw Error(`Message attachments cannot be removed`)}},qb=Object.freeze([]),Jb=Object.freeze({}),Yb=e=>Object.freeze({type:`thread`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,attachments:e?.attachments??qb,text:e?.text??``,role:e?.role??`user`,runConfig:e?.runConfig??Jb,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,value:e?.text??``}),Xb=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??qb,runConfig:e?.runConfig??Jb,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,parentId:e?.parentId??null,sourceId:e?.sourceId??null,value:e?.text??``}),Zb=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 Vb({event:e,binding:this._core}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},Qb=class extends Zb{get path(){return this._core.path}get type(){return`thread`}_getState;constructor(e){let t=new zb({path:e.path,getState:()=>Yb(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 Wb(new Rb({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`}:Pb},subscribe:e=>this._core.subscribe(e)}),this._core)}},$b=class extends Zb{_beginEdit;get path(){return this._core.path}get type(){return`edit`}_getState;constructor(e,t){let n=new zb({path:e.path,getState:()=>Xb(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 Gb(new Rb({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`}:Pb},subscribe:e=>this._core.subscribe(e)}),this._core)}},ex=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 _.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},$s=`DialogDescriptionWarning`,ec=({contentRef:e,descriptionId:t})=>{let n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Zs($s).contentName}}.`;return _.useEffect(()=>{let r=e.current?.getAttribute(`aria-describedby`);t&&r&&(document.getElementById(t)||console.warn(n))},[n,e,t]),null},tc=Es,nc=Ms,rc=Ps,ic=Rs,ac=Us,oc=Gs,sc=qs;function cc(e){let[t,n]=_.useState(void 0);return Ji(()=>{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 lc=[`top`,`right`,`bottom`,`left`],uc=Math.min,dc=Math.max,fc=Math.round,pc=Math.floor,mc=e=>({x:e,y:e}),hc={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function gc(e,t,n){return dc(e,uc(t,n))}function _c(e,t){return typeof e==`function`?e(t):e}function vc(e){return e.split(`-`)[0]}function yc(e){return e.split(`-`)[1]}function bc(e){return e===`x`?`y`:`x`}function xc(e){return e===`y`?`height`:`width`}function Sc(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function Cc(e){return bc(Sc(e))}function wc(e,t,n){n===void 0&&(n=!1);let r=yc(e),i=Cc(e),a=xc(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Nc(o)),[o,Nc(o)]}function Tc(e){let t=Nc(e);return[Ec(e),t,Ec(t)]}function Ec(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var Dc=[`left`,`right`],Oc=[`right`,`left`],kc=[`top`,`bottom`],Ac=[`bottom`,`top`];function jc(e,t,n){switch(e){case`top`:case`bottom`:return n?t?Oc:Dc:t?Dc:Oc;case`left`:case`right`:return t?kc:Ac;default:return[]}}function Mc(e,t,n,r){let i=yc(e),a=jc(vc(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Ec)))),a}function Nc(e){let t=vc(e);return hc[t]+e.slice(t.length)}function Pc(e){return{top:0,right:0,bottom:0,left:0,...e}}function Fc(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Pc(e)}function Ic(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 Lc(e,t,n){let{reference:r,floating:i}=e,a=Sc(t),o=Cc(t),s=xc(o),c=vc(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(yc(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 Rc(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}=_c(t,e),p=Fc(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Ic(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=Ic(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 zc=50,Bc=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Rc},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Lc(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<zc&&(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}=Lc(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},Vc=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}=_c(e,t)||{};if(l==null)return{};let d=Fc(u),f={x:n,y:r},p=Cc(i),m=xc(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=uc(d[_],T),D=uc(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=gc(O,A,k),M=!c.arrow&&yc(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}}}),Hc=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}=_c(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=vc(r),_=Sc(o),v=vc(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Nc(o)]:Tc(o)),x=p!==`none`;!d&&x&&b.push(...Mc(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=wc(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`&&_!==Sc(t))||T.every(e=>Sc(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=Sc(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 Uc(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Wc(e){return lc.some(t=>e[t]>=0)}var Gc=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=_c(e,t);switch(i){case`referenceHidden`:{let e=Uc(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:Wc(e)}}}case`escaped`:{let e=Uc(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:Wc(e)}}}default:return{}}}}},Kc=new Set([`left`,`top`]);async function qc(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=vc(n),s=yc(n),c=Sc(n)===`y`,l=Kc.has(o)?-1:1,u=a&&c?-1:1,d=_c(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 Jc=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 qc(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}}}}},Yc=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}=_c(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Sc(vc(i)),p=bc(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=gc(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=gc(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}}}}}},Xc=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}=_c(e,t),u={x:n,y:r},d=Sc(i),f=bc(d),p=u[f],m=u[d],h=_c(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=Kc.has(vc(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}}}},Zc=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}=_c(e,t),u=await o.detectOverflow(t,l),d=vc(i),f=yc(i),p=Sc(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=uc(h-u[g],v),x=uc(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=dc(u.left,0),t=dc(u.right,0),n=dc(u.top,0),r=dc(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:dc(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:dc(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 Qc(){return typeof window<`u`}function $c(e){return nl(e)?(e.nodeName||``).toLowerCase():`#document`}function el(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function tl(e){return((nl(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function nl(e){return Qc()?e instanceof Node||e instanceof el(e).Node:!1}function rl(e){return Qc()?e instanceof Element||e instanceof el(e).Element:!1}function il(e){return Qc()?e instanceof HTMLElement||e instanceof el(e).HTMLElement:!1}function al(e){return!Qc()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof el(e).ShadowRoot}function ol(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=_l(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function sl(e){return/^(table|td|th)$/.test($c(e))}function cl(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var ll=/transform|translate|scale|rotate|perspective|filter/,ul=/paint|layout|strict|content/,dl=e=>!!e&&e!==`none`,fl;function pl(e){let t=rl(e)?_l(e):e;return dl(t.transform)||dl(t.translate)||dl(t.scale)||dl(t.rotate)||dl(t.perspective)||!hl()&&(dl(t.backdropFilter)||dl(t.filter))||ll.test(t.willChange||``)||ul.test(t.contain||``)}function ml(e){let t=yl(e);for(;il(t)&&!gl(t);){if(pl(t))return t;if(cl(t))return null;t=yl(t)}return null}function hl(){return fl??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),fl}function gl(e){return/^(html|body|#document)$/.test($c(e))}function _l(e){return el(e).getComputedStyle(e)}function vl(e){return rl(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function yl(e){if($c(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||al(e)&&e.host||tl(e);return al(t)?t.host:t}function bl(e){let t=yl(e);return gl(t)?e.ownerDocument?e.ownerDocument.body:e.body:il(t)&&ol(t)?t:bl(t)}function xl(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=bl(e),i=r===e.ownerDocument?.body,a=el(r);if(i){let e=Sl(a);return t.concat(a,a.visualViewport||[],ol(r)?r:[],e&&n?xl(e):[])}else return t.concat(r,xl(r,[],n))}function Sl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Cl(e){let t=_l(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=il(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=fc(n)!==a||fc(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function wl(e){return rl(e)?e:e.contextElement}function Tl(e){let t=wl(e);if(!il(t))return mc(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Cl(t),o=(a?fc(n.width):n.width)/r,s=(a?fc(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var El=mc(0);function Dl(e){let t=el(e);return!hl()||!t.visualViewport?El:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Ol(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==el(e)?!1:t}function kl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=wl(e),o=mc(1);t&&(r?rl(r)&&(o=Tl(r)):o=Tl(e));let s=Ol(a,n,r)?Dl(a):mc(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=el(a),t=r&&rl(r)?el(r):r,n=e,i=Sl(n);for(;i&&r&&t!==n;){let e=Tl(i),t=i.getBoundingClientRect(),r=_l(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=el(i),i=Sl(n)}}return Ic({width:u,height:d,x:c,y:l})}function Al(e,t){let n=vl(e).scrollLeft;return t?t.left+n:kl(tl(e)).left+n}function jl(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Al(e,n),y:n.top+t.scrollTop}}function Ml(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=tl(r),s=t?cl(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=mc(1),u=mc(0),d=il(r);if((d||!d&&!a)&&(($c(r)!==`body`||ol(o))&&(c=vl(r)),d)){let e=kl(r);l=Tl(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?jl(o,c):mc(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 Nl(e){return Array.from(e.getClientRects())}function Pl(e){let t=tl(e),n=vl(e),r=e.ownerDocument.body,i=dc(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=dc(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+Al(e),s=-n.scrollTop;return _l(r).direction===`rtl`&&(o+=dc(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var Fl=25;function Il(e,t){let n=el(e),r=tl(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=hl();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=Al(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<=Fl&&(a-=o)}else l<=Fl&&(a+=l);return{width:a,height:o,x:s,y:c}}function Ll(e,t){let n=kl(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=il(e)?Tl(e):mc(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Rl(e,t,n){let r;if(t===`viewport`)r=Il(e,n);else if(t===`document`)r=Pl(tl(e));else if(rl(t))r=Ll(t,n);else{let n=Dl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Ic(r)}function zl(e,t){let n=yl(e);return n===t||!rl(n)||gl(n)?!1:_l(n).position===`fixed`||zl(n,t)}function Bl(e,t){let n=t.get(e);if(n)return n;let r=xl(e,[],!1).filter(e=>rl(e)&&$c(e)!==`body`),i=null,a=_l(e).position===`fixed`,o=a?yl(e):e;for(;rl(o)&&!gl(o);){let t=_l(o),n=pl(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||ol(o)&&!n&&zl(e,o))?r=r.filter(e=>e!==o):i=t,o=yl(o)}return t.set(e,r),r}function Vl(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?cl(t)?[]:Bl(t,this._c):[].concat(n),r],o=Rl(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=Rl(t,a[e],i);s=dc(n.top,s),c=uc(n.right,c),l=uc(n.bottom,l),u=dc(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function Hl(e){let{width:t,height:n}=Cl(e);return{width:t,height:n}}function Ul(e,t,n){let r=il(t),i=tl(t),a=n===`fixed`,o=kl(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=mc(0);function l(){c.x=Al(i)}if(r||!r&&!a)if(($c(t)!==`body`||ol(i))&&(s=vl(t)),r){let e=kl(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?jl(i,s):mc(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 Wl(e){return _l(e).position===`static`}function Gl(e,t){if(!il(e)||_l(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return tl(e)===n&&(n=n.ownerDocument.body),n}function Kl(e,t){let n=el(e);if(cl(e))return n;if(!il(e)){let t=yl(e);for(;t&&!gl(t);){if(rl(t)&&!Wl(t))return t;t=yl(t)}return n}let r=Gl(e,t);for(;r&&sl(r)&&Wl(r);)r=Gl(r,t);return r&&gl(r)&&Wl(r)&&!pl(r)?n:r||ml(e)||n}var ql=async function(e){let t=this.getOffsetParent||Kl,n=this.getDimensions,r=await n(e.floating);return{reference:Ul(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Jl(e){return _l(e).direction===`rtl`}var Yl={convertOffsetParentRelativeRectToViewportRelativeRect:Ml,getDocumentElement:tl,getClippingRect:Vl,getOffsetParent:Kl,getElementRects:ql,getClientRects:Nl,getDimensions:Hl,getScale:Tl,isElement:rl,isRTL:Jl};function Xl(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Zl(e,t){let n=null,r,i=tl(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=pc(d),h=pc(i.clientWidth-(u+f)),g=pc(i.clientHeight-(d+p)),_=pc(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:dc(0,uc(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&&!Xl(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 Ql(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=wl(e),u=i||a?[...l?xl(l):[],...t?xl(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?Zl(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?kl(e):null;c&&g();function g(){let t=kl(e);h&&!Xl(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 $l=Jc,eu=Yc,tu=Hc,nu=Zc,ru=Gc,iu=Vc,au=Xc,ou=(e,t,n)=>{let r=new Map,i={platform:Yl,...n},a={...i.platform,_c:r};return Bc(e,t,{...i,platform:a})},su=typeof document<`u`?_.useLayoutEffect:function(){};function cu(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(!cu(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)&&!cu(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function lu(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function uu(e,t){let n=lu(e);return Math.round(t*n)/n}function du(e){let t=_.useRef(e);return su(()=>{t.current=e}),t}function fu(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]=_.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=_.useState(r);cu(f,r)||p(r);let[m,h]=_.useState(null),[g,v]=_.useState(null),y=_.useCallback(e=>{e!==C.current&&(C.current=e,h(e))},[]),b=_.useCallback(e=>{e!==w.current&&(w.current=e,v(e))},[]),x=a||m,S=o||g,C=_.useRef(null),w=_.useRef(null),T=_.useRef(u),E=c!=null,D=du(c),O=du(i),k=du(l),A=_.useCallback(()=>{if(!C.current||!w.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),ou(C.current,w.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!cu(T.current,t)&&(T.current=t,dt.flushSync(()=>{d(t)}))})},[f,t,n,O,k]);su(()=>{l===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let j=_.useRef(!1);su(()=>(j.current=!0,()=>{j.current=!1}),[]),su(()=>{if(x&&(C.current=x),S&&(w.current=S),x&&S){if(D.current)return D.current(x,S,A);A()}},[x,S,A,D,E]);let M=_.useMemo(()=>({reference:C,floating:w,setReference:y,setFloating:b}),[y,b]),N=_.useMemo(()=>({reference:x,floating:S}),[x,S]),P=_.useMemo(()=>{let e={position:n,left:0,top:0};if(!N.floating)return e;let t=uu(N.floating,u.x),r=uu(N.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...lu(N.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,N.floating,u.x,u.y]);return _.useMemo(()=>({...u,update:A,refs:M,elements:N,floatingStyles:P}),[u,A,M,N,P])}var pu=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?{}:iu({element:r.current,padding:i}).fn(n):r?iu({element:r,padding:i}).fn(n):{}}}},mu=(e,t)=>{let n=$l(e);return{name:n.name,fn:n.fn,options:[e,t]}},hu=(e,t)=>{let n=eu(e);return{name:n.name,fn:n.fn,options:[e,t]}},gu=(e,t)=>({fn:au(e).fn,options:[e,t]}),_u=(e,t)=>{let n=tu(e);return{name:n.name,fn:n.fn,options:[e,t]}},vu=(e,t)=>{let n=nu(e);return{name:n.name,fn:n.fn,options:[e,t]}},yu=(e,t)=>{let n=ru(e);return{name:n.name,fn:n.fn,options:[e,t]}},bu=(e,t)=>{let n=pu(e);return{name:n.name,fn:n.fn,options:[e,t]}},xu=`Arrow`,Su=_.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,K.jsx)(zi.svg,{...a,ref:t,width:r,height:i,viewBox:`0 0 30 10`,preserveAspectRatio:`none`,children:e.asChild?n:(0,K.jsx)(`polygon`,{points:`0,0 30,0 15,10`})})});Su.displayName=xu;var Cu=Su,wu=`Popper`,[Tu,Eu]=Ki(wu),[Du,Ou]=Tu(wu),ku=e=>{let{__scopePopper:t,children:n}=e,[r,i]=_.useState(null);return(0,K.jsx)(Du,{scope:t,anchor:r,onAnchorChange:i,children:n})};ku.displayName=wu;var Au=`PopperAnchor`,ju=_.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=Ou(Au,n),o=_.useRef(null),s=Ai(t,o),c=_.useRef(null);return _.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,K.jsx)(zi.div,{...i,ref:s})});ju.displayName=Au;var Mu=`PopperContent`,[Nu,Pu]=Tu(Mu),Fu=_.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=Ou(Mu,n),[v,y]=_.useState(null),b=Ai(t,e=>y(e)),[x,S]=_.useState(null),C=cc(x),w=C?.width??0,T=C?.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(zu),altBoundary:k},{refs:j,floatingStyles:M,placement:N,isPositioned:P,middlewareData:F}=fu({strategy:`fixed`,placement:E,whileElementsMounted:(...e)=>Ql(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[mu({mainAxis:i+T,alignmentAxis:o}),c&&hu({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?gu():void 0,...A}),c&&_u({...A}),vu({...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`)}}),x&&bu({element:x,padding:s}),Bu({arrowWidth:w,arrowHeight:T}),f&&yu({strategy:`referenceHidden`,...A})]}),[I,L]=Vu(N),R=ba(m);Ji(()=>{P&&R?.()},[P,R]);let z=F.arrow?.x,B=F.arrow?.y,V=F.arrow?.centerOffset!==0,[H,U]=_.useState();return Ji(()=>{v&&U(window.getComputedStyle(v).zIndex)},[v]),(0,K.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,K.jsx)(Nu,{scope:n,placedSide:I,onArrowChange:S,arrowX:z,arrowY:B,shouldHideArrow:V,children:(0,K.jsx)(zi.div,{"data-side":I,"data-align":L,...h,ref:b,style:{...h.style,animation:P?void 0:`none`}})})})});Fu.displayName=Mu;var Iu=`PopperArrow`,Lu={top:`bottom`,right:`left`,bottom:`top`,left:`right`},Ru=_.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=Pu(Iu,n),a=Lu[i.placedSide];return(0,K.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,K.jsx)(Cu,{...r,ref:t,style:{...r.style,display:`block`}})})});Ru.displayName=Iu;function zu(e){return e!==null}var Bu=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]=Vu(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 Vu(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var Hu=ku,Uu=ju,Wu=Fu,Gu=Ru,Ku=`Popover`,[qu,Ju]=Ki(Ku,[Eu]),Yu=Eu(),[Xu,Zu]=qu(Ku),Qu=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=Yu(t),c=_.useRef(null),[l,u]=_.useState(!1),[d,f]=Xi({prop:r,defaultProp:i??!1,onChange:a,caller:Ku});return(0,K.jsx)(Hu,{...s,children:(0,K.jsx)(Xu,{scope:t,contentId:oa(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:_.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:_.useCallback(()=>u(!0),[]),onCustomAnchorRemove:_.useCallback(()=>u(!1),[]),modal:o,children:n})})};Qu.displayName=Ku;var $u=`PopoverAnchor`,ed=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Zu($u,n),a=Yu(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return _.useEffect(()=>(o(),()=>s()),[o,s]),(0,K.jsx)(Uu,{...a,...r,ref:t})});ed.displayName=$u;var td=`PopoverTrigger`,nd=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Zu(td,n),a=Yu(n),o=Ai(t,i.triggerRef),s=(0,K.jsx)(zi.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":_d(i.open),...r,ref:o,onClick:q(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,K.jsx)(Uu,{asChild:!0,...a,children:s})});nd.displayName=td;var rd=`PopoverPortal`,[id,ad]=qu(rd,{forceMount:void 0}),od=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=Zu(rd,t);return(0,K.jsx)(id,{scope:t,forceMount:n,children:(0,K.jsx)(ea,{present:n||a.open,children:(0,K.jsx)(Qa,{asChild:!0,container:i,children:r})})})};od.displayName=rd;var sd=`PopoverContent`,cd=_.forwardRef((e,t)=>{let n=ad(sd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=Zu(sd,e.__scopePopover);return(0,K.jsx)(ea,{present:r||a.open,children:a.modal?(0,K.jsx)(ud,{...i,ref:t}):(0,K.jsx)(dd,{...i,ref:t})})});cd.displayName=sd;var ld=ji(`PopoverContent.RemoveScroll`),ud=_.forwardRef((e,t)=>{let n=Zu(sd,e.__scopePopover),r=_.useRef(null),i=Ai(t,r),a=_.useRef(!1);return _.useEffect(()=>{let e=r.current;if(e)return bs(e)},[]),(0,K.jsx)(ds,{as:ld,allowPinchZoom:!0,children:(0,K.jsx)(fd,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:q(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:q(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:q(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),dd=_.forwardRef((e,t)=>{let n=Zu(sd,e.__scopePopover),r=_.useRef(!1),i=_.useRef(!1);return(0,K.jsx)(fd,{...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()}})}),fd=_.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=Zu(sd,n),p=Yu(n);return eo(),(0,K.jsx)(za,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,K.jsx)(Oa,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,K.jsx)(Wu,{"data-state":_d(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)`}})})})}),pd=`PopoverClose`,md=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Zu(pd,n);return(0,K.jsx)(zi.button,{type:`button`,...r,ref:t,onClick:q(e.onClick,()=>i.onOpenChange(!1))})});md.displayName=pd;var hd=`PopoverArrow`,gd=_.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=Yu(n);return(0,K.jsx)(Gu,{...i,...r,ref:t})});gd.displayName=hd;function _d(e){return e?`open`:`closed`}var vd=Qu,yd=nd,bd=od,xd=cd,Sd=md,[Cd,wd]=Ki(`Tooltip`,[Eu]),Td=Eu(),Ed=`TooltipProvider`,Dd=700,Od=`tooltip.open`,[kd,Ad]=Cd(Ed),jd=e=>{let{__scopeTooltip:t,delayDuration:n=Dd,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=_.useRef(!0),s=_.useRef(!1),c=_.useRef(0);return _.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,K.jsx)(kd,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:_.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:_.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:_.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};jd.displayName=Ed;var Md=`Tooltip`,[Nd,Pd]=Cd(Md),Fd=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Ad(Md,e.__scopeTooltip),l=Td(t),[u,d]=_.useState(null),f=oa(),p=_.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=_.useRef(!1),[v,y]=Xi({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(Od))):c.onClose(),a?.(e)},caller:Md}),b=_.useMemo(()=>v?g.current?`delayed-open`:`instant-open`:`closed`,[v]),x=_.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,y(!0)},[y]),S=_.useCallback(()=>{window.clearTimeout(p.current),p.current=0,y(!1)},[y]),C=_.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,y(!0),p.current=0},h)},[h,y]);return _.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,K.jsx)(Hu,{...l,children:(0,K.jsx)(Nd,{scope:t,contentId:f,open:v,stateAttribute:b,trigger:u,onTriggerChange:d,onTriggerEnter:_.useCallback(()=>{c.isOpenDelayedRef.current?C():x()},[c.isOpenDelayedRef,C,x]),onTriggerLeave:_.useCallback(()=>{m?S():(window.clearTimeout(p.current),p.current=0)},[S,m]),onOpen:x,onClose:S,disableHoverableContent:m,children:n})})};Fd.displayName=Md;var Id=`TooltipTrigger`,Ld=_.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Pd(Id,n),a=Ad(Id,n),o=Td(n),s=Ai(t,_.useRef(null),i.onTriggerChange),c=_.useRef(!1),l=_.useRef(!1),u=_.useCallback(()=>c.current=!1,[]);return _.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,K.jsx)(Uu,{asChild:!0,...o,children:(0,K.jsx)(zi.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:q(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:q(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:q(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:q(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:q(e.onBlur,i.onClose),onClick:q(e.onClick,i.onClose)})})});Ld.displayName=Id;var Rd=`TooltipPortal`,[zd,Bd]=Cd(Rd,{forceMount:void 0}),Vd=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=Pd(Rd,t);return(0,K.jsx)(zd,{scope:t,forceMount:n,children:(0,K.jsx)(ea,{present:n||a.open,children:(0,K.jsx)(Qa,{asChild:!0,container:i,children:r})})})};Vd.displayName=Rd;var Hd=`TooltipContent`,Ud=_.forwardRef((e,t)=>{let n=Bd(Hd,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=Pd(Hd,e.__scopeTooltip);return(0,K.jsx)(ea,{present:r||o.open,children:o.disableHoverableContent?(0,K.jsx)(Jd,{side:i,...a,ref:t}):(0,K.jsx)(Wd,{side:i,...a,ref:t})})}),Wd=_.forwardRef((e,t)=>{let n=Pd(Hd,e.__scopeTooltip),r=Ad(Hd,e.__scopeTooltip),i=_.useRef(null),a=Ai(t,i),[o,s]=_.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=_.useCallback(()=>{s(null),d(!1)},[d]),p=_.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=Qd(r,Zd(r,n.getBoundingClientRect())),a=$d(t.getBoundingClientRect());s(tf([...i,...a])),d(!0)},[d]);return _.useEffect(()=>()=>f(),[f]),_.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]),_.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=!ef(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,K.jsx)(Jd,{...e,ref:a})}),[Gd,Kd]=Cd(Md,{isInside:!1}),qd=Fi(`TooltipContent`),Jd=_.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=Pd(Hd,n),l=Td(n),{onClose:u}=c;return _.useEffect(()=>(document.addEventListener(Od,u),()=>document.removeEventListener(Od,u)),[u]),_.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,K.jsx)(Oa,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,K.jsxs)(Wu,{"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,K.jsx)(qd,{children:r}),(0,K.jsx)(Gd,{scope:n,isInside:!0,children:(0,K.jsx)(Wi,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});Ud.displayName=Hd;var Yd=`TooltipArrow`,Xd=_.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Td(n);return Kd(Yd,n).isInside?null:(0,K.jsx)(Gu,{...i,...r,ref:t})});Xd.displayName=Yd;function Zd(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 Qd(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 $d(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 ef(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 tf(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)),nf(t)}function nf(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 rf=jd,af=Fd,of=Ld,sf=Vd,cf=Ud,lf=Xd;function uf(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=uf(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function df(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=uf(e))&&(r&&(r+=` `),r+=t);return r}var ff=(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},pf=(e,t)=>({classGroupId:e,validator:t}),mf=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),hf=`-`,gf=[],_f=`arbitrary..`,vf=e=>{let t=xf(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:e=>{if(e.startsWith(`[`)&&e.endsWith(`]`))return bf(e);let n=e.split(hf);return yf(n,+(n[0]===``&&n.length>1),t)},getConflictingClassGroupIds:(e,t)=>{if(t){let t=r[e],i=n[e];return t?i?ff(i,t):t:i||gf}return n[e]||gf}}},yf=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;let r=e[t],i=n.nextPart.get(r);if(i){let n=yf(e,t+1,i);if(n)return n}let a=n.validators;if(a===null)return;let o=t===0?e.join(hf):e.slice(t).join(hf),s=a.length;for(let e=0;e<s;e++){let t=a[e];if(t.validator(o))return t.classGroupId}},bf=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?_f+r:void 0})(),xf=e=>{let{theme:t,classGroups:n}=e;return Sf(n,t)},Sf=(e,t)=>{let n=mf();for(let r in e){let i=e[r];Cf(i,n,r,t)}return n},Cf=(e,t,n,r)=>{let i=e.length;for(let a=0;a<i;a++){let i=e[a];wf(i,t,n,r)}},wf=(e,t,n,r)=>{if(typeof e==`string`){Tf(e,t,n);return}if(typeof e==`function`){Ef(e,t,n,r);return}Df(e,t,n,r)},Tf=(e,t,n)=>{let r=e===``?t:Of(t,e);r.classGroupId=n},Ef=(e,t,n,r)=>{if(kf(e)){Cf(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(pf(n,e))},Df=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e<a;e++){let[a,o]=i[e];Cf(o,Of(t,a),n,r)}},Of=(e,t)=>{let n=e,r=t.split(hf),i=r.length;for(let e=0;e<i;e++){let t=r[e],i=n.nextPart.get(t);i||(i=mf(),n.nextPart.set(t,i)),n=i}return n},kf=e=>`isThemeGetter`in e&&e.isThemeGetter===!0,Af=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)}}},jf=`!`,Mf=`:`,Nf=[],Pf=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),Ff=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===Mf){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(jf)?(c=s.slice(0,-1),l=!0):s.startsWith(jf)&&(c=s.slice(1),l=!0);let u=a&&a>i?a-i:void 0;return Pf(t,l,c,u)};if(t){let e=t+Mf,n=r;r=t=>t.startsWith(e)?n(t.slice(e.length)):Pf(Nf,!1,t,void 0,!0)}if(n){let e=r;r=t=>n({className:t,parseClassName:e})}return r},If=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}},Lf=e=>({cache:Af(e.cacheSize),parseClassName:Ff(e),sortModifiers:If(e),postfixLookupClassGroupIds:Rf(e),...vf(e)}),Rf=e=>{let t=Object.create(null),n=e.postfixLookupClassGroups;if(n)for(let e=0;e<n.length;e++)t[n[e]]=!0;return t},zf=/\s+/,Bf=(e,t)=>{let{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:a,postfixLookupClassGroupIds:o}=t,s=[],c=e.trim().split(zf),l=``;for(let e=c.length-1;e>=0;--e){let t=c[e],{isExternal:u,modifiers:d,hasImportantModifier:f,baseClassName:p,maybePostfixModifierPosition:m}=n(t);if(u){l=t+(l.length>0?` `+l:l);continue}let h=!!m,g;if(h){g=r(p.substring(0,m));let e=g&&o[g]?r(p):void 0;e&&e!==g&&(g=e,h=!1)}else g=r(p);if(!g){if(!h){l=t+(l.length>0?` `+l:l);continue}if(g=r(p),!g){l=t+(l.length>0?` `+l:l);continue}h=!1}let _=d.length===0?``:d.length===1?d[0]:a(d).join(`:`),v=f?_+jf:_,y=v+g;if(s.indexOf(y)>-1)continue;s.push(y);let b=i(g,h);for(let e=0;e<b.length;++e){let t=b[e];s.push(v+t)}l=t+(l.length>0?` `+l:l)}return l},Vf=(...e)=>{let t=0,n,r,i=``;for(;t<e.length;)(n=e[t++])&&(r=Hf(n))&&(i&&(i+=` `),i+=r);return i},Hf=e=>{if(typeof e==`string`)return e;let t,n=``;for(let r=0;r<e.length;r++)e[r]&&(t=Hf(e[r]))&&(n&&(n+=` `),n+=t);return n},Uf=(e,...t)=>{let n,r,i,a,o=o=>(n=Lf(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=Bf(e,n);return i(e,a),a};return a=o,(...e)=>a(Vf(...e))},Wf=[],Gf=e=>{let t=t=>t[e]||Wf;return t.isThemeGetter=!0,t},Kf=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,qf=/^\((?:(\w[\w-]*):)?(.+)\)$/i,Jf=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,Yf=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Xf=/\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$/,Zf=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Qf=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,$f=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,ep=e=>Jf.test(e),tp=e=>!!e&&!Number.isNaN(Number(e)),np=e=>!!e&&Number.isInteger(Number(e)),rp=e=>e.endsWith(`%`)&&tp(e.slice(0,-1)),ip=e=>Yf.test(e),ap=()=>!0,op=e=>Xf.test(e)&&!Zf.test(e),sp=()=>!1,cp=e=>Qf.test(e),lp=e=>$f.test(e),up=e=>!J(e)&&!Y(e),dp=e=>e.startsWith(`@container`)&&(e[10]===`/`&&e[11]!==void 0||e[11]===`s`&&e[16]!==void 0&&e.startsWith(`-size/`,10)||e[11]===`n`&&e[18]!==void 0&&e.startsWith(`-normal/`,10)),fp=e=>Dp(e,jp,sp),J=e=>Kf.test(e),pp=e=>Dp(e,Mp,op),mp=e=>Dp(e,Np,tp),hp=e=>Dp(e,Fp,ap),gp=e=>Dp(e,Pp,sp),_p=e=>Dp(e,kp,sp),vp=e=>Dp(e,Ap,lp),yp=e=>Dp(e,Ip,cp),Y=e=>qf.test(e),bp=e=>Op(e,Mp),xp=e=>Op(e,Pp),Sp=e=>Op(e,kp),Cp=e=>Op(e,jp),wp=e=>Op(e,Ap),Tp=e=>Op(e,Ip,!0),Ep=e=>Op(e,Fp,!0),Dp=(e,t,n)=>{let r=Kf.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},Op=(e,t,n=!1)=>{let r=qf.exec(e);return r?r[1]?t(r[1]):n:!1},kp=e=>e===`position`||e===`percentage`,Ap=e=>e===`image`||e===`url`,jp=e=>e===`length`||e===`size`||e===`bg-size`,Mp=e=>e===`length`,Np=e=>e===`number`,Pp=e=>e===`family-name`,Fp=e=>e===`number`||e===`weight`,Ip=e=>e===`shadow`,Lp=Uf(()=>{let e=Gf(`color`),t=Gf(`font`),n=Gf(`text`),r=Gf(`font-weight`),i=Gf(`tracking`),a=Gf(`leading`),o=Gf(`breakpoint`),s=Gf(`container`),c=Gf(`spacing`),l=Gf(`radius`),u=Gf(`shadow`),d=Gf(`inset-shadow`),f=Gf(`text-shadow`),p=Gf(`drop-shadow`),m=Gf(`blur`),h=Gf(`perspective`),g=Gf(`aspect`),_=Gf(`ease`),v=Gf(`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=()=>[ep,`full`,`auto`,...w()],E=()=>[np,`none`,`subgrid`,Y,J],D=()=>[`auto`,{span:[`full`,np,Y,J]},np,Y,J],O=()=>[np,`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=()=>[ep,`auto`,`full`,`dvw`,`dvh`,`lvw`,`lvh`,`svw`,`svh`,`min`,`max`,`fit`,...w()],P=()=>[ep,`screen`,`full`,`dvw`,`lvw`,`svw`,`min`,`max`,`fit`,...w()],F=()=>[ep,`screen`,`full`,`lh`,`dvh`,`lvh`,`svh`,`min`,`max`,`fit`,...w()],I=()=>[e,Y,J],L=()=>[...b(),Sp,_p,{position:[Y,J]}],R=()=>[`no-repeat`,{repeat:[``,`x`,`y`,`space`,`round`]}],z=()=>[`auto`,`cover`,`contain`,Cp,fp,{size:[Y,J]}],B=()=>[rp,bp,pp],V=()=>[``,`none`,`full`,l,Y,J],H=()=>[``,tp,bp,pp],U=()=>[`solid`,`dashed`,`dotted`,`double`],ee=()=>[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],W=()=>[tp,rp,Sp,_p],te=()=>[``,`none`,m,Y,J],ne=()=>[`none`,tp,Y,J],G=()=>[`none`,tp,Y,J],re=()=>[tp,Y,J],ie=()=>[ep,`full`,...w()];return{cacheSize:500,theme:{animate:[`spin`,`ping`,`pulse`,`bounce`],aspect:[`video`],blur:[ip],breakpoint:[ip],color:[ap],container:[ip],"drop-shadow":[ip],ease:[`in`,`out`,`in-out`],font:[up],"font-weight":[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`],"inset-shadow":[ip],leading:[`none`,`tight`,`snug`,`normal`,`relaxed`,`loose`],perspective:[`dramatic`,`near`,`normal`,`midrange`,`distant`,`none`],radius:[ip],shadow:[ip],spacing:[`px`,tp],text:[ip],"text-shadow":[ip],tracking:[`tighter`,`tight`,`normal`,`wide`,`wider`,`widest`]},classGroups:{aspect:[{aspect:[`auto`,`square`,ep,J,Y,g]}],container:[`container`],"container-type":[{"@container":[``,`normal`,`size`,Y,J]}],"container-named":[dp],columns:[{columns:[tp,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:[np,`auto`,Y,J]}],basis:[{basis:[ep,`full`,`auto`,s,...w()]}],"flex-direction":[{flex:[`row`,`row-reverse`,`col`,`col-reverse`]}],"flex-wrap":[{flex:[`nowrap`,`wrap`,`wrap-reverse`]}],flex:[{flex:[tp,ep,`auto`,`initial`,`none`,J]}],grow:[{grow:[``,tp,Y,J]}],shrink:[{shrink:[``,tp,Y,J]}],order:[{order:[np,`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,bp,pp]}],"font-smoothing":[`antialiased`,`subpixel-antialiased`],"font-style":[`italic`,`not-italic`],"font-weight":[{font:[r,Ep,hp]}],"font-stretch":[{"font-stretch":[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`,rp,J]}],"font-family":[{font:[xp,gp,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":[tp,`none`,Y,mp]}],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:[tp,`from-font`,`auto`,Y,pp]}],"text-decoration-color":[{decoration:I()}],"underline-offset":[{"underline-offset":[tp,`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()}],"tab-size":[{tab:[np,Y,J]}],"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`]},np,Y,J],radial:[``,Y,J],conic:[np,Y,J]},wp,vp]}],"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":[tp,Y,J]}],"outline-w":[{outline:[``,tp,bp,pp]}],"outline-color":[{outline:I()}],shadow:[{shadow:[``,`none`,u,Tp,yp]}],"shadow-color":[{shadow:I()}],"inset-shadow":[{"inset-shadow":[`none`,d,Tp,yp]}],"inset-shadow-color":[{"inset-shadow":I()}],"ring-w":[{ring:H()}],"ring-w-inset":[`ring-inset`],"ring-color":[{ring:I()}],"ring-offset-w":[{"ring-offset":[tp,pp]}],"ring-offset-color":[{"ring-offset":I()}],"inset-ring-w":[{"inset-ring":H()}],"inset-ring-color":[{"inset-ring":I()}],"text-shadow":[{"text-shadow":[`none`,f,Tp,yp]}],"text-shadow-color":[{"text-shadow":I()}],opacity:[{opacity:[tp,Y,J]}],"mix-blend":[{"mix-blend":[...ee(),`plus-darker`,`plus-lighter`]}],"bg-blend":[{"bg-blend":ee()}],"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":[tp]}],"mask-image-linear-from-pos":[{"mask-linear-from":W()}],"mask-image-linear-to-pos":[{"mask-linear-to":W()}],"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":W()}],"mask-image-t-to-pos":[{"mask-t-to":W()}],"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":W()}],"mask-image-r-to-pos":[{"mask-r-to":W()}],"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":W()}],"mask-image-b-to-pos":[{"mask-b-to":W()}],"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":W()}],"mask-image-l-to-pos":[{"mask-l-to":W()}],"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":W()}],"mask-image-x-to-pos":[{"mask-x-to":W()}],"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":W()}],"mask-image-y-to-pos":[{"mask-y-to":W()}],"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":W()}],"mask-image-radial-to-pos":[{"mask-radial-to":W()}],"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":[tp]}],"mask-image-conic-from-pos":[{"mask-conic-from":W()}],"mask-image-conic-to-pos":[{"mask-conic-to":W()}],"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:te()}],brightness:[{brightness:[tp,Y,J]}],contrast:[{contrast:[tp,Y,J]}],"drop-shadow":[{"drop-shadow":[``,`none`,p,Tp,yp]}],"drop-shadow-color":[{"drop-shadow":I()}],grayscale:[{grayscale:[``,tp,Y,J]}],"hue-rotate":[{"hue-rotate":[tp,Y,J]}],invert:[{invert:[``,tp,Y,J]}],saturate:[{saturate:[tp,Y,J]}],sepia:[{sepia:[``,tp,Y,J]}],"backdrop-filter":[{"backdrop-filter":[``,`none`,Y,J]}],"backdrop-blur":[{"backdrop-blur":te()}],"backdrop-brightness":[{"backdrop-brightness":[tp,Y,J]}],"backdrop-contrast":[{"backdrop-contrast":[tp,Y,J]}],"backdrop-grayscale":[{"backdrop-grayscale":[``,tp,Y,J]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[tp,Y,J]}],"backdrop-invert":[{"backdrop-invert":[``,tp,Y,J]}],"backdrop-opacity":[{"backdrop-opacity":[tp,Y,J]}],"backdrop-saturate":[{"backdrop-saturate":[tp,Y,J]}],"backdrop-sepia":[{"backdrop-sepia":[``,tp,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:[tp,`initial`,Y,J]}],ease:[{ease:[`linear`,`initial`,_,Y,J]}],delay:[{delay:[tp,Y,J]}],animate:[{animate:[`none`,v,Y,J]}],backface:[{backface:[`hidden`,`visible`]}],perspective:[{perspective:[h,Y,J]}],"perspective-origin":[{"perspective-origin":x()}],rotate:[{rotate:ne()}],"rotate-x":[{"rotate-x":ne()}],"rotate-y":[{"rotate-y":ne()}],"rotate-z":[{"rotate-z":ne()}],scale:[{scale:G()}],"scale-x":[{"scale-x":G()}],"scale-y":[{"scale-y":G()}],"scale-z":[{"scale-z":G()}],"scale-3d":[`scale-3d`],skew:[{skew:re()}],"skew-x":[{"skew-x":re()}],"skew-y":[{"skew-y":re()}],transform:[{transform:[Y,J,``,`none`,`gpu`,`cpu`]}],"transform-origin":[{origin:x()}],"transform-style":[{transform:[`3d`,`flat`]}],translate:[{translate:ie()}],"translate-x":[{"translate-x":ie()}],"translate-y":[{"translate-y":ie()}],"translate-z":[{"translate-z":ie()}],"translate-none":[`translate-none`],zoom:[{zoom:[np,Y,J]}],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`]}],"scrollbar-thumb-color":[{"scrollbar-thumb":I()}],"scrollbar-track-color":[{"scrollbar-track":I()}],"scrollbar-gutter":[{"scrollbar-gutter":[`auto`,`stable`,`both`]}],"scrollbar-w":[{scrollbar:[`auto`,`thin`,`none`]}],"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:[tp,bp,pp,mp]}],stroke:[{stroke:[`none`,...I()]}],"forced-color-adjust":[{"forced-color-adjust":[`auto`,`none`]}]},conflictingClassGroups:{"container-named":[`container-type`],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`]},postfixLookupClassGroups:[`container-type`],orderSensitiveModifiers:[`*`,`**`,`after`,`backdrop`,`before`,`details-content`,`file`,`first-letter`,`first-line`,`marker`,`placeholder`,`selection`]}});function X(...e){return Lp(df(e))}function Rp({delayDuration:e=0,...t}){return(0,K.jsx)(rf,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function zp({...e}){return(0,K.jsx)(af,{"data-slot":`tooltip`,...e})}function Bp({...e}){return(0,K.jsx)(of,{"data-slot":`tooltip-trigger`,...e})}function Vp({className:e,sideOffset:t=4,children:n,...r}){return(0,K.jsx)(sf,{children:(0,K.jsxs)(cf,{"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,K.jsx)(lf,{className:`fill-gray-900`})]})})}var Z=(e,t)=>fetch(e,{credentials:`include`,...t}),Hp=null;function Up(){return Hp||=Z(`/api/health`).then(e=>e.json()).then(e=>typeof e?.workspace==`string`?e.workspace:`loopat`).catch(()=>`loopat`),Hp}async function Wp(){let e=await Z(`/api/auth/me`);return e.ok?(await e.json()).user??null:null}async function Gp(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 Kp(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 Jp(){let e=await Z(`/api/personal/status`);return e.ok?await e.json():null}async function Yp(){let e=await Z(`/api/onboarding`);return e.ok?await e.json():null}async function Xp(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 Zp(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 Qp(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 $p(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 em(){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 tm(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 nm(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 rm(){await Z(`/api/auth/logout`,{method:`POST`}).catch(()=>{})}async function im(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 am(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 om(){let e=await Z(`/api/profiles`);return e.ok?(await e.json()).profiles??[]:[]}async function sm(){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 cm(e){let t=await Z(`/api/loop-stats?profiles=${encodeURIComponent(e.join(`,`))}`);return t.ok?await t.json():null}async function lm(){let e=await Z(`/api/vaults`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.vaults)?t.vaults:[]}async function um(e){return(await Z(`/api/loops/${e}/viewed`,{method:`POST`})).ok}async function dm(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 fm(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 pm(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 mm(e){let t=await Z(`/api/loops/${e}/request-drive`,{method:`POST`});return t.ok?await t.json():null}async function hm(e){let t=await Z(`/api/loops/${e}/drive`,{method:`POST`});return t.ok?await t.json():null}async function gm(e){let t=await Z(`/api/loops/${e}/distill`,{method:`POST`});return t.ok?await t.json():null}async function _m(e){let t=await Z(`/api/loops/${e}`);return t.ok?await t.json():null}async function vm(e){let t=await Z(`/api/loops/${e}/strip-thinking`,{method:`POST`});return t.ok?await t.json():{stripped:0,sessionsTouched:0}}async function ym(e,t=``){return(await(await Z(`/api/loops/${e}/files?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function bm(e,t=``){return(await(await Z(`/api/loops/${e}/files/tree?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function xm(e,t){let n=await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Sm(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 Cm(e,t){return(await Z(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function wm(e,t){return(await Z(`/api/loops/${e}/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).ok}async function Tm(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 Em(e){let t=await Z(`/api/loops/${e}/context`);return t.ok?(await t.json()).mounts??[]:[]}async function Dm(e,t=``){let n=await Z(`/api/workspace/files?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).entries??[]:[]}async function Om(e){let t=await Z(`/api/workspace/files?vault=${e}&flat=1`);return t.ok?(await t.json()).entries??[]:[]}async function km(e,t){let n=await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function Am(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 jm(){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 Mm(){let e=await(await Z(`/api/notes/behind`)).json().catch(()=>({}));return typeof e.behind==`number`?e.behind:0}async function Nm(){let e=await(await Z(`/api/notes/refresh`,{method:`POST`})).json().catch(()=>({}));return{ok:!!e.ok,diverged:e.diverged,error:e.error}}async function Pm(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 Fm(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 Im(e,t){return await(await Z(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`DELETE`})).json()}async function Lm(e,t){let n=await Z(`/api/workspace/backlinks?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).backlinks??[]:[]}async function Rm(){let e=await Z(`/api/context/repos`);if(!e.ok)return{notes:null,repos:[]};let t=await e.json();return{notes:t.notes??null,repos:t.repos??[]}}async function zm(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}`,savedLocally:n.savedLocally}}async function Bm(e){let t=await Z(`/api/loops/${e}/chat-history`);return t.ok?(await t.json()).map(e=>e.text):[]}async function Vm(e,t){await Z(`/api/loops/${e}/chat-history`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t})})}function Hm(e){return typeof e==`string`?`/api/sync/${e}`:`/api/sync/repos/${encodeURIComponent(e.repo)}`}async function Um(e){let t=await Z(`${Hm(e)}/status`);return t.ok?await t.json():null}async function Wm(e){let t=await Z(`${Hm(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 Gm(e){let t=await Z(`${Hm(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 Km(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 Jm(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/toggle`,{method:`PATCH`})).ok}async function Ym(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 Xm(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 Zm(e,t,n){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`DELETE`})).ok}async function Qm(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 $m(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 eh(){let e=await Z(`/api/kanban/boards`);return e.ok?(await e.json()).boards:[`default`]}async function th(e){return(await Z(`/api/kanban/boards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).ok}async function nh(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 rh(e=`default`){let t=await Z(`/api/kanban/config/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function ih(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 ah(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 oh(e,t){return(await Z(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function sh(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 ch(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 lh(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 uh(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 dh(){let e=await Z(`/api/topics`);return e.ok?(await e.json()).topics:[]}async function fh(){let e=await Z(`/api/providers`);return e.ok?await e.json():{providers:{},default:``}}async function ph(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 mh(){let e=await Z(`/api/version`);return e.ok?await e.json():{branch:`unknown`,commit:`unknown`}}async function hh(){let e=await Z(`/api/admin/system`);return e.ok?await e.json():null}async function gh(){return await(await Z(`/api/admin/system/check`,{method:`POST`})).json()}async function _h(){return await(await Z(`/api/admin/system/pull`,{method:`POST`})).json()}function vh(){return{commit:`988385b40afdcf584e518598dec8114295ed2c79`,time:`2026-06-02T11:07:18.495Z`}}async function yh(e){let t=await Z(`/api/loops/${e}/git-status`);return t.ok?await t.json():{unstaged:[],staged:[]}}async function bh(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 xh(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 Sh(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 Ch(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 wh(e,t=50){let n=await Z(`/api/loops/${e}/git-log?limit=${t}`);return n.ok?(await n.json()).commits??[]:[]}async function Th(){let e=await Z(`/api/settings/personal/disk`);return e.ok?await e.json():null}async function Eh(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 Dh(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 Oh(){return await(await Z(`/api/settings/workspace`)).json()}async function kh(e){return(await Z(`/api/settings/workspace`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Ah(){let e=await Z(`/api/settings/token-usage/daily`);return e.ok?await e.json():{}}async function jh(){let e=await Z(`/api/settings/token-usage/loops`);return e.ok?await e.json():[]}async function Mh(){let e=await Z(`/api/admin/presets`);return e.ok?await e.json():{providerPresets:[],miseToolPresets:[]}}async function Nh(e){return(await Z(`/api/admin/presets`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Ph(){let e=await Z(`/api/admin/users`);return e.ok?(await e.json()).users??[]:[]}async function Fh(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 Ih(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 Lh(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 Rh(){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 zh(e){let t=await Z(`/api/loops/${e}/share/current-port`);return t.ok?await t.json():{port:null}}async function Bh(e){return(await Z(`/api/serve/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Vh(){let e=await Z(`/api/serve/available-port`);return e.ok?await e.json():{port:null,error:`request failed`}}async function Hh(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 Uh(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 Wh(){let e=await Z(`/api/chat/conversations`);return e.ok?(await e.json()).conversations??[]:[]}async function Gh(){let e=await Z(`/api/chat/users`);return e.ok?(await e.json()).users??[]:[]}async function Kh(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 Jh(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 Yh(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 Xh(e){let t=await Z(`/api/chat/threads/${e}`);return t.ok?await t.json():null}async function Zh(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 Qh(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 $h(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 eg(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 tg(){let e=await Z(`/api/a2a`);return e.ok?await e.json():null}async function ng(e){return(await Z(`/api/a2a`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function rg(){let e=await Z(`/api/a2a/key`,{method:`POST`});return e.ok?(await e.json().catch(()=>({}))).token??null:null}async function ig(e){let t=await Z(`/api/mcp-servers${e?`?loopId=${encodeURIComponent(e)}`:``}`);return t.ok?await t.json():{servers:[]}}async function ag(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 og(e){return(await Z(`/api/envs/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}async function sg(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 cg(){let e=await Z(`/api/tiers`);return e.ok?await e.json():null}async function lg(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 ug(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 dg(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 fg(){let e=await Z(`/api/plugins/available`);return e.ok?(await e.json()).plugins??[]:[]}async function pg(){let e=await Z(`/api/plugins/browse`);return e.ok?(await e.json()).plugins??[]:[]}async function mg(){let e=await Z(`/api/marketplaces`);return e.ok?(await e.json()).marketplaces??[]:[]}async function hg(){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 gg(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 _g(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 vg(){let e=await Z(`/api/v1/me/tokens`);return e.ok?(await e.json().catch(()=>({tokens:[]}))).tokens??[]:[]}async function yg(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 bg(e){return(await Z(`/api/v1/me/tokens/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}function xg(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!0),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!0),g=(0,_.useCallback)(async()=>{r(!0),t(await im(i?`all`:`active`)),r(!1)},[i]);(0,_.useEffect)(()=>{let e=!1;return Wp().then(t=>{e||(p(t),h(!1))}),()=>{e=!0}},[]),(0,_.useEffect)(()=>{g()},[i,f]);let v=(0,_.useCallback)(async e=>{let n=await am(e);return t(e=>[n,...e]),n},[]),y=(0,_.useCallback)(async(e,n)=>{let r=await dm(e,n);r&&t(t=>!i&&r.archived?t.filter(t=>t.id!==e):t.map(t=>t.id===e?r:t))},[i]),b=(0,_.useCallback)(async(e,n)=>{let r=await fm(e,n);r&&t(t=>t.map(t=>t.id===e?r:t))},[]),x=(0,_.useCallback)(async(e,n)=>{let r=await pm(e,n);return r?(t(t=>t.map(t=>t.id===e?r:t)),r):null},[]),S=(0,_.useCallback)(async e=>{let n=await mm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),C=(0,_.useCallback)(async e=>{let n=await hm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),w=(0,_.useCallback)(async(e,t)=>{let n=await Gp(e,t);return n.user&&p(n.user),{error:n.error}},[]),T=(0,_.useCallback)(async e=>{let t=await Kp(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,_.useCallback)(async()=>{await rm(),p(null)},[]);return{loops:e,loopsLoading:n,showArchived:i,setShowArchived:a,refresh:g,createLoop:v,setLoopArchived:y,setLoopPublic:b,setLoopTitle:x,requestDrive:S,takeDrive:C,newLoopDialogOpen:o,newLoopDialogTitle:c,kanbanCreateCtx:u,setNewLoopDialogOpen:(0,_.useCallback)((e,t,n)=>{s(e),l(t??``),d(n??null)},[]),currentUser:f,authLoading:m,login:w,register:T,logout:E}}var Sg=(0,_.createContext)(null);function Cg(){let e=(0,_.useContext)(Sg);if(!e)throw Error(`useWorkspace outside provider`);return e}function wg({onClose:e,onCreate:t,initialTitle:n}){let[r,i]=(0,_.useState)(n??``),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(new Set),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(`default`),[p,m]=(0,_.useState)([]),[h,g]=(0,_.useState)([]),[v,y]=(0,_.useState)([]),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(!1),[w,T]=(0,_.useState)(!1),E=(0,_.useRef)(null);(0,_.useEffect)(()=>{Rm().then(e=>m(e.repos)),Promise.all([om(),sm()]).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`)))}),lm().then(e=>{y(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,_.useEffect)(()=>{C(!0);let e=setTimeout(()=>{cm([...s]).then(x).finally(()=>C(!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,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:e,children:(0,K.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,K.jsx)(`div`,{className:`text-base font-semibold text-gray-900 mb-4`,children:`New loop`}),(0,K.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),!w){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,K.jsxs)(Tg,{label:`Repo`,hint:`Sets the workdir. Optional — leave (none) for an empty workdir.`,children:[(0,K.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,K.jsx)(`option`,{value:``,children:`(none — empty workdir)`}),p.map(e=>(0,K.jsxs)(`option`,{value:e.name,children:[e.name,e.git?` · ${e.git}`:``]},e.name))]}),p.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`No repos in the roster. Add them on the Context → Repos page.`})]}),(0,K.jsxs)(Tg,{label:`Profiles`,hint:`Each profile contributes plugins + a CLAUDE.md fragment. Empty = base + personal only.`,children:[(0,K.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,K.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,K.jsx)(`input`,{type:`checkbox`,checked:!0,disabled:!0,className:`mt-0.5`}),(0,K.jsxs)(`span`,{className:`flex-1`,children:[(0,K.jsx)(`span`,{className:`font-medium`,children:`base`}),(0,K.jsx)(`span`,{className:`ml-1 text-[11px] text-gray-400`,children:`(always on)`}),k.description&&(0,K.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,K.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,K.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>j(e.name),className:`mt-0.5`}),(0,K.jsxs)(`span`,{className:`flex-1`,children:[(0,K.jsx)(`span`,{className:`font-medium text-gray-900`,children:e.name}),n&&(0,K.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,K.jsx)(`span`,{className:`block text-[11px] text-gray-500 mt-0.5`,children:e.description})]})]},e.name)}),A.length===0&&!k&&(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-400 p-1.5`,children:[`No profiles yet. Add them under`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`knowledge/.loopat/profiles/<name>/.claude/`}),` `,`in your knowledge repo.`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between mt-1`,children:[(0,K.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,K.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,K.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:S&&!b?(0,K.jsx)(`span`,{className:`text-gray-400`,children:`computing…`}):b?(0,K.jsxs)(`span`,{title:`Totals across team + selected profiles + their plugins (deduped by name)`,children:[(0,K.jsxs)(`span`,{className:b.plugins>0?``:`text-gray-400`,children:[b.plugins,` plugins`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.skills>0?``:`text-gray-400`,children:[b.skills,` skills`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.agents>0?``:`text-gray-400`,children:[b.agents,` agents`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.hooks>0?``:`text-gray-400`,children:[b.hooks,` hooks`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.mcpServers>0?``:`text-gray-400`,children:[b.mcpServers,` MCP servers`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:b.toolchain>0?``:`text-gray-400`,title:`mise.toml [tools] entries, deduped across team + selected profiles`,children:[b.toolchain,` toolchain`]}),S&&(0,K.jsx)(`span`,{className:`ml-1.5 text-gray-400`,children:`·`}),S&&(0,K.jsx)(`span`,{className:`ml-1 text-gray-400`,children:`updating…`})]}):(0,K.jsx)(`span`,{className:`text-gray-400`,children:`—`})})]}),(0,K.jsxs)(Tg,{label:`Vault`,hint:`Which credential set to inject. Only this vault is visible inside the loop.`,children:[(0,K.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:[v.length===0&&(0,K.jsx)(`option`,{value:`default`,children:`default`}),v.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),v.length===0&&(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:[`No vaults yet — using default. Create more under`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`personal/.loopat/vaults/<name>/`}),` `,`to isolate prod / test credentials.`]})]}),(0,K.jsx)(Tg,{label:`Name`,hint:`Optional — defaults to 'untitled'.`,children:(0,K.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,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-2 pt-3 border-t border-gray-100`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:e,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,K.jsx)(`button`,{type:`submit`,disabled:w,className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:w?`creating…`:`create`})]})]})]})})}function Tg({label:e,hint:t,children:n}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var Eg=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,Dg=df,Og=((e,t)=>n=>{if(t?.variants==null)return Dg(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=Eg(t)||Eg(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 Dg(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 kg({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,K.jsx)(r?Mi:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:X(Og({variant:t,size:n,className:e})),...i})}function Ag({...e}){return(0,K.jsx)(tc,{"data-slot":`dialog`,...e})}function jg({...e}){return(0,K.jsx)(nc,{"data-slot":`dialog-portal`,...e})}function Mg({className:e,...t}){return(0,K.jsx)(rc,{"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 Ng({className:e,children:t,showCloseButton:n=!0,...r}){return(0,K.jsxs)(jg,{"data-slot":`dialog-portal`,children:[(0,K.jsx)(Mg,{}),(0,K.jsxs)(ic,{"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,K.jsxs)(sc,{"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,K.jsx)(lt,{}),(0,K.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function Pg({className:e,...t}){return(0,K.jsx)(`div`,{"data-slot":`dialog-header`,className:X(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function Fg({className:e,...t}){return(0,K.jsx)(ac,{"data-slot":`dialog-title`,className:X(`text-lg leading-none font-semibold`,e),...t})}function Ig({className:e,...t}){return(0,K.jsx)(oc,{"data-slot":`dialog-description`,className:X(`text-sm text-muted-foreground`,e),...t})}function Lg({open:e,onClose:t}){let[n,r]=(0,_.useState)({branch:`…`,commit:`…`}),i=vh();return(0,_.useEffect)(()=>{e&&mh().then(e=>r(e))},[e]),(0,K.jsx)(Ag,{open:e,onOpenChange:e=>!e&&t(),children:(0,K.jsxs)(Ng,{className:`sm:max-w-sm bg-white`,children:[(0,K.jsx)(Pg,{children:(0,K.jsxs)(Fg,{className:`text-center`,children:[(0,K.jsx)(`img`,{src:`/logo.png`,alt:`loopat`,className:`w-full max-w-[240px] mx-auto mb-2`}),`loopat`]})}),(0,K.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,K.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,K.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Server`}),(0,K.jsxs)(`div`,{className:`font-mono text-gray-700`,children:[n.branch,`@`,n.commit.slice(0,7)]})]}),(0,K.jsxs)(`div`,{className:`bg-gray-50 rounded-lg p-3`,children:[(0,K.jsx)(`div`,{className:`text-gray-400 text-xs mb-1`,children:`Build`}),(0,K.jsx)(`div`,{className:`font-mono text-gray-700`,children:i.commit.slice(0,7)}),(0,K.jsx)(`div`,{className:`font-mono text-gray-400 text-xs mt-0.5`,children:new Date(i.time).toLocaleString()})]})]})]})})}function Rg(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 Bg(e){let t=e=>({type:t,props:e});return t[zg]=e,t}function Vg(e,t){return{...t,key:e}}var Hg=typeof process<`u`&&!1,Ug=null;function Wg(e,t){e.currentIndex=0;let n=Ug;Ug=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{Ug=n}}function Gg(){if(!Ug)throw Error(`No resource fiber available`);return Ug}function Kg(e){return Hg?Ug?.devStrictMode?Ug.isFirstRender?`child`:`root`:e?`root`:null:null}var qg=e=>({version:0,committedVersion:0,dispatchUpdate:e,changelog:[],dirtyCells:[]}),Jg=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},Yg=(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()),Jg(e)}}},Xg=(e,t)=>{t.dirty||(t.dirty=!0,e.markDirty?.(),e.root.dirtyCells.push(t))},Zg=(e,t)=>{let n=Gg(),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},Qg=e=>{Gg().renderContext.effectTasks.push(e)},$g=(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 e_(e,t,n,r){let i=Zg(`reducer`,()=>{let t=Gg(),a=r?r(n):n;return Hg&&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};$g(t,()=>t.root.dirtyCells.length===0&&!r.hasEagerState&&(r.eagerState=e(i.workInProgress,n),r.hasEagerState=!0,Object.is(i.current,r.eagerState))?null:()=>{Xg(t,i),i.queue.add(r)})}}}),a=Gg(),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),Hg&&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)||(Xg(a,i),i.workInProgress=e)}return[i.workInProgress,i.dispatch]}function t_(e,t,n){return e_(e,void 0,t,n)}function n_(e,t,n,r){return e_(e,t,n,r)}var r_=(e,t)=>typeof t==`function`?t(e):t,i_=e=>typeof e==`function`?e():e;function a_(e){return t_(r_,e,i_)}var o_=(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},s_=()=>({type:`effect`,cleanup:void 0,deps:null});function c_(e,t){let n=Zg(`effect`,s_);if(!(t&&n.deps&&o_(n.deps,t))){if(n.deps!==null&&!!t!=!!n.deps)throw Error(`tapEffect called with and without dependencies across re-renders`);Qg(()=>{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 l_(e){let[t]=a_(()=>({current:e}));return t}function u_(e,t){let[n]=a_(e);return n}var d_=()=>{throw Error(`Memo reducer should not be called`)},f_=(e,t)=>{let n=Gg(),[r]=n_(d_,r=>{if(r&&o_(r.deps,t))return r;let i=e();return Hg&&n.devStrictMode&&e(),{value:i,deps:t}},null);return r.value},p_=(e,t)=>f_(()=>e,t);function m_(e){let t=l_(e);c_(()=>{t.current=e});let n=Gg();return p_(((...e)=>{if(Hg&&n.renderContext)throw Error(`tapEffectEvent cannot be called during render`);return t.current(...e)}),[n])}function h_(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 g_(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`)}}function __(e,t,n=void 0,r=Kg(!1)){return{type:e,root:t,markDirty:n,devStrictMode:r,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function v_(e){if(!e.isMounted)throw Error(`Tried to unmount a fiber that is already unmounted`);e.isMounted=!1,g_(e)}function y_(e,t){let n={effectTasks:[],props:t,output:void 0};return Wg(e,()=>{e.renderContext=n;try{n.output=Rg(e.type,t)}finally{e.renderContext=void 0}}),n}function b_(e,t){e.isMounted=!0,Hg&&e.isNeverMounted&&e.devStrictMode===`root`&&(e.isNeverMounted=!1,h_(t),g_(e)),e.isNeverMounted=!1,h_(t)}function x_(e,t){let n=Gg(),r=l_(0),i=f_(()=>(e.key,__(e.type,n.root,()=>{r.current++,n.markDirty?.()})),[e.type,e.key,n]),a=t?f_(()=>y_(i,e.props),[i,...t,r.current]):y_(i,e.props);return c_(()=>()=>v_(i),[i]),c_(()=>{b_(i,a)},[i,a]),a.output}function S_(e,t){let n=l_(0),r=n.current,i=u_(Gg,[]),a=u_(()=>()=>{n.current++,i.markDirty?.()},[]),o=u_(()=>new Map,[]),s=t?p_(e,t):e,c=f_(()=>{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=__(c.type,i.root,a),t=y_(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=__(c.type,i.root,a),t=y_(e,c.props);u.next=[e,t],n.push(t.output)}else u.next=y_(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 c_(()=>()=>{for(let e of o.keys()){let t=o.get(e).fiber;v_(t)}},[]),c_(()=>{for(let[e,t]of o.entries())t.next===`delete`?(t.fiber.isMounted&&v_(t.fiber),o.delete(e)):Array.isArray(t.next)?(v_(t.fiber),t.fiber=t.next[0],b_(t.fiber,t.next[1])):b_(t.fiber,t.next)},[c]),c}var C_=50,w_={schedulers:new Set([]),isScheduled:!1},T_=class{_task;_isDirty=!1;constructor(e){this._task=e}get isDirty(){return this._isDirty}markDirty(){this._isDirty=!0,w_.schedulers.add(this),E_()}runTask(){this._isDirty=!1,this._task()}},E_=()=>{w_.isScheduled||(w_.isScheduled=!0,O_())},D_=()=>{try{let e=[],t=0;for(let n of w_.schedulers)if(w_.schedulers.delete(n),n.isDirty){if(t++,t>C_)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{w_.schedulers.clear(),w_.isScheduled=!1}},O_=(()=>{if(typeof MessageChannel<`u`){let e=new MessageChannel;return e.port1.onmessage=D_,()=>e.port2.postMessage(null)}return()=>setTimeout(D_,0)})(),k_=e=>{let t=w_;w_={schedulers:new Set([]),isScheduled:!0};try{let t=e();return D_(),t}finally{w_=t}},A_=e=>{let t=u_(()=>new T_(()=>l(null)),[]),n=u_(()=>[],[]),r=f_(()=>(e.key,__(e.type,qg(e=>{!t.isDirty&&!e()||(n.push(e),t.markDirty())}))),[e.type,e.key]);Yg(r.root,r.root.committedVersion);let i=y_(r,e.props),a=l_(!1),o=l_(e.props),s=l_(i.output),c=u_(()=>new Set,[]),l=m_(e=>{if(e===null&&(Yg(r.root,2),Yg(r.root,1),n.forEach(e=>{Hg&&r.devStrictMode&&e(),e()}),Hg&&r.devStrictMode&&y_(r,o.current),e=y_(r,o.current)),t.isDirty)throw Error(`Scheduler is dirty, this should never happen`);Jg(r.root),n.length=0,a.current&&b_(r,e),!(t.isDirty||s.current===e.output)&&(s.current=e.output,c.forEach(e=>e()))});return c_(()=>(a.current=!0,()=>{a.current=!1,v_(r)}),[r]),c_(()=>{o.current=i.props,Jg(r.root),b_(r,i),!(t.isDirty||s.current===i.output)&&(s.current=i.output,c.forEach(e=>e()))}),f_(()=>({getValue:()=>s.current,subscribe:e=>(c.add(e),()=>c.delete(e))}),[])},j_=Symbol(`tap.Context`),M_=e=>({[j_]:e}),N_=(e,t,n)=>{let r=e[j_];e[j_]=t;try{return n()}finally{e[j_]=r}},P_=e=>e[j_],F_=Bg(()=>{let[e,t]=a_(()=>({renderers:{},fallbacks:[]}));return{getState:()=>e,setDataUI:p_((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:p_(e=>(t(t=>({...t,fallbacks:[...t.fallbacks,e]})),()=>{t(t=>({...t,fallbacks:t.fallbacks.filter(t=>t!==e)}))}),[])}}),I_=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},{}),L_=class{_providers=new Set;getModelContext(){return I_(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)}},R_=[],z_={modelName:void 0,toolNames:R_},B_=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]),V_=(e,t)=>{let n=e.getModelContext(),r=n.config?.modelName,i=n.tools?Object.keys(n.tools).sort():R_,a=i.length?i:R_;return r===t.modelName&&B_(a,t.toolNames)?t:{modelName:r,toolNames:a}},H_=Bg(()=>{let e=f_(()=>new L_,[]),[t,n]=a_(()=>V_(e,z_));return c_(()=>(n(t=>V_(e,t)),e.subscribe(()=>{n(t=>V_(e,t))})),[e]),{getState:()=>V_(e,t),getModelContext:()=>e.getModelContext(),subscribe:t=>e.subscribe(t),register:t=>e.registerModelContextProvider(t)}}),U_=e=>e.display===void 0?e.type===`human`:e.display===`standalone`,W_=Symbol(`assistant-ui.store.clientIndex`),G_=e=>e[W_],K_=M_([]),q_=()=>P_(K_),J_=(e,t)=>{let n=q_();return N_(K_,f_(()=>[...n,e],[n,e]),t)},Y_=new Set([`$$typeof`,`nodeType`,`then`]),X_=(e,t)=>{if(e===Symbol.toStringTag)return t;if(typeof e!=`symbol`){if(e===`toJSON`)return()=>t;if(!Y_.has(e))return!1}},Z_=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}},Q_=e=>{let t=Bg(e);return e=>{let n=t(e);return e.key===void 0?n:Vg(e.key,n)}},$_=Symbol(`assistant-ui.store.getValue`),ev=e=>{let t=e[$_];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?.()},tv=new Map;function nv(e){let t=tv.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[$_];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)},tv.set(e,t)),t}var rv=class extends Z_{outputRef;index;boundFns;cachedReceiver;constructor(e,t){super(),this.outputRef=e,this.index=t}get(e,t,n){if(t===$_)return this.outputRef.current;if(t===W_)return this.index;let r=X_(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=nv(t).bind(n),this.boundFns.set(t,e)),e}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,t){return t===$_||t===W_?!0:t in this.outputRef.current}},iv=Q_(e=>{let t=l_(null),n=q_().length,r=f_(()=>new Proxy({},new rv(t,n)),[n]),i=J_(r,()=>x_(e));return t.current||=i,c_(()=>{t.current=i}),{methods:r,state:i.getState?.(),key:e.key}}),av=e=>x_(iv(e)),ov=Symbol(`assistant-ui.store.proxiedAssistantState`),sv=e=>e===`on`||e===`subscribe`||typeof e==`symbol`,cv=e=>{class t extends Z_{get(t,n){let r=X_(n,`AssistantState`);if(r!==!1)return r;let i=n;if(!sv(i))return ev(e[i]())}ownKeys(){return Object.keys(e).filter(e=>!sv(e))}has(t,n){return!sv(n)&&n in e}}return new Proxy({},new t)},lv=e=>e[ov],uv=()=>()=>{},dv=e=>{let t=(()=>{throw Error(e)});return t.source=null,t.query=null,t},fv=new Proxy({},new class extends Z_{get(e,t){if(t===`subscribe`||t===`on`)return uv;if(t===ov)return pv;let n=X_(t,`DefaultAssistantClient`);return n===!1?dv(`You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.`):n}ownKeys(){return[`subscribe`,`on`,ov]}has(e,t){return t===`subscribe`||t===`on`||t===ov}}),pv=cv(fv),mv=()=>new Proxy({},{get(e,t){let n=X_(t,`AssistantClient`);return n===!1?dv(`The current scope does not have a "${String(t)}" property.`):n}}),hv=(0,_.createContext)(fv),gv=()=>(0,_.useContext)(hv),_v=({value:e,children:t})=>(0,K.jsx)(hv.Provider,{value:e,children:t}),vv=Bg(e=>null),yv=Symbol(`assistant-ui.transform-scopes`);function bv(e,t){let n=e;if(n[yv])throw Error(`transformScopes is already attached to this resource`);n[yv]=t}function xv(e){return e[yv]}var Sv=e=>typeof e==`string`?{scope:e.split(`.`)[0],event:e}:{scope:e.scope,event:e.event},Cv=M_(null),wv=(e,t)=>N_(Cv,e,t),Tv=()=>{let e=P_(Cv);if(!e)throw Error(`AssistantTapContext is not available`);return e},Ev=()=>Tv().clientRef,Dv=()=>{let{emit:e}=Tv(),t=q_();return m_((n,r)=>{e(n,r,t)})};function Ov(e,t){let n={...e},r=new Set,i=!0;for(;i;){i=!1;for(let e of Object.values(n)){if(e.type===vv||r.has(e.type))continue;r.add(e.type);let a=xv(e.type);if(a){a(n,t),i=!0;break}}}let a={},o={};for(let[e,t]of Object.entries(n))t.type===vv?o[e]=t:a[e]=t;return{rootClients:a,derivedClients:o}}var kv=e=>f_(()=>e,[...Object.entries(e).flat()]),Av=(e,t)=>{let{rootClients:n,derivedClients:r}=Ov(e,t);return{rootClients:kv(n),derivedClients:kv(r)}},jv=Bg(()=>u_(()=>{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)}}}},[])),Mv=()=>{if(!Hg)return null;let e=(0,_.useRef)(0),t=e.current===0;return(0,_.useState)(()=>e.current++),e.current===2?t?`child`:`root`:null};function Nv(e){let t=(0,_.useMemo)(()=>qg(e=>r(e)),[]),[n,r]=(0,_.useReducer)((e,n)=>(Yg(t,e),e+ +!!n()),0);Yg(t,n);let i=Mv(),a=(0,_.useMemo)(()=>(e.key,__(e.type,t,void 0,i)),[e.type,e.key,t,i]),o=y_(a,e.props);return(0,_.useLayoutEffect)(()=>()=>v_(a),[a]),(0,_.useLayoutEffect)(()=>{Jg(t),b_(a,o)}),o.output}var Pv=e=>f_(()=>e,e),Fv=Bg(({element:e,emit:t,clientRef:n})=>{let{methods:r,state:i}=wv({clientRef:n,emit:t},()=>av(e));return f_(()=>({state:i,methods:r}),[r,i])}),Iv=Bg(({element:e,notifications:t,clientRef:n,name:r})=>{let i=A_(Fv({element:e,emit:t.emit,clientRef:n}));return c_(()=>i.subscribe(t.notifySubscribers),[i,t]),f_(()=>{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])}),Lv=Bg(()=>f_(()=>({clients:[],subscribe:void 0,on:void 0}),[])),Rv=Bg(({clients:e,clientRef:t})=>{let n=x_(jv());c_(()=>t.parent.subscribe(n.notifySubscribers),[t,n]);let r=Pv(S_(()=>Object.keys(e).map(r=>Vg(r,Iv({element:e[r],notifications:n,clientRef:t,name:r}))),[e,n,t]));return f_(()=>({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}=Sv(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[G_(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])}),zv=Bg(({element:e,clientRef:t,name:n})=>{let r=l_(e.props);return r.current=e.props,f_(()=>{let e=()=>r.current.get(t.current);return Object.defineProperties(e,{source:{value:r.current.source},query:{value:r.current.query},name:{value:n,configurable:!0}}),e},[t,n])}),Bv=(e,t)=>{let n;try{let e={};for(let n of Object.keys(t.query).sort())e[n]=t.query[n];n=JSON.stringify(e)}catch{n=String(t.query)}return`${e}::${t.source}::${n}`},Vv=Bg(({clients:e,clientRef:t})=>Pv(S_(()=>Object.keys(e).map(n=>{let r=n,i=e[r];return Vg(Bv(r,i.props),zv({element:i,clientRef:t,name:r}))}),[e,t]))),Hv=Bg(({parent:e,clients:t})=>{let{rootClients:n,derivedClients:r}=Av(t,e),i=l_({parent:e,current:null}).current;c_(()=>{i.current=s});let a=x_(Object.keys(n).length>0?Rv({clients:n,clientRef:i}):Lv()),o=x_(Vv({clients:r,clientRef:i})),s=f_(()=>{let t=e===fv?mv():e,n=Object.create(t);Object.assign(n,{subscribe:a.subscribe??e.subscribe,on:a.on??e.on,[ov]:cv(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 Uv(e,{parent:t}={parent:gv()}){if(e)return Nv(Hv({parent:t??fv,clients:e}));if(t===null)throw Error(`received null parent, this usage is not allowed`);return t}var Q=e=>{let t=Uv(),n=lv(t),r=(0,_.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,_.useDebugValue)(r),r},Wv=({children:e,condition:t})=>Q(t)?e:null;Wv.displayName=`AuiIf`;var Gv=e=>{let t=Uv(),n=(0,_.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,_.useMemo)(()=>t,[n,r,typeof t?.props==`object`&&t.props!=null&&Object.entries(t.props).length===0?Kv:t?.props])??e},Yv=_.createContext(!0);function Xv(){throw Error(`A function wrapped in useEffectEvent can't be called during rendering.`)}var Zv=`use`in _.default?()=>{try{return _.use(Yv)}catch{return!1}}:()=>!1;function Qv(e){let t=_.useRef(Xv);return _.useInsertionEffect(()=>{t.current=e},[e]),(...e)=>{Zv()&&Xv();let n=t.current;return n(...e)}}var $v=(e,t)=>{let n=Uv(),r=Qv(t),{scope:i,event:a}=Sv(e);(0,_.useEffect)(()=>n.on({scope:i,event:a},r),[n,i,a])},ey=Q_(e=>{if(e.key===void 0)throw Error(`tapClientResource: Element has no key`);return x_(iv(e))});function ty(e,t){let n=S_(()=>e().map(e=>ey(e)),t),r=f_(()=>Object.keys(n),[n]),i=f_(()=>n.reduce((e,t,n)=>(e[t.key]=n,e),{}),[n]);return{state:f_(()=>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 ny=Bg(({toolkit:e,mcpApp:t})=>{let n=S_(()=>t?[Vg(`mcpApp`,t)]:[],[t])[0],[r,i]=a_(()=>({})),a=f_(()=>({toolUIs:r,mcpApp:n,tools:Object.fromEntries(Object.entries(r).map(([e,t])=>[e,t.map(e=>e.render)]))}),[r,n]),o=Ev(),s=p_((e,t,n)=>{let r={render:t,standalone:n?.standalone??!1};return i(t=>({...t,[e]:[...t[e]??[],r]})),()=>{i(t=>{let n=t[e]?.filter(e=>e!==r)??[];if(n.length>0)return{...t,[e]:n};let{[e]:i,...a}=t;return a})}},[]);return c_(()=>{if(!e)return;let t=[];for(let[n,r]of Object.entries(e))r.render&&t.push(s(n,r.render,{standalone:U_(r)}));let n=Object.entries(e).reduce((e,[t,n])=>{let{render:r,display:i,...a}=n;return e[t]=a,e},{});return t.push(o.current.modelContext().register({getModelContext:()=>({tools:n})})),()=>{t.forEach(e=>e())}},[e,s,o]),{getState:()=>a,setToolUI:s}});bv(ny,(e,t)=>{!e.modelContext&&t.modelContext.source===null&&(e.modelContext=H_())});var ry=e=>{let[,t]=a_(e.getState);return c_(()=>(t(e.getState()),e.subscribe(()=>{t(e.getState())})),[e]),e.getState()},iy=Bg(({runtime:e})=>{let t=ry(e);return{getState:()=>t,remove:e.remove,__internal_getRuntime:()=>e}}),ay=Bg(({runtime:e,index:t})=>x_(iy({runtime:f_(()=>e.getAttachmentByIndex(t),[e,t])}))),oy=Bg(({threadIdRef:e,messageIdRef:t,runtime:n})=>{let r=ry(n),i=Dv();c_(()=>{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=ty(()=>r.attachments.map((e,t)=>Vg(e.id,ay({runtime:n,index:t}))),[r.attachments,n]),o=f_(()=>({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}}),sy=Bg(({runtime:e})=>{let t=ry(e);return{getState:()=>t,addToolResult:t=>e.addToolResult(t),resumeToolCall:t=>e.resumeToolCall(t),respondToToolApproval:t=>e.respondToToolApproval(t),__internal_getRuntime:()=>e}}),cy=Bg(({runtime:e,index:t})=>x_(iy({runtime:f_(()=>e.getAttachmentByIndex(t),[e,t])}))),ly=Bg(({runtime:e,index:t})=>x_(sy({runtime:f_(()=>e.getMessagePartByIndex(t),[e,t])}))),uy=Bg(({runtime:e,threadIdRef:t})=>{let n=ry(e),[r,i]=a_(!1),[a,o]=a_(!1),s=f_(()=>({get current(){return e.getState().id}}),[e]),c=av(oy({runtime:e.composer,threadIdRef:t,messageIdRef:s})),l=ty(()=>n.content.map((t,n)=>Vg(`toolCallId`in t&&t.toolCallId!=null?`toolCallId-${t.toolCallId}`:`index-${n}`,ly({runtime:e,index:n}))),[n.content,e]),u=ty(()=>(n.attachments??[]).map((t,n)=>Vg(t.id,cy({runtime:e,index:n}))),[n.attachments,e]),d=f_(()=>({...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}}),dy=Bg(({runtime:e,id:t,threadIdRef:n})=>x_(uy({runtime:f_(()=>e.getMessageById(t),[e,t]),threadIdRef:n}))),fy=Bg(({runtime:e})=>{let t=ry(e),n=Dv();c_(()=>{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=f_(()=>({get current(){return e.getState().threadId}}),[e]),i=av(oy({runtime:e.composer,threadIdRef:r})),a=ty(()=>t.messages.map(t=>Vg(t.id,dy({runtime:e,id:t.id,threadIdRef:r}))),[t.messages,e,r]),o=f_(()=>({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}}),py=Bg(({runtime:e})=>{let t=ry(e),n=Dv();return c_(()=>{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}}),my=Bg(({runtime:e,id:t})=>x_(py({runtime:f_(()=>e.getItemById(t),[e,t])}))),hy=Bg(({runtime:e,__internal_assistantRuntime:t})=>{let n=ry(e),r=av(fy({runtime:e.main})),i=ty(()=>Object.keys(n.threadItems).map(t=>Vg(t,my({runtime:e,id:t}))),[n.threadItems,e]),a=f_(()=>({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,n)=>{await e.switchToThread(t,n)},switchToNewThread:async()=>{await e.switchToNewThread()},getLoadThreadsPromise:()=>e.getLoadThreadsPromise(),reload:()=>e.reload(),loadMore:()=>e.loadMore(),__internal_getAssistantRuntime:()=>t}}),gy=Bg(e=>({getState:()=>e})),_y=Bg(e=>{let[t]=a_(()=>({suggestions:(e??[]).map(e=>typeof e==`string`?{title:e,label:``,prompt:e}:{title:e.title,label:e.label,prompt:e.prompt})})),n=ty(()=>t.suggestions.map((e,t)=>Vg(t,gy(e))),[t.suggestions]);return{getState:()=>t,suggestion:({index:e})=>n.get({index:e})}}),vy=Bg(e=>{let t=Ev();return c_(()=>e.registerModelContextProvider(t.current.modelContext()),[e,t]),x_(hy({runtime:e.threads,__internal_assistantRuntime:e}))}),yy=(e,t)=>{e.thread??=vv({source:`threads`,query:{type:`main`},get:e=>e.threads().thread(`main`)}),e.threadListItem??=vv({source:`threads`,query:{type:`main`},get:e=>e.threads().item(`main`)}),e.composer??=vv({source:`thread`,query:{},get:e=>e.threads().thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=H_()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=_y())},by=Bg(e=>x_(vy(e)));bv(by,(e,t)=>{yy(e,t),!e.tools&&t.tools.source===null&&(e.tools=ny({})),!e.dataRenderers&&t.dataRenderers.source===null&&(e.dataRenderers=F_())});var xy=e=>e._core?.RenderComponent,Sy=(0,_.memo)(({runtime:e,aui:t=null,children:n})=>{let r=Uv({threads:by(e)},{parent:t}),i=xy(e);return(0,K.jsxs)(_v,{value:r,children:[i&&(0,K.jsx)(i,{}),n]})}),Cy=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},wy=(e=>e?Cy(e):Cy),Ty=e=>e;function Ey(e,t=Ty){let n=_.useSyncExternalStore(e.subscribe,_.useCallback(()=>t(e.getState()),[e,t]),_.useCallback(()=>t(e.getInitialState()),[e,t]));return _.useDebugValue(n),n}var Dy=e=>{let t=wy(e),n=e=>Ey(t,e);return Object.assign(n,t),n},Oy=(e=>e?Dy(e):Dy),ky=()=>{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}},Ay=()=>{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=ky(),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()}}))}}},jy=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())}},My=e=>new ReadableStream({start(t){return e.start?.(new jy(t))},pull(t){return e.pull?.(new jy(t))},cancel(t){return e.cancel?.(t)}}),Ny=()=>{let e;return[My({start(t){e=t}}),e]},Py=class{_controller;_isClosed=!1;_mergeTask;constructor(e){this._controller=e;let t=My({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())}},Fy=e=>new ReadableStream({start(t){return e.start?.(new Py(t))},pull(t){return e.pull?.(new Py(t))},cancel(t){return e.cancel?.(t)}}),Iy=()=>{let e;return[Fy({start(t){e=t}}),e]},Ly=class{value=-1;up(){return++this.value}},Ry=class extends TransformStream{constructor(e){super({transform(t,n){n.enqueue({...t,path:[e,...t.path]})}})}};TransformStream;var zy=class extends TransformStream{constructor(e){let t=new Ly,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]})}})}},By=class extends TransformStream{constructor(e){super();let t=e(super.readable);Object.defineProperty(this,"readable",{value:t,writable:!1})}},Vy=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)}})}},Hy=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},Uy=Hy(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),Wy=class e{_state;_parentId;constructor(e){this._state=e||{merger:Ay(),contentCounter:new Ly}}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 Ry(this._state.contentCounter.value)))}merge(e){this._state.merger.addStream(e.pipeThrough(new zy(this._state.contentCounter)))}appendText(e){(this._state.append?.kind!==`text`||this._state.append.parentId!==this._parentId)&&(this._state.append={kind:`text`,parentId:this._parentId,controller:this.addTextPart()}),this._state.append.controller.append(e)}appendReasoning(e){(this._state.append?.kind!==`reasoning`||this._state.append.parentId!==this._parentId)&&(this._state.append={kind:`reasoning`,parentId:this._parentId,controller:this.addReasoningPart()}),this._state.append.controller.append(e)}addTextPart(){let[e,t]=Ny();return this._addPart(this._withParentIdOption({type:`text`}),e),t}addReasoningPart(){let[e,t]=Ny();return this._addPart(this._withParentIdOption({type:`reasoning`}),e),t}addToolCallPart(e){let t=typeof e==`string`?{toolName:e}:e,n=t.toolName,r=t.toolCallId??Uy(),[i,a]=Iy();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 Gy(e){let t=new Wy;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 Ky(){let{resolve:e,promise:t}=ky(),n;return[Gy(r=>(n=r,n.__internal_subscribeToClose(e),t)),n]}function qy(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 Jy=n(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}))(),1),Yy=Symbol(`aui.parse-partial-json-object.meta`),Xy=e=>e?.[Yy],Zy=e=>{if(e.length===0)return{[Yy]:{state:`partial`,partialPath:[]}};try{let t=Jy.default.parse(e);if(typeof t!=`object`||!t)throw Error(`argsText is expected to be an object`);return t[Yy]={state:`complete`,partialPath:[]},t}catch{try{let[t,n]=qy(e),r=Jy.default.parse(t);if(typeof r!=`object`||!r)throw Error(`argsText is expected to be an object`);return r[Yy]={state:`partial`,partialPath:n},r}catch{return}}},Qy=(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 Qy(s,{state:`partial`,partialPath:o},i)},$y=(e,t)=>{let n=Xy(e);if(!n)throw Error(`unable to determine object state`);return Qy(e,n,t.map(String))};async function*eb(){let e=this.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)break;yield n}}finally{e.releaseLock()}}function tb(e){return e[Symbol.asyncIterator]??=eb,e}var nb=Symbol.for(`aui.tool-response`),rb=class e{get[nb](){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&&nb in e}static toResponse(t){return t instanceof e?t:new e({result:t===void 0?`<no result>`:t})}};function ib(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 ab(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}var ob=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($y(e,this.fieldPath)===`complete`){let t=ab(e,this.fieldPath);t!==void 0&&(this.resolve(t),this.dispose())}}catch(e){this.reject(e),this.dispose()}}dispose(){this.disposed=!0}},sb=class{controller;disposed=!1;fieldPath;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=ab(e,this.fieldPath);t!==void 0&&this.controller.enqueue(t),$y(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},cb=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=ab(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)}$y(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},lb=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=ab(e,this.fieldPath);if(!Array.isArray(t))return;for(let n=0;n<t.length;n++)this.processedIndexes.has(n)||$y(e,[...this.fieldPath,n])===`complete`&&(this.controller.enqueue(t[n]),this.processedIndexes.add(n));$y(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},ub=class{argTextDeltas;handles=new Set;args=Zy(``);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=Zy(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 ob(t,n,e);if(this.args&&$y(this.args,e)===`complete`){let n=ab(this.args,e);if(n!==void 0){t(n);return}}this.handles.add(r),r.update(this.args)})}streamValues(...e){let t=e;return tb(new ReadableStream({start:e=>{let n=new sb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof sb){e.dispose(),this.handles.delete(e);break}}}))}streamText(...e){let t=e;return tb(new ReadableStream({start:e=>{let n=new cb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof cb){e.dispose(),this.handles.delete(e);break}}}))}forEach(...e){let t=e;return tb(new ReadableStream({start:e=>{let n=new lb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof lb){e.dispose(),this.handles.delete(e);break}}}))}},db=class{promise;constructor(e){this.promise=e}get(){return this.promise}},fb=class{args;response;writable;resolve;argsText=``;constructor(){let e=new TransformStream;this.writable=e.writable,this.args=new ub(e.readable);let{promise:t,resolve:n}=ky();this.resolve=n,this.response=new db(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}},pb=class extends By{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 fb;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 rb({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=ib(()=>{let t;try{t=Jy.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 rb({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 rb({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 Vy).pipeThrough(i)})}},mb=e=>typeof e==`object`&&!!e&&`~standard`in e&&e[`~standard`].version===1;function hb(e,t,n,r){let i=e?.[n.toolName];return i?.execute?(async e=>{if(t.aborted)return new rb({result:`Tool execution was cancelled.`,isError:!0});let a=e;if(mb(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 rb({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=rb.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 rb({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 gb(e,t,n,r,i){e?.[r.toolName]?.streamCall?.(n,{toolCallId:r.toolCallId,abortSignal:t,human:e=>i(r.toolCallId,e)})}function _b(e,t,n,r){let i=typeof e==`function`?e:()=>e,a=typeof t==`function`?t:()=>t;return new pb({execute:e=>hb(i(),a(),e,n),streamCall:({reader:e,...t})=>gb(i(),a(),e,t,n),onExecutionStart:r?.onExecutionStart,onExecutionEnd:r?.onExecutionEnd})}var vb=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({attachment:vv({source:`message`,query:{type:`index`,index:e},get:t=>t.message().attachment({index:e})})}),children:t}),yb=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({attachment:vv({source:`composer`,query:{type:`index`,index:e},get:t=>t.composer().attachment({index:e})})}),children:t}),bb=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({message:vv({source:`thread`,query:{type:`index`,index:e},get:t=>t.thread().message({index:e})}),composer:vv({source:`message`,query:{},get:t=>t.thread().message({index:e}).composer()})}),children:t}),xb=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({part:vv({source:`message`,query:{type:`index`,index:e},get:t=>t.message().part({index:e})})}),children:t}),Sb=Bg(({text:e,isRunning:t})=>{let n=f_(()=>({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`)},respondToToolApproval:()=>{throw Error(`Not supported`)}}}),Cb=({text:e,isRunning:t=!1,children:n})=>(0,K.jsx)(_v,{value:Uv({part:Sb({text:e,isRunning:t})}),children:n}),wb=Object.freeze({type:`complete`}),Tb=Bg(({parts:e,getMessagePart:t})=>{let[n,r]=a_(!0),i=f_(()=>e[e.length-1]?.status??wb,[e]),a=f_(()=>({parts:e,collapsed:n,status:i}),[e,n,i]);return{getState:()=>a,setCollapsed:r,part:t}}),Eb=({startIndex:e,endIndex:t,children:n})=>{let r=Q(e=>e.message.parts).slice(e,t+1),i=Uv();return(0,K.jsx)(_v,{value:Uv({chainOfThought:Tb({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})},Db=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({suggestion:vv({source:`suggestions`,query:{index:e},get:t=>t.suggestions().suggestion({index:e})})}),children:t}),Ob=({index:e,children:t})=>(0,K.jsx)(_v,{value:Uv({queueItem:vv({source:`composer`,query:{index:e},get:t=>t.composer().queueItem({index:e})})}),children:t}),kb=Symbol(`innerMessage`),Ab=Symbol(`innerMessages`),jb=[],Mb=(e,t)=>{kb in e||(e[kb]=t)},Nb=e=>{let t=`messages`in e?e.messages:e,n=t[Ab]||t[kb];return n?Array.isArray(n)?n:(t[Ab]=[n],t[Ab]):jb},Pb=Symbol(`skip-update`);function Fb(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 Ib=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)}}},Lb=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()}}},Rb=class extends Lb{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e;let t=e.getState();if(t===Pb)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===Pb||Fb(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){return this.binding.subscribe(()=>{this._syncState()&&this.notifySubscribers()})}},zb=class extends Lb{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!==Pb&&(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()})}},Bb=class extends Lb{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?.()}}},Vb=class extends Lb{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?.()}}},Hb=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)}},Ub=class extends Hb{_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)}},Wb=class extends Ub{get source(){return`thread-composer`}},Gb=class extends Ub{get source(){return`edit-composer`}},Kb=class extends Hb{get source(){return`message`}remove(){throw Error(`Message attachments cannot be removed`)}},qb=Object.freeze([]),Jb=Object.freeze({}),Yb=e=>Object.freeze({type:`thread`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,attachments:e?.attachments??qb,text:e?.text??``,role:e?.role??`user`,runConfig:e?.runConfig??Jb,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,value:e?.text??``}),Xb=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??qb,runConfig:e?.runConfig??Jb,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,parentId:e?.parentId??null,sourceId:e?.sourceId??null,value:e?.text??``}),Zb=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 Vb({event:e,binding:this._core}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},Qb=class extends Zb{get path(){return this._core.path}get type(){return`thread`}_getState;constructor(e){let t=new zb({path:e.path,getState:()=>Yb(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 Wb(new Rb({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`}:Pb},subscribe:e=>this._core.subscribe(e)}),this._core)}},$b=class extends Zb{_beginEdit;get path(){return this._core.path}get type(){return`edit`}_getState;constructor(e,t){let n=new zb({path:e.path,getState:()=>Xb(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 Gb(new Rb({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`}:Pb},subscribe:e=>this._core.subscribe(e)}),this._core)}},ex=e=>e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
57
57
|
|
|
58
58
|
`),tx=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.respondToToolApproval=this.respondToToolApproval.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=rb.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})}respondToToolApproval(e){let t=this.contentBinding.getState();if(!t)throw Error(`Message part is not available`);if(t.type!==`tool-call`)throw Error(`Tried to respond to tool approval on non-tool message part`);if(!t.approval||t.approval.approved!==void 0)throw Error(`Tool call has no pending approval`);if(!this.threadApi)throw Error(`Thread API is not available`);this.threadApi.getState().respondToToolApproval({approvalId:t.approval.id,approved:e.approved,...e.reason!=null&&{reason:e.reason}})}subscribe(e){return this.contentBinding.subscribe(e)}},nx=Object.freeze({type:`complete`}),rx=(e,t,n)=>{if(e.role!==`assistant`)return nx;if(n.type===`tool-call`)return n.result?nx:e.status;let r=t===Math.max(0,e.content.length-1);return e.status.type===`requires-action`?nx:r?e.status:nx},ix=(e,t)=>{let n=e.content[t];if(!n)return Pb;let r=rx(e,t,n);return Object.freeze({...n,[kb]:n[kb],status:r})},ax=class{_core;_threadBinding;get path(){return this._core.path}constructor(e,t){this._core=e,this._threadBinding=t,this.composer=new $b(new Bb({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 ex(this.getState())}subscribe(e){return this._core.subscribe(e)}getMessagePartByIndex(e){if(e<0)throw Error(`Message part index must be >= 0`);return new tx(new Rb({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.content[${e}]`,messagePartSelector:{type:`index`,index:e}},getState:()=>ix(this.getState(),e),subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getMessagePartByToolCallId(e){return new tx(new Rb({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?Pb:ix(t,n)},subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getAttachmentByIndex(e){return new Kb(new Rb({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`}:Pb},subscribe:e=>this._core.subscribe(e)}))}},ox=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{},...e.stream?{stream:e.stream}:{}}),sx=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{}}),cx=(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},lx=(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})},ux=class{get path(){return this._threadBinding.path}get __internal_threadBinding(){return this._threadBinding}_threadBinding;constructor(e,t){let n=new Rb({path:e.path,getState:()=>lx(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 Qb(new Bb({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(cx(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(sx(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 ax(new Rb({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 Pb;let o=this._threadBinding.getState().getBranches(e.id);return{...e,[kb]:e[kb],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 Vb({event:e,binding:this._threadBinding}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},dx=(0,_.createContext)(null),fx=()=>(0,_.useContext)(dx),px=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(e){let t=this._core.getState();return this._threadListBinding.switchToThread(t.id,e)}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}},mx=Promise.resolve(),hx=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}),gx=(e,t)=>{if(t===void 0)return Pb;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}:Pb},_x=class{_core;_runtimeFactory;_getState;constructor(e,t=ux){this._core=e,this._runtimeFactory=t;let n=new zb({path:{},getState:()=>hx(e),subscribe:t=>e.subscribe(t)});this._getState=n.getState.bind(n),this._mainThreadListItemRuntime=new px(new Rb({path:{ref:`threadItems[main]`,threadSelector:{type:`main`}},getState:()=>gx(this._core,this._core.mainThreadId),subscribe:e=>this._core.subscribe(e)}),this._core),this.main=new t(new Bb({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,t){return this._core.switchToThread(e,t)}switchToNewThread(){return this._core.switchToNewThread()}getLoadThreadsPromise(){return this._core.getLoadThreadsPromise()}reload(){return this._core.reload?.()??mx}loadMore(){return this._core.loadMore?.()??mx}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 Bb({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 px(new Rb({path:{ref:`threadItems[${e}]`,threadSelector:{type:`index`,index:e}},getState:()=>gx(this._core,this._core.threadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getArchivedItemByIndex(e){return new px(new Rb({path:{ref:`archivedThreadItems[${e}]`,threadSelector:{type:`archiveIndex`,index:e}},getState:()=>gx(this._core,this._core.archivedThreadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getItemById(e){return new px(new Rb({path:{ref:`threadItems[threadId=${e}]`,threadSelector:{type:`threadId`,threadId:e}},getState:()=>gx(this._core,e),subscribe:e=>this._core.subscribe(e)}),this._core)}},vx=class{_core;threads;_thread;constructor(e){this._core=e,this.threads=new _x(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)}},yx=class{_contextProvider=new L_;registerModelContextProvider(e){return this._contextProvider.registerModelContextProvider(e)}getModelContextProvider(){return this._contextProvider}},bx=Object.freeze([]),xx=`DEFAULT_THREAD_ID`,Sx=Object.freeze([xx]),Cx=Object.freeze({id:xx,remoteId:void 0,externalId:void 0,status:`regular`}),wx=Promise.resolve(),Tx=Object.freeze({[xx]:Cx}),Ex=class{threadFactory;_mainThreadId=xx;_threads=Sx;_archivedThreads=bx;_threadData=Tx;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 wx}_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??xx,i=e.threads??bx,a=e.archivedThreads??bx,o=n.threadId??xx,s=n.threads??bx,c=n.archivedThreads??bx;!t&&o===r&&s===i&&c===a||((s!==i||c!==a||o!==r)&&(this._threadData={...Tx,...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)??bx),c!==a&&(this._archivedThreads=this.adapter.archivedThreads?.map(e=>e.id)??bx),(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,t){if(this._mainThreadId===e)return;let n=this.adapter.onSwitchToThread;if(!n)throw Error(`External store adapter does not support switching to thread`);await n(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()}},Dx=Hy(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),Ox=Symbol(`autoStatus`),kx=Object.freeze(Object.assign({type:`running`},{[Ox]:!0})),Ax=Object.freeze(Object.assign({type:`complete`,reason:`unknown`},{[Ox]:!0})),jx=Object.freeze(Object.assign({type:`requires-action`,reason:`tool-calls`},{[Ox]:!0})),Mx=Object.freeze(Object.assign({type:`requires-action`,reason:`interrupt`},{[Ox]:!0})),Nx=e=>e[Ox]===!0,Px=(e,t,n,r,i)=>e&&i?Object.assign({type:`incomplete`,reason:`error`,error:i},{[Ox]:!0}):e&&t?kx:n?Mx:r?jx:Ax,Fx=(e,t)=>{if(e.startsWith(`data-`))return{type:`data`,name:e.substring(5),data:t}},Ix=(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|svg\+xml);base64,(.*)$/)||/^(https:\/\/|blob:)/.test(e)?{...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`generative-ui`:return e;case`tool-call`:{let{parentId:t,messages:n,...r}=e,i={...r,toolCallId:e.toolCallId??`tool-${Dx()}`,...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:Zy(e.argsText??``)??{},argsText:e.argsText??``}}default:{let n=Fx(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},...c?.isOptimistic&&{isOptimistic:!0}}};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=Fx(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=>Fx(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}`)}},Lx={fromArray:e=>{let t=e.map(e=>Ix(e,Dx(),Px(!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=Px(!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:Ix(e,e.id,n)}})}}},Rx=e=>e.next?Rx(e.next):`current`in e?e:null,zx=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}},Bx=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],(Rx(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 zx(()=>{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}}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=Rx(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}evictOffBranchOptimisticMessages(e,t){if(!e)return;let n=new Set;for(let e=t;e;e=e.prev)n.add(e.current.id);let r=[];for(let t=e;t&&!n.has(t.current.id);t=t.prev)t.current.metadata?.isOptimistic&&r.push(t.current.id);for(let e of r)this.messages.has(e)&&this.deleteMessage(e)}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=this.head,r=t.prev??this.root;r.next=t,this.head=Rx(t),this.evictOffBranchOptimisticMessages(n,this.head),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.`);let n=this.head;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.evictOffBranchOptimisticMessages(n,this.head),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)t.current.metadata?.isOptimistic||e.push({message:t.current,parentId:t.prev?.current.id??null});let t=this.head;for(;t?.current.metadata?.isOptimistic;)t=t.prev;return{headId:t?.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 Vx(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 Hx(e,t){return e.length===t.length?e.every((e,n)=>e.id===t[n].id):!1}function Ux(e){let t=Dx();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 Wx(e){let t=[];for(let n of e)n.type!==`text`&&t.push(Ux(n));return t}var Gx=e=>e.status.type===`complete`,Kx=class extends Ib{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=>!Gx(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(Gx(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&&!Vx({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??Dx(),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(!Vx({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(!Gx(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)}}},qx=class extends Kx{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()}},Jx=class extends Kx{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=ex(r),this.setText(this._previousText),this.setRole(r.role),r.role===`user`?(this._previousAttachments=[...r.attachments??[],...Wx(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=ex(e),r=!Hx(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()}},Yx=class{_contextProvider;_subscriptions=new Set;_isInitialized=!1;repository=new Bx;_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 qx(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 Jx(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(ex(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:Dx(),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:Dx(),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(Lx.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),e===`initialize`&&this._isInitialized&&queueMicrotask(()=>{r.has(n)&&n({})}),()=>{this._eventSubscribers.get(e)?.delete(n)}}},Xx=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})}};function Zx(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Qx(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=>Qx(e,t+1)):Zx(e)?Object.entries(e).every(([e,n])=>typeof e==`string`&&Qx(n,t+1)):!1}var $x=100,eS=(e,t,n)=>{if(e===t)return!0;if(n>$x||e==null||t==null)return!1;if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:e.every((e,r)=>eS(e,t[r],n+1));if(Array.isArray(t)||!Zx(e)||!Zx(t))return!1;let r=Object.keys(e),i=Object.keys(t);return r.length===i.length?r.every(r=>Object.hasOwn(t,r)&&eS(e[r],t[r],n+1)):!1},tS=(e,t)=>!Qx(e)||!Qx(t)?!1:eS(e,t,0),nS=e=>{try{return JSON.parse(e),!0}catch{return!1}},rS=e=>{try{return JSON.parse(e)}catch{return}},iS=(e,t)=>{let n=rS(e),r=rS(t);return n===void 0||r===void 0?!1:tS(n,r)},aS=class{_getTools;_callbacks;_entries=new Map;_skipExecuteStreamIds=new Set;_humanInput=new Map;_executing=new Set;_settledResolvers=[];_statuses=new Map;_ac=new AbortController;_pendingRestore=!0;_lastSnapshot=null;_isRunning=!1;_controller;_pipelineDead=!1;_pipelineRestartUsed=!1;constructor(e,t){this._getTools=e,this._callbacks=t,this._initPipeline()}_initPipeline(){let[e,t]=Ky();this._controller=t;let n=_b(()=>this._getWrappedTools(),()=>this._ac.signal,(e,t)=>this._onHumanInput(e,t),{onExecutionStart:e=>this._onExecutionStart(e),onExecutionEnd:e=>this._onExecutionEnd(e)});e.pipeThrough(n).pipeThrough(new Vy).pipeTo(new WritableStream({write:e=>{try{if(e.type!==`result`)return;this._handleResultChunk(e)}catch(e){console.error(`[ToolInvocationTracker] result chunk handling failed`,e)}}})).catch(e=>{console.error(`[ToolInvocationTracker] stream pipeline failed; will attempt single restart on next setState`,e),this._pipelineDead=!0})}setState(e){try{if(this._pipelineDead){if(this._pipelineRestartUsed)return;this._pipelineRestartUsed=!0,this._pipelineDead=!1,this._demoteEntriesToRestored(),this._executing.clear(),this._ac=new AbortController,this._initPipeline()}if(this._lastSnapshot&&this._lastSnapshot.messages===e.messages&&this._lastSnapshot.isRunning===e.isRunning&&this._lastSnapshot.isLoading===e.isLoading)return;e.isLoading===!0&&(this._pendingRestore=!0);let t=this._isRunning;this._isRunning=e.isRunning;try{this._processMessages(e.messages)}catch(e){throw this._isRunning=t,e}this._lastSnapshot=e,this._pendingRestore=!1}catch(e){console.error(`[ToolInvocationTracker] setState failed; snapshot dropped`,e)}}reset(){try{this._pendingRestore=!0,this._entries.clear(),this._lastSnapshot=null,this.abort().finally(()=>{this._executing.clear()})}catch(e){console.error(`[ToolInvocationTracker] reset failed`,e)}}abort(){try{return this._humanInput.forEach(({reject:e})=>{try{e(Error(`Tool execution aborted`))}catch{}}),this._humanInput.clear(),this._ac.abort(),this._ac=new AbortController,this._executing.size===0?Promise.resolve():new Promise(e=>{this._settledResolvers.push(e)})}catch(e){return console.error(`[ToolInvocationTracker] abort failed`,e),Promise.resolve()}}resume(e,t){try{let n=this._humanInput.get(e);return n?(this._humanInput.delete(e),this._setStatus(e,{type:`executing`}),n.resolve(t),!0):!1}catch(e){return console.error(`[ToolInvocationTracker] resume failed`,e),!1}}getStatuses(){return this._statuses}_getWrappedTools(){let e=this._getTools();if(e)return Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=t.execute;return n===void 0?[e,t]:[e,{...t,execute:(...[e,t])=>this._skipExecuteStreamIds.has(t.toolCallId)?new Promise(()=>{}):n(e,t)}]}))}_onHumanInput(e,t){return new Promise((n,r)=>{let i=this._humanInput.get(e);if(i)try{i.reject(Error(`Human input request was superseded by a new request`))}catch{}this._humanInput.set(e,{resolve:n,reject:r}),this._setStatus(e,{type:`interrupt`,payload:{type:`human`,payload:t}})})}_onExecutionStart(e){this._skipExecuteStreamIds.has(e)||(this._executing.add(e),this._setStatus(e,{type:`executing`}))}_onExecutionEnd(e){this._executing.delete(e)&&(this._deleteStatus(e),this._executing.size===0&&this._settledResolvers.splice(0).forEach(e=>{try{e()}catch{}}))}_handleResultChunk(e){let t=e.meta.toolCallId,n=this._entries.get(t);!n&&this._skipExecuteStreamIds.has(t)||n?.hasResult||this._invokeOnResult({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}})}_invokeOnResult(e){try{this._callbacks.onResult(e)}catch(e){console.error(`[ToolInvocationTracker] onResult callback threw; result dropped`,e)}}_invokeOnStatusesChange(){try{this._callbacks.onStatusesChange(this._statuses)}catch(e){console.error(`[ToolInvocationTracker] onStatusesChange callback threw; status change not propagated`,e)}}_setStatus(e,t){let n=new Map(this._statuses);n.set(e,t),this._statuses=n,this._invokeOnStatusesChange()}_deleteStatus(e){if(!this._statuses.has(e))return;let t=new Map(this._statuses);t.delete(e),this._statuses=t,this._invokeOnStatusesChange()}_hasExecutableTool(e){let t=this._getTools()?.[e];return t?.execute!==void 0||t?.streamCall!==void 0}_shouldCloseArgsStream({toolName:e,argsText:t,hasResult:n}){return n?!0:(this._hasExecutableTool(e)||!this._isRunning)&&nS(t)}_startActiveEntry(e,t,n){let r=this._controller.addToolCallPart({toolName:t,toolCallId:e});n&&this._skipExecuteStreamIds.add(e);let i={toolName:t,controller:r,argsText:``,hasResult:!1,argsComplete:!1};return this._entries.set(e,i),i}_demoteEntriesToRestored(){for(let[e,t]of this._entries)t.controller&&this._entries.set(e,{toolName:t.toolName,argsText:t.argsText,hasResult:t.hasResult})}_processArgsText(e,t){if(!e.controller)return;let n=t.result!==void 0;if(t.argsText!==e.argsText){let r=!0;if(e.argsComplete)iS(e.argsText,t.argsText)&&(e.argsText=t.argsText),r=!1;else if(!t.argsText.startsWith(e.argsText))if(nS(e.argsText)&&nS(t.argsText)&&iS(e.argsText,t.argsText)){let i=this._shouldCloseArgsStream({toolName:t.toolName,argsText:t.argsText,hasResult:n});i&&e.controller.argsText.close(),e.argsText=t.argsText,e.argsComplete=i,r=!1}else r=!1;if(r&&e.controller){let r=t.argsText.slice(e.argsText.length);e.controller.argsText.append(r);let i=this._shouldCloseArgsStream({toolName:t.toolName,argsText:t.argsText,hasResult:n});i&&e.controller.argsText.close(),e.argsText=t.argsText,e.argsComplete=i}}!e.argsComplete&&e.controller&&this._shouldCloseArgsStream({toolName:t.toolName,argsText:t.argsText,hasResult:n})&&(e.controller.argsText.close(),e.argsText=t.argsText,e.argsComplete=!0)}_processMessages(e){let t=this._pendingRestore;for(let n of e)if(!(!n||!Array.isArray(n.content)))for(let e of n.content){if(!e||e.type!==`tool-call`)continue;let n=this._entries.get(e.toolCallId);if(t){n?.controller||this._entries.set(e.toolCallId,{toolName:e.toolName,argsText:e.argsText,hasResult:e.result!==void 0}),e.messages&&this._processMessages(e.messages);continue}let r=n;if(r&&!r.controller){if(!(e.argsText!==r.argsText||e.result!==void 0!==r.hasResult)){e.messages&&this._processMessages(e.messages);continue}this._entries.delete(e.toolCallId),r=void 0}if(r||=this._startActiveEntry(e.toolCallId,e.toolName,e.result!==void 0),this._processArgsText(r,e),e.result!==void 0&&!r.hasResult){let{controller:t}=r;if(!t)continue;r.hasResult=!0,r.argsComplete=!0,t.setResponse(new rb({result:e.result,artifact:e.artifact,isError:e.isError,...e.modelContent===void 0?{}:{modelContent:e.modelContent}})),t.close()}e.messages&&this._processMessages(e.messages)}}},oS=Object.freeze([]),sS=(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},cS=(e,t)=>e&&t[t.length-1]?.role!==`assistant`,lS=class extends Yx{_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 Xx;_store;_toolInvocations=null;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??oS;sS(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};sS(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.repository.import(e.messageRepository),a=this.repository.getMessages()}else if(e.messages){if(n){if(n.convertMessage!==e.convertMessage)this._converter=new Xx;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=Px(i===(e.messages?.length??0)-1,t,!1,!1,void 0);if(n&&(n.role!==`assistant`||!Nx(n.status)||n.status===a))return n;let o=Ix(e.convertMessage(r,i),i.toString(),a);return Mb(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`,{}));let o=null;cS(t,a)&&(o=Dx(),this.repository.addOrUpdateMessage(a.at(-1)?.id??null,Ix({role:`assistant`,content:[],metadata:{isOptimistic:!0}},o,{type:`running`}))),this.repository.resetHead(o??a.at(-1)?.id??null),this._messages=this.repository.getMessages(),this._driveToolInvocations(),this._notifySubscribers()}_driveToolInvocations(){if(!this._store.unstable_enableToolInvocations){this._toolInvocations&&(this._toolInvocations.reset(),this._toolInvocations=null,this._store.setToolStatuses?.({}));return}this._toolInvocations||=new aS(()=>this.getModelContext().tools,{onResult:e=>{try{let t=this._findMessageIdForToolCall(e.toolCallId);if(t===void 0)return;this._store.onAddToolResult?.({messageId:t,toolCallId:e.toolCallId,toolName:e.toolName,result:e.result,isError:e.isError,...e.artifact!==void 0&&{artifact:e.artifact},...e.modelContent!==void 0&&{modelContent:e.modelContent}})}catch(e){console.error(`[ExternalStoreThreadRuntimeCore] onAddToolResult dispatch failed`,e)}},onStatusesChange:e=>{this._store.setToolStatuses?.(Object.fromEntries(e))}}),this._toolInvocations.setState({messages:this._messages,isRunning:this._store.isRunning??!1,...this._store.isLoading!==void 0&&{isLoading:this._store.isLoading}})}_toolCallToMessageId=new Map;_messagesForToolCallIndex=null;_findMessageIdForToolCall(e){if(this._messagesForToolCallIndex!==this._messages){this._toolCallToMessageId.clear();let e=t=>{for(let n of t)if(Array.isArray(n.content))for(let t of n.content)!t||t.type!==`tool-call`||(this._toolCallToMessageId.set(t.toolCallId,n.id),t.messages&&e(t.messages))};e(this._messages),this._messagesForToolCallIndex=this._messages}return this._toolCallToMessageId.get(e)}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.startRun??e.role===`user`)&&await this._toolInvocations?.abort(),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._toolInvocations?.abort(),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._toolInvocations&&(this._toolInvocations.reset(),this._store.setToolStatuses?.({})),this._store.onLoadExternalState(e)}cancelRun(){if(!this._store.onCancel)throw Error(`Runtime does not support cancelling runs.`);this._toolInvocations?.abort(),this._store.onCancel();let e=this.repository.getMessages().at(-1);e&&e.metadata.isOptimistic&&e.content.length===0&&this.repository.deleteMessage(e.id);let t=this.repository.getMessages(),n=t[t.length-1];n?.role===`user`&&n.id===t.at(-1)?.id?(this.repository.deleteMessage(n.id),this.composer.text.trim()||this.composer.setText(ex(n)),t=this.repository.getMessages()):this._notifySubscribers(),setTimeout(()=>{this.updateMessages(t)},0)}addToolResult(e){if(!this._store.onAddToolResult)throw Error(`Runtime does not support tool results.`);this._store.onAddToolResult?.(e)}resumeToolCall(e){if(!(this._toolInvocations?.resume(e.toolCallId,e.payload)??!1)){if(this._store.onResumeToolCall){this._store.onResumeToolCall(e);return}throw Error(`Tool call ${e.toolCallId} is not waiting for resume.`)}}respondToToolApproval(e){if(!this._store.onRespondToToolApproval)throw Error(`Runtime does not support tool approvals.`);this._store.onRespondToToolApproval(e)}reset(e){let t=new Bx;t.import(Lx.fromArray(e??[])),this.updateMessages(t.getMessages())}import(e){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(Nb))}},uS=e=>e.adapters?.threadList??{},dS=class extends yx{threads;constructor(e){super(),this.threads=new Ex(uS(e),()=>new lS(this._contextProvider,e))}setAdapter(e){this.threads.__internal_setAdapter(uS(e)),this.threads.getMainThreadRuntimeCore().__internal_setAdapter(e)}},fS=e=>{let[t]=(0,_.useState)(()=>new dS(e));(0,_.useEffect)(()=>{t.setAdapter(e)});let{modelContext:n}=fx()??{};return(0,_.useEffect)(()=>{if(n)return t.registerModelContextProvider(n)},[n,t]),(0,_.useMemo)(()=>new vx(t),[t])},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,K.jsx)(hS(e,Q(e=>e.message.role),Q(e=>e.message.composer.isEditing)),{}),_S=(0,_.memo)(({index:e,components:t})=>(0,K.jsx)(bb,{index:e,children:(0,K.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,_.useMemo)(()=>t===0?null:Array.from({length:t},(t,n)=>(0,K.jsx)(bb,{index:n,children:(0,K.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,K.jsx)(vS,{children:()=>(0,K.jsx)(gS,{components:e})}):(0,K.jsx)(vS,{children:t});yS.displayName=`ThreadPrimitive.Messages`;var bS=(0,_.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=class extends Error{componentName;constructor(e,t=`Component "${e}" is not in the generative-ui allowlist.`){super(t),this.name=`GenerativeUIRenderError`,this.componentName=e}},CS=e=>typeof e==`object`&&!!e,wS=(e,t,n,r)=>{if(e==null)return null;if(typeof e==`string`)return e;if(!CS(e)||!(`component`in e))return null;let{component:i,props:a,children:o,key:s}=e,c=t[i];if(!c){if(n)return(0,K.jsx)(n,{component:i,props:a},s??r);throw new SS(i)}let l=o?.length?o.map((e,i)=>wS(e,t,n,`${r}/${i}`)):void 0;return(0,_.createElement)(c,{...a??{},key:s??r},...l??[])},TS=e=>{if(!e||e.root===void 0||e.root===null)return[];let t=e.root;return Array.isArray(t)?t:[t]},ES=({spec:e,components:t,Fallback:n})=>(0,K.jsx)(K.Fragment,{children:(0,_.useMemo)(()=>TS(e),[e]).map((e,r)=>wS(e,t,n,`${r}`))});ES.displayName=`GenerativeUIRender`;var DS=({components:e,spec:t,Fallback:n})=>{let r=Q(e=>{let t=e.part;return t?.type===`generative-ui`?t.spec:void 0}),i=t??r;return i?(0,K.jsx)(ES,{spec:i,components:e,Fallback:n}):null};DS.displayName=`MessagePrimitive.GenerativeUI`;var OS=`ui://`,kS=e=>!!e?.startsWith(OS),AS=e=>Symbol.iterator in e,jS=e=>`entries`in e,MS=(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},NS=(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 PS(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:AS(e)&&AS(t)?jS(e)&&jS(t)?MS(e,t):NS(e,t):MS({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function FS(e){let t=_.useRef(void 0);return n=>{let r=e(n);return PS(t.current,r)?t.current:t.current=r}}var IS=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})}}},LS=(e,t)=>{let n=[];if(t){let t=IS(`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=IS(`toolGroup`),r=IS(`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},RS=e=>{let t=Q(FS(e=>e.message.parts.map(e=>e.type)));return(0,_.useMemo)(()=>t.length===0?[]:LS(t,e),[t,e])},zS=({Fallback:e,...t})=>{let n=Q(n=>n.tools.toolUIs[t.toolName]?.[0]?.render??e);return n?(0,K.jsx)(n,{...t}):null},BS=(e,t,n)=>e.renderers[t]?.[0]||(e.fallbacks[0]??n),VS=({Fallback:e,...t})=>{let n=Q(n=>BS(n.dataRenderers,t.name,e));return n?(0,K.jsx)(n,{...t}):null},HS={Text:()=>null,Reasoning:()=>null,Source:()=>null,Image:()=>null,File:()=>null,Unstable_Audio:()=>null,ToolGroup:({children:e})=>e,ReasoningGroup:({children:e})=>e},US=({components:{Text:e=HS.Text,Reasoning:t=HS.Reasoning,Image:n=HS.Image,Source:r=HS.Source,File:i=HS.File,Unstable_Audio:a=HS.Unstable_Audio,tools:o={},data:s,generativeUI:c}={}})=>{let l=Uv(),u=Q(e=>e.part),d=u.type;if(d===`tool-call`){let e=l.part().addToolResult,t=l.part().resumeToolCall,n=l.part().respondToToolApproval;if(`Override`in o)return(0,K.jsx)(o.Override,{...u,addResult:e,resume:t,respondToApproval:n});let r=o.by_name?.[u.toolName]??o.Fallback;return(0,K.jsx)(zS,{...u,Fallback:r,addResult:e,resume:t,respondToApproval:n})}if(u.status?.type===`requires-action`)throw Error(`Encountered unexpected requires-action status`);switch(d){case`text`:return(0,K.jsx)(e,{...u});case`reasoning`:return(0,K.jsx)(t,{...u});case`source`:return(0,K.jsx)(r,{...u});case`image`:return(0,K.jsx)(n,{...u});case`file`:return(0,K.jsx)(i,{...u});case`audio`:return(0,K.jsx)(a,{...u});case`data`:{let e=s?.by_name?.[u.name]??s?.Fallback;return(0,K.jsx)(VS,{...u,Fallback:e})}case`generative-ui`:return c?.components?(0,K.jsx)(ES,{spec:u.spec,components:c.components,Fallback:c.Fallback}):null;default:return console.warn(`Unknown message part type: ${d}`),null}},WS=(0,_.memo)(({index:e,components:t})=>(0,K.jsx)(xb,{index:e,children:(0,K.jsx)(US,{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?.generativeUI===t.components?.generativeUI&&e.components?.ToolGroup===t.components?.ToolGroup&&e.components?.ReasoningGroup===t.components?.ReasoningGroup);WS.displayName=`MessagePrimitive.PartByIndex`;var GS=({status:e,component:t})=>(0,K.jsx)(Cb,{text:``,isRunning:e.type===`running`,children:(0,K.jsx)(t,{type:`text`,text:``,status:e})}),KS=Object.freeze({type:`complete`}),qS=Object.freeze({type:`running`}),JS=(0,_.memo)(({components:e})=>{let t=Q(e=>e.message.status??KS);return e?.Empty?(0,K.jsx)(e.Empty,{status:t}):t.type===`running`?(0,K.jsx)(GS,{status:t,component:e?.Text??HS.Text}):null},(e,t)=>e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),YS=(0,_.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,K.jsx)(JS,{components:e}):null,(e,t)=>e.enabled===t.enabled&&e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),XS=(0,_.memo)(({Quote:e})=>{let t=Q(xS);return t?(0,K.jsx)(e,{text:t.text,messageId:t.messageId}):null});function ZS(e,t){return(e.toolUIs[t.toolName]?.[0]?.render??null)||(kS(t.mcp?.app?.resourceUri)&&e.mcpApp?e.mcpApp.render:null)}var QS=()=>{let e=Uv(),t=Q(e=>e.part),n=Q(e=>e.part.type===`tool-call`?ZS(e.tools,e.part):null);return!n||t.type!==`tool-call`?null:(0,K.jsx)(n,{...t,addResult:e.part().addToolResult,resume:e.part().resumeToolCall,respondToApproval:e.part().respondToToolApproval})},$S=()=>{let e=Q(e=>e.part),t=Q(e=>e.part.type===`data`?BS(e.dataRenderers,e.part.name,void 0)??null:null);return!t||e.type!==`data`?null:(0,K.jsx)(t,{...e})},eC=()=>{let e=Q(e=>e.part.type);return e===`tool-call`?(0,K.jsx)(QS,{}):e===`data`?(0,K.jsx)($S,{}):null},tC=Object.freeze({type:`text`,text:``,status:qS}),nC=({index:e,children:t})=>{let n=Uv(),r=Q(e=>e.dataRenderers);return(0,K.jsx)(xb,{index:e,children:(0,K.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=ZS(n.tools().getState(),t)!==null,i=n.message().part({index:e});return{...t,toolUI:r?(0,K.jsx)(QS,{}):null,addResult:i.addToolResult,resume:i.resumeToolCall,respondToApproval:i.respondToToolApproval}}if(t.type===`data`){let e=BS(r,t.name,void 0)!==void 0;return{...t,dataRendererUI:e?(0,K.jsx)($S,{}):null}}return t}})})})},rC=({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,K.jsx)(Cb,{text:``,isRunning:!0,children:e({part:tC})}):null:(0,K.jsx)(K.Fragment,{children:Array.from({length:t},(t,n)=>(0,K.jsx)(nC,{index:n,children:t=>e(t)??(0,K.jsx)(eC,{})},n))})},iC=({components:e,unstable_showEmptyOnNonTextEnd:t=!0,children:n})=>n?(0,K.jsx)(rC,{children:n}):(0,K.jsx)(aC,{components:e,unstable_showEmptyOnNonTextEnd:t});iC.displayName=`MessagePrimitive.Parts`;var aC=({components:e,unstable_showEmptyOnNonTextEnd:t})=>{let n=Q(e=>e.message.parts.length),r=RS(!!e?.ChainOfThought),i=(0,_.useMemo)(()=>n===0?(0,K.jsx)(JS,{components:e}):r.map(t=>{if(t.type===`single`)return(0,K.jsx)(WS,{index:t.index,components:e},t.index);if(t.type===`chainOfThoughtGroup`){let n=e?.ChainOfThought;return n?(0,K.jsx)(Eb,{startIndex:t.startIndex,endIndex:t.endIndex,children:(0,K.jsx)(n,{})},`chainOfThought-${t.startIndex}`):null}else if(t.type===`toolGroup`)return(0,K.jsx)(e?.ToolGroup??HS.ToolGroup,{startIndex:t.startIndex,endIndex:t.endIndex,children:Array.from({length:t.endIndex-t.startIndex+1},(n,r)=>{let i=t.startIndex+r;return(0,K.jsx)(WS,{index:i,components:e},`part-${i}`)})},`tool-${t.startIndex}`);else return(0,K.jsx)(e?.ReasoningGroup??HS.ReasoningGroup,{startIndex:t.startIndex,endIndex:t.endIndex,children:Array.from({length:t.endIndex-t.startIndex+1},(n,r)=>{let i=t.startIndex+r;return(0,K.jsx)(WS,{index:i,components:e},`part-${i}`)})},`reasoning-${t.startIndex}`)}),[r,e,n]);return(0,K.jsxs)(K.Fragment,{children:[e?.Quote&&(0,K.jsx)(XS,{Quote:e.Quote}),i,(0,K.jsx)(YS,{components:e,enabled:t})]})},oC=Symbol.for(`@assistant-ui/groupBy.memoKey`),sC=e=>{let t=e.nextChildIdx++;return e.nodeKey===``?String(t):`${e.nodeKey}.${t}`},cC=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:sC(e),indices:[],children:[],nextChildIdx:0})}let o=n[n.length-1];o.children.push({type:`part`,index:t,nodeKey:sC(o)});for(let e=1;e<n.length;e++)n[e].indices.push(t)}for(;n.length>1;)r();return t.children},lC=Object.freeze({type:`complete`}),uC=(e,t,n)=>{if(!n)return!1;switch(e){case`never`:return!1;case`always`:return!0;case`empty`:return t.length===0;case`no-text`:{let e=t[t.length-1];return e!==void 0&&e.type!==`text`&&e.type!==`reasoning`}}},dC=()=>{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.")},fC=(e,t,n)=>{if(e.type===`part`)return(0,K.jsx)(nC,{index:e.index,children:({part:e})=>n({part:e,children:(0,K.jsx)(dC,{})})},`part-${e.index}`);let r=t[e.indices.at(-1)]?.status??lC;return(0,K.jsx)(_.Fragment,{children:n({part:{type:e.key,status:r,indices:e.indices},children:(0,K.jsx)(K.Fragment,{children:e.children.map(e=>fC(e,t,n))})})},e.nodeKey)},pC=({groupBy:e,indicator:t=`no-text`,children:n})=>{let r=Q(FS(e=>e.message.parts)),i=Q(e=>e.tools.toolUIs),a=Q(e=>t===`never`?!1:e.message.status?.type===`running`);return(0,K.jsxs)(K.Fragment,{children:[(0,_.useMemo)(()=>{let t={toolUIs:i};return cC(r.map(n=>e(n,t)??[]))},[r,e[oC]??e,i]).map(e=>fC(e,r,n)),uC(t,r,a)&&n({part:{type:`indicator`},children:(0,K.jsx)(dC,{})})]})};pC.displayName=`MessagePrimitive.GroupedParts`;var mC=(0,_.memo)(({children:e})=>{let t=Q(xS);return t?(0,K.jsx)(K.Fragment,{children:e(t)}):null});mC.displayName=`MessagePrimitive.Quote`;var hC=(e,t)=>{switch(t.type){case`image`:return e?.Image??e?.Attachment;case`document`:return e?.Document??e?.Attachment;case`file`:return e?.File??e?.Attachment;default:return e?.Attachment}},gC=({components:e})=>{let t=Q(e=>e.attachment);if(!t)return null;let n=hC(e,t);return n?(0,K.jsx)(n,{}):null},_C=(0,_.memo)(({index:e,components:t})=>(0,K.jsx)(vb,{index:e,children:(0,K.jsx)(gC,{components:t})}),(e,t)=>e.index===t.index&&e.components?.Image===t.components?.Image&&e.components?.Document===t.components?.Document&&e.components?.File===t.components?.File&&e.components?.Attachment===t.components?.Attachment);_C.displayName=`MessagePrimitive.AttachmentByIndex`;var vC=({children:e})=>{let t=Q(e=>e.message.role===`user`?(e.message.attachments??[]).length:0);return(0,_.useMemo)(()=>Array.from({length:t},(t,n)=>(0,K.jsx)(vb,{index:n,children:(0,K.jsx)(qv,{getItemState:e=>e.message().attachment({index:n}).getState(),children:t=>e({get attachment(){return t()}})})},n)),[t,e])},yC=({components:e,children:t})=>e?(0,K.jsx)(vC,{children:({attachment:t})=>{let n=hC(e,t);return n?(0,K.jsx)(n,{}):null}}):(0,K.jsx)(vC,{children:t});yC.displayName=`MessagePrimitive.Attachments`;var bC=(e,t)=>{switch(t.type){case`image`:return e?.Image??e?.Attachment;case`document`:return e?.Document??e?.Attachment;case`file`:return e?.File??e?.Attachment;default:return e?.Attachment}},xC=({components:e})=>{let t=Q(e=>e.attachment);if(!t)return null;let n=bC(e,t);return n?(0,K.jsx)(n,{}):null},SC=(0,_.memo)(({index:e,components:t})=>(0,K.jsx)(yb,{index:e,children:(0,K.jsx)(xC,{components:t})}),(e,t)=>e.index===t.index&&e.components?.Image===t.components?.Image&&e.components?.Document===t.components?.Document&&e.components?.File===t.components?.File&&e.components?.Attachment===t.components?.Attachment);SC.displayName=`ComposerPrimitive.AttachmentByIndex`;var CC=({children:e})=>{let t=Q(e=>e.composer.attachments.length);return(0,_.useMemo)(()=>Array.from({length:t},(t,n)=>(0,K.jsx)(yb,{index:n,children:(0,K.jsx)(qv,{getItemState:e=>e.composer().attachment({index:n}).getState(),children:t=>e({get attachment(){return t()}})})},n)),[t,e])},wC=({components:e,children:t})=>e?(0,K.jsx)(CC,{children:({attachment:t})=>{let n=bC(e,t);return n?(0,K.jsx)(n,{}):null}}):(0,K.jsx)(CC,{children:t});wC.displayName=`ComposerPrimitive.Attachments`;var TC=(0,_.memo)(({children:e})=>{let t=Q(e=>e.composer.queue.length);return(0,_.useMemo)(()=>Array.from({length:t},(t,n)=>(0,K.jsx)(Ob,{index:n,children:(0,K.jsx)(qv,{getItemState:e=>e.composer().queueItem({index:n}).getState(),children:t=>e({get queueItem(){return t()}})})},n)),[t,e])});TC.displayName=`ComposerPrimitive.Queue`;var EC=({children:e})=>Q(e=>e.part.status.type===`running`)?e:null;EC.displayName=`MessagePartPrimitive.InProgress`;var DC=({components:e})=>{let t=e.Suggestion;return(0,K.jsx)(t,{})},OC=(0,_.memo)(({index:e,components:t})=>(0,K.jsx)(Db,{index:e,children:(0,K.jsx)(DC,{components:t})}),(e,t)=>e.index===t.index&&e.components.Suggestion===t.components.Suggestion);OC.displayName=`ThreadPrimitive.SuggestionByIndex`;var kC=({children:e})=>{let t=Q(e=>e.suggestions.suggestions.length);return(0,_.useMemo)(()=>t===0?null:Array.from({length:t},(t,n)=>(0,K.jsx)(Db,{index:n,children:(0,K.jsx)(qv,{getItemState:e=>e.suggestions().suggestion({index:n}).getState(),children:t=>e({get suggestion(){return t()}})})},n)),[t,e])},AC=({components:e,children:t})=>e?(0,K.jsx)(kC,{children:()=>(0,K.jsx)(DC,{components:e})}):(0,K.jsx)(kC,{children:t});AC.displayName=`ThreadPrimitive.Suggestions`;var jC=(0,_.memo)(AC,(e,t)=>e.children||t.children?e.children===t.children:e.components.Suggestion===t.components.Suggestion),MC=e=>Q(t=>{if(e.editing===!0&&!t.composer.isEditing||e.editing===!1&&t.composer.isEditing)return!1;let n=t.composer.dictation!=null;return!(e.dictation===!0&&!n||e.dictation===!1&&n)}),NC=({children:e,...t})=>MC(t)?e:null;NC.displayName=`ComposerPrimitive.If`;var PC=()=>{let e=Uv(),t=Q(e=>!e.composer.canSend||e.thread.isRunning&&!e.thread.capabilities.queue);return{send:(0,_.useCallback)(t=>{e.composer().send(t)},[e]),disabled:t}},FC=()=>{let e=Uv(),t=Q(e=>!e.composer.canCancel);return{cancel:(0,_.useCallback)(()=>{e.composer().cancel()},[e]),disabled:t}},IC=()=>{let e=Uv(),t=Q(e=>e.composer.dictation!=null||!e.thread.capabilities.dictation||!e.composer.isEditing);return{startDictation:(0,_.useCallback)(()=>{e.composer().startDictation()},[e]),disabled:t}},LC=()=>{let e=Uv(),t=Q(e=>!e.composer.isEditing);return{addAttachment:(0,_.useCallback)(t=>e.composer().addAttachment(t),[e]),disabled:t}},RC=({prompt:e,send:t,clearComposer:n=!0})=>{let r=Uv(),i=Q(e=>e.thread.isDisabled),a=t??!1;return{trigger:(0,_.useCallback)(()=>{let t=r.thread().getState().isRunning;if(a&&!t)r.thread().append({content:[{type:`text`,text:e}],runConfig:r.composer().getState().runConfig}),n&&r.composer().setText(``);else if(n)r.composer().setText(e);else{let t=r.composer().getState().text;r.composer().setText(t.trim()?`${t} ${e}`:e)}},[r,a,n,e]),disabled:i}},zC=()=>Q(e=>e.message.status?.type===`incomplete`&&e.message.status.reason===`error`?e.message.status.error??`An error occurred`:void 0),BC=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}},VC=/:([\w-]{1,64})\[([^\]\n]{1,1024})\](?:\{name=([^}\n]{1,1024})\})?/gu,HC={serialize(e){let t=e.id===e.label?``:`{name=${e.id}}`;return`:${e.type}[${e.label}]${t}`},parse(e){let t=[],n=0;for(let r of e.matchAll(VC)){r.index>n&&t.push({kind:`text`,text:e.slice(n,r.index)});let i=r[2];t.push({kind:`mention`,type:r[1],label:i,id:r[3]??i}),n=r.index+r[0].length}return n<e.length&&t.push({kind:`text`,text:e.slice(n)}),t}};function UC(e,t){function n(n){let r=(0,_.useContext)(e);if(!n?.optional&&!r)throw Error(`This component must be used within ${t}.`);return r}return n}function WC(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 GC=(0,_.createContext)(null),{useThreadViewport:KC,useThreadViewportStore:qC}=WC(UC(GC,`ThreadPrimitive.Viewport`),`useThreadViewport`),JC=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()}}}}},YC=(e={})=>{let t=new Set,n=JC(e=>{a.setState({height:{...a.getState().height,viewport:e}})}),r=JC(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=Oy(()=>({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},XC=e=>e,ZC=e=>{let t=qC({optional:!0}),[n]=(0,_.useState)(()=>YC(e));return(0,_.useEffect)(()=>t?.getState().onScrollToBottom(()=>{n.getState().scrollToBottom()}),[t,n]),(0,_.useEffect)(()=>{if(t)return n.subscribe(e=>{t.getState().isAtBottom!==e.isAtBottom&&XC(t).setState({isAtBottom:e.isAtBottom})})},[n,t]),n},QC=({children:e,options:t={}})=>{let n=ZC(t),[r]=(0,_.useState)(()=>({useThreadViewport:n}));return(0,K.jsx)(GC.Provider,{value:r,children:e})},$C=()=>((0,_.useEffect)(()=>{},[Uv()]),null),ew=(0,_.memo)(({children:e,aui:t,runtime:n})=>(0,K.jsxs)(Sy,{runtime:n,aui:t??null,children:[(0,K.jsx)($C,{}),(0,K.jsx)(QC,{children:e})]}));function tw(e){let t=Uv(),n=Q(()=>t.composer.source?t.composer().__internal_getRuntime?.()??null:null);if(!n&&!e?.optional)throw Error(`ComposerRuntime is not available`);return n}var nw=Object.defineProperty,rw=(e,t)=>{let n={};for(var r in e)nw(n,r,{get:e[r],enumerable:!0});return t||nw(n,Symbol.toStringTag,{value:`Module`}),n},iw=Symbol.for(`react.lazy`),aw=_.use;function ow(e){return typeof e==`object`&&!!e&&`then`in e}function sw(e){return typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===iw&&`_payload`in e&&ow(e._payload)}function cw(e){let t=lw(e),n=_.forwardRef((e,n)=>{let{children:r,...i}=e;sw(r)&&typeof aw==`function`&&(r=aw(r._payload));let a=_.Children.toArray(r),o=a.find(dw);if(o){let e=o.props.children,r=a.map(t=>t===o?_.Children.count(e)>1?_.Children.only(null):_.isValidElement(e)?e.props.children:null:t);return(0,K.jsx)(t,{...i,ref:n,children:_.isValidElement(e)?_.cloneElement(e,void 0,r):null})}return(0,K.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function lw(e){let t=_.forwardRef((e,t)=>{let{children:n,...r}=e;if(sw(n)&&typeof aw==`function`&&(n=aw(n._payload)),_.isValidElement(n)){let e=pw(n),i=fw(r,n.props);return n.type!==_.Fragment&&(i.ref=t?ki(t,e):e),_.cloneElement(n,i)}return _.Children.count(n)>1?_.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var uw=Symbol(`radix.slottable`);function dw(e){return _.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===uw}function fw(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 pw(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 mw=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=cw(`Primitive.${t}`),r=_.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,K.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),hw=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`];function gw(e){let t=(0,_.forwardRef)(({render:t,asChild:n,children:r,...i},a)=>{let o=e;if(t&&(0,_.isValidElement)(t)){let e=r===void 0?t.props.children:r;return(0,K.jsx)(o,{...i,asChild:!0,ref:a,children:(0,_.cloneElement)(t,void 0,e)})}return(0,K.jsx)(o,{...i,asChild:n,ref:a,children:r})});return t.displayName=typeof e==`string`?e:e.displayName??e.name??`Component`,t}function _w(e){let t=mw[e],n=gw(t);return n.displayName=`Primitive.${e}`,n}var vw=hw.reduce((e,t)=>(e[t]=_w(t),e),{}),yw=(e,t,n=[])=>{let r=(0,_.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,K.jsx)(vw.button,{...a,type:`button`,ref:r,disabled:a.disabled||!o,onClick:q(a.onClick,o)})});return r.displayName=e,r},bw=e=>Q(t=>{let{role:n,attachments:r,parts:i,branchCount:a,isLast:o,speech:s,isCopied:c,isHovering:l}=t.message;return!(e.hasBranches===!0&&a<2||e.user&&n!==`user`||e.assistant&&n!==`assistant`||e.system&&n!==`system`||e.lastOrHover===!0&&!l&&!o||e.last!==void 0&&e.last!==o||e.copied===!0&&!c||e.copied===!1&&c||e.speaking===!0&&s==null||e.speaking===!1&&s!=null||e.hasAttachments===!0&&(n!==`user`||!r?.length)||e.hasAttachments===!1&&n===`user`&&r?.length||e.hasContent===!0&&i.length===0||e.hasContent===!1&&i.length>0||e.submittedFeedback!==void 0&&(t.message.metadata.submittedFeedback?.type??null)!==e.submittedFeedback)}),xw=({children:e,...t})=>bw(t)?e:null;xw.displayName=`MessagePrimitive.If`;var Sw=(0,_.createContext)(null),Cw=()=>(0,_.useContext)(Sw),ww=({children:e})=>{let t=(0,_.useRef)(new Map),n=(0,_.useRef)([]),r=(0,_.useCallback)(()=>{let e=Array.from(t.current.entries());e.sort((e,t)=>t[1]-e[1]),n.current=e.map(([e])=>e)},[]),i=(0,_.useCallback)((e,n)=>{let i=n?.priority??0;return t.current.set(e,i),r(),()=>{t.current.delete(e),r()}},[r]),a=(0,_.useCallback)(()=>n.current,[]),o=(0,_.useMemo)(()=>({register:i,getPlugins:a}),[i,a]);return(0,K.jsx)(Sw.Provider,{value:o,children:e})},Tw=(0,_.createContext)(null),Ew=(0,_.createContext)(null),Dw=()=>{let e=(0,_.useContext)(Tw);if(!e)throw Error(`useTriggerPopoverRootContext must be used within ComposerPrimitive.TriggerPopoverRoot`);return e},Ow=()=>(0,_.useContext)(Tw),kw=()=>{let e=(0,_.useContext)(Ew);if(!e)throw Error(`useTriggerPopoverAriaPublish must be used within ComposerPrimitive.TriggerPopoverRoot`);return e},Aw=()=>{let e=Dw();return(0,_.useSyncExternalStore)(e.subscribe,e.getTriggers,e.getTriggers)},jw=new Map,Mw=()=>()=>{},Nw=()=>jw,Pw=()=>{let e=Ow();return(0,_.useSyncExternalStore)(e?e.subscribe:Mw,e?e.getTriggers:Nw,e?e.getTriggers:Nw)},Fw=()=>null,Iw=()=>{let e=Ow();return(0,_.useSyncExternalStore)(e?e.subscribeAria:Mw,e?e.getActiveAria:Fw,e?e.getActiveAria:Fw)};function Lw(){let e=(0,_.useRef)(new Set);return{notify:(0,_.useCallback)(()=>{for(let t of e.current)t()},[]),subscribe:(0,_.useCallback)(t=>(e.current.add(t),()=>{e.current.delete(t)}),[])}}var Rw=({children:e})=>{let t=(0,_.useRef)(new Map),n=(0,_.useRef)(new Set),{notify:r,subscribe:i}=Lw(),a=(0,_.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,_.useCallback)(()=>t.current,[]),s=(0,_.useCallback)(e=>(n.current.add(e),()=>{n.current.delete(e)}),[]),c=(0,_.useRef)(null),l=(0,_.useRef)(null),{notify:u,subscribe:d}=Lw(),f=(0,_.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,_.useCallback)(()=>c.current,[]),m=(0,_.useMemo)(()=>({register:a,getTriggers:o,subscribe:i,subscribeLifecycle:s,getActiveAria:p,subscribeAria:d}),[a,o,i,s,p,d]),h=(0,_.useMemo)(()=>({setActiveAria:f}),[f]);return(0,K.jsx)(Tw.Provider,{value:m,children:(0,K.jsx)(Ew.Provider,{value:h,children:e})})},zw=({children:e})=>Cw()?(0,K.jsx)(Rw,{children:e}):(0,K.jsx)(ww,{children:(0,K.jsx)(Rw,{children:e})});zw.displayName=`ComposerPrimitive.TriggerPopoverRoot`;var Bw=/\s/u;function Vw(e,t,n){let r=e.slice(0,n);for(let e=r.length-1;e>=0;e--){let n=r[e];if(Bw.test(n))return null;if(r.startsWith(t,e)){if(e>0&&!Bw.test(r[e-1]))continue;return{query:r.slice(e+t.length),offset:e}}}return null}var Hw=Bg(({text:e,triggerChar:t})=>{let[n,r]=a_(e.length),i=f_(()=>Vw(e,t,Math.min(n,e.length)),[n,e,t]);return{trigger:i,query:i?.query??``,setCursorPosition:r}});function Uw(e){return`type`in e}var Ww=Bg(({navigableList:e,isSearchMode:t,activeCategoryId:n,query:r,popoverId:i,open:a,selectItem:o,selectCategory:s,goBack:c,close:l})=>{let[u,d]=a_(0);c_(()=>{d(0)},[e]),c_(()=>{d(0)},[t,n]);let f=m_(t=>{t<0||t>=e.length||t!==u&&d(t)}),p=m_(t=>{if(!a)return!1;switch(t.key){case`ArrowDown`:return t.preventDefault(),d(t=>{let n=e.length;return n===0?0:t<n-1?t+1:0}),!0;case`ArrowUp`:return t.preventDefault(),d(t=>{let n=e.length;return n===0?0:t>0?t-1:n-1}),!0;case`Enter`:case`Tab`:{if(t.shiftKey)return!1;t.preventDefault();let n=e[u];return n&&(Uw(n)?o(n):s(n.id)),!0}case`Escape`:return t.preventDefault(),l(),!0;case`Backspace`:return n&&r===``?(t.preventDefault(),c(),!0):!1;default:return!1}}),m=e[u];return{highlightedIndex:u,highlightedItemId:a&&m?`${i}-option-${m.id}`:void 0,highlightIndex:f,handleKeyDown:p}});function Gw(e,t){return e.id.toLowerCase().includes(t)||e.label.toLowerCase().includes(t)||(e.description?.toLowerCase().includes(t)??!1)}var Kw=Bg(({adapter:e,query:t,open:n})=>{let[r,i]=a_(null);c_(()=>{n||i(null)},[n]);let a=f_(()=>!n||!e?[]:e.categories(),[n,e]),o=n?r:null,s=f_(()=>!o||!e?[]:e.categoryItems(o),[o,e]),c=f_(()=>{if(!n||!e||o||!t&&a.length>0)return null;if(e.search)return e.search(t);let r=[],i=t.toLowerCase();for(let t of a)for(let n of e.categoryItems(t.id))Gw(n,i)&&r.push(n);return r},[n,e,t,o,a]),l=c!==null,u=f_(()=>{if(l)return[];if(!t)return a;let e=t.toLowerCase();return a.filter(t=>t.label.toLowerCase().includes(e))},[a,t,l]),d=f_(()=>{if(l)return c??[];if(!t)return s;let e=t.toLowerCase();return s.filter(t=>Gw(t,e))},[s,t,l,c]);return{categories:u,items:d,isSearchMode:l,activeCategoryId:o,navigableList:f_(()=>l?c??[]:o?d:u,[l,c,o,d,u]),selectCategory:m_(e=>{i(e)}),goBack:m_(()=>{i(null)})}}),qw=Bg(({behavior:e,trigger:t,aui:n,triggerChar:r,setCursorPosition:i,onSelected:a})=>{let o=l_(null),s=m_(e=>(o.current=e,()=>{o.current===e&&(o.current=null)}));return{selectItem:m_(i=>{if(!t||!e)return;if(o.current?.(i)){a();return}let s=n.composer().getState().text,c=s.slice(0,t.offset),l=s.slice(t.offset+r.length+t.query.length),u=()=>{let t=e.formatter.serialize(i);n.composer().setText(c+t+(l.startsWith(` `)?l:` ${l}`))};e.kind===`directive`?(u(),e.onInserted?.(i)):(e.removeOnExecute?n.composer().setText(c+(l.startsWith(` `)?l.slice(1):l)):u(),e.onExecute(i)),a()}),close:m_(()=>{a(),t&&i(t.offset)}),registerSelectItemOverride:s}}),Jw=Bg(({adapter:e,text:t,triggerChar:n,behavior:r,aui:i,popoverId:a})=>{let o=x_(Hw({text:t,triggerChar:n})),s=o.trigger!==null&&e!==void 0&&r!==void 0,c=x_(Kw({adapter:e,query:o.query,open:s})),l=m_(()=>{c.goBack()}),u=x_(qw({behavior:r,trigger:o.trigger,aui:i,triggerChar:n,setCursorPosition:o.setCursorPosition,onSelected:l})),d=x_(Ww({navigableList:c.navigableList,isSearchMode:c.isSearchMode,activeCategoryId:c.activeCategoryId,query:o.query,popoverId:a,open:s,selectItem:u.selectItem,selectCategory:c.selectCategory,goBack:c.goBack,close:u.close}));return{open:s,query:o.query,activeCategoryId:c.activeCategoryId,categories:c.categories,items:c.items,highlightedIndex:d.highlightedIndex,isSearchMode:c.isSearchMode,popoverId:a,highlightedItemId:d.highlightedItemId,selectCategory:c.selectCategory,goBack:c.goBack,selectItem:u.selectItem,close:u.close,highlightIndex:d.highlightIndex,handleKeyDown:d.handleKeyDown,setCursorPosition:o.setCursorPosition,registerSelectItemOverride:u.registerSelectItemOverride}}),Yw=(0,_.createContext)(null),Xw=()=>{let e=(0,_.useContext)(Yw);if(!e)throw Error(`useTriggerPopoverScopeContext must be used within ComposerPrimitive.TriggerPopover`);return e},Zw=()=>(0,_.useContext)(Yw),Qw=(0,_.createContext)(null),$w=()=>{let e=(0,_.useContext)(Qw);if(!e)throw Error(`TriggerPopover.Directive / TriggerPopover.Action must be rendered inside ComposerPrimitive.TriggerPopover`);return e},eT=(0,_.forwardRef)(({char:e,adapter:t,"aria-label":n,children:r,...i},a)=>{let o=Uv(),s=Q(e=>e.composer.text),c=(0,_.useId)(),l=(0,_.useRef)(null),[u,d]=(0,_.useState)(null),f=(0,_.useRef)(0),p=(0,_.useCallback)(e=>(f.current+=1,l.current=e,d(e),()=>{f.current=Math.max(0,f.current-1),l.current===e&&(l.current=null,d(null))}),[e]),m=(0,_.useMemo)(()=>({register:p}),[p]),h=Nv(Jw({adapter:t,text:s,triggerChar:e,behavior:u??void 0,aui:o,popoverId:c})),g=(0,_.useRef)(h);g.current=h;let v=Dw();(0,_.useEffect)(()=>v.register({char:e,...u?{behavior:u}:{},resource:g.current}),[v,e,u]);let y=Cw();(0,_.useEffect)(()=>{if(y)return y.register(g.current)},[y]);let b=u!==null&&h.open,x=kw();return(0,_.useEffect)(()=>{if(b)return()=>{x.setActiveAria(e,null)}},[x,e,b]),(0,_.useEffect)(()=>{b&&x.setActiveAria(e,{popoverId:c,highlightedItemId:h.highlightedItemId})},[x,e,c,b,h.highlightedItemId]),(0,K.jsx)(Qw.Provider,{value:m,children:(0,K.jsx)(Yw.Provider,{value:h,children:b?(0,K.jsx)(vw.div,{role:`listbox`,id:c,"aria-label":n??`Suggestions`,"aria-activedescendant":h.highlightedItemId,"data-state":`open`,...i,ref:a,children:r}):r})})});eT.displayName=`ComposerPrimitive.TriggerPopover`;var tT=()=>{let{disabled:e,send:t}=PC(),n=(0,_.useCallback)(()=>t(),[t]);return e?null:n},nT=yw(`ComposerPrimitive.Send`,tT),rT=(0,_.forwardRef)(({onSubmit:e,...t},n)=>{let r=tT(),i=e=>{e.preventDefault(),r&&r()};return(0,K.jsx)(vw.form,{...t,ref:n,onSubmit:q(e,i)})});rT.displayName=`ComposerPrimitive.Root`;var iT=e=>{let t=ba(e),n=KC(e=>e.onScrollToBottom);(0,_.useEffect)(()=>n(t),[n,t])},aT=()=>!1,oT=()=>{},sT=e=>(0,_.useSyncExternalStore)((0,_.useCallback)(t=>{if(typeof window>`u`||e===null)return oT;let n=window.matchMedia(e);return n.addEventListener(`change`,t),()=>n.removeEventListener(`change`,t)},[e]),(0,_.useCallback)(()=>typeof window>`u`||e===null?!1:window.matchMedia(e).matches,[e]),aT);function cT(){return cT=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},cT.apply(null,arguments)}function lT(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 uT=_.useLayoutEffect,dT=function(e){var t=_.useRef(e);return uT(function(){t.current=e}),t},fT=function(e,t){if(typeof e==`function`){e(t);return}e.current=t},pT=function(e,t){var n=_.useRef();return _.useCallback(function(r){e.current=r,n.current&&fT(n.current,null),n.current=t,t&&fT(t,r)},[t])},mT={"min-height":`0`,"max-height":`none`,height:`0`,visibility:`hidden`,overflow:`hidden`,position:`absolute`,"z-index":`-1000`,top:`0`,right:`0`,display:`block`},hT=function(e){Object.keys(mT).forEach(function(t){e.style.setProperty(t,mT[t],`important`)})},gT=null,_T=function(e,t){var n=e.scrollHeight;return t.sizingStyle.boxSizing===`border-box`?n+t.borderSize:n-t.paddingSize};function vT(e,t,n,r){n===void 0&&(n=1),r===void 0&&(r=1/0),gT||(gT=document.createElement(`textarea`),gT.setAttribute(`tabindex`,`-1`),gT.setAttribute(`aria-hidden`,`true`),hT(gT)),gT.parentNode===null&&document.body.appendChild(gT);var i=e.paddingSize,a=e.borderSize,o=e.sizingStyle,s=o.boxSizing;Object.keys(o).forEach(function(e){var t=e;gT.style[t]=o[t]}),hT(gT),gT.value=t;var c=_T(gT,e);gT.value=t,c=_T(gT,e),gT.value=`x`;var l=gT.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 yT=function(){},bT=function(e,t){return e.reduce(function(e,n){return e[n]=t[n],e},{})},xT=[`borderBottomWidth`,`borderLeftWidth`,`borderRightWidth`,`borderTopWidth`,`boxSizing`,`fontFamily`,`fontSize`,`fontStyle`,`fontWeight`,`letterSpacing`,`lineHeight`,`paddingBottom`,`paddingLeft`,`paddingRight`,`paddingTop`,`tabSize`,`textIndent`,`textRendering`,`textTransform`,`width`,`wordBreak`,`wordSpacing`,`scrollbarGutter`],ST=!!document.documentElement.currentStyle,CT=function(e){var t=window.getComputedStyle(e);if(t===null)return null;var n=bT(xT,t),r=n.boxSizing;return r===``?null:(ST&&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 wT(e,t,n){var r=dT(n);_.useLayoutEffect(function(){var n=function(e){return r.current(e)};if(e)return e.addEventListener(t,n),function(){return e.removeEventListener(t,n)}},[])}var TT=function(e,t){wT(document.body,`reset`,function(n){e.current.form===n.target&&t(n)})},ET=function(e){wT(window,`resize`,e)},DT=function(e){wT(document.fonts,`loadingdone`,e)},OT=[`cacheMeasurements`,`maxRows`,`minRows`,`onChange`,`onHeightChange`],kT=_.forwardRef(function(e,t){var n=e.cacheMeasurements,r=e.maxRows,i=e.minRows,a=e.onChange,o=a===void 0?yT:a,s=e.onHeightChange,c=s===void 0?yT:s,l=lT(e,OT),u=l.value!==void 0,d=_.useRef(null),f=pT(d,t),p=_.useRef(0),m=_.useRef(),h=function(){var e=d.current,t=n&&m.current?m.current:CT(e);if(t){m.current=t;var a=vT(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 _.useLayoutEffect(h),TT(d,function(){if(!u){var e=d.current.value;requestAnimationFrame(function(){var t=d.current;t&&e!==t.value&&h()})}}),ET(h),DT(h),_.createElement(`textarea`,cT({},l,{onChange:function(e){u||h(),o(e)},ref:f}))}),AT=`(pointer: coarse) and (not (any-pointer: fine))`,jT=(0,_.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,unstable_insertNewlineOnTouchEnter:m=!1,addAttachmentOnPaste:h=!0,...g},v)=>{let y=Uv(),b=Cw(),x=Iw(),S=l??(c===!1?`none`:`enter`),C=sT(m?AT:null),w=m&&C&&S===`enter`?`none`:S,T=Q(e=>e.composer.isEditing?e.composer.text:``),E=Q(e=>e.thread.isDisabled||e.composer.dictation?.inputDisabled)||r,D=(0,_.useRef)(null),O=Ai(v,D),k=(0,_.useRef)(!1);xa(e=>{if(!D.current?.contains(e.target))return;if(b){for(let t of b.getPlugins())if(t.handleKeyDown(e))return}if(!u)return;let t=y.composer();t.getState().canCancel&&(t.cancel(),e.preventDefault())});let A=e=>{if(!E&&!e.nativeEvent.isComposing){if(b){for(let t of b.getPlugins())if(t.handleKeyDown(e))return}if(e.key===`Enter`){let t=y.thread().getState(),n=t.capabilities.queue;if(e.shiftKey&&(e.ctrlKey||e.metaKey)&&n&&S!==`none`&&y.composer().getState().canSend){e.preventDefault(),y.composer().send({steer:!0});return}if(e.shiftKey||t.isRunning&&!n)return;let r=!1;w===`ctrlEnter`?r=e.ctrlKey||e.metaKey:w===`enter`&&(r=!0),r&&(e.preventDefault(),D.current?.closest(`form`)?.requestSubmit())}}},j=async e=>{if(!h)return;let t=y.thread().getState().capabilities,n=Array.from(e.clipboardData?.files||[]);if(t.attachments&&n.length>0)try{e.preventDefault(),await Promise.all(n.map(e=>y.composer().addAttachment(e)))}catch(e){console.error(`Error adding attachment:`,e)}},M=e&&!E,N=(0,_.useCallback)(()=>{let e=D.current;!e||!M||(e.focus({preventScroll:!0}),e.setSelectionRange(e.value.length,e.value.length))},[M]);(0,_.useEffect)(()=>N(),[N]),iT(()=>{y.composer().getState().type===`thread`&&f&&N()}),(0,_.useEffect)(()=>{if(!(y.composer().getState().type!==`thread`||!d))return y.on(`thread.runStart`,N)},[d,N,y]),(0,_.useEffect)(()=>{if(!(y.composer().getState().type!==`thread`||!p))return y.on(`threadListItem.switchedTo`,N)},[p,N,y]);let P=x?{"aria-controls":x.popoverId,"aria-expanded":!0,"aria-haspopup":`listbox`,"aria-activedescendant":x.highlightedItemId}:{},F={name:`input`,value:T,...g,...P,ref:O,disabled:E,onChange:q(i,e=>{if(!y.composer().getState().isEditing)return;let t=e.nativeEvent.isComposing===!0;k.current&&!t&&(k.current=!1);let n=t||k.current;if(k_(()=>{y.composer().setText(e.target.value)}),n)return;let r=e.target.selectionStart??e.target.value.length;if(b)for(let e of b.getPlugins())e.setCursorPosition(r)}),onKeyDown:q(a,A),onCompositionStart:q(g.onCompositionStart,()=>{k.current=!0}),onCompositionEnd:q(g.onCompositionEnd,e=>{if(k.current=!1,!y.composer().getState().isEditing)return;let t=e.target;k_(()=>{y.composer().setText(t.value)});let n=t.selectionStart??t.value.length;if(b)for(let e of b.getPlugins())e.setCursorPosition(n)}),onSelect:q(s,e=>{if(k.current)return;let t=e.target,n=t.selectionStart??t.value.length;if(b)for(let e of b.getPlugins())e.setCursorPosition(n)}),onPaste:q(o,j)};if(n&&(0,_.isValidElement)(n)){let e=g.children===void 0?n.props.children:g.children;return(0,K.jsx)(Mi,{...F,children:(0,_.cloneElement)(n,void 0,e)})}return(0,K.jsx)(t?Mi:kT,{...F})});jT.displayName=`ComposerPrimitive.Input`;var MT=yw(`ComposerPrimitive.Cancel`,()=>{let{disabled:e,cancel:t}=FC();return e?null:t}),NT=yw(`ComposerPrimitive.AddAttachment`,({multiple:e=!0}={})=>{let{disabled:t,addAttachment:n}=LC(),r=Uv(),i=(0,_.useCallback)(()=>{let t=document.createElement(`input`);t.type=`file`,t.multiple=e,t.hidden=!0;let i=r.composer().getState().attachmentAccept;i!==`*`&&(t.accept=i),document.body.appendChild(t),t.onchange=e=>{let r=e.target.files;if(r){for(let e of r)n(e);document.body.removeChild(t)}},t.oncancel=()=>{(!t.files||t.files.length===0)&&document.body.removeChild(t)},t.click()},[r,e,n]);return t?null:i},[`multiple`]),PT=(0,_.forwardRef)(({disabled:e,asChild:t=!1,render:n,children:r,...i},a)=>{let[o,s]=(0,_.useState)(!1),c=Uv(),l=(0,_.useCallback)(t=>{e||(t.preventDefault(),s(!0))},[e]),u=(0,_.useCallback)(t=>{e||(t.preventDefault(),o||s(!0))},[e,o]),d=(0,_.useCallback)(t=>{if(e)return;t.preventDefault();let n=t.relatedTarget;n&&t.currentTarget.contains(n)||s(!1)},[e]),f=(0,_.useCallback)(async t=>{if(e)return;t.preventDefault(),s(!1);let n=Array.from(t.dataTransfer.files);await Promise.all(n.map(async e=>{try{await c.composer().addAttachment(e)}catch(e){console.error(`Failed to add attachment:`,e)}}))},[e,c]),p={...o?{"data-dragging":`true`}:null,...i,onDragEnterCapture:q(i.onDragEnterCapture,l),onDragOverCapture:q(i.onDragOverCapture,u),onDragLeaveCapture:q(i.onDragLeaveCapture,d),onDropCapture:q(i.onDropCapture,f),ref:a};if(n&&(0,_.isValidElement)(n)){let e=r===void 0?n.props.children:r;return(0,K.jsx)(Mi,{...p,children:(0,_.cloneElement)(n,void 0,e)})}return(0,K.jsx)(t?Mi:`div`,{...p,children:r})});PT.displayName=`ComposerPrimitive.AttachmentDropzone`;var FT=yw(`ComposerPrimitive.Dictate`,()=>{let{disabled:e,startDictation:t}=IC();return e?null:t}),IT=yw(`ComposerPrimitive.StopDictation`,()=>{let e=Uv(),t=Q(e=>e.composer.dictation!=null),n=(0,_.useCallback)(()=>{e.composer().stopDictation()},[e]);return t?n:null}),LT=(0,_.forwardRef)(({children:e,...t},n)=>{let r=Q(e=>e.composer.dictation?.transcript);return r?(0,K.jsx)(vw.span,{...t,ref:n,children:e??r}):null});LT.displayName=`ComposerPrimitive.DictationTranscript`;var RT=(0,_.forwardRef)((e,t)=>Q(e=>e.composer.quote)?(0,K.jsx)(vw.div,{...e,ref:t}):null);RT.displayName=`ComposerPrimitive.Quote`;var zT=(0,_.forwardRef)(({children:e,...t},n)=>{let r=Q(e=>e.composer.quote?.text);return r?(0,K.jsx)(vw.span,{...t,ref:n,children:e??r}):null});zT.displayName=`ComposerPrimitive.QuoteText`;var BT=(0,_.forwardRef)(({onClick:e,...t},n)=>{let r=Uv(),i=(0,_.useCallback)(()=>{r.composer().setQuote(void 0)},[r]);return(0,K.jsx)(vw.button,{type:`button`,...t,ref:n,onClick:q(e,i)})});BT.displayName=`ComposerPrimitive.QuoteDismiss`;var VT=(0,_.forwardRef)(({children:e,"aria-label":t,...n},r)=>{let{categories:i,activeCategoryId:a,isSearchMode:o,open:s}=Xw();return!s||a||o?null:(0,K.jsx)(vw.div,{role:`group`,"aria-label":t??`Categories`,...n,ref:r,children:e(i)})});VT.displayName=`ComposerPrimitive.TriggerPopoverCategories`;var HT=(0,_.forwardRef)(({categoryId:e,onClick:t,onMouseMove:n,...r},i)=>{let{selectCategory:a,highlightIndex:o,categories:s,highlightedIndex:c,activeCategoryId:l,isSearchMode:u,popoverId:d}=Xw(),f=(0,_.useCallback)(()=>{a(e)},[a,e]),p=s.findIndex(t=>t.id===e),m=!l&&!u&&p===c,h=(0,_.useCallback)(()=>{o(p)},[o,p]);return(0,K.jsx)(vw.button,{type:`button`,role:`option`,id:`${d}-option-${e}`,"aria-selected":m,"data-highlighted":m?``:void 0,...r,ref:i,onClick:q(t,f),onMouseMove:q(n,h)})});HT.displayName=`ComposerPrimitive.TriggerPopoverCategoryItem`;var UT=(0,_.forwardRef)(({children:e,"aria-label":t,...n},r)=>{let{items:i,activeCategoryId:a,isSearchMode:o,open:s}=Xw();return!s||!a&&!o?null:(0,K.jsx)(vw.div,{role:`group`,"aria-label":t??`Items`,...n,ref:r,children:e(i)})});UT.displayName=`ComposerPrimitive.TriggerPopoverItems`;var WT=(0,_.forwardRef)(({item:e,index:t,onClick:n,onMouseMove:r,...i},a)=>{let{selectItem:o,highlightIndex:s,items:c,highlightedIndex:l,activeCategoryId:u,isSearchMode:d,popoverId:f}=Xw(),p=(0,_.useCallback)(()=>{o(e)},[o,e]),m=t??c.findIndex(t=>t.id===e.id),h=(d||u!==null)&&m===l,g=(0,_.useCallback)(()=>{s(m)},[s,m]);return(0,K.jsx)(vw.button,{type:`button`,role:`option`,id:`${f}-option-${e.id}`,"aria-selected":h,"data-highlighted":h?``:void 0,...i,ref:a,onClick:q(n,p),onMouseMove:q(r,g)})});WT.displayName=`ComposerPrimitive.TriggerPopoverItem`;var GT=(0,_.forwardRef)(({onClick:e,...t},n)=>{let{activeCategoryId:r,isSearchMode:i,goBack:a,open:o}=Xw();return!o||!r||i?null:(0,K.jsx)(vw.button,{type:`button`,...t,ref:n,onClick:q(e,a)})});GT.displayName=`ComposerPrimitive.TriggerPopoverBack`;var KT=({formatter:e,onExecute:t,removeOnExecute:n})=>{let{register:r}=$w(),i=(0,_.useRef)(t);return i.current=t,(0,_.useEffect)(()=>r({kind:`action`,formatter:e??HC,onExecute:e=>i.current(e),...n===void 0?{}:{removeOnExecute:n}}),[r,e,n]),null};KT.displayName=`ComposerPrimitive.TriggerPopoverAction`;var qT=({formatter:e,onInserted:t})=>{let{register:n}=$w(),r=(0,_.useRef)(t);return r.current=t,(0,_.useEffect)(()=>n({kind:`directive`,formatter:e??HC,onInserted:e=>r.current?.(e)}),[n,e]),null};qT.displayName=`ComposerPrimitive.TriggerPopoverDirective`;var JT=Object.assign(eT,{Directive:qT,Action:KT}),YT=rw({AddAttachment:()=>NT,AttachmentByIndex:()=>SC,AttachmentDropzone:()=>PT,Attachments:()=>wC,Cancel:()=>MT,Dictate:()=>FT,DictationTranscript:()=>LT,If:()=>NC,Input:()=>jT,Queue:()=>TC,Quote:()=>RT,QuoteDismiss:()=>BT,QuoteText:()=>zT,Root:()=>rT,Send:()=>nT,StopDictation:()=>IT,Unstable_TriggerPopover:()=>JT,Unstable_TriggerPopoverBack:()=>GT,Unstable_TriggerPopoverCategories:()=>VT,Unstable_TriggerPopoverCategoryItem:()=>HT,Unstable_TriggerPopoverItem:()=>WT,Unstable_TriggerPopoverItems:()=>UT,Unstable_TriggerPopoverRoot:()=>zw,unstable_useTriggerPopoverRootContext:()=>Dw,unstable_useTriggerPopoverRootContextOptional:()=>Ow,unstable_useTriggerPopoverScopeContext:()=>Xw,unstable_useTriggerPopoverScopeContextOptional:()=>Zw,unstable_useTriggerPopoverTriggers:()=>Aw,unstable_useTriggerPopoverTriggersOptional:()=>Pw}),XT=()=>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}),ZT=()=>Q(e=>{if(e.part.type!==`image`)throw Error(`MessagePartImage can only be used inside image message parts.`);return e.part}),QT=(0,_.createContext)(null),$T=e=>({useSmoothStatus:Oy(()=>e)}),eE=({children:e})=>{let t=nE({optional:!0}),n=Uv(),[r]=(0,_.useState)(()=>$T(n.part().getState().status));return t?e:(0,K.jsx)(QT.Provider,{value:r,children:e})},tE=e=>{let t=(0,_.forwardRef)((t,n)=>(0,K.jsx)(eE,{children:(0,K.jsx)(e,{...t,ref:n})}));return t.displayName=e.displayName,t};function nE(e){let t=(0,_.useContext)(QT);if(!e?.optional&&!t)throw Error(`This component must be used within a SmoothContextProvider.`);return t}var{useSmoothStatus:rE,useSmoothStatusStore:iE}=WC(nE,`useSmoothStatus`),aE=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))}},oE=Object.freeze({type:`running`}),sE=(e,t=!1)=>{let{text:n}=e,[r,i]=(0,_.useState)(e.status.type===`running`?``:n),a=Uv(),o=Q(()=>a.part()),[s,c]=(0,_.useState)(o);(o!==s||!n.startsWith(r))&&(c(o),i(e.status.type===`running`?``:n));let l=iE({optional:!0}),u=ba(t=>{if(i(t),l){let n=r!==t||e.status.type===`running`?oE:e.status;XC(l).setState(n,!0)}});(0,_.useEffect)(()=>{if(l){let i=t&&(r!==n||e.status.type===`running`)?oE:e.status;XC(l).setState(i,!0)}},[l,t,n,r,e.status]);let[d]=(0,_.useState)(new aE(r,u)),f=(0,_.useRef)(o);return(0,_.useEffect)(()=>{if(!t){d.stop();return}let r=f.current!==o;if(f.current=o,r||!n.startsWith(d.targetText)){e.status.type===`running`?(d.currentText=``,d.targetText=n,d.start()):(d.currentText=n,d.targetText=n,d.stop());return}d.targetText=n,d.start()},[d,t,n,e.status.type,o]),(0,_.useEffect)(()=>()=>{d.stop()},[d]),(0,_.useMemo)(()=>t?{type:`text`,text:r,status:n===r?e.status:oE}:e,[t,r,e,n])},cE=(0,_.forwardRef)(({smooth:e=!0,component:t=`span`,...n},r)=>{let{text:i,status:a}=sE(XT(),e);return(0,K.jsx)(t,{"data-status":a.type,...n,ref:r,children:i})});cE.displayName=`MessagePartPrimitive.Text`;var lE=(0,_.forwardRef)((e,t)=>{let{image:n}=ZT();return(0,K.jsx)(vw.img,{src:n,...e,ref:t})});lE.displayName=`MessagePartPrimitive.Image`;var uE=e=>{let t=(0,_.useRef)(void 0);return(0,_.useCallback)(n=>{t.current&&=(t.current(),void 0),n&&(t.current=e(n))},[e])},dE=(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},fE=e=>e.dataset.messageId,pE=()=>{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},mE=(e,t)=>{let n=`${t}px`;return e.style.height===n?!1:(e.style.height=n,!0)},hE=e=>{let t=window.devicePixelRatio||1;return Math.round(e*t)/t},gE=()=>{let e=Uv(),t=Q(()=>e.message());return uE((0,_.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]))},_E=()=>{let e=KC(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))},vE=()=>{let e=KC(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))},yE=(e,t)=>uE((0,_.useCallback)(n=>{if(e)return t.getState().registerAnchorElement(n)},[e,t])),bE=({active:e,threadViewportStore:t})=>uE((0,_.useCallback)(n=>{if(!e)return;let r=t.getState(),i=r.topAnchorMessageClamp;return r.registerAnchorTargetElement(n,{tallerThan:dE(i.tallerThan,n),visibleHeight:dE(i.visibleHeight,n)})},[e,t])),xE=({forwardedRef:e,...t})=>{let n=Ai(e,gE()),r=Q(e=>e.message.id);return(0,K.jsx)(vw.div,{...t,ref:n,"data-message-id":r})},SE=({forwardedRef:e,threadViewportStore:t,...n})=>{let r=gE(),i=_E(),a=vE(),o=Ai(e,r,yE(i,t),bE({active:a,threadViewportStore:t})),s=Q(e=>e.message.id);return(0,K.jsx)(vw.div,{...n,ref:o,"data-message-id":s,"data-aui-top-anchor-user":i?``:void 0,"data-aui-top-anchor-target":a?``:void 0})},CE=(0,_.forwardRef)((e,t)=>{let n=qC();return n.getState().turnAnchor===`top`?(0,K.jsx)(SE,{...e,forwardedRef:t,threadViewportStore:n}):(0,K.jsx)(xE,{...e,forwardedRef:t})});CE.displayName=`MessagePrimitive.Root`;var wE={...HS,Text:()=>(0,K.jsxs)(`p`,{style:{whiteSpace:`pre-line`},children:[(0,K.jsx)(cE,{}),(0,K.jsx)(EC,{children:(0,K.jsx)(`span`,{style:{fontFamily:`revert`},children:` ●`})})]}),Image:()=>(0,K.jsx)(lE,{})},TE=e=>{if(`children`in e)return(0,K.jsx)(iC,{children:e.children});let{components:t,...n}=e;return(0,K.jsx)(iC,{components:t?{Text:t.Text??wE.Text,Image:t.Image??wE.Image,Reasoning:t.Reasoning??HS.Reasoning,Source:t.Source??HS.Source,File:t.File??HS.File,Unstable_Audio:t.Unstable_Audio??HS.Unstable_Audio,...`ChainOfThought`in t?{ChainOfThought:t.ChainOfThought}:{tools:t.tools,data:t.data,ToolGroup:t.ToolGroup??HS.ToolGroup,ReasoningGroup:t.ReasoningGroup??HS.ReasoningGroup},Empty:t.Empty,Quote:t.Quote,generativeUI:t.generativeUI}:wE,...n})};TE.displayName=`MessagePrimitive.Parts`;var EE=({children:e})=>zC()===void 0?null:e;EE.displayName=`MessagePrimitive.Error`;var DE=e=>{let t=new Map;for(let n=0;n<e.length;n++){let r=e[n]?.parentId??`__ungrouped_${n}`,i=t.get(r)??[];i.push(n),t.set(r,i)}let n=[];for(let[e,r]of t){let t=e.startsWith(`__ungrouped_`)?void 0:e;n.push({groupKey:t,indices:r})}return n},OE=e=>{let t=Q(e=>e.message.parts);return(0,_.useMemo)(()=>t.length===0?[]:e(t),[t,e])},kE=({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,K.jsx)(n,{...t}):null},AE=({Fallback:e,...t})=>{let n=Q(n=>{let r=n.dataRenderers.renderers[t.name]??e;return Array.isArray(r)?r[0]??e:r});return n?(0,K.jsx)(n,{...t}):null},jE={Text:()=>(0,K.jsxs)(`p`,{style:{whiteSpace:`pre-line`},children:[(0,K.jsx)(cE,{}),(0,K.jsx)(EC,{children:(0,K.jsx)(`span`,{style:{fontFamily:`revert`},children:` ●`})})]}),Reasoning:()=>null,Source:()=>null,Image:()=>(0,K.jsx)(lE,{}),File:()=>null,Unstable_Audio:()=>null,Group:({children:e})=>e},ME=({components:{Text:e=jE.Text,Reasoning:t=jE.Reasoning,Image:n=jE.Image,Source:r=jE.Source,File:i=jE.File,Unstable_Audio:a=jE.Unstable_Audio,tools:o={},data:s}={}})=>{let c=Uv(),l=Q(e=>e.part),u=l.type;if(u===`tool-call`){let e=c.part().addToolResult,t=c.part().resumeToolCall,n=c.part().respondToToolApproval;if(`Override`in o)return(0,K.jsx)(o.Override,{...l,addResult:e,resume:t,respondToApproval:n});let r=o.by_name?.[l.toolName]??o.Fallback;return(0,K.jsx)(kE,{...l,Fallback:r,addResult:e,resume:t,respondToApproval:n})}if(l.status?.type===`requires-action`)throw Error(`Encountered unexpected requires-action status`);switch(u){case`text`:return(0,K.jsx)(e,{...l});case`reasoning`:return(0,K.jsx)(t,{...l});case`source`:return(0,K.jsx)(r,{...l});case`image`:return(0,K.jsx)(n,{...l});case`file`:return(0,K.jsx)(i,{...l});case`audio`:return(0,K.jsx)(a,{...l});case`data`:{let e=s?.by_name?.[l.name]??s?.Fallback;return(0,K.jsx)(AE,{...l,Fallback:e})}default:return console.warn(`Unknown message part type: ${u}`),null}},NE=(0,_.memo)(({partIndex:e,components:t})=>(0,K.jsx)(xb,{index:e,children:(0,K.jsx)(ME,{components:t})}),(e,t)=>e.partIndex===t.partIndex&&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?.Group===t.components?.Group),PE=({status:e,component:t})=>(0,K.jsx)(Cb,{text:``,isRunning:e.type===`running`,children:(0,K.jsx)(t,{type:`text`,text:``,status:e})}),FE=Object.freeze({type:`complete`}),IE=(0,_.memo)(({components:e})=>{let t=Q(e=>e.message.status??FE);return e?.Empty?(0,K.jsx)(e.Empty,{status:t}):(0,K.jsx)(PE,{status:t,component:e?.Text??jE.Text})},(e,t)=>e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),LE=({groupingFunction:e,components:t})=>{let n=Q(e=>e.message.parts.length),r=OE(e);return(0,K.jsx)(K.Fragment,{children:(0,_.useMemo)(()=>n===0?(0,K.jsx)(IE,{components:t}):r.map((e,n)=>(0,K.jsx)(t?.Group??jE.Group,{groupKey:e.groupKey,indices:e.indices,children:e.indices.map(e=>(0,K.jsx)(NE,{partIndex:e,components:t},e))},`group-${n}-${e.groupKey??`ungrouped`}`)),[r,t,n])})};LE.displayName=`MessagePrimitive.Unstable_PartsGrouped`;var RE=({components:e,...t})=>(0,K.jsx)(LE,{...t,components:e,groupingFunction:DE});RE.displayName=`MessagePrimitive.Unstable_PartsGroupedByParentId`;var zE=rw({AttachmentByIndex:()=>_C,Attachments:()=>yC,Content:()=>TE,Error:()=>EE,GenerativeUI:()=>DS,GroupedParts:()=>pC,If:()=>xw,PartByIndex:()=>WS,Parts:()=>TE,Quote:()=>mC,Root:()=>CE,Unstable_PartsGrouped:()=>LE,Unstable_PartsGroupedByParentId:()=>RE}),BE=e=>{let t=ba(e);return uE((0,_.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]))},VE=({autoScroll:e,scrollToBottomOnRunStart:t=!0,scrollToBottomOnInitialize:n=!0,scrollToBottomOnThreadSwitch:r=!0})=>{let i=(0,_.useRef)(null),a=Q(e=>e.thread.messages.length>0),o=(0,_.useRef)(!1),s=(0,_.useRef)(null),c=qC();e===void 0&&(e=c.getState().turnAnchor!==`top`);let l=(0,_.useRef)(0),u=(0,_.useRef)(0),d=(0,_.useRef)(0),f=(0,_.useRef)(0),p=(0,_.useRef)(null),m=(0,_.useCallback)(e=>{let t=i.current;t&&(p.current=e,t.scrollTo({top:t.scrollHeight,behavior:e}))},[]),h=(0,_.useCallback)(e=>{p.current=e,s.current!==null&&cancelAnimationFrame(s.current),s.current=requestAnimationFrame(()=>{s.current=null,m(e)})},[m]);(0,_.useLayoutEffect)(()=>()=>{s.current!==null&&cancelAnimationFrame(s.current)},[]);let g=(0,_.useCallback)(()=>{let e=c.getState();return e.turnAnchor===`top`&&e.element.viewport===i.current&&e.element.anchor!==null},[c]),v=()=>{let e=i.current;if(!e)return;let t=c.getState().isAtBottom,n=Math.abs(e.scrollHeight-e.scrollTop-e.clientHeight)<=1||e.scrollHeight<=e.clientHeight;!n&&l.current<e.scrollTop||(n?e.scrollHeight>e.clientHeight+1&&(p.current=null):l.current>e.scrollTop&&u.current===e.scrollHeight&&(p.current=null),(n||p.current===null)&&n!==t&&XC(c).setState({isAtBottom:n})),l.current=e.scrollTop,u.current=e.scrollHeight},y=BE(()=>{let t=i.current;if(!t)return;let{scrollHeight:n,clientHeight:r}=t;if(n===d.current&&r===f.current)return;d.current=n,f.current=r;let a=p.current;a&&g()?p.current=null:a?m(a):e&&c.getState().isAtBottom&&m(`instant`),v()}),b=uE(e=>(e.addEventListener(`scroll`,v),()=>{e.removeEventListener(`scroll`,v)}));return(0,_.useLayoutEffect)(()=>{if(n){if(!a){o.current=!1;return}o.current||(o.current=!0,p.current===null&&h(`instant`))}},[a,h,n]),iT(({behavior:e})=>{m(e)}),$v(`thread.runStart`,()=>{t&&c.getState().turnAnchor!==`top`&&h(`auto`)}),$v(`threadListItem.switchedTo`,()=>{r&&h(`instant`)}),Ai(y,b,i)},HE=(0,_.forwardRef)((e,t)=>(0,K.jsx)(vw.div,{...e,ref:t}));HE.displayName=`ThreadPrimitive.Root`;var UE=({children:e})=>Q(e=>e.thread.isEmpty)?e:null;UE.displayName=`ThreadPrimitive.Empty`;var WE=e=>Q(t=>!(e.empty===!0&&!t.thread.isEmpty||e.empty===!1&&t.thread.isEmpty||e.running===!0&&!t.thread.isRunning||e.running===!1&&t.thread.isRunning||e.disabled===!0&&!t.thread.isDisabled||e.disabled===!1&&t.thread.isDisabled)),GE=({children:e,...t})=>WE(t)?e:null;GE.displayName=`ThreadPrimitive.If`;var KE=(e,t)=>uE((0,_.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])),qE=e=>{let t=0,n=e;for(;n;)t+=n.offsetTop,n=n.offsetParent;return t},JE=(e,t)=>{let n=0,r=e;for(;r&&r!==t;)n+=r.offsetTop,r=r.offsetParent;return r===t?n:qE(e)-qE(t)},YE=({viewport:e,anchor:t,tallerThan:n,visibleHeight:r})=>{let i=JE(t,e),a=t.offsetHeight;return i+Math.max(0,a-(a<=n?a:r))},XE=({scrollHeight:e,...t})=>{let{viewport:n}=t,r=YE(t)+n.clientHeight;return Math.max(0,r-e)},ZE=({viewport:e,reserve:t,...n})=>XE({viewport:e,...n,scrollHeight:e.scrollHeight-t.offsetHeight}),QE=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}},$E=e=>{let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},cancel:()=>{t!==null&&(cancelAnimationFrame(t),t=null)}}},eD=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&&(mE(t,0),t.remove());return}if(t??=pE(),(t.parentElement!==c.parentElement||t.previousElementSibling!==c)&&c.after(t),a.target(o,s,c),mE(t,ZE({viewport:o,anchor:s,reserve:t,...l}))){i.schedule();return}let u=fE(s);if(u!==void 0&&n===u)return;let d=hE(YE({viewport:o,anchor:s,...l}));Math.abs(o.scrollTop-d)>1&&o.scrollTo({top:d,behavior:`smooth`}),u!==void 0&&(n=u)}let i=$E(r),a=QE(i.schedule);i.schedule();let o=e.subscribe(i.schedule);return()=>{i.cancel(),o(),a.disconnect(),t?.remove()}},tD=e=>{let t=qC();(0,_.useLayoutEffect)(()=>{if(e)return eD(t)},[e,t])},nD=({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}},rD=e=>nD(e)?.anchorId,iD=e=>nD(e)?.targetId,aD=()=>KE(KC(e=>e.registerViewport),(0,_.useCallback)(e=>e.clientHeight,[])),oD=()=>uE(KC(e=>e.registerViewportElement)),sD=e=>{let t=qC(),n=Q(t=>{if(e)return rD(t.thread)}),r=Q(t=>{if(e)return iD(t.thread)}),i=(0,_.useMemo)(()=>!n||!r?null:{anchorId:n,targetId:r},[n,r]);(0,_.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,_.useCallback)(()=>{t.getState().setTopAnchorTurn(null)},[t]);$v(`thread.initialize`,a),$v(`threadListItem.switchedTo`,a)},cD=(0,_.forwardRef)(({autoScroll:e,scrollToBottomOnRunStart:t,scrollToBottomOnInitialize:n,scrollToBottomOnThreadSwitch:r,children:i,...a},o)=>{let s=VE({autoScroll:e,scrollToBottomOnRunStart:t,scrollToBottomOnInitialize:n,scrollToBottomOnThreadSwitch:r}),c=aD(),l=oD(),u=qC().getState().turnAnchor===`top`;sD(u),tD(u);let d=Ai(o,s,c,l);return(0,K.jsx)(vw.div,{...a,ref:d,children:i})});cD.displayName=`ThreadPrimitive.ViewportScrollable`;var lD=(0,_.forwardRef)(({turnAnchor:e,topAnchorMessageClamp:t,...n},r)=>(0,K.jsx)(QC,{options:{turnAnchor:e,topAnchorMessageClamp:t},children:(0,K.jsx)(cD,{...n,ref:r})}));lD.displayName=`ThreadPrimitive.Viewport`;var uD=(0,_.forwardRef)((e,t)=>{let n=Ai(t,KE(KC(e=>e.registerContentInset),(0,_.useCallback)(e=>{let t=parseFloat(getComputedStyle(e).marginTop)||0;return e.offsetHeight+t},[])));return(0,K.jsx)(vw.div,{...e,ref:n})});uD.displayName=`ThreadPrimitive.ViewportFooter`;var dD=yw(`ThreadPrimitive.ScrollToBottom`,({behavior:e}={})=>{let t=KC(e=>e.isAtBottom),n=qC(),r=(0,_.useCallback)(()=>{n.getState().scrollToBottom({behavior:e})},[n,e]);return t?null:r},[`behavior`]),fD=yw(`ThreadPrimitive.Suggestion`,({prompt:e,send:t,clearComposer:n,autoSend:r,method:i})=>{let{disabled:a,trigger:o}=RC({prompt:e,send:t??r??!1,clearComposer:n});return a?null:o},[`prompt`,`send`,`clearComposer`,`autoSend`,`method`]),pD=rw({Empty:()=>UE,If:()=>GE,MessageByIndex:()=>_S,Messages:()=>bS,Root:()=>HE,ScrollToBottom:()=>dD,Suggestion:()=>fD,SuggestionByIndex:()=>OC,Suggestions:()=>jC,Viewport:()=>lD,ViewportFooter:()=>uD,ViewportProvider:()=>QC}),mD=rw({AssistantRuntimeImpl:()=>vx,BaseAssistantRuntimeCore:()=>yx,CompositeContextProvider:()=>L_,DefaultThreadComposerRuntimeCore:()=>qx,MessageRepository:()=>Bx,ThreadRuntimeImpl:()=>ux,fromThreadMessageLike:()=>Ix,generateId:()=>Dx,getAutoStatus:()=>Px,splitLocalRuntimeOptions:()=>BC,useComposerInputPluginRegistryOptional:()=>Cw,useSmooth:()=>sE,useSmoothStatus:()=>rE,withSmoothContextProvider:()=>tE});function hD(e,t){let n=getComputedStyle(e);return t*parseFloat(n.fontSize)}function gD(e,t){let n=getComputedStyle(e.ownerDocument.documentElement);return t*parseFloat(n.fontSize)}function _D(e){return e/100*window.innerHeight}function vD(e){return e/100*window.innerWidth}function yD(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 bD({groupSize:e,panelElement:t,styleProp:n}){let r,[i,a]=yD(n);switch(a){case`%`:r=i/100*e;break;case`px`:r=i;break;case`rem`:r=gD(t,i);break;case`em`:r=hD(t,i);break;case`vh`:r=_D(i);break;case`vw`:r=vD(i);break}return r}function xD(e){return parseFloat(e.toFixed(3))}function SD({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 CD(e){let{panels:t}=e,n=SD({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=xD(bD({groupSize:n,panelElement:t,styleProp:r.collapsedSize})/n*100));let a;r.defaultSize!==void 0&&(a=xD(bD({groupSize:n,panelElement:t,styleProp:r.defaultSize})/n*100));let o=0;r.minSize!==void 0&&(o=xD(bD({groupSize:n,panelElement:t,styleProp:r.minSize})/n*100));let s=100;return r.maxSize!==void 0&&(s=xD(bD({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 wD(e,t=`Assertion error`){if(!e)throw Error(t)}function TD(e,t){return Array.from(t).sort(e===`horizontal`?ED:DD)}function ED(e,t){let n=e.element.offsetLeft-t.element.offsetLeft;return n===0?e.element.offsetWidth-t.element.offsetWidth:n}function DD(e,t){let n=e.element.offsetTop-t.element.offsetTop;return n===0?e.element.offsetHeight-t.element.offsetHeight:n}function OD(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.ELEMENT_NODE}function kD(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 AD({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}=kD(r,n),s=e===`horizontal`?t:o;s<a&&(a=s,i=n)}return wD(i,`No rect found`),i}var jD;function MD(){return jD===void 0&&(jD=typeof matchMedia==`function`?!!matchMedia(`(pointer:coarse)`).matches:!1),jD}function ND(e){let{element:t,orientation:n,panels:r,separators:i}=e,a=TD(n,Array.from(t.children).filter(OD).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,AD({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=MD()?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:SD({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 PD=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)}}},FD=new Map,ID=new PD;function LD(e){FD=new Map(FD),FD.delete(e)}function RD(e,t){for(let[t]of FD)if(t.id===e)return t}function zD(e,t){for(let[t,n]of FD)if(t.id===e)return n;if(t)throw Error(`Could not find data for Group with id ${e}`)}function BD(){return FD}function VD(e,t){return ID.addListener(`groupChange`,n=>{n.group.id===e&&t(n)})}function HD(e,t){let n=FD.get(e);FD=new Map(FD),FD.set(e,t),ID.emit(`groupChange`,{group:e,prev:n,next:t})}function UD(e,t,n){let r,i={x:1/0,y:1/0};for(let a of t){let t=kD(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 WD(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function GD(e,t){if(e===t)throw Error(`Cannot compare node with itself`);let n={a:ZD(e),b:ZD(t)},r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();wD(r,`Stacking order can only be calculated for elements with a common ancestor`);let i={a:XD(YD(n.a)),b:XD(YD(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 KD=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function qD(e){let t=getComputedStyle(QD(e)??e).display;return t===`flex`||t===`inline-flex`}function JD(e){let t=getComputedStyle(e);return!!(t.position===`fixed`||t.zIndex!==`auto`&&(t.position!==`static`||qD(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`||KD.test(t.willChange)||t.webkitOverflowScrolling===`touch`)}function YD(e){let t=e.length;for(;t--;){let n=e[t];if(wD(n,`Missing node`),JD(n))return n}return null}function XD(e){return e&&Number(getComputedStyle(e).zIndex)||0}function ZD(e){let t=[];for(;e;)t.push(e),e=QD(e);return t}function QD(e){let{parentNode:t}=e;return WD(t)?t.host:t}function $D(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 eO({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!OD(n)||n.contains(e)||e.contains(n))return!0;if(GD(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if($D(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function tO(e,t){let n=[];return t.forEach((t,r)=>{if(r.disabled)return;let i=ND(r),a=UD(r.orientation,i,{x:e.clientX,y:e.clientY});a&&a.distance.x<=0&&a.distance.y<=0&&eO({groupElement:r.element,hitRegion:a.hitRegion.rect,pointerEventTarget:e.target})&&n.push(a.hitRegion)}),n}function nO(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 rO(e,t,n=0){return Math.abs(xD(e)-xD(t))<=n}function iO(e,t){return rO(e,t)?0:e>t?1:-1}function aO({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(iO(r,c)<0)if(a){let e=(i+c)/2;r=iO(r,e)<0?i:c}else r=c;return r=Math.min(s,r),r=xD(r),r}function oO({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:a}){if(rO(e,0))return t;let o=a===`imperative-api`,s=Object.values(t),c=Object.values(i),l=[...s],[u,d]=r;wD(u!=null,`Invalid first pivot index`),wD(d!=null,`Invalid second pivot index`);let f=0;switch(a){case`keyboard`:{let t=e<0?d:u,r=n[t];wD(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(wD(n!=null,`Previous layout not found for panel index ${t}`),rO(n,i)){let t=o-n;iO(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}{let t=e<0?u:d,r=n[t];wD(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(wD(n!=null,`Previous layout not found for panel index ${t}`),rO(n,o)){let t=n-i;iO(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}break;default:{let t=e<0?d:u,r=n[t];wD(r,`Panel constraints not found for index ${t}`);let i=s[t],{collapsible:a,collapsedSize:o,minSize:c}=r;if(a&&iO(i,c)<0)if(e>0){let t=c-o,n=t/2;iO(i+e,c)<0&&(e=iO(e,n)<=0?0:t)}else{let t=c-o,n=100-t/2;iO(i-e,c)<0&&(e=iO(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];wD(e!=null,`Previous layout not found for panel index ${r}`);let a=aO({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];wD(i!=null,`Previous layout not found for panel index ${t}`);let a=i-r,c=aO({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:i,size:a});if(!rO(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(nO(c,l))return i;{let t=e<0?d:u,r=s[t];wD(r!=null,`Previous layout not found for panel index ${t}`);let i=r+f,a=aO({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:r,size:i});if(l[t]=a,!rO(a,i)){let t=i-a,r=e<0?d:u;for(;r>=0&&r<n.length;){let i=l[r];wD(i!=null,`Previous layout not found for panel index ${r}`);let a=i+t,s=aO({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:i,size:a});if(rO(i,s)||(t-=s-i,l[r]=s),rO(t,0))break;e>0?r--:r++}}}if(!rO(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 sO(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(t[n]===void 0||iO(e[n],t[n])!==0)return!1;return!0}function cO({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(!rO(i,100)&&r.length>0)for(let e=0;e<t.length;e++){let t=r[e];wD(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];wD(i!=null,`No layout data found for index ${e}`);let o=r[e];wD(o!=null,`No layout data found for index ${e}`);let s=aO({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:i,size:o});o!=s&&(a+=o-s,r[e]=s)}if(!rO(a,0))for(let e=0;e<t.length;e++){let n=r[e];wD(n!=null,`No layout data found for index ${e}`);let i=n+a,o=aO({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:n,size:i});if(n!==o&&(a-=o-n,r[e]=o,rO(a,0)))break}let o=Object.keys(e);return r.reduce((e,t,n)=>(e[o[n]]=t,e),{})}function lO({groupId:e,panelId:t}){let n=()=>{let t=BD();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&&rO(n.collapsedSize,r[n.panelId])}))){let e=n.slice(0,s).reduce((e,t)=>e+r[t.id],0);return{...r,[t]:xD(100-e)}}return oO({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=cO({layout:o({nextSize:e,panels:i.panels,prevLayout:c,derivedPanelConstraints:r}),panelConstraints:r});sO(c,u)||HD(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&&rO(t,n)},resize:e=>{let{group:t}=n(),{element:r}=i(),a=SD({group:t});s(xD(bD({groupSize:a,panelElement:r,styleProp:e})/a*100))}}}function uO(e){e.defaultPrevented||tO(e,BD()).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=lO({groupId:t.group.id,panelId:n.id});i&&r!==void 0&&(i.resize(r),e.preventDefault())}}})}function dO(e){let t=BD();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 fO({groupId:e}){let t=()=>{let t=BD();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=cO({layout:e,panelConstraints:r});return n?o:(sO(o,c)||HD(i,{defaultLayoutDeferred:n,derivedPanelConstraints:r,groupSize:a,layout:c,separatorToPanels:s}),c)}}}function pO(e,t){let n=dO(e),r=zD(n.id,!0),i=n.separators.find(t=>t.element===e);wD(i,`Matching separator not found`);let a=r.separatorToPanels.get(i);wD(a,`Matching panels not found`);let o=a.map(e=>n.panels.indexOf(e)),s=fO({groupId:n.id}).getLayout(),c=cO({layout:oO({delta:t,initialLayout:s,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:s,trigger:`keyboard`}),panelConstraints:r.derivedPanelConstraints});sO(s,c)||HD(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels})}function mO(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=dO(t);if(!n.disabled)switch(e.key){case`ArrowDown`:e.preventDefault(),n.orientation===`vertical`&&pO(t,5);break;case`ArrowLeft`:e.preventDefault(),n.orientation===`horizontal`&&pO(t,-5);break;case`ArrowRight`:e.preventDefault(),n.orientation===`horizontal`&&pO(t,5);break;case`ArrowUp`:e.preventDefault(),n.orientation===`vertical`&&pO(t,-5);break;case`End`:e.preventDefault(),pO(t,100);break;case`Enter`:{e.preventDefault();let n=dO(t),{derivedPanelConstraints:r,layout:i,separatorToPanels:a}=zD(n.id,!0),o=n.separators.find(e=>e.element===t);wD(o,`Matching separator not found`);let s=a.get(o);wD(s,`Matching panels not found`);let c=s[0],l=r.find(e=>e.panelId===c.id);if(wD(l,`Panel metadata not found`),l.collapsible){let e=i[c.id];pO(t,(l.collapsedSize===e?n.mutableState.expandedPanelSizes[c.id]??l.minSize:l.collapsedSize)-e)}break}case`F6`:{e.preventDefault();let n=dO(t).separators.map(e=>e.element),r=Array.from(n).findIndex(t=>t===e.currentTarget);wD(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(),pO(t,-100);break}}var hO={cursorFlags:0,state:`inactive`},gO=new PD;function _O(){return hO}function vO(e){return gO.addListener(`change`,e)}function yO(e){let t=hO,n={...hO};n.cursorFlags=e,hO=n,gO.emit(`change`,{prev:t,next:n})}function bO(e){let t=hO;hO=e,gO.emit(`change`,{prev:t,next:e})}function xO(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=BD(),n=tO(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)}),bO({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:`active`}),n.length&&e.preventDefault()}var SO=e=>e,CO=()=>{},wO=1,TO=2,EO=4,DO=8,OO=3,kO=12,AO;function jO(){return AO===void 0&&(AO=!1,typeof window<`u`&&(window.navigator.userAgent.includes(`Chrome`)||window.navigator.userAgent.includes(`Firefox`))&&(AO=!0)),AO}function MO({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&&jO()){let t=(e&wO)!==0,n=(e&TO)!==0,r=(e&EO)!==0,i=(e&DO)!==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 jO()?r>0&&i>0?`move`:r>0?`ew-resize`:`ns-resize`:r>0&&i>0?`grab`:r>0?`col-resize`:`row-resize`}}var NO=new WeakMap;function PO(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=NO.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=_O();switch(r.state){case`active`:case`hover`:{let e=MO({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}NO.set(e,{prevStyle:t,styleSheet:n})}function FO({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=oO({delta:d,initialLayout:f,panelConstraints:h,pivotIndices:e.panels.map(e=>l.indexOf(e)),prevLayout:_,trigger:`mouse-or-touch`});if(sO(t,_)){if(d!==0&&!u)switch(c){case`horizontal`:s|=d<0?wO:TO;break;case`vertical`:s|=d<0?EO:DO;break}}else HD(e.group,{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:t,separatorToPanels:v})}});let c=0;t.movementX===0?c|=o&OO:c|=s&OO,t.movementY===0?c|=o&kO:c|=s&kO,yO(c),PO(e)}function IO(e){let t=BD(),n=_O();switch(n.state){case`active`:FO({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function LO(e){if(e.defaultPrevented)return;let t=_O(),n=BD();switch(t.state){case`active`:if(e.buttons===0){bO({cursorFlags:0,state:`inactive`}),t.hitRegions.forEach(e=>{let t=zD(e.group.id,!0);HD(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)}FO({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break;default:{let r=tO(e,n);r.length===0?t.state!==`inactive`&&bO({cursorFlags:0,state:`inactive`}):bO({cursorFlags:0,hitRegions:r,state:`hover`}),PO(e.currentTarget);break}}}function RO(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(_O().state){case`hover`:bO({cursorFlags:0,state:`inactive`})}}function zO(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=_O();switch(t.state){case`active`:bO({cursorFlags:0,state:`inactive`}),t.hitRegions.length>0&&(PO(e.currentTarget),t.hitRegions.forEach(e=>{let t=zD(e.group.id,!0);HD(e.group,t)}),e.preventDefault())}}function BO(e){let t=0,n=0,r={};for(let i of e)if(i.defaultSize!==void 0){t++;let e=xD(i.defaultSize);n+=e,r[i.panelId]=e}else r[i.panelId]=void 0;let i=e.length-t;if(i!==0){let t=xD((100-n)/i);for(let n of e)n.defaultSize===void 0&&(r[n.panelId]=t)}return r}function VO(e,t,n){if(!n[0])return;let r=e.panels.find(e=>e.element===t);if(!r||!r.onResize)return;let i=SD({group:e}),a=e.orientation===`horizontal`?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,s={asPercentage:xD(a/i*100),inPixels:a};r.mutableValues.prevSize=s,r.onResize(s,r.id,o)}function HO(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 UO({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=xD(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]=xD((r[e]??0)/a*l);else{let e=xD(l/c.length);for(let t of c)u[t]=e}return u}function WO(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 GO=new Map;function KO(e){let t=!0;wD(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=SD({group:e});if(t===0)return;let n=zD(e.id);if(!n)return;let r=CD(e),i=n.defaultLayoutDeferred?BO(r):n.layout,a=cO({layout:UO({group:e,nextGroupSize:t,prevGroupSize:n.groupSize,prevLayout:i}),panelConstraints:r});if(!n.defaultLayoutDeferred&&sO(n.layout,a)&&HO(n.derivedPanelConstraints,r)&&n.groupSize===t)return;HD(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:r,groupSize:t,layout:a,separatorToPanels:n.separatorToPanels})}}else VO(e,i,n)}});a.observe(e.element),e.panels.forEach(e=>{wD(!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=SD({group:e}),s=CD(e),c=e.panels.map(({id:e})=>e).join(`,`),l=e.mutableState.defaultLayout;l&&(WO(e.panels,l)||(l=void 0));let u=cO({layout:e.mutableState.layouts[c]??l??BO(s),panelConstraints:s}),d=e.element.ownerDocument;GO.set(d,(GO.get(d)??0)+1);let f=new Map;return ND(e).forEach(e=>{e.separator&&f.set(e.separator,e.panels)}),HD(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:s,groupSize:o,layout:u,separatorToPanels:f}),e.separators.forEach(e=>{wD(!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`,mO)}),GO.get(d)===1&&(d.addEventListener(`dblclick`,uO,!0),d.addEventListener(`pointerdown`,xO,!0),d.addEventListener(`pointerleave`,IO),d.addEventListener(`pointermove`,LO),d.addEventListener(`pointerout`,RO),d.addEventListener(`pointerup`,zO,!0)),function(){t=!1,GO.set(d,Math.max(0,(GO.get(d)??0)-1)),LD(e),e.separators.forEach(e=>{e.element.removeEventListener(`keydown`,mO)}),GO.get(d)||(d.removeEventListener(`dblclick`,uO,!0),d.removeEventListener(`pointerdown`,xO,!0),d.removeEventListener(`pointerleave`,IO),d.removeEventListener(`pointermove`,LO),d.removeEventListener(`pointerout`,RO),d.removeEventListener(`pointerup`,zO,!0)),a.disconnect()}}function qO(){let[e,t]=(0,_.useState)({});return[e,(0,_.useCallback)(()=>t({}),[])]}function JO(e){let t=(0,_.useId)();return`${e??t}`}var YO=typeof window<`u`?_.useLayoutEffect:_.useEffect;function XO(e){let t=(0,_.useRef)(e);return YO(()=>{t.current=e},[e]),(0,_.useCallback)((...e)=>t.current?.(...e),[t])}function ZO(...e){return XO(t=>{e.forEach(e=>{if(e)switch(typeof e){case`function`:e(t);break;case`object`:e.current=t;break}})})}function QO(e){let t=(0,_.useRef)({...e});return YO(()=>{for(let n in e)t.current[n]=e[n]},[e]),t.current}var $O=(0,_.createContext)(null);function ek(e,t){let n=(0,_.useRef)({getLayout:()=>({}),setLayout:SO});(0,_.useImperativeHandle)(t,()=>n.current,[]),YO(()=>{Object.assign(n.current,fO({groupId:e}))})}function tk({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,_.useRef)({onLayoutChange:{},onLayoutChanged:{}}),h=XO(e=>{sO(m.current.onLayoutChange,e)||(m.current.onLayoutChange=e,c?.(e))}),g=XO(e=>{sO(m.current.onLayoutChanged,e)||(m.current.onLayoutChanged=e,l?.(e))}),v=JO(s),y=(0,_.useRef)(null),[b,x]=qO(),S=(0,_.useRef)({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),C=ZO(y,a);ek(v,o);let w=XO((e,t)=>{let r=_O(),i=RD(e),a=zD(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=QO({defaultLayout:n,disableCursor:r}),E=(0,_.useMemo)(()=>({get disableCursor(){return!!T.disableCursor},getPanelStyles:w,id:v,orientation:u,registerPanel:e=>{let t=S.current;return t.panels=TD(u,[...t.panels,e]),x(),()=>{t.panels=t.panels.filter(t=>t!==e),x()}},registerSeparator:e=>{let t=S.current;return t.separators=TD(u,[...t.separators,e]),x(),()=>{t.separators=t.separators.filter(t=>t!==e),x()}},updatePanelProps:(e,{disabled:t})=>{let n=S.current.panels.find(t=>t.id===e);n&&(n.panelConstraints.disabled=t);let r=RD(v),i=zD(v);r&&i&&HD(r,{...i,derivedPanelConstraints:CD(r)})},updateSeparatorProps:(e,{disabled:t,disableDoubleClick:n})=>{let r=S.current.separators.find(t=>t.id===e);r&&(r.disabled=t,r.disableDoubleClick=n)}}),[w,v,x,u,T]),D=(0,_.useRef)(null);return YO(()=>{let e=y.current;if(e===null)return;let t=S.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:v,mutableState:{defaultLayout:n,disableCursor:!!T.disableCursor,expandedPanelSizes:S.current.lastExpandedPanelSizes,layouts:S.current.layouts},orientation:u,panels:t.panels,resizeTargetMinimumSize:t.resizeTargetMinimumSize,separators:t.separators};D.current=r;let a=KO(r),{defaultLayoutDeferred:o,derivedPanelConstraints:s,layout:c}=zD(r.id,!0);!o&&s.length>0&&(h(c),g(c));let l=VD(v,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=rO(t.collapsedSize,i[t.panelId]),a=rO(t.collapsedSize,n[t.panelId]);e&&!a&&(r.mutableState.expandedPanelSizes[t.panelId]=n[t.panelId])}}});let o=_O().state!==`active`;h(i),o&&g(i)});return()=>{D.current=null,a(),l()}},[i,v,g,h,u,b,T]),(0,_.useEffect)(()=>{let e=D.current;e&&(e.mutableState.defaultLayout=n,e.mutableState.disableCursor=!!r)}),(0,K.jsx)($O.Provider,{value:E,children:(0,K.jsx)(`div`,{...p,className:t,"data-group":!0,"data-testid":v,id:v,ref:C,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})})}tk.displayName=`Group`;function nk(){let e=(0,_.useContext)($O);return wD(e,`Group Context not found; did you render a Panel or Separator outside of a Group?`),e}function rk(e,t){let{id:n}=nk(),r=(0,_.useRef)({collapse:CO,expand:CO,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:CO});(0,_.useImperativeHandle)(t,()=>r.current,[]),YO(()=>{Object.assign(r.current,lO({groupId:n,panelId:e}))})}function ik({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=JO(c),v=QO({disabled:a}),y=(0,_.useRef)(null),b=ZO(y,o),{getPanelStyles:x,id:S,orientation:C,registerPanel:w,updatePanelProps:T}=nk(),E=d!==null,D=XO((e,t,n)=>{d?.(e,c,n)});YO(()=>{let e=y.current;if(e!==null)return w({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:v.disabled,maxSize:l,minSize:u}})},[s,n,r,i,E,g,h,l,u,D,w,v]),(0,_.useEffect)(()=>{T(g,{disabled:a})},[a,g,T]),rk(g,f);let O=()=>{let e=x(S,g);if(e)return JSON.stringify(e)},k=(0,_.useSyncExternalStore)(e=>VD(S,e),O,O),A;return A=k?JSON.parse(k):i===void 0?{flexGrow:1}:{flexGrow:void 0,flexShrink:void 0,flexBasis:i},(0,K.jsx)(`div`,{...m,"data-disabled":a||void 0,"data-panel":!0,"data-testid":g,id:g,ref:b,style:{...ak,display:`flex`,flexBasis:0,flexShrink:1,overflow:`visible`,...A},children:(0,K.jsx)(`div`,{className:t,style:{maxHeight:`100%`,maxWidth:`100%`,flexGrow:1,overflow:`auto`,...p,touchAction:C===`horizontal`?`pan-y`:`pan-x`},children:e})})}ik.displayName=`Panel`;var ak={minHeight:0,maxHeight:`100%`,height:`auto`,minWidth:0,maxWidth:`100%`,width:`auto`,border:`none`,borderWidth:0,padding:0,margin:0};function ok({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=cO({layout:oO({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=cO({layout:oO({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:o}}function sk({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:a,style:o,...s}){let c=JO(a),l=QO({disabled:n,disableDoubleClick:r}),[u,d]=(0,_.useState)({}),[f,p]=(0,_.useState)(`inactive`),[m,h]=(0,_.useState)(!1),g=(0,_.useRef)(null),v=ZO(g,i),{disableCursor:y,id:b,orientation:x,registerSeparator:S,updateSeparatorProps:C}=nk(),w=x===`horizontal`?`vertical`:`horizontal`;YO(()=>{let e=g.current;if(e!==null){let t={disabled:l.disabled,disableDoubleClick:l.disableDoubleClick,element:e,id:c},n=S(t),r=vO(e=>{p(e.next.state!==`inactive`&&e.next.hitRegions.some(e=>e.separator===t)?e.next.state:`inactive`)}),i=VD(b,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(ok({layout:r,panelConstraints:n,panelId:e.id,panelIndex:t}))}});return()=>{r(),i(),n()}}},[b,c,S,l]),(0,_.useEffect)(()=>{C(c,{disabled:n,disableDoubleClick:r})},[n,r,c,C]);let T;n&&!y&&(T=`not-allowed`);let E;if(n)E=`disabled`;else switch(f){case`active`:E=`active`;break;default:E=m?`focus`:f}return(0,K.jsx)(`div`,{...s,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":w,"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:v,role:`separator`,style:{flexBasis:`auto`,cursor:T,...o,flexGrow:0,flexShrink:0,touchAction:`none`},tabIndex:n?void 0:0})}sk.displayName=`Separator`;var ck=(e,t)=>typeof e==`string`?e===t:JSON.stringify(e)===JSON.stringify(t),lk=(e,t)=>{if(!e||!t)return!1;let n=e=>{let{position:t,data:n,...r}=e||{};return r};return JSON.stringify(n(e.properties))===JSON.stringify(n(t.properties))&&ck(e.children,t.children)},uk=(e,t)=>lk(e.node,t.node),dk=(e={})=>Object.fromEntries(Object.entries(e??{}).map(([e,t])=>{if(!t)return[e,t];let n=t;return[e,(0,_.memo)(({node:e,...t})=>(0,K.jsx)(n,{...t}),uk)]})),fk=(0,_.createContext)(null),pk=()=>(0,_.useContext)(fk)!==null,mk=(0,_.memo)(({children:e,...t})=>(0,K.jsx)(fk.Provider,{value:t,children:e}),uk),hk=({node:e,...t})=>(0,K.jsx)(`pre`,{...t}),gk=({node:e,...t})=>(0,K.jsx)(`code`,{...t}),_k=({node:e,components:{Pre:t,Code:n},code:r})=>(0,K.jsx)(t,{children:(0,K.jsx)(n,{node:e,children:r})}),vk=()=>null,yk=({node:e,components:{Pre:t,Code:n,SyntaxHighlighter:r,CodeHeader:i},language:a,code:o})=>{let s=(0,_.useMemo)(()=>({Pre:t,Code:n}),[t,n]);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(i,{node:e,language:a,code:o}),(0,K.jsx)(a?r:_k,{node:e,components:s,language:a??`unknown`,code:o})]})},bk=n(r(((e,t)=>{(function(){var e={}.hasOwnProperty;function n(){for(var e=``,t=0;t<arguments.length;t++){var n=arguments[t];n&&(e=i(e,r(n)))}return e}function r(t){if(typeof t==`string`||typeof t==`number`)return t;if(typeof t!=`object`)return``;if(Array.isArray(t))return n.apply(null,t);if(t.toString!==Object.prototype.toString&&!t.toString.toString().includes(`[native code]`))return t.toString();var r=``;for(var a in t)e.call(t,a)&&t[a]&&(r=i(r,a));return r}function i(e,t){return t?e?e+` `+t:e+t:e}t!==void 0&&t.exports?(n.default=n,t.exports=n):typeof define==`function`&&typeof define.amd==`object`&&define.amd?define(`classnames`,[],function(){return n}):window.classNames=n})()}))(),1),xk=({className:e,...t})=>({className:n,...r})=>({className:(0,bk.default)(e,n),...t,...r}),Sk=({node:e,components:{Pre:t,Code:n,SyntaxHighlighter:r,CodeHeader:i},componentsByLanguage:a={},children:o,...s})=>{let c=xk((0,_.useContext)(fk)),l=ba(e=>(0,K.jsx)(t,{...c(e)})),u=xk(s),d=ba(e=>(0,K.jsx)(n,{...u(e)})),f=/language-(\w+)/.exec(s.className||``)?.[1]??``;return typeof o==`string`?(0,K.jsx)(yk,{node:e,components:{Pre:l,Code:d,SyntaxHighlighter:a[f]?.SyntaxHighlighter??r,CodeHeader:a[f]?.CodeHeader??i},language:f||`unknown`,code:o}):(0,K.jsx)(_k,{node:e,components:{Pre:l,Code:d},code:o})},Ck=(0,_.memo)(({node:e,components:t,componentsByLanguage:n,...r})=>pk()?(0,K.jsx)(Sk,{node:e,components:t,componentsByLanguage:n,...r}):(0,K.jsx)(t.Code,{...r}),(e,t)=>e.components===t.components&&e.componentsByLanguage===t.componentsByLanguage&&uk(e,t));function wk(){}function Tk(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var Ek=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Dk=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Ok={};function kk(e,t){return((t||Ok).jsx?Dk:Ek).test(e)}var Ak=/[ \t\n\f\r]/g;function jk(e){return typeof e==`object`?e.type===`text`?Mk(e.value):!1:Mk(e)}function Mk(e){return e.replace(Ak,``)===``}var Nk=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};Nk.prototype.normal={},Nk.prototype.property={},Nk.prototype.space=void 0;function Pk(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new Nk(n,r,t)}function Fk(e){return e.toLowerCase()}var Ik=class{constructor(e,t){this.attribute=t,this.property=e}};Ik.prototype.attribute=``,Ik.prototype.booleanish=!1,Ik.prototype.boolean=!1,Ik.prototype.commaOrSpaceSeparated=!1,Ik.prototype.commaSeparated=!1,Ik.prototype.defined=!1,Ik.prototype.mustUseProperty=!1,Ik.prototype.number=!1,Ik.prototype.overloadedBoolean=!1,Ik.prototype.property=``,Ik.prototype.spaceSeparated=!1,Ik.prototype.space=void 0;var Lk=e({boolean:()=>zk,booleanish:()=>Bk,commaOrSpaceSeparated:()=>Wk,commaSeparated:()=>Uk,number:()=>$,overloadedBoolean:()=>Vk,spaceSeparated:()=>Hk}),Rk=0,zk=Gk(),Bk=Gk(),Vk=Gk(),$=Gk(),Hk=Gk(),Uk=Gk(),Wk=Gk();function Gk(){return 2**++Rk}var Kk=Object.keys(Lk),qk=class extends Ik{constructor(e,t,n,r){let i=-1;if(super(e,t),Jk(this,`space`,r),typeof n==`number`)for(;++i<Kk.length;){let e=Kk[i];Jk(this,Kk[i],(n&Lk[e])===Lk[e])}}};qk.prototype.defined=!0;function Jk(e,t,n){n&&(e[t]=n)}function Yk(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new qk(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[Fk(r)]=r,n[Fk(a.attribute)]=r}return new Nk(t,n,e.space)}var Xk=Yk({properties:{ariaActiveDescendant:null,ariaAtomic:Bk,ariaAutoComplete:null,ariaBusy:Bk,ariaChecked:Bk,ariaColCount:$,ariaColIndex:$,ariaColSpan:$,ariaControls:Hk,ariaCurrent:null,ariaDescribedBy:Hk,ariaDetails:null,ariaDisabled:Bk,ariaDropEffect:Hk,ariaErrorMessage:null,ariaExpanded:Bk,ariaFlowTo:Hk,ariaGrabbed:Bk,ariaHasPopup:null,ariaHidden:Bk,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Hk,ariaLevel:$,ariaLive:null,ariaModal:Bk,ariaMultiLine:Bk,ariaMultiSelectable:Bk,ariaOrientation:null,ariaOwns:Hk,ariaPlaceholder:null,ariaPosInSet:$,ariaPressed:Bk,ariaReadOnly:Bk,ariaRelevant:null,ariaRequired:Bk,ariaRoleDescription:Hk,ariaRowCount:$,ariaRowIndex:$,ariaRowSpan:$,ariaSelected:Bk,ariaSetSize:$,ariaSort:null,ariaValueMax:$,ariaValueMin:$,ariaValueNow:$,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function Zk(e,t){return t in e?e[t]:t}function Qk(e,t){return Zk(e,t.toLowerCase())}var $k=Yk({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:Uk,acceptCharset:Hk,accessKey:Hk,action:null,allow:null,allowFullScreen:zk,allowPaymentRequest:zk,allowUserMedia:zk,alpha:zk,alt:null,as:null,async:zk,autoCapitalize:null,autoComplete:Hk,autoFocus:zk,autoPlay:zk,blocking:Hk,capture:null,charSet:null,checked:zk,cite:null,className:Hk,closedBy:null,colorSpace:null,cols:$,colSpan:$,command:null,commandFor:null,content:null,contentEditable:Bk,controls:zk,controlsList:Hk,coords:$|Uk,crossOrigin:null,data:null,dateTime:null,decoding:null,default:zk,defer:zk,dir:null,dirName:null,disabled:zk,download:Vk,draggable:Bk,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:zk,formTarget:null,headers:Hk,height:$,hidden:Vk,high:$,href:null,hrefLang:null,htmlFor:Hk,httpEquiv:Hk,id:null,imageSizes:null,imageSrcSet:null,inert:zk,inputMode:null,integrity:null,is:null,isMap:zk,itemId:null,itemProp:Hk,itemRef:Hk,itemScope:zk,itemType:Hk,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:zk,low:$,manifest:null,max:null,maxLength:$,media:null,method:null,min:null,minLength:$,multiple:zk,muted:zk,name:null,nonce:null,noModule:zk,noValidate:zk,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:zk,optimum:$,pattern:null,ping:Hk,placeholder:null,playsInline:zk,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:zk,referrerPolicy:null,rel:Hk,required:zk,reversed:zk,rows:$,rowSpan:$,sandbox:Hk,scope:null,scoped:zk,seamless:zk,selected:zk,shadowRootClonable:zk,shadowRootCustomElementRegistry:zk,shadowRootDelegatesFocus:zk,shadowRootMode:null,shadowRootSerializable:zk,shape:null,size:$,sizes:null,slot:null,span:$,spellCheck:Bk,src:null,srcDoc:null,srcLang:null,srcSet:null,start:$,step:null,style:null,tabIndex:$,target:null,title:null,translate:null,type:null,typeMustMatch:zk,useMap:null,value:Bk,width:$,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Hk,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:zk,declare:zk,event:null,face:null,frame:null,frameBorder:null,hSpace:$,leftMargin:$,link:null,longDesc:null,lowSrc:null,marginHeight:$,marginWidth:$,noResize:zk,noHref:zk,noShade:zk,noWrap:zk,object:null,profile:null,prompt:null,rev:null,rightMargin:$,rules:null,scheme:null,scrolling:Bk,standby:null,summary:null,text:null,topMargin:$,valueType:null,version:null,vAlign:null,vLink:null,vSpace:$,allowTransparency:null,autoCorrect:null,autoSave:null,credentialless:zk,disablePictureInPicture:zk,disableRemotePlayback:zk,exportParts:Uk,part:Hk,prefix:null,property:null,results:$,security:null,unselectable:null},space:`html`,transform:Qk}),eA=Yk({attributes:{accentHeight:`accent-height`,alignmentBaseline:`alignment-baseline`,arabicForm:`arabic-form`,baselineShift:`baseline-shift`,capHeight:`cap-height`,className:`class`,clipPath:`clip-path`,clipRule:`clip-rule`,colorInterpolation:`color-interpolation`,colorInterpolationFilters:`color-interpolation-filters`,colorProfile:`color-profile`,colorRendering:`color-rendering`,crossOrigin:`crossorigin`,dataType:`datatype`,dominantBaseline:`dominant-baseline`,enableBackground:`enable-background`,fillOpacity:`fill-opacity`,fillRule:`fill-rule`,floodColor:`flood-color`,floodOpacity:`flood-opacity`,fontFamily:`font-family`,fontSize:`font-size`,fontSizeAdjust:`font-size-adjust`,fontStretch:`font-stretch`,fontStyle:`font-style`,fontVariant:`font-variant`,fontWeight:`font-weight`,glyphName:`glyph-name`,glyphOrientationHorizontal:`glyph-orientation-horizontal`,glyphOrientationVertical:`glyph-orientation-vertical`,hrefLang:`hreflang`,horizAdvX:`horiz-adv-x`,horizOriginX:`horiz-origin-x`,horizOriginY:`horiz-origin-y`,imageRendering:`image-rendering`,letterSpacing:`letter-spacing`,lightingColor:`lighting-color`,markerEnd:`marker-end`,markerMid:`marker-mid`,markerStart:`marker-start`,maskType:`mask-type`,navDown:`nav-down`,navDownLeft:`nav-down-left`,navDownRight:`nav-down-right`,navLeft:`nav-left`,navNext:`nav-next`,navPrev:`nav-prev`,navRight:`nav-right`,navUp:`nav-up`,navUpLeft:`nav-up-left`,navUpRight:`nav-up-right`,onAbort:`onabort`,onActivate:`onactivate`,onAfterPrint:`onafterprint`,onBeforePrint:`onbeforeprint`,onBegin:`onbegin`,onCancel:`oncancel`,onCanPlay:`oncanplay`,onCanPlayThrough:`oncanplaythrough`,onChange:`onchange`,onClick:`onclick`,onClose:`onclose`,onCopy:`oncopy`,onCueChange:`oncuechange`,onCut:`oncut`,onDblClick:`ondblclick`,onDrag:`ondrag`,onDragEnd:`ondragend`,onDragEnter:`ondragenter`,onDragExit:`ondragexit`,onDragLeave:`ondragleave`,onDragOver:`ondragover`,onDragStart:`ondragstart`,onDrop:`ondrop`,onDurationChange:`ondurationchange`,onEmptied:`onemptied`,onEnd:`onend`,onEnded:`onended`,onError:`onerror`,onFocus:`onfocus`,onFocusIn:`onfocusin`,onFocusOut:`onfocusout`,onHashChange:`onhashchange`,onInput:`oninput`,onInvalid:`oninvalid`,onKeyDown:`onkeydown`,onKeyPress:`onkeypress`,onKeyUp:`onkeyup`,onLoad:`onload`,onLoadedData:`onloadeddata`,onLoadedMetadata:`onloadedmetadata`,onLoadStart:`onloadstart`,onMessage:`onmessage`,onMouseDown:`onmousedown`,onMouseEnter:`onmouseenter`,onMouseLeave:`onmouseleave`,onMouseMove:`onmousemove`,onMouseOut:`onmouseout`,onMouseOver:`onmouseover`,onMouseUp:`onmouseup`,onMouseWheel:`onmousewheel`,onOffline:`onoffline`,onOnline:`ononline`,onPageHide:`onpagehide`,onPageShow:`onpageshow`,onPaste:`onpaste`,onPause:`onpause`,onPlay:`onplay`,onPlaying:`onplaying`,onPopState:`onpopstate`,onProgress:`onprogress`,onRateChange:`onratechange`,onRepeat:`onrepeat`,onReset:`onreset`,onResize:`onresize`,onScroll:`onscroll`,onSeeked:`onseeked`,onSeeking:`onseeking`,onSelect:`onselect`,onShow:`onshow`,onStalled:`onstalled`,onStorage:`onstorage`,onSubmit:`onsubmit`,onSuspend:`onsuspend`,onTimeUpdate:`ontimeupdate`,onToggle:`ontoggle`,onUnload:`onunload`,onVolumeChange:`onvolumechange`,onWaiting:`onwaiting`,onZoom:`onzoom`,overlinePosition:`overline-position`,overlineThickness:`overline-thickness`,paintOrder:`paint-order`,panose1:`panose-1`,pointerEvents:`pointer-events`,referrerPolicy:`referrerpolicy`,renderingIntent:`rendering-intent`,shapeRendering:`shape-rendering`,stopColor:`stop-color`,stopOpacity:`stop-opacity`,strikethroughPosition:`strikethrough-position`,strikethroughThickness:`strikethrough-thickness`,strokeDashArray:`stroke-dasharray`,strokeDashOffset:`stroke-dashoffset`,strokeLineCap:`stroke-linecap`,strokeLineJoin:`stroke-linejoin`,strokeMiterLimit:`stroke-miterlimit`,strokeOpacity:`stroke-opacity`,strokeWidth:`stroke-width`,tabIndex:`tabindex`,textAnchor:`text-anchor`,textDecoration:`text-decoration`,textRendering:`text-rendering`,transformOrigin:`transform-origin`,typeOf:`typeof`,underlinePosition:`underline-position`,underlineThickness:`underline-thickness`,unicodeBidi:`unicode-bidi`,unicodeRange:`unicode-range`,unitsPerEm:`units-per-em`,vAlphabetic:`v-alphabetic`,vHanging:`v-hanging`,vIdeographic:`v-ideographic`,vMathematical:`v-mathematical`,vectorEffect:`vector-effect`,vertAdvY:`vert-adv-y`,vertOriginX:`vert-origin-x`,vertOriginY:`vert-origin-y`,wordSpacing:`word-spacing`,writingMode:`writing-mode`,xHeight:`x-height`,playbackOrder:`playbackorder`,timelineBegin:`timelinebegin`},properties:{about:Wk,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:Hk,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:zk,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:Uk,g2:Uk,glyphName:Uk,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:Wk,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,maskType: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:Hk,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:$,pointsAtY:$,pointsAtZ:$,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Wk,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Wk,rev:Wk,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Wk,requiredFeatures:Wk,requiredFonts:Wk,requiredFormats:Wk,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:Wk,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:$,strokeOpacity:$,strokeWidth:null,style:null,surfaceScale:$,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Wk,tabIndex:$,tableValues:null,target:null,targetX:$,targetY:$,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Wk,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:Zk}),tA=Yk({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()}}),nA=Yk({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:Qk}),rA=Yk({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),iA={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`},aA=/[A-Z]/g,oA=/-[a-z]/g,sA=/^data[-\w.:]+$/i;function cA(e,t){let n=Fk(t),r=t,i=Ik;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&sA.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(oA,uA);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!oA.test(e)){let n=e.replace(aA,lA);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=qk}return new i(r,t)}function lA(e){return`-`+e.toLowerCase()}function uA(e){return e.charAt(1).toUpperCase()}var dA=Pk([Xk,$k,tA,nA,rA],`html`),fA=Pk([Xk,eA,tA,nA,rA],`svg`);function pA(e){return e.join(` `).trim()}var mA=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})),hA=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(mA());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}})),gA=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))}})),_A=r(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(hA()),r=gA();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})),vA=bA(`end`),yA=bA(`start`);function bA(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 xA(e){let t=yA(e),n=vA(e);if(t&&n)return{start:t,end:n}}function SA(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?wA(e.position):`start`in e||`end`in e?wA(e):`line`in e||`column`in e?CA(e):``}function CA(e){return TA(e&&e.line)+`:`+TA(e&&e.column)}function wA(e){return CA(e&&e.start)+`-`+CA(e&&e.end)}function TA(e){return e&&typeof e==`number`?e:1}var EA=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=SA(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};EA.prototype.file=``,EA.prototype.name=``,EA.prototype.reason=``,EA.prototype.message=``,EA.prototype.stack=``,EA.prototype.column=void 0,EA.prototype.line=void 0,EA.prototype.ancestors=void 0,EA.prototype.cause=void 0,EA.prototype.fatal=void 0,EA.prototype.place=void 0,EA.prototype.ruleId=void 0,EA.prototype.source=void 0;var DA=n(_A(),1),OA={}.hasOwnProperty,kA=new Map,AA=/[A-Z]/g,jA=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),MA=new Set([`td`,`th`]);function NA(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=WA(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=UA(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`?fA:dA,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=PA(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function PA(e,t,n){if(t.type===`element`)return FA(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return IA(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return RA(e,t,n);if(t.type===`mdxjsEsm`)return LA(e,t);if(t.type===`root`)return zA(e,t,n);if(t.type===`text`)return BA(e,t)}function FA(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=fA,e.schema=i),e.ancestors.push(t);let a=XA(e,t.tagName,!1),o=GA(e,t),s=qA(e,t);return jA.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!jk(e):!0})),VA(e,o,a,t),HA(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function IA(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)}ZA(e,t.position)}function LA(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);ZA(e,t.position)}function RA(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=fA,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:XA(e,t.name,!0),o=KA(e,t),s=qA(e,t);return VA(e,o,a,t),HA(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function zA(e,t,n){let r={};return HA(r,qA(e,t)),e.create(t,e.Fragment,r,n)}function BA(e,t){return t.value}function VA(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function HA(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function UA(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 WA(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=yA(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 GA(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&OA.call(t.properties,i)){let a=JA(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&MA.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 KA(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 ZA(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 ZA(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function qA(e,t){let n=[],r=-1,i=e.passKeys?new Map:kA;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=PA(e,a,o);s!==void 0&&n.push(s)}return n}function JA(e,t,n){let r=cA(e.schema,t);if(!(n==null||typeof n==`number`&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?Tk(n):pA(n)),r.property===`style`){let t=typeof n==`object`?n:YA(e,String(n));return e.stylePropertyNameCase===`css`&&(t=QA(t)),[`style`,t]}return[e.elementAttributeNameCase===`react`&&r.space?iA[r.property]||r.property:r.attribute,n]}}function YA(e,t){try{return(0,DA.default)(t,{reactCompat:!0})}catch(t){if(e.ignoreInvalidStyle)return{};let n=t,r=new EA("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=`https://github.com/syntax-tree/hast-util-to-jsx-runtime#cannot-parse-style-attribute`,r}}function XA(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=kk(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=kk(t)&&!/^[a-z]/.test(t)?{type:`Identifier`,name:t}:{type:`Literal`,value:t};if(r.type===`Literal`){let t=r.value;return OA.call(e.components,t)?e.components[t]:t}if(e.evaluater)return e.evaluater.evaluateExpression(r);ZA(e)}function ZA(e,t){let n=new EA("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=`https://github.com/syntax-tree/hast-util-to-jsx-runtime#cannot-handle-mdx-estrees-without-createevaluater`,n}function QA(e){let t={},n;for(n in e)OA.call(e,n)&&(t[$A(n)]=e[n]);return t}function $A(e){let t=e.replace(AA,ej);return t.slice(0,3)===`ms-`&&(t=`-`+t),t}function ej(e){return`-`+e.toLowerCase()}var tj={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`]},nj={};function rj(e,t){let n=t||nj;return ij(e,typeof n.includeImageAlt==`boolean`?n.includeImageAlt:!0,typeof n.includeHtml==`boolean`?n.includeHtml:!0)}function ij(e,t,n){if(oj(e)){if(`value`in e)return e.type===`html`&&!n?``:e.value;if(t&&`alt`in e&&e.alt)return e.alt;if(`children`in e)return aj(e.children,t,n)}return Array.isArray(e)?aj(e,t,n):``}function aj(e,t,n){let r=[],i=-1;for(;++i<e.length;)r[i]=ij(e[i],t,n);return r.join(``)}function oj(e){return!!(e&&typeof e==`object`)}var sj=document.createElement(`i`);function cj(e){let t=`&`+e+`;`;sj.innerHTML=t;let n=sj.textContent;return n.charCodeAt(n.length-1)===59&&e!==`semi`||n===t?!1:n}function lj(e,t,n,r){let i=e.length,a=0,o;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a<r.length;)o=r.slice(a,a+1e4),o.unshift(t,0),e.splice(...o),a+=1e4,t+=1e4}function uj(e,t){return e.length>0?(lj(e,e.length,0,t),e):t}var dj={}.hasOwnProperty;function fj(e){let t={},n=-1;for(;++n<e.length;)pj(t,e[n]);return t}function pj(e,t){let n;for(n in t){let r=(dj.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n],a;if(i)for(a in i){dj.call(r,a)||(r[a]=[]);let e=i[a];mj(r[a],Array.isArray(e)?e:e?[e]:[])}}}function mj(e,t){let n=-1,r=[];for(;++n<t.length;)(t[n].add===`after`?e:r).push(t[n]);lj(e,0,0,r)}function hj(e,t){let n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function gj(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var _j=kj(/[A-Za-z]/),vj=kj(/[\dA-Za-z]/),yj=kj(/[#-'*+\--9=?A-Z^-~]/);function bj(e){return e!==null&&(e<32||e===127)}var xj=kj(/\d/),Sj=kj(/[\dA-Fa-f]/),Cj=kj(/[!-/:-@[-`{-~]/);function wj(e){return e!==null&&e<-2}function Tj(e){return e!==null&&(e<0||e===32)}function Ej(e){return e===-2||e===-1||e===32}var Dj=kj(/\p{P}|\p{S}/u),Oj=kj(/\s/);function kj(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function Aj(e){let t=[],n=-1,r=0,i=0;for(;++n<e.length;){let a=e.charCodeAt(n),o=``;if(a===37&&vj(e.charCodeAt(n+1))&&vj(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 jj(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return Ej(r)?(e.enter(n),s(r)):t(r)}function s(r){return Ej(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}var Mj={tokenize:Nj};function Nj(e){let t=e.attempt(this.parser.constructs.contentInitial,r,i),n;return t;function r(n){if(n===null){e.consume(n);return}return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),jj(e,t,`linePrefix`)}function i(t){return e.enter(`paragraph`),a(t)}function a(t){let r=e.enter(`chunkText`,{contentType:`text`,previous:n});return n&&(n.next=r),n=r,o(t)}function o(t){if(t===null){e.exit(`chunkText`),e.exit(`paragraph`),e.consume(t);return}return wj(t)?(e.consume(t),e.exit(`chunkText`),a):(e.consume(t),o)}}var Pj={tokenize:Ij},Fj={tokenize:Lj};function Ij(e){let t=this,n=[],r=0,i,a,o;return s;function s(i){if(r<n.length){let a=n[r];return t.containerState=a[1],e.attempt(a[0].continuation,c,l)(i)}return l(i)}function c(e){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&v();let n=t.events.length,a=n,o;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){o=t.events[a][1].end;break}_(r);let s=n;for(;s<t.events.length;)t.events[s][1].end={...o},s++;return lj(t.events,a+1,0,t.events.slice(n)),t.events.length=s,l(e)}return s(e)}function l(a){if(r===n.length){if(!i)return f(a);if(i.currentConstruct&&i.currentConstruct.concrete)return m(a);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(Fj,u,d)(a)}function u(e){return i&&v(),_(r),f(e)}function d(e){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(e)}function f(n){return t.containerState={},e.attempt(Fj,p,m)(n)}function p(e){return r++,n.push([t.currentConstruct,t.containerState]),f(e)}function m(n){if(n===null){i&&v(),_(0),e.consume(n);return}return i||=t.parser.flow(t.now()),e.enter(`chunkFlow`,{_tokenizer:i,contentType:`flow`,previous:a}),h(n)}function h(n){if(n===null){g(e.exit(`chunkFlow`),!0),_(0),e.consume(n);return}return wj(n)?(e.consume(n),g(e.exit(`chunkFlow`)),r=0,t.interrupt=void 0,s):(e.consume(n),h)}function g(e,n){let s=t.sliceStream(e);if(n&&s.push(null),e.previous=a,a&&(a.next=e),a=e,i.defineSkip(e.start),i.write(s),t.parser.lazy[e.start.line]){let e=i.events.length;for(;e--;)if(i.events[e][1].start.offset<o&&(!i.events[e][1].end||i.events[e][1].end.offset>o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;e<t.events.length;)t.events[e][1].end={...c},e++;lj(t.events,a+1,0,t.events.slice(n)),t.events.length=e}}function _(r){let i=n.length;for(;i-- >r;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Lj(e,t,n){return jj(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function Rj(e){if(e===null||Tj(e)||Oj(e))return 1;if(Dj(e))return 2}function zj(e,t,n){let r=[],i=-1;for(;++i<e.length;){let a=e[i].resolveAll;a&&!r.includes(a)&&(t=a(t,n),r.push(a))}return t}var Bj={name:`attention`,resolveAll:Vj,tokenize:Hj};function Vj(e,t){let n=-1,r,i,a,o,s,c,l,u;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`attentionSequence`&&e[n][1]._close){for(r=n;r--;)if(e[r][0]===`exit`&&e[r][1].type===`attentionSequence`&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;c=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;let d={...e[r][1].end},f={...e[n][1].start};Uj(d,-c),Uj(f,c),o={type:c>1?`strongSequence`:`emphasisSequence`,start:d,end:{...e[r][1].end}},s={type:c>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:f},a={type:c>1?`strongText`:`emphasisText`,start:{...e[r][1].end},end:{...e[n][1].start}},i={type:c>1?`strong`:`emphasis`,start:{...o.start},end:{...s.end}},e[r][1].end={...o.start},e[n][1].start={...s.end},l=[],e[r][1].end.offset-e[r][1].start.offset&&(l=uj(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=uj(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=uj(l,zj(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=uj(l,[[`exit`,a,t],[`enter`,s,t],[`exit`,s,t],[`exit`,i,t]]),e[n][1].end.offset-e[n][1].start.offset?(u=2,l=uj(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,lj(e,r-1,n-r+3,l),n=r+l.length-u-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`attentionSequence`&&(e[n][1].type=`data`);return e}function Hj(e,t){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=Rj(r),a;return o;function o(t){return a=t,e.enter(`attentionSequence`),s(t)}function s(o){if(o===a)return e.consume(o),s;let c=e.exit(`attentionSequence`),l=Rj(o),u=!l||l===2&&i||n.includes(o),d=!i||i===2&&l||n.includes(r);return c._open=!!(a===42?u:u&&(i||!d)),c._close=!!(a===42?d:d&&(l||!u)),t(o)}}function Uj(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}var Wj={name:`autolink`,tokenize:Gj};function Gj(e,t,n){let r=0;return i;function i(t){return e.enter(`autolink`),e.enter(`autolinkMarker`),e.consume(t),e.exit(`autolinkMarker`),e.enter(`autolinkProtocol`),a}function a(t){return _j(t)?(e.consume(t),o):t===64?n(t):l(t)}function o(e){return e===43||e===45||e===46||vj(e)?(r=1,s(e)):l(e)}function s(t){return t===58?(e.consume(t),r=0,c):(t===43||t===45||t===46||vj(t))&&r++<32?(e.consume(t),s):(r=0,l(t))}function c(r){return r===62?(e.exit(`autolinkProtocol`),e.enter(`autolinkMarker`),e.consume(r),e.exit(`autolinkMarker`),e.exit(`autolink`),t):r===null||r===32||r===60||bj(r)?n(r):(e.consume(r),c)}function l(t){return t===64?(e.consume(t),u):yj(t)?(e.consume(t),l):n(t)}function u(e){return vj(e)?d(e):n(e)}function d(n){return n===46?(e.consume(n),r=0,u):n===62?(e.exit(`autolinkProtocol`).type=`autolinkEmail`,e.enter(`autolinkMarker`),e.consume(n),e.exit(`autolinkMarker`),e.exit(`autolink`),t):f(n)}function f(t){if((t===45||vj(t))&&r++<63){let n=t===45?f:d;return e.consume(t),n}return n(t)}}var Kj={partial:!0,tokenize:qj};function qj(e,t,n){return r;function r(t){return Ej(t)?jj(e,i,`linePrefix`)(t):i(t)}function i(e){return e===null||wj(e)?t(e):n(e)}}var Jj={continuation:{tokenize:Xj},exit:Zj,name:`blockQuote`,tokenize:Yj};function Yj(e,t,n){let r=this;return i;function i(t){if(t===62){let n=r.containerState;return n.open||=(e.enter(`blockQuote`,{_container:!0}),!0),e.enter(`blockQuotePrefix`),e.enter(`blockQuoteMarker`),e.consume(t),e.exit(`blockQuoteMarker`),a}return n(t)}function a(n){return Ej(n)?(e.enter(`blockQuotePrefixWhitespace`),e.consume(n),e.exit(`blockQuotePrefixWhitespace`),e.exit(`blockQuotePrefix`),t):(e.exit(`blockQuotePrefix`),t(n))}}function Xj(e,t,n){let r=this;return i;function i(t){return Ej(t)?jj(e,a,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):a(t)}function a(r){return e.attempt(Jj,t,n)(r)}}function Zj(e){e.exit(`blockQuote`)}var Qj={name:`characterEscape`,tokenize:$j};function $j(e,t,n){return r;function r(t){return e.enter(`characterEscape`),e.enter(`escapeMarker`),e.consume(t),e.exit(`escapeMarker`),i}function i(r){return Cj(r)?(e.enter(`characterEscapeValue`),e.consume(r),e.exit(`characterEscapeValue`),e.exit(`characterEscape`),t):n(r)}}var eM={name:`characterReference`,tokenize:tM};function tM(e,t,n){let r=this,i=0,a,o;return s;function s(t){return e.enter(`characterReference`),e.enter(`characterReferenceMarker`),e.consume(t),e.exit(`characterReferenceMarker`),c}function c(t){return t===35?(e.enter(`characterReferenceMarkerNumeric`),e.consume(t),e.exit(`characterReferenceMarkerNumeric`),l):(e.enter(`characterReferenceValue`),a=31,o=vj,u(t))}function l(t){return t===88||t===120?(e.enter(`characterReferenceMarkerHexadecimal`),e.consume(t),e.exit(`characterReferenceMarkerHexadecimal`),e.enter(`characterReferenceValue`),a=6,o=Sj,u):(e.enter(`characterReferenceValue`),a=7,o=xj,u(t))}function u(s){if(s===59&&i){let i=e.exit(`characterReferenceValue`);return o===vj&&!cj(r.sliceSerialize(i))?n(s):(e.enter(`characterReferenceMarker`),e.consume(s),e.exit(`characterReferenceMarker`),e.exit(`characterReference`),t)}return o(s)&&i++<a?(e.consume(s),u):n(s)}}var nM={partial:!0,tokenize:aM},rM={concrete:!0,name:`codeFenced`,tokenize:iM};function iM(e,t,n){let r=this,i={partial:!0,tokenize:x},a=0,o=0,s;return c;function c(e){return l(e)}function l(t){let n=r.events[r.events.length-1];return a=n&&n[1].type===`linePrefix`?n[2].sliceSerialize(n[1],!0).length:0,s=t,e.enter(`codeFenced`),e.enter(`codeFencedFence`),e.enter(`codeFencedFenceSequence`),u(t)}function u(t){return t===s?(o++,e.consume(t),u):o<3?n(t):(e.exit(`codeFencedFenceSequence`),Ej(t)?jj(e,d,`whitespace`)(t):d(t))}function d(n){return n===null||wj(n)?(e.exit(`codeFencedFence`),r.interrupt?t(n):e.check(nM,h,b)(n)):(e.enter(`codeFencedFenceInfo`),e.enter(`chunkString`,{contentType:`string`}),f(n))}function f(t){return t===null||wj(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),d(t)):Ej(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),jj(e,p,`whitespace`)(t)):t===96&&t===s?n(t):(e.consume(t),f)}function p(t){return t===null||wj(t)?d(t):(e.enter(`codeFencedFenceMeta`),e.enter(`chunkString`,{contentType:`string`}),m(t))}function m(t){return t===null||wj(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceMeta`),d(t)):t===96&&t===s?n(t):(e.consume(t),m)}function h(t){return e.attempt(i,b,g)(t)}function g(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),_}function _(t){return a>0&&Ej(t)?jj(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||wj(t)?e.check(nM,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||wj(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),Ej(t)?jj(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),Ej(t)?jj(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||wj(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function aM(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var oM={name:`codeIndented`,tokenize:cM},sM={partial:!0,tokenize:lM};function cM(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),jj(e,a,`linePrefix`,5)(t)}function a(e){let t=r.events[r.events.length-1];return t&&t[1].type===`linePrefix`&&t[2].sliceSerialize(t[1],!0).length>=4?o(e):n(e)}function o(t){return t===null?c(t):wj(t)?e.attempt(sM,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||wj(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function lM(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):wj(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):jj(e,a,`linePrefix`,5)(t)}function a(e){let a=r.events[r.events.length-1];return a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(e):wj(e)?i(e):n(e)}}var uM={name:`codeText`,previous:fM,resolve:dM,tokenize:pM};function dM(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r<t;)if(e[r][1].type===`codeTextData`){e[n][1].type=`codeTextPadding`,e[t][1].type=`codeTextPadding`,n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!==`lineEnding`&&(i=r):(r===t||e[r][1].type===`lineEnding`)&&(e[i][1].type=`codeTextData`,r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function fM(e){return e!==96||this.events[this.events.length-1][1].type===`characterEscape`}function pM(e,t,n){let r=0,i,a;return o;function o(t){return e.enter(`codeText`),e.enter(`codeTextSequence`),s(t)}function s(t){return t===96?(e.consume(t),r++,s):(e.exit(`codeTextSequence`),c(t))}function c(t){return t===null?n(t):t===32?(e.enter(`space`),e.consume(t),e.exit(`space`),c):t===96?(a=e.enter(`codeTextSequence`),i=0,u(t)):wj(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c):(e.enter(`codeTextData`),l(t))}function l(t){return t===null||t===32||t===96||wj(t)?(e.exit(`codeTextData`),c(t)):(e.consume(t),l)}function u(n){return n===96?(e.consume(n),i++,u):i===r?(e.exit(`codeTextSequence`),e.exit(`codeText`),t(n)):(a.type=`codeTextData`,l(n))}}var mM=class{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,t){let n=t??1/0;return n<this.left.length?this.left.slice(e,n):e>this.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&hM(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),hM(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),hM(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e<this.left.length){let t=this.left.splice(e,1/0);hM(this.right,t.reverse())}else{let t=this.right.splice(this.left.length+this.right.length-e,1/0);hM(this.left,t.reverse())}}};function hM(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function gM(e){let t={},n=-1,r,i,a,o,s,c,l,u=new mM(e);for(;++n<u.length;){for(;n in t;)n=t[n];if(r=u.get(n),n&&r[1].type===`chunkFlow`&&u.get(n-1)[1].type===`listItemPrefix`&&(c=r[1]._tokenizer.events,a=0,a<c.length&&c[a][1].type===`lineEndingBlank`&&(a+=2),a<c.length&&c[a][1].type===`content`))for(;++a<c.length&&c[a][1].type!==`content`;)c[a][1].type===`chunkText`&&(c[a][1]._isInFirstContentOfListItem=!0,a++);if(r[0]===`enter`)r[1].contentType&&(Object.assign(t,_M(u,n)),n=t[n],l=!0);else if(r[1]._container){for(a=n,i=void 0;a--;)if(o=u.get(a),o[1].type===`lineEnding`||o[1].type===`lineEndingBlank`)o[0]===`enter`&&(i&&(u.get(i)[1].type=`lineEndingBlank`),o[1].type=`lineEnding`,i=a);else if(!(o[1].type===`linePrefix`||o[1].type===`listItemIndent`))break;i&&(r[1].end={...u.get(i)[1].start},s=u.slice(i,n),s.unshift(r),u.splice(i,n-i+1,s))}}return lj(e,0,1/0,u.slice(0)),!l}function _M(e,t){let n=e.get(t)[1],r=e.get(t)[2],i=t-1,a=[],o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));let s=o.events,c=[],l={},u,d,f=-1,p=n,m=0,h=0,g=[h];for(;p;){for(;e.get(++i)[1]!==p;);a.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),d&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(u),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=p,p=p.next}for(p=n;++f<s.length;)s[f][0]===`exit`&&s[f-1][0]===`enter`&&s[f][1].type===s[f-1][1].type&&s[f][1].start.line!==s[f][1].end.line&&(h=f+1,g.push(h),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):g.pop(),f=g.length;f--;){let t=s.slice(g[f],g[f+1]),n=a.pop();c.push([n,n+t.length-1]),e.splice(n,2,t)}for(c.reverse(),f=-1;++f<c.length;)l[m+c[f][0]]=m+c[f][1],m+=c[f][1]-c[f][0]-1;return l}var vM={resolve:bM,tokenize:xM},yM={partial:!0,tokenize:SM};function bM(e){return gM(e),e}function xM(e,t){let n;return r;function r(t){return e.enter(`content`),n=e.enter(`chunkContent`,{contentType:`content`}),i(t)}function i(t){return t===null?a(t):wj(t)?e.check(yM,o,a)(t):(e.consume(t),i)}function a(n){return e.exit(`chunkContent`),e.exit(`content`),t(n)}function o(t){return e.consume(t),e.exit(`chunkContent`),n.next=e.enter(`chunkContent`,{contentType:`content`,previous:n}),n=n.next,i}}function SM(e,t,n){let r=this;return i;function i(t){return e.exit(`chunkContent`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),jj(e,a,`linePrefix`)}function a(i){if(i===null||wj(i))return n(i);let a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes(`codeIndented`)&&a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function CM(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||bj(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||wj(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||Tj(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u<l&&i===40?(e.consume(i),u++,h):i===41?(e.consume(i),u--,h):i===null||i===32||i===40||bj(i)?n(i):(e.consume(i),i===92?g:h)}function g(t){return t===40||t===41||t===92?(e.consume(t),h):h(t)}}function wM(e,t,n,r,i,a){let o=this,s=0,c;return l;function l(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),e.enter(a),u}function u(l){return s>999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):wj(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||wj(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!Ej(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function TM(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):wj(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),jj(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||wj(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function EM(e,t){let n;return r;function r(i){return wj(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):Ej(i)?jj(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var DM={name:`definition`,tokenize:kM},OM={partial:!0,tokenize:AM};function kM(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return wM.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=gj(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return Tj(t)?EM(e,l)(t):l(t)}function l(t){return CM(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(OM,d,d)(t)}function d(t){return Ej(t)?jj(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||wj(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function AM(e,t,n){return r;function r(t){return Tj(t)?EM(e,i)(t):n(t)}function i(t){return TM(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return Ej(t)?jj(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||wj(e)?t(e):n(e)}}var jM={name:`hardBreakEscape`,tokenize:MM};function MM(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return wj(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var NM={name:`headingAtx`,resolve:PM,tokenize:FM};function PM(e,t){let n=e.length-2,r=3,i,a;return e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r&&(i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`},lj(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function FM(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||Tj(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||wj(n)?(e.exit(`atxHeading`),t(n)):Ej(n)?jj(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||Tj(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var IM=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),LM=[`pre`,`script`,`style`,`textarea`],RM={concrete:!0,name:`htmlFlow`,resolveTo:VM,tokenize:HM},zM={partial:!0,tokenize:WM},BM={partial:!0,tokenize:UM};function VM(e){let t=e.length;for(;t--&&!(e[t][0]===`enter`&&e[t][1].type===`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function HM(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:I):_j(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):_j(a)?(e.consume(a),i=4,r.interrupt?t:I):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:I):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return _j(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||Tj(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&LM.includes(l)?(i=1,r.interrupt?t(s):O(s)):IM.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||vj(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return Ej(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||_j(t)?(e.consume(t),b):Ej(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||vj(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):Ej(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):Ej(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||wj(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||Tj(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||Ej(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||wj(t)?O(t):Ej(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),M):t===60&&i===1?(e.consume(t),N):t===62&&i===4?(e.consume(t),L):t===63&&i===3?(e.consume(t),I):t===93&&i===5?(e.consume(t),F):wj(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(zM,R,k)(t)):t===null||wj(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(BM,A,R)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return t===null||wj(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function M(t){return t===45?(e.consume(t),I):O(t)}function N(t){return t===47?(e.consume(t),o=``,P):O(t)}function P(t){if(t===62){let n=o.toLowerCase();return LM.includes(n)?(e.consume(t),L):O(t)}return _j(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),P):O(t)}function F(t){return t===93?(e.consume(t),I):O(t)}function I(t){return t===62?(e.consume(t),L):t===45&&i===2?(e.consume(t),I):O(t)}function L(t){return t===null||wj(t)?(e.exit(`htmlFlowData`),R(t)):(e.consume(t),L)}function R(n){return e.exit(`htmlFlow`),t(n)}}function UM(e,t,n){let r=this;return i;function i(t){return wj(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a):n(t)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}function WM(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(Kj,t,n)}}var GM={name:`htmlText`,tokenize:KM};function KM(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):_j(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):_j(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):wj(t)?(o=d,N(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?M(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):wj(t)?(o=h,N(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?M(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?M(t):wj(t)?(o=v,N(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):wj(t)?(o=y,N(t)):(e.consume(t),y)}function b(e){return e===62?M(e):y(e)}function x(t){return _j(t)?(e.consume(t),S):n(t)}function S(t){return t===45||vj(t)?(e.consume(t),S):C(t)}function C(t){return wj(t)?(o=C,N(t)):Ej(t)?(e.consume(t),C):M(t)}function w(t){return t===45||vj(t)?(e.consume(t),w):t===47||t===62||Tj(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),M):t===58||t===95||_j(t)?(e.consume(t),E):wj(t)?(o=T,N(t)):Ej(t)?(e.consume(t),T):M(t)}function E(t){return t===45||t===46||t===58||t===95||vj(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):wj(t)?(o=D,N(t)):Ej(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):wj(t)?(o=O,N(t)):Ej(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,j):t===null?n(t):wj(t)?(o=k,N(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||Tj(t)?T(t):(e.consume(t),A)}function j(e){return e===47||e===62||Tj(e)?T(e):n(e)}function M(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function N(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),P}function P(t){return Ej(t)?jj(e,F,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):F(t)}function F(t){return e.enter(`htmlTextData`),o(t)}}var qM={name:`labelEnd`,resolveAll:ZM,resolveTo:QM,tokenize:$M},JM={tokenize:eN},YM={tokenize:tN},XM={tokenize:nN};function ZM(e){let t=-1,n=[];for(;++t<e.length;){let r=e[t][1];if(n.push(e[t]),r.type===`labelImage`||r.type===`labelLink`||r.type===`labelEnd`){let e=r.type===`labelImage`?4:2;r.type=`data`,t+=e}}return e.length!==n.length&&lj(e,0,e.length,n),e}function QM(e,t){let n=e.length,r=0,i,a,o,s;for(;n--;)if(i=e[n][1],a){if(i.type===`link`||i.type===`labelLink`&&i._inactive)break;e[n][0]===`enter`&&i.type===`labelLink`&&(i._inactive=!0)}else if(o){if(e[n][0]===`enter`&&(i.type===`labelImage`||i.type===`labelLink`)&&!i._balanced&&(a=n,i.type!==`labelLink`)){r=2;break}}else i.type===`labelEnd`&&(o=n);let c={type:e[a][1].type===`labelLink`?`link`:`image`,start:{...e[a][1].start},end:{...e[e.length-1][1].end}},l={type:`label`,start:{...e[a][1].start},end:{...e[o][1].end}},u={type:`labelText`,start:{...e[a+r+2][1].end},end:{...e[o-2][1].start}};return s=[[`enter`,c,t],[`enter`,l,t]],s=uj(s,e.slice(a+1,a+r+3)),s=uj(s,[[`enter`,u,t]]),s=uj(s,zj(t.parser.constructs.insideSpan.null,e.slice(a+r+4,o-3),t)),s=uj(s,[[`exit`,u,t],e[o-2],e[o-1],[`exit`,l,t]]),s=uj(s,e.slice(o+1)),s=uj(s,[[`exit`,c,t]]),lj(e,a,e.length,s),e}function $M(e,t,n){let r=this,i=r.events.length,a,o;for(;i--;)if((r.events[i][1].type===`labelImage`||r.events[i][1].type===`labelLink`)&&!r.events[i][1]._balanced){a=r.events[i][1];break}return s;function s(t){return a?a._inactive?d(t):(o=r.parser.defined.includes(gj(r.sliceSerialize({start:a.end,end:r.now()}))),e.enter(`labelEnd`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelEnd`),c):n(t)}function c(t){return t===40?e.attempt(JM,u,o?u:d)(t):t===91?e.attempt(YM,u,o?l:d)(t):o?u(t):d(t)}function l(t){return e.attempt(XM,u,d)(t)}function u(e){return t(e)}function d(e){return a._balanced=!0,n(e)}}function eN(e,t,n){return r;function r(t){return e.enter(`resource`),e.enter(`resourceMarker`),e.consume(t),e.exit(`resourceMarker`),i}function i(t){return Tj(t)?EM(e,a)(t):a(t)}function a(t){return t===41?u(t):CM(e,o,s,`resourceDestination`,`resourceDestinationLiteral`,`resourceDestinationLiteralMarker`,`resourceDestinationRaw`,`resourceDestinationString`,32)(t)}function o(t){return Tj(t)?EM(e,c)(t):u(t)}function s(e){return n(e)}function c(t){return t===34||t===39||t===40?TM(e,l,n,`resourceTitle`,`resourceTitleMarker`,`resourceTitleString`)(t):u(t)}function l(t){return Tj(t)?EM(e,u)(t):u(t)}function u(r){return r===41?(e.enter(`resourceMarker`),e.consume(r),e.exit(`resourceMarker`),e.exit(`resource`),t):n(r)}}function tN(e,t,n){let r=this;return i;function i(t){return wM.call(r,e,a,o,`reference`,`referenceMarker`,`referenceString`)(t)}function a(e){return r.parser.defined.includes(gj(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(e):n(e)}function o(e){return n(e)}}function nN(e,t,n){return r;function r(t){return e.enter(`reference`),e.enter(`referenceMarker`),e.consume(t),e.exit(`referenceMarker`),i}function i(r){return r===93?(e.enter(`referenceMarker`),e.consume(r),e.exit(`referenceMarker`),e.exit(`reference`),t):n(r)}}var rN={name:`labelStartImage`,resolveAll:qM.resolveAll,tokenize:iN};function iN(e,t,n){let r=this;return i;function i(t){return e.enter(`labelImage`),e.enter(`labelImageMarker`),e.consume(t),e.exit(`labelImageMarker`),a}function a(t){return t===91?(e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelImage`),o):n(t)}function o(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):t(e)}}var aN={name:`labelStartLink`,resolveAll:qM.resolveAll,tokenize:oN};function oN(e,t,n){let r=this;return i;function i(t){return e.enter(`labelLink`),e.enter(`labelMarker`),e.consume(t),e.exit(`labelMarker`),e.exit(`labelLink`),a}function a(e){return e===94&&`_hiddenFootnoteSupport`in r.parser.constructs?n(e):t(e)}}var sN={name:`lineEnding`,tokenize:cN};function cN(e,t){return n;function n(n){return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),jj(e,t,`linePrefix`)}}var lN={name:`thematicBreak`,tokenize:uN};function uN(e,t,n){let r=0,i;return a;function a(t){return e.enter(`thematicBreak`),o(t)}function o(e){return i=e,s(e)}function s(a){return a===i?(e.enter(`thematicBreakSequence`),c(a)):r>=3&&(a===null||wj(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),Ej(t)?jj(e,s,`whitespace`)(t):s(t))}}var dN={continuation:{tokenize:hN},exit:_N,name:`list`,tokenize:mN},fN={partial:!0,tokenize:vN},pN={partial:!0,tokenize:gN};function mN(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:xj(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(lN,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return xj(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(Kj,r.interrupt?n:u,e.attempt(fN,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return Ej(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function hN(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(Kj,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,jj(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!Ej(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(pN,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,jj(e,e.attempt(dN,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function gN(e,t,n){let r=this;return jj(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function _N(e){e.exit(this.containerState.type)}function vN(e,t,n){let r=this;return jj(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!Ej(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var yN={name:`setextUnderline`,resolveTo:bN,tokenize:xN};function bN(e,t){let n=e.length,r,i,a;for(;n--;)if(e[n][0]===`enter`){if(e[n][1].type===`content`){r=n;break}e[n][1].type===`paragraph`&&(i=n)}else e[n][1].type===`content`&&e.splice(n,1),!a&&e[n][1].type===`definition`&&(a=n);let o={type:`setextHeading`,start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type=`setextHeadingText`,a?(e.splice(i,0,[`enter`,o,t]),e.splice(a+1,0,[`exit`,e[r][1],t]),e[r][1].end={...e[a][1].end}):e[r][1]=o,e.push([`exit`,o,t]),e}function xN(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),Ej(t)?jj(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||wj(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var SN={tokenize:CN};function CN(e){let t=this,n=e.attempt(Kj,r,e.attempt(this.parser.constructs.flowInitial,i,jj(e,e.attempt(this.parser.constructs.flow,i,e.attempt(vM,i)),`linePrefix`)));return n;function r(r){if(r===null){e.consume(r);return}return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null){e.consume(r);return}return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var wN={resolveAll:ON()},TN=DN(`string`),EN=DN(`text`);function DN(e){return{resolveAll:ON(e===`text`?kN:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null){t.consume(e);return}return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++i<t.length;){let e=t[i];if(!e.previous||e.previous.call(n,n.previous))return!0}return!1}}}function ON(e){return t;function t(t,n){let r=-1,i;for(;++r<=t.length;)i===void 0?t[r]&&t[r][1].type===`data`&&(i=r,r++):(!t[r]||t[r][1].type!==`data`)&&(r!==i+2&&(t[i][1].end=t[r-1][1].end,t.splice(i+2,r-i-2),r=i+2),i=void 0);return e?e(t,n):t}}function kN(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type===`lineEnding`)&&e[n-1][1].type===`data`){let r=e[n-1][1],i=t.sliceStream(r),a=i.length,o=-1,s=0,c;for(;a--;){let e=i[a];if(typeof e==`string`){for(o=e.length;e.charCodeAt(o-1)===32;)s++,o--;if(o)break;o=-1}else if(e===-2)c=!0,s++;else if(e!==-1){a++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(s=0),s){let i={type:n===e.length||c||s<2?`lineSuffix`:`hardBreakTrailing`,start:{_bufferIndex:a?o:r.start._bufferIndex+o,_index:r.start._index+a,line:r.end.line,column:r.end.column-s,offset:r.end.offset-s},end:{...r.end}};r.end={...i.start},r.start.offset===r.end.offset?Object.assign(r,i):(e.splice(n,0,[`enter`,i,t],[`exit`,i,t]),n+=2)}n++}return e}var AN=e({attentionMarkers:()=>RN,contentInitial:()=>MN,disable:()=>zN,document:()=>jN,flow:()=>PN,flowInitial:()=>NN,insideSpan:()=>LN,string:()=>FN,text:()=>IN}),jN={42:dN,43:dN,45:dN,48:dN,49:dN,50:dN,51:dN,52:dN,53:dN,54:dN,55:dN,56:dN,57:dN,62:Jj},MN={91:DM},NN={[-2]:oM,[-1]:oM,32:oM},PN={35:NM,42:lN,45:[yN,lN],60:RM,61:yN,95:lN,96:rM,126:rM},FN={38:eM,92:Qj},IN={[-5]:sN,[-4]:sN,[-3]:sN,33:rN,38:eM,42:Bj,60:[Wj,GM],91:aN,92:[jM,Qj],93:qM,95:Bj,96:uM},LN={null:[Bj,wN]},RN={null:[42,95]},zN={null:[]};function BN(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=uj(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=zj(a,l.events,l),l.events):[]}function f(e,t){return HN(p(e),t)}function p(e){return VN(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){let e;for(;r._index<o.length;){let t=o[r._index];if(typeof t==`string`)for(e=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===e&&r._bufferIndex<t.length;)_(t.charCodeAt(r._bufferIndex));else _(t)}}function _(e){u=u(e)}function v(e){wj(e)?(r.line++,r.column=1,r.offset+=e===-3?2:1,E()):e!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),l.previous=e}function y(e,t){let n=t||{};return n.type=e,n.start=m(),l.events.push([`enter`,n,l]),s.push(n),n}function b(e){let t=s.pop();return t.end=m(),l.events.push([`exit`,t,l]),t}function x(e,t){w(e,t.from)}function S(e,t){t.restore()}function C(e,t){return n;function n(n,r,i){let a,o,s,u;return Array.isArray(n)?f(n):`tokenize`in n?f([n]):d(n);function d(e){return t;function t(t){let n=t!==null&&e[t],r=t!==null&&e.null;return f([...Array.isArray(n)?n:n?[n]:[],...Array.isArray(r)?r:r?[r]:[]])(t)}}function f(e){return a=e,o=0,e.length===0?i:p(e[o])}function p(e){return n;function n(n){return u=T(),s=e,e.partial||(l.currentConstruct=e),e.name&&l.parser.constructs.disable.null.includes(e.name)?h(n):e.tokenize.call(t?Object.assign(Object.create(l),t):l,c,m,h)(n)}}function m(t){return e(s,u),r}function h(e){return u.restore(),++o<a.length?p(a[o]):i}}}function w(e,t){e.resolveAll&&!a.includes(e)&&a.push(e),e.resolve&&lj(l.events,t,l.events.length-t,e.resolve(l.events.slice(t),l)),e.resolveTo&&(l.events=e.resolveTo(l.events,l))}function T(){let e=m(),t=l.previous,n=l.currentConstruct,i=l.events.length,a=Array.from(s);return{from:i,restore:o};function o(){r=e,l.previous=t,l.currentConstruct=n,l.events.length=i,s=a,E()}}function E(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function VN(e,t){let n=t.start._index,r=t.start._bufferIndex,i=t.end._index,a=t.end._bufferIndex,o;if(n===i)o=[e[n].slice(r,a)];else{if(o=e.slice(n,i),r>-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function HN(e,t){let n=-1,r=[],i;for(;++n<e.length;){let a=e[n],o;if(typeof a==`string`)o=a;else switch(a){case-5:o=`\r`;break;case-4:o=`
|
|
@@ -104,14 +104,14 @@ https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(
|
|
|
104
104
|
`),r=(0,_.useMemo)(()=>{try{if(t)return sU.highlight(e,{language:t,ignoreIllegals:!0}).value;{let t=sU.highlightAuto(e);if(t.language)return t.value}}catch{}return null},[e,t]);return(0,K.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,K.jsx)(`div`,{className:`max-h-80 overflow-auto`,children:r?(0,K.jsxs)(`div`,{className:`flex`,children:[(0,K.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,K.jsx)(`div`,{className:`pr-3 py-px`,children:t+1},t))}),(0,K.jsx)(`pre`,{className:`flex-1 pl-2 py-px whitespace-pre-wrap break-all`,dangerouslySetInnerHTML:{__html:r}})]}):n.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex`,children:[(0,K.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,K.jsx)(`span`,{className:`pl-2 py-px whitespace-pre-wrap break-all`,style:{color:`var(--cm-text)`},children:e})]},t))})})}function KU({command:e,output:t}){return(0,K.jsxs)(`div`,{className:`overflow-hidden rounded-md bg-[#0d1117] border border-gray-700 text-xs`,children:[e&&(0,K.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,K.jsx)(`span`,{className:`select-none text-gray-500 text-[10px]`,children:`$`}),(0,K.jsx)(`span`,{className:`whitespace-pre-wrap break-all font-medium`,children:e})]}),t!==void 0&&(0,K.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,K.jsx)(`span`,{className:`text-gray-500 italic`,children:`(no output)`})})]})}function qU({toolName:e,args:t,result:n,status:r=`complete`,elapsedSeconds:i,taskState:a,toolCallId:o}){let s=PU(e),c=s.icon,l=IU(e,t),[u,d]=(0,_.useState)(!1),f=r===`complete`,p=r===`running`,m=r===`requires-action`,h=NU[r],g=lU(),{permissionPrompt:v,answerPermission:y,openFile:b}=CU(),x=m||v?.toolUseId===o,S=u||x,C=MU(p,i),w=f&&n?LU(n):null,T=w!==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??``,I=A&&N&&P,L=FU(t.file_path||t.filePath||``),R=!!(b&&L&&f),z=(0,_.useMemo)(()=>{let e=L.includes(`.`)?L.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:``)},[L]),B=D?Array.isArray(t.todos)?t.todos:[]:null,H=S?null:k&&M?HU(M,200):A&&(T||I)?{type:`edit`,oldStr:N,newStr:P,diff:w}:null;return(0,K.jsxs)(Dz,{open:S,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,K.jsxs)(Oz,{className:`flex w-full flex-col text-left text-sm transition-colors hover:bg-gray-50`,children:[(0,K.jsxs)(`div`,{className:`flex w-full items-center gap-1.5 md:gap-2 px-2 md:px-3 py-1.5`,children:[(0,K.jsx)(c,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,K.jsx)(`span`,{className:`font-medium text-gray-700 text-xs`,children:e}),l&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[11px] text-gray-500`,children:l})]}),x?(0,K.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,K.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:jU(C)}):(0,K.jsx)(`span`,{className:X(`ml-auto shrink-0 rounded px-1.5 py-px text-[10px] font-medium`,h.className),children:h.label}),(0,K.jsx)(F,{className:X(`h-3.5 w-3.5 shrink-0 text-gray-300 transition-transform`,u&&`rotate-180`)})]}),H&&(0,K.jsx)(`div`,{className:`border-t border-gray-100 px-2 md:px-3 py-1.5`,children:typeof H==`string`?(0,K.jsx)(`pre`,{className:`font-mono text-[10px] leading-relaxed text-gray-500 whitespace-pre-wrap break-all line-clamp-3`,children:H}):H.type===`edit`?H.diff&&n?(0,K.jsx)(BU,{text:n,lang:z,maxLines:8}):(0,K.jsx)(`div`,{className:`opacity-70`,children:(0,K.jsx)(WU,{oldStr:H.oldStr,newStr:H.newStr,maxLen:20,lang:z})}):null})]}),(0,K.jsx)(kz,{className:X(`overflow-hidden`,`data-[state=open]:animate-collapsible-down`,`data-[state=closed]:animate-collapsible-up`),children:(0,K.jsxs)(`div`,{className:X(`border-t border-gray-100 px-2 md:px-3 py-2`,g&&`max-h-[60vh] overflow-y-auto`),children:[x&&v&&(0,K.jsx)(AU,{toolName:v.toolName,title:v.title,displayName:v.displayName,onAllow:()=>y(v.toolUseId,!0),onDeny:()=>y(v.toolUseId,!1)}),R&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>b(L),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,K.jsx)(re,{className:`h-3 w-3`}),`Open in Editor`]}),k&&f&&M&&(0,K.jsx)(VU,{content:M,lang:z}),A&&f&&T&&n&&(0,K.jsx)(BU,{text:n,lang:z}),A&&f&&!T&&I&&(0,K.jsx)(WU,{oldStr:N,newStr:P,lang:z}),E&&(l||n!==void 0)&&(0,K.jsx)(KU,{command:l,output:n}),D&&B&&B.length>0&&(0,K.jsx)(dU,{todos:B}),O&&(0,K.jsx)(OU,{args:t,result:n,status:r,taskState:a,elapsedSeconds:C,toolCallId:o}),!k&&!E&&!D&&!O&&!(A&&(T||I))&&n!==void 0&&(0,K.jsx)(GU,{text:typeof n==`string`?n:JSON.stringify(n,null,2),lang:z}),p&&!x&&!n&&!j&&!O&&!(D&&B&&B.length>0)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs text-gray-400`,children:[(0,K.jsx)(we,{className:`h-3 w-3 animate-spin`}),`Working...`]}),r===`incomplete`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-red-500`,children:[(0,K.jsx)(V,{className:`h-3.5 w-3.5`}),`Tool call failed`]})]})})]})}var JU=class extends _.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,K.jsxs)(`div`,{className:`rounded border border-red-200 bg-red-50 p-3 text-xs text-red-700`,children:[(0,K.jsxs)(`b`,{children:[`Error in `,this.props.name,`:`]}),` `,this.state.error.message]}):this.props.children}};function YU(e){if(!e)return``;let t=e.match(/(\d{13})/);return t?new Date(parseInt(t[1],10)).toLocaleTimeString():``}function XU({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,K.jsxs)(`div`,{className:`my-2`,children:[(0,K.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm text-gray-500`,children:[(0,K.jsx)(`svg`,{className:`h-4 w-4`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,K.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,K.jsx)(`span`,{className:`font-medium`,children:`JSON`})]}),(0,K.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-gray-600/30 bg-gray-900`,children:(0,K.jsx)(`pre`,{className:`overflow-x-auto p-4`,children:(0,K.jsx)(`code`,{className:`block whitespace-pre font-mono text-sm text-gray-200`,children:n})})})]})}catch{return null}}function ZU(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 QU(){let e=Q(e=>e.message.id),{toolProgressMap:t,taskMap:n,thinkingOpen:r,setThinkingOpen:i}=CU(),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=YU(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)?ZU(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,K.jsx)(zE.GroupedParts,{groupBy:e=>e.type===`reasoning`?[`group-chainOfThought`,`group-reasoning`]:null,children:({part:e,children:s})=>{switch(e.type){case`group-chainOfThought`:return(0,K.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,K.jsxs)(Dz,{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,K.jsxs)(Oz,{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,K.jsx)(M,{className:`h-3 w-3 shrink-0 text-gray-400`}),(0,K.jsx)(`span`,{className:`text-gray-400`,children:o}),t&&(0,K.jsx)(`span`,{className:`shrink-0 rounded px-1 py-px text-[10px] font-medium text-gray-400`,children:`thinking`}),(0,K.jsx)(F,{className:X(`ml-auto h-3 w-3 shrink-0 text-gray-300 transition-transform`,(t||r)&&`rotate-180`)})]}),(0,K.jsx)(kz,{className:X(`overflow-hidden`,`data-[state=open]:animate-collapsible-down`,`data-[state=closed]:animate-collapsible-up`),children:(0,K.jsx)(`div`,{className:`border-t border-gray-100 px-3 py-2`,children:(0,K.jsx)(`div`,{className:`max-h-64 overflow-y-auto text-[12px] text-gray-500 leading-relaxed`,children:s})})})]})}case`text`:{let e=XU({content:o});return e?(0,K.jsx)(`div`,{children:e}):(0,K.jsx)(vz,{})}case`reasoning`:return(0,K.jsx)(vz,{});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,K.jsx)(JU,{name:`ToolRenderer:`+s,children:(0,K.jsx)(qU,{toolName:s,args:r,result:i,status:a,elapsedSeconds:c?.elapsed_time_seconds,taskState:l,toolCallId:o})})}default:return null}}});return(0,K.jsxs)(zE.Root,{"data-role":`assistant`,className:`relative pl-6 md:pl-8`,children:[(0,K.jsx)(`div`,{className:`absolute left-[5px] -top-2 -bottom-2 w-[2px] bg-gray-200`}),(0,K.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,K.jsx)(`div`,{className:`w-full text-[13px] md:text-sm text-gray-700`,children:u}),s&&(0,K.jsx)(`div`,{className:`mt-1 flex items-center gap-2 text-[11px] text-gray-400`,children:(0,K.jsx)(`span`,{children:s})})]})}var $U=[`Thinking`,`Processing`,`Analyzing`,`Working`,`Computing`,`Reasoning`];function eW(e){let t=Math.floor(e/60),n=e%60;return t<1?`${n}s`:`${t}m ${n}s`}function tW(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 nW({isLoading:e,getTokenCount:t,getWaitingForResponse:n}){let{thinkingBudget:r,turnGeneration:i,turnStartedAt:a}=CU(),[o,s]=(0,_.useState)(0),[c,l]=(0,_.useState)(0),[u,d]=(0,_.useState)(``);if((0,_.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,_.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=$U[Math.floor(o/3)%$U.length],p=n()?`↑`:`↓`,m=r===null?null:r>=32e3?`think-hard`:r>=16e3?`think`:null;return(0,K.jsxs)(`div`,{className:`relative mb-1.5 pl-6 md:pl-8`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 md:gap-3 text-xs text-gray-500 py-1`,children:[(0,K.jsxs)(`span`,{className:`font-medium text-gray-600`,children:[f,(0,K.jsx)(`span`,{className:`inline-block w-4 tabular-nums`,children:u})]}),m&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,K.jsx)(`span`,{className:`rounded bg-blue-50 px-1.5 py-0.5 text-[10px] font-medium text-blue-600`,children:m})]}),(0,K.jsx)(`span`,{className:`tabular-nums text-gray-500 ml-auto mr-1`,children:eW(o)}),(0,K.jsxs)(`span`,{className:`tabular-nums text-gray-600 font-medium`,children:[p,tW(c),` tk`]})]})]})}function rW({...e}){return(0,K.jsx)(vd,{"data-slot":`popover`,...e})}function iW({...e}){return(0,K.jsx)(yd,{"data-slot":`popover-trigger`,...e})}function aW({className:e,align:t=`center`,sideOffset:n=8,children:r,...i}){return(0,K.jsx)(bd,{children:(0,K.jsx)(xd,{"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 oW({...e}){return(0,K.jsx)(Sd,{"data-slot":`popover-close`,...e})}var sW=[{id:`bypassPermissions`,label:`YOLO`,description:`Sandboxed — safe to proceed freely`,icon:ut,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:Ye,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:ae,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:Ie,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:U,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:qe,color:`text-gray-600`,activeBg:`bg-gray-50`,activeBorder:`border-gray-200`,activeHover:`hover:bg-gray-100`}];function cW({mode:e,onChange:t,className:n=``}){let[r,i]=(0,_.useState)(!1),a=sW.find(t=>t.id===e)??sW[0],o=a.icon;return(0,K.jsxs)(rW,{open:r,onOpenChange:i,children:[(0,K.jsx)(iW,{asChild:!0,children:(0,K.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,K.jsx)(o,{className:X(`h-3 w-3`,a.color)}),(0,K.jsx)(`span`,{className:`hidden font-medium sm:inline`,children:a.label})]})}),(0,K.jsxs)(aW,{className:`w-56`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200 p-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900`,children:`Permission Mode`}),(0,K.jsx)(oW,{asChild:!0,children:(0,K.jsx)(`button`,{type:`button`,className:`rounded p-1 hover:bg-gray-100`,"aria-label":`Close`,children:(0,K.jsx)(lt,{className:`h-4 w-4 text-gray-500`})})})]}),(0,K.jsx)(`div`,{className:`py-1`,children:sW.map(n=>{let r=n.icon,a=n.id===e;return(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,K.jsx)(r,{className:X(`h-4 w-4`,n.color)}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:X(`text-sm font-medium`,a?`text-gray-900`:`text-gray-700`),children:n.label}),a&&(0,K.jsx)(`span`,{className:`rounded bg-blue-100 px-1.5 py-0.5 text-[9px] text-blue-700`,children:`Active`})]}),(0,K.jsx)(`p`,{className:`text-xs text-gray-500`,children:n.description})]})]})},n.id)})})]})]})}function lW(){let{provider:e,selectProvider:t,thinkingBlockCount:n,loopId:r}=CU(),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(0),f=(0,_.useRef)(null),p=(0,_.useRef)(null);(0,_.useEffect)(()=>{fh().then(a)},[]);let m=e?.name||`default`,h=e?.model||``,g=(0,_.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,_.useEffect)(()=>{d(0)},[c,o]),(0,_.useEffect)(()=>{p.current&&p.current.children[u]?.scrollIntoView({block:`nearest`})},[u]),(0,_.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 v=(0,_.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]),y=e=>e.toLowerCase().startsWith(`claude`),b=(0,_.useCallback)(async e=>{if(s(!1),!(e.provName===m&&e.modelId===h)){if(y(h)!==y(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 vm(r)}t(e.provName,e.source,e.modelId)}},[m,h,n,r,t]);return(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(te,{className:`h-3 w-3`}),(0,K.jsx)(`span`,{className:`font-medium text-gray-700 truncate max-w-16 md:max-w-24`,children:m}),h&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`hidden md:inline text-gray-400`,children:`/`}),(0,K.jsx)(`span`,{className:`hidden md:inline font-mono truncate max-w-20`,children:h})]}),(0,K.jsx)(F,{className:`h-2.5 w-2.5 text-gray-400`})]}),o&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/20`,onClick:()=>s(!1)}),(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[15vh]`,onClick:()=>s(!1),children:(0,K.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]&&b(g[u])):e.key===`Escape`&&s(!1)},children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,K.jsx)(Ue,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,K.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,K.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,K.jsxs)(`div`,{ref:p,className:`flex-1 overflow-y-auto py-2`,role:`listbox`,children:[Array.from(v.entries()).map(([e,t])=>(0,K.jsxs)(`div`,{className:`mb-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 py-1`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e}),(0,K.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,K.jsx)(ot,{className:`h-2 w-2`}):(0,K.jsx)(_e,{className:`h-2 w-2`}),t.source]})]}),t.models.map(t=>{let n=t.idx===u,r=e===m&&t.modelId===h;return(0,K.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n,onClick:()=>b(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,K.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,K.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-blue-500 shrink-0`})]},t.modelId)})]},e)),g.length===0&&(0,K.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,K.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,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(O,{className:`h-3 w-3`}),(0,K.jsx)(T,{className:`h-3 w-3`}),`navigate`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(W,{className:`h-3 w-3`}),`select`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-gray-100 font-mono text-[9px]`,children:`esc`}),`close`]})]})]})})]})]})}function uW({onPick:e}){let{availableSlashCommands:t}=CU(),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(0),c=(0,_.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,_.useMemo)(()=>c.reduce((e,t)=>e+t.skills.length,0),[c]),u=(0,_.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,_.useEffect)(()=>{s(0)},[i,n]),(0,_.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,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(`span`,{className:`text-sm leading-none`,"aria-hidden":`true`,children:`🧩`}),(0,K.jsx)(`span`,{className:`font-medium text-gray-700`,children:l})]}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/20`,onClick:()=>r(!1)}),(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[15vh]`,onClick:()=>r(!1),children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,K.jsx)(Ue,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,K.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,K.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[u.length,` / `,l]}),(0,K.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,K.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,K.jsxs)(`div`,{className:`mb-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 py-1`,children:[(0,K.jsx)(`span`,{className:`text-xs leading-none`,"aria-hidden":`true`,children:`🧩`}),(0,K.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,K.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,K.jsxs)(`span`,{className:`font-mono text-[12px] text-gray-900`,children:[`/`,e,`:`,t]}),n&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500 line-clamp-2`,children:n})]},t)})]},e))})(),u.length===0&&(0,K.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,K.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,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(O,{className:`h-3 w-3`}),(0,K.jsx)(T,{className:`h-3 w-3`}),`navigate`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(W,{className:`h-3 w-3`}),`insert`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-gray-100 font-mono text-[9px]`,children:`esc`}),`close`]})]})]})})]})]})}function dW({onClose:e,loopId:t}){let[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),f=(0,_.useCallback)(async()=>{a(!0),r((await ig(t)).servers),a(!1)},[t]);(0,_.useEffect)(()=>{f()},[f]);let p=async e=>{if(o)return;s(e),l(null);let n=await ag(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 og(e),s(null),f())},h=async(e,n)=>{let r=await eg(e,n,t);return r.ok?(await f(),null):r.error};return(0,K.jsxs)(`div`,{className:`text-sm`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-gray-200`,children:[(0,K.jsx)(`div`,{className:`text-[13px] font-medium text-gray-700`,children:`MCP servers`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:f,className:`p-1 text-gray-400 hover:text-gray-700 rounded`,title:`reload`,children:(0,K.jsx)(Be,{size:12,className:i?`animate-spin`:``})}),(0,K.jsx)(`button`,{onClick:e,className:`p-1 text-gray-400 hover:text-gray-700 rounded`,title:`close`,children:(0,K.jsx)(lt,{size:14})})]})]}),c&&(0,K.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,K.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,K.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto`,children:i&&n.length===0?(0,K.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400`,children:`loading…`}):n.length===0?(0,K.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,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded font-mono text-[11px]`,children:`settings.json`}),`'s`,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded font-mono text-[11px]`,children:`mcpServers`}),`.`]}):n.map(e=>(0,K.jsx)(fW,{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,K.jsx)(`div`,{className:`border-t border-gray-200 px-3 py-2 flex items-center justify-end text-[11px]`,children:(0,K.jsxs)(`button`,{onClick:async()=>{d(null);let e=await sg(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,K.jsx)(Ve,{size:10}),` Reload session`]})})]})}function fW({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,_.useState)(!1),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(null);return(0,K.jsxs)(`div`,{className:`border-b border-gray-50 last:border-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50`,children:[(0,K.jsx)(`span`,{className:`text-[14px] text-gray-300 leading-none`,children:e.authed?`●`:o?`○`:`·`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,K.jsx)(`span`,{className:`font-medium text-gray-700 text-[13px]`,children:e.name}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase`,children:e.type})]}),e.url&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 font-mono truncate`,children:e.url})]}),(0,K.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1`,children:[e.authed&&(0,K.jsxs)(`span`,{className:`text-[11px] text-green-700 inline-flex items-center gap-1`,children:[(0,K.jsx)(P,{size:11}),` authed`]}),o&&(0,K.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,K.jsx)(Se,{size:10}):(0,K.jsx)(nt,{size:10}),t?`…`:e.authed?`re-auth`:`auth`]}),e.authed&&r&&(0,K.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,K.jsx)(it,{size:10}),` forget`]}),s&&(0,K.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,K.jsx)(be,{size:10}),e.authed?`re-setup`:`setup`]}),!s&&!o&&!e.authed&&a&&(e.oauthSupport===`manual`?(0,K.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,K.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,K.jsx)(`span`,{className:`text-[11px] text-red-500`,title:`Probe failed — server unreachable or returned malformed metadata.`,children:`unreachable`}):e.authTokenEnv===null?(0,K.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,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:`stdio`})]})]}),c&&s&&(0,K.jsxs)(`div`,{className:`px-3 pb-2.5 pt-0.5 bg-gray-50/60`,children:[(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 mb-1.5`,children:[`到`,` `,(0,K.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,K.jsx)(re,{size:9})]}),` `,`复制你的 MCP URL,粘贴到下面 —— 会自动解析出`,` `,(e.requiredEnvs??[]).join(`、`)||`所需密钥`,` 并存进你的 vault。`]}),(0,K.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,K.jsx)(`div`,{className:`text-[11px] text-red-600 mt-1`,children:m}),(0,K.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,K.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,K.jsx)(`button`,{onClick:()=>{l(!1),d(``),h(null)},className:`text-[11px] text-gray-500 hover:text-gray-800`,children:`取消`})]})]})]})}var pW=[{id:`think`,name:`Think`,description:`Extended thinking (16k token budget)`,icon:M,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:16e3},{id:`think-hard`,name:`Think Hard`,description:`Deep thinking (32k token budget)`,icon:ut,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:32e3},{id:`ultrathink`,name:`Ultrathink`,description:`Maximum thinking (no budget limit)`,icon:Ye,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:null},{id:`plan`,name:`Permission`,description:`Cycle permission mode`,icon:He,group:`quick`,action:`toggle`,prefix:``,toggleKey:`permissionMode`},{id:`goal`,name:`Goal`,description:`Set goal (/goal <text>), mark done (/goal done), clear (/goal clear)`,icon:$e,group:`quick`,action:`agent`,prefix:``},{id:`usage`,name:`Context Usage`,description:`Show context window token usage`,icon:N,group:`quick`,action:`command`,prefix:``,commandKey:`getContextUsage`},{id:`clear`,name:`Clear Context`,description:`Reset AI conversation (history kept)`,icon:G,group:`quick`,action:`command`,prefix:``,commandKey:`clearContext`},{id:`mcp`,name:`MCP Servers`,description:`Show MCP servers + tools available to this loop`,icon:Me,group:`quick`,action:`command`,prefix:``,commandKey:`openMcpPanel`}],mW=[{id:`quick`,label:`Quick actions`},{id:`plugin`,label:`Plugin commands`},{id:`skill`,label:`Skills`}],hW=new Set(pW.map(e=>e.id));function gW(){let e=Q(e=>e.composer.text),t=tw(),{permissionMode:n,setPermissionMode:r,clearContext:i,setMaxThinkingTokens:a,getContextUsage:o,availableSlashCommands:s,suppressSlashRef:c,loopId:l}=CU(),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(0),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(!1),y=(0,_.useRef)(null),b=(0,_.useMemo)(()=>{let e=s.filter(e=>!hW.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?ze:et,group:t?`plugin`:`skill`,action:`agent`,prefix:``,pluginName:n}});return[...pW,...e]},[s]),x=typeof e==`string`?e.trimStart():e,S=typeof x==`string`&&x.startsWith(`/`)&&!x.includes(` `);S&&c.current&&(S=!1);let C=S?x.slice(1).toLowerCase():``,w=(0,_.useMemo)(()=>b.filter(e=>!C||e.id.toLowerCase().includes(C)||e.name.toLowerCase().includes(C)),[b,C]),T=(0,_.useMemo)(()=>{let e={quick:0,plugin:1,skill:2};return[...w].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])},[w]),E=(0,_.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,_.useEffect)(()=>{S?(d(!0),h(C),p(0)):d(!1)},[S,C]);let D=(0,_.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`&&(v(!0),t.setText(``)):e.action===`agent`&&t.setText(`/${e.id} `);d(!1)},[t,n,r,i,a,o]);(0,_.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,_.useEffect)(()=>{if(!y.current)return;let e=y.current.querySelector(`[data-slash-idx="${f}"]`);e&&e.scrollIntoView({block:`nearest`})},[f]);let O=-1;return g&&(!u||T.length===0)?(0,K.jsx)(`div`,{className:`relative`,children:(0,K.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,K.jsx)(dW,{onClose:()=>v(!1),loopId:l})})}):!u||T.length===0?null:(0,K.jsxs)(`div`,{className:`relative`,children:[g&&(0,K.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,K.jsx)(dW,{onClose:()=>v(!1),loopId:l})}),(0,K.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,K.jsx)(`div`,{ref:y,className:`max-h-72 overflow-y-auto py-1`,children:mW.map(e=>{let t=E.get(e.id);return!t||t.length===0?null:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`px-3 pt-2 pb-1`,children:(0,K.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,K.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,K.jsx)(r,{className:`h-4 w-4 flex-shrink-0 ${a?`text-blue-600`:`text-gray-400`}`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[`/`,e.id]}),e.action===`toggle`&&a&&(0,K.jsx)(`span`,{className:`rounded bg-blue-100 px-1 py-0.5 text-[9px] text-blue-600`,children:`ON`})]}),(0,K.jsx)(`p`,{className:`text-xs text-gray-500 truncate`,children:e.description})]})]},e.id)})]},e.id)})})})]})}function _W({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,K.jsxs)(zp,{children:[(0,K.jsx)(Bp,{asChild:!0,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-gray-500`,children:[(0,K.jsxs)(`svg`,{width:`24`,height:`24`,viewBox:`0 0 24 24`,className:`-rotate-90 transform`,children:[(0,K.jsx)(`circle`,{cx:`12`,cy:`12`,r:10,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`text-gray-300`}),(0,K.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,K.jsxs)(`span`,{children:[n.toFixed(0),`%`]})]})}),(0,K.jsx)(Vp,{children:(0,K.jsx)(`div`,{className:`text-xs`,children:(0,K.jsxs)(`p`,{children:[e.toLocaleString(),` / `,t.toLocaleString(),` tokens`]})})})]})}function vW({loopId:e,onPick:t,onClose:n}){let[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(!0),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(0),[p,m]=(0,_.useState)(new Set),[h,g]=(0,_.useState)({}),v=(0,_.useRef)(null),y=(0,_.useRef)(null);(0,_.useEffect)(()=>{c(!0),Promise.all([ym(e,`workdir`).catch(()=>[]),bm(e,`workdir`).catch(()=>[])]).then(([e,t])=>{i(e),o(t),c(!1)})},[e]);let b=l.trim().length>0,x=(0,_.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]),S=(0,_.useMemo)(()=>{if(b)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,b,p,h]);(0,_.useEffect)(()=>{f(0)},[l]),(0,_.useEffect)(()=>{y.current&&y.current.children[d]?.scrollIntoView({block:`nearest`})},[d]);let C=(0,_.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 ym(e,t.path).catch(()=>[]);g(e=>({...e,[t.path]:n}))}m(e=>new Set(e).add(t.path))}},[p,h,e]),w=(0,_.useCallback)(e=>{if(e.type===`dir`){C(e);return}t(e.path)},[C,t]);return(0,dt.createPortal)((0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/20`,onClick:n}),(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[15vh]`,onClick:n,children:(0,K.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(b)e.key===`ArrowDown`?(e.preventDefault(),f(e=>Math.min(e+1,x.length-1))):e.key===`ArrowUp`?(e.preventDefault(),f(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),x[d]&&t(x[d].path));else if(e.key===`ArrowDown`)e.preventDefault(),f(e=>Math.min(e+1,S.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=S[d];if(!t||t.entry.type!==`dir`)return;let n=p.has(t.entry.path);(e.key===`ArrowRight`&&!n||e.key===`ArrowLeft`&&n)&&C(t.entry)}else e.key===`Enter`&&(e.preventDefault(),S[d]&&w(S[d].entry))},children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,K.jsx)(Ue,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,K.jsx)(`input`,{ref:v,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,K.jsx)(`div`,{ref:y,className:`flex-1 overflow-y-auto py-2`,role:`listbox`,children:s?(0,K.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`Loading...`}):b?x.length===0?(0,K.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`No files match your search`}):x.map((e,n)=>(0,K.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,K.jsx)(ce,{size:12,className:`text-blue-400 shrink-0`}),(0,K.jsx)(`span`,{className:`truncate font-mono text-gray-700`,children:e.path})]},e.path)):r.length===0?(0,K.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`No files found`}):S.map(({entry:e,depth:t},n)=>{let r=e.type===`dir`,i=p.has(e.path);return(0,K.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n===d,onClick:()=>w(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,K.jsxs)(K.Fragment,{children:[i?(0,K.jsx)(F,{size:11,className:`text-gray-300 shrink-0`}):(0,K.jsx)(I,{size:11,className:`text-gray-300 shrink-0`}),(0,K.jsx)(fe,{size:13,className:`text-amber-500 shrink-0`})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`w-[11px] shrink-0`}),(0,K.jsx)(ce,{size:13,className:`text-blue-400 shrink-0`})]}),(0,K.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path)})}),(0,K.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,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(O,{className:`h-3 w-3`}),(0,K.jsx)(T,{className:`h-3 w-3`}),`navigate`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(W,{className:`h-3 w-3`}),`select`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-gray-100 font-mono text-[9px]`,children:`esc`}),`close`]})]})]})})]}),document.body)}var yW=2e5,bW=500;function xW({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:v,goal:y,setGoal:b,goalStatus:x,completeGoal:S}=CU(),C=a?.contextWindow??yW,w=Uv(),[T,E]=(0,_.useState)(!1),[D,k]=(0,_.useState)([]),[A,j]=(0,_.useState)(!1),M=[...T&&e?[e]:[],...D],N=()=>E(e=>!e),P=e=>{k(t=>t.includes(e)?t:[...t,e]),j(!1)},F=e=>{k(t=>t.filter(t=>t!==e))},I=e=>{let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e},L=(0,_.useRef)(``),R=(0,_.useRef)([]),[B,V]=(0,_.useState)(!1);(0,_.useEffect)(()=>{let n=!1;async function r(){if(M.length===0){L.current=``,R.current=[];return}V(!0);let r=[],i=[];for(let a of M){if(n)return;try{let n=await xm(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(`
|
|
105
105
|
`),t=Math.max(0,s.from-1),r=Math.min(e.length,s.to);c=e.slice(t,r).join(`
|
|
106
106
|
`),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,V(!1))}return r(),()=>{n=!0}},[M.join(`,`),f,e,t?.from,t?.to]);let H=e=>{let t=L.current;return t?`${t}\n${e}`:e},[U,ee]=(0,_.useState)([]),[W,te]=(0,_.useState)(-1),ne=(0,_.useRef)(``),G=(0,_.useRef)(``);G.current=typeof i==`string`?i:``,(0,_.useEffect)(()=>{f&&Bm(f).then(e=>{ee(e),te(-1)})},[f]);let re=e=>{if(!e.trim()||!f)return;let t=e.trim();ee(e=>{if(e[e.length-1]===t)return e;let n=[...e,t];return n.length>bW&&n.splice(0,n.length-bW),n}),te(-1),Vm(f,t).catch(()=>{})},ie=()=>{let e=typeof i==`string`?i.trim():``;if(e){if(re(e),L.current)try{sessionStorage.setItem(`loopat:pendingFileContext`,L.current)}catch{}c(H(e)),w.composer().setText(``)}};return(0,K.jsxs)(YT.Root,{className:`relative flex w-full flex-col`,onSubmit:()=>{let e=G.current.trim();if(e&&(re(e),L.current))try{sessionStorage.setItem(`loopat:pendingFileContext`,L.current)}catch{}},children:[(0,K.jsx)(nW,{isLoading:n,getTokenCount:h,getWaitingForResponse:g}),l.length>0&&(0,K.jsx)(`div`,{className:`mb-1.5 space-y-1 px-2`,children:l.map((e,t)=>(0,K.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,K.jsxs)(`span`,{className:`text-xs text-gray-600 line-clamp-3 break-words whitespace-pre-wrap min-w-0`,children:[(0,K.jsxs)(`span`,{className:`text-gray-400 mr-1.5 shrink-0`,children:[t+1,`.`]}),e]}),(0,K.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,K.jsx)(lt,{className:`h-3.5 w-3.5`})})]},t))}),M.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 mb-1 flex-wrap`,children:[M.map(n=>(0,K.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,K.jsx)(ce,{size:11,className:`shrink-0`}),(0,K.jsx)(`span`,{className:`truncate max-w-[160px]`,children:I(n)}),n!==e&&(0,K.jsx)(`button`,{onClick:()=>F(n),className:`ml-0.5 hover:text-blue-900`,children:(0,K.jsx)(lt,{size:11})}),n===e&&T&&(0,K.jsx)(`span`,{className:`text-[9px] text-blue-400 ml-0.5`,children:t?`(${t.from}-${t.to})`:`editor`})]},n)),B&&(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:`loading...`})]}),y&&(0,K.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-2 px-2 py-1.5 rounded-lg border group ${x===`completed`?`border-green-200 bg-green-50`:`border-amber-200 bg-amber-50`}`,children:[x===`completed`?(0,K.jsx)(z,{className:`h-3.5 w-3.5 text-green-600 shrink-0`}):(0,K.jsx)($e,{className:`h-3.5 w-3.5 text-amber-600 shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0 ${x===`completed`?`text-green-800 line-through`:`text-amber-800`}`,children:y}),x===`active`&&(0,K.jsx)(`button`,{onClick:()=>S?.(),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,K.jsx)(`button`,{onClick:()=>b?.(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,K.jsx)(lt,{className:`h-3 w-3 ${x===`completed`?`text-green-500`:`text-amber-600`}`})})]}),(0,K.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,K.jsx)(gW,{}),(0,K.jsx)(YT.Input,{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&&G.current.trim().length>0){e.preventDefault(),w.composer().setText(``);return}}if(e.key!==`ArrowUp`&&e.key!==`ArrowDown`&&(v.current=!1),e.key===`Enter`&&!e.nativeEvent.isComposing&&!e.shiftKey&&n){e.preventDefault(),ie();return}if(e.key===`ArrowUp`&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey){if(U.length===0)return;if(e.preventDefault(),v.current=!0,W===-1)ne.current=G.current,te(U.length-1),w.composer().setText(U[U.length-1]);else if(W>0){let e=W-1;te(e),w.composer().setText(U[e])}return}if(e.key===`ArrowDown`&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey){if(W===-1)return;if(e.preventDefault(),v.current=!0,W<U.length-1){let e=W+1;te(e),w.composer().setText(U[e])}else te(-1),w.composer().setText(ne.current);return}}}}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-0.5 border-t border-gray-100 pt-2 overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5 min-w-0`,children:[(0,K.jsx)(_W,{used:Math.min(p,C),total:C}),(0,K.jsx)(lW,{}),(0,K.jsx)(uW,{onPick:e=>{let t=G.current,n=t.length===0||t.endsWith(` `)?`${t}${e}`:`${t} ${e}`;w.composer().setText(n)}}),e&&(0,K.jsxs)(`button`,{type:`button`,onClick:N,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,K.jsx)(ce,{size:12}),I(e)]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>j(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,K.jsx)(se,{size:12})}),A&&(0,K.jsx)(vW,{loopId:f,onPick:P,onClose:()=>j(!1)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 shrink-0`,children:[(0,K.jsx)(cW,{mode:o,onChange:s}),r&&(n?(0,K.jsx)(kg,{type:`button`,variant:`default`,size:`icon`,onClick:ie,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,K.jsx)(Ce,{className:`h-4 w-4`})}):(0,K.jsx)(YT.Send,{asChild:!0,children:(0,K.jsx)(kg,{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,K.jsx)(O,{className:`h-4 w-4`})})})),(0,K.jsx)(Wv,{condition:e=>e.thread.isRunning,children:(0,K.jsx)(YT.Cancel,{asChild:!0,children:(0,K.jsx)(kg,{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,K.jsx)(Xe,{className:`h-3 w-3 fill-current`})})})})]})]})]})]})}function SW({questions:e,toolUseId:t,onAnswers:n,onDismiss:r,disabled:i=!1}){let[a,o]=(0,_.useState)({}),[s,c]=(0,_.useState)({}),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.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}))},v=e=>s[e.question]?.trim()||a[e.question]||``,y=p.every(e=>{let t=v(e);return t!==void 0&&t!==``}),b=e=>{let t=v(e);return t!==void 0&&t!==``},x=()=>{if(!y||!t||!n||l)return;u(!0);let e={};for(let t of p)e[t.question]=v(t);n(t,e)},S=()=>{i||l||(u(!0),r?.(t||``))},C=()=>{f(e=>Math.min(e+1,p.length-1))},w=(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,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-violet-600 font-medium`,children:[(0,K.jsx)(B,{className:`h-3.5 w-3.5`}),(0,K.jsx)(`span`,{children:p.length>1?`Question ${d+1} of ${p.length}`:`Question`})]}),(0,K.jsx)(`button`,{type:`button`,onClick:S,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,K.jsx)(lt,{className:`h-3.5 w-3.5`})})]}),p.length>1&&(0,K.jsx)(`div`,{className:`flex gap-1 border-b border-gray-200`,children:p.map((e,t)=>{let n=b(e);return(0,K.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,K.jsx)(P,{className:`h-3 w-3 text-emerald-500`}),w(e,t)]},t)})}),(0,K.jsxs)(`div`,{className:`overflow-y-auto max-h-[260px] space-y-1.5`,children:[T.header&&(0,K.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wide text-gray-400`,children:T.header}),(0,K.jsx)(`p`,{className:`text-[12px] text-gray-800 font-medium`,children:T.question}),(0,K.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,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[T.multiSelect?(0,K.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,K.jsx)(`svg`,{className:`h-2.5 w-2.5 text-white`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,K.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:3,d:`M5 13l4 4L19 7`})})}):(0,K.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,K.jsx)(`span`,{className:`block h-1.5 w-1.5 rounded-full bg-white m-0.5`})}),(0,K.jsx)(`span`,{children:n}),r&&(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[`— `,r]})]})},t)})}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between pt-1`,children:[p.length>1&&d<p.length-1?(0,K.jsxs)(`button`,{type:`button`,disabled:i,onClick:C,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,K.jsx)(I,{className:`h-3 w-3`})]}):(0,K.jsx)(`div`,{}),(0,K.jsxs)(`button`,{type:`button`,disabled:!y||i,onClick:x,className:X(`inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,y?`bg-gray-900 text-white hover:bg-gray-800`:`bg-gray-100 text-gray-400 cursor-not-allowed`),children:[(0,K.jsx)(We,{className:`h-3 w-3`}),`Submit`]})]}),l&&(0,K.jsx)(`p`,{className:`text-[11px] text-emerald-600 font-medium text-right`,children:`Submitted`})]})}var CW=()=>(0,K.jsxs)(`div`,{className:`my-auto flex grow flex-col items-center justify-center gap-3`,children:[(0,K.jsx)(`div`,{className:`h-5 w-5 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600`}),(0,K.jsx)(`p`,{className:`text-sm text-gray-400`,children:`Loading history…`})]}),wW=`loopat:composer:drafts`;function TW(e){try{let t=localStorage.getItem(wW);return t?JSON.parse(t)[e]??null:null}catch{return null}}function EW(e,t){try{let n=localStorage.getItem(wW),r=n?JSON.parse(n):{};t.trim()?r[e]=t:delete r[e],localStorage.setItem(wW,JSON.stringify(r))}catch{}}function DW({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:v,showHistory:y,toggleShowHistory:b,hasOlderMessages:x,loadMoreMessages:S,thinkingBudget:C,setMaxThinkingTokens:w}=CU(),[E,D]=(0,_.useState)(`normal`),O=Q(e=>e.thread.isEmpty&&!e.thread.isRunning)&&!h,k=(0,_.useRef)(null),A=(0,_.useRef)(null),[j,M]=(0,_.useState)(!1),N=(0,_.useCallback)(()=>{let e=A.current;e&&e.scrollTo({top:e.scrollHeight,behavior:`smooth`})},[]),P=(0,_.useRef)(v);P.current=v;let F=(0,_.useRef)(y);F.current=y;let I=(0,_.useRef)(x);I.current=x;let[L,R]=(0,_.useState)(!1),z=(0,_.useRef)({oldScrollTop:0,oldScrollHeight:0,active:!1}),B=(0,_.useCallback)(()=>{let e=A.current;e&&(z.current={oldScrollTop:e.scrollTop,oldScrollHeight:e.scrollHeight,active:!0}),b()},[b]),V=(0,_.useRef)({oldScrollTop:0,oldScrollHeight:0,active:!1}),H=(0,_.useCallback)(()=>{let e=A.current;e&&(V.current={oldScrollTop:e.scrollTop,oldScrollHeight:e.scrollHeight,active:!0}),ee(!0),S()},[S]),[U,ee]=(0,_.useState)(!1),W=(0,_.useRef)(!1);W.current=U;let te=tw(),ne=Q(e=>e.composer.text),G=(0,_.useRef)(ne);G.current=ne,(0,_.useEffect)(()=>{let e=TW(g);e&&te.setText(e)},[]),(0,_.useEffect)(()=>()=>{EW(g,G.current)},[g]),(0,_.useEffect)(()=>{if(!ne)return;let e=setTimeout(()=>{EW(g,ne)},300);return()=>clearTimeout(e)},[ne,g]);let[re,ie]=(0,_.useState)(ne);(0,_.useEffect)(()=>{re&&!ne&&EW(g,``),ie(ne)},[ne,g]);let ae=(0,_.useRef)(null),oe=(0,_.useRef)(!1),se=(0,_.useRef)(h);se.current=h;let ce=(0,_.useRef)(h);(0,_.useEffect)(()=>{let e=k.current,t=e?.parentElement;if(!e||!t)return;A.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),M(t.scrollTop+t.clientHeight<t.scrollHeight-200),R(t.scrollTop<20&&P.current),t.scrollTop<40&&I.current&&!W.current&&H()};t.addEventListener(`scroll`,o,{passive:!0}),t.addEventListener(`wheel`,a,{passive:!0});let s=null,c=!1,l=()=>{if(oe.current&&r||c||!oe.current&&t.scrollHeight<=t.clientHeight+10)return;let e=t.style.scrollBehavior;t.style.scrollBehavior=`auto`,t.scrollTop=t.scrollHeight,t.style.scrollBehavior=e,oe.current||(se.current||(oe.current=!0),r=!1),c=!0,requestAnimationFrame(()=>{setTimeout(()=>{c=!1},120)})};l();let u=new ResizeObserver(()=>{s||se.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,_.useEffect)(()=>{if(ce.current&&!h){let e=A.current;if(e){let t=e.style.scrollBehavior;e.style.scrollBehavior=`auto`,e.scrollTop=e.scrollHeight,e.style.scrollBehavior=t,oe.current=!0}}ce.current=h},[h]),(0,_.useEffect)(()=>{if(!z.current.active)return;let e=A.current;if(!e)return;let{oldScrollTop:t,oldScrollHeight:n}=z.current;z.current.active=!1,requestAnimationFrame(()=>{e.scrollTop=t+(e.scrollHeight-n)})},[y]),(0,_.useEffect)(()=>{if(!V.current.active)return;let e=A.current;if(!e)return;let{oldScrollTop:t,oldScrollHeight:n}=V.current;V.current.active=!1,requestAnimationFrame(()=>{e.scrollTop=t+(e.scrollHeight-n)})},[x]),(0,_.useEffect)(()=>{if(!U)return;let e=setTimeout(()=>ee(!1),200);return()=>clearTimeout(e)},[U,x]);let le=p.size>0?Array.from(p.entries()):[];return(0,K.jsxs)(pD.Root,{className:`flex h-full flex-col bg-white relative`,style:{"--thread-max-width":`44rem`},children:[(0,K.jsx)(pD.Viewport,{turnAnchor:`top`,className:O?`hidden`:`relative flex-1 overflow-x-auto overflow-y-scroll scroll-smooth`,children:(0,K.jsxs)(`div`,{ref:k,className:`mx-auto flex w-full min-h-full flex-col px-2 md:px-3 pt-3 md:pt-4`,children:[h&&(0,K.jsx)(CW,{}),L&&(0,K.jsx)(`div`,{className:`flex justify-center pb-2`,children:(0,K.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:y?`Collapse earlier messages`:`View earlier messages`})}),U&&(0,K.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,K.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,K.jsx)(`div`,{className:`flex flex-col gap-1 pb-2`,children:(s??[]).slice(1).map(e=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-gray-500`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-px bg-gray-200`}),(0,K.jsxs)(`span`,{className:`text-gray-600`,children:[(0,K.jsx)(`span`,{className:`text-amber-600`,children:`▸`}),` `,`driving by `,(0,K.jsx)(`span`,{className:`text-gray-900 font-medium`,children:e.driver}),` since `,new Date(e.since).toLocaleString()]}),(0,K.jsx)(`div`,{className:`flex-1 h-px bg-gray-200`})]},e.since))}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 pb-1`,children:[(0,K.jsx)(pD.Messages,{children:({message:e})=>e.role===`user`?(0,K.jsx)(Ez,{}):(0,K.jsx)(QU,{})}),(0,K.jsx)(`div`,{ref:ae}),le.length>0&&(0,K.jsx)(JU,{name:`QuestionsPanel`,children:(0,K.jsx)(`div`,{className:`space-y-3 w-full pt-2`,children:le.map(([e,t])=>Array.isArray(t)&&t.length>0?(0,K.jsx)(`div`,{className:`rounded-lg border border-violet-100 bg-violet-50/30 p-4 shadow-sm`,children:(0,K.jsx)(SW,{questions:t,toolUseId:e,onAnswers:m,onDismiss:e=>m(e,{})})},e):null)})})]})]})}),(0,K.jsx)(`div`,{className:O?`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,K.jsxs)(`div`,{className:O?`w-full max-w-[36rem]`:``,children:[O&&(0,K.jsxs)(`div`,{className:`mb-4 space-y-2 px-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[a&&(0,K.jsx)(`h1`,{className:`text-xl font-semibold text-gray-800`,children:a}),o&&(0,K.jsxs)(`span`,{className:`text-xs text-gray-400`,children:[`driver: `,o]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-400`,children:[r&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,K.jsx)(he,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,K.jsxs)(`span`,{className:`font-mono truncate`,children:[r,i?(0,K.jsxs)(`span`,{className:`text-gray-300`,children:[` · `,i]}):``]})]}),(0,K.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,K.jsx)(`button`,{type:`button`,onClick:()=>{D(e.mode===`normal`?`normal`:e.mode===`ultra`?`ultra`:`normal`),w(e.tokens)},className:`px-1.5 py-0.5 text-[11px] rounded transition-colors `+((e.mode===`normal`?C===null&&E===`normal`:e.mode===`ultra`?C===null&&E===`ultra`:C===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,K.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,K.jsx)(`span`,{children:`📦`}),(0,K.jsx)(`span`,{className:`flex-1`,children:`This loop is archived (read-only).`}),t&&(0,K.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,K.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,K.jsx)(`span`,{children:`✋`}),(0,K.jsxs)(`span`,{className:`flex-1`,children:[`Released for drive`,l?` by ${l}`:``,` — no one can write until someone takes over.`]}),u&&(0,K.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,K.jsx)(xW,{pickedFile:d,editorSelection:f})]})}),j&&(0,K.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,K.jsx)(T,{className:`h-3.5 w-3.5`})})]})}function OW(){let{id:e}=Un(),[t,n]=(0,_.useState)(null);return(0,_.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{let r=await _m(e);t||n(r??`unauthorized`)})(),()=>{t=!0}},[e]),(0,_.useEffect)(()=>{t&&typeof t==`object`&&(document.title=`${t.title} · shared`)},[t]),e?t===null?(0,K.jsx)(AW,{}):t===`unauthorized`?(0,K.jsx)(jW,{reason:`this loop is private or does not exist`}):(0,K.jsx)(kW,{meta:t}):(0,K.jsx)(jW,{reason:`missing loop id`})}function kW({meta:e}){let{runtime:t,connected:n,reconnecting:r,extra:i}=TU(e.id,``);return(0,K.jsxs)(`div`,{className:`h-full w-full flex flex-col bg-white text-gray-900`,children:[(0,K.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,K.jsx)(`span`,{className:`text-lg leading-none`,children:`🧶`}),(0,K.jsx)(`span`,{className:`text-[14px] font-medium text-gray-900 truncate`,children:e.title}),(0,K.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,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`span`,{className:`text-[11px] `+(n?`text-emerald-600`:r?`text-amber-500`:`text-red-500`),title:n?`connected`:r?`reconnecting…`:`disconnected`,children:`●`})]}),(0,K.jsx)(`main`,{className:`flex-1 min-h-0`,children:(0,K.jsx)(wU,{extra:i,children:(0,K.jsx)(ew,{runtime:t,children:(0,K.jsx)(DW,{readOnly:!0})})})})]})}function AW(){return(0,K.jsx)(`div`,{className:`h-full w-full flex items-center justify-center text-gray-400 text-sm`,children:`loading…`})}function jW({reason:e}){return(0,K.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,K.jsx)(`span`,{className:`text-lg`,children:`🧶`}),(0,K.jsx)(`div`,{className:`text-sm`,children:`Loop unavailable`}),(0,K.jsx)(`div`,{className:`text-xs text-gray-400`,children:e})]})}function MW(e){let[t,n]=(0,_.useState)({}),r=(0,_.useRef)(null);return(0,_.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 NW=`loopat:tree:expanded:`;function PW(e){try{let t=localStorage.getItem(NW+e);return t?new Set(JSON.parse(t)):new Set}catch{return new Set}}function FW(e,t){try{localStorage.setItem(NW+e,JSON.stringify([...t]))}catch{}}function IW({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,K.jsx)(K.Fragment,{children:t.map(t=>(0,K.jsx)(LW,{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 LW({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,_.useState)(()=>PW(e).has(t.path)),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(!1),[v,y]=(0,_.useState)(null),b=(0,_.useCallback)(()=>{let n=PW(e);n.has(t.path)?n.delete(t.path):n.add(t.path),FW(e,n),f(e=>!e)},[e,t.path]),x=(0,_.useRef)(u);(0,_.useEffect)(()=>{x.current!==u&&(m(null),x.current=u)},[u]),(0,_.useEffect)(()=>{!d||p!==null||t.type===`dir`&&(g(!0),a(t.path).then(m).finally(()=>g(!1)))},[d,t.path,a,p]);let S=e=>{e.preventDefault(),e.stopPropagation(),y({x:e.clientX,y:e.clientY})},C=8+n*12;if(t.type===`dir`)return c?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{onContextMenu:S,children:c(t,n,d,b)}),d&&p&&(0,K.jsx)(K.Fragment,{children:p.map(t=>(0,K.jsx)(LW,{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))}),v&&(0,K.jsx)(RW,{x:v.x,y:v.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>y(null)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{onContextMenu:S,children:(0,K.jsxs)(`button`,{type:`button`,onClick:b,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:C,paddingRight:8},children:[(0,K.jsx)(`span`,{className:`text-gray-500 w-3`,children:d?`▾`:`▸`}),(0,K.jsx)(`span`,{className:`text-gray-500`,children:d?(0,K.jsx)(fe,{size:13}):(0,K.jsx)(me,{size:13})}),(0,K.jsx)(`span`,{className:`text-[13px] text-gray-900 truncate`,children:t.name})]})}),h&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,style:{paddingLeft:C+12},children:`...`}),d&&p&&(0,K.jsxs)(K.Fragment,{children:[p.map(t=>(0,K.jsx)(LW,{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,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-1`,style:{paddingLeft:C+12},children:`(empty)`})]}),v&&(0,K.jsx)(RW,{x:v.x,y:v.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>y(null)})]});let w=i===t.path;return c?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{onContextMenu:S,onClick:()=>r(t.path),children:c(t,n,!1,()=>{})}),v&&(0,K.jsx)(RW,{x:v.x,y:v.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>y(null)})]}):(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)(`div`,{className:`relative`,onContextMenu:S,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(t.path),className:l?l(t,n,!1,w):`w-full py-1 flex items-center gap-2 text-left `+(w?`bg-gray-100`:`hover:bg-gray-50`),style:{paddingLeft:C,paddingRight:8},children:[(0,K.jsx)(`span`,{className:`w-3 text-gray-400`,children:(0,K.jsx)(le,{size:13})}),(0,K.jsx)(`span`,{className:`text-[13px] text-gray-900 flex-1 min-w-0 truncate`,children:t.name})]}),v&&(0,K.jsx)(RW,{x:v.x,y:v.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>y(null)})]})})}function RW({x:e,y:t,items:n,onAction:r,onClose:i}){return(0,_.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,dt.createPortal)((0,K.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,K.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 zW=[{name:`context`,section:`context`,emoji:`🧷`,hint:`knowledge / notes / personal`},{name:`workdir`,section:`workdir`,emoji:`▣`}];function BW({loopId:e,onPick:t,picked:n}){let[r,i]=(0,_.useState)(0),a=(0,_.useRef)(null),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(``),f=(0,_.useCallback)(e=>{s(e??`workdir`),a.current?.click()},[]),p=async t=>{let n=t.target.files?.[0];if(!n)return;let r=await Tm(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 Sm(e,t,``):await wm(e,t),!n){alert(`create failed`),l(null);return}l(null),d(``),i(e=>e+1)},h=(0,_.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;Cm(e,n.path).then(e=>{if(!e){alert(`delete failed`);return}i(e=>e+1)})}},[f,e]),g=(0,_.useCallback)(e=>e.type===`dir`?[{label:`Upload here`,icon:(0,K.jsx)(at,{size:12}),action:`upload`},{label:`New file`,icon:(0,K.jsx)(se,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,K.jsx)(pe,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,K.jsx)(tt,{size:12}),action:`delete`,danger:!0}]:[{label:`View`,icon:(0,K.jsx)(ie,{size:12}),action:`view`},{label:`Delete`,icon:(0,K.jsx)(tt,{size:12}),action:`delete`,danger:!0}],[]);return(0,_.useCallback)(t=>ym(e,t).then(e=>e),[e]),(0,K.jsxs)(`aside`,{className:`flex-1 min-h-0 overflow-auto py-2 text-[13px]`,children:[(0,K.jsx)(`input`,{ref:a,type:`file`,className:`hidden`,onChange:p}),zW.map(a=>(0,K.jsx)(VW,{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,K.jsx)(HW,{depth:1,type:c.type,value:u,onChange:d,onSubmit:m,onCancel:()=>l(null)})]})}function VW({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,_.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,_.useCallback)(t=>ym(e,t).then(e=>e),[e]);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:h,style:{paddingLeft:`0.5rem`,paddingRight:`0.5rem`},children:[(0,K.jsx)(`span`,{className:`text-gray-500`,children:p?`▾`:`▸`}),(0,K.jsx)(`span`,{className:`text-[12px]`,children:r}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider font-semibold text-gray-700`,children:t}),i&&(0,K.jsx)(`span`,{className:`text-[10px] text-gray-500 italic ml-1`,children:i}),n===`workdir`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.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,K.jsx)(at,{size:12})})]})]}),p&&(0,K.jsx)(IW,{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 HW({depth:e,type:t,value:n,onChange:r,onSubmit:i,onCancel:a}){let o=(0,_.useRef)(null);return(0,_.useEffect)(()=>{o.current?.focus()},[]),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 py-0.5`,style:{paddingLeft:8+e*12},children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:t===`file`?`📄`:`📁`}),(0,K.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,K.jsx)(`button`,{onClick:i,className:`text-[10px] text-emerald-600 hover:text-emerald-800 px-1`,children:`✓`}),(0,K.jsx)(`button`,{onClick:a,className:`text-[10px] text-gray-400 hover:text-gray-600 px-1`,children:`✕`})]})}function UW(e){let t=e.split(`
|
|
107
|
-
`),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 WW({filePath:e,diff:t,loading:n,onClose:r}){let i=null;if(t)try{i=UW(t)}catch{}return(0,K.jsx)(Ag,{open:!0,onOpenChange:e=>{e||r()},children:(0,K.jsxs)(Ng,{className:`sm:max-w-4xl max-h-[85vh] flex flex-col bg-white p-0 gap-0`,showCloseButton:!1,children:[(0,K.jsxs)(`div`,{className:`px-4 py-2.5 border-b border-gray-200 shrink-0 flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-mono text-gray-900 truncate flex-1`,children:e}),(0,K.jsx)(`button`,{onClick:r,className:`text-gray-400 hover:text-gray-700 text-sm leading-none`,children:`✕`})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:n?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-gray-400 gap-2`,children:[(0,K.jsx)(we,{className:`animate-spin`,size:16}),(0,K.jsx)(`span`,{className:`text-sm`,children:`loading diff...`})]}):i?(0,K.jsx)(`div`,{className:`text-xs font-mono leading-5`,children:i.hunks.map((e,t)=>(0,K.jsxs)(`div`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex `+(n?`bg-emerald-50`:r?`bg-red-50`:``),children:[(0,K.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,K.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,K.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,K.jsx)(`span`,{className:`select-none`,children:n?`+`:r?`−`:` `}),e.text]})]},t)})]},t))}):(0,K.jsx)(`div`,{className:`py-16 text-center text-sm text-gray-400`,children:`empty diff`})})]})})}var GW={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 KW({loopId:e,onClose:t,onPickFile:n}){let[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!0),[l,u]=(0,_.useState)(!0),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)([]),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(!0),O=(0,_.useCallback)(async()=>{o(!0),f(null);try{i(await yh(e))}catch{f(`Failed to load git status`)}finally{o(!1)}},[e]),k=(0,_.useCallback)(async()=>{T(!0);try{C(await wh(e,50))}catch{}finally{T(!1)}},[e]);(0,_.useEffect)(()=>{O(),k()},[O,k]);let A=async()=>{r?.unstaged.length&&await xh(e,r.unstaged.map(e=>e.path))&&O()},j=async()=>{r?.staged.length&&await xh(e,r.staged.map(e=>e.path),!0)&&O()},M=async t=>{await xh(e,[t])&&O()},N=async t=>{await xh(e,[t],!0)&&O()},P=async t=>{await Sh(e,t)&&O()},F=async()=>{if(!h.trim())return;y(!0),x(null);let t=await Ch(e,h.trim());y(!1),t.ok?(g(``),O(),k()):x(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,K.jsxs)(`aside`,{className:`w-full h-full min-w-0 bg-white flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{className:`tracking-wide`,children:`Git Changes`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>{O(),k()},className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,title:`refresh`,children:(0,K.jsx)(Ve,{size:13,className:a||w?`animate-spin`:``})}),(0,K.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:t,title:`close`,children:`✕`})]}),(0,K.jsxs)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:[(0,K.jsx)(`textarea`,{placeholder:`Commit message...`,value:h,onChange:e=>{g(e.target.value),x(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,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`button`,{onClick:F,disabled:v||!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,K.jsx)(ge,{size:12}),v?`Committing...`:`Commit`]}),r&&r.staged.length>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[r.staged.length,` staged`]})]}),b&&(0,K.jsx)(`div`,{className:`mt-1 text-[10px] text-red-500`,children:b})]}),(0,K.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:(0,K.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,K.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto text-[13px]`,children:[(0,K.jsxs)(`div`,{className:`overflow-auto py-2`,children:[a&&!r&&(0,K.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`loading git status...`}),d&&(0,K.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-red-500`,children:d}),z&&!a&&(0,K.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`no changes`}),L.length>0&&(0,K.jsx)(JW,{title:`Unstaged Changes`,count:L.length,open:s,onToggle:()=>c(e=>!e),bulkAction:{label:`Stage all`,icon:(0,K.jsx)(Re,{size:12}),onClick:A},children:L.map(t=>(0,K.jsx)(YW,{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,K.jsx)(JW,{title:`Staged Changes`,count:R.length,open:l,onToggle:()=>u(e=>!e),bulkAction:{label:`Unstage all`,icon:(0,K.jsx)(Ae,{size:12}),onClick:j},children:R.map(t=>(0,K.jsx)(YW,{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,K.jsxs)(`div`,{className:`border-t border-gray-200`,children:[(0,K.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,K.jsx)(`span`,{className:`text-gray-500`,children:E?`▾`:`▸`}),(0,K.jsx)(he,{size:12,className:`text-gray-500`}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:`History`}),(0,K.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,S.length,`)`]})]}),E&&(0,K.jsx)(`div`,{className:`px-2 pb-2 max-h-64 overflow-auto`,children:w?(0,K.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`loading history...`}):S.length===0?(0,K.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`no commits`}):(0,K.jsx)(qW,{commits:S})})]})]})]})}function qW({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,K.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,K.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,K.jsxs)(`div`,{className:`flex flex-col items-center shrink-0`,children:[(0,K.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,K.jsx)(`div`,{className:`w-0.5 h-10 ${a} opacity-10`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400 truncate`,children:t.shortHash}),o&&(0,K.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,K.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,K.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-purple-100 text-purple-700 font-medium`,children:e},e))]}),(0,K.jsx)(`div`,{className:`text-gray-700 truncate`,children:t.subject}),(0,K.jsxs)(`div`,{className:`text-gray-400 text-[10px]`,children:[t.author,` · `,s]})]})]},t.hash)})})}function JW({title:e,count:t,open:n,onToggle:r,bulkAction:i,children:a}){return(0,K.jsxs)(`div`,{className:`mb-2`,children:[(0,K.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,K.jsx)(`span`,{className:`text-gray-500`,children:n?`▾`:`▸`}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:e}),(0,K.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,t,`)`]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.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,K.jsx)(`div`,{children:a})]})}function YW({file:e,loopId:t,staged:n,onStage:r,onUnstage:i,onDiscard:a,onEdit:o,onRefresh:s}){let[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=e=>{y.current&&!y.current.contains(e.target)&&v(null)};if(g)return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let b=async()=>{e.isBinary||(l(!0),u===null&&(p(!0),d(await bh(t,e.path,n)??``),p(!1)))},x=e=>{e.preventDefault(),v({x:e.clientX,y:e.clientY})},S=`workdir/${e.path}`,C=[{label:`Open in Editor`,icon:(0,K.jsx)(Le,{size:12}),onClick:()=>{o(S),v(null)}},{label:`View Diff`,icon:(0,K.jsx)(Ue,{size:12}),onClick:()=>{b(),v(null)}},{separator:!0,label:``,onClick:()=>{}},n?{label:`Unstage`,icon:(0,K.jsx)(Ae,{size:12}),onClick:()=>{i(),v(null)}}:{label:`Stage`,icon:(0,K.jsx)(Re,{size:12}),onClick:()=>{r(),v(null)}},!n&&{label:`Discard Changes`,icon:(0,K.jsx)(rt,{size:12}),onClick:()=>{h(!0),v(null)},danger:!0}].filter(Boolean),w=GW[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,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`group/row relative flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50`,onContextMenu:x,children:[(0,K.jsx)(`span`,{className:`w-5 text-center text-[11px] font-mono font-semibold ${w.color}`,children:w.label}),(0,K.jsxs)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] font-mono`,children:[(0,K.jsx)(`span`,{className:`text-gray-900`,children:E}),D&&(0,K.jsx)(`span`,{className:`text-gray-400 ml-0.5`,children:D})]}),!e.isBinary&&(e.additions>0||e.deletions>0)&&(0,K.jsxs)(`span`,{className:`text-[11px] font-mono flex items-center gap-0.5 shrink-0`,children:[(0,K.jsxs)(`span`,{className:`text-emerald-600`,children:[`+`,e.additions]}),(0,K.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]}),(0,K.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,K.jsx)(`button`,{type:`button`,onClick:()=>o(S),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-blue-600 rounded`,title:`edit file`,children:(0,K.jsx)(Le,{size:13})}),n&&(0,K.jsx)(`button`,{type:`button`,onClick:b,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,K.jsx)(Ue,{size:13})}),n?(0,K.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,K.jsx)(Ae,{size:13})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(rt,{size:13})}),(0,K.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,K.jsx)(Re,{size:13})})]})]})]}),g&&(0,K.jsx)(`div`,{ref:y,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:C.map((e,t)=>e.separator?(0,K.jsx)(`div`,{className:`my-1 border-t border-gray-100`},t):(0,K.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,K.jsx)(`span`,{children:e.label})]},t))}),c&&(0,K.jsx)(WW,{filePath:e.path,diff:u,loading:f,onClose:()=>l(!1)}),m&&(0,K.jsx)(Ag,{open:!0,onOpenChange:e=>{e||h(!1)},children:(0,K.jsxs)(Ng,{className:`sm:max-w-sm bg-white p-5 gap-4`,showCloseButton:!1,children:[(0,K.jsx)(Pg,{children:(0,K.jsx)(Fg,{className:`text-sm`,children:`Discard changes`})}),(0,K.jsx)(`p`,{className:`text-[13px] text-gray-600 break-all font-mono`,children:e.path}),(0,K.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,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.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,K.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 XW(e){return e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:`standard`}function ZW({loop:e,open:t,onClose:n,onSaved:r}){let[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(e.shareEnabled??!1),[c,l]=(0,_.useState)(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),[u,d]=(0,_.useState)(e.shareAlias??``),[f,p]=(0,_.useState)(e.sharePort??3e3),[m,h]=(0,_.useState)(e.shareExternalPort??1e4),[g,v]=(0,_.useState)(e.shareProtocol??`tcp`),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(``),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(``),[j,M]=(0,_.useState)(!1),[N,F]=(0,_.useState)(``),[I,L]=(0,_.useState)(``),[z,B]=(0,_.useState)(XW(e)),[V,H]=(0,_.useState)(null),U=e.id.slice(0,8),W=!!(i&&i.serveEnabled),te=!!(i&&i.serveDynamicEnabled),ne=!!(i&&i.serveEphemeralEnabled),G=[W,te,ne].filter(Boolean).length>1,re=W&&!te&&!ne,ie=!W&&te&&!ne,ae=!W&&!te&≠(0,_.useEffect)(()=>{t&&(Rh().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),v(e.shareProtocol??`tcp`),B(XW(e)),b(null),S(``),A(``),H(null))},[t,e]),(0,_.useEffect)(()=>{if(!t||!(ae||G&&z===`ephemeral`)||!e.shareEnabled||e.shareMode!==`ephemeral`)return;let n=!1,r=async()=>{let t=await zh(e.id);n||H(t.port)};r();let i=setInterval(r,3e3);return()=>{n=!0,clearInterval(i)}},[t,z,ae,G,e.id,e.shareEnabled,e.shareMode]),(0,_.useEffect)(()=>{!t||!i||i.serveDynamicEnabled&&(e.shareEnabled&&e.shareExternalPort||!e.shareEnabled&&!e.shareExternalPort&&Vh().then(e=>{e.port&&h(e.port)}))},[t,i,e.shareEnabled,e.shareExternalPort]),(0,_.useEffect)(()=>{t&&Uh(U,e.id).then(e=>{e.available?O(!1):(O(!0),S(`ID "${U}" is already in use. Please set an alias.`))})},[t,U,e.id]),(0,_.useEffect)(()=>{if(!u||!t){b(null),S(``);return}let n=setTimeout(async()=>{let t=await Uh(u,e.id);b(t.available),S(t.reason??``)},300);return()=>clearTimeout(n)},[u,t,e.id]);let oe=u||U,se=i?.https?`https`:`http`,ce=i?.withPort?`:${i.displayPort}`:``,le=i?`${se}://${oe}${i.baseUrl}${ce}`:``,ue=i?.serveDynamicDomain||i?.ip||`<host-ip>`,de=g===`static`?`http://${ue}:${m}`:`tcp://${ue}:${m}`,fe=i?.serveEphemeralDomain||i?.ip||`<host-ip>`,pe=V?`${g===`udp`?`udp`:`tcp`}://${fe}:${V}`:`(no active port — save & wait for container restart)`,me=ie||G&&z===`direct`&&te&&!ae,he=ae||G&&z===`ephemeral`,ge=he?pe:me?de:le;(0,_.useEffect)(()=>{if(!t||!me)return;let n=setTimeout(async()=>{M(!0);let t=await Hh(m,e.id);M(!1),t.available?A(``):A(t.reason??`Port unavailable`)},400);return()=>clearTimeout(n)},[m,t,c,e.id]);let ve=async()=>{if(E(!0),me){let t=await Hh(m,e.id);if(!t.available){A(t.reason??`Port unavailable`),E(!1);return}}let t={shareEnabled:o};o?he?(t.shareMode=`ephemeral`,t.sharePort=f,t.shareProtocol=g===`static`?`tcp`:g,t.shareAlias=void 0,t.shareExternalPort=void 0):me?(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)F(`Saved`),await r?.(),setTimeout(()=>{F(``),n()},800);else try{L((await i.json()).error??`Save failed (${i.status})`)}catch{L(`Save failed (${i.status})`)}},ye=async()=>{try{await navigator.clipboard.writeText(ge),w(!0),setTimeout(()=>w(!1),1500)}catch{window.prompt(`Copy this URL:`,ge)}},be=!T&&!k&&!j&&(he?f>=1&&f<=65535:(!me||m>=1024)&&(!me||f>=1||g===`static`)&&(me||c!==`port`||!D||u.trim().length>0)&&(me||c!==`port`||f>=1024));return i?(0,K.jsx)(Ag,{open:t,onOpenChange:e=>{e||n()},children:(0,K.jsxs)(Ng,{className:`sm:max-w-md bg-white max-h-[85vh] overflow-y-auto`,children:[(0,K.jsxs)(Pg,{children:[(0,K.jsxs)(Fg,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(_e,{size:16}),`Share Artifact`]}),(0,K.jsx)(Ig,{className:`sr-only`,children:`Share this artifact via a public URL.`})]}),(0,K.jsxs)(`div`,{className:`space-y-4 text-[13px]`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-gray-700`,children:`Enable sharing`}),(0,K.jsx)(`button`,{onClick:()=>s(!o),className:`w-10 h-5 rounded-full transition-colors ${o?`bg-blue-600`:`bg-gray-300`}`,children:(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${o?`translate-x-5`:`translate-x-0.5`}`})})]}),o&&(0,K.jsxs)(K.Fragment,{children:[G&&(0,K.jsxs)(`div`,{className:`flex gap-1.5 border-b border-gray-200 pb-2`,children:[W&&(0,K.jsx)(`button`,{onClick:()=>{B(`standard`),l(`static`)},className:`px-3 py-1 text-xs rounded-t ${z===`standard`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Subdomain`}),te&&(0,K.jsx)(`button`,{onClick:()=>{B(`direct`),l(`direct`)},className:`px-3 py-1 text-xs rounded-t ${z===`direct`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Direct Port`}),ne&&(0,K.jsx)(`button`,{onClick:()=>{B(`ephemeral`),l(`ephemeral`)},className:`px-3 py-1 text-xs rounded-t ${z===`ephemeral`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Ephemeral`})]}),(re||G&&z===`standard`)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Share mode`}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5 mt-1`,children:[(0,K.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,K.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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:[`Alias `,D?(0,K.jsx)(`span`,{className:`text-red-500`,children:`(required)`}):`(optional)`]}),(0,K.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,K.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,K.jsx)(R,{size:11}),` `,x||`ID "${U}" is already in use`]}),!D&&y===!0&&(0,K.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`}),!D&&y===!1&&(0,K.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,K.jsx)(R,{size:11}),` `,x||`Already in use`]})]}),c===`port`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Port (1024-65535)`}),(0,K.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`})]})]}),he&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,K.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,K.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,K.jsx)(`button`,{onClick:()=>v(`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,K.jsx)(`button`,{onClick:()=>v(`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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider flex items-center gap-1.5`,children:[`Current host port`,(0,K.jsx)(Be,{size:10,className:`text-gray-300`})]}),(0,K.jsx)(`div`,{className:`mt-1 px-2 py-1.5 text-sm bg-gray-50 rounded text-gray-700`,children:V==null?(0,K.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,K.jsx)(`span`,{className:`font-mono`,children:V})}),(0,K.jsxs)(`p`,{className:`text-[10px] text-amber-600 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(R,{size:10}),` Changes on every loop restart. Saving also restarts the container.`]})]})]}),(ie||G&&z===`direct`&&!he)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`External port`}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,K.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,K.jsx)(`button`,{onClick:async()=>{let e=await Vh();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,K.jsx)(Je,{size:14})})]}),(0,K.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The public port clients connect to`}),j&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 mt-0.5`,children:`Checking availability…`}),k&&(0,K.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,K.jsx)(R,{size:11}),` `,k]}),!j&&!k&&(0,K.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`})]}),g!==`static`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,K.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,K.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,K.jsx)(`button`,{onClick:()=>v(`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,K.jsx)(`button`,{onClick:()=>v(`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,K.jsx)(`button`,{onClick:()=>v(`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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Access URL`}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,K.jsx)(`code`,{className:`flex-1 px-2 py-1.5 text-xs bg-gray-50 rounded text-gray-700 truncate`,children:ge}),(0,K.jsx)(`button`,{onClick:ye,className:`px-2 py-1.5 rounded hover:bg-gray-100 text-gray-500`,title:`Copy URL`,children:C?(0,K.jsx)(P,{size:14,className:`text-emerald-600`}):(0,K.jsx)(ee,{size:14})})]}),(0,K.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-1`,children:me?`Direct TCP/UDP access — no domain needed`:`Domain suffix configured in Settings → Workspace → Workspace Serve`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2`,children:[I&&(0,K.jsx)(`span`,{className:`text-xs text-red-500`,children:I}),N&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:12}),` `,N]}),(0,K.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,K.jsx)(`button`,{onClick:ve,disabled:!be,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 QW=(0,_.lazy)(()=>gt(()=>import(`./Editor-BJwSRhKT.js`).then(e=>({default:e.Editor})),__vite__mapDeps([0,1,2,3]))),$W=(0,_.lazy)(()=>gt(()=>import(`./Terminal-trnCVajY.js`).then(e=>({default:e.Terminal})),__vite__mapDeps([4,1,5])));function eG(){let{id:e}=Un(),t=Cg();if(!e)return(0,K.jsx)(pr,{to:`/loop`,replace:!0});if(!t.currentUser)return(0,K.jsx)(OW,{});let n=t.loops.find(t=>t.id===e);return t.loopsLoading?null:n?(0,K.jsxs)(`div`,{className:`h-full w-full flex min-h-0`,children:[(0,K.jsx)(tG,{currentId:e}),(0,K.jsx)(nG,{meta:n},e)]}):(0,K.jsx)(pr,{to:`/loop`,replace:!0})}function tG({currentId:e}){let t=Cg(),n=zn(),[r,i]=(0,_.useState)(`mine`),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(()=>localStorage.getItem(`loopat:loopsList:collapsed`)===`1`),l=lU(),u=MW((0,_.useMemo)(()=>t.loops.map(e=>e.id),[t.loops]));(0,_.useEffect)(()=>{let t=u[e];t?.status===`Done`&&t?.viewed===!1&&um(e)},[u,e]);let d=t.currentUser?.id,f=(0,_.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,K.jsxs)(`aside`,{className:`w-60 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`px-2 pt-1.5 pb-1 space-y-1 border-b border-gray-200`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[[`mine`,`all`,`rfd`].map(e=>(0,K.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,K.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-auto pr-1`,children:f.length}),(0,K.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,K.jsx)(w,{size:13})}),(0,K.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,K.jsx)(Pe,{size:14})})]}),(0,K.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,K.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,K.jsxs)(`div`,{className:`group/row relative flex items-stretch `+(i?`bg-gray-100`:`hover:bg-gray-50`),children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{um(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,K.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,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`text-[13px] text-gray-900 truncate flex items-center gap-1.5`,children:[a&&(0,K.jsx)(w,{size:10,className:`text-gray-400 shrink-0`}),r.rfdRequestedAt&&(0,K.jsx)(`span`,{className:`shrink-0 text-[9px] px-1 rounded bg-amber-100 text-amber-800 font-medium tracking-wide`,children:`RFD`}),(0,K.jsx)(`span`,{className:`truncate`,children:r.title}),s&&(0,K.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium `+(d?`text-blue-500`:c?`text-emerald-500`:`text-gray-400`),children:s.status})]}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 truncate flex items-center gap-1 mt-0.5`,children:[(0,K.jsx)(`span`,{children:r.driver??r.createdBy}),(0,K.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400`,children:r.id.slice(0,6)})]})]})]}),(0,K.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,K.jsx)(C,{size:13}):(0,K.jsx)(w,{size:13})})]},r.id)}),f.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no loops · click "+ New Loop"`})]})]});return s?(0,K.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,K.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,K.jsx)(Fe,{size:16})})}):l?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,K.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,K.jsx)(Pe,{size:16})})}),(0,K.jsxs)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>p(!0),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.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 nG({meta:e}){let t=Cg(),n=lU(),[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(null);(0,_.useEffect)(()=>{Rh().then(m)},[]);let[h,g]=(0,_.useState)(null),v=e=>{c(e),g(null),i(e=>e.includes(`editor`)?e:[...e,`editor`])},{runtime:y,connected:b,reconnecting:x,running:S,viewers:C,extra:w,queue:T,onClearQueue:E}=TU(e.id,t.currentUser?.id??``,v);(0,_.useEffect)(()=>{Em(e.id).then(u),um(e.id),t.currentUser?.id&&localStorage.setItem(`loopat:lastLoop:${t.currentUser.id}`,e.id)},[e.id]);let D=Fn(),O=zn(),k=D.state?.kickoff;(0,_.useEffect)(()=>{!k||!b||(w.enqueueMessage(k),O(D.pathname,{replace:!0,state:null}))},[k,b]);let A=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},j=e=>{i(t=>t.includes(e)?t.filter(t=>t!==e):[e])},M=e=>{i(t=>t.filter(t=>t!==e)),o(t=>t===e?null:t)},N=r.length>0,P=r.filter(e=>e===`editor`||e===`terminal`),F=r.filter(e=>e!==`editor`&&e!==`terminal`),I=P.length>0,L=F.length>0,[R,z]=(0,_.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);return!isNaN(e)&&e>=10&&e<=90?e:55}),[B,V]=(0,_.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);return!isNaN(e)&&e>=5&&e<=50?e:18});(0,_.useEffect)(()=>{if(!L){let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);!isNaN(e)&&e>=5&&e<=50&&V(e)}if(!I&&!L){let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);!isNaN(e)&&e>=10&&e<=90&&z(e)}},[I,L]);let H=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)))},U=n=>{let r=a===n;return(0,K.jsx)(cG,{loopId:e.id,meta:e,mode:n,onClose:()=>M(n),pickedFile:s,onPickFile:v,currentUserId:t.currentUser?.id??``,isFullscreen:r,onToggleFullscreen:()=>o(r?null:n),onEditorSelection:g},n)};return(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,K.jsx)(rG,{meta:e,mounts:l,connected:b,reconnecting:x,running:S,viewers:C,queue:T,onClearQueue:E,openPanels:r,toggleMode:A,onShareWork:()=>f(!0),showShareButton:!p||p.serveEnabled||p.serveDynamicEnabled||p.serveEphemeralEnabled}),e.contextWarnings&&e.contextWarnings.length>0&&(0,K.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,K.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,K.jsx)(`ul`,{className:`mt-1 ml-4 list-disc`,children:e.contextWarnings.map((e,t)=>(0,K.jsx)(`li`,{className:`font-mono text-[11px] break-all`,children:e},t))})]}),n?(0,K.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,K.jsx)(wU,{extra:w,children:(0,K.jsx)(ew,{runtime:y,children:(0,K.jsx)(DW,{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})})})}):N?(0,K.jsxs)(tk,{orientation:`horizontal`,className:`flex-1 min-w-0 min-h-0`,onLayoutChange:H,children:[(0,K.jsx)(ik,{id:`chat`,minSize:20,defaultSize:R,className:`flex flex-col min-h-0 min-w-0`,children:(0,K.jsx)(wU,{extra:w,children:(0,K.jsx)(ew,{runtime:y,children:(0,K.jsx)(DW,{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||L)&&(0,K.jsx)(sk,{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,K.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`})}),I&&(0,K.jsx)(ik,{id:`editorCol`,minSize:15,defaultSize:30,className:`flex flex-col min-h-0 min-w-0`,children:P.length>1?(0,K.jsx)(tk,{orientation:`vertical`,className:`flex-1 min-h-0`,children:P.map((e,t)=>(0,K.jsxs)(_.Fragment,{children:[t>0&&(0,K.jsx)(sk,{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,K.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,K.jsx)(ik,{id:e,minSize:10,defaultSize:100/P.length,className:`flex flex-col min-h-0 min-w-0`,children:U(e)})]},e))}):U(P[0])}),I&&L&&(0,K.jsx)(sk,{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,K.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`})}),L&&(0,K.jsx)(ik,{id:`otherCol`,minSize:15,defaultSize:B,className:`flex flex-col min-h-0 min-w-0`,children:F.length>1?(0,K.jsx)(tk,{orientation:`vertical`,className:`flex-1 min-h-0`,children:F.map((e,t)=>(0,K.jsxs)(_.Fragment,{children:[t>0&&(0,K.jsx)(sk,{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,K.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,K.jsx)(ik,{id:e,minSize:10,defaultSize:100/F.length,className:`flex flex-col min-h-0 min-w-0`,children:U(e)})]},e))}):U(F[0])})]}):(0,K.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,K.jsx)(wU,{extra:w,children:(0,K.jsx)(ew,{runtime:y,children:(0,K.jsx)(DW,{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})})})}),N&&n&&r.map(e=>(0,K.jsx)(_.Fragment,{children:U(e)},e)),n&&(0,K.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,K.jsx)(`button`,{type:`button`,onClick:()=>j(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,K.jsx)(ZW,{loop:e,open:d,onClose:()=>f(!1),onSaved:async()=>{await t.refresh()}})]})}function rG({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=lU(),p=zn(),m=Cg(),[h,g]=(0,_.useState)(f),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(e.title),w=m.currentUser?.id===e.createdBy,T=async()=>{if(!v){y(!0);try{let t=await gm(e.id);t&&p(`/loop/${t.id}`)}finally{y(!1)}}},E=async()=>{let t=S.trim();if(!t||t===e.title){x(!1),C(e.title);return}x(!1),await m.setLoopTitle(e.id,t)||C(e.title)},D=(e,t)=>(0,K.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,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.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,K.jsx)(F,{size:14,className:`transition-transform `+(h?`-rotate-90`:``)})}),b?(0,K.jsx)(`input`,{type:`text`,value:S,autoFocus:!0,onChange:e=>C(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing?(t.preventDefault(),E()):t.key===`Escape`&&(t.preventDefault(),x(!1),C(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,K.jsx)(`span`,{className:`text-[14px] md:text-[15px] font-medium text-gray-900 `+(w?`cursor-pointer hover:bg-gray-100 rounded px-1 -mx-1`:``),onClick:()=>{w&&(C(e.title),x(!0))},title:w?`click to rename`:void 0,children:e.title}),(0,K.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`driver: `,(0,K.jsx)(`span`,{className:`text-gray-900`,children:e.driver??e.createdBy})]}),e.rfdRequestedAt&&(0,K.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,K.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`reconnecting…`}),i&&(0,K.jsx)(`span`,{className:`text-[11px] text-blue-600`,children:`running`}),a>1&&(0,K.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,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`button`,{type:`button`,onClick:T,disabled:v,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,K.jsx)(ue,{size:11}),v?`Distilling…`:`Distill`]}),d!==!1&&(0,K.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,K.jsx)(_e,{size:11}),`Share Artifact`]}),(0,K.jsx)(aG,{meta:e}),(0,K.jsx)(iG,{meta:e})]}),!h&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`text-xs text-gray-500 mt-1.5 flex items-center gap-2 flex-wrap`,children:[(0,K.jsxs)(`span`,{className:`font-mono`,children:[`~/.loopat/loops/`,e.id.slice(0,8),`/workdir`]}),(0,K.jsx)(`span`,{children:`·`}),(0,K.jsx)(`span`,{children:`main`}),a>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{children:[a,` viewing`]})]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,children:[D(`ℹ info`,`info`),D(`▤ workdir`,`workdir`),D(`✎ editor`,`editor`),D(`▷ terminal`,`terminal`),(0,K.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,K.jsx)(he,{size:14})})]})]}),(0,K.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:`context:`}),t.map(e=>(0,K.jsx)(oG,{label:e.name,value:e.name===`knowledge`?`ro`:`rw`},e.path))]}),e.config?.profiles&&e.config.profiles.length>0&&(0,K.jsx)(sG,{profiles:e.config.profiles}),(0,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:`vault:`}),(0,K.jsx)(oG,{label:e.config?.vault??`default`,value:`loaded`})]})]})]})}function iG({meta:e}){let t=Cg(),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.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,K.jsxs)(`div`,{className:`inline-flex items-center gap-1`,children:[s&&(0,K.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,K.jsx)(P,{size:11}):(0,K.jsx)(ee,{size:11}),(0,K.jsx)(`span`,{className:`hidden md:inline`,children:n?`copied`:`copy link`})]}),(0,K.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,K.jsx)(_e,{size:11}):(0,K.jsx)(Te,{size:11}),s?`shared`:`share`]})]}):(0,K.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,K.jsx)(_e,{size:11}):(0,K.jsx)(Te,{size:11}),s?`public`:`private`]})}function aG({meta:e}){let t=Cg(),[n,r]=(0,_.useState)(!1);if(!t.currentUser)return null;let i=e.driver??e.createdBy,a=t.currentUser.id===i;return e.rfdRequestedAt?(0,K.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,K.jsx)(ve,{size:11}),`Drive`]}):a?(0,K.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,K.jsx)(ve,{size:11}),`Request For Drive`]}):null}function oG({label:e,value:t,title:n}){return(0,K.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,K.jsxs)(`span`,{className:`text-gray-500`,children:[e,`:`]}),(0,K.jsx)(`span`,{className:`text-gray-900 font-medium`,children:t})]})}function sG({profiles:e}){let[t,n]=(0,_.useState)({});return(0,_.useEffect)(()=>{let e=!1;return om().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,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:`profiles:`}),e.map(e=>(0,K.jsx)(oG,{label:e,value:`active`,title:t[e]},e))]})}function cG({loopId:e,meta:t,mode:n,onClose:r,pickedFile:i,onPickFile:a,currentUserId:o,isFullscreen:s,onToggleFullscreen:c,onEditorSelection:l}){let u=lU(),[d,f]=(0,_.useState)(()=>{let e=localStorage.getItem(`loopat:mobilePanelPct`);return e?Math.max(20,Math.min(95,parseInt(e)||55)):55}),p=(0,_.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)},v=()=>{p.current=null},y=e=>{e.preventDefault(),e.stopPropagation(),h(e.touches[0].clientY)},b=e=>{e.preventDefault(),g(e.touches[0].clientY)},x=e=>{e.preventDefault(),v()},S=e=>{e.pointerType!==`touch`&&(e.preventDefault(),e.target.setPointerCapture(e.pointerId),h(e.clientY))},C=e=>{e.pointerType===`touch`||!p.current||g(e.clientY)},w=e=>{e.pointerType!==`touch`&&v()},T=(0,K.jsxs)(`aside`,{className:`flex-1 min-w-0 bg-white flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{className:`capitalize`,children:n}),n===`editor`&&(0,K.jsx)(`span`,{className:`ml-2 truncate text-gray-700`,children:i||`(no file)`}),(0,K.jsx)(`div`,{className:`flex-1`}),(n===`editor`||n===`terminal`)&&(0,K.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,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})}),(0,K.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,K.jsx)(lG,{meta:t}),n===`workdir`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(BW,{loopId:e,onPick:a,picked:i}),(0,K.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 text-[11px] text-gray-500`,children:[`⑂ `,(0,K.jsx)(`span`,{className:`text-gray-900`,children:`main`})]})]}),(0,K.jsxs)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading...`}),children:[n===`editor`&&(0,K.jsx)(QW,{loopId:e,path:i,onSelectionChange:l}),n===`terminal`&&(0,K.jsx)(`div`,{className:`flex-1 min-h-0 bg-[#1a1c20] overflow-hidden`,children:(0,K.jsx)($W,{loopId:e,currentUserId:o})}),n===`git`&&(0,K.jsx)(KW,{loopId:e,onClose:r,onPickFile:a})]})]});return u?(0,K.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,K.jsx)(`div`,{className:`absolute inset-0 bottom-7 overflow-y-auto flex flex-col`,children:T}),(0,K.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:y,onTouchMove:b,onTouchEnd:x,onPointerDown:S,onPointerMove:C,onPointerUp:w,children:(0,K.jsx)(`div`,{className:`w-8 h-1 rounded-full bg-gray-300`})})]}):s?(0,dt.createPortal)((0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex flex-col`,children:T}),document.body):T}function lG({meta:e}){let t=Cg().currentUser?.id===e.createdBy;return(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-5 py-4 text-[13px] text-gray-900`,children:[(0,K.jsxs)(uG,{label:`basics`,children:[(0,K.jsx)(dG,{label:`title`,value:e.title}),(0,K.jsx)(dG,{label:`created`,value:new Date(e.createdAt).toLocaleString()}),(0,K.jsx)(dG,{label:`status`,value:`active`}),(0,K.jsx)(dG,{label:`driver`,value:t?`${e.createdBy} (you)`:e.createdBy}),(0,K.jsx)(dG,{label:`sharing`,value:e.public?`public — /loop/${e.id.slice(0,8)}…`:`private`})]}),(0,K.jsxs)(uG,{label:`workdir`,children:[(0,K.jsx)(dG,{label:`id`,value:e.id,mono:!0}),(0,K.jsx)(dG,{label:`path`,value:`~/.loopat/loops/${e.id.slice(0,8)}/workdir`,mono:!0}),(0,K.jsx)(dG,{label:`branch`,value:`main`,mono:!0})]}),(0,K.jsxs)(uG,{label:`context`,children:[(0,K.jsx)(dG,{label:`knowledge`,value:`all (ro)`}),(0,K.jsx)(dG,{label:`notes`,value:`all (rw)`}),(0,K.jsx)(dG,{label:`personal`,value:`${e.createdBy} (rw)`})]})]})}function uG({label:e,children:t}){return(0,K.jsxs)(`section`,{className:`mb-5`,children:[(0,K.jsx)(`h3`,{className:`text-[11px] uppercase tracking-wide text-gray-400 mb-2`,children:e}),(0,K.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:t})]})}function dG({label:e,value:t,mono:n=!1}){return(0,K.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500 w-24 shrink-0`,children:e}),(0,K.jsx)(`span`,{className:n?`font-mono text-[12px] text-gray-800 truncate`:`text-[13px] text-gray-900 truncate`,children:t})]})}function fG({name:e,onClick:t,onEdit:n,size:r=`sm`}){return(0,K.jsxs)(`span`,{className:`relative inline-flex items-center group/chip`,children:[(0,K.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,K.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 pG(){let{name:e}=Un(),t=decodeURIComponent(e??``),n=zn(),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{let e=!1;return dh().then(n=>{e||(i(n.find(e=>e.name===t.toLowerCase())??null),o(!1))}),()=>{e=!0}},[t]),(0,K.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-white`,children:[(0,K.jsxs)(`header`,{className:`h-10 shrink-0 flex items-center gap-3 px-6 border-b border-gray-200`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>n(-1),className:`text-[11px] text-gray-500 hover:text-gray-900`,children:`← back`}),(0,K.jsx)(fG,{name:t,size:`md`}),(0,K.jsx)(`div`,{className:`flex-1`})]}),(0,K.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col overflow-auto`,children:(0,K.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,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`}):!r||r.loops.length===0?(0,K.jsxs)(`div`,{className:`text-[12px] text-gray-400 italic`,children:[`no entities tagged with `,(0,K.jsxs)(`code`,{children:[`#`,t]})]}):(0,K.jsxs)(`section`,{children:[(0,K.jsxs)(`div`,{className:`text-[12px] uppercase tracking-wider text-gray-500 mb-2 px-1`,children:[`Loops (`,r.loops.length,`)`]}),(0,K.jsx)(`div`,{className:`flex flex-col gap-1`,children:r.loops.map(e=>(0,K.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,K.jsx)(`span`,{className:`ml-2 text-[10px] font-mono text-gray-400`,children:e.id.slice(0,6)})]},e.id))})]})})})]})}var mG=(0,_.lazy)(()=>gt(()=>import(`./CodeEditor-DtHZtsPs.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([2,1,3]))),hG=(0,_.lazy)(()=>gt(()=>import(`./Markdown-DVBIITE2.js`).then(e=>({default:e.Markdown})),__vite__mapDeps([6,1]))),gG=(0,_.lazy)(()=>gt(()=>import(`./MilkdownEditor-DOK-C67j.js`).then(e=>({default:e.MilkdownEditor})),__vite__mapDeps([7,1,3]))),_G=[{id:`knowledge`,label:`Knowledge`},{id:`notes`,label:`Notes`},{id:`personal`,label:`Personal`},{id:`repos`,label:`Repos`}],vG=new Set([`knowledge`,`notes`,`personal`,`repos`]);function yG(){let{sub:e}=Un(),[t]=_i(),n=vG.has(e)?e:`knowledge`,r=t.get(`file`)||void 0,i=t.get(`edit`)===`1`;return(0,K.jsxs)(`div`,{className:`flex flex-col h-full w-full`,children:[(0,K.jsx)(`nav`,{className:`flex items-center gap-1 px-3 h-9 shrink-0 border-b border-gray-200 bg-white`,children:_G.map(e=>(0,K.jsx)(ui,{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,K.jsx)(`span`,{children:e.label})},e.id))}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0`,children:n===`repos`?(0,K.jsx)(jG,{}):(0,K.jsx)(CG,{vault:n,initialFile:r,initialEditing:i},n)})]})}var bG={knowledge:`workspace's distilled materials`,notes:`workspace · public`,personal:`yours · private`,repos:`registered code repos`};function xG({resource:e,canPush:t=!0}){let[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),c=(0,_.useCallback)(async()=>{a(`status`),r(await Um(e)),a(null)},[e]);(0,_.useEffect)(()=>{c()},[c]);let l=async()=>{a(`pull`),s(null);let t=await Wm(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 Gm(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,K.jsxs)(`div`,{className:`px-3 py-1.5 border-t border-gray-200 flex flex-col gap-1 text-[11px]`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:p?(0,K.jsx)(`span`,{className:`text-gray-400`,children:`no remote`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:d>0?`text-emerald-700`:`text-gray-400`,title:`unpushed commits`,children:[`↑`,d]}),(0,K.jsxs)(`span`,{className:f>0?`text-amber-700`:`text-gray-400`,title:`unpulled commits`,children:[`↓`,f]}),n&&n.uncommitted>0&&(0,K.jsxs)(`span`,{className:`text-red-600`,title:`uncommitted changes in primary`,children:[`! `,n.uncommitted]}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.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,K.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,K.jsx)(`span`,{className:`truncate flex-1 min-w-0 `+(o.ok?`text-emerald-700`:`text-red-600`),title:o.text,children:o.text})]})]})}function SG({onRefreshed:e}){let[t,n]=(0,_.useState)(0),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(null),s=(0,_.useRef)(e);s.current=e;let c=(0,_.useCallback)(async()=>{i(!0),o(null);let e=await Nm();i(!1),e.ok?(n(0),s.current()):e.diverged?o(`你有未保存的编辑,先保存再刷新`):o(e.error??`refresh failed`)},[]);return(0,_.useEffect)(()=>{c()},[c]),(0,_.useEffect)(()=>{let e=()=>Mm().then(n).catch(()=>{});e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]),(0,K.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 flex flex-col gap-1.5 text-[11px]`,children:[t>0?(0,K.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,K.jsxs)(`span`,{children:[`远端已更新 `,t,` 个改动`]}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-gray-400`,children:[(0,K.jsx)(`span`,{children:`已是最新`}),(0,K.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`text-gray-500 hover:text-gray-900 underline disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}),a&&(0,K.jsx)(`div`,{className:`text-amber-700`,children:a})]})}function CG({vault:e,initialFile:t,initialEditing:n}){let[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(t??null),[l,u]=_i();(0,_.useEffect)(()=>{(l.get(`file`)??null)!==s&&u(s?{file:s}:{},{replace:!0})},[s,l,u]);let[d,f]=(0,_.useState)(0),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(``),w=lU(),T=(0,_.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,_.useEffect)(()=>{Dm(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})}),Om(e).then(o),g(``)},[e,d]),(0,_.useEffect)(()=>{let t=!1,n=()=>{t||f(e=>e+1)};return e===`knowledge`?Wm(`knowledge`).then(e=>{e.ok&&(e.message??``).toLowerCase()!==`already up to date`&&n()}):e===`notes`?Mm().then(e=>{e>0&&Nm().then(e=>{e.ok&&n()})}):e===`personal`&&$p().then(e=>{e.ok&&(e.files?.length??0)>0&&n()}),()=>{t=!0}},[e]);let E=async t=>{let n=await Pm(e,t);n.ok?(m(!1),f(e=>e+1),c(t)):alert(`failed: ${n.error}`)},D=async()=>{if(!b||!S.trim()){x(null);return}let t=b.path+`/`+S.trim();if(b.type===`file`){let n=await Pm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}else{let n=await Fm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}x(null),C(``),f(e=>e+1)},O=(0,_.useCallback)((t,n)=>{if(t===`view`)c(n.path);else if(t===`new-file`||t===`new-folder`)x({type:t===`new-file`?`file`:`folder`,path:n.path}),C(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Im(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,_.useCallback)(t=>TG(e,t.path)?[]:t.type===`dir`?[{label:`New file`,icon:(0,K.jsx)(se,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,K.jsx)(pe,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,K.jsx)(tt,{size:12}),action:`delete`,danger:!0}]:EG(e,t.path)?[]:[{label:`View`,icon:(0,K.jsx)(ie,{size:12}),action:`view`},{label:`Delete`,icon:(0,K.jsx)(tt,{size:12}),action:`delete`,danger:!0}],[e]),A=(0,_.useCallback)(t=>Dm(e,t).then(e=>e),[e]),j=(0,_.useCallback)((t,n,r,i)=>{if(t.type===`dir`)return TG(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=EG(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,K.jsxs)(`aside`,{className:`w-64 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`px-3 h-9 flex items-center gap-1 border-b border-gray-200`,children:[w&&(0,K.jsx)(`button`,{onClick:()=>y(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,K.jsx)(Pe,{size:14})}),(0,K.jsx)(wG,{}),(0,K.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,K.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,K.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,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:N?P.length===0?(0,K.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no matches`}):P.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{c(e.path),w&&y(!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,K.jsx)(`span`,{className:`text-gray-500`,children:`📄`}),(0,K.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-gray-900`,children:e.path})]},e.path)):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(IW,{treeId:`vault-${e}`,entries:r,onPick:e=>{c(e),w&&y(!1)},picked:s,onLoadChildren:A,getContextActions:k,onAction:O,nodeClassName:j,reloadKey:d}),r.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`empty · click + 创建第一个文件`})]})}),(0,K.jsx)(`div`,{className:`px-3 h-9 border-t border-gray-200 flex items-center text-[11px] text-gray-500`,children:bG[e]}),e===`knowledge`&&(0,K.jsx)(xG,{resource:e}),e===`notes`&&(0,K.jsx)(SG,{onRefreshed:()=>f(e=>e+1)})]});return(0,K.jsxs)(`div`,{className:`flex h-full w-full`,children:[w?(0,K.jsx)(K.Fragment,{children:v?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>y(!1),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:F})]}):(0,K.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>y(!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,K.jsx)(Fe,{size:16})})})}):F,(0,K.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white min-h-0`,children:s?(0,K.jsx)(kG,{vault:e,path:s,onSelect:c,onSaved:()=>f(e=>e+1),initialEditing:n}):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-[13px] text-gray-400 italic`,children:`选一个文件,或点 + 新建`})}),p&&(0,K.jsx)(AG,{vault:e,onClose:()=>m(!1),onCreate:E}),b&&(0,K.jsx)(DG,{type:b.type,parentPath:b.path,value:S,onChange:C,onSubmit:D,onCancel:()=>x(null)})]})}function wG(){return(0,K.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,className:`text-gray-400 shrink-0`,children:(0,K.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 TG(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).length>0}function EG(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).includes(`/`)}function DG({type:e,parentPath:t,value:n,onChange:r,onSubmit:i,onCancel:a}){return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:a,children:(0,K.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,K.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[e===`file`?`New file`:`New folder`,` in `,(0,K.jsx)(`span`,{className:`font-mono text-[13px]`,children:t||`root`})]}),(0,K.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,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,K.jsx)(`button`,{onClick:a,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,K.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 OG(e){return/(^|\/)secrets\//.test(e)||e===`secrets`}function kG({vault:e,path:t,onSelect:n,onSaved:r,initialEditing:i}){let a=Cg(),o=zn(),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(i??!1),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)([]),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(!1),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(!1),O=lU(),k=(0,_.useRef)(i);(0,_.useEffect)(()=>{k.current?k.current=!1:f(!1),C(!1),y(null),T(!1),D(!1),km(e,t).then(e=>{let t=e?.content??``;c(t),u(t),D(!!e?.secret)}),Lm(e,t).then(g)},[e,t]);let A=OG(t)||E,j=t.endsWith(`.md`),M=e!==`knowledge`,N=!A,P=e===`notes`&&!A,F=A?l.length>0:l!==s,I=(0,_.useCallback)(async()=>{if(!(!F||p)){m(!0);try{let n=await Am(e,t,l);if(n.ok){if(A?(c(``),u(``)):c(l),y(n.commit??null),f(!1),r(),Lm(e,t).then(g),e===`notes`){let e=await jm();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 em();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&&C(!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,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`header`,{className:`px-3 md:px-5 h-10 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-gray-500 shrink-0`,children:A?`🔒`:`📄`}),(0,K.jsx)(`span`,{className:`font-mono text-[12px] text-gray-500 truncate`,children:t}),v&&!F&&!d&&(0,K.jsxs)(`span`,{className:`hidden md:inline text-[10px] text-emerald-700 font-mono`,children:[`commit `,v]})]}),(0,K.jsx)(`div`,{className:`flex items-center gap-1 md:gap-2 text-xs text-gray-500`,children:d?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:R,className:`px-2.5 h-7 rounded text-xs text-gray-600 hover:bg-gray-100`,children:`cancel`}),(0,K.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,K.jsxs)(K.Fragment,{children:[P&&(0,K.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,K.jsx)(`span`,{children:`↑`}),(0,K.jsx)(`span`,{children:`distill`})]}),N&&(0,K.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,K.jsx)(`span`,{children:`↻`}),(0,K.jsx)(`span`,{children:`edit by loop`})]}),M&&(0,K.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,K.jsxs)(`button`,{onClick:()=>x(e=>!e),className:`px-2.5 h-7 rounded text-xs border ${b?`bg-gray-900 text-white`:`border-gray-200 hover:bg-gray-100 text-gray-900`}`,title:`toggle backlinks`,children:[`⇄ `,h.length]})]})})]}),d?A?(0,K.jsxs)(`div`,{className:w?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{className:`text-amber-700`,children:`🔒`}),(0,K.jsx)(`span`,{children:`new value · saved encrypted`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>T(!w),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:w?`restore`:`maximize`,children:w?(0,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,K.jsx)(mG,{path:t,value:l,onChange:u})})})]}):j&&!S?(0,K.jsxs)(`div`,{className:w?`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,K.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 border-r border-gray-200 flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{children:`source · markdown`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>C(!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,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>T(!w),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:w?`restore`:`maximize`,children:w?(0,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,K.jsx)(mG,{path:t,value:l,onChange:u})})})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,K.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,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto px-6 py-4`,children:(0,K.jsx)(`div`,{className:`max-w-[760px]`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading preview...`}),children:(0,K.jsx)(hG,{text:l,onWikilink:V})})})})]})]}):j?(0,K.jsxs)(`div`,{className:w?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{children:`wysiwyg · milkdown`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>C(!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,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>T(!w),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:w?`restore`:`maximize`,children:w?(0,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,K.jsx)(gG,{value:l,onChange:u})})})]}):(0,K.jsxs)(`div`,{className:w?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,K.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,K.jsxs)(`span`,{children:[`source · `,t.includes(`.`)?t.split(`.`).pop():`text`]}),t.endsWith(`.json`)&&(0,K.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,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>T(!w),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:w?`restore`:`maximize`,children:w?(0,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,K.jsx)(mG,{path:t,value:l,onChange:u})})})]}):(0,K.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:[(0,K.jsx)(`article`,{className:`flex-1 min-h-0 overflow-auto px-4 md:px-8 py-4 md:py-6`,children:(0,K.jsx)(`div`,{className:`max-w-[760px]`,children:A?(0,K.jsxs)(`div`,{className:`font-sans text-[13px] text-gray-600 leading-relaxed`,children:[(0,K.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,K.jsxs)(`div`,{className:`mt-3 text-[12px] text-gray-500`,children:[`Click `,(0,K.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,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading...`}),children:(0,K.jsx)(hG,{text:s,onWikilink:V})}):(0,K.jsx)(`pre`,{className:`font-mono text-[12.5px] leading-relaxed whitespace-pre-wrap text-gray-900`,children:s||(0,K.jsx)(`span`,{className:`text-gray-400 italic`,children:`(empty)`})})})}),j&&!O&&(0,K.jsxs)(`aside`,{className:`w-64 shrink-0 border-l border-gray-200 bg-gray-50 overflow-auto`,children:[(0,K.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,K.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length})]}),h.length===0?(0,K.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,K.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,K.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]}),O&&j&&b&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>x(!1),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.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,K.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,K.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length}),(0,K.jsx)(`button`,{onClick:()=>x(!1),className:`ml-2 text-gray-400 hover:text-gray-700 px-1`,title:`close backlinks`,children:`✕`})]}),h.length===0?(0,K.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,K.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{n(e.path),x(!1)},className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,K.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]})]})]})]})}function AG({vault:e,onClose:t,onCreate:n}){let[r,i]=(0,_.useState)(``);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,K.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,K.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[`new file in `,e,`/`]}),(0,K.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,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`relative path. directories created as needed.`}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,K.jsx)(`button`,{onClick:t,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,K.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 jG(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),u=(0,_.useCallback)(async()=>{let e=await Rm();t(e),r(e.notes?.git??``),a(e.repos)},[]);(0,_.useEffect)(()=>{u()},[u]);let d=e!==null&&(n.trim()!==(e.notes?.git??``)||JSON.stringify(i)!==JSON.stringify(e.repos)),f=()=>a(e=>[...e,{name:``,git:``}]),p=(e,t,n)=>a(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r)),m=e=>a(t=>t.filter((t,n)=>n!==e));return e?(0,K.jsx)(`article`,{className:`flex-1 min-w-0 overflow-auto p-5`,children:(0,K.jsxs)(`div`,{className:`max-w-2xl flex flex-col gap-5`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900`,children:`Repo roster`}),(0,K.jsxs)(`p`,{className:`text-[12px] text-gray-500 leading-relaxed mt-1`,children:[`Declared in the knowledge repo's`,` `,(0,K.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. Saving commits + pushes back to the knowledge repo (needs your key to have write access).`]})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`notes remote`}),(0,K.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),placeholder:`git@…/notes.git`,className:`px-2 py-1.5 text-sm font-mono border border-gray-300 rounded outline-none focus:border-gray-500`})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`repos`}),i.length===0&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:`No repos yet.`}),i.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{value:e.name,onChange:e=>p(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,K.jsx)(`input`,{value:e.git,onChange:e=>p(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,K.jsx)(`button`,{type:`button`,onClick:()=>m(t),className:`px-2 py-1.5 text-gray-400 hover:text-red-600`,title:`remove`,children:`✕`})]},t)),(0,K.jsx)(`button`,{type:`button`,onClick:f,className:`self-start text-[12px] text-gray-600 hover:text-gray-900 border border-gray-200 rounded px-2 py-1`,children:`+ add repo`})]}),c&&(0,K.jsx)(`div`,{className:`text-[12px] rounded px-2 py-1.5 border ${c.ok?`text-emerald-700 bg-emerald-50 border-emerald-200`:`text-red-700 bg-red-50 border-red-200`}`,children:c.text}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{s(!0),l(null);let e=i.map(e=>({name:e.name.trim(),git:e.git.trim()})).filter(e=>e.name&&e.git),t=await zm({notes:n.trim()?{git:n.trim()}:null,repos:e});s(!1),t.ok?(l({ok:!0,text:`Saved + promoted to the knowledge repo.`}),await u()):l({ok:!1,text:(t.savedLocally?`Saved locally but promote failed: `:`Save failed: `)+(t.error??``)})},disabled:!d||o,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:o?`Saving…`:`Save + promote`}),d&&(0,K.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`unsaved changes`})]})]})}):(0,K.jsx)(`div`,{className:`p-6 text-sm text-gray-400`,children:`loading…`})}function MG(){var e=[...arguments];return(0,_.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var NG=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function PG(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function FG(e){return`nodeType`in e}function IG(e){return e?PG(e)?e:FG(e)?e.ownerDocument?.defaultView??window:window:window}function LG(e){let{Document:t}=IG(e);return e instanceof t}function RG(e){return PG(e)?!1:e instanceof IG(e).HTMLElement}function zG(e){return e instanceof IG(e).SVGElement}function BG(e){return e?PG(e)?e.document:FG(e)?LG(e)?e:RG(e)||zG(e)?e.ownerDocument:document:document:document}var VG=NG?_.useLayoutEffect:_.useEffect;function HG(e){let t=(0,_.useRef)(e);return VG(()=>{t.current=e}),(0,_.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function UG(){let e=(0,_.useRef)(null);return[(0,_.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,_.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function WG(e,t){t===void 0&&(t=[e]);let n=(0,_.useRef)(e);return VG(()=>{n.current!==e&&(n.current=e)},t),n}function GG(e,t){let n=(0,_.useRef)();return(0,_.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function KG(e){let t=HG(e),n=(0,_.useRef)(null);return[n,(0,_.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function qG(e){let t=(0,_.useRef)();return(0,_.useEffect)(()=>{t.current=e},[e]),t.current}var JG={};function YG(e,t){return(0,_.useMemo)(()=>{if(t)return t;let n=JG[e]==null?0:JG[e]+1;return JG[e]=n,e+`-`+n},[e,t])}function XG(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 ZG=XG(1),QG=XG(-1);function $G(e){return`clientX`in e&&`clientY`in e}function eK(e){if(!e)return!1;let{KeyboardEvent:t}=IG(e.target);return t&&e instanceof t}function tK(e){if(!e)return!1;let{TouchEvent:t}=IG(e.target);return t&&e instanceof t}function nK(e){if(tK(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 $G(e)?{x:e.clientX,y:e.clientY}:null}var rK=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[rK.Translate.toString(e),rK.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),iK=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function aK(e){return e.matches(iK)?e:e.querySelector(iK)}var oK={display:`none`};function sK(e){let{id:t,value:n}=e;return _.createElement(`div`,{id:t,style:oK},n)}function cK(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return _.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 lK(){let[e,t]=(0,_.useState)(``);return{announce:(0,_.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var uK=(0,_.createContext)(null);function dK(e){let t=(0,_.useContext)(uK);(0,_.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function fK(){let[e]=(0,_.useState)(()=>new Set),t=(0,_.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,_.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var pK={draggable:`
|
|
107
|
+
`),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 WW({filePath:e,diff:t,loading:n,onClose:r}){let i=null;if(t)try{i=UW(t)}catch{}return(0,K.jsx)(Ag,{open:!0,onOpenChange:e=>{e||r()},children:(0,K.jsxs)(Ng,{className:`sm:max-w-4xl max-h-[85vh] flex flex-col bg-white p-0 gap-0`,showCloseButton:!1,children:[(0,K.jsxs)(`div`,{className:`px-4 py-2.5 border-b border-gray-200 shrink-0 flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-mono text-gray-900 truncate flex-1`,children:e}),(0,K.jsx)(`button`,{onClick:r,className:`text-gray-400 hover:text-gray-700 text-sm leading-none`,children:`✕`})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:n?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-gray-400 gap-2`,children:[(0,K.jsx)(we,{className:`animate-spin`,size:16}),(0,K.jsx)(`span`,{className:`text-sm`,children:`loading diff...`})]}):i?(0,K.jsx)(`div`,{className:`text-xs font-mono leading-5`,children:i.hunks.map((e,t)=>(0,K.jsxs)(`div`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex `+(n?`bg-emerald-50`:r?`bg-red-50`:``),children:[(0,K.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,K.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,K.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,K.jsx)(`span`,{className:`select-none`,children:n?`+`:r?`−`:` `}),e.text]})]},t)})]},t))}):(0,K.jsx)(`div`,{className:`py-16 text-center text-sm text-gray-400`,children:`empty diff`})})]})})}var GW={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 KW({loopId:e,onClose:t,onPickFile:n}){let[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!0),[l,u]=(0,_.useState)(!0),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)([]),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(!0),O=(0,_.useCallback)(async()=>{o(!0),f(null);try{i(await yh(e))}catch{f(`Failed to load git status`)}finally{o(!1)}},[e]),k=(0,_.useCallback)(async()=>{T(!0);try{C(await wh(e,50))}catch{}finally{T(!1)}},[e]);(0,_.useEffect)(()=>{O(),k()},[O,k]);let A=async()=>{r?.unstaged.length&&await xh(e,r.unstaged.map(e=>e.path))&&O()},j=async()=>{r?.staged.length&&await xh(e,r.staged.map(e=>e.path),!0)&&O()},M=async t=>{await xh(e,[t])&&O()},N=async t=>{await xh(e,[t],!0)&&O()},P=async t=>{await Sh(e,t)&&O()},F=async()=>{if(!h.trim())return;y(!0),x(null);let t=await Ch(e,h.trim());y(!1),t.ok?(g(``),O(),k()):x(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,K.jsxs)(`aside`,{className:`w-full h-full min-w-0 bg-white flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{className:`tracking-wide`,children:`Git Changes`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>{O(),k()},className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,title:`refresh`,children:(0,K.jsx)(Ve,{size:13,className:a||w?`animate-spin`:``})}),(0,K.jsx)(`button`,{className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,onClick:t,title:`close`,children:`✕`})]}),(0,K.jsxs)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:[(0,K.jsx)(`textarea`,{placeholder:`Commit message...`,value:h,onChange:e=>{g(e.target.value),x(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,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`button`,{onClick:F,disabled:v||!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,K.jsx)(ge,{size:12}),v?`Committing...`:`Commit`]}),r&&r.staged.length>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[r.staged.length,` staged`]})]}),b&&(0,K.jsx)(`div`,{className:`mt-1 text-[10px] text-red-500`,children:b})]}),(0,K.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-100`,children:(0,K.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,K.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto text-[13px]`,children:[(0,K.jsxs)(`div`,{className:`overflow-auto py-2`,children:[a&&!r&&(0,K.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`loading git status...`}),d&&(0,K.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-red-500`,children:d}),z&&!a&&(0,K.jsx)(`div`,{className:`px-5 py-4 text-[12px] text-gray-400 italic`,children:`no changes`}),L.length>0&&(0,K.jsx)(JW,{title:`Unstaged Changes`,count:L.length,open:s,onToggle:()=>c(e=>!e),bulkAction:{label:`Stage all`,icon:(0,K.jsx)(Re,{size:12}),onClick:A},children:L.map(t=>(0,K.jsx)(YW,{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,K.jsx)(JW,{title:`Staged Changes`,count:R.length,open:l,onToggle:()=>u(e=>!e),bulkAction:{label:`Unstage all`,icon:(0,K.jsx)(Ae,{size:12}),onClick:j},children:R.map(t=>(0,K.jsx)(YW,{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,K.jsxs)(`div`,{className:`border-t border-gray-200`,children:[(0,K.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,K.jsx)(`span`,{className:`text-gray-500`,children:E?`▾`:`▸`}),(0,K.jsx)(he,{size:12,className:`text-gray-500`}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:`History`}),(0,K.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,S.length,`)`]})]}),E&&(0,K.jsx)(`div`,{className:`px-2 pb-2 max-h-64 overflow-auto`,children:w?(0,K.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`loading history...`}):S.length===0?(0,K.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`no commits`}):(0,K.jsx)(qW,{commits:S})})]})]})]})}function qW({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,K.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,K.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,K.jsxs)(`div`,{className:`flex flex-col items-center shrink-0`,children:[(0,K.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,K.jsx)(`div`,{className:`w-0.5 h-10 ${a} opacity-10`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400 truncate`,children:t.shortHash}),o&&(0,K.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,K.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,K.jsx)(`span`,{className:`text-[9px] px-1 py-0 rounded bg-purple-100 text-purple-700 font-medium`,children:e},e))]}),(0,K.jsx)(`div`,{className:`text-gray-700 truncate`,children:t.subject}),(0,K.jsxs)(`div`,{className:`text-gray-400 text-[10px]`,children:[t.author,` · `,s]})]})]},t.hash)})})}function JW({title:e,count:t,open:n,onToggle:r,bulkAction:i,children:a}){return(0,K.jsxs)(`div`,{className:`mb-2`,children:[(0,K.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,K.jsx)(`span`,{className:`text-gray-500`,children:n?`▾`:`▸`}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500`,children:e}),(0,K.jsxs)(`span`,{className:`text-[11px] text-gray-400`,children:[`(`,t,`)`]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.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,K.jsx)(`div`,{children:a})]})}function YW({file:e,loopId:t,staged:n,onStage:r,onUnstage:i,onDiscard:a,onEdit:o,onRefresh:s}){let[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=e=>{y.current&&!y.current.contains(e.target)&&v(null)};if(g)return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let b=async()=>{e.isBinary||(l(!0),u===null&&(p(!0),d(await bh(t,e.path,n)??``),p(!1)))},x=e=>{e.preventDefault(),v({x:e.clientX,y:e.clientY})},S=`workdir/${e.path}`,C=[{label:`Open in Editor`,icon:(0,K.jsx)(Le,{size:12}),onClick:()=>{o(S),v(null)}},{label:`View Diff`,icon:(0,K.jsx)(Ue,{size:12}),onClick:()=>{b(),v(null)}},{separator:!0,label:``,onClick:()=>{}},n?{label:`Unstage`,icon:(0,K.jsx)(Ae,{size:12}),onClick:()=>{i(),v(null)}}:{label:`Stage`,icon:(0,K.jsx)(Re,{size:12}),onClick:()=>{r(),v(null)}},!n&&{label:`Discard Changes`,icon:(0,K.jsx)(rt,{size:12}),onClick:()=>{h(!0),v(null)},danger:!0}].filter(Boolean),w=GW[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,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`group/row relative flex items-center gap-2 px-3 py-1.5 hover:bg-gray-50`,onContextMenu:x,children:[(0,K.jsx)(`span`,{className:`w-5 text-center text-[11px] font-mono font-semibold ${w.color}`,children:w.label}),(0,K.jsxs)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] font-mono`,children:[(0,K.jsx)(`span`,{className:`text-gray-900`,children:E}),D&&(0,K.jsx)(`span`,{className:`text-gray-400 ml-0.5`,children:D})]}),!e.isBinary&&(e.additions>0||e.deletions>0)&&(0,K.jsxs)(`span`,{className:`text-[11px] font-mono flex items-center gap-0.5 shrink-0`,children:[(0,K.jsxs)(`span`,{className:`text-emerald-600`,children:[`+`,e.additions]}),(0,K.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]}),(0,K.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,K.jsx)(`button`,{type:`button`,onClick:()=>o(S),className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-blue-600 rounded`,title:`edit file`,children:(0,K.jsx)(Le,{size:13})}),n&&(0,K.jsx)(`button`,{type:`button`,onClick:b,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,K.jsx)(Ue,{size:13})}),n?(0,K.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,K.jsx)(Ae,{size:13})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.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,K.jsx)(rt,{size:13})}),(0,K.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,K.jsx)(Re,{size:13})})]})]})]}),g&&(0,K.jsx)(`div`,{ref:y,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:C.map((e,t)=>e.separator?(0,K.jsx)(`div`,{className:`my-1 border-t border-gray-100`},t):(0,K.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,K.jsx)(`span`,{children:e.label})]},t))}),c&&(0,K.jsx)(WW,{filePath:e.path,diff:u,loading:f,onClose:()=>l(!1)}),m&&(0,K.jsx)(Ag,{open:!0,onOpenChange:e=>{e||h(!1)},children:(0,K.jsxs)(Ng,{className:`sm:max-w-sm bg-white p-5 gap-4`,showCloseButton:!1,children:[(0,K.jsx)(Pg,{children:(0,K.jsx)(Fg,{className:`text-sm`,children:`Discard changes`})}),(0,K.jsx)(`p`,{className:`text-[13px] text-gray-600 break-all font-mono`,children:e.path}),(0,K.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,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,K.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,K.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 XW(e){return e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:`standard`}function ZW({loop:e,open:t,onClose:n,onSaved:r}){let[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(e.shareEnabled??!1),[c,l]=(0,_.useState)(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),[u,d]=(0,_.useState)(e.shareAlias??``),[f,p]=(0,_.useState)(e.sharePort??3e3),[m,h]=(0,_.useState)(e.shareExternalPort??1e4),[g,v]=(0,_.useState)(e.shareProtocol??`tcp`),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(``),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(``),[j,M]=(0,_.useState)(!1),[N,F]=(0,_.useState)(``),[I,L]=(0,_.useState)(``),[z,B]=(0,_.useState)(XW(e)),[V,H]=(0,_.useState)(null),U=e.id.slice(0,8),W=!!(i&&i.serveEnabled),te=!!(i&&i.serveDynamicEnabled),ne=!!(i&&i.serveEphemeralEnabled),G=[W,te,ne].filter(Boolean).length>1,re=W&&!te&&!ne,ie=!W&&te&&!ne,ae=!W&&!te&≠(0,_.useEffect)(()=>{t&&(Rh().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),v(e.shareProtocol??`tcp`),B(XW(e)),b(null),S(``),A(``),H(null))},[t,e]),(0,_.useEffect)(()=>{if(!t||!(ae||G&&z===`ephemeral`)||!e.shareEnabled||e.shareMode!==`ephemeral`)return;let n=!1,r=async()=>{let t=await zh(e.id);n||H(t.port)};r();let i=setInterval(r,3e3);return()=>{n=!0,clearInterval(i)}},[t,z,ae,G,e.id,e.shareEnabled,e.shareMode]),(0,_.useEffect)(()=>{!t||!i||i.serveDynamicEnabled&&(e.shareEnabled&&e.shareExternalPort||!e.shareEnabled&&!e.shareExternalPort&&Vh().then(e=>{e.port&&h(e.port)}))},[t,i,e.shareEnabled,e.shareExternalPort]),(0,_.useEffect)(()=>{t&&Uh(U,e.id).then(e=>{e.available?O(!1):(O(!0),S(`ID "${U}" is already in use. Please set an alias.`))})},[t,U,e.id]),(0,_.useEffect)(()=>{if(!u||!t){b(null),S(``);return}let n=setTimeout(async()=>{let t=await Uh(u,e.id);b(t.available),S(t.reason??``)},300);return()=>clearTimeout(n)},[u,t,e.id]);let oe=u||U,se=i?.https?`https`:`http`,ce=i?.withPort?`:${i.displayPort}`:``,le=i?`${se}://${oe}${i.baseUrl}${ce}`:``,ue=i?.serveDynamicDomain||i?.ip||`<host-ip>`,de=g===`static`?`http://${ue}:${m}`:`tcp://${ue}:${m}`,fe=i?.serveEphemeralDomain||i?.ip||`<host-ip>`,pe=V?`${g===`udp`?`udp`:`tcp`}://${fe}:${V}`:`(no active port — save & wait for container restart)`,me=ie||G&&z===`direct`&&te&&!ae,he=ae||G&&z===`ephemeral`,ge=he?pe:me?de:le;(0,_.useEffect)(()=>{if(!t||!me)return;let n=setTimeout(async()=>{M(!0);let t=await Hh(m,e.id);M(!1),t.available?A(``):A(t.reason??`Port unavailable`)},400);return()=>clearTimeout(n)},[m,t,c,e.id]);let ve=async()=>{if(E(!0),me){let t=await Hh(m,e.id);if(!t.available){A(t.reason??`Port unavailable`),E(!1);return}}let t={shareEnabled:o};o?he?(t.shareMode=`ephemeral`,t.sharePort=f,t.shareProtocol=g===`static`?`tcp`:g,t.shareAlias=void 0,t.shareExternalPort=void 0):me?(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)F(`Saved`),await r?.(),setTimeout(()=>{F(``),n()},800);else try{L((await i.json()).error??`Save failed (${i.status})`)}catch{L(`Save failed (${i.status})`)}},ye=async()=>{try{await navigator.clipboard.writeText(ge),w(!0),setTimeout(()=>w(!1),1500)}catch{window.prompt(`Copy this URL:`,ge)}},be=!T&&!k&&!j&&(he?f>=1&&f<=65535:(!me||m>=1024)&&(!me||f>=1||g===`static`)&&(me||c!==`port`||!D||u.trim().length>0)&&(me||c!==`port`||f>=1024));return i?(0,K.jsx)(Ag,{open:t,onOpenChange:e=>{e||n()},children:(0,K.jsxs)(Ng,{className:`sm:max-w-md bg-white max-h-[85vh] overflow-y-auto`,children:[(0,K.jsxs)(Pg,{children:[(0,K.jsxs)(Fg,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(_e,{size:16}),`Share Artifact`]}),(0,K.jsx)(Ig,{className:`sr-only`,children:`Share this artifact via a public URL.`})]}),(0,K.jsxs)(`div`,{className:`space-y-4 text-[13px]`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-sm text-gray-700`,children:`Enable sharing`}),(0,K.jsx)(`button`,{onClick:()=>s(!o),className:`w-10 h-5 rounded-full transition-colors ${o?`bg-blue-600`:`bg-gray-300`}`,children:(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${o?`translate-x-5`:`translate-x-0.5`}`})})]}),o&&(0,K.jsxs)(K.Fragment,{children:[G&&(0,K.jsxs)(`div`,{className:`flex gap-1.5 border-b border-gray-200 pb-2`,children:[W&&(0,K.jsx)(`button`,{onClick:()=>{B(`standard`),l(`static`)},className:`px-3 py-1 text-xs rounded-t ${z===`standard`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Subdomain`}),te&&(0,K.jsx)(`button`,{onClick:()=>{B(`direct`),l(`direct`)},className:`px-3 py-1 text-xs rounded-t ${z===`direct`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Direct Port`}),ne&&(0,K.jsx)(`button`,{onClick:()=>{B(`ephemeral`),l(`ephemeral`)},className:`px-3 py-1 text-xs rounded-t ${z===`ephemeral`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Ephemeral`})]}),(re||G&&z===`standard`)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Share mode`}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5 mt-1`,children:[(0,K.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,K.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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:[`Alias `,D?(0,K.jsx)(`span`,{className:`text-red-500`,children:`(required)`}):`(optional)`]}),(0,K.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,K.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,K.jsx)(R,{size:11}),` `,x||`ID "${U}" is already in use`]}),!D&&y===!0&&(0,K.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`}),!D&&y===!1&&(0,K.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,K.jsx)(R,{size:11}),` `,x||`Already in use`]})]}),c===`port`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Port (1024-65535)`}),(0,K.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`})]})]}),he&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,K.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,K.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,K.jsx)(`button`,{onClick:()=>v(`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,K.jsx)(`button`,{onClick:()=>v(`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,K.jsxs)(`div`,{children:[(0,K.jsxs)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider flex items-center gap-1.5`,children:[`Current host port`,(0,K.jsx)(Be,{size:10,className:`text-gray-300`})]}),(0,K.jsx)(`div`,{className:`mt-1 px-2 py-1.5 text-sm bg-gray-50 rounded text-gray-700`,children:V==null?(0,K.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,K.jsx)(`span`,{className:`font-mono`,children:V})}),(0,K.jsxs)(`p`,{className:`text-[10px] text-amber-600 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(R,{size:10}),` Changes on every loop restart. Saving also restarts the container.`]})]})]}),(ie||G&&z===`direct`&&!he)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`External port`}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,K.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,K.jsx)(`button`,{onClick:async()=>{let e=await Vh();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,K.jsx)(Je,{size:14})})]}),(0,K.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The public port clients connect to`}),j&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 mt-0.5`,children:`Checking availability…`}),k&&(0,K.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,K.jsx)(R,{size:11}),` `,k]}),!j&&!k&&(0,K.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`})]}),g!==`static`&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Container port`}),(0,K.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,K.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-0.5`,children:`The port your app listens on inside the sandbox`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Protocol`}),(0,K.jsxs)(`div`,{className:`flex gap-1.5 mt-1`,children:[(0,K.jsx)(`button`,{onClick:()=>v(`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,K.jsx)(`button`,{onClick:()=>v(`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,K.jsx)(`button`,{onClick:()=>v(`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,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`text-[11px] text-gray-500 uppercase tracking-wider`,children:`Access URL`}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,K.jsx)(`code`,{className:`flex-1 px-2 py-1.5 text-xs bg-gray-50 rounded text-gray-700 truncate`,children:ge}),(0,K.jsx)(`button`,{onClick:ye,className:`px-2 py-1.5 rounded hover:bg-gray-100 text-gray-500`,title:`Copy URL`,children:C?(0,K.jsx)(P,{size:14,className:`text-emerald-600`}):(0,K.jsx)(ee,{size:14})})]}),(0,K.jsx)(`p`,{className:`text-[10px] text-gray-400 mt-1`,children:me?`Direct TCP/UDP access — no domain needed`:`Domain suffix configured in Settings → Workspace → Workspace Serve`})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2`,children:[I&&(0,K.jsx)(`span`,{className:`text-xs text-red-500`,children:I}),N&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:12}),` `,N]}),(0,K.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,K.jsx)(`button`,{onClick:ve,disabled:!be,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 QW=(0,_.lazy)(()=>gt(()=>import(`./Editor-0dvlktuX.js`).then(e=>({default:e.Editor})),__vite__mapDeps([0,1,2,3]))),$W=(0,_.lazy)(()=>gt(()=>import(`./Terminal-trnCVajY.js`).then(e=>({default:e.Terminal})),__vite__mapDeps([4,1,5])));function eG(){let{id:e}=Un(),t=Cg();if(!e)return(0,K.jsx)(pr,{to:`/loop`,replace:!0});if(!t.currentUser)return(0,K.jsx)(OW,{});let n=t.loops.find(t=>t.id===e);return t.loopsLoading?null:n?(0,K.jsxs)(`div`,{className:`h-full w-full flex min-h-0`,children:[(0,K.jsx)(tG,{currentId:e}),(0,K.jsx)(nG,{meta:n},e)]}):(0,K.jsx)(pr,{to:`/loop`,replace:!0})}function tG({currentId:e}){let t=Cg(),n=zn(),[r,i]=(0,_.useState)(`mine`),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(()=>localStorage.getItem(`loopat:loopsList:collapsed`)===`1`),l=lU(),u=MW((0,_.useMemo)(()=>t.loops.map(e=>e.id),[t.loops]));(0,_.useEffect)(()=>{let t=u[e];t?.status===`Done`&&t?.viewed===!1&&um(e)},[u,e]);let d=t.currentUser?.id,f=(0,_.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,K.jsxs)(`aside`,{className:`w-60 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`px-2 pt-1.5 pb-1 space-y-1 border-b border-gray-200`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[[`mine`,`all`,`rfd`].map(e=>(0,K.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,K.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-auto pr-1`,children:f.length}),(0,K.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,K.jsx)(w,{size:13})}),(0,K.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,K.jsx)(Pe,{size:14})})]}),(0,K.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,K.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,K.jsxs)(`div`,{className:`group/row relative flex items-stretch `+(i?`bg-gray-100`:`hover:bg-gray-50`),children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{um(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,K.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,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`text-[13px] text-gray-900 truncate flex items-center gap-1.5`,children:[a&&(0,K.jsx)(w,{size:10,className:`text-gray-400 shrink-0`}),r.rfdRequestedAt&&(0,K.jsx)(`span`,{className:`shrink-0 text-[9px] px-1 rounded bg-amber-100 text-amber-800 font-medium tracking-wide`,children:`RFD`}),(0,K.jsx)(`span`,{className:`truncate`,children:r.title}),s&&(0,K.jsx)(`span`,{className:`shrink-0 text-[10px] font-medium `+(d?`text-blue-500`:c?`text-emerald-500`:`text-gray-400`),children:s.status})]}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 truncate flex items-center gap-1 mt-0.5`,children:[(0,K.jsx)(`span`,{children:r.driver??r.createdBy}),(0,K.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-gray-400`,children:r.id.slice(0,6)})]})]})]}),(0,K.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,K.jsx)(C,{size:13}):(0,K.jsx)(w,{size:13})})]},r.id)}),f.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no loops · click "+ New Loop"`})]})]});return s?(0,K.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,K.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,K.jsx)(Fe,{size:16})})}):l?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,K.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,K.jsx)(Pe,{size:16})})}),(0,K.jsxs)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>p(!0),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.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 nG({meta:e}){let t=Cg(),n=lU(),[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(null);(0,_.useEffect)(()=>{Rh().then(m)},[]);let[h,g]=(0,_.useState)(null),v=e=>{c(e),g(null),i(e=>e.includes(`editor`)?e:[...e,`editor`])},{runtime:y,connected:b,reconnecting:x,running:S,viewers:C,extra:w,queue:T,onClearQueue:E}=TU(e.id,t.currentUser?.id??``,v),D=MW((0,_.useMemo)(()=>[e.id],[e.id])),O=D[e.id]?.phase===`preparing`,k=D[e.id]?.status;(0,_.useEffect)(()=>{Em(e.id).then(u),um(e.id),t.currentUser?.id&&localStorage.setItem(`loopat:lastLoop:${t.currentUser.id}`,e.id)},[e.id]);let A=Fn(),j=zn(),M=A.state?.kickoff;(0,_.useEffect)(()=>{!M||!b||(w.enqueueMessage(M),j(A.pathname,{replace:!0,state:null}))},[M,b]);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,_.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);return!isNaN(e)&&e>=10&&e<=90?e:55}),[U,ee]=(0,_.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);return!isNaN(e)&&e>=5&&e<=50?e:18});(0,_.useEffect)(()=>{if(!B){let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);!isNaN(e)&&e>=5&&e<=50&&ee(e)}if(!z&&!B){let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);!isNaN(e)&&e>=10&&e<=90&&H(e)}},[z,B]);let W=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)))},te=n=>{let r=a===n;return(0,K.jsx)(lG,{loopId:e.id,meta:e,mode:n,onClose:()=>F(n),pickedFile:s,onPickFile:v,currentUserId:t.currentUser?.id??``,isFullscreen:r,onToggleFullscreen:()=>o(r?null:n),onEditorSelection:g},n)};return(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,K.jsx)(rG,{meta:e,mounts:l,connected:b,reconnecting:x,running:S,viewers:C,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,K.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,K.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,K.jsx)(`ul`,{className:`mt-1 ml-4 list-disc`,children:e.contextWarnings.map((e,t)=>(0,K.jsx)(`li`,{className:`font-mono text-[11px] break-all`,children:e},t))})]}),(0,K.jsxs)(`div`,{className:`relative flex-1 min-h-0 flex flex-col`,children:[O&&(0,K.jsx)(oG,{detail:k}),n?(0,K.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,K.jsx)(wU,{extra:w,children:(0,K.jsx)(ew,{runtime:y,children:(0,K.jsx)(DW,{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,K.jsxs)(tk,{orientation:`horizontal`,className:`flex-1 min-w-0 min-h-0`,onLayoutChange:W,children:[(0,K.jsx)(ik,{id:`chat`,minSize:20,defaultSize:V,className:`flex flex-col min-h-0 min-w-0`,children:(0,K.jsx)(wU,{extra:w,children:(0,K.jsx)(ew,{runtime:y,children:(0,K.jsx)(DW,{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,K.jsx)(sk,{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,K.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,K.jsx)(ik,{id:`editorCol`,minSize:15,defaultSize:30,className:`flex flex-col min-h-0 min-w-0`,children:L.length>1?(0,K.jsx)(tk,{orientation:`vertical`,className:`flex-1 min-h-0`,children:L.map((e,t)=>(0,K.jsxs)(_.Fragment,{children:[t>0&&(0,K.jsx)(sk,{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,K.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,K.jsx)(ik,{id:e,minSize:10,defaultSize:100/L.length,className:`flex flex-col min-h-0 min-w-0`,children:te(e)})]},e))}):te(L[0])}),z&&B&&(0,K.jsx)(sk,{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,K.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,K.jsx)(ik,{id:`otherCol`,minSize:15,defaultSize:U,className:`flex flex-col min-h-0 min-w-0`,children:R.length>1?(0,K.jsx)(tk,{orientation:`vertical`,className:`flex-1 min-h-0`,children:R.map((e,t)=>(0,K.jsxs)(_.Fragment,{children:[t>0&&(0,K.jsx)(sk,{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,K.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,K.jsx)(ik,{id:e,minSize:10,defaultSize:100/R.length,className:`flex flex-col min-h-0 min-w-0`,children:te(e)})]},e))}):te(R[0])})]}):(0,K.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,K.jsx)(wU,{extra:w,children:(0,K.jsx)(ew,{runtime:y,children:(0,K.jsx)(DW,{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,K.jsx)(_.Fragment,{children:te(e)},e)),n&&(0,K.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,K.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,K.jsx)(ZW,{loop:e,open:d,onClose:()=>f(!1),onSaved:async()=>{await t.refresh()}})]})}function rG({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=lU(),p=zn(),m=Cg(),[h,g]=(0,_.useState)(f),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(e.title),w=m.currentUser?.id===e.createdBy,T=async()=>{if(!v){y(!0);try{let t=await gm(e.id);t&&p(`/loop/${t.id}`)}finally{y(!1)}}},E=async()=>{let t=S.trim();if(!t||t===e.title){x(!1),C(e.title);return}x(!1),await m.setLoopTitle(e.id,t)||C(e.title)},D=(e,t)=>(0,K.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,K.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,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.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,K.jsx)(F,{size:14,className:`transition-transform `+(h?`-rotate-90`:``)})}),b?(0,K.jsx)(`input`,{type:`text`,value:S,autoFocus:!0,onChange:e=>C(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing?(t.preventDefault(),E()):t.key===`Escape`&&(t.preventDefault(),x(!1),C(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,K.jsx)(`span`,{className:`text-[14px] md:text-[15px] font-medium text-gray-900 `+(w?`cursor-pointer hover:bg-gray-100 rounded px-1 -mx-1`:``),onClick:()=>{w&&(C(e.title),x(!0))},title:w?`click to rename`:void 0,children:e.title}),(0,K.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`driver: `,(0,K.jsx)(`span`,{className:`text-gray-900`,children:e.driver??e.createdBy})]}),e.rfdRequestedAt&&(0,K.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,K.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`reconnecting…`}),i&&(0,K.jsx)(`span`,{className:`text-[11px] text-blue-600`,children:`running`}),a>1&&(0,K.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,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`button`,{type:`button`,onClick:T,disabled:v,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,K.jsx)(ue,{size:11}),v?`Distilling…`:`Distill`]}),d!==!1&&(0,K.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,K.jsx)(_e,{size:11}),`Share Artifact`]}),(0,K.jsx)(aG,{meta:e}),(0,K.jsx)(iG,{meta:e})]}),!h&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`text-xs text-gray-500 mt-1.5 flex items-center gap-2 flex-wrap`,children:[(0,K.jsxs)(`span`,{className:`font-mono`,children:[`~/.loopat/loops/`,e.id.slice(0,8),`/workdir`]}),(0,K.jsx)(`span`,{children:`·`}),(0,K.jsx)(`span`,{children:`main`}),a>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{children:[a,` viewing`]})]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px]`,children:[D(`ℹ info`,`info`),D(`▤ workdir`,`workdir`),D(`✎ editor`,`editor`),D(`▷ terminal`,`terminal`),(0,K.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,K.jsx)(he,{size:14})})]})]}),(0,K.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:`context:`}),t.map(e=>(0,K.jsx)(sG,{label:e.name,value:e.name===`knowledge`?`ro`:`rw`},e.path))]}),e.config?.profiles&&e.config.profiles.length>0&&(0,K.jsx)(cG,{profiles:e.config.profiles}),(0,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:`vault:`}),(0,K.jsx)(sG,{label:e.config?.vault??`default`,value:`loaded`})]})]})]})}function iG({meta:e}){let t=Cg(),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.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,K.jsxs)(`div`,{className:`inline-flex items-center gap-1`,children:[s&&(0,K.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,K.jsx)(P,{size:11}):(0,K.jsx)(ee,{size:11}),(0,K.jsx)(`span`,{className:`hidden md:inline`,children:n?`copied`:`copy link`})]}),(0,K.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,K.jsx)(_e,{size:11}):(0,K.jsx)(Te,{size:11}),s?`shared`:`share`]})]}):(0,K.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,K.jsx)(_e,{size:11}):(0,K.jsx)(Te,{size:11}),s?`public`:`private`]})}function aG({meta:e}){let t=Cg(),[n,r]=(0,_.useState)(!1);if(!t.currentUser)return null;let i=e.driver??e.createdBy,a=t.currentUser.id===i;return e.rfdRequestedAt?(0,K.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,K.jsx)(ve,{size:11}),`Drive`]}):a?(0,K.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,K.jsx)(ve,{size:11}),`Request For Drive`]}):null}function oG({detail:e}){return(0,K.jsx)(`div`,{className:`absolute inset-0 z-30 flex items-center justify-center bg-white/70 backdrop-blur-sm`,children:(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-center gap-2 mb-2`,children:[(0,K.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border-2 border-blue-500 border-t-transparent animate-spin`}),(0,K.jsx)(`span`,{className:`text-sm font-medium text-gray-900`,children:`Preparing this loop’s sandbox…`})]}),(0,K.jsxs)(`p`,{className:`text-[12px] text-gray-600 leading-relaxed`,children:[`Installing the toolchain from `,(0,K.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,K.jsx)(`p`,{className:`mt-2 text-[11px] font-mono text-blue-700 break-words`,children:e})]})})}function sG({label:e,value:t,title:n}){return(0,K.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,K.jsxs)(`span`,{className:`text-gray-500`,children:[e,`:`]}),(0,K.jsx)(`span`,{className:`text-gray-900 font-medium`,children:t})]})}function cG({profiles:e}){let[t,n]=(0,_.useState)({});return(0,_.useEffect)(()=>{let e=!1;return om().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,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-1.5 flex-wrap text-[11px]`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:`profiles:`}),e.map(e=>(0,K.jsx)(sG,{label:e,value:`active`,title:t[e]},e))]})}function lG({loopId:e,meta:t,mode:n,onClose:r,pickedFile:i,onPickFile:a,currentUserId:o,isFullscreen:s,onToggleFullscreen:c,onEditorSelection:l}){let u=lU(),[d,f]=(0,_.useState)(()=>{let e=localStorage.getItem(`loopat:mobilePanelPct`);return e?Math.max(20,Math.min(95,parseInt(e)||55)):55}),p=(0,_.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)},v=()=>{p.current=null},y=e=>{e.preventDefault(),e.stopPropagation(),h(e.touches[0].clientY)},b=e=>{e.preventDefault(),g(e.touches[0].clientY)},x=e=>{e.preventDefault(),v()},S=e=>{e.pointerType!==`touch`&&(e.preventDefault(),e.target.setPointerCapture(e.pointerId),h(e.clientY))},C=e=>{e.pointerType===`touch`||!p.current||g(e.clientY)},w=e=>{e.pointerType!==`touch`&&v()},T=(0,K.jsxs)(`aside`,{className:`flex-1 min-w-0 bg-white flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{className:`capitalize`,children:n}),n===`editor`&&(0,K.jsx)(`span`,{className:`ml-2 truncate text-gray-700`,children:i||`(no file)`}),(0,K.jsx)(`div`,{className:`flex-1`}),(n===`editor`||n===`terminal`)&&(0,K.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,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})}),(0,K.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,K.jsx)(uG,{meta:t}),n===`workdir`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(BW,{loopId:e,onPick:a,picked:i}),(0,K.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 text-[11px] text-gray-500`,children:[`⑂ `,(0,K.jsx)(`span`,{className:`text-gray-900`,children:`main`})]})]}),(0,K.jsxs)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading...`}),children:[n===`editor`&&(0,K.jsx)(QW,{loopId:e,path:i,onSelectionChange:l}),n===`terminal`&&(0,K.jsx)(`div`,{className:`flex-1 min-h-0 bg-[#1a1c20] overflow-hidden`,children:(0,K.jsx)($W,{loopId:e,currentUserId:o})}),n===`git`&&(0,K.jsx)(KW,{loopId:e,onClose:r,onPickFile:a})]})]});return u?(0,K.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,K.jsx)(`div`,{className:`absolute inset-0 bottom-7 overflow-y-auto flex flex-col`,children:T}),(0,K.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:y,onTouchMove:b,onTouchEnd:x,onPointerDown:S,onPointerMove:C,onPointerUp:w,children:(0,K.jsx)(`div`,{className:`w-8 h-1 rounded-full bg-gray-300`})})]}):s?(0,dt.createPortal)((0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex flex-col`,children:T}),document.body):T}function uG({meta:e}){let t=Cg().currentUser?.id===e.createdBy;return(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-5 py-4 text-[13px] text-gray-900`,children:[(0,K.jsxs)(dG,{label:`basics`,children:[(0,K.jsx)(fG,{label:`title`,value:e.title}),(0,K.jsx)(fG,{label:`created`,value:new Date(e.createdAt).toLocaleString()}),(0,K.jsx)(fG,{label:`status`,value:`active`}),(0,K.jsx)(fG,{label:`driver`,value:t?`${e.createdBy} (you)`:e.createdBy}),(0,K.jsx)(fG,{label:`sharing`,value:e.public?`public — /loop/${e.id.slice(0,8)}…`:`private`})]}),(0,K.jsxs)(dG,{label:`workdir`,children:[(0,K.jsx)(fG,{label:`id`,value:e.id,mono:!0}),(0,K.jsx)(fG,{label:`path`,value:`~/.loopat/loops/${e.id.slice(0,8)}/workdir`,mono:!0}),(0,K.jsx)(fG,{label:`branch`,value:`main`,mono:!0})]}),(0,K.jsxs)(dG,{label:`context`,children:[(0,K.jsx)(fG,{label:`knowledge`,value:`all (ro)`}),(0,K.jsx)(fG,{label:`notes`,value:`all (rw)`}),(0,K.jsx)(fG,{label:`personal`,value:`${e.createdBy} (rw)`})]})]})}function dG({label:e,children:t}){return(0,K.jsxs)(`section`,{className:`mb-5`,children:[(0,K.jsx)(`h3`,{className:`text-[11px] uppercase tracking-wide text-gray-400 mb-2`,children:e}),(0,K.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:t})]})}function fG({label:e,value:t,mono:n=!1}){return(0,K.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500 w-24 shrink-0`,children:e}),(0,K.jsx)(`span`,{className:n?`font-mono text-[12px] text-gray-800 truncate`:`text-[13px] text-gray-900 truncate`,children:t})]})}function pG({name:e,onClick:t,onEdit:n,size:r=`sm`}){return(0,K.jsxs)(`span`,{className:`relative inline-flex items-center group/chip`,children:[(0,K.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,K.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 mG(){let{name:e}=Un(),t=decodeURIComponent(e??``),n=zn(),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{let e=!1;return dh().then(n=>{e||(i(n.find(e=>e.name===t.toLowerCase())??null),o(!1))}),()=>{e=!0}},[t]),(0,K.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-white`,children:[(0,K.jsxs)(`header`,{className:`h-10 shrink-0 flex items-center gap-3 px-6 border-b border-gray-200`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>n(-1),className:`text-[11px] text-gray-500 hover:text-gray-900`,children:`← back`}),(0,K.jsx)(pG,{name:t,size:`md`}),(0,K.jsx)(`div`,{className:`flex-1`})]}),(0,K.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col overflow-auto`,children:(0,K.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,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`}):!r||r.loops.length===0?(0,K.jsxs)(`div`,{className:`text-[12px] text-gray-400 italic`,children:[`no entities tagged with `,(0,K.jsxs)(`code`,{children:[`#`,t]})]}):(0,K.jsxs)(`section`,{children:[(0,K.jsxs)(`div`,{className:`text-[12px] uppercase tracking-wider text-gray-500 mb-2 px-1`,children:[`Loops (`,r.loops.length,`)`]}),(0,K.jsx)(`div`,{className:`flex flex-col gap-1`,children:r.loops.map(e=>(0,K.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,K.jsx)(`span`,{className:`ml-2 text-[10px] font-mono text-gray-400`,children:e.id.slice(0,6)})]},e.id))})]})})})]})}var hG=(0,_.lazy)(()=>gt(()=>import(`./CodeEditor-DtHZtsPs.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([2,1,3]))),gG=(0,_.lazy)(()=>gt(()=>import(`./Markdown-B7OaedKV.js`).then(e=>({default:e.Markdown})),__vite__mapDeps([6,1]))),_G=(0,_.lazy)(()=>gt(()=>import(`./MilkdownEditor-DOe3xJcb.js`).then(e=>({default:e.MilkdownEditor})),__vite__mapDeps([7,1,3]))),vG=[{id:`knowledge`,label:`Knowledge`},{id:`notes`,label:`Notes`},{id:`personal`,label:`Personal`},{id:`repos`,label:`Repos`}],yG=new Set([`knowledge`,`notes`,`personal`,`repos`]);function bG(){let{sub:e}=Un(),[t]=_i(),n=yG.has(e)?e:`knowledge`,r=t.get(`file`)||void 0,i=t.get(`edit`)===`1`;return(0,K.jsxs)(`div`,{className:`flex flex-col h-full w-full`,children:[(0,K.jsx)(`nav`,{className:`flex items-center gap-1 px-3 h-9 shrink-0 border-b border-gray-200 bg-white`,children:vG.map(e=>(0,K.jsx)(ui,{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,K.jsx)(`span`,{children:e.label})},e.id))}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 min-w-0`,children:n===`repos`?(0,K.jsx)(MG,{}):(0,K.jsx)(wG,{vault:n,initialFile:r,initialEditing:i},n)})]})}var xG={knowledge:`workspace's distilled materials`,notes:`workspace · public`,personal:`yours · private`,repos:`registered code repos`};function SG({resource:e,canPush:t=!0}){let[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),c=(0,_.useCallback)(async()=>{a(`status`),r(await Um(e)),a(null)},[e]);(0,_.useEffect)(()=>{c()},[c]);let l=async()=>{a(`pull`),s(null);let t=await Wm(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 Gm(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,K.jsxs)(`div`,{className:`px-3 py-1.5 border-t border-gray-200 flex flex-col gap-1 text-[11px]`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:p?(0,K.jsx)(`span`,{className:`text-gray-400`,children:`no remote`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:d>0?`text-emerald-700`:`text-gray-400`,title:`unpushed commits`,children:[`↑`,d]}),(0,K.jsxs)(`span`,{className:f>0?`text-amber-700`:`text-gray-400`,title:`unpulled commits`,children:[`↓`,f]}),n&&n.uncommitted>0&&(0,K.jsxs)(`span`,{className:`text-red-600`,title:`uncommitted changes in primary`,children:[`! `,n.uncommitted]}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.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,K.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,K.jsx)(`span`,{className:`truncate flex-1 min-w-0 `+(o.ok?`text-emerald-700`:`text-red-600`),title:o.text,children:o.text})]})]})}function CG({onRefreshed:e}){let[t,n]=(0,_.useState)(0),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(null),s=(0,_.useRef)(e);s.current=e;let c=(0,_.useCallback)(async()=>{i(!0),o(null);let e=await Nm();i(!1),e.ok?(n(0),s.current()):e.diverged?o(`你有未保存的编辑,先保存再刷新`):o(e.error??`refresh failed`)},[]);return(0,_.useEffect)(()=>{c()},[c]),(0,_.useEffect)(()=>{let e=()=>Mm().then(n).catch(()=>{});e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]),(0,K.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 flex flex-col gap-1.5 text-[11px]`,children:[t>0?(0,K.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,K.jsxs)(`span`,{children:[`远端已更新 `,t,` 个改动`]}),(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-gray-400`,children:[(0,K.jsx)(`span`,{children:`已是最新`}),(0,K.jsx)(`button`,{type:`button`,onClick:c,disabled:r,className:`text-gray-500 hover:text-gray-900 underline disabled:opacity-50`,children:r?`刷新中…`:`刷新`})]}),a&&(0,K.jsx)(`div`,{className:`text-amber-700`,children:a})]})}function wG({vault:e,initialFile:t,initialEditing:n}){let[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(t??null),[l,u]=_i();(0,_.useEffect)(()=>{(l.get(`file`)??null)!==s&&u(s?{file:s}:{},{replace:!0})},[s,l,u]);let[d,f]=(0,_.useState)(0),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(``),w=lU(),T=(0,_.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,_.useEffect)(()=>{Dm(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})}),Om(e).then(o),g(``)},[e,d]),(0,_.useEffect)(()=>{let t=!1,n=()=>{t||f(e=>e+1)};return e===`knowledge`?Wm(`knowledge`).then(e=>{e.ok&&(e.message??``).toLowerCase()!==`already up to date`&&n()}):e===`notes`?Mm().then(e=>{e>0&&Nm().then(e=>{e.ok&&n()})}):e===`personal`&&$p().then(e=>{e.ok&&(e.files?.length??0)>0&&n()}),()=>{t=!0}},[e]);let E=async t=>{let n=await Pm(e,t);n.ok?(m(!1),f(e=>e+1),c(t)):alert(`failed: ${n.error}`)},D=async()=>{if(!b||!S.trim()){x(null);return}let t=b.path+`/`+S.trim();if(b.type===`file`){let n=await Pm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}else{let n=await Fm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}x(null),C(``),f(e=>e+1)},O=(0,_.useCallback)((t,n)=>{if(t===`view`)c(n.path);else if(t===`new-file`||t===`new-folder`)x({type:t===`new-file`?`file`:`folder`,path:n.path}),C(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Im(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,_.useCallback)(t=>EG(e,t.path)?[]:t.type===`dir`?[{label:`New file`,icon:(0,K.jsx)(se,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,K.jsx)(pe,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,K.jsx)(tt,{size:12}),action:`delete`,danger:!0}]:DG(e,t.path)?[]:[{label:`View`,icon:(0,K.jsx)(ie,{size:12}),action:`view`},{label:`Delete`,icon:(0,K.jsx)(tt,{size:12}),action:`delete`,danger:!0}],[e]),A=(0,_.useCallback)(t=>Dm(e,t).then(e=>e),[e]),j=(0,_.useCallback)((t,n,r,i)=>{if(t.type===`dir`)return EG(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=DG(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,K.jsxs)(`aside`,{className:`w-64 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`px-3 h-9 flex items-center gap-1 border-b border-gray-200`,children:[w&&(0,K.jsx)(`button`,{onClick:()=>y(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,K.jsx)(Pe,{size:14})}),(0,K.jsx)(TG,{}),(0,K.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,K.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,K.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,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:N?P.length===0?(0,K.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`no matches`}):P.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{c(e.path),w&&y(!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,K.jsx)(`span`,{className:`text-gray-500`,children:`📄`}),(0,K.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[13px] text-gray-900`,children:e.path})]},e.path)):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(IW,{treeId:`vault-${e}`,entries:r,onPick:e=>{c(e),w&&y(!1)},picked:s,onLoadChildren:A,getContextActions:k,onAction:O,nodeClassName:j,reloadKey:d}),r.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`empty · click + 创建第一个文件`})]})}),(0,K.jsx)(`div`,{className:`px-3 h-9 border-t border-gray-200 flex items-center text-[11px] text-gray-500`,children:xG[e]}),e===`knowledge`&&(0,K.jsx)(SG,{resource:e}),e===`notes`&&(0,K.jsx)(CG,{onRefreshed:()=>f(e=>e+1)})]});return(0,K.jsxs)(`div`,{className:`flex h-full w-full`,children:[w?(0,K.jsx)(K.Fragment,{children:v?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>y(!1),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-64 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:F})]}):(0,K.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>y(!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,K.jsx)(Fe,{size:16})})})}):F,(0,K.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white min-h-0`,children:s?(0,K.jsx)(AG,{vault:e,path:s,onSelect:c,onSaved:()=>f(e=>e+1),initialEditing:n}):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-[13px] text-gray-400 italic`,children:`选一个文件,或点 + 新建`})}),p&&(0,K.jsx)(jG,{vault:e,onClose:()=>m(!1),onCreate:E}),b&&(0,K.jsx)(OG,{type:b.type,parentPath:b.path,value:S,onChange:C,onSubmit:D,onCancel:()=>x(null)})]})}function TG(){return(0,K.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,className:`text-gray-400 shrink-0`,children:(0,K.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 EG(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).length>0}function DG(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).includes(`/`)}function OG({type:e,parentPath:t,value:n,onChange:r,onSubmit:i,onCancel:a}){return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:a,children:(0,K.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,K.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[e===`file`?`New file`:`New folder`,` in `,(0,K.jsx)(`span`,{className:`font-mono text-[13px]`,children:t||`root`})]}),(0,K.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,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,K.jsx)(`button`,{onClick:a,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,K.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 kG(e){return/(^|\/)secrets\//.test(e)||e===`secrets`}function AG({vault:e,path:t,onSelect:n,onSaved:r,initialEditing:i}){let a=Cg(),o=zn(),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(i??!1),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)([]),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(!1),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(!1),O=lU(),k=(0,_.useRef)(i);(0,_.useEffect)(()=>{k.current?k.current=!1:f(!1),C(!1),y(null),T(!1),D(!1),km(e,t).then(e=>{let t=e?.content??``;c(t),u(t),D(!!e?.secret)}),Lm(e,t).then(g)},[e,t]);let A=kG(t)||E,j=t.endsWith(`.md`),M=e!==`knowledge`,N=!A,P=e===`notes`&&!A,F=A?l.length>0:l!==s,I=(0,_.useCallback)(async()=>{if(!(!F||p)){m(!0);try{let n=await Am(e,t,l);if(n.ok){if(A?(c(``),u(``)):c(l),y(n.commit??null),f(!1),r(),Lm(e,t).then(g),e===`notes`){let e=await jm();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 em();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&&C(!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,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`header`,{className:`px-3 md:px-5 h-10 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-gray-500 shrink-0`,children:A?`🔒`:`📄`}),(0,K.jsx)(`span`,{className:`font-mono text-[12px] text-gray-500 truncate`,children:t}),v&&!F&&!d&&(0,K.jsxs)(`span`,{className:`hidden md:inline text-[10px] text-emerald-700 font-mono`,children:[`commit `,v]})]}),(0,K.jsx)(`div`,{className:`flex items-center gap-1 md:gap-2 text-xs text-gray-500`,children:d?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:R,className:`px-2.5 h-7 rounded text-xs text-gray-600 hover:bg-gray-100`,children:`cancel`}),(0,K.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,K.jsxs)(K.Fragment,{children:[P&&(0,K.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,K.jsx)(`span`,{children:`↑`}),(0,K.jsx)(`span`,{children:`distill`})]}),N&&(0,K.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,K.jsx)(`span`,{children:`↻`}),(0,K.jsx)(`span`,{children:`edit by loop`})]}),M&&(0,K.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,K.jsxs)(`button`,{onClick:()=>x(e=>!e),className:`px-2.5 h-7 rounded text-xs border ${b?`bg-gray-900 text-white`:`border-gray-200 hover:bg-gray-100 text-gray-900`}`,title:`toggle backlinks`,children:[`⇄ `,h.length]})]})})]}),d?A?(0,K.jsxs)(`div`,{className:w?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{className:`text-amber-700`,children:`🔒`}),(0,K.jsx)(`span`,{children:`new value · saved encrypted`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>T(!w),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:w?`restore`:`maximize`,children:w?(0,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,K.jsx)(hG,{path:t,value:l,onChange:u})})})]}):j&&!S?(0,K.jsxs)(`div`,{className:w?`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,K.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 border-r border-gray-200 flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{children:`source · markdown`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>C(!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,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>T(!w),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:w?`restore`:`maximize`,children:w?(0,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,K.jsx)(hG,{path:t,value:l,onChange:u})})})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 min-h-0 flex flex-col`,children:[(0,K.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,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto px-6 py-4`,children:(0,K.jsx)(`div`,{className:`max-w-[760px]`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading preview...`}),children:(0,K.jsx)(gG,{text:l,onWikilink:V})})})})]})]}):j?(0,K.jsxs)(`div`,{className:w?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,K.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,K.jsx)(`span`,{children:`wysiwyg · milkdown`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>C(!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,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>T(!w),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:w?`restore`:`maximize`,children:w?(0,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,K.jsx)(_G,{value:l,onChange:u})})})]}):(0,K.jsxs)(`div`,{className:w?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,K.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,K.jsxs)(`span`,{children:[`source · `,t.includes(`.`)?t.split(`.`).pop():`text`]}),t.endsWith(`.json`)&&(0,K.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,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>T(!w),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:w?`restore`:`maximize`,children:w?(0,K.jsx)(ke,{size:13}):(0,K.jsx)(Ee,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-400 text-sm`,children:`Loading editor...`}),children:(0,K.jsx)(hG,{path:t,value:l,onChange:u})})})]}):(0,K.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 overflow-hidden`,children:[(0,K.jsx)(`article`,{className:`flex-1 min-h-0 overflow-auto px-4 md:px-8 py-4 md:py-6`,children:(0,K.jsx)(`div`,{className:`max-w-[760px]`,children:A?(0,K.jsxs)(`div`,{className:`font-sans text-[13px] text-gray-600 leading-relaxed`,children:[(0,K.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,K.jsxs)(`div`,{className:`mt-3 text-[12px] text-gray-500`,children:[`Click `,(0,K.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,K.jsx)(_.Suspense,{fallback:(0,K.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading...`}),children:(0,K.jsx)(gG,{text:s,onWikilink:V})}):(0,K.jsx)(`pre`,{className:`font-mono text-[12.5px] leading-relaxed whitespace-pre-wrap text-gray-900`,children:s||(0,K.jsx)(`span`,{className:`text-gray-400 italic`,children:`(empty)`})})})}),j&&!O&&(0,K.jsxs)(`aside`,{className:`w-64 shrink-0 border-l border-gray-200 bg-gray-50 overflow-auto`,children:[(0,K.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,K.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length})]}),h.length===0?(0,K.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,K.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,K.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]}),O&&j&&b&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>x(!1),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.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,K.jsxs)(`div`,{className:`px-3 h-9 flex items-center border-b border-gray-200`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Backlinks`}),(0,K.jsx)(`span`,{className:`ml-auto text-[11px] text-gray-500`,children:h.length}),(0,K.jsx)(`button`,{onClick:()=>x(!1),className:`ml-2 text-gray-400 hover:text-gray-700 px-1`,title:`close backlinks`,children:`✕`})]}),h.length===0?(0,K.jsx)(`div`,{className:`px-3 py-4 text-xs text-gray-500`,children:`No documents link here yet.`}):(0,K.jsx)(`ul`,{className:`py-2`,children:h.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{n(e.path),x(!1)},className:`w-full px-3 py-2 text-left hover:bg-gray-100`,children:[(0,K.jsx)(`div`,{className:`text-xs font-medium text-gray-900 truncate`,children:e.path}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mt-0.5 leading-snug line-clamp-2`,children:e.preview})]})},e.path))})]})]})]})]})}function jG({vault:e,onClose:t,onCreate:n}){let[r,i]=(0,_.useState)(``);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,K.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,K.jsxs)(`div`,{className:`text-base font-semibold text-gray-900 mb-3`,children:[`new file in `,e,`/`]}),(0,K.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,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:`relative path. directories created as needed.`}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-4`,children:[(0,K.jsx)(`button`,{onClick:t,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100`,children:`cancel`}),(0,K.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 MG(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),u=(0,_.useCallback)(async()=>{let e=await Rm();t(e),r(e.notes?.git??``),a(e.repos)},[]);(0,_.useEffect)(()=>{u()},[u]);let d=e!==null&&(n.trim()!==(e.notes?.git??``)||JSON.stringify(i)!==JSON.stringify(e.repos)),f=()=>a(e=>[...e,{name:``,git:``}]),p=(e,t,n)=>a(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r)),m=e=>a(t=>t.filter((t,n)=>n!==e));return e?(0,K.jsx)(`article`,{className:`flex-1 min-w-0 overflow-auto p-5`,children:(0,K.jsxs)(`div`,{className:`max-w-2xl flex flex-col gap-5`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900`,children:`Repo roster`}),(0,K.jsxs)(`p`,{className:`text-[12px] text-gray-500 leading-relaxed mt-1`,children:[`Declared in the knowledge repo's`,` `,(0,K.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. Saving commits + pushes back to the knowledge repo (needs your key to have write access).`]})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`notes remote`}),(0,K.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),placeholder:`git@…/notes.git`,className:`px-2 py-1.5 text-sm font-mono border border-gray-300 rounded outline-none focus:border-gray-500`})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`repos`}),i.length===0&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:`No repos yet.`}),i.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{value:e.name,onChange:e=>p(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,K.jsx)(`input`,{value:e.git,onChange:e=>p(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,K.jsx)(`button`,{type:`button`,onClick:()=>m(t),className:`px-2 py-1.5 text-gray-400 hover:text-red-600`,title:`remove`,children:`✕`})]},t)),(0,K.jsx)(`button`,{type:`button`,onClick:f,className:`self-start text-[12px] text-gray-600 hover:text-gray-900 border border-gray-200 rounded px-2 py-1`,children:`+ add repo`})]}),c&&(0,K.jsx)(`div`,{className:`text-[12px] rounded px-2 py-1.5 border ${c.ok?`text-emerald-700 bg-emerald-50 border-emerald-200`:`text-red-700 bg-red-50 border-red-200`}`,children:c.text}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{s(!0),l(null);let e=i.map(e=>({name:e.name.trim(),git:e.git.trim()})).filter(e=>e.name&&e.git),t=await zm({notes:n.trim()?{git:n.trim()}:null,repos:e});s(!1),t.ok?(l({ok:!0,text:`Saved + promoted to the knowledge repo.`}),await u()):l({ok:!1,text:(t.savedLocally?`Saved locally but promote failed: `:`Save failed: `)+(t.error??``)})},disabled:!d||o,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:o?`Saving…`:`Save + promote`}),d&&(0,K.jsx)(`span`,{className:`text-[11px] text-amber-600`,children:`unsaved changes`})]})]})}):(0,K.jsx)(`div`,{className:`p-6 text-sm text-gray-400`,children:`loading…`})}function NG(){var e=[...arguments];return(0,_.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var PG=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function FG(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function IG(e){return`nodeType`in e}function LG(e){return e?FG(e)?e:IG(e)?e.ownerDocument?.defaultView??window:window:window}function RG(e){let{Document:t}=LG(e);return e instanceof t}function zG(e){return FG(e)?!1:e instanceof LG(e).HTMLElement}function BG(e){return e instanceof LG(e).SVGElement}function VG(e){return e?FG(e)?e.document:IG(e)?RG(e)?e:zG(e)||BG(e)?e.ownerDocument:document:document:document}var HG=PG?_.useLayoutEffect:_.useEffect;function UG(e){let t=(0,_.useRef)(e);return HG(()=>{t.current=e}),(0,_.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function WG(){let e=(0,_.useRef)(null);return[(0,_.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,_.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function GG(e,t){t===void 0&&(t=[e]);let n=(0,_.useRef)(e);return HG(()=>{n.current!==e&&(n.current=e)},t),n}function KG(e,t){let n=(0,_.useRef)();return(0,_.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function qG(e){let t=UG(e),n=(0,_.useRef)(null);return[n,(0,_.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function JG(e){let t=(0,_.useRef)();return(0,_.useEffect)(()=>{t.current=e},[e]),t.current}var YG={};function XG(e,t){return(0,_.useMemo)(()=>{if(t)return t;let n=YG[e]==null?0:YG[e]+1;return YG[e]=n,e+`-`+n},[e,t])}function ZG(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 QG=ZG(1),$G=ZG(-1);function eK(e){return`clientX`in e&&`clientY`in e}function tK(e){if(!e)return!1;let{KeyboardEvent:t}=LG(e.target);return t&&e instanceof t}function nK(e){if(!e)return!1;let{TouchEvent:t}=LG(e.target);return t&&e instanceof t}function rK(e){if(nK(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 eK(e)?{x:e.clientX,y:e.clientY}:null}var iK=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[iK.Translate.toString(e),iK.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),aK=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function oK(e){return e.matches(aK)?e:e.querySelector(aK)}var sK={display:`none`};function cK(e){let{id:t,value:n}=e;return _.createElement(`div`,{id:t,style:sK},n)}function lK(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return _.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 uK(){let[e,t]=(0,_.useState)(``);return{announce:(0,_.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var dK=(0,_.createContext)(null);function fK(e){let t=(0,_.useContext)(dK);(0,_.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function pK(){let[e]=(0,_.useState)(()=>new Set),t=(0,_.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,_.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var mK={draggable:`
|
|
108
108
|
To pick up a draggable item, press the space bar.
|
|
109
109
|
While dragging, use the arrow keys to move the item.
|
|
110
110
|
Press space again to drop the item in its new position, or press escape to cancel.
|
|
111
|
-
`},mK={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function hK(e){let{announcements:t=mK,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=pK}=e,{announce:a,announcement:o}=lK(),s=YG(`DndLiveRegion`),[c,l]=(0,_.useState)(!1);if((0,_.useEffect)(()=>{l(!0)},[]),dK((0,_.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!c)return null;let u=_.createElement(_.Fragment,null,_.createElement(sK,{id:r,value:i.draggable}),_.createElement(cK,{id:s,announcement:o}));return n?(0,dt.createPortal)(u,n):u}var gK;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(gK||={});function _K(){}function vK(e,t){return(0,_.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function yK(){var e=[...arguments];return(0,_.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var bK=Object.freeze({x:0,y:0});function xK(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function SK(e,t){let n=nK(e);if(!n)return`0 0`;let r={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return r.x+`% `+r.y+`%`}function CK(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function wK(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function TK(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function EK(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}var DK=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=EK(t,t.left,t.top),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=xK(EK(r),i);a.push({id:t,data:{droppableContainer:e,value:n}})}}return a.sort(CK)};function OK(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r<i&&n<a){let n=t.width*t.height,r=e.width*e.height,i=o*s,a=i/(n+r-i);return Number(a.toFixed(4))}return 0}var kK=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=OK(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort(wK)};function AK(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function jK(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:bK}function MK(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var NK=MK(1);function PK(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function FK(e,t,n){let r=PK(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var IK={ignoreTransform:!1};function LK(e,t){t===void 0&&(t=IK);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=IG(e).getComputedStyle(e);t&&(n=FK(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function RK(e){return LK(e,{ignoreTransform:!0})}function zK(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function BK(e,t){return t===void 0&&(t=IG(e).getComputedStyle(e)),t.position===`fixed`}function VK(e,t){t===void 0&&(t=IG(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`?n.test(r):!1})}function HK(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(LG(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!RG(i)||zG(i)||n.includes(i))return n;let a=IG(e).getComputedStyle(i);return i!==e&&VK(i,a)&&n.push(i),BK(i,a)?n:r(i.parentNode)}return e?r(e):n}function UK(e){let[t]=HK(e,1);return t??null}function WK(e){return!NG||!e?null:PG(e)?e:FG(e)?LG(e)||e===BG(e).scrollingElement?window:RG(e)?e:null:null}function GK(e){return PG(e)?e.scrollX:e.scrollLeft}function KK(e){return PG(e)?e.scrollY:e.scrollTop}function qK(e){return{x:GK(e),y:KK(e)}}var JK;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(JK||={});function YK(e){return!NG||!e?!1:e===document.scrollingElement}function XK(e){let t={x:0,y:0},n=YK(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var ZK={x:.2,y:.2};function QK(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=ZK);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=XK(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=JK.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=JK.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=JK.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=JK.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function $K(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function eq(e){return e.reduce((e,t)=>ZG(e,qK(t)),bK)}function tq(e){return e.reduce((e,t)=>e+GK(t),0)}function nq(e){return e.reduce((e,t)=>e+KK(t),0)}function rq(e,t){if(t===void 0&&(t=LK),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);UK(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var iq=[[`x`,[`left`,`right`],tq],[`y`,[`top`,`bottom`],nq]],aq=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=HK(t),r=eq(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of iq)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}},oq=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function sq(e){let{EventTarget:t}=IG(e);return e instanceof t?e:BG(e)}function cq(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t?r>t.y:!1}var lq;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(lq||={});function uq(e){e.preventDefault()}function dq(e){e.stopPropagation()}var fq;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})(fq||={});var pq={start:[fq.Space,fq.Enter],cancel:[fq.Esc],end:[fq.Space,fq.Enter,fq.Tab]},mq=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case fq.Right:return{...n,x:n.x+25};case fq.Left:return{...n,x:n.x-25};case fq.Down:return{...n,y:n.y+25};case fq.Up:return{...n,y:n.y-25}}},hq=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new oq(BG(t)),this.windowListeners=new oq(IG(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(lq.Resize,this.handleCancel),this.windowListeners.add(lq.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(lq.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&rq(n),t(bK)}handleKeyDown(e){if(eK(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=pq,coordinateGetter:a=mq,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:bK;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=QG(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=XK(n),p=$K(n),m={x:Math.min(i===fq.Right?p.right-p.width/2:p.right,Math.max(i===fq.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===fq.Down?p.bottom-p.height/2:p.bottom,Math.max(i===fq.Down?p.top:p.top+p.height/2,u.y))},h=i===fq.Right&&!s||i===fq.Left&&!c,g=i===fq.Down&&!l||i===fq.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===fq.Right&&e<=d.x||i===fq.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}a?r.x=n.scrollLeft-e:r.x=i===fq.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}else if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===fq.Down&&e<=d.y||i===fq.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}a?r.y=n.scrollTop-e:r.y=i===fq.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,ZG(QG(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};hq.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=pq,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function gq(e){return!!(e&&`distance`in e)}function _q(e){return!!(e&&`delay`in e)}var vq=class{constructor(e,t,n){n===void 0&&(n=sq(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=BG(i),this.documentListeners=new oq(this.document),this.listeners=new oq(n),this.windowListeners=new oq(IG(i)),this.initialCoordinates=nK(r)??bK,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(lq.Resize,this.handleCancel),this.windowListeners.add(lq.DragStart,uq),this.windowListeners.add(lq.VisibilityChange,this.handleCancel),this.windowListeners.add(lq.ContextMenu,uq),this.documentListeners.add(lq.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(_q(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(gq(t)){this.handlePending(t);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(lq.Click,dq,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(lq.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=nK(e)??bK,s=QG(n,o);if(!t&&a){if(gq(a)){if(a.tolerance!=null&&cq(s,a.tolerance))return this.handleCancel();if(cq(s,a.distance))return this.handleStart()}if(_q(a)&&cq(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===fq.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},yq={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},bq=class extends vq{constructor(e){let{event:t}=e,n=BG(t.target);super(e,yq,n)}};bq.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var xq={move:{name:`mousemove`},end:{name:`mouseup`}},Sq;(function(e){e[e.RightClick=2]=`RightClick`})(Sq||={});var Cq=class extends vq{constructor(e){super(e,xq,BG(e.event.target))}};Cq.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===Sq.RightClick?!1:(r?.({event:n}),!0)}}];var wq={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},Tq=class extends vq{constructor(e){super(e,wq)}static setup(){return window.addEventListener(wq.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(wq.move.name,e)};function e(){}}};Tq.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var Eq;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(Eq||={});var Dq;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})(Dq||={});function Oq(e){let{acceleration:t,activator:n=Eq.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:o=5,order:s=Dq.TreeOrder,pointerCoordinates:c,scrollableAncestors:l,scrollableAncestorRects:u,delta:d,threshold:f}=e,p=Aq({delta:d,disabled:!a}),[m,h]=UG(),g=(0,_.useRef)({x:0,y:0}),v=(0,_.useRef)({x:0,y:0}),y=(0,_.useMemo)(()=>{switch(n){case Eq.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case Eq.DraggableRect:return i}},[n,i,c]),b=(0,_.useRef)(null),x=(0,_.useCallback)(()=>{let e=b.current;if(!e)return;let t=g.current.x*v.current.x,n=g.current.y*v.current.y;e.scrollBy(t,n)},[]),S=(0,_.useMemo)(()=>s===Dq.TreeOrder?[...l].reverse():l,[s,l]);(0,_.useEffect)(()=>{if(!a||!l.length||!y){h();return}for(let e of S){if(r?.(e)===!1)continue;let n=u[l.indexOf(e)];if(!n)continue;let{direction:i,speed:a}=QK(e,n,y,t,f);for(let e of[`x`,`y`])p[e][i[e]]||(a[e]=0,i[e]=0);if(a.x>0||a.y>0){h(),b.current=e,m(x,o),g.current=a,v.current=i;return}}g.current={x:0,y:0},v.current={x:0,y:0},h()},[t,x,r,h,a,o,JSON.stringify(y),JSON.stringify(p),m,l,S,u,JSON.stringify(f)])}var kq={x:{[JK.Backward]:!1,[JK.Forward]:!1},y:{[JK.Backward]:!1,[JK.Forward]:!1}};function Aq(e){let{delta:t,disabled:n}=e,r=qG(t);return GG(e=>{if(n||!r||!e)return kq;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[JK.Backward]:e.x[JK.Backward]||i.x===-1,[JK.Forward]:e.x[JK.Forward]||i.x===1},y:{[JK.Backward]:e.y[JK.Backward]||i.y===-1,[JK.Forward]:e.y[JK.Forward]||i.y===1}}},[n,t,r])}function jq(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return GG(e=>t==null?null:r??e??null,[r,t])}function Mq(e,t){return(0,_.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var Nq;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(Nq||={});var Pq;(function(e){e.Optimized=`optimized`})(Pq||={});var Fq=new Map;function Iq(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,o]=(0,_.useState)(null),{frequency:s,measure:c,strategy:l}=i,u=(0,_.useRef)(e),d=g(),f=WG(d),p=(0,_.useCallback)(function(e){e===void 0&&(e=[]),!f.current&&o(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[f]),m=(0,_.useRef)(null),h=GG(t=>{if(d&&!n)return Fq;if(!t||t===Fq||u.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new aq(c(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,d,c]);return(0,_.useEffect)(()=>{u.current=e},[e]),(0,_.useEffect)(()=>{d||p()},[n,d]),(0,_.useEffect)(()=>{a&&a.length>0&&o(null)},[JSON.stringify(a)]),(0,_.useEffect)(()=>{d||typeof s!=`number`||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},s))},[s,d,p,...r]),{droppableRects:h,measureDroppableContainers:p,measuringScheduled:a!=null};function g(){switch(l){case Nq.Always:return!1;case Nq.BeforeDragging:return n;default:return!n}}}function Lq(e,t){return GG(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function Rq(e,t){return Lq(e,t)}function zq(e){let{callback:t,disabled:n}=e,r=HG(t),i=(0,_.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,_.useEffect)(()=>()=>i?.disconnect(),[i]),i}function Bq(e){let{callback:t,disabled:n}=e,r=HG(t),i=(0,_.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,_.useEffect)(()=>()=>i?.disconnect(),[i]),i}function Vq(e){return new aq(LK(e),e)}function Hq(e,t,n){t===void 0&&(t=Vq);let[r,i]=(0,_.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let o=zq({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),s=Bq({callback:a});return VG(()=>{a(),e?(s?.observe(e),o?.observe(document.body,{childList:!0,subtree:!0})):(s?.disconnect(),o?.disconnect())},[e]),r}function Uq(e){return jK(e,Lq(e))}var Wq=[];function Gq(e){let t=(0,_.useRef)(e),n=GG(n=>e?n&&n!==Wq&&e&&t.current&&e.parentNode===t.current.parentNode?n:HK(e):Wq,[e]);return(0,_.useEffect)(()=>{t.current=e},[e]),n}function Kq(e){let[t,n]=(0,_.useState)(null),r=(0,_.useRef)(e),i=(0,_.useCallback)(e=>{let t=WK(e.target);t&&n(e=>e?(e.set(t,qK(t)),new Map(e)):null)},[]);return(0,_.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=WK(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,qK(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{WK(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,_.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>ZG(e,t),bK):eq(e):bK,[e,t])}function qq(e,t){t===void 0&&(t=[]);let n=(0,_.useRef)(null);return(0,_.useEffect)(()=>{n.current=null},t),(0,_.useEffect)(()=>{let t=e!==bK;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?QG(e,n.current):bK}function Jq(e){(0,_.useEffect)(()=>{if(!NG)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function Yq(e,t){return(0,_.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function Xq(e){return(0,_.useMemo)(()=>e?zK(e):null,[e])}var Zq=[];function Qq(e,t){t===void 0&&(t=LK);let[n]=e,r=Xq(n?IG(n):null),[i,a]=(0,_.useState)(Zq);function o(){a(()=>e.length?e.map(e=>YK(e)?r:new aq(t(e),e)):Zq)}let s=Bq({callback:o});return VG(()=>{s?.disconnect(),o(),e.forEach(e=>s?.observe(e))},[e]),i}function $q(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return RG(t)?t:e}function eJ(e){let{measure:t}=e,[n,r]=(0,_.useState)(null),i=Bq({callback:(0,_.useCallback)(e=>{for(let{target:n}of e)if(RG(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,o]=KG((0,_.useCallback)(e=>{let n=$q(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,_.useMemo)(()=>({nodeRef:a,rect:n,setRef:o}),[n,a,o])}var tJ=[{sensor:bq,options:{}},{sensor:hq,options:{}}],nJ={current:{}},rJ={draggable:{measure:RK},droppable:{measure:RK,strategy:Nq.WhileDragging,frequency:Pq.Optimized},dragOverlay:{measure:LK}},iJ=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},aJ={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new iJ,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:_K},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:rJ,measureDroppableContainers:_K,windowRect:null,measuringScheduled:!1},oJ={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:_K,draggableNodes:new Map,over:null,measureDroppableContainers:_K},sJ=(0,_.createContext)(oJ),cJ=(0,_.createContext)(aJ);function lJ(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new iJ}}}function uJ(e,t){switch(t.type){case gK.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case gK.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case gK.DragEnd:case gK.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case gK.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new iJ(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case gK.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new iJ(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case gK.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new iJ(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function dJ(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,_.useContext)(sJ),a=qG(r),o=qG(n?.id);return(0,_.useEffect)(()=>{if(!t&&!r&&a&&o!=null){if(!eK(a)||document.activeElement===a.target)return;let e=i.get(o);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=aK(e);if(t){t.focus();break}}})}},[r,t,i,o,a]),null}function fJ(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function pJ(e){return(0,_.useMemo)(()=>({draggable:{...rJ.draggable,...e?.draggable},droppable:{...rJ.droppable,...e?.droppable},dragOverlay:{...rJ.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function mJ(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,_.useRef)(!1),{x:o,y:s}=typeof i==`boolean`?{x:i,y:i}:i;VG(()=>{if(!o&&!s||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=jK(n(e),r);if(o||(i.x=0),s||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=UK(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,o,s,r,n])}var hJ=(0,_.createContext)({...bK,scaleX:1,scaleY:1}),gJ;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(gJ||={});var _J=(0,_.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=tJ,collisionDetection:o=kK,measuring:s,modifiers:c,...l}=e,[u,d]=(0,_.useReducer)(uJ,void 0,lJ),[f,p]=fK(),[m,h]=(0,_.useState)(gJ.Uninitialized),g=m===gJ.Initialized,{draggable:{active:v,nodes:y,translate:b},droppable:{containers:x}}=u,S=v==null?null:y.get(v),C=(0,_.useRef)({initial:null,translated:null}),w=(0,_.useMemo)(()=>v==null?null:{id:v,data:S?.data??nJ,rect:C},[v,S]),T=(0,_.useRef)(null),[E,D]=(0,_.useState)(null),[O,k]=(0,_.useState)(null),A=WG(l,Object.values(l)),j=YG(`DndDescribedBy`,t),M=(0,_.useMemo)(()=>x.getEnabled(),[x]),N=pJ(s),{droppableRects:P,measureDroppableContainers:F,measuringScheduled:I}=Iq(M,{dragging:g,dependencies:[b.x,b.y],config:N.droppable}),L=jq(y,v),R=(0,_.useMemo)(()=>O?nK(O):null,[O]),z=we(),B=Rq(L,N.draggable.measure);mJ({activeNode:v==null?null:y.get(v),config:z.layoutShiftCompensation,initialRect:B,measure:N.draggable.measure});let V=Hq(L,N.draggable.measure,B),H=Hq(L?L.parentElement:null),U=(0,_.useRef)({activatorEvent:null,active:null,activeNode:L,collisionRect:null,collisions:null,droppableRects:P,draggableNodes:y,draggingNode:null,draggingNodeRect:null,droppableContainers:x,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ee=x.getNodeFor(U.current.over?.id),W=eJ({measure:N.dragOverlay.measure}),te=W.nodeRef.current??L,ne=g?W.rect??V:null,G=!!(W.nodeRef.current&&W.rect),re=Uq(G?null:V),ie=Xq(te?IG(te):null),ae=Gq(g?ee??L:null),oe=Qq(ae),se=fJ(c,{transform:{x:b.x-re.x,y:b.y-re.y,scaleX:1,scaleY:1},activatorEvent:O,active:w,activeNodeRect:V,containerNodeRect:H,draggingNodeRect:ne,over:U.current.over,overlayNodeRect:W.rect,scrollableAncestors:ae,scrollableAncestorRects:oe,windowRect:ie}),ce=R?ZG(R,b):null,le=Kq(ae),ue=qq(le),de=qq(le,[V]),fe=ZG(se,ue),pe=ne?NK(ne,se):null,me=w&&pe?o({active:w,collisionRect:pe,droppableRects:P,droppableContainers:M,pointerCoordinates:ce}):null,he=TK(me,`id`),[ge,_e]=(0,_.useState)(null),ve=AK(G?se:ZG(se,de),ge?.rect??null,V),ye=(0,_.useRef)(null),be=(0,_.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(T.current==null)return;let i=y.get(T.current);if(!i)return;let a=e.nativeEvent;ye.current=new n({active:T.current,activeNode:i,event:a,options:r,context:U,onAbort(e){if(!y.get(e))return;let{onDragAbort:t}=A.current,n={id:e};t?.(n),f({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!y.get(e))return;let{onDragPending:i}=A.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),f({type:`onDragPending`,event:a})},onStart(e){let t=T.current;if(t==null)return;let n=y.get(t);if(!n)return;let{onDragStart:r}=A.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:C}};(0,dt.unstable_batchedUpdates)(()=>{r?.(i),h(gJ.Initializing),d({type:gK.DragStart,initialCoordinates:e,active:t}),f({type:`onDragStart`,event:i}),D(ye.current),k(a)})},onMove(e){d({type:gK.DragMove,coordinates:e})},onEnd:o(gK.DragEnd),onCancel:o(gK.DragCancel)});function o(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=U.current,o=null;if(t&&i){let{cancelDrop:s}=A.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===gK.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=gK.DragCancel)}T.current=null,(0,dt.unstable_batchedUpdates)(()=>{d({type:e}),h(gJ.Uninitialized),_e(null),D(null),k(null),ye.current=null;let t=e===gK.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=A.current[t];e?.(o),f({type:t,event:o})}})}}},[y]),xe=Mq(a,(0,_.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=y.get(r);if(T.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},T.current=r,be(n,t))},[y,be]));Jq(a),VG(()=>{V&&m===gJ.Initializing&&h(gJ.Initialized)},[V,m]),(0,_.useEffect)(()=>{let{onDragMove:e}=A.current,{active:t,activatorEvent:n,collisions:r,over:i}=U.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:fe.x,y:fe.y},over:i};(0,dt.unstable_batchedUpdates)(()=>{e?.(a),f({type:`onDragMove`,event:a})})},[fe.x,fe.y]),(0,_.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=U.current;if(!e||T.current==null||!t||!i)return;let{onDragOver:a}=A.current,o=r.get(he),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,dt.unstable_batchedUpdates)(()=>{_e(s),a?.(c),f({type:`onDragOver`,event:c})})},[he]),VG(()=>{U.current={activatorEvent:O,active:w,activeNode:L,collisionRect:pe,collisions:me,droppableRects:P,draggableNodes:y,draggingNode:te,draggingNodeRect:ne,droppableContainers:x,over:ge,scrollableAncestors:ae,scrollAdjustedTranslate:fe},C.current={initial:ne,translated:pe}},[w,L,me,pe,y,te,ne,P,x,ge,ae,fe]),Oq({...z,delta:b,draggingRect:pe,pointerCoordinates:ce,scrollableAncestors:ae,scrollableAncestorRects:oe});let Se=(0,_.useMemo)(()=>({active:w,activeNode:L,activeNodeRect:V,activatorEvent:O,collisions:me,containerNodeRect:H,dragOverlay:W,draggableNodes:y,droppableContainers:x,droppableRects:P,over:ge,measureDroppableContainers:F,scrollableAncestors:ae,scrollableAncestorRects:oe,measuringConfiguration:N,measuringScheduled:I,windowRect:ie}),[w,L,V,O,me,H,W,y,x,P,ge,F,ae,oe,N,I,ie]),Ce=(0,_.useMemo)(()=>({activatorEvent:O,activators:xe,active:w,activeNodeRect:V,ariaDescribedById:{draggable:j},dispatch:d,draggableNodes:y,over:ge,measureDroppableContainers:F}),[O,xe,w,V,d,j,y,ge,F]);return _.createElement(uK.Provider,{value:p},_.createElement(sJ.Provider,{value:Ce},_.createElement(cJ.Provider,{value:Se},_.createElement(hJ.Provider,{value:ve},i)),_.createElement(dJ,{disabled:n?.restoreFocus===!1})),_.createElement(hK,{...n,hiddenTextDescribedById:j}));function we(){let e=E?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=g&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),vJ=(0,_.createContext)(null),yJ=`button`,bJ=`Draggable`;function xJ(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=YG(bJ),{activators:o,activatorEvent:s,active:c,activeNodeRect:l,ariaDescribedById:u,draggableNodes:d,over:f}=(0,_.useContext)(sJ),{role:p=yJ,roleDescription:m=`draggable`,tabIndex:h=0}=i??{},g=c?.id===t,v=(0,_.useContext)(g?hJ:vJ),[y,b]=KG(),[x,S]=KG(),C=Yq(o,t),w=WG(n);return VG(()=>(d.set(t,{id:t,key:a,node:y,activatorNode:x,data:w}),()=>{let e=d.get(t);e&&e.key===a&&d.delete(t)}),[d,t]),{active:c,activatorEvent:s,activeNodeRect:l,attributes:(0,_.useMemo)(()=>({role:p,tabIndex:h,"aria-disabled":r,"aria-pressed":g&&p===yJ?!0:void 0,"aria-roledescription":m,"aria-describedby":u.draggable}),[r,p,h,g,m,u.draggable]),isDragging:g,listeners:r?void 0:C,node:y,over:f,setNodeRef:b,setActivatorNodeRef:S,transform:v}}function SJ(){return(0,_.useContext)(cJ)}var CJ=`Droppable`,wJ={timeout:25};function TJ(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=YG(CJ),{active:o,dispatch:s,over:c,measureDroppableContainers:l}=(0,_.useContext)(sJ),u=(0,_.useRef)({disabled:n}),d=(0,_.useRef)(!1),f=(0,_.useRef)(null),p=(0,_.useRef)(null),{disabled:m,updateMeasurementsFor:h,timeout:g}={...wJ,...i},v=WG(h??r),y=Bq({callback:(0,_.useCallback)(()=>{if(!d.current){d.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{l(Array.isArray(v.current)?v.current:[v.current]),p.current=null},g)},[g]),disabled:m||!o}),[b,x]=KG((0,_.useCallback)((e,t)=>{y&&(t&&(y.unobserve(t),d.current=!1),e&&y.observe(e))},[y])),S=WG(t);return(0,_.useEffect)(()=>{!y||!b.current||(y.disconnect(),d.current=!1,y.observe(b.current))},[b,y]),(0,_.useEffect)(()=>(s({type:gK.RegisterDroppable,element:{id:r,key:a,disabled:n,node:b,rect:f,data:S}}),()=>s({type:gK.UnregisterDroppable,key:a,id:r})),[r]),(0,_.useEffect)(()=>{n!==u.current.disabled&&(s({type:gK.SetDroppableDisabled,id:r,key:a,disabled:n}),u.current.disabled=n)},[r,a,n,s]),{active:o,rect:f,isOver:c?.id===r,node:b,over:c,setNodeRef:x}}function EJ(e){let{animation:t,children:n}=e,[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null),s=qG(n);return!n&&!r&&s&&i(s),VG(()=>{if(!a)return;let e=r?.key,n=r?.props.id;if(e==null||n==null){i(null);return}Promise.resolve(t(n,a)).then(()=>{i(null)})},[t,r,a]),_.createElement(_.Fragment,null,n,r?(0,_.cloneElement)(r,{ref:o}):null)}var DJ={x:0,y:0,scaleX:1,scaleY:1};function OJ(e){let{children:t}=e;return _.createElement(sJ.Provider,{value:oJ},_.createElement(hJ.Provider,{value:DJ},t))}var kJ={position:`fixed`,touchAction:`none`},AJ=e=>eK(e)?`transform 250ms ease`:void 0,jJ=(0,_.forwardRef)((e,t)=>{let{as:n,activatorEvent:r,adjustScale:i,children:a,className:o,rect:s,style:c,transform:l,transition:u=AJ}=e;if(!s)return null;let d=i?l:{...l,scaleX:1,scaleY:1},f={...kJ,width:s.width,height:s.height,top:s.top,left:s.left,transform:rK.Transform.toString(d),transformOrigin:i&&r?SK(r,s):void 0,transition:typeof u==`function`?u(r):u,...c};return _.createElement(n,{className:o,style:f,ref:t},a)}),MJ={duration:250,easing:`ease`,keyframes:e=>{let{transform:{initial:t,final:n}}=e;return[{transform:rK.Transform.toString(t)},{transform:rK.Transform.toString(n)}]},sideEffects:(e=>t=>{let{active:n,dragOverlay:r}=t,i={},{styles:a,className:o}=e;if(a!=null&&a.active)for(let[e,t]of Object.entries(a.active))t!==void 0&&(i[e]=n.node.style.getPropertyValue(e),n.node.style.setProperty(e,t));if(a!=null&&a.dragOverlay)for(let[e,t]of Object.entries(a.dragOverlay))t!==void 0&&r.node.style.setProperty(e,t);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&r.node.classList.add(o.dragOverlay),function(){for(let[e,t]of Object.entries(i))n.node.style.setProperty(e,t);o!=null&&o.active&&n.node.classList.remove(o.active)}})({styles:{active:{opacity:`0`}}})};function NJ(e){let{config:t,draggableNodes:n,droppableContainers:r,measuringConfiguration:i}=e;return HG((e,a)=>{if(t===null)return;let o=n.get(e);if(!o)return;let s=o.node.current;if(!s)return;let c=$q(a);if(!c)return;let{transform:l}=IG(a).getComputedStyle(a),u=PK(l);if(!u)return;let d=typeof t==`function`?t:PJ(t);return rq(s,i.draggable.measure),d({active:{id:e,data:o.data,node:s,rect:i.draggable.measure(s)},draggableNodes:n,dragOverlay:{node:a,rect:i.dragOverlay.measure(c)},droppableContainers:r,measuringConfiguration:i,transform:u})})}function PJ(e){let{duration:t,easing:n,sideEffects:r,keyframes:i}={...MJ,...e};return e=>{let{active:a,dragOverlay:o,transform:s,...c}=e;if(!t)return;let l={x:o.rect.left-a.rect.left,y:o.rect.top-a.rect.top},u={scaleX:s.scaleX===1?1:a.rect.width*s.scaleX/o.rect.width,scaleY:s.scaleY===1?1:a.rect.height*s.scaleY/o.rect.height},d={x:s.x-l.x,y:s.y-l.y,...u},f=i({...c,active:a,dragOverlay:o,transform:{initial:s,final:d}}),[p]=f,m=f[f.length-1];if(JSON.stringify(p)===JSON.stringify(m))return;let h=r?.({active:a,dragOverlay:o,...c}),g=o.node.animate(f,{duration:t,easing:n,fill:`forwards`});return new Promise(e=>{g.onfinish=()=>{h?.(),e()}})}}var FJ=0;function IJ(e){return(0,_.useMemo)(()=>{if(e!=null)return FJ++,FJ},[e])}var LJ=_.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:r,style:i,transition:a,modifiers:o,wrapperElement:s=`div`,className:c,zIndex:l=999}=e,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggableNodes:m,droppableContainers:h,dragOverlay:g,over:v,measuringConfiguration:y,scrollableAncestors:b,scrollableAncestorRects:x,windowRect:S}=SJ(),C=(0,_.useContext)(hJ),w=IJ(d?.id),T=fJ(o,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggingNodeRect:g.rect,over:v,overlayNodeRect:g.rect,scrollableAncestors:b,scrollableAncestorRects:x,transform:C,windowRect:S}),E=Lq(f),D=NJ({config:r,draggableNodes:m,droppableContainers:h,measuringConfiguration:y}),O=E?g.setRef:void 0;return _.createElement(OJ,null,_.createElement(EJ,{animation:D},d&&w?_.createElement(jJ,{key:w,id:d.id,ref:O,as:s,activatorEvent:u,adjustScale:t,className:c,transition:a,rect:E,style:{zIndex:l,...i},transform:T},n):null))});function RJ(e,t,n){let r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function zJ(e,t){return e.reduce((e,n,r)=>{let i=t.get(n);return i&&(e[r]=i),e},Array(e.length))}function BJ(e){return e!==null&&e>=0}function VJ(e,t){if(e===t)return!0;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 HJ(e){return typeof e==`boolean`?{draggable:e,droppable:e}:e}var UJ={scaleX:1,scaleY:1},WJ=e=>{let{rects:t,activeNodeRect:n,activeIndex:r,overIndex:i,index:a}=e,o=t[r]??n;if(!o)return null;let s=GJ(t,a,r);if(a===r){let e=t[i];return e?{x:r<i?e.left+e.width-(o.left+o.width):e.left-o.left,y:0,...UJ}:null}return a>r&&a<=i?{x:-o.width-s,y:0,...UJ}:a<r&&a>=i?{x:o.width+s,y:0,...UJ}:{x:0,y:0,...UJ}};function GJ(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return!r||!i&&!a?0:n<t?i?r.left-(i.left+i.width):a.left-(r.left+r.width):a?a.left-(r.left+r.width):r.left-(i.left+i.width)}var KJ=e=>{let{rects:t,activeIndex:n,overIndex:r,index:i}=e,a=RJ(t,r,n),o=t[i],s=a[i];return!s||!o?null:{x:s.left-o.left,y:s.top-o.top,scaleX:s.width/o.width,scaleY:s.height/o.height}},qJ={scaleX:1,scaleY:1},JJ=e=>{let{activeIndex:t,activeNodeRect:n,index:r,rects:i,overIndex:a}=e,o=i[t]??n;if(!o)return null;if(r===t){let e=i[a];return e?{x:0,y:t<a?e.top+e.height-(o.top+o.height):e.top-o.top,...qJ}:null}let s=YJ(i,r,t);return r>t&&r<=a?{x:0,y:-o.height-s,...qJ}:r<t&&r>=a?{x:0,y:o.height+s,...qJ}:{x:0,y:0,...qJ}};function YJ(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return r?n<t?i?r.top-(i.top+i.height):a?a.top-(r.top+r.height):0:a?a.top-(r.top+r.height):i?r.top-(i.top+i.height):0:0}var XJ=`Sortable`,ZJ=_.createContext({activeIndex:-1,containerId:XJ,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:KJ,disabled:{draggable:!1,droppable:!1}});function QJ(e){let{children:t,id:n,items:r,strategy:i=KJ,disabled:a=!1}=e,{active:o,dragOverlay:s,droppableRects:c,over:l,measureDroppableContainers:u}=SJ(),d=YG(XJ,n),f=s.rect!==null,p=(0,_.useMemo)(()=>r.map(e=>typeof e==`object`&&`id`in e?e.id:e),[r]),m=o!=null,h=o?p.indexOf(o.id):-1,g=l?p.indexOf(l.id):-1,v=(0,_.useRef)(p),y=!VJ(p,v.current),b=g!==-1&&h===-1||y,x=HJ(a);VG(()=>{y&&m&&u(p)},[y,p,m,u]),(0,_.useEffect)(()=>{v.current=p},[p]);let S=(0,_.useMemo)(()=>({activeIndex:h,containerId:d,disabled:x,disableTransforms:b,items:p,overIndex:g,useDragOverlay:f,sortedRects:zJ(p,c),strategy:i}),[h,d,x.draggable,x.droppable,b,p,g,c,f,i]);return _.createElement(ZJ.Provider,{value:S},t)}var $J=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return RJ(n,r,i).indexOf(t)},eY=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:a,newIndex:o,previousItems:s,previousContainerId:c,transition:l}=e;return!l||!r||s!==a&&i===o?!1:n?!0:o!==i&&t===c},tY={duration:200,easing:`ease`},nY=`transform`,rY=rK.Transition.toString({property:nY,duration:0,easing:`linear`}),iY={roleDescription:`sortable`};function aY(e){let{disabled:t,index:n,node:r,rect:i}=e,[a,o]=(0,_.useState)(null),s=(0,_.useRef)(n);return VG(()=>{if(!t&&n!==s.current&&r.current){let e=i.current;if(e){let t=LK(r.current,{ignoreTransform:!0}),n={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(n.x||n.y)&&o(n)}}n!==s.current&&(s.current=n)},[t,n,r,i]),(0,_.useEffect)(()=>{a&&o(null)},[a]),a}function oY(e){let{animateLayoutChanges:t=eY,attributes:n,disabled:r,data:i,getNewIndex:a=$J,id:o,strategy:s,resizeObserverConfig:c,transition:l=tY}=e,{items:u,containerId:d,activeIndex:f,disabled:p,disableTransforms:m,sortedRects:h,overIndex:g,useDragOverlay:v,strategy:y}=(0,_.useContext)(ZJ),b=sY(r,p),x=u.indexOf(o),S=(0,_.useMemo)(()=>({sortable:{containerId:d,index:x,items:u},...i}),[d,i,x,u]),C=(0,_.useMemo)(()=>u.slice(u.indexOf(o)),[u,o]),{rect:w,node:T,isOver:E,setNodeRef:D}=TJ({id:o,data:S,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:C,...c}}),{active:O,activatorEvent:k,activeNodeRect:A,attributes:j,setNodeRef:M,listeners:N,isDragging:P,over:F,setActivatorNodeRef:I,transform:L}=xJ({id:o,data:S,attributes:{...iY,...n},disabled:b.draggable}),R=MG(D,M),z=!!O,B=z&&!m&&BJ(f)&&BJ(g),V=!v&&P,H=B?(V&&B?L:null)??(s??y)({rects:h,activeNodeRect:A,activeIndex:f,overIndex:g,index:x}):null,U=BJ(f)&&BJ(g)?a({id:o,items:u,activeIndex:f,overIndex:g}):x,ee=O?.id,W=(0,_.useRef)({activeId:ee,items:u,newIndex:U,containerId:d}),te=u!==W.current.items,ne=t({active:O,containerId:d,isDragging:P,isSorting:z,id:o,index:x,items:u,newIndex:W.current.newIndex,previousItems:W.current.items,previousContainerId:W.current.containerId,transition:l,wasDragging:W.current.activeId!=null}),G=aY({disabled:!ne,index:x,node:T,rect:w});return(0,_.useEffect)(()=>{z&&W.current.newIndex!==U&&(W.current.newIndex=U),d!==W.current.containerId&&(W.current.containerId=d),u!==W.current.items&&(W.current.items=u)},[z,U,d,u]),(0,_.useEffect)(()=>{if(ee===W.current.activeId)return;if(ee!=null&&W.current.activeId==null){W.current.activeId=ee;return}let e=setTimeout(()=>{W.current.activeId=ee},50);return()=>clearTimeout(e)},[ee]),{active:O,activeIndex:f,attributes:j,data:S,rect:w,index:x,newIndex:U,items:u,isOver:E,isSorting:z,isDragging:P,listeners:N,node:T,overIndex:g,over:F,setNodeRef:R,setActivatorNodeRef:I,setDroppableNodeRef:D,setDraggableNodeRef:M,transform:G??H,transition:re()};function re(){if(G||te&&W.current.newIndex===x)return rY;if(!(V&&!eK(k)||!l)&&(z||ne))return rK.Transition.toString({...l,property:nY})}}function sY(e,t){return typeof e==`boolean`?{draggable:e,droppable:!1}:{draggable:e?.draggable??t.draggable,droppable:e?.droppable??t.droppable}}fq.Down,fq.Right,fq.Up,fq.Left;function cY({text:e}){return(0,K.jsx)(sI,{remarkPlugins:[_z],components:{p:({children:e})=>(0,K.jsx)(K.Fragment,{children:e}),strong:({children:e})=>(0,K.jsx)(`strong`,{className:`font-bold`,children:e}),em:({children:e})=>(0,K.jsx)(`em`,{className:`italic`,children:e}),a:({href:e,children:t})=>(0,K.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),className:`text-blue-700 hover:underline`,children:t}),code:({children:e})=>(0,K.jsx)(`code`,{className:`bg-gray-100 text-gray-800 rounded px-1 font-mono text-[11px]`,children:e})},children:e})}function lY(e){return e.assignee?e.assignee.split(/[,;,;]+/).map(e=>e.trim()).filter(Boolean):[]}var uY={P0:`bg-red-50 text-red-700 border-red-200`,P1:`bg-orange-50 text-orange-700 border-orange-200`};function dY({card:e}){let t=e.subtasks.length>0?Math.round(e.subtasks.filter(e=>e.done).length/e.subtasks.length*100):0,n=lY(e);return(0,K.jsxs)(`div`,{className:`text-left rounded-lg border bg-white px-3 py-2.5 w-full shadow-lg ${e.done?`opacity-60`:`border-gray-300`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`span`,{className:`shrink-0 mt-0.5 w-4 h-4 rounded border border-gray-300 flex items-center justify-center text-xs ${e.done?`bg-emerald-50 border-emerald-400`:``}`,children:e.done?`✓`:``}),(0,K.jsx)(`h4`,{className:`text-[13px] font-medium flex-1 min-w-0 ${e.done?`text-gray-400 line-through`:`text-gray-900`}`,children:(0,K.jsx)(cY,{text:e.text})}),e.priority&&(0,K.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded shrink-0 border ${uY[e.priority]??`bg-gray-50 text-gray-600 border-gray-200`}`,children:e.priority.toUpperCase()})]}),(n.length>0||e.due)&&(0,K.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2 text-[10px]`,children:[n.map((e,t)=>(0,K.jsx)(`span`,{className:`w-5 h-5 rounded-full bg-gray-200 text-gray-600 text-[9px] flex items-center justify-center font-medium`,title:e,children:e.slice(0,2).toUpperCase()},t)),e.due&&(0,K.jsx)(`span`,{className:`text-gray-400 ml-auto`,children:e.due})]}),e.topics.length>0&&(0,K.jsx)(`div`,{className:`mt-1.5 flex items-center gap-1 flex-wrap`,children:e.topics.map(e=>(0,K.jsx)(fG,{name:e,onClick:()=>{}},e))}),e.subtasks.length>0&&(0,K.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-1 bg-gray-100 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${t}%`}})}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-gray-500 shrink-0`,children:[e.subtasks.filter(e=>e.done).length,`/`,e.subtasks.length]})]})]})}function fY({board:e,card:t,colFilename:n,onClick:r,onToggle:i,onArchive:a}){let o=zn(),{attributes:s,listeners:c,setNodeRef:l,transform:u,transition:d,isDragging:f}=oY({id:t.cid,data:{card:t,colFilename:n}}),p=u&&(u.x!==0||u.y!==0)?{transform:`translate3d(${u.x}px, ${u.y}px, 0)`,transition:d}:void 0,[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(t.text);async function y(){let r=g.trim();if(!r||r===t.text){h(!1);return}await Ym(e,n,t.cid,{text:r}),h(!1)}let b=t.subtasks.length>0?Math.round(t.subtasks.filter(e=>e.done).length/t.subtasks.length*100):0,x=lY(t);return(0,K.jsxs)(`div`,{className:`relative group/card`,children:[(0,K.jsxs)(`div`,{ref:l,...c,...s,style:p,onClick:m?void 0:r,role:`button`,tabIndex:0,className:`text-left rounded-lg border bg-white px-3 py-2.5 transition-all w-full cursor-grab active:cursor-grabbing
|
|
112
|
-
${f?`opacity-30 shadow-lg`:`border-gray-200 hover:border-gray-400 hover:shadow-sm`} ${t.done?`opacity-60`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`span`,{className:`shrink-0 mt-0.5 w-4 h-4 rounded border border-gray-300 flex items-center justify-center cursor-pointer hover:border-gray-500`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),i()},children:t.done&&(0,K.jsx)(`span`,{className:`text-emerald-600 text-xs`,children:`✓`})}),m?(0,K.jsx)(`input`,{type:`text`,value:g,onChange:e=>v(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),y()),e.key===`Escape`&&(h(!1),v(t.text))},onBlur:y,onPointerDown:e=>e.stopPropagation(),className:`flex-1 min-w-0 text-[13px] font-medium border border-gray-300 rounded px-1 py-0.5 outline-none focus:border-gray-500`}):(0,K.jsx)(`h4`,{className:`text-[13px] font-medium flex-1 min-w-0 cursor-text ${t.done?`text-gray-400 line-through`:`text-gray-900`}`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),v(t.text),h(!0)},children:(0,K.jsx)(cY,{text:t.text})}),t.priority&&(0,K.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded shrink-0 border ${uY[t.priority]??`bg-gray-50 text-gray-600 border-gray-200`}`,children:t.priority.toUpperCase()})]}),(x.length>0||t.due)&&(0,K.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2 text-[10px]`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-0.5`,children:x.map((e,t)=>(0,K.jsx)(`span`,{className:`w-5 h-5 rounded-full bg-gray-200 text-gray-600 text-[9px] flex items-center justify-center font-medium`,title:e,children:e.slice(0,2).toUpperCase()},t))}),t.due&&(0,K.jsx)(`span`,{className:`text-gray-400 ml-auto`,children:t.due})]}),t.topics.length>0&&(0,K.jsx)(`div`,{className:`mt-1.5 flex items-center gap-1 flex-wrap`,onClick:e=>e.stopPropagation(),children:t.topics.map(e=>(0,K.jsx)(fG,{name:e,onClick:()=>o(`/topic/${encodeURIComponent(e)}`),onEdit:r},e))}),t.subtasks.length>0&&(0,K.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-1 bg-gray-100 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full bg-emerald-500 transition-all`,style:{width:`${b}%`}})}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-gray-500 shrink-0`,children:[t.subtasks.filter(e=>e.done).length,`/`,t.subtasks.length]})]}),t.loopId&&(0,K.jsx)(`div`,{className:`mt-1.5`,children:(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-gray-400 bg-gray-100 px-1 py-0.5 rounded`,children:[`L:`,t.loopId.slice(0,6)]})})]}),(0,K.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),r()},className:`absolute top-2 right-2 z-10 w-5 h-5 rounded-full bg-white border border-gray-300 text-[10px] text-gray-400 hover:text-gray-700 hover:border-gray-500 opacity-100 sm:opacity-0 sm:group-hover/card:opacity-100 transition-opacity flex items-center justify-center shadow-sm`,title:`Edit card`,children:`✎`}),t.done&&a&&(0,K.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`absolute top-2 right-9 z-10 w-5 h-5 rounded-full bg-white border border-gray-300 text-[10px] text-gray-400 hover:text-orange-600 hover:border-orange-400 opacity-100 sm:opacity-0 sm:group-hover/card:opacity-100 transition-opacity flex items-center justify-center shadow-sm`,title:`Archive card`,children:`◧`})]})}var pY=[``,`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#3b82f6`,`#8b5cf6`,`#ec4899`];function mY({board:e,column:t,cards:n,onCardClick:r,onCardToggle:i,onCardArchive:a,onCardSaved:o,onColumnSaved:s,color:c}){let{setNodeRef:l,isOver:u}=TJ({id:t.id}),{attributes:d,listeners:f,setNodeRef:p,transform:m,transition:h,isDragging:g}=oY({id:`col:${t.id}`,data:{columnId:t.id}}),v=m&&(m.x!==0||m.y!==0)?{transform:`translate3d(${m.x}px, ${m.y}px, 0)`,transition:h}:void 0,[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(``),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(t.label),[j,M]=(0,_.useState)(c??``),[N,P]=(0,_.useState)(!1);async function F(){let n=x.trim();if(!n||C)return;w(!0);let r=await qm(e,t.id,{text:n});w(!1),r.cid&&(S(``),b(!1),o())}async function I(){let n=k.trim();if(!n||n===t.label){O(!1);return}let r=n.toLowerCase().replace(/[^a-z0-9一-鿿]+/g,`-`).replace(/^-|-$/g,``)+`.md`;await ah(e,t.id,r),O(!1),s()}async function L(n){M(n),await sh(e,t.id,n),s()}async function R(){if(confirm(`Delete column "${t.label}" and all its cards?`)){P(!0);for(let r of n)await Qm(e,t.id,r.cid,`archived.md`);await oh(e,t.id),P(!1),O(!1),s()}}return(0,K.jsxs)(`div`,{ref:e=>{p(e),l(e)},...d,style:v,onMouseEnter:()=>E(!0),onMouseLeave:()=>E(!1),onTouchStart:()=>E(!0),className:`w-64 shrink-0 h-full flex flex-col rounded-lg transition-colors ${u?`bg-gray-100`:`bg-gray-50`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-2 shrink-0 select-none rounded-t-lg ${g?`opacity-30`:``}`,children:[(0,K.jsx)(`span`,{...f,className:`text-gray-400 text-[10px] shrink-0 cursor-grab active:cursor-grabbing hover:text-gray-600`,children:`⋮⋮`}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-gray-500 font-medium flex-1 min-w-0 truncate`,children:t.label}),(0,K.jsx)(`span`,{className:`text-[10px] font-mono text-gray-400 bg-gray-200 px-1.5 py-0.5 rounded-full shrink-0`,children:n.length}),T&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),O(!0),A(t.label),M(c??``)},className:`text-[10px] text-gray-400 hover:text-gray-700`,title:`Edit column`,children:`✎`}),(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),R()},className:`text-[10px] text-gray-400 hover:text-red-500`,title:`Delete column`,children:`×`})]})]}),c&&(0,K.jsx)(`div`,{className:`h-0.5 shrink-0 mx-2 rounded`,style:{backgroundColor:c}}),(0,K.jsxs)(`div`,{ref:l,className:`flex-1 min-h-[100px] overflow-y-auto px-1 pb-1 flex flex-col gap-1.5 ${u?`bg-gray-200/50 rounded-b-lg`:``}`,children:[n.length===0&&!y?(0,K.jsx)(`div`,{className:`text-[11px] text-gray-300 italic px-2 py-4 text-center`,children:`drop here`}):n.map(n=>(0,K.jsx)(fY,{board:e,card:n,colFilename:t.id,onClick:()=>r(n),onToggle:()=>i(n),onArchive:()=>a(n)},n.cid)),y&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-300 bg-white px-2 py-1.5`,children:[(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),F()),e.key===`Escape`&&(b(!1),S(``))},onBlur:()=>{x.trim()||(b(!1),S(``))},className:`w-full text-[13px] border-0 outline-none bg-transparent text-gray-900 placeholder:text-gray-400`,placeholder:`Card title…`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1.5`,children:[(0,K.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:F,disabled:!x.trim()||C,className:`px-2 h-6 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:C?`…`:`Add`}),(0,K.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{b(!1),S(``)},className:`text-gray-400 hover:text-gray-600 text-sm`,children:`✕`})]})]})]}),!y&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(!0),className:`mx-1 mb-1 shrink-0 rounded-lg border border-dashed border-gray-300 hover:border-gray-400 text-[11px] text-gray-400 hover:text-gray-600 py-2 transition-colors`,children:`+ Add card`}),D&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:()=>O(!1),children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-xl border border-gray-200 w-full max-w-xs mx-4`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-gray-100`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-gray-900`,children:`Edit Column`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>O(!1),className:`text-gray-400 hover:text-gray-700`,children:`✕`})]}),(0,K.jsxs)(`div`,{className:`px-4 py-3 space-y-3`,children:[(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:`Title`}),(0,K.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&I()},className:`w-full text-[13px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500`})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:`Color`}),(0,K.jsx)(`div`,{className:`flex gap-1.5`,children:pY.map(e=>(0,K.jsx)(`button`,{onClick:()=>L(e),className:`w-6 h-6 rounded-full border-2 ${j===e?`border-gray-900`:`border-gray-200`} ${e?``:`bg-white`}`,style:e?{backgroundColor:e}:void 0,title:e||`none`},e))})]}),(0,K.jsx)(`button`,{onClick:R,disabled:N,className:`w-full text-[12px] text-red-500 hover:text-red-700 text-left`,children:N?`Deleting…`:`Delete column`})]})]})})]})}function hY(e){let t=(0,_.useRef)(null),[n,r]=(0,_.useState)(!1),i=(0,_.useRef)(e);i.current=e;let a=(0,_.useCallback)(()=>{let e=location.protocol===`https:`?`wss:`:`ws:`,n=new WebSocket(`${e}//${location.host}/ws/kanban`);t.current=n,n.onopen=()=>r(!0),n.onmessage=e=>{try{JSON.parse(e.data).type===`kanban_update`&&i.current()}catch{}},n.onclose=()=>{r(!1),t.current=null,setTimeout(a,2e3+Math.random()*3e3)},n.onerror=()=>{n.close()}},[]);return(0,_.useEffect)(()=>(a(),()=>{t.current?.close(),t.current=null}),[a]),n}var gY=(0,_.forwardRef)(function({board:e,onCardClick:t,onCardArchive:n,showArchived:r},i){let a=yK(vK(bq,{activationConstraint:{distance:5}}),vK(Tq,{activationConstraint:{delay:150,tolerance:5}})),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(!0),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(``),[C,w]=(0,_.useState)(null),T=(0,_.useRef)(!1),E=(0,_.useCallback)(()=>{Promise.all([Km(e),rh(e)]).then(([e,t])=>{let n=[...e].sort((e,n)=>{let r=t.findIndex(t=>t.file===e.filename),i=t.findIndex(e=>e.file===n.filename);return r>=0&&i>=0?r-i:r>=0?-1:i>=0?1:e.title.localeCompare(n.title)});s(n),l(n.map(e=>e.filename)),d(t),p(!1)})},[e]);(0,_.useImperativeHandle)(i,()=>({refresh:E}),[E]),hY(E),(0,_.useEffect)(()=>{E()},[E]);function D(e){for(let t of o){let n=t.cards.findIndex(t=>t.cid===e);if(n>=0)return[t.filename,n]}return null}function O(e){let t=e.active.id;if(t.startsWith(`col:`)){T.current=!0;let e=o.find(e=>e.filename===t.slice(4));e&&v(e)}else{T.current=!1;let t=e.active.data.current?.card;t&&h(t)}}function k(e){if(e.startsWith(`col:`))return e.slice(4);if(P.some(t=>t.filename===e))return e;for(let t of P)if(t.cards.some(t=>t.cid===e))return t.filename;return null}function A(e){if(!T.current){w(null);return}let{active:t,over:n,collisions:r}=e;if(!n){w(null);return}let i=k(n.id);if(!i){w(null);return}let a=P.findIndex(e=>e.filename===i);if(a<0){w(null);return}let o=k(t.id),s=o?P.findIndex(e=>e.filename===o):-1;if(s<0){w(null);return}if(s===a){w(null);return}let c=r?.[0];if(!c){w(null);return}let l=(t.rect.current.translated?t.rect.current.translated.left+(t.rect.current.translated.width??0)/2:0)<(c.data?.droppableRect?c.data.droppableRect.left+c.data.droppableRect.width/2:0)?a:a+1;w(l>=0&&l<=P.length?l:null)}function j(t){h(null),v(null),w(null),T.current=!1;let{active:n,over:r}=t;if(!r)return;let i=n.id;if(i.startsWith(`col:`)){let a=i.slice(4),o=k(r.id);if(!o||a===o)return;let u=c.indexOf(a),d=c.indexOf(o);if(u<0||d<0)return;let f=t.collisions?.[0],p=(n.rect.current.translated?n.rect.current.translated.left+(n.rect.current.translated.width??0)/2:0)<(f?.data?.droppableRect?f.data.droppableRect.left+f.data.droppableRect.width/2:0)?d:d+1,m=Math.max(0,Math.min(p,c.length-1));if(m===u)return;let h=RJ([...c],u,m);l(h),s(e=>{let t=[...e];return t.sort((e,t)=>{let n=h.indexOf(e.filename),r=h.indexOf(t.filename);return n>=0&&r>=0?n-r:n>=0?-1:+(r>=0)}),t}),ih(e,h);return}let a=i,u=D(a);if(!u)return;let[d,f]=u,p=null,m;if(o.some(e=>e.filename===r.id)||r.id.startsWith(`col:`))p=r.id.startsWith(`col:`)?r.id.slice(4):r.id;else{let e=D(r.id);e&&(p=e[0],m=e[1])}if(p){if(s(e=>{let t=e.map(e=>({...e,cards:[...e.cards]})),n=t.find(e=>e.filename===d),r=t.find(e=>e.filename===p),i=n.cards.findIndex(e=>e.cid===a);if(i<0)return t;if(d===p){let e=m??r.cards.length-1;i!==e&&(r.cards=RJ(r.cards,i,e))}else{let[e]=n.cards.splice(i,1);m===void 0?r.cards.push(e):r.cards.splice(m,0,e)}return t}),d!==p)Qm(e,d,a,p,m);else if(d===p&&m!==void 0&&f!==m){let t=o.find(e=>e.filename===d);if(t){let n=[...t.cards],[r]=n.splice(f,1),i=m>f?m-1:m;n.splice(i,0,r),ch(e,d,n.map(e=>e.cid))}}}}function M(t,n){let r=!n.done;s(e=>e.map(e=>e.filename===t?{...e,cards:e.cards.map(e=>e.cid===n.cid?{...e,done:r}:e)}:e)),Jm(e,t,n.cid)}async function N(){let t=x.trim();t&&await $m(e,t)&&(b(!1),S(``),E())}let P=o.filter(e=>r||e.filename!==`archived.md`);return o.some(e=>e.filename===`archived.md`),f?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`})}):o.reduce((e,t)=>e+t.cards.length,0)===0&&o.length===0?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3 text-gray-500`,children:[(0,K.jsxs)(`div`,{className:`text-[13px]`,children:[`no kanban columns in notes/focus/boards/`,e,`/`]}),y?(0,K.jsxs)(`div`,{className:`w-56 bg-gray-50 rounded-lg p-3 space-y-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&N()},className:`w-full text-[13px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500`,placeholder:`Column name`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`button`,{onClick:N,disabled:!x.trim(),className:`px-2.5 h-7 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`Create`}),(0,K.jsx)(`button`,{onClick:()=>{b(!1),S(``)},className:`px-2.5 h-7 rounded text-[11px] text-gray-500 hover:bg-gray-200`,children:`✕`})]})]}):(0,K.jsx)(`button`,{onClick:()=>b(!0),className:`px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`+ Create first column`})]})}):(0,K.jsxs)(_J,{sensors:a,collisionDetection:DK,onDragStart:O,onDragOver:A,onDragEnd:j,children:[(0,K.jsx)(QJ,{items:P.map(e=>`col:${e.filename}`),strategy:WJ,children:(0,K.jsxs)(`div`,{className:`h-full flex gap-3 px-3 py-3 overflow-x-auto`,children:[P.map((r,i)=>{let a=u.find(e=>e.file===r.filename);return[C===i&&(0,K.jsx)(`div`,{className:`w-0.5 shrink-0 bg-blue-500 rounded-full self-stretch`},`indicator-${r.filename}`),(0,K.jsx)(QJ,{items:r.cards.map(e=>e.cid),strategy:JJ,children:(0,K.jsx)(mY,{board:e,column:{id:r.filename,label:r.title},cards:r.cards,onCardClick:e=>t(e,r.filename),onCardToggle:e=>M(r.filename,e),onCardArchive:e=>n(e,r.filename),onCardSaved:E,onColumnSaved:E,color:a?.color})},r.filename)]}),C===P.length&&(0,K.jsx)(`div`,{className:`w-0.5 shrink-0 bg-blue-500 rounded-full self-stretch`},`indicator-end`),y?(0,K.jsxs)(`div`,{className:`w-56 shrink-0 bg-gray-50 rounded-lg p-3 space-y-2 h-fit`,children:[(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&N()},className:`w-full text-[13px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500`,placeholder:`Column name`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`button`,{onClick:N,disabled:!x.trim(),className:`px-2.5 h-7 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`Create`}),(0,K.jsx)(`button`,{onClick:()=>{b(!1),S(``)},className:`px-2.5 h-7 rounded text-[11px] text-gray-500 hover:bg-gray-200`,children:`✕`})]})]}):(0,K.jsx)(`button`,{onClick:()=>b(!0),className:`w-56 shrink-0 h-fit rounded-lg border border-dashed border-gray-300 bg-gray-50 hover:bg-gray-100 py-3 text-[12px] text-gray-400`,children:`+ New Column`})]})}),(0,K.jsx)(LJ,{children:m?(0,K.jsx)(`div`,{className:`rotate-2 w-64`,children:(0,K.jsx)(dY,{card:m})}):g?(0,K.jsxs)(`div`,{className:`w-64 shrink-0 flex flex-col rounded-lg bg-gray-50 shadow-xl opacity-90 min-h-[120px]`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,K.jsx)(`span`,{className:`text-gray-400 text-[10px] shrink-0`,children:`⋮⋮`}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-gray-500 font-medium`,children:g.title}),(0,K.jsx)(`span`,{className:`text-[10px] font-mono text-gray-400 bg-gray-200 px-1.5 py-0.5 rounded-full`,children:g.cards.length})]}),(0,K.jsx)(`div`,{className:`flex-1 px-1 pb-1 flex flex-col gap-1.5`,children:g.cards.length===0?(0,K.jsx)(`div`,{className:`text-[11px] text-gray-300 italic px-2 py-4 text-center`,children:`drop here`}):g.cards.map(e=>(0,K.jsx)(dY,{card:e},e.cid))})]}):null})]})});function _Y(e,t,n,r,i,a,o,s){let c=[`- [${t?`x`:` `}] ${e}${s.length>0?` `+s.map(e=>`#${e}`).join(` `):``}`];if(n&&c.push(` > priority: ${n}`),r&&c.push(` > assignee: ${r}`),i&&c.push(` > due: ${i}`),a)for(let e of a.split(`
|
|
111
|
+
`},hK={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function gK(e){let{announcements:t=hK,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=mK}=e,{announce:a,announcement:o}=uK(),s=XG(`DndLiveRegion`),[c,l]=(0,_.useState)(!1);if((0,_.useEffect)(()=>{l(!0)},[]),fK((0,_.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!c)return null;let u=_.createElement(_.Fragment,null,_.createElement(cK,{id:r,value:i.draggable}),_.createElement(lK,{id:s,announcement:o}));return n?(0,dt.createPortal)(u,n):u}var _K;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(_K||={});function vK(){}function yK(e,t){return(0,_.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function bK(){var e=[...arguments];return(0,_.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var xK=Object.freeze({x:0,y:0});function SK(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function CK(e,t){let n=rK(e);if(!n)return`0 0`;let r={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return r.x+`% `+r.y+`%`}function wK(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function TK(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function EK(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function DK(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}var OK=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=DK(t,t.left,t.top),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=SK(DK(r),i);a.push({id:t,data:{droppableContainer:e,value:n}})}}return a.sort(wK)};function kK(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r<i&&n<a){let n=t.width*t.height,r=e.width*e.height,i=o*s,a=i/(n+r-i);return Number(a.toFixed(4))}return 0}var AK=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=kK(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort(TK)};function jK(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function MK(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:xK}function NK(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var PK=NK(1);function FK(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function IK(e,t,n){let r=FK(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var LK={ignoreTransform:!1};function RK(e,t){t===void 0&&(t=LK);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=LG(e).getComputedStyle(e);t&&(n=IK(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function zK(e){return RK(e,{ignoreTransform:!0})}function BK(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function VK(e,t){return t===void 0&&(t=LG(e).getComputedStyle(e)),t.position===`fixed`}function HK(e,t){t===void 0&&(t=LG(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`?n.test(r):!1})}function UK(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(RG(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!zG(i)||BG(i)||n.includes(i))return n;let a=LG(e).getComputedStyle(i);return i!==e&&HK(i,a)&&n.push(i),VK(i,a)?n:r(i.parentNode)}return e?r(e):n}function WK(e){let[t]=UK(e,1);return t??null}function GK(e){return!PG||!e?null:FG(e)?e:IG(e)?RG(e)||e===VG(e).scrollingElement?window:zG(e)?e:null:null}function KK(e){return FG(e)?e.scrollX:e.scrollLeft}function qK(e){return FG(e)?e.scrollY:e.scrollTop}function JK(e){return{x:KK(e),y:qK(e)}}var YK;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(YK||={});function XK(e){return!PG||!e?!1:e===document.scrollingElement}function ZK(e){let t={x:0,y:0},n=XK(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var QK={x:.2,y:.2};function $K(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=QK);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=ZK(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=YK.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=YK.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=YK.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=YK.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function eq(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function tq(e){return e.reduce((e,t)=>QG(e,JK(t)),xK)}function nq(e){return e.reduce((e,t)=>e+KK(t),0)}function rq(e){return e.reduce((e,t)=>e+qK(t),0)}function iq(e,t){if(t===void 0&&(t=RK),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);WK(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var aq=[[`x`,[`left`,`right`],nq],[`y`,[`top`,`bottom`],rq]],oq=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=UK(t),r=tq(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of aq)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}},sq=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function cq(e){let{EventTarget:t}=LG(e);return e instanceof t?e:VG(e)}function lq(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t?r>t.y:!1}var uq;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(uq||={});function dq(e){e.preventDefault()}function fq(e){e.stopPropagation()}var pq;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})(pq||={});var mq={start:[pq.Space,pq.Enter],cancel:[pq.Esc],end:[pq.Space,pq.Enter,pq.Tab]},hq=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case pq.Right:return{...n,x:n.x+25};case pq.Left:return{...n,x:n.x-25};case pq.Down:return{...n,y:n.y+25};case pq.Up:return{...n,y:n.y-25}}},gq=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new sq(VG(t)),this.windowListeners=new sq(LG(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(uq.Resize,this.handleCancel),this.windowListeners.add(uq.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(uq.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&iq(n),t(xK)}handleKeyDown(e){if(tK(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=mq,coordinateGetter:a=hq,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:xK;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=$G(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=ZK(n),p=eq(n),m={x:Math.min(i===pq.Right?p.right-p.width/2:p.right,Math.max(i===pq.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===pq.Down?p.bottom-p.height/2:p.bottom,Math.max(i===pq.Down?p.top:p.top+p.height/2,u.y))},h=i===pq.Right&&!s||i===pq.Left&&!c,g=i===pq.Down&&!l||i===pq.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===pq.Right&&e<=d.x||i===pq.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}a?r.x=n.scrollLeft-e:r.x=i===pq.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}else if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===pq.Down&&e<=d.y||i===pq.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}a?r.y=n.scrollTop-e:r.y=i===pq.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,QG($G(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};gq.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=mq,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function _q(e){return!!(e&&`distance`in e)}function vq(e){return!!(e&&`delay`in e)}var yq=class{constructor(e,t,n){n===void 0&&(n=cq(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=VG(i),this.documentListeners=new sq(this.document),this.listeners=new sq(n),this.windowListeners=new sq(LG(i)),this.initialCoordinates=rK(r)??xK,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(uq.Resize,this.handleCancel),this.windowListeners.add(uq.DragStart,dq),this.windowListeners.add(uq.VisibilityChange,this.handleCancel),this.windowListeners.add(uq.ContextMenu,dq),this.documentListeners.add(uq.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(vq(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(_q(t)){this.handlePending(t);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(uq.Click,fq,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(uq.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=rK(e)??xK,s=$G(n,o);if(!t&&a){if(_q(a)){if(a.tolerance!=null&&lq(s,a.tolerance))return this.handleCancel();if(lq(s,a.distance))return this.handleStart()}if(vq(a)&&lq(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===pq.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},bq={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},xq=class extends yq{constructor(e){let{event:t}=e,n=VG(t.target);super(e,bq,n)}};xq.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var Sq={move:{name:`mousemove`},end:{name:`mouseup`}},Cq;(function(e){e[e.RightClick=2]=`RightClick`})(Cq||={});var wq=class extends yq{constructor(e){super(e,Sq,VG(e.event.target))}};wq.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===Cq.RightClick?!1:(r?.({event:n}),!0)}}];var Tq={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},Eq=class extends yq{constructor(e){super(e,Tq)}static setup(){return window.addEventListener(Tq.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(Tq.move.name,e)};function e(){}}};Eq.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var Dq;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(Dq||={});var Oq;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})(Oq||={});function kq(e){let{acceleration:t,activator:n=Dq.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:o=5,order:s=Oq.TreeOrder,pointerCoordinates:c,scrollableAncestors:l,scrollableAncestorRects:u,delta:d,threshold:f}=e,p=jq({delta:d,disabled:!a}),[m,h]=WG(),g=(0,_.useRef)({x:0,y:0}),v=(0,_.useRef)({x:0,y:0}),y=(0,_.useMemo)(()=>{switch(n){case Dq.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case Dq.DraggableRect:return i}},[n,i,c]),b=(0,_.useRef)(null),x=(0,_.useCallback)(()=>{let e=b.current;if(!e)return;let t=g.current.x*v.current.x,n=g.current.y*v.current.y;e.scrollBy(t,n)},[]),S=(0,_.useMemo)(()=>s===Oq.TreeOrder?[...l].reverse():l,[s,l]);(0,_.useEffect)(()=>{if(!a||!l.length||!y){h();return}for(let e of S){if(r?.(e)===!1)continue;let n=u[l.indexOf(e)];if(!n)continue;let{direction:i,speed:a}=$K(e,n,y,t,f);for(let e of[`x`,`y`])p[e][i[e]]||(a[e]=0,i[e]=0);if(a.x>0||a.y>0){h(),b.current=e,m(x,o),g.current=a,v.current=i;return}}g.current={x:0,y:0},v.current={x:0,y:0},h()},[t,x,r,h,a,o,JSON.stringify(y),JSON.stringify(p),m,l,S,u,JSON.stringify(f)])}var Aq={x:{[YK.Backward]:!1,[YK.Forward]:!1},y:{[YK.Backward]:!1,[YK.Forward]:!1}};function jq(e){let{delta:t,disabled:n}=e,r=JG(t);return KG(e=>{if(n||!r||!e)return Aq;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[YK.Backward]:e.x[YK.Backward]||i.x===-1,[YK.Forward]:e.x[YK.Forward]||i.x===1},y:{[YK.Backward]:e.y[YK.Backward]||i.y===-1,[YK.Forward]:e.y[YK.Forward]||i.y===1}}},[n,t,r])}function Mq(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return KG(e=>t==null?null:r??e??null,[r,t])}function Nq(e,t){return(0,_.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var Pq;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(Pq||={});var Fq;(function(e){e.Optimized=`optimized`})(Fq||={});var Iq=new Map;function Lq(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,o]=(0,_.useState)(null),{frequency:s,measure:c,strategy:l}=i,u=(0,_.useRef)(e),d=g(),f=GG(d),p=(0,_.useCallback)(function(e){e===void 0&&(e=[]),!f.current&&o(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[f]),m=(0,_.useRef)(null),h=KG(t=>{if(d&&!n)return Iq;if(!t||t===Iq||u.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new oq(c(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,d,c]);return(0,_.useEffect)(()=>{u.current=e},[e]),(0,_.useEffect)(()=>{d||p()},[n,d]),(0,_.useEffect)(()=>{a&&a.length>0&&o(null)},[JSON.stringify(a)]),(0,_.useEffect)(()=>{d||typeof s!=`number`||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},s))},[s,d,p,...r]),{droppableRects:h,measureDroppableContainers:p,measuringScheduled:a!=null};function g(){switch(l){case Pq.Always:return!1;case Pq.BeforeDragging:return n;default:return!n}}}function Rq(e,t){return KG(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function zq(e,t){return Rq(e,t)}function Bq(e){let{callback:t,disabled:n}=e,r=UG(t),i=(0,_.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,_.useEffect)(()=>()=>i?.disconnect(),[i]),i}function Vq(e){let{callback:t,disabled:n}=e,r=UG(t),i=(0,_.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,_.useEffect)(()=>()=>i?.disconnect(),[i]),i}function Hq(e){return new oq(RK(e),e)}function Uq(e,t,n){t===void 0&&(t=Hq);let[r,i]=(0,_.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let o=Bq({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),s=Vq({callback:a});return HG(()=>{a(),e?(s?.observe(e),o?.observe(document.body,{childList:!0,subtree:!0})):(s?.disconnect(),o?.disconnect())},[e]),r}function Wq(e){return MK(e,Rq(e))}var Gq=[];function Kq(e){let t=(0,_.useRef)(e),n=KG(n=>e?n&&n!==Gq&&e&&t.current&&e.parentNode===t.current.parentNode?n:UK(e):Gq,[e]);return(0,_.useEffect)(()=>{t.current=e},[e]),n}function qq(e){let[t,n]=(0,_.useState)(null),r=(0,_.useRef)(e),i=(0,_.useCallback)(e=>{let t=GK(e.target);t&&n(e=>e?(e.set(t,JK(t)),new Map(e)):null)},[]);return(0,_.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=GK(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,JK(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{GK(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,_.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>QG(e,t),xK):tq(e):xK,[e,t])}function Jq(e,t){t===void 0&&(t=[]);let n=(0,_.useRef)(null);return(0,_.useEffect)(()=>{n.current=null},t),(0,_.useEffect)(()=>{let t=e!==xK;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?$G(e,n.current):xK}function Yq(e){(0,_.useEffect)(()=>{if(!PG)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function Xq(e,t){return(0,_.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function Zq(e){return(0,_.useMemo)(()=>e?BK(e):null,[e])}var Qq=[];function $q(e,t){t===void 0&&(t=RK);let[n]=e,r=Zq(n?LG(n):null),[i,a]=(0,_.useState)(Qq);function o(){a(()=>e.length?e.map(e=>XK(e)?r:new oq(t(e),e)):Qq)}let s=Vq({callback:o});return HG(()=>{s?.disconnect(),o(),e.forEach(e=>s?.observe(e))},[e]),i}function eJ(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return zG(t)?t:e}function tJ(e){let{measure:t}=e,[n,r]=(0,_.useState)(null),i=Vq({callback:(0,_.useCallback)(e=>{for(let{target:n}of e)if(zG(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,o]=qG((0,_.useCallback)(e=>{let n=eJ(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,_.useMemo)(()=>({nodeRef:a,rect:n,setRef:o}),[n,a,o])}var nJ=[{sensor:xq,options:{}},{sensor:gq,options:{}}],rJ={current:{}},iJ={draggable:{measure:zK},droppable:{measure:zK,strategy:Pq.WhileDragging,frequency:Fq.Optimized},dragOverlay:{measure:RK}},aJ=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},oJ={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new aJ,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:vK},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:iJ,measureDroppableContainers:vK,windowRect:null,measuringScheduled:!1},sJ={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:vK,draggableNodes:new Map,over:null,measureDroppableContainers:vK},cJ=(0,_.createContext)(sJ),lJ=(0,_.createContext)(oJ);function uJ(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new aJ}}}function dJ(e,t){switch(t.type){case _K.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case _K.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case _K.DragEnd:case _K.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case _K.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new aJ(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case _K.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new aJ(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case _K.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new aJ(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function fJ(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,_.useContext)(cJ),a=JG(r),o=JG(n?.id);return(0,_.useEffect)(()=>{if(!t&&!r&&a&&o!=null){if(!tK(a)||document.activeElement===a.target)return;let e=i.get(o);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=oK(e);if(t){t.focus();break}}})}},[r,t,i,o,a]),null}function pJ(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function mJ(e){return(0,_.useMemo)(()=>({draggable:{...iJ.draggable,...e?.draggable},droppable:{...iJ.droppable,...e?.droppable},dragOverlay:{...iJ.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function hJ(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,_.useRef)(!1),{x:o,y:s}=typeof i==`boolean`?{x:i,y:i}:i;HG(()=>{if(!o&&!s||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=MK(n(e),r);if(o||(i.x=0),s||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=WK(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,o,s,r,n])}var gJ=(0,_.createContext)({...xK,scaleX:1,scaleY:1}),_J;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(_J||={});var vJ=(0,_.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=nJ,collisionDetection:o=AK,measuring:s,modifiers:c,...l}=e,[u,d]=(0,_.useReducer)(dJ,void 0,uJ),[f,p]=pK(),[m,h]=(0,_.useState)(_J.Uninitialized),g=m===_J.Initialized,{draggable:{active:v,nodes:y,translate:b},droppable:{containers:x}}=u,S=v==null?null:y.get(v),C=(0,_.useRef)({initial:null,translated:null}),w=(0,_.useMemo)(()=>v==null?null:{id:v,data:S?.data??rJ,rect:C},[v,S]),T=(0,_.useRef)(null),[E,D]=(0,_.useState)(null),[O,k]=(0,_.useState)(null),A=GG(l,Object.values(l)),j=XG(`DndDescribedBy`,t),M=(0,_.useMemo)(()=>x.getEnabled(),[x]),N=mJ(s),{droppableRects:P,measureDroppableContainers:F,measuringScheduled:I}=Lq(M,{dragging:g,dependencies:[b.x,b.y],config:N.droppable}),L=Mq(y,v),R=(0,_.useMemo)(()=>O?rK(O):null,[O]),z=we(),B=zq(L,N.draggable.measure);hJ({activeNode:v==null?null:y.get(v),config:z.layoutShiftCompensation,initialRect:B,measure:N.draggable.measure});let V=Uq(L,N.draggable.measure,B),H=Uq(L?L.parentElement:null),U=(0,_.useRef)({activatorEvent:null,active:null,activeNode:L,collisionRect:null,collisions:null,droppableRects:P,draggableNodes:y,draggingNode:null,draggingNodeRect:null,droppableContainers:x,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ee=x.getNodeFor(U.current.over?.id),W=tJ({measure:N.dragOverlay.measure}),te=W.nodeRef.current??L,ne=g?W.rect??V:null,G=!!(W.nodeRef.current&&W.rect),re=Wq(G?null:V),ie=Zq(te?LG(te):null),ae=Kq(g?ee??L:null),oe=$q(ae),se=pJ(c,{transform:{x:b.x-re.x,y:b.y-re.y,scaleX:1,scaleY:1},activatorEvent:O,active:w,activeNodeRect:V,containerNodeRect:H,draggingNodeRect:ne,over:U.current.over,overlayNodeRect:W.rect,scrollableAncestors:ae,scrollableAncestorRects:oe,windowRect:ie}),ce=R?QG(R,b):null,le=qq(ae),ue=Jq(le),de=Jq(le,[V]),fe=QG(se,ue),pe=ne?PK(ne,se):null,me=w&&pe?o({active:w,collisionRect:pe,droppableRects:P,droppableContainers:M,pointerCoordinates:ce}):null,he=EK(me,`id`),[ge,_e]=(0,_.useState)(null),ve=jK(G?se:QG(se,de),ge?.rect??null,V),ye=(0,_.useRef)(null),be=(0,_.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(T.current==null)return;let i=y.get(T.current);if(!i)return;let a=e.nativeEvent;ye.current=new n({active:T.current,activeNode:i,event:a,options:r,context:U,onAbort(e){if(!y.get(e))return;let{onDragAbort:t}=A.current,n={id:e};t?.(n),f({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!y.get(e))return;let{onDragPending:i}=A.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),f({type:`onDragPending`,event:a})},onStart(e){let t=T.current;if(t==null)return;let n=y.get(t);if(!n)return;let{onDragStart:r}=A.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:C}};(0,dt.unstable_batchedUpdates)(()=>{r?.(i),h(_J.Initializing),d({type:_K.DragStart,initialCoordinates:e,active:t}),f({type:`onDragStart`,event:i}),D(ye.current),k(a)})},onMove(e){d({type:_K.DragMove,coordinates:e})},onEnd:o(_K.DragEnd),onCancel:o(_K.DragCancel)});function o(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=U.current,o=null;if(t&&i){let{cancelDrop:s}=A.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===_K.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=_K.DragCancel)}T.current=null,(0,dt.unstable_batchedUpdates)(()=>{d({type:e}),h(_J.Uninitialized),_e(null),D(null),k(null),ye.current=null;let t=e===_K.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=A.current[t];e?.(o),f({type:t,event:o})}})}}},[y]),xe=Nq(a,(0,_.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=y.get(r);if(T.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},T.current=r,be(n,t))},[y,be]));Yq(a),HG(()=>{V&&m===_J.Initializing&&h(_J.Initialized)},[V,m]),(0,_.useEffect)(()=>{let{onDragMove:e}=A.current,{active:t,activatorEvent:n,collisions:r,over:i}=U.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:fe.x,y:fe.y},over:i};(0,dt.unstable_batchedUpdates)(()=>{e?.(a),f({type:`onDragMove`,event:a})})},[fe.x,fe.y]),(0,_.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=U.current;if(!e||T.current==null||!t||!i)return;let{onDragOver:a}=A.current,o=r.get(he),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,dt.unstable_batchedUpdates)(()=>{_e(s),a?.(c),f({type:`onDragOver`,event:c})})},[he]),HG(()=>{U.current={activatorEvent:O,active:w,activeNode:L,collisionRect:pe,collisions:me,droppableRects:P,draggableNodes:y,draggingNode:te,draggingNodeRect:ne,droppableContainers:x,over:ge,scrollableAncestors:ae,scrollAdjustedTranslate:fe},C.current={initial:ne,translated:pe}},[w,L,me,pe,y,te,ne,P,x,ge,ae,fe]),kq({...z,delta:b,draggingRect:pe,pointerCoordinates:ce,scrollableAncestors:ae,scrollableAncestorRects:oe});let Se=(0,_.useMemo)(()=>({active:w,activeNode:L,activeNodeRect:V,activatorEvent:O,collisions:me,containerNodeRect:H,dragOverlay:W,draggableNodes:y,droppableContainers:x,droppableRects:P,over:ge,measureDroppableContainers:F,scrollableAncestors:ae,scrollableAncestorRects:oe,measuringConfiguration:N,measuringScheduled:I,windowRect:ie}),[w,L,V,O,me,H,W,y,x,P,ge,F,ae,oe,N,I,ie]),Ce=(0,_.useMemo)(()=>({activatorEvent:O,activators:xe,active:w,activeNodeRect:V,ariaDescribedById:{draggable:j},dispatch:d,draggableNodes:y,over:ge,measureDroppableContainers:F}),[O,xe,w,V,d,j,y,ge,F]);return _.createElement(dK.Provider,{value:p},_.createElement(cJ.Provider,{value:Ce},_.createElement(lJ.Provider,{value:Se},_.createElement(gJ.Provider,{value:ve},i)),_.createElement(fJ,{disabled:n?.restoreFocus===!1})),_.createElement(gK,{...n,hiddenTextDescribedById:j}));function we(){let e=E?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=g&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),yJ=(0,_.createContext)(null),bJ=`button`,xJ=`Draggable`;function SJ(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=XG(xJ),{activators:o,activatorEvent:s,active:c,activeNodeRect:l,ariaDescribedById:u,draggableNodes:d,over:f}=(0,_.useContext)(cJ),{role:p=bJ,roleDescription:m=`draggable`,tabIndex:h=0}=i??{},g=c?.id===t,v=(0,_.useContext)(g?gJ:yJ),[y,b]=qG(),[x,S]=qG(),C=Xq(o,t),w=GG(n);return HG(()=>(d.set(t,{id:t,key:a,node:y,activatorNode:x,data:w}),()=>{let e=d.get(t);e&&e.key===a&&d.delete(t)}),[d,t]),{active:c,activatorEvent:s,activeNodeRect:l,attributes:(0,_.useMemo)(()=>({role:p,tabIndex:h,"aria-disabled":r,"aria-pressed":g&&p===bJ?!0:void 0,"aria-roledescription":m,"aria-describedby":u.draggable}),[r,p,h,g,m,u.draggable]),isDragging:g,listeners:r?void 0:C,node:y,over:f,setNodeRef:b,setActivatorNodeRef:S,transform:v}}function CJ(){return(0,_.useContext)(lJ)}var wJ=`Droppable`,TJ={timeout:25};function EJ(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=XG(wJ),{active:o,dispatch:s,over:c,measureDroppableContainers:l}=(0,_.useContext)(cJ),u=(0,_.useRef)({disabled:n}),d=(0,_.useRef)(!1),f=(0,_.useRef)(null),p=(0,_.useRef)(null),{disabled:m,updateMeasurementsFor:h,timeout:g}={...TJ,...i},v=GG(h??r),y=Vq({callback:(0,_.useCallback)(()=>{if(!d.current){d.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{l(Array.isArray(v.current)?v.current:[v.current]),p.current=null},g)},[g]),disabled:m||!o}),[b,x]=qG((0,_.useCallback)((e,t)=>{y&&(t&&(y.unobserve(t),d.current=!1),e&&y.observe(e))},[y])),S=GG(t);return(0,_.useEffect)(()=>{!y||!b.current||(y.disconnect(),d.current=!1,y.observe(b.current))},[b,y]),(0,_.useEffect)(()=>(s({type:_K.RegisterDroppable,element:{id:r,key:a,disabled:n,node:b,rect:f,data:S}}),()=>s({type:_K.UnregisterDroppable,key:a,id:r})),[r]),(0,_.useEffect)(()=>{n!==u.current.disabled&&(s({type:_K.SetDroppableDisabled,id:r,key:a,disabled:n}),u.current.disabled=n)},[r,a,n,s]),{active:o,rect:f,isOver:c?.id===r,node:b,over:c,setNodeRef:x}}function DJ(e){let{animation:t,children:n}=e,[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null),s=JG(n);return!n&&!r&&s&&i(s),HG(()=>{if(!a)return;let e=r?.key,n=r?.props.id;if(e==null||n==null){i(null);return}Promise.resolve(t(n,a)).then(()=>{i(null)})},[t,r,a]),_.createElement(_.Fragment,null,n,r?(0,_.cloneElement)(r,{ref:o}):null)}var OJ={x:0,y:0,scaleX:1,scaleY:1};function kJ(e){let{children:t}=e;return _.createElement(cJ.Provider,{value:sJ},_.createElement(gJ.Provider,{value:OJ},t))}var AJ={position:`fixed`,touchAction:`none`},jJ=e=>tK(e)?`transform 250ms ease`:void 0,MJ=(0,_.forwardRef)((e,t)=>{let{as:n,activatorEvent:r,adjustScale:i,children:a,className:o,rect:s,style:c,transform:l,transition:u=jJ}=e;if(!s)return null;let d=i?l:{...l,scaleX:1,scaleY:1},f={...AJ,width:s.width,height:s.height,top:s.top,left:s.left,transform:iK.Transform.toString(d),transformOrigin:i&&r?CK(r,s):void 0,transition:typeof u==`function`?u(r):u,...c};return _.createElement(n,{className:o,style:f,ref:t},a)}),NJ={duration:250,easing:`ease`,keyframes:e=>{let{transform:{initial:t,final:n}}=e;return[{transform:iK.Transform.toString(t)},{transform:iK.Transform.toString(n)}]},sideEffects:(e=>t=>{let{active:n,dragOverlay:r}=t,i={},{styles:a,className:o}=e;if(a!=null&&a.active)for(let[e,t]of Object.entries(a.active))t!==void 0&&(i[e]=n.node.style.getPropertyValue(e),n.node.style.setProperty(e,t));if(a!=null&&a.dragOverlay)for(let[e,t]of Object.entries(a.dragOverlay))t!==void 0&&r.node.style.setProperty(e,t);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&r.node.classList.add(o.dragOverlay),function(){for(let[e,t]of Object.entries(i))n.node.style.setProperty(e,t);o!=null&&o.active&&n.node.classList.remove(o.active)}})({styles:{active:{opacity:`0`}}})};function PJ(e){let{config:t,draggableNodes:n,droppableContainers:r,measuringConfiguration:i}=e;return UG((e,a)=>{if(t===null)return;let o=n.get(e);if(!o)return;let s=o.node.current;if(!s)return;let c=eJ(a);if(!c)return;let{transform:l}=LG(a).getComputedStyle(a),u=FK(l);if(!u)return;let d=typeof t==`function`?t:FJ(t);return iq(s,i.draggable.measure),d({active:{id:e,data:o.data,node:s,rect:i.draggable.measure(s)},draggableNodes:n,dragOverlay:{node:a,rect:i.dragOverlay.measure(c)},droppableContainers:r,measuringConfiguration:i,transform:u})})}function FJ(e){let{duration:t,easing:n,sideEffects:r,keyframes:i}={...NJ,...e};return e=>{let{active:a,dragOverlay:o,transform:s,...c}=e;if(!t)return;let l={x:o.rect.left-a.rect.left,y:o.rect.top-a.rect.top},u={scaleX:s.scaleX===1?1:a.rect.width*s.scaleX/o.rect.width,scaleY:s.scaleY===1?1:a.rect.height*s.scaleY/o.rect.height},d={x:s.x-l.x,y:s.y-l.y,...u},f=i({...c,active:a,dragOverlay:o,transform:{initial:s,final:d}}),[p]=f,m=f[f.length-1];if(JSON.stringify(p)===JSON.stringify(m))return;let h=r?.({active:a,dragOverlay:o,...c}),g=o.node.animate(f,{duration:t,easing:n,fill:`forwards`});return new Promise(e=>{g.onfinish=()=>{h?.(),e()}})}}var IJ=0;function LJ(e){return(0,_.useMemo)(()=>{if(e!=null)return IJ++,IJ},[e])}var RJ=_.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:r,style:i,transition:a,modifiers:o,wrapperElement:s=`div`,className:c,zIndex:l=999}=e,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggableNodes:m,droppableContainers:h,dragOverlay:g,over:v,measuringConfiguration:y,scrollableAncestors:b,scrollableAncestorRects:x,windowRect:S}=CJ(),C=(0,_.useContext)(gJ),w=LJ(d?.id),T=pJ(o,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggingNodeRect:g.rect,over:v,overlayNodeRect:g.rect,scrollableAncestors:b,scrollableAncestorRects:x,transform:C,windowRect:S}),E=Rq(f),D=PJ({config:r,draggableNodes:m,droppableContainers:h,measuringConfiguration:y}),O=E?g.setRef:void 0;return _.createElement(kJ,null,_.createElement(DJ,{animation:D},d&&w?_.createElement(MJ,{key:w,id:d.id,ref:O,as:s,activatorEvent:u,adjustScale:t,className:c,transition:a,rect:E,style:{zIndex:l,...i},transform:T},n):null))});function zJ(e,t,n){let r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function BJ(e,t){return e.reduce((e,n,r)=>{let i=t.get(n);return i&&(e[r]=i),e},Array(e.length))}function VJ(e){return e!==null&&e>=0}function HJ(e,t){if(e===t)return!0;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 UJ(e){return typeof e==`boolean`?{draggable:e,droppable:e}:e}var WJ={scaleX:1,scaleY:1},GJ=e=>{let{rects:t,activeNodeRect:n,activeIndex:r,overIndex:i,index:a}=e,o=t[r]??n;if(!o)return null;let s=KJ(t,a,r);if(a===r){let e=t[i];return e?{x:r<i?e.left+e.width-(o.left+o.width):e.left-o.left,y:0,...WJ}:null}return a>r&&a<=i?{x:-o.width-s,y:0,...WJ}:a<r&&a>=i?{x:o.width+s,y:0,...WJ}:{x:0,y:0,...WJ}};function KJ(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return!r||!i&&!a?0:n<t?i?r.left-(i.left+i.width):a.left-(r.left+r.width):a?a.left-(r.left+r.width):r.left-(i.left+i.width)}var qJ=e=>{let{rects:t,activeIndex:n,overIndex:r,index:i}=e,a=zJ(t,r,n),o=t[i],s=a[i];return!s||!o?null:{x:s.left-o.left,y:s.top-o.top,scaleX:s.width/o.width,scaleY:s.height/o.height}},JJ={scaleX:1,scaleY:1},YJ=e=>{let{activeIndex:t,activeNodeRect:n,index:r,rects:i,overIndex:a}=e,o=i[t]??n;if(!o)return null;if(r===t){let e=i[a];return e?{x:0,y:t<a?e.top+e.height-(o.top+o.height):e.top-o.top,...JJ}:null}let s=XJ(i,r,t);return r>t&&r<=a?{x:0,y:-o.height-s,...JJ}:r<t&&r>=a?{x:0,y:o.height+s,...JJ}:{x:0,y:0,...JJ}};function XJ(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return r?n<t?i?r.top-(i.top+i.height):a?a.top-(r.top+r.height):0:a?a.top-(r.top+r.height):i?r.top-(i.top+i.height):0:0}var ZJ=`Sortable`,QJ=_.createContext({activeIndex:-1,containerId:ZJ,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:qJ,disabled:{draggable:!1,droppable:!1}});function $J(e){let{children:t,id:n,items:r,strategy:i=qJ,disabled:a=!1}=e,{active:o,dragOverlay:s,droppableRects:c,over:l,measureDroppableContainers:u}=CJ(),d=XG(ZJ,n),f=s.rect!==null,p=(0,_.useMemo)(()=>r.map(e=>typeof e==`object`&&`id`in e?e.id:e),[r]),m=o!=null,h=o?p.indexOf(o.id):-1,g=l?p.indexOf(l.id):-1,v=(0,_.useRef)(p),y=!HJ(p,v.current),b=g!==-1&&h===-1||y,x=UJ(a);HG(()=>{y&&m&&u(p)},[y,p,m,u]),(0,_.useEffect)(()=>{v.current=p},[p]);let S=(0,_.useMemo)(()=>({activeIndex:h,containerId:d,disabled:x,disableTransforms:b,items:p,overIndex:g,useDragOverlay:f,sortedRects:BJ(p,c),strategy:i}),[h,d,x.draggable,x.droppable,b,p,g,c,f,i]);return _.createElement(QJ.Provider,{value:S},t)}var eY=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return zJ(n,r,i).indexOf(t)},tY=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:a,newIndex:o,previousItems:s,previousContainerId:c,transition:l}=e;return!l||!r||s!==a&&i===o?!1:n?!0:o!==i&&t===c},nY={duration:200,easing:`ease`},rY=`transform`,iY=iK.Transition.toString({property:rY,duration:0,easing:`linear`}),aY={roleDescription:`sortable`};function oY(e){let{disabled:t,index:n,node:r,rect:i}=e,[a,o]=(0,_.useState)(null),s=(0,_.useRef)(n);return HG(()=>{if(!t&&n!==s.current&&r.current){let e=i.current;if(e){let t=RK(r.current,{ignoreTransform:!0}),n={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(n.x||n.y)&&o(n)}}n!==s.current&&(s.current=n)},[t,n,r,i]),(0,_.useEffect)(()=>{a&&o(null)},[a]),a}function sY(e){let{animateLayoutChanges:t=tY,attributes:n,disabled:r,data:i,getNewIndex:a=eY,id:o,strategy:s,resizeObserverConfig:c,transition:l=nY}=e,{items:u,containerId:d,activeIndex:f,disabled:p,disableTransforms:m,sortedRects:h,overIndex:g,useDragOverlay:v,strategy:y}=(0,_.useContext)(QJ),b=cY(r,p),x=u.indexOf(o),S=(0,_.useMemo)(()=>({sortable:{containerId:d,index:x,items:u},...i}),[d,i,x,u]),C=(0,_.useMemo)(()=>u.slice(u.indexOf(o)),[u,o]),{rect:w,node:T,isOver:E,setNodeRef:D}=EJ({id:o,data:S,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:C,...c}}),{active:O,activatorEvent:k,activeNodeRect:A,attributes:j,setNodeRef:M,listeners:N,isDragging:P,over:F,setActivatorNodeRef:I,transform:L}=SJ({id:o,data:S,attributes:{...aY,...n},disabled:b.draggable}),R=NG(D,M),z=!!O,B=z&&!m&&VJ(f)&&VJ(g),V=!v&&P,H=B?(V&&B?L:null)??(s??y)({rects:h,activeNodeRect:A,activeIndex:f,overIndex:g,index:x}):null,U=VJ(f)&&VJ(g)?a({id:o,items:u,activeIndex:f,overIndex:g}):x,ee=O?.id,W=(0,_.useRef)({activeId:ee,items:u,newIndex:U,containerId:d}),te=u!==W.current.items,ne=t({active:O,containerId:d,isDragging:P,isSorting:z,id:o,index:x,items:u,newIndex:W.current.newIndex,previousItems:W.current.items,previousContainerId:W.current.containerId,transition:l,wasDragging:W.current.activeId!=null}),G=oY({disabled:!ne,index:x,node:T,rect:w});return(0,_.useEffect)(()=>{z&&W.current.newIndex!==U&&(W.current.newIndex=U),d!==W.current.containerId&&(W.current.containerId=d),u!==W.current.items&&(W.current.items=u)},[z,U,d,u]),(0,_.useEffect)(()=>{if(ee===W.current.activeId)return;if(ee!=null&&W.current.activeId==null){W.current.activeId=ee;return}let e=setTimeout(()=>{W.current.activeId=ee},50);return()=>clearTimeout(e)},[ee]),{active:O,activeIndex:f,attributes:j,data:S,rect:w,index:x,newIndex:U,items:u,isOver:E,isSorting:z,isDragging:P,listeners:N,node:T,overIndex:g,over:F,setNodeRef:R,setActivatorNodeRef:I,setDroppableNodeRef:D,setDraggableNodeRef:M,transform:G??H,transition:re()};function re(){if(G||te&&W.current.newIndex===x)return iY;if(!(V&&!tK(k)||!l)&&(z||ne))return iK.Transition.toString({...l,property:rY})}}function cY(e,t){return typeof e==`boolean`?{draggable:e,droppable:!1}:{draggable:e?.draggable??t.draggable,droppable:e?.droppable??t.droppable}}pq.Down,pq.Right,pq.Up,pq.Left;function lY({text:e}){return(0,K.jsx)(sI,{remarkPlugins:[_z],components:{p:({children:e})=>(0,K.jsx)(K.Fragment,{children:e}),strong:({children:e})=>(0,K.jsx)(`strong`,{className:`font-bold`,children:e}),em:({children:e})=>(0,K.jsx)(`em`,{className:`italic`,children:e}),a:({href:e,children:t})=>(0,K.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),className:`text-blue-700 hover:underline`,children:t}),code:({children:e})=>(0,K.jsx)(`code`,{className:`bg-gray-100 text-gray-800 rounded px-1 font-mono text-[11px]`,children:e})},children:e})}function uY(e){return e.assignee?e.assignee.split(/[,;,;]+/).map(e=>e.trim()).filter(Boolean):[]}var dY={P0:`bg-red-50 text-red-700 border-red-200`,P1:`bg-orange-50 text-orange-700 border-orange-200`};function fY({card:e}){let t=e.subtasks.length>0?Math.round(e.subtasks.filter(e=>e.done).length/e.subtasks.length*100):0,n=uY(e);return(0,K.jsxs)(`div`,{className:`text-left rounded-lg border bg-white px-3 py-2.5 w-full shadow-lg ${e.done?`opacity-60`:`border-gray-300`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`span`,{className:`shrink-0 mt-0.5 w-4 h-4 rounded border border-gray-300 flex items-center justify-center text-xs ${e.done?`bg-emerald-50 border-emerald-400`:``}`,children:e.done?`✓`:``}),(0,K.jsx)(`h4`,{className:`text-[13px] font-medium flex-1 min-w-0 ${e.done?`text-gray-400 line-through`:`text-gray-900`}`,children:(0,K.jsx)(lY,{text:e.text})}),e.priority&&(0,K.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded shrink-0 border ${dY[e.priority]??`bg-gray-50 text-gray-600 border-gray-200`}`,children:e.priority.toUpperCase()})]}),(n.length>0||e.due)&&(0,K.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2 text-[10px]`,children:[n.map((e,t)=>(0,K.jsx)(`span`,{className:`w-5 h-5 rounded-full bg-gray-200 text-gray-600 text-[9px] flex items-center justify-center font-medium`,title:e,children:e.slice(0,2).toUpperCase()},t)),e.due&&(0,K.jsx)(`span`,{className:`text-gray-400 ml-auto`,children:e.due})]}),e.topics.length>0&&(0,K.jsx)(`div`,{className:`mt-1.5 flex items-center gap-1 flex-wrap`,children:e.topics.map(e=>(0,K.jsx)(pG,{name:e,onClick:()=>{}},e))}),e.subtasks.length>0&&(0,K.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-1 bg-gray-100 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${t}%`}})}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-gray-500 shrink-0`,children:[e.subtasks.filter(e=>e.done).length,`/`,e.subtasks.length]})]})]})}function pY({board:e,card:t,colFilename:n,onClick:r,onToggle:i,onArchive:a}){let o=zn(),{attributes:s,listeners:c,setNodeRef:l,transform:u,transition:d,isDragging:f}=sY({id:t.cid,data:{card:t,colFilename:n}}),p=u&&(u.x!==0||u.y!==0)?{transform:`translate3d(${u.x}px, ${u.y}px, 0)`,transition:d}:void 0,[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(t.text);async function y(){let r=g.trim();if(!r||r===t.text){h(!1);return}await Ym(e,n,t.cid,{text:r}),h(!1)}let b=t.subtasks.length>0?Math.round(t.subtasks.filter(e=>e.done).length/t.subtasks.length*100):0,x=uY(t);return(0,K.jsxs)(`div`,{className:`relative group/card`,children:[(0,K.jsxs)(`div`,{ref:l,...c,...s,style:p,onClick:m?void 0:r,role:`button`,tabIndex:0,className:`text-left rounded-lg border bg-white px-3 py-2.5 transition-all w-full cursor-grab active:cursor-grabbing
|
|
112
|
+
${f?`opacity-30 shadow-lg`:`border-gray-200 hover:border-gray-400 hover:shadow-sm`} ${t.done?`opacity-60`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`span`,{className:`shrink-0 mt-0.5 w-4 h-4 rounded border border-gray-300 flex items-center justify-center cursor-pointer hover:border-gray-500`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),i()},children:t.done&&(0,K.jsx)(`span`,{className:`text-emerald-600 text-xs`,children:`✓`})}),m?(0,K.jsx)(`input`,{type:`text`,value:g,onChange:e=>v(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),y()),e.key===`Escape`&&(h(!1),v(t.text))},onBlur:y,onPointerDown:e=>e.stopPropagation(),className:`flex-1 min-w-0 text-[13px] font-medium border border-gray-300 rounded px-1 py-0.5 outline-none focus:border-gray-500`}):(0,K.jsx)(`h4`,{className:`text-[13px] font-medium flex-1 min-w-0 cursor-text ${t.done?`text-gray-400 line-through`:`text-gray-900`}`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),v(t.text),h(!0)},children:(0,K.jsx)(lY,{text:t.text})}),t.priority&&(0,K.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded shrink-0 border ${dY[t.priority]??`bg-gray-50 text-gray-600 border-gray-200`}`,children:t.priority.toUpperCase()})]}),(x.length>0||t.due)&&(0,K.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2 text-[10px]`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-0.5`,children:x.map((e,t)=>(0,K.jsx)(`span`,{className:`w-5 h-5 rounded-full bg-gray-200 text-gray-600 text-[9px] flex items-center justify-center font-medium`,title:e,children:e.slice(0,2).toUpperCase()},t))}),t.due&&(0,K.jsx)(`span`,{className:`text-gray-400 ml-auto`,children:t.due})]}),t.topics.length>0&&(0,K.jsx)(`div`,{className:`mt-1.5 flex items-center gap-1 flex-wrap`,onClick:e=>e.stopPropagation(),children:t.topics.map(e=>(0,K.jsx)(pG,{name:e,onClick:()=>o(`/topic/${encodeURIComponent(e)}`),onEdit:r},e))}),t.subtasks.length>0&&(0,K.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1 h-1 bg-gray-100 rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full bg-emerald-500 transition-all`,style:{width:`${b}%`}})}),(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-gray-500 shrink-0`,children:[t.subtasks.filter(e=>e.done).length,`/`,t.subtasks.length]})]}),t.loopId&&(0,K.jsx)(`div`,{className:`mt-1.5`,children:(0,K.jsxs)(`span`,{className:`text-[10px] font-mono text-gray-400 bg-gray-100 px-1 py-0.5 rounded`,children:[`L:`,t.loopId.slice(0,6)]})})]}),(0,K.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),r()},className:`absolute top-2 right-2 z-10 w-5 h-5 rounded-full bg-white border border-gray-300 text-[10px] text-gray-400 hover:text-gray-700 hover:border-gray-500 opacity-100 sm:opacity-0 sm:group-hover/card:opacity-100 transition-opacity flex items-center justify-center shadow-sm`,title:`Edit card`,children:`✎`}),t.done&&a&&(0,K.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`absolute top-2 right-9 z-10 w-5 h-5 rounded-full bg-white border border-gray-300 text-[10px] text-gray-400 hover:text-orange-600 hover:border-orange-400 opacity-100 sm:opacity-0 sm:group-hover/card:opacity-100 transition-opacity flex items-center justify-center shadow-sm`,title:`Archive card`,children:`◧`})]})}var mY=[``,`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#3b82f6`,`#8b5cf6`,`#ec4899`];function hY({board:e,column:t,cards:n,onCardClick:r,onCardToggle:i,onCardArchive:a,onCardSaved:o,onColumnSaved:s,color:c}){let{setNodeRef:l,isOver:u}=EJ({id:t.id}),{attributes:d,listeners:f,setNodeRef:p,transform:m,transition:h,isDragging:g}=sY({id:`col:${t.id}`,data:{columnId:t.id}}),v=m&&(m.x!==0||m.y!==0)?{transform:`translate3d(${m.x}px, ${m.y}px, 0)`,transition:h}:void 0,[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(``),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(t.label),[j,M]=(0,_.useState)(c??``),[N,P]=(0,_.useState)(!1);async function F(){let n=x.trim();if(!n||C)return;w(!0);let r=await qm(e,t.id,{text:n});w(!1),r.cid&&(S(``),b(!1),o())}async function I(){let n=k.trim();if(!n||n===t.label){O(!1);return}let r=n.toLowerCase().replace(/[^a-z0-9一-鿿]+/g,`-`).replace(/^-|-$/g,``)+`.md`;await ah(e,t.id,r),O(!1),s()}async function L(n){M(n),await sh(e,t.id,n),s()}async function R(){if(confirm(`Delete column "${t.label}" and all its cards?`)){P(!0);for(let r of n)await Qm(e,t.id,r.cid,`archived.md`);await oh(e,t.id),P(!1),O(!1),s()}}return(0,K.jsxs)(`div`,{ref:e=>{p(e),l(e)},...d,style:v,onMouseEnter:()=>E(!0),onMouseLeave:()=>E(!1),onTouchStart:()=>E(!0),className:`w-64 shrink-0 h-full flex flex-col rounded-lg transition-colors ${u?`bg-gray-100`:`bg-gray-50`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-2 shrink-0 select-none rounded-t-lg ${g?`opacity-30`:``}`,children:[(0,K.jsx)(`span`,{...f,className:`text-gray-400 text-[10px] shrink-0 cursor-grab active:cursor-grabbing hover:text-gray-600`,children:`⋮⋮`}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-gray-500 font-medium flex-1 min-w-0 truncate`,children:t.label}),(0,K.jsx)(`span`,{className:`text-[10px] font-mono text-gray-400 bg-gray-200 px-1.5 py-0.5 rounded-full shrink-0`,children:n.length}),T&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),O(!0),A(t.label),M(c??``)},className:`text-[10px] text-gray-400 hover:text-gray-700`,title:`Edit column`,children:`✎`}),(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),R()},className:`text-[10px] text-gray-400 hover:text-red-500`,title:`Delete column`,children:`×`})]})]}),c&&(0,K.jsx)(`div`,{className:`h-0.5 shrink-0 mx-2 rounded`,style:{backgroundColor:c}}),(0,K.jsxs)(`div`,{ref:l,className:`flex-1 min-h-[100px] overflow-y-auto px-1 pb-1 flex flex-col gap-1.5 ${u?`bg-gray-200/50 rounded-b-lg`:``}`,children:[n.length===0&&!y?(0,K.jsx)(`div`,{className:`text-[11px] text-gray-300 italic px-2 py-4 text-center`,children:`drop here`}):n.map(n=>(0,K.jsx)(pY,{board:e,card:n,colFilename:t.id,onClick:()=>r(n),onToggle:()=>i(n),onArchive:()=>a(n)},n.cid)),y&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-300 bg-white px-2 py-1.5`,children:[(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),F()),e.key===`Escape`&&(b(!1),S(``))},onBlur:()=>{x.trim()||(b(!1),S(``))},className:`w-full text-[13px] border-0 outline-none bg-transparent text-gray-900 placeholder:text-gray-400`,placeholder:`Card title…`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1.5`,children:[(0,K.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:F,disabled:!x.trim()||C,className:`px-2 h-6 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:C?`…`:`Add`}),(0,K.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{b(!1),S(``)},className:`text-gray-400 hover:text-gray-600 text-sm`,children:`✕`})]})]})]}),!y&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(!0),className:`mx-1 mb-1 shrink-0 rounded-lg border border-dashed border-gray-300 hover:border-gray-400 text-[11px] text-gray-400 hover:text-gray-600 py-2 transition-colors`,children:`+ Add card`}),D&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:()=>O(!1),children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-xl border border-gray-200 w-full max-w-xs mx-4`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-gray-100`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-gray-900`,children:`Edit Column`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>O(!1),className:`text-gray-400 hover:text-gray-700`,children:`✕`})]}),(0,K.jsxs)(`div`,{className:`px-4 py-3 space-y-3`,children:[(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:`Title`}),(0,K.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&I()},className:`w-full text-[13px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500`})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:`Color`}),(0,K.jsx)(`div`,{className:`flex gap-1.5`,children:mY.map(e=>(0,K.jsx)(`button`,{onClick:()=>L(e),className:`w-6 h-6 rounded-full border-2 ${j===e?`border-gray-900`:`border-gray-200`} ${e?``:`bg-white`}`,style:e?{backgroundColor:e}:void 0,title:e||`none`},e))})]}),(0,K.jsx)(`button`,{onClick:R,disabled:N,className:`w-full text-[12px] text-red-500 hover:text-red-700 text-left`,children:N?`Deleting…`:`Delete column`})]})]})})]})}function gY(e){let t=(0,_.useRef)(null),[n,r]=(0,_.useState)(!1),i=(0,_.useRef)(e);i.current=e;let a=(0,_.useCallback)(()=>{let e=location.protocol===`https:`?`wss:`:`ws:`,n=new WebSocket(`${e}//${location.host}/ws/kanban`);t.current=n,n.onopen=()=>r(!0),n.onmessage=e=>{try{JSON.parse(e.data).type===`kanban_update`&&i.current()}catch{}},n.onclose=()=>{r(!1),t.current=null,setTimeout(a,2e3+Math.random()*3e3)},n.onerror=()=>{n.close()}},[]);return(0,_.useEffect)(()=>(a(),()=>{t.current?.close(),t.current=null}),[a]),n}var _Y=(0,_.forwardRef)(function({board:e,onCardClick:t,onCardArchive:n,showArchived:r},i){let a=bK(yK(xq,{activationConstraint:{distance:5}}),yK(Eq,{activationConstraint:{delay:150,tolerance:5}})),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(!0),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(``),[C,w]=(0,_.useState)(null),T=(0,_.useRef)(!1),E=(0,_.useCallback)(()=>{Promise.all([Km(e),rh(e)]).then(([e,t])=>{let n=[...e].sort((e,n)=>{let r=t.findIndex(t=>t.file===e.filename),i=t.findIndex(e=>e.file===n.filename);return r>=0&&i>=0?r-i:r>=0?-1:i>=0?1:e.title.localeCompare(n.title)});s(n),l(n.map(e=>e.filename)),d(t),p(!1)})},[e]);(0,_.useImperativeHandle)(i,()=>({refresh:E}),[E]),gY(E),(0,_.useEffect)(()=>{E()},[E]);function D(e){for(let t of o){let n=t.cards.findIndex(t=>t.cid===e);if(n>=0)return[t.filename,n]}return null}function O(e){let t=e.active.id;if(t.startsWith(`col:`)){T.current=!0;let e=o.find(e=>e.filename===t.slice(4));e&&v(e)}else{T.current=!1;let t=e.active.data.current?.card;t&&h(t)}}function k(e){if(e.startsWith(`col:`))return e.slice(4);if(P.some(t=>t.filename===e))return e;for(let t of P)if(t.cards.some(t=>t.cid===e))return t.filename;return null}function A(e){if(!T.current){w(null);return}let{active:t,over:n,collisions:r}=e;if(!n){w(null);return}let i=k(n.id);if(!i){w(null);return}let a=P.findIndex(e=>e.filename===i);if(a<0){w(null);return}let o=k(t.id),s=o?P.findIndex(e=>e.filename===o):-1;if(s<0){w(null);return}if(s===a){w(null);return}let c=r?.[0];if(!c){w(null);return}let l=(t.rect.current.translated?t.rect.current.translated.left+(t.rect.current.translated.width??0)/2:0)<(c.data?.droppableRect?c.data.droppableRect.left+c.data.droppableRect.width/2:0)?a:a+1;w(l>=0&&l<=P.length?l:null)}function j(t){h(null),v(null),w(null),T.current=!1;let{active:n,over:r}=t;if(!r)return;let i=n.id;if(i.startsWith(`col:`)){let a=i.slice(4),o=k(r.id);if(!o||a===o)return;let u=c.indexOf(a),d=c.indexOf(o);if(u<0||d<0)return;let f=t.collisions?.[0],p=(n.rect.current.translated?n.rect.current.translated.left+(n.rect.current.translated.width??0)/2:0)<(f?.data?.droppableRect?f.data.droppableRect.left+f.data.droppableRect.width/2:0)?d:d+1,m=Math.max(0,Math.min(p,c.length-1));if(m===u)return;let h=zJ([...c],u,m);l(h),s(e=>{let t=[...e];return t.sort((e,t)=>{let n=h.indexOf(e.filename),r=h.indexOf(t.filename);return n>=0&&r>=0?n-r:n>=0?-1:+(r>=0)}),t}),ih(e,h);return}let a=i,u=D(a);if(!u)return;let[d,f]=u,p=null,m;if(o.some(e=>e.filename===r.id)||r.id.startsWith(`col:`))p=r.id.startsWith(`col:`)?r.id.slice(4):r.id;else{let e=D(r.id);e&&(p=e[0],m=e[1])}if(p){if(s(e=>{let t=e.map(e=>({...e,cards:[...e.cards]})),n=t.find(e=>e.filename===d),r=t.find(e=>e.filename===p),i=n.cards.findIndex(e=>e.cid===a);if(i<0)return t;if(d===p){let e=m??r.cards.length-1;i!==e&&(r.cards=zJ(r.cards,i,e))}else{let[e]=n.cards.splice(i,1);m===void 0?r.cards.push(e):r.cards.splice(m,0,e)}return t}),d!==p)Qm(e,d,a,p,m);else if(d===p&&m!==void 0&&f!==m){let t=o.find(e=>e.filename===d);if(t){let n=[...t.cards],[r]=n.splice(f,1),i=m>f?m-1:m;n.splice(i,0,r),ch(e,d,n.map(e=>e.cid))}}}}function M(t,n){let r=!n.done;s(e=>e.map(e=>e.filename===t?{...e,cards:e.cards.map(e=>e.cid===n.cid?{...e,done:r}:e)}:e)),Jm(e,t,n.cid)}async function N(){let t=x.trim();t&&await $m(e,t)&&(b(!1),S(``),E())}let P=o.filter(e=>r||e.filename!==`archived.md`);return o.some(e=>e.filename===`archived.md`),f?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`})}):o.reduce((e,t)=>e+t.cards.length,0)===0&&o.length===0?(0,K.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3 text-gray-500`,children:[(0,K.jsxs)(`div`,{className:`text-[13px]`,children:[`no kanban columns in notes/focus/boards/`,e,`/`]}),y?(0,K.jsxs)(`div`,{className:`w-56 bg-gray-50 rounded-lg p-3 space-y-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&N()},className:`w-full text-[13px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500`,placeholder:`Column name`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`button`,{onClick:N,disabled:!x.trim(),className:`px-2.5 h-7 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`Create`}),(0,K.jsx)(`button`,{onClick:()=>{b(!1),S(``)},className:`px-2.5 h-7 rounded text-[11px] text-gray-500 hover:bg-gray-200`,children:`✕`})]})]}):(0,K.jsx)(`button`,{onClick:()=>b(!0),className:`px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`+ Create first column`})]})}):(0,K.jsxs)(vJ,{sensors:a,collisionDetection:OK,onDragStart:O,onDragOver:A,onDragEnd:j,children:[(0,K.jsx)($J,{items:P.map(e=>`col:${e.filename}`),strategy:GJ,children:(0,K.jsxs)(`div`,{className:`h-full flex gap-3 px-3 py-3 overflow-x-auto`,children:[P.map((r,i)=>{let a=u.find(e=>e.file===r.filename);return[C===i&&(0,K.jsx)(`div`,{className:`w-0.5 shrink-0 bg-blue-500 rounded-full self-stretch`},`indicator-${r.filename}`),(0,K.jsx)($J,{items:r.cards.map(e=>e.cid),strategy:YJ,children:(0,K.jsx)(hY,{board:e,column:{id:r.filename,label:r.title},cards:r.cards,onCardClick:e=>t(e,r.filename),onCardToggle:e=>M(r.filename,e),onCardArchive:e=>n(e,r.filename),onCardSaved:E,onColumnSaved:E,color:a?.color})},r.filename)]}),C===P.length&&(0,K.jsx)(`div`,{className:`w-0.5 shrink-0 bg-blue-500 rounded-full self-stretch`},`indicator-end`),y?(0,K.jsxs)(`div`,{className:`w-56 shrink-0 bg-gray-50 rounded-lg p-3 space-y-2 h-fit`,children:[(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&N()},className:`w-full text-[13px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500`,placeholder:`Column name`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`button`,{onClick:N,disabled:!x.trim(),className:`px-2.5 h-7 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`Create`}),(0,K.jsx)(`button`,{onClick:()=>{b(!1),S(``)},className:`px-2.5 h-7 rounded text-[11px] text-gray-500 hover:bg-gray-200`,children:`✕`})]})]}):(0,K.jsx)(`button`,{onClick:()=>b(!0),className:`w-56 shrink-0 h-fit rounded-lg border border-dashed border-gray-300 bg-gray-50 hover:bg-gray-100 py-3 text-[12px] text-gray-400`,children:`+ New Column`})]})}),(0,K.jsx)(RJ,{children:m?(0,K.jsx)(`div`,{className:`rotate-2 w-64`,children:(0,K.jsx)(fY,{card:m})}):g?(0,K.jsxs)(`div`,{className:`w-64 shrink-0 flex flex-col rounded-lg bg-gray-50 shadow-xl opacity-90 min-h-[120px]`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,K.jsx)(`span`,{className:`text-gray-400 text-[10px] shrink-0`,children:`⋮⋮`}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-gray-500 font-medium`,children:g.title}),(0,K.jsx)(`span`,{className:`text-[10px] font-mono text-gray-400 bg-gray-200 px-1.5 py-0.5 rounded-full`,children:g.cards.length})]}),(0,K.jsx)(`div`,{className:`flex-1 px-1 pb-1 flex flex-col gap-1.5`,children:g.cards.length===0?(0,K.jsx)(`div`,{className:`text-[11px] text-gray-300 italic px-2 py-4 text-center`,children:`drop here`}):g.cards.map(e=>(0,K.jsx)(fY,{card:e},e.cid))})]}):null})]})});function vY(e,t,n,r,i,a,o,s){let c=[`- [${t?`x`:` `}] ${e}${s.length>0?` `+s.map(e=>`#${e}`).join(` `):``}`];if(n&&c.push(` > priority: ${n}`),r&&c.push(` > assignee: ${r}`),i&&c.push(` > due: ${i}`),a)for(let e of a.split(`
|
|
113
113
|
`))c.push(` ${e}`);for(let e of o){let t=e.done?`x`:` `;c.push(` - [${t}] ${e.text}`)}return c.join(`
|
|
114
|
-
`)}function vY({board:e,card:t,colFilename:n,onClose:r,onSaved:i,onDeleted:a}){let o=Cg(),s=zn(),c=!!o.currentUser,[l,u]=(0,_.useState)(t.text),[d,f]=(0,_.useState)(t.done),[p,m]=(0,_.useState)(t.priority??``),[h,g]=(0,_.useState)(t.assignee??``),[v,y]=(0,_.useState)(t.due??``),[b,x]=(0,_.useState)(t.description),[S,C]=(0,_.useState)(t.subtasks.map(e=>({...e}))),[w,T]=(0,_.useState)(t.topics??[]),[E,D]=(0,_.useState)(``),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(!1),[M,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)(!1);function I(e){C(t=>t.map((t,n)=>n===e?{...t,done:!t.done}:t))}function L(e,t){C(n=>n.map((n,r)=>r===e?{...n,text:t}:n))}function R(e){C(t=>t.filter((t,n)=>n!==e))}function z(){C(e=>[...e,{text:``,done:!1}])}function B(){let e=E.trim().replace(/^#/,``);e&&!w.includes(e)&&(T([...w,e]),D(``))}function V(e){T(w.filter(t=>t!==e))}async function H(){j(!0);let a=_Y(l.trim()||t.text,d,p,h.trim(),v.trim(),b.trim(),S,w);await Xm(e,n,t.cid,a),j(!1),i(),r()}async function U(){await Jm(e,n,t.cid),f(e=>!e)}async function ee(){confirm(`Delete this card?`)&&(N(!0),await Zm(e,n,t.cid),N(!1),a())}async function W(){F(!0);let r=await lh(e,n,t.cid);F(!1),r.ok?i():alert(`No associated loop on this card`)}function te(){r(),o.setNewLoopDialogOpen(!0,t.text,{board:e,filename:n,cid:t.cid})}return(0,K.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/30 flex items-center justify-center`,onClick:r,children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-xl border border-gray-200 w-full max-w-lg max-h-[90vh] overflow-y-auto mx-4`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2 px-4 py-3 border-b border-gray-100`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:U,className:`shrink-0 mt-0.5 w-4 h-4 rounded border flex items-center justify-center text-xs hover:border-gray-500 ${d?`bg-emerald-50 border-emerald-400 text-emerald-600`:`border-gray-300`}`,children:d?`✓`:``}),(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),className:`flex-1 text-[14px] font-medium border-0 outline-none bg-transparent ${d?`text-gray-400 line-through`:`text-gray-900`}`}),(0,K.jsx)(`button`,{onClick:r,className:`text-gray-400 hover:text-gray-700 text-sm shrink-0`,children:`✕`})]}),(0,K.jsxs)(`div`,{className:`px-4 py-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:`Subtasks`}),S.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>I(t),className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center text-[10px] hover:border-gray-500 ${e.done?`bg-emerald-50 border-emerald-400 text-emerald-600`:`border-gray-300`}`,children:e.done?`✓`:``}),(0,K.jsx)(`input`,{type:`text`,value:e.text,onChange:e=>L(t,e.target.value),className:`flex-1 text-[12px] border border-gray-200 rounded px-1.5 py-0.5 outline-none focus:border-gray-400 ${e.done?`text-gray-400 line-through`:`text-gray-700`}`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>R(t),className:`text-gray-400 hover:text-red-500 text-sm shrink-0`,children:`×`})]},t)),(0,K.jsx)(`button`,{type:`button`,onClick:z,className:`flex items-center gap-1 text-[11px] text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded px-2 py-0.5 -ml-1 transition-colors`,children:`+ Add subtask`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:`Tags`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[w.map(e=>(0,K.jsx)(fG,{name:e,onClick:()=>s(`/topic/${encodeURIComponent(e)}`),onEdit:()=>V(e)},e)),O?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),B(),k(!1)),e.key===`Escape`&&(k(!1),D(``))},onBlur:()=>{k(!1),D(``)},className:`w-20 text-[11px] border border-gray-300 rounded px-1.5 py-0.5 outline-none focus:border-gray-400`,placeholder:`tag`}),(0,K.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{B(),k(!1)},className:`text-[11px] text-gray-500 hover:text-gray-700`,children:`Add`})]}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>k(!0),className:`flex items-center gap-1 text-[11px] text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded px-2 py-0.5 transition-colors`,children:`+ Add tag`})]})]}),(0,K.jsx)(`div`,{className:`border-t border-gray-100`}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsx)(yY,{label:`Priority`,children:(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full text-[12px] border border-gray-300 rounded px-2 py-1 outline-none focus:border-gray-500`,children:[(0,K.jsx)(`option`,{value:``,children:`---`}),(0,K.jsx)(`option`,{value:`P0`,children:`P0`}),(0,K.jsx)(`option`,{value:`P1`,children:`P1`}),(0,K.jsx)(`option`,{value:`P2`,children:`P2`}),(0,K.jsx)(`option`,{value:`P3`,children:`P3`})]})}),(0,K.jsx)(yY,{label:`Assignee`,children:(0,K.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),className:`w-full text-[12px] border border-gray-300 rounded px-2 py-1 outline-none focus:border-gray-500`,placeholder:`alice, bob`})}),(0,K.jsx)(yY,{label:`Due`,children:(0,K.jsx)(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),className:`w-full text-[12px] border border-gray-300 rounded px-2 py-1 outline-none focus:border-gray-500`,placeholder:`2026-05-20`})})]}),(0,K.jsx)(yY,{label:`Description`,children:(0,K.jsx)(`textarea`,{value:b,onChange:e=>x(e.target.value),rows:3,className:`w-full text-[12px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500 resize-none`,placeholder:`Notes…`})}),t.loopId&&(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-400`,children:[`Loop: `,(0,K.jsx)(`button`,{onClick:()=>{let e=t.loopId;s(`/loop/${o.loops.find(t=>t.id===e||t.id.startsWith(e))?.id??e}`)},className:`text-blue-700 hover:underline font-mono`,children:t.loopId.slice(0,8)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-t border-gray-100`,children:[c&&(0,K.jsx)(`button`,{type:`button`,disabled:P,onClick:W,className:`px-2.5 h-7 rounded text-[11px] border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-50`,children:P?(0,K.jsx)(Be,{size:12,className:`animate-spin`}):`Assign Driver`}),c&&(0,K.jsx)(`button`,{type:`button`,onClick:te,className:`px-2.5 h-7 rounded text-[11px] border border-gray-200 hover:bg-gray-100 text-gray-700`,children:`Create Loop`}),(0,K.jsx)(`div`,{className:`flex-1`}),c&&(0,K.jsx)(`button`,{type:`button`,disabled:A,onClick:H,className:`px-3 h-7 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:A?(0,K.jsx)(Be,{size:12,className:`animate-spin`}):`Save`}),c&&(0,K.jsx)(`button`,{type:`button`,disabled:M,onClick:ee,className:`px-2.5 h-7 rounded text-[11px] text-red-600 hover:bg-red-50 disabled:opacity-50`,children:M?(0,K.jsx)(Be,{size:12,className:`animate-spin`}):`Delete`})]})]})})}function yY({label:e,children:t}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:e}),t]})}var bY=`archived.md`;function xY(){let{board:e=`default`}=Un(),t=zn(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),y=(0,_.useRef)(null),b=(0,_.useRef)(null),x=(0,_.useCallback)(()=>b.current?.refresh(),[]),[S,C]=(0,_.useState)(0),[w,T]=(0,_.useState)(!1);(0,_.useEffect)(()=>{let e=()=>Mm().then(C).catch(()=>{});e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]);let E=(0,_.useCallback)(async()=>{T(!0),await Nm().catch(()=>{}),T(!1),C(0),b.current?.refresh()},[]),D=(0,_.useCallback)(async()=>{T(!0);let e=await jm();T(!1),e.ok||(e.conflict?alert(`保存了本地,但和远端冲突 (${(e.files??[]).join(`, `)})。本地保留——去 Notes 里 take remote 或手动解决。`):alert(`推送到远端失败:${e.error??`unknown`}`))},[]);(0,_.useEffect)(()=>{eh().then(l)},[e]);function O(){a(null),y.current&&clearTimeout(y.current)}function k(e){O(),a(e),y.current=setTimeout(O,1e4)}(0,_.useEffect)(()=>()=>{y.current&&clearTimeout(y.current)},[]);async function A(t,n){await $m(e,`archived`),await Qm(e,n,t.cid,bY)&&(k({cid:t.cid,card:t,fromFile:n,toFile:bY}),x())}async function j(){i&&(await Qm(e,i.toFile,i.cid,i.fromFile),O(),x())}async function M(){let e=f.trim();e&&await th(e)&&(d(!1),p(``),l(await eh()),t(`/kanban/${encodeURIComponent(e)}`))}async function N(e){let n=g.trim();if(!n||n===e){h(``);return}await nh(e,n)&&(h(``),v(``),l(await eh()),t(`/kanban/${encodeURIComponent(n)}`))}return(0,K.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-white`,children:[(0,K.jsxs)(`div`,{className:`h-9 shrink-0 flex items-center gap-1 px-3 border-b border-gray-200 overflow-x-auto`,children:[c.map(n=>(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/kanban/${encodeURIComponent(n)}`),className:`shrink-0 h-7 px-3 rounded text-[12px] transition-colors whitespace-nowrap ${n===e?`bg-gray-900 text-white`:`text-gray-500 hover:text-gray-900 hover:bg-gray-100`}`,children:n}),n===e&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h(n),v(n)},className:`absolute -top-0.5 -right-1 w-4 h-4 rounded-full bg-white border border-gray-300 text-[9px] text-gray-400 hover:text-gray-700 hidden group-hover:flex items-center justify-center shadow-sm`,title:`Rename board`,children:`✎`})]},n)),u?(0,K.jsx)(`span`,{className:`inline-flex items-center gap-1 ml-1 shrink-0`,children:(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&M(),e.key===`Escape`&&(d(!1),p(``))},onBlur:()=>{f.trim()||(d(!1),p(``))},className:`w-24 h-7 px-2 text-[12px] border border-gray-300 rounded outline-none focus:border-gray-500`,placeholder:`board name`})}):(0,K.jsx)(`button`,{onClick:()=>d(!0),className:`shrink-0 h-7 px-2 rounded text-[12px] text-gray-400 hover:text-gray-600 hover:bg-gray-100 ml-1`,title:`New board`,children:`+`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:D,disabled:w,className:`shrink-0 text-[11px] px-2 py-0.5 rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50 transition-colors`,title:`保存并推送到远端`,children:w?`…`:`保存`}),S>0&&(0,K.jsxs)(`span`,{className:`shrink-0 text-[11px] px-1.5 py-0.5 rounded bg-amber-100 text-amber-800`,title:`远端有更新,点 ↻ 拉取`,children:[`远端 +`,S]}),(0,K.jsx)(`button`,{onClick:E,disabled:w,className:`shrink-0 text-[11px] px-2 py-0.5 rounded border border-gray-200 text-gray-500 hover:text-gray-700 transition-colors disabled:opacity-50`,title:`拉取远端最新并刷新`,children:`↻`}),(0,K.jsx)(`button`,{onClick:()=>s(e=>!e),className:`text-[11px] px-2 py-0.5 rounded border transition-colors shrink-0 ${o?`border-gray-400 bg-gray-200 text-gray-700`:`border-gray-200 text-gray-500 hover:text-gray-700`}`,children:o?`Hide archived`:`Archived`}),(0,K.jsxs)(`button`,{onClick:()=>t(`/context/notes?file=focus/boards/${encodeURIComponent(e)}`),className:`shrink-0 text-[11px] text-gray-500 hover:text-gray-900 ml-2`,title:`edit files in notes/focus/`,children:[(0,K.jsxs)(`code`,{className:`text-gray-700`,children:[`notes/focus/boards/`,e,`/`]}),(0,K.jsx)(`span`,{children:` ↗`})]})]}),m&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:()=>h(``),children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-xl border border-gray-200 w-full max-w-xs mx-4`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100`,children:(0,K.jsx)(`span`,{className:`text-sm font-medium text-gray-900`,children:`Rename board`})}),(0,K.jsxs)(`div`,{className:`px-4 py-3 space-y-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:g,onChange:e=>v(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&N(m),e.key===`Escape`&&h(``)},className:`w-full text-[13px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>N(m),disabled:!g.trim(),className:`px-2.5 h-7 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`Rename`}),(0,K.jsx)(`button`,{onClick:()=>h(``),className:`px-2.5 h-7 rounded text-[11px] text-gray-500 hover:bg-gray-200`,children:`Cancel`})]})]})]})}),(0,K.jsx)(`main`,{className:`flex-1 min-h-0 overflow-hidden relative`,children:(0,K.jsx)(gY,{ref:b,board:e,onCardClick:(e,t)=>r({card:e,filename:t}),onCardArchive:A,showArchived:o})},e),n&&(0,K.jsx)(vY,{board:e,card:n.card,colFilename:n.filename,onClose:()=>r(null),onSaved:x,onDeleted:()=>{r(null),x()}}),i&&(0,K.jsxs)(`div`,{className:`fixed bottom-4 left-4 z-50 bg-white border border-gray-300 rounded-lg shadow-lg px-4 py-2.5 flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-[12px] text-gray-600`,children:`Card archived`}),(0,K.jsx)(`button`,{onClick:j,className:`text-[12px] text-blue-600 hover:text-blue-800 font-medium`,children:`Undo`}),(0,K.jsx)(`button`,{onClick:O,className:`text-gray-400 hover:text-gray-600 text-sm`,children:`✕`})]})]})}function SY(e){let t=(0,_.useRef)(null),[n,r]=(0,_.useState)(!1),i=(0,_.useRef)(e);i.current=e;let a=(0,_.useRef)(new Set),o=(0,_.useCallback)(e=>{let n=t.current;n&&n.readyState===WebSocket.OPEN&&n.send(JSON.stringify(e))},[]),s=(0,_.useCallback)(e=>{a.current.has(e)||(a.current.add(e),o({type:`subscribe`,convId:e}))},[o]),c=(0,_.useCallback)(e=>{a.current.has(e)&&(a.current.delete(e),o({type:`unsubscribe`,convId:e}))},[o]),l=(0,_.useCallback)(()=>{let e=location.protocol===`https:`?`wss:`:`ws:`,n=new WebSocket(`${e}//${location.host}/ws/chat`);t.current=n,n.onopen=()=>{r(!0);for(let e of a.current)try{n.send(JSON.stringify({type:`subscribe`,convId:e}))}catch{}mh().then(e=>{let t=vh();e.commit!==`unknown`&&t.commit!==`unknown`&&e.commit!==t.commit&&window.dispatchEvent(new CustomEvent(`loopat:version-mismatch`,{detail:{commit:e.commit}}))}).catch(()=>{})},n.onmessage=e=>{try{let t=JSON.parse(e.data);if(t.type===`chat_connected`)return;(t.type===`message`||t.type===`conv_created`||t.type===`conv_deleted`)&&i.current(t)}catch{}},n.onclose=()=>{r(!1),t.current=null,setTimeout(l,2e3+Math.random()*3e3)},n.onerror=()=>{}},[]);return(0,_.useEffect)(()=>(l(),()=>{let e=t.current;e&&(e.readyState===WebSocket.CONNECTING?(e.onopen=()=>e.close(),e.onmessage=null,e.onclose=null,e.onerror=null):(e.onclose=null,e.onerror=null,e.close())),t.current=null}),[l]),{connected:n,subscribe:s,unsubscribe:c}}function CY(){return`tmp-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function wY(e){let t=new Date(e),n=new Date,r=t.toDateString()===n.toDateString(),i=new Date(n.getTime()-864e5).toDateString()===t.toDateString(),a=t.toTimeString().slice(0,5);return r?a:i?`yesterday ${a}`:`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)} ${a}`}function TY(e){return e.kind===`channel`?e.name??`(unnamed)`:e.peerUserId??`(unknown)`}function EY(e){return e.kind===`channel`?`#`:`@`}function DY(){let e=Cg(),t=e.currentUser?.id??``,n=e.currentUser?.role===`admin`,r=zn(),{convId:i}=Un(),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)([]),[v,y]=(0,_.useState)([]),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(``),[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(!1),[M,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)(!1),I=lU(),L=(0,_.useRef)(null),R=(0,_.useRef)(null),z=(0,_.useRef)(i);z.current=i;let B=(0,_.useRef)(null);B.current=b;let[V,H]=(0,_.useState)(10),U=l.slice(-V),ee=l.length>V,W=(0,_.useCallback)(()=>{H(e=>e+20)},[]),te=(0,_.useRef)(W);te.current=W;let ne=(0,_.useRef)(ee);ne.current=ee;let G=(0,_.useMemo)(()=>a.find(e=>e.id===i),[a,i]),re=(0,_.useMemo)(()=>a.filter(e=>e.kind===`channel`).sort((e,t)=>(e.name??``).localeCompare(t.name??``)),[a]),ie=(0,_.useMemo)(()=>a.filter(e=>e.kind===`dm`).sort((e,t)=>(t.lastMessageTs??0)-(e.lastMessageTs??0)),[a]),ae=(0,_.useCallback)(async()=>{o(await Wh())},[]),oe=(0,_.useCallback)(async()=>{c(await Gh())},[]);(0,_.useEffect)(()=>{ae(),oe()},[ae,oe]);let se=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!i)return;x(null),C(null),H(10),se.current=null,le.current=!1;let e=!1;return Yh(i,{limit:100}).then(t=>{if(e)return;se.current=i,u(t);let n=t[t.length-1];n&&(Qh(i,n.id).catch(()=>{}),o(e=>e.map(e=>e.id===i?{...e,unread:0}:e)),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:i}})))}),()=>{e=!0}},[i]),(0,_.useEffect)(()=>{if(b==null){C(null);return}let e=!1;return C(null),Xh(b).then(t=>{e||C(t)}),()=>{e=!0}},[b]),(0,_.useEffect)(()=>{if(i||a.length===0)return;let e=re[0]??a[0];e&&r(`/chat/${e.id}`,{replace:!0})},[i,a,re,r]);let ce=(0,_.useRef)(!1);(0,_.useEffect)(()=>{L.current?.scrollIntoView({behavior:ce.current?`smooth`:`auto`}),ce.current=!0},[l,V]),(0,_.useEffect)(()=>{R.current?.scrollIntoView({behavior:`smooth`})},[S?.replies.length]);let le=(0,_.useRef)(!1),ue=(0,_.useRef)(null);(0,_.useEffect)(()=>{H(10),le.current=!1},[i]),(0,_.useEffect)(()=>{if(!i||l.length===0||se.current!==i||le.current)return;le.current=!0,H(e=>e+20),requestAnimationFrame(()=>{L.current?.scrollIntoView({behavior:`auto`})});let e=ue.current;if(!e)return;let t=null,n=()=>{t&&clearTimeout(t),t=setTimeout(()=>{e.scrollTop<60&&ne.current&&(te.current(),requestAnimationFrame(()=>{L.current?.scrollIntoView({behavior:`auto`})}))},400)};return e.addEventListener(`scroll`,n,{passive:!0}),()=>{e.removeEventListener(`scroll`,n),t&&clearTimeout(t)}},[i,l]);let{subscribe:de,unsubscribe:fe}=SY((0,_.useCallback)(e=>{if(e.type===`message`){let n=e.message;n.convId===z.current?(n.parentId==null?u(e=>e.some(e=>e.id===n.id)?e:[...e,{...n,replyCount:0,lastReplyTs:null}]):(u(e=>e.map(e=>e.id===n.parentId?{...e,replyCount:e.replyCount+1,lastReplyTs:n.ts}:e)),B.current===n.parentId&&C(e=>e&&!e.replies.some(e=>e.id===n.id)?{...e,replies:[...e.replies,n]}:e)),Qh(n.convId,n.id).catch(()=>{})):n.author!==t&&o(e=>e.map(e=>e.id===n.convId?{...e,unread:e.unread+1,lastMessageTs:n.ts}:e))}else e.type===`conv_created`?o(t=>t.some(t=>t.id===e.conv.id)?t:[...t,e.conv]):e.type===`conv_deleted`&&(o(t=>t.filter(t=>t.id!==e.convId)),z.current===e.convId&&r(`/chat`,{replace:!0}))},[r,t]));(0,_.useEffect)(()=>{for(let e of a)de(e.id);return()=>{for(let e of a)fe(e.id)}},[a,de,fe]);let pe=async(e,t,n)=>{g(e=>e.map(e=>e.tempId===t?{...e,status:`pending`,error:void 0}:e));let r=await Zh(n,e);if(r.message){let e=r.message;g(e=>e.filter(e=>e.tempId!==t)),u(t=>t.some(t=>t.id===e.id)?t:[...t,{...e,replyCount:0,lastReplyTs:null}])}else g(e=>e.map(e=>e.tempId===t?{...e,status:`failed`,error:r.error??`send failed`}:e))},me=async()=>{let e=d.trim();if(!e||!i||p)return;m(!0);let t=CY();g(n=>[...n,{tempId:t,convId:i,parentId:null,text:e,ts:Date.now(),status:`pending`}]),f(``),await pe(e,t,i),m(!1)},he=e=>{e.convId&&pe(e.text,e.tempId,e.convId).catch(()=>{})},ge=e=>{g(t=>t.filter(t=>t.tempId!==e))},_e=async(e,t,n,r)=>{y(e=>e.map(e=>e.tempId===t?{...e,status:`pending`,error:void 0}:e));let i=await Zh(n,e,r);if(i.message){let e=i.message;y(e=>e.filter(e=>e.tempId!==t)),C(t=>t&&!t.replies.some(t=>t.id===e.id)?{...t,replies:[...t.replies,e]}:t)}else y(e=>e.map(e=>e.tempId===t?{...e,status:`failed`,error:i.error??`send failed`}:e))},ve=async()=>{let e=w.trim();if(!e||!i||!S||E)return;D(!0);let t=CY();y(n=>[...n,{tempId:t,convId:i,parentId:S.root.id,text:e,ts:Date.now(),status:`pending`}]),T(``),await _e(e,t,i,S.root.id),D(!1)},ye=e=>{!e.convId||e.parentId==null||_e(e.text,e.tempId,e.convId,e.parentId).catch(()=>{})},be=e=>{y(t=>t.filter(t=>t.tempId!==e))},xe=async()=>{if(!S||O)return;k(!0);let t=await $h(S.root.id);t.loopId?(await e.refresh(),k(!1),r(`/loop/${t.loopId}`)):(k(!1),t.error&&console.error(`spawn failed:`,t.error))},Se=async(e,t)=>{let n=await Kh(e,t||void 0);n.conv?(N(!1),r(`/chat/${n.conv.id}`),ae()):n.error&&alert(n.error)},Ce=async e=>{if(!n||!confirm(`Delete this channel? Messages will be archived but hidden.`))return;let t=await qh(e);!t.ok&&t.error&&alert(t.error)},we=async e=>{let t=await Jh(e);t.conv?(j(!1),r(`/chat/${t.conv.id}`),ae()):t.error&&alert(t.error)},Te=(0,K.jsxs)(`aside`,{className:`w-60 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[I&&(0,K.jsxs)(`div`,{className:`h-9 flex items-center px-3 border-b border-gray-200`,children:[(0,K.jsx)(`button`,{onClick:()=>F(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,K.jsx)(Pe,{size:14})}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500 font-medium`,children:`Chat`})]}),(0,K.jsxs)(`div`,{className:I?`flex-1 min-h-0 overflow-auto py-2`:``,children:[(0,K.jsxs)(`div`,{className:`px-3 mt-3 mb-1 text-xs text-gray-500 flex items-center justify-between`,children:[(0,K.jsx)(`span`,{children:`Channels`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>N(!0),className:`text-gray-500 hover:text-gray-900 text-base leading-none`,title:`new channel`,children:`+`})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[re.map(e=>(0,K.jsx)(kY,{conv:e,active:e.id===i,onClick:()=>{r(`/chat/${e.id}`),I&&F(!1)},onDelete:n?()=>Ce(e.id):void 0},e.id)),re.length===0&&(0,K.jsx)(`div`,{className:`mx-2 px-2 py-1 text-[11px] text-gray-400`,children:`no channels yet`})]}),(0,K.jsxs)(`div`,{className:`px-3 mt-4 mb-1 text-xs text-gray-500 flex items-center justify-between`,children:[(0,K.jsx)(`span`,{children:`Direct messages`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>j(!0),className:`text-gray-500 hover:text-gray-900 text-base leading-none`,title:`new DM`,children:`+`})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[ie.map(e=>(0,K.jsx)(kY,{conv:e,active:e.id===i,onClick:()=>{r(`/chat/${e.id}`),I&&F(!1)}},e.id)),ie.length===0&&(0,K.jsx)(`div`,{className:`mx-2 px-2 py-1 text-[11px] text-gray-400`,children:`no DMs yet`})]})]}),(0,K.jsx)(`div`,{className:`flex-1`})]});return(0,K.jsxs)(`div`,{className:`flex h-full w-full bg-white`,children:[I?(0,K.jsx)(K.Fragment,{children:P?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>F(!1),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-60 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:Te})]}):(0,K.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>F(!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 sidebar`,children:(0,K.jsx)(Fe,{size:16})})})}):Te,(0,K.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white`,children:G?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`header`,{className:`px-5 h-12 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsxs)(`span`,{className:`text-[15px] font-medium text-gray-900 truncate`,children:[EY(G),TY(G)]}),G.topic&&(0,K.jsxs)(`span`,{className:`text-xs text-gray-500 truncate`,children:[`— `,G.topic]})]})}),(0,K.jsxs)(`div`,{ref:ue,className:`flex-1 min-h-0 overflow-auto px-5 py-4 flex flex-col gap-3 chat-messages-container`,children:[l.length===0&&(0,K.jsx)(`div`,{className:`text-[13px] text-gray-500`,children:`no messages yet — say hi`}),U.map(e=>(0,K.jsx)(AY,{message:e,isMe:e.author===t,active:e.id===b,onOpenThread:()=>x(e.id)},e.id)),h.filter(e=>e.convId===i).map(e=>(0,K.jsx)(jY,{pending:e,author:t,onRetry:()=>he(e),onDiscard:()=>ge(e.tempId)},e.tempId)),(0,K.jsx)(`div`,{ref:L})]}),(0,K.jsx)(`div`,{className:`px-5 pb-4 pt-2 shrink-0`,children:(0,K.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white p-2.5 shadow-sm flex flex-col gap-2`,children:[(0,K.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),me())},rows:1,placeholder:`Message ${EY(G)}${TY(G)}…`,className:`field-sizing-content w-full max-h-40 min-h-10 resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 pt-2 px-0.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400`,children:`Enter to send · Shift+Enter for newline`}),(0,K.jsx)(`button`,{type:`button`,onClick:me,disabled:p||!d.trim(),className:`px-3 py-1 rounded bg-gray-900 text-white text-xs hover:bg-gray-700 disabled:opacity-40`,children:`send`})]})]})})]}):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-500 text-sm`,children:`select a conversation`})}),G&&b!=null&&(0,K.jsx)(OY,{isMobile:I,thread:S,me:t,spawning:O,threadDraft:w,threadSending:E,pendingReplies:v,threadEndRef:R,onClose:()=>x(null),onSpawnLoop:xe,onThreadDraftChange:T,onThreadSend:ve,onRetryReply:ye,onDiscardReply:be}),M&&(0,K.jsx)(MY,{onClose:()=>N(!1),onCreate:Se}),A&&(0,K.jsx)(NY,{users:s,existing:ie,onClose:()=>j(!1),onPick:we})]})}function OY({isMobile:e,thread:t,me:n,spawning:r,threadDraft:i,threadSending:a,pendingReplies:o,threadEndRef:s,onClose:c,onSpawnLoop:l,onThreadDraftChange:u,onThreadSend:d,onRetryReply:f,onDiscardReply:p}){let m=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`header`,{className:`px-4 h-12 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:[(0,K.jsx)(`div`,{className:`text-[13px] font-medium text-gray-900`,children:`Thread`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:l,disabled:r||!t,className:`px-2 py-1 rounded border border-gray-200 text-[11px] text-gray-700 hover:bg-gray-50 hover:border-gray-300 disabled:opacity-50 flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-gray-500`,children:`⑂`}),(0,K.jsx)(`span`,{children:r?`spawning…`:`spawn loop`})]}),(0,K.jsx)(`button`,{type:`button`,onClick:c,className:`text-gray-400 hover:text-gray-900 text-base leading-none px-1`,children:`×`})]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto px-4 py-3 flex flex-col gap-3`,children:t===null?(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(AY,{message:t.root,isMe:t.root.author===n,compact:!0}),t.replies.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-gray-400`,children:[(0,K.jsx)(`span`,{className:`flex-1 h-px bg-gray-200`}),(0,K.jsxs)(`span`,{children:[t.replies.length,` `,t.replies.length===1?`reply`:`replies`]}),(0,K.jsx)(`span`,{className:`flex-1 h-px bg-gray-200`})]}),t.replies.map(e=>(0,K.jsx)(AY,{message:e,isMe:e.author===n,compact:!0},e.id)),o.filter(e=>t&&e.parentId===t.root.id).map(e=>(0,K.jsx)(jY,{pending:e,author:n,compact:!0,onRetry:()=>f(e),onDiscard:()=>p(e.tempId)},e.tempId)),(0,K.jsx)(`div`,{ref:s})]})}),(0,K.jsx)(`div`,{className:`px-4 pb-4 pt-2 shrink-0`,children:(0,K.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white p-2.5 shadow-sm flex flex-col gap-2`,children:[(0,K.jsx)(`textarea`,{value:i,onChange:e=>u(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),d())},rows:1,placeholder:`Reply…`,className:`field-sizing-content w-full max-h-40 min-h-10 resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 pt-2 px-0.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400`,children:`Enter to reply · Shift+Enter for newline`}),(0,K.jsx)(`button`,{type:`button`,onClick:d,disabled:a||!i.trim()||!t,className:`px-3 py-1 rounded bg-gray-900 text-white text-xs hover:bg-gray-700 disabled:opacity-40`,children:`reply`})]})]})})]});return e?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:c,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-full max-w-full bg-white border-l border-gray-200 shadow-xl flex flex-col`,onClick:e=>e.stopPropagation(),children:m})]}):(0,K.jsx)(`aside`,{className:`w-[28rem] max-w-[40vw] min-w-[20rem] shrink-0 border-l border-gray-200 bg-white flex flex-col`,children:m})}function kY(e){let t=e.conv;return(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:e.onClick,className:e.active?`mx-2 px-2 py-1 w-[calc(100%-1rem)] rounded text-[13px] flex items-center gap-2 bg-gray-100 text-gray-900`:`mx-2 px-2 py-1 w-[calc(100%-1rem)] rounded text-[13px] flex items-center gap-2 text-gray-500 hover:bg-gray-50 hover:text-gray-900`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:EY(t)}),(0,K.jsx)(`span`,{className:`truncate flex-1 text-left`,children:TY(t)}),t.unread>0&&(0,K.jsx)(`span`,{className:`text-[11px] px-1.5 rounded-full bg-gray-200 text-gray-700`,children:t.unread})]}),e.onDelete&&(0,K.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),e.onDelete()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-red-600 opacity-0 group-hover:opacity-100 text-xs px-1`,title:`delete channel (admin)`,children:`×`})]})}function AY(e){let t=e.message,n=e.isMe,r=`replyCount`in t?t.replyCount:0,i=`lastReplyTs`in t?t.lastReplyTs:null;return(0,K.jsxs)(`div`,{className:`group/msg relative -mx-1 px-1 py-0.5 rounded flex gap-3 `+(n?`flex-row-reverse `:``)+(e.active?`bg-amber-50/60`:`hover:bg-gray-50`),children:[(0,K.jsx)(`div`,{className:n?`w-7 h-7 rounded shrink-0 flex items-center justify-center text-[11px] font-medium bg-gray-900 text-white`:`w-7 h-7 rounded shrink-0 flex items-center justify-center text-[11px] font-medium bg-gray-200 text-gray-900`,title:t.author,children:t.author.slice(0,1).toUpperCase()}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 ${n?`justify-end`:``}`,children:n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:wY(t.ts)}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:`you`}),(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:t.author})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:t.author}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:wY(t.ts)})]})}),(0,K.jsx)(`div`,{className:`text-[13px] text-gray-900 whitespace-pre-wrap leading-relaxed break-words ${n?`text-right`:``}`,children:t.text}),!e.compact&&e.onOpenThread&&r>0&&(0,K.jsxs)(`button`,{type:`button`,onClick:e.onOpenThread,className:`mt-1 text-[11px] text-blue-600 hover:underline ${n?`ml-auto block text-right`:``}`,children:[`💬 `,r,` `,r===1?`reply`:`replies`,i&&(0,K.jsxs)(`span`,{className:`text-gray-400 ml-1.5`,children:[`· last `,wY(i)]})]}),!e.compact&&e.onOpenThread&&r===0&&(0,K.jsx)(`button`,{type:`button`,onClick:e.onOpenThread,className:`mt-1 text-[11px] text-gray-400 hover:text-blue-600 hover:underline opacity-0 group-hover/msg:opacity-100 transition-opacity `+(n?`ml-auto block text-right`:``),children:`💬 Reply`})]})]})}function jY(e){let t=e.pending,n=t.status===`failed`;return(0,K.jsxs)(`div`,{className:`flex flex-row-reverse gap-3 -mx-1 px-1 py-0.5 rounded `+(n?`ring-1 ring-red-200 bg-red-50/40`:``),children:[(0,K.jsx)(`div`,{className:`w-7 h-7 rounded shrink-0 flex items-center justify-center text-[11px] font-medium bg-gray-900 text-white`,title:e.author,children:e.author.slice(0,1).toUpperCase()}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:wY(t.ts)}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:`you`}),(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:e.author}),n?(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-red-100 text-red-700 border border-red-200`,children:`failed`}):(0,K.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-gray-100 text-gray-500 inline-flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full bg-gray-400 animate-pulse`}),`sending…`]})]}),(0,K.jsx)(`div`,{className:`text-[13px] whitespace-pre-wrap leading-relaxed break-words text-right `+(n?`text-gray-700`:`text-gray-400`),children:t.text}),n&&(0,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 justify-end text-[11px]`,children:[t.error&&(0,K.jsx)(`span`,{className:`text-red-600`,children:t.error}),(0,K.jsx)(`button`,{type:`button`,onClick:e.onRetry,className:`px-1.5 py-0.5 rounded border border-gray-300 text-gray-700 hover:bg-white`,children:`retry`}),(0,K.jsx)(`button`,{type:`button`,onClick:e.onDiscard,className:`px-1.5 py-0.5 rounded text-gray-500 hover:text-red-600`,children:`discard`})]})]})]})}function MY(e){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)(``);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/30 flex items-center justify-center`,onClick:e.onClose,children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-lg w-96 p-4 flex flex-col gap-3`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:`New channel`}),(0,K.jsx)(`input`,{autoFocus:!0,value:t,onChange:e=>n(e.target.value),placeholder:`channel-name`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,K.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`topic (optional)`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:e.onClose,className:`px-3 py-1.5 text-xs text-gray-600 hover:text-gray-900`,children:`cancel`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>t.trim()&&e.onCreate(t.trim(),r.trim()),disabled:!t.trim(),className:`px-3 py-1.5 text-xs rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`create`})]})]})})}function NY(e){let[t,n]=(0,_.useState)(``),r=e.users.filter(e=>!e.isMe).filter(e=>e.id.toLowerCase().includes(t.toLowerCase()));return(0,K.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/30 flex items-center justify-center`,onClick:e.onClose,children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-lg w-96 p-4 flex flex-col gap-3`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:`Direct message`}),(0,K.jsx)(`input`,{autoFocus:!0,value:t,onChange:e=>n(e.target.value),placeholder:`search users…`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,K.jsxs)(`div`,{className:`max-h-64 overflow-auto flex flex-col gap-0.5`,children:[r.map(t=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e.onPick(t.id),className:`text-left px-2 py-1.5 text-sm rounded hover:bg-gray-100 flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-6 h-6 rounded bg-gray-200 text-gray-900 text-[11px] flex items-center justify-center`,children:t.id.slice(0,1).toUpperCase()}),(0,K.jsx)(`span`,{children:t.id}),t.role===`admin`&&(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 ml-auto`,children:`admin`})]},t.id)),r.length===0&&(0,K.jsx)(`div`,{className:`text-xs text-gray-400 px-2 py-2`,children:`no users match`})]})]})})}async function PY(e){try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-9999px`,document.body.appendChild(t),t.focus(),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function FY({onDone:e}={}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)([]),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(``),[S,C]=(0,_.useState)(``),[w,T]=(0,_.useState)(``),[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)([]),[A,j]=(0,_.useState)(!1),[M,N]=(0,_.useState)(null),[F,I]=(0,_.useState)(!1),[L,R]=(0,_.useState)(null),[z,B]=(0,_.useState)(!1),[V,H]=(0,_.useState)(!1),[U,ee]=(0,_.useState)(`token`),[W,te]=(0,_.useState)(``);(0,_.useEffect)(()=>{f(null),m(!1),g([]),u(``),c(!1),R(null),H(!1),i(!0),Jp().then(e=>{n(e),o(e?.personalRepo??``),C(e?.gitHost?.defaultRepo??`loopat-personal`)}).finally(()=>i(!1))},[]);let ne=async()=>{t?.publicKey&&await PY(t.publicKey)&&(I(!0),setTimeout(()=>I(!1),1500))},G=async()=>{L&&await PY(L)&&(B(!0),setTimeout(()=>B(!1),1500))},re=async()=>{if(!v){f(null),m(!1),g([]),y(!0);try{let e=await tm(a.trim()||void 0,s&&l.trim()?l.trim():void 0);if(!e.ok){f(e.error??`import failed`),e.notClean&&m(!0),e.secretsExposed&&g(e.exposedFiles??[]);return}e.autoInitialized&&e.cryptKey?R(e.cryptKey):n(await Jp())}finally{y(!1)}}},ie=async()=>{if(!A){N(null),j(!0);try{let e=await nm(b.trim(),S.trim()||void 0,w.trim()||void 0);if(!e.ok){e.needsCryptKey?(D(!0),N(`This repo already has a .loopat vault — paste its git-crypt key to unlock it.`)):N(e.error??`setup failed`);return}e.autoInitialized&&e.cryptKey?R(e.cryptKey):n(await Jp())}finally{j(!1)}}},ae=async()=>{if(!(A||!b.trim())){N(null),j(!0);try{let e=await qp(b.trim());if(!e.ok){N(e.error??`invalid token`);return}k(e.repos),e.login&&te(e.login),ee(`repo`)}finally{j(!1)}}},oe=t?.gitHost?.provider??`github`,se=oe===`github`?`GitHub`:oe,ce=O.some(e=>e.name===S.trim()),le=t?.gitHost?.baseUrl&&W&&S.trim()?`${t.gitHost.baseUrl.replace(/\/+$/,``)}/${W}/${S.trim()}`:null;if(r)return(0,K.jsx)(`div`,{className:`text-sm text-gray-400 py-8 text-center`,children:`loading…`});if(!t)return(0,K.jsx)(`div`,{className:`text-sm text-red-600`,children:`failed to load status`});if(L)return(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-2 py-1`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-full bg-emerald-100`,children:(0,K.jsx)(P,{size:20,className:`text-emerald-600`})}),(0,K.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:`Your personal repo is ready 🎉`})]}),(0,K.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:`One last thing — back up your git-crypt key`}),(0,K.jsxs)(`div`,{className:`text-xs text-gray-600 leading-relaxed`,children:[`The symmetric key below decrypts everything under`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat/vaults/`}),`. It's already stored on this host, but `,(0,K.jsx)(`b`,{children:`save your own copy`}),` — if this host dies and you don't have it, your secrets are unrecoverable.`]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`textarea`,{readOnly:!0,value:L,rows:4,className:`w-full text-[11px] font-mono text-gray-800 bg-gray-50 border border-gray-200 rounded p-2 outline-none resize-none break-all`,onClick:e=>e.target.select()}),(0,K.jsx)(`button`,{type:`button`,onClick:G,className:`absolute top-1.5 right-1.5 px-2 py-0.5 text-[11px] rounded bg-white border border-gray-300 text-gray-700 hover:bg-gray-100`,children:z?`copied`:`copy`})]}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed bg-gray-50 border border-gray-200 rounded p-2`,children:[(0,K.jsx)(`b`,{children:`Suggested:`}),` stash this in your password manager (1Password / Bitwarden / Apple Keychain). To later restore on a new host, paste this same value into the Recovery field on the new host's Personal repo settings.`]}),(0,K.jsxs)(`div`,{className:`text-[11px] text-emerald-700 leading-relaxed bg-emerald-50 border border-emerald-200 rounded p-2`,children:[(0,K.jsx)(`b`,{children:`Next:`}),` if your providers need API keys, add them in`,` `,(0,K.jsx)(`b`,{children:`Settings → Providers`}),` to start chatting.`]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:V,onChange:e=>H(e.target.checked),className:`accent-gray-900`}),`I've saved this key somewhere safe.`]}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{V&&(n(await Jp()),R(null),e&&e())},disabled:!V,className:`self-end px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`Done`})]});if(t.imported)return(0,K.jsx)(IY,{status:t});if(!t.publicKey)return(0,K.jsxs)(`div`,{className:`text-sm text-amber-700 bg-amber-50 border border-amber-200 rounded px-2 py-2 leading-relaxed`,children:[`No deploy key available — the server is probably missing`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-white px-1 rounded`,children:`openssh-client`}),`. Install it and reopen this panel.`]});let ue=[`token`,`repo`,`confirm`].indexOf(U);return(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-[11px] mb-1`,children:[{k:`token`,label:`Token`},{k:`repo`,label:`Repository`},{k:`confirm`,label:`Confirm`}].map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 ${U===e.k?`text-gray-900 font-medium`:t<ue?`text-emerald-600`:`text-gray-400`}`,children:[(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 rounded-full text-[9px] ${U===e.k?`bg-gray-900 text-white`:t<ue?`bg-emerald-500 text-white`:`bg-gray-200 text-gray-500`}`,children:t<ue?`✓`:t+1}),e.label]}),t<2&&(0,K.jsx)(`span`,{className:`text-gray-300`,children:`→`})]},e.k))}),U===`token`&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[`Paste your `,se,` token. Loopat will list your repos so you can pick one (or create a new one), then set everything up with git-crypt — no manual repo creation or deploy-key pasting.`]}),(0,K.jsx)(`input`,{type:`password`,value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ae())},placeholder:`${se} personal access / private token`,autoComplete:`off`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),t.gitHost?.tokenHelp&&(/^https?:\/\//.test(t.gitHost.tokenHelp)?(0,K.jsx)(`a`,{href:t.gitHost.tokenHelp,target:`_blank`,rel:`noreferrer`,className:`text-[11px] text-blue-600 hover:underline w-fit`,children:`Where do I get a token? ↗`}):(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 leading-relaxed`,children:t.gitHost.tokenHelp})),M&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:M}),(0,K.jsx)(`button`,{type:`button`,onClick:ae,disabled:A||!b.trim(),className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:A?`loading repos…`:`Next`}),oe===`github`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 text-center`,children:`— or set up a deploy key manually —`}),(0,K.jsxs)(`div`,{className:`text-xs text-gray-600 leading-relaxed`,children:[`Two steps:`,(0,K.jsxs)(`ol`,{className:`list-decimal pl-5 mt-1 space-y-0.5 text-gray-600`,children:[(0,K.jsxs)(`li`,{children:[`Create a `,(0,K.jsx)(`b`,{children:`fresh, empty`}),` private GitHub repo (no README, no`,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat/`}),`).`]}),(0,K.jsxs)(`li`,{children:[`Paste the public key below into that repo's`,` `,(0,K.jsx)(`i`,{children:`Settings → Deploy keys → Add deploy key`}),`, check`,` `,(0,K.jsx)(`b`,{children:`Allow write access`}),`, then put the repo URL here and Continue.`]})]}),(0,K.jsxs)(`div`,{className:`mt-2 text-[11px] text-gray-500`,children:[`Loopat will run `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`git-crypt init`}),` `,`inside your repo for you and push the encrypted scaffold. You don't need git-crypt installed locally.`]})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`textarea`,{readOnly:!0,value:t.publicKey,rows:3,className:`w-full text-[11px] font-mono text-gray-800 bg-gray-50 border border-gray-200 rounded p-2 outline-none resize-none`,onClick:e=>e.target.select()}),(0,K.jsx)(`button`,{type:`button`,onClick:ne,className:`absolute top-1.5 right-1.5 px-2 py-0.5 text-[11px] rounded bg-white border border-gray-300 text-gray-700 hover:bg-gray-100`,children:F?`copied`:`copy`})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:`Repo URL`}),(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`git@github.com:you/loopat-personal.git`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})]}),(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`w-full flex justify-between items-center px-2.5 py-1.5 text-[11px] text-gray-600 hover:bg-gray-50`,children:[(0,K.jsx)(`span`,{children:`Recovery: I already have a git-crypt key for this repo`}),(0,K.jsx)(`span`,{className:`text-gray-400`,children:s?`▾`:`▸`})]}),s&&(0,K.jsxs)(`div`,{className:`px-2.5 pb-2.5 text-[11px] text-gray-600 leading-relaxed border-t border-gray-200`,children:[(0,K.jsx)(`p`,{className:`mt-2`,children:`Use this if you're re-importing an existing loopat repo onto a new host (or this host lost its host-secrets). The repo must already have git-crypt configured.`}),(0,K.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:3,placeholder:`base64 git-crypt key`,className:`mt-2 w-full px-2 py-1.5 text-[11px] font-mono border border-gray-300 rounded outline-none focus:border-gray-500 resize-none`}),(0,K.jsxs)(`p`,{className:`mt-1 text-gray-500`,children:[`Paste the value you saved from "Back up your git-crypt key" on another host (or the base64 of`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`git-crypt export-key`}),` `,`if you originally set the repo up by hand).`]})]})]}),h.length>0&&(0,K.jsxs)(`div`,{className:`text-xs bg-red-50 border border-red-300 rounded p-2.5 leading-relaxed`,children:[(0,K.jsx)(`div`,{className:`font-semibold text-red-700 mb-1`,children:`⚠️ Your secrets are exposed`}),(0,K.jsxs)(`div`,{className:`text-red-700 mb-1.5`,children:[`The following files appear in git as `,(0,K.jsx)(`b`,{children:`plaintext`}),`. Anyone with repo access can already read them:`]}),(0,K.jsx)(`ul`,{className:`font-mono text-[10.5px] text-red-800 bg-white/60 rounded p-1.5 max-h-24 overflow-auto`,children:h.map(e=>(0,K.jsx)(`li`,{children:e},e))}),(0,K.jsxs)(`ol`,{className:`list-decimal pl-4 text-red-700 space-y-0.5 mt-2`,children:[(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`b`,{children:`Rotate`}),` the leaked secrets immediately — the old ones are burned.`]}),(0,K.jsx)(`li`,{children:`Create a fresh empty repo and point loopat there instead.`})]})]}),p&&h.length===0&&(0,K.jsxs)(`div`,{className:`text-xs bg-amber-50 border border-amber-300 rounded p-2.5 leading-relaxed text-amber-800`,children:[(0,K.jsx)(`div`,{className:`font-semibold mb-0.5`,children:`This repo isn't a clean slate`}),(0,K.jsx)(`div`,{children:d}),(0,K.jsxs)(`div`,{className:`mt-1.5 text-amber-700`,children:[`Two options: point at a fresh empty repo, or — if it's your own previous loopat repo — expand `,(0,K.jsx)(`i`,{children:`Recovery`}),` above and paste the crypt key.`]})]}),d&&!p&&h.length===0&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:d}),(0,K.jsx)(`div`,{className:`flex gap-2 mt-1`,children:(0,K.jsx)(`button`,{type:`button`,onClick:re,disabled:v||!a.trim(),className:`flex-1 px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:v?s&&l.trim()?`unlocking…`:`initializing…`:`Continue`})})]})]}),U===`repo`&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:`Pick one of your repos, or type a new name to create one. Repos with "personal" in the name are listed first.`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 max-h-52 overflow-auto border border-gray-200 rounded p-1`,children:[O.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 px-2 py-4 text-center`,children:`no existing repos found — type a name below to create one`}),O.map(e=>{let t=S.trim()===e.name;return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>C(e.name),className:`flex items-center justify-between gap-2 px-2 py-1.5 rounded text-left text-xs ${t?`bg-gray-900 text-white`:`hover:bg-gray-100 text-gray-700`}`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[t&&(0,K.jsx)(P,{size:12,className:`shrink-0`}),(0,K.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),e.name.includes(`personal`)&&(0,K.jsx)(`span`,{className:`text-[9px] px-1 rounded ${t?`bg-white/20`:`bg-emerald-100 text-emerald-700`}`,children:`personal`})]}),(0,K.jsx)(`span`,{className:`text-[10px] truncate ${t?`text-white/60`:`text-gray-400`}`,children:e.path})]},e.path)})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`or type a new repo name`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S.trim()&&(e.preventDefault(),N(null),ee(`confirm`))},placeholder:`loopat-personal`,className:`flex-1 px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,K.jsx)(`span`,{className:`text-[11px] whitespace-nowrap ${ce?`text-gray-500`:`text-emerald-600`}`,children:S.trim()?ce?`use existing`:`will create`:``})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{ee(`token`),N(null)},className:`px-3 h-9 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Back`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{N(null),ee(`confirm`)},disabled:!S.trim(),className:`flex-1 px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`Next`})]})]}),U===`confirm`&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded p-3 text-xs text-gray-700 leading-relaxed flex flex-col gap-2`,children:[ce?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`font-semibold text-gray-900`,children:`Use existing repo`}),(0,K.jsxs)(`div`,{children:[`Loopat will use your existing repo`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:S.trim()}),` and create a git-crypt-encrypted`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat/`}),` vault inside it. The repo should be a clean slate — if it already has a`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat`}),` vault you'll be asked for its git-crypt key.`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`font-semibold text-gray-900`,children:`Create new repo`}),(0,K.jsxs)(`div`,{children:[`Loopat will create a new private `,se,` repo named`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:S.trim()}),`, then initialize a git-crypt-encrypted`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat/`}),` vault and push it. Your secrets stay encrypted in git.`]})]}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500`,children:`You'll get a one-time git-crypt key to back up right after.`}),le&&(0,K.jsxs)(`a`,{href:le,target:`_blank`,rel:`noreferrer`,className:`text-[11px] text-blue-600 hover:underline break-all w-fit`,children:[le,` ↗`]})]}),E&&(0,K.jsx)(`textarea`,{value:w,onChange:e=>T(e.target.value),rows:3,placeholder:`git-crypt key — this repo already has a .loopat vault, paste its key to unlock`,className:`w-full px-2 py-1.5 text-[11px] font-mono border border-gray-300 rounded outline-none focus:border-gray-500 resize-none`}),M&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:M}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{ee(`repo`),N(null)},disabled:A,className:`px-3 h-9 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50 disabled:opacity-50`,children:`Back`}),(0,K.jsx)(`button`,{type:`button`,onClick:ie,disabled:A,className:`flex-1 px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:A?`setting up…`:ce?`Use this repo`:`Create & set up`})]})]})]})}function IY({status:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null),s=async()=>{n(`pull`),i(null),i(await $p())},c=async()=>{n(`push`),o(null),o(await em())};return(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsxs)(`div`,{className:`text-sm text-gray-700`,children:[`Imported`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 py-0.5 rounded`,children:e.personalRepo??`(unknown remote)`}),`.`]}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 leading-relaxed`,children:`Sync your personal vault with the remote repo.`}),t===`export`?(0,K.jsx)(BY,{onDone:()=>n(null)}):t===`delete`?(0,K.jsx)(VY,{status:e,onDone:()=>n(null)}):t===`pull`?(0,K.jsx)(RY,{type:`pull`,result:r,onDone:()=>n(null),onRetry:s}):t===`push`?(0,K.jsx)(RY,{type:`push`,result:a,onDone:()=>n(null),onRetry:c}):t===`showkey`?(0,K.jsx)(zY,{vaultKeys:e.vaultKeys??[],onDone:()=>n(null)}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:s,className:`flex-1 flex items-center justify-center gap-1.5 px-2.5 py-1.5 text-[11px] text-gray-700 border border-gray-200 rounded hover:bg-gray-50`,children:[(0,K.jsx)(T,{size:12}),`Pull`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:c,className:`flex-1 flex items-center justify-center gap-1.5 px-2.5 py-1.5 text-[11px] text-gray-700 border border-gray-200 rounded hover:bg-gray-50`,children:[(0,K.jsx)(O,{size:12}),`Push`]})]}),(e.vaultKeys?.length??0)>0&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>n(`showkey`),className:`w-full text-left px-2.5 py-1.5 text-[11px] text-gray-700 border border-gray-200 rounded hover:bg-gray-50`,children:`Show vault SSH keys (for team repos)`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>n(`export`),className:`w-full text-left px-2.5 py-1.5 text-[11px] text-gray-700 border border-gray-200 rounded hover:bg-gray-50`,children:`Show / export git-crypt key (requires password)`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>n(`delete`),className:`w-full text-left px-2.5 py-1.5 text-[11px] text-red-700 border border-red-200 rounded hover:bg-red-50`,children:`Delete personal vault (requires password)`})]})]})}function LY({onRetry:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(!1);return r?(0,K.jsx)(`button`,{disabled:!0,className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white opacity-50`,children:`Force pulling…`}):t?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:async()=>{i(!0);let t=await $p({force:!0});i(!1),n(!1),t.ok&&e()},className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800`,children:`Confirm — discard all local changes`}),(0,K.jsx)(`button`,{onClick:()=>n(!1),className:`px-3 h-8 text-sm rounded border border-gray-200 text-gray-600 hover:bg-gray-100`,children:`Cancel`})]}):(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>n(!0),className:`flex-1 px-3 h-8 text-sm rounded bg-amber-600 text-white hover:bg-amber-700`,children:`Discard changes & force pull`}),(0,K.jsx)(`button`,{onClick:e,className:`px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800`,children:`Retry`})]})}function RY({type:e,result:t,onDone:n,onRetry:r}){let[i,a]=(0,_.useState)(!1);if(!t)return(0,K.jsx)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:(0,K.jsx)(`div`,{className:`text-xs font-semibold text-gray-900`,children:e===`pull`?`Pulling from remote...`:`Pushing to remote...`})});if(t.ok)return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-emerald-200 bg-emerald-50 rounded p-2.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-emerald-800`,children:[(0,K.jsx)(P,{size:14}),e===`pull`?`Pulled successfully`:`Pushed successfully`]}),(0,K.jsx)(`div`,{className:`text-xs text-emerald-700 leading-relaxed`,children:e===`pull`?`Your local vault is now up to date with the remote.`:`Your changes have been pushed to the remote.`}),(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`self-end px-3 h-8 text-sm rounded bg-emerald-700 text-white hover:bg-emerald-800`,children:`Done`})]});let o=(t.conflict??!1)&&(t.files?.length??0)>0,s=e===`push`&&t.needsPull;return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-red-200 bg-red-50 rounded p-2.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-red-800`,children:[(0,K.jsx)(nt,{size:14}),o?`Held back — conflicts with remote`:e===`pull`?`Pull failed`:`Push failed`]}),o&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:[`Your change conflicts with the remote, so it wasn't merged — but your local edit is `,(0,K.jsx)(`b`,{children:`kept, not lost`}),`. Either take the remote (discard this edit) or resolve it by hand / in a loop.`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`text-left text-[11px] text-red-700 underline`,children:[i?`Hide`:`Show`,` conflicting files (`,t.files.length,`)`]}),i&&(0,K.jsx)(`ul`,{className:`font-mono text-[10.5px] text-red-900 bg-white/60 rounded p-1.5 max-h-24 overflow-auto`,children:t.files.map(e=>(0,K.jsx)(`li`,{children:e},e))})]}),s&&!o&&(0,K.jsx)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:`Remote moved again while pushing. Just try again.`}),!o&&!s&&(0,K.jsx)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:t.error}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[o?(0,K.jsx)(LY,{onRetry:r}):(0,K.jsx)(`button`,{type:`button`,onClick:r,className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800`,children:`Retry`}),(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`px-3 h-8 text-sm rounded border border-red-300 text-red-700 bg-white hover:bg-red-50`,children:`Close`})]})]})}function zY({vaultKeys:e,onDone:t}){let[n,r]=(0,_.useState)(null),i=async(e,t)=>{await PY(t)&&(r(e),setTimeout(()=>r(null),1500))};return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold text-gray-900`,children:`Vault SSH keys — for team repos`}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[`Register these on the git host that hosts your `,(0,K.jsx)(`b`,{children:`team`}),` repos (knowledge / notes / repos). A loop authenticates with its vault's key — one per vault. Public keys, safe to share. (The deploy key is separate — it's for your `,(0,K.jsx)(`i`,{children:`personal`}),` repo only.)`]}),e.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400`,children:`No vault keys yet.`}),e.map(e=>(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-600 font-medium`,children:[`vault: `,e.vault]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`textarea`,{readOnly:!0,value:e.publicKey,rows:3,className:`w-full text-[11px] font-mono text-gray-800 bg-gray-50 border border-gray-200 rounded p-2 outline-none resize-none break-all`,onClick:e=>e.target.select()}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>i(e.vault,e.publicKey),className:`absolute top-1.5 right-1.5 px-2 py-0.5 text-[11px] rounded bg-white border border-gray-300 text-gray-700 hover:bg-gray-100`,children:n===e.vault?`copied`:`copy`})]})]},e.vault)),(0,K.jsx)(`button`,{type:`button`,onClick:t,className:`self-end px-3 h-8 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Close`})]})}function BY({onDone:e}){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(!1),d=async()=>{if(!(r||!t)){o(null),i(!0);try{let e=await Zp(t);e.ok?c(e.cryptKey):o(e.error)}finally{i(!1)}}};return s?(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold text-gray-900`,children:`git-crypt key`}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`textarea`,{readOnly:!0,value:s,rows:4,className:`w-full text-[11px] font-mono text-gray-800 bg-gray-50 border border-gray-200 rounded p-2 outline-none resize-none break-all`,onClick:e=>e.target.select()}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{if(s)try{await navigator.clipboard.writeText(s),u(!0),setTimeout(()=>u(!1),1500)}catch{}},className:`absolute top-1.5 right-1.5 px-2 py-0.5 text-[11px] rounded bg-white border border-gray-300 text-gray-700 hover:bg-gray-100`,children:l?`copied`:`copy`})]}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[`Treat it like a password — anyone with this key can decrypt everything under `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`.loopat/vaults/`}),`.`]}),(0,K.jsx)(`button`,{type:`button`,onClick:e,className:`self-end px-3 h-8 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Close`})]}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold text-gray-900`,children:`Confirm password to reveal the key`}),(0,K.jsx)(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},autoFocus:!0,autoComplete:`current-password`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),a&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:a}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:d,disabled:r||!t,className:`flex-1 px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:r?`verifying…`:`Reveal`}),(0,K.jsx)(`button`,{type:`button`,onClick:e,disabled:r,className:`px-3 h-8 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Cancel`})]})]})}function VY({status:e,onDone:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=()=>{t(),setTimeout(()=>window.location.reload(),50)},b=async e=>{if(!(i||!n)){s(null),a(!0);try{let t=await Qp(n,e);if(t.ok){v({synced:t.synced??!1,dataLost:t.dataLost??!1});return}if(t.wrongPassword){s(t.error??`wrong password`);return}if(t.syncFailed){l({syncError:t.syncError??t.error??`unknown sync error`,uncommitted:t.uncommitted,unpushed:t.unpushed,hasRemote:t.hasRemote});return}s(t.error??`delete failed`)}finally{a(!1)}}};if(g)return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:`Vault deleted`}),(0,K.jsx)(`div`,{className:`text-xs text-gray-600 leading-relaxed`,children:g.dataLost?(0,K.jsx)(`span`,{className:`text-red-700`,children:`Unsynced changes were discarded. The vault is gone.`}):g.synced?`Synced to remote and deleted. You can re-import any time.`:`Vault deleted. You can re-import any time.`}),(0,K.jsx)(`button`,{type:`button`,onClick:y,className:`self-end px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700`,children:`Done`})]});if(c){let e=u&&f&&m;return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-red-300 bg-red-50 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-sm font-semibold text-red-800`,children:`⚠️ Sync failed — data will be lost`}),(0,K.jsxs)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:[`Loopat couldn't push your local changes to the remote.`,(c.uncommitted??0)>0&&(0,K.jsxs)(`span`,{children:[` `,c.uncommitted,` uncommitted file(s).`]}),(c.unpushed??0)>0&&(0,K.jsxs)(`span`,{children:[` `,c.unpushed,` unpushed commit(s).`]}),c.hasRemote===!1&&(0,K.jsx)(`span`,{children:` No remote is configured on this vault.`})]}),(0,K.jsx)(`pre`,{className:`text-[10.5px] text-red-900 bg-white/60 border border-red-200 rounded p-1.5 overflow-auto max-h-24`,children:c.syncError}),(0,K.jsx)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:`Continuing now will permanently delete the unsynced changes from this host. To keep them, cancel and resolve the sync issue first (network, deploy-key write access, branch protection).`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 mt-1 text-xs text-red-900`,children:[(0,K.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`mt-0.5 accent-red-700`}),(0,K.jsx)(`span`,{children:`I understand the unsynced changes will be deleted.`})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`mt-0.5 accent-red-700`}),(0,K.jsx)(`span`,{children:`I cannot recover them from this host afterwards.`})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`mt-0.5 accent-red-700`}),(0,K.jsx)(`span`,{children:`I still want to delete the vault now.`})]})]}),o&&(0,K.jsx)(`div`,{className:`text-xs text-red-700 bg-white border border-red-200 rounded px-2 py-1.5`,children:o}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(!0),disabled:i||!e,className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800 disabled:opacity-40`,children:i?`deleting…`:`Delete anyway`}),(0,K.jsx)(`button`,{type:`button`,onClick:t,disabled:i,className:`px-3 h-8 text-sm rounded border border-red-300 text-red-700 bg-white hover:bg-red-50`,children:`Cancel`})]})]})}return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-red-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold text-red-800`,children:`Delete personal vault`}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-600 leading-relaxed`,children:[`Removes `,(0,K.jsxs)(`code`,{className:`bg-gray-100 px-1 rounded`,children:[`personal/`,e.userId,`/`]}),` `,`on this host and forgets the git-crypt key. Loopat will try to push any unsynced changes to`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:e.personalRepo??`remote`}),` `,`first. Your GitHub repo itself is not touched.`]}),(0,K.jsx)(`input`,{type:`password`,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&b(!1)},placeholder:`confirm password`,autoFocus:!0,autoComplete:`current-password`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),o&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:o}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(!1),disabled:i||!n,className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800 disabled:opacity-50`,children:i?`working…`:`Sync & delete`}),(0,K.jsx)(`button`,{type:`button`,onClick:t,disabled:i,className:`px-3 h-8 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Cancel`})]})]})}function HY({label:e,value:t}){let[n,r]=(0,_.useState)(!1);return(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500 w-20 shrink-0`,children:e}),(0,K.jsx)(`code`,{className:`flex-1 min-w-0 truncate bg-white border border-gray-200 rounded px-2 py-1 text-[10px] font-mono`,children:t}),(0,K.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),1500)},className:`text-[11px] text-gray-500 hover:text-gray-800 shrink-0`,children:n?`copied`:`copy`})]})}function UY(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(!1),y=async()=>{let e=await tg();e&&(t(e),r(e.card.name),a(e.card.description),s(e.profiles),l(e.vault))};(0,_.useEffect)(()=>{y()},[]);let b=e=>s(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return e?(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white px-4 py-3 space-y-3`,children:[(0,K.jsx)(`div`,{className:`text-[13px] font-medium text-gray-800`,children:`A2A (Agent-to-Agent)`}),(0,K.jsx)(`p`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:`This account is exposed as a standard A2A agent. Register its Agent Card URL with any A2A orchestrator.`}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(HY,{label:`Agent Card`,value:e.cardUrl}),(0,K.jsx)(HY,{label:`Endpoint`,value:e.endpoint})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-[11px] font-medium text-gray-600`,children:`Agent card`}),(0,K.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),placeholder:`Agent name (default: Loopat Agent)`,className:`w-full h-8 px-2 rounded border border-gray-300 text-[12px] focus:outline-none focus:border-gray-500`}),(0,K.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Description shown to orchestrators (what this agent does)`,rows:2,className:`w-full px-2 py-1 rounded border border-gray-300 text-[12px] resize-none focus:outline-none focus:border-gray-500`})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-[11px] font-medium text-gray-600`,children:`Loops created via A2A use`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Profiles`}),e.availableProfiles.length===0?(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 italic`,children:`no profiles in your knowledge repo`}):(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.availableProfiles.map(e=>(0,K.jsx)(`button`,{onClick:()=>b(e),className:`text-[11px] px-2 h-6 rounded border ${o.includes(e)?`bg-gray-900 text-white border-gray-900`:`bg-white text-gray-600 border-gray-300 hover:bg-gray-50`}`,children:e},e))})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Vault`}),(0,K.jsxs)(`select`,{value:c,onChange:e=>l(e.target.value),className:`h-7 px-2 rounded border border-gray-300 text-[12px] focus:outline-none focus:border-gray-500`,children:[(0,K.jsx)(`option`,{value:``,children:`default`}),e.availableVaults.filter(e=>e!=="default").map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,K.jsx)(`button`,{onClick:async()=>{d(!0);let e=await ng({card:{name:n,description:i},profiles:o,vault:c});d(!1),e&&(p(!0),setTimeout(()=>p(!1),1500),y())},disabled:u,className:`text-[12px] px-3 h-8 rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:u?`Saving…`:`Save`}),f&&(0,K.jsx)(`span`,{className:`text-[11px] text-green-700`,children:`saved`})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`text-[11px] font-medium text-gray-600`,children:[`Service key `,e.hasKey?(0,K.jsx)(`span`,{className:`text-green-700`,children:`· set`}):(0,K.jsx)(`span`,{className:`text-amber-700`,children:`· none`})]}),(0,K.jsx)(`button`,{onClick:async()=>{v(!0);let e=await rg();v(!1),e&&(h(e),y())},disabled:g,className:`text-[11px] px-2 h-6 rounded border border-gray-300 text-gray-700 hover:bg-gray-50 disabled:opacity-40`,children:g?`…`:e.hasKey?`regenerate`:`generate`})]}),(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[`The orchestrator presents this token (`,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[10px]`,children:`Authorization: Bearer …`}),`) to call your agent. Calls run as you, with your providers/keys.`]}),m&&(0,K.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 px-2 py-1.5 space-y-1`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-amber-800`,children:`Copy now — shown once:`}),(0,K.jsx)(HY,{label:`Key`,value:m})]})]})]}):null}function WY({checked:e,onCheckedChange:t,disabled:n,size:r=`default`}){let i=r===`sm`?`h-4 w-[28px]`:`h-5 w-[36px]`,a=r===`sm`?`h-3 w-3`:`h-3.5 w-3.5`,o=r===`sm`?`translate-x-[13px]`:`translate-x-[17px]`;return(0,K.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:n,onClick:()=>t(!e),className:`
|
|
114
|
+
`)}function yY({board:e,card:t,colFilename:n,onClose:r,onSaved:i,onDeleted:a}){let o=Cg(),s=zn(),c=!!o.currentUser,[l,u]=(0,_.useState)(t.text),[d,f]=(0,_.useState)(t.done),[p,m]=(0,_.useState)(t.priority??``),[h,g]=(0,_.useState)(t.assignee??``),[v,y]=(0,_.useState)(t.due??``),[b,x]=(0,_.useState)(t.description),[S,C]=(0,_.useState)(t.subtasks.map(e=>({...e}))),[w,T]=(0,_.useState)(t.topics??[]),[E,D]=(0,_.useState)(``),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(!1),[M,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)(!1);function I(e){C(t=>t.map((t,n)=>n===e?{...t,done:!t.done}:t))}function L(e,t){C(n=>n.map((n,r)=>r===e?{...n,text:t}:n))}function R(e){C(t=>t.filter((t,n)=>n!==e))}function z(){C(e=>[...e,{text:``,done:!1}])}function B(){let e=E.trim().replace(/^#/,``);e&&!w.includes(e)&&(T([...w,e]),D(``))}function V(e){T(w.filter(t=>t!==e))}async function H(){j(!0);let a=vY(l.trim()||t.text,d,p,h.trim(),v.trim(),b.trim(),S,w);await Xm(e,n,t.cid,a),j(!1),i(),r()}async function U(){await Jm(e,n,t.cid),f(e=>!e)}async function ee(){confirm(`Delete this card?`)&&(N(!0),await Zm(e,n,t.cid),N(!1),a())}async function W(){F(!0);let r=await lh(e,n,t.cid);F(!1),r.ok?i():alert(`No associated loop on this card`)}function te(){r(),o.setNewLoopDialogOpen(!0,t.text,{board:e,filename:n,cid:t.cid})}return(0,K.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/30 flex items-center justify-center`,onClick:r,children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-xl border border-gray-200 w-full max-w-lg max-h-[90vh] overflow-y-auto mx-4`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2 px-4 py-3 border-b border-gray-100`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:U,className:`shrink-0 mt-0.5 w-4 h-4 rounded border flex items-center justify-center text-xs hover:border-gray-500 ${d?`bg-emerald-50 border-emerald-400 text-emerald-600`:`border-gray-300`}`,children:d?`✓`:``}),(0,K.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),className:`flex-1 text-[14px] font-medium border-0 outline-none bg-transparent ${d?`text-gray-400 line-through`:`text-gray-900`}`}),(0,K.jsx)(`button`,{onClick:r,className:`text-gray-400 hover:text-gray-700 text-sm shrink-0`,children:`✕`})]}),(0,K.jsxs)(`div`,{className:`px-4 py-3 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:`Subtasks`}),S.map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>I(t),className:`shrink-0 w-4 h-4 rounded border flex items-center justify-center text-[10px] hover:border-gray-500 ${e.done?`bg-emerald-50 border-emerald-400 text-emerald-600`:`border-gray-300`}`,children:e.done?`✓`:``}),(0,K.jsx)(`input`,{type:`text`,value:e.text,onChange:e=>L(t,e.target.value),className:`flex-1 text-[12px] border border-gray-200 rounded px-1.5 py-0.5 outline-none focus:border-gray-400 ${e.done?`text-gray-400 line-through`:`text-gray-700`}`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>R(t),className:`text-gray-400 hover:text-red-500 text-sm shrink-0`,children:`×`})]},t)),(0,K.jsx)(`button`,{type:`button`,onClick:z,className:`flex items-center gap-1 text-[11px] text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded px-2 py-0.5 -ml-1 transition-colors`,children:`+ Add subtask`})]}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:`Tags`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[w.map(e=>(0,K.jsx)(pG,{name:e,onClick:()=>s(`/topic/${encodeURIComponent(e)}`),onEdit:()=>V(e)},e)),O?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,K.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),B(),k(!1)),e.key===`Escape`&&(k(!1),D(``))},onBlur:()=>{k(!1),D(``)},className:`w-20 text-[11px] border border-gray-300 rounded px-1.5 py-0.5 outline-none focus:border-gray-400`,placeholder:`tag`}),(0,K.jsx)(`button`,{type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>{B(),k(!1)},className:`text-[11px] text-gray-500 hover:text-gray-700`,children:`Add`})]}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>k(!0),className:`flex items-center gap-1 text-[11px] text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded px-2 py-0.5 transition-colors`,children:`+ Add tag`})]})]}),(0,K.jsx)(`div`,{className:`border-t border-gray-100`}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,K.jsx)(bY,{label:`Priority`,children:(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full text-[12px] border border-gray-300 rounded px-2 py-1 outline-none focus:border-gray-500`,children:[(0,K.jsx)(`option`,{value:``,children:`---`}),(0,K.jsx)(`option`,{value:`P0`,children:`P0`}),(0,K.jsx)(`option`,{value:`P1`,children:`P1`}),(0,K.jsx)(`option`,{value:`P2`,children:`P2`}),(0,K.jsx)(`option`,{value:`P3`,children:`P3`})]})}),(0,K.jsx)(bY,{label:`Assignee`,children:(0,K.jsx)(`input`,{type:`text`,value:h,onChange:e=>g(e.target.value),className:`w-full text-[12px] border border-gray-300 rounded px-2 py-1 outline-none focus:border-gray-500`,placeholder:`alice, bob`})}),(0,K.jsx)(bY,{label:`Due`,children:(0,K.jsx)(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),className:`w-full text-[12px] border border-gray-300 rounded px-2 py-1 outline-none focus:border-gray-500`,placeholder:`2026-05-20`})})]}),(0,K.jsx)(bY,{label:`Description`,children:(0,K.jsx)(`textarea`,{value:b,onChange:e=>x(e.target.value),rows:3,className:`w-full text-[12px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500 resize-none`,placeholder:`Notes…`})}),t.loopId&&(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-400`,children:[`Loop: `,(0,K.jsx)(`button`,{onClick:()=>{let e=t.loopId;s(`/loop/${o.loops.find(t=>t.id===e||t.id.startsWith(e))?.id??e}`)},className:`text-blue-700 hover:underline font-mono`,children:t.loopId.slice(0,8)})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-t border-gray-100`,children:[c&&(0,K.jsx)(`button`,{type:`button`,disabled:P,onClick:W,className:`px-2.5 h-7 rounded text-[11px] border border-gray-200 hover:bg-gray-100 text-gray-700 disabled:opacity-50`,children:P?(0,K.jsx)(Be,{size:12,className:`animate-spin`}):`Assign Driver`}),c&&(0,K.jsx)(`button`,{type:`button`,onClick:te,className:`px-2.5 h-7 rounded text-[11px] border border-gray-200 hover:bg-gray-100 text-gray-700`,children:`Create Loop`}),(0,K.jsx)(`div`,{className:`flex-1`}),c&&(0,K.jsx)(`button`,{type:`button`,disabled:A,onClick:H,className:`px-3 h-7 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:A?(0,K.jsx)(Be,{size:12,className:`animate-spin`}):`Save`}),c&&(0,K.jsx)(`button`,{type:`button`,disabled:M,onClick:ee,className:`px-2.5 h-7 rounded text-[11px] text-red-600 hover:bg-red-50 disabled:opacity-50`,children:M?(0,K.jsx)(Be,{size:12,className:`animate-spin`}):`Delete`})]})]})})}function bY({label:e,children:t}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wider`,children:e}),t]})}var xY=`archived.md`;function SY(){let{board:e=`default`}=Un(),t=zn(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),y=(0,_.useRef)(null),b=(0,_.useRef)(null),x=(0,_.useCallback)(()=>b.current?.refresh(),[]),[S,C]=(0,_.useState)(0),[w,T]=(0,_.useState)(!1);(0,_.useEffect)(()=>{let e=()=>Mm().then(C).catch(()=>{});e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[]);let E=(0,_.useCallback)(async()=>{T(!0),await Nm().catch(()=>{}),T(!1),C(0),b.current?.refresh()},[]),D=(0,_.useCallback)(async()=>{T(!0);let e=await jm();T(!1),e.ok||(e.conflict?alert(`保存了本地,但和远端冲突 (${(e.files??[]).join(`, `)})。本地保留——去 Notes 里 take remote 或手动解决。`):alert(`推送到远端失败:${e.error??`unknown`}`))},[]);(0,_.useEffect)(()=>{eh().then(l)},[e]);function O(){a(null),y.current&&clearTimeout(y.current)}function k(e){O(),a(e),y.current=setTimeout(O,1e4)}(0,_.useEffect)(()=>()=>{y.current&&clearTimeout(y.current)},[]);async function A(t,n){await $m(e,`archived`),await Qm(e,n,t.cid,xY)&&(k({cid:t.cid,card:t,fromFile:n,toFile:xY}),x())}async function j(){i&&(await Qm(e,i.toFile,i.cid,i.fromFile),O(),x())}async function M(){let e=f.trim();e&&await th(e)&&(d(!1),p(``),l(await eh()),t(`/kanban/${encodeURIComponent(e)}`))}async function N(e){let n=g.trim();if(!n||n===e){h(``);return}await nh(e,n)&&(h(``),v(``),l(await eh()),t(`/kanban/${encodeURIComponent(n)}`))}return(0,K.jsxs)(`div`,{className:`flex flex-col h-full w-full bg-white`,children:[(0,K.jsxs)(`div`,{className:`h-9 shrink-0 flex items-center gap-1 px-3 border-b border-gray-200 overflow-x-auto`,children:[c.map(n=>(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/kanban/${encodeURIComponent(n)}`),className:`shrink-0 h-7 px-3 rounded text-[12px] transition-colors whitespace-nowrap ${n===e?`bg-gray-900 text-white`:`text-gray-500 hover:text-gray-900 hover:bg-gray-100`}`,children:n}),n===e&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),h(n),v(n)},className:`absolute -top-0.5 -right-1 w-4 h-4 rounded-full bg-white border border-gray-300 text-[9px] text-gray-400 hover:text-gray-700 hidden group-hover:flex items-center justify-center shadow-sm`,title:`Rename board`,children:`✎`})]},n)),u?(0,K.jsx)(`span`,{className:`inline-flex items-center gap-1 ml-1 shrink-0`,children:(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&M(),e.key===`Escape`&&(d(!1),p(``))},onBlur:()=>{f.trim()||(d(!1),p(``))},className:`w-24 h-7 px-2 text-[12px] border border-gray-300 rounded outline-none focus:border-gray-500`,placeholder:`board name`})}):(0,K.jsx)(`button`,{onClick:()=>d(!0),className:`shrink-0 h-7 px-2 rounded text-[12px] text-gray-400 hover:text-gray-600 hover:bg-gray-100 ml-1`,title:`New board`,children:`+`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:D,disabled:w,className:`shrink-0 text-[11px] px-2 py-0.5 rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50 transition-colors`,title:`保存并推送到远端`,children:w?`…`:`保存`}),S>0&&(0,K.jsxs)(`span`,{className:`shrink-0 text-[11px] px-1.5 py-0.5 rounded bg-amber-100 text-amber-800`,title:`远端有更新,点 ↻ 拉取`,children:[`远端 +`,S]}),(0,K.jsx)(`button`,{onClick:E,disabled:w,className:`shrink-0 text-[11px] px-2 py-0.5 rounded border border-gray-200 text-gray-500 hover:text-gray-700 transition-colors disabled:opacity-50`,title:`拉取远端最新并刷新`,children:`↻`}),(0,K.jsx)(`button`,{onClick:()=>s(e=>!e),className:`text-[11px] px-2 py-0.5 rounded border transition-colors shrink-0 ${o?`border-gray-400 bg-gray-200 text-gray-700`:`border-gray-200 text-gray-500 hover:text-gray-700`}`,children:o?`Hide archived`:`Archived`}),(0,K.jsxs)(`button`,{onClick:()=>t(`/context/notes?file=focus/boards/${encodeURIComponent(e)}`),className:`shrink-0 text-[11px] text-gray-500 hover:text-gray-900 ml-2`,title:`edit files in notes/focus/`,children:[(0,K.jsxs)(`code`,{className:`text-gray-700`,children:[`notes/focus/boards/`,e,`/`]}),(0,K.jsx)(`span`,{children:` ↗`})]})]}),m&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`,onClick:()=>h(``),children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-xl border border-gray-200 w-full max-w-xs mx-4`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100`,children:(0,K.jsx)(`span`,{className:`text-sm font-medium text-gray-900`,children:`Rename board`})}),(0,K.jsxs)(`div`,{className:`px-4 py-3 space-y-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:g,onChange:e=>v(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&N(m),e.key===`Escape`&&h(``)},className:`w-full text-[13px] border border-gray-300 rounded px-2 py-1.5 outline-none focus:border-gray-500`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>N(m),disabled:!g.trim(),className:`px-2.5 h-7 rounded text-[11px] bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`Rename`}),(0,K.jsx)(`button`,{onClick:()=>h(``),className:`px-2.5 h-7 rounded text-[11px] text-gray-500 hover:bg-gray-200`,children:`Cancel`})]})]})]})}),(0,K.jsx)(`main`,{className:`flex-1 min-h-0 overflow-hidden relative`,children:(0,K.jsx)(_Y,{ref:b,board:e,onCardClick:(e,t)=>r({card:e,filename:t}),onCardArchive:A,showArchived:o})},e),n&&(0,K.jsx)(yY,{board:e,card:n.card,colFilename:n.filename,onClose:()=>r(null),onSaved:x,onDeleted:()=>{r(null),x()}}),i&&(0,K.jsxs)(`div`,{className:`fixed bottom-4 left-4 z-50 bg-white border border-gray-300 rounded-lg shadow-lg px-4 py-2.5 flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-[12px] text-gray-600`,children:`Card archived`}),(0,K.jsx)(`button`,{onClick:j,className:`text-[12px] text-blue-600 hover:text-blue-800 font-medium`,children:`Undo`}),(0,K.jsx)(`button`,{onClick:O,className:`text-gray-400 hover:text-gray-600 text-sm`,children:`✕`})]})]})}function CY(e){let t=(0,_.useRef)(null),[n,r]=(0,_.useState)(!1),i=(0,_.useRef)(e);i.current=e;let a=(0,_.useRef)(new Set),o=(0,_.useCallback)(e=>{let n=t.current;n&&n.readyState===WebSocket.OPEN&&n.send(JSON.stringify(e))},[]),s=(0,_.useCallback)(e=>{a.current.has(e)||(a.current.add(e),o({type:`subscribe`,convId:e}))},[o]),c=(0,_.useCallback)(e=>{a.current.has(e)&&(a.current.delete(e),o({type:`unsubscribe`,convId:e}))},[o]),l=(0,_.useCallback)(()=>{let e=location.protocol===`https:`?`wss:`:`ws:`,n=new WebSocket(`${e}//${location.host}/ws/chat`);t.current=n,n.onopen=()=>{r(!0);for(let e of a.current)try{n.send(JSON.stringify({type:`subscribe`,convId:e}))}catch{}mh().then(e=>{let t=vh();e.commit!==`unknown`&&t.commit!==`unknown`&&e.commit!==t.commit&&window.dispatchEvent(new CustomEvent(`loopat:version-mismatch`,{detail:{commit:e.commit}}))}).catch(()=>{})},n.onmessage=e=>{try{let t=JSON.parse(e.data);if(t.type===`chat_connected`)return;(t.type===`message`||t.type===`conv_created`||t.type===`conv_deleted`)&&i.current(t)}catch{}},n.onclose=()=>{r(!1),t.current=null,setTimeout(l,2e3+Math.random()*3e3)},n.onerror=()=>{}},[]);return(0,_.useEffect)(()=>(l(),()=>{let e=t.current;e&&(e.readyState===WebSocket.CONNECTING?(e.onopen=()=>e.close(),e.onmessage=null,e.onclose=null,e.onerror=null):(e.onclose=null,e.onerror=null,e.close())),t.current=null}),[l]),{connected:n,subscribe:s,unsubscribe:c}}function wY(){return`tmp-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function TY(e){let t=new Date(e),n=new Date,r=t.toDateString()===n.toDateString(),i=new Date(n.getTime()-864e5).toDateString()===t.toDateString(),a=t.toTimeString().slice(0,5);return r?a:i?`yesterday ${a}`:`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)} ${a}`}function EY(e){return e.kind===`channel`?e.name??`(unnamed)`:e.peerUserId??`(unknown)`}function DY(e){return e.kind===`channel`?`#`:`@`}function OY(){let e=Cg(),t=e.currentUser?.id??``,n=e.currentUser?.role===`admin`,r=zn(),{convId:i}=Un(),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)([]),[v,y]=(0,_.useState)([]),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(``),[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(!1),[M,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)(!1),I=lU(),L=(0,_.useRef)(null),R=(0,_.useRef)(null),z=(0,_.useRef)(i);z.current=i;let B=(0,_.useRef)(null);B.current=b;let[V,H]=(0,_.useState)(10),U=l.slice(-V),ee=l.length>V,W=(0,_.useCallback)(()=>{H(e=>e+20)},[]),te=(0,_.useRef)(W);te.current=W;let ne=(0,_.useRef)(ee);ne.current=ee;let G=(0,_.useMemo)(()=>a.find(e=>e.id===i),[a,i]),re=(0,_.useMemo)(()=>a.filter(e=>e.kind===`channel`).sort((e,t)=>(e.name??``).localeCompare(t.name??``)),[a]),ie=(0,_.useMemo)(()=>a.filter(e=>e.kind===`dm`).sort((e,t)=>(t.lastMessageTs??0)-(e.lastMessageTs??0)),[a]),ae=(0,_.useCallback)(async()=>{o(await Wh())},[]),oe=(0,_.useCallback)(async()=>{c(await Gh())},[]);(0,_.useEffect)(()=>{ae(),oe()},[ae,oe]);let se=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!i)return;x(null),C(null),H(10),se.current=null,le.current=!1;let e=!1;return Yh(i,{limit:100}).then(t=>{if(e)return;se.current=i,u(t);let n=t[t.length-1];n&&(Qh(i,n.id).catch(()=>{}),o(e=>e.map(e=>e.id===i?{...e,unread:0}:e)),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:i}})))}),()=>{e=!0}},[i]),(0,_.useEffect)(()=>{if(b==null){C(null);return}let e=!1;return C(null),Xh(b).then(t=>{e||C(t)}),()=>{e=!0}},[b]),(0,_.useEffect)(()=>{if(i||a.length===0)return;let e=re[0]??a[0];e&&r(`/chat/${e.id}`,{replace:!0})},[i,a,re,r]);let ce=(0,_.useRef)(!1);(0,_.useEffect)(()=>{L.current?.scrollIntoView({behavior:ce.current?`smooth`:`auto`}),ce.current=!0},[l,V]),(0,_.useEffect)(()=>{R.current?.scrollIntoView({behavior:`smooth`})},[S?.replies.length]);let le=(0,_.useRef)(!1),ue=(0,_.useRef)(null);(0,_.useEffect)(()=>{H(10),le.current=!1},[i]),(0,_.useEffect)(()=>{if(!i||l.length===0||se.current!==i||le.current)return;le.current=!0,H(e=>e+20),requestAnimationFrame(()=>{L.current?.scrollIntoView({behavior:`auto`})});let e=ue.current;if(!e)return;let t=null,n=()=>{t&&clearTimeout(t),t=setTimeout(()=>{e.scrollTop<60&&ne.current&&(te.current(),requestAnimationFrame(()=>{L.current?.scrollIntoView({behavior:`auto`})}))},400)};return e.addEventListener(`scroll`,n,{passive:!0}),()=>{e.removeEventListener(`scroll`,n),t&&clearTimeout(t)}},[i,l]);let{subscribe:de,unsubscribe:fe}=CY((0,_.useCallback)(e=>{if(e.type===`message`){let n=e.message;n.convId===z.current?(n.parentId==null?u(e=>e.some(e=>e.id===n.id)?e:[...e,{...n,replyCount:0,lastReplyTs:null}]):(u(e=>e.map(e=>e.id===n.parentId?{...e,replyCount:e.replyCount+1,lastReplyTs:n.ts}:e)),B.current===n.parentId&&C(e=>e&&!e.replies.some(e=>e.id===n.id)?{...e,replies:[...e.replies,n]}:e)),Qh(n.convId,n.id).catch(()=>{})):n.author!==t&&o(e=>e.map(e=>e.id===n.convId?{...e,unread:e.unread+1,lastMessageTs:n.ts}:e))}else e.type===`conv_created`?o(t=>t.some(t=>t.id===e.conv.id)?t:[...t,e.conv]):e.type===`conv_deleted`&&(o(t=>t.filter(t=>t.id!==e.convId)),z.current===e.convId&&r(`/chat`,{replace:!0}))},[r,t]));(0,_.useEffect)(()=>{for(let e of a)de(e.id);return()=>{for(let e of a)fe(e.id)}},[a,de,fe]);let pe=async(e,t,n)=>{g(e=>e.map(e=>e.tempId===t?{...e,status:`pending`,error:void 0}:e));let r=await Zh(n,e);if(r.message){let e=r.message;g(e=>e.filter(e=>e.tempId!==t)),u(t=>t.some(t=>t.id===e.id)?t:[...t,{...e,replyCount:0,lastReplyTs:null}])}else g(e=>e.map(e=>e.tempId===t?{...e,status:`failed`,error:r.error??`send failed`}:e))},me=async()=>{let e=d.trim();if(!e||!i||p)return;m(!0);let t=wY();g(n=>[...n,{tempId:t,convId:i,parentId:null,text:e,ts:Date.now(),status:`pending`}]),f(``),await pe(e,t,i),m(!1)},he=e=>{e.convId&&pe(e.text,e.tempId,e.convId).catch(()=>{})},ge=e=>{g(t=>t.filter(t=>t.tempId!==e))},_e=async(e,t,n,r)=>{y(e=>e.map(e=>e.tempId===t?{...e,status:`pending`,error:void 0}:e));let i=await Zh(n,e,r);if(i.message){let e=i.message;y(e=>e.filter(e=>e.tempId!==t)),C(t=>t&&!t.replies.some(t=>t.id===e.id)?{...t,replies:[...t.replies,e]}:t)}else y(e=>e.map(e=>e.tempId===t?{...e,status:`failed`,error:i.error??`send failed`}:e))},ve=async()=>{let e=w.trim();if(!e||!i||!S||E)return;D(!0);let t=wY();y(n=>[...n,{tempId:t,convId:i,parentId:S.root.id,text:e,ts:Date.now(),status:`pending`}]),T(``),await _e(e,t,i,S.root.id),D(!1)},ye=e=>{!e.convId||e.parentId==null||_e(e.text,e.tempId,e.convId,e.parentId).catch(()=>{})},be=e=>{y(t=>t.filter(t=>t.tempId!==e))},xe=async()=>{if(!S||O)return;k(!0);let t=await $h(S.root.id);t.loopId?(await e.refresh(),k(!1),r(`/loop/${t.loopId}`)):(k(!1),t.error&&console.error(`spawn failed:`,t.error))},Se=async(e,t)=>{let n=await Kh(e,t||void 0);n.conv?(N(!1),r(`/chat/${n.conv.id}`),ae()):n.error&&alert(n.error)},Ce=async e=>{if(!n||!confirm(`Delete this channel? Messages will be archived but hidden.`))return;let t=await qh(e);!t.ok&&t.error&&alert(t.error)},we=async e=>{let t=await Jh(e);t.conv?(j(!1),r(`/chat/${t.conv.id}`),ae()):t.error&&alert(t.error)},Te=(0,K.jsxs)(`aside`,{className:`w-60 shrink-0 border-r border-gray-200 bg-white flex flex-col h-full`,children:[I&&(0,K.jsxs)(`div`,{className:`h-9 flex items-center px-3 border-b border-gray-200`,children:[(0,K.jsx)(`button`,{onClick:()=>F(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,K.jsx)(Pe,{size:14})}),(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500 font-medium`,children:`Chat`})]}),(0,K.jsxs)(`div`,{className:I?`flex-1 min-h-0 overflow-auto py-2`:``,children:[(0,K.jsxs)(`div`,{className:`px-3 mt-3 mb-1 text-xs text-gray-500 flex items-center justify-between`,children:[(0,K.jsx)(`span`,{children:`Channels`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>N(!0),className:`text-gray-500 hover:text-gray-900 text-base leading-none`,title:`new channel`,children:`+`})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[re.map(e=>(0,K.jsx)(AY,{conv:e,active:e.id===i,onClick:()=>{r(`/chat/${e.id}`),I&&F(!1)},onDelete:n?()=>Ce(e.id):void 0},e.id)),re.length===0&&(0,K.jsx)(`div`,{className:`mx-2 px-2 py-1 text-[11px] text-gray-400`,children:`no channels yet`})]}),(0,K.jsxs)(`div`,{className:`px-3 mt-4 mb-1 text-xs text-gray-500 flex items-center justify-between`,children:[(0,K.jsx)(`span`,{children:`Direct messages`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>j(!0),className:`text-gray-500 hover:text-gray-900 text-base leading-none`,title:`new DM`,children:`+`})]}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[ie.map(e=>(0,K.jsx)(AY,{conv:e,active:e.id===i,onClick:()=>{r(`/chat/${e.id}`),I&&F(!1)}},e.id)),ie.length===0&&(0,K.jsx)(`div`,{className:`mx-2 px-2 py-1 text-[11px] text-gray-400`,children:`no DMs yet`})]})]}),(0,K.jsx)(`div`,{className:`flex-1`})]});return(0,K.jsxs)(`div`,{className:`flex h-full w-full bg-white`,children:[I?(0,K.jsx)(K.Fragment,{children:P?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>F(!1),children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-60 max-w-[80vw] shadow-xl`,onClick:e=>e.stopPropagation(),children:Te})]}):(0,K.jsx)(`aside`,{className:`w-9 shrink-0 border-r border-gray-200 bg-white flex flex-col items-center pt-2`,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>F(!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 sidebar`,children:(0,K.jsx)(Fe,{size:16})})})}):Te,(0,K.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white`,children:G?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`header`,{className:`px-5 h-12 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsxs)(`span`,{className:`text-[15px] font-medium text-gray-900 truncate`,children:[DY(G),EY(G)]}),G.topic&&(0,K.jsxs)(`span`,{className:`text-xs text-gray-500 truncate`,children:[`— `,G.topic]})]})}),(0,K.jsxs)(`div`,{ref:ue,className:`flex-1 min-h-0 overflow-auto px-5 py-4 flex flex-col gap-3 chat-messages-container`,children:[l.length===0&&(0,K.jsx)(`div`,{className:`text-[13px] text-gray-500`,children:`no messages yet — say hi`}),U.map(e=>(0,K.jsx)(jY,{message:e,isMe:e.author===t,active:e.id===b,onOpenThread:()=>x(e.id)},e.id)),h.filter(e=>e.convId===i).map(e=>(0,K.jsx)(MY,{pending:e,author:t,onRetry:()=>he(e),onDiscard:()=>ge(e.tempId)},e.tempId)),(0,K.jsx)(`div`,{ref:L})]}),(0,K.jsx)(`div`,{className:`px-5 pb-4 pt-2 shrink-0`,children:(0,K.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white p-2.5 shadow-sm flex flex-col gap-2`,children:[(0,K.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),me())},rows:1,placeholder:`Message ${DY(G)}${EY(G)}…`,className:`field-sizing-content w-full max-h-40 min-h-10 resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 pt-2 px-0.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400`,children:`Enter to send · Shift+Enter for newline`}),(0,K.jsx)(`button`,{type:`button`,onClick:me,disabled:p||!d.trim(),className:`px-3 py-1 rounded bg-gray-900 text-white text-xs hover:bg-gray-700 disabled:opacity-40`,children:`send`})]})]})})]}):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-gray-500 text-sm`,children:`select a conversation`})}),G&&b!=null&&(0,K.jsx)(kY,{isMobile:I,thread:S,me:t,spawning:O,threadDraft:w,threadSending:E,pendingReplies:v,threadEndRef:R,onClose:()=>x(null),onSpawnLoop:xe,onThreadDraftChange:T,onThreadSend:ve,onRetryReply:ye,onDiscardReply:be}),M&&(0,K.jsx)(NY,{onClose:()=>N(!1),onCreate:Se}),A&&(0,K.jsx)(PY,{users:s,existing:ie,onClose:()=>j(!1),onPick:we})]})}function kY({isMobile:e,thread:t,me:n,spawning:r,threadDraft:i,threadSending:a,pendingReplies:o,threadEndRef:s,onClose:c,onSpawnLoop:l,onThreadDraftChange:u,onThreadSend:d,onRetryReply:f,onDiscardReply:p}){let m=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`header`,{className:`px-4 h-12 shrink-0 border-b border-gray-200 flex items-center justify-between`,children:[(0,K.jsx)(`div`,{className:`text-[13px] font-medium text-gray-900`,children:`Thread`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:l,disabled:r||!t,className:`px-2 py-1 rounded border border-gray-200 text-[11px] text-gray-700 hover:bg-gray-50 hover:border-gray-300 disabled:opacity-50 flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-gray-500`,children:`⑂`}),(0,K.jsx)(`span`,{children:r?`spawning…`:`spawn loop`})]}),(0,K.jsx)(`button`,{type:`button`,onClick:c,className:`text-gray-400 hover:text-gray-900 text-base leading-none px-1`,children:`×`})]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto px-4 py-3 flex flex-col gap-3`,children:t===null?(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`loading…`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(jY,{message:t.root,isMe:t.root.author===n,compact:!0}),t.replies.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-gray-400`,children:[(0,K.jsx)(`span`,{className:`flex-1 h-px bg-gray-200`}),(0,K.jsxs)(`span`,{children:[t.replies.length,` `,t.replies.length===1?`reply`:`replies`]}),(0,K.jsx)(`span`,{className:`flex-1 h-px bg-gray-200`})]}),t.replies.map(e=>(0,K.jsx)(jY,{message:e,isMe:e.author===n,compact:!0},e.id)),o.filter(e=>t&&e.parentId===t.root.id).map(e=>(0,K.jsx)(MY,{pending:e,author:n,compact:!0,onRetry:()=>f(e),onDiscard:()=>p(e.tempId)},e.tempId)),(0,K.jsx)(`div`,{ref:s})]})}),(0,K.jsx)(`div`,{className:`px-4 pb-4 pt-2 shrink-0`,children:(0,K.jsxs)(`div`,{className:`rounded-2xl border border-gray-200 bg-white p-2.5 shadow-sm flex flex-col gap-2`,children:[(0,K.jsx)(`textarea`,{value:i,onChange:e=>u(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),d())},rows:1,placeholder:`Reply…`,className:`field-sizing-content w-full max-h-40 min-h-10 resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 pt-2 px-0.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400`,children:`Enter to reply · Shift+Enter for newline`}),(0,K.jsx)(`button`,{type:`button`,onClick:d,disabled:a||!i.trim()||!t,className:`px-3 py-1 rounded bg-gray-900 text-white text-xs hover:bg-gray-700 disabled:opacity-40`,children:`reply`})]})]})})]});return e?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:c,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/30`}),(0,K.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-full max-w-full bg-white border-l border-gray-200 shadow-xl flex flex-col`,onClick:e=>e.stopPropagation(),children:m})]}):(0,K.jsx)(`aside`,{className:`w-[28rem] max-w-[40vw] min-w-[20rem] shrink-0 border-l border-gray-200 bg-white flex flex-col`,children:m})}function AY(e){let t=e.conv;return(0,K.jsxs)(`div`,{className:`relative group`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:e.onClick,className:e.active?`mx-2 px-2 py-1 w-[calc(100%-1rem)] rounded text-[13px] flex items-center gap-2 bg-gray-100 text-gray-900`:`mx-2 px-2 py-1 w-[calc(100%-1rem)] rounded text-[13px] flex items-center gap-2 text-gray-500 hover:bg-gray-50 hover:text-gray-900`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:DY(t)}),(0,K.jsx)(`span`,{className:`truncate flex-1 text-left`,children:EY(t)}),t.unread>0&&(0,K.jsx)(`span`,{className:`text-[11px] px-1.5 rounded-full bg-gray-200 text-gray-700`,children:t.unread})]}),e.onDelete&&(0,K.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),e.onDelete()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-red-600 opacity-0 group-hover:opacity-100 text-xs px-1`,title:`delete channel (admin)`,children:`×`})]})}function jY(e){let t=e.message,n=e.isMe,r=`replyCount`in t?t.replyCount:0,i=`lastReplyTs`in t?t.lastReplyTs:null;return(0,K.jsxs)(`div`,{className:`group/msg relative -mx-1 px-1 py-0.5 rounded flex gap-3 `+(n?`flex-row-reverse `:``)+(e.active?`bg-amber-50/60`:`hover:bg-gray-50`),children:[(0,K.jsx)(`div`,{className:n?`w-7 h-7 rounded shrink-0 flex items-center justify-center text-[11px] font-medium bg-gray-900 text-white`:`w-7 h-7 rounded shrink-0 flex items-center justify-center text-[11px] font-medium bg-gray-200 text-gray-900`,title:t.author,children:t.author.slice(0,1).toUpperCase()}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 ${n?`justify-end`:``}`,children:n?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:TY(t.ts)}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:`you`}),(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:t.author})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:t.author}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:TY(t.ts)})]})}),(0,K.jsx)(`div`,{className:`text-[13px] text-gray-900 whitespace-pre-wrap leading-relaxed break-words ${n?`text-right`:``}`,children:t.text}),!e.compact&&e.onOpenThread&&r>0&&(0,K.jsxs)(`button`,{type:`button`,onClick:e.onOpenThread,className:`mt-1 text-[11px] text-blue-600 hover:underline ${n?`ml-auto block text-right`:``}`,children:[`💬 `,r,` `,r===1?`reply`:`replies`,i&&(0,K.jsxs)(`span`,{className:`text-gray-400 ml-1.5`,children:[`· last `,TY(i)]})]}),!e.compact&&e.onOpenThread&&r===0&&(0,K.jsx)(`button`,{type:`button`,onClick:e.onOpenThread,className:`mt-1 text-[11px] text-gray-400 hover:text-blue-600 hover:underline opacity-0 group-hover/msg:opacity-100 transition-opacity `+(n?`ml-auto block text-right`:``),children:`💬 Reply`})]})]})}function MY(e){let t=e.pending,n=t.status===`failed`;return(0,K.jsxs)(`div`,{className:`flex flex-row-reverse gap-3 -mx-1 px-1 py-0.5 rounded `+(n?`ring-1 ring-red-200 bg-red-50/40`:``),children:[(0,K.jsx)(`div`,{className:`w-7 h-7 rounded shrink-0 flex items-center justify-center text-[11px] font-medium bg-gray-900 text-white`,title:e.author,children:e.author.slice(0,1).toUpperCase()}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:TY(t.ts)}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-500`,children:`you`}),(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:e.author}),n?(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-red-100 text-red-700 border border-red-200`,children:`failed`}):(0,K.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-gray-100 text-gray-500 inline-flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full bg-gray-400 animate-pulse`}),`sending…`]})]}),(0,K.jsx)(`div`,{className:`text-[13px] whitespace-pre-wrap leading-relaxed break-words text-right `+(n?`text-gray-700`:`text-gray-400`),children:t.text}),n&&(0,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 justify-end text-[11px]`,children:[t.error&&(0,K.jsx)(`span`,{className:`text-red-600`,children:t.error}),(0,K.jsx)(`button`,{type:`button`,onClick:e.onRetry,className:`px-1.5 py-0.5 rounded border border-gray-300 text-gray-700 hover:bg-white`,children:`retry`}),(0,K.jsx)(`button`,{type:`button`,onClick:e.onDiscard,className:`px-1.5 py-0.5 rounded text-gray-500 hover:text-red-600`,children:`discard`})]})]})]})}function NY(e){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)(``);return(0,K.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/30 flex items-center justify-center`,onClick:e.onClose,children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-lg w-96 p-4 flex flex-col gap-3`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:`New channel`}),(0,K.jsx)(`input`,{autoFocus:!0,value:t,onChange:e=>n(e.target.value),placeholder:`channel-name`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,K.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`topic (optional)`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 pt-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:e.onClose,className:`px-3 py-1.5 text-xs text-gray-600 hover:text-gray-900`,children:`cancel`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>t.trim()&&e.onCreate(t.trim(),r.trim()),disabled:!t.trim(),className:`px-3 py-1.5 text-xs rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`create`})]})]})})}function PY(e){let[t,n]=(0,_.useState)(``),r=e.users.filter(e=>!e.isMe).filter(e=>e.id.toLowerCase().includes(t.toLowerCase()));return(0,K.jsx)(`div`,{className:`fixed inset-0 z-30 bg-black/30 flex items-center justify-center`,onClick:e.onClose,children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-lg w-96 p-4 flex flex-col gap-3`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:`Direct message`}),(0,K.jsx)(`input`,{autoFocus:!0,value:t,onChange:e=>n(e.target.value),placeholder:`search users…`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,K.jsxs)(`div`,{className:`max-h-64 overflow-auto flex flex-col gap-0.5`,children:[r.map(t=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e.onPick(t.id),className:`text-left px-2 py-1.5 text-sm rounded hover:bg-gray-100 flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-6 h-6 rounded bg-gray-200 text-gray-900 text-[11px] flex items-center justify-center`,children:t.id.slice(0,1).toUpperCase()}),(0,K.jsx)(`span`,{children:t.id}),t.role===`admin`&&(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 ml-auto`,children:`admin`})]},t.id)),r.length===0&&(0,K.jsx)(`div`,{className:`text-xs text-gray-400 px-2 py-2`,children:`no users match`})]})]})})}async function FY(e){try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-9999px`,document.body.appendChild(t),t.focus(),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function IY({onDone:e}={}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)([]),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(``),[S,C]=(0,_.useState)(``),[w,T]=(0,_.useState)(``),[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)([]),[A,j]=(0,_.useState)(!1),[M,N]=(0,_.useState)(null),[F,I]=(0,_.useState)(!1),[L,R]=(0,_.useState)(null),[z,B]=(0,_.useState)(!1),[V,H]=(0,_.useState)(!1),[U,ee]=(0,_.useState)(`token`),[W,te]=(0,_.useState)(``);(0,_.useEffect)(()=>{f(null),m(!1),g([]),u(``),c(!1),R(null),H(!1),i(!0),Jp().then(e=>{n(e),o(e?.personalRepo??``),C(e?.gitHost?.defaultRepo??`loopat-personal`)}).finally(()=>i(!1))},[]);let ne=async()=>{t?.publicKey&&await FY(t.publicKey)&&(I(!0),setTimeout(()=>I(!1),1500))},G=async()=>{L&&await FY(L)&&(B(!0),setTimeout(()=>B(!1),1500))},re=async()=>{if(!v){f(null),m(!1),g([]),y(!0);try{let e=await tm(a.trim()||void 0,s&&l.trim()?l.trim():void 0);if(!e.ok){f(e.error??`import failed`),e.notClean&&m(!0),e.secretsExposed&&g(e.exposedFiles??[]);return}e.autoInitialized&&e.cryptKey?R(e.cryptKey):n(await Jp())}finally{y(!1)}}},ie=async()=>{if(!A){N(null),j(!0);try{let e=await nm(b.trim(),S.trim()||void 0,w.trim()||void 0);if(!e.ok){e.needsCryptKey?(D(!0),N(`This repo already has a .loopat vault — paste its git-crypt key to unlock it.`)):N(e.error??`setup failed`);return}e.autoInitialized&&e.cryptKey?R(e.cryptKey):n(await Jp())}finally{j(!1)}}},ae=async()=>{if(!(A||!b.trim())){N(null),j(!0);try{let e=await qp(b.trim());if(!e.ok){N(e.error??`invalid token`);return}k(e.repos),e.login&&te(e.login),ee(`repo`)}finally{j(!1)}}},oe=t?.gitHost?.provider??`github`,se=oe===`github`?`GitHub`:oe,ce=O.some(e=>e.name===S.trim()),le=t?.gitHost?.baseUrl&&W&&S.trim()?`${t.gitHost.baseUrl.replace(/\/+$/,``)}/${W}/${S.trim()}`:null;if(r)return(0,K.jsx)(`div`,{className:`text-sm text-gray-400 py-8 text-center`,children:`loading…`});if(!t)return(0,K.jsx)(`div`,{className:`text-sm text-red-600`,children:`failed to load status`});if(L)return(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-2 py-1`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-full bg-emerald-100`,children:(0,K.jsx)(P,{size:20,className:`text-emerald-600`})}),(0,K.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:`Your personal repo is ready 🎉`})]}),(0,K.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:`One last thing — back up your git-crypt key`}),(0,K.jsxs)(`div`,{className:`text-xs text-gray-600 leading-relaxed`,children:[`The symmetric key below decrypts everything under`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat/vaults/`}),`. It's already stored on this host, but `,(0,K.jsx)(`b`,{children:`save your own copy`}),` — if this host dies and you don't have it, your secrets are unrecoverable.`]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`textarea`,{readOnly:!0,value:L,rows:4,className:`w-full text-[11px] font-mono text-gray-800 bg-gray-50 border border-gray-200 rounded p-2 outline-none resize-none break-all`,onClick:e=>e.target.select()}),(0,K.jsx)(`button`,{type:`button`,onClick:G,className:`absolute top-1.5 right-1.5 px-2 py-0.5 text-[11px] rounded bg-white border border-gray-300 text-gray-700 hover:bg-gray-100`,children:z?`copied`:`copy`})]}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed bg-gray-50 border border-gray-200 rounded p-2`,children:[(0,K.jsx)(`b`,{children:`Suggested:`}),` stash this in your password manager (1Password / Bitwarden / Apple Keychain). To later restore on a new host, paste this same value into the Recovery field on the new host's Personal repo settings.`]}),(0,K.jsxs)(`div`,{className:`text-[11px] text-emerald-700 leading-relaxed bg-emerald-50 border border-emerald-200 rounded p-2`,children:[(0,K.jsx)(`b`,{children:`Next:`}),` if your providers need API keys, add them in`,` `,(0,K.jsx)(`b`,{children:`Settings → Providers`}),` to start chatting.`]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:V,onChange:e=>H(e.target.checked),className:`accent-gray-900`}),`I've saved this key somewhere safe.`]}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{V&&(n(await Jp()),R(null),e&&e())},disabled:!V,className:`self-end px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:`Done`})]});if(t.imported)return(0,K.jsx)(LY,{status:t});if(!t.publicKey)return(0,K.jsxs)(`div`,{className:`text-sm text-amber-700 bg-amber-50 border border-amber-200 rounded px-2 py-2 leading-relaxed`,children:[`No deploy key available — the server is probably missing`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-white px-1 rounded`,children:`openssh-client`}),`. Install it and reopen this panel.`]});let ue=[`token`,`repo`,`confirm`].indexOf(U);return(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-2 text-[11px] mb-1`,children:[{k:`token`,label:`Token`},{k:`repo`,label:`Repository`},{k:`confirm`,label:`Confirm`}].map((e,t)=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 ${U===e.k?`text-gray-900 font-medium`:t<ue?`text-emerald-600`:`text-gray-400`}`,children:[(0,K.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 rounded-full text-[9px] ${U===e.k?`bg-gray-900 text-white`:t<ue?`bg-emerald-500 text-white`:`bg-gray-200 text-gray-500`}`,children:t<ue?`✓`:t+1}),e.label]}),t<2&&(0,K.jsx)(`span`,{className:`text-gray-300`,children:`→`})]},e.k))}),U===`token`&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[`Paste your `,se,` token. Loopat will list your repos so you can pick one (or create a new one), then set everything up with git-crypt — no manual repo creation or deploy-key pasting.`]}),(0,K.jsx)(`input`,{type:`password`,value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ae())},placeholder:`${se} personal access / private token`,autoComplete:`off`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),t.gitHost?.tokenHelp&&(/^https?:\/\//.test(t.gitHost.tokenHelp)?(0,K.jsx)(`a`,{href:t.gitHost.tokenHelp,target:`_blank`,rel:`noreferrer`,className:`text-[11px] text-blue-600 hover:underline w-fit`,children:`Where do I get a token? ↗`}):(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 leading-relaxed`,children:t.gitHost.tokenHelp})),M&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:M}),(0,K.jsx)(`button`,{type:`button`,onClick:ae,disabled:A||!b.trim(),className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:A?`loading repos…`:`Next`}),oe===`github`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 text-center`,children:`— or set up a deploy key manually —`}),(0,K.jsxs)(`div`,{className:`text-xs text-gray-600 leading-relaxed`,children:[`Two steps:`,(0,K.jsxs)(`ol`,{className:`list-decimal pl-5 mt-1 space-y-0.5 text-gray-600`,children:[(0,K.jsxs)(`li`,{children:[`Create a `,(0,K.jsx)(`b`,{children:`fresh, empty`}),` private GitHub repo (no README, no`,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat/`}),`).`]}),(0,K.jsxs)(`li`,{children:[`Paste the public key below into that repo's`,` `,(0,K.jsx)(`i`,{children:`Settings → Deploy keys → Add deploy key`}),`, check`,` `,(0,K.jsx)(`b`,{children:`Allow write access`}),`, then put the repo URL here and Continue.`]})]}),(0,K.jsxs)(`div`,{className:`mt-2 text-[11px] text-gray-500`,children:[`Loopat will run `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`git-crypt init`}),` `,`inside your repo for you and push the encrypted scaffold. You don't need git-crypt installed locally.`]})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`textarea`,{readOnly:!0,value:t.publicKey,rows:3,className:`w-full text-[11px] font-mono text-gray-800 bg-gray-50 border border-gray-200 rounded p-2 outline-none resize-none`,onClick:e=>e.target.select()}),(0,K.jsx)(`button`,{type:`button`,onClick:ne,className:`absolute top-1.5 right-1.5 px-2 py-0.5 text-[11px] rounded bg-white border border-gray-300 text-gray-700 hover:bg-gray-100`,children:F?`copied`:`copy`})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:`Repo URL`}),(0,K.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`git@github.com:you/loopat-personal.git`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})]}),(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`w-full flex justify-between items-center px-2.5 py-1.5 text-[11px] text-gray-600 hover:bg-gray-50`,children:[(0,K.jsx)(`span`,{children:`Recovery: I already have a git-crypt key for this repo`}),(0,K.jsx)(`span`,{className:`text-gray-400`,children:s?`▾`:`▸`})]}),s&&(0,K.jsxs)(`div`,{className:`px-2.5 pb-2.5 text-[11px] text-gray-600 leading-relaxed border-t border-gray-200`,children:[(0,K.jsx)(`p`,{className:`mt-2`,children:`Use this if you're re-importing an existing loopat repo onto a new host (or this host lost its host-secrets). The repo must already have git-crypt configured.`}),(0,K.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:3,placeholder:`base64 git-crypt key`,className:`mt-2 w-full px-2 py-1.5 text-[11px] font-mono border border-gray-300 rounded outline-none focus:border-gray-500 resize-none`}),(0,K.jsxs)(`p`,{className:`mt-1 text-gray-500`,children:[`Paste the value you saved from "Back up your git-crypt key" on another host (or the base64 of`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`git-crypt export-key`}),` `,`if you originally set the repo up by hand).`]})]})]}),h.length>0&&(0,K.jsxs)(`div`,{className:`text-xs bg-red-50 border border-red-300 rounded p-2.5 leading-relaxed`,children:[(0,K.jsx)(`div`,{className:`font-semibold text-red-700 mb-1`,children:`⚠️ Your secrets are exposed`}),(0,K.jsxs)(`div`,{className:`text-red-700 mb-1.5`,children:[`The following files appear in git as `,(0,K.jsx)(`b`,{children:`plaintext`}),`. Anyone with repo access can already read them:`]}),(0,K.jsx)(`ul`,{className:`font-mono text-[10.5px] text-red-800 bg-white/60 rounded p-1.5 max-h-24 overflow-auto`,children:h.map(e=>(0,K.jsx)(`li`,{children:e},e))}),(0,K.jsxs)(`ol`,{className:`list-decimal pl-4 text-red-700 space-y-0.5 mt-2`,children:[(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`b`,{children:`Rotate`}),` the leaked secrets immediately — the old ones are burned.`]}),(0,K.jsx)(`li`,{children:`Create a fresh empty repo and point loopat there instead.`})]})]}),p&&h.length===0&&(0,K.jsxs)(`div`,{className:`text-xs bg-amber-50 border border-amber-300 rounded p-2.5 leading-relaxed text-amber-800`,children:[(0,K.jsx)(`div`,{className:`font-semibold mb-0.5`,children:`This repo isn't a clean slate`}),(0,K.jsx)(`div`,{children:d}),(0,K.jsxs)(`div`,{className:`mt-1.5 text-amber-700`,children:[`Two options: point at a fresh empty repo, or — if it's your own previous loopat repo — expand `,(0,K.jsx)(`i`,{children:`Recovery`}),` above and paste the crypt key.`]})]}),d&&!p&&h.length===0&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:d}),(0,K.jsx)(`div`,{className:`flex gap-2 mt-1`,children:(0,K.jsx)(`button`,{type:`button`,onClick:re,disabled:v||!a.trim(),className:`flex-1 px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:v?s&&l.trim()?`unlocking…`:`initializing…`:`Continue`})})]})]}),U===`repo`&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:`Pick one of your repos, or type a new name to create one. Repos with "personal" in the name are listed first.`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 max-h-52 overflow-auto border border-gray-200 rounded p-1`,children:[O.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 px-2 py-4 text-center`,children:`no existing repos found — type a name below to create one`}),O.map(e=>{let t=S.trim()===e.name;return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>C(e.name),className:`flex items-center justify-between gap-2 px-2 py-1.5 rounded text-left text-xs ${t?`bg-gray-900 text-white`:`hover:bg-gray-100 text-gray-700`}`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[t&&(0,K.jsx)(P,{size:12,className:`shrink-0`}),(0,K.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),e.name.includes(`personal`)&&(0,K.jsx)(`span`,{className:`text-[9px] px-1 rounded ${t?`bg-white/20`:`bg-emerald-100 text-emerald-700`}`,children:`personal`})]}),(0,K.jsx)(`span`,{className:`text-[10px] truncate ${t?`text-white/60`:`text-gray-400`}`,children:e.path})]},e.path)})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`or type a new repo name`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S.trim()&&(e.preventDefault(),N(null),ee(`confirm`))},placeholder:`loopat-personal`,className:`flex-1 px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),(0,K.jsx)(`span`,{className:`text-[11px] whitespace-nowrap ${ce?`text-gray-500`:`text-emerald-600`}`,children:S.trim()?ce?`use existing`:`will create`:``})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{ee(`token`),N(null)},className:`px-3 h-9 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Back`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{N(null),ee(`confirm`)},disabled:!S.trim(),className:`flex-1 px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:`Next`})]})]}),U===`confirm`&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded p-3 text-xs text-gray-700 leading-relaxed flex flex-col gap-2`,children:[ce?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`font-semibold text-gray-900`,children:`Use existing repo`}),(0,K.jsxs)(`div`,{children:[`Loopat will use your existing repo`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:S.trim()}),` and create a git-crypt-encrypted`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat/`}),` vault inside it. The repo should be a clean slate — if it already has a`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat`}),` vault you'll be asked for its git-crypt key.`]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`font-semibold text-gray-900`,children:`Create new repo`}),(0,K.jsxs)(`div`,{children:[`Loopat will create a new private `,se,` repo named`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:S.trim()}),`, then initialize a git-crypt-encrypted`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`.loopat/`}),` vault and push it. Your secrets stay encrypted in git.`]})]}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500`,children:`You'll get a one-time git-crypt key to back up right after.`}),le&&(0,K.jsxs)(`a`,{href:le,target:`_blank`,rel:`noreferrer`,className:`text-[11px] text-blue-600 hover:underline break-all w-fit`,children:[le,` ↗`]})]}),E&&(0,K.jsx)(`textarea`,{value:w,onChange:e=>T(e.target.value),rows:3,placeholder:`git-crypt key — this repo already has a .loopat vault, paste its key to unlock`,className:`w-full px-2 py-1.5 text-[11px] font-mono border border-gray-300 rounded outline-none focus:border-gray-500 resize-none`}),M&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:M}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{ee(`repo`),N(null)},disabled:A,className:`px-3 h-9 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50 disabled:opacity-50`,children:`Back`}),(0,K.jsx)(`button`,{type:`button`,onClick:ie,disabled:A,className:`flex-1 px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:A?`setting up…`:ce?`Use this repo`:`Create & set up`})]})]})]})}function LY({status:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null),s=async()=>{n(`pull`),i(null),i(await $p())},c=async()=>{n(`push`),o(null),o(await em())};return(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsxs)(`div`,{className:`text-sm text-gray-700`,children:[`Imported`,` `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 py-0.5 rounded`,children:e.personalRepo??`(unknown remote)`}),`.`]}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 leading-relaxed`,children:`Sync your personal vault with the remote repo.`}),t===`export`?(0,K.jsx)(VY,{onDone:()=>n(null)}):t===`delete`?(0,K.jsx)(HY,{status:e,onDone:()=>n(null)}):t===`pull`?(0,K.jsx)(zY,{type:`pull`,result:r,onDone:()=>n(null),onRetry:s}):t===`push`?(0,K.jsx)(zY,{type:`push`,result:a,onDone:()=>n(null),onRetry:c}):t===`showkey`?(0,K.jsx)(BY,{vaultKeys:e.vaultKeys??[],onDone:()=>n(null)}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:s,className:`flex-1 flex items-center justify-center gap-1.5 px-2.5 py-1.5 text-[11px] text-gray-700 border border-gray-200 rounded hover:bg-gray-50`,children:[(0,K.jsx)(T,{size:12}),`Pull`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:c,className:`flex-1 flex items-center justify-center gap-1.5 px-2.5 py-1.5 text-[11px] text-gray-700 border border-gray-200 rounded hover:bg-gray-50`,children:[(0,K.jsx)(O,{size:12}),`Push`]})]}),(e.vaultKeys?.length??0)>0&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>n(`showkey`),className:`w-full text-left px-2.5 py-1.5 text-[11px] text-gray-700 border border-gray-200 rounded hover:bg-gray-50`,children:`Show vault SSH keys (for team repos)`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>n(`export`),className:`w-full text-left px-2.5 py-1.5 text-[11px] text-gray-700 border border-gray-200 rounded hover:bg-gray-50`,children:`Show / export git-crypt key (requires password)`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>n(`delete`),className:`w-full text-left px-2.5 py-1.5 text-[11px] text-red-700 border border-red-200 rounded hover:bg-red-50`,children:`Delete personal vault (requires password)`})]})]})}function RY({onRetry:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(!1);return r?(0,K.jsx)(`button`,{disabled:!0,className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white opacity-50`,children:`Force pulling…`}):t?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:async()=>{i(!0);let t=await $p({force:!0});i(!1),n(!1),t.ok&&e()},className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800`,children:`Confirm — discard all local changes`}),(0,K.jsx)(`button`,{onClick:()=>n(!1),className:`px-3 h-8 text-sm rounded border border-gray-200 text-gray-600 hover:bg-gray-100`,children:`Cancel`})]}):(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>n(!0),className:`flex-1 px-3 h-8 text-sm rounded bg-amber-600 text-white hover:bg-amber-700`,children:`Discard changes & force pull`}),(0,K.jsx)(`button`,{onClick:e,className:`px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800`,children:`Retry`})]})}function zY({type:e,result:t,onDone:n,onRetry:r}){let[i,a]=(0,_.useState)(!1);if(!t)return(0,K.jsx)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:(0,K.jsx)(`div`,{className:`text-xs font-semibold text-gray-900`,children:e===`pull`?`Pulling from remote...`:`Pushing to remote...`})});if(t.ok)return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-emerald-200 bg-emerald-50 rounded p-2.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-emerald-800`,children:[(0,K.jsx)(P,{size:14}),e===`pull`?`Pulled successfully`:`Pushed successfully`]}),(0,K.jsx)(`div`,{className:`text-xs text-emerald-700 leading-relaxed`,children:e===`pull`?`Your local vault is now up to date with the remote.`:`Your changes have been pushed to the remote.`}),(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`self-end px-3 h-8 text-sm rounded bg-emerald-700 text-white hover:bg-emerald-800`,children:`Done`})]});let o=(t.conflict??!1)&&(t.files?.length??0)>0,s=e===`push`&&t.needsPull;return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-red-200 bg-red-50 rounded p-2.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-red-800`,children:[(0,K.jsx)(nt,{size:14}),o?`Held back — conflicts with remote`:e===`pull`?`Pull failed`:`Push failed`]}),o&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:[`Your change conflicts with the remote, so it wasn't merged — but your local edit is `,(0,K.jsx)(`b`,{children:`kept, not lost`}),`. Either take the remote (discard this edit) or resolve it by hand / in a loop.`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`text-left text-[11px] text-red-700 underline`,children:[i?`Hide`:`Show`,` conflicting files (`,t.files.length,`)`]}),i&&(0,K.jsx)(`ul`,{className:`font-mono text-[10.5px] text-red-900 bg-white/60 rounded p-1.5 max-h-24 overflow-auto`,children:t.files.map(e=>(0,K.jsx)(`li`,{children:e},e))})]}),s&&!o&&(0,K.jsx)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:`Remote moved again while pushing. Just try again.`}),!o&&!s&&(0,K.jsx)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:t.error}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[o?(0,K.jsx)(RY,{onRetry:r}):(0,K.jsx)(`button`,{type:`button`,onClick:r,className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800`,children:`Retry`}),(0,K.jsx)(`button`,{type:`button`,onClick:n,className:`px-3 h-8 text-sm rounded border border-red-300 text-red-700 bg-white hover:bg-red-50`,children:`Close`})]})]})}function BY({vaultKeys:e,onDone:t}){let[n,r]=(0,_.useState)(null),i=async(e,t)=>{await FY(t)&&(r(e),setTimeout(()=>r(null),1500))};return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold text-gray-900`,children:`Vault SSH keys — for team repos`}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[`Register these on the git host that hosts your `,(0,K.jsx)(`b`,{children:`team`}),` repos (knowledge / notes / repos). A loop authenticates with its vault's key — one per vault. Public keys, safe to share. (The deploy key is separate — it's for your `,(0,K.jsx)(`i`,{children:`personal`}),` repo only.)`]}),e.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400`,children:`No vault keys yet.`}),e.map(e=>(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-600 font-medium`,children:[`vault: `,e.vault]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`textarea`,{readOnly:!0,value:e.publicKey,rows:3,className:`w-full text-[11px] font-mono text-gray-800 bg-gray-50 border border-gray-200 rounded p-2 outline-none resize-none break-all`,onClick:e=>e.target.select()}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>i(e.vault,e.publicKey),className:`absolute top-1.5 right-1.5 px-2 py-0.5 text-[11px] rounded bg-white border border-gray-300 text-gray-700 hover:bg-gray-100`,children:n===e.vault?`copied`:`copy`})]})]},e.vault)),(0,K.jsx)(`button`,{type:`button`,onClick:t,className:`self-end px-3 h-8 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Close`})]})}function VY({onDone:e}){let[t,n]=(0,_.useState)(``),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(!1),d=async()=>{if(!(r||!t)){o(null),i(!0);try{let e=await Zp(t);e.ok?c(e.cryptKey):o(e.error)}finally{i(!1)}}};return s?(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold text-gray-900`,children:`git-crypt key`}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`textarea`,{readOnly:!0,value:s,rows:4,className:`w-full text-[11px] font-mono text-gray-800 bg-gray-50 border border-gray-200 rounded p-2 outline-none resize-none break-all`,onClick:e=>e.target.select()}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{if(s)try{await navigator.clipboard.writeText(s),u(!0),setTimeout(()=>u(!1),1500)}catch{}},className:`absolute top-1.5 right-1.5 px-2 py-0.5 text-[11px] rounded bg-white border border-gray-300 text-gray-700 hover:bg-gray-100`,children:l?`copied`:`copy`})]}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[`Treat it like a password — anyone with this key can decrypt everything under `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`.loopat/vaults/`}),`.`]}),(0,K.jsx)(`button`,{type:`button`,onClick:e,className:`self-end px-3 h-8 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Close`})]}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold text-gray-900`,children:`Confirm password to reveal the key`}),(0,K.jsx)(`input`,{type:`password`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},autoFocus:!0,autoComplete:`current-password`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),a&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:a}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:d,disabled:r||!t,className:`flex-1 px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:r?`verifying…`:`Reveal`}),(0,K.jsx)(`button`,{type:`button`,onClick:e,disabled:r,className:`px-3 h-8 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Cancel`})]})]})}function HY({status:e,onDone:t}){let[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=()=>{t(),setTimeout(()=>window.location.reload(),50)},b=async e=>{if(!(i||!n)){s(null),a(!0);try{let t=await Qp(n,e);if(t.ok){v({synced:t.synced??!1,dataLost:t.dataLost??!1});return}if(t.wrongPassword){s(t.error??`wrong password`);return}if(t.syncFailed){l({syncError:t.syncError??t.error??`unknown sync error`,uncommitted:t.uncommitted,unpushed:t.unpushed,hasRemote:t.hasRemote});return}s(t.error??`delete failed`)}finally{a(!1)}}};if(g)return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-gray-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-sm font-semibold text-gray-900`,children:`Vault deleted`}),(0,K.jsx)(`div`,{className:`text-xs text-gray-600 leading-relaxed`,children:g.dataLost?(0,K.jsx)(`span`,{className:`text-red-700`,children:`Unsynced changes were discarded. The vault is gone.`}):g.synced?`Synced to remote and deleted. You can re-import any time.`:`Vault deleted. You can re-import any time.`}),(0,K.jsx)(`button`,{type:`button`,onClick:y,className:`self-end px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700`,children:`Done`})]});if(c){let e=u&&f&&m;return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-red-300 bg-red-50 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-sm font-semibold text-red-800`,children:`⚠️ Sync failed — data will be lost`}),(0,K.jsxs)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:[`Loopat couldn't push your local changes to the remote.`,(c.uncommitted??0)>0&&(0,K.jsxs)(`span`,{children:[` `,c.uncommitted,` uncommitted file(s).`]}),(c.unpushed??0)>0&&(0,K.jsxs)(`span`,{children:[` `,c.unpushed,` unpushed commit(s).`]}),c.hasRemote===!1&&(0,K.jsx)(`span`,{children:` No remote is configured on this vault.`})]}),(0,K.jsx)(`pre`,{className:`text-[10.5px] text-red-900 bg-white/60 border border-red-200 rounded p-1.5 overflow-auto max-h-24`,children:c.syncError}),(0,K.jsx)(`div`,{className:`text-xs text-red-800 leading-relaxed`,children:`Continuing now will permanently delete the unsynced changes from this host. To keep them, cancel and resolve the sync issue first (network, deploy-key write access, branch protection).`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 mt-1 text-xs text-red-900`,children:[(0,K.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`mt-0.5 accent-red-700`}),(0,K.jsx)(`span`,{children:`I understand the unsynced changes will be deleted.`})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`mt-0.5 accent-red-700`}),(0,K.jsx)(`span`,{children:`I cannot recover them from this host afterwards.`})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`mt-0.5 accent-red-700`}),(0,K.jsx)(`span`,{children:`I still want to delete the vault now.`})]})]}),o&&(0,K.jsx)(`div`,{className:`text-xs text-red-700 bg-white border border-red-200 rounded px-2 py-1.5`,children:o}),(0,K.jsxs)(`div`,{className:`flex gap-2 mt-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(!0),disabled:i||!e,className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800 disabled:opacity-40`,children:i?`deleting…`:`Delete anyway`}),(0,K.jsx)(`button`,{type:`button`,onClick:t,disabled:i,className:`px-3 h-8 text-sm rounded border border-red-300 text-red-700 bg-white hover:bg-red-50`,children:`Cancel`})]})]})}return(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 border border-red-200 rounded p-2.5`,children:[(0,K.jsx)(`div`,{className:`text-xs font-semibold text-red-800`,children:`Delete personal vault`}),(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-600 leading-relaxed`,children:[`Removes `,(0,K.jsxs)(`code`,{className:`bg-gray-100 px-1 rounded`,children:[`personal/`,e.userId,`/`]}),` `,`on this host and forgets the git-crypt key. Loopat will try to push any unsynced changes to`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:e.personalRepo??`remote`}),` `,`first. Your GitHub repo itself is not touched.`]}),(0,K.jsx)(`input`,{type:`password`,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&b(!1)},placeholder:`confirm password`,autoFocus:!0,autoComplete:`current-password`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`}),o&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:o}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>b(!1),disabled:i||!n,className:`flex-1 px-3 h-8 text-sm rounded bg-red-700 text-white hover:bg-red-800 disabled:opacity-50`,children:i?`working…`:`Sync & delete`}),(0,K.jsx)(`button`,{type:`button`,onClick:t,disabled:i,className:`px-3 h-8 text-sm rounded border border-gray-300 text-gray-700 hover:bg-gray-50`,children:`Cancel`})]})]})}function UY({label:e,value:t}){let[n,r]=(0,_.useState)(!1);return(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500 w-20 shrink-0`,children:e}),(0,K.jsx)(`code`,{className:`flex-1 min-w-0 truncate bg-white border border-gray-200 rounded px-2 py-1 text-[10px] font-mono`,children:t}),(0,K.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),1500)},className:`text-[11px] text-gray-500 hover:text-gray-800 shrink-0`,children:n?`copied`:`copy`})]})}function WY(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(!1),y=async()=>{let e=await tg();e&&(t(e),r(e.card.name),a(e.card.description),s(e.profiles),l(e.vault))};(0,_.useEffect)(()=>{y()},[]);let b=e=>s(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return e?(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white px-4 py-3 space-y-3`,children:[(0,K.jsx)(`div`,{className:`text-[13px] font-medium text-gray-800`,children:`A2A (Agent-to-Agent)`}),(0,K.jsx)(`p`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:`This account is exposed as a standard A2A agent. Register its Agent Card URL with any A2A orchestrator.`}),(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(UY,{label:`Agent Card`,value:e.cardUrl}),(0,K.jsx)(UY,{label:`Endpoint`,value:e.endpoint})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-[11px] font-medium text-gray-600`,children:`Agent card`}),(0,K.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),placeholder:`Agent name (default: Loopat Agent)`,className:`w-full h-8 px-2 rounded border border-gray-300 text-[12px] focus:outline-none focus:border-gray-500`}),(0,K.jsx)(`textarea`,{value:i,onChange:e=>a(e.target.value),placeholder:`Description shown to orchestrators (what this agent does)`,rows:2,className:`w-full px-2 py-1 rounded border border-gray-300 text-[12px] resize-none focus:outline-none focus:border-gray-500`})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 space-y-2`,children:[(0,K.jsx)(`div`,{className:`text-[11px] font-medium text-gray-600`,children:`Loops created via A2A use`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Profiles`}),e.availableProfiles.length===0?(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 italic`,children:`no profiles in your knowledge repo`}):(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.availableProfiles.map(e=>(0,K.jsx)(`button`,{onClick:()=>b(e),className:`text-[11px] px-2 h-6 rounded border ${o.includes(e)?`bg-gray-900 text-white border-gray-900`:`bg-white text-gray-600 border-gray-300 hover:bg-gray-50`}`,children:e},e))})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] text-gray-500`,children:`Vault`}),(0,K.jsxs)(`select`,{value:c,onChange:e=>l(e.target.value),className:`h-7 px-2 rounded border border-gray-300 text-[12px] focus:outline-none focus:border-gray-500`,children:[(0,K.jsx)(`option`,{value:``,children:`default`}),e.availableVaults.filter(e=>e!=="default").map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,K.jsx)(`button`,{onClick:async()=>{d(!0);let e=await ng({card:{name:n,description:i},profiles:o,vault:c});d(!1),e&&(p(!0),setTimeout(()=>p(!1),1500),y())},disabled:u,className:`text-[12px] px-3 h-8 rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:u?`Saving…`:`Save`}),f&&(0,K.jsx)(`span`,{className:`text-[11px] text-green-700`,children:`saved`})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`text-[11px] font-medium text-gray-600`,children:[`Service key `,e.hasKey?(0,K.jsx)(`span`,{className:`text-green-700`,children:`· set`}):(0,K.jsx)(`span`,{className:`text-amber-700`,children:`· none`})]}),(0,K.jsx)(`button`,{onClick:async()=>{v(!0);let e=await rg();v(!1),e&&(h(e),y())},disabled:g,className:`text-[11px] px-2 h-6 rounded border border-gray-300 text-gray-700 hover:bg-gray-50 disabled:opacity-40`,children:g?`…`:e.hasKey?`regenerate`:`generate`})]}),(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[`The orchestrator presents this token (`,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[10px]`,children:`Authorization: Bearer …`}),`) to call your agent. Calls run as you, with your providers/keys.`]}),m&&(0,K.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 px-2 py-1.5 space-y-1`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-amber-800`,children:`Copy now — shown once:`}),(0,K.jsx)(UY,{label:`Key`,value:m})]})]})]}):null}function GY({checked:e,onCheckedChange:t,disabled:n,size:r=`default`}){let i=r===`sm`?`h-4 w-[28px]`:`h-5 w-[36px]`,a=r===`sm`?`h-3 w-3`:`h-3.5 w-3.5`,o=r===`sm`?`translate-x-[13px]`:`translate-x-[17px]`;return(0,K.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,disabled:n,onClick:()=>t(!e),className:`
|
|
115
115
|
${i} rounded-full shrink-0 transition-colors duration-150
|
|
116
116
|
${e?`bg-gray-900`:`bg-gray-200`}
|
|
117
117
|
${n?`opacity-40 cursor-not-allowed`:`cursor-pointer hover:`+(e?`bg-gray-800`:`bg-gray-300`)}
|
|
@@ -119,44 +119,44 @@ https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(
|
|
|
119
119
|
${a} block rounded-full bg-white shadow-sm
|
|
120
120
|
transform transition-transform duration-150
|
|
121
121
|
${e?o:`translate-x-[2px]`}
|
|
122
|
-
`})})}var GY=`w-full px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900 transition-colors disabled:bg-gray-50 disabled:text-gray-400`;function KY({currentUserId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),l=(0,_.useCallback)(async()=>{i(!0),o(``);try{n(await Ph())}finally{i(!1)}},[]);(0,_.useEffect)(()=>{l()},[l]);let u=t.filter(e=>e.role===`admin`).length;async function d(e){c(e),o(``);try{let t=await Fh(e);if(!t.ok){o(t.error??`activate failed`);return}await l()}finally{c(null)}}async function f(e){let t=e.role===`admin`?`member`:`admin`;c(e.id),o(``);try{let n=await Ih(e.id,t);if(!n.ok){o(n.error??`role change failed`);return}await l()}finally{c(null)}}async function p(e){if(confirm(`Delete user ${e.id}? Entry in users.json will be removed; personal/${e.id}/ on disk is preserved.`)){c(e.id),o(``);try{let t=await Lh(e.id);if(!t.ok){o(t.error??`delete failed`);return}await l()}finally{c(null)}}}return r?(0,K.jsx)(`div`,{className:`text-sm text-gray-400 py-8 text-center`,children:`Loading…`}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[a&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:a}),(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`text-xs text-gray-500 border-b border-gray-200`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left font-medium py-2 pr-2`,children:`User`}),(0,K.jsx)(`th`,{className:`text-left font-medium py-2 pr-2`,children:`Role`}),(0,K.jsx)(`th`,{className:`text-left font-medium py-2 pr-2`,children:`Status`}),(0,K.jsx)(`th`,{className:`text-left font-medium py-2 pr-2`,children:`Created`}),(0,K.jsx)(`th`,{className:`text-right font-medium py-2 pl-2`,children:`Actions`})]})}),(0,K.jsxs)(`tbody`,{children:[t.map(t=>{let n=t.id===e,r=t.role===`admin`&&u<=1,i=s===t.id;return(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,K.jsxs)(`td`,{className:`py-2 pr-2`,children:[(0,K.jsx)(`span`,{className:`font-medium text-gray-900`,children:t.id}),n&&(0,K.jsx)(`span`,{className:`ml-1.5 text-[10px] text-gray-400`,children:`(you)`})]}),(0,K.jsx)(`td`,{className:`py-2 pr-2`,children:(0,K.jsx)(qY,{role:t.role})}),(0,K.jsx)(`td`,{className:`py-2 pr-2`,children:(0,K.jsx)(JY,{status:t.status})}),(0,K.jsx)(`td`,{className:`py-2 pr-2 text-xs text-gray-500`,children:t.createdAt.slice(0,10)}),(0,K.jsxs)(`td`,{className:`py-2 pl-2 text-right space-x-1`,children:[t.status===`pending`&&(0,K.jsx)(kg,{size:`xs`,onClick:()=>d(t.id),disabled:i,children:`Activate`}),(0,K.jsx)(kg,{size:`xs`,variant:`outline`,onClick:()=>f(t),disabled:i||r,title:r?`cannot demote the last admin`:void 0,children:t.role===`admin`?`Demote`:`Promote`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(t),disabled:i||n||r,title:n?`cannot delete yourself`:r?`cannot delete the last admin`:void 0,className:`text-xs text-gray-500 hover:text-red-500 disabled:text-gray-300 disabled:cursor-not-allowed px-1.5`,children:`Delete`})]})]},t.id)}),t.length===0&&(0,K.jsx)(`tr`,{children:(0,K.jsx)(`td`,{colSpan:5,className:`text-center py-8 text-gray-400 text-sm`,children:`no users`})})]})]})})]})}function qY({role:e}){return(0,K.jsx)(`span`,{className:`inline-block text-[10px] px-1.5 py-0.5 rounded border ${e===`admin`?`bg-violet-50 text-violet-700 border-violet-200`:`bg-gray-50 text-gray-600 border-gray-200`}`,children:e})}function JY({status:e}){return(0,K.jsx)(`span`,{className:`inline-block text-[10px] px-1.5 py-0.5 rounded border ${e===`active`?`bg-emerald-50 text-emerald-700 border-emerald-200`:`bg-amber-50 text-amber-700 border-amber-200`}`,children:e})}function YY(){let[e,t]=(0,_.useState)(!0),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)({}),[g,v]=(0,_.useState)({}),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(``),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(``),[D,O]=(0,_.useState)({}),[k,A]=(0,_.useState)({}),[j,M]=(0,_.useState)([]);(0,_.useEffect)(()=>{Mh().then(e=>M(e.providerPresets)).catch(()=>{})},[]),(0,_.useEffect)(()=>{t(!0),a(null),Oh().then(e=>{let t={default:e.default??``,providers:{}};for(let[n,r]of Object.entries(e.providers))t.providers[n]={models:r.models?.map(e=>({id:e.id,enabled:e.enabled!==!1,...e.maxContextTokens&&e.maxContextTokens>0?{maxContextTokens:e.maxContextTokens}:{}}))??[],baseUrl:r.baseUrl??``,maxContextTokens:r.maxContextTokens||void 0,apiKey:``,keyDirty:!1,hasKey:r.hasKey??!1,enabled:r.enabled!==!1};l(t)}).catch(e=>{a(e?.message??`load failed`)}).finally(()=>t(!1))},[]);let N=c?Object.keys(c.providers):[],F=(e,t)=>{l(n=>!n||!n.providers[e]?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}})},I=e=>{l(t=>{if(!t)return t;let{[e]:n,...r}=t.providers,i=t.default===e||t.default.startsWith(`${e}/`);return{...t,providers:r,default:i?``:t.default}})},L=(e,t,n)=>{l(r=>{if(!r||!r.providers[e])return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,...n}:e);return{...r,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}})},R=(e,t)=>{l(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.map(e=>e.id===t?{...e,enabled:!e.enabled}:e);return{...n,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},z=(e,t)=>{l(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.filter(e=>e.id!==t),i=n.default===`${e}/${t}`;return{...n,default:i?``:n.default,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},B=e=>{let t=(m[e]??``).trim();t&&(l(n=>!n||!n.providers[e]||n.providers[e].models.some(e=>e.id===t)?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],models:[...n.providers[e].models,{id:t,enabled:!0}]}}}),h(t=>({...t,[e]:``})),v(t=>({...t,[e]:!1})))},V=(e,t)=>{let n=T.trim();if(!n||n===t){w(null);return}l(r=>{if(!r||!r.providers[e]||r.providers[e].models.some(e=>e.id===n))return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,id:n}:e),a=r.default===`${e}/${t}`?`${e}/${n}`:r.default;return{...r,default:a,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}}),w(null)},H=e=>{let t=x.trim();if(!t||t===e||t==="default"){b(null);return}l(n=>{if(!n||!n.providers[e]||n.providers[t])return n;let{[e]:r,...i}=n.providers,a=n.default;return n.default===e?a=t:n.default.startsWith(`${e}/`)&&(a=t+n.default.slice(e.length)),{...n,default:a,providers:{...i,[t]:r}}}),b(null)},U=()=>{let e=u.trim();if(e){if(c?.providers[e]){a(`provider name already exists`);return}l(t=>t&&{...t,providers:{...t.providers,[e]:{models:[],baseUrl:``,apiKey:``,keyDirty:!1,hasKey:!1,enabled:!1}}}),d(``),p(!1),a(null)}};return e?(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-12 text-center`,children:`loading…`}):c?(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[N.map(e=>{let t=c.providers[e],n=g[e]??!1,r=t.hasKey||t.apiKey.trim()!==``;return(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 bg-gray-50/50 border-b border-gray-100`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2.5 flex-1 min-w-0 select-none`,children:[(0,K.jsx)(WY,{checked:t.enabled,onCheckedChange:t=>r?F(e,{enabled:t}):void 0,disabled:!r,size:`sm`}),y===e?(0,K.jsx)(`input`,{autoFocus:!0,value:x,onChange:e=>S(e.target.value),onBlur:()=>H(e),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&H(e),t.key===`Escape`&&b(null)},className:X(GY,`text-[13px] font-semibold flex-1 min-w-0`)}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>{b(e),S(e)},className:`text-[13px] font-semibold truncate text-left hover:underline ${t.enabled?`text-gray-900`:`text-gray-400`}`,title:`click to rename`,children:e}),!t.enabled&&(0,K.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium shrink-0`,children:`disabled`})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>I(e),className:`text-[11px] text-gray-400 hover:text-red-500 transition-colors shrink-0`,children:`remove`})]}),(0,K.jsxs)(`div`,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(XY,{label:`Base URL`,children:(0,K.jsx)(`input`,{value:t.baseUrl,onChange:t=>F(e,{baseUrl:t.target.value}),placeholder:`https://api.example.com`,className:GY})}),(0,K.jsx)(XY,{label:`Max context tokens`,children:(0,K.jsx)(`input`,{type:`number`,value:t.maxContextTokens??``,onChange:t=>F(e,{maxContextTokens:t.target.value?Number(t.target.value):void 0}),placeholder:`auto`,className:GY})}),(0,K.jsx)(XY,{label:t.hasKey&&!t.keyDirty?`API Key (set — type to overwrite)`:`API Key`,className:`sm:col-span-2`,children:(0,K.jsx)(`input`,{type:`password`,value:t.apiKey,onChange:t=>F(e,{apiKey:t.target.value,keyDirty:!0}),placeholder:t.hasKey&&!t.keyDirty?`•••••• stored`:`API key`,className:GY})})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:[`Models (`,t.models.length,`)`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>v(t=>({...t,[e]:!n})),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Re,{size:11}),` add model`]})]}),n&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:m[e]??``,onChange:t=>h(n=>({...n,[e]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&B(e),t.key===`Escape`&&v(t=>({...t,[e]:!1}))},placeholder:`model ID (e.g. claude-sonnet-4-20250514)`,className:X(GY,`flex-1 text-[11px]`)}),(0,K.jsx)(kg,{size:`xs`,onClick:()=>B(e),children:`add`}),(0,K.jsx)(kg,{variant:`ghost`,size:`xs`,onClick:()=>v(t=>({...t,[e]:!1})),children:`cancel`})]}),t.models.length===0&&!n&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 italic py-2`,children:`no models — add one above`}),(0,K.jsx)(`div`,{className:`-mx-1`,children:t.models.map(n=>{let r=c.default===`${e}/${n.id}`,i=`${e}::${n.id}`,a=C===i,o=D[`${e}::${n.id}`],s=k[`${e}::${n.id}`];return(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 py-1.5 rounded group hover:bg-gray-50 transition-colors`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>l(t=>t&&{...t,default:r?``:`${e}/${n.id}`}),className:`shrink-0 text-[13px] leading-none transition-colors ${r?`text-amber-500`:`text-gray-200 hover:text-amber-400`}`,title:r?`current default model`:`set as default model`,children:`★`}),(0,K.jsx)(`label`,{className:`flex items-center shrink-0 cursor-pointer`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:n.enabled!==!1,onChange:()=>R(e,n.id),className:`h-3.5 w-3.5 rounded border-gray-300 text-gray-900 accent-gray-900`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1`,children:[a?(0,K.jsx)(`input`,{autoFocus:!0,value:T,onChange:e=>E(e.target.value),onBlur:()=>V(e,n.id),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&V(e,n.id),t.key===`Escape`&&w(null)},className:X(GY,`text-[11px] flex-1 min-w-0`)}):(0,K.jsx)(`code`,{className:`text-[12px] truncate cursor-pointer hover:bg-gray-100 px-0.5 rounded ${n.enabled===!1?`text-gray-300 line-through`:`text-gray-700`}`,onClick:()=>{w(i),E(n.id)},title:`click to edit model ID`,children:n.id}),n.enabled===!1&&(0,K.jsx)(`span`,{className:`text-[9px] text-gray-300 font-medium shrink-0`,children:`off`})]}),(0,K.jsx)(`input`,{type:`number`,value:n.maxContextTokens??``,onChange:t=>L(e,n.id,{maxContextTokens:t.target.value?Number(t.target.value):void 0}),placeholder:`auto`,className:`w-24 px-1.5 py-0.5 border border-gray-200 rounded text-[10px] outline-none focus:border-gray-400 shrink-0 ${n.maxContextTokens?``:`opacity-0 group-hover:opacity-100 transition-opacity`}`,title:`max context tokens (empty = auto)`}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{let r=t.apiKey.trim(),i=`${e}::${n.id}`;if(!r&&!t.hasKey){O(e=>({...e,[i]:`error`})),A(e=>({...e,[i]:`enter an API key first`})),setTimeout(()=>{O(e=>{let{[i]:t,...n}=e;return n}),A(e=>{let{[i]:t,...n}=e;return n})},3e3);return}O(e=>({...e,[i]:`testing`})),A(e=>({...e,[i]:``}));try{let a=r?await ph(t.baseUrl,r,n.id):await ph(t.baseUrl,``,n.id,e,`workspace`);O(e=>({...e,[i]:a.ok?`ok`:`error`})),a.ok||A(e=>({...e,[i]:a.error??`unknown error`}))}catch(e){O(e=>({...e,[i]:`error`})),A(t=>({...t,[i]:e?.message??`connection failed`}))}setTimeout(()=>{O(e=>{let{[i]:t,...n}=e;return n}),A(e=>{let{[i]:t,...n}=e;return n})},4e3)},disabled:o===`testing`||!t.hasKey&&!t.apiKey.trim(),className:`shrink-0 text-[9px] px-1 py-0 rounded transition-colors ${!t.hasKey&&!t.apiKey.trim()?`opacity-0 group-hover:opacity-100 text-gray-300`:o===`ok`?`bg-emerald-100 text-emerald-700`:o===`error`?`bg-red-100 text-red-700`:o===`testing`?`bg-gray-100 text-gray-400 animate-pulse`:`text-gray-400 hover:text-gray-700 opacity-0 group-hover:opacity-100`}`,title:s||(t.apiKey.trim()||t.hasKey?`test connection`:`enter an API key first`),children:o===`ok`?`OK`:o===`error`?`FAIL`:o===`testing`?`...`:`test`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>z(e,n.id),className:`text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,title:`remove model`,children:(0,K.jsx)(tt,{size:11})})]},n.id)})})]})]})]},e)}),(0,K.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:j.filter(e=>!c.providers[e.name]).map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{l(t=>!t||t.providers[e.name]?t:{...t,providers:{...t.providers,[e.name]:{models:e.models.map(e=>({id:e,enabled:!0})),baseUrl:e.baseUrl,apiKey:``,keyDirty:!1,hasKey:!1,enabled:!1}}})},className:`px-2 py-0.5 rounded border border-gray-200 bg-white text-[10px] text-gray-500 hover:text-gray-900 hover:border-gray-400 transition-colors`,title:`Add ${e.name} preset`,children:[`+ `,e.name]},e.name))}),f?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&U(),e.key===`Escape`&&p(!1)},placeholder:`provider name`,className:X(GY,`flex-1`)}),(0,K.jsx)(`button`,{onClick:U,className:`px-2.5 h-7 rounded bg-gray-900 text-white text-xs hover:bg-gray-700`,children:`add`}),(0,K.jsx)(`button`,{onClick:()=>{p(!1),d(``)},className:`text-xs text-gray-400 hover:text-gray-700`,children:`cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>p(!0),className:`self-start text-xs text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:12}),` add custom provider`]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-3 border-t border-gray-100`,children:[i&&(0,K.jsx)(`span`,{className:`text-xs text-red-600`,children:i}),o&&!i&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-700 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:12}),` saved`]}),(0,K.jsx)(kg,{size:`sm`,onClick:async()=>{if(c){r(!0),a(null);try{let e={};for(let[t,n]of Object.entries(c.providers))e[t]={models:n.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),...e.enabled?{}:{enabled:!1},...e.maxContextTokens&&e.maxContextTokens>0?{maxContextTokens:e.maxContextTokens}:{}})),baseUrl:n.baseUrl,enabled:n.enabled,...n.maxContextTokens&&n.maxContextTokens>0?{maxContextTokens:n.maxContextTokens}:{}},n.keyDirty&&n.apiKey.trim()&&(e[t].apiKey=n.apiKey.trim());if(!await kh({providers:e,default:c.default})){a(`save failed`);return}s(!0),setTimeout(()=>s(!1),2500),l(e=>{if(!e)return e;let t={...e,providers:{...e.providers}};for(let e of Object.keys(t.providers)){let n=t.providers[e].keyDirty;t.providers[e]={...t.providers[e],keyDirty:!1,apiKey:``,hasKey:n||t.providers[e].hasKey}}return t})}catch(e){a(e?.message??`save failed`)}finally{r(!1)}}},disabled:n,children:n?`saving…`:`save providers`})]})]}):null}function XY({label:e,children:t,className:n}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1 ${n??``}`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e}),t]})}function ZY(){let[e,t]=(0,_.useState)(!0),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(7788),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(`10000-20000`),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(``),[k,A]=(0,_.useState)(!1),[j,M]=(0,_.useState)(``),[N,F]=(0,_.useState)(!1);(0,_.useEffect)(()=>{Rh().then(e=>{t(e.serveEnabled),r(e.domain),a(e.ip),s(e.baseUrl),l(e.withPort??!1),d(e.https??!1),p(e.displayPort??7788),h(e.serveDynamicEnabled),v(e.serveDynamicDomain),b(e.serveDynamicPortRange),S(e.serveDynamicUdpEnabled),w(e.serveDynamicStaticEnabled),E(e.serveEphemeralEnabled??!1),O(e.serveEphemeralDomain??``)}).catch(e=>{M(e?.message??`load failed`)})},[]);async function I(){A(!0),M(``);try{if(!await Bh({serveEnabled:e,domain:n.trim(),withPort:c,https:u,displayPort:f,serveDynamicEnabled:m,serveDynamicDomain:g.trim(),serveDynamicPortRange:y.trim(),serveDynamicUdpEnabled:x,serveDynamicStaticEnabled:C,serveEphemeralEnabled:T,serveEphemeralDomain:D.trim()})){M(`save failed`);return}F(!0),setTimeout(()=>F(!1),2500);let i=await Rh();t(i.serveEnabled),r(i.domain),a(i.ip),s(i.baseUrl),l(i.withPort),d(i.https),p(i.displayPort),h(i.serveDynamicEnabled),v(i.serveDynamicDomain),b(i.serveDynamicPortRange),S(i.serveDynamicUdpEnabled),w(i.serveDynamicStaticEnabled),E(i.serveEphemeralEnabled??!1),O(i.serveEphemeralDomain??``)}catch(e){M(e?.message??`save failed`)}finally{A(!1)}}return(0,K.jsxs)(`div`,{className:`flex flex-col gap-6 min-h-full`,children:[(0,K.jsxs)(`section`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-gray-800`,children:`Standard Serve`}),(0,K.jsx)(WY,{checked:e,onCheckedChange:t,size:`sm`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-gray-400 mb-3`,children:[`Subdomain-based sharing via `,(0,K.jsx)(`code`,{className:`bg-gray-50 px-1 rounded`,children:`alias.domain`}),` URLs.`]}),e&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3 pl-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Domain Suffix`}),(0,K.jsx)(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`nip.io`,className:GY}),(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-400 mt-0.5`,children:[`URL: `,(0,K.jsxs)(`code`,{className:`bg-gray-50 px-1 rounded`,children:[`<alias>`,o]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(WY,{checked:u,onCheckedChange:d,size:`sm`}),` HTTPS`]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(WY,{checked:c,onCheckedChange:l,size:`sm`}),` Show port in URL`]})]}),c&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Display Port`}),(0,K.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(parseInt(e.target.value,10)||7788),placeholder:`7788`,className:GY})]})]})]}),(0,K.jsxs)(`section`,{className:`border-t border-gray-200 pt-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-gray-800`,children:`Dynamic Port`}),(0,K.jsx)(WY,{checked:m,onCheckedChange:h,size:`sm`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-gray-400 mb-3`,children:[`Direct TCP/UDP port forwarding — no domain needed. Access via `,(0,K.jsx)(`code`,{className:`bg-gray-50 px-1 rounded`,children:`host:port`}),`.`]}),m&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3 pl-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Domain / IP (optional)`}),(0,K.jsx)(`input`,{type:`text`,value:g,onChange:e=>v(e.target.value),placeholder:i||`auto-detect IP`,className:GY}),(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-400 mt-0.5`,children:[`Leave empty to auto-detect. Access URL: `,(0,K.jsxs)(`code`,{className:`bg-gray-50 px-1 rounded`,children:[g||i||`<ip>`,`:<external-port>`]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Port Range`}),(0,K.jsx)(`input`,{type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`10000-20000`,className:GY})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(WY,{checked:x,onCheckedChange:S,size:`sm`}),` Enable UDP`]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(WY,{checked:C,onCheckedChange:w,size:`sm`}),` Enable static file serving`]})]})]})]}),(0,K.jsxs)(`section`,{className:`border-t border-gray-200 pt-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-gray-800`,children:`Ephemeral Port`}),(0,K.jsx)(WY,{checked:T,onCheckedChange:E,size:`sm`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-gray-400 mb-3`,children:[`Per-loop random host port via `,(0,K.jsx)(`code`,{className:`bg-gray-50 px-1 rounded`,children:`podman -p :inner`}),`. The kernel picks an unused port on each loop container start — the URL changes after every restart. Recommended when you don't need a stable URL and want zero port-conflict risk.`]}),T&&(0,K.jsx)(`div`,{className:`flex flex-col gap-3 pl-1`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Domain / IP (optional)`}),(0,K.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(e.target.value),placeholder:i||`auto-detect IP`,className:GY}),(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-400 mt-0.5`,children:[`Leave empty to auto-detect. Access URL: `,(0,K.jsxs)(`code`,{className:`bg-gray-50 px-1 rounded`,children:[D||i||`<ip>`,`:<random>`]})]})]})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-3 pt-2 border-t border-gray-200`,children:[j&&(0,K.jsx)(`span`,{className:`text-xs text-red-500`,children:j}),N&&!j&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-700 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:12}),` saved`]}),(0,K.jsx)(kg,{onClick:I,disabled:k,children:k?`Saving…`:`Save`})]})]})}function QY(e){let t=e.trim();if(!t.includes(`claude`)||!t.includes(`mcp`)||!t.includes(`add`))return null;let n=[],r=0;for(;r<t.length;){if(t[r]===` `||t[r]===` `){r++;continue}if(t[r]===`"`||t[r]===`'`){let e=t[r],i=t.indexOf(e,r+1);if(i===-1){n.push(t.slice(r+1));break}n.push(t.slice(r+1,i)),r=i+1}else{let e=r;for(;e<t.length&&t[e]!==` `&&t[e]!==` `;)e++;n.push(t.slice(r,e)),r=e}}let i=n.findIndex(e=>e===`add`);if(i===-1||i+2>=n.length)return null;let a=n[Math.min(i+1,n.length-1)],o=n[Math.min(i+2,n.length-1)],s=``,c=``,l=`stdio`,u=[],d=[];o.startsWith(`http://`)||o.startsWith(`https://`)?(s=o,l=`http`):o.startsWith(`-`)||(c=o);for(let e=i+3;e<n.length;e++){let t=n[e];if(t===`-t`||t===`--type`){let t=n[++e];(t===`http`||t===`sse`||t===`stdio`)&&(l=t)}else t===`-H`||t===`--header`?u.push(n[++e]??``):t===`-e`||t===`--env`?d.push(n[++e]??``):t===`-a`||t===`--args`||t.startsWith(`-`)||(c||=t)}return{name:a,type:l,url:s,command:c,args:``,env:d.join(`
|
|
122
|
+
`})})}var KY=`w-full px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900 transition-colors disabled:bg-gray-50 disabled:text-gray-400`;function qY({currentUserId:e}){let[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),l=(0,_.useCallback)(async()=>{i(!0),o(``);try{n(await Ph())}finally{i(!1)}},[]);(0,_.useEffect)(()=>{l()},[l]);let u=t.filter(e=>e.role===`admin`).length;async function d(e){c(e),o(``);try{let t=await Fh(e);if(!t.ok){o(t.error??`activate failed`);return}await l()}finally{c(null)}}async function f(e){let t=e.role===`admin`?`member`:`admin`;c(e.id),o(``);try{let n=await Ih(e.id,t);if(!n.ok){o(n.error??`role change failed`);return}await l()}finally{c(null)}}async function p(e){if(confirm(`Delete user ${e.id}? Entry in users.json will be removed; personal/${e.id}/ on disk is preserved.`)){c(e.id),o(``);try{let t=await Lh(e.id);if(!t.ok){o(t.error??`delete failed`);return}await l()}finally{c(null)}}}return r?(0,K.jsx)(`div`,{className:`text-sm text-gray-400 py-8 text-center`,children:`Loading…`}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[a&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:a}),(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{className:`text-xs text-gray-500 border-b border-gray-200`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left font-medium py-2 pr-2`,children:`User`}),(0,K.jsx)(`th`,{className:`text-left font-medium py-2 pr-2`,children:`Role`}),(0,K.jsx)(`th`,{className:`text-left font-medium py-2 pr-2`,children:`Status`}),(0,K.jsx)(`th`,{className:`text-left font-medium py-2 pr-2`,children:`Created`}),(0,K.jsx)(`th`,{className:`text-right font-medium py-2 pl-2`,children:`Actions`})]})}),(0,K.jsxs)(`tbody`,{children:[t.map(t=>{let n=t.id===e,r=t.role===`admin`&&u<=1,i=s===t.id;return(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,K.jsxs)(`td`,{className:`py-2 pr-2`,children:[(0,K.jsx)(`span`,{className:`font-medium text-gray-900`,children:t.id}),n&&(0,K.jsx)(`span`,{className:`ml-1.5 text-[10px] text-gray-400`,children:`(you)`})]}),(0,K.jsx)(`td`,{className:`py-2 pr-2`,children:(0,K.jsx)(JY,{role:t.role})}),(0,K.jsx)(`td`,{className:`py-2 pr-2`,children:(0,K.jsx)(YY,{status:t.status})}),(0,K.jsx)(`td`,{className:`py-2 pr-2 text-xs text-gray-500`,children:t.createdAt.slice(0,10)}),(0,K.jsxs)(`td`,{className:`py-2 pl-2 text-right space-x-1`,children:[t.status===`pending`&&(0,K.jsx)(kg,{size:`xs`,onClick:()=>d(t.id),disabled:i,children:`Activate`}),(0,K.jsx)(kg,{size:`xs`,variant:`outline`,onClick:()=>f(t),disabled:i||r,title:r?`cannot demote the last admin`:void 0,children:t.role===`admin`?`Demote`:`Promote`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(t),disabled:i||n||r,title:n?`cannot delete yourself`:r?`cannot delete the last admin`:void 0,className:`text-xs text-gray-500 hover:text-red-500 disabled:text-gray-300 disabled:cursor-not-allowed px-1.5`,children:`Delete`})]})]},t.id)}),t.length===0&&(0,K.jsx)(`tr`,{children:(0,K.jsx)(`td`,{colSpan:5,className:`text-center py-8 text-gray-400 text-sm`,children:`no users`})})]})]})})]})}function JY({role:e}){return(0,K.jsx)(`span`,{className:`inline-block text-[10px] px-1.5 py-0.5 rounded border ${e===`admin`?`bg-violet-50 text-violet-700 border-violet-200`:`bg-gray-50 text-gray-600 border-gray-200`}`,children:e})}function YY({status:e}){return(0,K.jsx)(`span`,{className:`inline-block text-[10px] px-1.5 py-0.5 rounded border ${e===`active`?`bg-emerald-50 text-emerald-700 border-emerald-200`:`bg-amber-50 text-amber-700 border-amber-200`}`,children:e})}function XY(){let[e,t]=(0,_.useState)(!0),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)({}),[g,v]=(0,_.useState)({}),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(``),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(``),[D,O]=(0,_.useState)({}),[k,A]=(0,_.useState)({}),[j,M]=(0,_.useState)([]);(0,_.useEffect)(()=>{Mh().then(e=>M(e.providerPresets)).catch(()=>{})},[]),(0,_.useEffect)(()=>{t(!0),a(null),Oh().then(e=>{let t={default:e.default??``,providers:{}};for(let[n,r]of Object.entries(e.providers))t.providers[n]={models:r.models?.map(e=>({id:e.id,enabled:e.enabled!==!1,...e.maxContextTokens&&e.maxContextTokens>0?{maxContextTokens:e.maxContextTokens}:{}}))??[],baseUrl:r.baseUrl??``,maxContextTokens:r.maxContextTokens||void 0,apiKey:``,keyDirty:!1,hasKey:r.hasKey??!1,enabled:r.enabled!==!1};l(t)}).catch(e=>{a(e?.message??`load failed`)}).finally(()=>t(!1))},[]);let N=c?Object.keys(c.providers):[],F=(e,t)=>{l(n=>!n||!n.providers[e]?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}})},I=e=>{l(t=>{if(!t)return t;let{[e]:n,...r}=t.providers,i=t.default===e||t.default.startsWith(`${e}/`);return{...t,providers:r,default:i?``:t.default}})},L=(e,t,n)=>{l(r=>{if(!r||!r.providers[e])return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,...n}:e);return{...r,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}})},R=(e,t)=>{l(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.map(e=>e.id===t?{...e,enabled:!e.enabled}:e);return{...n,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},z=(e,t)=>{l(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.filter(e=>e.id!==t),i=n.default===`${e}/${t}`;return{...n,default:i?``:n.default,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},B=e=>{let t=(m[e]??``).trim();t&&(l(n=>!n||!n.providers[e]||n.providers[e].models.some(e=>e.id===t)?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],models:[...n.providers[e].models,{id:t,enabled:!0}]}}}),h(t=>({...t,[e]:``})),v(t=>({...t,[e]:!1})))},V=(e,t)=>{let n=T.trim();if(!n||n===t){w(null);return}l(r=>{if(!r||!r.providers[e]||r.providers[e].models.some(e=>e.id===n))return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,id:n}:e),a=r.default===`${e}/${t}`?`${e}/${n}`:r.default;return{...r,default:a,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}}),w(null)},H=e=>{let t=x.trim();if(!t||t===e||t==="default"){b(null);return}l(n=>{if(!n||!n.providers[e]||n.providers[t])return n;let{[e]:r,...i}=n.providers,a=n.default;return n.default===e?a=t:n.default.startsWith(`${e}/`)&&(a=t+n.default.slice(e.length)),{...n,default:a,providers:{...i,[t]:r}}}),b(null)},U=()=>{let e=u.trim();if(e){if(c?.providers[e]){a(`provider name already exists`);return}l(t=>t&&{...t,providers:{...t.providers,[e]:{models:[],baseUrl:``,apiKey:``,keyDirty:!1,hasKey:!1,enabled:!1}}}),d(``),p(!1),a(null)}};return e?(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-12 text-center`,children:`loading…`}):c?(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[N.map(e=>{let t=c.providers[e],n=g[e]??!1,r=t.hasKey||t.apiKey.trim()!==``;return(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 bg-gray-50/50 border-b border-gray-100`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2.5 flex-1 min-w-0 select-none`,children:[(0,K.jsx)(GY,{checked:t.enabled,onCheckedChange:t=>r?F(e,{enabled:t}):void 0,disabled:!r,size:`sm`}),y===e?(0,K.jsx)(`input`,{autoFocus:!0,value:x,onChange:e=>S(e.target.value),onBlur:()=>H(e),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&H(e),t.key===`Escape`&&b(null)},className:X(KY,`text-[13px] font-semibold flex-1 min-w-0`)}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>{b(e),S(e)},className:`text-[13px] font-semibold truncate text-left hover:underline ${t.enabled?`text-gray-900`:`text-gray-400`}`,title:`click to rename`,children:e}),!t.enabled&&(0,K.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium shrink-0`,children:`disabled`})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>I(e),className:`text-[11px] text-gray-400 hover:text-red-500 transition-colors shrink-0`,children:`remove`})]}),(0,K.jsxs)(`div`,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(ZY,{label:`Base URL`,children:(0,K.jsx)(`input`,{value:t.baseUrl,onChange:t=>F(e,{baseUrl:t.target.value}),placeholder:`https://api.example.com`,className:KY})}),(0,K.jsx)(ZY,{label:`Max context tokens`,children:(0,K.jsx)(`input`,{type:`number`,value:t.maxContextTokens??``,onChange:t=>F(e,{maxContextTokens:t.target.value?Number(t.target.value):void 0}),placeholder:`auto`,className:KY})}),(0,K.jsx)(ZY,{label:t.hasKey&&!t.keyDirty?`API Key (set — type to overwrite)`:`API Key`,className:`sm:col-span-2`,children:(0,K.jsx)(`input`,{type:`password`,value:t.apiKey,onChange:t=>F(e,{apiKey:t.target.value,keyDirty:!0}),placeholder:t.hasKey&&!t.keyDirty?`•••••• stored`:`API key`,className:KY})})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:[`Models (`,t.models.length,`)`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>v(t=>({...t,[e]:!n})),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Re,{size:11}),` add model`]})]}),n&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:m[e]??``,onChange:t=>h(n=>({...n,[e]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&B(e),t.key===`Escape`&&v(t=>({...t,[e]:!1}))},placeholder:`model ID (e.g. claude-sonnet-4-20250514)`,className:X(KY,`flex-1 text-[11px]`)}),(0,K.jsx)(kg,{size:`xs`,onClick:()=>B(e),children:`add`}),(0,K.jsx)(kg,{variant:`ghost`,size:`xs`,onClick:()=>v(t=>({...t,[e]:!1})),children:`cancel`})]}),t.models.length===0&&!n&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 italic py-2`,children:`no models — add one above`}),(0,K.jsx)(`div`,{className:`-mx-1`,children:t.models.map(n=>{let r=c.default===`${e}/${n.id}`,i=`${e}::${n.id}`,a=C===i,o=D[`${e}::${n.id}`],s=k[`${e}::${n.id}`];return(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 py-1.5 rounded group hover:bg-gray-50 transition-colors`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>l(t=>t&&{...t,default:r?``:`${e}/${n.id}`}),className:`shrink-0 text-[13px] leading-none transition-colors ${r?`text-amber-500`:`text-gray-200 hover:text-amber-400`}`,title:r?`current default model`:`set as default model`,children:`★`}),(0,K.jsx)(`label`,{className:`flex items-center shrink-0 cursor-pointer`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:n.enabled!==!1,onChange:()=>R(e,n.id),className:`h-3.5 w-3.5 rounded border-gray-300 text-gray-900 accent-gray-900`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1`,children:[a?(0,K.jsx)(`input`,{autoFocus:!0,value:T,onChange:e=>E(e.target.value),onBlur:()=>V(e,n.id),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&V(e,n.id),t.key===`Escape`&&w(null)},className:X(KY,`text-[11px] flex-1 min-w-0`)}):(0,K.jsx)(`code`,{className:`text-[12px] truncate cursor-pointer hover:bg-gray-100 px-0.5 rounded ${n.enabled===!1?`text-gray-300 line-through`:`text-gray-700`}`,onClick:()=>{w(i),E(n.id)},title:`click to edit model ID`,children:n.id}),n.enabled===!1&&(0,K.jsx)(`span`,{className:`text-[9px] text-gray-300 font-medium shrink-0`,children:`off`})]}),(0,K.jsx)(`input`,{type:`number`,value:n.maxContextTokens??``,onChange:t=>L(e,n.id,{maxContextTokens:t.target.value?Number(t.target.value):void 0}),placeholder:`auto`,className:`w-24 px-1.5 py-0.5 border border-gray-200 rounded text-[10px] outline-none focus:border-gray-400 shrink-0 ${n.maxContextTokens?``:`opacity-0 group-hover:opacity-100 transition-opacity`}`,title:`max context tokens (empty = auto)`}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{let r=t.apiKey.trim(),i=`${e}::${n.id}`;if(!r&&!t.hasKey){O(e=>({...e,[i]:`error`})),A(e=>({...e,[i]:`enter an API key first`})),setTimeout(()=>{O(e=>{let{[i]:t,...n}=e;return n}),A(e=>{let{[i]:t,...n}=e;return n})},3e3);return}O(e=>({...e,[i]:`testing`})),A(e=>({...e,[i]:``}));try{let a=r?await ph(t.baseUrl,r,n.id):await ph(t.baseUrl,``,n.id,e,`workspace`);O(e=>({...e,[i]:a.ok?`ok`:`error`})),a.ok||A(e=>({...e,[i]:a.error??`unknown error`}))}catch(e){O(e=>({...e,[i]:`error`})),A(t=>({...t,[i]:e?.message??`connection failed`}))}setTimeout(()=>{O(e=>{let{[i]:t,...n}=e;return n}),A(e=>{let{[i]:t,...n}=e;return n})},4e3)},disabled:o===`testing`||!t.hasKey&&!t.apiKey.trim(),className:`shrink-0 text-[9px] px-1 py-0 rounded transition-colors ${!t.hasKey&&!t.apiKey.trim()?`opacity-0 group-hover:opacity-100 text-gray-300`:o===`ok`?`bg-emerald-100 text-emerald-700`:o===`error`?`bg-red-100 text-red-700`:o===`testing`?`bg-gray-100 text-gray-400 animate-pulse`:`text-gray-400 hover:text-gray-700 opacity-0 group-hover:opacity-100`}`,title:s||(t.apiKey.trim()||t.hasKey?`test connection`:`enter an API key first`),children:o===`ok`?`OK`:o===`error`?`FAIL`:o===`testing`?`...`:`test`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>z(e,n.id),className:`text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,title:`remove model`,children:(0,K.jsx)(tt,{size:11})})]},n.id)})})]})]})]},e)}),(0,K.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:j.filter(e=>!c.providers[e.name]).map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{l(t=>!t||t.providers[e.name]?t:{...t,providers:{...t.providers,[e.name]:{models:e.models.map(e=>({id:e,enabled:!0})),baseUrl:e.baseUrl,apiKey:``,keyDirty:!1,hasKey:!1,enabled:!1}}})},className:`px-2 py-0.5 rounded border border-gray-200 bg-white text-[10px] text-gray-500 hover:text-gray-900 hover:border-gray-400 transition-colors`,title:`Add ${e.name} preset`,children:[`+ `,e.name]},e.name))}),f?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&U(),e.key===`Escape`&&p(!1)},placeholder:`provider name`,className:X(KY,`flex-1`)}),(0,K.jsx)(`button`,{onClick:U,className:`px-2.5 h-7 rounded bg-gray-900 text-white text-xs hover:bg-gray-700`,children:`add`}),(0,K.jsx)(`button`,{onClick:()=>{p(!1),d(``)},className:`text-xs text-gray-400 hover:text-gray-700`,children:`cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>p(!0),className:`self-start text-xs text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:12}),` add custom provider`]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-3 border-t border-gray-100`,children:[i&&(0,K.jsx)(`span`,{className:`text-xs text-red-600`,children:i}),o&&!i&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-700 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:12}),` saved`]}),(0,K.jsx)(kg,{size:`sm`,onClick:async()=>{if(c){r(!0),a(null);try{let e={};for(let[t,n]of Object.entries(c.providers))e[t]={models:n.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),...e.enabled?{}:{enabled:!1},...e.maxContextTokens&&e.maxContextTokens>0?{maxContextTokens:e.maxContextTokens}:{}})),baseUrl:n.baseUrl,enabled:n.enabled,...n.maxContextTokens&&n.maxContextTokens>0?{maxContextTokens:n.maxContextTokens}:{}},n.keyDirty&&n.apiKey.trim()&&(e[t].apiKey=n.apiKey.trim());if(!await kh({providers:e,default:c.default})){a(`save failed`);return}s(!0),setTimeout(()=>s(!1),2500),l(e=>{if(!e)return e;let t={...e,providers:{...e.providers}};for(let e of Object.keys(t.providers)){let n=t.providers[e].keyDirty;t.providers[e]={...t.providers[e],keyDirty:!1,apiKey:``,hasKey:n||t.providers[e].hasKey}}return t})}catch(e){a(e?.message??`save failed`)}finally{r(!1)}}},disabled:n,children:n?`saving…`:`save providers`})]})]}):null}function ZY({label:e,children:t,className:n}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1 ${n??``}`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e}),t]})}function QY(){let[e,t]=(0,_.useState)(!0),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(7788),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(`10000-20000`),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(``),[k,A]=(0,_.useState)(!1),[j,M]=(0,_.useState)(``),[N,F]=(0,_.useState)(!1);(0,_.useEffect)(()=>{Rh().then(e=>{t(e.serveEnabled),r(e.domain),a(e.ip),s(e.baseUrl),l(e.withPort??!1),d(e.https??!1),p(e.displayPort??7788),h(e.serveDynamicEnabled),v(e.serveDynamicDomain),b(e.serveDynamicPortRange),S(e.serveDynamicUdpEnabled),w(e.serveDynamicStaticEnabled),E(e.serveEphemeralEnabled??!1),O(e.serveEphemeralDomain??``)}).catch(e=>{M(e?.message??`load failed`)})},[]);async function I(){A(!0),M(``);try{if(!await Bh({serveEnabled:e,domain:n.trim(),withPort:c,https:u,displayPort:f,serveDynamicEnabled:m,serveDynamicDomain:g.trim(),serveDynamicPortRange:y.trim(),serveDynamicUdpEnabled:x,serveDynamicStaticEnabled:C,serveEphemeralEnabled:T,serveEphemeralDomain:D.trim()})){M(`save failed`);return}F(!0),setTimeout(()=>F(!1),2500);let i=await Rh();t(i.serveEnabled),r(i.domain),a(i.ip),s(i.baseUrl),l(i.withPort),d(i.https),p(i.displayPort),h(i.serveDynamicEnabled),v(i.serveDynamicDomain),b(i.serveDynamicPortRange),S(i.serveDynamicUdpEnabled),w(i.serveDynamicStaticEnabled),E(i.serveEphemeralEnabled??!1),O(i.serveEphemeralDomain??``)}catch(e){M(e?.message??`save failed`)}finally{A(!1)}}return(0,K.jsxs)(`div`,{className:`flex flex-col gap-6 min-h-full`,children:[(0,K.jsxs)(`section`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-gray-800`,children:`Standard Serve`}),(0,K.jsx)(GY,{checked:e,onCheckedChange:t,size:`sm`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-gray-400 mb-3`,children:[`Subdomain-based sharing via `,(0,K.jsx)(`code`,{className:`bg-gray-50 px-1 rounded`,children:`alias.domain`}),` URLs.`]}),e&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3 pl-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Domain Suffix`}),(0,K.jsx)(`input`,{type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`nip.io`,className:KY}),(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-400 mt-0.5`,children:[`URL: `,(0,K.jsxs)(`code`,{className:`bg-gray-50 px-1 rounded`,children:[`<alias>`,o]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(GY,{checked:u,onCheckedChange:d,size:`sm`}),` HTTPS`]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(GY,{checked:c,onCheckedChange:l,size:`sm`}),` Show port in URL`]})]}),c&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Display Port`}),(0,K.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(parseInt(e.target.value,10)||7788),placeholder:`7788`,className:KY})]})]})]}),(0,K.jsxs)(`section`,{className:`border-t border-gray-200 pt-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-gray-800`,children:`Dynamic Port`}),(0,K.jsx)(GY,{checked:m,onCheckedChange:h,size:`sm`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-gray-400 mb-3`,children:[`Direct TCP/UDP port forwarding — no domain needed. Access via `,(0,K.jsx)(`code`,{className:`bg-gray-50 px-1 rounded`,children:`host:port`}),`.`]}),m&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-3 pl-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Domain / IP (optional)`}),(0,K.jsx)(`input`,{type:`text`,value:g,onChange:e=>v(e.target.value),placeholder:i||`auto-detect IP`,className:KY}),(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-400 mt-0.5`,children:[`Leave empty to auto-detect. Access URL: `,(0,K.jsxs)(`code`,{className:`bg-gray-50 px-1 rounded`,children:[g||i||`<ip>`,`:<external-port>`]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Port Range`}),(0,K.jsx)(`input`,{type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`10000-20000`,className:KY})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(GY,{checked:x,onCheckedChange:S,size:`sm`}),` Enable UDP`]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-gray-700`,children:[(0,K.jsx)(GY,{checked:C,onCheckedChange:w,size:`sm`}),` Enable static file serving`]})]})]})]}),(0,K.jsxs)(`section`,{className:`border-t border-gray-200 pt-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold text-gray-800`,children:`Ephemeral Port`}),(0,K.jsx)(GY,{checked:T,onCheckedChange:E,size:`sm`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-gray-400 mb-3`,children:[`Per-loop random host port via `,(0,K.jsx)(`code`,{className:`bg-gray-50 px-1 rounded`,children:`podman -p :inner`}),`. The kernel picks an unused port on each loop container start — the URL changes after every restart. Recommended when you don't need a stable URL and want zero port-conflict risk.`]}),T&&(0,K.jsx)(`div`,{className:`flex flex-col gap-3 pl-1`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 mb-1`,children:`Domain / IP (optional)`}),(0,K.jsx)(`input`,{type:`text`,value:D,onChange:e=>O(e.target.value),placeholder:i||`auto-detect IP`,className:KY}),(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-400 mt-0.5`,children:[`Leave empty to auto-detect. Access URL: `,(0,K.jsxs)(`code`,{className:`bg-gray-50 px-1 rounded`,children:[D||i||`<ip>`,`:<random>`]})]})]})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-3 pt-2 border-t border-gray-200`,children:[j&&(0,K.jsx)(`span`,{className:`text-xs text-red-500`,children:j}),N&&!j&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-700 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:12}),` saved`]}),(0,K.jsx)(kg,{onClick:I,disabled:k,children:k?`Saving…`:`Save`})]})]})}function $Y(e){let t=e.trim();if(!t.includes(`claude`)||!t.includes(`mcp`)||!t.includes(`add`))return null;let n=[],r=0;for(;r<t.length;){if(t[r]===` `||t[r]===` `){r++;continue}if(t[r]===`"`||t[r]===`'`){let e=t[r],i=t.indexOf(e,r+1);if(i===-1){n.push(t.slice(r+1));break}n.push(t.slice(r+1,i)),r=i+1}else{let e=r;for(;e<t.length&&t[e]!==` `&&t[e]!==` `;)e++;n.push(t.slice(r,e)),r=e}}let i=n.findIndex(e=>e===`add`);if(i===-1||i+2>=n.length)return null;let a=n[Math.min(i+1,n.length-1)],o=n[Math.min(i+2,n.length-1)],s=``,c=``,l=`stdio`,u=[],d=[];o.startsWith(`http://`)||o.startsWith(`https://`)?(s=o,l=`http`):o.startsWith(`-`)||(c=o);for(let e=i+3;e<n.length;e++){let t=n[e];if(t===`-t`||t===`--type`){let t=n[++e];(t===`http`||t===`sse`||t===`stdio`)&&(l=t)}else t===`-H`||t===`--header`?u.push(n[++e]??``):t===`-e`||t===`--env`?d.push(n[++e]??``):t===`-a`||t===`--args`||t.startsWith(`-`)||(c||=t)}return{name:a,type:l,url:s,command:c,args:``,env:d.join(`
|
|
123
123
|
`),headers:u.join(`
|
|
124
|
-
`)}}function
|
|
124
|
+
`)}}function eX(e){try{let t=JSON.parse(e.trim()),n;if(t.mcpServers)n=t.mcpServers;else if(t.mcp)n=t.mcp;else if(typeof Object.values(t)[0]==`object`&&Object.values(t)[0]!==null&&!Array.isArray(Object.values(t)[0]))n=t;else return null;let[r,i]=Object.entries(n)[0]??[];return!r||!i||typeof i!=`object`?null:{name:r,type:i?.type===`http`||i?.type===`sse`||i?.type===`remote`?`http`:i?.type===`sse`?`sse`:`stdio`,url:i?.url??``,command:i?.command??``,args:i?.args?Array.isArray(i.args)?i.args.join(` `):String(i.args):``,env:i?.env?Object.entries(i.env).map(([e,t])=>`${e}=${t}`).join(`
|
|
125
125
|
`):``,headers:i?.headers?Object.entries(i.headers).map(([e,t])=>`${e}: ${t}`).join(`
|
|
126
|
-
`):``}}catch{return null}}function
|
|
126
|
+
`):``}}catch{return null}}function tX(e){return eX(e)??$Y(e)}function nX(){return{name:``,type:`stdio`,url:``,command:``,args:``,env:``,headers:``}}function rX(e,t){return{name:e,type:t?.type===`http`||t?.type===`sse`||t?.type===`remote`?`http`:`stdio`,url:t?.url??``,command:t?.command??``,args:t?.args?Array.isArray(t.args)?t.args.join(` `):String(t.args):``,env:t?.env?Object.entries(t.env).map(([e,t])=>`${e}=${t}`).join(`
|
|
127
127
|
`):``,headers:t?.headers?Object.entries(t.headers).map(([e,t])=>`${e}: ${t}`).join(`
|
|
128
|
-
`):``}}function
|
|
128
|
+
`):``}}function iX(e){if(e.type===`http`||e.type===`sse`){let t={type:e.type,url:e.url};return e.headers.trim()&&(t.headers=Object.fromEntries(e.headers.split(`
|
|
129
129
|
`).filter(Boolean).map(e=>{let t=e.indexOf(`:`);return t>=0?[e.slice(0,t).trim(),e.slice(t+1).trim()]:[e.trim(),``]}))),t}let t={command:e.command};return e.args.trim()&&(t.args=e.args.split(/\s+/)),e.env.trim()&&(t.env=Object.fromEntries(e.env.split(`
|
|
130
|
-
`).filter(Boolean).map(e=>{let t=e.indexOf(`=`);return t>=0?[e.slice(0,t),e.slice(t+1)]:[e,``]}))),t}function
|
|
130
|
+
`).filter(Boolean).map(e=>{let t=e.indexOf(`=`);return t>=0?[e.slice(0,t),e.slice(t+1)]:[e,``]}))),t}function aX(e){return e?.mcpServers?new Map(Object.entries(e.mcpServers)):new Map}function oX({servers:e,onChange:t,readonly:n}){let r=()=>[...e.entries()].map(([e,t])=>rX(e,t)),[i,a]=(0,_.useState)(r),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(nX()),[u,d]=(0,_.useState)(null);(0,_.useEffect)(()=>{a(r()),d(null),s(!1)},[e]);let f=e=>{a(e);let n={};for(let t of e)t.name.trim()&&(n[t.name]=iX(t));t(n)},p=(e,t)=>{f(i.map((n,r)=>r===e?{...n,...t}:n))},m=e=>{f(i.filter((t,n)=>n!==e)),d(null)},h=()=>{c.name.trim()&&(f([...i,c]),l(nX()),s(!1))};return i.length===0&&!o?(0,K.jsxs)(`div`,{className:`py-3`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 text-center py-3`,children:[(0,K.jsx)(Ge,{size:18,className:`text-gray-300`}),(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:`No MCP servers`}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400/70`,children:`Add servers to extend Claude with external tools.`})]}),!n&&(0,K.jsxs)(`button`,{onClick:()=>s(!0),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(Re,{size:13}),`Add MCP server`]})]}):(0,K.jsxs)(`div`,{className:`space-y-1`,children:[i.map((e,t)=>{let r=u===t;return(0,K.jsx)(sX,{row:e,isEditing:r,readonly:n,onEdit:()=>d(r?null:t),onCommit:e=>{p(t,e),r||d(null)},onRemove:()=>m(t)},t)}),o&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-blue-50/20 p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:c.name,onChange:e=>l(t=>({...t,name:e.target.value})),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h(),e.key===`Escape`&&(s(!1),l(nX()))},placeholder:`server name`,className:`flex-1 min-w-0 border border-gray-300 rounded px-2.5 py-1.5 text-[12px] font-medium outline-none focus:border-gray-900 bg-white`}),(0,K.jsxs)(`select`,{value:c.type,onChange:e=>l(t=>({...t,type:e.target.value})),className:`w-20 shrink-0 border border-gray-300 rounded px-2 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white`,children:[(0,K.jsx)(`option`,{value:`stdio`,children:`stdio`}),(0,K.jsx)(`option`,{value:`http`,children:`http`}),(0,K.jsx)(`option`,{value:`sse`,children:`sse`})]})]}),c.type===`http`||c.type===`sse`?(0,K.jsx)(`input`,{value:c.url,onChange:e=>l(t=>({...t,url:e.target.value})),placeholder:`https://example.com/mcp`,className:`ip text-[12px] w-full font-mono`}):(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`input`,{value:c.command,onChange:e=>l(t=>({...t,command:e.target.value})),placeholder:`command (e.g. npx, uvx)`,className:`ip text-[12px] w-full font-mono`}),(0,K.jsx)(`input`,{value:c.args,onChange:e=>l(t=>({...t,args:e.target.value})),placeholder:`args (space-separated)`,className:`ip text-[12px] w-full font-mono`}),(0,K.jsx)(`textarea`,{value:c.env,onChange:e=>l(t=>({...t,env:e.target.value})),placeholder:`env vars (KEY=val, one per line)`,className:`ip text-[12px] w-full font-mono resize-none h-14`})]}),(c.type===`http`||c.type===`sse`)&&(0,K.jsx)(`textarea`,{value:c.headers,onChange:e=>l(t=>({...t,headers:e.target.value})),placeholder:`headers (Key: Value, one per line)`,className:`ip text-[12px] w-full font-mono resize-none h-14`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:h,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>{s(!1),l(nX())},className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}),!n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(cX,{onParse:e=>{l(e),s(!0)}}),(0,K.jsxs)(`button`,{onClick:()=>s(!0),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(Re,{size:13}),`Add MCP server`]})]})]})}function sX({row:e,isEditing:t,readonly:n,onEdit:r,onCommit:i,onRemove:a}){return t?(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(`input`,{value:e.name,onChange:e=>i({name:e.target.value}),placeholder:`server name`,className:`flex-1 min-w-0 border border-gray-300 rounded px-2.5 py-1.5 text-[12px] font-medium outline-none focus:border-gray-900 bg-white`}),(0,K.jsxs)(`select`,{value:e.type,onChange:e=>i({type:e.target.value}),className:`w-20 shrink-0 border border-gray-300 rounded px-2 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white`,children:[(0,K.jsx)(`option`,{value:`stdio`,children:`stdio`}),(0,K.jsx)(`option`,{value:`http`,children:`http`}),(0,K.jsx)(`option`,{value:`sse`,children:`sse`})]}),(0,K.jsx)(`button`,{onClick:a,className:`text-gray-300 hover:text-red-500 shrink-0`,title:`remove`,children:(0,K.jsx)(tt,{size:13})})]}),e.type===`http`||e.type===`sse`?(0,K.jsx)(`input`,{value:e.url,onChange:e=>i({url:e.target.value}),placeholder:`https://example.com/mcp`,className:`ip text-[12px] w-full font-mono`}):(0,K.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,K.jsx)(`input`,{value:e.command,onChange:e=>i({command:e.target.value}),placeholder:`command (e.g. npx, uvx)`,className:`ip text-[12px] w-full font-mono`}),(0,K.jsx)(`input`,{value:e.args,onChange:e=>i({args:e.target.value}),placeholder:`args (space-separated)`,className:`ip text-[12px] w-full font-mono`}),(0,K.jsx)(`textarea`,{value:e.env,onChange:e=>i({env:e.target.value}),placeholder:`env vars (KEY=val, one per line)`,className:`ip text-[12px] w-full font-mono resize-none h-14`})]}),(e.type===`http`||e.type===`sse`)&&(0,K.jsx)(`textarea`,{value:e.headers,onChange:e=>i({headers:e.target.value}),placeholder:`headers (Key: Value, one per line)`,className:`ip text-[12px] w-full font-mono resize-none h-14`}),(0,K.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,K.jsx)(`button`,{onClick:r,className:`px-2.5 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Done`})})]}):(0,K.jsxs)(`div`,{className:`group flex items-center gap-3 px-3 py-2.5 rounded-lg hover:bg-gray-50 transition-colors cursor-pointer`,onClick:n?void 0:r,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${e.type===`stdio`?`bg-purple-400`:`bg-blue-400`}`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-800 truncate`,children:e.name||(0,K.jsx)(`span`,{className:`text-gray-400 italic`,children:`unnamed`})}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase shrink-0`,children:e.type})]}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 truncate mt-0.5 font-mono`,children:e.type===`http`||e.type===`sse`?e.url||`—`:e.command||`—`})]}),!n&&(0,K.jsx)(`button`,{onClick:e=>{e.stopPropagation(),a()},className:`shrink-0 text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-all`,title:`remove`,children:(0,K.jsx)(tt,{size:13})})]})}function cX({onParse:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(null),s=()=>{let t=r.trim();if(!t)return;o(null);let a=tX(t);if(!a){o("Couldn't parse. Paste a JSON object with mcpServers, or a `claude mcp add ...` command.");return}e(a),i(``),n(!1),o(null)};return t?(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-gray-50/50 p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(ut,{size:13,className:`text-amber-500 shrink-0`}),(0,K.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`Paste JSON or CLI command`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>{n(!1),i(``),o(null)},className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`cancel`})]}),(0,K.jsx)(`textarea`,{autoFocus:!0,value:r,onChange:e=>{i(e.target.value),o(null)},onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&s()},placeholder:`Paste JSON:
|
|
131
131
|
{ "mcpServers": { "name": { "type": "http", "url": "...", "headers": { "Key": "Value" } } } }
|
|
132
132
|
|
|
133
133
|
Or CLI:
|
|
134
|
-
claude mcp add name url -t http -H "Key: Value"`,className:`ip text-[12px] w-full font-mono resize-y min-h-[80px]`,rows:4}),a&&(0,K.jsx)(`div`,{className:`text-[11px] text-red-600`,children:a}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Parse & Fill`}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:`or Ctrl+Enter`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(ut,{size:13}),`Paste JSON / CLI`]})}function cX({enabledPlugins:e,onChange:t,readonly:n,focusMarketplaceRef:r}){let[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!0),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``);(0,_.useEffect)(()=>{fg().then(e=>{a(e),s(!1)})},[]);let f=r=>{if(n)return;let i={...e};i[r]??!1?delete i[r]:i[r]=!0,t(i)},p=()=>{n||!u.trim()||(t({...e,[u.trim()]:!0}),d(``),l(!1))},m=r=>{if(n)return;let{[r]:i,...a}=e;t(a)},h=new Set(i.map(e=>`${e.name}@${e.marketplace}`)),g=i.filter(t=>e[`${t.name}@${t.marketplace}`]),v=i.filter(t=>!e[`${t.name}@${t.marketplace}`]),y=Object.keys(e).filter(t=>e[t]&&!h.has(t));return(0,K.jsxs)(`div`,{className:`space-y-2`,children:[o?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-3 text-[12px] text-gray-400`,children:[(0,K.jsx)(Be,{size:11,className:`animate-spin`}),` loading…`]}):(0,K.jsx)(K.Fragment,{children:g.length===0&&v.length===0&&y.length===0?(0,K.jsx)(`div`,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 text-center py-4`,children:[(0,K.jsx)(Ne,{size:18,className:`text-gray-300`}),(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:`No plugins`}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400/70`,children:`Browse marketplaces below or type a plugin spec to add one.`})]})}):(0,K.jsxs)(`div`,{className:`space-y-0.5`,children:[g.map(e=>{let t=`${e.name}@${e.marketplace}`;return(0,K.jsx)(uX,{name:e.displayName||e.name,subtitle:`@${e.marketplace}`,description:e.description,enabled:!0,onToggle:()=>f(t),readonly:n},t)}),y.map(e=>(0,K.jsx)(uX,{name:e,subtitle:`custom`,enabled:!0,onToggle:()=>f(e),onRemove:()=>m(e),readonly:n},e)),v.map(e=>{let t=`${e.name}@${e.marketplace}`;return(0,K.jsx)(uX,{name:e.displayName||e.name,subtitle:`@${e.marketplace}`,description:e.description,enabled:!1,onToggle:()=>f(t),readonly:n},t)})]})}),!n&&(0,K.jsx)(dX,{open:c,value:u,onOpen:()=>l(!0),onCancel:()=>{l(!1),d(``)},onChange:d,onAdd:p}),!n&&(0,K.jsx)(lX,{enabledPlugins:e,onToggle:f,focusMarketplaceRef:r})]})}function lX({enabledPlugins:e,onToggle:t,focusMarketplaceRef:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(`all`),S=async()=>{u(!0),g(null);let[e,t]=await Promise.all([pg(),mg()]);o(e),c(t),u(!1)},C=async()=>{f(!0),g(null),y(null);let e=await hg();e.ok?(e.added&&e.added.length>0&&y(`Registered: ${e.added.join(`, `)}`),await S()):g(e.error??`refresh failed`),f(!1)};(0,_.useEffect)(()=>{if(!r)return;let e=!1;return(async()=>{u(!0),g(null),y(null);let t=await hg();if(e)return;t.ok&&t.added&&t.added.length>0&&y(`Auto-registered: ${t.added.join(`, `)}`);let[n,r]=await Promise.all([pg(),mg()]);e||(o(n),c(r),u(!1))})(),()=>{e=!0}},[r]);let w=[...new Set(a.map(e=>e.marketplaceName).filter(Boolean))].sort(),T=a.filter(e=>{if(b!==`all`&&e.marketplaceName!==b)return!1;if(p.trim()){let t=p.toLowerCase();if(!e.name.toLowerCase().includes(t)&&!e.marketplaceName.toLowerCase().includes(t)&&!(e.description&&e.description.toLowerCase().includes(t)))return!1}return!0}),E={};for(let e of T){let t=e.marketplaceName||`unknown`;E[t]||(E[t]=[]),E[t].push(e)}return(0,K.jsx)(`div`,{children:r?(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-gray-50 border-b border-gray-100`,children:[(0,K.jsx)(Ze,{size:13,className:`text-gray-500 shrink-0`}),(0,K.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`Marketplace Plugins`}),(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[s.length,` source`,s.length===1?``:`s`]}),(0,K.jsx)(`div`,{className:`flex-1`}),n&&(0,K.jsx)(`button`,{onClick:()=>n.current?.(),className:`text-[11px] text-gray-400 hover:text-gray-700 px-1.5 py-0.5 rounded transition-colors`,title:`Add a marketplace source`,children:`+ Add source`}),(0,K.jsx)(`button`,{onClick:C,disabled:d,className:`p-1 rounded text-gray-400 hover:text-gray-700 disabled:opacity-50`,title:`Refresh marketplace registrations`,children:(0,K.jsx)(Be,{size:11,className:d?`animate-spin`:``})}),(0,K.jsx)(`button`,{onClick:()=>i(!1),className:`p-1 rounded text-gray-400 hover:text-gray-700`,children:(0,K.jsx)(lt,{size:13})})]}),(0,K.jsxs)(`div`,{className:`px-3 py-2 border-b border-gray-100 flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Ue,{size:12,className:`absolute left-2 top-1/2 -translate-y-1/2 text-gray-400`}),(0,K.jsx)(`input`,{value:p,onChange:e=>m(e.target.value),placeholder:`search plugins…`,className:`w-full pl-7 pr-2 py-1.5 text-[12px] border border-gray-200 rounded-lg outline-none focus:border-gray-400 bg-white`})]}),w.length>1&&(0,K.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-28 shrink-0 border border-gray-200 rounded-lg px-2 py-1.5 text-[11px] outline-none focus:border-gray-400 bg-white`,children:[(0,K.jsx)(`option`,{value:`all`,children:`All sources`}),w.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),v&&(0,K.jsx)(`div`,{className:`px-3 py-1.5 bg-emerald-50 border-b border-emerald-100 text-[11px] text-emerald-700`,children:v}),(0,K.jsx)(`div`,{className:`max-h-[300px] overflow-y-auto`,children:l?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-6 justify-center text-[12px] text-gray-400`,children:[(0,K.jsx)(Be,{size:11,className:`animate-spin`}),` loading marketplace catalogs…`]}):h?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-4 text-[12px] text-red-600`,children:[(0,K.jsx)(R,{size:12}),` `,h]}):Object.keys(E).length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 py-6 text-center`,children:[(0,K.jsx)(Ne,{size:18,className:`text-gray-300`}),(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:p?`No matching plugins`:s.length===0?`No marketplaces configured`:`No plugins found in marketplaces`}),s.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400/70 px-4 space-y-2`,children:(0,K.jsxs)(`div`,{children:[`No marketplace sources registered. Add one below or`,` `,n?(0,K.jsx)(`button`,{onClick:()=>n.current?.(),className:`text-gray-700 underline hover:text-gray-900`,children:`add a marketplace source`}):`add a marketplace source`,` `,`in the Marketplaces section, then refresh.`]})})]}):(0,K.jsx)(`div`,{className:`py-1`,children:Object.entries(E).map(([n,r])=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] font-semibold text-gray-400 uppercase tracking-wider bg-gray-50/50`,children:n}),r.map(n=>{let r=`${n.name}@${n.marketplaceName}`,i=e[r]??!1;return(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-gray-50 transition-colors cursor-pointer`,children:[(0,K.jsx)(WY,{checked:i,onCheckedChange:()=>t(r),size:`sm`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-[12px] text-gray-900 truncate`,children:n.displayName||n.name}),n.installed&&(0,K.jsx)(`span`,{className:`text-[9px] bg-gray-100 text-gray-500 px-1 py-0.5 rounded-full shrink-0`,children:`installed`}),i&&(0,K.jsx)(`span`,{className:`text-[9px] bg-emerald-100 text-emerald-700 px-1 py-0.5 rounded-full shrink-0`,children:`on`})]}),n.description&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-0.5 line-clamp-1`,children:n.description})]})]},r)})]},n))})})]}):(0,K.jsxs)(`button`,{onClick:()=>i(!0),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(Ze,{size:13}),`Browse marketplace plugins`]})})}function uX({name:e,subtitle:t,description:n,enabled:r,onToggle:i,onRemove:a,readonly:o}){return(0,K.jsxs)(`div`,{className:`group flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors ${r?`hover:bg-gray-50`:`hover:bg-gray-50/50`}`,children:[(0,K.jsx)(WY,{checked:r,onCheckedChange:i,disabled:o,size:`sm`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-[13px] truncate ${r?`text-gray-900 font-medium`:`text-gray-400`}`,children:e}),t&&(0,K.jsx)(`span`,{className:`text-[10px] shrink-0 ${r?`text-gray-400`:`text-gray-300`}`,children:t})]}),n&&(0,K.jsx)(`div`,{className:`text-[11px] mt-0.5 line-clamp-1 ${r?`text-gray-500`:`text-gray-400`}`,children:n})]}),a&&!o&&(0,K.jsx)(`button`,{onClick:a,className:`shrink-0 text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-all`,title:`remove`,children:(0,K.jsx)(tt,{size:13})})]})}function dX({open:e,value:t,onOpen:n,onCancel:r,onChange:i,onAdd:a}){return e?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&a(),e.key===`Escape`&&r()},placeholder:`name@marketplace`,className:`flex-1 min-w-0 border border-gray-300 rounded px-2.5 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white`}),(0,K.jsx)(`button`,{onClick:a,className:`px-2.5 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800 shrink-0`,children:`add`}),(0,K.jsx)(`button`,{onClick:r,className:`text-[11px] text-gray-400 hover:text-gray-600 shrink-0`,children:`cancel`})]}):(0,K.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(Re,{size:13}),`Add plugin by spec`]})}var fX={team:{icon:_e,borderClass:`border-l-violet-400`,badgeClass:`bg-violet-100 text-violet-700`,desc:`Workspace-wide, set by admin`},personal:{icon:ot,borderClass:`border-l-emerald-400`,badgeClass:`bg-emerald-100 text-emerald-700`,desc:`Your personal overrides`},project:{icon:de,borderClass:`border-l-gray-300`,badgeClass:`bg-gray-100 text-gray-500`,desc:`SDK reads from workdir`},local:{icon:oe,borderClass:`border-l-amber-300`,badgeClass:`bg-amber-100 text-amber-700`,desc:`Per-checkout .local.* overrides`}};function pX(e){return e.startsWith(`profile:`)?{icon:k,borderClass:`border-l-blue-400`,badgeClass:`bg-blue-100 text-blue-700`,desc:`Opt-in role-based config`}:fX[e]??fX.team}function mX(e){return e.id===`team`?{vault:`knowledge`,file:`.loopat/.claude/settings.json`}:e.id.startsWith(`profile:`)?{vault:`knowledge`,file:`.loopat/profiles/${e.id.slice(8)}/.claude/settings.json`}:e.id===`personal`?{vault:`personal`,file:`.loopat/.claude/settings.json`}:null}function hX(e){return e===`team`?1:e.startsWith(`profile:`)?2:e===`personal`?3:e===`project`?4:e===`local`?5:99}function gX(e){return e===`admin`?`bg-violet-100 text-violet-700`:e===`user`?`bg-gray-100 text-gray-600`:`bg-gray-100 text-gray-400`}function _X({disabled:e}){let t=Cg().currentUser?.role===`admin`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!0),[o,s]=_i(),c=o.get(`expand`)??`personal`,l=new Set(c.split(`,`).filter(Boolean)),u=e=>{let t=[...e].join(`,`);s(t?{expand:t}:{},{replace:!0})},[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(async()=>{a(!0),r(await cg()),a(!1)},[]);(0,_.useEffect)(()=>{p()},[p]);let m=e=>{let t=new Set(l);t.has(e)?t.delete(e):t.add(e),u(t)},h=n?.tiers??[],g=h.filter(e=>e.id.startsWith(`profile:`)),v=h.filter(e=>!e.id.startsWith(`profile:`)).sort((e,t)=>hX(e.id)-hX(t.id)),y={pluginCount:g.reduce((e,t)=>e+t.pluginCount,0),mcpServerCount:g.reduce((e,t)=>e+t.mcpServerCount,0),overrideCount:g.reduce((e,t)=>e+Object.keys(t.overrides).length,0)},b=[...v.filter(e=>hX(e.id)<3),...g.length>0?[{id:`__profiles__`,label:`Profiles (${g.length})`,tier:g[0],isGroup:!0}]:[],...v.filter(e=>hX(e.id)>=3)];return i&&!n?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-12 justify-center text-[13px] text-gray-400`,children:[(0,K.jsx)(Be,{size:13,className:`animate-spin`}),` loading tiers…`]}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white overflow-hidden transition-shadow hover:shadow-sm`,children:[(0,K.jsxs)(`div`,{className:`px-4 py-3 border-b border-gray-100 flex items-center gap-2.5`,children:[(0,K.jsx)(xe,{size:15,className:`text-gray-400`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:`Claude Config Composition`}),(0,K.jsxs)(`span`,{className:`text-[11px] text-gray-400 ml-2`,children:[h.filter(e=>e.exists).length,` active tiers · merged at loop spawn`]})]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:p,disabled:i,className:`p-1.5 rounded hover:bg-gray-100 text-gray-400 hover:text-gray-700 transition-colors`,children:(0,K.jsx)(Be,{size:13,className:i?`animate-spin`:``})})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-px bg-gray-100`,children:b.map(e=>{if(`isGroup`in e)return(0,K.jsx)(CX,{profiles:g,expanded:l,summary:y,open:d,onToggle:()=>f(!d)},`__profiles__`);let t=e,n=pX(t.id).icon,r=l.has(t.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(t.id),className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${r?`bg-gray-50`:``}`,children:[(0,K.jsx)(n,{size:14,className:`shrink-0 ${t.exists?`text-gray-500`:`text-gray-300`}`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-1.5`,children:(0,K.jsx)(`span`,{className:`text-[11px] font-medium truncate ${t.exists?`text-gray-700`:`text-gray-400`}`,children:t.label})}),(0,K.jsxs)(`div`,{className:`text-[10px] text-gray-400 mt-0.5 flex items-center gap-1.5`,children:[t.pluginCount>0&&(0,K.jsxs)(`span`,{children:[t.pluginCount,`p`]}),t.mcpServerCount>0&&(0,K.jsxs)(`span`,{children:[t.mcpServerCount,`m`]}),t.pluginCount===0&&t.mcpServerCount===0&&!t.exists&&(0,K.jsx)(`span`,{children:`—`}),Object.keys(t.overrides).length>0&&(0,K.jsxs)(`span`,{className:`text-amber-500`,children:[Object.keys(t.overrides).length,`↗`]})]})]}),r?(0,K.jsx)(F,{size:10,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:10,className:`text-gray-400 shrink-0`})]},t.id)})}),d&&g.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-gray-200 bg-gray-50/50 px-4 py-2 space-y-0.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider px-1 mb-1`,children:`Select a profile to expand`}),g.map(e=>{let t=l.has(e.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{m(e.id),f(!1),setTimeout(()=>{document.getElementById(`tier-${e.id}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},50)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded hover:bg-white/80 text-left transition-colors`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${t?`bg-blue-400`:`bg-gray-300`}`}),(0,K.jsx)(`span`,{className:`text-[12px] text-gray-700 flex-1`,children:e.label.replace(`Profile: `,``)}),(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-400 tabular-nums shrink-0`,children:[e.pluginCount>0&&(0,K.jsxs)(K.Fragment,{children:[e.pluginCount,`p `]}),e.mcpServerCount>0&&(0,K.jsxs)(K.Fragment,{children:[e.mcpServerCount,`m`]}),!e.pluginCount&&!e.mcpServerCount&&`—`]}),t&&(0,K.jsx)(F,{size:9,className:`text-blue-400 shrink-0`})]},e.id)}),t&&(0,K.jsx)(wX,{onCreated:e=>{f(!1),p().then(()=>{let t=`profile:${e}`;m(t),setTimeout(()=>{document.getElementById(`tier-${t}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},100)})}})]})]}),[...v,...g].map(n=>(0,K.jsx)(vX,{tier:n,isAdmin:!!t,isExpanded:l.has(n.id),disabled:e,onSaved:()=>p()},n.id))]})}function vX({tier:e,isAdmin:t,isExpanded:n,disabled:r,onSaved:i}){if(!n)return null;let a=pX(e.id),o=a.icon,s=e.editable&&(e.managedBy===`user`||e.managedBy===`admin`&&t),c=e.managedBy===`sdk`,l=e.id.startsWith(`profile:`),u=l?e.id.slice(8):``,d=!s&&e.managedBy===`admin`&&!t?`Admin access required`:null,[f,p]=(0,_.useState)({}),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(!1),x=zn(),S=(0,_.useRef)(null),C=mX(e);(0,_.useEffect)(()=>{p(e.settings?{...e.settings}:{}),v(null),b(!1)},[e.settings,e.id]);let w=async()=>{h(!0),v(null);let{_comment:t,...n}=f,r=await lg(e.id,n);if(h(!1),!r.ok){v(r.error??`save failed`);return}b(!0),setTimeout(()=>b(!1),2500),i()},T=Object.keys(e.overrides).length;return(0,K.jsxs)(`div`,{id:`tier-${e.id}`,className:`rounded-lg border overflow-hidden transition-shadow hover:shadow-sm ${s?`border-gray-200 bg-white`:`border-gray-200 bg-gray-50/50`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-gray-100 border-l-2 ${a.borderClass}`,children:[(0,K.jsx)(o,{size:16,className:`text-gray-500 shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[14px] font-semibold text-gray-900`,children:e.label}),(0,K.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full font-medium ${gX(e.managedBy)}`,children:e.managedBy===`admin`?`admin`:e.managedBy===`user`?`you`:`SDK`}),!e.exists&&!c&&(0,K.jsx)(`span`,{className:`text-[10px] text-amber-600 bg-amber-50 px-1.5 py-0.5 rounded-full`,children:`not created`}),d&&(0,K.jsx)(Te,{size:11,className:`text-amber-500 shrink-0`})]}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-0.5`,children:c?e.path:a.desc})]}),(0,K.jsxs)(`div`,{className:`hidden sm:flex items-center gap-1.5 shrink-0`,children:[(0,K.jsx)(yX,{label:`Plugins`,value:e.pluginCount}),(0,K.jsx)(yX,{label:`MCP`,value:e.mcpServerCount}),e.skillCount>0&&(0,K.jsx)(yX,{label:`Skills`,value:e.skillCount}),e.agentCount>0&&(0,K.jsx)(yX,{label:`Agents`,value:e.agentCount}),e.toolchainCount>0&&(0,K.jsx)(yX,{label:`Toolchain`,value:e.toolchainCount}),T>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-amber-600 bg-amber-50 px-1.5 py-0.5 rounded-full font-medium`,children:[T,` override`,T>1?`s`:``]})]}),C&&(0,K.jsxs)(zp,{children:[(0,K.jsx)(Bp,{asChild:!0,children:(0,K.jsx)(`button`,{onClick:()=>x(`/context/${C.vault}?file=${encodeURIComponent(C.file)}&edit=1`),className:`shrink-0 p-1.5 rounded-lg text-gray-300 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:(0,K.jsx)(oe,{size:13})})}),(0,K.jsxs)(Vp,{children:[`edit `,C.vault,`/`,C.file]})]})]}),(0,K.jsx)(`div`,{className:`px-4 py-4 space-y-5`,children:c?(0,K.jsxs)(`div`,{className:`rounded-lg bg-gray-50 px-3 py-2.5 text-[12px] text-gray-500`,children:[`SDK-managed — read directly from `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[11px]`,children:e.path}),`. Not editable here.`]}):(0,K.jsxs)(K.Fragment,{children:[C&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-gray-400`,children:[(0,K.jsxs)(`button`,{onClick:()=>x(`/context/${C.vault}?file=${encodeURIComponent(C.file)}&edit=1`),className:`inline-flex items-center gap-1 px-2 py-1 rounded hover:bg-gray-100 text-gray-500 hover:text-gray-700 transition-colors`,children:[(0,K.jsx)(oe,{size:11}),`edit settings.json`]}),e.claudeMd!==null&&(0,K.jsx)(`button`,{onClick:()=>x(`/context/${C.vault}?file=${encodeURIComponent(C.file.replace(`settings.json`,`CLAUDE.md`))}`),className:`inline-flex items-center gap-1 px-2 py-1 rounded hover:bg-gray-100 text-gray-500 hover:text-gray-700 transition-colors`,children:`view CLAUDE.md`}),(0,K.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-gray-400 truncate font-mono text-[10px]`,children:[C.vault,`/`,C.file]})]}),T>0&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50/50 px-3 py-2`,children:[(0,K.jsx)(`div`,{className:`text-[11px] font-medium text-amber-700 mb-1.5`,children:`Overrides from lower tiers`}),(0,K.jsxs)(`div`,{className:`space-y-0.5`,children:[Object.entries(e.overrides).slice(0,8).map(([e,t])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-amber-700/80`,children:[(0,K.jsx)(R,{size:10,className:`text-amber-400 shrink-0`}),(0,K.jsx)(`code`,{className:`text-[10px] bg-amber-100/50 px-1 rounded`,children:e}),(0,K.jsxs)(`span`,{className:`text-amber-500`,children:[`shadows `,t.overrides]})]},e)),T>8&&(0,K.jsxs)(`div`,{className:`text-[10px] text-amber-400 ml-5`,children:[`+`,T-8,` more`]})]})]}),(0,K.jsx)(bX,{title:`Plugins`,count:e.pluginCount,defaultOpen:e.pluginCount>0,children:!s&&e.pluginCount===0?(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-2`,children:`No plugins configured in this tier`}):(0,K.jsx)(cX,{enabledPlugins:f?.enabledPlugins??{},readonly:!s||r,focusMarketplaceRef:S,onChange:e=>p(t=>t?{...t,enabledPlugins:e}:{enabledPlugins:e})})}),(0,K.jsx)(bX,{title:`MCP Servers`,count:e.mcpServerCount,defaultOpen:e.mcpServerCount>0,children:(0,K.jsx)(aX,{servers:iX(f),readonly:!s||r,onChange:e=>p(t=>t?{...t,mcpServers:e}:{mcpServers:e})})}),(0,K.jsx)(bX,{title:`Marketplaces`,count:e.marketplaceCount,defaultOpen:e.marketplaceCount>0||s,children:(0,K.jsx)(SX,{marketplaces:f?.extraKnownMarketplaces??{},readonly:!s||r,onChange:e=>p(t=>t?{...t,extraKnownMarketplaces:e}:{extraKnownMarketplaces:e}),focusRef:S})}),e.hookCount>0&&(0,K.jsx)(bX,{title:`Hooks`,count:e.hookCount,defaultOpen:!1,children:(0,K.jsxs)(`div`,{className:`text-[12px] text-gray-500`,children:[Object.keys(f?.hooks??{}).length,` hook groups configured.`]})}),d&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-50 text-[12px] text-amber-700`,children:[(0,K.jsx)(Te,{size:12}),d]}),l&&t&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-gray-100`,children:[(0,K.jsx)(`button`,{onClick:async()=>{if(!confirm(`Delete profile "${u}"? This removes all its .claude/ contents permanently.`))return;let e=await _g(u);if(!e.ok){v(e.error??`delete failed`);return}i()},className:`px-3 h-7 rounded-lg text-[11px] text-red-500 hover:bg-red-50 hover:text-red-600 transition-colors`,children:`Delete profile`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[g&&(0,K.jsx)(`span`,{className:`text-[12px] text-red-600`,children:g}),y&&(0,K.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:13}),` saved`]}),(0,K.jsx)(`button`,{onClick:w,disabled:m||r,className:`px-4 h-8 rounded-lg bg-gray-900 text-white text-xs font-medium hover:bg-gray-800 disabled:opacity-50 transition-colors`,children:m?`Saving…`:`Save`})]})]}),s&&!l&&(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-3 border-t border-gray-100`,children:[g&&(0,K.jsx)(`span`,{className:`text-[12px] text-red-600`,children:g}),y&&(0,K.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:13}),` saved`]}),(0,K.jsx)(`button`,{onClick:w,disabled:m||r,className:`px-4 h-8 rounded-lg bg-gray-900 text-white text-xs font-medium hover:bg-gray-800 disabled:opacity-50 transition-colors`,children:m?`Saving…`:`Save`})]})]})})]})}function yX({label:e,value:t}){return(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-500 bg-gray-100 px-1.5 py-0.5 rounded-full font-medium tabular-nums`,children:[t,` `,(0,K.jsx)(`span`,{className:`text-gray-400`,children:e})]})}function bX({title:e,count:t,defaultOpen:n,children:r}){let[i,a]=(0,_.useState)(n);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-1.5 mb-2 hover:text-gray-900 transition-colors`,children:[i?(0,K.jsx)(F,{size:12,className:`text-gray-400`}):(0,K.jsx)(I,{size:12,className:`text-gray-400`}),(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:e}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 tabular-nums`,children:t})]}),i&&(0,K.jsx)(`div`,{className:`ml-3 pl-3 border-l-2 border-gray-100`,children:r})]})}function xX(e){try{let t=e.trim().replace(/\.git$/,``).split(/[?#]/)[0].replace(/\/$/,``).split(`/`);return t[t.length-1]||``}catch{return``}}function SX({marketplaces:e,readonly:t,onChange:n,focusRef:r}){let[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(`git`),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(`main`),[m,h]=(0,_.useState)(!1),g=(0,_.useRef)(null);(0,_.useEffect)(()=>{r&&(r.current=()=>{a(!0),setTimeout(()=>g.current?.focus(),50)})},[r]);let v=Object.entries(e),y=()=>{let t=o.trim();if(!t||!u.trim())return;let r;switch(c){case`git`:r={source:`git`,url:u.trim()};break;case`github`:r={source:`github`,repo:u.trim()};break;case`directory`:r={source:`directory`,path:u.trim()};break}c!==`directory`&&f.trim()&&f.trim()!==`main`&&(r.branch=f.trim()),n({...e,[t]:{source:r}}),s(``),d(``),p(`main`),h(!1),a(!1)},b=t=>{let{[t]:r,...i}=e;n(i)};return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[v.length===0&&!i&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-2`,children:`No additional marketplaces. The built-in marketplace is always available.`}),v.map(([e,n])=>{let r=n?.source??{},i=r?.branch,a=r.source===`git`?`git ${r.url??``}${i?` @${i}`:``}`:r.source===`github`?`github:${r.repo??``}${i?` @${i}`:``}`:r.source===`directory`?`dir: ${r.path??``}`:JSON.stringify(r);return(0,K.jsxs)(`div`,{className:`group flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-50 transition-colors`,children:[(0,K.jsx)(Ze,{size:13,className:`text-gray-400 shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-[12px] font-medium text-gray-800 truncate`,children:e}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 font-mono truncate`,children:a})]}),!t&&(0,K.jsx)(`button`,{onClick:()=>b(e),className:`shrink-0 text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-all`,title:`remove`,children:(0,K.jsx)(tt,{size:13})})]},e)}),i&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-gray-50/50 p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{ref:g,autoFocus:!0,value:o,onChange:e=>{s(e.target.value),h(!0)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&y(),e.key===`Escape`&&(a(!1),s(``),h(!1))},placeholder:`marketplace name`,className:`flex-1 min-w-0 border border-gray-300 rounded px-2.5 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white`}),(0,K.jsxs)(`select`,{value:c,onChange:e=>{l(e.target.value),e.target.value===`directory`&&h(!0)},className:`w-24 shrink-0 border border-gray-300 rounded px-2 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white`,children:[(0,K.jsx)(`option`,{value:`git`,children:`git URL`}),(0,K.jsx)(`option`,{value:`github`,children:`github repo`}),(0,K.jsx)(`option`,{value:`directory`,children:`directory`})]})]}),(0,K.jsx)(`input`,{value:u,onChange:e=>{if(d(e.target.value),(c===`git`||c===`github`)&&!m){let t=xX(e.target.value);t&&s(t)}},placeholder:c===`git`?`https://...`:c===`github`?`owner/repo`:`/path/to/marketplace`,className:`ip text-[12px] w-full font-mono`}),c!==`directory`&&(0,K.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:`branch (default: main)`,className:`ip text-[12px] w-full font-mono`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:y,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>{a(!1),s(``),d(``)},className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}),!t&&(0,K.jsxs)(`button`,{onClick:()=>a(!0),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(Re,{size:13}),`Add marketplace source`]})]})}function CX({profiles:e,expanded:t,summary:n,open:r,onToggle:i}){return(0,K.jsxs)(`button`,{type:`button`,onClick:i,className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${e.some(e=>t.has(e.id))||r?`bg-gray-50`:``}`,children:[(0,K.jsx)(k,{size:14,className:`text-blue-400 shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-1.5`,children:(0,K.jsxs)(`span`,{className:`text-[11px] font-medium text-gray-700 truncate`,children:[`Profiles (`,e.length,`)`]})}),(0,K.jsxs)(`div`,{className:`text-[10px] text-gray-400 mt-0.5 flex items-center gap-1.5`,children:[n.pluginCount>0&&(0,K.jsxs)(`span`,{children:[n.pluginCount,`p`]}),n.mcpServerCount>0&&(0,K.jsxs)(`span`,{children:[n.mcpServerCount,`m`]}),n.pluginCount===0&&n.mcpServerCount===0&&(0,K.jsx)(`span`,{children:`—`}),n.overrideCount>0&&(0,K.jsxs)(`span`,{className:`text-amber-500`,children:[n.overrideCount,`↗`]})]})]}),r?(0,K.jsx)(F,{size:10,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:10,className:`text-gray-400 shrink-0`})]})}function wX({onCreated:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(null),s=async()=>{let t=r.trim();if(!t)return;o(null);let a=await gg(t);if(!a.ok){o(a.error??`create failed`);return}i(``),n(!1),e(t)};return t?(0,K.jsxs)(`div`,{className:`px-3 py-1.5 space-y-1.5`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>{i(e.target.value),o(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&(n(!1),i(``))},placeholder:`profile name`,className:`flex-1 min-w-0 border border-gray-300 rounded px-2.5 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white w-full`}),a&&(0,K.jsx)(`div`,{className:`text-[11px] text-red-600`,children:a}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Create`}),(0,K.jsx)(`button`,{onClick:()=>{n(!1),i(``),o(null)},className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-[11px] text-gray-400 hover:text-gray-700 hover:bg-white/80 rounded w-full transition-colors`,children:[(0,K.jsx)(Re,{size:12}),`Create profile`]})}function TX(e,t){let n=e.slice(0,t).split(/\r\n|\n|\r/g);return[n.length,n.pop().length+1]}function EX(e,t,n){let r=e.split(/\r\n|\n|\r/g),i=``,a=(Math.log10(t+1)|0)+1;for(let e=t-1;e<=t+1;e++){let o=r[e-1];o&&(i+=e.toString().padEnd(a,` `),i+=`: `,i+=o,i+=`
|
|
134
|
+
claude mcp add name url -t http -H "Key: Value"`,className:`ip text-[12px] w-full font-mono resize-y min-h-[80px]`,rows:4}),a&&(0,K.jsx)(`div`,{className:`text-[11px] text-red-600`,children:a}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Parse & Fill`}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:`or Ctrl+Enter`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(ut,{size:13}),`Paste JSON / CLI`]})}function lX({enabledPlugins:e,onChange:t,readonly:n,focusMarketplaceRef:r}){let[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!0),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``);(0,_.useEffect)(()=>{fg().then(e=>{a(e),s(!1)})},[]);let f=r=>{if(n)return;let i={...e};i[r]??!1?delete i[r]:i[r]=!0,t(i)},p=()=>{n||!u.trim()||(t({...e,[u.trim()]:!0}),d(``),l(!1))},m=r=>{if(n)return;let{[r]:i,...a}=e;t(a)},h=new Set(i.map(e=>`${e.name}@${e.marketplace}`)),g=i.filter(t=>e[`${t.name}@${t.marketplace}`]),v=i.filter(t=>!e[`${t.name}@${t.marketplace}`]),y=Object.keys(e).filter(t=>e[t]&&!h.has(t));return(0,K.jsxs)(`div`,{className:`space-y-2`,children:[o?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-3 text-[12px] text-gray-400`,children:[(0,K.jsx)(Be,{size:11,className:`animate-spin`}),` loading…`]}):(0,K.jsx)(K.Fragment,{children:g.length===0&&v.length===0&&y.length===0?(0,K.jsx)(`div`,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 text-center py-4`,children:[(0,K.jsx)(Ne,{size:18,className:`text-gray-300`}),(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:`No plugins`}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400/70`,children:`Browse marketplaces below or type a plugin spec to add one.`})]})}):(0,K.jsxs)(`div`,{className:`space-y-0.5`,children:[g.map(e=>{let t=`${e.name}@${e.marketplace}`;return(0,K.jsx)(dX,{name:e.displayName||e.name,subtitle:`@${e.marketplace}`,description:e.description,enabled:!0,onToggle:()=>f(t),readonly:n},t)}),y.map(e=>(0,K.jsx)(dX,{name:e,subtitle:`custom`,enabled:!0,onToggle:()=>f(e),onRemove:()=>m(e),readonly:n},e)),v.map(e=>{let t=`${e.name}@${e.marketplace}`;return(0,K.jsx)(dX,{name:e.displayName||e.name,subtitle:`@${e.marketplace}`,description:e.description,enabled:!1,onToggle:()=>f(t),readonly:n},t)})]})}),!n&&(0,K.jsx)(fX,{open:c,value:u,onOpen:()=>l(!0),onCancel:()=>{l(!1),d(``)},onChange:d,onAdd:p}),!n&&(0,K.jsx)(uX,{enabledPlugins:e,onToggle:f,focusMarketplaceRef:r})]})}function uX({enabledPlugins:e,onToggle:t,focusMarketplaceRef:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(`all`),S=async()=>{u(!0),g(null);let[e,t]=await Promise.all([pg(),mg()]);o(e),c(t),u(!1)},C=async()=>{f(!0),g(null),y(null);let e=await hg();e.ok?(e.added&&e.added.length>0&&y(`Registered: ${e.added.join(`, `)}`),await S()):g(e.error??`refresh failed`),f(!1)};(0,_.useEffect)(()=>{if(!r)return;let e=!1;return(async()=>{u(!0),g(null),y(null);let t=await hg();if(e)return;t.ok&&t.added&&t.added.length>0&&y(`Auto-registered: ${t.added.join(`, `)}`);let[n,r]=await Promise.all([pg(),mg()]);e||(o(n),c(r),u(!1))})(),()=>{e=!0}},[r]);let w=[...new Set(a.map(e=>e.marketplaceName).filter(Boolean))].sort(),T=a.filter(e=>{if(b!==`all`&&e.marketplaceName!==b)return!1;if(p.trim()){let t=p.toLowerCase();if(!e.name.toLowerCase().includes(t)&&!e.marketplaceName.toLowerCase().includes(t)&&!(e.description&&e.description.toLowerCase().includes(t)))return!1}return!0}),E={};for(let e of T){let t=e.marketplaceName||`unknown`;E[t]||(E[t]=[]),E[t].push(e)}return(0,K.jsx)(`div`,{children:r?(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-gray-50 border-b border-gray-100`,children:[(0,K.jsx)(Ze,{size:13,className:`text-gray-500 shrink-0`}),(0,K.jsx)(`span`,{className:`text-[12px] font-medium text-gray-700`,children:`Marketplace Plugins`}),(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[s.length,` source`,s.length===1?``:`s`]}),(0,K.jsx)(`div`,{className:`flex-1`}),n&&(0,K.jsx)(`button`,{onClick:()=>n.current?.(),className:`text-[11px] text-gray-400 hover:text-gray-700 px-1.5 py-0.5 rounded transition-colors`,title:`Add a marketplace source`,children:`+ Add source`}),(0,K.jsx)(`button`,{onClick:C,disabled:d,className:`p-1 rounded text-gray-400 hover:text-gray-700 disabled:opacity-50`,title:`Refresh marketplace registrations`,children:(0,K.jsx)(Be,{size:11,className:d?`animate-spin`:``})}),(0,K.jsx)(`button`,{onClick:()=>i(!1),className:`p-1 rounded text-gray-400 hover:text-gray-700`,children:(0,K.jsx)(lt,{size:13})})]}),(0,K.jsxs)(`div`,{className:`px-3 py-2 border-b border-gray-100 flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Ue,{size:12,className:`absolute left-2 top-1/2 -translate-y-1/2 text-gray-400`}),(0,K.jsx)(`input`,{value:p,onChange:e=>m(e.target.value),placeholder:`search plugins…`,className:`w-full pl-7 pr-2 py-1.5 text-[12px] border border-gray-200 rounded-lg outline-none focus:border-gray-400 bg-white`})]}),w.length>1&&(0,K.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-28 shrink-0 border border-gray-200 rounded-lg px-2 py-1.5 text-[11px] outline-none focus:border-gray-400 bg-white`,children:[(0,K.jsx)(`option`,{value:`all`,children:`All sources`}),w.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),v&&(0,K.jsx)(`div`,{className:`px-3 py-1.5 bg-emerald-50 border-b border-emerald-100 text-[11px] text-emerald-700`,children:v}),(0,K.jsx)(`div`,{className:`max-h-[300px] overflow-y-auto`,children:l?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-6 justify-center text-[12px] text-gray-400`,children:[(0,K.jsx)(Be,{size:11,className:`animate-spin`}),` loading marketplace catalogs…`]}):h?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-4 text-[12px] text-red-600`,children:[(0,K.jsx)(R,{size:12}),` `,h]}):Object.keys(E).length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 py-6 text-center`,children:[(0,K.jsx)(Ne,{size:18,className:`text-gray-300`}),(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400`,children:p?`No matching plugins`:s.length===0?`No marketplaces configured`:`No plugins found in marketplaces`}),s.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400/70 px-4 space-y-2`,children:(0,K.jsxs)(`div`,{children:[`No marketplace sources registered. Add one below or`,` `,n?(0,K.jsx)(`button`,{onClick:()=>n.current?.(),className:`text-gray-700 underline hover:text-gray-900`,children:`add a marketplace source`}):`add a marketplace source`,` `,`in the Marketplaces section, then refresh.`]})})]}):(0,K.jsx)(`div`,{className:`py-1`,children:Object.entries(E).map(([n,r])=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] font-semibold text-gray-400 uppercase tracking-wider bg-gray-50/50`,children:n}),r.map(n=>{let r=`${n.name}@${n.marketplaceName}`,i=e[r]??!1;return(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-gray-50 transition-colors cursor-pointer`,children:[(0,K.jsx)(GY,{checked:i,onCheckedChange:()=>t(r),size:`sm`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-[12px] text-gray-900 truncate`,children:n.displayName||n.name}),n.installed&&(0,K.jsx)(`span`,{className:`text-[9px] bg-gray-100 text-gray-500 px-1 py-0.5 rounded-full shrink-0`,children:`installed`}),i&&(0,K.jsx)(`span`,{className:`text-[9px] bg-emerald-100 text-emerald-700 px-1 py-0.5 rounded-full shrink-0`,children:`on`})]}),n.description&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-0.5 line-clamp-1`,children:n.description})]})]},r)})]},n))})})]}):(0,K.jsxs)(`button`,{onClick:()=>i(!0),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(Ze,{size:13}),`Browse marketplace plugins`]})})}function dX({name:e,subtitle:t,description:n,enabled:r,onToggle:i,onRemove:a,readonly:o}){return(0,K.jsxs)(`div`,{className:`group flex items-center gap-3 px-3 py-2.5 rounded-lg transition-colors ${r?`hover:bg-gray-50`:`hover:bg-gray-50/50`}`,children:[(0,K.jsx)(GY,{checked:r,onCheckedChange:i,disabled:o,size:`sm`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,K.jsx)(`span`,{className:`text-[13px] truncate ${r?`text-gray-900 font-medium`:`text-gray-400`}`,children:e}),t&&(0,K.jsx)(`span`,{className:`text-[10px] shrink-0 ${r?`text-gray-400`:`text-gray-300`}`,children:t})]}),n&&(0,K.jsx)(`div`,{className:`text-[11px] mt-0.5 line-clamp-1 ${r?`text-gray-500`:`text-gray-400`}`,children:n})]}),a&&!o&&(0,K.jsx)(`button`,{onClick:a,className:`shrink-0 text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-all`,title:`remove`,children:(0,K.jsx)(tt,{size:13})})]})}function fX({open:e,value:t,onOpen:n,onCancel:r,onChange:i,onAdd:a}){return e?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&a(),e.key===`Escape`&&r()},placeholder:`name@marketplace`,className:`flex-1 min-w-0 border border-gray-300 rounded px-2.5 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white`}),(0,K.jsx)(`button`,{onClick:a,className:`px-2.5 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800 shrink-0`,children:`add`}),(0,K.jsx)(`button`,{onClick:r,className:`text-[11px] text-gray-400 hover:text-gray-600 shrink-0`,children:`cancel`})]}):(0,K.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(Re,{size:13}),`Add plugin by spec`]})}var pX={team:{icon:_e,borderClass:`border-l-violet-400`,badgeClass:`bg-violet-100 text-violet-700`,desc:`Workspace-wide, set by admin`},personal:{icon:ot,borderClass:`border-l-emerald-400`,badgeClass:`bg-emerald-100 text-emerald-700`,desc:`Your personal overrides`},project:{icon:de,borderClass:`border-l-gray-300`,badgeClass:`bg-gray-100 text-gray-500`,desc:`SDK reads from workdir`},local:{icon:oe,borderClass:`border-l-amber-300`,badgeClass:`bg-amber-100 text-amber-700`,desc:`Per-checkout .local.* overrides`}};function mX(e){return e.startsWith(`profile:`)?{icon:k,borderClass:`border-l-blue-400`,badgeClass:`bg-blue-100 text-blue-700`,desc:`Opt-in role-based config`}:pX[e]??pX.team}function hX(e){return e.id===`team`?{vault:`knowledge`,file:`.loopat/.claude/settings.json`}:e.id.startsWith(`profile:`)?{vault:`knowledge`,file:`.loopat/profiles/${e.id.slice(8)}/.claude/settings.json`}:e.id===`personal`?{vault:`personal`,file:`.loopat/.claude/settings.json`}:null}function gX(e){return e===`team`?1:e.startsWith(`profile:`)?2:e===`personal`?3:e===`project`?4:e===`local`?5:99}function _X(e){return e===`admin`?`bg-violet-100 text-violet-700`:e===`user`?`bg-gray-100 text-gray-600`:`bg-gray-100 text-gray-400`}function vX({disabled:e}){let t=Cg().currentUser?.role===`admin`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!0),[o,s]=_i(),c=o.get(`expand`)??`personal`,l=new Set(c.split(`,`).filter(Boolean)),u=e=>{let t=[...e].join(`,`);s(t?{expand:t}:{},{replace:!0})},[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(async()=>{a(!0),r(await cg()),a(!1)},[]);(0,_.useEffect)(()=>{p()},[p]);let m=e=>{let t=new Set(l);t.has(e)?t.delete(e):t.add(e),u(t)},h=n?.tiers??[],g=h.filter(e=>e.id.startsWith(`profile:`)),v=h.filter(e=>!e.id.startsWith(`profile:`)).sort((e,t)=>gX(e.id)-gX(t.id)),y={pluginCount:g.reduce((e,t)=>e+t.pluginCount,0),mcpServerCount:g.reduce((e,t)=>e+t.mcpServerCount,0),overrideCount:g.reduce((e,t)=>e+Object.keys(t.overrides).length,0)},b=[...v.filter(e=>gX(e.id)<3),...g.length>0?[{id:`__profiles__`,label:`Profiles (${g.length})`,tier:g[0],isGroup:!0}]:[],...v.filter(e=>gX(e.id)>=3)];return i&&!n?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-12 justify-center text-[13px] text-gray-400`,children:[(0,K.jsx)(Be,{size:13,className:`animate-spin`}),` loading tiers…`]}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white overflow-hidden transition-shadow hover:shadow-sm`,children:[(0,K.jsxs)(`div`,{className:`px-4 py-3 border-b border-gray-100 flex items-center gap-2.5`,children:[(0,K.jsx)(xe,{size:15,className:`text-gray-400`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:`Claude Config Composition`}),(0,K.jsxs)(`span`,{className:`text-[11px] text-gray-400 ml-2`,children:[h.filter(e=>e.exists).length,` active tiers · merged at loop spawn`]})]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:p,disabled:i,className:`p-1.5 rounded hover:bg-gray-100 text-gray-400 hover:text-gray-700 transition-colors`,children:(0,K.jsx)(Be,{size:13,className:i?`animate-spin`:``})})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-px bg-gray-100`,children:b.map(e=>{if(`isGroup`in e)return(0,K.jsx)(wX,{profiles:g,expanded:l,summary:y,open:d,onToggle:()=>f(!d)},`__profiles__`);let t=e,n=mX(t.id).icon,r=l.has(t.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(t.id),className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${r?`bg-gray-50`:``}`,children:[(0,K.jsx)(n,{size:14,className:`shrink-0 ${t.exists?`text-gray-500`:`text-gray-300`}`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-1.5`,children:(0,K.jsx)(`span`,{className:`text-[11px] font-medium truncate ${t.exists?`text-gray-700`:`text-gray-400`}`,children:t.label})}),(0,K.jsxs)(`div`,{className:`text-[10px] text-gray-400 mt-0.5 flex items-center gap-1.5`,children:[t.pluginCount>0&&(0,K.jsxs)(`span`,{children:[t.pluginCount,`p`]}),t.mcpServerCount>0&&(0,K.jsxs)(`span`,{children:[t.mcpServerCount,`m`]}),t.pluginCount===0&&t.mcpServerCount===0&&!t.exists&&(0,K.jsx)(`span`,{children:`—`}),Object.keys(t.overrides).length>0&&(0,K.jsxs)(`span`,{className:`text-amber-500`,children:[Object.keys(t.overrides).length,`↗`]})]})]}),r?(0,K.jsx)(F,{size:10,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:10,className:`text-gray-400 shrink-0`})]},t.id)})}),d&&g.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-gray-200 bg-gray-50/50 px-4 py-2 space-y-0.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider px-1 mb-1`,children:`Select a profile to expand`}),g.map(e=>{let t=l.has(e.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{m(e.id),f(!1),setTimeout(()=>{document.getElementById(`tier-${e.id}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},50)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded hover:bg-white/80 text-left transition-colors`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${t?`bg-blue-400`:`bg-gray-300`}`}),(0,K.jsx)(`span`,{className:`text-[12px] text-gray-700 flex-1`,children:e.label.replace(`Profile: `,``)}),(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-400 tabular-nums shrink-0`,children:[e.pluginCount>0&&(0,K.jsxs)(K.Fragment,{children:[e.pluginCount,`p `]}),e.mcpServerCount>0&&(0,K.jsxs)(K.Fragment,{children:[e.mcpServerCount,`m`]}),!e.pluginCount&&!e.mcpServerCount&&`—`]}),t&&(0,K.jsx)(F,{size:9,className:`text-blue-400 shrink-0`})]},e.id)}),t&&(0,K.jsx)(TX,{onCreated:e=>{f(!1),p().then(()=>{let t=`profile:${e}`;m(t),setTimeout(()=>{document.getElementById(`tier-${t}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},100)})}})]})]}),[...v,...g].map(n=>(0,K.jsx)(yX,{tier:n,isAdmin:!!t,isExpanded:l.has(n.id),disabled:e,onSaved:()=>p()},n.id))]})}function yX({tier:e,isAdmin:t,isExpanded:n,disabled:r,onSaved:i}){if(!n)return null;let a=mX(e.id),o=a.icon,s=e.editable&&(e.managedBy===`user`||e.managedBy===`admin`&&t),c=e.managedBy===`sdk`,l=e.id.startsWith(`profile:`),u=l?e.id.slice(8):``,d=!s&&e.managedBy===`admin`&&!t?`Admin access required`:null,[f,p]=(0,_.useState)({}),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(!1),x=zn(),S=(0,_.useRef)(null),C=hX(e);(0,_.useEffect)(()=>{p(e.settings?{...e.settings}:{}),v(null),b(!1)},[e.settings,e.id]);let w=async()=>{h(!0),v(null);let{_comment:t,...n}=f,r=await lg(e.id,n);if(h(!1),!r.ok){v(r.error??`save failed`);return}b(!0),setTimeout(()=>b(!1),2500),i()},T=Object.keys(e.overrides).length;return(0,K.jsxs)(`div`,{id:`tier-${e.id}`,className:`rounded-lg border overflow-hidden transition-shadow hover:shadow-sm ${s?`border-gray-200 bg-white`:`border-gray-200 bg-gray-50/50`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-gray-100 border-l-2 ${a.borderClass}`,children:[(0,K.jsx)(o,{size:16,className:`text-gray-500 shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[14px] font-semibold text-gray-900`,children:e.label}),(0,K.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full font-medium ${_X(e.managedBy)}`,children:e.managedBy===`admin`?`admin`:e.managedBy===`user`?`you`:`SDK`}),!e.exists&&!c&&(0,K.jsx)(`span`,{className:`text-[10px] text-amber-600 bg-amber-50 px-1.5 py-0.5 rounded-full`,children:`not created`}),d&&(0,K.jsx)(Te,{size:11,className:`text-amber-500 shrink-0`})]}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-0.5`,children:c?e.path:a.desc})]}),(0,K.jsxs)(`div`,{className:`hidden sm:flex items-center gap-1.5 shrink-0`,children:[(0,K.jsx)(bX,{label:`Plugins`,value:e.pluginCount}),(0,K.jsx)(bX,{label:`MCP`,value:e.mcpServerCount}),e.skillCount>0&&(0,K.jsx)(bX,{label:`Skills`,value:e.skillCount}),e.agentCount>0&&(0,K.jsx)(bX,{label:`Agents`,value:e.agentCount}),e.toolchainCount>0&&(0,K.jsx)(bX,{label:`Toolchain`,value:e.toolchainCount}),T>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-amber-600 bg-amber-50 px-1.5 py-0.5 rounded-full font-medium`,children:[T,` override`,T>1?`s`:``]})]}),C&&(0,K.jsxs)(zp,{children:[(0,K.jsx)(Bp,{asChild:!0,children:(0,K.jsx)(`button`,{onClick:()=>x(`/context/${C.vault}?file=${encodeURIComponent(C.file)}&edit=1`),className:`shrink-0 p-1.5 rounded-lg text-gray-300 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:(0,K.jsx)(oe,{size:13})})}),(0,K.jsxs)(Vp,{children:[`edit `,C.vault,`/`,C.file]})]})]}),(0,K.jsx)(`div`,{className:`px-4 py-4 space-y-5`,children:c?(0,K.jsxs)(`div`,{className:`rounded-lg bg-gray-50 px-3 py-2.5 text-[12px] text-gray-500`,children:[`SDK-managed — read directly from `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[11px]`,children:e.path}),`. Not editable here.`]}):(0,K.jsxs)(K.Fragment,{children:[C&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-gray-400`,children:[(0,K.jsxs)(`button`,{onClick:()=>x(`/context/${C.vault}?file=${encodeURIComponent(C.file)}&edit=1`),className:`inline-flex items-center gap-1 px-2 py-1 rounded hover:bg-gray-100 text-gray-500 hover:text-gray-700 transition-colors`,children:[(0,K.jsx)(oe,{size:11}),`edit settings.json`]}),e.claudeMd!==null&&(0,K.jsx)(`button`,{onClick:()=>x(`/context/${C.vault}?file=${encodeURIComponent(C.file.replace(`settings.json`,`CLAUDE.md`))}`),className:`inline-flex items-center gap-1 px-2 py-1 rounded hover:bg-gray-100 text-gray-500 hover:text-gray-700 transition-colors`,children:`view CLAUDE.md`}),(0,K.jsx)(`span`,{className:`text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:`text-gray-400 truncate font-mono text-[10px]`,children:[C.vault,`/`,C.file]})]}),T>0&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50/50 px-3 py-2`,children:[(0,K.jsx)(`div`,{className:`text-[11px] font-medium text-amber-700 mb-1.5`,children:`Overrides from lower tiers`}),(0,K.jsxs)(`div`,{className:`space-y-0.5`,children:[Object.entries(e.overrides).slice(0,8).map(([e,t])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-amber-700/80`,children:[(0,K.jsx)(R,{size:10,className:`text-amber-400 shrink-0`}),(0,K.jsx)(`code`,{className:`text-[10px] bg-amber-100/50 px-1 rounded`,children:e}),(0,K.jsxs)(`span`,{className:`text-amber-500`,children:[`shadows `,t.overrides]})]},e)),T>8&&(0,K.jsxs)(`div`,{className:`text-[10px] text-amber-400 ml-5`,children:[`+`,T-8,` more`]})]})]}),(0,K.jsx)(xX,{title:`Plugins`,count:e.pluginCount,defaultOpen:e.pluginCount>0,children:!s&&e.pluginCount===0?(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-2`,children:`No plugins configured in this tier`}):(0,K.jsx)(lX,{enabledPlugins:f?.enabledPlugins??{},readonly:!s||r,focusMarketplaceRef:S,onChange:e=>p(t=>t?{...t,enabledPlugins:e}:{enabledPlugins:e})})}),(0,K.jsx)(xX,{title:`MCP Servers`,count:e.mcpServerCount,defaultOpen:e.mcpServerCount>0,children:(0,K.jsx)(oX,{servers:aX(f),readonly:!s||r,onChange:e=>p(t=>t?{...t,mcpServers:e}:{mcpServers:e})})}),(0,K.jsx)(xX,{title:`Marketplaces`,count:e.marketplaceCount,defaultOpen:e.marketplaceCount>0||s,children:(0,K.jsx)(CX,{marketplaces:f?.extraKnownMarketplaces??{},readonly:!s||r,onChange:e=>p(t=>t?{...t,extraKnownMarketplaces:e}:{extraKnownMarketplaces:e}),focusRef:S})}),e.hookCount>0&&(0,K.jsx)(xX,{title:`Hooks`,count:e.hookCount,defaultOpen:!1,children:(0,K.jsxs)(`div`,{className:`text-[12px] text-gray-500`,children:[Object.keys(f?.hooks??{}).length,` hook groups configured.`]})}),d&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-50 text-[12px] text-amber-700`,children:[(0,K.jsx)(Te,{size:12}),d]}),l&&t&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-gray-100`,children:[(0,K.jsx)(`button`,{onClick:async()=>{if(!confirm(`Delete profile "${u}"? This removes all its .claude/ contents permanently.`))return;let e=await _g(u);if(!e.ok){v(e.error??`delete failed`);return}i()},className:`px-3 h-7 rounded-lg text-[11px] text-red-500 hover:bg-red-50 hover:text-red-600 transition-colors`,children:`Delete profile`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[g&&(0,K.jsx)(`span`,{className:`text-[12px] text-red-600`,children:g}),y&&(0,K.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:13}),` saved`]}),(0,K.jsx)(`button`,{onClick:w,disabled:m||r,className:`px-4 h-8 rounded-lg bg-gray-900 text-white text-xs font-medium hover:bg-gray-800 disabled:opacity-50 transition-colors`,children:m?`Saving…`:`Save`})]})]}),s&&!l&&(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-3 border-t border-gray-100`,children:[g&&(0,K.jsx)(`span`,{className:`text-[12px] text-red-600`,children:g}),y&&(0,K.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:13}),` saved`]}),(0,K.jsx)(`button`,{onClick:w,disabled:m||r,className:`px-4 h-8 rounded-lg bg-gray-900 text-white text-xs font-medium hover:bg-gray-800 disabled:opacity-50 transition-colors`,children:m?`Saving…`:`Save`})]})]})})]})}function bX({label:e,value:t}){return(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-500 bg-gray-100 px-1.5 py-0.5 rounded-full font-medium tabular-nums`,children:[t,` `,(0,K.jsx)(`span`,{className:`text-gray-400`,children:e})]})}function xX({title:e,count:t,defaultOpen:n,children:r}){let[i,a]=(0,_.useState)(n);return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-1.5 mb-2 hover:text-gray-900 transition-colors`,children:[i?(0,K.jsx)(F,{size:12,className:`text-gray-400`}):(0,K.jsx)(I,{size:12,className:`text-gray-400`}),(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:e}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 tabular-nums`,children:t})]}),i&&(0,K.jsx)(`div`,{className:`ml-3 pl-3 border-l-2 border-gray-100`,children:r})]})}function SX(e){try{let t=e.trim().replace(/\.git$/,``).split(/[?#]/)[0].replace(/\/$/,``).split(`/`);return t[t.length-1]||``}catch{return``}}function CX({marketplaces:e,readonly:t,onChange:n,focusRef:r}){let[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(`git`),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(`main`),[m,h]=(0,_.useState)(!1),g=(0,_.useRef)(null);(0,_.useEffect)(()=>{r&&(r.current=()=>{a(!0),setTimeout(()=>g.current?.focus(),50)})},[r]);let v=Object.entries(e),y=()=>{let t=o.trim();if(!t||!u.trim())return;let r;switch(c){case`git`:r={source:`git`,url:u.trim()};break;case`github`:r={source:`github`,repo:u.trim()};break;case`directory`:r={source:`directory`,path:u.trim()};break}c!==`directory`&&f.trim()&&f.trim()!==`main`&&(r.branch=f.trim()),n({...e,[t]:{source:r}}),s(``),d(``),p(`main`),h(!1),a(!1)},b=t=>{let{[t]:r,...i}=e;n(i)};return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[v.length===0&&!i&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-2`,children:`No additional marketplaces. The built-in marketplace is always available.`}),v.map(([e,n])=>{let r=n?.source??{},i=r?.branch,a=r.source===`git`?`git ${r.url??``}${i?` @${i}`:``}`:r.source===`github`?`github:${r.repo??``}${i?` @${i}`:``}`:r.source===`directory`?`dir: ${r.path??``}`:JSON.stringify(r);return(0,K.jsxs)(`div`,{className:`group flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-gray-50 transition-colors`,children:[(0,K.jsx)(Ze,{size:13,className:`text-gray-400 shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-[12px] font-medium text-gray-800 truncate`,children:e}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 font-mono truncate`,children:a})]}),!t&&(0,K.jsx)(`button`,{onClick:()=>b(e),className:`shrink-0 text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-all`,title:`remove`,children:(0,K.jsx)(tt,{size:13})})]},e)}),i&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-gray-50/50 p-3 space-y-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{ref:g,autoFocus:!0,value:o,onChange:e=>{s(e.target.value),h(!0)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&y(),e.key===`Escape`&&(a(!1),s(``),h(!1))},placeholder:`marketplace name`,className:`flex-1 min-w-0 border border-gray-300 rounded px-2.5 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white`}),(0,K.jsxs)(`select`,{value:c,onChange:e=>{l(e.target.value),e.target.value===`directory`&&h(!0)},className:`w-24 shrink-0 border border-gray-300 rounded px-2 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white`,children:[(0,K.jsx)(`option`,{value:`git`,children:`git URL`}),(0,K.jsx)(`option`,{value:`github`,children:`github repo`}),(0,K.jsx)(`option`,{value:`directory`,children:`directory`})]})]}),(0,K.jsx)(`input`,{value:u,onChange:e=>{if(d(e.target.value),(c===`git`||c===`github`)&&!m){let t=SX(e.target.value);t&&s(t)}},placeholder:c===`git`?`https://...`:c===`github`?`owner/repo`:`/path/to/marketplace`,className:`ip text-[12px] w-full font-mono`}),c!==`directory`&&(0,K.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:`branch (default: main)`,className:`ip text-[12px] w-full font-mono`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:y,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>{a(!1),s(``),d(``)},className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}),!t&&(0,K.jsxs)(`button`,{onClick:()=>a(!0),className:`flex items-center gap-1.5 px-3 py-2 text-[12px] text-gray-400 hover:text-gray-700 hover:bg-gray-50 rounded-lg w-full transition-colors`,children:[(0,K.jsx)(Re,{size:13}),`Add marketplace source`]})]})}function wX({profiles:e,expanded:t,summary:n,open:r,onToggle:i}){return(0,K.jsxs)(`button`,{type:`button`,onClick:i,className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${e.some(e=>t.has(e.id))||r?`bg-gray-50`:``}`,children:[(0,K.jsx)(k,{size:14,className:`text-blue-400 shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`flex items-center gap-1.5`,children:(0,K.jsxs)(`span`,{className:`text-[11px] font-medium text-gray-700 truncate`,children:[`Profiles (`,e.length,`)`]})}),(0,K.jsxs)(`div`,{className:`text-[10px] text-gray-400 mt-0.5 flex items-center gap-1.5`,children:[n.pluginCount>0&&(0,K.jsxs)(`span`,{children:[n.pluginCount,`p`]}),n.mcpServerCount>0&&(0,K.jsxs)(`span`,{children:[n.mcpServerCount,`m`]}),n.pluginCount===0&&n.mcpServerCount===0&&(0,K.jsx)(`span`,{children:`—`}),n.overrideCount>0&&(0,K.jsxs)(`span`,{className:`text-amber-500`,children:[n.overrideCount,`↗`]})]})]}),r?(0,K.jsx)(F,{size:10,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:10,className:`text-gray-400 shrink-0`})]})}function TX({onCreated:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(null),s=async()=>{let t=r.trim();if(!t)return;o(null);let a=await gg(t);if(!a.ok){o(a.error??`create failed`);return}i(``),n(!1),e(t)};return t?(0,K.jsxs)(`div`,{className:`px-3 py-1.5 space-y-1.5`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>{i(e.target.value),o(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&(n(!1),i(``))},placeholder:`profile name`,className:`flex-1 min-w-0 border border-gray-300 rounded px-2.5 py-1.5 text-[12px] outline-none focus:border-gray-900 bg-white w-full`}),a&&(0,K.jsx)(`div`,{className:`text-[11px] text-red-600`,children:a}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Create`}),(0,K.jsx)(`button`,{onClick:()=>{n(!1),i(``),o(null)},className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-[11px] text-gray-400 hover:text-gray-700 hover:bg-white/80 rounded w-full transition-colors`,children:[(0,K.jsx)(Re,{size:12}),`Create profile`]})}function EX(e,t){let n=e.slice(0,t).split(/\r\n|\n|\r/g);return[n.length,n.pop().length+1]}function DX(e,t,n){let r=e.split(/\r\n|\n|\r/g),i=``,a=(Math.log10(t+1)|0)+1;for(let e=t-1;e<=t+1;e++){let o=r[e-1];o&&(i+=e.toString().padEnd(a,` `),i+=`: `,i+=o,i+=`
|
|
135
135
|
`,e===t&&(i+=` `.repeat(a+n+2),i+=`^
|
|
136
|
-
`))}return i}var
|
|
137
|
-
`,t);return e[r-1]===`\r`&&r--,r<=n?r:-1}function
|
|
136
|
+
`))}return i}var OX=class extends Error{line;column;codeblock;constructor(e,t){let[n,r]=EX(t.toml,t.ptr),i=DX(t.toml,n,r);super(`Invalid TOML document: ${e}\n\n${i}`,t),this.line=n,this.column=r,this.codeblock=i}};function kX(e,t){let n=0;for(;e[t-++n]===`\\`;);return--n&&n%2}function AX(e,t=0,n=e.length){let r=e.indexOf(`
|
|
137
|
+
`,t);return e[r-1]===`\r`&&r--,r<=n?r:-1}function jX(e,t){for(let n=t;n<e.length;n++){let r=e[n];if(r===`
|
|
138
138
|
`)return n;if(r===`\r`&&e[n+1]===`
|
|
139
|
-
`)return n+1;if(r<` `&&r!==` `||r===``)throw new
|
|
139
|
+
`)return n+1;if(r<` `&&r!==` `||r===``)throw new OX(`control characters are not allowed in comments`,{toml:e,ptr:t})}return e.length}function MX(e,t,n,r){let i;for(;;){for(;(i=e[t])===` `||i===` `||!n&&(i===`
|
|
140
140
|
`||i===`\r`&&e[t+1]===`
|
|
141
|
-
`);)t++;if(r||i!==`#`)break;t=
|
|
141
|
+
`);)t++;if(r||i!==`#`)break;t=jX(e,t)}return t}function NX(e,t,n,r,i=!1){if(!r)return t=AX(e,t),t<0?e.length:t;for(let a=t;a<e.length;a++){let t=e[a];if(t===`#`)a=AX(e,a);else if(t===n)return a+1;else if(t===r||i&&(t===`
|
|
142
142
|
`||t===`\r`&&e[a+1]===`
|
|
143
|
-
`))return a}throw new
|
|
144
|
-
`,f:`\f`,r:`\r`,e:`\x1B`,'"':`"`,"\\":`\\`};function
|
|
143
|
+
`))return a}throw new OX(`cannot find end of structure`,{toml:e,ptr:t})}function PX(e,t){let n=e[t],r=n===e[t+1]&&e[t+1]===e[t+2]?e.slice(t,t+3):n;t+=r.length-1;do t=e.indexOf(r,++t);while(t>-1&&n!==`'`&&kX(e,t));return t>-1&&(t+=r.length,r.length>1&&(e[t]===n&&t++,e[t]===n&&t++)),t}var FX=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i,IX=class e extends Date{#e=!1;#t=!1;#n=null;constructor(e){let t=!0,n=!0,r=`Z`;if(typeof e==`string`){let i=e.match(FX);i?(i[1]||(t=!1,e=`0000-01-01T${e}`),n=!!i[2],n&&e[10]===` `&&(e=e.replace(` `,`T`)),i[2]&&+i[2]>23?e=``:(r=i[3]||null,e=e.toUpperCase(),!r&&n&&(e+=`Z`))):e=``}super(e),isNaN(this.getTime())||(this.#e=t,this.#t=n,this.#n=r)}isDateTime(){return this.#e&&this.#t}isLocal(){return!this.#e||!this.#t||!this.#n}isDate(){return this.#e&&!this.#t}isTime(){return this.#t&&!this.#e}isValid(){return this.#e||this.#t}toISOString(){let e=super.toISOString();if(this.isDate())return e.slice(0,10);if(this.isTime())return e.slice(11,23);if(this.#n===null)return e.slice(0,-1);if(this.#n===`Z`)return e;let t=this.#n.slice(1,3)*60+ +this.#n.slice(4,6);return t=this.#n[0]===`-`?t:-t,new Date(this.getTime()-t*6e4).toISOString().slice(0,-1)+this.#n}static wrapAsOffsetDateTime(t,n=`Z`){let r=new e(t);return r.#n=n,r}static wrapAsLocalDateTime(t){let n=new e(t);return n.#n=null,n}static wrapAsLocalDate(t){let n=new e(t);return n.#t=!1,n.#n=null,n}static wrapAsLocalTime(t){let n=new e(t);return n.#e=!1,n.#n=null,n}},LX=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,RX=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,zX=/^[+-]?0[0-9_]/,BX=/^[0-9a-f]{2,8}$/i,VX={b:`\b`,t:` `,n:`
|
|
144
|
+
`,f:`\f`,r:`\r`,e:`\x1B`,'"':`"`,"\\":`\\`};function HX(e,t=0,n=e.length){let r=e[t]===`'`,i=e[t++]===e[t]&&e[t]===e[t+1];i&&(n-=2,e[t+=2]===`\r`&&t++,e[t]===`
|
|
145
145
|
`&&t++);let a=0,o,s=``,c=t;for(;t<n-1;){let n=e[t++];if(n===`
|
|
146
146
|
`||n===`\r`&&e[t]===`
|
|
147
|
-
`){if(!i)throw new
|
|
148
|
-
`||n===` `||n===` `||n===`\r`)){if(t=
|
|
149
|
-
`&&e[t]!==`\r`)throw new
|
|
150
|
-
`&&e[o]!==`\r`)throw new
|
|
151
|
-
`&&o!==`\r`){let o,s=i,c=!1,[l,u]=
|
|
152
|
-
`&&a!==`\r`){let a=
|
|
153
|
-
`&&e[s]!==`\r`)throw new
|
|
154
|
-
`}[[${t}]]\n`,i+=
|
|
155
|
-
`)+
|
|
156
|
-
`)+
|
|
157
|
-
`}}return e&&(a||!o)&&(a=a?`[${e}]\n${a}`:`[${e}]`),a&&o?`${a}\n${o}`:a||o}function
|
|
147
|
+
`){if(!i)throw new OX(`newlines are not allowed in strings`,{toml:e,ptr:t-1})}else if(n<` `&&n!==` `||n===``)throw new OX(`control characters are not allowed in strings`,{toml:e,ptr:t-1});if(o){if(o=!1,n===`x`||n===`u`||n===`U`){let r=e.slice(t,t+=n===`x`?2:n===`u`?4:8);if(!BX.test(r))throw new OX(`invalid unicode escape`,{toml:e,ptr:a});try{s+=String.fromCodePoint(parseInt(r,16))}catch{throw new OX(`invalid unicode escape`,{toml:e,ptr:a})}}else if(i&&(n===`
|
|
148
|
+
`||n===` `||n===` `||n===`\r`)){if(t=MX(e,t-1,!0),e[t]!==`
|
|
149
|
+
`&&e[t]!==`\r`)throw new OX(`invalid escape: only line-ending whitespace may be escaped`,{toml:e,ptr:a});t=MX(e,t)}else if(n in VX)s+=VX[n];else throw new OX(`unrecognized escape sequence`,{toml:e,ptr:a});c=t}else !r&&n===`\\`&&(a=t-1,o=!0,s+=e.slice(c,a))}return s+e.slice(c,n-1)}function UX(e,t,n,r){if(e===`true`)return!0;if(e===`false`)return!1;if(e===`-inf`)return-1/0;if(e===`inf`||e===`+inf`)return 1/0;if(e===`nan`||e===`+nan`||e===`-nan`)return NaN;if(e===`-0`)return r?0n:0;let i=LX.test(e);if(i||RX.test(e)){if(zX.test(e))throw new OX(`leading zeroes are not allowed`,{toml:t,ptr:n});e=e.replace(/_/g,``);let a=+e;if(isNaN(a))throw new OX(`invalid number`,{toml:t,ptr:n});if(i){if((i=!Number.isSafeInteger(a))&&!r)throw new OX(`integer value cannot be represented losslessly`,{toml:t,ptr:n});(i||r===!0)&&(a=BigInt(e))}return a}let a=new IX(e);if(!a.isValid())throw new OX(`invalid value`,{toml:t,ptr:n});return a}function WX(e,t,n){let r=e.slice(t,n),i=r.indexOf(`#`);return i>-1&&(jX(e,i),r=r.slice(0,i)),[r.trimEnd(),i]}function GX(e,t,n,r,i){if(r===0)throw new OX(`document contains excessively nested structures. aborting.`,{toml:e,ptr:t});let a=e[t];if(a===`[`||a===`{`){let[o,s]=a===`[`?YX(e,t,r,i):JX(e,t,r,i);if(n){if(s=MX(e,s),e[s]===`,`)s++;else if(e[s]!==n)throw new OX(`expected comma or end of structure`,{toml:e,ptr:s})}return[o,s]}let o;if(a===`"`||a===`'`){o=PX(e,t);let r=HX(e,t,o);if(n){if(o=MX(e,o),e[o]&&e[o]!==`,`&&e[o]!==n&&e[o]!==`
|
|
150
|
+
`&&e[o]!==`\r`)throw new OX(`unexpected character encountered`,{toml:e,ptr:o});o+=+(e[o]===`,`)}return[r,o]}o=NX(e,t,`,`,n);let s=WX(e,t,o-+(e[o-1]===`,`));if(!s[0])throw new OX(`incomplete key-value declaration: no value specified`,{toml:e,ptr:t});return n&&s[1]>-1&&(o=MX(e,t+s[1]),o+=+(e[o]===`,`)),[UX(s[0],e,t,i),o]}var KX=/^[a-zA-Z0-9-_]+[ \t]*$/;function qX(e,t,n=`=`){let r=t-1,i=[],a=e.indexOf(n,t);if(a<0)throw new OX(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});do{let o=e[t=++r];if(o!==` `&&o!==` `)if(o===`"`||o===`'`){if(o===e[t+1]&&o===e[t+2])throw new OX(`multiline strings are not allowed in keys`,{toml:e,ptr:t});let s=PX(e,t);if(s<0)throw new OX(`unfinished string encountered`,{toml:e,ptr:t});r=e.indexOf(`.`,s);let c=e.slice(s,r<0||r>a?a:r),l=AX(c);if(l>-1)throw new OX(`newlines are not allowed in keys`,{toml:e,ptr:t+r+l});if(c.trimStart())throw new OX(`found extra tokens after the string part`,{toml:e,ptr:s});if(a<s&&(a=e.indexOf(n,s),a<0))throw new OX(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});i.push(HX(e,t,s))}else{r=e.indexOf(`.`,t);let n=e.slice(t,r<0||r>a?a:r);if(!KX.test(n))throw new OX(`only letter, numbers, dashes and underscores are allowed in keys`,{toml:e,ptr:t});i.push(n.trimEnd())}}while(r+1&&r<a);return[i,MX(e,a+1,!0,!0)]}function JX(e,t,n,r){let i={},a=new Set,o;for(t++;(o=e[t++])!==`}`&&o;)if(o===`,`)throw new OX(`expected value, found comma`,{toml:e,ptr:t-1});else if(o===`#`)t=jX(e,t);else if(o!==` `&&o!==` `&&o!==`
|
|
151
|
+
`&&o!==`\r`){let o,s=i,c=!1,[l,u]=qX(e,t-1);for(let n=0;n<l.length;n++){if(n&&(s=c?s[o]:s[o]={}),o=l[n],(c=Object.hasOwn(s,o))&&(typeof s[o]!=`object`||a.has(s[o])))throw new OX(`trying to redefine an already defined value`,{toml:e,ptr:t});!c&&o===`__proto__`&&Object.defineProperty(s,o,{enumerable:!0,configurable:!0,writable:!0})}if(c)throw new OX(`trying to redefine an already defined value`,{toml:e,ptr:t});let[d,f]=GX(e,u,`}`,n-1,r);a.add(d),s[o]=d,t=f}if(!o)throw new OX(`unfinished table encountered`,{toml:e,ptr:t});return[i,t]}function YX(e,t,n,r){let i=[],a;for(t++;(a=e[t++])!==`]`&&a;)if(a===`,`)throw new OX(`expected value, found comma`,{toml:e,ptr:t-1});else if(a===`#`)t=jX(e,t);else if(a!==` `&&a!==` `&&a!==`
|
|
152
|
+
`&&a!==`\r`){let a=GX(e,t-1,`]`,n-1,r);i.push(a[0]),t=a[1]}if(!a)throw new OX(`unfinished array encountered`,{toml:e,ptr:t});return[i,t]}function XX(e,t,n,r){let i=t,a=n,o,s=!1,c;for(let t=0;t<e.length;t++){if(t){if(i=s?i[o]:i[o]={},a=(c=a[o]).c,r===0&&(c.t===1||c.t===2))return null;if(c.t===2){let e=i.length-1;i=i[e],a=a[e].c}}if(o=e[t],(s=Object.hasOwn(i,o))&&a[o]?.t===0&&a[o]?.d)return null;s||(o===`__proto__`&&(Object.defineProperty(i,o,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(a,o,{enumerable:!0,configurable:!0,writable:!0})),a[o]={t:t<e.length-1&&r===2?3:r,d:!1,i:0,c:{}})}if(c=a[o],c.t!==r&&!(r===1&&c.t===3)||(r===2&&(c.d||(c.d=!0,i[o]=[]),i[o].push(i={}),c.c[c.i++]=c={t:1,d:!1,i:0,c:{}}),c.d))return null;if(c.d=!0,r===1)i=s?i[o]:i[o]={};else if(r===0&&s)return null;return[o,i,c.c]}function ZX(e,{maxDepth:t=1e3,integersAsBigInt:n}={}){let r={},i={},a=r,o=i;for(let s=MX(e,0);s<e.length;){if(e[s]===`[`){let t=e[++s]===`[`,n=qX(e,s+=+t,`]`);if(t){if(e[n[1]-1]!==`]`)throw new OX(`expected end of table declaration`,{toml:e,ptr:n[1]-1});n[1]++}let c=XX(n[0],r,i,t?2:1);if(!c)throw new OX(`trying to redefine an already defined table or value`,{toml:e,ptr:s});o=c[2],a=c[1],s=n[1]}else{let r=qX(e,s),i=XX(r[0],a,o,0);if(!i)throw new OX(`trying to redefine an already defined table or value`,{toml:e,ptr:s});let c=GX(e,r[1],void 0,t,n);i[1][i[0]]=c[0],s=c[1]}if(s=MX(e,s,!0),e[s]&&e[s]!==`
|
|
153
|
+
`&&e[s]!==`\r`)throw new OX(`each key-value declaration must be followed by an end-of-line`,{toml:e,ptr:s});s=MX(e,s)}return r}var QX=/^[a-z0-9-_]+$/i;function $X(e){let t=typeof e;if(t===`object`){if(Array.isArray(e))return`array`;if(e instanceof Date)return`date`}return t}function eZ(e){for(let t=0;t<e.length;t++)if($X(e[t])!==`object`)return!1;return e.length!=0}function tZ(e){return JSON.stringify(e).replace(/\x7f/g,`\\u007f`)}function nZ(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);if(t===`number`)return isNaN(e)?`nan`:e===1/0?`inf`:e===-1/0?`-inf`:r&&Number.isInteger(e)?e.toFixed(1):e.toString();if(t===`bigint`||t===`boolean`)return e.toString();if(t===`string`)return tZ(e);if(t===`date`){if(isNaN(e.getTime()))throw TypeError(`cannot serialize invalid date`);return e.toISOString()}if(t===`object`)return rZ(e,n,r);if(t===`array`)return iZ(e,n,r)}function rZ(e,t,n){let r=Object.keys(e);if(r.length===0)return`{}`;let i=`{ `;for(let a=0;a<r.length;a++){let o=r[a];a&&(i+=`, `),i+=QX.test(o)?o:tZ(o),i+=` = `,i+=nZ(e[o],$X(e[o]),t-1,n)}return i+` }`}function iZ(e,t,n){if(e.length===0)return`[]`;let r=`[ `;for(let i=0;i<e.length;i++){if(i&&(r+=`, `),e[i]===null||e[i]===void 0)throw TypeError(`arrays cannot contain null or undefined values`);r+=nZ(e[i],$X(e[i]),t-1,n)}return r+` ]`}function aZ(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let i=``;for(let a=0;a<e.length;a++)i+=`${i&&`
|
|
154
|
+
`}[[${t}]]\n`,i+=oZ(0,e[a],t,n,r);return i}function oZ(e,t,n,r,i){if(r===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let a=``,o=``,s=Object.keys(t);for(let e=0;e<s.length;e++){let c=s[e];if(t[c]!==null&&t[c]!==void 0){let e=$X(t[c]);if(e===`symbol`||e===`function`)throw TypeError(`cannot serialize values of type '${e}'`);let s=QX.test(c)?c:tZ(c);if(e===`array`&&eZ(t[c]))o+=(o&&`
|
|
155
|
+
`)+aZ(t[c],n?`${n}.${s}`:s,r-1,i);else if(e===`object`){let e=n?`${n}.${s}`:s;o+=(o&&`
|
|
156
|
+
`)+oZ(e,t[c],e,r-1,i)}else a+=s,a+=` = `,a+=nZ(t[c],e,r,i),a+=`
|
|
157
|
+
`}}return e&&(a||!o)&&(a=a?`[${e}]\n${a}`:`[${e}]`),a&&o?`${a}\n${o}`:a||o}function sZ(e,{maxDepth:t=1e3,numbersAsFloat:n=!1}={}){if($X(e)!==`object`)throw TypeError(`stringify can only be called with an object`);let r=oZ(0,e,``,t,n);return r[r.length-1]===`
|
|
158
158
|
`?r:r+`
|
|
159
|
-
`}var sZ={team:{icon:_e,borderClass:`border-l-violet-400`,badgeClass:`bg-violet-100 text-violet-700`,desc:`Workspace-wide, set by admin`},personal:{icon:ot,borderClass:`border-l-emerald-400`,badgeClass:`bg-emerald-100 text-emerald-700`,desc:`Your personal overrides`},project:{icon:de,borderClass:`border-l-gray-300`,badgeClass:`bg-gray-100 text-gray-500`,desc:`SDK reads from workdir`},local:{icon:oe,borderClass:`border-l-amber-300`,badgeClass:`bg-amber-100 text-amber-700`,desc:`Per-checkout .local.* overrides`}};function cZ(e){return e.startsWith(`profile:`)?{icon:k,borderClass:`border-l-blue-400`,badgeClass:`bg-blue-100 text-blue-700`,desc:`Opt-in role-based config`}:sZ[e]??sZ.team}function lZ(e){return e===`team`?1:e.startsWith(`profile:`)?2:e===`personal`?3:e===`project`?4:e===`local`?5:99}function uZ(e){return e===`admin`?`bg-violet-100 text-violet-700`:e===`user`?`bg-gray-100 text-gray-600`:`bg-gray-100 text-gray-400`}function dZ(e){return e.id===`team`?{vault:`knowledge`,file:`.loopat/.claude/mise.toml`}:e.id.startsWith(`profile:`)?{vault:`knowledge`,file:`.loopat/profiles/${e.id.slice(8)}/.claude/mise.toml`}:e.id===`personal`?{vault:`personal`,file:`.loopat/.claude/mise.toml`}:null}var fZ=`w-full px-2.5 py-1.5 border border-gray-300 rounded text-[12px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900 transition-colors font-mono`,pZ=`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono`;function mZ(e){let t={};try{t=XX(e)}catch{}let n={};if(t.tools&&typeof t.tools==`object`)for(let[e,r]of Object.entries(t.tools))e.startsWith(`_`)||(typeof r==`string`?n[e]={version:r}:r&&typeof r==`object`&&(n[e]={version:typeof r.version==`string`?r.version:String(r.version??``),backend:typeof r.backend==`string`?r.backend:void 0}));let r={},i=``,a=[];if(t.env&&typeof t.env==`object`)for(let[e,n]of Object.entries(t.env)){if(e===`_.file`&&typeof n==`string`){i=n;continue}if(e===`_.path`&&Array.isArray(n)){a=n.map(String);continue}typeof n==`string`?r[e]=n:Array.isArray(n)?r[e]=n.join(`:`):n!=null&&(r[e]=String(n))}let o={};if(t.tasks&&typeof t.tasks==`object`)for(let[e,n]of Object.entries(t.tasks)){if(!n||typeof n!=`object`)continue;let t=n?.run_windows;o[e]={description:typeof n.description==`string`?n.description:void 0,run:typeof n.run==`string`?n.run:void 0,dir:typeof n.dir==`string`?n.dir:void 0,depends:Array.isArray(n.depends)?n.depends.map(String):void 0,waitFor:Array.isArray(n.wait_for)?n.wait_for.map(String):void 0,sources:Array.isArray(n.sources)?n.sources.map(String):void 0,outputs:Array.isArray(n.outputs)?n.outputs.map(String):void 0,hide:typeof n.hide==`boolean`?n.hide:void 0,raw:typeof n.raw==`boolean`?n.raw:void 0,env:n.env&&typeof n.env==`object`?Object.fromEntries(Object.entries(n.env).map(([e,t])=>[e,String(t)])):void 0,runWindows:typeof t==`string`?t:void 0}}let s={};if(t.alias&&typeof t.alias==`object`){for(let[e,n]of Object.entries(t.alias))if(n&&typeof n==`object`){s[e]={};for(let[t,r]of Object.entries(n))s[e][t]=String(r)}}let c={};if(t.settings&&typeof t.settings==`object`)for(let[e,n]of Object.entries(t.settings))e.startsWith(`_`)||(c[e]=n);let l={};if(t.plugins&&typeof t.plugins==`object`)for(let[e,n]of Object.entries(t.plugins))l[e]=n&&typeof n==`object`&&typeof n.url==`string`?n.url:typeof n==`string`?n:``;let u={};if(t.hooks&&typeof t.hooks==`object`)for(let[e,n]of Object.entries(t.hooks))typeof n==`string`&&(u[e]=n);return{tools:n,env:r,envFile:i,envPath:a,tasks:o,alias:s,settings:c,plugins:l,hooks:u}}function hZ(e){let t={};if(Object.keys(e.tools).length>0){t.tools={};for(let[n,r]of Object.entries(e.tools))r.backend?t.tools[n]={version:r.version,backend:r.backend}:t.tools[n]=r.version}if((Object.keys(e.env).length>0||e.envFile||e.envPath.length>0)&&(t.env={},e.envFile&&(t.env[`_.file`]=e.envFile),e.envPath.length>0&&(t.env[`_.path`]=e.envPath),Object.assign(t.env,e.env)),Object.keys(e.tasks).length>0){t.tasks={};for(let[n,r]of Object.entries(e.tasks)){let e={};r.description&&(e.description=r.description),r.run&&(e.run=r.run),r.dir&&(e.dir=r.dir),r.depends&&r.depends.length>0&&(e.depends=r.depends),r.waitFor&&r.waitFor.length>0&&(e.wait_for=r.waitFor),r.sources&&r.sources.length>0&&(e.sources=r.sources),r.outputs&&r.outputs.length>0&&(e.outputs=r.outputs),r.hide!==void 0&&(e.hide=r.hide),r.raw!==void 0&&(e.raw=r.raw),r.env&&Object.keys(r.env).length>0&&(e.env=r.env),r.runWindows&&(e.run_windows=r.runWindows),t.tasks[n]=e}}if(Object.keys(e.alias).length>0&&(t.alias=e.alias),Object.keys(e.settings).length>0&&(t.settings=e.settings),Object.keys(e.plugins).length>0){t.plugins={};for(let[n,r]of Object.entries(e.plugins))t.plugins[n]={url:r}}return Object.keys(e.hooks).length>0&&(t.hooks=e.hooks),Object.keys(t).length===0?``:oZ(t)}var gZ=[{id:`tools`,label:`Tools`,desc:`Tool versions (node, python, rust, …)`},{id:`env`,label:`Env`,desc:`Environment variables`},{id:`tasks`,label:`Tasks`,desc:`Build / run tasks`},{id:`alias`,label:`Alias`,desc:`Tool version aliases`},{id:`settings`,label:`Settings`,desc:`mise behavior flags`},{id:`plugins`,label:`Plugins`,desc:`asdf plugin sources`},{id:`hooks`,label:`Hooks`,desc:`Lifecycle hook commands`},{id:`raw`,label:`Raw TOML`,desc:`Direct TOML editing`}];function _Z({disabled:e}){let t=Cg().currentUser?.role===`admin`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!0),[o,s]=_i(),c=o.get(`expand`)??`personal`,l=new Set(c.split(`,`).filter(Boolean)),u=e=>{let t=[...e].join(`,`);s(t?{expand:t}:{},{replace:!0})},[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(async()=>{a(!0),r(await cg()),a(!1)},[]);(0,_.useEffect)(()=>{p()},[p]);let m=e=>{let t=new Set(l);t.has(e)?t.delete(e):t.add(e),u(t)},h=n?.tiers??[],g=h.filter(e=>e.id.startsWith(`profile:`)),v=h.filter(e=>!e.id.startsWith(`profile:`)).sort((e,t)=>lZ(e.id)-lZ(t.id)),y=g.reduce((e,t)=>e+t.toolchainCount,0),b=[...v.filter(e=>lZ(e.id)<3),...g.length>0?[{id:`__profiles__`,label:`Profiles (${g.length})`,tier:g[0],isGroup:!0}]:[],...v.filter(e=>lZ(e.id)>=3)];return i&&!n?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-12 justify-center text-[13px] text-gray-400`,children:[(0,K.jsx)(Be,{size:13,className:`animate-spin`}),` loading tiers…`]}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white overflow-hidden transition-shadow hover:shadow-sm`,children:[(0,K.jsxs)(`div`,{className:`px-4 py-3 border-b border-gray-100 flex items-center gap-2.5`,children:[(0,K.jsx)(et,{size:15,className:`text-gray-400`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:`Mise Config`}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-2`,children:`mise.toml per tier — tools, env, tasks, aliases, settings, plugins, hooks`})]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`a`,{href:`https://mise.jdx.dev/configuration.html`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 px-2 py-1 rounded text-[10px] text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:[(0,K.jsx)(re,{size:10}),` docs`]}),(0,K.jsx)(`button`,{onClick:p,disabled:i,className:`p-1.5 rounded hover:bg-gray-100 text-gray-400 hover:text-gray-700 transition-colors`,children:(0,K.jsx)(Be,{size:13,className:i?`animate-spin`:``})})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-px bg-gray-100`,children:b.map(e=>{if(`isGroup`in e)return(0,K.jsx)(vZ,{profiles:g,expanded:l,toolSum:y,open:d,onToggle:()=>f(!d)},`__profiles__`);let t=e,n=cZ(t.id).icon,r=l.has(t.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(t.id),className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${r?`bg-gray-50`:``}`,children:[(0,K.jsx)(n,{size:14,className:`shrink-0 ${t.exists?`text-gray-500`:`text-gray-300`}`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-medium truncate ${t.exists?`text-gray-700`:`text-gray-400`}`,children:t.label}),(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 mt-0.5`,children:t.toolchainCount>0?`${t.toolchainCount} tools`:t.exists?`0 tools`:`—`})]}),r?(0,K.jsx)(F,{size:10,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:10,className:`text-gray-400 shrink-0`})]},t.id)})}),d&&g.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-gray-200 bg-gray-50/50 px-4 py-2 space-y-0.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider px-1 mb-1`,children:`Select a profile to expand`}),g.map(e=>{let t=l.has(e.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{m(e.id),f(!1),setTimeout(()=>{document.getElementById(`tier-${e.id}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},50)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded hover:bg-white/80 text-left transition-colors`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${t?`bg-blue-400`:`bg-gray-300`}`}),(0,K.jsx)(`span`,{className:`text-[12px] text-gray-700 flex-1`,children:e.label.replace(`Profile: `,``)}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 tabular-nums shrink-0`,children:e.toolchainCount>0?`${e.toolchainCount} tools`:`—`}),t&&(0,K.jsx)(F,{size:9,className:`text-blue-400 shrink-0`})]},e.id)}),t&&(0,K.jsx)(yZ,{onCreated:e=>{f(!1),p().then(()=>{let t=`profile:${e}`;m(t),setTimeout(()=>{document.getElementById(`tier-${t}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},100)})}})]})]}),[...v,...g].map(n=>(0,K.jsx)(bZ,{tier:n,isAdmin:!!t,isExpanded:l.has(n.id),disabled:e,onSaved:()=>p()},n.id))]})}function vZ({profiles:e,expanded:t,toolSum:n,open:r,onToggle:i}){return(0,K.jsxs)(`button`,{type:`button`,onClick:i,className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${e.some(e=>t.has(e.id))||r?`bg-gray-50`:``}`,children:[(0,K.jsx)(k,{size:14,className:`text-blue-400 shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`span`,{className:`text-[11px] font-medium text-gray-700`,children:[`Profiles (`,e.length,`)`]}),(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 mt-0.5`,children:n>0?`${n} tools`:`—`})]}),r?(0,K.jsx)(F,{size:10,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:10,className:`text-gray-400 shrink-0`})]})}function yZ({onCreated:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(null),s=async()=>{let t=r.trim();if(!t)return;o(null);let a=await gg(t);if(!a.ok){o(a.error??`create failed`);return}i(``),n(!1),e(t)};return t?(0,K.jsxs)(`div`,{className:`px-3 py-1.5 space-y-1.5`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>{i(e.target.value),o(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&(n(!1),i(``))},placeholder:`profile name`,className:fZ}),a&&(0,K.jsx)(`div`,{className:`text-[11px] text-red-600`,children:a}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Create`}),(0,K.jsx)(`button`,{onClick:()=>{n(!1),i(``),o(null)},className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-[11px] text-gray-400 hover:text-gray-700 hover:bg-white/80 rounded w-full transition-colors`,children:[(0,K.jsx)(Re,{size:12}),` Create profile`]})}function bZ({tier:e,isAdmin:t,isExpanded:n,disabled:r,onSaved:i}){if(!n)return null;let a=cZ(e.id),o=a.icon,s=e.editable&&(e.managedBy===`user`||e.managedBy===`admin`&&t),c=e.managedBy===`sdk`,l=e.id.startsWith(`profile:`),u=l?e.id.slice(8):``,d=!s&&e.managedBy===`admin`&&!t?`Admin access required`:null,f=zn(),p=dZ(e),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)({tools:{},env:{},envFile:``,envPath:[],tasks:{},alias:{},settings:{},plugins:{},hooks:{}}),[y,b]=(0,_.useState)(`tools`),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(null),[D,O]=(0,_.useState)(!1);(0,_.useEffect)(()=>{n&&(async()=>{let t=await ug(e.id),n=t.exists?t.content:``;h(n),v(mZ(n)),S(!0),E(null),O(!1)})()},[n,e.id]);let k=async()=>{w(!0),E(null);let t=y===`raw`?m:hZ(g),n=await dg(e.id,t);if(w(!1),!n.ok){E(n.error??`save failed`);return}y===`raw`?v(mZ(m)):(h(t),v(mZ(t))),O(!0),setTimeout(()=>O(!1),2500),i()},A=e=>{v(t=>({...t,...e})),O(!1)},j=()=>{v(mZ(m)),O(!1)},M=Object.keys(g.tools).length>0||Object.keys(g.env).length>0||g.envFile||g.envPath.length>0||Object.keys(g.tasks).length>0||Object.keys(g.alias).length>0||Object.keys(g.settings).length>0||Object.keys(g.plugins).length>0||Object.keys(g.hooks).length>0;return x?(0,K.jsxs)(`div`,{id:`tier-${e.id}`,className:`rounded-lg border overflow-hidden transition-shadow hover:shadow-sm ${s?`border-gray-200 bg-white`:`border-gray-200 bg-gray-50/50`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-gray-100 border-l-2 ${a.borderClass}`,children:[(0,K.jsx)(o,{size:16,className:`text-gray-500 shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[14px] font-semibold text-gray-900`,children:e.label}),(0,K.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full font-medium ${uZ(e.managedBy)}`,children:e.managedBy===`admin`?`admin`:e.managedBy===`user`?`you`:`SDK`}),!e.exists&&!c&&(0,K.jsx)(`span`,{className:`text-[10px] text-amber-600 bg-amber-50 px-1.5 py-0.5 rounded-full`,children:`not created`}),d&&(0,K.jsx)(Te,{size:11,className:`text-amber-500 shrink-0`})]}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-0.5`,children:c?e.path:a.desc})]}),(0,K.jsxs)(`div`,{className:`hidden sm:flex items-center gap-1 shrink-0`,children:[Object.keys(g.tools).length>0&&(0,K.jsx)(xZ,{label:`tools`,value:Object.keys(g.tools).length}),Object.keys(g.tasks).length>0&&(0,K.jsx)(xZ,{label:`tasks`,value:Object.keys(g.tasks).length}),Object.keys(g.env).length>0&&(0,K.jsx)(xZ,{label:`env`,value:Object.keys(g.env).length})]}),p&&(0,K.jsxs)(zp,{children:[(0,K.jsx)(Bp,{asChild:!0,children:(0,K.jsx)(`button`,{onClick:()=>f(`/context/${p.vault}?file=${encodeURIComponent(p.file)}&edit=1`),className:`shrink-0 p-1.5 rounded-lg text-gray-300 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:(0,K.jsx)(oe,{size:13})})}),(0,K.jsxs)(Vp,{children:[`edit `,p.vault,`/`,p.file]})]})]}),(0,K.jsx)(`div`,{className:`px-4 py-4 space-y-4`,children:c?(0,K.jsxs)(`div`,{className:`rounded-lg bg-gray-50 px-3 py-2.5 text-[12px] text-gray-500`,children:[`SDK-managed — mise.toml is read from `,(0,K.jsxs)(`code`,{className:`bg-gray-100 px-1 rounded text-[11px]`,children:[e.path,`/mise.toml`]}),`. Not editable here.`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 bg-gray-100 rounded-lg p-0.5 overflow-x-auto`,children:gZ.map(e=>(0,K.jsx)(`button`,{onClick:()=>b(e.id),className:`px-3 py-1 rounded text-[11px] font-medium whitespace-nowrap transition-colors ${y===e.id?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:e.label},e.id))}),(0,K.jsx)(`p`,{className:`text-[10px] text-gray-400 -mt-3`,children:gZ.find(e=>e.id===y)?.desc}),y===`tools`&&(0,K.jsx)(SZ,{tools:g.tools,readonly:!s||!!r,onChange:e=>A({tools:e})}),y===`env`&&(0,K.jsx)(CZ,{env:g.env,envFile:g.envFile,envPath:g.envPath,readonly:!s||!!r,onChange:(e,t,n)=>A({env:e,envFile:t,envPath:n})}),y===`tasks`&&(0,K.jsx)(wZ,{tasks:g.tasks,readonly:!s||!!r,onChange:e=>A({tasks:e})}),y===`alias`&&(0,K.jsx)(TZ,{alias:g.alias,readonly:!s||!!r,onChange:e=>A({alias:e})}),y===`settings`&&(0,K.jsx)(DZ,{settings:g.settings,readonly:!s||!!r,onChange:e=>A({settings:e})}),y===`plugins`&&(0,K.jsx)(kZ,{plugins:g.plugins,readonly:!s||!!r,onChange:e=>A({plugins:e})}),y===`hooks`&&(0,K.jsx)(jZ,{hooks:g.hooks,readonly:!s||!!r,onChange:e=>A({hooks:e})}),y===`raw`&&(0,K.jsx)(`div`,{className:`space-y-2`,children:(0,K.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),O(!1)},onBlur:j,readOnly:!s||r,spellCheck:!1,className:`w-full h-80 px-3 py-2 border border-gray-300 rounded text-[12px] font-mono outline-none bg-white focus:border-gray-900 resize-y disabled:bg-gray-50 disabled:text-gray-500`})}),d&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-50 text-[12px] text-amber-700`,children:[(0,K.jsx)(Te,{size:12}),` `,d]}),s&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 pt-3 border-t border-gray-100 ${l?`justify-between`:`justify-end`}`,children:[l&&t&&(0,K.jsx)(`button`,{onClick:async()=>{if(!confirm(`Delete profile "${u}"?`))return;let e=await _g(u);if(!e.ok){E(e.error??`delete failed`);return}i()},className:`px-3 h-7 rounded-lg text-[11px] text-red-500 hover:bg-red-50 hover:text-red-600 transition-colors`,children:`Delete profile`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!M&&y!==`raw`&&!m&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 italic`,children:`empty — save will create the file`}),T&&(0,K.jsx)(`span`,{className:`text-[12px] text-red-600`,children:T}),D&&(0,K.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:13}),` saved`]}),(0,K.jsx)(`button`,{onClick:k,disabled:C||r,className:`px-4 h-8 rounded-lg bg-gray-900 text-white text-xs font-medium hover:bg-gray-800 disabled:opacity-50 transition-colors`,children:C?`Saving…`:`Save`})]})]})]})})]}):(0,K.jsx)(`div`,{id:`tier-${e.id}`,className:`rounded-lg border border-gray-200 bg-white p-4 text-[12px] text-gray-400 italic`,children:`loading mise.toml…`})}function xZ({label:e,value:t}){return(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-500 bg-gray-100 px-1.5 py-0.5 rounded-full font-medium tabular-nums`,children:[t,` `,(0,K.jsx)(`span`,{className:`text-gray-400`,children:e})]})}function SZ({tools:e,readonly:t,onChange:n}){let r=Object.entries(e),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)([]);(0,_.useEffect)(()=>{Mh().then(e=>p(e.miseToolPresets)).catch(()=>{})},[]);let m=t=>{n({...e,[t.name]:{version:t.suggestedVersion,backend:t.backend}})},h=()=>{let t=o.trim();t&&(n({...e,[t]:{version:c.trim()||`latest`,backend:u.trim()||void 0}}),s(``),l(``),d(``),a(!1))},g=t=>{let{[t]:r,...i}=e;n(i)},v=(t,r)=>{let i={...e[t],...r};i.backend===``&&(i.backend=void 0),n({...e,[t]:i})};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[r.length===0&&!i&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No tools. Add one to get started.`}),r.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Tool`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Backend`}),!t&&(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:r.map(([r,i])=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:r}):(0,K.jsx)(`input`,{value:r,onChange:t=>{let{[r]:i,...a}=e;n({...a,[t.target.value]:i})},className:pZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-600`,children:i.version}):(0,K.jsx)(`input`,{value:i.version,onChange:e=>v(r,{version:e.target.value}),className:`w-24 ${pZ}`})}),(0,K.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:t?(0,K.jsx)(`code`,{className:`text-[11px] text-gray-500`,children:i.backend||`—`}):(0,K.jsx)(`input`,{value:i.backend??``,onChange:e=>v(r,{backend:e.target.value}),placeholder:`e.g. aqua:hashicorp/terraform`,className:`w-44 ${pZ}`})}),!t&&(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>g(r),className:`text-gray-300 hover:text-red-500 transition-colors`,children:(0,K.jsx)(tt,{size:12})})})]},r))})]})}),!t&&(0,K.jsxs)(K.Fragment,{children:[i?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h(),e.key===`Escape`&&a(!1)},placeholder:`tool name`,className:pZ}),(0,K.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h()},placeholder:`version (e.g. 3.12)`,className:pZ}),(0,K.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h()},placeholder:`backend (optional)`,className:pZ})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:h,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>a(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>a(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Re,{size:11}),` add tool`]}),f.filter(t=>!e[t.name]).length>0&&(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 mt-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Suggested tools`}),(0,K.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-2`,children:f.filter(t=>!e[t.name]).map(e=>(0,K.jsxs)(`button`,{onClick:()=>m(e),className:`px-2 py-0.5 rounded border border-gray-200 bg-white text-[10px] text-gray-500 hover:text-gray-900 hover:border-gray-400 transition-colors`,title:e.description,children:[`+ `,e.name,` `,e.suggestedVersion]},e.name))})]})]})]})}function CZ({env:e,envFile:t,envPath:n,readonly:r,onChange:i}){let a=Object.entries(e),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),f=()=>{let r=c.trim();r&&(i({...e,[r]:u},t,n),l(``),d(``),s(!1))},p=r=>{let{[r]:a,...o}=e;i(o,t,n)},m=(r,a)=>{i({...e,[r]:a},t,n)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`label`,{className:`text-[11px] font-medium text-gray-500 w-20 shrink-0`,children:`_.file`}),(0,K.jsx)(`input`,{value:t,onChange:t=>i(e,t.target.value,n),readOnly:r,placeholder:`.env (load from dotenv file)`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`label`,{className:`text-[11px] font-medium text-gray-500 w-20 shrink-0`,children:`_.path`}),(0,K.jsx)(`input`,{value:n.join(`, `),onChange:n=>i(e,t,n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)),readOnly:r,placeholder:`./node_modules/.bin (comma-separated PATH additions)`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Variables`}),!r&&(0,K.jsxs)(`button`,{onClick:()=>s(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add`]})]}),a.length===0&&!o&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-2`,children:`No env vars set.`}),a.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-1/3`,children:`Name`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Value`}),!r&&(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:a.map(([a,o])=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:r?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:a}):(0,K.jsx)(`input`,{value:a,onChange:r=>{let{[a]:o,...s}=e;i({...s,[r.target.value]:o},t,n)},className:pZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:r?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-600`,children:o}):(0,K.jsx)(`input`,{value:o,onChange:e=>m(a,e.target.value),className:pZ})}),!r&&(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>p(a),className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:12})})})]},a))})]})}),!r&&o&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&f(),e.key===`Escape`&&s(!1)},placeholder:`VAR_NAME`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&f()},placeholder:`value`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`button`,{onClick:f,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>s(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]})]})}function wZ({tasks:e,readonly:t,onChange:n}){let r=Object.entries(e),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),u=()=>{let t=c.trim();t&&(n({...e,[t]:{run:``}}),l(``),s(!1),a(t))},d=t=>{let{[t]:r,...o}=e;n(o),i===t&&a(null)},f=(t,r)=>{n({...e,[t]:{...e[t],...r}})};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[r.length===0&&!o&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No tasks defined. Add a build or run task.`}),r.map(([e,n])=>{let r=i===e;return(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(r?null:e),className:`w-full flex items-center gap-2 px-3 py-2 hover:bg-gray-50 transition-colors text-left`,children:[r?(0,K.jsx)(F,{size:12,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:12,className:`text-gray-400 shrink-0`}),(0,K.jsx)(`code`,{className:`text-[13px] font-medium text-gray-800 flex-1`,children:e}),n.description&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 truncate hidden sm:inline`,children:n.description}),!t&&(0,K.jsx)(`button`,{onClick:t=>{t.stopPropagation(),d(e)},className:`text-gray-300 hover:text-red-500 ml-1`,children:(0,K.jsx)(tt,{size:12})})]}),r&&(0,K.jsxs)(`div`,{className:`border-t border-gray-100 px-4 py-3 space-y-3 bg-gray-50/30`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,K.jsx)(NZ,{label:`Run command`,children:(0,K.jsx)(`input`,{value:n.run??``,onChange:t=>f(e,{run:t.target.value}),readOnly:t,placeholder:`npm run build`,className:fZ})}),(0,K.jsx)(NZ,{label:`Description`,children:(0,K.jsx)(`input`,{value:n.description??``,onChange:t=>f(e,{description:t.target.value}),readOnly:t,placeholder:`Build the project`,className:fZ})}),(0,K.jsx)(NZ,{label:`Working dir`,children:(0,K.jsx)(`input`,{value:n.dir??``,onChange:t=>f(e,{dir:t.target.value}),readOnly:t,placeholder:`{{config_root}}/frontend`,className:fZ})}),(0,K.jsx)(NZ,{label:`Run (Windows)`,children:(0,K.jsx)(`input`,{value:n.runWindows??``,onChange:t=>f(e,{runWindows:t.target.value}),readOnly:t,placeholder:`npm.cmd run build`,className:fZ})}),(0,K.jsx)(NZ,{label:`Depends on (comma-sep)`,children:(0,K.jsx)(`input`,{value:n.depends?.join(`, `)??``,onChange:t=>f(e,{depends:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`lint, test`,className:fZ})}),(0,K.jsx)(NZ,{label:`Wait for (comma-sep)`,children:(0,K.jsx)(`input`,{value:n.waitFor?.join(`, `)??``,onChange:t=>f(e,{waitFor:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`db:5432`,className:fZ})}),(0,K.jsx)(NZ,{label:`Sources (comma-sep)`,children:(0,K.jsx)(`input`,{value:n.sources?.join(`, `)??``,onChange:t=>f(e,{sources:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`src/**/*.ts`,className:fZ})}),(0,K.jsx)(NZ,{label:`Outputs (comma-sep)`,children:(0,K.jsx)(`input`,{value:n.outputs?.join(`, `)??``,onChange:t=>f(e,{outputs:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`dist/**/*.js`,className:fZ})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-gray-600 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:n.hide??!1,onChange:t=>f(e,{hide:t.target.checked||void 0}),disabled:t,className:`h-3.5 w-3.5 rounded border-gray-300`}),`Hide in `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`mise run`}),` list`]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-gray-600 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:n.raw??!1,onChange:t=>f(e,{raw:t.target.checked||void 0}),disabled:t,className:`h-3.5 w-3.5 rounded border-gray-300`}),`Raw (pass directly to shell)`]})]}),(0,K.jsxs)(`details`,{className:`text-[11px]`,children:[(0,K.jsxs)(`summary`,{className:`text-gray-400 cursor-pointer hover:text-gray-600`,children:[`Task environment variables (`,Object.keys(n.env??{}).length,`)`]}),(0,K.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[Object.entries(n.env??{}).map(([r,i])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{value:r,onChange:t=>{let i={...n.env??{}},a=i[r]??``;delete i[r],i[t.target.value]=a,f(e,{env:i})},readOnly:t,placeholder:`VAR`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-40`}),(0,K.jsx)(`span`,{className:`text-gray-400`,children:`=`}),(0,K.jsx)(`input`,{value:i,onChange:t=>{f(e,{env:{...n.env??{},[r]:t.target.value}})},readOnly:t,placeholder:`value`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),!t&&(0,K.jsx)(`button`,{onClick:()=>{let{[r]:t,...i}=n.env??{};f(e,{env:Object.keys(i).length>0?i:void 0})},className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:11})})]},r)),!t&&(0,K.jsxs)(`button`,{onClick:()=>f(e,{env:{...n.env??{},"":``}}),className:`text-[10px] text-gray-400 hover:text-gray-600 inline-flex items-center gap-1 mt-1`,children:[(0,K.jsx)(Re,{size:10}),` add env var`]})]})]})]})]},e)}),!t&&(0,K.jsx)(K.Fragment,{children:o?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&u(),e.key===`Escape`&&s(!1)},placeholder:`task name`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`button`,{onClick:u,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>s(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>s(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add task`]})})]})}function TZ({alias:e,readonly:t,onChange:n}){let[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(!1),d=()=>{let t=r.trim(),l=a.trim();!t||!l||(n({...e,[t]:{...e[t]??{},[l]:s.trim()||`latest`}}),i(``),o(``),c(``),u(!1))},f=(t,r)=>{let{[r]:i,...a}=e[t];if(Object.keys(a).length===0){let{[t]:r,...i}=e;n(i)}else n({...e,[t]:a})},p=Object.entries(e);return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[p.length===0&&!l&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No aliases. Create version aliases for tools (e.g. node:myapp → 22.11.0).`}),p.map(([e,n])=>(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:[(0,K.jsx)(`div`,{className:`px-3 py-2 bg-gray-50/50 border-b border-gray-100 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:e}),Object.entries(n).map(([n,r])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-gray-50 hover:bg-gray-50/50`,children:[(0,K.jsx)(`code`,{className:`text-[12px] text-gray-600 w-32 truncate`,children:n}),(0,K.jsx)(`span`,{className:`text-gray-300`,children:`→`}),(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800 flex-1`,children:r}),!t&&(0,K.jsx)(`button`,{onClick:()=>f(e,n),className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:11})})]},n))]},e)),!t&&(0,K.jsx)(K.Fragment,{children:l?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d(),e.key===`Escape`&&u(!1)},placeholder:`tool (e.g. node)`,className:pZ}),(0,K.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`alias (e.g. myapp)`,className:pZ}),(0,K.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`version`,className:pZ})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:d,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>u(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>u(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add alias`]})})]})}var EZ=[{key:`always_keep_download`,label:`Always keep download`,type:`bool`,desc:`Keep downloaded archives after install`},{key:`always_keep_install`,label:`Always keep install`,type:`bool`,desc:`Keep install directory after uninstall`},{key:`legacy_version_file`,label:`Legacy version file`,type:`bool`,desc:`Read .node-version, .python-version, etc.`},{key:`jobs`,label:`Jobs`,type:`number`,desc:`Parallel install jobs (default: 4)`},{key:`experimental`,label:`Experimental`,type:`bool`,desc:`Enable experimental features`},{key:`yes`,label:`Yes`,type:`bool`,desc:`Auto-answer yes to prompts`},{key:`quiet`,label:`Quiet`,type:`bool`,desc:`Suppress non-error output`},{key:`verbose`,label:`Verbose`,type:`bool`,desc:`Show extra debug output`},{key:`raw`,label:`Raw`,type:`bool`,desc:`Pass commands directly to shell`},{key:`color`,label:`Color`,type:`bool`,desc:`Enable colored output`},{key:`pipx_uvx`,label:`pipx / uvx`,type:`bool`,desc:`Use uvx for pipx operations`},{key:`python_venv_auto_create`,label:`Python venv auto-create`,type:`bool`,desc:`Auto-create venv when entering dir`},{key:`python_default_packages_file`,label:`Python default packages file`,type:`string`,desc:`Default pip packages file`,placeholder:`~/.default-python-packages`},{key:`node_mirror_url`,label:`Node mirror URL`,type:`string`,desc:`Custom nodejs.org mirror`},{key:`python_mirror_url`,label:`Python mirror URL`,type:`string`,desc:`Custom python.org mirror`},{key:`plugin_autoupdate_last_check_duration`,label:`Plugin autoupdate check`,type:`string`,desc:`Duration between update checks`,placeholder:`7d`},{key:`trusted_config_paths`,label:`Trusted config paths`,type:`string[]`,desc:`Paths to trust (comma-separated)`,placeholder:`/path/to/trusted`}];function DZ({settings:e,readonly:t,onChange:n}){let r=(t,r)=>{if(r===null||r===``||r===void 0||typeof r==`boolean`&&r===!0){let{[t]:r,...i}=e;n(i)}else n({...e,[t]:r})},i=new Set(Object.keys(e)),a=EZ.filter(e=>i.has(e.key)||e.type===`bool`),o=Object.entries(e).filter(([e])=>!EZ.some(t=>t.key===e));return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[a.map(n=>{let i=e[n.key],a=i!==void 0;return(0,K.jsxs)(`div`,{className:`flex items-start gap-3 py-1.5 border-b border-gray-50`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:n.label}),!a&&(0,K.jsx)(`span`,{className:`text-[9px] text-gray-300`,children:`default`})]}),(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400`,children:n.desc})]}),(0,K.jsx)(`div`,{className:`shrink-0`,children:n.type===`bool`?(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:i===!0,onChange:e=>r(n.key,e.target.checked||null),disabled:t,className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-8 h-4.5 bg-gray-200 peer-checked:bg-gray-900 rounded-full transition-colors after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-transform peer-checked:after:translate-x-[14px]`})]}):n.type===`number`?(0,K.jsx)(`input`,{type:`number`,value:i??``,onChange:e=>r(n.key,e.target.value?Number(e.target.value):null),readOnly:t,placeholder:n.placeholder,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-24`}):(0,K.jsx)(`input`,{value:i??``,onChange:e=>r(n.key,e.target.value||null),readOnly:t,placeholder:n.placeholder,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-48`})})]},n.key)}),o.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-gray-200 pt-3 mt-3`,children:[(0,K.jsx)(`span`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Custom`}),o.map(([i,a])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(`input`,{value:i,readOnly:!0,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-40`}),(0,K.jsx)(`input`,{value:String(a),onChange:e=>r(i,e.target.value),readOnly:t,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),!t&&(0,K.jsx)(`button`,{onClick:()=>{let{[i]:t,...r}=e;n(r)},className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:11})})]},i))]}),!t&&(0,K.jsx)(OZ,{onAdd:(t,r)=>n({...e,[t]:r})})]})}function OZ({onAdd:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),s=()=>{let t=r.trim();t&&(e(t,a),i(``),o(``),n(!1))};return t?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&n(!1)},placeholder:`setting key`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s()},placeholder:`value`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>n(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add custom setting`]})}function kZ({plugins:e,readonly:t,onChange:n}){let r=Object.entries(e),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),u=()=>{let t=o.trim();t&&(n({...e,[t]:c.trim()||`https://github.com/asdf-community/asdf-${t}.git`}),s(``),l(``),a(!1))},d=t=>{let{[t]:r,...i}=e;n(i)};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[r.length===0&&!i&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No plugins. Add asdf-compatible plugin sources for tools not in the default registry.`}),r.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Plugin`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`URL`}),!t&&(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:r.map(([r,i])=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:r}):(0,K.jsx)(`input`,{value:r,onChange:t=>{let{[r]:i,...a}=e;n({...a,[t.target.value]:i})},className:pZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,K.jsx)(`code`,{className:`text-[11px] text-gray-500 truncate block max-w-xs`,children:i}):(0,K.jsx)(`input`,{value:i,onChange:t=>n({...e,[r]:t.target.value}),className:pZ})}),!t&&(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>d(r),className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:12})})})]},r))})]})}),!t&&(0,K.jsx)(K.Fragment,{children:i?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&u(),e.key===`Escape`&&a(!1)},placeholder:`plugin name (e.g. rust)`,className:pZ}),(0,K.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&u()},placeholder:`git URL (or leave empty for default)`,className:pZ})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:u,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>a(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>a(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add plugin`]})})]})}var AZ=[`enter`,`leave`,`cd`,`preinstall`,`postinstall`];function jZ({hooks:e,readonly:t,onChange:n}){let r=(t,r)=>{if(r.trim())n({...e,[t]:r});else{let{[t]:r,...i}=e;n(i)}};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 mb-2`,children:[`Commands that run on lifecycle events. Use `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[10px]`,children:`{{env.PWD}}`}),` for template variables.`]}),AZ.map(n=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`code`,{className:`text-[11px] font-medium text-gray-600 w-24 shrink-0`,children:n}),(0,K.jsx)(`input`,{value:e[n]??``,onChange:e=>r(n,e.target.value),readOnly:t,placeholder:`echo '${n} hook'`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`})]},n)),Object.entries(e).filter(([e])=>!AZ.includes(e)).map(([i,a])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`input`,{value:i,readOnly:!0,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-24 shrink-0`}),(0,K.jsx)(`input`,{value:a,onChange:e=>r(i,e.target.value),readOnly:t,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),!t&&(0,K.jsx)(`button`,{onClick:()=>{let{[i]:t,...r}=e;n(r)},className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:11})})]},i)),!t&&(0,K.jsx)(MZ,{onAdd:(t,r)=>n({...e,[t]:r})})]})}function MZ({onAdd:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),s=()=>{let t=r.trim();t&&(e(t,a),i(``),o(``),n(!1))};return t?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&n(!1)},placeholder:`hook event`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-32`}),(0,K.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s()},placeholder:`command`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>n(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 mt-1`,children:[(0,K.jsx)(Re,{size:11}),` add custom hook`]})}function NZ({label:e,children:t}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[10px] font-medium text-gray-400 uppercase tracking-wider`,children:e}),t]})}var PZ=`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono`;function FZ(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!0),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(`providers`),f=(0,_.useCallback)(async()=>{r(!0),s(null),t(await Mh()),r(!1)},[]);(0,_.useEffect)(()=>{f()},[f]);let p=async n=>{if(!e)return;let r={...e,...n};t(r),a(!0),s(null);let i=await Nh(r);if(a(!1),!i){s(`save failed`);return}l(!0),setTimeout(()=>l(!1),2500)};return n&&!e?(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-12 text-center`,children:`loading presets…`}):e?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1 bg-gray-100 rounded-lg p-0.5 w-fit`,children:[(0,K.jsxs)(`button`,{onClick:()=>d(`providers`),className:`px-3 py-1 rounded text-[11px] font-medium transition-colors flex items-center gap-1.5 ${u===`providers`?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[(0,K.jsx)(te,{size:12}),` AI Providers`]}),(0,K.jsxs)(`button`,{onClick:()=>d(`mise-tools`),className:`px-3 py-1 rounded text-[11px] font-medium transition-colors flex items-center gap-1.5 ${u===`mise-tools`?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[(0,K.jsx)(ct,{size:12}),` Mise Tools`]})]}),u===`providers`&&(0,K.jsx)(IZ,{presets:e.providerPresets,onChange:e=>p({providerPresets:e}),saving:i}),u===`mise-tools`&&(0,K.jsx)(LZ,{presets:e.miseToolPresets,onChange:e=>p({miseToolPresets:e}),saving:i}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[o&&(0,K.jsx)(`span`,{className:`text-[12px] text-red-600`,children:o}),c&&(0,K.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:13}),` saved`]})]})]}):(0,K.jsx)(`div`,{className:`text-[12px] text-red-600 py-12 text-center`,children:`failed to load presets`})}function IZ({presets:e,onChange:t,saving:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),d=()=>{let n=a.trim();if(!n||!s.trim())return;let r=l.trim()?l.split(`
|
|
160
|
-
`).map(e=>e.trim()).filter(Boolean):[];t([...e,{name:n,baseUrl:s.trim(),models:r}]),o(``),c(``),u(``),i(!1)},f=n=>{t(e.filter((e,t)=>t!==n))},p=(n,r)=>{t(e.map((e,t)=>t===n?{...e,...r}:e))};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.length===0&&!r&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No provider presets. Add one to get started.`}),e.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-1/5`,children:`Name`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Base URL`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Models`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:e.map((e,t)=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{value:e.name,onChange:e=>p(t,{name:e.target.value}),disabled:n,className:
|
|
159
|
+
`}var cZ={team:{icon:_e,borderClass:`border-l-violet-400`,badgeClass:`bg-violet-100 text-violet-700`,desc:`Workspace-wide, set by admin`},personal:{icon:ot,borderClass:`border-l-emerald-400`,badgeClass:`bg-emerald-100 text-emerald-700`,desc:`Your personal overrides`},project:{icon:de,borderClass:`border-l-gray-300`,badgeClass:`bg-gray-100 text-gray-500`,desc:`SDK reads from workdir`},local:{icon:oe,borderClass:`border-l-amber-300`,badgeClass:`bg-amber-100 text-amber-700`,desc:`Per-checkout .local.* overrides`}};function lZ(e){return e.startsWith(`profile:`)?{icon:k,borderClass:`border-l-blue-400`,badgeClass:`bg-blue-100 text-blue-700`,desc:`Opt-in role-based config`}:cZ[e]??cZ.team}function uZ(e){return e===`team`?1:e.startsWith(`profile:`)?2:e===`personal`?3:e===`project`?4:e===`local`?5:99}function dZ(e){return e===`admin`?`bg-violet-100 text-violet-700`:e===`user`?`bg-gray-100 text-gray-600`:`bg-gray-100 text-gray-400`}function fZ(e){return e.id===`team`?{vault:`knowledge`,file:`.loopat/.claude/mise.toml`}:e.id.startsWith(`profile:`)?{vault:`knowledge`,file:`.loopat/profiles/${e.id.slice(8)}/.claude/mise.toml`}:e.id===`personal`?{vault:`personal`,file:`.loopat/.claude/mise.toml`}:null}var pZ=`w-full px-2.5 py-1.5 border border-gray-300 rounded text-[12px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900 transition-colors font-mono`,mZ=`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono`;function hZ(e){let t={};try{t=ZX(e)}catch{}let n={};if(t.tools&&typeof t.tools==`object`)for(let[e,r]of Object.entries(t.tools))e.startsWith(`_`)||(typeof r==`string`?n[e]={version:r}:r&&typeof r==`object`&&(n[e]={version:typeof r.version==`string`?r.version:String(r.version??``),backend:typeof r.backend==`string`?r.backend:void 0}));let r={},i=``,a=[];if(t.env&&typeof t.env==`object`)for(let[e,n]of Object.entries(t.env)){if(e===`_.file`&&typeof n==`string`){i=n;continue}if(e===`_.path`&&Array.isArray(n)){a=n.map(String);continue}typeof n==`string`?r[e]=n:Array.isArray(n)?r[e]=n.join(`:`):n!=null&&(r[e]=String(n))}let o={};if(t.tasks&&typeof t.tasks==`object`)for(let[e,n]of Object.entries(t.tasks)){if(!n||typeof n!=`object`)continue;let t=n?.run_windows;o[e]={description:typeof n.description==`string`?n.description:void 0,run:typeof n.run==`string`?n.run:void 0,dir:typeof n.dir==`string`?n.dir:void 0,depends:Array.isArray(n.depends)?n.depends.map(String):void 0,waitFor:Array.isArray(n.wait_for)?n.wait_for.map(String):void 0,sources:Array.isArray(n.sources)?n.sources.map(String):void 0,outputs:Array.isArray(n.outputs)?n.outputs.map(String):void 0,hide:typeof n.hide==`boolean`?n.hide:void 0,raw:typeof n.raw==`boolean`?n.raw:void 0,env:n.env&&typeof n.env==`object`?Object.fromEntries(Object.entries(n.env).map(([e,t])=>[e,String(t)])):void 0,runWindows:typeof t==`string`?t:void 0}}let s={};if(t.alias&&typeof t.alias==`object`){for(let[e,n]of Object.entries(t.alias))if(n&&typeof n==`object`){s[e]={};for(let[t,r]of Object.entries(n))s[e][t]=String(r)}}let c={};if(t.settings&&typeof t.settings==`object`)for(let[e,n]of Object.entries(t.settings))e.startsWith(`_`)||(c[e]=n);let l={};if(t.plugins&&typeof t.plugins==`object`)for(let[e,n]of Object.entries(t.plugins))l[e]=n&&typeof n==`object`&&typeof n.url==`string`?n.url:typeof n==`string`?n:``;let u={};if(t.hooks&&typeof t.hooks==`object`)for(let[e,n]of Object.entries(t.hooks))typeof n==`string`&&(u[e]=n);return{tools:n,env:r,envFile:i,envPath:a,tasks:o,alias:s,settings:c,plugins:l,hooks:u}}function gZ(e){let t={};if(Object.keys(e.tools).length>0){t.tools={};for(let[n,r]of Object.entries(e.tools))r.backend?t.tools[n]={version:r.version,backend:r.backend}:t.tools[n]=r.version}if((Object.keys(e.env).length>0||e.envFile||e.envPath.length>0)&&(t.env={},e.envFile&&(t.env[`_.file`]=e.envFile),e.envPath.length>0&&(t.env[`_.path`]=e.envPath),Object.assign(t.env,e.env)),Object.keys(e.tasks).length>0){t.tasks={};for(let[n,r]of Object.entries(e.tasks)){let e={};r.description&&(e.description=r.description),r.run&&(e.run=r.run),r.dir&&(e.dir=r.dir),r.depends&&r.depends.length>0&&(e.depends=r.depends),r.waitFor&&r.waitFor.length>0&&(e.wait_for=r.waitFor),r.sources&&r.sources.length>0&&(e.sources=r.sources),r.outputs&&r.outputs.length>0&&(e.outputs=r.outputs),r.hide!==void 0&&(e.hide=r.hide),r.raw!==void 0&&(e.raw=r.raw),r.env&&Object.keys(r.env).length>0&&(e.env=r.env),r.runWindows&&(e.run_windows=r.runWindows),t.tasks[n]=e}}if(Object.keys(e.alias).length>0&&(t.alias=e.alias),Object.keys(e.settings).length>0&&(t.settings=e.settings),Object.keys(e.plugins).length>0){t.plugins={};for(let[n,r]of Object.entries(e.plugins))t.plugins[n]={url:r}}return Object.keys(e.hooks).length>0&&(t.hooks=e.hooks),Object.keys(t).length===0?``:sZ(t)}var _Z=[{id:`tools`,label:`Tools`,desc:`Tool versions (node, python, rust, …)`},{id:`env`,label:`Env`,desc:`Environment variables`},{id:`tasks`,label:`Tasks`,desc:`Build / run tasks`},{id:`alias`,label:`Alias`,desc:`Tool version aliases`},{id:`settings`,label:`Settings`,desc:`mise behavior flags`},{id:`plugins`,label:`Plugins`,desc:`asdf plugin sources`},{id:`hooks`,label:`Hooks`,desc:`Lifecycle hook commands`},{id:`raw`,label:`Raw TOML`,desc:`Direct TOML editing`}];function vZ({disabled:e}){let t=Cg().currentUser?.role===`admin`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!0),[o,s]=_i(),c=o.get(`expand`)??`personal`,l=new Set(c.split(`,`).filter(Boolean)),u=e=>{let t=[...e].join(`,`);s(t?{expand:t}:{},{replace:!0})},[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(async()=>{a(!0),r(await cg()),a(!1)},[]);(0,_.useEffect)(()=>{p()},[p]);let m=e=>{let t=new Set(l);t.has(e)?t.delete(e):t.add(e),u(t)},h=n?.tiers??[],g=h.filter(e=>e.id.startsWith(`profile:`)),v=h.filter(e=>!e.id.startsWith(`profile:`)).sort((e,t)=>uZ(e.id)-uZ(t.id)),y=g.reduce((e,t)=>e+t.toolchainCount,0),b=[...v.filter(e=>uZ(e.id)<3),...g.length>0?[{id:`__profiles__`,label:`Profiles (${g.length})`,tier:g[0],isGroup:!0}]:[],...v.filter(e=>uZ(e.id)>=3)];return i&&!n?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-12 justify-center text-[13px] text-gray-400`,children:[(0,K.jsx)(Be,{size:13,className:`animate-spin`}),` loading tiers…`]}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white overflow-hidden transition-shadow hover:shadow-sm`,children:[(0,K.jsxs)(`div`,{className:`px-4 py-3 border-b border-gray-100 flex items-center gap-2.5`,children:[(0,K.jsx)(et,{size:15,className:`text-gray-400`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900`,children:`Mise Config`}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-2`,children:`mise.toml per tier — tools, env, tasks, aliases, settings, plugins, hooks`})]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`a`,{href:`https://mise.jdx.dev/configuration.html`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 px-2 py-1 rounded text-[10px] text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:[(0,K.jsx)(re,{size:10}),` docs`]}),(0,K.jsx)(`button`,{onClick:p,disabled:i,className:`p-1.5 rounded hover:bg-gray-100 text-gray-400 hover:text-gray-700 transition-colors`,children:(0,K.jsx)(Be,{size:13,className:i?`animate-spin`:``})})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-px bg-gray-100`,children:b.map(e=>{if(`isGroup`in e)return(0,K.jsx)(yZ,{profiles:g,expanded:l,toolSum:y,open:d,onToggle:()=>f(!d)},`__profiles__`);let t=e,n=lZ(t.id).icon,r=l.has(t.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>m(t.id),className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${r?`bg-gray-50`:``}`,children:[(0,K.jsx)(n,{size:14,className:`shrink-0 ${t.exists?`text-gray-500`:`text-gray-300`}`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-medium truncate ${t.exists?`text-gray-700`:`text-gray-400`}`,children:t.label}),(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 mt-0.5`,children:t.toolchainCount>0?`${t.toolchainCount} tools`:t.exists?`0 tools`:`—`})]}),r?(0,K.jsx)(F,{size:10,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:10,className:`text-gray-400 shrink-0`})]},t.id)})}),d&&g.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-gray-200 bg-gray-50/50 px-4 py-2 space-y-0.5`,children:[(0,K.jsx)(`div`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider px-1 mb-1`,children:`Select a profile to expand`}),g.map(e=>{let t=l.has(e.id);return(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{m(e.id),f(!1),setTimeout(()=>{document.getElementById(`tier-${e.id}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},50)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded hover:bg-white/80 text-left transition-colors`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${t?`bg-blue-400`:`bg-gray-300`}`}),(0,K.jsx)(`span`,{className:`text-[12px] text-gray-700 flex-1`,children:e.label.replace(`Profile: `,``)}),(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 tabular-nums shrink-0`,children:e.toolchainCount>0?`${e.toolchainCount} tools`:`—`}),t&&(0,K.jsx)(F,{size:9,className:`text-blue-400 shrink-0`})]},e.id)}),t&&(0,K.jsx)(bZ,{onCreated:e=>{f(!1),p().then(()=>{let t=`profile:${e}`;m(t),setTimeout(()=>{document.getElementById(`tier-${t}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},100)})}})]})]}),[...v,...g].map(n=>(0,K.jsx)(xZ,{tier:n,isAdmin:!!t,isExpanded:l.has(n.id),disabled:e,onSaved:()=>p()},n.id))]})}function yZ({profiles:e,expanded:t,toolSum:n,open:r,onToggle:i}){return(0,K.jsxs)(`button`,{type:`button`,onClick:i,className:`flex-1 min-w-[120px] flex items-center gap-2 px-3 py-2.5 bg-white hover:bg-gray-50 transition-colors text-left ${e.some(e=>t.has(e.id))||r?`bg-gray-50`:``}`,children:[(0,K.jsx)(k,{size:14,className:`text-blue-400 shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`span`,{className:`text-[11px] font-medium text-gray-700`,children:[`Profiles (`,e.length,`)`]}),(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 mt-0.5`,children:n>0?`${n} tools`:`—`})]}),r?(0,K.jsx)(F,{size:10,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:10,className:`text-gray-400 shrink-0`})]})}function bZ({onCreated:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(null),s=async()=>{let t=r.trim();if(!t)return;o(null);let a=await gg(t);if(!a.ok){o(a.error??`create failed`);return}i(``),n(!1),e(t)};return t?(0,K.jsxs)(`div`,{className:`px-3 py-1.5 space-y-1.5`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>{i(e.target.value),o(null)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&(n(!1),i(``))},placeholder:`profile name`,className:pZ}),a&&(0,K.jsx)(`div`,{className:`text-[11px] text-red-600`,children:a}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded-lg bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Create`}),(0,K.jsx)(`button`,{onClick:()=>{n(!1),i(``),o(null)},className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-[11px] text-gray-400 hover:text-gray-700 hover:bg-white/80 rounded w-full transition-colors`,children:[(0,K.jsx)(Re,{size:12}),` Create profile`]})}function xZ({tier:e,isAdmin:t,isExpanded:n,disabled:r,onSaved:i}){if(!n)return null;let a=lZ(e.id),o=a.icon,s=e.editable&&(e.managedBy===`user`||e.managedBy===`admin`&&t),c=e.managedBy===`sdk`,l=e.id.startsWith(`profile:`),u=l?e.id.slice(8):``,d=!s&&e.managedBy===`admin`&&!t?`Admin access required`:null,f=zn(),p=fZ(e),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)({tools:{},env:{},envFile:``,envPath:[],tasks:{},alias:{},settings:{},plugins:{},hooks:{}}),[y,b]=(0,_.useState)(`tools`),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),[T,E]=(0,_.useState)(null),[D,O]=(0,_.useState)(!1);(0,_.useEffect)(()=>{n&&(async()=>{let t=await ug(e.id),n=t.exists?t.content:``;h(n),v(hZ(n)),S(!0),E(null),O(!1)})()},[n,e.id]);let k=async()=>{w(!0),E(null);let t=y===`raw`?m:gZ(g),n=await dg(e.id,t);if(w(!1),!n.ok){E(n.error??`save failed`);return}y===`raw`?v(hZ(m)):(h(t),v(hZ(t))),O(!0),setTimeout(()=>O(!1),2500),i()},A=e=>{v(t=>({...t,...e})),O(!1)},j=()=>{v(hZ(m)),O(!1)},M=Object.keys(g.tools).length>0||Object.keys(g.env).length>0||g.envFile||g.envPath.length>0||Object.keys(g.tasks).length>0||Object.keys(g.alias).length>0||Object.keys(g.settings).length>0||Object.keys(g.plugins).length>0||Object.keys(g.hooks).length>0;return x?(0,K.jsxs)(`div`,{id:`tier-${e.id}`,className:`rounded-lg border overflow-hidden transition-shadow hover:shadow-sm ${s?`border-gray-200 bg-white`:`border-gray-200 bg-gray-50/50`}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-gray-100 border-l-2 ${a.borderClass}`,children:[(0,K.jsx)(o,{size:16,className:`text-gray-500 shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[14px] font-semibold text-gray-900`,children:e.label}),(0,K.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full font-medium ${dZ(e.managedBy)}`,children:e.managedBy===`admin`?`admin`:e.managedBy===`user`?`you`:`SDK`}),!e.exists&&!c&&(0,K.jsx)(`span`,{className:`text-[10px] text-amber-600 bg-amber-50 px-1.5 py-0.5 rounded-full`,children:`not created`}),d&&(0,K.jsx)(Te,{size:11,className:`text-amber-500 shrink-0`})]}),(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-0.5`,children:c?e.path:a.desc})]}),(0,K.jsxs)(`div`,{className:`hidden sm:flex items-center gap-1 shrink-0`,children:[Object.keys(g.tools).length>0&&(0,K.jsx)(SZ,{label:`tools`,value:Object.keys(g.tools).length}),Object.keys(g.tasks).length>0&&(0,K.jsx)(SZ,{label:`tasks`,value:Object.keys(g.tasks).length}),Object.keys(g.env).length>0&&(0,K.jsx)(SZ,{label:`env`,value:Object.keys(g.env).length})]}),p&&(0,K.jsxs)(zp,{children:[(0,K.jsx)(Bp,{asChild:!0,children:(0,K.jsx)(`button`,{onClick:()=>f(`/context/${p.vault}?file=${encodeURIComponent(p.file)}&edit=1`),className:`shrink-0 p-1.5 rounded-lg text-gray-300 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:(0,K.jsx)(oe,{size:13})})}),(0,K.jsxs)(Vp,{children:[`edit `,p.vault,`/`,p.file]})]})]}),(0,K.jsx)(`div`,{className:`px-4 py-4 space-y-4`,children:c?(0,K.jsxs)(`div`,{className:`rounded-lg bg-gray-50 px-3 py-2.5 text-[12px] text-gray-500`,children:[`SDK-managed — mise.toml is read from `,(0,K.jsxs)(`code`,{className:`bg-gray-100 px-1 rounded text-[11px]`,children:[e.path,`/mise.toml`]}),`. Not editable here.`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 bg-gray-100 rounded-lg p-0.5 overflow-x-auto`,children:_Z.map(e=>(0,K.jsx)(`button`,{onClick:()=>b(e.id),className:`px-3 py-1 rounded text-[11px] font-medium whitespace-nowrap transition-colors ${y===e.id?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:e.label},e.id))}),(0,K.jsx)(`p`,{className:`text-[10px] text-gray-400 -mt-3`,children:_Z.find(e=>e.id===y)?.desc}),y===`tools`&&(0,K.jsx)(CZ,{tools:g.tools,readonly:!s||!!r,onChange:e=>A({tools:e})}),y===`env`&&(0,K.jsx)(wZ,{env:g.env,envFile:g.envFile,envPath:g.envPath,readonly:!s||!!r,onChange:(e,t,n)=>A({env:e,envFile:t,envPath:n})}),y===`tasks`&&(0,K.jsx)(TZ,{tasks:g.tasks,readonly:!s||!!r,onChange:e=>A({tasks:e})}),y===`alias`&&(0,K.jsx)(EZ,{alias:g.alias,readonly:!s||!!r,onChange:e=>A({alias:e})}),y===`settings`&&(0,K.jsx)(OZ,{settings:g.settings,readonly:!s||!!r,onChange:e=>A({settings:e})}),y===`plugins`&&(0,K.jsx)(AZ,{plugins:g.plugins,readonly:!s||!!r,onChange:e=>A({plugins:e})}),y===`hooks`&&(0,K.jsx)(MZ,{hooks:g.hooks,readonly:!s||!!r,onChange:e=>A({hooks:e})}),y===`raw`&&(0,K.jsx)(`div`,{className:`space-y-2`,children:(0,K.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),O(!1)},onBlur:j,readOnly:!s||r,spellCheck:!1,className:`w-full h-80 px-3 py-2 border border-gray-300 rounded text-[12px] font-mono outline-none bg-white focus:border-gray-900 resize-y disabled:bg-gray-50 disabled:text-gray-500`})}),d&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-50 text-[12px] text-amber-700`,children:[(0,K.jsx)(Te,{size:12}),` `,d]}),s&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 pt-3 border-t border-gray-100 ${l?`justify-between`:`justify-end`}`,children:[l&&t&&(0,K.jsx)(`button`,{onClick:async()=>{if(!confirm(`Delete profile "${u}"?`))return;let e=await _g(u);if(!e.ok){E(e.error??`delete failed`);return}i()},className:`px-3 h-7 rounded-lg text-[11px] text-red-500 hover:bg-red-50 hover:text-red-600 transition-colors`,children:`Delete profile`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!M&&y!==`raw`&&!m&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 italic`,children:`empty — save will create the file`}),T&&(0,K.jsx)(`span`,{className:`text-[12px] text-red-600`,children:T}),D&&(0,K.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:13}),` saved`]}),(0,K.jsx)(`button`,{onClick:k,disabled:C||r,className:`px-4 h-8 rounded-lg bg-gray-900 text-white text-xs font-medium hover:bg-gray-800 disabled:opacity-50 transition-colors`,children:C?`Saving…`:`Save`})]})]})]})})]}):(0,K.jsx)(`div`,{id:`tier-${e.id}`,className:`rounded-lg border border-gray-200 bg-white p-4 text-[12px] text-gray-400 italic`,children:`loading mise.toml…`})}function SZ({label:e,value:t}){return(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-500 bg-gray-100 px-1.5 py-0.5 rounded-full font-medium tabular-nums`,children:[t,` `,(0,K.jsx)(`span`,{className:`text-gray-400`,children:e})]})}function CZ({tools:e,readonly:t,onChange:n}){let r=Object.entries(e),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)([]);(0,_.useEffect)(()=>{Mh().then(e=>p(e.miseToolPresets)).catch(()=>{})},[]);let m=t=>{n({...e,[t.name]:{version:t.suggestedVersion,backend:t.backend}})},h=()=>{let t=o.trim();t&&(n({...e,[t]:{version:c.trim()||`latest`,backend:u.trim()||void 0}}),s(``),l(``),d(``),a(!1))},g=t=>{let{[t]:r,...i}=e;n(i)},v=(t,r)=>{let i={...e[t],...r};i.backend===``&&(i.backend=void 0),n({...e,[t]:i})};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[r.length===0&&!i&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No tools. Add one to get started.`}),r.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Tool`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Backend`}),!t&&(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:r.map(([r,i])=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:r}):(0,K.jsx)(`input`,{value:r,onChange:t=>{let{[r]:i,...a}=e;n({...a,[t.target.value]:i})},className:mZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-600`,children:i.version}):(0,K.jsx)(`input`,{value:i.version,onChange:e=>v(r,{version:e.target.value}),className:`w-24 ${mZ}`})}),(0,K.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:t?(0,K.jsx)(`code`,{className:`text-[11px] text-gray-500`,children:i.backend||`—`}):(0,K.jsx)(`input`,{value:i.backend??``,onChange:e=>v(r,{backend:e.target.value}),placeholder:`e.g. aqua:hashicorp/terraform`,className:`w-44 ${mZ}`})}),!t&&(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>g(r),className:`text-gray-300 hover:text-red-500 transition-colors`,children:(0,K.jsx)(tt,{size:12})})})]},r))})]})}),!t&&(0,K.jsxs)(K.Fragment,{children:[i?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h(),e.key===`Escape`&&a(!1)},placeholder:`tool name`,className:mZ}),(0,K.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h()},placeholder:`version (e.g. 3.12)`,className:mZ}),(0,K.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&h()},placeholder:`backend (optional)`,className:mZ})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:h,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>a(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>a(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Re,{size:11}),` add tool`]}),f.filter(t=>!e[t.name]).length>0&&(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 mt-2`,children:[(0,K.jsx)(`span`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Suggested tools`}),(0,K.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-2`,children:f.filter(t=>!e[t.name]).map(e=>(0,K.jsxs)(`button`,{onClick:()=>m(e),className:`px-2 py-0.5 rounded border border-gray-200 bg-white text-[10px] text-gray-500 hover:text-gray-900 hover:border-gray-400 transition-colors`,title:e.description,children:[`+ `,e.name,` `,e.suggestedVersion]},e.name))})]})]})]})}function wZ({env:e,envFile:t,envPath:n,readonly:r,onChange:i}){let a=Object.entries(e),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),f=()=>{let r=c.trim();r&&(i({...e,[r]:u},t,n),l(``),d(``),s(!1))},p=r=>{let{[r]:a,...o}=e;i(o,t,n)},m=(r,a)=>{i({...e,[r]:a},t,n)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`label`,{className:`text-[11px] font-medium text-gray-500 w-20 shrink-0`,children:`_.file`}),(0,K.jsx)(`input`,{value:t,onChange:t=>i(e,t.target.value,n),readOnly:r,placeholder:`.env (load from dotenv file)`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`label`,{className:`text-[11px] font-medium text-gray-500 w-20 shrink-0`,children:`_.path`}),(0,K.jsx)(`input`,{value:n.join(`, `),onChange:n=>i(e,t,n.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)),readOnly:r,placeholder:`./node_modules/.bin (comma-separated PATH additions)`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Variables`}),!r&&(0,K.jsxs)(`button`,{onClick:()=>s(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add`]})]}),a.length===0&&!o&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-2`,children:`No env vars set.`}),a.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-1/3`,children:`Name`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Value`}),!r&&(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:a.map(([a,o])=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:r?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:a}):(0,K.jsx)(`input`,{value:a,onChange:r=>{let{[a]:o,...s}=e;i({...s,[r.target.value]:o},t,n)},className:mZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:r?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-600`,children:o}):(0,K.jsx)(`input`,{value:o,onChange:e=>m(a,e.target.value),className:mZ})}),!r&&(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>p(a),className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:12})})})]},a))})]})}),!r&&o&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&f(),e.key===`Escape`&&s(!1)},placeholder:`VAR_NAME`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&f()},placeholder:`value`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`button`,{onClick:f,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>s(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]})]})}function TZ({tasks:e,readonly:t,onChange:n}){let r=Object.entries(e),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),u=()=>{let t=c.trim();t&&(n({...e,[t]:{run:``}}),l(``),s(!1),a(t))},d=t=>{let{[t]:r,...o}=e;n(o),i===t&&a(null)},f=(t,r)=>{n({...e,[t]:{...e[t],...r}})};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[r.length===0&&!o&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No tasks defined. Add a build or run task.`}),r.map(([e,n])=>{let r=i===e;return(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(r?null:e),className:`w-full flex items-center gap-2 px-3 py-2 hover:bg-gray-50 transition-colors text-left`,children:[r?(0,K.jsx)(F,{size:12,className:`text-gray-400 shrink-0`}):(0,K.jsx)(I,{size:12,className:`text-gray-400 shrink-0`}),(0,K.jsx)(`code`,{className:`text-[13px] font-medium text-gray-800 flex-1`,children:e}),n.description&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 truncate hidden sm:inline`,children:n.description}),!t&&(0,K.jsx)(`button`,{onClick:t=>{t.stopPropagation(),d(e)},className:`text-gray-300 hover:text-red-500 ml-1`,children:(0,K.jsx)(tt,{size:12})})]}),r&&(0,K.jsxs)(`div`,{className:`border-t border-gray-100 px-4 py-3 space-y-3 bg-gray-50/30`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,K.jsx)(PZ,{label:`Run command`,children:(0,K.jsx)(`input`,{value:n.run??``,onChange:t=>f(e,{run:t.target.value}),readOnly:t,placeholder:`npm run build`,className:pZ})}),(0,K.jsx)(PZ,{label:`Description`,children:(0,K.jsx)(`input`,{value:n.description??``,onChange:t=>f(e,{description:t.target.value}),readOnly:t,placeholder:`Build the project`,className:pZ})}),(0,K.jsx)(PZ,{label:`Working dir`,children:(0,K.jsx)(`input`,{value:n.dir??``,onChange:t=>f(e,{dir:t.target.value}),readOnly:t,placeholder:`{{config_root}}/frontend`,className:pZ})}),(0,K.jsx)(PZ,{label:`Run (Windows)`,children:(0,K.jsx)(`input`,{value:n.runWindows??``,onChange:t=>f(e,{runWindows:t.target.value}),readOnly:t,placeholder:`npm.cmd run build`,className:pZ})}),(0,K.jsx)(PZ,{label:`Depends on (comma-sep)`,children:(0,K.jsx)(`input`,{value:n.depends?.join(`, `)??``,onChange:t=>f(e,{depends:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`lint, test`,className:pZ})}),(0,K.jsx)(PZ,{label:`Wait for (comma-sep)`,children:(0,K.jsx)(`input`,{value:n.waitFor?.join(`, `)??``,onChange:t=>f(e,{waitFor:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`db:5432`,className:pZ})}),(0,K.jsx)(PZ,{label:`Sources (comma-sep)`,children:(0,K.jsx)(`input`,{value:n.sources?.join(`, `)??``,onChange:t=>f(e,{sources:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`src/**/*.ts`,className:pZ})}),(0,K.jsx)(PZ,{label:`Outputs (comma-sep)`,children:(0,K.jsx)(`input`,{value:n.outputs?.join(`, `)??``,onChange:t=>f(e,{outputs:t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)}),readOnly:t,placeholder:`dist/**/*.js`,className:pZ})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-gray-600 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:n.hide??!1,onChange:t=>f(e,{hide:t.target.checked||void 0}),disabled:t,className:`h-3.5 w-3.5 rounded border-gray-300`}),`Hide in `,(0,K.jsx)(`code`,{className:`text-[11px] bg-gray-100 px-1 rounded`,children:`mise run`}),` list`]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-[12px] text-gray-600 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:n.raw??!1,onChange:t=>f(e,{raw:t.target.checked||void 0}),disabled:t,className:`h-3.5 w-3.5 rounded border-gray-300`}),`Raw (pass directly to shell)`]})]}),(0,K.jsxs)(`details`,{className:`text-[11px]`,children:[(0,K.jsxs)(`summary`,{className:`text-gray-400 cursor-pointer hover:text-gray-600`,children:[`Task environment variables (`,Object.keys(n.env??{}).length,`)`]}),(0,K.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[Object.entries(n.env??{}).map(([r,i])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{value:r,onChange:t=>{let i={...n.env??{}},a=i[r]??``;delete i[r],i[t.target.value]=a,f(e,{env:i})},readOnly:t,placeholder:`VAR`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-40`}),(0,K.jsx)(`span`,{className:`text-gray-400`,children:`=`}),(0,K.jsx)(`input`,{value:i,onChange:t=>{f(e,{env:{...n.env??{},[r]:t.target.value}})},readOnly:t,placeholder:`value`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),!t&&(0,K.jsx)(`button`,{onClick:()=>{let{[r]:t,...i}=n.env??{};f(e,{env:Object.keys(i).length>0?i:void 0})},className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:11})})]},r)),!t&&(0,K.jsxs)(`button`,{onClick:()=>f(e,{env:{...n.env??{},"":``}}),className:`text-[10px] text-gray-400 hover:text-gray-600 inline-flex items-center gap-1 mt-1`,children:[(0,K.jsx)(Re,{size:10}),` add env var`]})]})]})]})]},e)}),!t&&(0,K.jsx)(K.Fragment,{children:o?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&u(),e.key===`Escape`&&s(!1)},placeholder:`task name`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`button`,{onClick:u,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>s(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>s(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add task`]})})]})}function EZ({alias:e,readonly:t,onChange:n}){let[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(!1),d=()=>{let t=r.trim(),l=a.trim();!t||!l||(n({...e,[t]:{...e[t]??{},[l]:s.trim()||`latest`}}),i(``),o(``),c(``),u(!1))},f=(t,r)=>{let{[r]:i,...a}=e[t];if(Object.keys(a).length===0){let{[t]:r,...i}=e;n(i)}else n({...e,[t]:a})},p=Object.entries(e);return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[p.length===0&&!l&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No aliases. Create version aliases for tools (e.g. node:myapp → 22.11.0).`}),p.map(([e,n])=>(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:[(0,K.jsx)(`div`,{className:`px-3 py-2 bg-gray-50/50 border-b border-gray-100 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:e}),Object.entries(n).map(([n,r])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-gray-50 hover:bg-gray-50/50`,children:[(0,K.jsx)(`code`,{className:`text-[12px] text-gray-600 w-32 truncate`,children:n}),(0,K.jsx)(`span`,{className:`text-gray-300`,children:`→`}),(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800 flex-1`,children:r}),!t&&(0,K.jsx)(`button`,{onClick:()=>f(e,n),className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:11})})]},n))]},e)),!t&&(0,K.jsx)(K.Fragment,{children:l?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d(),e.key===`Escape`&&u(!1)},placeholder:`tool (e.g. node)`,className:mZ}),(0,K.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`alias (e.g. myapp)`,className:mZ}),(0,K.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`version`,className:mZ})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:d,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>u(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>u(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add alias`]})})]})}var DZ=[{key:`always_keep_download`,label:`Always keep download`,type:`bool`,desc:`Keep downloaded archives after install`},{key:`always_keep_install`,label:`Always keep install`,type:`bool`,desc:`Keep install directory after uninstall`},{key:`legacy_version_file`,label:`Legacy version file`,type:`bool`,desc:`Read .node-version, .python-version, etc.`},{key:`jobs`,label:`Jobs`,type:`number`,desc:`Parallel install jobs (default: 4)`},{key:`experimental`,label:`Experimental`,type:`bool`,desc:`Enable experimental features`},{key:`yes`,label:`Yes`,type:`bool`,desc:`Auto-answer yes to prompts`},{key:`quiet`,label:`Quiet`,type:`bool`,desc:`Suppress non-error output`},{key:`verbose`,label:`Verbose`,type:`bool`,desc:`Show extra debug output`},{key:`raw`,label:`Raw`,type:`bool`,desc:`Pass commands directly to shell`},{key:`color`,label:`Color`,type:`bool`,desc:`Enable colored output`},{key:`pipx_uvx`,label:`pipx / uvx`,type:`bool`,desc:`Use uvx for pipx operations`},{key:`python_venv_auto_create`,label:`Python venv auto-create`,type:`bool`,desc:`Auto-create venv when entering dir`},{key:`python_default_packages_file`,label:`Python default packages file`,type:`string`,desc:`Default pip packages file`,placeholder:`~/.default-python-packages`},{key:`node_mirror_url`,label:`Node mirror URL`,type:`string`,desc:`Custom nodejs.org mirror`},{key:`python_mirror_url`,label:`Python mirror URL`,type:`string`,desc:`Custom python.org mirror`},{key:`plugin_autoupdate_last_check_duration`,label:`Plugin autoupdate check`,type:`string`,desc:`Duration between update checks`,placeholder:`7d`},{key:`trusted_config_paths`,label:`Trusted config paths`,type:`string[]`,desc:`Paths to trust (comma-separated)`,placeholder:`/path/to/trusted`}];function OZ({settings:e,readonly:t,onChange:n}){let r=(t,r)=>{if(r===null||r===``||r===void 0||typeof r==`boolean`&&r===!0){let{[t]:r,...i}=e;n(i)}else n({...e,[t]:r})},i=new Set(Object.keys(e)),a=DZ.filter(e=>i.has(e.key)||e.type===`bool`),o=Object.entries(e).filter(([e])=>!DZ.some(t=>t.key===e));return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[a.map(n=>{let i=e[n.key],a=i!==void 0;return(0,K.jsxs)(`div`,{className:`flex items-start gap-3 py-1.5 border-b border-gray-50`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:n.label}),!a&&(0,K.jsx)(`span`,{className:`text-[9px] text-gray-300`,children:`default`})]}),(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400`,children:n.desc})]}),(0,K.jsx)(`div`,{className:`shrink-0`,children:n.type===`bool`?(0,K.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:i===!0,onChange:e=>r(n.key,e.target.checked||null),disabled:t,className:`sr-only peer`}),(0,K.jsx)(`div`,{className:`w-8 h-4.5 bg-gray-200 peer-checked:bg-gray-900 rounded-full transition-colors after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-3.5 after:w-3.5 after:transition-transform peer-checked:after:translate-x-[14px]`})]}):n.type===`number`?(0,K.jsx)(`input`,{type:`number`,value:i??``,onChange:e=>r(n.key,e.target.value?Number(e.target.value):null),readOnly:t,placeholder:n.placeholder,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-24`}):(0,K.jsx)(`input`,{value:i??``,onChange:e=>r(n.key,e.target.value||null),readOnly:t,placeholder:n.placeholder,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-48`})})]},n.key)}),o.length>0&&(0,K.jsxs)(`div`,{className:`border-t border-gray-200 pt-3 mt-3`,children:[(0,K.jsx)(`span`,{className:`text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Custom`}),o.map(([i,a])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(`input`,{value:i,readOnly:!0,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-40`}),(0,K.jsx)(`input`,{value:String(a),onChange:e=>r(i,e.target.value),readOnly:t,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),!t&&(0,K.jsx)(`button`,{onClick:()=>{let{[i]:t,...r}=e;n(r)},className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:11})})]},i))]}),!t&&(0,K.jsx)(kZ,{onAdd:(t,r)=>n({...e,[t]:r})})]})}function kZ({onAdd:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),s=()=>{let t=r.trim();t&&(e(t,a),i(``),o(``),n(!1))};return t?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&n(!1)},placeholder:`setting key`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s()},placeholder:`value`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>n(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add custom setting`]})}function AZ({plugins:e,readonly:t,onChange:n}){let r=Object.entries(e),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),u=()=>{let t=o.trim();t&&(n({...e,[t]:c.trim()||`https://github.com/asdf-community/asdf-${t}.git`}),s(``),l(``),a(!1))},d=t=>{let{[t]:r,...i}=e;n(i)};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[r.length===0&&!i&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No plugins. Add asdf-compatible plugin sources for tools not in the default registry.`}),r.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Plugin`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`URL`}),!t&&(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:r.map(([r,i])=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:r}):(0,K.jsx)(`input`,{value:r,onChange:t=>{let{[r]:i,...a}=e;n({...a,[t.target.value]:i})},className:mZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:t?(0,K.jsx)(`code`,{className:`text-[11px] text-gray-500 truncate block max-w-xs`,children:i}):(0,K.jsx)(`input`,{value:i,onChange:t=>n({...e,[r]:t.target.value}),className:mZ})}),!t&&(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>d(r),className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:12})})})]},r))})]})}),!t&&(0,K.jsx)(K.Fragment,{children:i?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&u(),e.key===`Escape`&&a(!1)},placeholder:`plugin name (e.g. rust)`,className:mZ}),(0,K.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&u()},placeholder:`git URL (or leave empty for default)`,className:mZ})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:u,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>a(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>a(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:11}),` add plugin`]})})]})}var jZ=[`enter`,`leave`,`cd`,`preinstall`,`postinstall`];function MZ({hooks:e,readonly:t,onChange:n}){let r=(t,r)=>{if(r.trim())n({...e,[t]:r});else{let{[t]:r,...i}=e;n(i)}};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`text-[11px] text-gray-500 mb-2`,children:[`Commands that run on lifecycle events. Use `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded text-[10px]`,children:`{{env.PWD}}`}),` for template variables.`]}),jZ.map(n=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`code`,{className:`text-[11px] font-medium text-gray-600 w-24 shrink-0`,children:n}),(0,K.jsx)(`input`,{value:e[n]??``,onChange:e=>r(n,e.target.value),readOnly:t,placeholder:`echo '${n} hook'`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`})]},n)),Object.entries(e).filter(([e])=>!jZ.includes(e)).map(([i,a])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`input`,{value:i,readOnly:!0,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-24 shrink-0`}),(0,K.jsx)(`input`,{value:a,onChange:e=>r(i,e.target.value),readOnly:t,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),!t&&(0,K.jsx)(`button`,{onClick:()=>{let{[i]:t,...r}=e;n(r)},className:`text-gray-300 hover:text-red-500`,children:(0,K.jsx)(tt,{size:11})})]},i)),!t&&(0,K.jsx)(NZ,{onAdd:(t,r)=>n({...e,[t]:r})})]})}function NZ({onAdd:e}){let[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(``),s=()=>{let t=r.trim();t&&(e(t,a),i(``),o(``),n(!1))};return t?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s(),e.key===`Escape`&&n(!1)},placeholder:`hook event`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-32`}),(0,K.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&s()},placeholder:`command`,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono flex-1`}),(0,K.jsx)(`button`,{onClick:s,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>n(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>n(!0),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 mt-1`,children:[(0,K.jsx)(Re,{size:11}),` add custom hook`]})}function PZ({label:e,children:t}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-[10px] font-medium text-gray-400 uppercase tracking-wider`,children:e}),t]})}var FZ=`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono`;function IZ(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!0),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(`providers`),f=(0,_.useCallback)(async()=>{r(!0),s(null),t(await Mh()),r(!1)},[]);(0,_.useEffect)(()=>{f()},[f]);let p=async n=>{if(!e)return;let r={...e,...n};t(r),a(!0),s(null);let i=await Nh(r);if(a(!1),!i){s(`save failed`);return}l(!0),setTimeout(()=>l(!1),2500)};return n&&!e?(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-12 text-center`,children:`loading presets…`}):e?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1 bg-gray-100 rounded-lg p-0.5 w-fit`,children:[(0,K.jsxs)(`button`,{onClick:()=>d(`providers`),className:`px-3 py-1 rounded text-[11px] font-medium transition-colors flex items-center gap-1.5 ${u===`providers`?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[(0,K.jsx)(te,{size:12}),` AI Providers`]}),(0,K.jsxs)(`button`,{onClick:()=>d(`mise-tools`),className:`px-3 py-1 rounded text-[11px] font-medium transition-colors flex items-center gap-1.5 ${u===`mise-tools`?`bg-white text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[(0,K.jsx)(ct,{size:12}),` Mise Tools`]})]}),u===`providers`&&(0,K.jsx)(LZ,{presets:e.providerPresets,onChange:e=>p({providerPresets:e}),saving:i}),u===`mise-tools`&&(0,K.jsx)(RZ,{presets:e.miseToolPresets,onChange:e=>p({miseToolPresets:e}),saving:i}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[o&&(0,K.jsx)(`span`,{className:`text-[12px] text-red-600`,children:o}),c&&(0,K.jsxs)(`span`,{className:`text-[12px] text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:13}),` saved`]})]})]}):(0,K.jsx)(`div`,{className:`text-[12px] text-red-600 py-12 text-center`,children:`failed to load presets`})}function LZ({presets:e,onChange:t,saving:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),d=()=>{let n=a.trim();if(!n||!s.trim())return;let r=l.trim()?l.split(`
|
|
160
|
+
`).map(e=>e.trim()).filter(Boolean):[];t([...e,{name:n,baseUrl:s.trim(),models:r}]),o(``),c(``),u(``),i(!1)},f=n=>{t(e.filter((e,t)=>t!==n))},p=(n,r)=>{t(e.map((e,t)=>t===n?{...e,...r}:e))};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.length===0&&!r&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No provider presets. Add one to get started.`}),e.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-1/5`,children:`Name`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Base URL`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Models`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:e.map((e,t)=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{value:e.name,onChange:e=>p(t,{name:e.target.value}),disabled:n,className:FZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{value:e.baseUrl,onChange:e=>p(t,{baseUrl:e.target.value}),disabled:n,className:FZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,K.jsx)(`textarea`,{value:e.models.join(`
|
|
161
161
|
`),onChange:e=>p(t,{models:e.target.value.split(`
|
|
162
|
-
`).map(e=>e.trim()).filter(Boolean)}),disabled:n,rows:Math.max(1,e.models.length),className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono resize-none`})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>f(t),disabled:n,className:`text-gray-300 hover:text-red-500 transition-colors disabled:opacity-30`,children:(0,K.jsx)(tt,{size:12})})})]},t))})]})}),r?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d(),e.key===`Escape`&&i(!1)},placeholder:`Provider name`,className:PZ}),(0,K.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`Base URL`,className:PZ})]}),(0,K.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),placeholder:`Models (one per line)`,rows:3,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono resize-none`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:d,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>i(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>i(!0),disabled:n,className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors disabled:opacity-50`,children:[(0,K.jsx)(Re,{size:11}),` add provider preset`]})]})}function LZ({presets:e,onChange:t,saving:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(``),p=()=>{let n=a.trim();!n||!s.trim()||(t([...e,{name:n,suggestedVersion:s.trim(),description:l.trim()||void 0,backend:d.trim()||void 0}]),o(``),c(``),u(``),f(``),i(!1))},m=n=>{t(e.filter((e,t)=>t!==n))},h=(n,r)=>{t(e.map((e,t)=>t===n?{...e,...r}:e))};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.length===0&&!r&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No mise tool presets. Add one to get started.`}),e.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Tool`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Description`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Backend`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:e.map((e,t)=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{value:e.name,onChange:e=>h(t,{name:e.target.value}),disabled:n,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-24`})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{value:e.suggestedVersion,onChange:e=>h(t,{suggestedVersion:e.target.value}),disabled:n,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-20`})}),(0,K.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,K.jsx)(`input`,{value:e.description??``,onChange:e=>h(t,{description:e.target.value||void 0}),disabled:n,placeholder:`optional`,className:PZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,K.jsx)(`input`,{value:e.backend??``,onChange:e=>h(t,{backend:e.target.value||void 0}),disabled:n,placeholder:`optional`,className:PZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>m(t),disabled:n,className:`text-gray-300 hover:text-red-500 transition-colors disabled:opacity-30`,children:(0,K.jsx)(tt,{size:12})})})]},t))})]})}),r?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&p(),e.key===`Escape`&&i(!1)},placeholder:`Tool name (e.g. python)`,className:PZ}),(0,K.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&p()},placeholder:`Suggested version (e.g. 3.12)`,className:PZ})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,K.jsx)(`input`,{value:l,onChange:e=>u(e.target.value),placeholder:`Description (optional)`,className:PZ}),(0,K.jsx)(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`Backend (optional, e.g. aqua:sharkdp/fd)`,className:PZ})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:p,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>i(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>i(!0),disabled:n,className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors disabled:opacity-50`,children:[(0,K.jsx)(Re,{size:11}),` add mise tool preset`]})]})}function RZ(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function zZ(e){return new Date(e).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}function BZ(e){return new Date(e).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})}function VZ(e){let t=new Date;return t.setDate(t.getDate()-e),t.toISOString().slice(0,10)}function HZ(e){return e?e===`desc`?`asc`:null:`desc`}function UZ({label:e,field:t,sortField:n,sortDir:r,onSort:i,className:a}){let o=n===t;return(0,K.jsx)(`th`,{className:`px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider cursor-pointer select-none hover:text-gray-700 transition-colors ${a??``}`,onClick:()=>i(t),children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e,o&&r===`desc`?(0,K.jsx)(T,{className:`h-3 w-3`}):o&&r===`asc`?(0,K.jsx)(O,{className:`h-3 w-3`}):(0,K.jsx)(D,{className:`h-3 w-3 opacity-30`})]})})}function WZ({data:e,maxVal:t,height:n=24,gap:r=6}){return(0,K.jsx)(`svg`,{width:280,height:e.length*(n+r),className:`shrink-0`,children:e.map((e,i)=>{let a=i*(n+r),o=t>0?e.input/t*280:0,s=t>0?e.output/t*280:0;return(0,K.jsxs)(`g`,{children:[(0,K.jsx)(`rect`,{x:0,y:a,width:o,height:n,rx:3,fill:`var(--color-blue-500)`,opacity:.7}),(0,K.jsx)(`rect`,{x:o,y:a,width:s,height:n,rx:3,fill:`var(--color-green-500)`,opacity:.7}),(0,K.jsx)(`text`,{x:o+s+4,y:a+n/2,dominantBaseline:`central`,className:`fill-gray-500 text-[10px]`,children:e.label})]},e.label)})})}function GZ({data:e,w:t=600,h:n=180}){let r={top:10,right:10,bottom:24,left:50},i=t-r.left-r.right,a=n-r.top-r.bottom,o=Math.max(1,...e.map(e=>e.input+e.output)),s=t=>r.left+(e.length>1?t/(e.length-1)*i:i/2),c=e=>r.top+a-e/o*a,l=e.map((e,t)=>`${s(t)},${c(e.input)}`).join(` `),u=e.map((e,t)=>`${s(t)},${c(e.input+e.output)}`).join(` `),d=`${s(e.length-1)},${r.top+a} ${s(0)},${r.top+a}`,f=[0,o/2,o].map(e=>({y:c(e),label:RZ(e)}));return(0,K.jsxs)(`svg`,{width:t,height:n,className:`w-full`,viewBox:`0 0 ${t} ${n}`,preserveAspectRatio:`xMidYMid meet`,children:[f.map(e=>(0,K.jsxs)(`g`,{children:[(0,K.jsx)(`line`,{x1:r.left,y1:e.y,x2:t-r.right,y2:e.y,stroke:`var(--color-gray-200)`,strokeDasharray:`3,2`}),(0,K.jsx)(`text`,{x:r.left-6,y:e.y,textAnchor:`end`,dominantBaseline:`central`,className:`fill-gray-400 text-[9px]`,children:e.label})]},e.label)),(0,K.jsx)(`polygon`,{points:`${u} ${d}`,fill:`var(--color-green-500)`,opacity:.2}),(0,K.jsx)(`polyline`,{points:u,fill:`none`,stroke:`var(--color-green-500)`,strokeWidth:1.5,opacity:.6}),(0,K.jsx)(`polygon`,{points:`${l} ${d}`,fill:`var(--color-blue-500)`,opacity:.2}),(0,K.jsx)(`polyline`,{points:l,fill:`none`,stroke:`var(--color-blue-500)`,strokeWidth:1.5}),e.filter((t,n)=>e.length<=14||n%Math.ceil(e.length/14)===0||n===e.length-1).map((t,r)=>(0,K.jsx)(`text`,{x:s(e.indexOf(t)),y:n-4,textAnchor:`middle`,className:`fill-gray-400 text-[9px]`,children:zZ(t.date)},t.date))]})}function KZ({dailyUsage:e,timeRange:t}){let[n,r]=(0,_.useState)(`total`),[i,a]=(0,_.useState)(`desc`),[o,s]=(0,_.useState)(!1),c=(0,_.useMemo)(()=>{let n=t===`today`?VZ(0):t===`7d`?VZ(7):t===`30d`?VZ(30):``,r={};for(let[t,i]of Object.entries(e))for(let[e,a]of Object.entries(i)){if(n&&e<n)continue;let i=r[t]??{inputTokens:0,outputTokens:0,cacheReadInputTokens:0};i.inputTokens+=a.inputTokens,i.outputTokens+=a.outputTokens,i.cacheReadInputTokens+=a.cacheReadInputTokens??0,r[t]=i}return Object.entries(r).map(([e,t])=>({model:e,...t,total:t.inputTokens+t.outputTokens,cacheRate:t.inputTokens+t.cacheReadInputTokens>0?Math.round(t.cacheReadInputTokens/(t.inputTokens+t.cacheReadInputTokens)*100):0}))},[e,t]),l=(0,_.useMemo)(()=>{let e=[...c];return n&&i&&e.sort((e,t)=>{let r=n===`model`?e.model:e[n]??0,a=n===`model`?t.model:t[n]??0;return typeof r==`string`&&typeof a==`string`?i===`desc`?a.localeCompare(r):r.localeCompare(a):i===`desc`?a-r:r-a}),e},[c,n,i]),u=e=>{if(n===e){let e=HZ(i);e?a(e):(r(null),a(null))}else r(e),a(`desc`)},d=l.reduce((e,t)=>e+t.total,0),f=Math.max(...l.map(e=>e.total),1),p=o?l:l.slice(0,10),m=p.map(e=>({label:e.model,input:e.inputTokens,output:e.outputTokens}));return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-4 gap-3 mb-6`,children:[(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Total Tokens`}),(0,K.jsx)(`div`,{className:`text-xl font-semibold text-gray-900`,children:RZ(d)})]}),(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Prompt`}),(0,K.jsx)(`div`,{className:`text-xl font-semibold text-blue-600`,children:RZ(l.reduce((e,t)=>e+t.inputTokens,0))})]}),(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Completion`}),(0,K.jsx)(`div`,{className:`text-xl font-semibold text-green-600`,children:RZ(l.reduce((e,t)=>e+t.outputTokens,0))})]}),(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Cached Tokens`}),(0,K.jsx)(`div`,{className:`text-xl font-semibold text-purple-600`,children:RZ(l.reduce((e,t)=>e+t.cacheReadInputTokens,0))}),(0,K.jsx)(`div`,{className:`text-[11px] text-purple-400 mt-0.5`,children:(()=>{let e=l.reduce((e,t)=>e+t.cacheReadInputTokens,0),t=l.reduce((e,t)=>e+t.inputTokens,0);return t+e>0?`${Math.round(e/(t+e)*100)}% of potential input`:`—`})()})]})]}),p.length>0&&(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4 mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mb-3`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Token Distribution`}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-blue-500 opacity-70`}),` Input`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-green-500 opacity-70`}),` Output`]})]}),(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsx)(WZ,{data:m,maxVal:f})})]}),(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,K.jsx)(UZ,{label:`Model`,field:`model`,sortField:n,sortDir:i,onSort:u,className:`text-left`}),(0,K.jsx)(UZ,{label:`Input`,field:`inputTokens`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,K.jsx)(UZ,{label:`Output`,field:`outputTokens`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,K.jsx)(UZ,{label:`Total`,field:`total`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,K.jsx)(UZ,{label:`Cached`,field:`cacheRate`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,K.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`%`})]})}),(0,K.jsxs)(`tbody`,{children:[p.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:e.model})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-blue-600 tabular-nums`,children:RZ(e.inputTokens)}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-green-600 tabular-nums`,children:RZ(e.outputTokens)}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:RZ(e.total)}),(0,K.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-purple-600 tabular-nums`,children:[RZ(e.cacheReadInputTokens),` `,(0,K.jsxs)(`span`,{className:`text-[10px] text-purple-400`,children:[`(`,e.cacheRate,`%)`]})]}),(0,K.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[11px] text-gray-400 tabular-nums`,children:[d>0?(e.total/d*100).toFixed(1):0,`%`]})]},e.model)),p.length===0&&(0,K.jsx)(`tr`,{children:(0,K.jsx)(`td`,{colSpan:6,className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:`No token usage data`})})]})]}),l.length>10&&(0,K.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 bg-gray-50/50`,children:(0,K.jsx)(`button`,{onClick:()=>s(!o),className:`text-[11px] text-gray-500 hover:text-gray-900 transition-colors`,children:o?`Show less`:`Show all ${l.length} models`})})]})]})}function qZ({dailyUsage:e,timeRange:t}){let{dates:n,models:r,data:i,chartData:a}=(0,_.useMemo)(()=>{let n=new Set(Object.keys(e)),r=new Set;for(let t of Object.keys(e))for(let n of Object.keys(e[t]))r.add(n);let i=Array.from(r).sort(),a=Array.from(n).sort(),o=t===`today`?VZ(0):t===`7d`?VZ(7):t===`30d`?VZ(30):``,s=o?i.filter(e=>e>=o):i,c={};for(let t of a){c[t]={};for(let n of s)c[t][n]=(e[t]?.[n]?.inputTokens??0)+(e[t]?.[n]?.outputTokens??0)}return{dates:s,models:a,data:c,chartData:s.map(t=>{let n=0,r=0;for(let i of a)n+=e[i]?.[t]?.inputTokens??0,r+=e[i]?.[t]?.outputTokens??0;return{date:t,input:n,output:r}})}},[e,t]);return n.length===0?(0,K.jsx)(`div`,{className:`text-center py-8 text-[12px] text-gray-400 italic`,children:`No daily data for this time range`}):(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4 mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Daily Trend`}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-blue-500 opacity-70`}),` Input`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-green-500 opacity-20`}),` Output`]})]}),(0,K.jsx)(GZ,{data:a})]}),(0,K.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full min-w-[500px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,K.jsx)(`th`,{className:`text-left px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider sticky left-0 bg-gray-50/50`,children:`Date`}),(0,K.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Total`}),r.map(e=>(0,K.jsx)(`th`,{className:`text-right px-3 py-2.5 text-[10px] font-medium text-gray-400 uppercase tracking-wider max-w-[120px]`,children:(0,K.jsx)(`span`,{className:`truncate block`,children:e})},e))]})}),(0,K.jsx)(`tbody`,{children:n.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2 text-[12px] text-gray-700 sticky left-0 bg-white`,children:zZ(e)}),(0,K.jsx)(`td`,{className:`px-4 py-2 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:RZ(r.reduce((t,n)=>t+(i[n]?.[e]??0),0))}),r.map(t=>(0,K.jsx)(`td`,{className:`px-3 py-2 text-right text-[11px] text-gray-500 tabular-nums`,children:i[t]?.[e]?RZ(i[t][e]):``},t))]},e))})]})})})]})}function JZ({loopUsage:e,timeRange:t}){let[n,r]=(0,_.useState)(`lastActivity`),[i,a]=(0,_.useState)(`desc`),o=t===`today`?VZ(0):t===`7d`?VZ(7):t===`30d`?VZ(30):``,s=(0,_.useMemo)(()=>{let t=o?e.filter(e=>(e.lastActivity??``).slice(0,10)>=o):[...e];return n&&i&&t.sort((e,t)=>{let r,a;return n===`total`?(r=e.inputTokens+e.outputTokens,a=t.inputTokens+t.outputTokens):n===`title`||n===`lastActivity`?(r=e[n]??``,a=t[n]??``):(r=e[n]??0,a=t[n]??0),typeof r==`string`&&typeof a==`string`?i===`desc`?a.localeCompare(r):r.localeCompare(a):i===`desc`?a-r:r-a}),t},[e,o,n,i]),c=e=>{if(n===e){let e=HZ(i);e?a(e):(r(null),a(null))}else r(e),a(`desc`)},l=s.reduce((e,t)=>e+t.inputTokens+t.outputTokens,0),u=zn();return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex items-center gap-4 mb-4 px-1`,children:(0,K.jsxs)(`span`,{className:`text-[13px] text-gray-600`,children:[(0,K.jsx)(`span`,{className:`font-semibold text-gray-900`,children:s.length}),` loops ·`,` `,(0,K.jsx)(`span`,{className:`font-semibold text-gray-900`,children:RZ(l)}),` total tokens`]})}),(0,K.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,K.jsx)(UZ,{label:`Loop`,field:`title`,sortField:n,sortDir:i,onSort:c,className:`text-left`}),(0,K.jsx)(`th`,{className:`hidden sm:table-cell text-left px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Models`}),(0,K.jsx)(UZ,{label:`Input`,field:`inputTokens`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,K.jsx)(UZ,{label:`Output`,field:`outputTokens`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,K.jsx)(UZ,{label:`Total`,field:`total`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,K.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Cached`}),(0,K.jsx)(UZ,{label:`Last active`,field:`lastActivity`,sortField:n,sortDir:i,onSort:c,className:`text-right hidden sm:table-cell`})]})}),(0,K.jsxs)(`tbody`,{children:[s.map(e=>{let t=e.inputTokens+e.outputTokens,n=e.inputTokens+e.cacheReadInputTokens>0?Math.round(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens)*100):0;return(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors cursor-pointer`,onClick:()=>u(`/loop/${e.loopId}`),children:[(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-[12px] text-gray-800 font-medium hover:text-blue-600`,children:e.title})}),(0,K.jsx)(`td`,{className:`hidden sm:table-cell px-4 py-2.5`,children:(0,K.jsx)(`code`,{className:`text-[11px] text-gray-500`,children:e.model})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-blue-600 tabular-nums`,children:RZ(e.inputTokens)}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-green-600 tabular-nums`,children:RZ(e.outputTokens)}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:RZ(t)}),(0,K.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-purple-600 tabular-nums`,children:[RZ(e.cacheReadInputTokens),` `,(0,K.jsxs)(`span`,{className:`text-[10px] text-purple-400`,children:[`(`,n,`%)`]})]}),(0,K.jsx)(`td`,{className:`hidden sm:table-cell px-4 py-2.5 text-right text-[11px] text-gray-400`,children:BZ(e.lastActivity)})]},e.loopId)}),s.length===0&&(0,K.jsx)(`tr`,{children:(0,K.jsxs)(`td`,{colSpan:6,className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:[`No loops with token usage`,o?` in this range`:``]})})]})]})})]})}var YZ=[{id:`today`,label:`Today`},{id:`7d`,label:`7 days`},{id:`30d`,label:`30 days`},{id:`all`,label:`All time`}],XZ=[{id:`models`,label:`By Model`,icon:(0,K.jsx)(ye,{className:`h-3.5 w-3.5`})},{id:`daily`,label:`Daily`,icon:(0,K.jsx)(N,{className:`h-3.5 w-3.5`})},{id:`loops`,label:`By Loop`,icon:(0,K.jsx)(Oe,{className:`h-3.5 w-3.5`})}];function ZZ(){zn();let[e,t]=(0,_.useState)(`models`),[n,r]=(0,_.useState)(`30d`),[i,a]=(0,_.useState)({}),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{l(!0),Promise.all([Ah().then(a),jh().then(s)]).finally(()=>l(!1))},[]),c?(0,K.jsx)(`div`,{className:`h-full flex items-center justify-center bg-gray-50`,children:(0,K.jsx)(`div`,{className:`text-[13px] text-gray-400`,children:`loading token data…`})}):(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1 mb-6`,children:[XZ.map(n=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded text-[12px] font-medium transition-colors ${e===n.id?`bg-white border border-gray-200 text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[n.icon,n.label]},n.id)),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`div`,{className:`flex items-center gap-0.5`,children:YZ.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>r(e.id),className:`px-2 py-1 rounded text-[11px] font-medium transition-colors ${n===e.id?`bg-white border border-gray-200 text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:e.label},e.id))})]}),e===`models`&&(0,K.jsx)(KZ,{dailyUsage:i,timeRange:n}),e===`daily`&&(0,K.jsx)(qZ,{dailyUsage:i,timeRange:n}),e===`loops`&&(0,K.jsx)(JZ,{loopUsage:o,timeRange:n})]})}var QZ=`w-full px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900 transition-colors disabled:bg-gray-50 disabled:text-gray-400`;function $Z(e){return`${e.replace(/[^A-Za-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).toUpperCase()||`PROVIDER`}_API_KEY`}var eQ=[{id:`personal-repo`,label:`Personal Repo`,gated:!1,description:`Your private repo carrying credentials + dotfiles.`,icon:ot},{id:`providers`,label:`AI Providers`,gated:!0,description:`Models, base URLs, API keys. Pick a default.`,icon:te},{id:`claude-config`,label:`Claude Config`,gated:!0,description:`Compose your .claude/ tiers — plugins, MCP servers, settings per tier.`,icon:xe},{id:`mise-config`,label:`Mise Config`,gated:!0,description:`Configure mise toolchain tools per tier — mise.toml for each tier.`,icon:ct},{id:`token-usage`,label:`Token Usage`,gated:!1,description:`Token consumption across models, loops, and time.`,icon:N},{id:`api-tokens`,label:`API Tokens`,gated:!1,description:`Bearer tokens for external programs to drive your loops via the Loop API. See API docs below.`,icon:be},{id:`admin-users`,label:`Users`,gated:!1,description:`Manage workspace members — activate, promote, remove.`,icon:st},{id:`admin-workspace`,label:`Workspace AI Providers`,gated:!1,description:`Shared workspace provider configuration.`,icon:_e},{id:`admin-serve`,label:`Share Artifact Serve`,gated:!1,description:`Public share domain and HTTPS settings.`,icon:Ke},{id:`admin-presets`,label:`Presets`,gated:!1,description:`Manage preset defaults — AI providers and Mise tool suggestions.`,icon:A}];function tQ(){let e=zn(),t=Cg(),n=t.currentUser?.role===`admin`,{tab:r}=Un(),i=eQ.some(e=>e.id===r)?r:`personal-repo`,[a,o]=(0,_.useState)(!0),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)({}),h=(0,_.useCallback)(async()=>{o(!0);let[e,t]=await Promise.all([Jp(),Th()]);c(!!e&&!!e.personalRepo&&e.imported),u(!e||!e.personalRepo?`no personal repo configured`:e.imported?``:`personal repo not imported yet`),t&&(f(t.disk),m(t.refExists)),o(!1)},[]);(0,_.useEffect)(()=>{$p().catch(()=>{}).finally(()=>{h()})},[h]),(0,_.useEffect)(()=>{!a&&!s&&eQ.find(e=>e.id===i)?.gated&&!i.startsWith(`admin-`)&&e(`/settings/personal-repo`,{replace:!0})},[a,s,i,e]);let g=eQ.find(e=>e.id===i)??eQ[0],v=g.gated&&!s&&!i.startsWith(`admin-`),[y,b]=(0,_.useState)(``),x=eQ.filter(e=>!(e.id.startsWith(`admin-`)&&!n)),S=x.filter(e=>!e.id.startsWith(`admin-`)),C=x.filter(e=>e.id.startsWith(`admin-`)),w=y.trim()===``?x:x.filter(e=>e.label.toLowerCase().includes(y.toLowerCase())||e.description.toLowerCase().includes(y.toLowerCase())||e.id.toLowerCase().includes(y.toLowerCase()));return(0,K.jsxs)(`div`,{className:`h-full overflow-hidden bg-gray-50 flex flex-col`,children:[(0,K.jsxs)(`header`,{className:`shrink-0 border-b border-gray-200 bg-white px-4 sm:px-6 h-12 flex items-center gap-3`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>e(-1),className:`w-8 h-8 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`back`,children:(0,K.jsx)(E,{size:16})}),(0,K.jsx)(`h1`,{className:`text-[15px] font-semibold text-gray-900`,children:`Settings`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e(`/context/personal?file=.loopat/config.json&edit=1`),className:`h-7 px-2.5 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-700 flex items-center gap-1.5`,title:`open raw config.json in Context tab`,children:[(0,K.jsx)(oe,{size:12}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:`edit raw config.json`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:h,disabled:a,className:`h-7 px-2.5 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-700 flex items-center gap-1.5 disabled:opacity-50`,title:`reload`,children:[(0,K.jsx)(Be,{size:12,className:a?`animate-spin`:``}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:`reload`})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col sm:flex-row`,children:[(0,K.jsxs)(`nav`,{className:`sm:w-56 shrink-0 sm:border-r border-b sm:border-b-0 border-gray-200 bg-white flex flex-col`,children:[(0,K.jsx)(`div`,{className:`hidden sm:block px-3 py-3 border-b border-gray-100`,children:(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Ue,{size:12,className:`absolute left-2 top-1/2 -translate-y-1/2 text-gray-400`}),(0,K.jsx)(`input`,{value:y,onChange:e=>b(e.target.value),placeholder:`search settings`,className:`w-full pl-7 pr-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-400 bg-gray-50 focus:bg-white`})]})}),(0,K.jsxs)(`ul`,{className:`flex sm:flex-col gap-0.5 sm:gap-0 p-2 sm:py-2 overflow-x-auto sm:overflow-x-visible`,children:[y.trim()?w.map(t=>{let n=t.id===i,r=t.gated&&!a&&!s;return(0,K.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,K.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,K.jsx)(`span`,{className:`flex-1 truncate`,children:t.label}),r&&(0,K.jsx)(`span`,{title:`locked`,children:(0,K.jsx)(Te,{size:11,className:`text-gray-400 shrink-0`})})]})},t.id)}):(0,K.jsxs)(K.Fragment,{children:[S.map(t=>{let n=t.id===i,r=t.gated&&!a&&!s;return(0,K.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,K.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,K.jsx)(`span`,{className:`flex-1 truncate`,children:t.label}),r&&(0,K.jsx)(`span`,{title:`locked`,children:(0,K.jsx)(Te,{size:11,className:`text-gray-400 shrink-0`})})]})},t.id)}),C.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`li`,{className:`px-3 pt-3 pb-1 text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Admin Settings`}),C.map(t=>{let n=t.id===i;return(0,K.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,K.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,K.jsx)(`span`,{className:`flex-1 truncate`,children:t.label})]})},t.id)})]})]}),w.length===0&&(0,K.jsx)(`li`,{className:`px-3 py-2 text-[11px] text-gray-400 italic`,children:`no match`})]})]}),(0,K.jsx)(`main`,{className:`flex-1 min-w-0 min-h-0 overflow-auto`,children:(0,K.jsx)(`div`,{className:`max-w-4xl mx-auto px-4 sm:px-6 py-5`,children:a&&!d?(0,K.jsx)(`div`,{className:`text-[13px] text-gray-400 italic py-12 text-center`,children:`loading…`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-base font-semibold text-gray-900 flex items-center gap-2`,children:[(0,K.jsx)(g.icon,{size:18,className:`text-gray-400`}),g.label]}),(0,K.jsx)(`p`,{className:`text-xs text-gray-500 mt-0.5`,children:g.description})]}),v&&(0,K.jsxs)(`div`,{className:`mb-4 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 flex items-start gap-2`,children:[(0,K.jsx)(R,{size:16,className:`text-amber-700 mt-0.5 shrink-0`}),(0,K.jsxs)(`div`,{className:`text-[13px] text-amber-900 flex-1`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:`Set up your personal repo first`}),(0,K.jsxs)(`div`,{className:`text-[12px] text-amber-800/90 mt-0.5`,children:[`These settings live in your personal repo. Complete setup in the `,(0,K.jsx)(`button`,{onClick:()=>e(`/settings/personal-repo`),className:`underline`,children:`Personal Repo`}),` tab; this section will unlock automatically.`,(0,K.jsxs)(`span`,{className:`text-amber-700/70`,children:[` (`,l,`)`]})]})]})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[v&&(0,K.jsxs)(`div`,{className:`absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-white/60 backdrop-blur-[1px] rounded-lg`,children:[(0,K.jsx)(Te,{size:24,className:`text-gray-300`}),(0,K.jsx)(`span`,{className:`text-[13px] text-gray-500 font-medium`,children:`Set up your personal repo first`})]}),(0,K.jsxs)(`div`,{className:v?`opacity-30`:``,children:[i===`personal-repo`&&(0,K.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,K.jsx)(FY,{onDone:h})}),i===`providers`&&(0,K.jsx)(nQ,{disk:d,refExists:p,onChanged:h,disabled:v}),i===`claude-config`&&(0,K.jsx)(_X,{disabled:v}),i===`mise-config`&&(0,K.jsx)(_Z,{disabled:v}),i===`token-usage`&&(0,K.jsx)(ZZ,{}),i===`api-tokens`&&(0,K.jsx)(iQ,{}),i===`admin-users`&&(0,K.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,K.jsx)(KY,{currentUserId:t.currentUser?.id??``})}),i===`admin-workspace`&&(0,K.jsx)(YY,{}),i===`admin-serve`&&(0,K.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,K.jsx)(ZY,{})}),i===`admin-presets`&&(0,K.jsx)(FZ,{})]})]})]})})})]})]})}function nQ({disk:e,refExists:t,onChanged:n,disabled:r}){let[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)({}),[y,b]=(0,_.useState)({}),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(``),[T,E]=(0,_.useState)(null),[D,O]=(0,_.useState)(``),[k,A]=(0,_.useState)({}),[j,M]=(0,_.useState)({}),[N,F]=(0,_.useState)([]);(0,_.useEffect)(()=>{Mh().then(e=>F(e.providerPresets)).catch(()=>{})},[]),(0,_.useEffect)(()=>{if(!e){a(null),d(!1);return}let n={default:``,providers:{}};for(let[r,i]of Object.entries(e.providers)){if(r==="default"){typeof i==`string`&&(n.default=i);continue}if(i&&typeof i==`object`){let e=i,a=t[`providers.${r}.apiKey`];n.providers[r]={models:e.models&&e.models.length>0?e.models.map(e=>({id:e.id,enabled:e.enabled!==!1})):e.model?[{id:e.model,enabled:!0}]:[],baseUrl:e.baseUrl??``,maxContextTokens:e.maxContextTokens?String(e.maxContextTokens):``,enabled:e.enabled!==!1,apiKeyNewValue:``,apiKeyStored:!!a?.exists}}}a(n)},[e,t]);let I=i?Object.keys(i.providers):[],L=(e,t)=>{a(n=>!n||!n.providers[e]?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}})},R=e=>{a(t=>{if(!t)return t;let{[e]:n,...r}=t.providers,i=t.default===e||t.default.startsWith(`${e}/`);return{...t,providers:r,default:i?``:t.default}})},z=(e,t,n)=>{a(r=>{if(!r||!r.providers[e])return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,...n}:e);return{...r,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}})},B=(e,t)=>{a(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.map(e=>e.id===t?{...e,enabled:!e.enabled}:e);return{...n,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},V=(e,t)=>{a(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.filter(e=>e.id!==t),i=n.default===`${e}/${t}`;return{...n,default:i?``:n.default,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},H=e=>{let t=(g[e]??``).trim();t&&(a(n=>!n||!n.providers[e]||n.providers[e].models.some(e=>e.id===t)?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],models:[...n.providers[e].models,{id:t,enabled:!0}]}}}),v(t=>({...t,[e]:``})),b(t=>({...t,[e]:!1})))},U=(e,t)=>{let n=D.trim();if(!n||n===t){E(null);return}a(r=>{if(!r||!r.providers[e]||r.providers[e].models.some(e=>e.id===n))return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,id:n}:e),a=r.default===`${e}/${t}`?`${e}/${n}`:r.default;return{...r,default:a,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}}),E(null)},ee=e=>{let t=C.trim();if(!t||t===e||t==="default"){S(null);return}a(n=>{if(!n||!n.providers[e]||n.providers[t])return n;let{[e]:r,...i}=n.providers,a=n.default;return n.default===e?a=t:n.default.startsWith(`${e}/`)&&(a=t+n.default.slice(e.length)),{...n,default:a,providers:{...i,[t]:r}}}),S(null)},W=()=>{let e=f.trim();if(e){if(e==="default"){l(`'default' is reserved`);return}a(t=>!t||t.providers[e]?t:{...t,providers:{...t.providers,[e]:{models:[],baseUrl:``,maxContextTokens:``,enabled:!1,apiKeyNewValue:``,apiKeyStored:!1}}}),p(``),h(!1),l(null)}};return i?(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[I.map(e=>{let t=i.providers[e],n=y[e]??!1,r=t.apiKeyStored||t.apiKeyNewValue.trim()!==``;return(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden transition-shadow hover:shadow-sm`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 bg-gray-50/50 border-b border-gray-100`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2.5 flex-1 min-w-0 select-none`,children:[(0,K.jsx)(WY,{checked:t.enabled,onCheckedChange:t=>r?L(e,{enabled:t}):void 0,disabled:!r,size:`sm`}),x===e?(0,K.jsx)(`input`,{autoFocus:!0,value:C,onChange:e=>w(e.target.value),onBlur:()=>ee(e),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&ee(e),t.key===`Escape`&&S(null)},className:X(QZ,`text-[13px] font-semibold flex-1 min-w-0`)}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>{S(e),w(e)},className:`text-[13px] font-semibold truncate text-left hover:underline ${t.enabled?`text-gray-900`:`text-gray-400`}`,title:`click to rename`,children:e}),!t.enabled&&(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium shrink-0`,children:`disabled`})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>R(e),className:`text-[11px] text-gray-400 hover:text-red-500 transition-colors shrink-0`,children:`remove`})]}),(0,K.jsxs)(`div`,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(rQ,{label:`Base URL`,children:(0,K.jsx)(`input`,{value:t.baseUrl,onChange:t=>L(e,{baseUrl:t.target.value}),placeholder:`https://api.example.com`,className:QZ})}),(0,K.jsx)(rQ,{label:`Max context tokens`,children:(0,K.jsx)(`input`,{type:`number`,value:t.maxContextTokens,onChange:t=>L(e,{maxContextTokens:t.target.value}),placeholder:`auto`,className:QZ})}),(0,K.jsx)(rQ,{label:t.apiKeyStored?`API key (set — type to overwrite)`:`API key`,className:`sm:col-span-2`,children:(0,K.jsx)(`input`,{type:`password`,value:t.apiKeyNewValue,onChange:t=>L(e,{apiKeyNewValue:t.target.value}),placeholder:t.apiKeyStored?`•••••• stored encrypted in vault`:`paste API key`,className:QZ})})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:[`Models (`,t.models.length,`)`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>b(t=>({...t,[e]:!n})),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Re,{size:11}),` add model`]})]}),n&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:g[e]??``,onChange:t=>v(n=>({...n,[e]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&H(e),t.key===`Escape`&&b(t=>({...t,[e]:!1}))},placeholder:`model ID (e.g. claude-sonnet-4-20250514)`,className:X(QZ,`flex-1 text-[11px]`)}),(0,K.jsx)(kg,{size:`xs`,onClick:()=>H(e),children:`add`}),(0,K.jsx)(kg,{variant:`ghost`,size:`xs`,onClick:()=>b(t=>({...t,[e]:!1})),children:`cancel`})]}),t.models.length===0&&!n&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 italic py-2`,children:`no models — add one above`}),(0,K.jsx)(`div`,{className:`-mx-1`,children:t.models.map(n=>{let r=i.default===`${e}/${n.id}`,o=`${e}::${n.id}`,s=T===o,c=k[`${e}::${n.id}`],l=j[`${e}::${n.id}`];return(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 py-1.5 rounded group hover:bg-gray-50 transition-colors`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>a(t=>t&&{...t,default:r?``:`${e}/${n.id}`}),className:`shrink-0 text-[13px] leading-none transition-colors ${r?`text-amber-500`:`text-gray-200 hover:text-amber-400`}`,title:r?`current default model`:`set as default model`,children:`★`}),(0,K.jsx)(`label`,{className:`flex items-center shrink-0 cursor-pointer`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:n.enabled!==!1,onChange:()=>B(e,n.id),className:`h-3.5 w-3.5 rounded border-gray-300 text-gray-900 accent-gray-900`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1`,children:[s?(0,K.jsx)(`input`,{autoFocus:!0,value:D,onChange:e=>O(e.target.value),onBlur:()=>U(e,n.id),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&U(e,n.id),t.key===`Escape`&&E(null)},className:X(QZ,`text-[11px] flex-1 min-w-0`)}):(0,K.jsx)(`code`,{className:`text-[12px] truncate cursor-pointer hover:bg-gray-100 px-0.5 rounded ${n.enabled===!1?`text-gray-300 line-through`:`text-gray-700`}`,onClick:()=>{E(o),O(n.id)},title:`click to edit model ID`,children:n.id}),n.enabled===!1&&(0,K.jsx)(`span`,{className:`text-[10px] text-gray-300 font-medium shrink-0`,children:`off`})]}),(0,K.jsx)(`input`,{type:`number`,value:n.maxContextTokens??``,onChange:t=>z(e,n.id,{maxContextTokens:t.target.value?Number(t.target.value):void 0}),placeholder:`auto`,className:`w-24 px-1.5 py-0.5 border border-gray-200 rounded text-[10px] outline-none focus:border-gray-400 shrink-0 ${n.maxContextTokens?``:`opacity-0 group-hover:opacity-100 transition-opacity`}`,title:`max context tokens (empty = auto)`}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{let r=t.apiKeyNewValue.trim(),i=`${e}::${n.id}`;if(!r&&!t.apiKeyStored){A(e=>({...e,[i]:`error`})),M(e=>({...e,[i]:`enter an API key first`})),setTimeout(()=>{A(e=>{let{[i]:t,...n}=e;return n}),M(e=>{let{[i]:t,...n}=e;return n})},3e3);return}A(e=>({...e,[i]:`testing`})),M(e=>({...e,[i]:``}));try{let a=r?await ph(t.baseUrl,r,n.id):await ph(t.baseUrl,``,n.id,e,`personal`);A(e=>({...e,[i]:a.ok?`ok`:`error`})),a.ok||M(e=>({...e,[i]:a.error??`unknown error`}))}catch(e){A(e=>({...e,[i]:`error`})),M(t=>({...t,[i]:e?.message??`connection failed`}))}setTimeout(()=>{A(e=>{let{[i]:t,...n}=e;return n}),M(e=>{let{[i]:t,...n}=e;return n})},4e3)},disabled:c===`testing`||!t.apiKeyStored&&!t.apiKeyNewValue.trim(),className:`shrink-0 text-[10px] px-1 py-0 rounded transition-colors ${!t.apiKeyStored&&!t.apiKeyNewValue.trim()?`opacity-0 group-hover:opacity-100 text-gray-300`:c===`ok`?`bg-emerald-100 text-emerald-700`:c===`error`?`bg-red-100 text-red-700`:c===`testing`?`bg-gray-100 text-gray-400 animate-pulse`:`text-gray-400 hover:text-gray-700 opacity-0 group-hover:opacity-100`}`,title:l||(t.apiKeyNewValue.trim()||t.apiKeyStored?`test connection`:`enter an API key first`),children:c===`ok`?`OK`:c===`error`?`FAIL`:c===`testing`?`...`:`test`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>V(e,n.id),className:`text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,title:`remove model`,children:(0,K.jsx)(tt,{size:11})})]},n.id)})})]})]})]},e)}),(0,K.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:N.filter(e=>!i.providers[e.name]).map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{a(t=>!t||t.providers[e.name]?t:{...t,providers:{...t.providers,[e.name]:{models:e.models.map(e=>({id:e,enabled:!0})),baseUrl:e.baseUrl,maxContextTokens:``,enabled:!1,apiKeyNewValue:``,apiKeyStored:!1}}})},className:`px-2 py-0.5 rounded border border-gray-200 bg-white text-[10px] text-gray-500 hover:text-gray-900 hover:border-gray-400 transition-colors`,title:`Add ${e.name} preset`,children:[`+ `,e.name]},e.name))}),m?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&W(),e.key===`Escape`&&h(!1)},placeholder:`provider name`,className:X(QZ,`flex-1`)}),(0,K.jsx)(kg,{size:`sm`,onClick:W,children:`add`}),(0,K.jsx)(kg,{variant:`ghost`,size:`sm`,onClick:()=>{h(!1),p(``)},children:`cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>h(!0),className:`self-start text-xs text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:12}),` add custom provider`]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-3 border-t border-gray-100`,children:[c&&(0,K.jsx)(`span`,{className:`text-xs text-red-600`,children:c}),u&&!c&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-700 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:12}),` saved`]}),(0,K.jsx)(kg,{size:`sm`,onClick:async()=>{if(!i)return;s(!0),l(null);for(let[e,t]of Object.entries(i.providers)){if(!t.apiKeyNewValue.trim())continue;let n=await Dh($Z(e),t.apiKeyNewValue.trim());if(!n.ok){l(`apiKey write failed for "${e}": ${n.error}`),s(!1);return}}let e={};i.default&&(e.default=i.default);for(let[t,n]of Object.entries(i.providers)){let r=n.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),...e.enabled?{}:{enabled:!1},...e.maxContextTokens&&e.maxContextTokens>0?{maxContextTokens:e.maxContextTokens}:{}}));e[t]={baseUrl:n.baseUrl,apiKey:`\${${$Z(t)}}`,...r.length>0?{models:r}:{},...n.maxContextTokens?{maxContextTokens:Number(n.maxContextTokens)}:{},...n.enabled?{}:{enabled:!1}}}let t=await Eh({providers:e});if(!t.ok){s(!1),l(t.error??`save failed`);return}let r=await em();s(!1),r.ok||l(r.conflict?`Saved locally, but it conflicts with the remote — your edit is kept, not lost. Resolve it in Settings → Personal repo (take remote, or in a loop).`:r.needsPull?`Saved locally — remote moved while pushing. Save again to retry.`:`Saved locally, but push to remote failed: ${r.error??`unknown`}`),d(!0),setTimeout(()=>d(!1),2500),n()},disabled:o||r,children:o?`saving…`:`save providers`})]})]}):(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`no providers yet`})}function rQ({label:e,children:t,className:n}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1 ${n??``}`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e}),t]})}function iQ(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!0),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(null),g=(0,_.useCallback)(async()=>{r(!0),h(null),t(await vg()),r(!1)},[]);(0,_.useEffect)(()=>{g()},[g]);let v=async()=>{if(o)return;s(!0),h(null);let e=await yg(i.trim()||`default`);s(!1),e?(l(e.token),a(``),d(!1),g()):h(`Failed to create token`)},y=async e=>{h(null);let t=await bg(e);p(null),t?g():h(`Failed to revoke token`)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[m&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-[12px] text-red-700 flex items-center gap-2`,children:[(0,K.jsx)(R,{size:14}),` `,m]}),c&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-emerald-200 bg-emerald-50 p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(P,{size:14,className:`text-emerald-600`}),(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-emerald-900`,children:`Token created — copy it now, it won't be shown again`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`code`,{className:`flex-1 text-[12px] bg-white border border-emerald-200 rounded px-3 py-2 font-mono text-gray-800 select-all break-all`,children:c}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{c&&navigator.clipboard.writeText(c).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})},className:`shrink-0 h-8 px-3 rounded text-xs border border-emerald-300 hover:bg-emerald-100 text-emerald-800 flex items-center gap-1.5`,children:[u?(0,K.jsx)(P,{size:12}):(0,K.jsx)(ee,{size:12}),u?`copied`:`copy`]})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>l(null),className:`mt-2 text-[11px] text-emerald-700 hover:text-emerald-900 underline`,children:`dismiss`})]}),(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white px-4 py-3 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900`,children:`Loop API documentation`}),(0,K.jsx)(`p`,{className:`text-[11px] text-gray-500 mt-0.5`,children:`Interactive reference for the endpoints these tokens authenticate against.`})]}),(0,K.jsx)(`a`,{href:`/api/v1/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`shrink-0 inline-flex items-center gap-1.5 h-8 px-3 rounded text-[12px] border border-gray-300 hover:bg-gray-50 text-gray-700`,children:`Open docs →`})]}),(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white`,children:[(0,K.jsxs)(`div`,{className:`px-4 py-3 border-b border-gray-100`,children:[(0,K.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900`,children:`Your tokens`}),(0,K.jsx)(`p`,{className:`text-[11px] text-gray-500 mt-0.5`,children:`External programs use these tokens to call loopat under your identity — your providers, API keys, and vault.`})]}),n?(0,K.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:`loading…`}):e.length===0?(0,K.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-gray-400`,children:`No API tokens yet. Create one below.`}):(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 text-left text-[11px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Label`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Token`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Created`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:e.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-gray-900`,children:e.label}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 font-mono text-[12px] text-gray-500`,children:e.tokenId}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-gray-500 text-[12px]`,children:new Date(e.createdAt).toLocaleDateString()}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:f===e.tokenId?(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>y(e.tokenId),className:`text-[11px] text-red-600 hover:text-red-800 font-medium`,children:`confirm`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(null),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`cancel`})]}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(e.tokenId),className:`w-7 h-7 flex items-center justify-center rounded text-gray-400 hover:text-red-600 hover:bg-red-50`,title:`revoke token`,children:(0,K.jsx)(tt,{size:13})})})]},e.tokenId))})]})]}),(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,K.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900 mb-2`,children:`Create new token`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`label (e.g. dingtalk-bot)`,className:`flex-1 px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900`,onKeyDown:e=>e.key===`Enter`&&v()}),(0,K.jsxs)(`button`,{type:`button`,onClick:v,disabled:o,className:`h-8 px-3 rounded text-xs bg-gray-900 hover:bg-gray-800 text-white flex items-center gap-1.5 disabled:opacity-50`,children:[(0,K.jsx)(Re,{size:12}),o?`creating…`:`create token`]})]})]}),(0,K.jsx)(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 px-4 py-3`,children:(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[(0,K.jsx)(`strong`,{className:`text-gray-700`,children:`Usage:`}),` pass the token as`,` `,(0,K.jsx)(`code`,{className:`bg-white border border-gray-200 rounded px-1 py-0.5 text-[10px]`,children:`Authorization: Bearer <token>`}),` `,`when calling`,` `,(0,K.jsx)(`code`,{className:`bg-white border border-gray-200 rounded px-1 py-0.5 text-[10px]`,children:`POST /api/runtime/v1/turn/stream`}),`. The request will run under your identity with your configured providers and API keys.`]})}),(0,K.jsx)(UY,{})]})}function aQ(){let e=zn(),t=Cg().currentUser?.role===`admin`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(``),g=(0,_.useCallback)(async()=>{let e=await hh();e?r(e):h(`forbidden or server unreachable`),a(!1)},[]);if((0,_.useEffect)(()=>{if(!t)return;g();let e=setInterval(g,5e3);return()=>clearInterval(e)},[t,g]),!t)return(0,K.jsxs)(`div`,{className:`h-full flex items-center justify-center text-sm text-gray-500`,children:[`admin only.\xA0`,(0,K.jsx)(`button`,{className:`underline`,onClick:()=>e(`/loop`),children:`back`})]});async function v(){s(!0),h(``);try{let e=await gh();e.ok||h(e.error??`check failed`),await g()}finally{s(!1)}}async function y(){if(n&&!(n.activity.activeLoops>0&&!confirm(`${n.activity.activeLoops} loop(s) and ${n.activity.activeUsers} user(s) are active.\n\nbun --hot will reload code in-place — most pulls don't disturb anyone. If the pull touches deps or schema, you'll need to ssh in and restart manually.\n\nContinue?`))){l(!0),h(``),d(``);try{let e=await _h();p(e.ok),e.ok?e.pulled?d(`pulled ${e.oldHead?.slice(0,7)} → ${e.newHead?.slice(0,7)}\n${e.message??``}`.trim()):d(`already up to date`):d(e.error??`pull failed`),await g()}finally{l(!1)}}}return(0,K.jsx)(`div`,{className:`h-full overflow-y-auto bg-gray-50`,children:(0,K.jsxs)(`div`,{className:`max-w-3xl mx-auto p-4 sm:p-6 flex flex-col gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>e(-1),className:`p-1 rounded hover:bg-gray-100 text-gray-500 hover:text-gray-700`,title:`back`,children:(0,K.jsx)(E,{className:`w-4 h-4`})}),(0,K.jsx)(`h1`,{className:`text-lg font-semibold text-gray-900`,children:`Platform`}),(0,K.jsx)(`span`,{className:`text-xs text-gray-400 ml-auto`,children:`refreshes every 5s`})]}),i&&!n&&(0,K.jsx)(`div`,{className:`text-sm text-gray-400 py-8 text-center`,children:`loading…`}),m&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:m}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(oQ,{icon:(0,K.jsx)(he,{className:`w-4 h-4`}),title:`Version`,children:(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,K.jsxs)(`div`,{className:`text-gray-700`,children:[(0,K.jsx)(`span`,{className:`text-gray-400 mr-2`,children:`branch`}),(0,K.jsx)(`span`,{className:`font-mono`,children:n.version.branch}),(0,K.jsx)(`span`,{className:`text-gray-400 mx-2`,children:`·`}),(0,K.jsx)(`span`,{className:`text-gray-400 mr-1`,children:`commit`}),(0,K.jsx)(`span`,{className:`font-mono`,children:n.version.commit.slice(0,7)})]}),n.version.behindBy>0?(0,K.jsxs)(`div`,{className:`text-amber-700 text-xs`,children:[`behind by `,n.version.behindBy,` commit`,n.version.behindBy===1?``:`s`,` —`,` `,(0,K.jsx)(`span`,{className:`font-mono`,children:n.version.latestCommit?.slice(0,7)}),` `,`"`,n.version.latestMessage,`"`]}):(0,K.jsx)(`div`,{className:`text-xs text-emerald-700`,children:`up to date`}),(0,K.jsx)(`div`,{className:`mt-2`,children:(0,K.jsxs)(`button`,{onClick:v,disabled:o,className:`text-xs px-2.5 py-1 rounded border border-gray-300 hover:bg-gray-100 disabled:opacity-50 inline-flex items-center gap-1.5`,children:[(0,K.jsx)(Be,{className:`w-3 h-3 ${o?`animate-spin`:``}`}),o?`checking…`:`Check for updates`]})})]})}),(0,K.jsxs)(oQ,{icon:(0,K.jsx)(S,{className:`w-4 h-4`}),title:`Activity`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-sm mb-3`,children:[(0,K.jsx)(sQ,{label:`Active loops`,value:n.activity.activeLoops}),(0,K.jsx)(sQ,{label:`Active users`,value:n.activity.activeUsers}),(0,K.jsx)(sQ,{label:`Live WS`,value:n.activity.totalWs}),(0,K.jsx)(sQ,{label:`SDK streaming`,value:n.activity.totalGenerating})]}),n.activity.loops.length===0?(0,K.jsx)(`div`,{className:`text-xs text-gray-400 text-center py-3`,children:`no active loops`}):(0,K.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,K.jsx)(`thead`,{className:`text-gray-400 border-b border-gray-200`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left font-normal py-1.5 pr-2`,children:`title`}),(0,K.jsx)(`th`,{className:`text-left font-normal py-1.5 pr-2`,children:`driver`}),(0,K.jsx)(`th`,{className:`text-right font-normal py-1.5 pr-2`,children:`WS`}),(0,K.jsx)(`th`,{className:`text-left font-normal py-1.5`,children:`state`})]})}),(0,K.jsx)(`tbody`,{children:n.activity.loops.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,K.jsx)(`td`,{className:`py-1.5 pr-2 truncate max-w-[260px]`,title:e.title,children:e.title}),(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-gray-600`,children:e.driver}),(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-right`,children:e.wsCount}),(0,K.jsx)(`td`,{className:`py-1.5`,children:e.generating?(0,K.jsx)(`span`,{className:`text-blue-600`,children:`streaming…`}):e.lastMsgAgeSec>=0&&e.lastMsgAgeSec<60?(0,K.jsxs)(`span`,{className:`text-emerald-600`,children:[`msg `,e.lastMsgAgeSec,`s ago`]}):(0,K.jsx)(`span`,{className:`text-gray-400`,children:`idle (attached)`})})]},e.id))})]})]}),(0,K.jsx)(oQ,{icon:(0,K.jsx)(ne,{className:`w-4 h-4`}),title:`Update`,children:(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 text-sm`,children:[(0,K.jsx)(`button`,{onClick:y,disabled:c||n.version.behindBy===0,className:`self-start text-sm px-3 py-1.5 rounded text-white disabled:opacity-50 `+(n.activity.activeLoops>0?`bg-amber-600 hover:bg-amber-700`:`bg-gray-900 hover:bg-gray-700`),children:c?`pulling…`:n.version.behindBy===0?`Pull latest (nothing to pull)`:`Pull latest`}),n.activity.activeLoops>0&&n.version.behindBy>0&&(0,K.jsxs)(`div`,{className:`text-xs text-amber-700`,children:[n.activity.activeLoops,` loop(s) active — bun --hot reloads code in-place. Dep / schema changes need a manual restart.`]}),u&&(0,K.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap rounded p-2 border `+(f?`bg-emerald-50 border-emerald-200 text-emerald-800`:`bg-red-50 border-red-200 text-red-800`),children:u})]})})]})]})})}function oQ({icon:e,title:t,children:n}){return(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-gray-700 mb-3`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:e}),t]}),n]})}function sQ({label:e,value:t}){return(0,K.jsxs)(`div`,{className:`flex flex-col`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wide`,children:e}),(0,K.jsx)(`span`,{className:`text-xl font-semibold text-gray-900 tabular-nums`,children:t})]})}function cQ({onClose:e}={}){let t=Cg(),[n,r]=(0,_.useState)(`login`),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null);return(0,K.jsx)(`div`,{className:e?`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`:`h-full w-full flex items-center justify-center bg-gray-50`,onClick:e?()=>e():void 0,children:(0,K.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-6`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,K.jsx)(`span`,{className:`text-xl leading-none`,children:`🧶`}),(0,K.jsx)(`span`,{className:`text-base font-semibold text-gray-900`,children:`loopat`}),e&&(0,K.jsx)(`button`,{type:`button`,onClick:e,className:`ml-auto text-gray-400 hover:text-gray-700 px-1`,"aria-label":`close`,children:`✕`})]}),(0,K.jsx)(`div`,{className:`flex border-b border-gray-200 mb-5`,children:[`login`,`register`].map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>{r(e),d(null),p(null)},className:n===e?`px-3 py-2 text-sm border-b-2 border-gray-900 text-gray-900 font-medium`:`px-3 py-2 text-sm text-gray-500 hover:text-gray-800`,children:e===`login`?`Login`:`Register`},e))}),(0,K.jsxs)(`form`,{onSubmit:async a=>{if(a.preventDefault(),!c){d(null),l(!0);try{if(n===`login`){let n=await t.login(i.trim().toLowerCase(),o);n.error?d(n.error):e&&e();return}let a=await t.register({username:i.trim().toLowerCase(),password:o});if(a.error){d(a.error);return}if(a.user&&a.user.status===`pending`){p(`账号 ${a.user.id} 已创建,等待管理员激活后即可登录。`),r(`login`),s(``);return}e&&e()}finally{l(!1)}}},className:`flex flex-col gap-4`,children:[(0,K.jsx)(lQ,{label:`Username`,hint:`lowercase a-z 0-9 _ - · 1-32 chars`,children:(0,K.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`simpx`,autoFocus:!0,autoComplete:`username`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),(0,K.jsx)(lQ,{label:`Password`,children:(0,K.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),autoComplete:n===`login`?`current-password`:`new-password`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),n===`register`&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 leading-relaxed`,children:`Just creates your account. Set up your personal repo afterwards in Settings → Personal Repo.`}),f&&!u&&(0,K.jsx)(`div`,{className:`text-xs text-amber-700 bg-amber-50 border border-amber-200 rounded px-2 py-1.5`,children:f}),u&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:u}),(0,K.jsx)(`button`,{type:`submit`,disabled:c||!i||!o,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:c?n===`login`?`logging in…`:`registering…`:n===`login`?`Login`:`Register`})]})]})})}function lQ({label:e,hint:t,children:n}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var uQ=`loopat:floating-dm-open`,dQ=`loopat:floating-dm-conv`;function fQ(e){let t=new Date(e),n=new Date,r=t.toDateString()===n.toDateString(),i=t.toTimeString().slice(0,5);return r?i:new Date(n.getTime()-864e5).toDateString()===t.toDateString()?`yesterday ${i}`:`${t.getMonth()+1}/${t.getDate()} ${i}`}function pQ({me:e}){let t=zn(),[n,r]=(0,_.useState)(()=>localStorage.getItem(uQ)===`1`),[i,a]=(0,_.useState)(()=>localStorage.getItem(dQ)),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)([]),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(!1),y=(0,_.useRef)(null),b=(0,_.useMemo)(()=>c.filter(e=>e.kind===`dm`).sort((e,t)=>(t.lastMessageTs??0)-(e.lastMessageTs??0)),[c]),x=(0,_.useMemo)(()=>b.reduce((e,t)=>e+t.unread,0),[b]),S=(0,_.useMemo)(()=>b.find(e=>e.id===i)??null,[b,i]);(0,_.useEffect)(()=>{localStorage.setItem(uQ,n?`1`:`0`)},[n]),(0,_.useEffect)(()=>{i?localStorage.setItem(dQ,i):localStorage.removeItem(dQ)},[i]);let C=(0,_.useCallback)(async()=>{l(await Wh())},[]);(0,_.useEffect)(()=>{C(),Gh().then(d)},[C]),(0,_.useEffect)(()=>{if(!i){p([]);return}let e=!1;return Yh(i,{limit:100}).then(t=>{if(e)return;p(t);let n=t[t.length-1];n&&(Qh(i,n.id).catch(()=>{}),l(e=>e.map(e=>e.id===i?{...e,unread:0}:e)),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:i}})))}),()=>{e=!0}},[i]),(0,_.useEffect)(()=>{n&&S&&y.current?.scrollIntoView({behavior:`auto`})},[f,n,S]);let w=(0,_.useRef)(i);w.current=i;let{subscribe:T,unsubscribe:D}=SY((0,_.useCallback)(t=>{if(t.type===`message`){let n=t.message,r=n.convId===w.current;r&&n.parentId==null?(p(e=>e.some(e=>e.id===n.id)?e:[...e,{...n,replyCount:0,lastReplyTs:null}]),Qh(n.convId,n.id).catch(()=>{}),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:n.convId}}))):r&&n.parentId!=null?p(e=>e.map(e=>e.id===n.parentId?{...e,replyCount:e.replyCount+1,lastReplyTs:n.ts}:e)):n.author!==e&&l(e=>e.map(e=>e.id===n.convId?{...e,unread:e.unread+1,lastMessageTs:n.ts}:e))}else t.type===`conv_created`?l(e=>e.some(e=>e.id===t.conv.id)?e:[...e,t.conv]):t.type===`conv_deleted`&&(l(e=>e.filter(e=>e.id!==t.convId)),w.current===t.convId&&a(null))},[e]));(0,_.useEffect)(()=>{for(let e of b)T(e.id);return()=>{for(let e of b)D(e.id)}},[b,T,D]),(0,_.useEffect)(()=>{let e=e=>{let t=e.detail;t?.convId&&l(e=>e.map(e=>e.id===t.convId?{...e,unread:0}:e))};return window.addEventListener(`loopat:chat-read`,e),()=>window.removeEventListener(`loopat:chat-read`,e)},[]);let O=async()=>{if(!S||!m.trim()||g)return;let e=m.trim();h(``),v(!0);let t=await Zh(S.id,e);if(v(!1),t.message){let e=t.message;p(t=>t.some(t=>t.id===e.id)?t:[...t,{...e,replyCount:0,lastReplyTs:null}])}else h(e)};return e?(0,K.jsxs)(K.Fragment,{children:[!n&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(!0),className:`fixed bottom-20 right-5 z-30 w-12 h-12 rounded-full flex items-center justify-center shadow-lg transition-colors `+(x>0?`bg-gray-700 text-white animate-pulse`:`bg-gray-700 text-white hover:bg-gray-500`),title:`direct messages`,children:[(0,K.jsx)(De,{size:20}),x>0&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 rounded-full bg-red-500 text-white text-[10px] font-medium flex items-center justify-center`,children:x>99?`99+`:x})]}),n&&(0,K.jsxs)(`div`,{className:`fixed bottom-20 right-5 z-30 w-[22rem] max-w-[calc(100vw-2.5rem)] h-[32rem] max-h-[calc(100dvh-2.5rem)] bg-white rounded-lg shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,children:[(0,K.jsxs)(`header`,{className:`h-10 shrink-0 border-b border-gray-200 px-2 flex items-center gap-1`,children:[S?(0,K.jsx)(`button`,{type:`button`,onClick:()=>a(null),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`back to DMs`,children:(0,K.jsx)(E,{size:14})}):(0,K.jsx)(`span`,{className:`px-2 text-[13px] font-medium text-gray-900`,children:`Direct messages`}),S&&(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-gray-400 text-[13px]`,children:`@`}),(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900 truncate`,children:S.peerUserId??`(unknown)`})]}),!S&&(0,K.jsx)(`div`,{className:`flex-1`}),!S&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`new DM`,children:(0,K.jsx)(Re,{size:14})}),S&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{t(S?`/chat/${S.id}`:`/chat`),r(!1)},className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`open in chat tab`,children:(0,K.jsx)(re,{size:13})}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>r(!1),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`close`,children:(0,K.jsx)(lt,{size:14})})]}),S?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-3 py-2 flex flex-col gap-2`,children:[f.length===0&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-4 text-center`,children:`no messages yet — say hi`}),f.map(t=>(0,K.jsx)(mQ,{message:t,isMe:t.author===e},t.id)),(0,K.jsx)(`div`,{ref:y})]}),(0,K.jsx)(`div`,{className:`px-2 pb-2 pt-1 shrink-0`,children:(0,K.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-1.5 flex items-end gap-1`,children:[(0,K.jsx)(`textarea`,{value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),O())},rows:1,placeholder:`message @${S.peerUserId??``}…`,className:`field-sizing-content flex-1 max-h-32 min-h-7 resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`}),(0,K.jsx)(`button`,{type:`button`,onClick:O,disabled:g||!m.trim(),className:`px-2.5 h-7 rounded bg-gray-900 text-white text-xs hover:bg-gray-700 disabled:opacity-40 shrink-0`,children:`send`})]})})]}):(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:b.length===0?(0,K.jsxs)(`div`,{className:`px-4 py-6 text-center text-[12px] text-gray-400`,children:[`no DMs yet`,(0,K.jsx)(`div`,{className:`mt-2`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`px-2 py-1 rounded border border-gray-200 text-[12px] text-gray-700 hover:bg-gray-50 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:12}),(0,K.jsx)(`span`,{children:`new DM`})]})})]}):(0,K.jsx)(`ul`,{className:`py-1`,children:b.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:`w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-gray-50`,children:[(0,K.jsx)(`span`,{className:`w-7 h-7 rounded bg-gray-200 text-gray-900 text-[11px] font-medium flex items-center justify-center shrink-0`,children:(e.peerUserId??`?`).slice(0,1).toUpperCase()}),(0,K.jsxs)(`span`,{className:`flex-1 min-w-0 text-[13px] text-gray-900 truncate`,children:[`@`,e.peerUserId??`(unknown)`]}),e.unread>0&&(0,K.jsx)(`span`,{className:`text-[10px] font-medium px-1.5 rounded-full bg-red-500 text-white`,children:e.unread}),e.lastMessageTs&&e.unread===0&&(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:fQ(e.lastMessageTs)})]})},e.id))})})]}),o&&(0,K.jsx)(hQ,{users:u,onClose:()=>s(!1),onPick:async e=>{let t=await Jh(e);t.conv?(s(!1),a(t.conv.id),C()):t.error&&alert(t.error)}})]}):null}function mQ({message:e,isMe:t}){return(0,K.jsxs)(`div`,{className:`flex gap-1.5 `+(t?`flex-row-reverse`:``),children:[(0,K.jsx)(`div`,{className:t?`w-6 h-6 rounded shrink-0 flex items-center justify-center text-[10px] font-medium bg-gray-900 text-white`:`w-6 h-6 rounded shrink-0 flex items-center justify-center text-[10px] font-medium bg-gray-200 text-gray-900`,title:e.author,children:e.author.slice(0,1).toUpperCase()}),(0,K.jsxs)(`div`,{className:`min-w-0 max-w-[80%]`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 `+(t?`text-right`:``),children:fQ(e.ts)}),(0,K.jsx)(`div`,{className:`text-[12.5px] whitespace-pre-wrap break-words leading-relaxed px-2 py-1 rounded-lg `+(t?`bg-gray-900 text-white`:`bg-gray-100 text-gray-900`),children:e.text})]})]})}function hQ({users:e,onClose:t,onPick:n}){let[r,i]=(0,_.useState)(``),a=e.filter(e=>!e.isMe).filter(e=>e.id.toLowerCase().includes(r.toLowerCase()));return(0,K.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-lg w-80 p-3 flex flex-col gap-2`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:`New DM`}),(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`search users…`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,K.jsxs)(`div`,{className:`max-h-64 overflow-auto flex flex-col gap-0.5`,children:[a.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),className:`text-left px-2 py-1.5 text-sm rounded hover:bg-gray-100 flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-6 h-6 rounded bg-gray-200 text-gray-900 text-[11px] flex items-center justify-center`,children:e.id.slice(0,1).toUpperCase()}),(0,K.jsx)(`span`,{children:e.id})]},e.id)),a.length===0&&(0,K.jsx)(`div`,{className:`text-xs text-gray-400 px-2 py-2`,children:`no users match`})]})]})})}var gQ=`loopat:setupPersonalRepoDismissed`;function _Q(){try{return localStorage.getItem(gQ)===`1`}catch{return!1}}function vQ({onDismiss:e,hideSkip:t}){let n=zn();return(0,K.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,K.jsx)(`div`,{className:`text-2xl mb-2`,children:`👋 欢迎来到 loopat`}),(0,K.jsxs)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-3`,children:[`在你开始之前,建议先配一个`,(0,K.jsx)(`b`,{children:`个人仓库`}),`——`]}),(0,K.jsxs)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-3`,children:[`loopat 一个反直觉的设计:服务器`,(0,K.jsx)(`b`,{children:`不存你的数据`}),`。你的 API key、ssh、token、 笔记、memory 全部存在你自己的 GitHub 私有仓库里,由你自己持有解密密钥。 这是 loopat 跟其他工具最大的不同。`]}),(0,K.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:`配置 3 步,大约 2 分钟:创建一个空的私有仓库 → 把 loopat 的 deploy key 贴上去 → 把仓库 URL 填进来。配完后回到这个页面,AI 引导会自动接上。`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>n(`/settings/personal-repo`),className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`去配置个人仓库 →`}),!t&&(0,K.jsx)(`button`,{onClick:()=>{try{localStorage.setItem(gQ,`1`)}catch{}e()},className:`text-xs text-gray-500 hover:text-gray-700`,children:`跳过(先用 workspace 的 key)`})]}),(0,K.jsx)(`p`,{className:`mt-4 text-[11px] text-gray-400 leading-relaxed`,children:`跳过后这个提示就不再出现。但 loopat 的核心安全模型依赖你的个人仓库 —— 想用自己的凭据、记自己的 memory 时,从右上角 Settings → Personal Repo 随时可以补上。`})]})}function yQ({form:e,onAdvance:t}){let[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(``),c=e.fields.filter(e=>(n[e.name]??``).trim().length>0).length,l=e.require===`any`?c>=1:c===e.fields.length;return(0,K.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,K.jsx)(`div`,{className:`text-2xl mb-2`,children:e.title}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:e.description}),(0,K.jsx)(`div`,{className:`flex flex-col gap-4`,children:e.fields.map(e=>(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,K.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:e.label}),e.help&&(0,K.jsx)(`a`,{href:e.help,target:`_blank`,rel:`noreferrer`,className:`text-xs text-blue-600 hover:text-blue-800`,children:`获取 →`})]}),(0,K.jsx)(`input`,{type:e.type===`text`?`text`:`password`,autoComplete:`off`,spellCheck:!1,placeholder:e.placeholder??e.label,value:n[e.name]??``,onChange:t=>r(n=>({...n,[e.name]:t.target.value})),className:`h-9 px-3 rounded border border-gray-300 text-sm font-mono focus:outline-none focus:border-gray-500`})]},e.name))}),o&&(0,K.jsx)(`p`,{className:`mt-3 text-sm text-red-600`,children:o}),(0,K.jsxs)(`div`,{className:`mt-6 flex items-center gap-3`,children:[(0,K.jsx)(`button`,{onClick:async()=>{a(!0),s(``);try{let r={};for(let t of e.fields){let e=(n[t.name]??``).trim();e&&(r[t.name]=e)}let i=await Xp(r);if(`error`in i){s(i.error);return}t(i)}finally{a(!1)}},disabled:!l||i,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i?`处理中…`:e.submitLabel??`继续 →`}),e.require===`any`&&e.fields.length>1&&(0,K.jsx)(`span`,{className:`text-xs text-gray-400`,children:`至少填一个`})]})]})}function bQ({show:e,onAdvance:t}){let[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null);return(0,K.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,K.jsxs)(`div`,{className:`text-2xl mb-2`,children:[`🔐 `,e.title]}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-4 whitespace-pre-line`,children:e.description}),e.values&&e.values.length>0&&(0,K.jsx)(`div`,{className:`flex flex-col gap-2 mb-4`,children:e.values.map(e=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:e.label}),(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`code`,{className:`flex-1 min-w-0 break-all bg-gray-50 border border-gray-200 rounded px-2 py-1.5 text-[10px] font-mono`,children:e.value}),(0,K.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(e.value),a(e.label),setTimeout(()=>a(null),1500)},className:`shrink-0 text-[11px] text-gray-500 hover:text-gray-800 px-1.5 py-1`,children:i===e.label?`copied`:`copy`})]})]},e.label))}),e.help&&e.help.length>0&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-3 mb-5`,children:e.help.map(e=>(0,K.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-xs text-blue-600 hover:text-blue-800`,children:[e.label,` →`]},e.url))}),(0,K.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,K.jsx)(`button`,{onClick:async()=>{r(!0);let e=await Yp();r(!1),e&&t(e)},disabled:n,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:n?`检查中…`:`我已配置好,重新检查`})})]})}function xQ(e,t,n){let[r,i]=(0,_.useState)({}),a=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!t)return;let e=!1,r=async()=>{let t=await Wh();if(e)return;let n={};for(let e of t)n[e.id]=e.unread;i(n)},o=t=>{let r=location.protocol===`https:`?`wss:`:`ws:`,o=new WebSocket(`${r}//${location.host}/ws/chat`);a.current=o,o.onopen=()=>{for(let e of t)o.send(JSON.stringify({type:`subscribe`,convId:e}))},o.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`message`?t.message.author!==n&&i(e=>({...e,[t.message.convId]:(e[t.message.convId]??0)+1})):t.type===`conv_created`&&o.send(JSON.stringify({type:`subscribe`,convId:t.conv.id}))}catch{}},o.onclose=()=>{e||setTimeout(()=>{e||s()},3e3)},o.onerror=()=>{try{o.close()}catch{}}},s=async()=>{let t=await Wh();if(e)return;let n={};for(let e of t)n[e.id]=e.unread;i(n),o(t.map(e=>e.id))};s();let c=e=>{let t=e.detail;t?.convId&&i(e=>e[t.convId]===0?e:{...e,[t.convId]:0})},l=()=>{r().catch(()=>{})};return window.addEventListener(`loopat:chat-read`,c),window.addEventListener(`focus`,l),()=>{e=!0,window.removeEventListener(`loopat:chat-read`,c),window.removeEventListener(`focus`,l);try{a.current?.close()}catch{}a.current=null}},[t,n]),(0,_.useEffect)(()=>{if(!t)return;let n=0;for(let e in r)n+=r[e];let i=`${e} · loopat`;document.title=n>0?`(${n}) ${i}`:i},[r,e,t])}var SQ=(0,_.createContext)({theme:`light`,toggle:()=>{}});function CQ(){return(0,_.useContext)(SQ)}var wQ=`loopat:theme`;function TQ(){try{let e=localStorage.getItem(wQ);if(e===`dark`||e===`light`)return e}catch{}return window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}function EQ(e){let t=document.documentElement;e===`dark`?t.classList.add(`dark`):t.classList.remove(`dark`)}EQ(TQ());function DQ({children:e}){let[t,n]=(0,_.useState)(TQ);(0,_.useLayoutEffect)(()=>{EQ(t)},[t]);let r=(0,_.useCallback)(()=>{n(e=>{let t=e===`light`?`dark`:`light`;EQ(t);try{localStorage.setItem(wQ,t)}catch{}return t})},[]);return(0,K.jsx)(SQ.Provider,{value:{theme:t,toggle:r},children:e})}var OQ=[{id:`loop`,label:`Loop`,icon:`⑂`},{id:`kanban`,label:`Focus`,icon:`◎`},{id:`context`,label:`Context`,icon:`⌘`},{id:`chat`,label:`Chat`,icon:(0,K.jsx)(De,{size:14})}];function kQ(){let e=xg();return(0,K.jsx)(Sg.Provider,{value:e,children:e.authLoading?null:(0,K.jsx)(AQ,{ws:e})})}function AQ({ws:e}){let t=zn(),n=Fn(),[r,i]=(0,_.useState)(`loopat`),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(``),{theme:h,toggle:g}=CQ(),v=e.currentUser?.id??``,y=e.currentUser?.role===`admin`,b=!!e.currentUser,x=!!In(`/loop/:id`),S=n.pathname.startsWith(`/chat`),C=!b&&x;(0,_.useEffect)(()=>{C||Up().then(e=>{e&&(i(e),document.title=`${e} · loopat`)})},[C]),xQ(r,b&&!C,v);let w=`loopat:version-dismissed`;(0,_.useEffect)(()=>{let e=e=>{let t=e.detail?.commit;if(t){try{if(JSON.parse(localStorage.getItem(w)||`[]`).includes(t))return}catch{}f(t),m(new Date(vh().time).toLocaleString()),u(!0)}};return window.addEventListener(`loopat:version-mismatch`,e),()=>window.removeEventListener(`loopat:version-mismatch`,e)},[]),(0,_.useEffect)(()=>{if(C)return;let e=vh();mh().then(t=>{console.log(`%cloopat %cserver:%c ${t.branch}@${t.commit.slice(0,7)} %cbuild:%c ${e.commit.slice(0,7)} @ ${e.time}`,`font-weight:bold`,`color:#666`,`color:#61afef`,`color:#666`,`color:#98c379`)})},[C]);let[T,E]=(0,_.useState)(null);return(0,_.useEffect)(()=>{if(!b||C){E(null);return}Yp().then(E)},[b,C]),(0,_.useEffect)(()=>{if(!b||C||!T||T.done||!T.gated||T.show.kind!==`route`)return;let e=setInterval(()=>{Yp().then(E)},3e3);return()=>clearInterval(e)},[b,C,T]),C?(0,K.jsx)(`div`,{className:`h-full w-full bg-white text-gray-900`,children:(0,K.jsx)(mr,{})}):b?(0,K.jsxs)(`div`,{className:`h-full w-full flex flex-col bg-gray-50 text-gray-900`,children:[(0,K.jsxs)(`header`,{className:`h-12 shrink-0 border-b border-gray-200 bg-white flex items-center px-2 md:px-4 gap-2 md:gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-1 md:px-2 h-8 shrink-0 cursor-pointer`,title:`workspace: ${r}`,onClick:()=>{window.location.href=`/`},children:[(0,K.jsx)(`span`,{className:`text-lg leading-none`,children:`🧶`}),(0,K.jsx)(`span`,{className:`hidden md:inline text-sm text-gray-900 font-medium`,children:r})]}),(0,K.jsx)(`nav`,{className:`flex items-center gap-0.5 md:gap-1`,children:OQ.map(e=>(0,K.jsxs)(ui,{to:`/${e.id}`,className:({isActive:e})=>e?`px-2 md:px-3 h-8 rounded text-sm bg-gray-900 text-white flex items-center gap-1.5`:`px-2 md:px-3 h-8 rounded text-sm text-gray-600 hover:bg-gray-100 flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`opacity-70`,children:e.icon}),(0,K.jsx)(`span`,{className:`hidden md:inline`,children:e.label})]},e.id))}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e.setNewLoopDialogOpen(!0),className:`flex items-center gap-1 md:gap-1.5 px-2 md:px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,title:`create new loop`,children:[(0,K.jsx)(`span`,{className:`text-base leading-none`,children:`+`}),(0,K.jsx)(`span`,{className:`hidden md:inline`,children:`New Loop`})]}),(0,K.jsx)(`button`,{type:`button`,onClick:g,className:`flex items-center justify-center w-8 h-8 rounded text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,title:h===`dark`?`Switch to light mode`:`Switch to dark mode`,children:h===`dark`?(0,K.jsx)(Qe,{size:16}):(0,K.jsx)(je,{size:16})}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-1 md:gap-2 px-1 md:px-2 h-8 rounded hover:bg-gray-100`,title:`account`,children:[(0,K.jsx)(`span`,{className:`w-6 h-6 rounded-full bg-gray-900 text-white text-xs flex items-center justify-center`,children:v[0]?.toUpperCase()??`?`}),(0,K.jsx)(`span`,{className:`hidden md:inline text-sm text-gray-700`,children:v}),(0,K.jsx)(`span`,{className:`text-gray-400 text-xs`,children:`▾`})]}),a&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>o(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 w-40 bg-white border border-gray-200 rounded shadow-md py-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),t(`/settings`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`Settings`}),y&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),t(`/admin/system`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,title:`server version + activity + pull latest code`,children:`Platform`}),y&&(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{o(!1);try{t(`/loop/${(await e.createLoop({title:`cross-loop distill`,mountAllLoops:!0,knowledgeRw:!0})).id}`)}catch(e){alert(e?.message??`create failed`)}},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,title:`New loop with /loopat/loops/ mounted read-only — read every loop's chat/workdir for distill`,children:`Cross-loop distill`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),c(!0)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`About`}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{o(!1),await e.logout(),t(`/loop`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`Logout`})]})]})]})]}),l&&(0,K.jsxs)(`div`,{className:`shrink-0 bg-gradient-to-r from-blue-50 to-indigo-50 border-b border-blue-200 flex items-center px-4 py-2.5 gap-2.5`,children:[(0,K.jsx)(Be,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,K.jsxs)(`span`,{className:`text-sm text-blue-700`,children:[`New version available`,(0,K.jsxs)(`span`,{className:`text-blue-400 ml-1 text-xs`,children:[`(`,d.slice(0,7),` `,p,`)`]})]}),(0,K.jsx)(`button`,{type:`button`,className:`text-xs font-medium px-2.5 py-1 rounded bg-blue-500 text-white hover:bg-blue-600 cursor-pointer shrink-0`,onClick:()=>{try{let e=JSON.parse(localStorage.getItem(w)||`[]`);e.push(d),localStorage.setItem(w,JSON.stringify(e))}catch{}window.location.reload()},children:`Update`}),(0,K.jsx)(`button`,{type:`button`,className:`ml-auto p-0.5 rounded hover:bg-blue-100 text-blue-400 hover:text-blue-600 cursor-pointer shrink-0`,onClick:()=>{try{let e=JSON.parse(localStorage.getItem(w)||`[]`);e.push(d),localStorage.setItem(w,JSON.stringify(e))}catch{}u(!1)},"aria-label":`关闭`,children:(0,K.jsx)(lt,{className:`w-4 h-4`})})]}),(0,K.jsx)(`main`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(()=>{let e=T;return b&&e&&e.gated&&!e.done?e.show.kind===`route`?n.pathname===e.show.path?(0,K.jsx)(mr,{}):(0,K.jsx)(pr,{to:e.show.path,replace:!0}):e.show.kind===`info`?(0,K.jsx)(bQ,{show:e.show,onAdvance:E}):(0,K.jsx)(yQ,{form:e.show,onAdvance:E}):(0,K.jsx)(mr,{})})()}),e.newLoopDialogOpen&&(0,K.jsx)(wg,{onClose:()=>e.setNewLoopDialogOpen(!1),onCreate:async n=>{let r=await e.createLoop(n);return e.kanbanCreateCtx&&await uh(e.kanbanCreateCtx.board,e.kanbanCreateCtx.filename,e.kanbanCreateCtx.cid,r.id),e.setNewLoopDialogOpen(!1),t(`/loop/${r.id}`),r.id},initialTitle:e.newLoopDialogTitle}),(0,K.jsx)(Lg,{open:s,onClose:()=>c(!1)}),!S&&(0,K.jsx)(pQ,{me:v})]}):(0,K.jsx)(cQ,{})}function jQ(){let e=Cg(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(0);if((0,_.useEffect)(()=>{e.currentUser&&Jp().then(e=>n(e))},[e.currentUser,r]),e.currentUser&&t===null||e.loopsLoading)return null;if(e.currentUser&&t&&!t.imported&&!_Q())return(0,K.jsx)(vQ,{onDismiss:()=>i(e=>e+1)});if(e.loops.length===0)return(0,K.jsx)(MQ,{loggedIn:!!e.currentUser,onNew:()=>e.setNewLoopDialogOpen(!0)});let a=e.currentUser?.id?localStorage.getItem(`loopat:lastLoop:${e.currentUser.id}`):null,o=e.currentUser?.id?e.loops.filter(t=>t.createdBy===e.currentUser.id):[];return(0,K.jsx)(pr,{to:`/loop/${a&&e.loops.some(e=>e.id===a)?a:o.length>0?o[0].id:e.loops[0].id}`,replace:!0})}function MQ({loggedIn:e,onNew:t}){return(0,K.jsxs)(`div`,{className:`h-full w-full flex flex-col items-center justify-center text-gray-500 gap-3`,children:[(0,K.jsx)(`div`,{children:`no loops yet`}),e?(0,K.jsx)(`button`,{onClick:t,className:`px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`+ New Loop`}):(0,K.jsx)(`div`,{className:`text-xs text-gray-400`,children:`log in to create one`})]})}function NQ(){return(0,K.jsx)(DQ,{children:(0,K.jsx)(Rp,{children:(0,K.jsx)(oi,{children:(0,K.jsx)(_r,{children:(0,K.jsxs)(hr,{element:(0,K.jsx)(kQ,{}),children:[(0,K.jsx)(hr,{path:`/`,element:(0,K.jsx)(pr,{to:`/loop`,replace:!0})}),(0,K.jsx)(hr,{path:`/loop`,element:(0,K.jsx)(jQ,{})}),(0,K.jsx)(hr,{path:`/loop/:id`,element:(0,K.jsx)(eG,{})}),(0,K.jsx)(hr,{path:`/topic/:name`,element:(0,K.jsx)(pG,{})}),(0,K.jsx)(hr,{path:`/kanban`,element:(0,K.jsx)(pr,{to:`/kanban/default`,replace:!0})}),(0,K.jsx)(hr,{path:`/kanban/:board`,element:(0,K.jsx)(xY,{})}),(0,K.jsx)(hr,{path:`/context`,element:(0,K.jsx)(pr,{to:`/context/knowledge`,replace:!0})}),(0,K.jsx)(hr,{path:`/context/:sub`,element:(0,K.jsx)(yG,{})}),(0,K.jsx)(hr,{path:`/chat`,element:(0,K.jsx)(DY,{})}),(0,K.jsx)(hr,{path:`/chat/:convId`,element:(0,K.jsx)(DY,{})}),(0,K.jsx)(hr,{path:`/settings`,element:(0,K.jsx)(pr,{to:`/settings/personal-repo`,replace:!0})}),(0,K.jsx)(hr,{path:`/settings/:tab`,element:(0,K.jsx)(tQ,{})}),(0,K.jsx)(hr,{path:`/admin/system`,element:(0,K.jsx)(aQ,{})})]})})})})})}var PQ=class extends _.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary]`,e,t.componentStack)}reset=()=>{this.setState({error:null})};render(){if(!this.state.error)return this.props.children;let e=this.state.error;return(0,K.jsxs)(`div`,{className:`m-4 flex flex-col gap-3 rounded-md border border-red-300 bg-red-50 p-4 text-sm text-red-900`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:`UI crashed — caught by error boundary`}),(0,K.jsxs)(`pre`,{className:`overflow-auto whitespace-pre-wrap break-words rounded bg-white/70 p-2 text-xs leading-relaxed`,children:[e.name,`: `,e.message,e.stack?`\n\n${e.stack}`:``]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,className:`rounded bg-red-600 px-3 py-1 text-xs font-medium text-white hover:bg-red-700`,onClick:this.reset,children:`Try again`}),(0,K.jsx)(`button`,{type:`button`,className:`rounded border border-red-300 bg-white px-3 py-1 text-xs font-medium text-red-700 hover:bg-red-100`,onClick:()=>window.location.reload(),children:`Reload page`})]})]})}};document.addEventListener(`gesturestart`,e=>e.preventDefault()),(0,ft.createRoot)(document.getElementById(`root`)).render((0,K.jsx)(_.StrictMode,{children:(0,K.jsx)(PQ,{children:(0,K.jsx)(NQ,{})})}));export{xm as _,wL as a,sI as c,oF as d,sF as f,wk as g,JN as h,OL as i,qF as l,rP as m,_z as n,_L as o,ZP as p,aR as r,pL as s,Az as t,lF as u,Sm as v,x as y};
|
|
162
|
+
`).map(e=>e.trim()).filter(Boolean)}),disabled:n,rows:Math.max(1,e.models.length),className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono resize-none`})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>f(t),disabled:n,className:`text-gray-300 hover:text-red-500 transition-colors disabled:opacity-30`,children:(0,K.jsx)(tt,{size:12})})})]},t))})]})}),r?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d(),e.key===`Escape`&&i(!1)},placeholder:`Provider name`,className:FZ}),(0,K.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&d()},placeholder:`Base URL`,className:FZ})]}),(0,K.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),placeholder:`Models (one per line)`,rows:3,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono resize-none`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:d,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>i(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>i(!0),disabled:n,className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors disabled:opacity-50`,children:[(0,K.jsx)(Re,{size:11}),` add provider preset`]})]})}function RZ({presets:e,onChange:t,saving:n}){let[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(``),p=()=>{let n=a.trim();!n||!s.trim()||(t([...e,{name:n,suggestedVersion:s.trim(),description:l.trim()||void 0,backend:d.trim()||void 0}]),o(``),c(``),u(``),f(``),i(!1))},m=n=>{t(e.filter((e,t)=>t!==n))},h=(n,r)=>{t(e.map((e,t)=>t===n?{...e,...r}:e))};return(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.length===0&&!r&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-3`,children:`No mise tool presets. Add one to get started.`}),e.length>0&&(0,K.jsx)(`div`,{className:`border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 bg-gray-50/50 text-left text-[10px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Tool`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Description`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium hidden sm:table-cell`,children:`Backend`}),(0,K.jsx)(`th`,{className:`px-3 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:e.map((e,t)=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{value:e.name,onChange:e=>h(t,{name:e.target.value}),disabled:n,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-24`})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`input`,{value:e.suggestedVersion,onChange:e=>h(t,{suggestedVersion:e.target.value}),disabled:n,className:`w-full px-2 py-1 border border-gray-300 rounded text-[11px] outline-none bg-white focus:border-gray-900 font-mono w-20`})}),(0,K.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,K.jsx)(`input`,{value:e.description??``,onChange:e=>h(t,{description:e.target.value||void 0}),disabled:n,placeholder:`optional`,className:FZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2 hidden sm:table-cell`,children:(0,K.jsx)(`input`,{value:e.backend??``,onChange:e=>h(t,{backend:e.target.value||void 0}),disabled:n,placeholder:`optional`,className:FZ})}),(0,K.jsx)(`td`,{className:`px-3 py-2`,children:(0,K.jsx)(`button`,{onClick:()=>m(t),disabled:n,className:`text-gray-300 hover:text-red-500 transition-colors disabled:opacity-30`,children:(0,K.jsx)(tt,{size:12})})})]},t))})]})}),r?(0,K.jsxs)(`div`,{className:`border border-gray-200 rounded-lg p-3 space-y-2 bg-gray-50/50`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&p(),e.key===`Escape`&&i(!1)},placeholder:`Tool name (e.g. python)`,className:FZ}),(0,K.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&p()},placeholder:`Suggested version (e.g. 3.12)`,className:FZ})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:[(0,K.jsx)(`input`,{value:l,onChange:e=>u(e.target.value),placeholder:`Description (optional)`,className:FZ}),(0,K.jsx)(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`Backend (optional, e.g. aqua:sharkdp/fd)`,className:FZ})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:p,className:`px-3 h-7 rounded bg-gray-900 text-white text-[11px] font-medium hover:bg-gray-800`,children:`Add`}),(0,K.jsx)(`button`,{onClick:()=>i(!1),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`Cancel`})]})]}):(0,K.jsxs)(`button`,{onClick:()=>i(!0),disabled:n,className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors disabled:opacity-50`,children:[(0,K.jsx)(Re,{size:11}),` add mise tool preset`]})]})}function zZ(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function BZ(e){return new Date(e).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}function VZ(e){return new Date(e).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})}function HZ(e){let t=new Date;return t.setDate(t.getDate()-e),t.toISOString().slice(0,10)}function UZ(e){return e?e===`desc`?`asc`:null:`desc`}function WZ({label:e,field:t,sortField:n,sortDir:r,onSort:i,className:a}){let o=n===t;return(0,K.jsx)(`th`,{className:`px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider cursor-pointer select-none hover:text-gray-700 transition-colors ${a??``}`,onClick:()=>i(t),children:(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e,o&&r===`desc`?(0,K.jsx)(T,{className:`h-3 w-3`}):o&&r===`asc`?(0,K.jsx)(O,{className:`h-3 w-3`}):(0,K.jsx)(D,{className:`h-3 w-3 opacity-30`})]})})}function GZ({data:e,maxVal:t,height:n=24,gap:r=6}){return(0,K.jsx)(`svg`,{width:280,height:e.length*(n+r),className:`shrink-0`,children:e.map((e,i)=>{let a=i*(n+r),o=t>0?e.input/t*280:0,s=t>0?e.output/t*280:0;return(0,K.jsxs)(`g`,{children:[(0,K.jsx)(`rect`,{x:0,y:a,width:o,height:n,rx:3,fill:`var(--color-blue-500)`,opacity:.7}),(0,K.jsx)(`rect`,{x:o,y:a,width:s,height:n,rx:3,fill:`var(--color-green-500)`,opacity:.7}),(0,K.jsx)(`text`,{x:o+s+4,y:a+n/2,dominantBaseline:`central`,className:`fill-gray-500 text-[10px]`,children:e.label})]},e.label)})})}function KZ({data:e,w:t=600,h:n=180}){let r={top:10,right:10,bottom:24,left:50},i=t-r.left-r.right,a=n-r.top-r.bottom,o=Math.max(1,...e.map(e=>e.input+e.output)),s=t=>r.left+(e.length>1?t/(e.length-1)*i:i/2),c=e=>r.top+a-e/o*a,l=e.map((e,t)=>`${s(t)},${c(e.input)}`).join(` `),u=e.map((e,t)=>`${s(t)},${c(e.input+e.output)}`).join(` `),d=`${s(e.length-1)},${r.top+a} ${s(0)},${r.top+a}`,f=[0,o/2,o].map(e=>({y:c(e),label:zZ(e)}));return(0,K.jsxs)(`svg`,{width:t,height:n,className:`w-full`,viewBox:`0 0 ${t} ${n}`,preserveAspectRatio:`xMidYMid meet`,children:[f.map(e=>(0,K.jsxs)(`g`,{children:[(0,K.jsx)(`line`,{x1:r.left,y1:e.y,x2:t-r.right,y2:e.y,stroke:`var(--color-gray-200)`,strokeDasharray:`3,2`}),(0,K.jsx)(`text`,{x:r.left-6,y:e.y,textAnchor:`end`,dominantBaseline:`central`,className:`fill-gray-400 text-[9px]`,children:e.label})]},e.label)),(0,K.jsx)(`polygon`,{points:`${u} ${d}`,fill:`var(--color-green-500)`,opacity:.2}),(0,K.jsx)(`polyline`,{points:u,fill:`none`,stroke:`var(--color-green-500)`,strokeWidth:1.5,opacity:.6}),(0,K.jsx)(`polygon`,{points:`${l} ${d}`,fill:`var(--color-blue-500)`,opacity:.2}),(0,K.jsx)(`polyline`,{points:l,fill:`none`,stroke:`var(--color-blue-500)`,strokeWidth:1.5}),e.filter((t,n)=>e.length<=14||n%Math.ceil(e.length/14)===0||n===e.length-1).map((t,r)=>(0,K.jsx)(`text`,{x:s(e.indexOf(t)),y:n-4,textAnchor:`middle`,className:`fill-gray-400 text-[9px]`,children:BZ(t.date)},t.date))]})}function qZ({dailyUsage:e,timeRange:t}){let[n,r]=(0,_.useState)(`total`),[i,a]=(0,_.useState)(`desc`),[o,s]=(0,_.useState)(!1),c=(0,_.useMemo)(()=>{let n=t===`today`?HZ(0):t===`7d`?HZ(7):t===`30d`?HZ(30):``,r={};for(let[t,i]of Object.entries(e))for(let[e,a]of Object.entries(i)){if(n&&e<n)continue;let i=r[t]??{inputTokens:0,outputTokens:0,cacheReadInputTokens:0};i.inputTokens+=a.inputTokens,i.outputTokens+=a.outputTokens,i.cacheReadInputTokens+=a.cacheReadInputTokens??0,r[t]=i}return Object.entries(r).map(([e,t])=>({model:e,...t,total:t.inputTokens+t.outputTokens,cacheRate:t.inputTokens+t.cacheReadInputTokens>0?Math.round(t.cacheReadInputTokens/(t.inputTokens+t.cacheReadInputTokens)*100):0}))},[e,t]),l=(0,_.useMemo)(()=>{let e=[...c];return n&&i&&e.sort((e,t)=>{let r=n===`model`?e.model:e[n]??0,a=n===`model`?t.model:t[n]??0;return typeof r==`string`&&typeof a==`string`?i===`desc`?a.localeCompare(r):r.localeCompare(a):i===`desc`?a-r:r-a}),e},[c,n,i]),u=e=>{if(n===e){let e=UZ(i);e?a(e):(r(null),a(null))}else r(e),a(`desc`)},d=l.reduce((e,t)=>e+t.total,0),f=Math.max(...l.map(e=>e.total),1),p=o?l:l.slice(0,10),m=p.map(e=>({label:e.model,input:e.inputTokens,output:e.outputTokens}));return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-4 gap-3 mb-6`,children:[(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Total Tokens`}),(0,K.jsx)(`div`,{className:`text-xl font-semibold text-gray-900`,children:zZ(d)})]}),(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Prompt`}),(0,K.jsx)(`div`,{className:`text-xl font-semibold text-blue-600`,children:zZ(l.reduce((e,t)=>e+t.inputTokens,0))})]}),(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Completion`}),(0,K.jsx)(`div`,{className:`text-xl font-semibold text-green-600`,children:zZ(l.reduce((e,t)=>e+t.outputTokens,0))})]}),(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:`Cached Tokens`}),(0,K.jsx)(`div`,{className:`text-xl font-semibold text-purple-600`,children:zZ(l.reduce((e,t)=>e+t.cacheReadInputTokens,0))}),(0,K.jsx)(`div`,{className:`text-[11px] text-purple-400 mt-0.5`,children:(()=>{let e=l.reduce((e,t)=>e+t.cacheReadInputTokens,0),t=l.reduce((e,t)=>e+t.inputTokens,0);return t+e>0?`${Math.round(e/(t+e)*100)}% of potential input`:`—`})()})]})]}),p.length>0&&(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4 mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mb-3`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Token Distribution`}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-blue-500 opacity-70`}),` Input`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-green-500 opacity-70`}),` Output`]})]}),(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsx)(GZ,{data:m,maxVal:f})})]}),(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:[(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,K.jsx)(WZ,{label:`Model`,field:`model`,sortField:n,sortDir:i,onSort:u,className:`text-left`}),(0,K.jsx)(WZ,{label:`Input`,field:`inputTokens`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,K.jsx)(WZ,{label:`Output`,field:`outputTokens`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,K.jsx)(WZ,{label:`Total`,field:`total`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,K.jsx)(WZ,{label:`Cached`,field:`cacheRate`,sortField:n,sortDir:i,onSort:u,className:`text-right`}),(0,K.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`%`})]})}),(0,K.jsxs)(`tbody`,{children:[p.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`code`,{className:`text-[12px] text-gray-800`,children:e.model})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-blue-600 tabular-nums`,children:zZ(e.inputTokens)}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-green-600 tabular-nums`,children:zZ(e.outputTokens)}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:zZ(e.total)}),(0,K.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-purple-600 tabular-nums`,children:[zZ(e.cacheReadInputTokens),` `,(0,K.jsxs)(`span`,{className:`text-[10px] text-purple-400`,children:[`(`,e.cacheRate,`%)`]})]}),(0,K.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[11px] text-gray-400 tabular-nums`,children:[d>0?(e.total/d*100).toFixed(1):0,`%`]})]},e.model)),p.length===0&&(0,K.jsx)(`tr`,{children:(0,K.jsx)(`td`,{colSpan:6,className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:`No token usage data`})})]})]}),l.length>10&&(0,K.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 bg-gray-50/50`,children:(0,K.jsx)(`button`,{onClick:()=>s(!o),className:`text-[11px] text-gray-500 hover:text-gray-900 transition-colors`,children:o?`Show less`:`Show all ${l.length} models`})})]})]})}function JZ({dailyUsage:e,timeRange:t}){let{dates:n,models:r,data:i,chartData:a}=(0,_.useMemo)(()=>{let n=new Set(Object.keys(e)),r=new Set;for(let t of Object.keys(e))for(let n of Object.keys(e[t]))r.add(n);let i=Array.from(r).sort(),a=Array.from(n).sort(),o=t===`today`?HZ(0):t===`7d`?HZ(7):t===`30d`?HZ(30):``,s=o?i.filter(e=>e>=o):i,c={};for(let t of a){c[t]={};for(let n of s)c[t][n]=(e[t]?.[n]?.inputTokens??0)+(e[t]?.[n]?.outputTokens??0)}return{dates:s,models:a,data:c,chartData:s.map(t=>{let n=0,r=0;for(let i of a)n+=e[i]?.[t]?.inputTokens??0,r+=e[i]?.[t]?.outputTokens??0;return{date:t,input:n,output:r}})}},[e,t]);return n.length===0?(0,K.jsx)(`div`,{className:`text-center py-8 text-[12px] text-gray-400 italic`,children:`No daily data for this time range`}):(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4 mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 mb-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Daily Trend`}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-blue-500 opacity-70`}),` Input`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-gray-500`,children:[(0,K.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm bg-green-500 opacity-20`}),` Output`]})]}),(0,K.jsx)(KZ,{data:a})]}),(0,K.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full min-w-[500px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,K.jsx)(`th`,{className:`text-left px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider sticky left-0 bg-gray-50/50`,children:`Date`}),(0,K.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Total`}),r.map(e=>(0,K.jsx)(`th`,{className:`text-right px-3 py-2.5 text-[10px] font-medium text-gray-400 uppercase tracking-wider max-w-[120px]`,children:(0,K.jsx)(`span`,{className:`truncate block`,children:e})},e))]})}),(0,K.jsx)(`tbody`,{children:n.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2 text-[12px] text-gray-700 sticky left-0 bg-white`,children:BZ(e)}),(0,K.jsx)(`td`,{className:`px-4 py-2 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:zZ(r.reduce((t,n)=>t+(i[n]?.[e]??0),0))}),r.map(t=>(0,K.jsx)(`td`,{className:`px-3 py-2 text-right text-[11px] text-gray-500 tabular-nums`,children:i[t]?.[e]?zZ(i[t][e]):``},t))]},e))})]})})})]})}function YZ({loopUsage:e,timeRange:t}){let[n,r]=(0,_.useState)(`lastActivity`),[i,a]=(0,_.useState)(`desc`),o=t===`today`?HZ(0):t===`7d`?HZ(7):t===`30d`?HZ(30):``,s=(0,_.useMemo)(()=>{let t=o?e.filter(e=>(e.lastActivity??``).slice(0,10)>=o):[...e];return n&&i&&t.sort((e,t)=>{let r,a;return n===`total`?(r=e.inputTokens+e.outputTokens,a=t.inputTokens+t.outputTokens):n===`title`||n===`lastActivity`?(r=e[n]??``,a=t[n]??``):(r=e[n]??0,a=t[n]??0),typeof r==`string`&&typeof a==`string`?i===`desc`?a.localeCompare(r):r.localeCompare(a):i===`desc`?a-r:r-a}),t},[e,o,n,i]),c=e=>{if(n===e){let e=UZ(i);e?a(e):(r(null),a(null))}else r(e),a(`desc`)},l=s.reduce((e,t)=>e+t.inputTokens+t.outputTokens,0),u=zn();return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex items-center gap-4 mb-4 px-1`,children:(0,K.jsxs)(`span`,{className:`text-[13px] text-gray-600`,children:[(0,K.jsx)(`span`,{className:`font-semibold text-gray-900`,children:s.length}),` loops ·`,` `,(0,K.jsx)(`span`,{className:`font-semibold text-gray-900`,children:zZ(l)}),` total tokens`]})}),(0,K.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-200 bg-gray-50/50`,children:[(0,K.jsx)(WZ,{label:`Loop`,field:`title`,sortField:n,sortDir:i,onSort:c,className:`text-left`}),(0,K.jsx)(`th`,{className:`hidden sm:table-cell text-left px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Models`}),(0,K.jsx)(WZ,{label:`Input`,field:`inputTokens`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,K.jsx)(WZ,{label:`Output`,field:`outputTokens`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,K.jsx)(WZ,{label:`Total`,field:`total`,sortField:n,sortDir:i,onSort:c,className:`text-right`}),(0,K.jsx)(`th`,{className:`text-right px-4 py-2.5 text-[11px] font-semibold text-gray-500 uppercase tracking-wider`,children:`Cached`}),(0,K.jsx)(WZ,{label:`Last active`,field:`lastActivity`,sortField:n,sortDir:i,onSort:c,className:`text-right hidden sm:table-cell`})]})}),(0,K.jsxs)(`tbody`,{children:[s.map(e=>{let t=e.inputTokens+e.outputTokens,n=e.inputTokens+e.cacheReadInputTokens>0?Math.round(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens)*100):0;return(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 hover:bg-gray-50/50 transition-colors cursor-pointer`,onClick:()=>u(`/loop/${e.loopId}`),children:[(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,K.jsx)(`span`,{className:`text-[12px] text-gray-800 font-medium hover:text-blue-600`,children:e.title})}),(0,K.jsx)(`td`,{className:`hidden sm:table-cell px-4 py-2.5`,children:(0,K.jsx)(`code`,{className:`text-[11px] text-gray-500`,children:e.model})}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-blue-600 tabular-nums`,children:zZ(e.inputTokens)}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-green-600 tabular-nums`,children:zZ(e.outputTokens)}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-gray-900 font-medium tabular-nums`,children:zZ(t)}),(0,K.jsxs)(`td`,{className:`px-4 py-2.5 text-right text-[12px] text-purple-600 tabular-nums`,children:[zZ(e.cacheReadInputTokens),` `,(0,K.jsxs)(`span`,{className:`text-[10px] text-purple-400`,children:[`(`,n,`%)`]})]}),(0,K.jsx)(`td`,{className:`hidden sm:table-cell px-4 py-2.5 text-right text-[11px] text-gray-400`,children:VZ(e.lastActivity)})]},e.loopId)}),s.length===0&&(0,K.jsx)(`tr`,{children:(0,K.jsxs)(`td`,{colSpan:6,className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:[`No loops with token usage`,o?` in this range`:``]})})]})]})})]})}var XZ=[{id:`today`,label:`Today`},{id:`7d`,label:`7 days`},{id:`30d`,label:`30 days`},{id:`all`,label:`All time`}],ZZ=[{id:`models`,label:`By Model`,icon:(0,K.jsx)(ye,{className:`h-3.5 w-3.5`})},{id:`daily`,label:`Daily`,icon:(0,K.jsx)(N,{className:`h-3.5 w-3.5`})},{id:`loops`,label:`By Loop`,icon:(0,K.jsx)(Oe,{className:`h-3.5 w-3.5`})}];function QZ(){zn();let[e,t]=(0,_.useState)(`models`),[n,r]=(0,_.useState)(`30d`),[i,a]=(0,_.useState)({}),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{l(!0),Promise.all([Ah().then(a),jh().then(s)]).finally(()=>l(!1))},[]),c?(0,K.jsx)(`div`,{className:`h-full flex items-center justify-center bg-gray-50`,children:(0,K.jsx)(`div`,{className:`text-[13px] text-gray-400`,children:`loading token data…`})}):(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1 mb-6`,children:[ZZ.map(n=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded text-[12px] font-medium transition-colors ${e===n.id?`bg-white border border-gray-200 text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:[n.icon,n.label]},n.id)),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`div`,{className:`flex items-center gap-0.5`,children:XZ.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>r(e.id),className:`px-2 py-1 rounded text-[11px] font-medium transition-colors ${n===e.id?`bg-white border border-gray-200 text-gray-900 shadow-sm`:`text-gray-500 hover:text-gray-700`}`,children:e.label},e.id))})]}),e===`models`&&(0,K.jsx)(qZ,{dailyUsage:i,timeRange:n}),e===`daily`&&(0,K.jsx)(JZ,{dailyUsage:i,timeRange:n}),e===`loops`&&(0,K.jsx)(YZ,{loopUsage:o,timeRange:n})]})}var $Z=`w-full px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900 transition-colors disabled:bg-gray-50 disabled:text-gray-400`;function eQ(e){return`${e.replace(/[^A-Za-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).toUpperCase()||`PROVIDER`}_API_KEY`}var tQ=[{id:`personal-repo`,label:`Personal Repo`,gated:!1,description:`Your private repo carrying credentials + dotfiles.`,icon:ot},{id:`providers`,label:`AI Providers`,gated:!0,description:`Models, base URLs, API keys. Pick a default.`,icon:te},{id:`claude-config`,label:`Claude Config`,gated:!0,description:`Compose your .claude/ tiers — plugins, MCP servers, settings per tier.`,icon:xe},{id:`mise-config`,label:`Mise Config`,gated:!0,description:`Configure mise toolchain tools per tier — mise.toml for each tier.`,icon:ct},{id:`token-usage`,label:`Token Usage`,gated:!1,description:`Token consumption across models, loops, and time.`,icon:N},{id:`api-tokens`,label:`API Tokens`,gated:!1,description:`Bearer tokens for external programs to drive your loops via the Loop API. See API docs below.`,icon:be},{id:`admin-users`,label:`Users`,gated:!1,description:`Manage workspace members — activate, promote, remove.`,icon:st},{id:`admin-workspace`,label:`Workspace AI Providers`,gated:!1,description:`Shared workspace provider configuration.`,icon:_e},{id:`admin-serve`,label:`Share Artifact Serve`,gated:!1,description:`Public share domain and HTTPS settings.`,icon:Ke},{id:`admin-presets`,label:`Presets`,gated:!1,description:`Manage preset defaults — AI providers and Mise tool suggestions.`,icon:A}];function nQ(){let e=zn(),t=Cg(),n=t.currentUser?.role===`admin`,{tab:r}=Un(),i=tQ.some(e=>e.id===r)?r:`personal-repo`,[a,o]=(0,_.useState)(!0),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)({}),h=(0,_.useCallback)(async()=>{o(!0);let[e,t]=await Promise.all([Jp(),Th()]);c(!!e&&!!e.personalRepo&&e.imported),u(!e||!e.personalRepo?`no personal repo configured`:e.imported?``:`personal repo not imported yet`),t&&(f(t.disk),m(t.refExists)),o(!1)},[]);(0,_.useEffect)(()=>{$p().catch(()=>{}).finally(()=>{h()})},[h]),(0,_.useEffect)(()=>{!a&&!s&&tQ.find(e=>e.id===i)?.gated&&!i.startsWith(`admin-`)&&e(`/settings/personal-repo`,{replace:!0})},[a,s,i,e]);let g=tQ.find(e=>e.id===i)??tQ[0],v=g.gated&&!s&&!i.startsWith(`admin-`),[y,b]=(0,_.useState)(``),x=tQ.filter(e=>!(e.id.startsWith(`admin-`)&&!n)),S=x.filter(e=>!e.id.startsWith(`admin-`)),C=x.filter(e=>e.id.startsWith(`admin-`)),w=y.trim()===``?x:x.filter(e=>e.label.toLowerCase().includes(y.toLowerCase())||e.description.toLowerCase().includes(y.toLowerCase())||e.id.toLowerCase().includes(y.toLowerCase()));return(0,K.jsxs)(`div`,{className:`h-full overflow-hidden bg-gray-50 flex flex-col`,children:[(0,K.jsxs)(`header`,{className:`shrink-0 border-b border-gray-200 bg-white px-4 sm:px-6 h-12 flex items-center gap-3`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>e(-1),className:`w-8 h-8 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`back`,children:(0,K.jsx)(E,{size:16})}),(0,K.jsx)(`h1`,{className:`text-[15px] font-semibold text-gray-900`,children:`Settings`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e(`/context/personal?file=.loopat/config.json&edit=1`),className:`h-7 px-2.5 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-700 flex items-center gap-1.5`,title:`open raw config.json in Context tab`,children:[(0,K.jsx)(oe,{size:12}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:`edit raw config.json`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:h,disabled:a,className:`h-7 px-2.5 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-700 flex items-center gap-1.5 disabled:opacity-50`,title:`reload`,children:[(0,K.jsx)(Be,{size:12,className:a?`animate-spin`:``}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:`reload`})]})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col sm:flex-row`,children:[(0,K.jsxs)(`nav`,{className:`sm:w-56 shrink-0 sm:border-r border-b sm:border-b-0 border-gray-200 bg-white flex flex-col`,children:[(0,K.jsx)(`div`,{className:`hidden sm:block px-3 py-3 border-b border-gray-100`,children:(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Ue,{size:12,className:`absolute left-2 top-1/2 -translate-y-1/2 text-gray-400`}),(0,K.jsx)(`input`,{value:y,onChange:e=>b(e.target.value),placeholder:`search settings`,className:`w-full pl-7 pr-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-400 bg-gray-50 focus:bg-white`})]})}),(0,K.jsxs)(`ul`,{className:`flex sm:flex-col gap-0.5 sm:gap-0 p-2 sm:py-2 overflow-x-auto sm:overflow-x-visible`,children:[y.trim()?w.map(t=>{let n=t.id===i,r=t.gated&&!a&&!s;return(0,K.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,K.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,K.jsx)(`span`,{className:`flex-1 truncate`,children:t.label}),r&&(0,K.jsx)(`span`,{title:`locked`,children:(0,K.jsx)(Te,{size:11,className:`text-gray-400 shrink-0`})})]})},t.id)}):(0,K.jsxs)(K.Fragment,{children:[S.map(t=>{let n=t.id===i,r=t.gated&&!a&&!s;return(0,K.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,K.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,K.jsx)(`span`,{className:`flex-1 truncate`,children:t.label}),r&&(0,K.jsx)(`span`,{title:`locked`,children:(0,K.jsx)(Te,{size:11,className:`text-gray-400 shrink-0`})})]})},t.id)}),C.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`li`,{className:`px-3 pt-3 pb-1 text-[10px] font-semibold text-gray-400 uppercase tracking-wider`,children:`Admin Settings`}),C.map(t=>{let n=t.id===i;return(0,K.jsx)(`li`,{className:`shrink-0 sm:px-1`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e(`/settings/${t.id}`),className:`w-full text-left px-2.5 py-1.5 rounded text-[13px] flex items-center gap-2 transition-colors whitespace-nowrap `+(n?`bg-gray-100 text-gray-900 font-medium`:`text-gray-600 hover:bg-gray-50 hover:text-gray-900`),children:[(0,K.jsx)(t.icon,{size:14,className:`shrink-0 ${n?`text-gray-600`:`text-gray-400`}`}),(0,K.jsx)(`span`,{className:`flex-1 truncate`,children:t.label})]})},t.id)})]})]}),w.length===0&&(0,K.jsx)(`li`,{className:`px-3 py-2 text-[11px] text-gray-400 italic`,children:`no match`})]})]}),(0,K.jsx)(`main`,{className:`flex-1 min-w-0 min-h-0 overflow-auto`,children:(0,K.jsx)(`div`,{className:`max-w-4xl mx-auto px-4 sm:px-6 py-5`,children:a&&!d?(0,K.jsx)(`div`,{className:`text-[13px] text-gray-400 italic py-12 text-center`,children:`loading…`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-base font-semibold text-gray-900 flex items-center gap-2`,children:[(0,K.jsx)(g.icon,{size:18,className:`text-gray-400`}),g.label]}),(0,K.jsx)(`p`,{className:`text-xs text-gray-500 mt-0.5`,children:g.description})]}),v&&(0,K.jsxs)(`div`,{className:`mb-4 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 flex items-start gap-2`,children:[(0,K.jsx)(R,{size:16,className:`text-amber-700 mt-0.5 shrink-0`}),(0,K.jsxs)(`div`,{className:`text-[13px] text-amber-900 flex-1`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:`Set up your personal repo first`}),(0,K.jsxs)(`div`,{className:`text-[12px] text-amber-800/90 mt-0.5`,children:[`These settings live in your personal repo. Complete setup in the `,(0,K.jsx)(`button`,{onClick:()=>e(`/settings/personal-repo`),className:`underline`,children:`Personal Repo`}),` tab; this section will unlock automatically.`,(0,K.jsxs)(`span`,{className:`text-amber-700/70`,children:[` (`,l,`)`]})]})]})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[v&&(0,K.jsxs)(`div`,{className:`absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-white/60 backdrop-blur-[1px] rounded-lg`,children:[(0,K.jsx)(Te,{size:24,className:`text-gray-300`}),(0,K.jsx)(`span`,{className:`text-[13px] text-gray-500 font-medium`,children:`Set up your personal repo first`})]}),(0,K.jsxs)(`div`,{className:v?`opacity-30`:``,children:[i===`personal-repo`&&(0,K.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,K.jsx)(IY,{onDone:h})}),i===`providers`&&(0,K.jsx)(rQ,{disk:d,refExists:p,onChanged:h,disabled:v}),i===`claude-config`&&(0,K.jsx)(vX,{disabled:v}),i===`mise-config`&&(0,K.jsx)(vZ,{disabled:v}),i===`token-usage`&&(0,K.jsx)(QZ,{}),i===`api-tokens`&&(0,K.jsx)(aQ,{}),i===`admin-users`&&(0,K.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,K.jsx)(qY,{currentUserId:t.currentUser?.id??``})}),i===`admin-workspace`&&(0,K.jsx)(XY,{}),i===`admin-serve`&&(0,K.jsx)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-5`,children:(0,K.jsx)(QY,{})}),i===`admin-presets`&&(0,K.jsx)(IZ,{})]})]})]})})})]})]})}function rQ({disk:e,refExists:t,onChanged:n,disabled:r}){let[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)({}),[y,b]=(0,_.useState)({}),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(``),[T,E]=(0,_.useState)(null),[D,O]=(0,_.useState)(``),[k,A]=(0,_.useState)({}),[j,M]=(0,_.useState)({}),[N,F]=(0,_.useState)([]);(0,_.useEffect)(()=>{Mh().then(e=>F(e.providerPresets)).catch(()=>{})},[]),(0,_.useEffect)(()=>{if(!e){a(null),d(!1);return}let n={default:``,providers:{}};for(let[r,i]of Object.entries(e.providers)){if(r==="default"){typeof i==`string`&&(n.default=i);continue}if(i&&typeof i==`object`){let e=i,a=t[`providers.${r}.apiKey`];n.providers[r]={models:e.models&&e.models.length>0?e.models.map(e=>({id:e.id,enabled:e.enabled!==!1})):e.model?[{id:e.model,enabled:!0}]:[],baseUrl:e.baseUrl??``,maxContextTokens:e.maxContextTokens?String(e.maxContextTokens):``,enabled:e.enabled!==!1,apiKeyNewValue:``,apiKeyStored:!!a?.exists}}}a(n)},[e,t]);let I=i?Object.keys(i.providers):[],L=(e,t)=>{a(n=>!n||!n.providers[e]?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],...t}}})},R=e=>{a(t=>{if(!t)return t;let{[e]:n,...r}=t.providers,i=t.default===e||t.default.startsWith(`${e}/`);return{...t,providers:r,default:i?``:t.default}})},z=(e,t,n)=>{a(r=>{if(!r||!r.providers[e])return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,...n}:e);return{...r,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}})},B=(e,t)=>{a(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.map(e=>e.id===t?{...e,enabled:!e.enabled}:e);return{...n,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},V=(e,t)=>{a(n=>{if(!n||!n.providers[e])return n;let r=n.providers[e].models.filter(e=>e.id!==t),i=n.default===`${e}/${t}`;return{...n,default:i?``:n.default,providers:{...n.providers,[e]:{...n.providers[e],models:r}}}})},H=e=>{let t=(g[e]??``).trim();t&&(a(n=>!n||!n.providers[e]||n.providers[e].models.some(e=>e.id===t)?n:{...n,providers:{...n.providers,[e]:{...n.providers[e],models:[...n.providers[e].models,{id:t,enabled:!0}]}}}),v(t=>({...t,[e]:``})),b(t=>({...t,[e]:!1})))},U=(e,t)=>{let n=D.trim();if(!n||n===t){E(null);return}a(r=>{if(!r||!r.providers[e]||r.providers[e].models.some(e=>e.id===n))return r;let i=r.providers[e].models.map(e=>e.id===t?{...e,id:n}:e),a=r.default===`${e}/${t}`?`${e}/${n}`:r.default;return{...r,default:a,providers:{...r.providers,[e]:{...r.providers[e],models:i}}}}),E(null)},ee=e=>{let t=C.trim();if(!t||t===e||t==="default"){S(null);return}a(n=>{if(!n||!n.providers[e]||n.providers[t])return n;let{[e]:r,...i}=n.providers,a=n.default;return n.default===e?a=t:n.default.startsWith(`${e}/`)&&(a=t+n.default.slice(e.length)),{...n,default:a,providers:{...i,[t]:r}}}),S(null)},W=()=>{let e=f.trim();if(e){if(e==="default"){l(`'default' is reserved`);return}a(t=>!t||t.providers[e]?t:{...t,providers:{...t.providers,[e]:{models:[],baseUrl:``,maxContextTokens:``,enabled:!1,apiKeyNewValue:``,apiKeyStored:!1}}}),p(``),h(!1),l(null)}};return i?(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[I.map(e=>{let t=i.providers[e],n=y[e]??!1,r=t.apiKeyStored||t.apiKeyNewValue.trim()!==``;return(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg overflow-hidden transition-shadow hover:shadow-sm`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 bg-gray-50/50 border-b border-gray-100`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2.5 flex-1 min-w-0 select-none`,children:[(0,K.jsx)(GY,{checked:t.enabled,onCheckedChange:t=>r?L(e,{enabled:t}):void 0,disabled:!r,size:`sm`}),x===e?(0,K.jsx)(`input`,{autoFocus:!0,value:C,onChange:e=>w(e.target.value),onBlur:()=>ee(e),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&ee(e),t.key===`Escape`&&S(null)},className:X($Z,`text-[13px] font-semibold flex-1 min-w-0`)}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>{S(e),w(e)},className:`text-[13px] font-semibold truncate text-left hover:underline ${t.enabled?`text-gray-900`:`text-gray-400`}`,title:`click to rename`,children:e}),!t.enabled&&(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-gray-100 text-gray-400 font-medium shrink-0`,children:`disabled`})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>R(e),className:`text-[11px] text-gray-400 hover:text-red-500 transition-colors shrink-0`,children:`remove`})]}),(0,K.jsxs)(`div`,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(iQ,{label:`Base URL`,children:(0,K.jsx)(`input`,{value:t.baseUrl,onChange:t=>L(e,{baseUrl:t.target.value}),placeholder:`https://api.example.com`,className:$Z})}),(0,K.jsx)(iQ,{label:`Max context tokens`,children:(0,K.jsx)(`input`,{type:`number`,value:t.maxContextTokens,onChange:t=>L(e,{maxContextTokens:t.target.value}),placeholder:`auto`,className:$Z})}),(0,K.jsx)(iQ,{label:t.apiKeyStored?`API key (set — type to overwrite)`:`API key`,className:`sm:col-span-2`,children:(0,K.jsx)(`input`,{type:`password`,value:t.apiKeyNewValue,onChange:t=>L(e,{apiKeyNewValue:t.target.value}),placeholder:t.apiKeyStored?`•••••• stored encrypted in vault`:`paste API key`,className:$Z})})]}),(0,K.jsxs)(`div`,{className:`border-t border-gray-100 pt-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`span`,{className:`text-[11px] font-semibold text-gray-400 uppercase tracking-wider`,children:[`Models (`,t.models.length,`)`]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>b(t=>({...t,[e]:!n})),className:`text-[11px] text-gray-500 hover:text-gray-900 inline-flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Re,{size:11}),` add model`]})]}),n&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:g[e]??``,onChange:t=>v(n=>({...n,[e]:t.target.value})),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&H(e),t.key===`Escape`&&b(t=>({...t,[e]:!1}))},placeholder:`model ID (e.g. claude-sonnet-4-20250514)`,className:X($Z,`flex-1 text-[11px]`)}),(0,K.jsx)(kg,{size:`xs`,onClick:()=>H(e),children:`add`}),(0,K.jsx)(kg,{variant:`ghost`,size:`xs`,onClick:()=>b(t=>({...t,[e]:!1})),children:`cancel`})]}),t.models.length===0&&!n&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 italic py-2`,children:`no models — add one above`}),(0,K.jsx)(`div`,{className:`-mx-1`,children:t.models.map(n=>{let r=i.default===`${e}/${n.id}`,o=`${e}::${n.id}`,s=T===o,c=k[`${e}::${n.id}`],l=j[`${e}::${n.id}`];return(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 py-1.5 rounded group hover:bg-gray-50 transition-colors`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>a(t=>t&&{...t,default:r?``:`${e}/${n.id}`}),className:`shrink-0 text-[13px] leading-none transition-colors ${r?`text-amber-500`:`text-gray-200 hover:text-amber-400`}`,title:r?`current default model`:`set as default model`,children:`★`}),(0,K.jsx)(`label`,{className:`flex items-center shrink-0 cursor-pointer`,children:(0,K.jsx)(`input`,{type:`checkbox`,checked:n.enabled!==!1,onChange:()=>B(e,n.id),className:`h-3.5 w-3.5 rounded border-gray-300 text-gray-900 accent-gray-900`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1`,children:[s?(0,K.jsx)(`input`,{autoFocus:!0,value:D,onChange:e=>O(e.target.value),onBlur:()=>U(e,n.id),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing&&U(e,n.id),t.key===`Escape`&&E(null)},className:X($Z,`text-[11px] flex-1 min-w-0`)}):(0,K.jsx)(`code`,{className:`text-[12px] truncate cursor-pointer hover:bg-gray-100 px-0.5 rounded ${n.enabled===!1?`text-gray-300 line-through`:`text-gray-700`}`,onClick:()=>{E(o),O(n.id)},title:`click to edit model ID`,children:n.id}),n.enabled===!1&&(0,K.jsx)(`span`,{className:`text-[10px] text-gray-300 font-medium shrink-0`,children:`off`})]}),(0,K.jsx)(`input`,{type:`number`,value:n.maxContextTokens??``,onChange:t=>z(e,n.id,{maxContextTokens:t.target.value?Number(t.target.value):void 0}),placeholder:`auto`,className:`w-24 px-1.5 py-0.5 border border-gray-200 rounded text-[10px] outline-none focus:border-gray-400 shrink-0 ${n.maxContextTokens?``:`opacity-0 group-hover:opacity-100 transition-opacity`}`,title:`max context tokens (empty = auto)`}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{let r=t.apiKeyNewValue.trim(),i=`${e}::${n.id}`;if(!r&&!t.apiKeyStored){A(e=>({...e,[i]:`error`})),M(e=>({...e,[i]:`enter an API key first`})),setTimeout(()=>{A(e=>{let{[i]:t,...n}=e;return n}),M(e=>{let{[i]:t,...n}=e;return n})},3e3);return}A(e=>({...e,[i]:`testing`})),M(e=>({...e,[i]:``}));try{let a=r?await ph(t.baseUrl,r,n.id):await ph(t.baseUrl,``,n.id,e,`personal`);A(e=>({...e,[i]:a.ok?`ok`:`error`})),a.ok||M(e=>({...e,[i]:a.error??`unknown error`}))}catch(e){A(e=>({...e,[i]:`error`})),M(t=>({...t,[i]:e?.message??`connection failed`}))}setTimeout(()=>{A(e=>{let{[i]:t,...n}=e;return n}),M(e=>{let{[i]:t,...n}=e;return n})},4e3)},disabled:c===`testing`||!t.apiKeyStored&&!t.apiKeyNewValue.trim(),className:`shrink-0 text-[10px] px-1 py-0 rounded transition-colors ${!t.apiKeyStored&&!t.apiKeyNewValue.trim()?`opacity-0 group-hover:opacity-100 text-gray-300`:c===`ok`?`bg-emerald-100 text-emerald-700`:c===`error`?`bg-red-100 text-red-700`:c===`testing`?`bg-gray-100 text-gray-400 animate-pulse`:`text-gray-400 hover:text-gray-700 opacity-0 group-hover:opacity-100`}`,title:l||(t.apiKeyNewValue.trim()||t.apiKeyStored?`test connection`:`enter an API key first`),children:c===`ok`?`OK`:c===`error`?`FAIL`:c===`testing`?`...`:`test`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>V(e,n.id),className:`text-gray-300 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,title:`remove model`,children:(0,K.jsx)(tt,{size:11})})]},n.id)})})]})]})]},e)}),(0,K.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:N.filter(e=>!i.providers[e.name]).map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{a(t=>!t||t.providers[e.name]?t:{...t,providers:{...t.providers,[e.name]:{models:e.models.map(e=>({id:e,enabled:!0})),baseUrl:e.baseUrl,maxContextTokens:``,enabled:!1,apiKeyNewValue:``,apiKeyStored:!1}}})},className:`px-2 py-0.5 rounded border border-gray-200 bg-white text-[10px] text-gray-500 hover:text-gray-900 hover:border-gray-400 transition-colors`,title:`Add ${e.name} preset`,children:[`+ `,e.name]},e.name))}),m?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{autoFocus:!0,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&W(),e.key===`Escape`&&h(!1)},placeholder:`provider name`,className:X($Z,`flex-1`)}),(0,K.jsx)(kg,{size:`sm`,onClick:W,children:`add`}),(0,K.jsx)(kg,{variant:`ghost`,size:`sm`,onClick:()=>{h(!1),p(``)},children:`cancel`})]}):(0,K.jsxs)(`button`,{onClick:()=>h(!0),className:`self-start text-xs text-gray-500 hover:text-gray-900 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:12}),` add custom provider`]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 py-3 border-t border-gray-100`,children:[c&&(0,K.jsx)(`span`,{className:`text-xs text-red-600`,children:c}),u&&!c&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-700 flex items-center gap-1`,children:[(0,K.jsx)(P,{size:12}),` saved`]}),(0,K.jsx)(kg,{size:`sm`,onClick:async()=>{if(!i)return;s(!0),l(null);for(let[e,t]of Object.entries(i.providers)){if(!t.apiKeyNewValue.trim())continue;let n=await Dh(eQ(e),t.apiKeyNewValue.trim());if(!n.ok){l(`apiKey write failed for "${e}": ${n.error}`),s(!1);return}}let e={};i.default&&(e.default=i.default);for(let[t,n]of Object.entries(i.providers)){let r=n.models.filter(e=>e.id.trim()).map(e=>({id:e.id.trim(),...e.enabled?{}:{enabled:!1},...e.maxContextTokens&&e.maxContextTokens>0?{maxContextTokens:e.maxContextTokens}:{}}));e[t]={baseUrl:n.baseUrl,apiKey:`\${${eQ(t)}}`,...r.length>0?{models:r}:{},...n.maxContextTokens?{maxContextTokens:Number(n.maxContextTokens)}:{},...n.enabled?{}:{enabled:!1}}}let t=await Eh({providers:e});if(!t.ok){s(!1),l(t.error??`save failed`);return}let r=await em();s(!1),r.ok||l(r.conflict?`Saved locally, but it conflicts with the remote — your edit is kept, not lost. Resolve it in Settings → Personal repo (take remote, or in a loop).`:r.needsPull?`Saved locally — remote moved while pushing. Save again to retry.`:`Saved locally, but push to remote failed: ${r.error??`unknown`}`),d(!0),setTimeout(()=>d(!1),2500),n()},disabled:o||r,children:o?`saving…`:`save providers`})]})]}):(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic`,children:`no providers yet`})}function iQ({label:e,children:t,className:n}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1 ${n??``}`,children:[(0,K.jsx)(`span`,{className:`text-[11px] font-medium text-gray-500`,children:e}),t]})}function aQ(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(!0),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(null),g=(0,_.useCallback)(async()=>{r(!0),h(null),t(await vg()),r(!1)},[]);(0,_.useEffect)(()=>{g()},[g]);let v=async()=>{if(o)return;s(!0),h(null);let e=await yg(i.trim()||`default`);s(!1),e?(l(e.token),a(``),d(!1),g()):h(`Failed to create token`)},y=async e=>{h(null);let t=await bg(e);p(null),t?g():h(`Failed to revoke token`)};return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[m&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-[12px] text-red-700 flex items-center gap-2`,children:[(0,K.jsx)(R,{size:14}),` `,m]}),c&&(0,K.jsxs)(`div`,{className:`rounded-lg border border-emerald-200 bg-emerald-50 p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,K.jsx)(P,{size:14,className:`text-emerald-600`}),(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-emerald-900`,children:`Token created — copy it now, it won't be shown again`})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`code`,{className:`flex-1 text-[12px] bg-white border border-emerald-200 rounded px-3 py-2 font-mono text-gray-800 select-all break-all`,children:c}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{c&&navigator.clipboard.writeText(c).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})},className:`shrink-0 h-8 px-3 rounded text-xs border border-emerald-300 hover:bg-emerald-100 text-emerald-800 flex items-center gap-1.5`,children:[u?(0,K.jsx)(P,{size:12}):(0,K.jsx)(ee,{size:12}),u?`copied`:`copy`]})]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>l(null),className:`mt-2 text-[11px] text-emerald-700 hover:text-emerald-900 underline`,children:`dismiss`})]}),(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white px-4 py-3 flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900`,children:`Loop API documentation`}),(0,K.jsx)(`p`,{className:`text-[11px] text-gray-500 mt-0.5`,children:`Interactive reference for the endpoints these tokens authenticate against.`})]}),(0,K.jsx)(`a`,{href:`/api/v1/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`shrink-0 inline-flex items-center gap-1.5 h-8 px-3 rounded text-[12px] border border-gray-300 hover:bg-gray-50 text-gray-700`,children:`Open docs →`})]}),(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white`,children:[(0,K.jsxs)(`div`,{className:`px-4 py-3 border-b border-gray-100`,children:[(0,K.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900`,children:`Your tokens`}),(0,K.jsx)(`p`,{className:`text-[11px] text-gray-500 mt-0.5`,children:`External programs use these tokens to call loopat under your identity — your providers, API keys, and vault.`})]}),n?(0,K.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-gray-400 italic`,children:`loading…`}):e.length===0?(0,K.jsx)(`div`,{className:`px-4 py-8 text-center text-[12px] text-gray-400`,children:`No API tokens yet. Create one below.`}):(0,K.jsxs)(`table`,{className:`w-full text-[13px]`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 text-left text-[11px] text-gray-500 uppercase tracking-wider`,children:[(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Label`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Token`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Created`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium w-10`})]})}),(0,K.jsx)(`tbody`,{children:e.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-50 hover:bg-gray-50`,children:[(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-gray-900`,children:e.label}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 font-mono text-[12px] text-gray-500`,children:e.tokenId}),(0,K.jsx)(`td`,{className:`px-4 py-2.5 text-gray-500 text-[12px]`,children:new Date(e.createdAt).toLocaleDateString()}),(0,K.jsx)(`td`,{className:`px-4 py-2.5`,children:f===e.tokenId?(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>y(e.tokenId),className:`text-[11px] text-red-600 hover:text-red-800 font-medium`,children:`confirm`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(null),className:`text-[11px] text-gray-400 hover:text-gray-600`,children:`cancel`})]}):(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(e.tokenId),className:`w-7 h-7 flex items-center justify-center rounded text-gray-400 hover:text-red-600 hover:bg-red-50`,title:`revoke token`,children:(0,K.jsx)(tt,{size:13})})})]},e.tokenId))})]})]}),(0,K.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,K.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900 mb-2`,children:`Create new token`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`label (e.g. dingtalk-bot)`,className:`flex-1 px-2.5 py-1.5 border border-gray-300 rounded text-[13px] outline-none bg-white focus:border-gray-900 focus:ring-1 focus:ring-gray-900`,onKeyDown:e=>e.key===`Enter`&&v()}),(0,K.jsxs)(`button`,{type:`button`,onClick:v,disabled:o,className:`h-8 px-3 rounded text-xs bg-gray-900 hover:bg-gray-800 text-white flex items-center gap-1.5 disabled:opacity-50`,children:[(0,K.jsx)(Re,{size:12}),o?`creating…`:`create token`]})]})]}),(0,K.jsx)(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 px-4 py-3`,children:(0,K.jsxs)(`p`,{className:`text-[11px] text-gray-500 leading-relaxed`,children:[(0,K.jsx)(`strong`,{className:`text-gray-700`,children:`Usage:`}),` pass the token as`,` `,(0,K.jsx)(`code`,{className:`bg-white border border-gray-200 rounded px-1 py-0.5 text-[10px]`,children:`Authorization: Bearer <token>`}),` `,`when calling`,` `,(0,K.jsx)(`code`,{className:`bg-white border border-gray-200 rounded px-1 py-0.5 text-[10px]`,children:`POST /api/runtime/v1/turn/stream`}),`. The request will run under your identity with your configured providers and API keys.`]})}),(0,K.jsx)(WY,{})]})}function oQ(){let e=zn(),t=Cg().currentUser?.role===`admin`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(``),g=(0,_.useCallback)(async()=>{let e=await hh();e?r(e):h(`forbidden or server unreachable`),a(!1)},[]);if((0,_.useEffect)(()=>{if(!t)return;g();let e=setInterval(g,5e3);return()=>clearInterval(e)},[t,g]),!t)return(0,K.jsxs)(`div`,{className:`h-full flex items-center justify-center text-sm text-gray-500`,children:[`admin only.\xA0`,(0,K.jsx)(`button`,{className:`underline`,onClick:()=>e(`/loop`),children:`back`})]});async function v(){s(!0),h(``);try{let e=await gh();e.ok||h(e.error??`check failed`),await g()}finally{s(!1)}}async function y(){if(n&&!(n.activity.activeLoops>0&&!confirm(`${n.activity.activeLoops} loop(s) and ${n.activity.activeUsers} user(s) are active.\n\nbun --hot will reload code in-place — most pulls don't disturb anyone. If the pull touches deps or schema, you'll need to ssh in and restart manually.\n\nContinue?`))){l(!0),h(``),d(``);try{let e=await _h();p(e.ok),e.ok?e.pulled?d(`pulled ${e.oldHead?.slice(0,7)} → ${e.newHead?.slice(0,7)}\n${e.message??``}`.trim()):d(`already up to date`):d(e.error??`pull failed`),await g()}finally{l(!1)}}}return(0,K.jsx)(`div`,{className:`h-full overflow-y-auto bg-gray-50`,children:(0,K.jsxs)(`div`,{className:`max-w-3xl mx-auto p-4 sm:p-6 flex flex-col gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>e(-1),className:`p-1 rounded hover:bg-gray-100 text-gray-500 hover:text-gray-700`,title:`back`,children:(0,K.jsx)(E,{className:`w-4 h-4`})}),(0,K.jsx)(`h1`,{className:`text-lg font-semibold text-gray-900`,children:`Platform`}),(0,K.jsx)(`span`,{className:`text-xs text-gray-400 ml-auto`,children:`refreshes every 5s`})]}),i&&!n&&(0,K.jsx)(`div`,{className:`text-sm text-gray-400 py-8 text-center`,children:`loading…`}),m&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:m}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(sQ,{icon:(0,K.jsx)(he,{className:`w-4 h-4`}),title:`Version`,children:(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,K.jsxs)(`div`,{className:`text-gray-700`,children:[(0,K.jsx)(`span`,{className:`text-gray-400 mr-2`,children:`branch`}),(0,K.jsx)(`span`,{className:`font-mono`,children:n.version.branch}),(0,K.jsx)(`span`,{className:`text-gray-400 mx-2`,children:`·`}),(0,K.jsx)(`span`,{className:`text-gray-400 mr-1`,children:`commit`}),(0,K.jsx)(`span`,{className:`font-mono`,children:n.version.commit.slice(0,7)})]}),n.version.behindBy>0?(0,K.jsxs)(`div`,{className:`text-amber-700 text-xs`,children:[`behind by `,n.version.behindBy,` commit`,n.version.behindBy===1?``:`s`,` —`,` `,(0,K.jsx)(`span`,{className:`font-mono`,children:n.version.latestCommit?.slice(0,7)}),` `,`"`,n.version.latestMessage,`"`]}):(0,K.jsx)(`div`,{className:`text-xs text-emerald-700`,children:`up to date`}),(0,K.jsx)(`div`,{className:`mt-2`,children:(0,K.jsxs)(`button`,{onClick:v,disabled:o,className:`text-xs px-2.5 py-1 rounded border border-gray-300 hover:bg-gray-100 disabled:opacity-50 inline-flex items-center gap-1.5`,children:[(0,K.jsx)(Be,{className:`w-3 h-3 ${o?`animate-spin`:``}`}),o?`checking…`:`Check for updates`]})})]})}),(0,K.jsxs)(sQ,{icon:(0,K.jsx)(S,{className:`w-4 h-4`}),title:`Activity`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-sm mb-3`,children:[(0,K.jsx)(cQ,{label:`Active loops`,value:n.activity.activeLoops}),(0,K.jsx)(cQ,{label:`Active users`,value:n.activity.activeUsers}),(0,K.jsx)(cQ,{label:`Live WS`,value:n.activity.totalWs}),(0,K.jsx)(cQ,{label:`SDK streaming`,value:n.activity.totalGenerating})]}),n.activity.loops.length===0?(0,K.jsx)(`div`,{className:`text-xs text-gray-400 text-center py-3`,children:`no active loops`}):(0,K.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,K.jsx)(`thead`,{className:`text-gray-400 border-b border-gray-200`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left font-normal py-1.5 pr-2`,children:`title`}),(0,K.jsx)(`th`,{className:`text-left font-normal py-1.5 pr-2`,children:`driver`}),(0,K.jsx)(`th`,{className:`text-right font-normal py-1.5 pr-2`,children:`WS`}),(0,K.jsx)(`th`,{className:`text-left font-normal py-1.5`,children:`state`})]})}),(0,K.jsx)(`tbody`,{children:n.activity.loops.map(e=>(0,K.jsxs)(`tr`,{className:`border-b border-gray-100 last:border-b-0`,children:[(0,K.jsx)(`td`,{className:`py-1.5 pr-2 truncate max-w-[260px]`,title:e.title,children:e.title}),(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-gray-600`,children:e.driver}),(0,K.jsx)(`td`,{className:`py-1.5 pr-2 text-right`,children:e.wsCount}),(0,K.jsx)(`td`,{className:`py-1.5`,children:e.generating?(0,K.jsx)(`span`,{className:`text-blue-600`,children:`streaming…`}):e.lastMsgAgeSec>=0&&e.lastMsgAgeSec<60?(0,K.jsxs)(`span`,{className:`text-emerald-600`,children:[`msg `,e.lastMsgAgeSec,`s ago`]}):(0,K.jsx)(`span`,{className:`text-gray-400`,children:`idle (attached)`})})]},e.id))})]})]}),(0,K.jsx)(sQ,{icon:(0,K.jsx)(ne,{className:`w-4 h-4`}),title:`Update`,children:(0,K.jsxs)(`div`,{className:`flex flex-col gap-2 text-sm`,children:[(0,K.jsx)(`button`,{onClick:y,disabled:c||n.version.behindBy===0,className:`self-start text-sm px-3 py-1.5 rounded text-white disabled:opacity-50 `+(n.activity.activeLoops>0?`bg-amber-600 hover:bg-amber-700`:`bg-gray-900 hover:bg-gray-700`),children:c?`pulling…`:n.version.behindBy===0?`Pull latest (nothing to pull)`:`Pull latest`}),n.activity.activeLoops>0&&n.version.behindBy>0&&(0,K.jsxs)(`div`,{className:`text-xs text-amber-700`,children:[n.activity.activeLoops,` loop(s) active — bun --hot reloads code in-place. Dep / schema changes need a manual restart.`]}),u&&(0,K.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap rounded p-2 border `+(f?`bg-emerald-50 border-emerald-200 text-emerald-800`:`bg-red-50 border-red-200 text-red-800`),children:u})]})})]})]})})}function sQ({icon:e,title:t,children:n}){return(0,K.jsxs)(`div`,{className:`bg-white border border-gray-200 rounded-lg p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-gray-700 mb-3`,children:[(0,K.jsx)(`span`,{className:`text-gray-400`,children:e}),t]}),n]})}function cQ({label:e,value:t}){return(0,K.jsxs)(`div`,{className:`flex flex-col`,children:[(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400 uppercase tracking-wide`,children:e}),(0,K.jsx)(`span`,{className:`text-xl font-semibold text-gray-900 tabular-nums`,children:t})]})}function lQ({onClose:e}={}){let t=Cg(),[n,r]=(0,_.useState)(`login`),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null);return(0,K.jsx)(`div`,{className:e?`fixed inset-0 z-50 bg-black/30 flex items-center justify-center`:`h-full w-full flex items-center justify-center bg-gray-50`,onClick:e?()=>e():void 0,children:(0,K.jsxs)(`div`,{className:`w-full max-w-[420px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-6`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,K.jsx)(`span`,{className:`text-xl leading-none`,children:`🧶`}),(0,K.jsx)(`span`,{className:`text-base font-semibold text-gray-900`,children:`loopat`}),e&&(0,K.jsx)(`button`,{type:`button`,onClick:e,className:`ml-auto text-gray-400 hover:text-gray-700 px-1`,"aria-label":`close`,children:`✕`})]}),(0,K.jsx)(`div`,{className:`flex border-b border-gray-200 mb-5`,children:[`login`,`register`].map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>{r(e),d(null),p(null)},className:n===e?`px-3 py-2 text-sm border-b-2 border-gray-900 text-gray-900 font-medium`:`px-3 py-2 text-sm text-gray-500 hover:text-gray-800`,children:e===`login`?`Login`:`Register`},e))}),(0,K.jsxs)(`form`,{onSubmit:async a=>{if(a.preventDefault(),!c){d(null),l(!0);try{if(n===`login`){let n=await t.login(i.trim().toLowerCase(),o);n.error?d(n.error):e&&e();return}let a=await t.register({username:i.trim().toLowerCase(),password:o});if(a.error){d(a.error);return}if(a.user&&a.user.status===`pending`){p(`账号 ${a.user.id} 已创建,等待管理员激活后即可登录。`),r(`login`),s(``);return}e&&e()}finally{l(!1)}}},className:`flex flex-col gap-4`,children:[(0,K.jsx)(uQ,{label:`Username`,hint:`lowercase a-z 0-9 _ - · 1-32 chars`,children:(0,K.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`simpx`,autoFocus:!0,autoComplete:`username`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),(0,K.jsx)(uQ,{label:`Password`,children:(0,K.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),autoComplete:n===`login`?`current-password`:`new-password`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500`})}),n===`register`&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 leading-relaxed`,children:`Just creates your account. Set up your personal repo afterwards in Settings → Personal Repo.`}),f&&!u&&(0,K.jsx)(`div`,{className:`text-xs text-amber-700 bg-amber-50 border border-amber-200 rounded px-2 py-1.5`,children:f}),u&&(0,K.jsx)(`div`,{className:`text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1.5`,children:u}),(0,K.jsx)(`button`,{type:`submit`,disabled:c||!i||!o,className:`px-3 h-9 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:c?n===`login`?`logging in…`:`registering…`:n===`login`?`Login`:`Register`})]})]})})}function uQ({label:e,hint:t,children:n}){return(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:e}),n,t&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:t})]})}var dQ=`loopat:floating-dm-open`,fQ=`loopat:floating-dm-conv`;function pQ(e){let t=new Date(e),n=new Date,r=t.toDateString()===n.toDateString(),i=t.toTimeString().slice(0,5);return r?i:new Date(n.getTime()-864e5).toDateString()===t.toDateString()?`yesterday ${i}`:`${t.getMonth()+1}/${t.getDate()} ${i}`}function mQ({me:e}){let t=zn(),[n,r]=(0,_.useState)(()=>localStorage.getItem(dQ)===`1`),[i,a]=(0,_.useState)(()=>localStorage.getItem(fQ)),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)([]),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(!1),y=(0,_.useRef)(null),b=(0,_.useMemo)(()=>c.filter(e=>e.kind===`dm`).sort((e,t)=>(t.lastMessageTs??0)-(e.lastMessageTs??0)),[c]),x=(0,_.useMemo)(()=>b.reduce((e,t)=>e+t.unread,0),[b]),S=(0,_.useMemo)(()=>b.find(e=>e.id===i)??null,[b,i]);(0,_.useEffect)(()=>{localStorage.setItem(dQ,n?`1`:`0`)},[n]),(0,_.useEffect)(()=>{i?localStorage.setItem(fQ,i):localStorage.removeItem(fQ)},[i]);let C=(0,_.useCallback)(async()=>{l(await Wh())},[]);(0,_.useEffect)(()=>{C(),Gh().then(d)},[C]),(0,_.useEffect)(()=>{if(!i){p([]);return}let e=!1;return Yh(i,{limit:100}).then(t=>{if(e)return;p(t);let n=t[t.length-1];n&&(Qh(i,n.id).catch(()=>{}),l(e=>e.map(e=>e.id===i?{...e,unread:0}:e)),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:i}})))}),()=>{e=!0}},[i]),(0,_.useEffect)(()=>{n&&S&&y.current?.scrollIntoView({behavior:`auto`})},[f,n,S]);let w=(0,_.useRef)(i);w.current=i;let{subscribe:T,unsubscribe:D}=CY((0,_.useCallback)(t=>{if(t.type===`message`){let n=t.message,r=n.convId===w.current;r&&n.parentId==null?(p(e=>e.some(e=>e.id===n.id)?e:[...e,{...n,replyCount:0,lastReplyTs:null}]),Qh(n.convId,n.id).catch(()=>{}),window.dispatchEvent(new CustomEvent(`loopat:chat-read`,{detail:{convId:n.convId}}))):r&&n.parentId!=null?p(e=>e.map(e=>e.id===n.parentId?{...e,replyCount:e.replyCount+1,lastReplyTs:n.ts}:e)):n.author!==e&&l(e=>e.map(e=>e.id===n.convId?{...e,unread:e.unread+1,lastMessageTs:n.ts}:e))}else t.type===`conv_created`?l(e=>e.some(e=>e.id===t.conv.id)?e:[...e,t.conv]):t.type===`conv_deleted`&&(l(e=>e.filter(e=>e.id!==t.convId)),w.current===t.convId&&a(null))},[e]));(0,_.useEffect)(()=>{for(let e of b)T(e.id);return()=>{for(let e of b)D(e.id)}},[b,T,D]),(0,_.useEffect)(()=>{let e=e=>{let t=e.detail;t?.convId&&l(e=>e.map(e=>e.id===t.convId?{...e,unread:0}:e))};return window.addEventListener(`loopat:chat-read`,e),()=>window.removeEventListener(`loopat:chat-read`,e)},[]);let O=async()=>{if(!S||!m.trim()||g)return;let e=m.trim();h(``),v(!0);let t=await Zh(S.id,e);if(v(!1),t.message){let e=t.message;p(t=>t.some(t=>t.id===e.id)?t:[...t,{...e,replyCount:0,lastReplyTs:null}])}else h(e)};return e?(0,K.jsxs)(K.Fragment,{children:[!n&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(!0),className:`fixed bottom-20 right-5 z-30 w-12 h-12 rounded-full flex items-center justify-center shadow-lg transition-colors `+(x>0?`bg-gray-700 text-white animate-pulse`:`bg-gray-700 text-white hover:bg-gray-500`),title:`direct messages`,children:[(0,K.jsx)(De,{size:20}),x>0&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 rounded-full bg-red-500 text-white text-[10px] font-medium flex items-center justify-center`,children:x>99?`99+`:x})]}),n&&(0,K.jsxs)(`div`,{className:`fixed bottom-20 right-5 z-30 w-[22rem] max-w-[calc(100vw-2.5rem)] h-[32rem] max-h-[calc(100dvh-2.5rem)] bg-white rounded-lg shadow-2xl border border-gray-200 flex flex-col overflow-hidden`,children:[(0,K.jsxs)(`header`,{className:`h-10 shrink-0 border-b border-gray-200 px-2 flex items-center gap-1`,children:[S?(0,K.jsx)(`button`,{type:`button`,onClick:()=>a(null),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`back to DMs`,children:(0,K.jsx)(E,{size:14})}):(0,K.jsx)(`span`,{className:`px-2 text-[13px] font-medium text-gray-900`,children:`Direct messages`}),S&&(0,K.jsxs)(`div`,{className:`flex-1 min-w-0 flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-gray-400 text-[13px]`,children:`@`}),(0,K.jsx)(`span`,{className:`text-[13px] font-medium text-gray-900 truncate`,children:S.peerUserId??`(unknown)`})]}),!S&&(0,K.jsx)(`div`,{className:`flex-1`}),!S&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>s(!0),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`new DM`,children:(0,K.jsx)(Re,{size:14})}),S&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{t(S?`/chat/${S.id}`:`/chat`),r(!1)},className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`open in chat tab`,children:(0,K.jsx)(re,{size:13})}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>r(!1),className:`w-7 h-7 flex items-center justify-center rounded text-gray-500 hover:text-gray-900 hover:bg-gray-100`,title:`close`,children:(0,K.jsx)(lt,{size:14})})]}),S?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto px-3 py-2 flex flex-col gap-2`,children:[f.length===0&&(0,K.jsx)(`div`,{className:`text-[12px] text-gray-400 italic py-4 text-center`,children:`no messages yet — say hi`}),f.map(t=>(0,K.jsx)(hQ,{message:t,isMe:t.author===e},t.id)),(0,K.jsx)(`div`,{ref:y})]}),(0,K.jsx)(`div`,{className:`px-2 pb-2 pt-1 shrink-0`,children:(0,K.jsxs)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-1.5 flex items-end gap-1`,children:[(0,K.jsx)(`textarea`,{value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),O())},rows:1,placeholder:`message @${S.peerUserId??``}…`,className:`field-sizing-content flex-1 max-h-32 min-h-7 resize-none bg-transparent px-1.5 py-1 text-sm text-gray-900 outline-none placeholder:text-gray-400`}),(0,K.jsx)(`button`,{type:`button`,onClick:O,disabled:g||!m.trim(),className:`px-2.5 h-7 rounded bg-gray-900 text-white text-xs hover:bg-gray-700 disabled:opacity-40 shrink-0`,children:`send`})]})})]}):(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:b.length===0?(0,K.jsxs)(`div`,{className:`px-4 py-6 text-center text-[12px] text-gray-400`,children:[`no DMs yet`,(0,K.jsx)(`div`,{className:`mt-2`,children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`px-2 py-1 rounded border border-gray-200 text-[12px] text-gray-700 hover:bg-gray-50 inline-flex items-center gap-1`,children:[(0,K.jsx)(Re,{size:12}),(0,K.jsx)(`span`,{children:`new DM`})]})})]}):(0,K.jsx)(`ul`,{className:`py-1`,children:b.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:`w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-gray-50`,children:[(0,K.jsx)(`span`,{className:`w-7 h-7 rounded bg-gray-200 text-gray-900 text-[11px] font-medium flex items-center justify-center shrink-0`,children:(e.peerUserId??`?`).slice(0,1).toUpperCase()}),(0,K.jsxs)(`span`,{className:`flex-1 min-w-0 text-[13px] text-gray-900 truncate`,children:[`@`,e.peerUserId??`(unknown)`]}),e.unread>0&&(0,K.jsx)(`span`,{className:`text-[10px] font-medium px-1.5 rounded-full bg-red-500 text-white`,children:e.unread}),e.lastMessageTs&&e.unread===0&&(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:pQ(e.lastMessageTs)})]})},e.id))})})]}),o&&(0,K.jsx)(gQ,{users:u,onClose:()=>s(!1),onPick:async e=>{let t=await Jh(e);t.conv?(s(!1),a(t.conv.id),C()):t.error&&alert(t.error)}})]}):null}function hQ({message:e,isMe:t}){return(0,K.jsxs)(`div`,{className:`flex gap-1.5 `+(t?`flex-row-reverse`:``),children:[(0,K.jsx)(`div`,{className:t?`w-6 h-6 rounded shrink-0 flex items-center justify-center text-[10px] font-medium bg-gray-900 text-white`:`w-6 h-6 rounded shrink-0 flex items-center justify-center text-[10px] font-medium bg-gray-200 text-gray-900`,title:e.author,children:e.author.slice(0,1).toUpperCase()}),(0,K.jsxs)(`div`,{className:`min-w-0 max-w-[80%]`,children:[(0,K.jsx)(`div`,{className:`text-[10px] text-gray-400 `+(t?`text-right`:``),children:pQ(e.ts)}),(0,K.jsx)(`div`,{className:`text-[12.5px] whitespace-pre-wrap break-words leading-relaxed px-2 py-1 rounded-lg `+(t?`bg-gray-900 text-white`:`bg-gray-100 text-gray-900`),children:e.text})]})]})}function gQ({users:e,onClose:t,onPick:n}){let[r,i]=(0,_.useState)(``),a=e.filter(e=>!e.isMe).filter(e=>e.id.toLowerCase().includes(r.toLowerCase()));return(0,K.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/30 flex items-center justify-center`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-white rounded-md shadow-lg w-80 p-3 flex flex-col gap-2`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-gray-900`,children:`New DM`}),(0,K.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`search users…`,className:`px-2 py-1.5 text-sm rounded border border-gray-200 outline-none focus:border-gray-400`}),(0,K.jsxs)(`div`,{className:`max-h-64 overflow-auto flex flex-col gap-0.5`,children:[a.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),className:`text-left px-2 py-1.5 text-sm rounded hover:bg-gray-100 flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`w-6 h-6 rounded bg-gray-200 text-gray-900 text-[11px] flex items-center justify-center`,children:e.id.slice(0,1).toUpperCase()}),(0,K.jsx)(`span`,{children:e.id})]},e.id)),a.length===0&&(0,K.jsx)(`div`,{className:`text-xs text-gray-400 px-2 py-2`,children:`no users match`})]})]})})}var _Q=`loopat:setupPersonalRepoDismissed`;function vQ(){try{return localStorage.getItem(_Q)===`1`}catch{return!1}}function yQ({onDismiss:e,hideSkip:t}){let n=zn();return(0,K.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,K.jsx)(`div`,{className:`text-2xl mb-2`,children:`👋 欢迎来到 loopat`}),(0,K.jsxs)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-3`,children:[`在你开始之前,建议先配一个`,(0,K.jsx)(`b`,{children:`个人仓库`}),`——`]}),(0,K.jsxs)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-3`,children:[`loopat 一个反直觉的设计:服务器`,(0,K.jsx)(`b`,{children:`不存你的数据`}),`。你的 API key、ssh、token、 笔记、memory 全部存在你自己的 GitHub 私有仓库里,由你自己持有解密密钥。 这是 loopat 跟其他工具最大的不同。`]}),(0,K.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:`配置 3 步,大约 2 分钟:创建一个空的私有仓库 → 把 loopat 的 deploy key 贴上去 → 把仓库 URL 填进来。配完后回到这个页面,AI 引导会自动接上。`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>n(`/settings/personal-repo`),className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`去配置个人仓库 →`}),!t&&(0,K.jsx)(`button`,{onClick:()=>{try{localStorage.setItem(_Q,`1`)}catch{}e()},className:`text-xs text-gray-500 hover:text-gray-700`,children:`跳过(先用 workspace 的 key)`})]}),(0,K.jsx)(`p`,{className:`mt-4 text-[11px] text-gray-400 leading-relaxed`,children:`跳过后这个提示就不再出现。但 loopat 的核心安全模型依赖你的个人仓库 —— 想用自己的凭据、记自己的 memory 时,从右上角 Settings → Personal Repo 随时可以补上。`})]})}function bQ({form:e,onAdvance:t}){let[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(``),c=e.fields.filter(e=>(n[e.name]??``).trim().length>0).length,l=e.require===`any`?c>=1:c===e.fields.length;return(0,K.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,K.jsx)(`div`,{className:`text-2xl mb-2`,children:e.title}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-5`,children:e.description}),(0,K.jsx)(`div`,{className:`flex flex-col gap-4`,children:e.fields.map(e=>(0,K.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,K.jsx)(`label`,{className:`text-sm font-medium text-gray-800`,children:e.label}),e.help&&(0,K.jsx)(`a`,{href:e.help,target:`_blank`,rel:`noreferrer`,className:`text-xs text-blue-600 hover:text-blue-800`,children:`获取 →`})]}),(0,K.jsx)(`input`,{type:e.type===`text`?`text`:`password`,autoComplete:`off`,spellCheck:!1,placeholder:e.placeholder??e.label,value:n[e.name]??``,onChange:t=>r(n=>({...n,[e.name]:t.target.value})),className:`h-9 px-3 rounded border border-gray-300 text-sm font-mono focus:outline-none focus:border-gray-500`})]},e.name))}),o&&(0,K.jsx)(`p`,{className:`mt-3 text-sm text-red-600`,children:o}),(0,K.jsxs)(`div`,{className:`mt-6 flex items-center gap-3`,children:[(0,K.jsx)(`button`,{onClick:async()=>{a(!0),s(``);try{let r={};for(let t of e.fields){let e=(n[t.name]??``).trim();e&&(r[t.name]=e)}let i=await Xp(r);if(`error`in i){s(i.error);return}t(i)}finally{a(!1)}},disabled:!l||i,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i?`处理中…`:e.submitLabel??`继续 →`}),e.require===`any`&&e.fields.length>1&&(0,K.jsx)(`span`,{className:`text-xs text-gray-400`,children:`至少填一个`})]})]})}function xQ({show:e,onAdvance:t}){let[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null);return(0,K.jsxs)(`div`,{className:`max-w-2xl mx-auto mt-12 px-6 py-8 rounded-lg border border-gray-200 bg-white shadow-sm`,children:[(0,K.jsxs)(`div`,{className:`text-2xl mb-2`,children:[`🔐 `,e.title]}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-gray-600 leading-relaxed mb-4 whitespace-pre-line`,children:e.description}),e.values&&e.values.length>0&&(0,K.jsx)(`div`,{className:`flex flex-col gap-2 mb-4`,children:e.values.map(e=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-[11px] text-gray-500 mb-1`,children:e.label}),(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsx)(`code`,{className:`flex-1 min-w-0 break-all bg-gray-50 border border-gray-200 rounded px-2 py-1.5 text-[10px] font-mono`,children:e.value}),(0,K.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(e.value),a(e.label),setTimeout(()=>a(null),1500)},className:`shrink-0 text-[11px] text-gray-500 hover:text-gray-800 px-1.5 py-1`,children:i===e.label?`copied`:`copy`})]})]},e.label))}),e.help&&e.help.length>0&&(0,K.jsx)(`div`,{className:`flex flex-wrap gap-3 mb-5`,children:e.help.map(e=>(0,K.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`text-xs text-blue-600 hover:text-blue-800`,children:[e.label,` →`]},e.url))}),(0,K.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,K.jsx)(`button`,{onClick:async()=>{r(!0);let e=await Yp();r(!1),e&&t(e)},disabled:n,className:`px-4 h-9 rounded text-sm bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-40`,children:n?`检查中…`:`我已配置好,重新检查`})})]})}function SQ(e,t,n){let[r,i]=(0,_.useState)({}),a=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!t)return;let e=!1,r=async()=>{let t=await Wh();if(e)return;let n={};for(let e of t)n[e.id]=e.unread;i(n)},o=t=>{let r=location.protocol===`https:`?`wss:`:`ws:`,o=new WebSocket(`${r}//${location.host}/ws/chat`);a.current=o,o.onopen=()=>{for(let e of t)o.send(JSON.stringify({type:`subscribe`,convId:e}))},o.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`message`?t.message.author!==n&&i(e=>({...e,[t.message.convId]:(e[t.message.convId]??0)+1})):t.type===`conv_created`&&o.send(JSON.stringify({type:`subscribe`,convId:t.conv.id}))}catch{}},o.onclose=()=>{e||setTimeout(()=>{e||s()},3e3)},o.onerror=()=>{try{o.close()}catch{}}},s=async()=>{let t=await Wh();if(e)return;let n={};for(let e of t)n[e.id]=e.unread;i(n),o(t.map(e=>e.id))};s();let c=e=>{let t=e.detail;t?.convId&&i(e=>e[t.convId]===0?e:{...e,[t.convId]:0})},l=()=>{r().catch(()=>{})};return window.addEventListener(`loopat:chat-read`,c),window.addEventListener(`focus`,l),()=>{e=!0,window.removeEventListener(`loopat:chat-read`,c),window.removeEventListener(`focus`,l);try{a.current?.close()}catch{}a.current=null}},[t,n]),(0,_.useEffect)(()=>{if(!t)return;let n=0;for(let e in r)n+=r[e];let i=`${e} · loopat`;document.title=n>0?`(${n}) ${i}`:i},[r,e,t])}var CQ=(0,_.createContext)({theme:`light`,toggle:()=>{}});function wQ(){return(0,_.useContext)(CQ)}var TQ=`loopat:theme`;function EQ(){try{let e=localStorage.getItem(TQ);if(e===`dark`||e===`light`)return e}catch{}return window.matchMedia?.(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}function DQ(e){let t=document.documentElement;e===`dark`?t.classList.add(`dark`):t.classList.remove(`dark`)}DQ(EQ());function OQ({children:e}){let[t,n]=(0,_.useState)(EQ);(0,_.useLayoutEffect)(()=>{DQ(t)},[t]);let r=(0,_.useCallback)(()=>{n(e=>{let t=e===`light`?`dark`:`light`;DQ(t);try{localStorage.setItem(TQ,t)}catch{}return t})},[]);return(0,K.jsx)(CQ.Provider,{value:{theme:t,toggle:r},children:e})}var kQ=[{id:`loop`,label:`Loop`,icon:`⑂`},{id:`kanban`,label:`Focus`,icon:`◎`},{id:`context`,label:`Context`,icon:`⌘`},{id:`chat`,label:`Chat`,icon:(0,K.jsx)(De,{size:14})}];function AQ(){let e=xg();return(0,K.jsx)(Sg.Provider,{value:e,children:e.authLoading?null:(0,K.jsx)(jQ,{ws:e})})}function jQ({ws:e}){let t=zn(),n=Fn(),[r,i]=(0,_.useState)(`loopat`),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(``),{theme:h,toggle:g}=wQ(),v=e.currentUser?.id??``,y=e.currentUser?.role===`admin`,b=!!e.currentUser,x=!!In(`/loop/:id`),S=n.pathname.startsWith(`/chat`),C=!b&&x;(0,_.useEffect)(()=>{C||Up().then(e=>{e&&(i(e),document.title=`${e} · loopat`)})},[C]),SQ(r,b&&!C,v);let w=`loopat:version-dismissed`;(0,_.useEffect)(()=>{let e=e=>{let t=e.detail?.commit;if(t){try{if(JSON.parse(localStorage.getItem(w)||`[]`).includes(t))return}catch{}f(t),m(new Date(vh().time).toLocaleString()),u(!0)}};return window.addEventListener(`loopat:version-mismatch`,e),()=>window.removeEventListener(`loopat:version-mismatch`,e)},[]),(0,_.useEffect)(()=>{if(C)return;let e=vh();mh().then(t=>{console.log(`%cloopat %cserver:%c ${t.branch}@${t.commit.slice(0,7)} %cbuild:%c ${e.commit.slice(0,7)} @ ${e.time}`,`font-weight:bold`,`color:#666`,`color:#61afef`,`color:#666`,`color:#98c379`)})},[C]);let[T,E]=(0,_.useState)(null);return(0,_.useEffect)(()=>{if(!b||C){E(null);return}Yp().then(E)},[b,C]),(0,_.useEffect)(()=>{if(!b||C||!T||T.done||!T.gated||T.show.kind!==`route`)return;let e=setInterval(()=>{Yp().then(E)},3e3);return()=>clearInterval(e)},[b,C,T]),C?(0,K.jsx)(`div`,{className:`h-full w-full bg-white text-gray-900`,children:(0,K.jsx)(mr,{})}):b?(0,K.jsxs)(`div`,{className:`h-full w-full flex flex-col bg-gray-50 text-gray-900`,children:[(0,K.jsxs)(`header`,{className:`h-12 shrink-0 border-b border-gray-200 bg-white flex items-center px-2 md:px-4 gap-2 md:gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-1 md:px-2 h-8 shrink-0 cursor-pointer`,title:`workspace: ${r}`,onClick:()=>{window.location.href=`/`},children:[(0,K.jsx)(`span`,{className:`text-lg leading-none`,children:`🧶`}),(0,K.jsx)(`span`,{className:`hidden md:inline text-sm text-gray-900 font-medium`,children:r})]}),(0,K.jsx)(`nav`,{className:`flex items-center gap-0.5 md:gap-1`,children:kQ.map(e=>(0,K.jsxs)(ui,{to:`/${e.id}`,className:({isActive:e})=>e?`px-2 md:px-3 h-8 rounded text-sm bg-gray-900 text-white flex items-center gap-1.5`:`px-2 md:px-3 h-8 rounded text-sm text-gray-600 hover:bg-gray-100 flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`opacity-70`,children:e.icon}),(0,K.jsx)(`span`,{className:`hidden md:inline`,children:e.label})]},e.id))}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>e.setNewLoopDialogOpen(!0),className:`flex items-center gap-1 md:gap-1.5 px-2 md:px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,title:`create new loop`,children:[(0,K.jsx)(`span`,{className:`text-base leading-none`,children:`+`}),(0,K.jsx)(`span`,{className:`hidden md:inline`,children:`New Loop`})]}),(0,K.jsx)(`button`,{type:`button`,onClick:g,className:`flex items-center justify-center w-8 h-8 rounded text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,title:h===`dark`?`Switch to light mode`:`Switch to dark mode`,children:h===`dark`?(0,K.jsx)(Qe,{size:16}):(0,K.jsx)(je,{size:16})}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex items-center gap-1 md:gap-2 px-1 md:px-2 h-8 rounded hover:bg-gray-100`,title:`account`,children:[(0,K.jsx)(`span`,{className:`w-6 h-6 rounded-full bg-gray-900 text-white text-xs flex items-center justify-center`,children:v[0]?.toUpperCase()??`?`}),(0,K.jsx)(`span`,{className:`hidden md:inline text-sm text-gray-700`,children:v}),(0,K.jsx)(`span`,{className:`text-gray-400 text-xs`,children:`▾`})]}),a&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>o(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 w-40 bg-white border border-gray-200 rounded shadow-md py-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),t(`/settings`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`Settings`}),y&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),t(`/admin/system`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,title:`server version + activity + pull latest code`,children:`Platform`}),y&&(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{o(!1);try{t(`/loop/${(await e.createLoop({title:`cross-loop distill`,mountAllLoops:!0,knowledgeRw:!0})).id}`)}catch(e){alert(e?.message??`create failed`)}},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,title:`New loop with /loopat/loops/ mounted read-only — read every loop's chat/workdir for distill`,children:`Cross-loop distill`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),c(!0)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`About`}),(0,K.jsx)(`button`,{type:`button`,onClick:async()=>{o(!1),await e.logout(),t(`/loop`)},className:`w-full text-left px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100`,children:`Logout`})]})]})]})]}),l&&(0,K.jsxs)(`div`,{className:`shrink-0 bg-gradient-to-r from-blue-50 to-indigo-50 border-b border-blue-200 flex items-center px-4 py-2.5 gap-2.5`,children:[(0,K.jsx)(Be,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,K.jsxs)(`span`,{className:`text-sm text-blue-700`,children:[`New version available`,(0,K.jsxs)(`span`,{className:`text-blue-400 ml-1 text-xs`,children:[`(`,d.slice(0,7),` `,p,`)`]})]}),(0,K.jsx)(`button`,{type:`button`,className:`text-xs font-medium px-2.5 py-1 rounded bg-blue-500 text-white hover:bg-blue-600 cursor-pointer shrink-0`,onClick:()=>{try{let e=JSON.parse(localStorage.getItem(w)||`[]`);e.push(d),localStorage.setItem(w,JSON.stringify(e))}catch{}window.location.reload()},children:`Update`}),(0,K.jsx)(`button`,{type:`button`,className:`ml-auto p-0.5 rounded hover:bg-blue-100 text-blue-400 hover:text-blue-600 cursor-pointer shrink-0`,onClick:()=>{try{let e=JSON.parse(localStorage.getItem(w)||`[]`);e.push(d),localStorage.setItem(w,JSON.stringify(e))}catch{}u(!1)},"aria-label":`关闭`,children:(0,K.jsx)(lt,{className:`w-4 h-4`})})]}),(0,K.jsx)(`main`,{className:`flex-1 min-h-0 min-w-0 overflow-hidden`,children:(()=>{let e=T;return b&&e&&e.gated&&!e.done?e.show.kind===`route`?n.pathname===e.show.path?(0,K.jsx)(mr,{}):(0,K.jsx)(pr,{to:e.show.path,replace:!0}):e.show.kind===`info`?(0,K.jsx)(xQ,{show:e.show,onAdvance:E}):(0,K.jsx)(bQ,{form:e.show,onAdvance:E}):(0,K.jsx)(mr,{})})()}),e.newLoopDialogOpen&&(0,K.jsx)(wg,{onClose:()=>e.setNewLoopDialogOpen(!1),onCreate:async n=>{let r=await e.createLoop(n);return e.kanbanCreateCtx&&await uh(e.kanbanCreateCtx.board,e.kanbanCreateCtx.filename,e.kanbanCreateCtx.cid,r.id),e.setNewLoopDialogOpen(!1),t(`/loop/${r.id}`),r.id},initialTitle:e.newLoopDialogTitle}),(0,K.jsx)(Lg,{open:s,onClose:()=>c(!1)}),!S&&(0,K.jsx)(mQ,{me:v})]}):(0,K.jsx)(lQ,{})}function MQ(){let e=Cg(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(0);if((0,_.useEffect)(()=>{e.currentUser&&Jp().then(e=>n(e))},[e.currentUser,r]),e.currentUser&&t===null||e.loopsLoading)return null;if(e.currentUser&&t&&!t.imported&&!vQ())return(0,K.jsx)(yQ,{onDismiss:()=>i(e=>e+1)});if(e.loops.length===0)return(0,K.jsx)(NQ,{loggedIn:!!e.currentUser,onNew:()=>e.setNewLoopDialogOpen(!0)});let a=e.currentUser?.id?localStorage.getItem(`loopat:lastLoop:${e.currentUser.id}`):null,o=e.currentUser?.id?e.loops.filter(t=>t.createdBy===e.currentUser.id):[];return(0,K.jsx)(pr,{to:`/loop/${a&&e.loops.some(e=>e.id===a)?a:o.length>0?o[0].id:e.loops[0].id}`,replace:!0})}function NQ({loggedIn:e,onNew:t}){return(0,K.jsxs)(`div`,{className:`h-full w-full flex flex-col items-center justify-center text-gray-500 gap-3`,children:[(0,K.jsx)(`div`,{children:`no loops yet`}),e?(0,K.jsx)(`button`,{onClick:t,className:`px-3 h-8 rounded text-sm bg-gray-900 text-white hover:bg-gray-700`,children:`+ New Loop`}):(0,K.jsx)(`div`,{className:`text-xs text-gray-400`,children:`log in to create one`})]})}function PQ(){return(0,K.jsx)(OQ,{children:(0,K.jsx)(Rp,{children:(0,K.jsx)(oi,{children:(0,K.jsx)(_r,{children:(0,K.jsxs)(hr,{element:(0,K.jsx)(AQ,{}),children:[(0,K.jsx)(hr,{path:`/`,element:(0,K.jsx)(pr,{to:`/loop`,replace:!0})}),(0,K.jsx)(hr,{path:`/loop`,element:(0,K.jsx)(MQ,{})}),(0,K.jsx)(hr,{path:`/loop/:id`,element:(0,K.jsx)(eG,{})}),(0,K.jsx)(hr,{path:`/topic/:name`,element:(0,K.jsx)(mG,{})}),(0,K.jsx)(hr,{path:`/kanban`,element:(0,K.jsx)(pr,{to:`/kanban/default`,replace:!0})}),(0,K.jsx)(hr,{path:`/kanban/:board`,element:(0,K.jsx)(SY,{})}),(0,K.jsx)(hr,{path:`/context`,element:(0,K.jsx)(pr,{to:`/context/knowledge`,replace:!0})}),(0,K.jsx)(hr,{path:`/context/:sub`,element:(0,K.jsx)(bG,{})}),(0,K.jsx)(hr,{path:`/chat`,element:(0,K.jsx)(OY,{})}),(0,K.jsx)(hr,{path:`/chat/:convId`,element:(0,K.jsx)(OY,{})}),(0,K.jsx)(hr,{path:`/settings`,element:(0,K.jsx)(pr,{to:`/settings/personal-repo`,replace:!0})}),(0,K.jsx)(hr,{path:`/settings/:tab`,element:(0,K.jsx)(nQ,{})}),(0,K.jsx)(hr,{path:`/admin/system`,element:(0,K.jsx)(oQ,{})})]})})})})})}var FQ=class extends _.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary]`,e,t.componentStack)}reset=()=>{this.setState({error:null})};render(){if(!this.state.error)return this.props.children;let e=this.state.error;return(0,K.jsxs)(`div`,{className:`m-4 flex flex-col gap-3 rounded-md border border-red-300 bg-red-50 p-4 text-sm text-red-900`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:`UI crashed — caught by error boundary`}),(0,K.jsxs)(`pre`,{className:`overflow-auto whitespace-pre-wrap break-words rounded bg-white/70 p-2 text-xs leading-relaxed`,children:[e.name,`: `,e.message,e.stack?`\n\n${e.stack}`:``]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,className:`rounded bg-red-600 px-3 py-1 text-xs font-medium text-white hover:bg-red-700`,onClick:this.reset,children:`Try again`}),(0,K.jsx)(`button`,{type:`button`,className:`rounded border border-red-300 bg-white px-3 py-1 text-xs font-medium text-red-700 hover:bg-red-100`,onClick:()=>window.location.reload(),children:`Reload page`})]})]})}};document.addEventListener(`gesturestart`,e=>e.preventDefault()),(0,ft.createRoot)(document.getElementById(`root`)).render((0,K.jsx)(_.StrictMode,{children:(0,K.jsx)(FQ,{children:(0,K.jsx)(PQ,{})})}));export{xm as _,wL as a,sI as c,oF as d,sF as f,wk as g,JN as h,OL as i,qF as l,rP as m,_z as n,_L as o,ZP as p,aR as r,pL as s,Az as t,lF as u,Sm as v,x as y};
|