loopat 0.1.8 → 0.1.10
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/bootstrap.ts +17 -1
- package/server/src/loops.ts +45 -20
- package/server/src/session.ts +12 -1
- package/web/dist/assets/{CodeEditor-B1jg6Yiy.js → CodeEditor-DCyHh42b.js} +1 -1
- package/web/dist/assets/{Editor-C17JCtKx.js → Editor-C9mcMyB9.js} +1 -1
- package/web/dist/assets/{Markdown-DqMis2lt.js → Markdown-C34y5IWD.js} +1 -1
- package/web/dist/assets/{MilkdownEditor-Br5IzCOU.js → MilkdownEditor-BG3OOnaR.js} +1 -1
- package/web/dist/assets/{Terminal-B980yCb2.js → Terminal-yITknn_A.js} +1 -1
- package/web/dist/assets/{index-DG47mq8t.js → index-BwHdjyPW.js} +3 -3
- package/web/dist/index.html +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Editor-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Editor-C9mcMyB9.js","assets/CodeEditor-DCyHh42b.js","assets/w3c-keyname-BOAvb0qz.js","assets/Terminal-yITknn_A.js","assets/Terminal-BrP-ENHg.css","assets/MilkdownEditor-BG3OOnaR.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},l=(n,r,a)=>(a=n==null?{}:e(i(n)),c(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),u=(e=>typeof require<`u`?require:typeof Proxy<`u`?new Proxy(e,{get:(e,t)=>(typeof require<`u`?require:e)[t]}):e)(function(e){if(typeof require<`u`)return require.apply(this,arguments);throw Error('Calling `require` for "'+e+"\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.")});(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 d=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var I=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,I)}catch(e){I(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.6`})),f=o(((e,t)=>{t.exports=d()})),p=o((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}}}})),m=o(((e,t)=>{t.exports=p()})),h=o((e=>{var t=f();function n(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 r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(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=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.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,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,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=c(t.as,t.crossOrigin);i.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??i.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=c(n,t.crossOrigin);i.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=c(t.as,t.crossOrigin);i.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 i.d.m(e)},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.6`})),g=o(((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=h()})),_=o((e=>{var t=m(),n=f(),r=g();function i(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 a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(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 s(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 c(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 l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var p=Object.assign,h=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=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,L=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,R={pending:!1,data:null,method:null,action:null},z=[],B=-1;function V(e){return{current:e}}function H(e){0>B||(e.current=z[B],z[B]=null,B--)}function U(e,t){B++,z[B]=e.current,e.current=t}var W=V(null),G=V(null),ee=V(null),te=V(null);function ne(e,t){switch(U(ee,t),U(G,e),U(W,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Jd(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Jd(t),e=Yd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}H(W),U(W,e)}function re(){H(W),H(G),H(ee)}function ie(e){e.memoizedState!==null&&U(te,e);var t=W.current,n=Yd(t,e.type);t!==n&&(U(G,e),U(W,n))}function ae(e){G.current===e&&(H(W),H(G)),te.current===e&&(H(te),ap._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 T.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},uc=`DialogDescriptionWarning`,dc=({contentRef:e,descriptionId:t})=>{let n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${cc(uc).contentName}}.`;return T.useEffect(()=>{let r=e.current?.getAttribute(`aria-describedby`);t&&r&&(document.getElementById(t)||console.warn(n))},[n,e,t]),null},fc=Ls,pc=Us,mc=Gs,hc=Ys,gc=ec,_c=nc,vc=ic;function yc(e){let[t,n]=T.useState(void 0);return aa(()=>{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 bc=[`top`,`right`,`bottom`,`left`],xc=Math.min,Sc=Math.max,Cc=Math.round,wc=Math.floor,Tc=e=>({x:e,y:e}),Ec={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Dc(e,t,n){return Sc(e,xc(t,n))}function Oc(e,t){return typeof e==`function`?e(t):e}function kc(e){return e.split(`-`)[0]}function Ac(e){return e.split(`-`)[1]}function jc(e){return e===`x`?`y`:`x`}function Mc(e){return e===`y`?`height`:`width`}function Nc(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function Pc(e){return jc(Nc(e))}function Fc(e,t,n){n===void 0&&(n=!1);let r=Ac(e),i=Pc(e),a=Mc(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Wc(o)),[o,Wc(o)]}function Ic(e){let t=Wc(e);return[Lc(e),t,Lc(t)]}function Lc(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var Rc=[`left`,`right`],zc=[`right`,`left`],Bc=[`top`,`bottom`],Vc=[`bottom`,`top`];function Hc(e,t,n){switch(e){case`top`:case`bottom`:return n?t?zc:Rc:t?Rc:zc;case`left`:case`right`:return t?Bc:Vc;default:return[]}}function Uc(e,t,n,r){let i=Ac(e),a=Hc(kc(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Lc)))),a}function Wc(e){let t=kc(e);return Ec[t]+e.slice(t.length)}function Gc(e){return{top:0,right:0,bottom:0,left:0,...e}}function Kc(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Gc(e)}function qc(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 Jc(e,t,n){let{reference:r,floating:i}=e,a=Nc(t),o=Pc(t),s=Mc(o),c=kc(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(Ac(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 Yc(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}=Oc(t,e),p=Kc(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=qc(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=qc(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 Xc=50,Zc=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Yc},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Jc(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<Xc&&(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}=Jc(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},Qc=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}=Oc(e,t)||{};if(l==null)return{};let d=Kc(u),f={x:n,y:r},p=Pc(i),m=Mc(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=xc(d[_],T),D=xc(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=Dc(O,A,k),M=!c.arrow&&Ac(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}}}),$c=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}=Oc(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=kc(r),_=Nc(o),v=kc(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Wc(o)]:Ic(o)),x=p!==`none`;!d&&x&&b.push(...Uc(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=Fc(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`&&_!==Nc(t))||T.every(e=>Nc(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=Nc(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 el(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function tl(e){return bc.some(t=>e[t]>=0)}var nl=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=Oc(e,t);switch(i){case`referenceHidden`:{let e=el(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:tl(e)}}}case`escaped`:{let e=el(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:tl(e)}}}default:return{}}}}},rl=new Set([`left`,`top`]);async function il(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=kc(n),s=Ac(n),c=Nc(n)===`y`,l=rl.has(o)?-1:1,u=a&&c?-1:1,d=Oc(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 al=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 il(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}}}}},ol=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}=Oc(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Nc(kc(i)),p=jc(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=Dc(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=Dc(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}}}}}},sl=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}=Oc(e,t),u={x:n,y:r},d=Nc(i),f=jc(d),p=u[f],m=u[d],h=Oc(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=rl.has(kc(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}}}},cl=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}=Oc(e,t),u=await o.detectOverflow(t,l),d=kc(i),f=Ac(i),p=Nc(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=xc(h-u[g],v),x=xc(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=Sc(u.left,0),t=Sc(u.right,0),n=Sc(u.top,0),r=Sc(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:Sc(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:Sc(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 ll(){return typeof window<`u`}function ul(e){return pl(e)?(e.nodeName||``).toLowerCase():`#document`}function dl(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function fl(e){return((pl(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function pl(e){return ll()?e instanceof Node||e instanceof dl(e).Node:!1}function ml(e){return ll()?e instanceof Element||e instanceof dl(e).Element:!1}function hl(e){return ll()?e instanceof HTMLElement||e instanceof dl(e).HTMLElement:!1}function gl(e){return!ll()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof dl(e).ShadowRoot}function _l(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=Ol(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function vl(e){return/^(table|td|th)$/.test(ul(e))}function yl(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var bl=/transform|translate|scale|rotate|perspective|filter/,xl=/paint|layout|strict|content/,Sl=e=>!!e&&e!==`none`,Cl;function wl(e){let t=ml(e)?Ol(e):e;return Sl(t.transform)||Sl(t.translate)||Sl(t.scale)||Sl(t.rotate)||Sl(t.perspective)||!El()&&(Sl(t.backdropFilter)||Sl(t.filter))||bl.test(t.willChange||``)||xl.test(t.contain||``)}function Tl(e){let t=Al(e);for(;hl(t)&&!Dl(t);){if(wl(t))return t;if(yl(t))return null;t=Al(t)}return null}function El(){return Cl??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Cl}function Dl(e){return/^(html|body|#document)$/.test(ul(e))}function Ol(e){return dl(e).getComputedStyle(e)}function kl(e){return ml(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Al(e){if(ul(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||gl(e)&&e.host||fl(e);return gl(t)?t.host:t}function jl(e){let t=Al(e);return Dl(t)?e.ownerDocument?e.ownerDocument.body:e.body:hl(t)&&_l(t)?t:jl(t)}function Ml(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=jl(e),i=r===e.ownerDocument?.body,a=dl(r);if(i){let e=Nl(a);return t.concat(a,a.visualViewport||[],_l(r)?r:[],e&&n?Ml(e):[])}else return t.concat(r,Ml(r,[],n))}function Nl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Pl(e){let t=Ol(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=hl(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Cc(n)!==a||Cc(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function Fl(e){return ml(e)?e:e.contextElement}function Il(e){let t=Fl(e);if(!hl(t))return Tc(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Pl(t),o=(a?Cc(n.width):n.width)/r,s=(a?Cc(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var Ll=Tc(0);function Rl(e){let t=dl(e);return!El()||!t.visualViewport?Ll:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function zl(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==dl(e)?!1:t}function Bl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=Fl(e),o=Tc(1);t&&(r?ml(r)&&(o=Il(r)):o=Il(e));let s=zl(a,n,r)?Rl(a):Tc(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=dl(a),t=r&&ml(r)?dl(r):r,n=e,i=Nl(n);for(;i&&r&&t!==n;){let e=Il(i),t=i.getBoundingClientRect(),r=Ol(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=dl(i),i=Nl(n)}}return qc({width:u,height:d,x:c,y:l})}function Vl(e,t){let n=kl(e).scrollLeft;return t?t.left+n:Bl(fl(e)).left+n}function Hl(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Vl(e,n),y:n.top+t.scrollTop}}function Ul(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=fl(r),s=t?yl(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Tc(1),u=Tc(0),d=hl(r);if((d||!d&&!a)&&((ul(r)!==`body`||_l(o))&&(c=kl(r)),d)){let e=Bl(r);l=Il(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?Hl(o,c):Tc(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 Wl(e){return Array.from(e.getClientRects())}function Gl(e){let t=fl(e),n=kl(e),r=e.ownerDocument.body,i=Sc(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=Sc(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+Vl(e),s=-n.scrollTop;return Ol(r).direction===`rtl`&&(o+=Sc(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var Kl=25;function ql(e,t){let n=dl(e),r=fl(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=El();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=Vl(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<=Kl&&(a-=o)}else l<=Kl&&(a+=l);return{width:a,height:o,x:s,y:c}}function Jl(e,t){let n=Bl(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=hl(e)?Il(e):Tc(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Yl(e,t,n){let r;if(t===`viewport`)r=ql(e,n);else if(t===`document`)r=Gl(fl(e));else if(ml(t))r=Jl(t,n);else{let n=Rl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return qc(r)}function Xl(e,t){let n=Al(e);return n===t||!ml(n)||Dl(n)?!1:Ol(n).position===`fixed`||Xl(n,t)}function Zl(e,t){let n=t.get(e);if(n)return n;let r=Ml(e,[],!1).filter(e=>ml(e)&&ul(e)!==`body`),i=null,a=Ol(e).position===`fixed`,o=a?Al(e):e;for(;ml(o)&&!Dl(o);){let t=Ol(o),n=wl(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||_l(o)&&!n&&Xl(e,o))?r=r.filter(e=>e!==o):i=t,o=Al(o)}return t.set(e,r),r}function Ql(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?yl(t)?[]:Zl(t,this._c):[].concat(n),r],o=Yl(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=Yl(t,a[e],i);s=Sc(n.top,s),c=xc(n.right,c),l=xc(n.bottom,l),u=Sc(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function $l(e){let{width:t,height:n}=Pl(e);return{width:t,height:n}}function eu(e,t,n){let r=hl(t),i=fl(t),a=n===`fixed`,o=Bl(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Tc(0);function l(){c.x=Vl(i)}if(r||!r&&!a)if((ul(t)!==`body`||_l(i))&&(s=kl(t)),r){let e=Bl(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?Hl(i,s):Tc(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 tu(e){return Ol(e).position===`static`}function nu(e,t){if(!hl(e)||Ol(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return fl(e)===n&&(n=n.ownerDocument.body),n}function ru(e,t){let n=dl(e);if(yl(e))return n;if(!hl(e)){let t=Al(e);for(;t&&!Dl(t);){if(ml(t)&&!tu(t))return t;t=Al(t)}return n}let r=nu(e,t);for(;r&&vl(r)&&tu(r);)r=nu(r,t);return r&&Dl(r)&&tu(r)&&!wl(r)?n:r||Tl(e)||n}var iu=async function(e){let t=this.getOffsetParent||ru,n=this.getDimensions,r=await n(e.floating);return{reference:eu(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function au(e){return Ol(e).direction===`rtl`}var ou={convertOffsetParentRelativeRectToViewportRelativeRect:Ul,getDocumentElement:fl,getClippingRect:Ql,getOffsetParent:ru,getElementRects:iu,getClientRects:Wl,getDimensions:$l,getScale:Il,isElement:ml,isRTL:au};function su(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function cu(e,t){let n=null,r,i=fl(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=wc(d),h=wc(i.clientWidth-(u+f)),g=wc(i.clientHeight-(d+p)),_=wc(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Sc(0,xc(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&&!su(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 lu(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=Fl(e),u=i||a?[...l?Ml(l):[],...t?Ml(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?cu(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?Bl(e):null;c&&g();function g(){let t=Bl(e);h&&!su(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 uu=al,du=ol,fu=$c,pu=cl,mu=nl,hu=Qc,gu=sl,_u=(e,t,n)=>{let r=new Map,i={platform:ou,...n},a={...i.platform,_c:r};return Zc(e,t,{...i,platform:a})},vu=typeof document<`u`?T.useLayoutEffect:function(){};function yu(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(!yu(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)&&!yu(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function bu(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function xu(e,t){let n=bu(e);return Math.round(t*n)/n}function Su(e){let t=T.useRef(e);return vu(()=>{t.current=e}),t}function Cu(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]=T.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=T.useState(r);yu(f,r)||p(r);let[m,h]=T.useState(null),[g,_]=T.useState(null),v=T.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=T.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=T.useRef(null),C=T.useRef(null),w=T.useRef(u),E=c!=null,D=Su(c),O=Su(i),k=Su(l),A=T.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),_u(S.current,C.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!yu(w.current,t)&&(w.current=t,yt.flushSync(()=>{d(t)}))})},[f,t,n,O,k]);vu(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let j=T.useRef(!1);vu(()=>(j.current=!0,()=>{j.current=!1}),[]),vu(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(D.current)return D.current(b,x,A);A()}},[b,x,A,D,E]);let M=T.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),N=T.useMemo(()=>({reference:b,floating:x}),[b,x]),P=T.useMemo(()=>{let e={position:n,left:0,top:0};if(!N.floating)return e;let t=xu(N.floating,u.x),r=xu(N.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...bu(N.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,N.floating,u.x,u.y]);return T.useMemo(()=>({...u,update:A,refs:M,elements:N,floatingStyles:P}),[u,A,M,N,P])}var wu=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?{}:hu({element:r.current,padding:i}).fn(n):r?hu({element:r,padding:i}).fn(n):{}}}},Tu=(e,t)=>{let n=uu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eu=(e,t)=>{let n=du(e);return{name:n.name,fn:n.fn,options:[e,t]}},Du=(e,t)=>({fn:gu(e).fn,options:[e,t]}),Ou=(e,t)=>{let n=fu(e);return{name:n.name,fn:n.fn,options:[e,t]}},ku=(e,t)=>{let n=pu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Au=(e,t)=>{let n=mu(e);return{name:n.name,fn:n.fn,options:[e,t]}},ju=(e,t)=>{let n=wu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Mu=`Arrow`,Nu=T.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,K.jsx)(Yi.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`})})});Nu.displayName=Mu;var Pu=Nu,Fu=`Popper`,[Iu,Lu]=na(Fu),[Ru,zu]=Iu(Fu),Bu=e=>{let{__scopePopper:t,children:n}=e,[r,i]=T.useState(null);return(0,K.jsx)(Ru,{scope:t,anchor:r,onAnchorChange:i,children:n})};Bu.displayName=Fu;var Vu=`PopperAnchor`,Hu=T.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=zu(Vu,n),o=T.useRef(null),s=Ri(t,o),c=T.useRef(null);return T.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,K.jsx)(Yi.div,{...i,ref:s})});Hu.displayName=Vu;var Uu=`PopperContent`,[Wu,Gu]=Iu(Uu),Ku=T.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=zu(Uu,n),[_,v]=T.useState(null),y=Ri(t,e=>v(e)),[b,x]=T.useState(null),S=yc(b),C=S?.width??0,w=S?.height??0,E=r+(a===`center`?``:`-`+a),D=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},O=Array.isArray(l)?l:[l],k=O.length>0,A={padding:D,boundary:O.filter(Xu),altBoundary:k},{refs:j,floatingStyles:M,placement:N,isPositioned:P,middlewareData:F}=Cu({strategy:`fixed`,placement:E,whileElementsMounted:(...e)=>lu(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[Tu({mainAxis:i+w,alignmentAxis:o}),c&&Eu({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Du():void 0,...A}),c&&Ou({...A}),ku({...A,apply:({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)}}),b&&ju({element:b,padding:s}),Zu({arrowWidth:C,arrowHeight:w}),f&&Au({strategy:`referenceHidden`,...A})]}),[I,L]=Qu(N),R=ja(m);aa(()=>{P&&R?.()},[P,R]);let z=F.arrow?.x,B=F.arrow?.y,V=F.arrow?.centerOffset!==0,[H,U]=T.useState();return aa(()=>{_&&U(window.getComputedStyle(_).zIndex)},[_]),(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)(Wu,{scope:n,placedSide:I,onArrowChange:x,arrowX:z,arrowY:B,shouldHideArrow:V,children:(0,K.jsx)(Yi.div,{"data-side":I,"data-align":L,...h,ref:y,style:{...h.style,animation:P?void 0:`none`}})})})});Ku.displayName=Uu;var qu=`PopperArrow`,Ju={top:`bottom`,right:`left`,bottom:`top`,left:`right`},Yu=T.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=Gu(qu,n),a=Ju[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)(Pu,{...r,ref:t,style:{...r.style,display:`block`}})})});Yu.displayName=qu;function Xu(e){return e!==null}var Zu=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]=Qu(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 Qu(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var $u=Bu,ed=Hu,td=Ku,nd=Yu,rd=`Popover`,[id,ad]=na(rd,[Lu]),od=Lu(),[sd,cd]=id(rd),ld=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=od(t),c=T.useRef(null),[l,u]=T.useState(!1),[d,f]=sa({prop:r,defaultProp:i??!1,onChange:a,caller:rd});return(0,K.jsx)($u,{...s,children:(0,K.jsx)(sd,{scope:t,contentId:_a(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:T.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:T.useCallback(()=>u(!0),[]),onCustomAnchorRemove:T.useCallback(()=>u(!1),[]),modal:o,children:n})})};ld.displayName=rd;var ud=`PopoverAnchor`,dd=T.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=cd(ud,n),a=od(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return T.useEffect(()=>(o(),()=>s()),[o,s]),(0,K.jsx)(ed,{...a,...r,ref:t})});dd.displayName=ud;var fd=`PopoverTrigger`,pd=T.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=cd(fd,n),a=od(n),o=Ri(t,i.triggerRef),s=(0,K.jsx)(Yi.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Od(i.open),...r,ref:o,onClick:ia(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,K.jsx)(ed,{asChild:!0,...a,children:s})});pd.displayName=fd;var md=`PopoverPortal`,[hd,gd]=id(md,{forceMount:void 0}),_d=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=cd(md,t);return(0,K.jsx)(hd,{scope:t,forceMount:n,children:(0,K.jsx)(da,{present:n||a.open,children:(0,K.jsx)(lo,{asChild:!0,container:i,children:r})})})};_d.displayName=md;var vd=`PopoverContent`,yd=T.forwardRef((e,t)=>{let n=gd(vd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=cd(vd,e.__scopePopover);return(0,K.jsx)(da,{present:r||a.open,children:a.modal?(0,K.jsx)(xd,{...i,ref:t}):(0,K.jsx)(Sd,{...i,ref:t})})});yd.displayName=vd;var bd=Vi(`PopoverContent.RemoveScroll`),xd=T.forwardRef((e,t)=>{let n=cd(vd,e.__scopePopover),r=T.useRef(null),i=Ri(t,r),a=T.useRef(!1);return T.useEffect(()=>{let e=r.current;if(e)return js(e)},[]),(0,K.jsx)(Ss,{as:bd,allowPinchZoom:!0,children:(0,K.jsx)(Cd,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ia(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:ia(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:ia(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),Sd=T.forwardRef((e,t)=>{let n=cd(vd,e.__scopePopover),r=T.useRef(!1),i=T.useRef(!1);return(0,K.jsx)(Cd,{...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()}})}),Cd=T.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=cd(vd,n),p=od(n);return fo(),(0,K.jsx)(Xa,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,K.jsx)(za,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,K.jsx)(td,{"data-state":Od(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)`}})})})}),wd=`PopoverClose`,Td=T.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=cd(wd,n);return(0,K.jsx)(Yi.button,{type:`button`,...r,ref:t,onClick:ia(e.onClick,()=>i.onOpenChange(!1))})});Td.displayName=wd;var Ed=`PopoverArrow`,Dd=T.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=od(n);return(0,K.jsx)(nd,{...i,...r,ref:t})});Dd.displayName=Ed;function Od(e){return e?`open`:`closed`}var kd=ld,Ad=pd,jd=_d,Md=yd,Nd=Td,[Pd,Fd]=na(`Tooltip`,[Lu]),Id=Lu(),Ld=`TooltipProvider`,Rd=700,zd=`tooltip.open`,[Bd,Vd]=Pd(Ld),Hd=e=>{let{__scopeTooltip:t,delayDuration:n=Rd,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=T.useRef(!0),s=T.useRef(!1),c=T.useRef(0);return T.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,K.jsx)(Bd,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:T.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:T.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:T.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};Hd.displayName=Ld;var Ud=`Tooltip`,[Wd,Gd]=Pd(Ud),Kd=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Vd(Ud,e.__scopeTooltip),l=Id(t),[u,d]=T.useState(null),f=_a(),p=T.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=T.useRef(!1),[_,v]=sa({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(zd))):c.onClose(),a?.(e)},caller:Ud}),y=T.useMemo(()=>_?g.current?`delayed-open`:`instant-open`:`closed`,[_]),b=T.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,v(!0)},[v]),x=T.useCallback(()=>{window.clearTimeout(p.current),p.current=0,v(!1)},[v]),S=T.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,v(!0),p.current=0},h)},[h,v]);return T.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,K.jsx)($u,{...l,children:(0,K.jsx)(Wd,{scope:t,contentId:f,open:_,stateAttribute:y,trigger:u,onTriggerChange:d,onTriggerEnter:T.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:T.useCallback(()=>{m?x():(window.clearTimeout(p.current),p.current=0)},[x,m]),onOpen:b,onClose:x,disableHoverableContent:m,children:n})})};Kd.displayName=Ud;var qd=`TooltipTrigger`,Jd=T.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Gd(qd,n),a=Vd(qd,n),o=Id(n),s=Ri(t,T.useRef(null),i.onTriggerChange),c=T.useRef(!1),l=T.useRef(!1),u=T.useCallback(()=>c.current=!1,[]);return T.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,K.jsx)(ed,{asChild:!0,...o,children:(0,K.jsx)(Yi.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:ia(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:ia(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:ia(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:ia(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:ia(e.onBlur,i.onClose),onClick:ia(e.onClick,i.onClose)})})});Jd.displayName=qd;var Yd=`TooltipPortal`,[Xd,Zd]=Pd(Yd,{forceMount:void 0}),Qd=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=Gd(Yd,t);return(0,K.jsx)(Xd,{scope:t,forceMount:n,children:(0,K.jsx)(da,{present:n||a.open,children:(0,K.jsx)(lo,{asChild:!0,container:i,children:r})})})};Qd.displayName=Yd;var $d=`TooltipContent`,ef=T.forwardRef((e,t)=>{let n=Zd($d,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=Gd($d,e.__scopeTooltip);return(0,K.jsx)(da,{present:r||o.open,children:o.disableHoverableContent?(0,K.jsx)(of,{side:i,...a,ref:t}):(0,K.jsx)(tf,{side:i,...a,ref:t})})}),tf=T.forwardRef((e,t)=>{let n=Gd($d,e.__scopeTooltip),r=Vd($d,e.__scopeTooltip),i=T.useRef(null),a=Ri(t,i),[o,s]=T.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=T.useCallback(()=>{s(null),d(!1)},[d]),p=T.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=uf(r,lf(r,n.getBoundingClientRect())),a=df(t.getBoundingClientRect());s(pf([...i,...a])),d(!0)},[d]);return T.useEffect(()=>()=>f(),[f]),T.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]),T.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=!ff(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,K.jsx)(of,{...e,ref:a})}),[nf,rf]=Pd(Ud,{isInside:!1}),af=Gi(`TooltipContent`),of=T.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=Gd($d,n),l=Id(n),{onClose:u}=c;return T.useEffect(()=>(document.addEventListener(zd,u),()=>document.removeEventListener(zd,u)),[u]),T.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)(za,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,K.jsxs)(td,{"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)(af,{children:r}),(0,K.jsx)(nf,{scope:n,isInside:!0,children:(0,K.jsx)(ea,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});ef.displayName=$d;var sf=`TooltipArrow`,cf=T.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Id(n);return rf(sf,n).isInside?null:(0,K.jsx)(nd,{...i,...r,ref:t})});cf.displayName=sf;function lf(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 uf(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 df(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 ff(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 pf(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)),mf(t)}function mf(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 hf=Hd,gf=Kd,_f=Jd,vf=Qd,yf=ef,bf=cf;function xf(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=xf(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function Sf(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=xf(e))&&(r&&(r+=` `),r+=t);return r}var Cf=(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},wf=(e,t)=>({classGroupId:e,validator:t}),Tf=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),Ef=`-`,Df=[],Of=`arbitrary..`,kf=e=>{let t=Mf(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:e=>{if(e.startsWith(`[`)&&e.endsWith(`]`))return jf(e);let n=e.split(Ef);return Af(n,+(n[0]===``&&n.length>1),t)},getConflictingClassGroupIds:(e,t)=>{if(t){let t=r[e],i=n[e];return t?i?Cf(i,t):t:i||Df}return n[e]||Df}}},Af=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;let r=e[t],i=n.nextPart.get(r);if(i){let n=Af(e,t+1,i);if(n)return n}let a=n.validators;if(a===null)return;let o=t===0?e.join(Ef):e.slice(t).join(Ef),s=a.length;for(let e=0;e<s;e++){let t=a[e];if(t.validator(o))return t.classGroupId}},jf=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?Of+r:void 0})(),Mf=e=>{let{theme:t,classGroups:n}=e;return Nf(n,t)},Nf=(e,t)=>{let n=Tf();for(let r in e){let i=e[r];Pf(i,n,r,t)}return n},Pf=(e,t,n,r)=>{let i=e.length;for(let a=0;a<i;a++){let i=e[a];Ff(i,t,n,r)}},Ff=(e,t,n,r)=>{if(typeof e==`string`){If(e,t,n);return}if(typeof e==`function`){Lf(e,t,n,r);return}Rf(e,t,n,r)},If=(e,t,n)=>{let r=e===``?t:zf(t,e);r.classGroupId=n},Lf=(e,t,n,r)=>{if(Bf(e)){Pf(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(wf(n,e))},Rf=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e<a;e++){let[a,o]=i[e];Pf(o,zf(t,a),n,r)}},zf=(e,t)=>{let n=e,r=t.split(Ef),i=r.length;for(let e=0;e<i;e++){let t=r[e],i=n.nextPart.get(t);i||(i=Tf(),n.nextPart.set(t,i)),n=i}return n},Bf=e=>`isThemeGetter`in e&&e.isThemeGetter===!0,Vf=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)}}},Hf=`!`,Uf=`:`,Wf=[],Gf=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),Kf=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===Uf){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(Hf)?(c=s.slice(0,-1),l=!0):s.startsWith(Hf)&&(c=s.slice(1),l=!0);let u=a&&a>i?a-i:void 0;return Gf(t,l,c,u)};if(t){let e=t+Uf,n=r;r=t=>t.startsWith(e)?n(t.slice(e.length)):Gf(Wf,!1,t,void 0,!0)}if(n){let e=r;r=t=>n({className:t,parseClassName:e})}return r},qf=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}},Jf=e=>({cache:Vf(e.cacheSize),parseClassName:Kf(e),sortModifiers:qf(e),postfixLookupClassGroupIds:Yf(e),...kf(e)}),Yf=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},Xf=/\s+/,Zf=(e,t)=>{let{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:a,postfixLookupClassGroupIds:o}=t,s=[],c=e.trim().split(Xf),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?_+Hf:_,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},Qf=(...e)=>{let t=0,n,r,i=``;for(;t<e.length;)(n=e[t++])&&(r=$f(n))&&(i&&(i+=` `),i+=r);return i},$f=e=>{if(typeof e==`string`)return e;let t,n=``;for(let r=0;r<e.length;r++)e[r]&&(t=$f(e[r]))&&(n&&(n+=` `),n+=t);return n},ep=(e,...t)=>{let n,r,i,a,o=o=>(n=Jf(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=Zf(e,n);return i(e,a),a};return a=o,(...e)=>a(Qf(...e))},tp=[],np=e=>{let t=t=>t[e]||tp;return t.isThemeGetter=!0,t},rp=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,ip=/^\((?:(\w[\w-]*):)?(.+)\)$/i,ap=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,op=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,sp=/\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$/,cp=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,lp=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,up=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,dp=e=>ap.test(e),fp=e=>!!e&&!Number.isNaN(Number(e)),pp=e=>!!e&&Number.isInteger(Number(e)),mp=e=>e.endsWith(`%`)&&fp(e.slice(0,-1)),hp=e=>op.test(e),gp=()=>!0,_p=e=>sp.test(e)&&!cp.test(e),vp=()=>!1,yp=e=>lp.test(e),bp=e=>up.test(e),xp=e=>!q(e)&&!J(e),Sp=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)),Cp=e=>Rp(e,Hp,vp),q=e=>rp.test(e),wp=e=>Rp(e,Up,_p),Tp=e=>Rp(e,Wp,fp),Ep=e=>Rp(e,Kp,gp),Dp=e=>Rp(e,Gp,vp),Op=e=>Rp(e,Bp,vp),kp=e=>Rp(e,Vp,bp),Ap=e=>Rp(e,qp,yp),J=e=>ip.test(e),jp=e=>zp(e,Up),Mp=e=>zp(e,Gp),Np=e=>zp(e,Bp),Pp=e=>zp(e,Hp),Fp=e=>zp(e,Vp),Ip=e=>zp(e,qp,!0),Lp=e=>zp(e,Kp,!0),Rp=(e,t,n)=>{let r=rp.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},zp=(e,t,n=!1)=>{let r=ip.exec(e);return r?r[1]?t(r[1]):n:!1},Bp=e=>e===`position`||e===`percentage`,Vp=e=>e===`image`||e===`url`,Hp=e=>e===`length`||e===`size`||e===`bg-size`,Up=e=>e===`length`,Wp=e=>e===`number`,Gp=e=>e===`family-name`,Kp=e=>e===`number`||e===`weight`,qp=e=>e===`shadow`,Jp=ep(()=>{let e=np(`color`),t=np(`font`),n=np(`text`),r=np(`font-weight`),i=np(`tracking`),a=np(`leading`),o=np(`breakpoint`),s=np(`container`),c=np(`spacing`),l=np(`radius`),u=np(`shadow`),d=np(`inset-shadow`),f=np(`text-shadow`),p=np(`drop-shadow`),m=np(`blur`),h=np(`perspective`),g=np(`aspect`),_=np(`ease`),v=np(`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(),J,q],S=()=>[`auto`,`hidden`,`clip`,`visible`,`scroll`],C=()=>[`auto`,`contain`,`none`],w=()=>[J,q,c],T=()=>[dp,`full`,`auto`,...w()],E=()=>[pp,`none`,`subgrid`,J,q],D=()=>[`auto`,{span:[`full`,pp,J,q]},pp,J,q],O=()=>[pp,`auto`,J,q],k=()=>[`auto`,`min`,`max`,`fr`,J,q],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=()=>[dp,`auto`,`full`,`dvw`,`dvh`,`lvw`,`lvh`,`svw`,`svh`,`min`,`max`,`fit`,...w()],P=()=>[dp,`screen`,`full`,`dvw`,`lvw`,`svw`,`min`,`max`,`fit`,...w()],F=()=>[dp,`screen`,`full`,`lh`,`dvh`,`lvh`,`svh`,`min`,`max`,`fit`,...w()],I=()=>[e,J,q],L=()=>[...b(),Np,Op,{position:[J,q]}],R=()=>[`no-repeat`,{repeat:[``,`x`,`y`,`space`,`round`]}],z=()=>[`auto`,`cover`,`contain`,Pp,Cp,{size:[J,q]}],B=()=>[mp,jp,wp],V=()=>[``,`none`,`full`,l,J,q],H=()=>[``,fp,jp,wp],U=()=>[`solid`,`dashed`,`dotted`,`double`],W=()=>[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],G=()=>[fp,mp,Np,Op],ee=()=>[``,`none`,m,J,q],te=()=>[`none`,fp,J,q],ne=()=>[`none`,fp,J,q],re=()=>[fp,J,q],ie=()=>[dp,`full`,...w()];return{cacheSize:500,theme:{animate:[`spin`,`ping`,`pulse`,`bounce`],aspect:[`video`],blur:[hp],breakpoint:[hp],color:[gp],container:[hp],"drop-shadow":[hp],ease:[`in`,`out`,`in-out`],font:[xp],"font-weight":[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`],"inset-shadow":[hp],leading:[`none`,`tight`,`snug`,`normal`,`relaxed`,`loose`],perspective:[`dramatic`,`near`,`normal`,`midrange`,`distant`,`none`],radius:[hp],shadow:[hp],spacing:[`px`,fp],text:[hp],"text-shadow":[hp],tracking:[`tighter`,`tight`,`normal`,`wide`,`wider`,`widest`]},classGroups:{aspect:[{aspect:[`auto`,`square`,dp,q,J,g]}],container:[`container`],"container-type":[{"@container":[``,`normal`,`size`,J,q]}],"container-named":[Sp],columns:[{columns:[fp,q,J,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:[pp,`auto`,J,q]}],basis:[{basis:[dp,`full`,`auto`,s,...w()]}],"flex-direction":[{flex:[`row`,`row-reverse`,`col`,`col-reverse`]}],"flex-wrap":[{flex:[`nowrap`,`wrap`,`wrap-reverse`]}],flex:[{flex:[fp,dp,`auto`,`initial`,`none`,q]}],grow:[{grow:[``,fp,J,q]}],shrink:[{shrink:[``,fp,J,q]}],order:[{order:[pp,`first`,`last`,`none`,J,q]}],"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,jp,wp]}],"font-smoothing":[`antialiased`,`subpixel-antialiased`],"font-style":[`italic`,`not-italic`],"font-weight":[{font:[r,Lp,Ep]}],"font-stretch":[{"font-stretch":[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`,mp,q]}],"font-family":[{font:[Mp,Dp,t]}],"font-features":[{"font-features":[q]}],"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,J,q]}],"line-clamp":[{"line-clamp":[fp,`none`,J,Tp]}],leading:[{leading:[a,...w()]}],"list-image":[{"list-image":[`none`,J,q]}],"list-style-position":[{list:[`inside`,`outside`]}],"list-style-type":[{list:[`disc`,`decimal`,`none`,J,q]}],"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:[fp,`from-font`,`auto`,J,wp]}],"text-decoration-color":[{decoration:I()}],"underline-offset":[{"underline-offset":[fp,`auto`,J,q]}],"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:[pp,J,q]}],"vertical-align":[{align:[`baseline`,`top`,`middle`,`bottom`,`text-top`,`text-bottom`,`sub`,`super`,J,q]}],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`,J,q]}],"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`]},pp,J,q],radial:[``,J,q],conic:[pp,J,q]},Fp,kp]}],"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":[fp,J,q]}],"outline-w":[{outline:[``,fp,jp,wp]}],"outline-color":[{outline:I()}],shadow:[{shadow:[``,`none`,u,Ip,Ap]}],"shadow-color":[{shadow:I()}],"inset-shadow":[{"inset-shadow":[`none`,d,Ip,Ap]}],"inset-shadow-color":[{"inset-shadow":I()}],"ring-w":[{ring:H()}],"ring-w-inset":[`ring-inset`],"ring-color":[{ring:I()}],"ring-offset-w":[{"ring-offset":[fp,wp]}],"ring-offset-color":[{"ring-offset":I()}],"inset-ring-w":[{"inset-ring":H()}],"inset-ring-color":[{"inset-ring":I()}],"text-shadow":[{"text-shadow":[`none`,f,Ip,Ap]}],"text-shadow-color":[{"text-shadow":I()}],opacity:[{opacity:[fp,J,q]}],"mix-blend":[{"mix-blend":[...W(),`plus-darker`,`plus-lighter`]}],"bg-blend":[{"bg-blend":W()}],"mask-clip":[{"mask-clip":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]},`mask-no-clip`],"mask-composite":[{mask:[`add`,`subtract`,`intersect`,`exclude`]}],"mask-image-linear-pos":[{"mask-linear":[fp]}],"mask-image-linear-from-pos":[{"mask-linear-from":G()}],"mask-image-linear-to-pos":[{"mask-linear-to":G()}],"mask-image-linear-from-color":[{"mask-linear-from":I()}],"mask-image-linear-to-color":[{"mask-linear-to":I()}],"mask-image-t-from-pos":[{"mask-t-from":G()}],"mask-image-t-to-pos":[{"mask-t-to":G()}],"mask-image-t-from-color":[{"mask-t-from":I()}],"mask-image-t-to-color":[{"mask-t-to":I()}],"mask-image-r-from-pos":[{"mask-r-from":G()}],"mask-image-r-to-pos":[{"mask-r-to":G()}],"mask-image-r-from-color":[{"mask-r-from":I()}],"mask-image-r-to-color":[{"mask-r-to":I()}],"mask-image-b-from-pos":[{"mask-b-from":G()}],"mask-image-b-to-pos":[{"mask-b-to":G()}],"mask-image-b-from-color":[{"mask-b-from":I()}],"mask-image-b-to-color":[{"mask-b-to":I()}],"mask-image-l-from-pos":[{"mask-l-from":G()}],"mask-image-l-to-pos":[{"mask-l-to":G()}],"mask-image-l-from-color":[{"mask-l-from":I()}],"mask-image-l-to-color":[{"mask-l-to":I()}],"mask-image-x-from-pos":[{"mask-x-from":G()}],"mask-image-x-to-pos":[{"mask-x-to":G()}],"mask-image-x-from-color":[{"mask-x-from":I()}],"mask-image-x-to-color":[{"mask-x-to":I()}],"mask-image-y-from-pos":[{"mask-y-from":G()}],"mask-image-y-to-pos":[{"mask-y-to":G()}],"mask-image-y-from-color":[{"mask-y-from":I()}],"mask-image-y-to-color":[{"mask-y-to":I()}],"mask-image-radial":[{"mask-radial":[J,q]}],"mask-image-radial-from-pos":[{"mask-radial-from":G()}],"mask-image-radial-to-pos":[{"mask-radial-to":G()}],"mask-image-radial-from-color":[{"mask-radial-from":I()}],"mask-image-radial-to-color":[{"mask-radial-to":I()}],"mask-image-radial-shape":[{"mask-radial":[`circle`,`ellipse`]}],"mask-image-radial-size":[{"mask-radial":[{closest:[`side`,`corner`],farthest:[`side`,`corner`]}]}],"mask-image-radial-pos":[{"mask-radial-at":b()}],"mask-image-conic-pos":[{"mask-conic":[fp]}],"mask-image-conic-from-pos":[{"mask-conic-from":G()}],"mask-image-conic-to-pos":[{"mask-conic-to":G()}],"mask-image-conic-from-color":[{"mask-conic-from":I()}],"mask-image-conic-to-color":[{"mask-conic-to":I()}],"mask-mode":[{mask:[`alpha`,`luminance`,`match`]}],"mask-origin":[{"mask-origin":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]}],"mask-position":[{mask:L()}],"mask-repeat":[{mask:R()}],"mask-size":[{mask:z()}],"mask-type":[{"mask-type":[`alpha`,`luminance`]}],"mask-image":[{mask:[`none`,J,q]}],filter:[{filter:[``,`none`,J,q]}],blur:[{blur:ee()}],brightness:[{brightness:[fp,J,q]}],contrast:[{contrast:[fp,J,q]}],"drop-shadow":[{"drop-shadow":[``,`none`,p,Ip,Ap]}],"drop-shadow-color":[{"drop-shadow":I()}],grayscale:[{grayscale:[``,fp,J,q]}],"hue-rotate":[{"hue-rotate":[fp,J,q]}],invert:[{invert:[``,fp,J,q]}],saturate:[{saturate:[fp,J,q]}],sepia:[{sepia:[``,fp,J,q]}],"backdrop-filter":[{"backdrop-filter":[``,`none`,J,q]}],"backdrop-blur":[{"backdrop-blur":ee()}],"backdrop-brightness":[{"backdrop-brightness":[fp,J,q]}],"backdrop-contrast":[{"backdrop-contrast":[fp,J,q]}],"backdrop-grayscale":[{"backdrop-grayscale":[``,fp,J,q]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[fp,J,q]}],"backdrop-invert":[{"backdrop-invert":[``,fp,J,q]}],"backdrop-opacity":[{"backdrop-opacity":[fp,J,q]}],"backdrop-saturate":[{"backdrop-saturate":[fp,J,q]}],"backdrop-sepia":[{"backdrop-sepia":[``,fp,J,q]}],"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`,J,q]}],"transition-behavior":[{transition:[`normal`,`discrete`]}],duration:[{duration:[fp,`initial`,J,q]}],ease:[{ease:[`linear`,`initial`,_,J,q]}],delay:[{delay:[fp,J,q]}],animate:[{animate:[`none`,v,J,q]}],backface:[{backface:[`hidden`,`visible`]}],perspective:[{perspective:[h,J,q]}],"perspective-origin":[{"perspective-origin":x()}],rotate:[{rotate:te()}],"rotate-x":[{"rotate-x":te()}],"rotate-y":[{"rotate-y":te()}],"rotate-z":[{"rotate-z":te()}],scale:[{scale:ne()}],"scale-x":[{"scale-x":ne()}],"scale-y":[{"scale-y":ne()}],"scale-z":[{"scale-z":ne()}],"scale-3d":[`scale-3d`],skew:[{skew:re()}],"skew-x":[{"skew-x":re()}],"skew-y":[{"skew-y":re()}],transform:[{transform:[J,q,``,`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:[pp,J,q]}],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`,J,q]}],"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`,J,q]}],fill:[{fill:[`none`,...I()]}],"stroke-w":[{stroke:[fp,jp,wp,Tp]}],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 Y(...e){return Jp(Sf(e))}function Yp({delayDuration:e=0,...t}){return(0,K.jsx)(hf,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Xp({...e}){return(0,K.jsx)(gf,{"data-slot":`tooltip`,...e})}function Zp({...e}){return(0,K.jsx)(_f,{"data-slot":`tooltip-trigger`,...e})}function Qp({className:e,sideOffset:t=4,children:n,...r}){return(0,K.jsx)(vf,{children:(0,K.jsxs)(yf,{"data-slot":`tooltip-content`,sideOffset:t,className:Y(`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)(bf,{className:`fill-gray-900`})]})})}var X=(e,t)=>fetch(e,{credentials:`include`,...t}),$p=null;function em(){return $p||=X(`/api/health`).then(e=>e.json()).then(e=>typeof e?.workspace==`string`?e.workspace:`loopat`).catch(()=>`loopat`),$p}async function tm(){let e=await X(`/api/auth/me`);return e.ok?(await e.json()).user??null:null}async function nm(e,t){let n=await X(`/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 rm(e){let t=await X(`/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 im(e){let t=await X(`/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 am(){let e=await X(`/api/personal/status`);return e.ok?await e.json():null}async function om(e){let t=await X(`/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 sm(e,t=!1){let n=await X(`/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 cm(e){let t=await X(`/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 lm(){let e=await X(`/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 um(e,t){let n={};e&&(n.repoUrl=e),t&&(n.cryptKey=t);let r=await X(`/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 dm(e,t,n,r){let i={token:e};t&&(i.repoName=t),n&&(i.cryptKey=n),r&&(i.baseUrl=r);let a=await X(`/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 fm(){await X(`/api/auth/logout`,{method:`POST`}).catch(()=>{})}async function pm(e=`active`){let t=await X(`/api/loops`+(e===`all`?`?archived=all`:e===`archived`?`?archived=true`:``));return t.ok?(await t.json()).loops:[]}async function mm(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 X(`/api/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json()}let t=await X(`/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 hm(){let e=await X(`/api/profiles`);return e.ok?(await e.json()).profiles??[]:[]}async function gm(){let e=await X(`/api/personal/default-profiles`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.default_profiles)?t.default_profiles:[]}async function _m(e){let t=await X(`/api/loop-stats?profiles=${encodeURIComponent(e.join(`,`))}`);return t.ok?await t.json():null}async function vm(){let e=await X(`/api/vaults`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.vaults)?t.vaults:[]}async function ym(e){return(await X(`/api/loops/${e}/viewed`,{method:`POST`})).ok}async function bm(e,t){let n=await X(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({archived:t})});return n.ok?await n.json():null}async function xm(e,t){let n=await X(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({public:t})});return n.ok?await n.json():null}async function Sm(e,t){let n=await X(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({title:t})});return n.ok?await n.json():null}async function Cm(e){let t=await X(`/api/loops/${e}/request-drive`,{method:`POST`});return t.ok?await t.json():null}async function wm(e){let t=await X(`/api/loops/${e}/drive`,{method:`POST`});return t.ok?await t.json():null}async function Tm(e){let t=await X(`/api/loops/${e}/distill`,{method:`POST`});return t.ok?await t.json():null}async function Em(e){let t=await X(`/api/loops/${e}`);return t.ok?await t.json():null}async function Dm(e){let t=await X(`/api/loops/${e}/strip-thinking`,{method:`POST`});return t.ok?await t.json():{stripped:0,sessionsTouched:0}}async function Om(e,t=``){return(await(await X(`/api/loops/${e}/files?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function km(e,t=``){return(await(await X(`/api/loops/${e}/files/tree?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Am(e,t){let n=await X(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function jm(e,t,n){return(await X(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).ok}async function Mm(e,t){return(await X(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function Nm(e,t){return(await X(`/api/loops/${e}/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).ok}async function Pm(e,t){let n=new FormData;n.append(`file`,t);let r=await X(`/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 Fm(e){let t=await X(`/api/loops/${e}/context`);return t.ok?(await t.json()).mounts??[]:[]}async function Im(e,t=``){let n=await X(`/api/workspace/files?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).entries??[]:[]}async function Lm(e){let t=await X(`/api/workspace/files?vault=${e}&flat=1`);return t.ok?(await t.json()).entries??[]:[]}async function Rm(e,t){let n=await X(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function zm(e,t,n){return await(await X(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).json()}async function Bm(){let e=await X(`/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 Vm(){let e=await(await X(`/api/notes/behind`)).json().catch(()=>({}));return typeof e.behind==`number`?e.behind:0}async function Hm(){let e=await(await X(`/api/notes/refresh`,{method:`POST`})).json().catch(()=>({}));return{ok:!!e.ok,diverged:e.diverged,error:e.error}}async function Um(e,t){return await(await X(`/api/workspace/file?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Wm(e,t){return await(await X(`/api/workspace/folder?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Gm(e,t){return await(await X(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`DELETE`})).json()}async function Km(e,t){let n=await X(`/api/workspace/backlinks?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).backlinks??[]:[]}async function qm(){let e=await X(`/api/workspace/repos`);return e.ok?(await e.json()).repos??[]:[]}async function Jm(e){let t=await X(`/api/loops/${e}/chat-history`);return t.ok?(await t.json()).map(e=>e.text):[]}async function Ym(e,t){await X(`/api/loops/${e}/chat-history`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t})})}async function Xm(e){let t=await X(`/api/workspace/repo/${encodeURIComponent(e)}`);return t.ok?await t.json():null}async function Zm(e){let t=await X(`/api/workspace/repo/${encodeURIComponent(e)}/pull`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,output:n.output}:{ok:!1,error:n.error??`http ${t.status}`}}function Qm(e){return typeof e==`string`?`/api/sync/${e}`:`/api/sync/repos/${encodeURIComponent(e.repo)}`}async function $m(e){let t=await X(`${Qm(e)}/status`);return t.ok?await t.json():null}async function eh(e){let t=await X(`${Qm(e)}/pull`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function th(e){let t=await X(`${Qm(e)}/push`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function nh(e){let t=await X(`/api/workspace/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,name:n.name,kind:n.kind}:{ok:!1,error:n.error??`http ${t.status}`}}async function rh(e=`default`){let t=await X(`/api/kanban/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function ih(e,t,n){let r=await X(`/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 ah(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/toggle`,{method:`PATCH`})).ok}async function oh(e,t,n,r){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(r)})).ok}async function sh(e,t,n,r){return(await X(`/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 ch(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`DELETE`})).ok}async function lh(e,t,n,r,i){return(await X(`/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 uh(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({filename:t,title:n})})).ok}async function dh(){let e=await X(`/api/kanban/boards`);return e.ok?(await e.json()).boards:[`default`]}async function fh(e){return(await X(`/api/kanban/boards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).ok}async function ph(e,t){return(await X(`/api/kanban/boards/${encodeURIComponent(e)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})})).ok}async function mh(e=`default`){let t=await X(`/api/kanban/config/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function hh(e,t){return(await X(`/api/kanban/config/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({columns:t})})).ok}async function gh(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:n})})).ok}async function _h(e,t){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function vh(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/color`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({color:n})})).ok}async function yh(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/reorder`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({cids:n})})).ok}async function bh(e,t,n){let r=await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/assign-driver`,{method:`POST`});return r.ok?await r.json():{ok:!1}}async function xh(e,t,n,r){return(await X(`/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 Sh(){let e=await X(`/api/topics`);return e.ok?(await e.json()).topics:[]}async function Ch(){let e=await X(`/api/providers`);return e.ok?await e.json():{providers:{},default:``}}async function wh(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 X(`/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 Th(){let e=await X(`/api/version`);return e.ok?await e.json():{branch:`unknown`,commit:`unknown`}}async function Eh(){let e=await X(`/api/admin/system`);return e.ok?await e.json():null}async function Dh(){return await(await X(`/api/admin/system/check`,{method:`POST`})).json()}async function Oh(){return await(await X(`/api/admin/system/pull`,{method:`POST`})).json()}function kh(){return{commit:`f47b022d4b3c3d6d0c999568a5b1bd98040eb959`,time:`2026-05-31T14:55:25.017Z`}}async function Ah(e){let t=await X(`/api/loops/${e}/git-status`);return t.ok?await t.json():{unstaged:[],staged:[]}}async function jh(e,t,n){let r=await X(`/api/loops/${e}/git-diff?path=${encodeURIComponent(t)}&staged=${n?`1`:`0`}`);return r.ok?(await r.json()).diff??null:null}async function Mh(e,t,n=!1){return(await X(`/api/loops/${e}/git-stage`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({files:t,unstage:n})})).ok}async function Nh(e,t){return(await X(`/api/loops/${e}/git-discard`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({file:t})})).ok}async function Ph(e,t){let n=await X(`/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 Fh(e,t=50){let n=await X(`/api/loops/${e}/git-log?limit=${t}`);return n.ok?(await n.json()).commits??[]:[]}async function Ih(){let e=await X(`/api/settings/personal/disk`);return e.ok?await e.json():null}async function Lh(e){let t=await X(`/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 Rh(e,t,n=`default`){let r=await X(`/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 zh(){return await(await X(`/api/settings/workspace`)).json()}async function Bh(e){return(await X(`/api/settings/workspace`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Vh(){let e=await X(`/api/settings/token-usage/daily`);return e.ok?await e.json():{}}async function Hh(){let e=await X(`/api/settings/token-usage/loops`);return e.ok?await e.json():[]}async function Uh(){let e=await X(`/api/admin/presets`);return e.ok?await e.json():{providerPresets:[],miseToolPresets:[]}}async function Wh(e){return(await X(`/api/admin/presets`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Gh(){let e=await X(`/api/admin/users`);return e.ok?(await e.json()).users??[]:[]}async function Kh(e){let t=await X(`/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 qh(e,t){let n=await X(`/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 Jh(e){let t=await X(`/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 Yh(){let e=await X(`/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 Xh(e){let t=await X(`/api/loops/${e}/share/current-port`);return t.ok?await t.json():{port:null}}async function Zh(e){return(await X(`/api/serve/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Qh(){let e=await X(`/api/serve/available-port`);return e.ok?await e.json():{port:null,error:`request failed`}}async function $h(e,t){let n=await X(`/api/serve/check-port?port=${e}&loopId=${t||``}`);return n.ok?await n.json():{available:!1,reason:`request failed`}}async function eg(e,t){let n=new URLSearchParams({alias:e});t&&n.set(`loopId`,t);let r=await X(`/api/serve/alias-check?${n}`);return r.ok?await r.json():{available:!1,reason:`check failed`}}async function tg(){let e=await X(`/api/chat/conversations`);return e.ok?(await e.json()).conversations??[]:[]}async function ng(){let e=await X(`/api/chat/users`);return e.ok?(await e.json()).users??[]:[]}async function rg(e,t){let n=await X(`/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 ig(e){let t=await X(`/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 ag(e){let t=await X(`/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 og(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 X(`/api/chat/conversations/${encodeURIComponent(e)}/messages?${n.toString()}`);return r.ok?(await r.json()).messages??[]:[]}async function sg(e){let t=await X(`/api/chat/threads/${e}`);return t.ok?await t.json():null}async function cg(e,t,n=null){let r=await X(`/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 lg(e,t){return(await X(`/api/chat/conversations/${encodeURIComponent(e)}/read`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({lastReadId:t})})).ok}async function ug(e,t){let n=await X(`/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 dg(){let e=await X(`/api/onboarding`);return e.ok?await e.json():{state:`fresh`}}async function fg(){let e=await X(`/api/onboarding/start`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{loopId:t.loopId}:{error:t.error??`start failed`}}async function pg(){return(await X(`/api/onboarding/done`,{method:`POST`})).ok}async function mg(e){let t=await X(`/api/mcp-servers${e?`?loopId=${encodeURIComponent(e)}`:``}`);return t.ok?await t.json():{servers:[]}}async function hg(e,t){let n=await X(`/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 gg(e){return(await X(`/api/envs/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}async function _g(e){let t=await X(`/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 vg(){let e=await X(`/api/tiers`);return e.ok?await e.json():null}async function yg(e,t){let n=await X(`/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 bg(e){let t=await X(`/api/tiers/${encodeURIComponent(e)}/mise-config`);return t.ok?await t.json():{content:``,exists:!1,error:`fetch failed (${t.status})`}}async function xg(e,t){let n=await X(`/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 Sg(){let e=await X(`/api/plugins/available`);return e.ok?(await e.json()).plugins??[]:[]}async function Cg(){let e=await X(`/api/plugins/browse`);return e.ok?(await e.json()).plugins??[]:[]}async function wg(){let e=await X(`/api/marketplaces`);return e.ok?(await e.json()).marketplaces??[]:[]}async function Tg(){let e=await X(`/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 Eg(e){let t=await X(`/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 Dg(e){let t=await X(`/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 Og(){let e=await X(`/api/v1/me/tokens`);return e.ok?(await e.json().catch(()=>({tokens:[]}))).tokens??[]:[]}async function kg(e){let t=await X(`/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 Ag(e){return(await X(`/api/v1/me/tokens/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}function jg(){let[e,t]=(0,T.useState)([]),[n,r]=(0,T.useState)(!0),[i,a]=(0,T.useState)(!1),[o,s]=(0,T.useState)(!1),[c,l]=(0,T.useState)(``),[u,d]=(0,T.useState)(null),[f,p]=(0,T.useState)(null),[m,h]=(0,T.useState)(!0),g=(0,T.useCallback)(async()=>{r(!0),t(await pm(i?`all`:`active`)),r(!1)},[i]);(0,T.useEffect)(()=>{let e=!1;return tm().then(t=>{e||(p(t),h(!1))}),()=>{e=!0}},[]),(0,T.useEffect)(()=>{g()},[i,f]);let _=(0,T.useCallback)(async e=>{let n=await mm(e);return t(e=>[n,...e]),n},[]),v=(0,T.useCallback)(async(e,n)=>{let r=await bm(e,n);r&&t(t=>!i&&r.archived?t.filter(t=>t.id!==e):t.map(t=>t.id===e?r:t))},[i]),y=(0,T.useCallback)(async(e,n)=>{let r=await xm(e,n);r&&t(t=>t.map(t=>t.id===e?r:t))},[]),b=(0,T.useCallback)(async(e,n)=>{let r=await Sm(e,n);return r?(t(t=>t.map(t=>t.id===e?r:t)),r):null},[]),x=(0,T.useCallback)(async e=>{let n=await Cm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),S=(0,T.useCallback)(async e=>{let n=await wm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),C=(0,T.useCallback)(async(e,t)=>{let n=await nm(e,t);return n.user&&p(n.user),{error:n.error}},[]),w=(0,T.useCallback)(async e=>{let t=await rm(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,T.useCallback)(async()=>{await fm(),p(null)},[]);return{loops:e,loopsLoading:n,showArchived:i,setShowArchived:a,refresh:g,createLoop:_,setLoopArchived:v,setLoopPublic:y,setLoopTitle:b,requestDrive:x,takeDrive:S,newLoopDialogOpen:o,newLoopDialogTitle:c,kanbanCreateCtx:u,setNewLoopDialogOpen:(0,T.useCallback)((e,t,n)=>{s(e),l(t??``),d(n??null)},[]),currentUser:f,authLoading:m,login:C,register:w,logout:E}}var Mg=(0,T.createContext)(null);function Ng(){let e=(0,T.useContext)(Mg);if(!e)throw Error(`useWorkspace outside provider`);return e}function Pg({onClose:e,onCreate:t,initialTitle:n}){let[r,i]=(0,T.useState)(n??``),[a,o]=(0,T.useState)(``),[s,c]=(0,T.useState)(new Set),[l,u]=(0,T.useState)([]),[d,f]=(0,T.useState)(`default`),[p,m]=(0,T.useState)([]),[h,g]=(0,T.useState)([]),[_,v]=(0,T.useState)([]),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)(!1),[C,w]=(0,T.useState)(!1),E=(0,T.useRef)(null);(0,T.useEffect)(()=>{qm().then(m),Promise.all([hm(),gm()]).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`)))}),vm().then(e=>{v(e),e.includes(`default`)?f(`default`):e.length>0&&f(e[0])}),E.current?.focus()},[]);function D(){let e=new Set(h.map(e=>e.name));c(new Set(l.filter(t=>e.has(t)&&t!==`base`)))}(0,T.useEffect)(()=>{S(!0);let e=setTimeout(()=>{_m([...s]).then(b).finally(()=>S(!1))},120);return()=>clearTimeout(e)},[s]);let O=(()=>{let e=new Set(l.filter(e=>e!==`base`));if(e.size!==s.size)return!0;for(let t of e)if(!s.has(t))return!0;return!1})(),k=h.find(e=>e.name===`base`),A=h.filter(e=>e.name!==`base`);function j(e){c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return(0,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(),!C){w(!0);try{await t({title:r.trim()||`untitled`,repo:a||void 0,profiles:s.size>0?[...s]:void 0,vault:d||void 0})}finally{w(!1)}}},className:`flex flex-col gap-4`,children:[(0,K.jsxs)(Fg,{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.remote?` · ${e.remote}`:``]},e.name))]}),p.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:"No repos registered. Run `git clone` into context/repos/<name>/."})]}),(0,K.jsxs)(Fg,{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 in workspace. Create directories under`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`context/profiles/<name>/`}),` with a profile.json.`]})]}),(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:x&&!y?(0,K.jsx)(`span`,{className:`text-gray-400`,children:`computing…`}):y?(0,K.jsxs)(`span`,{title:`Totals across team + selected profiles + their plugins (deduped by name)`,children:[(0,K.jsxs)(`span`,{className:y.plugins>0?``:`text-gray-400`,children:[y.plugins,` plugins`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.skills>0?``:`text-gray-400`,children:[y.skills,` skills`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.agents>0?``:`text-gray-400`,children:[y.agents,` agents`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.hooks>0?``:`text-gray-400`,children:[y.hooks,` hooks`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.mcpServers>0?``:`text-gray-400`,children:[y.mcpServers,` MCP servers`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.toolchain>0?``:`text-gray-400`,title:`mise.toml [tools] entries, deduped across team + selected profiles`,children:[y.toolchain,` toolchain`]}),x&&(0,K.jsx)(`span`,{className:`ml-1.5 text-gray-400`,children:`·`}),x&&(0,K.jsx)(`span`,{className:`ml-1 text-gray-400`,children:`updating…`})]}):(0,K.jsx)(`span`,{className:`text-gray-400`,children:`—`})})]}),(0,K.jsxs)(Fg,{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:[_.length===0&&(0,K.jsx)(`option`,{value:`default`,children:`default`}),_.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),_.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)(Fg,{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:C,className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:C?`creating…`:`create`})]})]})]})})}function Fg({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 Ig=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,Lg=Sf,Rg=((e,t)=>n=>{if(t?.variants==null)return Lg(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=Ig(t)||Ig(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 Lg(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 zg({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,K.jsx)(r?Hi:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:Y(Rg({variant:t,size:n,className:e})),...i})}function Bg({...e}){return(0,K.jsx)(fc,{"data-slot":`dialog`,...e})}function Vg({...e}){return(0,K.jsx)(pc,{"data-slot":`dialog-portal`,...e})}function Hg({className:e,...t}){return(0,K.jsx)(mc,{"data-slot":`dialog-overlay`,className:Y(`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 Ug({className:e,children:t,showCloseButton:n=!0,...r}){return(0,K.jsxs)(Vg,{"data-slot":`dialog-portal`,children:[(0,K.jsx)(Hg,{}),(0,K.jsxs)(hc,{"data-slot":`dialog-content`,className:Y(`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)(vc,{"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)(_t,{}),(0,K.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function Wg({className:e,...t}){return(0,K.jsx)(`div`,{"data-slot":`dialog-header`,className:Y(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function Gg({className:e,...t}){return(0,K.jsx)(gc,{"data-slot":`dialog-title`,className:Y(`text-lg leading-none font-semibold`,e),...t})}function Kg({className:e,...t}){return(0,K.jsx)(_c,{"data-slot":`dialog-description`,className:Y(`text-sm text-muted-foreground`,e),...t})}function qg({open:e,onClose:t}){let[n,r]=(0,T.useState)({branch:`…`,commit:`…`}),i=kh();return(0,T.useEffect)(()=>{e&&Th().then(e=>r(e))},[e]),(0,K.jsx)(Bg,{open:e,onOpenChange:e=>!e&&t(),children:(0,K.jsxs)(Ug,{className:`sm:max-w-sm bg-white`,children:[(0,K.jsx)(Wg,{children:(0,K.jsxs)(Gg,{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 Jg(e,t){let n=e[Yg];if(!n)throw Error(`ResourceElement.type is not a valid Resource`);return n(t)}var Yg=Symbol(`fnSymbol`);function Xg(e){let t=e=>({type:t,props:e});return t[Yg]=e,t}function Zg(e,t){return{...t,key:e}}var Qg=typeof process<`u`&&!1,$g=null;function e_(e,t){e.currentIndex=0;let n=$g;$g=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{$g=n}}function t_(){if(!$g)throw Error(`No resource fiber available`);return $g}function n_(e){return Qg?$g?.devStrictMode?$g.isFirstRender?`child`:`root`:e?`root`:null:null}var r_=e=>({version:0,committedVersion:0,dispatchUpdate:e,changelog:[],dirtyCells:[]}),i_=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},a_=(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()),i_(e)}}},o_=(e,t)=>{t.dirty||(t.dirty=!0,e.markDirty?.(),e.root.dirtyCells.push(t))},s_=(e,t)=>{let n=t_(),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},c_=e=>{t_().renderContext.effectTasks.push(e)},l_=(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 u_(e,t,n,r){let i=s_(`reducer`,()=>{let t=t_(),a=r?r(n):n;return Qg&&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};l_(t,()=>t.root.dirtyCells.length===0&&!r.hasEagerState&&(r.eagerState=e(i.workInProgress,n),r.hasEagerState=!0,Object.is(i.current,r.eagerState))?null:()=>{o_(t,i),i.queue.add(r)})}}}),a=t_(),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),Qg&&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)||(o_(a,i),i.workInProgress=e)}return[i.workInProgress,i.dispatch]}function d_(e,t,n){return u_(e,void 0,t,n)}function f_(e,t,n,r){return u_(e,t,n,r)}var p_=(e,t)=>typeof t==`function`?t(e):t,m_=e=>typeof e==`function`?e():e;function h_(e){return d_(p_,e,m_)}var g_=(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},__=()=>({type:`effect`,cleanup:void 0,deps:null});function v_(e,t){let n=s_(`effect`,__);if(!(t&&n.deps&&g_(n.deps,t))){if(n.deps!==null&&!!t!=!!n.deps)throw Error(`tapEffect called with and without dependencies across re-renders`);c_(()=>{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 y_(e){let[t]=h_(()=>({current:e}));return t}function b_(e,t){let[n]=h_(e);return n}var x_=()=>{throw Error(`Memo reducer should not be called`)},S_=(e,t)=>{let n=t_(),[r]=f_(x_,r=>{if(r&&g_(r.deps,t))return r;let i=e();return Qg&&n.devStrictMode&&e(),{value:i,deps:t}},null);return r.value},C_=(e,t)=>S_(()=>e,t);function w_(e){let t=y_(e);v_(()=>{t.current=e});let n=t_();return C_(((...e)=>{if(Qg&&n.renderContext)throw Error(`tapEffectEvent cannot be called during render`);return t.current(...e)}),[n])}function T_(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 E_(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 D_(e,t,n=void 0,r=n_(!1)){return{type:e,root:t,markDirty:n,devStrictMode:r,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function O_(e){if(!e.isMounted)throw Error(`Tried to unmount a fiber that is already unmounted`);e.isMounted=!1,E_(e)}function k_(e,t){let n={effectTasks:[],props:t,output:void 0};return e_(e,()=>{e.renderContext=n;try{n.output=Jg(e.type,t)}finally{e.renderContext=void 0}}),n}function A_(e,t){e.isMounted=!0,Qg&&e.isNeverMounted&&e.devStrictMode===`root`&&(e.isNeverMounted=!1,T_(t),E_(e)),e.isNeverMounted=!1,T_(t)}function j_(e,t){let n=t_(),r=y_(0),i=S_(()=>(e.key,D_(e.type,n.root,()=>{r.current++,n.markDirty?.()})),[e.type,e.key,n]),a=t?S_(()=>k_(i,e.props),[i,...t,r.current]):k_(i,e.props);return v_(()=>()=>O_(i),[i]),v_(()=>{A_(i,a)},[i,a]),a.output}function M_(e,t){let n=y_(0),r=n.current,i=b_(t_,[]),a=b_(()=>()=>{n.current++,i.markDirty?.()},[]),o=b_(()=>new Map,[]),s=t?C_(e,t):e,c=S_(()=>{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=D_(c.type,i.root,a),t=k_(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=D_(c.type,i.root,a),t=k_(e,c.props);u.next=[e,t],n.push(t.output)}else u.next=k_(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 v_(()=>()=>{for(let e of o.keys()){let t=o.get(e).fiber;O_(t)}},[]),v_(()=>{for(let[e,t]of o.entries())t.next===`delete`?(t.fiber.isMounted&&O_(t.fiber),o.delete(e)):Array.isArray(t.next)?(O_(t.fiber),t.fiber=t.next[0],A_(t.fiber,t.next[1])):A_(t.fiber,t.next)},[c]),c}var N_=50,P_={schedulers:new Set([]),isScheduled:!1},F_=class{_task;_isDirty=!1;constructor(e){this._task=e}get isDirty(){return this._isDirty}markDirty(){this._isDirty=!0,P_.schedulers.add(this),I_()}runTask(){this._isDirty=!1,this._task()}},I_=()=>{P_.isScheduled||(P_.isScheduled=!0,R_())},L_=()=>{try{let e=[],t=0;for(let n of P_.schedulers)if(P_.schedulers.delete(n),n.isDirty){if(t++,t>N_)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{P_.schedulers.clear(),P_.isScheduled=!1}},R_=(()=>{if(typeof MessageChannel<`u`){let e=new MessageChannel;return e.port1.onmessage=L_,()=>e.port2.postMessage(null)}return()=>setTimeout(L_,0)})(),z_=e=>{let t=P_;P_={schedulers:new Set([]),isScheduled:!0};try{let t=e();return L_(),t}finally{P_=t}},B_=e=>{let t=b_(()=>new F_(()=>l(null)),[]),n=b_(()=>[],[]),r=S_(()=>(e.key,D_(e.type,r_(e=>{!t.isDirty&&!e()||(n.push(e),t.markDirty())}))),[e.type,e.key]);a_(r.root,r.root.committedVersion);let i=k_(r,e.props),a=y_(!1),o=y_(e.props),s=y_(i.output),c=b_(()=>new Set,[]),l=w_(e=>{if(e===null&&(a_(r.root,2),a_(r.root,1),n.forEach(e=>{Qg&&r.devStrictMode&&e(),e()}),Qg&&r.devStrictMode&&k_(r,o.current),e=k_(r,o.current)),t.isDirty)throw Error(`Scheduler is dirty, this should never happen`);i_(r.root),n.length=0,a.current&&A_(r,e),!(t.isDirty||s.current===e.output)&&(s.current=e.output,c.forEach(e=>e()))});return v_(()=>(a.current=!0,()=>{a.current=!1,O_(r)}),[r]),v_(()=>{o.current=i.props,i_(r.root),A_(r,i),!(t.isDirty||s.current===i.output)&&(s.current=i.output,c.forEach(e=>e()))}),S_(()=>({getValue:()=>s.current,subscribe:e=>(c.add(e),()=>c.delete(e))}),[])},V_=Symbol(`tap.Context`),H_=e=>({[V_]:e}),U_=(e,t,n)=>{let r=e[V_];e[V_]=t;try{return n()}finally{e[V_]=r}},W_=e=>e[V_],G_=Xg(()=>{let[e,t]=h_(()=>({renderers:{},fallbacks:[]}));return{getState:()=>e,setDataUI:C_((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:C_(e=>(t(t=>({...t,fallbacks:[...t.fallbacks,e]})),()=>{t(t=>({...t,fallbacks:t.fallbacks.filter(t=>t!==e)}))}),[])}}),K_=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},{}),q_=class{_providers=new Set;getModelContext(){return K_(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)}},J_=[],Y_={modelName:void 0,toolNames:J_},X_=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]),Z_=(e,t)=>{let n=e.getModelContext(),r=n.config?.modelName,i=n.tools?Object.keys(n.tools).sort():J_,a=i.length?i:J_;return r===t.modelName&&X_(a,t.toolNames)?t:{modelName:r,toolNames:a}},Q_=Xg(()=>{let e=S_(()=>new q_,[]),[t,n]=h_(()=>Z_(e,Y_));return v_(()=>(n(t=>Z_(e,t)),e.subscribe(()=>{n(t=>Z_(e,t))})),[e]),{getState:()=>Z_(e,t),getModelContext:()=>e.getModelContext(),subscribe:t=>e.subscribe(t),register:t=>e.registerModelContextProvider(t)}}),$_=e=>e.display===void 0?e.type===`human`:e.display===`standalone`,ev=Symbol(`assistant-ui.store.clientIndex`),tv=e=>e[ev],nv=H_([]),rv=()=>W_(nv),iv=(e,t)=>{let n=rv();return U_(nv,S_(()=>[...n,e],[n,e]),t)},av=new Set([`$$typeof`,`nodeType`,`then`]),ov=(e,t)=>{if(e===Symbol.toStringTag)return t;if(typeof e!=`symbol`){if(e===`toJSON`)return()=>t;if(!av.has(e))return!1}},sv=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}},cv=e=>{let t=Xg(e);return e=>{let n=t(e);return e.key===void 0?n:Zg(e.key,n)}},lv=Symbol(`assistant-ui.store.getValue`),uv=e=>{let t=e[lv];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?.()},dv=new Map;function fv(e){let t=dv.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[lv];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)},dv.set(e,t)),t}var pv=class extends sv{outputRef;index;boundFns;cachedReceiver;constructor(e,t){super(),this.outputRef=e,this.index=t}get(e,t,n){if(t===lv)return this.outputRef.current;if(t===ev)return this.index;let r=ov(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=fv(t).bind(n),this.boundFns.set(t,e)),e}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,t){return t===lv||t===ev?!0:t in this.outputRef.current}},mv=cv(e=>{let t=y_(null),n=rv().length,r=S_(()=>new Proxy({},new pv(t,n)),[n]),i=iv(r,()=>j_(e));return t.current||=i,v_(()=>{t.current=i}),{methods:r,state:i.getState?.(),key:e.key}}),hv=e=>j_(mv(e)),gv=Symbol(`assistant-ui.store.proxiedAssistantState`),_v=e=>e===`on`||e===`subscribe`||typeof e==`symbol`,vv=e=>{class t extends sv{get(t,n){let r=ov(n,`AssistantState`);if(r!==!1)return r;let i=n;if(!_v(i))return uv(e[i]())}ownKeys(){return Object.keys(e).filter(e=>!_v(e))}has(t,n){return!_v(n)&&n in e}}return new Proxy({},new t)},yv=e=>e[gv],bv=()=>()=>{},xv=e=>{let t=(()=>{throw Error(e)});return t.source=null,t.query=null,t},Sv=new Proxy({},new class extends sv{get(e,t){if(t===`subscribe`||t===`on`)return bv;if(t===gv)return Cv;let n=ov(t,`DefaultAssistantClient`);return n===!1?xv(`You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.`):n}ownKeys(){return[`subscribe`,`on`,gv]}has(e,t){return t===`subscribe`||t===`on`||t===gv}}),Cv=vv(Sv),wv=()=>new Proxy({},{get(e,t){let n=ov(t,`AssistantClient`);return n===!1?xv(`The current scope does not have a "${String(t)}" property.`):n}}),Tv=(0,T.createContext)(Sv),Ev=()=>(0,T.useContext)(Tv),Dv=({value:e,children:t})=>(0,K.jsx)(Tv.Provider,{value:e,children:t}),Ov=Xg(e=>null),kv=Symbol(`assistant-ui.transform-scopes`);function Av(e,t){let n=e;if(n[kv])throw Error(`transformScopes is already attached to this resource`);n[kv]=t}function jv(e){return e[kv]}var Mv=e=>typeof e==`string`?{scope:e.split(`.`)[0],event:e}:{scope:e.scope,event:e.event},Nv=H_(null),Pv=(e,t)=>U_(Nv,e,t),Fv=()=>{let e=W_(Nv);if(!e)throw Error(`AssistantTapContext is not available`);return e},Iv=()=>Fv().clientRef,Lv=()=>{let{emit:e}=Fv(),t=rv();return w_((n,r)=>{e(n,r,t)})};function Rv(e,t){let n={...e},r=new Set,i=!0;for(;i;){i=!1;for(let e of Object.values(n)){if(e.type===Ov||r.has(e.type))continue;r.add(e.type);let a=jv(e.type);if(a){a(n,t),i=!0;break}}}let a={},o={};for(let[e,t]of Object.entries(n))t.type===Ov?o[e]=t:a[e]=t;return{rootClients:a,derivedClients:o}}var zv=e=>S_(()=>e,[...Object.entries(e).flat()]),Bv=(e,t)=>{let{rootClients:n,derivedClients:r}=Rv(e,t);return{rootClients:zv(n),derivedClients:zv(r)}},Vv=Xg(()=>b_(()=>{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)}}}},[])),Hv=()=>{if(!Qg)return null;let e=(0,T.useRef)(0),t=e.current===0;return(0,T.useState)(()=>e.current++),e.current===2?t?`child`:`root`:null};function Uv(e){let t=(0,T.useMemo)(()=>r_(e=>r(e)),[]),[n,r]=(0,T.useReducer)((e,n)=>(a_(t,e),e+ +!!n()),0);a_(t,n);let i=Hv(),a=(0,T.useMemo)(()=>(e.key,D_(e.type,t,void 0,i)),[e.type,e.key,t,i]),o=k_(a,e.props);return(0,T.useLayoutEffect)(()=>()=>O_(a),[a]),(0,T.useLayoutEffect)(()=>{i_(t),A_(a,o)}),o.output}var Wv=e=>S_(()=>e,e),Gv=Xg(({element:e,emit:t,clientRef:n})=>{let{methods:r,state:i}=Pv({clientRef:n,emit:t},()=>hv(e));return S_(()=>({state:i,methods:r}),[r,i])}),Kv=Xg(({element:e,notifications:t,clientRef:n,name:r})=>{let i=B_(Gv({element:e,emit:t.emit,clientRef:n}));return v_(()=>i.subscribe(t.notifySubscribers),[i,t]),S_(()=>{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])}),qv=Xg(()=>S_(()=>({clients:[],subscribe:void 0,on:void 0}),[])),Jv=Xg(({clients:e,clientRef:t})=>{let n=j_(Vv());v_(()=>t.parent.subscribe(n.notifySubscribers),[t,n]);let r=Wv(M_(()=>Object.keys(e).map(r=>Zg(r,Kv({element:e[r],notifications:n,clientRef:t,name:r}))),[e,n,t]));return S_(()=>({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}=Mv(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[tv(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])}),Yv=Xg(({element:e,clientRef:t,name:n})=>{let r=y_(e.props);return r.current=e.props,S_(()=>{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])}),Xv=(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}`},Zv=Xg(({clients:e,clientRef:t})=>Wv(M_(()=>Object.keys(e).map(n=>{let r=n,i=e[r];return Zg(Xv(r,i.props),Yv({element:i,clientRef:t,name:r}))}),[e,t]))),Qv=Xg(({parent:e,clients:t})=>{let{rootClients:n,derivedClients:r}=Bv(t,e),i=y_({parent:e,current:null}).current;v_(()=>{i.current=s});let a=j_(Object.keys(n).length>0?Jv({clients:n,clientRef:i}):qv()),o=j_(Zv({clients:r,clientRef:i})),s=S_(()=>{let t=e===Sv?wv():e,n=Object.create(t);Object.assign(n,{subscribe:a.subscribe??e.subscribe,on:a.on??e.on,[gv]:vv(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 $v(e,{parent:t}={parent:Ev()}){if(e)return Uv(Qv({parent:t??Sv,clients:e}));if(t===null)throw Error(`received null parent, this usage is not allowed`);return t}var Z=e=>{let t=$v(),n=yv(t),r=(0,T.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,T.useDebugValue)(r),r},ey=({children:e,condition:t})=>Z(t)?e:null;ey.displayName=`AuiIf`;var ty=e=>{let t=$v(),n=(0,T.useRef)(!1),r=n.current?null:e(t);return Z(()=>n.current?e(t):r),()=>(n.current=!0,e(t))},ny=Object.freeze({});function ry({getItemState:e,children:t}){return iy(t(ty(e)))}var iy=e=>{let t=typeof e==`object`&&e&&`type`in e?e:null,n=t?.type,r=t?.key;return(0,T.useMemo)(()=>t,[n,r,typeof t?.props==`object`&&t.props!=null&&Object.entries(t.props).length===0?ny:t?.props])??e},ay=T.createContext(!0);function oy(){throw Error(`A function wrapped in useEffectEvent can't be called during rendering.`)}var sy=`use`in T.default?()=>{try{return T.use(ay)}catch{return!1}}:()=>!1;function cy(e){let t=T.useRef(oy);return T.useInsertionEffect(()=>{t.current=e},[e]),(...e)=>{sy()&&oy();let n=t.current;return n(...e)}}var ly=(e,t)=>{let n=$v(),r=cy(t),{scope:i,event:a}=Mv(e);(0,T.useEffect)(()=>n.on({scope:i,event:a},r),[n,i,a])},uy=cv(e=>{if(e.key===void 0)throw Error(`tapClientResource: Element has no key`);return j_(mv(e))});function dy(e,t){let n=M_(()=>e().map(e=>uy(e)),t),r=S_(()=>Object.keys(n),[n]),i=S_(()=>n.reduce((e,t,n)=>(e[t.key]=n,e),{}),[n]);return{state:S_(()=>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 fy=Xg(({toolkit:e,mcpApp:t})=>{let n=M_(()=>t?[Zg(`mcpApp`,t)]:[],[t])[0],[r,i]=h_(()=>({})),a=S_(()=>({toolUIs:r,mcpApp:n,tools:Object.fromEntries(Object.entries(r).map(([e,t])=>[e,t.map(e=>e.render)]))}),[r,n]),o=Iv(),s=C_((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 v_(()=>{if(!e)return;let t=[];for(let[n,r]of Object.entries(e))r.render&&t.push(s(n,r.render,{standalone:$_(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}});Av(fy,(e,t)=>{!e.modelContext&&t.modelContext.source===null&&(e.modelContext=Q_())});var py=e=>{let[,t]=h_(e.getState);return v_(()=>(t(e.getState()),e.subscribe(()=>{t(e.getState())})),[e]),e.getState()},my=Xg(({runtime:e})=>{let t=py(e);return{getState:()=>t,remove:e.remove,__internal_getRuntime:()=>e}}),hy=Xg(({runtime:e,index:t})=>j_(my({runtime:S_(()=>e.getAttachmentByIndex(t),[e,t])}))),gy=Xg(({threadIdRef:e,messageIdRef:t,runtime:n})=>{let r=py(n),i=Lv();v_(()=>{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=dy(()=>r.attachments.map((e,t)=>Zg(e.id,hy({runtime:n,index:t}))),[r.attachments,n]),o=S_(()=>({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}}),_y=Xg(({runtime:e})=>{let t=py(e);return{getState:()=>t,addToolResult:t=>e.addToolResult(t),resumeToolCall:t=>e.resumeToolCall(t),respondToToolApproval:t=>e.respondToToolApproval(t),__internal_getRuntime:()=>e}}),vy=Xg(({runtime:e,index:t})=>j_(my({runtime:S_(()=>e.getAttachmentByIndex(t),[e,t])}))),yy=Xg(({runtime:e,index:t})=>j_(_y({runtime:S_(()=>e.getMessagePartByIndex(t),[e,t])}))),by=Xg(({runtime:e,threadIdRef:t})=>{let n=py(e),[r,i]=h_(!1),[a,o]=h_(!1),s=S_(()=>({get current(){return e.getState().id}}),[e]),c=hv(gy({runtime:e.composer,threadIdRef:t,messageIdRef:s})),l=dy(()=>n.content.map((t,n)=>Zg(`toolCallId`in t&&t.toolCallId!=null?`toolCallId-${t.toolCallId}`:`index-${n}`,yy({runtime:e,index:n}))),[n.content,e]),u=dy(()=>(n.attachments??[]).map((t,n)=>Zg(t.id,vy({runtime:e,index:n}))),[n.attachments,e]),d=S_(()=>({...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}}),xy=Xg(({runtime:e,id:t,threadIdRef:n})=>j_(by({runtime:S_(()=>e.getMessageById(t),[e,t]),threadIdRef:n}))),Sy=Xg(({runtime:e})=>{let t=py(e),n=Lv();v_(()=>{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=S_(()=>({get current(){return e.getState().threadId}}),[e]),i=hv(gy({runtime:e.composer,threadIdRef:r})),a=dy(()=>t.messages.map(t=>Zg(t.id,xy({runtime:e,id:t.id,threadIdRef:r}))),[t.messages,e,r]),o=S_(()=>({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}}),Cy=Xg(({runtime:e})=>{let t=py(e),n=Lv();return v_(()=>{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}}),wy=Xg(({runtime:e,id:t})=>j_(Cy({runtime:S_(()=>e.getItemById(t),[e,t])}))),Ty=Xg(({runtime:e,__internal_assistantRuntime:t})=>{let n=py(e),r=hv(Sy({runtime:e.main})),i=dy(()=>Object.keys(n.threadItems).map(t=>Zg(t,wy({runtime:e,id:t}))),[n.threadItems,e]),a=S_(()=>({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}}),Ey=Xg(e=>({getState:()=>e})),Dy=Xg(e=>{let[t]=h_(()=>({suggestions:(e??[]).map(e=>typeof e==`string`?{title:e,label:``,prompt:e}:{title:e.title,label:e.label,prompt:e.prompt})})),n=dy(()=>t.suggestions.map((e,t)=>Zg(t,Ey(e))),[t.suggestions]);return{getState:()=>t,suggestion:({index:e})=>n.get({index:e})}}),Oy=Xg(e=>{let t=Iv();return v_(()=>e.registerModelContextProvider(t.current.modelContext()),[e,t]),j_(Ty({runtime:e.threads,__internal_assistantRuntime:e}))}),ky=(e,t)=>{e.thread??=Ov({source:`threads`,query:{type:`main`},get:e=>e.threads().thread(`main`)}),e.threadListItem??=Ov({source:`threads`,query:{type:`main`},get:e=>e.threads().item(`main`)}),e.composer??=Ov({source:`thread`,query:{},get:e=>e.threads().thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=Q_()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=Dy())},Ay=Xg(e=>j_(Oy(e)));Av(Ay,(e,t)=>{ky(e,t),!e.tools&&t.tools.source===null&&(e.tools=fy({})),!e.dataRenderers&&t.dataRenderers.source===null&&(e.dataRenderers=G_())});var jy=e=>e._core?.RenderComponent,My=(0,T.memo)(({runtime:e,aui:t=null,children:n})=>{let r=$v({threads:Ay(e)},{parent:t}),i=jy(e);return(0,K.jsxs)(Dv,{value:r,children:[i&&(0,K.jsx)(i,{}),n]})}),Ny=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},Py=(e=>e?Ny(e):Ny),Fy=e=>e;function Iy(e,t=Fy){let n=T.useSyncExternalStore(e.subscribe,T.useCallback(()=>t(e.getState()),[e,t]),T.useCallback(()=>t(e.getInitialState()),[e,t]));return T.useDebugValue(n),n}var Ly=e=>{let t=Py(e),n=e=>Iy(t,e);return Object.assign(n,t),n},Ry=(e=>e?Ly(e):Ly),zy=()=>{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}},By=()=>{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=zy(),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()}}))}}},Vy=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())}},Hy=e=>new ReadableStream({start(t){return e.start?.(new Vy(t))},pull(t){return e.pull?.(new Vy(t))},cancel(t){return e.cancel?.(t)}}),Uy=()=>{let e;return[Hy({start(t){e=t}}),e]},Wy=class{_controller;_isClosed=!1;_mergeTask;constructor(e){this._controller=e;let t=Hy({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())}},Gy=e=>new ReadableStream({start(t){return e.start?.(new Wy(t))},pull(t){return e.pull?.(new Wy(t))},cancel(t){return e.cancel?.(t)}}),Ky=()=>{let e;return[Gy({start(t){e=t}}),e]},qy=class{value=-1;up(){return++this.value}},Jy=class extends TransformStream{constructor(e){super({transform(t,n){n.enqueue({...t,path:[e,...t.path]})}})}};TransformStream;var Yy=class extends TransformStream{constructor(e){let t=new qy,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]})}})}},Xy=class extends TransformStream{constructor(e){super();let t=e(super.readable);Object.defineProperty(this,"readable",{value:t,writable:!1})}},Zy=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)}})}},Qy=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},$y=Qy(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),eb=class e{_state;_parentId;constructor(e){this._state=e||{merger:By(),contentCounter:new qy}}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 Jy(this._state.contentCounter.value)))}merge(e){this._state.merger.addStream(e.pipeThrough(new Yy(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]=Uy();return this._addPart(this._withParentIdOption({type:`text`}),e),t}addReasoningPart(){let[e,t]=Uy();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??$y(),[i,a]=Ky();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 tb(e){let t=new eb;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 nb(){let{resolve:e,promise:t}=zy(),n;return[tb(r=>(n=r,n.__internal_subscribeToClose(e),t)),n]}function rb(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 ib=l(o(((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),ab=Symbol(`aui.parse-partial-json-object.meta`),ob=e=>e?.[ab],sb=e=>{if(e.length===0)return{[ab]:{state:`partial`,partialPath:[]}};try{let t=ib.default.parse(e);if(typeof t!=`object`||!t)throw Error(`argsText is expected to be an object`);return t[ab]={state:`complete`,partialPath:[]},t}catch{try{let[t,n]=rb(e),r=ib.default.parse(t);if(typeof r!=`object`||!r)throw Error(`argsText is expected to be an object`);return r[ab]={state:`partial`,partialPath:n},r}catch{return}}},cb=(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 cb(s,{state:`partial`,partialPath:o},i)},lb=(e,t)=>{let n=ob(e);if(!n)throw Error(`unable to determine object state`);return cb(e,n,t.map(String))};async function*ub(){let e=this.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)break;yield n}}finally{e.releaseLock()}}function db(e){return e[Symbol.asyncIterator]??=ub,e}var fb=Symbol.for(`aui.tool-response`),pb=class e{get[fb](){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&&fb in e}static toResponse(t){return t instanceof e?t:new e({result:t===void 0?`<no result>`:t})}};function mb(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 hb(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}var gb=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(lb(e,this.fieldPath)===`complete`){let t=hb(e,this.fieldPath);t!==void 0&&(this.resolve(t),this.dispose())}}catch(e){this.reject(e),this.dispose()}}dispose(){this.disposed=!0}},_b=class{controller;disposed=!1;fieldPath;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=hb(e,this.fieldPath);t!==void 0&&this.controller.enqueue(t),lb(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},vb=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=hb(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)}lb(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},yb=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=hb(e,this.fieldPath);if(!Array.isArray(t))return;for(let n=0;n<t.length;n++)this.processedIndexes.has(n)||lb(e,[...this.fieldPath,n])===`complete`&&(this.controller.enqueue(t[n]),this.processedIndexes.add(n));lb(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},bb=class{argTextDeltas;handles=new Set;args=sb(``);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=sb(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 gb(t,n,e);if(this.args&&lb(this.args,e)===`complete`){let n=hb(this.args,e);if(n!==void 0){t(n);return}}this.handles.add(r),r.update(this.args)})}streamValues(...e){let t=e;return db(new ReadableStream({start:e=>{let n=new _b(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof _b){e.dispose(),this.handles.delete(e);break}}}))}streamText(...e){let t=e;return db(new ReadableStream({start:e=>{let n=new vb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof vb){e.dispose(),this.handles.delete(e);break}}}))}forEach(...e){let t=e;return db(new ReadableStream({start:e=>{let n=new yb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof yb){e.dispose(),this.handles.delete(e);break}}}))}},xb=class{promise;constructor(e){this.promise=e}get(){return this.promise}},Sb=class{args;response;writable;resolve;argsText=``;constructor(){let e=new TransformStream;this.writable=e.writable,this.args=new bb(e.readable);let{promise:t,resolve:n}=zy();this.resolve=n,this.response=new xb(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}},Cb=class extends Xy{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 Sb;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 pb({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=mb(()=>{let t;try{t=ib.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 pb({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 pb({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 Zy).pipeThrough(i)})}},wb=e=>typeof e==`object`&&!!e&&`~standard`in e&&e[`~standard`].version===1;function Tb(e,t,n,r){let i=e?.[n.toolName];return i?.execute?(async e=>{if(t.aborted)return new pb({result:`Tool execution was cancelled.`,isError:!0});let a=e;if(wb(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 pb({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=pb.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 pb({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 Eb(e,t,n,r,i){e?.[r.toolName]?.streamCall?.(n,{toolCallId:r.toolCallId,abortSignal:t,human:e=>i(r.toolCallId,e)})}function Db(e,t,n,r){let i=typeof e==`function`?e:()=>e,a=typeof t==`function`?t:()=>t;return new Cb({execute:e=>Tb(i(),a(),e,n),streamCall:({reader:e,...t})=>Eb(i(),a(),e,t,n),onExecutionStart:r?.onExecutionStart,onExecutionEnd:r?.onExecutionEnd})}var Ob=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({attachment:Ov({source:`message`,query:{type:`index`,index:e},get:t=>t.message().attachment({index:e})})}),children:t}),kb=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({attachment:Ov({source:`composer`,query:{type:`index`,index:e},get:t=>t.composer().attachment({index:e})})}),children:t}),Ab=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({message:Ov({source:`thread`,query:{type:`index`,index:e},get:t=>t.thread().message({index:e})}),composer:Ov({source:`message`,query:{},get:t=>t.thread().message({index:e}).composer()})}),children:t}),jb=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({part:Ov({source:`message`,query:{type:`index`,index:e},get:t=>t.message().part({index:e})})}),children:t}),Mb=Xg(({text:e,isRunning:t})=>{let n=S_(()=>({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`)}}}),Nb=({text:e,isRunning:t=!1,children:n})=>(0,K.jsx)(Dv,{value:$v({part:Mb({text:e,isRunning:t})}),children:n}),Pb=Object.freeze({type:`complete`}),Fb=Xg(({parts:e,getMessagePart:t})=>{let[n,r]=h_(!0),i=S_(()=>e[e.length-1]?.status??Pb,[e]),a=S_(()=>({parts:e,collapsed:n,status:i}),[e,n,i]);return{getState:()=>a,setCollapsed:r,part:t}}),Ib=({startIndex:e,endIndex:t,children:n})=>{let r=Z(e=>e.message.parts).slice(e,t+1),i=$v();return(0,K.jsx)(Dv,{value:$v({chainOfThought:Fb({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})},Lb=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({suggestion:Ov({source:`suggestions`,query:{index:e},get:t=>t.suggestions().suggestion({index:e})})}),children:t}),Rb=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({queueItem:Ov({source:`composer`,query:{index:e},get:t=>t.composer().queueItem({index:e})})}),children:t}),zb=Symbol(`innerMessage`),Bb=Symbol(`innerMessages`),Vb=[],Hb=(e,t)=>{zb in e||(e[zb]=t)},Ub=e=>{let t=`messages`in e?e.messages:e,n=t[Bb]||t[zb];return n?Array.isArray(n)?n:(t[Bb]=[n],t[Bb]):Vb},Wb=Symbol(`skip-update`);function Gb(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 Kb=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)}}},qb=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()}}},Jb=class extends qb{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e;let t=e.getState();if(t===Wb)throw Error(`Entry not available in the store`);this._previousState=t}_previousState;getState=()=>(this.isConnected||this._syncState(),this._previousState);_syncState(){let e=this.binding.getState();return e===Wb||Gb(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){return this.binding.subscribe(()=>{this._syncState()&&this.notifySubscribers()})}},Yb=class extends qb{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}_previousStateDirty=!0;_previousState;getState=()=>{if(!this.isConnected||this._previousStateDirty){let e=this.binding.getState();e!==Wb&&(this._previousState=e),this._previousStateDirty=!1}if(this._previousState===void 0)throw Error(`Entry not available in the store`);return this._previousState};_connect(){return this.binding.subscribe(()=>{this._previousStateDirty=!0,this.notifySubscribers()})}},Xb=class extends qb{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?.()}}},Zb=class extends qb{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?.()}}},Qb=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)}},$b=class extends Qb{_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)}},ex=class extends $b{get source(){return`thread-composer`}},tx=class extends $b{get source(){return`edit-composer`}},nx=class extends Qb{get source(){return`message`}remove(){throw Error(`Message attachments cannot be removed`)}},rx=Object.freeze([]),ix=Object.freeze({}),ax=e=>Object.freeze({type:`thread`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,attachments:e?.attachments??rx,text:e?.text??``,role:e?.role??`user`,runConfig:e?.runConfig??ix,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,value:e?.text??``}),ox=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??rx,runConfig:e?.runConfig??ix,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,parentId:e?.parentId??null,sourceId:e?.sourceId??null,value:e?.text??``}),sx=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 Zb({event:e,binding:this._core}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},cx=class extends sx{get path(){return this._core.path}get type(){return`thread`}_getState;constructor(e){let t=new Yb({path:e.path,getState:()=>ax(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 ex(new Jb({path:{...this.path,attachmentSource:`thread-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`thread-composer`}:Wb},subscribe:e=>this._core.subscribe(e)}),this._core)}},lx=class extends sx{_beginEdit;get path(){return this._core.path}get type(){return`edit`}_getState;constructor(e,t){let n=new Yb({path:e.path,getState:()=>ox(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 tx(new Jb({path:{...this.path,attachmentSource:`edit-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`edit-composer`}:Wb},subscribe:e=>this._core.subscribe(e)}),this._core)}},ux=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 T.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},uc=`DialogDescriptionWarning`,dc=({contentRef:e,descriptionId:t})=>{let n=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${cc(uc).contentName}}.`;return T.useEffect(()=>{let r=e.current?.getAttribute(`aria-describedby`);t&&r&&(document.getElementById(t)||console.warn(n))},[n,e,t]),null},fc=Ls,pc=Us,mc=Gs,hc=Ys,gc=ec,_c=nc,vc=ic;function yc(e){let[t,n]=T.useState(void 0);return aa(()=>{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 bc=[`top`,`right`,`bottom`,`left`],xc=Math.min,Sc=Math.max,Cc=Math.round,wc=Math.floor,Tc=e=>({x:e,y:e}),Ec={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Dc(e,t,n){return Sc(e,xc(t,n))}function Oc(e,t){return typeof e==`function`?e(t):e}function kc(e){return e.split(`-`)[0]}function Ac(e){return e.split(`-`)[1]}function jc(e){return e===`x`?`y`:`x`}function Mc(e){return e===`y`?`height`:`width`}function Nc(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function Pc(e){return jc(Nc(e))}function Fc(e,t,n){n===void 0&&(n=!1);let r=Ac(e),i=Pc(e),a=Mc(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Wc(o)),[o,Wc(o)]}function Ic(e){let t=Wc(e);return[Lc(e),t,Lc(t)]}function Lc(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var Rc=[`left`,`right`],zc=[`right`,`left`],Bc=[`top`,`bottom`],Vc=[`bottom`,`top`];function Hc(e,t,n){switch(e){case`top`:case`bottom`:return n?t?zc:Rc:t?Rc:zc;case`left`:case`right`:return t?Bc:Vc;default:return[]}}function Uc(e,t,n,r){let i=Ac(e),a=Hc(kc(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(Lc)))),a}function Wc(e){let t=kc(e);return Ec[t]+e.slice(t.length)}function Gc(e){return{top:0,right:0,bottom:0,left:0,...e}}function Kc(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Gc(e)}function qc(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 Jc(e,t,n){let{reference:r,floating:i}=e,a=Nc(t),o=Pc(t),s=Mc(o),c=kc(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(Ac(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 Yc(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}=Oc(t,e),p=Kc(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=qc(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=qc(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 Xc=50,Zc=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:Yc},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Jc(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<Xc&&(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}=Jc(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:m}},Qc=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}=Oc(e,t)||{};if(l==null)return{};let d=Kc(u),f={x:n,y:r},p=Pc(i),m=Mc(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=xc(d[_],T),D=xc(d[v],T),O=E,k=C-h[m]-D,A=C/2-h[m]/2+w,j=Dc(O,A,k),M=!c.arrow&&Ac(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}}}),$c=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}=Oc(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=kc(r),_=Nc(o),v=kc(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Wc(o)]:Ic(o)),x=p!==`none`;!d&&x&&b.push(...Uc(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=Fc(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`&&_!==Nc(t))||T.every(e=>Nc(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=Nc(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 el(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function tl(e){return bc.some(t=>e[t]>=0)}var nl=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=Oc(e,t);switch(i){case`referenceHidden`:{let e=el(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:tl(e)}}}case`escaped`:{let e=el(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:tl(e)}}}default:return{}}}}},rl=new Set([`left`,`top`]);async function il(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=kc(n),s=Ac(n),c=Nc(n)===`y`,l=rl.has(o)?-1:1,u=a&&c?-1:1,d=Oc(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 al=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 il(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}}}}},ol=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}=Oc(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Nc(kc(i)),p=jc(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=Dc(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=Dc(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}}}}}},sl=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}=Oc(e,t),u={x:n,y:r},d=Nc(i),f=jc(d),p=u[f],m=u[d],h=Oc(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=rl.has(kc(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}}}},cl=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}=Oc(e,t),u=await o.detectOverflow(t,l),d=kc(i),f=Ac(i),p=Nc(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=xc(h-u[g],v),x=xc(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=Sc(u.left,0),t=Sc(u.right,0),n=Sc(u.top,0),r=Sc(u.bottom,0);p?w=m-2*(e!==0||t!==0?e+t:Sc(u.left,u.right)):C=h-2*(n!==0||r!==0?n+r:Sc(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 ll(){return typeof window<`u`}function ul(e){return pl(e)?(e.nodeName||``).toLowerCase():`#document`}function dl(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function fl(e){return((pl(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function pl(e){return ll()?e instanceof Node||e instanceof dl(e).Node:!1}function ml(e){return ll()?e instanceof Element||e instanceof dl(e).Element:!1}function hl(e){return ll()?e instanceof HTMLElement||e instanceof dl(e).HTMLElement:!1}function gl(e){return!ll()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof dl(e).ShadowRoot}function _l(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=Ol(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function vl(e){return/^(table|td|th)$/.test(ul(e))}function yl(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var bl=/transform|translate|scale|rotate|perspective|filter/,xl=/paint|layout|strict|content/,Sl=e=>!!e&&e!==`none`,Cl;function wl(e){let t=ml(e)?Ol(e):e;return Sl(t.transform)||Sl(t.translate)||Sl(t.scale)||Sl(t.rotate)||Sl(t.perspective)||!El()&&(Sl(t.backdropFilter)||Sl(t.filter))||bl.test(t.willChange||``)||xl.test(t.contain||``)}function Tl(e){let t=Al(e);for(;hl(t)&&!Dl(t);){if(wl(t))return t;if(yl(t))return null;t=Al(t)}return null}function El(){return Cl??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Cl}function Dl(e){return/^(html|body|#document)$/.test(ul(e))}function Ol(e){return dl(e).getComputedStyle(e)}function kl(e){return ml(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Al(e){if(ul(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||gl(e)&&e.host||fl(e);return gl(t)?t.host:t}function jl(e){let t=Al(e);return Dl(t)?e.ownerDocument?e.ownerDocument.body:e.body:hl(t)&&_l(t)?t:jl(t)}function Ml(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=jl(e),i=r===e.ownerDocument?.body,a=dl(r);if(i){let e=Nl(a);return t.concat(a,a.visualViewport||[],_l(r)?r:[],e&&n?Ml(e):[])}else return t.concat(r,Ml(r,[],n))}function Nl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Pl(e){let t=Ol(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=hl(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Cc(n)!==a||Cc(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function Fl(e){return ml(e)?e:e.contextElement}function Il(e){let t=Fl(e);if(!hl(t))return Tc(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Pl(t),o=(a?Cc(n.width):n.width)/r,s=(a?Cc(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var Ll=Tc(0);function Rl(e){let t=dl(e);return!El()||!t.visualViewport?Ll:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function zl(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==dl(e)?!1:t}function Bl(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=Fl(e),o=Tc(1);t&&(r?ml(r)&&(o=Il(r)):o=Il(e));let s=zl(a,n,r)?Rl(a):Tc(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=dl(a),t=r&&ml(r)?dl(r):r,n=e,i=Nl(n);for(;i&&r&&t!==n;){let e=Il(i),t=i.getBoundingClientRect(),r=Ol(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=dl(i),i=Nl(n)}}return qc({width:u,height:d,x:c,y:l})}function Vl(e,t){let n=kl(e).scrollLeft;return t?t.left+n:Bl(fl(e)).left+n}function Hl(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Vl(e,n),y:n.top+t.scrollTop}}function Ul(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=fl(r),s=t?yl(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Tc(1),u=Tc(0),d=hl(r);if((d||!d&&!a)&&((ul(r)!==`body`||_l(o))&&(c=kl(r)),d)){let e=Bl(r);l=Il(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?Hl(o,c):Tc(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 Wl(e){return Array.from(e.getClientRects())}function Gl(e){let t=fl(e),n=kl(e),r=e.ownerDocument.body,i=Sc(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=Sc(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+Vl(e),s=-n.scrollTop;return Ol(r).direction===`rtl`&&(o+=Sc(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}var Kl=25;function ql(e,t){let n=dl(e),r=fl(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=El();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=Vl(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<=Kl&&(a-=o)}else l<=Kl&&(a+=l);return{width:a,height:o,x:s,y:c}}function Jl(e,t){let n=Bl(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=hl(e)?Il(e):Tc(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function Yl(e,t,n){let r;if(t===`viewport`)r=ql(e,n);else if(t===`document`)r=Gl(fl(e));else if(ml(t))r=Jl(t,n);else{let n=Rl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return qc(r)}function Xl(e,t){let n=Al(e);return n===t||!ml(n)||Dl(n)?!1:Ol(n).position===`fixed`||Xl(n,t)}function Zl(e,t){let n=t.get(e);if(n)return n;let r=Ml(e,[],!1).filter(e=>ml(e)&&ul(e)!==`body`),i=null,a=Ol(e).position===`fixed`,o=a?Al(e):e;for(;ml(o)&&!Dl(o);){let t=Ol(o),n=wl(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&(i.position===`absolute`||i.position===`fixed`)||_l(o)&&!n&&Xl(e,o))?r=r.filter(e=>e!==o):i=t,o=Al(o)}return t.set(e,r),r}function Ql(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?yl(t)?[]:Zl(t,this._c):[].concat(n),r],o=Yl(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=Yl(t,a[e],i);s=Sc(n.top,s),c=xc(n.right,c),l=xc(n.bottom,l),u=Sc(n.left,u)}return{width:c-u,height:l-s,x:u,y:s}}function $l(e){let{width:t,height:n}=Pl(e);return{width:t,height:n}}function eu(e,t,n){let r=hl(t),i=fl(t),a=n===`fixed`,o=Bl(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=Tc(0);function l(){c.x=Vl(i)}if(r||!r&&!a)if((ul(t)!==`body`||_l(i))&&(s=kl(t)),r){let e=Bl(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?Hl(i,s):Tc(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 tu(e){return Ol(e).position===`static`}function nu(e,t){if(!hl(e)||Ol(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return fl(e)===n&&(n=n.ownerDocument.body),n}function ru(e,t){let n=dl(e);if(yl(e))return n;if(!hl(e)){let t=Al(e);for(;t&&!Dl(t);){if(ml(t)&&!tu(t))return t;t=Al(t)}return n}let r=nu(e,t);for(;r&&vl(r)&&tu(r);)r=nu(r,t);return r&&Dl(r)&&tu(r)&&!wl(r)?n:r||Tl(e)||n}var iu=async function(e){let t=this.getOffsetParent||ru,n=this.getDimensions,r=await n(e.floating);return{reference:eu(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function au(e){return Ol(e).direction===`rtl`}var ou={convertOffsetParentRelativeRectToViewportRelativeRect:Ul,getDocumentElement:fl,getClippingRect:Ql,getOffsetParent:ru,getElementRects:iu,getClientRects:Wl,getDimensions:$l,getScale:Il,isElement:ml,isRTL:au};function su(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function cu(e,t){let n=null,r,i=fl(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=wc(d),h=wc(i.clientWidth-(u+f)),g=wc(i.clientHeight-(d+p)),_=wc(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:Sc(0,xc(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&&!su(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 lu(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=Fl(e),u=i||a?[...l?Ml(l):[],...t?Ml(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?cu(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?Bl(e):null;c&&g();function g(){let t=Bl(e);h&&!su(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 uu=al,du=ol,fu=$c,pu=cl,mu=nl,hu=Qc,gu=sl,_u=(e,t,n)=>{let r=new Map,i={platform:ou,...n},a={...i.platform,_c:r};return Zc(e,t,{...i,platform:a})},vu=typeof document<`u`?T.useLayoutEffect:function(){};function yu(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(!yu(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)&&!yu(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function bu(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function xu(e,t){let n=bu(e);return Math.round(t*n)/n}function Su(e){let t=T.useRef(e);return vu(()=>{t.current=e}),t}function Cu(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]=T.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=T.useState(r);yu(f,r)||p(r);let[m,h]=T.useState(null),[g,_]=T.useState(null),v=T.useCallback(e=>{e!==S.current&&(S.current=e,h(e))},[]),y=T.useCallback(e=>{e!==C.current&&(C.current=e,_(e))},[]),b=a||m,x=o||g,S=T.useRef(null),C=T.useRef(null),w=T.useRef(u),E=c!=null,D=Su(c),O=Su(i),k=Su(l),A=T.useCallback(()=>{if(!S.current||!C.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),_u(S.current,C.current,e).then(e=>{let t={...e,isPositioned:k.current!==!1};j.current&&!yu(w.current,t)&&(w.current=t,yt.flushSync(()=>{d(t)}))})},[f,t,n,O,k]);vu(()=>{l===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let j=T.useRef(!1);vu(()=>(j.current=!0,()=>{j.current=!1}),[]),vu(()=>{if(b&&(S.current=b),x&&(C.current=x),b&&x){if(D.current)return D.current(b,x,A);A()}},[b,x,A,D,E]);let M=T.useMemo(()=>({reference:S,floating:C,setReference:v,setFloating:y}),[v,y]),N=T.useMemo(()=>({reference:b,floating:x}),[b,x]),P=T.useMemo(()=>{let e={position:n,left:0,top:0};if(!N.floating)return e;let t=xu(N.floating,u.x),r=xu(N.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...bu(N.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,N.floating,u.x,u.y]);return T.useMemo(()=>({...u,update:A,refs:M,elements:N,floatingStyles:P}),[u,A,M,N,P])}var wu=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?{}:hu({element:r.current,padding:i}).fn(n):r?hu({element:r,padding:i}).fn(n):{}}}},Tu=(e,t)=>{let n=uu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Eu=(e,t)=>{let n=du(e);return{name:n.name,fn:n.fn,options:[e,t]}},Du=(e,t)=>({fn:gu(e).fn,options:[e,t]}),Ou=(e,t)=>{let n=fu(e);return{name:n.name,fn:n.fn,options:[e,t]}},ku=(e,t)=>{let n=pu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Au=(e,t)=>{let n=mu(e);return{name:n.name,fn:n.fn,options:[e,t]}},ju=(e,t)=>{let n=wu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Mu=`Arrow`,Nu=T.forwardRef((e,t)=>{let{children:n,width:r=10,height:i=5,...a}=e;return(0,K.jsx)(Yi.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`})})});Nu.displayName=Mu;var Pu=Nu,Fu=`Popper`,[Iu,Lu]=na(Fu),[Ru,zu]=Iu(Fu),Bu=e=>{let{__scopePopper:t,children:n}=e,[r,i]=T.useState(null);return(0,K.jsx)(Ru,{scope:t,anchor:r,onAnchorChange:i,children:n})};Bu.displayName=Fu;var Vu=`PopperAnchor`,Hu=T.forwardRef((e,t)=>{let{__scopePopper:n,virtualRef:r,...i}=e,a=zu(Vu,n),o=T.useRef(null),s=Ri(t,o),c=T.useRef(null);return T.useEffect(()=>{let e=c.current;c.current=r?.current||o.current,e!==c.current&&a.onAnchorChange(c.current)}),r?null:(0,K.jsx)(Yi.div,{...i,ref:s})});Hu.displayName=Vu;var Uu=`PopperContent`,[Wu,Gu]=Iu(Uu),Ku=T.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=zu(Uu,n),[_,v]=T.useState(null),y=Ri(t,e=>v(e)),[b,x]=T.useState(null),S=yc(b),C=S?.width??0,w=S?.height??0,E=r+(a===`center`?``:`-`+a),D=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},O=Array.isArray(l)?l:[l],k=O.length>0,A={padding:D,boundary:O.filter(Xu),altBoundary:k},{refs:j,floatingStyles:M,placement:N,isPositioned:P,middlewareData:F}=Cu({strategy:`fixed`,placement:E,whileElementsMounted:(...e)=>lu(...e,{animationFrame:p===`always`}),elements:{reference:g.anchor},middleware:[Tu({mainAxis:i+w,alignmentAxis:o}),c&&Eu({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Du():void 0,...A}),c&&Ou({...A}),ku({...A,apply:({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)}}),b&&ju({element:b,padding:s}),Zu({arrowWidth:C,arrowHeight:w}),f&&Au({strategy:`referenceHidden`,...A})]}),[I,L]=Qu(N),R=ja(m);aa(()=>{P&&R?.()},[P,R]);let z=F.arrow?.x,B=F.arrow?.y,V=F.arrow?.centerOffset!==0,[H,U]=T.useState();return aa(()=>{_&&U(window.getComputedStyle(_).zIndex)},[_]),(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)(Wu,{scope:n,placedSide:I,onArrowChange:x,arrowX:z,arrowY:B,shouldHideArrow:V,children:(0,K.jsx)(Yi.div,{"data-side":I,"data-align":L,...h,ref:y,style:{...h.style,animation:P?void 0:`none`}})})})});Ku.displayName=Uu;var qu=`PopperArrow`,Ju={top:`bottom`,right:`left`,bottom:`top`,left:`right`},Yu=T.forwardRef(function(e,t){let{__scopePopper:n,...r}=e,i=Gu(qu,n),a=Ju[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)(Pu,{...r,ref:t,style:{...r.style,display:`block`}})})});Yu.displayName=qu;function Xu(e){return e!==null}var Zu=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]=Qu(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 Qu(e){let[t,n=`center`]=e.split(`-`);return[t,n]}var $u=Bu,ed=Hu,td=Ku,nd=Yu,rd=`Popover`,[id,ad]=na(rd,[Lu]),od=Lu(),[sd,cd]=id(rd),ld=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!1}=e,s=od(t),c=T.useRef(null),[l,u]=T.useState(!1),[d,f]=sa({prop:r,defaultProp:i??!1,onChange:a,caller:rd});return(0,K.jsx)($u,{...s,children:(0,K.jsx)(sd,{scope:t,contentId:_a(),triggerRef:c,open:d,onOpenChange:f,onOpenToggle:T.useCallback(()=>f(e=>!e),[f]),hasCustomAnchor:l,onCustomAnchorAdd:T.useCallback(()=>u(!0),[]),onCustomAnchorRemove:T.useCallback(()=>u(!1),[]),modal:o,children:n})})};ld.displayName=rd;var ud=`PopoverAnchor`,dd=T.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=cd(ud,n),a=od(n),{onCustomAnchorAdd:o,onCustomAnchorRemove:s}=i;return T.useEffect(()=>(o(),()=>s()),[o,s]),(0,K.jsx)(ed,{...a,...r,ref:t})});dd.displayName=ud;var fd=`PopoverTrigger`,pd=T.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=cd(fd,n),a=od(n),o=Ri(t,i.triggerRef),s=(0,K.jsx)(Yi.button,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Od(i.open),...r,ref:o,onClick:ia(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?s:(0,K.jsx)(ed,{asChild:!0,...a,children:s})});pd.displayName=fd;var md=`PopoverPortal`,[hd,gd]=id(md,{forceMount:void 0}),_d=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,a=cd(md,t);return(0,K.jsx)(hd,{scope:t,forceMount:n,children:(0,K.jsx)(da,{present:n||a.open,children:(0,K.jsx)(lo,{asChild:!0,container:i,children:r})})})};_d.displayName=md;var vd=`PopoverContent`,yd=T.forwardRef((e,t)=>{let n=gd(vd,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,a=cd(vd,e.__scopePopover);return(0,K.jsx)(da,{present:r||a.open,children:a.modal?(0,K.jsx)(xd,{...i,ref:t}):(0,K.jsx)(Sd,{...i,ref:t})})});yd.displayName=vd;var bd=Vi(`PopoverContent.RemoveScroll`),xd=T.forwardRef((e,t)=>{let n=cd(vd,e.__scopePopover),r=T.useRef(null),i=Ri(t,r),a=T.useRef(!1);return T.useEffect(()=>{let e=r.current;if(e)return js(e)},[]),(0,K.jsx)(Ss,{as:bd,allowPinchZoom:!0,children:(0,K.jsx)(Cd,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ia(e.onCloseAutoFocus,e=>{e.preventDefault(),a.current||n.triggerRef.current?.focus()}),onPointerDownOutside:ia(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;a.current=t.button===2||n},{checkForDefaultPrevented:!1}),onFocusOutside:ia(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),Sd=T.forwardRef((e,t)=>{let n=cd(vd,e.__scopePopover),r=T.useRef(!1),i=T.useRef(!1);return(0,K.jsx)(Cd,{...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()}})}),Cd=T.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=cd(vd,n),p=od(n);return fo(),(0,K.jsx)(Xa,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,K.jsx)(za,{asChild:!0,disableOutsidePointerEvents:o,onInteractOutside:u,onEscapeKeyDown:s,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1),children:(0,K.jsx)(td,{"data-state":Od(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)`}})})})}),wd=`PopoverClose`,Td=T.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=cd(wd,n);return(0,K.jsx)(Yi.button,{type:`button`,...r,ref:t,onClick:ia(e.onClick,()=>i.onOpenChange(!1))})});Td.displayName=wd;var Ed=`PopoverArrow`,Dd=T.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=od(n);return(0,K.jsx)(nd,{...i,...r,ref:t})});Dd.displayName=Ed;function Od(e){return e?`open`:`closed`}var kd=ld,Ad=pd,jd=_d,Md=yd,Nd=Td,[Pd,Fd]=na(`Tooltip`,[Lu]),Id=Lu(),Ld=`TooltipProvider`,Rd=700,zd=`tooltip.open`,[Bd,Vd]=Pd(Ld),Hd=e=>{let{__scopeTooltip:t,delayDuration:n=Rd,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,o=T.useRef(!0),s=T.useRef(!1),c=T.useRef(0);return T.useEffect(()=>{let e=c.current;return()=>window.clearTimeout(e)},[]),(0,K.jsx)(Bd,{scope:t,isOpenDelayedRef:o,delayDuration:n,onOpen:T.useCallback(()=>{window.clearTimeout(c.current),o.current=!1},[]),onClose:T.useCallback(()=>{window.clearTimeout(c.current),c.current=window.setTimeout(()=>o.current=!0,r)},[r]),isPointerInTransitRef:s,onPointerInTransitChange:T.useCallback(e=>{s.current=e},[]),disableHoverableContent:i,children:a})};Hd.displayName=Ld;var Ud=`Tooltip`,[Wd,Gd]=Pd(Ud),Kd=e=>{let{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:o,delayDuration:s}=e,c=Vd(Ud,e.__scopeTooltip),l=Id(t),[u,d]=T.useState(null),f=_a(),p=T.useRef(0),m=o??c.disableHoverableContent,h=s??c.delayDuration,g=T.useRef(!1),[_,v]=sa({prop:r,defaultProp:i??!1,onChange:e=>{e?(c.onOpen(),document.dispatchEvent(new CustomEvent(zd))):c.onClose(),a?.(e)},caller:Ud}),y=T.useMemo(()=>_?g.current?`delayed-open`:`instant-open`:`closed`,[_]),b=T.useCallback(()=>{window.clearTimeout(p.current),p.current=0,g.current=!1,v(!0)},[v]),x=T.useCallback(()=>{window.clearTimeout(p.current),p.current=0,v(!1)},[v]),S=T.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{g.current=!0,v(!0),p.current=0},h)},[h,v]);return T.useEffect(()=>()=>{p.current&&=(window.clearTimeout(p.current),0)},[]),(0,K.jsx)($u,{...l,children:(0,K.jsx)(Wd,{scope:t,contentId:f,open:_,stateAttribute:y,trigger:u,onTriggerChange:d,onTriggerEnter:T.useCallback(()=>{c.isOpenDelayedRef.current?S():b()},[c.isOpenDelayedRef,S,b]),onTriggerLeave:T.useCallback(()=>{m?x():(window.clearTimeout(p.current),p.current=0)},[x,m]),onOpen:b,onClose:x,disableHoverableContent:m,children:n})})};Kd.displayName=Ud;var qd=`TooltipTrigger`,Jd=T.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Gd(qd,n),a=Vd(qd,n),o=Id(n),s=Ri(t,T.useRef(null),i.onTriggerChange),c=T.useRef(!1),l=T.useRef(!1),u=T.useCallback(()=>c.current=!1,[]);return T.useEffect(()=>()=>document.removeEventListener(`pointerup`,u),[u]),(0,K.jsx)(ed,{asChild:!0,...o,children:(0,K.jsx)(Yi.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:s,onPointerMove:ia(e.onPointerMove,e=>{e.pointerType!==`touch`&&!l.current&&!a.isPointerInTransitRef.current&&(i.onTriggerEnter(),l.current=!0)}),onPointerLeave:ia(e.onPointerLeave,()=>{i.onTriggerLeave(),l.current=!1}),onPointerDown:ia(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener(`pointerup`,u,{once:!0})}),onFocus:ia(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:ia(e.onBlur,i.onClose),onClick:ia(e.onClick,i.onClose)})})});Jd.displayName=qd;var Yd=`TooltipPortal`,[Xd,Zd]=Pd(Yd,{forceMount:void 0}),Qd=e=>{let{__scopeTooltip:t,forceMount:n,children:r,container:i}=e,a=Gd(Yd,t);return(0,K.jsx)(Xd,{scope:t,forceMount:n,children:(0,K.jsx)(da,{present:n||a.open,children:(0,K.jsx)(lo,{asChild:!0,container:i,children:r})})})};Qd.displayName=Yd;var $d=`TooltipContent`,ef=T.forwardRef((e,t)=>{let n=Zd($d,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i=`top`,...a}=e,o=Gd($d,e.__scopeTooltip);return(0,K.jsx)(da,{present:r||o.open,children:o.disableHoverableContent?(0,K.jsx)(of,{side:i,...a,ref:t}):(0,K.jsx)(tf,{side:i,...a,ref:t})})}),tf=T.forwardRef((e,t)=>{let n=Gd($d,e.__scopeTooltip),r=Vd($d,e.__scopeTooltip),i=T.useRef(null),a=Ri(t,i),[o,s]=T.useState(null),{trigger:c,onClose:l}=n,u=i.current,{onPointerInTransitChange:d}=r,f=T.useCallback(()=>{s(null),d(!1)},[d]),p=T.useCallback((e,t)=>{let n=e.currentTarget,r={x:e.clientX,y:e.clientY},i=uf(r,lf(r,n.getBoundingClientRect())),a=df(t.getBoundingClientRect());s(pf([...i,...a])),d(!0)},[d]);return T.useEffect(()=>()=>f(),[f]),T.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]),T.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=!ff(n,o);r?f():i&&(f(),l())};return document.addEventListener(`pointermove`,e),()=>document.removeEventListener(`pointermove`,e)}},[c,u,o,l,f]),(0,K.jsx)(of,{...e,ref:a})}),[nf,rf]=Pd(Ud,{isInside:!1}),af=Gi(`TooltipContent`),of=T.forwardRef((e,t)=>{let{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:a,onPointerDownOutside:o,...s}=e,c=Gd($d,n),l=Id(n),{onClose:u}=c;return T.useEffect(()=>(document.addEventListener(zd,u),()=>document.removeEventListener(zd,u)),[u]),T.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)(za,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:u,children:(0,K.jsxs)(td,{"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)(af,{children:r}),(0,K.jsx)(nf,{scope:n,isInside:!0,children:(0,K.jsx)(ea,{id:c.contentId,role:`tooltip`,children:i||r})})]})})});ef.displayName=$d;var sf=`TooltipArrow`,cf=T.forwardRef((e,t)=>{let{__scopeTooltip:n,...r}=e,i=Id(n);return rf(sf,n).isInside?null:(0,K.jsx)(nd,{...i,...r,ref:t})});cf.displayName=sf;function lf(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 uf(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 df(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 ff(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 pf(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)),mf(t)}function mf(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 hf=Hd,gf=Kd,_f=Jd,vf=Qd,yf=ef,bf=cf;function xf(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=xf(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function Sf(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=xf(e))&&(r&&(r+=` `),r+=t);return r}var Cf=(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},wf=(e,t)=>({classGroupId:e,validator:t}),Tf=(e=new Map,t=null,n)=>({nextPart:e,validators:t,classGroupId:n}),Ef=`-`,Df=[],Of=`arbitrary..`,kf=e=>{let t=Mf(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:r}=e;return{getClassGroupId:e=>{if(e.startsWith(`[`)&&e.endsWith(`]`))return jf(e);let n=e.split(Ef);return Af(n,+(n[0]===``&&n.length>1),t)},getConflictingClassGroupIds:(e,t)=>{if(t){let t=r[e],i=n[e];return t?i?Cf(i,t):t:i||Df}return n[e]||Df}}},Af=(e,t,n)=>{if(e.length-t===0)return n.classGroupId;let r=e[t],i=n.nextPart.get(r);if(i){let n=Af(e,t+1,i);if(n)return n}let a=n.validators;if(a===null)return;let o=t===0?e.join(Ef):e.slice(t).join(Ef),s=a.length;for(let e=0;e<s;e++){let t=a[e];if(t.validator(o))return t.classGroupId}},jf=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?Of+r:void 0})(),Mf=e=>{let{theme:t,classGroups:n}=e;return Nf(n,t)},Nf=(e,t)=>{let n=Tf();for(let r in e){let i=e[r];Pf(i,n,r,t)}return n},Pf=(e,t,n,r)=>{let i=e.length;for(let a=0;a<i;a++){let i=e[a];Ff(i,t,n,r)}},Ff=(e,t,n,r)=>{if(typeof e==`string`){If(e,t,n);return}if(typeof e==`function`){Lf(e,t,n,r);return}Rf(e,t,n,r)},If=(e,t,n)=>{let r=e===``?t:zf(t,e);r.classGroupId=n},Lf=(e,t,n,r)=>{if(Bf(e)){Pf(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(wf(n,e))},Rf=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e<a;e++){let[a,o]=i[e];Pf(o,zf(t,a),n,r)}},zf=(e,t)=>{let n=e,r=t.split(Ef),i=r.length;for(let e=0;e<i;e++){let t=r[e],i=n.nextPart.get(t);i||(i=Tf(),n.nextPart.set(t,i)),n=i}return n},Bf=e=>`isThemeGetter`in e&&e.isThemeGetter===!0,Vf=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)}}},Hf=`!`,Uf=`:`,Wf=[],Gf=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),Kf=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===Uf){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(Hf)?(c=s.slice(0,-1),l=!0):s.startsWith(Hf)&&(c=s.slice(1),l=!0);let u=a&&a>i?a-i:void 0;return Gf(t,l,c,u)};if(t){let e=t+Uf,n=r;r=t=>t.startsWith(e)?n(t.slice(e.length)):Gf(Wf,!1,t,void 0,!0)}if(n){let e=r;r=t=>n({className:t,parseClassName:e})}return r},qf=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}},Jf=e=>({cache:Vf(e.cacheSize),parseClassName:Kf(e),sortModifiers:qf(e),postfixLookupClassGroupIds:Yf(e),...kf(e)}),Yf=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},Xf=/\s+/,Zf=(e,t)=>{let{parseClassName:n,getClassGroupId:r,getConflictingClassGroupIds:i,sortModifiers:a,postfixLookupClassGroupIds:o}=t,s=[],c=e.trim().split(Xf),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?_+Hf:_,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},Qf=(...e)=>{let t=0,n,r,i=``;for(;t<e.length;)(n=e[t++])&&(r=$f(n))&&(i&&(i+=` `),i+=r);return i},$f=e=>{if(typeof e==`string`)return e;let t,n=``;for(let r=0;r<e.length;r++)e[r]&&(t=$f(e[r]))&&(n&&(n+=` `),n+=t);return n},ep=(e,...t)=>{let n,r,i,a,o=o=>(n=Jf(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=Zf(e,n);return i(e,a),a};return a=o,(...e)=>a(Qf(...e))},tp=[],np=e=>{let t=t=>t[e]||tp;return t.isThemeGetter=!0,t},rp=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,ip=/^\((?:(\w[\w-]*):)?(.+)\)$/i,ap=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,op=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,sp=/\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$/,cp=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,lp=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,up=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,dp=e=>ap.test(e),fp=e=>!!e&&!Number.isNaN(Number(e)),pp=e=>!!e&&Number.isInteger(Number(e)),mp=e=>e.endsWith(`%`)&&fp(e.slice(0,-1)),hp=e=>op.test(e),gp=()=>!0,_p=e=>sp.test(e)&&!cp.test(e),vp=()=>!1,yp=e=>lp.test(e),bp=e=>up.test(e),xp=e=>!q(e)&&!J(e),Sp=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)),Cp=e=>Rp(e,Hp,vp),q=e=>rp.test(e),wp=e=>Rp(e,Up,_p),Tp=e=>Rp(e,Wp,fp),Ep=e=>Rp(e,Kp,gp),Dp=e=>Rp(e,Gp,vp),Op=e=>Rp(e,Bp,vp),kp=e=>Rp(e,Vp,bp),Ap=e=>Rp(e,qp,yp),J=e=>ip.test(e),jp=e=>zp(e,Up),Mp=e=>zp(e,Gp),Np=e=>zp(e,Bp),Pp=e=>zp(e,Hp),Fp=e=>zp(e,Vp),Ip=e=>zp(e,qp,!0),Lp=e=>zp(e,Kp,!0),Rp=(e,t,n)=>{let r=rp.exec(e);return r?r[1]?t(r[1]):n(r[2]):!1},zp=(e,t,n=!1)=>{let r=ip.exec(e);return r?r[1]?t(r[1]):n:!1},Bp=e=>e===`position`||e===`percentage`,Vp=e=>e===`image`||e===`url`,Hp=e=>e===`length`||e===`size`||e===`bg-size`,Up=e=>e===`length`,Wp=e=>e===`number`,Gp=e=>e===`family-name`,Kp=e=>e===`number`||e===`weight`,qp=e=>e===`shadow`,Jp=ep(()=>{let e=np(`color`),t=np(`font`),n=np(`text`),r=np(`font-weight`),i=np(`tracking`),a=np(`leading`),o=np(`breakpoint`),s=np(`container`),c=np(`spacing`),l=np(`radius`),u=np(`shadow`),d=np(`inset-shadow`),f=np(`text-shadow`),p=np(`drop-shadow`),m=np(`blur`),h=np(`perspective`),g=np(`aspect`),_=np(`ease`),v=np(`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(),J,q],S=()=>[`auto`,`hidden`,`clip`,`visible`,`scroll`],C=()=>[`auto`,`contain`,`none`],w=()=>[J,q,c],T=()=>[dp,`full`,`auto`,...w()],E=()=>[pp,`none`,`subgrid`,J,q],D=()=>[`auto`,{span:[`full`,pp,J,q]},pp,J,q],O=()=>[pp,`auto`,J,q],k=()=>[`auto`,`min`,`max`,`fr`,J,q],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=()=>[dp,`auto`,`full`,`dvw`,`dvh`,`lvw`,`lvh`,`svw`,`svh`,`min`,`max`,`fit`,...w()],P=()=>[dp,`screen`,`full`,`dvw`,`lvw`,`svw`,`min`,`max`,`fit`,...w()],F=()=>[dp,`screen`,`full`,`lh`,`dvh`,`lvh`,`svh`,`min`,`max`,`fit`,...w()],I=()=>[e,J,q],L=()=>[...b(),Np,Op,{position:[J,q]}],R=()=>[`no-repeat`,{repeat:[``,`x`,`y`,`space`,`round`]}],z=()=>[`auto`,`cover`,`contain`,Pp,Cp,{size:[J,q]}],B=()=>[mp,jp,wp],V=()=>[``,`none`,`full`,l,J,q],H=()=>[``,fp,jp,wp],U=()=>[`solid`,`dashed`,`dotted`,`double`],W=()=>[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],G=()=>[fp,mp,Np,Op],ee=()=>[``,`none`,m,J,q],te=()=>[`none`,fp,J,q],ne=()=>[`none`,fp,J,q],re=()=>[fp,J,q],ie=()=>[dp,`full`,...w()];return{cacheSize:500,theme:{animate:[`spin`,`ping`,`pulse`,`bounce`],aspect:[`video`],blur:[hp],breakpoint:[hp],color:[gp],container:[hp],"drop-shadow":[hp],ease:[`in`,`out`,`in-out`],font:[xp],"font-weight":[`thin`,`extralight`,`light`,`normal`,`medium`,`semibold`,`bold`,`extrabold`,`black`],"inset-shadow":[hp],leading:[`none`,`tight`,`snug`,`normal`,`relaxed`,`loose`],perspective:[`dramatic`,`near`,`normal`,`midrange`,`distant`,`none`],radius:[hp],shadow:[hp],spacing:[`px`,fp],text:[hp],"text-shadow":[hp],tracking:[`tighter`,`tight`,`normal`,`wide`,`wider`,`widest`]},classGroups:{aspect:[{aspect:[`auto`,`square`,dp,q,J,g]}],container:[`container`],"container-type":[{"@container":[``,`normal`,`size`,J,q]}],"container-named":[Sp],columns:[{columns:[fp,q,J,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:[pp,`auto`,J,q]}],basis:[{basis:[dp,`full`,`auto`,s,...w()]}],"flex-direction":[{flex:[`row`,`row-reverse`,`col`,`col-reverse`]}],"flex-wrap":[{flex:[`nowrap`,`wrap`,`wrap-reverse`]}],flex:[{flex:[fp,dp,`auto`,`initial`,`none`,q]}],grow:[{grow:[``,fp,J,q]}],shrink:[{shrink:[``,fp,J,q]}],order:[{order:[pp,`first`,`last`,`none`,J,q]}],"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,jp,wp]}],"font-smoothing":[`antialiased`,`subpixel-antialiased`],"font-style":[`italic`,`not-italic`],"font-weight":[{font:[r,Lp,Ep]}],"font-stretch":[{"font-stretch":[`ultra-condensed`,`extra-condensed`,`condensed`,`semi-condensed`,`normal`,`semi-expanded`,`expanded`,`extra-expanded`,`ultra-expanded`,mp,q]}],"font-family":[{font:[Mp,Dp,t]}],"font-features":[{"font-features":[q]}],"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,J,q]}],"line-clamp":[{"line-clamp":[fp,`none`,J,Tp]}],leading:[{leading:[a,...w()]}],"list-image":[{"list-image":[`none`,J,q]}],"list-style-position":[{list:[`inside`,`outside`]}],"list-style-type":[{list:[`disc`,`decimal`,`none`,J,q]}],"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:[fp,`from-font`,`auto`,J,wp]}],"text-decoration-color":[{decoration:I()}],"underline-offset":[{"underline-offset":[fp,`auto`,J,q]}],"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:[pp,J,q]}],"vertical-align":[{align:[`baseline`,`top`,`middle`,`bottom`,`text-top`,`text-bottom`,`sub`,`super`,J,q]}],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`,J,q]}],"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`]},pp,J,q],radial:[``,J,q],conic:[pp,J,q]},Fp,kp]}],"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":[fp,J,q]}],"outline-w":[{outline:[``,fp,jp,wp]}],"outline-color":[{outline:I()}],shadow:[{shadow:[``,`none`,u,Ip,Ap]}],"shadow-color":[{shadow:I()}],"inset-shadow":[{"inset-shadow":[`none`,d,Ip,Ap]}],"inset-shadow-color":[{"inset-shadow":I()}],"ring-w":[{ring:H()}],"ring-w-inset":[`ring-inset`],"ring-color":[{ring:I()}],"ring-offset-w":[{"ring-offset":[fp,wp]}],"ring-offset-color":[{"ring-offset":I()}],"inset-ring-w":[{"inset-ring":H()}],"inset-ring-color":[{"inset-ring":I()}],"text-shadow":[{"text-shadow":[`none`,f,Ip,Ap]}],"text-shadow-color":[{"text-shadow":I()}],opacity:[{opacity:[fp,J,q]}],"mix-blend":[{"mix-blend":[...W(),`plus-darker`,`plus-lighter`]}],"bg-blend":[{"bg-blend":W()}],"mask-clip":[{"mask-clip":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]},`mask-no-clip`],"mask-composite":[{mask:[`add`,`subtract`,`intersect`,`exclude`]}],"mask-image-linear-pos":[{"mask-linear":[fp]}],"mask-image-linear-from-pos":[{"mask-linear-from":G()}],"mask-image-linear-to-pos":[{"mask-linear-to":G()}],"mask-image-linear-from-color":[{"mask-linear-from":I()}],"mask-image-linear-to-color":[{"mask-linear-to":I()}],"mask-image-t-from-pos":[{"mask-t-from":G()}],"mask-image-t-to-pos":[{"mask-t-to":G()}],"mask-image-t-from-color":[{"mask-t-from":I()}],"mask-image-t-to-color":[{"mask-t-to":I()}],"mask-image-r-from-pos":[{"mask-r-from":G()}],"mask-image-r-to-pos":[{"mask-r-to":G()}],"mask-image-r-from-color":[{"mask-r-from":I()}],"mask-image-r-to-color":[{"mask-r-to":I()}],"mask-image-b-from-pos":[{"mask-b-from":G()}],"mask-image-b-to-pos":[{"mask-b-to":G()}],"mask-image-b-from-color":[{"mask-b-from":I()}],"mask-image-b-to-color":[{"mask-b-to":I()}],"mask-image-l-from-pos":[{"mask-l-from":G()}],"mask-image-l-to-pos":[{"mask-l-to":G()}],"mask-image-l-from-color":[{"mask-l-from":I()}],"mask-image-l-to-color":[{"mask-l-to":I()}],"mask-image-x-from-pos":[{"mask-x-from":G()}],"mask-image-x-to-pos":[{"mask-x-to":G()}],"mask-image-x-from-color":[{"mask-x-from":I()}],"mask-image-x-to-color":[{"mask-x-to":I()}],"mask-image-y-from-pos":[{"mask-y-from":G()}],"mask-image-y-to-pos":[{"mask-y-to":G()}],"mask-image-y-from-color":[{"mask-y-from":I()}],"mask-image-y-to-color":[{"mask-y-to":I()}],"mask-image-radial":[{"mask-radial":[J,q]}],"mask-image-radial-from-pos":[{"mask-radial-from":G()}],"mask-image-radial-to-pos":[{"mask-radial-to":G()}],"mask-image-radial-from-color":[{"mask-radial-from":I()}],"mask-image-radial-to-color":[{"mask-radial-to":I()}],"mask-image-radial-shape":[{"mask-radial":[`circle`,`ellipse`]}],"mask-image-radial-size":[{"mask-radial":[{closest:[`side`,`corner`],farthest:[`side`,`corner`]}]}],"mask-image-radial-pos":[{"mask-radial-at":b()}],"mask-image-conic-pos":[{"mask-conic":[fp]}],"mask-image-conic-from-pos":[{"mask-conic-from":G()}],"mask-image-conic-to-pos":[{"mask-conic-to":G()}],"mask-image-conic-from-color":[{"mask-conic-from":I()}],"mask-image-conic-to-color":[{"mask-conic-to":I()}],"mask-mode":[{mask:[`alpha`,`luminance`,`match`]}],"mask-origin":[{"mask-origin":[`border`,`padding`,`content`,`fill`,`stroke`,`view`]}],"mask-position":[{mask:L()}],"mask-repeat":[{mask:R()}],"mask-size":[{mask:z()}],"mask-type":[{"mask-type":[`alpha`,`luminance`]}],"mask-image":[{mask:[`none`,J,q]}],filter:[{filter:[``,`none`,J,q]}],blur:[{blur:ee()}],brightness:[{brightness:[fp,J,q]}],contrast:[{contrast:[fp,J,q]}],"drop-shadow":[{"drop-shadow":[``,`none`,p,Ip,Ap]}],"drop-shadow-color":[{"drop-shadow":I()}],grayscale:[{grayscale:[``,fp,J,q]}],"hue-rotate":[{"hue-rotate":[fp,J,q]}],invert:[{invert:[``,fp,J,q]}],saturate:[{saturate:[fp,J,q]}],sepia:[{sepia:[``,fp,J,q]}],"backdrop-filter":[{"backdrop-filter":[``,`none`,J,q]}],"backdrop-blur":[{"backdrop-blur":ee()}],"backdrop-brightness":[{"backdrop-brightness":[fp,J,q]}],"backdrop-contrast":[{"backdrop-contrast":[fp,J,q]}],"backdrop-grayscale":[{"backdrop-grayscale":[``,fp,J,q]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[fp,J,q]}],"backdrop-invert":[{"backdrop-invert":[``,fp,J,q]}],"backdrop-opacity":[{"backdrop-opacity":[fp,J,q]}],"backdrop-saturate":[{"backdrop-saturate":[fp,J,q]}],"backdrop-sepia":[{"backdrop-sepia":[``,fp,J,q]}],"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`,J,q]}],"transition-behavior":[{transition:[`normal`,`discrete`]}],duration:[{duration:[fp,`initial`,J,q]}],ease:[{ease:[`linear`,`initial`,_,J,q]}],delay:[{delay:[fp,J,q]}],animate:[{animate:[`none`,v,J,q]}],backface:[{backface:[`hidden`,`visible`]}],perspective:[{perspective:[h,J,q]}],"perspective-origin":[{"perspective-origin":x()}],rotate:[{rotate:te()}],"rotate-x":[{"rotate-x":te()}],"rotate-y":[{"rotate-y":te()}],"rotate-z":[{"rotate-z":te()}],scale:[{scale:ne()}],"scale-x":[{"scale-x":ne()}],"scale-y":[{"scale-y":ne()}],"scale-z":[{"scale-z":ne()}],"scale-3d":[`scale-3d`],skew:[{skew:re()}],"skew-x":[{"skew-x":re()}],"skew-y":[{"skew-y":re()}],transform:[{transform:[J,q,``,`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:[pp,J,q]}],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`,J,q]}],"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`,J,q]}],fill:[{fill:[`none`,...I()]}],"stroke-w":[{stroke:[fp,jp,wp,Tp]}],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 Y(...e){return Jp(Sf(e))}function Yp({delayDuration:e=0,...t}){return(0,K.jsx)(hf,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function Xp({...e}){return(0,K.jsx)(gf,{"data-slot":`tooltip`,...e})}function Zp({...e}){return(0,K.jsx)(_f,{"data-slot":`tooltip-trigger`,...e})}function Qp({className:e,sideOffset:t=4,children:n,...r}){return(0,K.jsx)(vf,{children:(0,K.jsxs)(yf,{"data-slot":`tooltip-content`,sideOffset:t,className:Y(`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)(bf,{className:`fill-gray-900`})]})})}var X=(e,t)=>fetch(e,{credentials:`include`,...t}),$p=null;function em(){return $p||=X(`/api/health`).then(e=>e.json()).then(e=>typeof e?.workspace==`string`?e.workspace:`loopat`).catch(()=>`loopat`),$p}async function tm(){let e=await X(`/api/auth/me`);return e.ok?(await e.json()).user??null:null}async function nm(e,t){let n=await X(`/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 rm(e){let t=await X(`/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 im(e){let t=await X(`/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 am(){let e=await X(`/api/personal/status`);return e.ok?await e.json():null}async function om(e){let t=await X(`/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 sm(e,t=!1){let n=await X(`/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 cm(e){let t=await X(`/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 lm(){let e=await X(`/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 um(e,t){let n={};e&&(n.repoUrl=e),t&&(n.cryptKey=t);let r=await X(`/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 dm(e,t,n,r){let i={token:e};t&&(i.repoName=t),n&&(i.cryptKey=n),r&&(i.baseUrl=r);let a=await X(`/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 fm(){await X(`/api/auth/logout`,{method:`POST`}).catch(()=>{})}async function pm(e=`active`){let t=await X(`/api/loops`+(e===`all`?`?archived=all`:e===`archived`?`?archived=true`:``));return t.ok?(await t.json()).loops:[]}async function mm(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 X(`/api/loops`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)})).json()}let t=await X(`/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 hm(){let e=await X(`/api/profiles`);return e.ok?(await e.json()).profiles??[]:[]}async function gm(){let e=await X(`/api/personal/default-profiles`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.default_profiles)?t.default_profiles:[]}async function _m(e){let t=await X(`/api/loop-stats?profiles=${encodeURIComponent(e.join(`,`))}`);return t.ok?await t.json():null}async function vm(){let e=await X(`/api/vaults`);if(!e.ok)return[];let t=await e.json();return Array.isArray(t.vaults)?t.vaults:[]}async function ym(e){return(await X(`/api/loops/${e}/viewed`,{method:`POST`})).ok}async function bm(e,t){let n=await X(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({archived:t})});return n.ok?await n.json():null}async function xm(e,t){let n=await X(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({public:t})});return n.ok?await n.json():null}async function Sm(e,t){let n=await X(`/api/loops/${e}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({title:t})});return n.ok?await n.json():null}async function Cm(e){let t=await X(`/api/loops/${e}/request-drive`,{method:`POST`});return t.ok?await t.json():null}async function wm(e){let t=await X(`/api/loops/${e}/drive`,{method:`POST`});return t.ok?await t.json():null}async function Tm(e){let t=await X(`/api/loops/${e}/distill`,{method:`POST`});return t.ok?await t.json():null}async function Em(e){let t=await X(`/api/loops/${e}`);return t.ok?await t.json():null}async function Dm(e){let t=await X(`/api/loops/${e}/strip-thinking`,{method:`POST`});return t.ok?await t.json():{stripped:0,sessionsTouched:0}}async function Om(e,t=``){return(await(await X(`/api/loops/${e}/files?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function km(e,t=``){return(await(await X(`/api/loops/${e}/files/tree?path=${encodeURIComponent(t)}`)).json()).entries??[]}async function Am(e,t){let n=await X(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function jm(e,t,n){return(await X(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).ok}async function Mm(e,t){return(await X(`/api/loops/${e}/file?path=${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function Nm(e,t){return(await X(`/api/loops/${e}/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).ok}async function Pm(e,t){let n=new FormData;n.append(`file`,t);let r=await X(`/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 Fm(e){let t=await X(`/api/loops/${e}/context`);return t.ok?(await t.json()).mounts??[]:[]}async function Im(e,t=``){let n=await X(`/api/workspace/files?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).entries??[]:[]}async function Lm(e){let t=await X(`/api/workspace/files?vault=${e}&flat=1`);return t.ok?(await t.json()).entries??[]:[]}async function Rm(e,t){let n=await X(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null}async function zm(e,t,n){return await(await X(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:n})})).json()}async function Bm(){let e=await X(`/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 Vm(){let e=await(await X(`/api/notes/behind`)).json().catch(()=>({}));return typeof e.behind==`number`?e.behind:0}async function Hm(){let e=await(await X(`/api/notes/refresh`,{method:`POST`})).json().catch(()=>({}));return{ok:!!e.ok,diverged:e.diverged,error:e.error}}async function Um(e,t){return await(await X(`/api/workspace/file?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Wm(e,t){return await(await X(`/api/workspace/folder?vault=${e}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t})})).json()}async function Gm(e,t){return await(await X(`/api/workspace/file?vault=${e}&path=${encodeURIComponent(t)}`,{method:`DELETE`})).json()}async function Km(e,t){let n=await X(`/api/workspace/backlinks?vault=${e}&path=${encodeURIComponent(t)}`);return n.ok?(await n.json()).backlinks??[]:[]}async function qm(){let e=await X(`/api/workspace/repos`);return e.ok?(await e.json()).repos??[]:[]}async function Jm(e){let t=await X(`/api/loops/${e}/chat-history`);return t.ok?(await t.json()).map(e=>e.text):[]}async function Ym(e,t){await X(`/api/loops/${e}/chat-history`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t})})}async function Xm(e){let t=await X(`/api/workspace/repo/${encodeURIComponent(e)}`);return t.ok?await t.json():null}async function Zm(e){let t=await X(`/api/workspace/repo/${encodeURIComponent(e)}/pull`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,output:n.output}:{ok:!1,error:n.error??`http ${t.status}`}}function Qm(e){return typeof e==`string`?`/api/sync/${e}`:`/api/sync/repos/${encodeURIComponent(e.repo)}`}async function $m(e){let t=await X(`${Qm(e)}/status`);return t.ok?await t.json():null}async function eh(e){let t=await X(`${Qm(e)}/pull`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function th(e){let t=await X(`${Qm(e)}/push`,{method:`POST`}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,message:n.message}:{ok:!1,error:n.error??`http ${t.status}`}}async function nh(e){let t=await X(`/api/workspace/repos`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json().catch(()=>({}));return t.ok?{ok:!0,name:n.name,kind:n.kind}:{ok:!1,error:n.error??`http ${t.status}`}}async function rh(e=`default`){let t=await X(`/api/kanban/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function ih(e,t,n){let r=await X(`/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 ah(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/toggle`,{method:`PATCH`})).ok}async function oh(e,t,n,r){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(r)})).ok}async function sh(e,t,n,r){return(await X(`/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 ch(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}`,{method:`DELETE`})).ok}async function lh(e,t,n,r,i){return(await X(`/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 uh(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({filename:t,title:n})})).ok}async function dh(){let e=await X(`/api/kanban/boards`);return e.ok?(await e.json()).boards:[`default`]}async function fh(e){return(await X(`/api/kanban/boards`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e})})).ok}async function ph(e,t){return(await X(`/api/kanban/boards/${encodeURIComponent(e)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t})})).ok}async function mh(e=`default`){let t=await X(`/api/kanban/config/${encodeURIComponent(e)}`);return t.ok?(await t.json()).columns:[]}async function hh(e,t){return(await X(`/api/kanban/config/${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({columns:t})})).ok}async function gh(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/rename`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({toFile:n})})).ok}async function _h(e,t){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`})).ok}async function vh(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/color`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({color:n})})).ok}async function yh(e,t,n){return(await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/reorder`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({cids:n})})).ok}async function bh(e,t,n){let r=await X(`/api/kanban/columns/${encodeURIComponent(e)}/${encodeURIComponent(t)}/cards/${encodeURIComponent(n)}/assign-driver`,{method:`POST`});return r.ok?await r.json():{ok:!1}}async function xh(e,t,n,r){return(await X(`/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 Sh(){let e=await X(`/api/topics`);return e.ok?(await e.json()).topics:[]}async function Ch(){let e=await X(`/api/providers`);return e.ok?await e.json():{providers:{},default:``}}async function wh(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 X(`/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 Th(){let e=await X(`/api/version`);return e.ok?await e.json():{branch:`unknown`,commit:`unknown`}}async function Eh(){let e=await X(`/api/admin/system`);return e.ok?await e.json():null}async function Dh(){return await(await X(`/api/admin/system/check`,{method:`POST`})).json()}async function Oh(){return await(await X(`/api/admin/system/pull`,{method:`POST`})).json()}function kh(){return{commit:`f8398e2f3f624a7b2e4920146c7414527bbe9a2d`,time:`2026-05-31T16:09:20.544Z`}}async function Ah(e){let t=await X(`/api/loops/${e}/git-status`);return t.ok?await t.json():{unstaged:[],staged:[]}}async function jh(e,t,n){let r=await X(`/api/loops/${e}/git-diff?path=${encodeURIComponent(t)}&staged=${n?`1`:`0`}`);return r.ok?(await r.json()).diff??null:null}async function Mh(e,t,n=!1){return(await X(`/api/loops/${e}/git-stage`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({files:t,unstage:n})})).ok}async function Nh(e,t){return(await X(`/api/loops/${e}/git-discard`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({file:t})})).ok}async function Ph(e,t){let n=await X(`/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 Fh(e,t=50){let n=await X(`/api/loops/${e}/git-log?limit=${t}`);return n.ok?(await n.json()).commits??[]:[]}async function Ih(){let e=await X(`/api/settings/personal/disk`);return e.ok?await e.json():null}async function Lh(e){let t=await X(`/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 Rh(e,t,n=`default`){let r=await X(`/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 zh(){return await(await X(`/api/settings/workspace`)).json()}async function Bh(e){return(await X(`/api/settings/workspace`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Vh(){let e=await X(`/api/settings/token-usage/daily`);return e.ok?await e.json():{}}async function Hh(){let e=await X(`/api/settings/token-usage/loops`);return e.ok?await e.json():[]}async function Uh(){let e=await X(`/api/admin/presets`);return e.ok?await e.json():{providerPresets:[],miseToolPresets:[]}}async function Wh(e){return(await X(`/api/admin/presets`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Gh(){let e=await X(`/api/admin/users`);return e.ok?(await e.json()).users??[]:[]}async function Kh(e){let t=await X(`/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 qh(e,t){let n=await X(`/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 Jh(e){let t=await X(`/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 Yh(){let e=await X(`/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 Xh(e){let t=await X(`/api/loops/${e}/share/current-port`);return t.ok?await t.json():{port:null}}async function Zh(e){return(await X(`/api/serve/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)})).ok}async function Qh(){let e=await X(`/api/serve/available-port`);return e.ok?await e.json():{port:null,error:`request failed`}}async function $h(e,t){let n=await X(`/api/serve/check-port?port=${e}&loopId=${t||``}`);return n.ok?await n.json():{available:!1,reason:`request failed`}}async function eg(e,t){let n=new URLSearchParams({alias:e});t&&n.set(`loopId`,t);let r=await X(`/api/serve/alias-check?${n}`);return r.ok?await r.json():{available:!1,reason:`check failed`}}async function tg(){let e=await X(`/api/chat/conversations`);return e.ok?(await e.json()).conversations??[]:[]}async function ng(){let e=await X(`/api/chat/users`);return e.ok?(await e.json()).users??[]:[]}async function rg(e,t){let n=await X(`/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 ig(e){let t=await X(`/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 ag(e){let t=await X(`/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 og(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 X(`/api/chat/conversations/${encodeURIComponent(e)}/messages?${n.toString()}`);return r.ok?(await r.json()).messages??[]:[]}async function sg(e){let t=await X(`/api/chat/threads/${e}`);return t.ok?await t.json():null}async function cg(e,t,n=null){let r=await X(`/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 lg(e,t){return(await X(`/api/chat/conversations/${encodeURIComponent(e)}/read`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({lastReadId:t})})).ok}async function ug(e,t){let n=await X(`/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 dg(){let e=await X(`/api/onboarding`);return e.ok?await e.json():{state:`fresh`}}async function fg(){let e=await X(`/api/onboarding/start`,{method:`POST`}),t=await e.json().catch(()=>({}));return e.ok?{loopId:t.loopId}:{error:t.error??`start failed`}}async function pg(){return(await X(`/api/onboarding/done`,{method:`POST`})).ok}async function mg(e){let t=await X(`/api/mcp-servers${e?`?loopId=${encodeURIComponent(e)}`:``}`);return t.ok?await t.json():{servers:[]}}async function hg(e,t){let n=await X(`/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 gg(e){return(await X(`/api/envs/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}async function _g(e){let t=await X(`/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 vg(){let e=await X(`/api/tiers`);return e.ok?await e.json():null}async function yg(e,t){let n=await X(`/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 bg(e){let t=await X(`/api/tiers/${encodeURIComponent(e)}/mise-config`);return t.ok?await t.json():{content:``,exists:!1,error:`fetch failed (${t.status})`}}async function xg(e,t){let n=await X(`/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 Sg(){let e=await X(`/api/plugins/available`);return e.ok?(await e.json()).plugins??[]:[]}async function Cg(){let e=await X(`/api/plugins/browse`);return e.ok?(await e.json()).plugins??[]:[]}async function wg(){let e=await X(`/api/marketplaces`);return e.ok?(await e.json()).marketplaces??[]:[]}async function Tg(){let e=await X(`/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 Eg(e){let t=await X(`/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 Dg(e){let t=await X(`/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 Og(){let e=await X(`/api/v1/me/tokens`);return e.ok?(await e.json().catch(()=>({tokens:[]}))).tokens??[]:[]}async function kg(e){let t=await X(`/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 Ag(e){return(await X(`/api/v1/me/tokens/${encodeURIComponent(e)}`,{method:`DELETE`})).ok}function jg(){let[e,t]=(0,T.useState)([]),[n,r]=(0,T.useState)(!0),[i,a]=(0,T.useState)(!1),[o,s]=(0,T.useState)(!1),[c,l]=(0,T.useState)(``),[u,d]=(0,T.useState)(null),[f,p]=(0,T.useState)(null),[m,h]=(0,T.useState)(!0),g=(0,T.useCallback)(async()=>{r(!0),t(await pm(i?`all`:`active`)),r(!1)},[i]);(0,T.useEffect)(()=>{let e=!1;return tm().then(t=>{e||(p(t),h(!1))}),()=>{e=!0}},[]),(0,T.useEffect)(()=>{g()},[i,f]);let _=(0,T.useCallback)(async e=>{let n=await mm(e);return t(e=>[n,...e]),n},[]),v=(0,T.useCallback)(async(e,n)=>{let r=await bm(e,n);r&&t(t=>!i&&r.archived?t.filter(t=>t.id!==e):t.map(t=>t.id===e?r:t))},[i]),y=(0,T.useCallback)(async(e,n)=>{let r=await xm(e,n);r&&t(t=>t.map(t=>t.id===e?r:t))},[]),b=(0,T.useCallback)(async(e,n)=>{let r=await Sm(e,n);return r?(t(t=>t.map(t=>t.id===e?r:t)),r):null},[]),x=(0,T.useCallback)(async e=>{let n=await Cm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),S=(0,T.useCallback)(async e=>{let n=await wm(e);n&&t(t=>t.map(t=>t.id===e?n:t))},[]),C=(0,T.useCallback)(async(e,t)=>{let n=await nm(e,t);return n.user&&p(n.user),{error:n.error}},[]),w=(0,T.useCallback)(async e=>{let t=await rm(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,T.useCallback)(async()=>{await fm(),p(null)},[]);return{loops:e,loopsLoading:n,showArchived:i,setShowArchived:a,refresh:g,createLoop:_,setLoopArchived:v,setLoopPublic:y,setLoopTitle:b,requestDrive:x,takeDrive:S,newLoopDialogOpen:o,newLoopDialogTitle:c,kanbanCreateCtx:u,setNewLoopDialogOpen:(0,T.useCallback)((e,t,n)=>{s(e),l(t??``),d(n??null)},[]),currentUser:f,authLoading:m,login:C,register:w,logout:E}}var Mg=(0,T.createContext)(null);function Ng(){let e=(0,T.useContext)(Mg);if(!e)throw Error(`useWorkspace outside provider`);return e}function Pg({onClose:e,onCreate:t,initialTitle:n}){let[r,i]=(0,T.useState)(n??``),[a,o]=(0,T.useState)(``),[s,c]=(0,T.useState)(new Set),[l,u]=(0,T.useState)([]),[d,f]=(0,T.useState)(`default`),[p,m]=(0,T.useState)([]),[h,g]=(0,T.useState)([]),[_,v]=(0,T.useState)([]),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)(!1),[C,w]=(0,T.useState)(!1),E=(0,T.useRef)(null);(0,T.useEffect)(()=>{qm().then(m),Promise.all([hm(),gm()]).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`)))}),vm().then(e=>{v(e),e.includes(`default`)?f(`default`):e.length>0&&f(e[0])}),E.current?.focus()},[]);function D(){let e=new Set(h.map(e=>e.name));c(new Set(l.filter(t=>e.has(t)&&t!==`base`)))}(0,T.useEffect)(()=>{S(!0);let e=setTimeout(()=>{_m([...s]).then(b).finally(()=>S(!1))},120);return()=>clearTimeout(e)},[s]);let O=(()=>{let e=new Set(l.filter(e=>e!==`base`));if(e.size!==s.size)return!0;for(let t of e)if(!s.has(t))return!0;return!1})(),k=h.find(e=>e.name===`base`),A=h.filter(e=>e.name!==`base`);function j(e){c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return(0,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(),!C){w(!0);try{await t({title:r.trim()||`untitled`,repo:a||void 0,profiles:s.size>0?[...s]:void 0,vault:d||void 0})}finally{w(!1)}}},className:`flex flex-col gap-4`,children:[(0,K.jsxs)(Fg,{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.remote?` · ${e.remote}`:``]},e.name))]}),p.length===0&&(0,K.jsx)(`div`,{className:`text-[11px] text-gray-400 mt-1`,children:"No repos registered. Run `git clone` into context/repos/<name>/."})]}),(0,K.jsxs)(Fg,{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 in workspace. Create directories under`,` `,(0,K.jsx)(`code`,{className:`bg-gray-100 px-1 rounded`,children:`context/profiles/<name>/`}),` with a profile.json.`]})]}),(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:x&&!y?(0,K.jsx)(`span`,{className:`text-gray-400`,children:`computing…`}):y?(0,K.jsxs)(`span`,{title:`Totals across team + selected profiles + their plugins (deduped by name)`,children:[(0,K.jsxs)(`span`,{className:y.plugins>0?``:`text-gray-400`,children:[y.plugins,` plugins`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.skills>0?``:`text-gray-400`,children:[y.skills,` skills`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.agents>0?``:`text-gray-400`,children:[y.agents,` agents`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.hooks>0?``:`text-gray-400`,children:[y.hooks,` hooks`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.mcpServers>0?``:`text-gray-400`,children:[y.mcpServers,` MCP servers`]}),(0,K.jsx)(`span`,{className:`mx-1 text-gray-300`,children:`·`}),(0,K.jsxs)(`span`,{className:y.toolchain>0?``:`text-gray-400`,title:`mise.toml [tools] entries, deduped across team + selected profiles`,children:[y.toolchain,` toolchain`]}),x&&(0,K.jsx)(`span`,{className:`ml-1.5 text-gray-400`,children:`·`}),x&&(0,K.jsx)(`span`,{className:`ml-1 text-gray-400`,children:`updating…`})]}):(0,K.jsx)(`span`,{className:`text-gray-400`,children:`—`})})]}),(0,K.jsxs)(Fg,{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:[_.length===0&&(0,K.jsx)(`option`,{value:`default`,children:`default`}),_.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),_.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)(Fg,{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:C,className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:C?`creating…`:`create`})]})]})]})})}function Fg({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 Ig=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,Lg=Sf,Rg=((e,t)=>n=>{if(t?.variants==null)return Lg(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=Ig(t)||Ig(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 Lg(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 zg({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,K.jsx)(r?Hi:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:Y(Rg({variant:t,size:n,className:e})),...i})}function Bg({...e}){return(0,K.jsx)(fc,{"data-slot":`dialog`,...e})}function Vg({...e}){return(0,K.jsx)(pc,{"data-slot":`dialog-portal`,...e})}function Hg({className:e,...t}){return(0,K.jsx)(mc,{"data-slot":`dialog-overlay`,className:Y(`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 Ug({className:e,children:t,showCloseButton:n=!0,...r}){return(0,K.jsxs)(Vg,{"data-slot":`dialog-portal`,children:[(0,K.jsx)(Hg,{}),(0,K.jsxs)(hc,{"data-slot":`dialog-content`,className:Y(`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)(vc,{"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)(_t,{}),(0,K.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function Wg({className:e,...t}){return(0,K.jsx)(`div`,{"data-slot":`dialog-header`,className:Y(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function Gg({className:e,...t}){return(0,K.jsx)(gc,{"data-slot":`dialog-title`,className:Y(`text-lg leading-none font-semibold`,e),...t})}function Kg({className:e,...t}){return(0,K.jsx)(_c,{"data-slot":`dialog-description`,className:Y(`text-sm text-muted-foreground`,e),...t})}function qg({open:e,onClose:t}){let[n,r]=(0,T.useState)({branch:`…`,commit:`…`}),i=kh();return(0,T.useEffect)(()=>{e&&Th().then(e=>r(e))},[e]),(0,K.jsx)(Bg,{open:e,onOpenChange:e=>!e&&t(),children:(0,K.jsxs)(Ug,{className:`sm:max-w-sm bg-white`,children:[(0,K.jsx)(Wg,{children:(0,K.jsxs)(Gg,{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 Jg(e,t){let n=e[Yg];if(!n)throw Error(`ResourceElement.type is not a valid Resource`);return n(t)}var Yg=Symbol(`fnSymbol`);function Xg(e){let t=e=>({type:t,props:e});return t[Yg]=e,t}function Zg(e,t){return{...t,key:e}}var Qg=typeof process<`u`&&!1,$g=null;function e_(e,t){e.currentIndex=0;let n=$g;$g=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{$g=n}}function t_(){if(!$g)throw Error(`No resource fiber available`);return $g}function n_(e){return Qg?$g?.devStrictMode?$g.isFirstRender?`child`:`root`:e?`root`:null:null}var r_=e=>({version:0,committedVersion:0,dispatchUpdate:e,changelog:[],dirtyCells:[]}),i_=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},a_=(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()),i_(e)}}},o_=(e,t)=>{t.dirty||(t.dirty=!0,e.markDirty?.(),e.root.dirtyCells.push(t))},s_=(e,t)=>{let n=t_(),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},c_=e=>{t_().renderContext.effectTasks.push(e)},l_=(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 u_(e,t,n,r){let i=s_(`reducer`,()=>{let t=t_(),a=r?r(n):n;return Qg&&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};l_(t,()=>t.root.dirtyCells.length===0&&!r.hasEagerState&&(r.eagerState=e(i.workInProgress,n),r.hasEagerState=!0,Object.is(i.current,r.eagerState))?null:()=>{o_(t,i),i.queue.add(r)})}}}),a=t_(),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),Qg&&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)||(o_(a,i),i.workInProgress=e)}return[i.workInProgress,i.dispatch]}function d_(e,t,n){return u_(e,void 0,t,n)}function f_(e,t,n,r){return u_(e,t,n,r)}var p_=(e,t)=>typeof t==`function`?t(e):t,m_=e=>typeof e==`function`?e():e;function h_(e){return d_(p_,e,m_)}var g_=(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},__=()=>({type:`effect`,cleanup:void 0,deps:null});function v_(e,t){let n=s_(`effect`,__);if(!(t&&n.deps&&g_(n.deps,t))){if(n.deps!==null&&!!t!=!!n.deps)throw Error(`tapEffect called with and without dependencies across re-renders`);c_(()=>{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 y_(e){let[t]=h_(()=>({current:e}));return t}function b_(e,t){let[n]=h_(e);return n}var x_=()=>{throw Error(`Memo reducer should not be called`)},S_=(e,t)=>{let n=t_(),[r]=f_(x_,r=>{if(r&&g_(r.deps,t))return r;let i=e();return Qg&&n.devStrictMode&&e(),{value:i,deps:t}},null);return r.value},C_=(e,t)=>S_(()=>e,t);function w_(e){let t=y_(e);v_(()=>{t.current=e});let n=t_();return C_(((...e)=>{if(Qg&&n.renderContext)throw Error(`tapEffectEvent cannot be called during render`);return t.current(...e)}),[n])}function T_(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 E_(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 D_(e,t,n=void 0,r=n_(!1)){return{type:e,root:t,markDirty:n,devStrictMode:r,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function O_(e){if(!e.isMounted)throw Error(`Tried to unmount a fiber that is already unmounted`);e.isMounted=!1,E_(e)}function k_(e,t){let n={effectTasks:[],props:t,output:void 0};return e_(e,()=>{e.renderContext=n;try{n.output=Jg(e.type,t)}finally{e.renderContext=void 0}}),n}function A_(e,t){e.isMounted=!0,Qg&&e.isNeverMounted&&e.devStrictMode===`root`&&(e.isNeverMounted=!1,T_(t),E_(e)),e.isNeverMounted=!1,T_(t)}function j_(e,t){let n=t_(),r=y_(0),i=S_(()=>(e.key,D_(e.type,n.root,()=>{r.current++,n.markDirty?.()})),[e.type,e.key,n]),a=t?S_(()=>k_(i,e.props),[i,...t,r.current]):k_(i,e.props);return v_(()=>()=>O_(i),[i]),v_(()=>{A_(i,a)},[i,a]),a.output}function M_(e,t){let n=y_(0),r=n.current,i=b_(t_,[]),a=b_(()=>()=>{n.current++,i.markDirty?.()},[]),o=b_(()=>new Map,[]),s=t?C_(e,t):e,c=S_(()=>{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=D_(c.type,i.root,a),t=k_(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=D_(c.type,i.root,a),t=k_(e,c.props);u.next=[e,t],n.push(t.output)}else u.next=k_(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 v_(()=>()=>{for(let e of o.keys()){let t=o.get(e).fiber;O_(t)}},[]),v_(()=>{for(let[e,t]of o.entries())t.next===`delete`?(t.fiber.isMounted&&O_(t.fiber),o.delete(e)):Array.isArray(t.next)?(O_(t.fiber),t.fiber=t.next[0],A_(t.fiber,t.next[1])):A_(t.fiber,t.next)},[c]),c}var N_=50,P_={schedulers:new Set([]),isScheduled:!1},F_=class{_task;_isDirty=!1;constructor(e){this._task=e}get isDirty(){return this._isDirty}markDirty(){this._isDirty=!0,P_.schedulers.add(this),I_()}runTask(){this._isDirty=!1,this._task()}},I_=()=>{P_.isScheduled||(P_.isScheduled=!0,R_())},L_=()=>{try{let e=[],t=0;for(let n of P_.schedulers)if(P_.schedulers.delete(n),n.isDirty){if(t++,t>N_)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{P_.schedulers.clear(),P_.isScheduled=!1}},R_=(()=>{if(typeof MessageChannel<`u`){let e=new MessageChannel;return e.port1.onmessage=L_,()=>e.port2.postMessage(null)}return()=>setTimeout(L_,0)})(),z_=e=>{let t=P_;P_={schedulers:new Set([]),isScheduled:!0};try{let t=e();return L_(),t}finally{P_=t}},B_=e=>{let t=b_(()=>new F_(()=>l(null)),[]),n=b_(()=>[],[]),r=S_(()=>(e.key,D_(e.type,r_(e=>{!t.isDirty&&!e()||(n.push(e),t.markDirty())}))),[e.type,e.key]);a_(r.root,r.root.committedVersion);let i=k_(r,e.props),a=y_(!1),o=y_(e.props),s=y_(i.output),c=b_(()=>new Set,[]),l=w_(e=>{if(e===null&&(a_(r.root,2),a_(r.root,1),n.forEach(e=>{Qg&&r.devStrictMode&&e(),e()}),Qg&&r.devStrictMode&&k_(r,o.current),e=k_(r,o.current)),t.isDirty)throw Error(`Scheduler is dirty, this should never happen`);i_(r.root),n.length=0,a.current&&A_(r,e),!(t.isDirty||s.current===e.output)&&(s.current=e.output,c.forEach(e=>e()))});return v_(()=>(a.current=!0,()=>{a.current=!1,O_(r)}),[r]),v_(()=>{o.current=i.props,i_(r.root),A_(r,i),!(t.isDirty||s.current===i.output)&&(s.current=i.output,c.forEach(e=>e()))}),S_(()=>({getValue:()=>s.current,subscribe:e=>(c.add(e),()=>c.delete(e))}),[])},V_=Symbol(`tap.Context`),H_=e=>({[V_]:e}),U_=(e,t,n)=>{let r=e[V_];e[V_]=t;try{return n()}finally{e[V_]=r}},W_=e=>e[V_],G_=Xg(()=>{let[e,t]=h_(()=>({renderers:{},fallbacks:[]}));return{getState:()=>e,setDataUI:C_((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:C_(e=>(t(t=>({...t,fallbacks:[...t.fallbacks,e]})),()=>{t(t=>({...t,fallbacks:t.fallbacks.filter(t=>t!==e)}))}),[])}}),K_=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},{}),q_=class{_providers=new Set;getModelContext(){return K_(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)}},J_=[],Y_={modelName:void 0,toolNames:J_},X_=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>e===t[n]),Z_=(e,t)=>{let n=e.getModelContext(),r=n.config?.modelName,i=n.tools?Object.keys(n.tools).sort():J_,a=i.length?i:J_;return r===t.modelName&&X_(a,t.toolNames)?t:{modelName:r,toolNames:a}},Q_=Xg(()=>{let e=S_(()=>new q_,[]),[t,n]=h_(()=>Z_(e,Y_));return v_(()=>(n(t=>Z_(e,t)),e.subscribe(()=>{n(t=>Z_(e,t))})),[e]),{getState:()=>Z_(e,t),getModelContext:()=>e.getModelContext(),subscribe:t=>e.subscribe(t),register:t=>e.registerModelContextProvider(t)}}),$_=e=>e.display===void 0?e.type===`human`:e.display===`standalone`,ev=Symbol(`assistant-ui.store.clientIndex`),tv=e=>e[ev],nv=H_([]),rv=()=>W_(nv),iv=(e,t)=>{let n=rv();return U_(nv,S_(()=>[...n,e],[n,e]),t)},av=new Set([`$$typeof`,`nodeType`,`then`]),ov=(e,t)=>{if(e===Symbol.toStringTag)return t;if(typeof e!=`symbol`){if(e===`toJSON`)return()=>t;if(!av.has(e))return!1}},sv=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}},cv=e=>{let t=Xg(e);return e=>{let n=t(e);return e.key===void 0?n:Zg(e.key,n)}},lv=Symbol(`assistant-ui.store.getValue`),uv=e=>{let t=e[lv];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?.()},dv=new Map;function fv(e){let t=dv.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[lv];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)},dv.set(e,t)),t}var pv=class extends sv{outputRef;index;boundFns;cachedReceiver;constructor(e,t){super(),this.outputRef=e,this.index=t}get(e,t,n){if(t===lv)return this.outputRef.current;if(t===ev)return this.index;let r=ov(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=fv(t).bind(n),this.boundFns.set(t,e)),e}return i}ownKeys(){return Object.keys(this.outputRef.current)}has(e,t){return t===lv||t===ev?!0:t in this.outputRef.current}},mv=cv(e=>{let t=y_(null),n=rv().length,r=S_(()=>new Proxy({},new pv(t,n)),[n]),i=iv(r,()=>j_(e));return t.current||=i,v_(()=>{t.current=i}),{methods:r,state:i.getState?.(),key:e.key}}),hv=e=>j_(mv(e)),gv=Symbol(`assistant-ui.store.proxiedAssistantState`),_v=e=>e===`on`||e===`subscribe`||typeof e==`symbol`,vv=e=>{class t extends sv{get(t,n){let r=ov(n,`AssistantState`);if(r!==!1)return r;let i=n;if(!_v(i))return uv(e[i]())}ownKeys(){return Object.keys(e).filter(e=>!_v(e))}has(t,n){return!_v(n)&&n in e}}return new Proxy({},new t)},yv=e=>e[gv],bv=()=>()=>{},xv=e=>{let t=(()=>{throw Error(e)});return t.source=null,t.query=null,t},Sv=new Proxy({},new class extends sv{get(e,t){if(t===`subscribe`||t===`on`)return bv;if(t===gv)return Cv;let n=ov(t,`DefaultAssistantClient`);return n===!1?xv(`You are using a component or hook that requires an AuiProvider. Wrap your component in an <AuiProvider> component.`):n}ownKeys(){return[`subscribe`,`on`,gv]}has(e,t){return t===`subscribe`||t===`on`||t===gv}}),Cv=vv(Sv),wv=()=>new Proxy({},{get(e,t){let n=ov(t,`AssistantClient`);return n===!1?xv(`The current scope does not have a "${String(t)}" property.`):n}}),Tv=(0,T.createContext)(Sv),Ev=()=>(0,T.useContext)(Tv),Dv=({value:e,children:t})=>(0,K.jsx)(Tv.Provider,{value:e,children:t}),Ov=Xg(e=>null),kv=Symbol(`assistant-ui.transform-scopes`);function Av(e,t){let n=e;if(n[kv])throw Error(`transformScopes is already attached to this resource`);n[kv]=t}function jv(e){return e[kv]}var Mv=e=>typeof e==`string`?{scope:e.split(`.`)[0],event:e}:{scope:e.scope,event:e.event},Nv=H_(null),Pv=(e,t)=>U_(Nv,e,t),Fv=()=>{let e=W_(Nv);if(!e)throw Error(`AssistantTapContext is not available`);return e},Iv=()=>Fv().clientRef,Lv=()=>{let{emit:e}=Fv(),t=rv();return w_((n,r)=>{e(n,r,t)})};function Rv(e,t){let n={...e},r=new Set,i=!0;for(;i;){i=!1;for(let e of Object.values(n)){if(e.type===Ov||r.has(e.type))continue;r.add(e.type);let a=jv(e.type);if(a){a(n,t),i=!0;break}}}let a={},o={};for(let[e,t]of Object.entries(n))t.type===Ov?o[e]=t:a[e]=t;return{rootClients:a,derivedClients:o}}var zv=e=>S_(()=>e,[...Object.entries(e).flat()]),Bv=(e,t)=>{let{rootClients:n,derivedClients:r}=Rv(e,t);return{rootClients:zv(n),derivedClients:zv(r)}},Vv=Xg(()=>b_(()=>{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)}}}},[])),Hv=()=>{if(!Qg)return null;let e=(0,T.useRef)(0),t=e.current===0;return(0,T.useState)(()=>e.current++),e.current===2?t?`child`:`root`:null};function Uv(e){let t=(0,T.useMemo)(()=>r_(e=>r(e)),[]),[n,r]=(0,T.useReducer)((e,n)=>(a_(t,e),e+ +!!n()),0);a_(t,n);let i=Hv(),a=(0,T.useMemo)(()=>(e.key,D_(e.type,t,void 0,i)),[e.type,e.key,t,i]),o=k_(a,e.props);return(0,T.useLayoutEffect)(()=>()=>O_(a),[a]),(0,T.useLayoutEffect)(()=>{i_(t),A_(a,o)}),o.output}var Wv=e=>S_(()=>e,e),Gv=Xg(({element:e,emit:t,clientRef:n})=>{let{methods:r,state:i}=Pv({clientRef:n,emit:t},()=>hv(e));return S_(()=>({state:i,methods:r}),[r,i])}),Kv=Xg(({element:e,notifications:t,clientRef:n,name:r})=>{let i=B_(Gv({element:e,emit:t.emit,clientRef:n}));return v_(()=>i.subscribe(t.notifySubscribers),[i,t]),S_(()=>{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])}),qv=Xg(()=>S_(()=>({clients:[],subscribe:void 0,on:void 0}),[])),Jv=Xg(({clients:e,clientRef:t})=>{let n=j_(Vv());v_(()=>t.parent.subscribe(n.notifySubscribers),[t,n]);let r=Wv(M_(()=>Object.keys(e).map(r=>Zg(r,Kv({element:e[r],notifications:n,clientRef:t,name:r}))),[e,n,t]));return S_(()=>({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}=Mv(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[tv(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])}),Yv=Xg(({element:e,clientRef:t,name:n})=>{let r=y_(e.props);return r.current=e.props,S_(()=>{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])}),Xv=(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}`},Zv=Xg(({clients:e,clientRef:t})=>Wv(M_(()=>Object.keys(e).map(n=>{let r=n,i=e[r];return Zg(Xv(r,i.props),Yv({element:i,clientRef:t,name:r}))}),[e,t]))),Qv=Xg(({parent:e,clients:t})=>{let{rootClients:n,derivedClients:r}=Bv(t,e),i=y_({parent:e,current:null}).current;v_(()=>{i.current=s});let a=j_(Object.keys(n).length>0?Jv({clients:n,clientRef:i}):qv()),o=j_(Zv({clients:r,clientRef:i})),s=S_(()=>{let t=e===Sv?wv():e,n=Object.create(t);Object.assign(n,{subscribe:a.subscribe??e.subscribe,on:a.on??e.on,[gv]:vv(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 $v(e,{parent:t}={parent:Ev()}){if(e)return Uv(Qv({parent:t??Sv,clients:e}));if(t===null)throw Error(`received null parent, this usage is not allowed`);return t}var Z=e=>{let t=$v(),n=yv(t),r=(0,T.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,T.useDebugValue)(r),r},ey=({children:e,condition:t})=>Z(t)?e:null;ey.displayName=`AuiIf`;var ty=e=>{let t=$v(),n=(0,T.useRef)(!1),r=n.current?null:e(t);return Z(()=>n.current?e(t):r),()=>(n.current=!0,e(t))},ny=Object.freeze({});function ry({getItemState:e,children:t}){return iy(t(ty(e)))}var iy=e=>{let t=typeof e==`object`&&e&&`type`in e?e:null,n=t?.type,r=t?.key;return(0,T.useMemo)(()=>t,[n,r,typeof t?.props==`object`&&t.props!=null&&Object.entries(t.props).length===0?ny:t?.props])??e},ay=T.createContext(!0);function oy(){throw Error(`A function wrapped in useEffectEvent can't be called during rendering.`)}var sy=`use`in T.default?()=>{try{return T.use(ay)}catch{return!1}}:()=>!1;function cy(e){let t=T.useRef(oy);return T.useInsertionEffect(()=>{t.current=e},[e]),(...e)=>{sy()&&oy();let n=t.current;return n(...e)}}var ly=(e,t)=>{let n=$v(),r=cy(t),{scope:i,event:a}=Mv(e);(0,T.useEffect)(()=>n.on({scope:i,event:a},r),[n,i,a])},uy=cv(e=>{if(e.key===void 0)throw Error(`tapClientResource: Element has no key`);return j_(mv(e))});function dy(e,t){let n=M_(()=>e().map(e=>uy(e)),t),r=S_(()=>Object.keys(n),[n]),i=S_(()=>n.reduce((e,t,n)=>(e[t.key]=n,e),{}),[n]);return{state:S_(()=>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 fy=Xg(({toolkit:e,mcpApp:t})=>{let n=M_(()=>t?[Zg(`mcpApp`,t)]:[],[t])[0],[r,i]=h_(()=>({})),a=S_(()=>({toolUIs:r,mcpApp:n,tools:Object.fromEntries(Object.entries(r).map(([e,t])=>[e,t.map(e=>e.render)]))}),[r,n]),o=Iv(),s=C_((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 v_(()=>{if(!e)return;let t=[];for(let[n,r]of Object.entries(e))r.render&&t.push(s(n,r.render,{standalone:$_(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}});Av(fy,(e,t)=>{!e.modelContext&&t.modelContext.source===null&&(e.modelContext=Q_())});var py=e=>{let[,t]=h_(e.getState);return v_(()=>(t(e.getState()),e.subscribe(()=>{t(e.getState())})),[e]),e.getState()},my=Xg(({runtime:e})=>{let t=py(e);return{getState:()=>t,remove:e.remove,__internal_getRuntime:()=>e}}),hy=Xg(({runtime:e,index:t})=>j_(my({runtime:S_(()=>e.getAttachmentByIndex(t),[e,t])}))),gy=Xg(({threadIdRef:e,messageIdRef:t,runtime:n})=>{let r=py(n),i=Lv();v_(()=>{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=dy(()=>r.attachments.map((e,t)=>Zg(e.id,hy({runtime:n,index:t}))),[r.attachments,n]),o=S_(()=>({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}}),_y=Xg(({runtime:e})=>{let t=py(e);return{getState:()=>t,addToolResult:t=>e.addToolResult(t),resumeToolCall:t=>e.resumeToolCall(t),respondToToolApproval:t=>e.respondToToolApproval(t),__internal_getRuntime:()=>e}}),vy=Xg(({runtime:e,index:t})=>j_(my({runtime:S_(()=>e.getAttachmentByIndex(t),[e,t])}))),yy=Xg(({runtime:e,index:t})=>j_(_y({runtime:S_(()=>e.getMessagePartByIndex(t),[e,t])}))),by=Xg(({runtime:e,threadIdRef:t})=>{let n=py(e),[r,i]=h_(!1),[a,o]=h_(!1),s=S_(()=>({get current(){return e.getState().id}}),[e]),c=hv(gy({runtime:e.composer,threadIdRef:t,messageIdRef:s})),l=dy(()=>n.content.map((t,n)=>Zg(`toolCallId`in t&&t.toolCallId!=null?`toolCallId-${t.toolCallId}`:`index-${n}`,yy({runtime:e,index:n}))),[n.content,e]),u=dy(()=>(n.attachments??[]).map((t,n)=>Zg(t.id,vy({runtime:e,index:n}))),[n.attachments,e]),d=S_(()=>({...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}}),xy=Xg(({runtime:e,id:t,threadIdRef:n})=>j_(by({runtime:S_(()=>e.getMessageById(t),[e,t]),threadIdRef:n}))),Sy=Xg(({runtime:e})=>{let t=py(e),n=Lv();v_(()=>{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=S_(()=>({get current(){return e.getState().threadId}}),[e]),i=hv(gy({runtime:e.composer,threadIdRef:r})),a=dy(()=>t.messages.map(t=>Zg(t.id,xy({runtime:e,id:t.id,threadIdRef:r}))),[t.messages,e,r]),o=S_(()=>({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}}),Cy=Xg(({runtime:e})=>{let t=py(e),n=Lv();return v_(()=>{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}}),wy=Xg(({runtime:e,id:t})=>j_(Cy({runtime:S_(()=>e.getItemById(t),[e,t])}))),Ty=Xg(({runtime:e,__internal_assistantRuntime:t})=>{let n=py(e),r=hv(Sy({runtime:e.main})),i=dy(()=>Object.keys(n.threadItems).map(t=>Zg(t,wy({runtime:e,id:t}))),[n.threadItems,e]),a=S_(()=>({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}}),Ey=Xg(e=>({getState:()=>e})),Dy=Xg(e=>{let[t]=h_(()=>({suggestions:(e??[]).map(e=>typeof e==`string`?{title:e,label:``,prompt:e}:{title:e.title,label:e.label,prompt:e.prompt})})),n=dy(()=>t.suggestions.map((e,t)=>Zg(t,Ey(e))),[t.suggestions]);return{getState:()=>t,suggestion:({index:e})=>n.get({index:e})}}),Oy=Xg(e=>{let t=Iv();return v_(()=>e.registerModelContextProvider(t.current.modelContext()),[e,t]),j_(Ty({runtime:e.threads,__internal_assistantRuntime:e}))}),ky=(e,t)=>{e.thread??=Ov({source:`threads`,query:{type:`main`},get:e=>e.threads().thread(`main`)}),e.threadListItem??=Ov({source:`threads`,query:{type:`main`},get:e=>e.threads().item(`main`)}),e.composer??=Ov({source:`thread`,query:{},get:e=>e.threads().thread(`main`).composer()}),!e.modelContext&&t.modelContext.source===null&&(e.modelContext=Q_()),!e.suggestions&&t.suggestions.source===null&&(e.suggestions=Dy())},Ay=Xg(e=>j_(Oy(e)));Av(Ay,(e,t)=>{ky(e,t),!e.tools&&t.tools.source===null&&(e.tools=fy({})),!e.dataRenderers&&t.dataRenderers.source===null&&(e.dataRenderers=G_())});var jy=e=>e._core?.RenderComponent,My=(0,T.memo)(({runtime:e,aui:t=null,children:n})=>{let r=$v({threads:Ay(e)},{parent:t}),i=jy(e);return(0,K.jsxs)(Dv,{value:r,children:[i&&(0,K.jsx)(i,{}),n]})}),Ny=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},Py=(e=>e?Ny(e):Ny),Fy=e=>e;function Iy(e,t=Fy){let n=T.useSyncExternalStore(e.subscribe,T.useCallback(()=>t(e.getState()),[e,t]),T.useCallback(()=>t(e.getInitialState()),[e,t]));return T.useDebugValue(n),n}var Ly=e=>{let t=Py(e),n=e=>Iy(t,e);return Object.assign(n,t),n},Ry=(e=>e?Ly(e):Ly),zy=()=>{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}},By=()=>{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=zy(),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()}}))}}},Vy=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())}},Hy=e=>new ReadableStream({start(t){return e.start?.(new Vy(t))},pull(t){return e.pull?.(new Vy(t))},cancel(t){return e.cancel?.(t)}}),Uy=()=>{let e;return[Hy({start(t){e=t}}),e]},Wy=class{_controller;_isClosed=!1;_mergeTask;constructor(e){this._controller=e;let t=Hy({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())}},Gy=e=>new ReadableStream({start(t){return e.start?.(new Wy(t))},pull(t){return e.pull?.(new Wy(t))},cancel(t){return e.cancel?.(t)}}),Ky=()=>{let e;return[Gy({start(t){e=t}}),e]},qy=class{value=-1;up(){return++this.value}},Jy=class extends TransformStream{constructor(e){super({transform(t,n){n.enqueue({...t,path:[e,...t.path]})}})}};TransformStream;var Yy=class extends TransformStream{constructor(e){let t=new qy,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]})}})}},Xy=class extends TransformStream{constructor(e){super();let t=e(super.readable);Object.defineProperty(this,"readable",{value:t,writable:!1})}},Zy=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)}})}},Qy=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},$y=Qy(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),eb=class e{_state;_parentId;constructor(e){this._state=e||{merger:By(),contentCounter:new qy}}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 Jy(this._state.contentCounter.value)))}merge(e){this._state.merger.addStream(e.pipeThrough(new Yy(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]=Uy();return this._addPart(this._withParentIdOption({type:`text`}),e),t}addReasoningPart(){let[e,t]=Uy();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??$y(),[i,a]=Ky();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 tb(e){let t=new eb;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 nb(){let{resolve:e,promise:t}=zy(),n;return[tb(r=>(n=r,n.__internal_subscribeToClose(e),t)),n]}function rb(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 ib=l(o(((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),ab=Symbol(`aui.parse-partial-json-object.meta`),ob=e=>e?.[ab],sb=e=>{if(e.length===0)return{[ab]:{state:`partial`,partialPath:[]}};try{let t=ib.default.parse(e);if(typeof t!=`object`||!t)throw Error(`argsText is expected to be an object`);return t[ab]={state:`complete`,partialPath:[]},t}catch{try{let[t,n]=rb(e),r=ib.default.parse(t);if(typeof r!=`object`||!r)throw Error(`argsText is expected to be an object`);return r[ab]={state:`partial`,partialPath:n},r}catch{return}}},cb=(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 cb(s,{state:`partial`,partialPath:o},i)},lb=(e,t)=>{let n=ob(e);if(!n)throw Error(`unable to determine object state`);return cb(e,n,t.map(String))};async function*ub(){let e=this.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)break;yield n}}finally{e.releaseLock()}}function db(e){return e[Symbol.asyncIterator]??=ub,e}var fb=Symbol.for(`aui.tool-response`),pb=class e{get[fb](){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&&fb in e}static toResponse(t){return t instanceof e?t:new e({result:t===void 0?`<no result>`:t})}};function mb(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 hb(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}var gb=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(lb(e,this.fieldPath)===`complete`){let t=hb(e,this.fieldPath);t!==void 0&&(this.resolve(t),this.dispose())}}catch(e){this.reject(e),this.dispose()}}dispose(){this.disposed=!0}},_b=class{controller;disposed=!1;fieldPath;constructor(e,t){this.controller=e,this.fieldPath=t}update(e){if(!this.disposed)try{let t=hb(e,this.fieldPath);t!==void 0&&this.controller.enqueue(t),lb(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},vb=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=hb(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)}lb(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},yb=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=hb(e,this.fieldPath);if(!Array.isArray(t))return;for(let n=0;n<t.length;n++)this.processedIndexes.has(n)||lb(e,[...this.fieldPath,n])===`complete`&&(this.controller.enqueue(t[n]),this.processedIndexes.add(n));lb(e,this.fieldPath)===`complete`&&(this.controller.close(),this.dispose())}catch(e){this.controller.error(e),this.dispose()}}dispose(){this.disposed=!0}},bb=class{argTextDeltas;handles=new Set;args=sb(``);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=sb(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 gb(t,n,e);if(this.args&&lb(this.args,e)===`complete`){let n=hb(this.args,e);if(n!==void 0){t(n);return}}this.handles.add(r),r.update(this.args)})}streamValues(...e){let t=e;return db(new ReadableStream({start:e=>{let n=new _b(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof _b){e.dispose(),this.handles.delete(e);break}}}))}streamText(...e){let t=e;return db(new ReadableStream({start:e=>{let n=new vb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof vb){e.dispose(),this.handles.delete(e);break}}}))}forEach(...e){let t=e;return db(new ReadableStream({start:e=>{let n=new yb(e,t);this.handles.add(n),n.update(this.args)},cancel:()=>{for(let e of this.handles)if(e instanceof yb){e.dispose(),this.handles.delete(e);break}}}))}},xb=class{promise;constructor(e){this.promise=e}get(){return this.promise}},Sb=class{args;response;writable;resolve;argsText=``;constructor(){let e=new TransformStream;this.writable=e.writable,this.args=new bb(e.readable);let{promise:t,resolve:n}=zy();this.resolve=n,this.response=new xb(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}},Cb=class extends Xy{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 Sb;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 pb({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=mb(()=>{let t;try{t=ib.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 pb({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 pb({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 Zy).pipeThrough(i)})}},wb=e=>typeof e==`object`&&!!e&&`~standard`in e&&e[`~standard`].version===1;function Tb(e,t,n,r){let i=e?.[n.toolName];return i?.execute?(async e=>{if(t.aborted)return new pb({result:`Tool execution was cancelled.`,isError:!0});let a=e;if(wb(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 pb({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=pb.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 pb({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 Eb(e,t,n,r,i){e?.[r.toolName]?.streamCall?.(n,{toolCallId:r.toolCallId,abortSignal:t,human:e=>i(r.toolCallId,e)})}function Db(e,t,n,r){let i=typeof e==`function`?e:()=>e,a=typeof t==`function`?t:()=>t;return new Cb({execute:e=>Tb(i(),a(),e,n),streamCall:({reader:e,...t})=>Eb(i(),a(),e,t,n),onExecutionStart:r?.onExecutionStart,onExecutionEnd:r?.onExecutionEnd})}var Ob=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({attachment:Ov({source:`message`,query:{type:`index`,index:e},get:t=>t.message().attachment({index:e})})}),children:t}),kb=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({attachment:Ov({source:`composer`,query:{type:`index`,index:e},get:t=>t.composer().attachment({index:e})})}),children:t}),Ab=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({message:Ov({source:`thread`,query:{type:`index`,index:e},get:t=>t.thread().message({index:e})}),composer:Ov({source:`message`,query:{},get:t=>t.thread().message({index:e}).composer()})}),children:t}),jb=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({part:Ov({source:`message`,query:{type:`index`,index:e},get:t=>t.message().part({index:e})})}),children:t}),Mb=Xg(({text:e,isRunning:t})=>{let n=S_(()=>({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`)}}}),Nb=({text:e,isRunning:t=!1,children:n})=>(0,K.jsx)(Dv,{value:$v({part:Mb({text:e,isRunning:t})}),children:n}),Pb=Object.freeze({type:`complete`}),Fb=Xg(({parts:e,getMessagePart:t})=>{let[n,r]=h_(!0),i=S_(()=>e[e.length-1]?.status??Pb,[e]),a=S_(()=>({parts:e,collapsed:n,status:i}),[e,n,i]);return{getState:()=>a,setCollapsed:r,part:t}}),Ib=({startIndex:e,endIndex:t,children:n})=>{let r=Z(e=>e.message.parts).slice(e,t+1),i=$v();return(0,K.jsx)(Dv,{value:$v({chainOfThought:Fb({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})},Lb=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({suggestion:Ov({source:`suggestions`,query:{index:e},get:t=>t.suggestions().suggestion({index:e})})}),children:t}),Rb=({index:e,children:t})=>(0,K.jsx)(Dv,{value:$v({queueItem:Ov({source:`composer`,query:{index:e},get:t=>t.composer().queueItem({index:e})})}),children:t}),zb=Symbol(`innerMessage`),Bb=Symbol(`innerMessages`),Vb=[],Hb=(e,t)=>{zb in e||(e[zb]=t)},Ub=e=>{let t=`messages`in e?e.messages:e,n=t[Bb]||t[zb];return n?Array.isArray(n)?n:(t[Bb]=[n],t[Bb]):Vb},Wb=Symbol(`skip-update`);function Gb(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 Kb=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)}}},qb=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()}}},Jb=class extends qb{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e;let t=e.getState();if(t===Wb)throw Error(`Entry not available in the store`);this._previousState=t}_previousState;getState=()=>(this.isConnected||this._syncState(),this._previousState);_syncState(){let e=this.binding.getState();return e===Wb||Gb(e,this._previousState)?!1:(this._previousState=e,!0)}_connect(){return this.binding.subscribe(()=>{this._syncState()&&this.notifySubscribers()})}},Yb=class extends qb{binding;get path(){return this.binding.path}constructor(e){super(),this.binding=e}_previousStateDirty=!0;_previousState;getState=()=>{if(!this.isConnected||this._previousStateDirty){let e=this.binding.getState();e!==Wb&&(this._previousState=e),this._previousStateDirty=!1}if(this._previousState===void 0)throw Error(`Entry not available in the store`);return this._previousState};_connect(){return this.binding.subscribe(()=>{this._previousStateDirty=!0,this.notifySubscribers()})}},Xb=class extends qb{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?.()}}},Zb=class extends qb{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?.()}}},Qb=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)}},$b=class extends Qb{_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)}},ex=class extends $b{get source(){return`thread-composer`}},tx=class extends $b{get source(){return`edit-composer`}},nx=class extends Qb{get source(){return`message`}remove(){throw Error(`Message attachments cannot be removed`)}},rx=Object.freeze([]),ix=Object.freeze({}),ax=e=>Object.freeze({type:`thread`,isEditing:e?.isEditing??!1,canCancel:e?.canCancel??!1,canSend:e?.canSend??!1,isEmpty:e?.isEmpty??!0,attachments:e?.attachments??rx,text:e?.text??``,role:e?.role??`user`,runConfig:e?.runConfig??ix,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,value:e?.text??``}),ox=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??rx,runConfig:e?.runConfig??ix,attachmentAccept:e?.attachmentAccept??``,dictation:e?.dictation,quote:e?.quote,parentId:e?.parentId??null,sourceId:e?.sourceId??null,value:e?.text??``}),sx=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 Zb({event:e,binding:this._core}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},cx=class extends sx{get path(){return this._core.path}get type(){return`thread`}_getState;constructor(e){let t=new Yb({path:e.path,getState:()=>ax(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 ex(new Jb({path:{...this.path,attachmentSource:`thread-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`thread-composer`}:Wb},subscribe:e=>this._core.subscribe(e)}),this._core)}},lx=class extends sx{_beginEdit;get path(){return this._core.path}get type(){return`edit`}_getState;constructor(e,t){let n=new Yb({path:e.path,getState:()=>ox(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 tx(new Jb({path:{...this.path,attachmentSource:`edit-composer`,attachmentSelector:{type:`index`,index:e},ref:`${this.path.ref}.attachments[${e}]`},getState:()=>{let t=this.getState().attachments[e];return t?{...t,source:`edit-composer`}:Wb},subscribe:e=>this._core.subscribe(e)}),this._core)}},ux=e=>e.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
57
57
|
|
|
58
58
|
`),dx=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=pb.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)}},fx=Object.freeze({type:`complete`}),px=(e,t,n)=>{if(e.role!==`assistant`)return fx;if(n.type===`tool-call`)return n.result?fx:e.status;let r=t===Math.max(0,e.content.length-1);return e.status.type===`requires-action`?fx:r?e.status:fx},mx=(e,t)=>{let n=e.content[t];if(!n)return Wb;let r=px(e,t,n);return Object.freeze({...n,[zb]:n[zb],status:r})},hx=class{_core;_threadBinding;get path(){return this._core.path}constructor(e,t){this._core=e,this._threadBinding=t,this.composer=new lx(new Xb({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 ux(this.getState())}subscribe(e){return this._core.subscribe(e)}getMessagePartByIndex(e){if(e<0)throw Error(`Message part index must be >= 0`);return new dx(new Jb({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.content[${e}]`,messagePartSelector:{type:`index`,index:e}},getState:()=>mx(this.getState(),e),subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getMessagePartByToolCallId(e){return new dx(new Jb({path:{...this.path,ref:this.path.ref+`${this.path.ref}.content[toolCallId=${JSON.stringify(e)}]`,messagePartSelector:{type:`toolCallId`,toolCallId:e}},getState:()=>{let t=this._core.getState(),n=t.content.findIndex(t=>t.type===`tool-call`&&t.toolCallId===e);return n===-1?Wb:mx(t,n)},subscribe:e=>this._core.subscribe(e)}),this._core,this._threadBinding)}getAttachmentByIndex(e){return new nx(new Jb({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.attachments[${e}]`,attachmentSource:`message`,attachmentSelector:{type:`index`,index:e}},getState:()=>{let t=this.getState().attachments?.[e];return t?{...t,source:`message`}:Wb},subscribe:e=>this._core.subscribe(e)}))}},gx=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{},...e.stream?{stream:e.stream}:{}}),_x=e=>({parentId:e.parentId??null,sourceId:e.sourceId??null,runConfig:e.runConfig??{}}),vx=(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},yx=(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})},bx=class{get path(){return this._threadBinding.path}get __internal_threadBinding(){return this._threadBinding}_threadBinding;constructor(e,t){let n=new Jb({path:e.path,getState:()=>yx(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 cx(new Xb({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(vx(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(_x(e))}resumeRun(e){return this._threadBinding.getState().resumeRun(gx(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 hx(new Jb({path:e,getState:()=>{let{message:e,parentId:n,index:r}=t()??{},{messages:i,speech:a}=this._threadBinding.getState();if(!e||n===void 0||r===void 0)return Wb;let o=this._threadBinding.getState().getBranches(e.id);return{...e,[zb]:e[zb],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 Zb({event:e,binding:this._threadBinding}),this._eventSubscriptionSubjects.set(e,n)),n.subscribe(t)}},xx=(0,T.createContext)(null),Sx=()=>(0,T.useContext)(xx),Cx=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}},wx=Promise.resolve(),Tx=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}),Ex=(e,t)=>{if(t===void 0)return Wb;let n=e.getItemById(t);return n?{id:n.id,remoteId:n.remoteId,externalId:n.externalId,title:n.title,status:n.status,custom:n.custom,isMain:n.id===e.mainThreadId}:Wb},Dx=class{_core;_runtimeFactory;_getState;constructor(e,t=bx){this._core=e,this._runtimeFactory=t;let n=new Yb({path:{},getState:()=>Tx(e),subscribe:t=>e.subscribe(t)});this._getState=n.getState.bind(n),this._mainThreadListItemRuntime=new Cx(new Jb({path:{ref:`threadItems[main]`,threadSelector:{type:`main`}},getState:()=>Ex(this._core,this._core.mainThreadId),subscribe:e=>this._core.subscribe(e)}),this._core),this.main=new t(new Xb({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?.()??wx}loadMore(){return this._core.loadMore?.()??wx}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 Xb({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 Cx(new Jb({path:{ref:`threadItems[${e}]`,threadSelector:{type:`index`,index:e}},getState:()=>Ex(this._core,this._core.threadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getArchivedItemByIndex(e){return new Cx(new Jb({path:{ref:`archivedThreadItems[${e}]`,threadSelector:{type:`archiveIndex`,index:e}},getState:()=>Ex(this._core,this._core.archivedThreadIds[e]),subscribe:e=>this._core.subscribe(e)}),this._core)}getItemById(e){return new Cx(new Jb({path:{ref:`threadItems[threadId=${e}]`,threadSelector:{type:`threadId`,threadId:e}},getState:()=>Ex(this._core,e),subscribe:e=>this._core.subscribe(e)}),this._core)}},Ox=class{_core;threads;_thread;constructor(e){this._core=e,this.threads=new Dx(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)}},kx=class{_contextProvider=new q_;registerModelContextProvider(e){return this._contextProvider.registerModelContextProvider(e)}getModelContextProvider(){return this._contextProvider}},Ax=Object.freeze([]),jx=`DEFAULT_THREAD_ID`,Mx=Object.freeze([jx]),Nx=Object.freeze({id:jx,remoteId:void 0,externalId:void 0,status:`regular`}),Px=Promise.resolve(),Fx=Object.freeze({[jx]:Nx}),Ix=class{threadFactory;_mainThreadId=jx;_threads=Mx;_archivedThreads=Ax;_threadData=Fx;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 Px}_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??jx,i=e.threads??Ax,a=e.archivedThreads??Ax,o=n.threadId??jx,s=n.threads??Ax,c=n.archivedThreads??Ax;!t&&o===r&&s===i&&c===a||((s!==i||c!==a||o!==r)&&(this._threadData={...Fx,...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)??Ax),c!==a&&(this._archivedThreads=this.adapter.archivedThreads?.map(e=>e.id)??Ax),(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()}},Lx=Qy(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,7),Rx=Symbol(`autoStatus`),zx=Object.freeze(Object.assign({type:`running`},{[Rx]:!0})),Bx=Object.freeze(Object.assign({type:`complete`,reason:`unknown`},{[Rx]:!0})),Vx=Object.freeze(Object.assign({type:`requires-action`,reason:`tool-calls`},{[Rx]:!0})),Hx=Object.freeze(Object.assign({type:`requires-action`,reason:`interrupt`},{[Rx]:!0})),Ux=e=>e[Rx]===!0,Wx=(e,t,n,r,i)=>e&&i?Object.assign({type:`incomplete`,reason:`error`,error:i},{[Rx]:!0}):e&&t?zx:n?Hx:r?Vx:Bx,Gx=(e,t)=>{if(e.startsWith(`data-`))return{type:`data`,name:e.substring(5),data:t}},Kx=(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-${Lx()}`,...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:sb(e.argsText??``)??{},argsText:e.argsText??``}}default:{let n=Gx(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=Gx(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=>Gx(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}`)}},qx={fromArray:e=>{let t=e.map(e=>Kx(e,Lx(),Wx(!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=Wx(!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:Kx(e,e.id,n)}})}}},Jx=e=>e.next?Jx(e.next):`current`in e?e:null,Yx=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}},Xx=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],(Jx(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 Yx(()=>{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=Jx(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=Jx(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 Zx(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 Qx(e,t){return e.length===t.length?e.every((e,n)=>e.id===t[n].id):!1}function $x(e){let t=Lx();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 eS(e){let t=[];for(let n of e)n.type!==`text`&&t.push($x(n));return t}var tS=e=>e.status.type===`complete`,nS=class extends Kb{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=>!tS(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(tS(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&&!Zx({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??Lx(),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(!Zx({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(!tS(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)}}},rS=class extends nS{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()}},iS=class extends nS{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=ux(r),this.setText(this._previousText),this.setRole(r.role),r.role===`user`?(this._previousAttachments=[...r.attachments??[],...eS(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=ux(e),r=!Qx(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()}},aS=class{_contextProvider;_subscriptions=new Set;_isInitialized=!1;repository=new Xx;_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 rS(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 iS(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(ux(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:Lx(),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:Lx(),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(qx.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)}}},oS=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 sS(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function cS(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=>cS(e,t+1)):sS(e)?Object.entries(e).every(([e,n])=>typeof e==`string`&&cS(n,t+1)):!1}var lS=100,uS=(e,t,n)=>{if(e===t)return!0;if(n>lS||e==null||t==null)return!1;if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:e.every((e,r)=>uS(e,t[r],n+1));if(Array.isArray(t)||!sS(e)||!sS(t))return!1;let r=Object.keys(e),i=Object.keys(t);return r.length===i.length?r.every(r=>Object.hasOwn(t,r)&&uS(e[r],t[r],n+1)):!1},dS=(e,t)=>!cS(e)||!cS(t)?!1:uS(e,t,0),fS=e=>{try{return JSON.parse(e),!0}catch{return!1}},pS=e=>{try{return JSON.parse(e)}catch{return}},mS=(e,t)=>{let n=pS(e),r=pS(t);return n===void 0||r===void 0?!1:dS(n,r)},hS=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]=nb();this._controller=t;let n=Db(()=>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 Zy).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)&&fS(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)mS(e.argsText,t.argsText)&&(e.argsText=t.argsText),r=!1;else if(!t.argsText.startsWith(e.argsText))if(fS(e.argsText)&&fS(t.argsText)&&mS(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 pb({result:e.result,artifact:e.artifact,isError:e.isError,...e.modelContent===void 0?{}:{modelContent:e.modelContent}})),t.close()}e.messages&&this._processMessages(e.messages)}}},gS=Object.freeze([]),_S=(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},vS=(e,t)=>e&&t[t.length-1]?.role!==`assistant`,yS=class extends aS{_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 oS;_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??gS;_S(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};_S(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 oS;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=Wx(i===(e.messages?.length??0)-1,t,!1,!1,void 0);if(n&&(n.role!==`assistant`||!Ux(n.status)||n.status===a))return n;let o=Kx(e.convertMessage(r,i),i.toString(),a);return Hb(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;vS(t,a)&&(o=Lx(),this.repository.addOrUpdateMessage(a.at(-1)?.id??null,Kx({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 hS(()=>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(ux(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 Xx;t.import(qx.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(Ub))}},bS=e=>e.adapters?.threadList??{},xS=class extends kx{threads;constructor(e){super(),this.threads=new Ix(bS(e),()=>new yS(this._contextProvider,e))}setAdapter(e){this.threads.__internal_setAdapter(bS(e)),this.threads.getMainThreadRuntimeCore().__internal_setAdapter(e)}},SS=e=>{let[t]=(0,T.useState)(()=>new xS(e));(0,T.useEffect)(()=>{t.setAdapter(e)});let{modelContext:n}=Sx()??{};return(0,T.useEffect)(()=>{if(n)return t.registerModelContextProvider(n)},[n,t]),(0,T.useMemo)(()=>new Ox(t),[t])},CS=(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,wS=()=>null,TS=(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??wS;default:throw Error(`Unknown message role: ${t}`)}},ES=({components:e})=>(0,K.jsx)(TS(e,Z(e=>e.message.role),Z(e=>e.message.composer.isEditing)),{}),DS=(0,T.memo)(({index:e,components:t})=>(0,K.jsx)(Ab,{index:e,children:(0,K.jsx)(ES,{components:t})}),(e,t)=>e.index===t.index&&CS(e.components,t.components));DS.displayName=`ThreadPrimitive.MessageByIndex`;var OS=({children:e})=>{let t=Z(e=>e.thread.messages.length);return(0,T.useMemo)(()=>t===0?null:Array.from({length:t},(t,n)=>(0,K.jsx)(Ab,{index:n,children:(0,K.jsx)(ry,{getItemState:e=>e.thread().message({index:n}).getState(),children:t=>e({get message(){return t()}})})},n)),[t,e])},kS=({components:e,children:t})=>e?(0,K.jsx)(OS,{children:()=>(0,K.jsx)(ES,{components:e})}):(0,K.jsx)(OS,{children:t});kS.displayName=`ThreadPrimitive.Messages`;var AS=(0,T.memo)(kS,(e,t)=>e.children||t.children?e.children===t.children:CS(e.components,t.components)),jS=e=>{let t=e.message.metadata;if(!(!t||typeof t!=`object`))return t.custom?.quote},MS=class extends Error{componentName;constructor(e,t=`Component "${e}" is not in the generative-ui allowlist.`){super(t),this.name=`GenerativeUIRenderError`,this.componentName=e}},NS=e=>typeof e==`object`&&!!e,PS=(e,t,n,r)=>{if(e==null)return null;if(typeof e==`string`)return e;if(!NS(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 MS(i)}let l=o?.length?o.map((e,i)=>PS(e,t,n,`${r}/${i}`)):void 0;return(0,T.createElement)(c,{...a??{},key:s??r},...l??[])},FS=e=>{if(!e||e.root===void 0||e.root===null)return[];let t=e.root;return Array.isArray(t)?t:[t]},IS=({spec:e,components:t,Fallback:n})=>(0,K.jsx)(K.Fragment,{children:(0,T.useMemo)(()=>FS(e),[e]).map((e,r)=>PS(e,t,n,`${r}`))});IS.displayName=`GenerativeUIRender`;var LS=({components:e,spec:t,Fallback:n})=>{let r=Z(e=>{let t=e.part;return t?.type===`generative-ui`?t.spec:void 0}),i=t??r;return i?(0,K.jsx)(IS,{spec:i,components:e,Fallback:n}):null};LS.displayName=`MessagePrimitive.GenerativeUI`;var RS=`ui://`,zS=e=>!!e?.startsWith(RS),BS=e=>Symbol.iterator in e,VS=e=>`entries`in e,HS=(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},US=(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 WS(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:BS(e)&&BS(t)?VS(e)&&VS(t)?HS(e,t):US(e,t):HS({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function GS(e){let t=T.useRef(void 0);return n=>{let r=e(n);return WS(t.current,r)?t.current:t.current=r}}var KS=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})}}},qS=(e,t)=>{let n=[];if(t){let t=KS(`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=KS(`toolGroup`),r=KS(`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},JS=e=>{let t=Z(GS(e=>e.message.parts.map(e=>e.type)));return(0,T.useMemo)(()=>t.length===0?[]:qS(t,e),[t,e])},YS=({Fallback:e,...t})=>{let n=Z(n=>n.tools.toolUIs[t.toolName]?.[0]?.render??e);return n?(0,K.jsx)(n,{...t}):null},XS=(e,t,n)=>e.renderers[t]?.[0]||(e.fallbacks[0]??n),ZS=({Fallback:e,...t})=>{let n=Z(n=>XS(n.dataRenderers,t.name,e));return n?(0,K.jsx)(n,{...t}):null},QS={Text:()=>null,Reasoning:()=>null,Source:()=>null,Image:()=>null,File:()=>null,Unstable_Audio:()=>null,ToolGroup:({children:e})=>e,ReasoningGroup:({children:e})=>e},$S=({components:{Text:e=QS.Text,Reasoning:t=QS.Reasoning,Image:n=QS.Image,Source:r=QS.Source,File:i=QS.File,Unstable_Audio:a=QS.Unstable_Audio,tools:o={},data:s,generativeUI:c}={}})=>{let l=$v(),u=Z(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)(YS,{...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)(ZS,{...u,Fallback:e})}case`generative-ui`:return c?.components?(0,K.jsx)(IS,{spec:u.spec,components:c.components,Fallback:c.Fallback}):null;default:return console.warn(`Unknown message part type: ${d}`),null}},eC=(0,T.memo)(({index:e,components:t})=>(0,K.jsx)(jb,{index:e,children:(0,K.jsx)($S,{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);eC.displayName=`MessagePrimitive.PartByIndex`;var tC=({status:e,component:t})=>(0,K.jsx)(Nb,{text:``,isRunning:e.type===`running`,children:(0,K.jsx)(t,{type:`text`,text:``,status:e})}),nC=Object.freeze({type:`complete`}),rC=Object.freeze({type:`running`}),iC=(0,T.memo)(({components:e})=>{let t=Z(e=>e.message.status??nC);return e?.Empty?(0,K.jsx)(e.Empty,{status:t}):t.type===`running`?(0,K.jsx)(tC,{status:t,component:e?.Text??QS.Text}):null},(e,t)=>e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),aC=(0,T.memo)(({components:e,enabled:t})=>Z(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)(iC,{components:e}):null,(e,t)=>e.enabled===t.enabled&&e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),oC=(0,T.memo)(({Quote:e})=>{let t=Z(jS);return t?(0,K.jsx)(e,{text:t.text,messageId:t.messageId}):null});function sC(e,t){return(e.toolUIs[t.toolName]?.[0]?.render??null)||(zS(t.mcp?.app?.resourceUri)&&e.mcpApp?e.mcpApp.render:null)}var cC=()=>{let e=$v(),t=Z(e=>e.part),n=Z(e=>e.part.type===`tool-call`?sC(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})},lC=()=>{let e=Z(e=>e.part),t=Z(e=>e.part.type===`data`?XS(e.dataRenderers,e.part.name,void 0)??null:null);return!t||e.type!==`data`?null:(0,K.jsx)(t,{...e})},uC=()=>{let e=Z(e=>e.part.type);return e===`tool-call`?(0,K.jsx)(cC,{}):e===`data`?(0,K.jsx)(lC,{}):null},dC=Object.freeze({type:`text`,text:``,status:rC}),fC=({index:e,children:t})=>{let n=$v(),r=Z(e=>e.dataRenderers);return(0,K.jsx)(jb,{index:e,children:(0,K.jsx)(ry,{getItemState:t=>t.message().part({index:e}).getState(),children:i=>t({get part(){let t=i();if(t.type===`tool-call`){let r=sC(n.tools().getState(),t)!==null,i=n.message().part({index:e});return{...t,toolUI:r?(0,K.jsx)(cC,{}):null,addResult:i.addToolResult,resume:i.resumeToolCall,respondToApproval:i.respondToToolApproval}}if(t.type===`data`){let e=XS(r,t.name,void 0)!==void 0;return{...t,dataRendererUI:e?(0,K.jsx)(lC,{}):null}}return t}})})})},pC=({children:e})=>{let t=Z(e=>e.message.parts.length),n=Z(e=>(e.message.status?.type??`complete`)===`running`);return t===0?t===0&&n?(0,K.jsx)(Nb,{text:``,isRunning:!0,children:e({part:dC})}):null:(0,K.jsx)(K.Fragment,{children:Array.from({length:t},(t,n)=>(0,K.jsx)(fC,{index:n,children:t=>e(t)??(0,K.jsx)(uC,{})},n))})},mC=({components:e,unstable_showEmptyOnNonTextEnd:t=!0,children:n})=>n?(0,K.jsx)(pC,{children:n}):(0,K.jsx)(hC,{components:e,unstable_showEmptyOnNonTextEnd:t});mC.displayName=`MessagePrimitive.Parts`;var hC=({components:e,unstable_showEmptyOnNonTextEnd:t})=>{let n=Z(e=>e.message.parts.length),r=JS(!!e?.ChainOfThought),i=(0,T.useMemo)(()=>n===0?(0,K.jsx)(iC,{components:e}):r.map(t=>{if(t.type===`single`)return(0,K.jsx)(eC,{index:t.index,components:e},t.index);if(t.type===`chainOfThoughtGroup`){let n=e?.ChainOfThought;return n?(0,K.jsx)(Ib,{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??QS.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)(eC,{index:i,components:e},`part-${i}`)})},`tool-${t.startIndex}`);else return(0,K.jsx)(e?.ReasoningGroup??QS.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)(eC,{index:i,components:e},`part-${i}`)})},`reasoning-${t.startIndex}`)}),[r,e,n]);return(0,K.jsxs)(K.Fragment,{children:[e?.Quote&&(0,K.jsx)(oC,{Quote:e.Quote}),i,(0,K.jsx)(aC,{components:e,enabled:t})]})},gC=Symbol.for(`@assistant-ui/groupBy.memoKey`),_C=e=>{let t=e.nextChildIdx++;return e.nodeKey===``?String(t):`${e.nodeKey}.${t}`},vC=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:_C(e),indices:[],children:[],nextChildIdx:0})}let o=n[n.length-1];o.children.push({type:`part`,index:t,nodeKey:_C(o)});for(let e=1;e<n.length;e++)n[e].indices.push(t)}for(;n.length>1;)r();return t.children},yC=Object.freeze({type:`complete`}),bC=(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`}}},xC=()=>{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.")},SC=(e,t,n)=>{if(e.type===`part`)return(0,K.jsx)(fC,{index:e.index,children:({part:e})=>n({part:e,children:(0,K.jsx)(xC,{})})},`part-${e.index}`);let r=t[e.indices.at(-1)]?.status??yC;return(0,K.jsx)(T.Fragment,{children:n({part:{type:e.key,status:r,indices:e.indices},children:(0,K.jsx)(K.Fragment,{children:e.children.map(e=>SC(e,t,n))})})},e.nodeKey)},CC=({groupBy:e,indicator:t=`no-text`,children:n})=>{let r=Z(GS(e=>e.message.parts)),i=Z(e=>e.tools.toolUIs),a=Z(e=>t===`never`?!1:e.message.status?.type===`running`);return(0,K.jsxs)(K.Fragment,{children:[(0,T.useMemo)(()=>{let t={toolUIs:i};return vC(r.map(n=>e(n,t)??[]))},[r,e[gC]??e,i]).map(e=>SC(e,r,n)),bC(t,r,a)&&n({part:{type:`indicator`},children:(0,K.jsx)(xC,{})})]})};CC.displayName=`MessagePrimitive.GroupedParts`;var wC=(0,T.memo)(({children:e})=>{let t=Z(jS);return t?(0,K.jsx)(K.Fragment,{children:e(t)}):null});wC.displayName=`MessagePrimitive.Quote`;var TC=(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}},EC=({components:e})=>{let t=Z(e=>e.attachment);if(!t)return null;let n=TC(e,t);return n?(0,K.jsx)(n,{}):null},DC=(0,T.memo)(({index:e,components:t})=>(0,K.jsx)(Ob,{index:e,children:(0,K.jsx)(EC,{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);DC.displayName=`MessagePrimitive.AttachmentByIndex`;var OC=({children:e})=>{let t=Z(e=>e.message.role===`user`?(e.message.attachments??[]).length:0);return(0,T.useMemo)(()=>Array.from({length:t},(t,n)=>(0,K.jsx)(Ob,{index:n,children:(0,K.jsx)(ry,{getItemState:e=>e.message().attachment({index:n}).getState(),children:t=>e({get attachment(){return t()}})})},n)),[t,e])},kC=({components:e,children:t})=>e?(0,K.jsx)(OC,{children:({attachment:t})=>{let n=TC(e,t);return n?(0,K.jsx)(n,{}):null}}):(0,K.jsx)(OC,{children:t});kC.displayName=`MessagePrimitive.Attachments`;var AC=(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}},jC=({components:e})=>{let t=Z(e=>e.attachment);if(!t)return null;let n=AC(e,t);return n?(0,K.jsx)(n,{}):null},MC=(0,T.memo)(({index:e,components:t})=>(0,K.jsx)(kb,{index:e,children:(0,K.jsx)(jC,{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);MC.displayName=`ComposerPrimitive.AttachmentByIndex`;var NC=({children:e})=>{let t=Z(e=>e.composer.attachments.length);return(0,T.useMemo)(()=>Array.from({length:t},(t,n)=>(0,K.jsx)(kb,{index:n,children:(0,K.jsx)(ry,{getItemState:e=>e.composer().attachment({index:n}).getState(),children:t=>e({get attachment(){return t()}})})},n)),[t,e])},PC=({components:e,children:t})=>e?(0,K.jsx)(NC,{children:({attachment:t})=>{let n=AC(e,t);return n?(0,K.jsx)(n,{}):null}}):(0,K.jsx)(NC,{children:t});PC.displayName=`ComposerPrimitive.Attachments`;var FC=(0,T.memo)(({children:e})=>{let t=Z(e=>e.composer.queue.length);return(0,T.useMemo)(()=>Array.from({length:t},(t,n)=>(0,K.jsx)(Rb,{index:n,children:(0,K.jsx)(ry,{getItemState:e=>e.composer().queueItem({index:n}).getState(),children:t=>e({get queueItem(){return t()}})})},n)),[t,e])});FC.displayName=`ComposerPrimitive.Queue`;var IC=({children:e})=>Z(e=>e.part.status.type===`running`)?e:null;IC.displayName=`MessagePartPrimitive.InProgress`;var LC=({components:e})=>{let t=e.Suggestion;return(0,K.jsx)(t,{})},RC=(0,T.memo)(({index:e,components:t})=>(0,K.jsx)(Lb,{index:e,children:(0,K.jsx)(LC,{components:t})}),(e,t)=>e.index===t.index&&e.components.Suggestion===t.components.Suggestion);RC.displayName=`ThreadPrimitive.SuggestionByIndex`;var zC=({children:e})=>{let t=Z(e=>e.suggestions.suggestions.length);return(0,T.useMemo)(()=>t===0?null:Array.from({length:t},(t,n)=>(0,K.jsx)(Lb,{index:n,children:(0,K.jsx)(ry,{getItemState:e=>e.suggestions().suggestion({index:n}).getState(),children:t=>e({get suggestion(){return t()}})})},n)),[t,e])},BC=({components:e,children:t})=>e?(0,K.jsx)(zC,{children:()=>(0,K.jsx)(LC,{components:e})}):(0,K.jsx)(zC,{children:t});BC.displayName=`ThreadPrimitive.Suggestions`;var VC=(0,T.memo)(BC,(e,t)=>e.children||t.children?e.children===t.children:e.components.Suggestion===t.components.Suggestion),HC=e=>Z(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)}),UC=({children:e,...t})=>HC(t)?e:null;UC.displayName=`ComposerPrimitive.If`;var WC=()=>{let e=$v(),t=Z(e=>!e.composer.canSend||e.thread.isRunning&&!e.thread.capabilities.queue);return{send:(0,T.useCallback)(t=>{e.composer().send(t)},[e]),disabled:t}},GC=()=>{let e=$v(),t=Z(e=>!e.composer.canCancel);return{cancel:(0,T.useCallback)(()=>{e.composer().cancel()},[e]),disabled:t}},KC=()=>{let e=$v(),t=Z(e=>e.composer.dictation!=null||!e.thread.capabilities.dictation||!e.composer.isEditing);return{startDictation:(0,T.useCallback)(()=>{e.composer().startDictation()},[e]),disabled:t}},qC=()=>{let e=$v(),t=Z(e=>!e.composer.isEditing);return{addAttachment:(0,T.useCallback)(t=>e.composer().addAttachment(t),[e]),disabled:t}},JC=({prompt:e,send:t,clearComposer:n=!0})=>{let r=$v(),i=Z(e=>e.thread.isDisabled),a=t??!1;return{trigger:(0,T.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}},YC=()=>Z(e=>e.message.status?.type===`incomplete`&&e.message.status.reason===`error`?e.message.status.error??`An error occurred`:void 0),XC=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}},ZC=/:([\w-]{1,64})\[([^\]\n]{1,1024})\](?:\{name=([^}\n]{1,1024})\})?/gu,QC={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(ZC)){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 $C(e,t){function n(n){let r=(0,T.useContext)(e);if(!n?.optional&&!r)throw Error(`This component must be used within ${t}.`);return r}return n}function ew(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 tw=(0,T.createContext)(null),{useThreadViewport:nw,useThreadViewportStore:rw}=ew($C(tw,`ThreadPrimitive.Viewport`),`useThreadViewport`),iw=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()}}}}},aw=(e={})=>{let t=new Set,n=iw(e=>{a.setState({height:{...a.getState().height,viewport:e}})}),r=iw(e=>{a.setState({height:{...a.getState().height,inset:e}})}),i=(e,t)=>(a.setState({element:{...a.getState().element,[e]:t}}),()=>{a.getState().element[e]===t&&a.setState({element:{...a.getState().element,[e]:null}})}),a=Ry(()=>({isAtBottom:!0,scrollToBottom:({behavior:e=`auto`}={})=>{for(let n of t)n({behavior:e})},onScrollToBottom:e=>(t.add(e),()=>{t.delete(e)}),turnAnchor:e.turnAnchor??`bottom`,topAnchorMessageClamp:{tallerThan:e.topAnchorMessageClamp?.tallerThan??`10em`,visibleHeight:e.topAnchorMessageClamp?.visibleHeight??`6em`},height:{viewport:0,inset:0},element:{viewport:null,anchor:null,target:null},targetConfig:null,topAnchorTurn:null,registerViewport:n.register,registerContentInset:r.register,registerViewportElement:e=>i(`viewport`,e),registerAnchorElement:e=>i(`anchor`,e),registerAnchorTargetElement:(e,t)=>(a.setState({element:{...a.getState().element,target:e},targetConfig:e&&t?t:null}),()=>{a.getState().element.target===e&&a.setState({element:{...a.getState().element,target:null},targetConfig:null})}),setTopAnchorTurn:e=>{a.setState({topAnchorTurn:e})}}));return a},ow=e=>e,sw=e=>{let t=rw({optional:!0}),[n]=(0,T.useState)(()=>aw(e));return(0,T.useEffect)(()=>t?.getState().onScrollToBottom(()=>{n.getState().scrollToBottom()}),[t,n]),(0,T.useEffect)(()=>{if(t)return n.subscribe(e=>{t.getState().isAtBottom!==e.isAtBottom&&ow(t).setState({isAtBottom:e.isAtBottom})})},[n,t]),n},cw=({children:e,options:t={}})=>{let n=sw(t),[r]=(0,T.useState)(()=>({useThreadViewport:n}));return(0,K.jsx)(tw.Provider,{value:r,children:e})},lw=()=>((0,T.useEffect)(()=>{},[$v()]),null),uw=(0,T.memo)(({children:e,aui:t,runtime:n})=>(0,K.jsxs)(My,{runtime:n,aui:t??null,children:[(0,K.jsx)(lw,{}),(0,K.jsx)(cw,{children:e})]}));function dw(e){let t=$v(),n=Z(()=>t.composer.source?t.composer().__internal_getRuntime?.()??null:null);if(!n&&!e?.optional)throw Error(`ComposerRuntime is not available`);return n}var fw=Object.defineProperty,pw=(e,t)=>{let n={};for(var r in e)fw(n,r,{get:e[r],enumerable:!0});return t||fw(n,Symbol.toStringTag,{value:`Module`}),n},mw=Symbol.for(`react.lazy`),hw=T.use;function gw(e){return typeof e==`object`&&!!e&&`then`in e}function _w(e){return typeof e==`object`&&!!e&&`$$typeof`in e&&e.$$typeof===mw&&`_payload`in e&&gw(e._payload)}function vw(e){let t=yw(e),n=T.forwardRef((e,n)=>{let{children:r,...i}=e;_w(r)&&typeof hw==`function`&&(r=hw(r._payload));let a=T.Children.toArray(r),o=a.find(xw);if(o){let e=o.props.children,r=a.map(t=>t===o?T.Children.count(e)>1?T.Children.only(null):T.isValidElement(e)?e.props.children:null:t);return(0,K.jsx)(t,{...i,ref:n,children:T.isValidElement(e)?T.cloneElement(e,void 0,r):null})}return(0,K.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}function yw(e){let t=T.forwardRef((e,t)=>{let{children:n,...r}=e;if(_w(n)&&typeof hw==`function`&&(n=hw(n._payload)),T.isValidElement(n)){let e=Cw(n),i=Sw(r,n.props);return n.type!==T.Fragment&&(i.ref=t?Li(t,e):e),T.cloneElement(n,i)}return T.Children.count(n)>1?T.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var bw=Symbol(`radix.slottable`);function xw(e){return T.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===bw}function Sw(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 Cw(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 ww=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=vw(`Primitive.${t}`),r=T.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}},{}),Tw=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`];function Ew(e){let t=(0,T.forwardRef)(({render:t,asChild:n,children:r,...i},a)=>{let o=e;if(t&&(0,T.isValidElement)(t)){let e=r===void 0?t.props.children:r;return(0,K.jsx)(o,{...i,asChild:!0,ref:a,children:(0,T.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 Dw(e){let t=ww[e],n=Ew(t);return n.displayName=`Primitive.${e}`,n}var Ow=Tw.reduce((e,t)=>(e[t]=Dw(t),e),{}),kw=(e,t,n=[])=>{let r=(0,T.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)(Ow.button,{...a,type:`button`,ref:r,disabled:a.disabled||!o,onClick:ia(a.onClick,o)})});return r.displayName=e,r},Aw=e=>Z(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)}),jw=({children:e,...t})=>Aw(t)?e:null;jw.displayName=`MessagePrimitive.If`;var Mw=(0,T.createContext)(null),Nw=()=>(0,T.useContext)(Mw),Pw=({children:e})=>{let t=(0,T.useRef)(new Map),n=(0,T.useRef)([]),r=(0,T.useCallback)(()=>{let e=Array.from(t.current.entries());e.sort((e,t)=>t[1]-e[1]),n.current=e.map(([e])=>e)},[]),i=(0,T.useCallback)((e,n)=>{let i=n?.priority??0;return t.current.set(e,i),r(),()=>{t.current.delete(e),r()}},[r]),a=(0,T.useCallback)(()=>n.current,[]),o=(0,T.useMemo)(()=>({register:i,getPlugins:a}),[i,a]);return(0,K.jsx)(Mw.Provider,{value:o,children:e})},Fw=(0,T.createContext)(null),Iw=(0,T.createContext)(null),Lw=()=>{let e=(0,T.useContext)(Fw);if(!e)throw Error(`useTriggerPopoverRootContext must be used within ComposerPrimitive.TriggerPopoverRoot`);return e},Rw=()=>(0,T.useContext)(Fw),zw=()=>{let e=(0,T.useContext)(Iw);if(!e)throw Error(`useTriggerPopoverAriaPublish must be used within ComposerPrimitive.TriggerPopoverRoot`);return e},Bw=()=>{let e=Lw();return(0,T.useSyncExternalStore)(e.subscribe,e.getTriggers,e.getTriggers)},Vw=new Map,Hw=()=>()=>{},Uw=()=>Vw,Ww=()=>{let e=Rw();return(0,T.useSyncExternalStore)(e?e.subscribe:Hw,e?e.getTriggers:Uw,e?e.getTriggers:Uw)},Gw=()=>null,Kw=()=>{let e=Rw();return(0,T.useSyncExternalStore)(e?e.subscribeAria:Hw,e?e.getActiveAria:Gw,e?e.getActiveAria:Gw)};function qw(){let e=(0,T.useRef)(new Set);return{notify:(0,T.useCallback)(()=>{for(let t of e.current)t()},[]),subscribe:(0,T.useCallback)(t=>(e.current.add(t),()=>{e.current.delete(t)}),[])}}var Jw=({children:e})=>{let t=(0,T.useRef)(new Map),n=(0,T.useRef)(new Set),{notify:r,subscribe:i}=qw(),a=(0,T.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,T.useCallback)(()=>t.current,[]),s=(0,T.useCallback)(e=>(n.current.add(e),()=>{n.current.delete(e)}),[]),c=(0,T.useRef)(null),l=(0,T.useRef)(null),{notify:u,subscribe:d}=qw(),f=(0,T.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,T.useCallback)(()=>c.current,[]),m=(0,T.useMemo)(()=>({register:a,getTriggers:o,subscribe:i,subscribeLifecycle:s,getActiveAria:p,subscribeAria:d}),[a,o,i,s,p,d]),h=(0,T.useMemo)(()=>({setActiveAria:f}),[f]);return(0,K.jsx)(Fw.Provider,{value:m,children:(0,K.jsx)(Iw.Provider,{value:h,children:e})})},Yw=({children:e})=>Nw()?(0,K.jsx)(Jw,{children:e}):(0,K.jsx)(Pw,{children:(0,K.jsx)(Jw,{children:e})});Yw.displayName=`ComposerPrimitive.TriggerPopoverRoot`;var Xw=/\s/u;function Zw(e,t,n){let r=e.slice(0,n);for(let e=r.length-1;e>=0;e--){let n=r[e];if(Xw.test(n))return null;if(r.startsWith(t,e)){if(e>0&&!Xw.test(r[e-1]))continue;return{query:r.slice(e+t.length),offset:e}}}return null}var Qw=Xg(({text:e,triggerChar:t})=>{let[n,r]=h_(e.length),i=S_(()=>Zw(e,t,Math.min(n,e.length)),[n,e,t]);return{trigger:i,query:i?.query??``,setCursorPosition:r}});function $w(e){return`type`in e}var eT=Xg(({navigableList:e,isSearchMode:t,activeCategoryId:n,query:r,popoverId:i,open:a,selectItem:o,selectCategory:s,goBack:c,close:l})=>{let[u,d]=h_(0);v_(()=>{d(0)},[e]),v_(()=>{d(0)},[t,n]);let f=w_(t=>{t<0||t>=e.length||t!==u&&d(t)}),p=w_(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&&($w(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 tT(e,t){return e.id.toLowerCase().includes(t)||e.label.toLowerCase().includes(t)||(e.description?.toLowerCase().includes(t)??!1)}var nT=Xg(({adapter:e,query:t,open:n})=>{let[r,i]=h_(null);v_(()=>{n||i(null)},[n]);let a=S_(()=>!n||!e?[]:e.categories(),[n,e]),o=n?r:null,s=S_(()=>!o||!e?[]:e.categoryItems(o),[o,e]),c=S_(()=>{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))tT(n,i)&&r.push(n);return r},[n,e,t,o,a]),l=c!==null,u=S_(()=>{if(l)return[];if(!t)return a;let e=t.toLowerCase();return a.filter(t=>t.label.toLowerCase().includes(e))},[a,t,l]),d=S_(()=>{if(l)return c??[];if(!t)return s;let e=t.toLowerCase();return s.filter(t=>tT(t,e))},[s,t,l,c]);return{categories:u,items:d,isSearchMode:l,activeCategoryId:o,navigableList:S_(()=>l?c??[]:o?d:u,[l,c,o,d,u]),selectCategory:w_(e=>{i(e)}),goBack:w_(()=>{i(null)})}}),rT=Xg(({behavior:e,trigger:t,aui:n,triggerChar:r,setCursorPosition:i,onSelected:a})=>{let o=y_(null),s=w_(e=>(o.current=e,()=>{o.current===e&&(o.current=null)}));return{selectItem:w_(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:w_(()=>{a(),t&&i(t.offset)}),registerSelectItemOverride:s}}),iT=Xg(({adapter:e,text:t,triggerChar:n,behavior:r,aui:i,popoverId:a})=>{let o=j_(Qw({text:t,triggerChar:n})),s=o.trigger!==null&&e!==void 0&&r!==void 0,c=j_(nT({adapter:e,query:o.query,open:s})),l=w_(()=>{c.goBack()}),u=j_(rT({behavior:r,trigger:o.trigger,aui:i,triggerChar:n,setCursorPosition:o.setCursorPosition,onSelected:l})),d=j_(eT({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}}),aT=(0,T.createContext)(null),oT=()=>{let e=(0,T.useContext)(aT);if(!e)throw Error(`useTriggerPopoverScopeContext must be used within ComposerPrimitive.TriggerPopover`);return e},sT=()=>(0,T.useContext)(aT),cT=(0,T.createContext)(null),lT=()=>{let e=(0,T.useContext)(cT);if(!e)throw Error(`TriggerPopover.Directive / TriggerPopover.Action must be rendered inside ComposerPrimitive.TriggerPopover`);return e},uT=(0,T.forwardRef)(({char:e,adapter:t,"aria-label":n,children:r,...i},a)=>{let o=$v(),s=Z(e=>e.composer.text),c=(0,T.useId)(),l=(0,T.useRef)(null),[u,d]=(0,T.useState)(null),f=(0,T.useRef)(0),p=(0,T.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,T.useMemo)(()=>({register:p}),[p]),h=Uv(iT({adapter:t,text:s,triggerChar:e,behavior:u??void 0,aui:o,popoverId:c})),g=(0,T.useRef)(h);g.current=h;let _=Lw();(0,T.useEffect)(()=>_.register({char:e,...u?{behavior:u}:{},resource:g.current}),[_,e,u]);let v=Nw();(0,T.useEffect)(()=>{if(v)return v.register(g.current)},[v]);let y=u!==null&&h.open,b=zw();return(0,T.useEffect)(()=>{if(y)return()=>{b.setActiveAria(e,null)}},[b,e,y]),(0,T.useEffect)(()=>{y&&b.setActiveAria(e,{popoverId:c,highlightedItemId:h.highlightedItemId})},[b,e,c,y,h.highlightedItemId]),(0,K.jsx)(cT.Provider,{value:m,children:(0,K.jsx)(aT.Provider,{value:h,children:y?(0,K.jsx)(Ow.div,{role:`listbox`,id:c,"aria-label":n??`Suggestions`,"aria-activedescendant":h.highlightedItemId,"data-state":`open`,...i,ref:a,children:r}):r})})});uT.displayName=`ComposerPrimitive.TriggerPopover`;var dT=()=>{let{disabled:e,send:t}=WC(),n=(0,T.useCallback)(()=>t(),[t]);return e?null:n},fT=kw(`ComposerPrimitive.Send`,dT),pT=(0,T.forwardRef)(({onSubmit:e,...t},n)=>{let r=dT(),i=e=>{e.preventDefault(),r&&r()};return(0,K.jsx)(Ow.form,{...t,ref:n,onSubmit:ia(e,i)})});pT.displayName=`ComposerPrimitive.Root`;var mT=e=>{let t=ja(e),n=nw(e=>e.onScrollToBottom);(0,T.useEffect)(()=>n(t),[n,t])},hT=()=>!1,gT=()=>{},_T=e=>(0,T.useSyncExternalStore)((0,T.useCallback)(t=>{if(typeof window>`u`||e===null)return gT;let n=window.matchMedia(e);return n.addEventListener(`change`,t),()=>n.removeEventListener(`change`,t)},[e]),(0,T.useCallback)(()=>typeof window>`u`||e===null?!1:window.matchMedia(e).matches,[e]),hT);function vT(){return vT=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},vT.apply(null,arguments)}function yT(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 bT=T.useLayoutEffect,xT=function(e){var t=T.useRef(e);return bT(function(){t.current=e}),t},ST=function(e,t){if(typeof e==`function`){e(t);return}e.current=t},CT=function(e,t){var n=T.useRef();return T.useCallback(function(r){e.current=r,n.current&&ST(n.current,null),n.current=t,t&&ST(t,r)},[t])},wT={"min-height":`0`,"max-height":`none`,height:`0`,visibility:`hidden`,overflow:`hidden`,position:`absolute`,"z-index":`-1000`,top:`0`,right:`0`,display:`block`},TT=function(e){Object.keys(wT).forEach(function(t){e.style.setProperty(t,wT[t],`important`)})},ET=null,DT=function(e,t){var n=e.scrollHeight;return t.sizingStyle.boxSizing===`border-box`?n+t.borderSize:n-t.paddingSize};function OT(e,t,n,r){n===void 0&&(n=1),r===void 0&&(r=1/0),ET||(ET=document.createElement(`textarea`),ET.setAttribute(`tabindex`,`-1`),ET.setAttribute(`aria-hidden`,`true`),TT(ET)),ET.parentNode===null&&document.body.appendChild(ET);var i=e.paddingSize,a=e.borderSize,o=e.sizingStyle,s=o.boxSizing;Object.keys(o).forEach(function(e){var t=e;ET.style[t]=o[t]}),TT(ET),ET.value=t;var c=DT(ET,e);ET.value=t,c=DT(ET,e),ET.value=`x`;var l=ET.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 kT=function(){},AT=function(e,t){return e.reduce(function(e,n){return e[n]=t[n],e},{})},jT=[`borderBottomWidth`,`borderLeftWidth`,`borderRightWidth`,`borderTopWidth`,`boxSizing`,`fontFamily`,`fontSize`,`fontStyle`,`fontWeight`,`letterSpacing`,`lineHeight`,`paddingBottom`,`paddingLeft`,`paddingRight`,`paddingTop`,`tabSize`,`textIndent`,`textRendering`,`textTransform`,`width`,`wordBreak`,`wordSpacing`,`scrollbarGutter`],MT=!!document.documentElement.currentStyle,NT=function(e){var t=window.getComputedStyle(e);if(t===null)return null;var n=AT(jT,t),r=n.boxSizing;return r===``?null:(MT&&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 PT(e,t,n){var r=xT(n);T.useLayoutEffect(function(){var n=function(e){return r.current(e)};if(e)return e.addEventListener(t,n),function(){return e.removeEventListener(t,n)}},[])}var FT=function(e,t){PT(document.body,`reset`,function(n){e.current.form===n.target&&t(n)})},IT=function(e){PT(window,`resize`,e)},LT=function(e){PT(document.fonts,`loadingdone`,e)},RT=[`cacheMeasurements`,`maxRows`,`minRows`,`onChange`,`onHeightChange`],zT=T.forwardRef(function(e,t){var n=e.cacheMeasurements,r=e.maxRows,i=e.minRows,a=e.onChange,o=a===void 0?kT:a,s=e.onHeightChange,c=s===void 0?kT:s,l=yT(e,RT),u=l.value!==void 0,d=T.useRef(null),f=CT(d,t),p=T.useRef(0),m=T.useRef(),h=function(){var e=d.current,t=n&&m.current?m.current:NT(e);if(t){m.current=t;var a=OT(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 T.useLayoutEffect(h),FT(d,function(){if(!u){var e=d.current.value;requestAnimationFrame(function(){var t=d.current;t&&e!==t.value&&h()})}}),IT(h),LT(h),T.createElement(`textarea`,vT({},l,{onChange:function(e){u||h(),o(e)},ref:f}))}),BT=`(pointer: coarse) and (not (any-pointer: fine))`,VT=(0,T.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},_)=>{let v=$v(),y=Nw(),b=Kw(),x=l??(c===!1?`none`:`enter`),S=_T(m?BT:null),C=m&&S&&x===`enter`?`none`:x,w=Z(e=>e.composer.isEditing?e.composer.text:``),E=Z(e=>e.thread.isDisabled||e.composer.dictation?.inputDisabled)||r,D=(0,T.useRef)(null),O=Ri(_,D),k=(0,T.useRef)(!1);Ma(e=>{if(!D.current?.contains(e.target))return;if(y){for(let t of y.getPlugins())if(t.handleKeyDown(e))return}if(!u)return;let t=v.composer();t.getState().canCancel&&(t.cancel(),e.preventDefault())});let A=e=>{if(!E&&!e.nativeEvent.isComposing){if(y){for(let t of y.getPlugins())if(t.handleKeyDown(e))return}if(e.key===`Enter`){let t=v.thread().getState(),n=t.capabilities.queue;if(e.shiftKey&&(e.ctrlKey||e.metaKey)&&n&&x!==`none`&&v.composer().getState().canSend){e.preventDefault(),v.composer().send({steer:!0});return}if(e.shiftKey||t.isRunning&&!n)return;let r=!1;C===`ctrlEnter`?r=e.ctrlKey||e.metaKey:C===`enter`&&(r=!0),r&&(e.preventDefault(),D.current?.closest(`form`)?.requestSubmit())}}},j=async e=>{if(!h)return;let t=v.thread().getState().capabilities,n=Array.from(e.clipboardData?.files||[]);if(t.attachments&&n.length>0)try{e.preventDefault(),await Promise.all(n.map(e=>v.composer().addAttachment(e)))}catch(e){console.error(`Error adding attachment:`,e)}},M=e&&!E,N=(0,T.useCallback)(()=>{let e=D.current;!e||!M||(e.focus({preventScroll:!0}),e.setSelectionRange(e.value.length,e.value.length))},[M]);(0,T.useEffect)(()=>N(),[N]),mT(()=>{v.composer().getState().type===`thread`&&f&&N()}),(0,T.useEffect)(()=>{if(!(v.composer().getState().type!==`thread`||!d))return v.on(`thread.runStart`,N)},[d,N,v]),(0,T.useEffect)(()=>{if(!(v.composer().getState().type!==`thread`||!p))return v.on(`threadListItem.switchedTo`,N)},[p,N,v]);let P=b?{"aria-controls":b.popoverId,"aria-expanded":!0,"aria-haspopup":`listbox`,"aria-activedescendant":b.highlightedItemId}:{},F={name:`input`,value:w,...g,...P,ref:O,disabled:E,onChange:ia(i,e=>{if(!v.composer().getState().isEditing)return;let t=e.nativeEvent.isComposing===!0;k.current&&!t&&(k.current=!1);let n=t||k.current;if(z_(()=>{v.composer().setText(e.target.value)}),n)return;let r=e.target.selectionStart??e.target.value.length;if(y)for(let e of y.getPlugins())e.setCursorPosition(r)}),onKeyDown:ia(a,A),onCompositionStart:ia(g.onCompositionStart,()=>{k.current=!0}),onCompositionEnd:ia(g.onCompositionEnd,e=>{if(k.current=!1,!v.composer().getState().isEditing)return;let t=e.target;z_(()=>{v.composer().setText(t.value)});let n=t.selectionStart??t.value.length;if(y)for(let e of y.getPlugins())e.setCursorPosition(n)}),onSelect:ia(s,e=>{if(k.current)return;let t=e.target,n=t.selectionStart??t.value.length;if(y)for(let e of y.getPlugins())e.setCursorPosition(n)}),onPaste:ia(o,j)};if(n&&(0,T.isValidElement)(n)){let e=g.children===void 0?n.props.children:g.children;return(0,K.jsx)(Hi,{...F,children:(0,T.cloneElement)(n,void 0,e)})}return(0,K.jsx)(t?Hi:zT,{...F})});VT.displayName=`ComposerPrimitive.Input`;var HT=kw(`ComposerPrimitive.Cancel`,()=>{let{disabled:e,cancel:t}=GC();return e?null:t}),UT=kw(`ComposerPrimitive.AddAttachment`,({multiple:e=!0}={})=>{let{disabled:t,addAttachment:n}=qC(),r=$v(),i=(0,T.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`]),WT=(0,T.forwardRef)(({disabled:e,asChild:t=!1,render:n,children:r,...i},a)=>{let[o,s]=(0,T.useState)(!1),c=$v(),l=(0,T.useCallback)(t=>{e||(t.preventDefault(),s(!0))},[e]),u=(0,T.useCallback)(t=>{e||(t.preventDefault(),o||s(!0))},[e,o]),d=(0,T.useCallback)(t=>{if(e)return;t.preventDefault();let n=t.relatedTarget;n&&t.currentTarget.contains(n)||s(!1)},[e]),f=(0,T.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:ia(i.onDragEnterCapture,l),onDragOverCapture:ia(i.onDragOverCapture,u),onDragLeaveCapture:ia(i.onDragLeaveCapture,d),onDropCapture:ia(i.onDropCapture,f),ref:a};if(n&&(0,T.isValidElement)(n)){let e=r===void 0?n.props.children:r;return(0,K.jsx)(Hi,{...p,children:(0,T.cloneElement)(n,void 0,e)})}return(0,K.jsx)(t?Hi:`div`,{...p,children:r})});WT.displayName=`ComposerPrimitive.AttachmentDropzone`;var GT=kw(`ComposerPrimitive.Dictate`,()=>{let{disabled:e,startDictation:t}=KC();return e?null:t}),KT=kw(`ComposerPrimitive.StopDictation`,()=>{let e=$v(),t=Z(e=>e.composer.dictation!=null),n=(0,T.useCallback)(()=>{e.composer().stopDictation()},[e]);return t?n:null}),qT=(0,T.forwardRef)(({children:e,...t},n)=>{let r=Z(e=>e.composer.dictation?.transcript);return r?(0,K.jsx)(Ow.span,{...t,ref:n,children:e??r}):null});qT.displayName=`ComposerPrimitive.DictationTranscript`;var JT=(0,T.forwardRef)((e,t)=>Z(e=>e.composer.quote)?(0,K.jsx)(Ow.div,{...e,ref:t}):null);JT.displayName=`ComposerPrimitive.Quote`;var YT=(0,T.forwardRef)(({children:e,...t},n)=>{let r=Z(e=>e.composer.quote?.text);return r?(0,K.jsx)(Ow.span,{...t,ref:n,children:e??r}):null});YT.displayName=`ComposerPrimitive.QuoteText`;var XT=(0,T.forwardRef)(({onClick:e,...t},n)=>{let r=$v(),i=(0,T.useCallback)(()=>{r.composer().setQuote(void 0)},[r]);return(0,K.jsx)(Ow.button,{type:`button`,...t,ref:n,onClick:ia(e,i)})});XT.displayName=`ComposerPrimitive.QuoteDismiss`;var ZT=(0,T.forwardRef)(({children:e,"aria-label":t,...n},r)=>{let{categories:i,activeCategoryId:a,isSearchMode:o,open:s}=oT();return!s||a||o?null:(0,K.jsx)(Ow.div,{role:`group`,"aria-label":t??`Categories`,...n,ref:r,children:e(i)})});ZT.displayName=`ComposerPrimitive.TriggerPopoverCategories`;var QT=(0,T.forwardRef)(({categoryId:e,onClick:t,onMouseMove:n,...r},i)=>{let{selectCategory:a,highlightIndex:o,categories:s,highlightedIndex:c,activeCategoryId:l,isSearchMode:u,popoverId:d}=oT(),f=(0,T.useCallback)(()=>{a(e)},[a,e]),p=s.findIndex(t=>t.id===e),m=!l&&!u&&p===c,h=(0,T.useCallback)(()=>{o(p)},[o,p]);return(0,K.jsx)(Ow.button,{type:`button`,role:`option`,id:`${d}-option-${e}`,"aria-selected":m,"data-highlighted":m?``:void 0,...r,ref:i,onClick:ia(t,f),onMouseMove:ia(n,h)})});QT.displayName=`ComposerPrimitive.TriggerPopoverCategoryItem`;var $T=(0,T.forwardRef)(({children:e,"aria-label":t,...n},r)=>{let{items:i,activeCategoryId:a,isSearchMode:o,open:s}=oT();return!s||!a&&!o?null:(0,K.jsx)(Ow.div,{role:`group`,"aria-label":t??`Items`,...n,ref:r,children:e(i)})});$T.displayName=`ComposerPrimitive.TriggerPopoverItems`;var eE=(0,T.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}=oT(),p=(0,T.useCallback)(()=>{o(e)},[o,e]),m=t??c.findIndex(t=>t.id===e.id),h=(d||u!==null)&&m===l,g=(0,T.useCallback)(()=>{s(m)},[s,m]);return(0,K.jsx)(Ow.button,{type:`button`,role:`option`,id:`${f}-option-${e.id}`,"aria-selected":h,"data-highlighted":h?``:void 0,...i,ref:a,onClick:ia(n,p),onMouseMove:ia(r,g)})});eE.displayName=`ComposerPrimitive.TriggerPopoverItem`;var tE=(0,T.forwardRef)(({onClick:e,...t},n)=>{let{activeCategoryId:r,isSearchMode:i,goBack:a,open:o}=oT();return!o||!r||i?null:(0,K.jsx)(Ow.button,{type:`button`,...t,ref:n,onClick:ia(e,a)})});tE.displayName=`ComposerPrimitive.TriggerPopoverBack`;var nE=({formatter:e,onExecute:t,removeOnExecute:n})=>{let{register:r}=lT(),i=(0,T.useRef)(t);return i.current=t,(0,T.useEffect)(()=>r({kind:`action`,formatter:e??QC,onExecute:e=>i.current(e),...n===void 0?{}:{removeOnExecute:n}}),[r,e,n]),null};nE.displayName=`ComposerPrimitive.TriggerPopoverAction`;var rE=({formatter:e,onInserted:t})=>{let{register:n}=lT(),r=(0,T.useRef)(t);return r.current=t,(0,T.useEffect)(()=>n({kind:`directive`,formatter:e??QC,onInserted:e=>r.current?.(e)}),[n,e]),null};rE.displayName=`ComposerPrimitive.TriggerPopoverDirective`;var iE=Object.assign(uT,{Directive:rE,Action:nE}),aE=pw({AddAttachment:()=>UT,AttachmentByIndex:()=>MC,AttachmentDropzone:()=>WT,Attachments:()=>PC,Cancel:()=>HT,Dictate:()=>GT,DictationTranscript:()=>qT,If:()=>UC,Input:()=>VT,Queue:()=>FC,Quote:()=>JT,QuoteDismiss:()=>XT,QuoteText:()=>YT,Root:()=>pT,Send:()=>fT,StopDictation:()=>KT,Unstable_TriggerPopover:()=>iE,Unstable_TriggerPopoverBack:()=>tE,Unstable_TriggerPopoverCategories:()=>ZT,Unstable_TriggerPopoverCategoryItem:()=>QT,Unstable_TriggerPopoverItem:()=>eE,Unstable_TriggerPopoverItems:()=>$T,Unstable_TriggerPopoverRoot:()=>Yw,unstable_useTriggerPopoverRootContext:()=>Lw,unstable_useTriggerPopoverRootContextOptional:()=>Rw,unstable_useTriggerPopoverScopeContext:()=>oT,unstable_useTriggerPopoverScopeContextOptional:()=>sT,unstable_useTriggerPopoverTriggers:()=>Bw,unstable_useTriggerPopoverTriggersOptional:()=>Ww}),oE=()=>Z(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}),sE=()=>Z(e=>{if(e.part.type!==`image`)throw Error(`MessagePartImage can only be used inside image message parts.`);return e.part}),cE=(0,T.createContext)(null),lE=e=>({useSmoothStatus:Ry(()=>e)}),uE=({children:e})=>{let t=fE({optional:!0}),n=$v(),[r]=(0,T.useState)(()=>lE(n.part().getState().status));return t?e:(0,K.jsx)(cE.Provider,{value:r,children:e})},dE=e=>{let t=(0,T.forwardRef)((t,n)=>(0,K.jsx)(uE,{children:(0,K.jsx)(e,{...t,ref:n})}));return t.displayName=e.displayName,t};function fE(e){let t=(0,T.useContext)(cE);if(!e?.optional&&!t)throw Error(`This component must be used within a SmoothContextProvider.`);return t}var{useSmoothStatus:pE,useSmoothStatusStore:mE}=ew(fE,`useSmoothStatus`),hE=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))}},gE=Object.freeze({type:`running`}),_E=(e,t=!1)=>{let{text:n}=e,[r,i]=(0,T.useState)(e.status.type===`running`?``:n),a=$v(),o=Z(()=>a.part()),[s,c]=(0,T.useState)(o);(o!==s||!n.startsWith(r))&&(c(o),i(e.status.type===`running`?``:n));let l=mE({optional:!0}),u=ja(t=>{if(i(t),l){let n=r!==t||e.status.type===`running`?gE:e.status;ow(l).setState(n,!0)}});(0,T.useEffect)(()=>{if(l){let i=t&&(r!==n||e.status.type===`running`)?gE:e.status;ow(l).setState(i,!0)}},[l,t,n,r,e.status]);let[d]=(0,T.useState)(new hE(r,u)),f=(0,T.useRef)(o);return(0,T.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,T.useEffect)(()=>()=>{d.stop()},[d]),(0,T.useMemo)(()=>t?{type:`text`,text:r,status:n===r?e.status:gE}:e,[t,r,e,n])},vE=(0,T.forwardRef)(({smooth:e=!0,component:t=`span`,...n},r)=>{let{text:i,status:a}=_E(oE(),e);return(0,K.jsx)(t,{"data-status":a.type,...n,ref:r,children:i})});vE.displayName=`MessagePartPrimitive.Text`;var yE=(0,T.forwardRef)((e,t)=>{let{image:n}=sE();return(0,K.jsx)(Ow.img,{src:n,...e,ref:t})});yE.displayName=`MessagePartPrimitive.Image`;var bE=e=>{let t=(0,T.useRef)(void 0);return(0,T.useCallback)(n=>{t.current&&=(t.current(),void 0),n&&(t.current=e(n))},[e])},xE=(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},SE=e=>e.dataset.messageId,CE=()=>{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},wE=(e,t)=>{let n=`${t}px`;return e.style.height===n?!1:(e.style.height=n,!0)},TE=e=>{let t=window.devicePixelRatio||1;return Math.round(e*t)/t},EE=()=>{let e=$v(),t=Z(()=>e.message());return bE((0,T.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]))},DE=()=>{let e=nw(e=>e.topAnchorTurn?.anchorId);return Z(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))},OE=()=>{let e=nw(e=>e.topAnchorTurn?.targetId);return Z(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))},kE=(e,t)=>bE((0,T.useCallback)(n=>{if(e)return t.getState().registerAnchorElement(n)},[e,t])),AE=({active:e,threadViewportStore:t})=>bE((0,T.useCallback)(n=>{if(!e)return;let r=t.getState(),i=r.topAnchorMessageClamp;return r.registerAnchorTargetElement(n,{tallerThan:xE(i.tallerThan,n),visibleHeight:xE(i.visibleHeight,n)})},[e,t])),jE=({forwardedRef:e,...t})=>{let n=Ri(e,EE()),r=Z(e=>e.message.id);return(0,K.jsx)(Ow.div,{...t,ref:n,"data-message-id":r})},ME=({forwardedRef:e,threadViewportStore:t,...n})=>{let r=EE(),i=DE(),a=OE(),o=Ri(e,r,kE(i,t),AE({active:a,threadViewportStore:t})),s=Z(e=>e.message.id);return(0,K.jsx)(Ow.div,{...n,ref:o,"data-message-id":s,"data-aui-top-anchor-user":i?``:void 0,"data-aui-top-anchor-target":a?``:void 0})},NE=(0,T.forwardRef)((e,t)=>{let n=rw();return n.getState().turnAnchor===`top`?(0,K.jsx)(ME,{...e,forwardedRef:t,threadViewportStore:n}):(0,K.jsx)(jE,{...e,forwardedRef:t})});NE.displayName=`MessagePrimitive.Root`;var PE={...QS,Text:()=>(0,K.jsxs)(`p`,{style:{whiteSpace:`pre-line`},children:[(0,K.jsx)(vE,{}),(0,K.jsx)(IC,{children:(0,K.jsx)(`span`,{style:{fontFamily:`revert`},children:` ●`})})]}),Image:()=>(0,K.jsx)(yE,{})},FE=e=>{if(`children`in e)return(0,K.jsx)(mC,{children:e.children});let{components:t,...n}=e;return(0,K.jsx)(mC,{components:t?{Text:t.Text??PE.Text,Image:t.Image??PE.Image,Reasoning:t.Reasoning??QS.Reasoning,Source:t.Source??QS.Source,File:t.File??QS.File,Unstable_Audio:t.Unstable_Audio??QS.Unstable_Audio,...`ChainOfThought`in t?{ChainOfThought:t.ChainOfThought}:{tools:t.tools,data:t.data,ToolGroup:t.ToolGroup??QS.ToolGroup,ReasoningGroup:t.ReasoningGroup??QS.ReasoningGroup},Empty:t.Empty,Quote:t.Quote,generativeUI:t.generativeUI}:PE,...n})};FE.displayName=`MessagePrimitive.Parts`;var IE=({children:e})=>YC()===void 0?null:e;IE.displayName=`MessagePrimitive.Error`;var LE=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},RE=e=>{let t=Z(e=>e.message.parts);return(0,T.useMemo)(()=>t.length===0?[]:e(t),[t,e])},zE=({Fallback:e,...t})=>{let n=Z(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},BE=({Fallback:e,...t})=>{let n=Z(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},VE={Text:()=>(0,K.jsxs)(`p`,{style:{whiteSpace:`pre-line`},children:[(0,K.jsx)(vE,{}),(0,K.jsx)(IC,{children:(0,K.jsx)(`span`,{style:{fontFamily:`revert`},children:` ●`})})]}),Reasoning:()=>null,Source:()=>null,Image:()=>(0,K.jsx)(yE,{}),File:()=>null,Unstable_Audio:()=>null,Group:({children:e})=>e},HE=({components:{Text:e=VE.Text,Reasoning:t=VE.Reasoning,Image:n=VE.Image,Source:r=VE.Source,File:i=VE.File,Unstable_Audio:a=VE.Unstable_Audio,tools:o={},data:s}={}})=>{let c=$v(),l=Z(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)(zE,{...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)(BE,{...l,Fallback:e})}default:return console.warn(`Unknown message part type: ${u}`),null}},UE=(0,T.memo)(({partIndex:e,components:t})=>(0,K.jsx)(jb,{index:e,children:(0,K.jsx)(HE,{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),WE=({status:e,component:t})=>(0,K.jsx)(Nb,{text:``,isRunning:e.type===`running`,children:(0,K.jsx)(t,{type:`text`,text:``,status:e})}),GE=Object.freeze({type:`complete`}),KE=(0,T.memo)(({components:e})=>{let t=Z(e=>e.message.status??GE);return e?.Empty?(0,K.jsx)(e.Empty,{status:t}):(0,K.jsx)(WE,{status:t,component:e?.Text??VE.Text})},(e,t)=>e.components?.Empty===t.components?.Empty&&e.components?.Text===t.components?.Text),qE=({groupingFunction:e,components:t})=>{let n=Z(e=>e.message.parts.length),r=RE(e);return(0,K.jsx)(K.Fragment,{children:(0,T.useMemo)(()=>n===0?(0,K.jsx)(KE,{components:t}):r.map((e,n)=>(0,K.jsx)(t?.Group??VE.Group,{groupKey:e.groupKey,indices:e.indices,children:e.indices.map(e=>(0,K.jsx)(UE,{partIndex:e,components:t},e))},`group-${n}-${e.groupKey??`ungrouped`}`)),[r,t,n])})};qE.displayName=`MessagePrimitive.Unstable_PartsGrouped`;var JE=({components:e,...t})=>(0,K.jsx)(qE,{...t,components:e,groupingFunction:LE});JE.displayName=`MessagePrimitive.Unstable_PartsGroupedByParentId`;var YE=pw({AttachmentByIndex:()=>DC,Attachments:()=>kC,Content:()=>FE,Error:()=>IE,GenerativeUI:()=>LS,GroupedParts:()=>CC,If:()=>jw,PartByIndex:()=>eC,Parts:()=>FE,Quote:()=>wC,Root:()=>NE,Unstable_PartsGrouped:()=>qE,Unstable_PartsGroupedByParentId:()=>JE}),XE=e=>{let t=ja(e);return bE((0,T.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]))},ZE=({autoScroll:e,scrollToBottomOnRunStart:t=!0,scrollToBottomOnInitialize:n=!0,scrollToBottomOnThreadSwitch:r=!0})=>{let i=(0,T.useRef)(null),a=Z(e=>e.thread.messages.length>0),o=(0,T.useRef)(!1),s=(0,T.useRef)(null),c=rw();e===void 0&&(e=c.getState().turnAnchor!==`top`);let l=(0,T.useRef)(0),u=(0,T.useRef)(0),d=(0,T.useRef)(0),f=(0,T.useRef)(0),p=(0,T.useRef)(null),m=(0,T.useCallback)(e=>{let t=i.current;t&&(p.current=e,t.scrollTo({top:t.scrollHeight,behavior:e}))},[]),h=(0,T.useCallback)(e=>{p.current=e,s.current!==null&&cancelAnimationFrame(s.current),s.current=requestAnimationFrame(()=>{s.current=null,m(e)})},[m]);(0,T.useLayoutEffect)(()=>()=>{s.current!==null&&cancelAnimationFrame(s.current)},[]);let g=(0,T.useCallback)(()=>{let e=c.getState();return e.turnAnchor===`top`&&e.element.viewport===i.current&&e.element.anchor!==null},[c]),_=()=>{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&&ow(c).setState({isAtBottom:n})),l.current=e.scrollTop,u.current=e.scrollHeight},v=XE(()=>{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`),_()}),y=bE(e=>(e.addEventListener(`scroll`,_),()=>{e.removeEventListener(`scroll`,_)}));return(0,T.useLayoutEffect)(()=>{if(n){if(!a){o.current=!1;return}o.current||(o.current=!0,p.current===null&&h(`instant`))}},[a,h,n]),mT(({behavior:e})=>{m(e)}),ly(`thread.runStart`,()=>{t&&c.getState().turnAnchor!==`top`&&h(`auto`)}),ly(`threadListItem.switchedTo`,()=>{r&&h(`instant`)}),Ri(v,y,i)},QE=(0,T.forwardRef)((e,t)=>(0,K.jsx)(Ow.div,{...e,ref:t}));QE.displayName=`ThreadPrimitive.Root`;var $E=({children:e})=>Z(e=>e.thread.isEmpty)?e:null;$E.displayName=`ThreadPrimitive.Empty`;var eD=e=>Z(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)),tD=({children:e,...t})=>eD(t)?e:null;tD.displayName=`ThreadPrimitive.If`;var nD=(e,t)=>bE((0,T.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])),rD=e=>{let t=0,n=e;for(;n;)t+=n.offsetTop,n=n.offsetParent;return t},iD=(e,t)=>{let n=0,r=e;for(;r&&r!==t;)n+=r.offsetTop,r=r.offsetParent;return r===t?n:rD(e)-rD(t)},aD=({viewport:e,anchor:t,tallerThan:n,visibleHeight:r})=>{let i=iD(t,e),a=t.offsetHeight;return i+Math.max(0,a-(a<=n?a:r))},oD=({scrollHeight:e,...t})=>{let{viewport:n}=t,r=aD(t)+n.clientHeight;return Math.max(0,r-e)},sD=({viewport:e,reserve:t,...n})=>oD({viewport:e,...n,scrollHeight:e.scrollHeight-t.offsetHeight}),cD=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}},lD=e=>{let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},cancel:()=>{t!==null&&(cancelAnimationFrame(t),t=null)}}},uD=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&&(wE(t,0),t.remove());return}if(t??=CE(),(t.parentElement!==c.parentElement||t.previousElementSibling!==c)&&c.after(t),a.target(o,s,c),wE(t,sD({viewport:o,anchor:s,reserve:t,...l}))){i.schedule();return}let u=SE(s);if(u!==void 0&&n===u)return;let d=TE(aD({viewport:o,anchor:s,...l}));Math.abs(o.scrollTop-d)>1&&o.scrollTo({top:d,behavior:`smooth`}),u!==void 0&&(n=u)}let i=lD(r),a=cD(i.schedule);i.schedule();let o=e.subscribe(i.schedule);return()=>{i.cancel(),o(),a.disconnect(),t?.remove()}},dD=e=>{let t=rw();(0,T.useLayoutEffect)(()=>{if(e)return uD(t)},[e,t])},fD=({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}},pD=e=>fD(e)?.anchorId,mD=e=>fD(e)?.targetId,hD=()=>nD(nw(e=>e.registerViewport),(0,T.useCallback)(e=>e.clientHeight,[])),gD=()=>bE(nw(e=>e.registerViewportElement)),_D=e=>{let t=rw(),n=Z(t=>{if(e)return pD(t.thread)}),r=Z(t=>{if(e)return mD(t.thread)}),i=(0,T.useMemo)(()=>!n||!r?null:{anchorId:n,targetId:r},[n,r]);(0,T.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,T.useCallback)(()=>{t.getState().setTopAnchorTurn(null)},[t]);ly(`thread.initialize`,a),ly(`threadListItem.switchedTo`,a)},vD=(0,T.forwardRef)(({autoScroll:e,scrollToBottomOnRunStart:t,scrollToBottomOnInitialize:n,scrollToBottomOnThreadSwitch:r,children:i,...a},o)=>{let s=ZE({autoScroll:e,scrollToBottomOnRunStart:t,scrollToBottomOnInitialize:n,scrollToBottomOnThreadSwitch:r}),c=hD(),l=gD(),u=rw().getState().turnAnchor===`top`;_D(u),dD(u);let d=Ri(o,s,c,l);return(0,K.jsx)(Ow.div,{...a,ref:d,children:i})});vD.displayName=`ThreadPrimitive.ViewportScrollable`;var yD=(0,T.forwardRef)(({turnAnchor:e,topAnchorMessageClamp:t,...n},r)=>(0,K.jsx)(cw,{options:{turnAnchor:e,topAnchorMessageClamp:t},children:(0,K.jsx)(vD,{...n,ref:r})}));yD.displayName=`ThreadPrimitive.Viewport`;var bD=(0,T.forwardRef)((e,t)=>{let n=Ri(t,nD(nw(e=>e.registerContentInset),(0,T.useCallback)(e=>{let t=parseFloat(getComputedStyle(e).marginTop)||0;return e.offsetHeight+t},[])));return(0,K.jsx)(Ow.div,{...e,ref:n})});bD.displayName=`ThreadPrimitive.ViewportFooter`;var xD=kw(`ThreadPrimitive.ScrollToBottom`,({behavior:e}={})=>{let t=nw(e=>e.isAtBottom),n=rw(),r=(0,T.useCallback)(()=>{n.getState().scrollToBottom({behavior:e})},[n,e]);return t?null:r},[`behavior`]),SD=kw(`ThreadPrimitive.Suggestion`,({prompt:e,send:t,clearComposer:n,autoSend:r,method:i})=>{let{disabled:a,trigger:o}=JC({prompt:e,send:t??r??!1,clearComposer:n});return a?null:o},[`prompt`,`send`,`clearComposer`,`autoSend`,`method`]),CD=pw({Empty:()=>$E,If:()=>tD,MessageByIndex:()=>DS,Messages:()=>AS,Root:()=>QE,ScrollToBottom:()=>xD,Suggestion:()=>SD,SuggestionByIndex:()=>RC,Suggestions:()=>VC,Viewport:()=>yD,ViewportFooter:()=>bD,ViewportProvider:()=>cw}),wD=pw({AssistantRuntimeImpl:()=>Ox,BaseAssistantRuntimeCore:()=>kx,CompositeContextProvider:()=>q_,DefaultThreadComposerRuntimeCore:()=>rS,MessageRepository:()=>Xx,ThreadRuntimeImpl:()=>bx,fromThreadMessageLike:()=>Kx,generateId:()=>Lx,getAutoStatus:()=>Wx,splitLocalRuntimeOptions:()=>XC,useComposerInputPluginRegistryOptional:()=>Nw,useSmooth:()=>_E,useSmoothStatus:()=>pE,withSmoothContextProvider:()=>dE});function TD(e,t){let n=getComputedStyle(e);return t*parseFloat(n.fontSize)}function ED(e,t){let n=getComputedStyle(e.ownerDocument.documentElement);return t*parseFloat(n.fontSize)}function DD(e){return e/100*window.innerHeight}function OD(e){return e/100*window.innerWidth}function kD(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 AD({groupSize:e,panelElement:t,styleProp:n}){let r,[i,a]=kD(n);switch(a){case`%`:r=i/100*e;break;case`px`:r=i;break;case`rem`:r=ED(t,i);break;case`em`:r=TD(t,i);break;case`vh`:r=DD(i);break;case`vw`:r=OD(i);break}return r}function jD(e){return parseFloat(e.toFixed(3))}function MD({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 ND(e){let{panels:t}=e,n=MD({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=jD(AD({groupSize:n,panelElement:t,styleProp:r.collapsedSize})/n*100));let a;r.defaultSize!==void 0&&(a=jD(AD({groupSize:n,panelElement:t,styleProp:r.defaultSize})/n*100));let o=0;r.minSize!==void 0&&(o=jD(AD({groupSize:n,panelElement:t,styleProp:r.minSize})/n*100));let s=100;return r.maxSize!==void 0&&(s=jD(AD({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 PD(e,t=`Assertion error`){if(!e)throw Error(t)}function FD(e,t){return Array.from(t).sort(e===`horizontal`?ID:LD)}function ID(e,t){let n=e.element.offsetLeft-t.element.offsetLeft;return n===0?e.element.offsetWidth-t.element.offsetWidth:n}function LD(e,t){let n=e.element.offsetTop-t.element.offsetTop;return n===0?e.element.offsetHeight-t.element.offsetHeight:n}function RD(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.ELEMENT_NODE}function zD(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 BD({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}=zD(r,n),s=e===`horizontal`?t:o;s<a&&(a=s,i=n)}return PD(i,`No rect found`),i}var VD;function HD(){return VD===void 0&&(VD=typeof matchMedia==`function`?!!matchMedia(`(pointer:coarse)`).matches:!1),VD}function UD(e){let{element:t,orientation:n,panels:r,separators:i}=e,a=FD(n,Array.from(t.children).filter(RD).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,BD({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=HD()?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:MD({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 WD=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)}}},GD=new Map,KD=new WD;function qD(e){GD=new Map(GD),GD.delete(e)}function JD(e,t){for(let[t]of GD)if(t.id===e)return t}function YD(e,t){for(let[t,n]of GD)if(t.id===e)return n;if(t)throw Error(`Could not find data for Group with id ${e}`)}function XD(){return GD}function ZD(e,t){return KD.addListener(`groupChange`,n=>{n.group.id===e&&t(n)})}function QD(e,t){let n=GD.get(e);GD=new Map(GD),GD.set(e,t),KD.emit(`groupChange`,{group:e,prev:n,next:t})}function $D(e,t,n){let r,i={x:1/0,y:1/0};for(let a of t){let t=zD(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 eO(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function tO(e,t){if(e===t)throw Error(`Cannot compare node with itself`);let n={a:sO(e),b:sO(t)},r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();PD(r,`Stacking order can only be calculated for elements with a common ancestor`);let i={a:oO(aO(n.a)),b:oO(aO(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 nO=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function rO(e){let t=getComputedStyle(cO(e)??e).display;return t===`flex`||t===`inline-flex`}function iO(e){let t=getComputedStyle(e);return!!(t.position===`fixed`||t.zIndex!==`auto`&&(t.position!==`static`||rO(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`||nO.test(t.willChange)||t.webkitOverflowScrolling===`touch`)}function aO(e){let t=e.length;for(;t--;){let n=e[t];if(PD(n,`Missing node`),iO(n))return n}return null}function oO(e){return e&&Number(getComputedStyle(e).zIndex)||0}function sO(e){let t=[];for(;e;)t.push(e),e=cO(e);return t}function cO(e){let{parentNode:t}=e;return eO(t)?t.host:t}function lO(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 uO({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!RD(n)||n.contains(e)||e.contains(n))return!0;if(tO(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(lO(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function dO(e,t){let n=[];return t.forEach((t,r)=>{if(r.disabled)return;let i=UD(r),a=$D(r.orientation,i,{x:e.clientX,y:e.clientY});a&&a.distance.x<=0&&a.distance.y<=0&&uO({groupElement:r.element,hitRegion:a.hitRegion.rect,pointerEventTarget:e.target})&&n.push(a.hitRegion)}),n}function fO(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 pO(e,t,n=0){return Math.abs(jD(e)-jD(t))<=n}function mO(e,t){return pO(e,t)?0:e>t?1:-1}function hO({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(mO(r,c)<0)if(a){let e=(i+c)/2;r=mO(r,e)<0?i:c}else r=c;return r=Math.min(s,r),r=jD(r),r}function gO({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:a}){if(pO(e,0))return t;let o=a===`imperative-api`,s=Object.values(t),c=Object.values(i),l=[...s],[u,d]=r;PD(u!=null,`Invalid first pivot index`),PD(d!=null,`Invalid second pivot index`);let f=0;switch(a){case`keyboard`:{let t=e<0?d:u,r=n[t];PD(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(PD(n!=null,`Previous layout not found for panel index ${t}`),pO(n,i)){let t=o-n;mO(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}{let t=e<0?u:d,r=n[t];PD(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(PD(n!=null,`Previous layout not found for panel index ${t}`),pO(n,o)){let t=n-i;mO(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}break;default:{let t=e<0?d:u,r=n[t];PD(r,`Panel constraints not found for index ${t}`);let i=s[t],{collapsible:a,collapsedSize:o,minSize:c}=r;if(a&&mO(i,c)<0)if(e>0){let t=c-o,n=t/2;mO(i+e,c)<0&&(e=mO(e,n)<=0?0:t)}else{let t=c-o,n=100-t/2;mO(i-e,c)<0&&(e=mO(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];PD(e!=null,`Previous layout not found for panel index ${r}`);let a=hO({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];PD(i!=null,`Previous layout not found for panel index ${t}`);let a=i-r,c=hO({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:i,size:a});if(!pO(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(fO(c,l))return i;{let t=e<0?d:u,r=s[t];PD(r!=null,`Previous layout not found for panel index ${t}`);let i=r+f,a=hO({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:r,size:i});if(l[t]=a,!pO(a,i)){let t=i-a,r=e<0?d:u;for(;r>=0&&r<n.length;){let i=l[r];PD(i!=null,`Previous layout not found for panel index ${r}`);let a=i+t,s=hO({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:i,size:a});if(pO(i,s)||(t-=s-i,l[r]=s),pO(t,0))break;e>0?r--:r++}}}if(!pO(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 _O(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(t[n]===void 0||mO(e[n],t[n])!==0)return!1;return!0}function vO({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(!pO(i,100)&&r.length>0)for(let e=0;e<t.length;e++){let t=r[e];PD(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];PD(i!=null,`No layout data found for index ${e}`);let o=r[e];PD(o!=null,`No layout data found for index ${e}`);let s=hO({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:i,size:o});o!=s&&(a+=o-s,r[e]=s)}if(!pO(a,0))for(let e=0;e<t.length;e++){let n=r[e];PD(n!=null,`No layout data found for index ${e}`);let i=n+a,o=hO({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:n,size:i});if(n!==o&&(a-=o-n,r[e]=o,pO(a,0)))break}let o=Object.keys(e);return r.reduce((e,t,n)=>(e[o[n]]=t,e),{})}function yO({groupId:e,panelId:t}){let n=()=>{let t=XD();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&&pO(n.collapsedSize,r[n.panelId])}))){let e=n.slice(0,s).reduce((e,t)=>e+r[t.id],0);return{...r,[t]:jD(100-e)}}return gO({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=vO({layout:o({nextSize:e,panels:i.panels,prevLayout:c,derivedPanelConstraints:r}),panelConstraints:r});_O(c,u)||QD(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&&pO(t,n)},resize:e=>{let{group:t}=n(),{element:r}=i(),a=MD({group:t});s(jD(AD({groupSize:a,panelElement:r,styleProp:e})/a*100))}}}function bO(e){e.defaultPrevented||dO(e,XD()).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=yO({groupId:t.group.id,panelId:n.id});i&&r!==void 0&&(i.resize(r),e.preventDefault())}}})}function xO(e){let t=XD();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 SO({groupId:e}){let t=()=>{let t=XD();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=vO({layout:e,panelConstraints:r});return n?o:(_O(o,c)||QD(i,{defaultLayoutDeferred:n,derivedPanelConstraints:r,groupSize:a,layout:c,separatorToPanels:s}),c)}}}function CO(e,t){let n=xO(e),r=YD(n.id,!0),i=n.separators.find(t=>t.element===e);PD(i,`Matching separator not found`);let a=r.separatorToPanels.get(i);PD(a,`Matching panels not found`);let o=a.map(e=>n.panels.indexOf(e)),s=SO({groupId:n.id}).getLayout(),c=vO({layout:gO({delta:t,initialLayout:s,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:s,trigger:`keyboard`}),panelConstraints:r.derivedPanelConstraints});_O(s,c)||QD(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels})}function wO(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=xO(t);if(!n.disabled)switch(e.key){case`ArrowDown`:e.preventDefault(),n.orientation===`vertical`&&CO(t,5);break;case`ArrowLeft`:e.preventDefault(),n.orientation===`horizontal`&&CO(t,-5);break;case`ArrowRight`:e.preventDefault(),n.orientation===`horizontal`&&CO(t,5);break;case`ArrowUp`:e.preventDefault(),n.orientation===`vertical`&&CO(t,-5);break;case`End`:e.preventDefault(),CO(t,100);break;case`Enter`:{e.preventDefault();let n=xO(t),{derivedPanelConstraints:r,layout:i,separatorToPanels:a}=YD(n.id,!0),o=n.separators.find(e=>e.element===t);PD(o,`Matching separator not found`);let s=a.get(o);PD(s,`Matching panels not found`);let c=s[0],l=r.find(e=>e.panelId===c.id);if(PD(l,`Panel metadata not found`),l.collapsible){let e=i[c.id];CO(t,(l.collapsedSize===e?n.mutableState.expandedPanelSizes[c.id]??l.minSize:l.collapsedSize)-e)}break}case`F6`:{e.preventDefault();let n=xO(t).separators.map(e=>e.element),r=Array.from(n).findIndex(t=>t===e.currentTarget);PD(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(),CO(t,-100);break}}var TO={cursorFlags:0,state:`inactive`},EO=new WD;function DO(){return TO}function OO(e){return EO.addListener(`change`,e)}function kO(e){let t=TO,n={...TO};n.cursorFlags=e,TO=n,EO.emit(`change`,{prev:t,next:n})}function AO(e){let t=TO;TO=e,EO.emit(`change`,{prev:t,next:e})}function jO(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=XD(),n=dO(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)}),AO({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:`active`}),n.length&&e.preventDefault()}var MO=e=>e,NO=()=>{},PO=1,FO=2,IO=4,LO=8,RO=3,zO=12,BO;function VO(){return BO===void 0&&(BO=!1,typeof window<`u`&&(window.navigator.userAgent.includes(`Chrome`)||window.navigator.userAgent.includes(`Firefox`))&&(BO=!0)),BO}function HO({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&&VO()){let t=(e&PO)!==0,n=(e&FO)!==0,r=(e&IO)!==0,i=(e&LO)!==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 VO()?r>0&&i>0?`move`:r>0?`ew-resize`:`ns-resize`:r>0&&i>0?`grab`:r>0?`col-resize`:`row-resize`}}var UO=new WeakMap;function WO(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=UO.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=DO();switch(r.state){case`active`:case`hover`:{let e=HO({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}UO.set(e,{prevStyle:t,styleSheet:n})}function GO({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=gO({delta:d,initialLayout:f,panelConstraints:h,pivotIndices:e.panels.map(e=>l.indexOf(e)),prevLayout:_,trigger:`mouse-or-touch`});if(_O(t,_)){if(d!==0&&!u)switch(c){case`horizontal`:s|=d<0?PO:FO;break;case`vertical`:s|=d<0?IO:LO;break}}else QD(e.group,{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:t,separatorToPanels:v})}});let c=0;t.movementX===0?c|=o&RO:c|=s&RO,t.movementY===0?c|=o&zO:c|=s&zO,kO(c),WO(e)}function KO(e){let t=XD(),n=DO();switch(n.state){case`active`:GO({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function qO(e){if(e.defaultPrevented)return;let t=DO(),n=XD();switch(t.state){case`active`:if(e.buttons===0){AO({cursorFlags:0,state:`inactive`}),t.hitRegions.forEach(e=>{let t=YD(e.group.id,!0);QD(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)}GO({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break;default:{let r=dO(e,n);r.length===0?t.state!==`inactive`&&AO({cursorFlags:0,state:`inactive`}):AO({cursorFlags:0,hitRegions:r,state:`hover`}),WO(e.currentTarget);break}}}function JO(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(DO().state){case`hover`:AO({cursorFlags:0,state:`inactive`})}}function YO(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=DO();switch(t.state){case`active`:AO({cursorFlags:0,state:`inactive`}),t.hitRegions.length>0&&(WO(e.currentTarget),t.hitRegions.forEach(e=>{let t=YD(e.group.id,!0);QD(e.group,t)}),e.preventDefault())}}function XO(e){let t=0,n=0,r={};for(let i of e)if(i.defaultSize!==void 0){t++;let e=jD(i.defaultSize);n+=e,r[i.panelId]=e}else r[i.panelId]=void 0;let i=e.length-t;if(i!==0){let t=jD((100-n)/i);for(let n of e)n.defaultSize===void 0&&(r[n.panelId]=t)}return r}function ZO(e,t,n){if(!n[0])return;let r=e.panels.find(e=>e.element===t);if(!r||!r.onResize)return;let i=MD({group:e}),a=e.orientation===`horizontal`?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,s={asPercentage:jD(a/i*100),inPixels:a};r.mutableValues.prevSize=s,r.onResize(s,r.id,o)}function QO(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 $O({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=jD(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]=jD((r[e]??0)/a*l);else{let e=jD(l/c.length);for(let t of c)u[t]=e}return u}function ek(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 tk=new Map;function nk(e){let t=!0;PD(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=MD({group:e});if(t===0)return;let n=YD(e.id);if(!n)return;let r=ND(e),i=n.defaultLayoutDeferred?XO(r):n.layout,a=vO({layout:$O({group:e,nextGroupSize:t,prevGroupSize:n.groupSize,prevLayout:i}),panelConstraints:r});if(!n.defaultLayoutDeferred&&_O(n.layout,a)&&QO(n.derivedPanelConstraints,r)&&n.groupSize===t)return;QD(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:r,groupSize:t,layout:a,separatorToPanels:n.separatorToPanels})}}else ZO(e,i,n)}});a.observe(e.element),e.panels.forEach(e=>{PD(!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=MD({group:e}),s=ND(e),c=e.panels.map(({id:e})=>e).join(`,`),l=e.mutableState.defaultLayout;l&&(ek(e.panels,l)||(l=void 0));let u=vO({layout:e.mutableState.layouts[c]??l??XO(s),panelConstraints:s}),d=e.element.ownerDocument;tk.set(d,(tk.get(d)??0)+1);let f=new Map;return UD(e).forEach(e=>{e.separator&&f.set(e.separator,e.panels)}),QD(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:s,groupSize:o,layout:u,separatorToPanels:f}),e.separators.forEach(e=>{PD(!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`,wO)}),tk.get(d)===1&&(d.addEventListener(`dblclick`,bO,!0),d.addEventListener(`pointerdown`,jO,!0),d.addEventListener(`pointerleave`,KO),d.addEventListener(`pointermove`,qO),d.addEventListener(`pointerout`,JO),d.addEventListener(`pointerup`,YO,!0)),function(){t=!1,tk.set(d,Math.max(0,(tk.get(d)??0)-1)),qD(e),e.separators.forEach(e=>{e.element.removeEventListener(`keydown`,wO)}),tk.get(d)||(d.removeEventListener(`dblclick`,bO,!0),d.removeEventListener(`pointerdown`,jO,!0),d.removeEventListener(`pointerleave`,KO),d.removeEventListener(`pointermove`,qO),d.removeEventListener(`pointerout`,JO),d.removeEventListener(`pointerup`,YO,!0)),a.disconnect()}}function rk(){let[e,t]=(0,T.useState)({});return[e,(0,T.useCallback)(()=>t({}),[])]}function ik(e){let t=(0,T.useId)();return`${e??t}`}var ak=typeof window<`u`?T.useLayoutEffect:T.useEffect;function ok(e){let t=(0,T.useRef)(e);return ak(()=>{t.current=e},[e]),(0,T.useCallback)((...e)=>t.current?.(...e),[t])}function sk(...e){return ok(t=>{e.forEach(e=>{if(e)switch(typeof e){case`function`:e(t);break;case`object`:e.current=t;break}})})}function ck(e){let t=(0,T.useRef)({...e});return ak(()=>{for(let n in e)t.current[n]=e[n]},[e]),t.current}var lk=(0,T.createContext)(null);function uk(e,t){let n=(0,T.useRef)({getLayout:()=>({}),setLayout:MO});(0,T.useImperativeHandle)(t,()=>n.current,[]),ak(()=>{Object.assign(n.current,SO({groupId:e}))})}function dk({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,T.useRef)({onLayoutChange:{},onLayoutChanged:{}}),h=ok(e=>{_O(m.current.onLayoutChange,e)||(m.current.onLayoutChange=e,c?.(e))}),g=ok(e=>{_O(m.current.onLayoutChanged,e)||(m.current.onLayoutChanged=e,l?.(e))}),_=ik(s),v=(0,T.useRef)(null),[y,b]=rk(),x=(0,T.useRef)({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),S=sk(v,a);uk(_,o);let C=ok((e,t)=>{let r=DO(),i=JD(e),a=YD(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]}}),w=ck({defaultLayout:n,disableCursor:r}),E=(0,T.useMemo)(()=>({get disableCursor(){return!!w.disableCursor},getPanelStyles:C,id:_,orientation:u,registerPanel:e=>{let t=x.current;return t.panels=FD(u,[...t.panels,e]),b(),()=>{t.panels=t.panels.filter(t=>t!==e),b()}},registerSeparator:e=>{let t=x.current;return t.separators=FD(u,[...t.separators,e]),b(),()=>{t.separators=t.separators.filter(t=>t!==e),b()}},updatePanelProps:(e,{disabled:t})=>{let n=x.current.panels.find(t=>t.id===e);n&&(n.panelConstraints.disabled=t);let r=JD(_),i=YD(_);r&&i&&QD(r,{...i,derivedPanelConstraints:ND(r)})},updateSeparatorProps:(e,{disabled:t,disableDoubleClick:n})=>{let r=x.current.separators.find(t=>t.id===e);r&&(r.disabled=t,r.disableDoubleClick=n)}}),[C,_,b,u,w]),D=(0,T.useRef)(null);return ak(()=>{let e=v.current;if(e===null)return;let t=x.current,n;if(w.defaultLayout!==void 0&&Object.keys(w.defaultLayout).length===t.panels.length){n={};for(let e of t.panels){let t=w.defaultLayout[e.id];t!==void 0&&(n[e.id]=t)}}let r={disabled:!!i,element:e,id:_,mutableState:{defaultLayout:n,disableCursor:!!w.disableCursor,expandedPanelSizes:x.current.lastExpandedPanelSizes,layouts:x.current.layouts},orientation:u,panels:t.panels,resizeTargetMinimumSize:t.resizeTargetMinimumSize,separators:t.separators};D.current=r;let a=nk(r),{defaultLayoutDeferred:o,derivedPanelConstraints:s,layout:c}=YD(r.id,!0);!o&&s.length>0&&(h(c),g(c));let l=ZD(_,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=pO(t.collapsedSize,i[t.panelId]),a=pO(t.collapsedSize,n[t.panelId]);e&&!a&&(r.mutableState.expandedPanelSizes[t.panelId]=n[t.panelId])}}});let o=DO().state!==`active`;h(i),o&&g(i)});return()=>{D.current=null,a(),l()}},[i,_,g,h,u,y,w]),(0,T.useEffect)(()=>{let e=D.current;e&&(e.mutableState.defaultLayout=n,e.mutableState.disableCursor=!!r)}),(0,K.jsx)(lk.Provider,{value:E,children:(0,K.jsx)(`div`,{...p,className:t,"data-group":!0,"data-testid":_,id:_,ref:S,style:{height:`100%`,width:`100%`,overflow:`hidden`,...f,display:`flex`,flexDirection:u===`horizontal`?`row`:`column`,flexWrap:`nowrap`,touchAction:u===`horizontal`?`pan-y`:`pan-x`},children:e})})}dk.displayName=`Group`;function fk(){let e=(0,T.useContext)(lk);return PD(e,`Group Context not found; did you render a Panel or Separator outside of a Group?`),e}function pk(e,t){let{id:n}=fk(),r=(0,T.useRef)({collapse:NO,expand:NO,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:NO});(0,T.useImperativeHandle)(t,()=>r.current,[]),ak(()=>{Object.assign(r.current,yO({groupId:n,panelId:e}))})}function mk({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=ik(c),_=ck({disabled:a}),v=(0,T.useRef)(null),y=sk(v,o),{getPanelStyles:b,id:x,orientation:S,registerPanel:C,updatePanelProps:w}=fk(),E=d!==null,D=ok((e,t,n)=>{d?.(e,c,n)});ak(()=>{let e=v.current;if(e!==null)return C({element:e,id:g,idIsStable:h,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:E?D:void 0,panelConstraints:{groupResizeBehavior:s,collapsedSize:n,collapsible:r,defaultSize:i,disabled:_.disabled,maxSize:l,minSize:u}})},[s,n,r,i,E,g,h,l,u,D,C,_]),(0,T.useEffect)(()=>{w(g,{disabled:a})},[a,g,w]),pk(g,f);let O=()=>{let e=b(x,g);if(e)return JSON.stringify(e)},k=(0,T.useSyncExternalStore)(e=>ZD(x,e),O,O),A;return A=k?JSON.parse(k):i===void 0?{flexGrow:1}:{flexGrow:void 0,flexShrink:void 0,flexBasis:i},(0,K.jsx)(`div`,{...m,"data-disabled":a||void 0,"data-panel":!0,"data-testid":g,id:g,ref:y,style:{...hk,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:S===`horizontal`?`pan-y`:`pan-x`},children:e})})}mk.displayName=`Panel`;var hk={minHeight:0,maxHeight:`100%`,height:`auto`,minWidth:0,maxWidth:`100%`,width:`auto`,border:`none`,borderWidth:0,padding:0,margin:0};function gk({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=vO({layout:gO({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=vO({layout:gO({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:o}}function _k({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:a,style:o,...s}){let c=ik(a),l=ck({disabled:n,disableDoubleClick:r}),[u,d]=(0,T.useState)({}),[f,p]=(0,T.useState)(`inactive`),[m,h]=(0,T.useState)(!1),g=(0,T.useRef)(null),_=sk(g,i),{disableCursor:v,id:y,orientation:b,registerSeparator:x,updateSeparatorProps:S}=fk(),C=b===`horizontal`?`vertical`:`horizontal`;ak(()=>{let e=g.current;if(e!==null){let t={disabled:l.disabled,disableDoubleClick:l.disableDoubleClick,element:e,id:c},n=x(t),r=OO(e=>{p(e.next.state!==`inactive`&&e.next.hitRegions.some(e=>e.separator===t)?e.next.state:`inactive`)}),i=ZD(y,e=>{let{derivedPanelConstraints:n,layout:r,separatorToPanels:i}=e.next,a=i.get(t);if(a){let e=a[0],t=a.indexOf(e);d(gk({layout:r,panelConstraints:n,panelId:e.id,panelIndex:t}))}});return()=>{r(),i(),n()}}},[y,c,x,l]),(0,T.useEffect)(()=>{S(c,{disabled:n,disableDoubleClick:r})},[n,r,c,S]);let w;n&&!v&&(w=`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":C,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":E,"data-testid":c,id:c,onBlur:()=>h(!1),onFocus:()=>h(!0),ref:_,role:`separator`,style:{flexBasis:`auto`,cursor:w,...o,flexGrow:0,flexShrink:0,touchAction:`none`},tabIndex:n?void 0:0})}_k.displayName=`Separator`;var vk=(e,t)=>typeof e==`string`?e===t:JSON.stringify(e)===JSON.stringify(t),yk=(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))&&vk(e.children,t.children)},bk=(e,t)=>yk(e.node,t.node),xk=(e={})=>Object.fromEntries(Object.entries(e??{}).map(([e,t])=>{if(!t)return[e,t];let n=t;return[e,(0,T.memo)(({node:e,...t})=>(0,K.jsx)(n,{...t}),bk)]})),Sk=(0,T.createContext)(null),Ck=()=>(0,T.useContext)(Sk)!==null,wk=(0,T.memo)(({children:e,...t})=>(0,K.jsx)(Sk.Provider,{value:t,children:e}),bk),Tk=({node:e,...t})=>(0,K.jsx)(`pre`,{...t}),Ek=({node:e,...t})=>(0,K.jsx)(`code`,{...t}),Dk=({node:e,components:{Pre:t,Code:n},code:r})=>(0,K.jsx)(t,{children:(0,K.jsx)(n,{node:e,children:r})}),Ok=()=>null,kk=({node:e,components:{Pre:t,Code:n,SyntaxHighlighter:r,CodeHeader:i},language:a,code:o})=>{let s=(0,T.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:Dk,{node:e,components:s,language:a??`unknown`,code:o})]})},Ak=l(o(((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),jk=({className:e,...t})=>({className:n,...r})=>({className:(0,Ak.default)(e,n),...t,...r}),Mk=({node:e,components:{Pre:t,Code:n,SyntaxHighlighter:r,CodeHeader:i},componentsByLanguage:a={},children:o,...s})=>{let c=jk((0,T.useContext)(Sk)),l=ja(e=>(0,K.jsx)(t,{...c(e)})),u=jk(s),d=ja(e=>(0,K.jsx)(n,{...u(e)})),f=/language-(\w+)/.exec(s.className||``)?.[1]??``;return typeof o==`string`?(0,K.jsx)(kk,{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)(Dk,{node:e,components:{Pre:l,Code:d},code:o})},Nk=(0,T.memo)(({node:e,components:t,componentsByLanguage:n,...r})=>Ck()?(0,K.jsx)(Mk,{node:e,components:t,componentsByLanguage:n,...r}):(0,K.jsx)(t.Code,{...r}),(e,t)=>e.components===t.components&&e.componentsByLanguage===t.componentsByLanguage&&bk(e,t));function Pk(){}function Fk(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var Ik=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Lk=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Rk={};function zk(e,t){return((t||Rk).jsx?Lk:Ik).test(e)}var Bk=/[ \t\n\f\r]/g;function Vk(e){return typeof e==`object`?e.type===`text`?Hk(e.value):!1:Hk(e)}function Hk(e){return e.replace(Bk,``)===``}var Uk=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};Uk.prototype.normal={},Uk.prototype.property={},Uk.prototype.space=void 0;function Wk(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new Uk(n,r,t)}function Gk(e){return e.toLowerCase()}var Kk=class{constructor(e,t){this.attribute=t,this.property=e}};Kk.prototype.attribute=``,Kk.prototype.booleanish=!1,Kk.prototype.boolean=!1,Kk.prototype.commaOrSpaceSeparated=!1,Kk.prototype.commaSeparated=!1,Kk.prototype.defined=!1,Kk.prototype.mustUseProperty=!1,Kk.prototype.number=!1,Kk.prototype.overloadedBoolean=!1,Kk.prototype.property=``,Kk.prototype.spaceSeparated=!1,Kk.prototype.space=void 0;var qk=s({boolean:()=>Yk,booleanish:()=>Xk,commaOrSpaceSeparated:()=>eA,commaSeparated:()=>$k,number:()=>Q,overloadedBoolean:()=>Zk,spaceSeparated:()=>Qk}),Jk=0,Yk=tA(),Xk=tA(),Zk=tA(),Q=tA(),Qk=tA(),$k=tA(),eA=tA();function tA(){return 2**++Jk}var nA=Object.keys(qk),rA=class extends Kk{constructor(e,t,n,r){let i=-1;if(super(e,t),iA(this,`space`,r),typeof n==`number`)for(;++i<nA.length;){let e=nA[i];iA(this,nA[i],(n&qk[e])===qk[e])}}};rA.prototype.defined=!0;function iA(e,t,n){n&&(e[t]=n)}function aA(e){let t={},n={};for(let[r,i]of Object.entries(e.properties)){let a=new rA(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(a.mustUseProperty=!0),t[r]=a,n[Gk(r)]=r,n[Gk(a.attribute)]=r}return new Uk(t,n,e.space)}var oA=aA({properties:{ariaActiveDescendant:null,ariaAtomic:Xk,ariaAutoComplete:null,ariaBusy:Xk,ariaChecked:Xk,ariaColCount:Q,ariaColIndex:Q,ariaColSpan:Q,ariaControls:Qk,ariaCurrent:null,ariaDescribedBy:Qk,ariaDetails:null,ariaDisabled:Xk,ariaDropEffect:Qk,ariaErrorMessage:null,ariaExpanded:Xk,ariaFlowTo:Qk,ariaGrabbed:Xk,ariaHasPopup:null,ariaHidden:Xk,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Qk,ariaLevel:Q,ariaLive:null,ariaModal:Xk,ariaMultiLine:Xk,ariaMultiSelectable:Xk,ariaOrientation:null,ariaOwns:Qk,ariaPlaceholder:null,ariaPosInSet:Q,ariaPressed:Xk,ariaReadOnly:Xk,ariaRelevant:null,ariaRequired:Xk,ariaRoleDescription:Qk,ariaRowCount:Q,ariaRowIndex:Q,ariaRowSpan:Q,ariaSelected:Xk,ariaSetSize:Q,ariaSort:null,ariaValueMax:Q,ariaValueMin:Q,ariaValueNow:Q,ariaValueText:null,role:null},transform(e,t){return t===`role`?t:`aria-`+t.slice(4).toLowerCase()}});function sA(e,t){return t in e?e[t]:t}function cA(e,t){return sA(e,t.toLowerCase())}var lA=aA({attributes:{acceptcharset:`accept-charset`,classname:`class`,htmlfor:`for`,httpequiv:`http-equiv`},mustUseProperty:[`checked`,`multiple`,`muted`,`selected`],properties:{abbr:null,accept:$k,acceptCharset:Qk,accessKey:Qk,action:null,allow:null,allowFullScreen:Yk,allowPaymentRequest:Yk,allowUserMedia:Yk,alt:null,as:null,async:Yk,autoCapitalize:null,autoComplete:Qk,autoFocus:Yk,autoPlay:Yk,blocking:Qk,capture:null,charSet:null,checked:Yk,cite:null,className:Qk,cols:Q,colSpan:null,content:null,contentEditable:Xk,controls:Yk,controlsList:Qk,coords:Q|$k,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Yk,defer:Yk,dir:null,dirName:null,disabled:Yk,download:Zk,draggable:Xk,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Yk,formTarget:null,headers:Qk,height:Q,hidden:Zk,high:Q,href:null,hrefLang:null,htmlFor:Qk,httpEquiv:Qk,id:null,imageSizes:null,imageSrcSet:null,inert:Yk,inputMode:null,integrity:null,is:null,isMap:Yk,itemId:null,itemProp:Qk,itemRef:Qk,itemScope:Yk,itemType:Qk,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Yk,low:Q,manifest:null,max:null,maxLength:Q,media:null,method:null,min:null,minLength:Q,multiple:Yk,muted:Yk,name:null,nonce:null,noModule:Yk,noValidate:Yk,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:Yk,optimum:Q,pattern:null,ping:Qk,placeholder:null,playsInline:Yk,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Yk,referrerPolicy:null,rel:Qk,required:Yk,reversed:Yk,rows:Q,rowSpan:Q,sandbox:Qk,scope:null,scoped:Yk,seamless:Yk,selected:Yk,shadowRootClonable:Yk,shadowRootDelegatesFocus:Yk,shadowRootMode:null,shape:null,size:Q,sizes:null,slot:null,span:Q,spellCheck:Xk,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Q,step:null,style:null,tabIndex:Q,target:null,title:null,translate:null,type:null,typeMustMatch:Yk,useMap:null,value:Xk,width:Q,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Qk,axis:null,background:null,bgColor:null,border:Q,borderColor:null,bottomMargin:Q,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Yk,declare:Yk,event:null,face:null,frame:null,frameBorder:null,hSpace:Q,leftMargin:Q,link:null,longDesc:null,lowSrc:null,marginHeight:Q,marginWidth:Q,noResize:Yk,noHref:Yk,noShade:Yk,noWrap:Yk,object:null,profile:null,prompt:null,rev:null,rightMargin:Q,rules:null,scheme:null,scrolling:Xk,standby:null,summary:null,text:null,topMargin:Q,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Q,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Yk,disableRemotePlayback:Yk,prefix:null,property:null,results:Q,security:null,unselectable:null},space:`html`,transform:cA}),uA=aA({attributes:{accentHeight:`accent-height`,alignmentBaseline:`alignment-baseline`,arabicForm:`arabic-form`,baselineShift:`baseline-shift`,capHeight:`cap-height`,className:`class`,clipPath:`clip-path`,clipRule:`clip-rule`,colorInterpolation:`color-interpolation`,colorInterpolationFilters:`color-interpolation-filters`,colorProfile:`color-profile`,colorRendering:`color-rendering`,crossOrigin:`crossorigin`,dataType:`datatype`,dominantBaseline:`dominant-baseline`,enableBackground:`enable-background`,fillOpacity:`fill-opacity`,fillRule:`fill-rule`,floodColor:`flood-color`,floodOpacity:`flood-opacity`,fontFamily:`font-family`,fontSize:`font-size`,fontSizeAdjust:`font-size-adjust`,fontStretch:`font-stretch`,fontStyle:`font-style`,fontVariant:`font-variant`,fontWeight:`font-weight`,glyphName:`glyph-name`,glyphOrientationHorizontal:`glyph-orientation-horizontal`,glyphOrientationVertical:`glyph-orientation-vertical`,hrefLang:`hreflang`,horizAdvX:`horiz-adv-x`,horizOriginX:`horiz-origin-x`,horizOriginY:`horiz-origin-y`,imageRendering:`image-rendering`,letterSpacing:`letter-spacing`,lightingColor:`lighting-color`,markerEnd:`marker-end`,markerMid:`marker-mid`,markerStart:`marker-start`,navDown:`nav-down`,navDownLeft:`nav-down-left`,navDownRight:`nav-down-right`,navLeft:`nav-left`,navNext:`nav-next`,navPrev:`nav-prev`,navRight:`nav-right`,navUp:`nav-up`,navUpLeft:`nav-up-left`,navUpRight:`nav-up-right`,onAbort:`onabort`,onActivate:`onactivate`,onAfterPrint:`onafterprint`,onBeforePrint:`onbeforeprint`,onBegin:`onbegin`,onCancel:`oncancel`,onCanPlay:`oncanplay`,onCanPlayThrough:`oncanplaythrough`,onChange:`onchange`,onClick:`onclick`,onClose:`onclose`,onCopy:`oncopy`,onCueChange:`oncuechange`,onCut:`oncut`,onDblClick:`ondblclick`,onDrag:`ondrag`,onDragEnd:`ondragend`,onDragEnter:`ondragenter`,onDragExit:`ondragexit`,onDragLeave:`ondragleave`,onDragOver:`ondragover`,onDragStart:`ondragstart`,onDrop:`ondrop`,onDurationChange:`ondurationchange`,onEmptied:`onemptied`,onEnd:`onend`,onEnded:`onended`,onError:`onerror`,onFocus:`onfocus`,onFocusIn:`onfocusin`,onFocusOut:`onfocusout`,onHashChange:`onhashchange`,onInput:`oninput`,onInvalid:`oninvalid`,onKeyDown:`onkeydown`,onKeyPress:`onkeypress`,onKeyUp:`onkeyup`,onLoad:`onload`,onLoadedData:`onloadeddata`,onLoadedMetadata:`onloadedmetadata`,onLoadStart:`onloadstart`,onMessage:`onmessage`,onMouseDown:`onmousedown`,onMouseEnter:`onmouseenter`,onMouseLeave:`onmouseleave`,onMouseMove:`onmousemove`,onMouseOut:`onmouseout`,onMouseOver:`onmouseover`,onMouseUp:`onmouseup`,onMouseWheel:`onmousewheel`,onOffline:`onoffline`,onOnline:`ononline`,onPageHide:`onpagehide`,onPageShow:`onpageshow`,onPaste:`onpaste`,onPause:`onpause`,onPlay:`onplay`,onPlaying:`onplaying`,onPopState:`onpopstate`,onProgress:`onprogress`,onRateChange:`onratechange`,onRepeat:`onrepeat`,onReset:`onreset`,onResize:`onresize`,onScroll:`onscroll`,onSeeked:`onseeked`,onSeeking:`onseeking`,onSelect:`onselect`,onShow:`onshow`,onStalled:`onstalled`,onStorage:`onstorage`,onSubmit:`onsubmit`,onSuspend:`onsuspend`,onTimeUpdate:`ontimeupdate`,onToggle:`ontoggle`,onUnload:`onunload`,onVolumeChange:`onvolumechange`,onWaiting:`onwaiting`,onZoom:`onzoom`,overlinePosition:`overline-position`,overlineThickness:`overline-thickness`,paintOrder:`paint-order`,panose1:`panose-1`,pointerEvents:`pointer-events`,referrerPolicy:`referrerpolicy`,renderingIntent:`rendering-intent`,shapeRendering:`shape-rendering`,stopColor:`stop-color`,stopOpacity:`stop-opacity`,strikethroughPosition:`strikethrough-position`,strikethroughThickness:`strikethrough-thickness`,strokeDashArray:`stroke-dasharray`,strokeDashOffset:`stroke-dashoffset`,strokeLineCap:`stroke-linecap`,strokeLineJoin:`stroke-linejoin`,strokeMiterLimit:`stroke-miterlimit`,strokeOpacity:`stroke-opacity`,strokeWidth:`stroke-width`,tabIndex:`tabindex`,textAnchor:`text-anchor`,textDecoration:`text-decoration`,textRendering:`text-rendering`,transformOrigin:`transform-origin`,typeOf:`typeof`,underlinePosition:`underline-position`,underlineThickness:`underline-thickness`,unicodeBidi:`unicode-bidi`,unicodeRange:`unicode-range`,unitsPerEm:`units-per-em`,vAlphabetic:`v-alphabetic`,vHanging:`v-hanging`,vIdeographic:`v-ideographic`,vMathematical:`v-mathematical`,vectorEffect:`vector-effect`,vertAdvY:`vert-adv-y`,vertOriginX:`vert-origin-x`,vertOriginY:`vert-origin-y`,wordSpacing:`word-spacing`,writingMode:`writing-mode`,xHeight:`x-height`,playbackOrder:`playbackorder`,timelineBegin:`timelinebegin`},properties:{about:eA,accentHeight:Q,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Q,amplitude:Q,arabicForm:null,ascent:Q,attributeName:null,attributeType:null,azimuth:Q,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Q,by:null,calcMode:null,capHeight:Q,className:Qk,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:Q,diffuseConstant:Q,direction:null,display:null,dur:null,divisor:Q,dominantBaseline:null,download:Yk,dx:null,dy:null,edgeMode:null,editable:null,elevation:Q,enableBackground:null,end:null,event:null,exponent:Q,externalResourcesRequired:null,fill:null,fillOpacity:Q,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:$k,g2:$k,glyphName:$k,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Q,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Q,horizOriginX:Q,horizOriginY:Q,id:null,ideographic:Q,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Q,k:Q,k1:Q,k2:Q,k3:Q,k4:Q,kernelMatrix:eA,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Q,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Q,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:Q,overlineThickness:Q,paintOrder:null,panose1:null,path:null,pathLength:Q,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Qk,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Q,pointsAtY:Q,pointsAtZ:Q,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:eA,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:eA,rev:eA,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:eA,requiredFeatures:eA,requiredFonts:eA,requiredFormats:eA,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:Q,specularExponent:Q,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Q,strikethroughThickness:Q,string:null,stroke:null,strokeDashArray:eA,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Q,strokeOpacity:Q,strokeWidth:null,style:null,surfaceScale:Q,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:eA,tabIndex:Q,tableValues:null,target:null,targetX:Q,targetY:Q,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:eA,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Q,underlineThickness:Q,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Q,values:null,vAlphabetic:Q,vMathematical:Q,vectorEffect:null,vHanging:Q,vIdeographic:Q,version:null,vertAdvY:Q,vertOriginX:Q,vertOriginY:Q,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Q,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:`svg`,transform:sA}),dA=aA({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()}}),fA=aA({attributes:{xmlnsxlink:`xmlns:xlink`},properties:{xmlnsXLink:null,xmlns:null},space:`xmlns`,transform:cA}),pA=aA({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:`xml`,transform(e,t){return`xml:`+t.slice(3).toLowerCase()}}),mA={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`},hA=/[A-Z]/g,gA=/-[a-z]/g,_A=/^data[-\w.:]+$/i;function vA(e,t){let n=Gk(t),r=t,i=Kk;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)===`data`&&_A.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(gA,bA);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!gA.test(e)){let n=e.replace(hA,yA);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=rA}return new i(r,t)}function yA(e){return`-`+e.toLowerCase()}function bA(e){return e.charAt(1).toUpperCase()}var xA=Wk([oA,lA,dA,fA,pA],`html`),SA=Wk([oA,uA,dA,fA,pA],`svg`);function CA(e){return e.join(` `).trim()}var wA=o(((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})),TA=o((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(wA());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}})),EA=o((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))}})),DA=o(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(TA()),r=EA();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})),OA=AA(`end`),kA=AA(`start`);function AA(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 jA(e){let t=kA(e),n=OA(e);if(t&&n)return{start:t,end:n}}function MA(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?PA(e.position):`start`in e||`end`in e?PA(e):`line`in e||`column`in e?NA(e):``}function NA(e){return FA(e&&e.line)+`:`+FA(e&&e.column)}function PA(e){return NA(e&&e.start)+`-`+NA(e&&e.end)}function FA(e){return e&&typeof e==`number`?e:1}var IA=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=MA(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}};IA.prototype.file=``,IA.prototype.name=``,IA.prototype.reason=``,IA.prototype.message=``,IA.prototype.stack=``,IA.prototype.column=void 0,IA.prototype.line=void 0,IA.prototype.ancestors=void 0,IA.prototype.cause=void 0,IA.prototype.fatal=void 0,IA.prototype.place=void 0,IA.prototype.ruleId=void 0,IA.prototype.source=void 0;var LA=l(DA(),1),RA={}.hasOwnProperty,zA=new Map,BA=/[A-Z]/g,VA=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),HA=new Set([`td`,`th`]);function UA(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=ej(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=$A(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`?SA:xA,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=WA(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function WA(e,t,n){if(t.type===`element`)return GA(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return KA(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return JA(e,t,n);if(t.type===`mdxjsEsm`)return qA(e,t);if(t.type===`root`)return YA(e,t,n);if(t.type===`text`)return XA(e,t)}function GA(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=SA,e.schema=i),e.ancestors.push(t);let a=oj(e,t.tagName,!1),o=tj(e,t),s=rj(e,t);return VA.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!Vk(e):!0})),ZA(e,o,a,t),QA(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function KA(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)}sj(e,t.position)}function qA(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);sj(e,t.position)}function JA(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=SA,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:oj(e,t.name,!0),o=nj(e,t),s=rj(e,t);return ZA(e,o,a,t),QA(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function YA(e,t,n){let r={};return QA(r,rj(e,t)),e.create(t,e.Fragment,r,n)}function XA(e,t){return t.value}function ZA(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function QA(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function $A(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 ej(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=kA(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 tj(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&RA.call(t.properties,i)){let a=ij(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&HA.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 nj(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 sj(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 sj(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function rj(e,t){let n=[],r=-1,i=e.passKeys?new Map:zA;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=WA(e,a,o);s!==void 0&&n.push(s)}return n}function ij(e,t,n){let r=vA(e.schema,t);if(!(n==null||typeof n==`number`&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?Fk(n):CA(n)),r.property===`style`){let t=typeof n==`object`?n:aj(e,String(n));return e.stylePropertyNameCase===`css`&&(t=cj(t)),[`style`,t]}return[e.elementAttributeNameCase===`react`&&r.space?mA[r.property]||r.property:r.attribute,n]}}function aj(e,t){try{return(0,LA.default)(t,{reactCompat:!0})}catch(t){if(e.ignoreInvalidStyle)return{};let n=t,r=new IA("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 oj(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=zk(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=zk(t)&&!/^[a-z]/.test(t)?{type:`Identifier`,name:t}:{type:`Literal`,value:t};if(r.type===`Literal`){let t=r.value;return RA.call(e.components,t)?e.components[t]:t}if(e.evaluater)return e.evaluater.evaluateExpression(r);sj(e)}function sj(e,t){let n=new IA("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 cj(e){let t={},n;for(n in e)RA.call(e,n)&&(t[lj(n)]=e[n]);return t}function lj(e){let t=e.replace(BA,uj);return t.slice(0,3)===`ms-`&&(t=`-`+t),t}function uj(e){return`-`+e.toLowerCase()}var dj={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`]},fj={};function pj(e,t){let n=t||fj;return mj(e,typeof n.includeImageAlt==`boolean`?n.includeImageAlt:!0,typeof n.includeHtml==`boolean`?n.includeHtml:!0)}function mj(e,t,n){if(gj(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 hj(e.children,t,n)}return Array.isArray(e)?hj(e,t,n):``}function hj(e,t,n){let r=[],i=-1;for(;++i<e.length;)r[i]=mj(e[i],t,n);return r.join(``)}function gj(e){return!!(e&&typeof e==`object`)}var _j=document.createElement(`i`);function vj(e){let t=`&`+e+`;`;_j.innerHTML=t;let n=_j.textContent;return n.charCodeAt(n.length-1)===59&&e!==`semi`||n===t?!1:n}function yj(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 bj(e,t){return e.length>0?(yj(e,e.length,0,t),e):t}var xj={}.hasOwnProperty;function Sj(e){let t={},n=-1;for(;++n<e.length;)Cj(t,e[n]);return t}function Cj(e,t){let n;for(n in t){let r=(xj.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n],a;if(i)for(a in i){xj.call(r,a)||(r[a]=[]);let e=i[a];wj(r[a],Array.isArray(e)?e:e?[e]:[])}}}function wj(e,t){let n=-1,r=[];for(;++n<t.length;)(t[n].add===`after`?e:r).push(t[n]);yj(e,0,0,r)}function Tj(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 Ej(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var Dj=Rj(/[A-Za-z]/),Oj=Rj(/[\dA-Za-z]/),kj=Rj(/[#-'*+\--9=?A-Z^-~]/);function Aj(e){return e!==null&&(e<32||e===127)}var jj=Rj(/\d/),Mj=Rj(/[\dA-Fa-f]/),Nj=Rj(/[!-/:-@[-`{-~]/);function $(e){return e!==null&&e<-2}function Pj(e){return e!==null&&(e<0||e===32)}function Fj(e){return e===-2||e===-1||e===32}var Ij=Rj(/\p{P}|\p{S}/u),Lj=Rj(/\s/);function Rj(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function zj(e){let t=[],n=-1,r=0,i=0;for(;++n<e.length;){let a=e.charCodeAt(n),o=``;if(a===37&&Oj(e.charCodeAt(n+1))&&Oj(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 Bj(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return Fj(r)?(e.enter(n),s(r)):t(r)}function s(r){return Fj(r)&&a++<i?(e.consume(r),s):(e.exit(n),t(r))}}var Vj={tokenize:Hj};function Hj(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`),Bj(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 $(t)?(e.consume(t),e.exit(`chunkText`),a):(e.consume(t),o)}}var Uj={tokenize:Gj},Wj={tokenize:Kj};function Gj(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 yj(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(Wj,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(Wj,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 $(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++;yj(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 Kj(e,t,n){return Bj(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function qj(e){if(e===null||Pj(e)||Lj(e))return 1;if(Ij(e))return 2}function Jj(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 Yj={name:`attention`,resolveAll:Xj,tokenize:Zj};function Xj(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};Qj(d,-c),Qj(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=bj(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=bj(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=bj(l,Jj(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=bj(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=bj(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,yj(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 Zj(e,t){let n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=qj(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=qj(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 Qj(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}var $j={name:`autolink`,tokenize:eM};function eM(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 Dj(t)?(e.consume(t),o):t===64?n(t):l(t)}function o(e){return e===43||e===45||e===46||Oj(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||Oj(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||Aj(r)?n(r):(e.consume(r),c)}function l(t){return t===64?(e.consume(t),u):kj(t)?(e.consume(t),l):n(t)}function u(e){return Oj(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||Oj(t))&&r++<63){let n=t===45?f:d;return e.consume(t),n}return n(t)}}var tM={partial:!0,tokenize:nM};function nM(e,t,n){return r;function r(t){return Fj(t)?Bj(e,i,`linePrefix`)(t):i(t)}function i(e){return e===null||$(e)?t(e):n(e)}}var rM={continuation:{tokenize:aM},exit:oM,name:`blockQuote`,tokenize:iM};function iM(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 Fj(n)?(e.enter(`blockQuotePrefixWhitespace`),e.consume(n),e.exit(`blockQuotePrefixWhitespace`),e.exit(`blockQuotePrefix`),t):(e.exit(`blockQuotePrefix`),t(n))}}function aM(e,t,n){let r=this;return i;function i(t){return Fj(t)?Bj(e,a,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):a(t)}function a(r){return e.attempt(rM,t,n)(r)}}function oM(e){e.exit(`blockQuote`)}var sM={name:`characterEscape`,tokenize:cM};function cM(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 Nj(r)?(e.enter(`characterEscapeValue`),e.consume(r),e.exit(`characterEscapeValue`),e.exit(`characterEscape`),t):n(r)}}var lM={name:`characterReference`,tokenize:uM};function uM(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=Oj,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=Mj,u):(e.enter(`characterReferenceValue`),a=7,o=jj,u(t))}function u(s){if(s===59&&i){let i=e.exit(`characterReferenceValue`);return o===Oj&&!vj(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 dM={partial:!0,tokenize:mM},fM={concrete:!0,name:`codeFenced`,tokenize:pM};function pM(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`),Fj(t)?Bj(e,d,`whitespace`)(t):d(t))}function d(n){return n===null||$(n)?(e.exit(`codeFencedFence`),r.interrupt?t(n):e.check(dM,h,b)(n)):(e.enter(`codeFencedFenceInfo`),e.enter(`chunkString`,{contentType:`string`}),f(n))}function f(t){return t===null||$(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),d(t)):Fj(t)?(e.exit(`chunkString`),e.exit(`codeFencedFenceInfo`),Bj(e,p,`whitespace`)(t)):t===96&&t===s?n(t):(e.consume(t),f)}function p(t){return t===null||$(t)?d(t):(e.enter(`codeFencedFenceMeta`),e.enter(`chunkString`,{contentType:`string`}),m(t))}function m(t){return t===null||$(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&&Fj(t)?Bj(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||$(t)?e.check(dM,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||$(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`),Fj(t)?Bj(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`),Fj(t)?Bj(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||$(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function mM(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 hM={name:`codeIndented`,tokenize:_M},gM={partial:!0,tokenize:vM};function _M(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),Bj(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):$(t)?e.attempt(gM,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||$(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function vM(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):$(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):Bj(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):$(e)?i(e):n(e)}}var yM={name:`codeText`,previous:xM,resolve:bM,tokenize:SM};function bM(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 xM(e){return e!==96||this.events[this.events.length-1][1].type===`characterEscape`}function SM(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)):$(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||$(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 CM=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&&wM(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),wM(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),wM(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);wM(this.right,t.reverse())}else{let t=this.right.splice(this.left.length+this.right.length-e,1/0);wM(this.left,t.reverse())}}};function wM(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 TM(e){let t={},n=-1,r,i,a,o,s,c,l,u=new CM(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,EM(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 yj(e,0,1/0,u.slice(0)),!l}function EM(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 DM={resolve:kM,tokenize:AM},OM={partial:!0,tokenize:jM};function kM(e){return TM(e),e}function AM(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):$(t)?e.check(OM,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 jM(e,t,n){let r=this;return i;function i(t){return e.exit(`chunkContent`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),Bj(e,a,`linePrefix`)}function a(i){if(i===null||$(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 MM(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||Aj(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||$(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||Pj(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||Aj(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 NM(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):$(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||$(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!Fj(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function PM(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):$(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),Bj(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||$(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 FM(e,t){let n;return r;function r(i){return $(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):Fj(i)?Bj(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var IM={name:`definition`,tokenize:RM},LM={partial:!0,tokenize:zM};function RM(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return NM.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=Ej(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 Pj(t)?FM(e,l)(t):l(t)}function l(t){return MM(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(LM,d,d)(t)}function d(t){return Fj(t)?Bj(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||$(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function zM(e,t,n){return r;function r(t){return Pj(t)?FM(e,i)(t):n(t)}function i(t){return PM(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return Fj(t)?Bj(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||$(e)?t(e):n(e)}}var BM={name:`hardBreakEscape`,tokenize:VM};function VM(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return $(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var HM={name:`headingAtx`,resolve:UM,tokenize:WM};function UM(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`},yj(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function WM(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||Pj(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||$(n)?(e.exit(`atxHeading`),t(n)):Fj(n)?Bj(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||Pj(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var GM=`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(`.`),KM=[`pre`,`script`,`style`,`textarea`],qM={concrete:!0,name:`htmlFlow`,resolveTo:XM,tokenize:ZM},JM={partial:!0,tokenize:$M},YM={partial:!0,tokenize:QM};function XM(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 ZM(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):Dj(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):Dj(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 Dj(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||Pj(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&KM.includes(l)?(i=1,r.interrupt?t(s):O(s)):GM.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||Oj(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 Fj(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||Dj(t)?(e.consume(t),b):Fj(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||Oj(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):Fj(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):Fj(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||$(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||Pj(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||Fj(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||$(t)?O(t):Fj(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):$(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(JM,R,k)(t)):t===null||$(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(YM,A,R)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return t===null||$(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 KM.includes(n)?(e.consume(t),L):O(t)}return Dj(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||$(t)?(e.exit(`htmlFlowData`),R(t)):(e.consume(t),L)}function R(n){return e.exit(`htmlFlow`),t(n)}}function QM(e,t,n){let r=this;return i;function i(t){return $(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 $M(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(tM,t,n)}}var eN={name:`htmlText`,tokenize:tN};function tN(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):Dj(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):Dj(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):$(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):$(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):$(t)?(o=v,N(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):$(t)?(o=y,N(t)):(e.consume(t),y)}function b(e){return e===62?M(e):y(e)}function x(t){return Dj(t)?(e.consume(t),S):n(t)}function S(t){return t===45||Oj(t)?(e.consume(t),S):C(t)}function C(t){return $(t)?(o=C,N(t)):Fj(t)?(e.consume(t),C):M(t)}function w(t){return t===45||Oj(t)?(e.consume(t),w):t===47||t===62||Pj(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),M):t===58||t===95||Dj(t)?(e.consume(t),E):$(t)?(o=T,N(t)):Fj(t)?(e.consume(t),T):M(t)}function E(t){return t===45||t===46||t===58||t===95||Oj(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):$(t)?(o=D,N(t)):Fj(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):$(t)?(o=O,N(t)):Fj(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):$(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||Pj(t)?T(t):(e.consume(t),A)}function j(e){return e===47||e===62||Pj(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 Fj(t)?Bj(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 nN={name:`labelEnd`,resolveAll:oN,resolveTo:sN,tokenize:cN},rN={tokenize:lN},iN={tokenize:uN},aN={tokenize:dN};function oN(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&&yj(e,0,e.length,n),e}function sN(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=bj(s,e.slice(a+1,a+r+3)),s=bj(s,[[`enter`,u,t]]),s=bj(s,Jj(t.parser.constructs.insideSpan.null,e.slice(a+r+4,o-3),t)),s=bj(s,[[`exit`,u,t],e[o-2],e[o-1],[`exit`,l,t]]),s=bj(s,e.slice(o+1)),s=bj(s,[[`exit`,c,t]]),yj(e,a,e.length,s),e}function cN(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(Ej(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(rN,u,o?u:d)(t):t===91?e.attempt(iN,u,o?l:d)(t):o?u(t):d(t)}function l(t){return e.attempt(aN,u,d)(t)}function u(e){return t(e)}function d(e){return a._balanced=!0,n(e)}}function lN(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 Pj(t)?FM(e,a)(t):a(t)}function a(t){return t===41?u(t):MM(e,o,s,`resourceDestination`,`resourceDestinationLiteral`,`resourceDestinationLiteralMarker`,`resourceDestinationRaw`,`resourceDestinationString`,32)(t)}function o(t){return Pj(t)?FM(e,c)(t):u(t)}function s(e){return n(e)}function c(t){return t===34||t===39||t===40?PM(e,l,n,`resourceTitle`,`resourceTitleMarker`,`resourceTitleString`)(t):u(t)}function l(t){return Pj(t)?FM(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 uN(e,t,n){let r=this;return i;function i(t){return NM.call(r,e,a,o,`reference`,`referenceMarker`,`referenceString`)(t)}function a(e){return r.parser.defined.includes(Ej(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(e):n(e)}function o(e){return n(e)}}function dN(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 fN={name:`labelStartImage`,resolveAll:nN.resolveAll,tokenize:pN};function pN(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 mN={name:`labelStartLink`,resolveAll:nN.resolveAll,tokenize:hN};function hN(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 gN={name:`lineEnding`,tokenize:_N};function _N(e,t){return n;function n(n){return e.enter(`lineEnding`),e.consume(n),e.exit(`lineEnding`),Bj(e,t,`linePrefix`)}}var vN={name:`thematicBreak`,tokenize:yN};function yN(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||$(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),Fj(t)?Bj(e,s,`whitespace`)(t):s(t))}}var bN={continuation:{tokenize:wN},exit:EN,name:`list`,tokenize:CN},xN={partial:!0,tokenize:DN},SN={partial:!0,tokenize:TN};function CN(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:jj(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(vN,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 jj(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(tM,r.interrupt?n:u,e.attempt(xN,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return Fj(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 wN(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(tM,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,Bj(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!Fj(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(SN,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,Bj(e,e.attempt(bN,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function TN(e,t,n){let r=this;return Bj(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 EN(e){e.exit(this.containerState.type)}function DN(e,t,n){let r=this;return Bj(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!Fj(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var ON={name:`setextUnderline`,resolveTo:kN,tokenize:AN};function kN(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 AN(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`),Fj(t)?Bj(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||$(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var jN={tokenize:MN};function MN(e){let t=this,n=e.attempt(tM,r,e.attempt(this.parser.constructs.flowInitial,i,Bj(e,e.attempt(this.parser.constructs.flow,i,e.attempt(DM,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 NN={resolveAll:LN()},PN=IN(`string`),FN=IN(`text`);function IN(e){return{resolveAll:LN(e===`text`?RN: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 LN(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 RN(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 zN=s({attentionMarkers:()=>qN,contentInitial:()=>VN,disable:()=>JN,document:()=>BN,flow:()=>UN,flowInitial:()=>HN,insideSpan:()=>KN,string:()=>WN,text:()=>GN}),BN={42:bN,43:bN,45:bN,48:bN,49:bN,50:bN,51:bN,52:bN,53:bN,54:bN,55:bN,56:bN,57:bN,62:rM},VN={91:IM},HN={[-2]:hM,[-1]:hM,32:hM},UN={35:HM,42:vN,45:[ON,vN],60:qM,61:ON,95:vN,96:fM,126:fM},WN={38:lM,92:sM},GN={[-5]:gN,[-4]:gN,[-3]:gN,33:fN,38:lM,42:Yj,60:[$j,eN],91:mN,92:[BM,sM],93:nN,95:Yj,96:yM},KN={null:[Yj,NN]},qN={null:[42,95]},JN={null:[]};function YN(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=bj(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=Jj(a,l.events,l),l.events):[]}function f(e,t){return ZN(p(e),t)}function p(e){return XN(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){$(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&&yj(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 XN(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 ZN(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,7 +104,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),i=e,r=t),n===void 0&&(
|
|
|
104
104
|
`),r=(0,T.useMemo)(()=>{try{if(t)return gU.highlight(e,{language:t,ignoreIllegals:!0}).value;{let t=gU.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 tW({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 nW({toolName:e,args:t,result:n,status:r=`complete`,elapsedSeconds:i,taskState:a,toolCallId:o}){let s=UU(e),c=s.icon,l=GU(e,t),[u,d]=(0,T.useState)(!1),f=r===`complete`,p=r===`running`,m=r===`requires-action`,h=HU[r],g=vU(),{permissionPrompt:_,answerPermission:v,openFile:y}=MU(),b=m||_?.toolUseId===o,x=u||b,S=VU(p,i),C=f&&n?KU(n):null,w=C!==null,E=e===`Bash`,D=e===`TodoWrite`,O=e===`Agent`||e===`Task`,k=e===`Write`,A=e===`Edit`||e===`ApplyPatch`,j=Object.keys(t).length>0,M=t.content??``,N=t.old_string??``,P=t.new_string??``,F=A&&N&&P,I=WU(t.file_path||t.filePath||``),L=!!(y&&I&&f),R=(0,T.useMemo)(()=>{let e=I.includes(`.`)?I.split(`.`).pop()?.toLowerCase()??``:``;return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,rs:`rust`,go:`go`,rb:`ruby`,swift:`swift`,java:`java`,c:`c`,cpp:`cpp`,cs:`csharp`,kt:`kotlin`,json:`json`,yaml:`yaml`,yml:`yaml`,toml:`ini`,xml:`xml`,html:`xml`,htm:`xml`,svg:`xml`,css:`css`,scss:`scss`,less:`less`,sql:`sql`,sh:`bash`,bash:`bash`,zsh:`bash`,fish:`bash`,md:`markdown`,dockerfile:`dockerfile`,proto:`protobuf`,php:`php`,lua:`lua`,r:`r`,scala:`scala`}[e]||(e&&e.length<=5?e:``)},[I]),z=D?Array.isArray(t.todos)?t.todos:[]:null,B=x?null:k&&M?ZU(M,200):A&&(w||F)?{type:`edit`,oldStr:N,newStr:P,diff:C}:null;return(0,K.jsxs)(Iz,{open:x,onOpenChange:d,className:Y(`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)(Lz,{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})]}),b?(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:BU(S)}):(0,K.jsx)(`span`,{className:Y(`ml-auto shrink-0 rounded px-1.5 py-px text-[10px] font-medium`,h.className),children:h.label}),(0,K.jsx)(U,{className:Y(`h-3.5 w-3.5 shrink-0 text-gray-300 transition-transform`,u&&`rotate-180`)})]}),B&&(0,K.jsx)(`div`,{className:`border-t border-gray-100 px-2 md:px-3 py-1.5`,children:typeof B==`string`?(0,K.jsx)(`pre`,{className:`font-mono text-[10px] leading-relaxed text-gray-500 whitespace-pre-wrap break-all line-clamp-3`,children:B}):B.type===`edit`?B.diff&&n?(0,K.jsx)(YU,{text:n,lang:R,maxLines:8}):(0,K.jsx)(`div`,{className:`opacity-70`,children:(0,K.jsx)($U,{oldStr:B.oldStr,newStr:B.newStr,maxLen:20,lang:R})}):null})]}),(0,K.jsx)(Rz,{className:Y(`overflow-hidden`,`data-[state=open]:animate-collapsible-down`,`data-[state=closed]:animate-collapsible-up`),children:(0,K.jsxs)(`div`,{className:Y(`border-t border-gray-100 px-2 md:px-3 py-2`,g&&`max-h-[60vh] overflow-y-auto`),children:[b&&_&&(0,K.jsx)(zU,{toolName:_.toolName,title:_.title,displayName:_.displayName,onAllow:()=>v(_.toolUseId,!0),onDeny:()=>v(_.toolUseId,!1)}),L&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>y(I),className:`inline-flex items-center gap-1 mb-2 px-2 py-1 rounded text-[11px] border border-gray-200 bg-white hover:bg-gray-50 text-gray-600 hover:text-gray-900 transition-colors`,children:[(0,K.jsx)(de,{className:`h-3 w-3`}),`Open in Editor`]}),k&&f&&M&&(0,K.jsx)(XU,{content:M,lang:R}),A&&f&&w&&n&&(0,K.jsx)(YU,{text:n,lang:R}),A&&f&&!w&&F&&(0,K.jsx)($U,{oldStr:N,newStr:P,lang:R}),E&&(l||n!==void 0)&&(0,K.jsx)(tW,{command:l,output:n}),D&&z&&z.length>0&&(0,K.jsx)(bU,{todos:z}),O&&(0,K.jsx)(LU,{args:t,result:n,status:r,taskState:a,elapsedSeconds:S,toolCallId:o}),!k&&!E&&!D&&!O&&!(A&&(w||F))&&n!==void 0&&(0,K.jsx)(eW,{text:typeof n==`string`?n:JSON.stringify(n,null,2),lang:R}),p&&!b&&!n&&!j&&!O&&!(D&&z&&z.length>0)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs text-gray-400`,children:[(0,K.jsx)(Me,{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)(re,{className:`h-3.5 w-3.5`}),`Tool call failed`]})]})})]})}var rW=class extends T.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 iW(e){if(!e)return``;let t=e.match(/(\d{13})/);return t?new Date(parseInt(t[1],10)).toLocaleTimeString():``}function aW({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 oW(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 sW(){let e=Z(e=>e.message.id),{toolProgressMap:t,taskMap:n,thinkingOpen:r,setThinkingOpen:i}=MU(),a=Z(e=>e.message.content),o=Z(e=>{let t=e.message.content;return Array.isArray(t)?t.filter(e=>e.type===`text`).map(e=>e.text??``).join(``):``}),s=iW(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)?oW(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)(YE.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)(Iz,{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)(Lz,{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)(B,{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)(U,{className:Y(`ml-auto h-3 w-3 shrink-0 text-gray-300 transition-transform`,(t||r)&&`rotate-180`)})]}),(0,K.jsx)(Rz,{className:Y(`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=aW({content:o});return e?(0,K.jsx)(`div`,{children:e}):(0,K.jsx)(Dz,{})}case`reasoning`:return(0,K.jsx)(Dz,{});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)(rW,{name:`ToolRenderer:`+s,children:(0,K.jsx)(nW,{toolName:s,args:r,result:i,status:a,elapsedSeconds:c?.elapsed_time_seconds,taskState:l,toolCallId:o})})}default:return null}}});return(0,K.jsxs)(YE.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:Y(`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 cW=[`Thinking`,`Processing`,`Analyzing`,`Working`,`Computing`,`Reasoning`];function lW(e){let t=Math.floor(e/60),n=e%60;return t<1?`${n}s`:`${t}m ${n}s`}function uW(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 dW({isLoading:e,getTokenCount:t,getWaitingForResponse:n}){let{thinkingBudget:r,turnGeneration:i,turnStartedAt:a}=MU(),[o,s]=(0,T.useState)(0),[c,l]=(0,T.useState)(0),[u,d]=(0,T.useState)(``);if((0,T.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,T.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=cW[Math.floor(o/3)%cW.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:lW(o)}),(0,K.jsxs)(`span`,{className:`tabular-nums text-gray-600 font-medium`,children:[p,uW(c),` tk`]})]})]})}function fW({...e}){return(0,K.jsx)(kd,{"data-slot":`popover`,...e})}function pW({...e}){return(0,K.jsx)(Ad,{"data-slot":`popover-trigger`,...e})}function mW({className:e,align:t=`center`,sideOffset:n=8,children:r,...i}){return(0,K.jsx)(jd,{children:(0,K.jsx)(Md,{"data-slot":`popover-content`,align:t,sideOffset:n,className:Y(`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 hW({...e}){return(0,K.jsx)(Nd,{"data-slot":`popover-close`,...e})}var gW=[{id:`bypassPermissions`,label:`YOLO`,description:`Sandboxed — safe to proceed freely`,icon:vt,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:rt,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:pe,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:We,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:ae,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:tt,color:`text-gray-600`,activeBg:`bg-gray-50`,activeBorder:`border-gray-200`,activeHover:`hover:bg-gray-100`}];function _W({mode:e,onChange:t,className:n=``}){let[r,i]=(0,T.useState)(!1),a=gW.find(t=>t.id===e)??gW[0],o=a.icon;return(0,K.jsxs)(fW,{open:r,onOpenChange:i,children:[(0,K.jsx)(pW,{asChild:!0,children:(0,K.jsxs)(`button`,{type:`button`,className:Y(`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:Y(`h-3 w-3`,a.color)}),(0,K.jsx)(`span`,{className:`hidden font-medium sm:inline`,children:a.label})]})}),(0,K.jsxs)(mW,{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)(hW,{asChild:!0,children:(0,K.jsx)(`button`,{type:`button`,className:`rounded p-1 hover:bg-gray-100`,"aria-label":`Close`,children:(0,K.jsx)(_t,{className:`h-4 w-4 text-gray-500`})})})]}),(0,K.jsx)(`div`,{className:`py-1`,children:gW.map(n=>{let r=n.icon,a=n.id===e;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>{t(n.id),i(!1)},className:Y(`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:Y(`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:Y(`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 vW(){let{provider:e,selectProvider:t,thinkingBlockCount:n,loopId:r}=MU(),[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(!1),[c,l]=(0,T.useState)(``),[u,d]=(0,T.useState)(0),f=(0,T.useRef)(null),p=(0,T.useRef)(null);(0,T.useEffect)(()=>{Ch().then(a)},[]);let m=e?.name||`default`,h=e?.model||``,g=(0,T.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,T.useEffect)(()=>{d(0)},[c,o]),(0,T.useEffect)(()=>{p.current&&p.current.children[u]?.scrollIntoView({block:`nearest`})},[u]),(0,T.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key===`k`&&(e.preventDefault(),s(e=>!e)),e.key===`Escape`&&o&&s(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o]);let _=(0,T.useMemo)(()=>{let e=new Map;return g.forEach((t,n)=>{let r=e.get(t.provName)??{source:t.source,models:[]};r.models.push({modelId:t.modelId,idx:n}),e.set(t.provName,r)}),e},[g]),v=e=>e.toLowerCase().startsWith(`claude`),y=(0,T.useCallback)(async e=>{if(s(!1),!(e.provName===m&&e.modelId===h)){if(v(h)!==v(e.modelId)&&n>0&&r){let e=`Switching between Claude and non-Claude models makes the ${n} existing thinking block${n===1?``:`s`} in this conversation fail signature validation.\n\nClick OK to remove them from the AI's context (chat history stays). Cancel to keep the current provider.`;if(!window.confirm(e))return;await Dm(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)(ce,{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)(U,{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]&&y(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)(Ze,{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(_.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)(mt,{className:`h-2 w-2`}):(0,K.jsx)(Te,{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:()=>y(g[t.idx]),onMouseEnter:()=>d(t.idx),className:`w-full px-6 py-1.5 text-left flex items-center gap-2 transition-colors ${n?`bg-blue-50`:``}`,children:[(0,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)(I,{className:`h-3 w-3`}),(0,K.jsx)(N,{className:`h-3 w-3`}),`navigate`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(se,{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 yW({onPick:e}){let{availableSlashCommands:t}=MU(),[n,r]=(0,T.useState)(!1),[i,a]=(0,T.useState)(``),[o,s]=(0,T.useState)(0),c=(0,T.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,T.useMemo)(()=>c.reduce((e,t)=>e+t.skills.length,0),[c]),u=(0,T.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,T.useEffect)(()=>{s(0)},[i,n]),(0,T.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)(Ze,{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)(I,{className:`h-3 w-3`}),(0,K.jsx)(N,{className:`h-3 w-3`}),`navigate`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(se,{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 bW({onClose:e,loopId:t}){let[n,r]=(0,T.useState)([]),[i,a]=(0,T.useState)(!0),[o,s]=(0,T.useState)(null),[c,l]=(0,T.useState)(null),[u,d]=(0,T.useState)(null),f=(0,T.useCallback)(async()=>{a(!0),r((await mg(t)).servers),a(!1)},[t]);(0,T.useEffect)(()=>{f()},[f]);let p=async e=>{if(o)return;s(e),l(null);let n=await hg(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 gg(e),s(null),f())};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)(Je,{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)(_t,{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)(xW,{server:e,busy:o===e.name||e.authTokenEnv!==null&&o===e.authTokenEnv,onConnect:()=>p(e.name),onForget:e.authTokenEnv?()=>m(e.authTokenEnv):void 0},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 _g(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)(Ye,{size:10}),` Reload session`]})})]})}function xW({server:e,busy:t,onConnect:n,onForget:r}){let i=e.type===`http`||e.type===`sse`,a=i&&e.oauthSupport===`dcr`&&!!e.authTokenEnv;return(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?`●`:a?`○`:`·`}),(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)(H,{size:11}),` authed`]}),a&&(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)(Ae,{size:10}):(0,K.jsx)(ut,{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)(ft,{size:10}),` forget`]}),!a&&!e.authed&&i&&(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),!i&&(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:`stdio`})]})]})}var SW=[{id:`think`,name:`Think`,description:`Extended thinking (16k token budget)`,icon:B,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:16e3},{id:`think-hard`,name:`Think Hard`,description:`Deep thinking (32k token budget)`,icon:vt,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:32e3},{id:`ultrathink`,name:`Ultrathink`,description:`Maximum thinking (no budget limit)`,icon:rt,group:`quick`,action:`command`,prefix:``,commandKey:`setMaxThinkingTokens`,tokens:null},{id:`plan`,name:`Permission`,description:`Cycle permission mode`,icon:Xe,group:`quick`,action:`toggle`,prefix:``,toggleKey:`permissionMode`},{id:`goal`,name:`Goal`,description:`Set goal (/goal <text>), mark done (/goal done), clear (/goal clear)`,icon:st,group:`quick`,action:`agent`,prefix:``},{id:`usage`,name:`Context Usage`,description:`Show context window token usage`,icon:V,group:`quick`,action:`command`,prefix:``,commandKey:`getContextUsage`},{id:`clear`,name:`Clear Context`,description:`Reset AI conversation (history kept)`,icon:ue,group:`quick`,action:`command`,prefix:``,commandKey:`clearContext`},{id:`mcp`,name:`MCP Servers`,description:`Show MCP servers + tools available to this loop`,icon:Be,group:`quick`,action:`command`,prefix:``,commandKey:`openMcpPanel`}],CW=[{id:`quick`,label:`Quick actions`},{id:`plugin`,label:`Plugin commands`},{id:`skill`,label:`Skills`}],wW=new Set(SW.map(e=>e.id));function TW(){let e=Z(e=>e.composer.text),t=dw(),{permissionMode:n,setPermissionMode:r,clearContext:i,setMaxThinkingTokens:a,getContextUsage:o,availableSlashCommands:s,suppressSlashRef:c,loopId:l}=MU(),[u,d]=(0,T.useState)(!1),[f,p]=(0,T.useState)(0),[m,h]=(0,T.useState)(``),[g,_]=(0,T.useState)(!1),v=(0,T.useRef)(null),y=(0,T.useMemo)(()=>{let e=s.filter(e=>!wW.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?qe:ct,group:t?`plugin`:`skill`,action:`agent`,prefix:``,pluginName:n}});return[...SW,...e]},[s]),b=typeof e==`string`?e.trimStart():e,x=typeof b==`string`&&b.startsWith(`/`)&&!b.includes(` `);x&&c.current&&(x=!1);let S=x?b.slice(1).toLowerCase():``,C=(0,T.useMemo)(()=>y.filter(e=>!S||e.id.toLowerCase().includes(S)||e.name.toLowerCase().includes(S)),[y,S]),w=(0,T.useMemo)(()=>{let e={quick:0,plugin:1,skill:2};return[...C].sort((t,n)=>t.group===n.group?t.group===`plugin`&&t.pluginName!==n.pluginName?(t.pluginName??``).localeCompare(n.pluginName??``):t.id.localeCompare(n.id):e[t.group]-e[n.group])},[C]),E=(0,T.useMemo)(()=>{let e=new Map;for(let t of w){let n=e.get(t.group)??[];n.push(t),e.set(t.group,n)}return e},[w]);(0,T.useEffect)(()=>{x?(d(!0),h(S),p(0)):d(!1)},[x,S]);let D=(0,T.useCallback)(e=>{if(e.action===`toggle`&&e.toggleKey===`permissionMode`){let e=[`bypassPermissions`,`auto`,`dontAsk`,`acceptEdits`,`plan`,`default`],i=e[(e.indexOf(n)+1)%e.length];r(i),t.setText(``)}else e.action===`command`?e.commandKey===`clearContext`?(i(),t.setText(``)):e.commandKey===`setMaxThinkingTokens`?(a(e.tokens??null),t.setText(``)):e.commandKey===`getContextUsage`?(o(),t.setText(``)):e.commandKey===`openMcpPanel`&&(_(!0),t.setText(``)):e.action===`agent`&&t.setText(`/${e.id} `);d(!1)},[t,n,r,i,a,o]);(0,T.useEffect)(()=>{if(!u)return;let e=e=>{e.key===`ArrowDown`?(e.preventDefault(),e.stopImmediatePropagation(),p(e=>Math.min(e+1,w.length-1))):e.key===`ArrowUp`?(e.preventDefault(),e.stopImmediatePropagation(),p(e=>Math.max(e-1,0))):e.key===`Enter`&&w.length>0?(e.preventDefault(),e.stopImmediatePropagation(),D(w[f])):e.key===`Escape`&&(e.preventDefault(),e.stopImmediatePropagation(),t.setText(``))};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},[u,w,f,t,D]),(0,T.useEffect)(()=>{if(!v.current)return;let e=v.current.querySelector(`[data-slash-idx="${f}"]`);e&&e.scrollIntoView({block:`nearest`})},[f]);let O=-1;return g&&(!u||w.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)(bW,{onClose:()=>_(!1),loopId:l})})}):!u||w.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)(bW,{onClose:()=>_(!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:v,className:`max-h-72 overflow-y-auto py-1`,children:CW.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 EW({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)(Xp,{children:[(0,K.jsx)(Zp,{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)(Qp,{children:(0,K.jsx)(`div`,{className:`text-xs`,children:(0,K.jsxs)(`p`,{children:[e.toLocaleString(),` / `,t.toLocaleString(),` tokens`]})})})]})}function DW({loopId:e,onPick:t,onClose:n}){let[r,i]=(0,T.useState)([]),[a,o]=(0,T.useState)([]),[s,c]=(0,T.useState)(!0),[l,u]=(0,T.useState)(``),[d,f]=(0,T.useState)(0),[p,m]=(0,T.useState)(new Set),[h,g]=(0,T.useState)({}),_=(0,T.useRef)(null),v=(0,T.useRef)(null);(0,T.useEffect)(()=>{c(!0),Promise.all([Om(e,`workdir`).catch(()=>[]),km(e,`workdir`).catch(()=>[])]).then(([e,t])=>{i(e),o(t),c(!1)})},[e]);let y=l.trim().length>0,b=(0,T.useMemo)(()=>{let e=l.trim().toLowerCase();return e?a.filter(t=>t.type===`file`&&(t.path.toLowerCase().includes(e)||t.name.toLowerCase().includes(e))):[]},[a,l]),x=(0,T.useMemo)(()=>{if(y)return[];let e=[];function t(n,r){for(let i of n)e.push({entry:i,depth:r}),i.type===`dir`&&p.has(i.path)&&h[i.path]&&t(h[i.path],r+1)}return t(r,0),e},[r,y,p,h]);(0,T.useEffect)(()=>{f(0)},[l]),(0,T.useEffect)(()=>{v.current&&v.current.children[d]?.scrollIntoView({block:`nearest`})},[d]);let S=(0,T.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 Om(e,t.path).catch(()=>[]);g(e=>({...e,[t.path]:n}))}m(e=>new Set(e).add(t.path))}},[p,h,e]),C=(0,T.useCallback)(e=>{if(e.type===`dir`){S(e);return}t(e.path)},[S,t]);return(0,yt.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(y)e.key===`ArrowDown`?(e.preventDefault(),f(e=>Math.min(e+1,b.length-1))):e.key===`ArrowUp`?(e.preventDefault(),f(e=>Math.max(e-1,0))):e.key===`Enter`&&(e.preventDefault(),b[d]&&t(b[d].path));else if(e.key===`ArrowDown`)e.preventDefault(),f(e=>Math.min(e+1,x.length-1));else if(e.key===`ArrowUp`)e.preventDefault(),f(e=>Math.max(e-1,0));else if(e.key===`ArrowRight`||e.key===`ArrowLeft`){e.preventDefault();let t=x[d];if(!t||t.entry.type!==`dir`)return;let n=p.has(t.entry.path);(e.key===`ArrowRight`&&!n||e.key===`ArrowLeft`&&n)&&S(t.entry)}else e.key===`Enter`&&(e.preventDefault(),x[d]&&C(x[d].entry))},children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-gray-200 shrink-0`,children:[(0,K.jsx)(Ze,{className:`h-4 w-4 text-gray-400 shrink-0`}),(0,K.jsx)(`input`,{ref:_,autoFocus:!0,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search files...`,className:`flex-1 text-sm outline-none text-gray-900 placeholder:text-gray-400`})]}),(0,K.jsx)(`div`,{ref:v,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...`}):y?b.length===0?(0,K.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-gray-400`,children:`No files match your search`}):b.map((e,n)=>(0,K.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n===d,onClick:()=>t(e.path),onMouseEnter:()=>f(n),className:Y(`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)(ge,{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`}):x.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:()=>C(e),onMouseEnter:()=>f(n),className:Y(`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)(U,{size:11,className:`text-gray-300 shrink-0`}):(0,K.jsx)(W,{size:11,className:`text-gray-300 shrink-0`}),(0,K.jsx)(be,{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)(ge,{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)(I,{className:`h-3 w-3`}),(0,K.jsx)(N,{className:`h-3 w-3`}),`navigate`]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(se,{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 OW=2e5,kW=500;function AW({pickedFile:e,editorSelection:t}){let n=Z(e=>e.thread.isRunning),r=Z(e=>typeof e.composer.text==`string`&&e.composer.text.trim().length>0),i=Z(e=>e.composer.text),{provider:a,permissionMode:o,setPermissionMode:s,enqueueMessage:c,queue:l,clearQueue:u,removeFromQueue:d,loopId:f,contextTokens:p,cumulativeTokens:m,getStreamingTokenCount:h,getWaitingForResponse:g,suppressSlashRef:_,goal:v,setGoal:y,goalStatus:b,completeGoal:x}=MU(),S=a?.contextWindow??OW,C=$v(),[w,E]=(0,T.useState)(!1),[D,O]=(0,T.useState)([]),[k,A]=(0,T.useState)(!1),j=[...w&&e?[e]:[],...D],M=()=>E(e=>!e),N=e=>{O(t=>t.includes(e)?t:[...t,e]),A(!1)},P=e=>{O(t=>t.filter(t=>t!==e))},F=e=>{let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e},L=(0,T.useRef)(``),R=(0,T.useRef)([]),[z,B]=(0,T.useState)(!1);(0,T.useEffect)(()=>{let n=!1;async function r(){if(j.length===0){L.current=``,R.current=[];return}B(!0);let r=[],i=[];for(let a of j){if(n)return;try{let n=await Am(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,B(!1))}return r(),()=>{n=!0}},[j.join(`,`),f,e,t?.from,t?.to]);let V=e=>{let t=L.current;return t?`${t}\n${e}`:e},[H,U]=(0,T.useState)([]),[W,G]=(0,T.useState)(-1),ee=(0,T.useRef)(``),ne=(0,T.useRef)(``);ne.current=typeof i==`string`?i:``,(0,T.useEffect)(()=>{f&&Jm(f).then(e=>{U(e),G(-1)})},[f]);let re=e=>{if(!e.trim()||!f)return;let t=e.trim();U(e=>{if(e[e.length-1]===t)return e;let n=[...e,t];return n.length>kW&&n.splice(0,n.length-kW),n}),G(-1),Ym(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(V(e)),C.composer().setText(``)}};return(0,K.jsxs)(aE.Root,{className:`relative flex w-full flex-col`,onSubmit:()=>{let e=ne.current.trim();if(e&&(re(e),L.current))try{sessionStorage.setItem(`loopat:pendingFileContext`,L.current)}catch{}},children:[(0,K.jsx)(dW,{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)(_t,{className:`h-3.5 w-3.5`})})]},t))}),j.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 px-1 mb-1 flex-wrap`,children:[j.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)(ge,{size:11,className:`shrink-0`}),(0,K.jsx)(`span`,{className:`truncate max-w-[160px]`,children:F(n)}),n!==e&&(0,K.jsx)(`button`,{onClick:()=>P(n),className:`ml-0.5 hover:text-blue-900`,children:(0,K.jsx)(_t,{size:11})}),n===e&&w&&(0,K.jsx)(`span`,{className:`text-[9px] text-blue-400 ml-0.5`,children:t?`(${t.from}-${t.to})`:`editor`})]},n)),z&&(0,K.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:`loading...`})]}),v&&(0,K.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-2 px-2 py-1.5 rounded-lg border group ${b===`completed`?`border-green-200 bg-green-50`:`border-amber-200 bg-amber-50`}`,children:[b===`completed`?(0,K.jsx)(te,{className:`h-3.5 w-3.5 text-green-600 shrink-0`}):(0,K.jsx)(st,{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 ${b===`completed`?`text-green-800 line-through`:`text-amber-800`}`,children:v}),b===`active`&&(0,K.jsx)(`button`,{onClick:()=>x?.(),className:`shrink-0 px-1.5 py-0.5 rounded text-[10px] font-medium text-amber-700 hover:bg-amber-200 opacity-0 group-hover:opacity-100 transition-opacity`,title:`Mark goal as complete`,children:`Done`}),(0,K.jsx)(`button`,{onClick:()=>y?.(null),className:`shrink-0 p-0.5 rounded hover:bg-amber-200/50 opacity-0 group-hover:opacity-100 transition-opacity`,title:`Clear goal`,children:(0,K.jsx)(_t,{className:`h-3 w-3 ${b===`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)(TW,{}),(0,K.jsx)(aE.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&&ne.current.trim().length>0){e.preventDefault(),C.composer().setText(``);return}}if(e.key!==`ArrowUp`&&e.key!==`ArrowDown`&&(_.current=!1),e.key===`Enter`&&!e.nativeEvent.isComposing&&!e.shiftKey&&n){e.preventDefault(),ie();return}if(e.key===`ArrowUp`&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey){if(H.length===0)return;if(e.preventDefault(),_.current=!0,W===-1)ee.current=ne.current,G(H.length-1),C.composer().setText(H[H.length-1]);else if(W>0){let e=W-1;G(e),C.composer().setText(H[e])}return}if(e.key===`ArrowDown`&&!e.shiftKey&&!e.altKey&&!e.metaKey&&!e.ctrlKey){if(W===-1)return;if(e.preventDefault(),_.current=!0,W<H.length-1){let e=W+1;G(e),C.composer().setText(H[e])}else G(-1),C.composer().setText(ee.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)(EW,{used:Math.min(p,S),total:S}),(0,K.jsx)(vW,{}),(0,K.jsx)(yW,{onPick:e=>{let t=ne.current,n=t.length===0||t.endsWith(` `)?`${t}${e}`:`${t} ${e}`;C.composer().setText(n)}}),e&&(0,K.jsxs)(`button`,{type:`button`,onClick:M,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${w?`bg-blue-50 text-blue-600 border border-blue-200`:`text-gray-400 hover:text-gray-600 hover:bg-gray-100`}`,title:w?`Remove editor file from context`:`Include editor file in context`,children:[(0,K.jsx)(ge,{size:12}),F(e)]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>A(e=>!e),className:`inline-flex items-center justify-center rounded-md border border-gray-200 bg-gray-50 w-[21px] h-[21px] mt-px text-gray-500 hover:bg-gray-100 transition-colors`,title:`Add file to context`,children:(0,K.jsx)(he,{size:12})}),k&&(0,K.jsx)(DW,{loopId:f,onPick:N,onClose:()=>A(!1)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 shrink-0`,children:[(0,K.jsx)(_W,{mode:o,onChange:s}),r&&(n?(0,K.jsx)(zg,{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)(je,{className:`h-4 w-4`})}):(0,K.jsx)(aE.Send,{asChild:!0,children:(0,K.jsx)(zg,{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)(I,{className:`h-4 w-4`})})})),(0,K.jsx)(ey,{condition:e=>e.thread.isRunning,children:(0,K.jsx)(aE.Cancel,{asChild:!0,children:(0,K.jsx)(zg,{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)(it,{className:`h-3 w-3 fill-current`})})})})]})]})]})]})}function jW({questions:e,toolUseId:t,onAnswers:n,onDismiss:r,disabled:i=!1}){let[a,o]=(0,T.useState)({}),[s,c]=(0,T.useState)({}),[l,u]=(0,T.useState)(!1),[d,f]=(0,T.useState)(0),p=Array.isArray(e)?e.filter(e=>e!=null&&typeof e.question==`string`&&e.question.length>0&&Array.isArray(e.options)):[];if(p.length===0)return null;let m=(e,t)=>{i||l||(c(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),o(n=>({...n,[e]:t})))},h=(e,t)=>{i||l||(c(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}),o(n=>{let r=(n[e]??``).split(`,`).filter(Boolean),i=r.indexOf(t);return i>=0?r.splice(i,1):r.push(t),{...n,[e]:r.join(`,`)}}))},g=(e,t)=>{i||l||(c(n=>({...n,[e]:t})),o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n}))},_=e=>s[e.question]?.trim()||a[e.question]||``,v=p.every(e=>{let t=_(e);return t!==void 0&&t!==``}),y=e=>{let t=_(e);return t!==void 0&&t!==``},b=()=>{if(!v||!t||!n||l)return;u(!0);let e={};for(let t of p)e[t.question]=_(t);n(t,e)},x=()=>{i||l||(u(!0),r?.(t||``))},S=()=>{f(e=>Math.min(e+1,p.length-1))},C=(e,t)=>e.header?e.header:`Question ${t+1}`,w=p[d],E=a[w.question]??``,D=new Set(E.split(`,`).filter(Boolean)),O=Array.isArray(w.options)?w.options:[],k=s[w.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)(ne,{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:x,disabled:i||l,className:`flex items-center justify-center h-5 w-5 rounded text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors`,children:(0,K.jsx)(_t,{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=y(e);return(0,K.jsxs)(`button`,{type:`button`,disabled:i||l,onClick:()=>f(t),className:Y(`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)(H,{className:`h-3 w-3 text-emerald-500`}),C(e,t)]},t)})}),(0,K.jsxs)(`div`,{className:`overflow-y-auto max-h-[260px] space-y-1.5`,children:[w.header&&(0,K.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wide text-gray-400`,children:w.header}),(0,K.jsx)(`p`,{className:`text-[12px] text-gray-800 font-medium`,children:w.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=w.multiSelect?D.has(n):E===n;return(0,K.jsx)(`button`,{type:`button`,disabled:i||l,onClick:()=>w.multiSelect?h(w.question,n):m(w.question,n),className:Y(`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:[w.multiSelect?(0,K.jsx)(`span`,{className:Y(`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:Y(`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(w.question,e.target.value),placeholder:`Or type your own answer...`,disabled:i||l,className:Y(`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:S,className:`inline-flex items-center gap-1 rounded-lg px-3 py-1.5 text-[11px] font-medium text-gray-500 hover:text-gray-700 hover:bg-gray-100 transition-colors`,children:[`Next`,(0,K.jsx)(W,{className:`h-3 w-3`})]}):(0,K.jsx)(`div`,{}),(0,K.jsxs)(`button`,{type:`button`,disabled:!v||i,onClick:b,className:Y(`inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,v?`bg-gray-900 text-white hover:bg-gray-800`:`bg-gray-100 text-gray-400 cursor-not-allowed`),children:[(0,K.jsx)(Qe,{className:`h-3 w-3`}),`Submit`]})]}),l&&(0,K.jsx)(`p`,{className:`text-[11px] text-emerald-600 font-medium text-right`,children:`Submitted`})]})}var MW=()=>(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…`})]}),NW=`loopat:composer:drafts`;function PW(e){try{let t=localStorage.getItem(NW);return t?JSON.parse(t)[e]??null:null}catch{return null}}function FW(e,t){try{let n=localStorage.getItem(NW),r=n?JSON.parse(n):{};t.trim()?r[e]=t:delete r[e],localStorage.setItem(NW,JSON.stringify(r))}catch{}}function IW({archived:e=!1,onUnarchive:t,readOnly:n=!1,repo:r,branch:i,title:a,driver:o,driverHistory:s,rfdRequestedAt:c,rfdRequestedBy:l,onTakeDrive:u,pickedFile:d,editorSelection:f}={}){let{questions:p,sendAnswers:m,loadingHistory:h,loopId:g,hasHistory:_,showHistory:v,toggleShowHistory:y,hasOlderMessages:b,loadMoreMessages:x,thinkingBudget:S,setMaxThinkingTokens:C}=MU(),[w,E]=(0,T.useState)(`normal`),D=Z(e=>e.thread.isEmpty&&!e.thread.isRunning)&&!h,O=(0,T.useRef)(null),k=(0,T.useRef)(null),[A,j]=(0,T.useState)(!1),M=(0,T.useCallback)(()=>{let e=k.current;e&&e.scrollTo({top:e.scrollHeight,behavior:`smooth`})},[]),P=(0,T.useRef)(_);P.current=_;let F=(0,T.useRef)(v);F.current=v;let I=(0,T.useRef)(b);I.current=b;let[L,R]=(0,T.useState)(!1),z=(0,T.useRef)({oldScrollTop:0,oldScrollHeight:0,active:!1}),B=(0,T.useCallback)(()=>{let e=k.current;e&&(z.current={oldScrollTop:e.scrollTop,oldScrollHeight:e.scrollHeight,active:!0}),y()},[y]),V=(0,T.useRef)({oldScrollTop:0,oldScrollHeight:0,active:!1}),H=(0,T.useCallback)(()=>{let e=k.current;e&&(V.current={oldScrollTop:e.scrollTop,oldScrollHeight:e.scrollHeight,active:!0}),W(!0),x()},[x]),[U,W]=(0,T.useState)(!1),G=(0,T.useRef)(!1);G.current=U;let ee=dw(),te=Z(e=>e.composer.text),ne=(0,T.useRef)(te);ne.current=te,(0,T.useEffect)(()=>{let e=PW(g);e&&ee.setText(e)},[]),(0,T.useEffect)(()=>()=>{FW(g,ne.current)},[g]),(0,T.useEffect)(()=>{if(!te)return;let e=setTimeout(()=>{FW(g,te)},300);return()=>clearTimeout(e)},[te,g]);let[re,ie]=(0,T.useState)(te);(0,T.useEffect)(()=>{re&&!te&&FW(g,``),ie(te)},[te,g]);let ae=(0,T.useRef)(null),oe=(0,T.useRef)(!1),se=(0,T.useRef)(h);se.current=h;let ce=(0,T.useRef)(h);(0,T.useEffect)(()=>{let e=O.current,t=e?.parentElement;if(!e||!t)return;k.current=t;let n=()=>t.scrollTop+t.clientHeight>=t.scrollHeight-120,r=!1,i=null,a=e=>{e.deltaY<0&&(r=!0,i&&clearTimeout(i),i=setTimeout(()=>{i=null,n()&&(r=!1)},200))},o=()=>{!i&&n()?r=!1:n()||(r=!0),j(t.scrollTop+t.clientHeight<t.scrollHeight-200),R(t.scrollTop<20&&P.current),t.scrollTop<40&&I.current&&!G.current&&H()};t.addEventListener(`scroll`,o,{passive:!0}),t.addEventListener(`wheel`,a,{passive:!0});let s=null,c=!1,l=()=>{if(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,T.useEffect)(()=>{if(ce.current&&!h){let e=k.current;if(e){let t=e.style.scrollBehavior;e.style.scrollBehavior=`auto`,e.scrollTop=e.scrollHeight,e.style.scrollBehavior=t,oe.current=!0}}ce.current=h},[h]),(0,T.useEffect)(()=>{if(!z.current.active)return;let e=k.current;if(!e)return;let{oldScrollTop:t,oldScrollHeight:n}=z.current;z.current.active=!1,requestAnimationFrame(()=>{e.scrollTop=t+(e.scrollHeight-n)})},[v]),(0,T.useEffect)(()=>{if(!V.current.active)return;let e=k.current;if(!e)return;let{oldScrollTop:t,oldScrollHeight:n}=V.current;V.current.active=!1,requestAnimationFrame(()=>{e.scrollTop=t+(e.scrollHeight-n)})},[b]),(0,T.useEffect)(()=>{if(!U)return;let e=setTimeout(()=>W(!1),200);return()=>clearTimeout(e)},[U,b]);let le=p.size>0?Array.from(p.entries()):[];return(0,K.jsxs)(CD.Root,{className:`flex h-full flex-col bg-white relative`,style:{"--thread-max-width":`44rem`},children:[(0,K.jsx)(CD.Viewport,{turnAnchor:`top`,className:D?`hidden`:`relative flex-1 overflow-x-auto overflow-y-scroll scroll-smooth`,children:(0,K.jsxs)(`div`,{ref:O,className:`mx-auto flex w-full min-h-full flex-col px-2 md:px-3 pt-3 md:pt-4`,children:[h&&(0,K.jsx)(MW,{}),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:v?`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)(CD.Messages,{children:({message:e})=>e.role===`user`?(0,K.jsx)(Fz,{}):(0,K.jsx)(sW,{})}),(0,K.jsx)(`div`,{ref:ae}),le.length>0&&(0,K.jsx)(rW,{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)(jW,{questions:t,toolUseId:e,onAnswers:m,onDismiss:e=>m(e,{})})},e):null)})})]})]})}),(0,K.jsx)(`div`,{className:D?`flex-1 flex items-center justify-center px-2 md:px-3 pb-3 md:pb-6`:`shrink-0 z-10 bg-gradient-to-t from-white via-white to-transparent px-2 md:px-3 pt-1 md:pt-2 pb-3 md:pb-6`,children:(0,K.jsxs)(`div`,{className:D?`w-full max-w-[36rem]`:``,children:[D&&(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)(Ce,{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:()=>{E(e.mode===`normal`?`normal`:e.mode===`ultra`?`ultra`:`normal`),C(e.tokens)},className:`px-1.5 py-0.5 text-[11px] rounded transition-colors `+((e.mode===`normal`?S===null&&w===`normal`:e.mode===`ultra`?S===null&&w===`ultra`:S===e.tokens)?`bg-gray-200 text-gray-700 font-medium`:`text-gray-400 hover:text-gray-600 hover:bg-gray-100`),children:e.label},e.label))})]})]}),e?(0,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)(AW,{pickedFile:d,editorSelection:f})]})}),A&&(0,K.jsx)(`button`,{type:`button`,onClick:M,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)(N,{className:`h-3.5 w-3.5`})})]})}function LW(){let{id:e}=Zn(),[t,n]=(0,T.useState)(null);return(0,T.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{let r=await Em(e);t||n(r??`unauthorized`)})(),()=>{t=!0}},[e]),(0,T.useEffect)(()=>{t&&typeof t==`object`&&(document.title=`${t.title} · shared`)},[t]),e?t===null?(0,K.jsx)(zW,{}):t===`unauthorized`?(0,K.jsx)(BW,{reason:`this loop is private or does not exist`}):(0,K.jsx)(RW,{meta:t}):(0,K.jsx)(BW,{reason:`missing loop id`})}function RW({meta:e}){let{runtime:t,connected:n,reconnecting:r,extra:i}=PU(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)(NU,{extra:i,children:(0,K.jsx)(uw,{runtime:t,children:(0,K.jsx)(IW,{readOnly:!0})})})})]})}function zW(){return(0,K.jsx)(`div`,{className:`h-full w-full flex items-center justify-center text-gray-400 text-sm`,children:`loading…`})}function BW({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 VW(e){let[t,n]=(0,T.useState)({}),r=(0,T.useRef)(null);return(0,T.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 HW=`loopat:tree:expanded:`;function UW(e){try{let t=localStorage.getItem(HW+e);return t?new Set(JSON.parse(t)):new Set}catch{return new Set}}function WW(e,t){try{localStorage.setItem(HW+e,JSON.stringify([...t]))}catch{}}function GW({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)(KW,{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 KW({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,T.useState)(()=>UW(e).has(t.path)),[p,m]=(0,T.useState)(null),[h,g]=(0,T.useState)(!1),[_,v]=(0,T.useState)(null),y=(0,T.useCallback)(()=>{let n=UW(e);n.has(t.path)?n.delete(t.path):n.add(t.path),WW(e,n),f(e=>!e)},[e,t.path]),b=(0,T.useRef)(u);(0,T.useEffect)(()=>{b.current!==u&&(m(null),b.current=u)},[u]),(0,T.useEffect)(()=>{!d||p!==null||t.type===`dir`&&(g(!0),a(t.path).then(m).finally(()=>g(!1)))},[d,t.path,a,p]);let x=e=>{e.preventDefault(),e.stopPropagation(),v({x:e.clientX,y:e.clientY})},S=8+n*12;if(t.type===`dir`)return c?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{onContextMenu:x,children:c(t,n,d,y)}),d&&p&&(0,K.jsx)(K.Fragment,{children:p.map(t=>(0,K.jsx)(KW,{treeId:e,entry:t,depth:n+1,onPick:r,picked:i,onLoadChildren:a,getContextActions:o,onAction:s,renderNode:c,nodeClassName:l,reloadKey:u},t.path))}),_&&(0,K.jsx)(qW,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{onContextMenu:x,children:(0,K.jsxs)(`button`,{type:`button`,onClick:y,className:l?l(t,n,d,!1):`w-full py-1 flex items-center gap-1.5 hover:bg-gray-50 text-left group`,style:{paddingLeft:S,paddingRight:8},children:[(0,K.jsx)(`span`,{className:`text-gray-500 w-3`,children:d?`▾`:`▸`}),(0,K.jsx)(`span`,{className:`text-gray-500`,children:d?(0,K.jsx)(be,{size:13}):(0,K.jsx)(Se,{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:S+12},children:`...`}),d&&p&&(0,K.jsxs)(K.Fragment,{children:[p.map(t=>(0,K.jsx)(KW,{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:S+12},children:`(empty)`})]}),_&&(0,K.jsx)(qW,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]});let C=i===t.path;return c?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{onContextMenu:x,onClick:()=>r(t.path),children:c(t,n,!1,()=>{})}),_&&(0,K.jsx)(qW,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]}):(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)(`div`,{className:`relative`,onContextMenu:x,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(t.path),className:l?l(t,n,!1,C):`w-full py-1 flex items-center gap-2 text-left `+(C?`bg-gray-100`:`hover:bg-gray-50`),style:{paddingLeft:S,paddingRight:8},children:[(0,K.jsx)(`span`,{className:`w-3 text-gray-400`,children:(0,K.jsx)(_e,{size:13})}),(0,K.jsx)(`span`,{className:`text-[13px] text-gray-900 flex-1 min-w-0 truncate`,children:t.name})]}),_&&(0,K.jsx)(qW,{x:_.x,y:_.y,items:o(t).filter(e=>!e.hidden),onAction:e=>s(e,t),onClose:()=>v(null)})]})})}function qW({x:e,y:t,items:n,onAction:r,onClose:i}){return(0,T.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,yt.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 JW=[{name:`context`,section:`context`,emoji:`🧷`,hint:`knowledge / notes / personal`},{name:`workdir`,section:`workdir`,emoji:`▣`}];function YW({loopId:e,onPick:t,picked:n}){let[r,i]=(0,T.useState)(0),a=(0,T.useRef)(null),[o,s]=(0,T.useState)(``),[c,l]=(0,T.useState)(null),[u,d]=(0,T.useState)(``),f=(0,T.useCallback)(e=>{s(e??`workdir`),a.current?.click()},[]),p=async t=>{let n=t.target.files?.[0];if(!n)return;let r=await Pm(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 jm(e,t,``):await Nm(e,t),!n){alert(`create failed`),l(null);return}l(null),d(``),i(e=>e+1)},h=(0,T.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;Mm(e,n.path).then(e=>{if(!e){alert(`delete failed`);return}i(e=>e+1)})}},[f,e]),g=(0,T.useCallback)(e=>e.type===`dir`?[{label:`Upload here`,icon:(0,K.jsx)(pt,{size:12}),action:`upload`},{label:`New file`,icon:(0,K.jsx)(he,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,K.jsx)(xe,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,K.jsx)(lt,{size:12}),action:`delete`,danger:!0}]:[{label:`View`,icon:(0,K.jsx)(fe,{size:12}),action:`view`},{label:`Delete`,icon:(0,K.jsx)(lt,{size:12}),action:`delete`,danger:!0}],[]);return(0,T.useCallback)(t=>Om(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}),JW.map(a=>(0,K.jsx)(XW,{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)(ZW,{depth:1,type:c.type,value:u,onChange:d,onSubmit:m,onCancel:()=>l(null)})]})}function XW({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,T.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,T.useCallback)(t=>Om(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)(pt,{size:12})})]})]}),p&&(0,K.jsx)(GW,{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 ZW({depth:e,type:t,value:n,onChange:r,onSubmit:i,onCancel:a}){let o=(0,T.useRef)(null);return(0,T.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 QW(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 $W({filePath:e,diff:t,loading:n,onClose:r}){let i=null;if(t)try{i=QW(t)}catch{}return(0,K.jsx)(Bg,{open:!0,onOpenChange:e=>{e||r()},children:(0,K.jsxs)(Ug,{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)(Me,{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 eG={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 tG({loopId:e,onClose:t,onPickFile:n}){let[r,i]=(0,T.useState)(null),[a,o]=(0,T.useState)(!1),[s,c]=(0,T.useState)(!0),[l,u]=(0,T.useState)(!0),[d,f]=(0,T.useState)(null),[p,m]=(0,T.useState)(``),[h,g]=(0,T.useState)(``),[_,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)([]),[C,w]=(0,T.useState)(!1),[E,D]=(0,T.useState)(!0),O=(0,T.useCallback)(async()=>{o(!0),f(null);try{i(await Ah(e))}catch{f(`Failed to load git status`)}finally{o(!1)}},[e]),k=(0,T.useCallback)(async()=>{w(!0);try{S(await Fh(e,50))}catch{}finally{w(!1)}},[e]);(0,T.useEffect)(()=>{O(),k()},[O,k]);let A=async()=>{r?.unstaged.length&&await Mh(e,r.unstaged.map(e=>e.path))&&O()},j=async()=>{r?.staged.length&&await Mh(e,r.staged.map(e=>e.path),!0)&&O()},M=async t=>{await Mh(e,[t])&&O()},N=async t=>{await Mh(e,[t],!0)&&O()},P=async t=>{await Nh(e,t)&&O()},F=async()=>{if(!h.trim())return;v(!0),b(null);let t=await Ph(e,h.trim());v(!1),t.ok?(g(``),O(),k()):b(t.error??`Commit failed`)},I=p.trim().toLowerCase(),L=r?r.unstaged.filter(e=>!I||e.path.toLowerCase().includes(I)):[],R=r?r.staged.filter(e=>!I||e.path.toLowerCase().includes(I)):[],z=!r||r.unstaged.length===0&&r.staged.length===0;return(0,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)(Ye,{size:13,className:a||C?`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),b(null)},rows:2,className:`w-full px-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300 resize-none mb-1.5`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`button`,{onClick:F,disabled:_||!h.trim(),className:`flex-1 flex items-center justify-center gap-1 px-2 py-1 text-[11px] rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:[(0,K.jsx)(we,{size:12}),_?`Committing...`:`Commit`]}),r&&r.staged.length>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[r.staged.length,` staged`]})]}),y&&(0,K.jsx)(`div`,{className:`mt-1 text-[10px] text-red-500`,children:y})]}),(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)(rG,{title:`Unstaged Changes`,count:L.length,open:s,onToggle:()=>c(e=>!e),bulkAction:{label:`Stage all`,icon:(0,K.jsx)(Ke,{size:12}),onClick:A},children:L.map(t=>(0,K.jsx)(iG,{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)(rG,{title:`Staged Changes`,count:R.length,open:l,onToggle:()=>u(e=>!e),bulkAction:{label:`Unstage all`,icon:(0,K.jsx)(Re,{size:12}),onClick:j},children:R.map(t=>(0,K.jsx)(iG,{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)(Ce,{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:[`(`,x.length,`)`]})]}),E&&(0,K.jsx)(`div`,{className:`px-2 pb-2 max-h-64 overflow-auto`,children:C?(0,K.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`loading history...`}):x.length===0?(0,K.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`no commits`}):(0,K.jsx)(nG,{commits:x})})]})]})]})}function nG({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 rG({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 iG({file:e,loopId:t,staged:n,onStage:r,onUnstage:i,onDiscard:a,onEdit:o,onRefresh:s}){let[c,l]=(0,T.useState)(!1),[u,d]=(0,T.useState)(null),[f,p]=(0,T.useState)(!1),[m,h]=(0,T.useState)(!1),[g,_]=(0,T.useState)(null),v=(0,T.useRef)(null);(0,T.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&_(null)};if(g)return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let y=async()=>{e.isBinary||(l(!0),u===null&&(p(!0),d(await jh(t,e.path,n)??``),p(!1)))},b=e=>{e.preventDefault(),_({x:e.clientX,y:e.clientY})},x=`workdir/${e.path}`,S=[{label:`Open in Editor`,icon:(0,K.jsx)(Ge,{size:12}),onClick:()=>{o(x),_(null)}},{label:`View Diff`,icon:(0,K.jsx)(Ze,{size:12}),onClick:()=>{y(),_(null)}},{separator:!0,label:``,onClick:()=>{}},n?{label:`Unstage`,icon:(0,K.jsx)(Re,{size:12}),onClick:()=>{i(),_(null)}}:{label:`Stage`,icon:(0,K.jsx)(Ke,{size:12}),onClick:()=>{r(),_(null)}},!n&&{label:`Discard Changes`,icon:(0,K.jsx)(dt,{size:12}),onClick:()=>{h(!0),_(null)},danger:!0}].filter(Boolean),C=eG[e.status]??{label:e.status,color:`text-gray-500`},w=e.path.lastIndexOf(`/`),E=w>=0?e.path.slice(w+1):e.path,D=w>=0?e.path.slice(0,w+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:b,children:[(0,K.jsx)(`span`,{className:`w-5 text-center text-[11px] font-mono font-semibold ${C.color}`,children:C.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(x),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)(Ge,{size:13})}),n&&(0,K.jsx)(`button`,{type:`button`,onClick:y,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-gray-700 rounded`,title:`view diff`,disabled:e.isBinary,children:(0,K.jsx)(Ze,{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)(Re,{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)(dt,{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)(Ke,{size:13})})]})]})]}),g&&(0,K.jsx)(`div`,{ref:v,className:`fixed z-50 min-w-[160px] py-1 bg-white border border-gray-200 rounded-md shadow-lg text-[12px]`,style:{left:g.x,top:g.y},children:S.map((e,t)=>e.separator?(0,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)($W,{filePath:e.path,diff:u,loading:f,onClose:()=>l(!1)}),m&&(0,K.jsx)(Bg,{open:!0,onOpenChange:e=>{e||h(!1)},children:(0,K.jsxs)(Ug,{className:`sm:max-w-sm bg-white p-5 gap-4`,showCloseButton:!1,children:[(0,K.jsx)(Wg,{children:(0,K.jsx)(Gg,{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 aG(e){return e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:`standard`}function oG({loop:e,open:t,onClose:n,onSaved:r}){let[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(e.shareEnabled??!1),[c,l]=(0,T.useState)(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),[u,d]=(0,T.useState)(e.shareAlias??``),[f,p]=(0,T.useState)(e.sharePort??3e3),[m,h]=(0,T.useState)(e.shareExternalPort??1e4),[g,_]=(0,T.useState)(e.shareProtocol??`tcp`),[v,y]=(0,T.useState)(null),[b,x]=(0,T.useState)(``),[S,C]=(0,T.useState)(!1),[w,E]=(0,T.useState)(!1),[D,O]=(0,T.useState)(!1),[k,A]=(0,T.useState)(``),[j,M]=(0,T.useState)(!1),[N,P]=(0,T.useState)(``),[F,I]=(0,T.useState)(``),[L,R]=(0,T.useState)(aG(e)),[z,B]=(0,T.useState)(null),V=e.id.slice(0,8),U=!!(i&&i.serveEnabled),W=!!(i&&i.serveDynamicEnabled),G=!!(i&&i.serveEphemeralEnabled),te=[U,W,G].filter(Boolean).length>1,ne=U&&!W&&!G,re=!U&&W&&!G,ie=!U&&!W&&G;(0,T.useEffect)(()=>{t&&(Yh().then(a),s(e.shareEnabled??!1),l(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),d(e.shareAlias??``),p(e.sharePort??3e3),h(e.shareExternalPort??1e4),_(e.shareProtocol??`tcp`),R(aG(e)),y(null),x(``),A(``),B(null))},[t,e]),(0,T.useEffect)(()=>{if(!t||!(ie||te&&L===`ephemeral`)||!e.shareEnabled||e.shareMode!==`ephemeral`)return;let n=!1,r=async()=>{let t=await Xh(e.id);n||B(t.port)};r();let i=setInterval(r,3e3);return()=>{n=!0,clearInterval(i)}},[t,L,ie,te,e.id,e.shareEnabled,e.shareMode]),(0,T.useEffect)(()=>{!t||!i||i.serveDynamicEnabled&&(e.shareEnabled&&e.shareExternalPort||!e.shareEnabled&&!e.shareExternalPort&&Qh().then(e=>{e.port&&h(e.port)}))},[t,i,e.shareEnabled,e.shareExternalPort]),(0,T.useEffect)(()=>{t&&eg(V,e.id).then(e=>{e.available?O(!1):(O(!0),x(`ID "${V}" is already in use. Please set an alias.`))})},[t,V,e.id]),(0,T.useEffect)(()=>{if(!u||!t){y(null),x(``);return}let n=setTimeout(async()=>{let t=await eg(u,e.id);y(t.available),x(t.reason??``)},300);return()=>clearTimeout(n)},[u,t,e.id]);let ae=u||V,se=i?.https?`https`:`http`,ce=i?.withPort?`:${i.displayPort}`:``,le=i?`${se}://${ae}${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=z?`${g===`udp`?`udp`:`tcp`}://${fe}:${z}`:`(no active port — save & wait for container restart)`,me=re||te&&L===`direct`&&W&&!ie,he=ie||te&&L===`ephemeral`,ge=he?pe:me?de:le;(0,T.useEffect)(()=>{if(!t||!me)return;let n=setTimeout(async()=>{M(!0);let t=await $h(m,e.id);M(!1),t.available?A(``):A(t.reason??`Port unavailable`)},400);return()=>clearTimeout(n)},[m,t,c,e.id]);let _e=async()=>{if(E(!0),me){let t=await $h(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)P(`Saved`),await r?.(),setTimeout(()=>{P(``),n()},800);else try{I((await i.json()).error??`Save failed (${i.status})`)}catch{I(`Save failed (${i.status})`)}},ve=async()=>{try{await navigator.clipboard.writeText(ge),C(!0),setTimeout(()=>C(!1),1500)}catch{window.prompt(`Copy this URL:`,ge)}},ye=!w&&!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)(Bg,{open:t,onOpenChange:e=>{e||n()},children:(0,K.jsxs)(Ug,{className:`sm:max-w-md bg-white max-h-[85vh] overflow-y-auto`,children:[(0,K.jsxs)(Wg,{children:[(0,K.jsxs)(Gg,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Te,{size:16}),`Share Artifact`]}),(0,K.jsx)(Kg,{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:[te&&(0,K.jsxs)(`div`,{className:`flex gap-1.5 border-b border-gray-200 pb-2`,children:[U&&(0,K.jsx)(`button`,{onClick:()=>{R(`standard`),l(`static`)},className:`px-3 py-1 text-xs rounded-t ${L===`standard`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Subdomain`}),W&&(0,K.jsx)(`button`,{onClick:()=>{R(`direct`),l(`direct`)},className:`px-3 py-1 text-xs rounded-t ${L===`direct`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Direct Port`}),G&&(0,K.jsx)(`button`,{onClick:()=>{R(`ephemeral`),l(`ephemeral`)},className:`px-3 py-1 text-xs rounded-t ${L===`ephemeral`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Ephemeral`})]}),(ne||te&&L===`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)(ee,{size:11}),` `,b||`ID "${V}" is already in use`]}),!D&&v===!0&&(0,K.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`}),!D&&v===!1&&(0,K.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,K.jsx)(ee,{size:11}),` `,b||`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:()=>_(`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:()=>_(`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)(Je,{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:z==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:z})}),(0,K.jsxs)(`p`,{className:`text-[10px] text-amber-600 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(ee,{size:10}),` Changes on every loop restart. Saving also restarts the container.`]})]})]}),(re||te&&L===`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 Qh();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)(nt,{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)(ee,{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:()=>_(`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:()=>_(`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:()=>_(`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:ve,className:`px-2 py-1.5 rounded hover:bg-gray-100 text-gray-500`,title:`Copy URL`,children:S?(0,K.jsx)(H,{size:14,className:`text-emerald-600`}):(0,K.jsx)(oe,{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:[F&&(0,K.jsx)(`span`,{className:`text-xs text-red-500`,children:F}),N&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(H,{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:_e,disabled:!ye,className:`px-3 py-1.5 text-xs rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40`,children:w?`Saving...`:`Save`})]})]})]})}):null}var sG=(0,T.lazy)(()=>wt(()=>import(`./Editor-C17JCtKx.js`).then(e=>({default:e.Editor})),__vite__mapDeps([0,1,2]))),cG=(0,T.lazy)(()=>wt(()=>import(`./Terminal-B980yCb2.js`).then(e=>({default:e.Terminal})),__vite__mapDeps([3,4])));function lG(){let{id:e}=Zn(),t=Ng();if(!e)return(0,K.jsx)(xr,{to:`/loop`,replace:!0});if(!t.currentUser)return(0,K.jsx)(LW,{});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)(uG,{currentId:e}),(0,K.jsx)(dG,{meta:n},e)]}):(0,K.jsx)(xr,{to:`/loop`,replace:!0})}function uG({currentId:e}){let t=Ng(),n=qn(),[r,i]=(0,T.useState)(`mine`),[a,o]=(0,T.useState)(``),[s,c]=(0,T.useState)(()=>localStorage.getItem(`loopat:loopsList:collapsed`)===`1`),l=vU(),u=VW((0,T.useMemo)(()=>t.loops.map(e=>e.id),[t.loops]));(0,T.useEffect)(()=>{let t=u[e];t?.status===`Done`&&t?.viewed===!1&&ym(e)},[u,e]);let d=t.currentUser?.id,f=(0,T.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)(M,{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)(He,{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:()=>{ym(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)(M,{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)(j,{size:13}):(0,K.jsx)(M,{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)(Ue,{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)(He,{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 dG({meta:e}){let t=Ng(),n=vU(),[r,i]=(0,T.useState)([]),[a,o]=(0,T.useState)(null),[s,c]=(0,T.useState)(null),[l,u]=(0,T.useState)([]),[d,f]=(0,T.useState)(!1),[p,m]=(0,T.useState)(null);(0,T.useEffect)(()=>{Yh().then(m)},[]);let[h,g]=(0,T.useState)(null),_=e=>{c(e),g(null),i(e=>e.includes(`editor`)?e:[...e,`editor`])},{runtime:v,connected:y,reconnecting:b,running:x,viewers:S,extra:C,queue:w,onClearQueue:E}=PU(e.id,t.currentUser?.id??``,_);(0,T.useEffect)(()=>{Fm(e.id).then(u),ym(e.id),t.currentUser?.id&&localStorage.setItem(`loopat:lastLoop:${t.currentUser.id}`,e.id)},[e.id]);let D=Un(),O=qn(),k=D.state?.kickoff;(0,T.useEffect)(()=>{!k||!y||(C.enqueueMessage(k),O(D.pathname,{replace:!0,state:null}))},[k,y]);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,T.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);return!isNaN(e)&&e>=10&&e<=90?e:55}),[B,V]=(0,T.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);return!isNaN(e)&&e>=5&&e<=50?e:18});(0,T.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)(_G,{loopId:e.id,meta:e,mode:n,onClose:()=>M(n),pickedFile:s,onPickFile:_,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)(fG,{meta:e,mounts:l,connected:y,reconnecting:b,running:x,viewers:S,queue:w,onClearQueue:E,openPanels:r,toggleMode:A,onShareWork:()=>f(!0),showShareButton:!p||p.serveEnabled||p.serveDynamicEnabled||p.serveEphemeralEnabled}),n?(0,K.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,K.jsx)(NU,{extra:C,children:(0,K.jsx)(uw,{runtime:v,children:(0,K.jsx)(IW,{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)(dk,{orientation:`horizontal`,className:`flex-1 min-w-0 min-h-0`,onLayoutChange:H,children:[(0,K.jsx)(mk,{id:`chat`,minSize:20,defaultSize:R,className:`flex flex-col min-h-0 min-w-0`,children:(0,K.jsx)(NU,{extra:C,children:(0,K.jsx)(uw,{runtime:v,children:(0,K.jsx)(IW,{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)(_k,{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)(mk,{id:`editorCol`,minSize:15,defaultSize:30,className:`flex flex-col min-h-0 min-w-0`,children:P.length>1?(0,K.jsx)(dk,{orientation:`vertical`,className:`flex-1 min-h-0`,children:P.map((e,t)=>(0,K.jsxs)(T.Fragment,{children:[t>0&&(0,K.jsx)(_k,{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)(mk,{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)(_k,{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)(mk,{id:`otherCol`,minSize:15,defaultSize:B,className:`flex flex-col min-h-0 min-w-0`,children:F.length>1?(0,K.jsx)(dk,{orientation:`vertical`,className:`flex-1 min-h-0`,children:F.map((e,t)=>(0,K.jsxs)(T.Fragment,{children:[t>0&&(0,K.jsx)(_k,{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)(mk,{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)(NU,{extra:C,children:(0,K.jsx)(uw,{runtime:v,children:(0,K.jsx)(IW,{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)(T.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)(oG,{loop:e,open:d,onClose:()=>f(!1),onSaved:async()=>{await t.refresh()}})]})}function fG({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=vU(),p=qn(),m=Ng(),[h,g]=(0,T.useState)(f),[_,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(!1),[x,S]=(0,T.useState)(e.title),C=m.currentUser?.id===e.createdBy,w=async()=>{if(!_){v(!0);try{let t=await Tm(e.id);t&&p(`/loop/${t.id}`)}finally{v(!1)}}},E=async()=>{let t=x.trim();if(!t||t===e.title){b(!1),S(e.title);return}b(!1),await m.setLoopTitle(e.id,t)||S(e.title)},D=(e,t)=>(0,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)(U,{size:14,className:`transition-transform `+(h?`-rotate-90`:``)})}),y?(0,K.jsx)(`input`,{type:`text`,value:x,autoFocus:!0,onChange:e=>S(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing?(t.preventDefault(),E()):t.key===`Escape`&&(t.preventDefault(),b(!1),S(e.title))},onBlur:E,maxLength:200,className:`text-[14px] md:text-[15px] font-medium text-gray-900 bg-white border border-blue-400 rounded px-1 py-0 outline-none min-w-[120px]`}):(0,K.jsx)(`span`,{className:`text-[14px] md:text-[15px] font-medium text-gray-900 `+(C?`cursor-pointer hover:bg-gray-100 rounded px-1 -mx-1`:``),onClick:()=>{C&&(S(e.title),b(!0))},title:C?`click to rename`:void 0,children:e.title}),(0,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:w,disabled:_,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-violet-700 border-violet-300 hover:bg-violet-50 disabled:opacity-50`,title:`Spawn a child loop seeded with this loop's conversation, for sedimenting reusable insights into knowledge/`,children:[(0,K.jsx)(ve,{size:11}),_?`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)(Te,{size:11}),`Share Artifact`]}),(0,K.jsx)(mG,{meta:e}),(0,K.jsx)(pG,{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)(Ce,{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)(hG,{label:e.name,value:e.name===`knowledge`?`ro`:`rw`},e.path))]}),e.config?.profiles&&e.config.profiles.length>0&&(0,K.jsx)(gG,{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)(hG,{label:e.config?.vault??`default`,value:`loaded`})]})]})]})}function pG({meta:e}){let t=Ng(),[n,r]=(0,T.useState)(!1),[i,a]=(0,T.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)(H,{size:11}):(0,K.jsx)(oe,{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)(Te,{size:11}):(0,K.jsx)(Ne,{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)(Te,{size:11}):(0,K.jsx)(Ne,{size:11}),s?`public`:`private`]})}function mG({meta:e}){let t=Ng(),[n,r]=(0,T.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)(Ee,{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)(Ee,{size:11}),`Request For Drive`]}):null}function hG({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 gG({profiles:e}){let[t,n]=(0,T.useState)({});return(0,T.useEffect)(()=>{let e=!1;return hm().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)(hG,{label:e,value:`active`,title:t[e]},e))]})}function _G({loopId:e,meta:t,mode:n,onClose:r,pickedFile:i,onPickFile:a,currentUserId:o,isFullscreen:s,onToggleFullscreen:c,onEditorSelection:l}){let u=vU(),[d,f]=(0,T.useState)(()=>{let e=localStorage.getItem(`loopat:mobilePanelPct`);return e?Math.max(20,Math.min(95,parseInt(e)||55)):55}),p=(0,T.useRef)(null),m=e=>{localStorage.setItem(`loopat:mobilePanelPct`,String(e))},h=e=>{if(p.current={startY:e,startPct:d},s){let t=Math.round(e/window.innerHeight*100),n=Math.max(20,Math.min(95,t));f(n),m(n),c?.()}},g=e=>{if(!p.current)return;let t=e-p.current.startY,n=Math.round(t/window.innerHeight*100),r=Math.max(20,Math.min(95,p.current.startPct+n));f(r),m(r)},_=()=>{p.current=null},v=e=>{e.preventDefault(),e.stopPropagation(),h(e.touches[0].clientY)},y=e=>{e.preventDefault(),g(e.touches[0].clientY)},b=e=>{e.preventDefault(),_()},x=e=>{e.pointerType!==`touch`&&(e.preventDefault(),e.target.setPointerCapture(e.pointerId),h(e.clientY))},S=e=>{e.pointerType===`touch`||!p.current||g(e.clientY)},C=e=>{e.pointerType!==`touch`&&_()},w=(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)(Le,{size:13}):(0,K.jsx)(Pe,{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)(vG,{meta:t}),n===`workdir`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(YW,{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)(T.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)(sG,{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)(cG,{loopId:e,currentUserId:o})}),n===`git`&&(0,K.jsx)(tG,{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:w}),(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:v,onTouchMove:y,onTouchEnd:b,onPointerDown:x,onPointerMove:S,onPointerUp:C,children:(0,K.jsx)(`div`,{className:`w-8 h-1 rounded-full bg-gray-300`})})]}):s?(0,yt.createPortal)((0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex flex-col`,children:w}),document.body):w}function vG({meta:e}){let t=Ng().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)(yG,{label:`basics`,children:[(0,K.jsx)(bG,{label:`title`,value:e.title}),(0,K.jsx)(bG,{label:`created`,value:new Date(e.createdAt).toLocaleString()}),(0,K.jsx)(bG,{label:`status`,value:`active`}),(0,K.jsx)(bG,{label:`driver`,value:t?`${e.createdBy} (you)`:e.createdBy}),(0,K.jsx)(bG,{label:`sharing`,value:e.public?`public — /loop/${e.id.slice(0,8)}…`:`private`})]}),(0,K.jsxs)(yG,{label:`workdir`,children:[(0,K.jsx)(bG,{label:`id`,value:e.id,mono:!0}),(0,K.jsx)(bG,{label:`path`,value:`~/.loopat/loops/${e.id.slice(0,8)}/workdir`,mono:!0}),(0,K.jsx)(bG,{label:`branch`,value:`main`,mono:!0})]}),(0,K.jsxs)(yG,{label:`context`,children:[(0,K.jsx)(bG,{label:`knowledge`,value:`all (ro)`}),(0,K.jsx)(bG,{label:`notes`,value:`all (rw)`}),(0,K.jsx)(bG,{label:`personal`,value:`${e.createdBy} (rw)`})]})]})}function yG({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 bG({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 xG({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 SG(){let{name:e}=Zn(),t=decodeURIComponent(e??``),n=qn(),[r,i]=(0,T.useState)(null),[a,o]=(0,T.useState)(!0);return(0,T.useEffect)(()=>{let e=!1;return Sh().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)(xG,{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 CG=(0,T.lazy)(()=>wt(()=>import(`./CodeEditor-B1jg6Yiy.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([1,2]))),wG=(0,T.lazy)(()=>wt(()=>import(`./Markdown-DqMis2lt.js`).then(e=>({default:e.Markdown})),[])),TG=(0,T.lazy)(()=>wt(()=>import(`./MilkdownEditor-Br5IzCOU.js`).then(e=>({default:e.MilkdownEditor})),__vite__mapDeps([5,2]))),EG=[{id:`knowledge`,label:`Knowledge`},{id:`notes`,label:`Notes`},{id:`personal`,label:`Personal`},{id:`repos`,label:`Repos`}],DG=new Set([`knowledge`,`notes`,`personal`,`repos`]);function OG(){let{sub:e}=Zn(),[t]=Ti(),n=DG.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:EG.map(e=>(0,K.jsx)(vi,{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)(BG,{}):(0,K.jsx)(MG,{vault:n,initialFile:r,initialEditing:i},n)})]})}var kG={knowledge:`workspace's distilled materials`,notes:`workspace · public`,personal:`yours · private`,repos:`registered code repos`};function AG({resource:e,canPush:t=!0}){let[n,r]=(0,T.useState)(null),[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(null),c=(0,T.useCallback)(async()=>{a(`status`),r(await $m(e)),a(null)},[e]);(0,T.useEffect)(()=>{c()},[c]);let l=async()=>{a(`pull`),s(null);let t=await eh(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 th(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 jG({onRefreshed:e}){let[t,n]=(0,T.useState)(0),[r,i]=(0,T.useState)(!1),[a,o]=(0,T.useState)(null),s=(0,T.useRef)(e);s.current=e;let c=(0,T.useCallback)(async()=>{i(!0),o(null);let e=await Hm();i(!1),e.ok?(n(0),s.current()):e.diverged?o(`你有未保存的编辑,先保存再刷新`):o(e.error??`refresh failed`)},[]);return(0,T.useEffect)(()=>{c()},[c]),(0,T.useEffect)(()=>{let e=()=>Vm().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 MG({vault:e,initialFile:t,initialEditing:n}){let[r,i]=(0,T.useState)([]),[a,o]=(0,T.useState)([]),[s,c]=(0,T.useState)(t??null),[l,u]=Ti();(0,T.useEffect)(()=>{(l.get(`file`)??null)!==s&&u(s?{file:s}:{},{replace:!0})},[s,l,u]);let[d,f]=(0,T.useState)(0),[p,m]=(0,T.useState)(!1),[h,g]=(0,T.useState)(``),[_,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)(``),C=vU(),w=(0,T.useRef)(!1);if(!w.current&&t){w.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,T.useEffect)(()=>{Im(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})}),Lm(e).then(o),g(``)},[e,d]);let E=async t=>{let n=await Um(e,t);n.ok?(m(!1),f(e=>e+1),c(t)):alert(`failed: ${n.error}`)},D=async()=>{if(!y||!x.trim()){b(null);return}let t=y.path+`/`+x.trim();if(y.type===`file`){let n=await Um(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}else{let n=await Wm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}b(null),S(``),f(e=>e+1)},O=(0,T.useCallback)((t,n)=>{if(t===`view`)c(n.path);else if(t===`new-file`||t===`new-folder`)b({type:t===`new-file`?`file`:`folder`,path:n.path}),S(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Gm(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,T.useCallback)(t=>PG(e,t.path)?[]:t.type===`dir`?[{label:`New file`,icon:(0,K.jsx)(he,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,K.jsx)(xe,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,K.jsx)(lt,{size:12}),action:`delete`,danger:!0}]:FG(e,t.path)?[]:[{label:`View`,icon:(0,K.jsx)(fe,{size:12}),action:`view`},{label:`Delete`,icon:(0,K.jsx)(lt,{size:12}),action:`delete`,danger:!0}],[e]),A=(0,T.useCallback)(t=>Im(e,t).then(e=>e),[e]),j=(0,T.useCallback)((t,n,r,i)=>{if(t.type===`dir`)return PG(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=FG(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:[C&&(0,K.jsx)(`button`,{onClick:()=>v(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,K.jsx)(He,{size:14})}),(0,K.jsx)(NG,{}),(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),C&&v(!1)},className:`w-full px-3 py-1.5 flex items-center gap-2 text-left `+(s===e.path?`bg-gray-100`:`hover:bg-gray-50`),title:e.path,children:[(0,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)(GW,{treeId:`vault-${e}`,entries:r,onPick:e=>{c(e),C&&v(!1)},picked:s,onLoadChildren:A,getContextActions:k,onAction:O,nodeClassName:j,reloadKey:d}),r.length===0&&(0,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:kG[e]}),e===`knowledge`&&(0,K.jsx)(AG,{resource:e}),e===`notes`&&(0,K.jsx)(jG,{onRefreshed:()=>f(e=>e+1)})]});return(0,K.jsxs)(`div`,{className:`flex h-full w-full`,children:[C?(0,K.jsx)(K.Fragment,{children:_?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>v(!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:()=>v(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`open file tree`,children:(0,K.jsx)(Ue,{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)(RG,{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)(zG,{vault:e,onClose:()=>m(!1),onCreate:E}),y&&(0,K.jsx)(IG,{type:y.type,parentPath:y.path,value:x,onChange:S,onSubmit:D,onCancel:()=>b(null)})]})}function NG(){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 PG(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).length>0}function FG(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).includes(`/`)}function IG({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 LG(e){return/(^|\/)secrets\//.test(e)||e===`secrets`}function RG({vault:e,path:t,onSelect:n,onSaved:r,initialEditing:i}){let a=Ng(),o=qn(),[s,c]=(0,T.useState)(``),[l,u]=(0,T.useState)(``),[d,f]=(0,T.useState)(i??!1),[p,m]=(0,T.useState)(!1),[h,g]=(0,T.useState)([]),[_,v]=(0,T.useState)(null),[y,b]=(0,T.useState)(!1),[x,S]=(0,T.useState)(!1),[C,w]=(0,T.useState)(!1),[E,D]=(0,T.useState)(!1),O=vU(),k=(0,T.useRef)(i);(0,T.useEffect)(()=>{k.current?k.current=!1:f(!1),S(!1),v(null),w(!1),D(!1),Rm(e,t).then(e=>{let t=e?.content??``;c(t),u(t),D(!!e?.secret)}),Km(e,t).then(g)},[e,t]);let A=LG(t)||E,j=t.endsWith(`.md`),M=e!==`knowledge`,N=!A,P=e===`notes`&&!A,F=A?l.length>0:l!==s,I=(0,T.useCallback)(async()=>{if(!(!F||p)){m(!0);try{let n=await zm(e,t,l);if(n.ok){if(A?(c(``),u(``)):c(l),v(n.commit??null),f(!1),r(),Km(e,t).then(g),e===`notes`){let e=await Bm();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 alert(`save failed: ${n.error}`)}finally{m(!1)}}},[e,t,l,F,p,r,A]),L=()=>{f(!0),j&&S(!0)},R=()=>{u(s),f(!1)},z=async()=>{o(`/loop/${(await a.createLoop({title:`edit ${e}/${t}`})).id}`)},B=async()=>{o(`/loop/${(await a.createLoop({title:`distill ${t} → knowledge`,knowledgeRw:!0})).id}`)},V=e=>{n([t.replace(/[^/]+$/,``)+e+`.md`,e+`.md`,e][0].replace(/^\//,``))};return(0,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}),_&&!F&&!d&&(0,K.jsxs)(`span`,{className:`hidden md:inline text-[10px] text-emerald-700 font-mono`,children:[`commit `,_]})]}),(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:()=>b(e=>!e),className:`px-2.5 h-7 rounded text-xs border ${y?`bg-gray-900 text-white`:`border-gray-200 hover:bg-gray-100 text-gray-900`}`,title:`toggle backlinks`,children:[`⇄ `,h.length]})]})})]}),d?A?(0,K.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,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:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,K.jsx)(Le,{size:13}):(0,K.jsx)(Pe,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(T.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)(CG,{path:t,value:l,onChange:u})})})]}):j&&!x?(0,K.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col md:flex-row`:`flex-1 min-h-0 min-w-0 flex flex-col md:flex-row`,children:[(0,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:()=>S(!0),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to WYSIWYG editor`,children:`wysiwyg`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,K.jsx)(Le,{size:13}):(0,K.jsx)(Pe,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(T.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)(CG,{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)(T.Suspense,{fallback:(0,K.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading preview...`}),children:(0,K.jsx)(wG,{text:l,onWikilink:V})})})})]})]}):j?(0,K.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,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:()=>S(!1),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to source editor`,children:`source`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,K.jsx)(Le,{size:13}):(0,K.jsx)(Pe,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(T.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)(TG,{value:l,onChange:u})})})]}):(0,K.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,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:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,K.jsx)(Le,{size:13}):(0,K.jsx)(Pe,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(T.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)(CG,{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)(T.Suspense,{fallback:(0,K.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading...`}),children:(0,K.jsx)(wG,{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&&y&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>b(!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:()=>b(!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),b(!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 zG({vault:e,onClose:t,onCreate:n}){let[r,i]=(0,T.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 BG(){let e=Ng(),t=qn(),[n,r]=(0,T.useState)([]),[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(null),[c,l]=(0,T.useState)(0),[u,d]=(0,T.useState)(!1),[f,p]=(0,T.useState)(!1),m=vU(),h=(0,T.useCallback)(async()=>{let e=await qm();return r(e),e},[]);(0,T.useEffect)(()=>{h().then(e=>{e.length>0&&!i&&a(e[0].name)})},[h]),(0,T.useEffect)(()=>{i&&Xm(i).then(s)},[i,c]);let g=async()=>{i&&t(`/loop/${(await e.createLoop({title:`${i} loop`,repo:i})).id}`)},_=(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 justify-between border-b border-gray-200`,children:[m?(0,K.jsx)(`button`,{onClick:()=>d(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,title:`close repos`,children:(0,K.jsx)(He,{size:14})}):(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500 font-medium`,children:`repos`}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-auto`,children:n.length})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:[n.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{a(e.name),m&&d(!1)},className:i===e.name?`w-full px-3 py-2 flex items-center gap-2 text-left bg-gray-100`:`w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-gray-50`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 bg-emerald-500`}),(0,K.jsx)(`span`,{className:`text-[13px] text-gray-900 flex-1 min-w-0 truncate`,children:e.name})]},e.name)),n.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`none yet · click "add repo" below`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>p(!0),className:`m-3 px-2 py-1.5 rounded border border-gray-200 text-xs text-gray-700 hover:bg-gray-50 flex items-center gap-2`,title:`clone a remote URL or symlink a local directory`,children:[(0,K.jsx)(`span`,{children:`+`}),(0,K.jsx)(`span`,{children:`add repo`})]})]});return(0,K.jsxs)(`div`,{className:`flex h-full w-full`,children:[m?(0,K.jsx)(K.Fragment,{children:u?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>d(!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:_})]}):(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:()=>d(!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 repos list`,children:(0,K.jsx)(Ue,{size:16})})})}):_,(0,K.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white min-h-0`,children:o?(0,K.jsx)(WG,{repo:o,onSpawnLoop:g,onPulled:()=>l(e=>e+1)},o.name):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-[13px] text-gray-400 italic`,children:`select a repo`})}),f&&(0,K.jsx)(UG,{existingNames:n.map(e=>e.name),onClose:()=>p(!1),onAdded:async e=>{p(!1),await h(),a(e)}})]})}var VG=/^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;function HG(e){let t=e.trim().replace(/[?#].*$/,``);t=t.replace(/\/+$/,``).replace(/\.git$/i,``);let n=t.match(/[/:]([^/:]+)$/);return(n?n[1]:t).trim()}function UG({existingNames:e,onClose:t,onAdded:n}){let[r,i]=(0,T.useState)(``),[a,o]=(0,T.useState)(``),[s,c]=(0,T.useState)(!1),[l,u]=(0,T.useState)(!1),[d,f]=(0,T.useState)(null),p=HG(r),m=s?a:p,h=/:\/\//.test(r.trim())||/^git@/.test(r.trim());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-[480px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`text-base font-semibold text-gray-900 mb-4`,children:`Add repo`}),(0,K.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault();let i=m.trim();if(!r.trim()){f(`source required`);return}if(!VG.test(i)){f(`invalid name (letters/digits/_.-, max 64, must start with alnum)`);return}if(e.includes(i)){f(`name already exists`);return}f(null),u(!0);let a=await nh({name:i,source:r.trim()});if(u(!1),!a.ok){f(a.error??`add failed`);return}n(i)},className:`flex flex-col gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:`Source`}),(0,K.jsx)(`input`,{autoFocus:!0,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`git@github.com:user/repo.git or ~/code/myrepo`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:r.trim()===``?`git URL (clone) or local path (symlink)`:h?`→ git clone into context/repos/`:`→ symlink into context/repos/`})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:`Name`}),(0,K.jsx)(`input`,{type:`text`,value:m,onChange:e=>{o(e.target.value),c(!0)},placeholder:`repo-name`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:`directory name under context/repos/`})]}),d&&(0,K.jsx)(`div`,{className:`text-[11px] text-red-600 break-words`,children:d}),(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:t,disabled:l,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100 disabled:opacity-50`,children:`cancel`}),(0,K.jsx)(`button`,{type:`submit`,disabled:l||!r.trim()||!m.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:l?`adding…`:`add`})]})]})]})})}function WG({repo:e,onSpawnLoop:t,onPulled:n}){let r=qn(),[i,a]=(0,T.useState)(!1),[o,s]=(0,T.useState)(null);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`header`,{className:`px-5 h-10 shrink-0 border-b border-gray-200 flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] min-w-0`,children:[(0,K.jsx)(`span`,{className:e.status===`online`?`w-2 h-2 rounded-full bg-emerald-500 shrink-0`:`w-2 h-2 rounded-full bg-gray-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-gray-900 font-medium truncate`,children:e.name}),e.remote&&(0,K.jsxs)(`span`,{className:`text-gray-500 truncate`,children:[`· `,e.remote]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[o&&(0,K.jsx)(`span`,{className:`text-[11px] truncate max-w-[260px] `+(o.ok?`text-emerald-700`:`text-red-600`),title:o.text,children:o.text}),(0,K.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`default branch: `,e.branch??`—`]}),(0,K.jsxs)(`button`,{onClick:async()=>{if(i)return;a(!0),s(null);let t=await Zm(e.name);a(!1),t.ok?(s({ok:!0,text:t.output?.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 $W({filePath:e,diff:t,loading:n,onClose:r}){let i=null;if(t)try{i=QW(t)}catch{}return(0,K.jsx)(Bg,{open:!0,onOpenChange:e=>{e||r()},children:(0,K.jsxs)(Ug,{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)(Me,{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 eG={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 tG({loopId:e,onClose:t,onPickFile:n}){let[r,i]=(0,T.useState)(null),[a,o]=(0,T.useState)(!1),[s,c]=(0,T.useState)(!0),[l,u]=(0,T.useState)(!0),[d,f]=(0,T.useState)(null),[p,m]=(0,T.useState)(``),[h,g]=(0,T.useState)(``),[_,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)([]),[C,w]=(0,T.useState)(!1),[E,D]=(0,T.useState)(!0),O=(0,T.useCallback)(async()=>{o(!0),f(null);try{i(await Ah(e))}catch{f(`Failed to load git status`)}finally{o(!1)}},[e]),k=(0,T.useCallback)(async()=>{w(!0);try{S(await Fh(e,50))}catch{}finally{w(!1)}},[e]);(0,T.useEffect)(()=>{O(),k()},[O,k]);let A=async()=>{r?.unstaged.length&&await Mh(e,r.unstaged.map(e=>e.path))&&O()},j=async()=>{r?.staged.length&&await Mh(e,r.staged.map(e=>e.path),!0)&&O()},M=async t=>{await Mh(e,[t])&&O()},N=async t=>{await Mh(e,[t],!0)&&O()},P=async t=>{await Nh(e,t)&&O()},F=async()=>{if(!h.trim())return;v(!0),b(null);let t=await Ph(e,h.trim());v(!1),t.ok?(g(``),O(),k()):b(t.error??`Commit failed`)},I=p.trim().toLowerCase(),L=r?r.unstaged.filter(e=>!I||e.path.toLowerCase().includes(I)):[],R=r?r.staged.filter(e=>!I||e.path.toLowerCase().includes(I)):[],z=!r||r.unstaged.length===0&&r.staged.length===0;return(0,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)(Ye,{size:13,className:a||C?`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),b(null)},rows:2,className:`w-full px-2 py-1.5 text-[12px] border border-gray-200 rounded outline-none focus:border-gray-300 placeholder:text-gray-300 resize-none mb-1.5`}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`button`,{onClick:F,disabled:_||!h.trim(),className:`flex-1 flex items-center justify-center gap-1 px-2 py-1 text-[11px] rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:[(0,K.jsx)(we,{size:12}),_?`Committing...`:`Commit`]}),r&&r.staged.length>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-gray-400`,children:[r.staged.length,` staged`]})]}),y&&(0,K.jsx)(`div`,{className:`mt-1 text-[10px] text-red-500`,children:y})]}),(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)(rG,{title:`Unstaged Changes`,count:L.length,open:s,onToggle:()=>c(e=>!e),bulkAction:{label:`Stage all`,icon:(0,K.jsx)(Ke,{size:12}),onClick:A},children:L.map(t=>(0,K.jsx)(iG,{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)(rG,{title:`Staged Changes`,count:R.length,open:l,onToggle:()=>u(e=>!e),bulkAction:{label:`Unstage all`,icon:(0,K.jsx)(Re,{size:12}),onClick:j},children:R.map(t=>(0,K.jsx)(iG,{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)(Ce,{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:[`(`,x.length,`)`]})]}),E&&(0,K.jsx)(`div`,{className:`px-2 pb-2 max-h-64 overflow-auto`,children:C?(0,K.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`loading history...`}):x.length===0?(0,K.jsx)(`div`,{className:`px-3 py-3 text-[11px] text-gray-400 italic`,children:`no commits`}):(0,K.jsx)(nG,{commits:x})})]})]})]})}function nG({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 rG({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 iG({file:e,loopId:t,staged:n,onStage:r,onUnstage:i,onDiscard:a,onEdit:o,onRefresh:s}){let[c,l]=(0,T.useState)(!1),[u,d]=(0,T.useState)(null),[f,p]=(0,T.useState)(!1),[m,h]=(0,T.useState)(!1),[g,_]=(0,T.useState)(null),v=(0,T.useRef)(null);(0,T.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&_(null)};if(g)return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]);let y=async()=>{e.isBinary||(l(!0),u===null&&(p(!0),d(await jh(t,e.path,n)??``),p(!1)))},b=e=>{e.preventDefault(),_({x:e.clientX,y:e.clientY})},x=`workdir/${e.path}`,S=[{label:`Open in Editor`,icon:(0,K.jsx)(Ge,{size:12}),onClick:()=>{o(x),_(null)}},{label:`View Diff`,icon:(0,K.jsx)(Ze,{size:12}),onClick:()=>{y(),_(null)}},{separator:!0,label:``,onClick:()=>{}},n?{label:`Unstage`,icon:(0,K.jsx)(Re,{size:12}),onClick:()=>{i(),_(null)}}:{label:`Stage`,icon:(0,K.jsx)(Ke,{size:12}),onClick:()=>{r(),_(null)}},!n&&{label:`Discard Changes`,icon:(0,K.jsx)(dt,{size:12}),onClick:()=>{h(!0),_(null)},danger:!0}].filter(Boolean),C=eG[e.status]??{label:e.status,color:`text-gray-500`},w=e.path.lastIndexOf(`/`),E=w>=0?e.path.slice(w+1):e.path,D=w>=0?e.path.slice(0,w+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:b,children:[(0,K.jsx)(`span`,{className:`w-5 text-center text-[11px] font-mono font-semibold ${C.color}`,children:C.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(x),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)(Ge,{size:13})}),n&&(0,K.jsx)(`button`,{type:`button`,onClick:y,className:`w-5 h-5 flex items-center justify-center text-gray-400 hover:text-gray-700 rounded`,title:`view diff`,disabled:e.isBinary,children:(0,K.jsx)(Ze,{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)(Re,{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)(dt,{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)(Ke,{size:13})})]})]})]}),g&&(0,K.jsx)(`div`,{ref:v,className:`fixed z-50 min-w-[160px] py-1 bg-white border border-gray-200 rounded-md shadow-lg text-[12px]`,style:{left:g.x,top:g.y},children:S.map((e,t)=>e.separator?(0,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)($W,{filePath:e.path,diff:u,loading:f,onClose:()=>l(!1)}),m&&(0,K.jsx)(Bg,{open:!0,onOpenChange:e=>{e||h(!1)},children:(0,K.jsxs)(Ug,{className:`sm:max-w-sm bg-white p-5 gap-4`,showCloseButton:!1,children:[(0,K.jsx)(Wg,{children:(0,K.jsx)(Gg,{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 aG(e){return e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:`standard`}function oG({loop:e,open:t,onClose:n,onSaved:r}){let[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(e.shareEnabled??!1),[c,l]=(0,T.useState)(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),[u,d]=(0,T.useState)(e.shareAlias??``),[f,p]=(0,T.useState)(e.sharePort??3e3),[m,h]=(0,T.useState)(e.shareExternalPort??1e4),[g,_]=(0,T.useState)(e.shareProtocol??`tcp`),[v,y]=(0,T.useState)(null),[b,x]=(0,T.useState)(``),[S,C]=(0,T.useState)(!1),[w,E]=(0,T.useState)(!1),[D,O]=(0,T.useState)(!1),[k,A]=(0,T.useState)(``),[j,M]=(0,T.useState)(!1),[N,P]=(0,T.useState)(``),[F,I]=(0,T.useState)(``),[L,R]=(0,T.useState)(aG(e)),[z,B]=(0,T.useState)(null),V=e.id.slice(0,8),U=!!(i&&i.serveEnabled),W=!!(i&&i.serveDynamicEnabled),G=!!(i&&i.serveEphemeralEnabled),te=[U,W,G].filter(Boolean).length>1,ne=U&&!W&&!G,re=!U&&W&&!G,ie=!U&&!W&&G;(0,T.useEffect)(()=>{t&&(Yh().then(a),s(e.shareEnabled??!1),l(e.shareMode===`ephemeral`?`ephemeral`:e.shareExternalPort?`direct`:e.shareMode??`static`),d(e.shareAlias??``),p(e.sharePort??3e3),h(e.shareExternalPort??1e4),_(e.shareProtocol??`tcp`),R(aG(e)),y(null),x(``),A(``),B(null))},[t,e]),(0,T.useEffect)(()=>{if(!t||!(ie||te&&L===`ephemeral`)||!e.shareEnabled||e.shareMode!==`ephemeral`)return;let n=!1,r=async()=>{let t=await Xh(e.id);n||B(t.port)};r();let i=setInterval(r,3e3);return()=>{n=!0,clearInterval(i)}},[t,L,ie,te,e.id,e.shareEnabled,e.shareMode]),(0,T.useEffect)(()=>{!t||!i||i.serveDynamicEnabled&&(e.shareEnabled&&e.shareExternalPort||!e.shareEnabled&&!e.shareExternalPort&&Qh().then(e=>{e.port&&h(e.port)}))},[t,i,e.shareEnabled,e.shareExternalPort]),(0,T.useEffect)(()=>{t&&eg(V,e.id).then(e=>{e.available?O(!1):(O(!0),x(`ID "${V}" is already in use. Please set an alias.`))})},[t,V,e.id]),(0,T.useEffect)(()=>{if(!u||!t){y(null),x(``);return}let n=setTimeout(async()=>{let t=await eg(u,e.id);y(t.available),x(t.reason??``)},300);return()=>clearTimeout(n)},[u,t,e.id]);let ae=u||V,se=i?.https?`https`:`http`,ce=i?.withPort?`:${i.displayPort}`:``,le=i?`${se}://${ae}${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=z?`${g===`udp`?`udp`:`tcp`}://${fe}:${z}`:`(no active port — save & wait for container restart)`,me=re||te&&L===`direct`&&W&&!ie,he=ie||te&&L===`ephemeral`,ge=he?pe:me?de:le;(0,T.useEffect)(()=>{if(!t||!me)return;let n=setTimeout(async()=>{M(!0);let t=await $h(m,e.id);M(!1),t.available?A(``):A(t.reason??`Port unavailable`)},400);return()=>clearTimeout(n)},[m,t,c,e.id]);let _e=async()=>{if(E(!0),me){let t=await $h(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)P(`Saved`),await r?.(),setTimeout(()=>{P(``),n()},800);else try{I((await i.json()).error??`Save failed (${i.status})`)}catch{I(`Save failed (${i.status})`)}},ve=async()=>{try{await navigator.clipboard.writeText(ge),C(!0),setTimeout(()=>C(!1),1500)}catch{window.prompt(`Copy this URL:`,ge)}},ye=!w&&!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)(Bg,{open:t,onOpenChange:e=>{e||n()},children:(0,K.jsxs)(Ug,{className:`sm:max-w-md bg-white max-h-[85vh] overflow-y-auto`,children:[(0,K.jsxs)(Wg,{children:[(0,K.jsxs)(Gg,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Te,{size:16}),`Share Artifact`]}),(0,K.jsx)(Kg,{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:[te&&(0,K.jsxs)(`div`,{className:`flex gap-1.5 border-b border-gray-200 pb-2`,children:[U&&(0,K.jsx)(`button`,{onClick:()=>{R(`standard`),l(`static`)},className:`px-3 py-1 text-xs rounded-t ${L===`standard`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Subdomain`}),W&&(0,K.jsx)(`button`,{onClick:()=>{R(`direct`),l(`direct`)},className:`px-3 py-1 text-xs rounded-t ${L===`direct`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Direct Port`}),G&&(0,K.jsx)(`button`,{onClick:()=>{R(`ephemeral`),l(`ephemeral`)},className:`px-3 py-1 text-xs rounded-t ${L===`ephemeral`?`bg-blue-50 text-blue-700 font-medium`:`text-gray-500 hover:text-gray-700`}`,children:`Ephemeral`})]}),(ne||te&&L===`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)(ee,{size:11}),` `,b||`ID "${V}" is already in use`]}),!D&&v===!0&&(0,K.jsx)(`span`,{className:`text-[11px] text-emerald-600 mt-0.5`,children:`Available`}),!D&&v===!1&&(0,K.jsxs)(`span`,{className:`text-[11px] text-red-500 mt-0.5 flex items-center gap-1`,children:[(0,K.jsx)(ee,{size:11}),` `,b||`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:()=>_(`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:()=>_(`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)(Je,{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:z==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:z})}),(0,K.jsxs)(`p`,{className:`text-[10px] text-amber-600 mt-1 flex items-center gap-1`,children:[(0,K.jsx)(ee,{size:10}),` Changes on every loop restart. Saving also restarts the container.`]})]})]}),(re||te&&L===`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 Qh();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)(nt,{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)(ee,{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:()=>_(`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:()=>_(`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:()=>_(`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:ve,className:`px-2 py-1.5 rounded hover:bg-gray-100 text-gray-500`,title:`Copy URL`,children:S?(0,K.jsx)(H,{size:14,className:`text-emerald-600`}):(0,K.jsx)(oe,{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:[F&&(0,K.jsx)(`span`,{className:`text-xs text-red-500`,children:F}),N&&(0,K.jsxs)(`span`,{className:`text-xs text-emerald-600 flex items-center gap-1`,children:[(0,K.jsx)(H,{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:_e,disabled:!ye,className:`px-3 py-1.5 text-xs rounded bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-40`,children:w?`Saving...`:`Save`})]})]})]})}):null}var sG=(0,T.lazy)(()=>wt(()=>import(`./Editor-C9mcMyB9.js`).then(e=>({default:e.Editor})),__vite__mapDeps([0,1,2]))),cG=(0,T.lazy)(()=>wt(()=>import(`./Terminal-yITknn_A.js`).then(e=>({default:e.Terminal})),__vite__mapDeps([3,4])));function lG(){let{id:e}=Zn(),t=Ng();if(!e)return(0,K.jsx)(xr,{to:`/loop`,replace:!0});if(!t.currentUser)return(0,K.jsx)(LW,{});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)(uG,{currentId:e}),(0,K.jsx)(dG,{meta:n},e)]}):(0,K.jsx)(xr,{to:`/loop`,replace:!0})}function uG({currentId:e}){let t=Ng(),n=qn(),[r,i]=(0,T.useState)(`mine`),[a,o]=(0,T.useState)(``),[s,c]=(0,T.useState)(()=>localStorage.getItem(`loopat:loopsList:collapsed`)===`1`),l=vU(),u=VW((0,T.useMemo)(()=>t.loops.map(e=>e.id),[t.loops]));(0,T.useEffect)(()=>{let t=u[e];t?.status===`Done`&&t?.viewed===!1&&ym(e)},[u,e]);let d=t.currentUser?.id,f=(0,T.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)(M,{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)(He,{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:()=>{ym(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)(M,{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)(j,{size:13}):(0,K.jsx)(M,{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)(Ue,{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)(He,{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 dG({meta:e}){let t=Ng(),n=vU(),[r,i]=(0,T.useState)([]),[a,o]=(0,T.useState)(null),[s,c]=(0,T.useState)(null),[l,u]=(0,T.useState)([]),[d,f]=(0,T.useState)(!1),[p,m]=(0,T.useState)(null);(0,T.useEffect)(()=>{Yh().then(m)},[]);let[h,g]=(0,T.useState)(null),_=e=>{c(e),g(null),i(e=>e.includes(`editor`)?e:[...e,`editor`])},{runtime:v,connected:y,reconnecting:b,running:x,viewers:S,extra:C,queue:w,onClearQueue:E}=PU(e.id,t.currentUser?.id??``,_);(0,T.useEffect)(()=>{Fm(e.id).then(u),ym(e.id),t.currentUser?.id&&localStorage.setItem(`loopat:lastLoop:${t.currentUser.id}`,e.id)},[e.id]);let D=Un(),O=qn(),k=D.state?.kickoff;(0,T.useEffect)(()=>{!k||!y||(C.enqueueMessage(k),O(D.pathname,{replace:!0,state:null}))},[k,y]);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,T.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:chatPct`)||``,10);return!isNaN(e)&&e>=10&&e<=90?e:55}),[B,V]=(0,T.useState)(()=>{let e=parseInt(localStorage.getItem(`loopat:otherPct`)||``,10);return!isNaN(e)&&e>=5&&e<=50?e:18});(0,T.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)(_G,{loopId:e.id,meta:e,mode:n,onClose:()=>M(n),pickedFile:s,onPickFile:_,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)(fG,{meta:e,mounts:l,connected:y,reconnecting:b,running:x,viewers:S,queue:w,onClearQueue:E,openPanels:r,toggleMode:A,onShareWork:()=>f(!0),showShareButton:!p||p.serveEnabled||p.serveDynamicEnabled||p.serveEphemeralEnabled}),n?(0,K.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,K.jsx)(NU,{extra:C,children:(0,K.jsx)(uw,{runtime:v,children:(0,K.jsx)(IW,{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)(dk,{orientation:`horizontal`,className:`flex-1 min-w-0 min-h-0`,onLayoutChange:H,children:[(0,K.jsx)(mk,{id:`chat`,minSize:20,defaultSize:R,className:`flex flex-col min-h-0 min-w-0`,children:(0,K.jsx)(NU,{extra:C,children:(0,K.jsx)(uw,{runtime:v,children:(0,K.jsx)(IW,{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)(_k,{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)(mk,{id:`editorCol`,minSize:15,defaultSize:30,className:`flex flex-col min-h-0 min-w-0`,children:P.length>1?(0,K.jsx)(dk,{orientation:`vertical`,className:`flex-1 min-h-0`,children:P.map((e,t)=>(0,K.jsxs)(T.Fragment,{children:[t>0&&(0,K.jsx)(_k,{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)(mk,{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)(_k,{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)(mk,{id:`otherCol`,minSize:15,defaultSize:B,className:`flex flex-col min-h-0 min-w-0`,children:F.length>1?(0,K.jsx)(dk,{orientation:`vertical`,className:`flex-1 min-h-0`,children:F.map((e,t)=>(0,K.jsxs)(T.Fragment,{children:[t>0&&(0,K.jsx)(_k,{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)(mk,{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)(NU,{extra:C,children:(0,K.jsx)(uw,{runtime:v,children:(0,K.jsx)(IW,{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)(T.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)(oG,{loop:e,open:d,onClose:()=>f(!1),onSaved:async()=>{await t.refresh()}})]})}function fG({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=vU(),p=qn(),m=Ng(),[h,g]=(0,T.useState)(f),[_,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(!1),[x,S]=(0,T.useState)(e.title),C=m.currentUser?.id===e.createdBy,w=async()=>{if(!_){v(!0);try{let t=await Tm(e.id);t&&p(`/loop/${t.id}`)}finally{v(!1)}}},E=async()=>{let t=x.trim();if(!t||t===e.title){b(!1),S(e.title);return}b(!1),await m.setLoopTitle(e.id,t)||S(e.title)},D=(e,t)=>(0,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)(U,{size:14,className:`transition-transform `+(h?`-rotate-90`:``)})}),y?(0,K.jsx)(`input`,{type:`text`,value:x,autoFocus:!0,onChange:e=>S(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.nativeEvent.isComposing?(t.preventDefault(),E()):t.key===`Escape`&&(t.preventDefault(),b(!1),S(e.title))},onBlur:E,maxLength:200,className:`text-[14px] md:text-[15px] font-medium text-gray-900 bg-white border border-blue-400 rounded px-1 py-0 outline-none min-w-[120px]`}):(0,K.jsx)(`span`,{className:`text-[14px] md:text-[15px] font-medium text-gray-900 `+(C?`cursor-pointer hover:bg-gray-100 rounded px-1 -mx-1`:``),onClick:()=>{C&&(S(e.title),b(!0))},title:C?`click to rename`:void 0,children:e.title}),(0,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:w,disabled:_,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] border bg-white text-violet-700 border-violet-300 hover:bg-violet-50 disabled:opacity-50`,title:`Spawn a child loop seeded with this loop's conversation, for sedimenting reusable insights into knowledge/`,children:[(0,K.jsx)(ve,{size:11}),_?`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)(Te,{size:11}),`Share Artifact`]}),(0,K.jsx)(mG,{meta:e}),(0,K.jsx)(pG,{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)(Ce,{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)(hG,{label:e.name,value:e.name===`knowledge`?`ro`:`rw`},e.path))]}),e.config?.profiles&&e.config.profiles.length>0&&(0,K.jsx)(gG,{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)(hG,{label:e.config?.vault??`default`,value:`loaded`})]})]})]})}function pG({meta:e}){let t=Ng(),[n,r]=(0,T.useState)(!1),[i,a]=(0,T.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)(H,{size:11}):(0,K.jsx)(oe,{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)(Te,{size:11}):(0,K.jsx)(Ne,{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)(Te,{size:11}):(0,K.jsx)(Ne,{size:11}),s?`public`:`private`]})}function mG({meta:e}){let t=Ng(),[n,r]=(0,T.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)(Ee,{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)(Ee,{size:11}),`Request For Drive`]}):null}function hG({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 gG({profiles:e}){let[t,n]=(0,T.useState)({});return(0,T.useEffect)(()=>{let e=!1;return hm().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)(hG,{label:e,value:`active`,title:t[e]},e))]})}function _G({loopId:e,meta:t,mode:n,onClose:r,pickedFile:i,onPickFile:a,currentUserId:o,isFullscreen:s,onToggleFullscreen:c,onEditorSelection:l}){let u=vU(),[d,f]=(0,T.useState)(()=>{let e=localStorage.getItem(`loopat:mobilePanelPct`);return e?Math.max(20,Math.min(95,parseInt(e)||55)):55}),p=(0,T.useRef)(null),m=e=>{localStorage.setItem(`loopat:mobilePanelPct`,String(e))},h=e=>{if(p.current={startY:e,startPct:d},s){let t=Math.round(e/window.innerHeight*100),n=Math.max(20,Math.min(95,t));f(n),m(n),c?.()}},g=e=>{if(!p.current)return;let t=e-p.current.startY,n=Math.round(t/window.innerHeight*100),r=Math.max(20,Math.min(95,p.current.startPct+n));f(r),m(r)},_=()=>{p.current=null},v=e=>{e.preventDefault(),e.stopPropagation(),h(e.touches[0].clientY)},y=e=>{e.preventDefault(),g(e.touches[0].clientY)},b=e=>{e.preventDefault(),_()},x=e=>{e.pointerType!==`touch`&&(e.preventDefault(),e.target.setPointerCapture(e.pointerId),h(e.clientY))},S=e=>{e.pointerType===`touch`||!p.current||g(e.clientY)},C=e=>{e.pointerType!==`touch`&&_()},w=(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)(Le,{size:13}):(0,K.jsx)(Pe,{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)(vG,{meta:t}),n===`workdir`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(YW,{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)(T.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)(sG,{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)(cG,{loopId:e,currentUserId:o})}),n===`git`&&(0,K.jsx)(tG,{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:w}),(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:v,onTouchMove:y,onTouchEnd:b,onPointerDown:x,onPointerMove:S,onPointerUp:C,children:(0,K.jsx)(`div`,{className:`w-8 h-1 rounded-full bg-gray-300`})})]}):s?(0,yt.createPortal)((0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex flex-col`,children:w}),document.body):w}function vG({meta:e}){let t=Ng().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)(yG,{label:`basics`,children:[(0,K.jsx)(bG,{label:`title`,value:e.title}),(0,K.jsx)(bG,{label:`created`,value:new Date(e.createdAt).toLocaleString()}),(0,K.jsx)(bG,{label:`status`,value:`active`}),(0,K.jsx)(bG,{label:`driver`,value:t?`${e.createdBy} (you)`:e.createdBy}),(0,K.jsx)(bG,{label:`sharing`,value:e.public?`public — /loop/${e.id.slice(0,8)}…`:`private`})]}),(0,K.jsxs)(yG,{label:`workdir`,children:[(0,K.jsx)(bG,{label:`id`,value:e.id,mono:!0}),(0,K.jsx)(bG,{label:`path`,value:`~/.loopat/loops/${e.id.slice(0,8)}/workdir`,mono:!0}),(0,K.jsx)(bG,{label:`branch`,value:`main`,mono:!0})]}),(0,K.jsxs)(yG,{label:`context`,children:[(0,K.jsx)(bG,{label:`knowledge`,value:`all (ro)`}),(0,K.jsx)(bG,{label:`notes`,value:`all (rw)`}),(0,K.jsx)(bG,{label:`personal`,value:`${e.createdBy} (rw)`})]})]})}function yG({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 bG({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 xG({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 SG(){let{name:e}=Zn(),t=decodeURIComponent(e??``),n=qn(),[r,i]=(0,T.useState)(null),[a,o]=(0,T.useState)(!0);return(0,T.useEffect)(()=>{let e=!1;return Sh().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)(xG,{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 CG=(0,T.lazy)(()=>wt(()=>import(`./CodeEditor-DCyHh42b.js`).then(e=>({default:e.CodeEditor})),__vite__mapDeps([1,2]))),wG=(0,T.lazy)(()=>wt(()=>import(`./Markdown-C34y5IWD.js`).then(e=>({default:e.Markdown})),[])),TG=(0,T.lazy)(()=>wt(()=>import(`./MilkdownEditor-BG3OOnaR.js`).then(e=>({default:e.MilkdownEditor})),__vite__mapDeps([5,2]))),EG=[{id:`knowledge`,label:`Knowledge`},{id:`notes`,label:`Notes`},{id:`personal`,label:`Personal`},{id:`repos`,label:`Repos`}],DG=new Set([`knowledge`,`notes`,`personal`,`repos`]);function OG(){let{sub:e}=Zn(),[t]=Ti(),n=DG.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:EG.map(e=>(0,K.jsx)(vi,{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)(BG,{}):(0,K.jsx)(MG,{vault:n,initialFile:r,initialEditing:i},n)})]})}var kG={knowledge:`workspace's distilled materials`,notes:`workspace · public`,personal:`yours · private`,repos:`registered code repos`};function AG({resource:e,canPush:t=!0}){let[n,r]=(0,T.useState)(null),[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(null),c=(0,T.useCallback)(async()=>{a(`status`),r(await $m(e)),a(null)},[e]);(0,T.useEffect)(()=>{c()},[c]);let l=async()=>{a(`pull`),s(null);let t=await eh(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 th(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 jG({onRefreshed:e}){let[t,n]=(0,T.useState)(0),[r,i]=(0,T.useState)(!1),[a,o]=(0,T.useState)(null),s=(0,T.useRef)(e);s.current=e;let c=(0,T.useCallback)(async()=>{i(!0),o(null);let e=await Hm();i(!1),e.ok?(n(0),s.current()):e.diverged?o(`你有未保存的编辑,先保存再刷新`):o(e.error??`refresh failed`)},[]);return(0,T.useEffect)(()=>{c()},[c]),(0,T.useEffect)(()=>{let e=()=>Vm().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 MG({vault:e,initialFile:t,initialEditing:n}){let[r,i]=(0,T.useState)([]),[a,o]=(0,T.useState)([]),[s,c]=(0,T.useState)(t??null),[l,u]=Ti();(0,T.useEffect)(()=>{(l.get(`file`)??null)!==s&&u(s?{file:s}:{},{replace:!0})},[s,l,u]);let[d,f]=(0,T.useState)(0),[p,m]=(0,T.useState)(!1),[h,g]=(0,T.useState)(``),[_,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)(``),C=vU(),w=(0,T.useRef)(!1);if(!w.current&&t){w.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,T.useEffect)(()=>{Im(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})}),Lm(e).then(o),g(``)},[e,d]);let E=async t=>{let n=await Um(e,t);n.ok?(m(!1),f(e=>e+1),c(t)):alert(`failed: ${n.error}`)},D=async()=>{if(!y||!x.trim()){b(null);return}let t=y.path+`/`+x.trim();if(y.type===`file`){let n=await Um(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}else{let n=await Wm(e,t);if(!n.ok){alert(`create failed: ${n.error}`);return}}b(null),S(``),f(e=>e+1)},O=(0,T.useCallback)((t,n)=>{if(t===`view`)c(n.path);else if(t===`new-file`||t===`new-folder`)b({type:t===`new-file`?`file`:`folder`,path:n.path}),S(``);else if(t===`delete`){if(!confirm(`Delete "${n.name}"?`))return;Gm(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,T.useCallback)(t=>PG(e,t.path)?[]:t.type===`dir`?[{label:`New file`,icon:(0,K.jsx)(he,{size:12}),action:`new-file`},{label:`New folder`,icon:(0,K.jsx)(xe,{size:12}),action:`new-folder`},{label:`Delete`,icon:(0,K.jsx)(lt,{size:12}),action:`delete`,danger:!0}]:FG(e,t.path)?[]:[{label:`View`,icon:(0,K.jsx)(fe,{size:12}),action:`view`},{label:`Delete`,icon:(0,K.jsx)(lt,{size:12}),action:`delete`,danger:!0}],[e]),A=(0,T.useCallback)(t=>Im(e,t).then(e=>e),[e]),j=(0,T.useCallback)((t,n,r,i)=>{if(t.type===`dir`)return PG(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=FG(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:[C&&(0,K.jsx)(`button`,{onClick:()=>v(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100 mr-1`,title:`close sidebar`,children:(0,K.jsx)(He,{size:14})}),(0,K.jsx)(NG,{}),(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),C&&v(!1)},className:`w-full px-3 py-1.5 flex items-center gap-2 text-left `+(s===e.path?`bg-gray-100`:`hover:bg-gray-50`),title:e.path,children:[(0,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)(GW,{treeId:`vault-${e}`,entries:r,onPick:e=>{c(e),C&&v(!1)},picked:s,onLoadChildren:A,getContextActions:k,onAction:O,nodeClassName:j,reloadKey:d}),r.length===0&&(0,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:kG[e]}),e===`knowledge`&&(0,K.jsx)(AG,{resource:e}),e===`notes`&&(0,K.jsx)(jG,{onRefreshed:()=>f(e=>e+1)})]});return(0,K.jsxs)(`div`,{className:`flex h-full w-full`,children:[C?(0,K.jsx)(K.Fragment,{children:_?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>v(!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:()=>v(!0),className:`w-7 h-7 flex items-center justify-center text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded`,title:`open file tree`,children:(0,K.jsx)(Ue,{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)(RG,{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)(zG,{vault:e,onClose:()=>m(!1),onCreate:E}),y&&(0,K.jsx)(IG,{type:y.type,parentPath:y.path,value:x,onChange:S,onSubmit:D,onCancel:()=>b(null)})]})}function NG(){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 PG(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).length>0}function FG(e,t){return e!==`personal`||!t.startsWith(`.loopat/vaults/`)?!1:t.slice(15).includes(`/`)}function IG({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 LG(e){return/(^|\/)secrets\//.test(e)||e===`secrets`}function RG({vault:e,path:t,onSelect:n,onSaved:r,initialEditing:i}){let a=Ng(),o=qn(),[s,c]=(0,T.useState)(``),[l,u]=(0,T.useState)(``),[d,f]=(0,T.useState)(i??!1),[p,m]=(0,T.useState)(!1),[h,g]=(0,T.useState)([]),[_,v]=(0,T.useState)(null),[y,b]=(0,T.useState)(!1),[x,S]=(0,T.useState)(!1),[C,w]=(0,T.useState)(!1),[E,D]=(0,T.useState)(!1),O=vU(),k=(0,T.useRef)(i);(0,T.useEffect)(()=>{k.current?k.current=!1:f(!1),S(!1),v(null),w(!1),D(!1),Rm(e,t).then(e=>{let t=e?.content??``;c(t),u(t),D(!!e?.secret)}),Km(e,t).then(g)},[e,t]);let A=LG(t)||E,j=t.endsWith(`.md`),M=e!==`knowledge`,N=!A,P=e===`notes`&&!A,F=A?l.length>0:l!==s,I=(0,T.useCallback)(async()=>{if(!(!F||p)){m(!0);try{let n=await zm(e,t,l);if(n.ok){if(A?(c(``),u(``)):c(l),v(n.commit??null),f(!1),r(),Km(e,t).then(g),e===`notes`){let e=await Bm();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 alert(`save failed: ${n.error}`)}finally{m(!1)}}},[e,t,l,F,p,r,A]),L=()=>{f(!0),j&&S(!0)},R=()=>{u(s),f(!1)},z=async()=>{o(`/loop/${(await a.createLoop({title:`edit ${e}/${t}`})).id}`)},B=async()=>{o(`/loop/${(await a.createLoop({title:`distill ${t} → knowledge`,knowledgeRw:!0})).id}`)},V=e=>{n([t.replace(/[^/]+$/,``)+e+`.md`,e+`.md`,e][0].replace(/^\//,``))};return(0,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}),_&&!F&&!d&&(0,K.jsxs)(`span`,{className:`hidden md:inline text-[10px] text-emerald-700 font-mono`,children:[`commit `,_]})]}),(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:()=>b(e=>!e),className:`px-2.5 h-7 rounded text-xs border ${y?`bg-gray-900 text-white`:`border-gray-200 hover:bg-gray-100 text-gray-900`}`,title:`toggle backlinks`,children:[`⇄ `,h.length]})]})})]}),d?A?(0,K.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,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:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,K.jsx)(Le,{size:13}):(0,K.jsx)(Pe,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(T.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)(CG,{path:t,value:l,onChange:u})})})]}):j&&!x?(0,K.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col md:flex-row`:`flex-1 min-h-0 min-w-0 flex flex-col md:flex-row`,children:[(0,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:()=>S(!0),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to WYSIWYG editor`,children:`wysiwyg`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,K.jsx)(Le,{size:13}):(0,K.jsx)(Pe,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(T.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)(CG,{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)(T.Suspense,{fallback:(0,K.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading preview...`}),children:(0,K.jsx)(wG,{text:l,onWikilink:V})})})})]})]}):j?(0,K.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,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:()=>S(!1),className:`px-2 h-5 rounded text-[10px] bg-gray-100 hover:bg-gray-200 text-gray-600`,title:`Switch to source editor`,children:`source`}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsx)(`button`,{onClick:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,K.jsx)(Le,{size:13}):(0,K.jsx)(Pe,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(T.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)(TG,{value:l,onChange:u})})})]}):(0,K.jsxs)(`div`,{className:C?`fixed inset-0 z-50 bg-white flex flex-col`:`flex-1 min-h-0 min-w-0 flex flex-col`,children:[(0,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:()=>w(!C),className:`text-gray-400 hover:text-gray-700 px-1 rounded hover:bg-gray-100`,title:C?`restore`:`maximize`,children:C?(0,K.jsx)(Le,{size:13}):(0,K.jsx)(Pe,{size:13})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:(0,K.jsx)(T.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)(CG,{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)(T.Suspense,{fallback:(0,K.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading...`}),children:(0,K.jsx)(wG,{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&&y&&(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>b(!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:()=>b(!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),b(!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 zG({vault:e,onClose:t,onCreate:n}){let[r,i]=(0,T.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 BG(){let e=Ng(),t=qn(),[n,r]=(0,T.useState)([]),[i,a]=(0,T.useState)(null),[o,s]=(0,T.useState)(null),[c,l]=(0,T.useState)(0),[u,d]=(0,T.useState)(!1),[f,p]=(0,T.useState)(!1),m=vU(),h=(0,T.useCallback)(async()=>{let e=await qm();return r(e),e},[]);(0,T.useEffect)(()=>{h().then(e=>{e.length>0&&!i&&a(e[0].name)})},[h]),(0,T.useEffect)(()=>{i&&Xm(i).then(s)},[i,c]);let g=async()=>{i&&t(`/loop/${(await e.createLoop({title:`${i} loop`,repo:i})).id}`)},_=(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 justify-between border-b border-gray-200`,children:[m?(0,K.jsx)(`button`,{onClick:()=>d(!1),className:`text-gray-500 hover:text-gray-900 px-1 rounded hover:bg-gray-100`,title:`close repos`,children:(0,K.jsx)(He,{size:14})}):(0,K.jsx)(`span`,{className:`text-[11px] uppercase tracking-wide text-gray-500 font-medium`,children:`repos`}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400 ml-auto`,children:n.length})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto py-2`,children:[n.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{a(e.name),m&&d(!1)},className:i===e.name?`w-full px-3 py-2 flex items-center gap-2 text-left bg-gray-100`:`w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-gray-50`,children:[(0,K.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 bg-emerald-500`}),(0,K.jsx)(`span`,{className:`text-[13px] text-gray-900 flex-1 min-w-0 truncate`,children:e.name})]},e.name)),n.length===0&&(0,K.jsx)(`div`,{className:`px-3 py-4 text-[12px] text-gray-400 italic`,children:`none yet · click "add repo" below`})]}),(0,K.jsxs)(`button`,{type:`button`,onClick:()=>p(!0),className:`m-3 px-2 py-1.5 rounded border border-gray-200 text-xs text-gray-700 hover:bg-gray-50 flex items-center gap-2`,title:`clone a remote URL or symlink a local directory`,children:[(0,K.jsx)(`span`,{children:`+`}),(0,K.jsx)(`span`,{children:`add repo`})]})]});return(0,K.jsxs)(`div`,{className:`flex h-full w-full`,children:[m?(0,K.jsx)(K.Fragment,{children:u?(0,K.jsxs)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>d(!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:_})]}):(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:()=>d(!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 repos list`,children:(0,K.jsx)(Ue,{size:16})})})}):_,(0,K.jsx)(`main`,{className:`flex-1 min-w-0 flex flex-col bg-white min-h-0`,children:o?(0,K.jsx)(WG,{repo:o,onSpawnLoop:g,onPulled:()=>l(e=>e+1)},o.name):(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-[13px] text-gray-400 italic`,children:`select a repo`})}),f&&(0,K.jsx)(UG,{existingNames:n.map(e=>e.name),onClose:()=>p(!1),onAdded:async e=>{p(!1),await h(),a(e)}})]})}var VG=/^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;function HG(e){let t=e.trim().replace(/[?#].*$/,``);t=t.replace(/\/+$/,``).replace(/\.git$/i,``);let n=t.match(/[/:]([^/:]+)$/);return(n?n[1]:t).trim()}function UG({existingNames:e,onClose:t,onAdded:n}){let[r,i]=(0,T.useState)(``),[a,o]=(0,T.useState)(``),[s,c]=(0,T.useState)(!1),[l,u]=(0,T.useState)(!1),[d,f]=(0,T.useState)(null),p=HG(r),m=s?a:p,h=/:\/\//.test(r.trim())||/^git@/.test(r.trim());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-[480px] mx-4 bg-white rounded-md shadow-xl border border-gray-200 p-4 md:p-5`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`text-base font-semibold text-gray-900 mb-4`,children:`Add repo`}),(0,K.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault();let i=m.trim();if(!r.trim()){f(`source required`);return}if(!VG.test(i)){f(`invalid name (letters/digits/_.-, max 64, must start with alnum)`);return}if(e.includes(i)){f(`name already exists`);return}f(null),u(!0);let a=await nh({name:i,source:r.trim()});if(u(!1),!a.ok){f(a.error??`add failed`);return}n(i)},className:`flex flex-col gap-4`,children:[(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:`Source`}),(0,K.jsx)(`input`,{autoFocus:!0,type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`git@github.com:user/repo.git or ~/code/myrepo`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:r.trim()===``?`git URL (clone) or local path (symlink)`:h?`→ git clone into context/repos/`:`→ symlink into context/repos/`})]}),(0,K.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-gray-700 font-medium`,children:`Name`}),(0,K.jsx)(`input`,{type:`text`,value:m,onChange:e=>{o(e.target.value),c(!0)},placeholder:`repo-name`,className:`w-full px-2 py-1.5 text-sm border border-gray-300 rounded outline-none focus:border-gray-500 font-mono`}),(0,K.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:`directory name under context/repos/`})]}),d&&(0,K.jsx)(`div`,{className:`text-[11px] text-red-600 break-words`,children:d}),(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:t,disabled:l,className:`px-3 h-8 text-sm rounded text-gray-700 hover:bg-gray-100 disabled:opacity-50`,children:`cancel`}),(0,K.jsx)(`button`,{type:`submit`,disabled:l||!r.trim()||!m.trim(),className:`px-3 h-8 text-sm rounded bg-gray-900 text-white hover:bg-gray-700 disabled:opacity-50`,children:l?`adding…`:`add`})]})]})]})})}function WG({repo:e,onSpawnLoop:t,onPulled:n}){let r=qn(),[i,a]=(0,T.useState)(!1),[o,s]=(0,T.useState)(null);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`header`,{className:`px-5 h-10 shrink-0 border-b border-gray-200 flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-[13px] min-w-0`,children:[(0,K.jsx)(`span`,{className:e.status===`online`?`w-2 h-2 rounded-full bg-emerald-500 shrink-0`:`w-2 h-2 rounded-full bg-gray-300 shrink-0`}),(0,K.jsx)(`span`,{className:`text-gray-900 font-medium truncate`,children:e.name}),e.remote&&(0,K.jsxs)(`span`,{className:`text-gray-500 truncate`,children:[`· `,e.remote]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[o&&(0,K.jsx)(`span`,{className:`text-[11px] truncate max-w-[260px] `+(o.ok?`text-emerald-700`:`text-red-600`),title:o.text,children:o.text}),(0,K.jsxs)(`span`,{className:`text-xs text-gray-500`,children:[`default branch: `,e.branch??`—`]}),(0,K.jsxs)(`button`,{onClick:async()=>{if(i)return;a(!0),s(null);let t=await Zm(e.name);a(!1),t.ok?(s({ok:!0,text:t.output?.split(`
|
|
108
108
|
`).pop()||`up to date`}),n()):s({ok:!1,text:t.error??`pull failed`})},disabled:i||e.status!==`online`,className:`px-2.5 h-7 rounded text-xs border border-gray-200 hover:bg-gray-100 text-gray-900 flex items-center gap-1 disabled:opacity-50 disabled:cursor-not-allowed`,title:`git pull --ff-only from origin`,children:[(0,K.jsx)(Je,{size:12,className:i?`animate-spin`:``}),(0,K.jsx)(`span`,{children:i?`syncing…`:`sync`})]})]})]}),(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.jsxs)(`div`,{className:`max-w-[820px]`,children:[(0,K.jsxs)(`section`,{className:`mb-6`,children:[(0,K.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900 mb-2`,children:`Recent loops on this repo`}),e.recentLoops.length>0?(0,K.jsx)(`ul`,{className:`flex flex-col gap-1`,children:e.recentLoops.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{onClick:()=>r(`/loop/${e.id}`),className:`w-full px-3 py-2 rounded hover:bg-gray-100 flex items-center gap-3 text-[13px] text-left`,children:[(0,K.jsx)(`span`,{className:`text-gray-500`,children:`⑂`}),(0,K.jsx)(`span`,{className:`text-gray-900`,children:e.title}),(0,K.jsx)(`span`,{className:`text-gray-500 font-mono text-[11px]`,children:e.branch??`main`}),(0,K.jsx)(`span`,{className:`text-gray-500 ml-auto text-[11px]`,children:new Date(e.createdAt).toLocaleString()})]})},e.id))}):(0,K.jsx)(`p`,{className:`text-[13px] text-gray-500`,children:`No active loops yet.`}),(0,K.jsxs)(`button`,{onClick:t,className:`mt-3 px-3 py-1.5 rounded bg-gray-900 text-white text-xs hover:bg-gray-700 flex items-center gap-2`,children:[(0,K.jsx)(`span`,{children:`+`}),(0,K.jsx)(`span`,{children:`spawn new loop on a branch`})]})]}),(0,K.jsxs)(`section`,{children:[(0,K.jsx)(`h3`,{className:`text-[13px] font-medium text-gray-900 mb-2`,children:`README`}),(0,K.jsx)(`div`,{className:`max-w-[760px]`,children:e.readme?(0,K.jsx)(T.Suspense,{fallback:(0,K.jsx)(`div`,{className:`text-gray-400 text-sm`,children:`Loading...`}),children:(0,K.jsx)(wG,{text:e.readme})}):(0,K.jsx)(`p`,{className:`text-[13px] text-gray-500 italic`,children:`No README found at repo root.`})})]})]})})]})}function GG(){var e=[...arguments];return(0,T.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var KG=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function qG(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function JG(e){return`nodeType`in e}function YG(e){return e?qG(e)?e:JG(e)?e.ownerDocument?.defaultView??window:window:window}function XG(e){let{Document:t}=YG(e);return e instanceof t}function ZG(e){return qG(e)?!1:e instanceof YG(e).HTMLElement}function QG(e){return e instanceof YG(e).SVGElement}function $G(e){return e?qG(e)?e.document:JG(e)?XG(e)?e:ZG(e)||QG(e)?e.ownerDocument:document:document:document}var eK=KG?T.useLayoutEffect:T.useEffect;function tK(e){let t=(0,T.useRef)(e);return eK(()=>{t.current=e}),(0,T.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function nK(){let e=(0,T.useRef)(null);return[(0,T.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,T.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function rK(e,t){t===void 0&&(t=[e]);let n=(0,T.useRef)(e);return eK(()=>{n.current!==e&&(n.current=e)},t),n}function iK(e,t){let n=(0,T.useRef)();return(0,T.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function aK(e){let t=tK(e),n=(0,T.useRef)(null);return[n,(0,T.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function oK(e){let t=(0,T.useRef)();return(0,T.useEffect)(()=>{t.current=e},[e]),t.current}var sK={};function cK(e,t){return(0,T.useMemo)(()=>{if(t)return t;let n=sK[e]==null?0:sK[e]+1;return sK[e]=n,e+`-`+n},[e,t])}function lK(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 uK=lK(1),dK=lK(-1);function fK(e){return`clientX`in e&&`clientY`in e}function pK(e){if(!e)return!1;let{KeyboardEvent:t}=YG(e.target);return t&&e instanceof t}function mK(e){if(!e)return!1;let{TouchEvent:t}=YG(e.target);return t&&e instanceof t}function hK(e){if(mK(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 fK(e)?{x:e.clientX,y:e.clientY}:null}var gK=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[gK.Translate.toString(e),gK.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),_K=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function vK(e){return e.matches(_K)?e:e.querySelector(_K)}var yK={display:`none`};function bK(e){let{id:t,value:n}=e;return T.createElement(`div`,{id:t,style:yK},n)}function xK(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return T.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 SK(){let[e,t]=(0,T.useState)(``);return{announce:(0,T.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var CK=(0,T.createContext)(null);function wK(e){let t=(0,T.useContext)(CK);(0,T.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function TK(){let[e]=(0,T.useState)(()=>new Set),t=(0,T.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,T.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var EK={draggable:`
|
|
109
109
|
To pick up a draggable item, press the space bar.
|
|
110
110
|
While dragging, use the arrow keys to move the item.
|