@anhlp/alp-cli 0.0.1-beta.8 → 0.0.1-beta.9

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.
Files changed (50) hide show
  1. package/dist/acp/main.js +1 -1
  2. package/dist/acp.js +180 -82
  3. package/dist/{alp-web → alp-dashboard}/THIRD-PARTY-NOTICES.txt +1 -1
  4. package/dist/{alp-web/assets/TerminalPanel-BbYa_Xkd.js → alp-dashboard/assets/TerminalPanel-BSjqIfNr.js} +1 -1
  5. package/dist/{alp-web/assets/index-DOJh89Ik.js → alp-dashboard/assets/index-CZFfSOIE.js} +5 -5
  6. package/dist/{alp-web → alp-dashboard}/index.html +1 -1
  7. package/dist/{alp-web.js → alp-dashboard.js} +349 -306
  8. package/dist/alpd.js +1308 -1271
  9. package/dist/backup.js +1 -1
  10. package/dist/build-manifest.json +14 -5
  11. package/dist/cli.js +4 -3
  12. package/dist/daemon.d.ts +1 -1
  13. package/dist/daemon.js +6 -6
  14. package/dist/dashboard-migrate.d.ts +31 -0
  15. package/dist/dashboard-migrate.js +127 -0
  16. package/dist/dashboard-service.d.ts +69 -0
  17. package/dist/{web-service.js → dashboard-service.js} +30 -32
  18. package/dist/desktop.d.ts +56 -0
  19. package/dist/desktop.js +91 -0
  20. package/dist/interfaces.d.ts +2 -2
  21. package/dist/interfaces.js +133 -43
  22. package/dist/paths.d.ts +6 -1
  23. package/dist/paths.js +4 -2
  24. package/dist/roles.d.ts +5 -5
  25. package/dist/self-update.d.ts +2 -1
  26. package/dist/self-update.js +7 -1
  27. package/dist/sessions.d.ts +0 -1
  28. package/dist/usage.d.ts +1 -1
  29. package/dist/usage.js +6 -4
  30. package/package.json +6 -6
  31. package/src/cli.js +3 -2
  32. package/src/daemon.js +7 -6
  33. package/src/dashboard-migrate.js +152 -0
  34. package/src/{web-service.js → dashboard-service.js} +54 -48
  35. package/src/desktop.js +122 -0
  36. package/src/interfaces.js +170 -61
  37. package/src/paths.js +9 -3
  38. package/src/roles.js +4 -4
  39. package/src/self-update.js +10 -2
  40. package/src/sessions.js +0 -2
  41. package/src/usage.js +6 -4
  42. package/dist/web-service.d.ts +0 -56
  43. /package/dist/{alp-web → alp-dashboard}/alp-boundary.json +0 -0
  44. /package/dist/{alp-web → alp-dashboard}/apple-touch-icon.png +0 -0
  45. /package/dist/{alp-web → alp-dashboard}/assets/TerminalPanel-DLuoa74B.css +0 -0
  46. /package/dist/{alp-web → alp-dashboard}/assets/highlighter-BnicKQ_d.js +0 -0
  47. /package/dist/{alp-web → alp-dashboard}/assets/index-DwqDSiIi.css +0 -0
  48. /package/dist/{alp-web → alp-dashboard}/favicon-attention.svg +0 -0
  49. /package/dist/{alp-web → alp-dashboard}/favicon-running.svg +0 -0
  50. /package/dist/{alp-web → alp-dashboard}/favicon.svg +0 -0
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-BbYa_Xkd.js","assets/TerminalPanel-DLuoa74B.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TerminalPanel-BSjqIfNr.js","assets/TerminalPanel-DLuoa74B.css"])))=>i.map(i=>d[i]);
2
2
  function Lk(s,t){for(var i=0;i<t.length;i++){const a=t[i];if(typeof a!="string"&&!Array.isArray(a)){for(const l in a)if(l!=="default"&&!(l in s)){const u=Object.getOwnPropertyDescriptor(a,l);u&&Object.defineProperty(s,l,u.get?u:{enumerable:!0,get:()=>a[l]})}}}return Object.freeze(Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))a(l);new MutationObserver(l=>{for(const u of l)if(u.type==="childList")for(const d of u.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&a(d)}).observe(document,{childList:!0,subtree:!0});function i(l){const u={};return l.integrity&&(u.integrity=l.integrity),l.referrerPolicy&&(u.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?u.credentials="include":l.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function a(l){if(l.ep)return;l.ep=!0;const u=i(l);fetch(l.href,u)}})();function Ok(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var _d={exports:{}},Lr={};var gx;function Dk(){if(gx)return Lr;gx=1;var s=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function i(a,l,u){var d=null;if(u!==void 0&&(d=""+u),l.key!==void 0&&(d=""+l.key),"key"in l){u={};for(var h in l)h!=="key"&&(u[h]=l[h])}else u=l;return l=u.ref,{$$typeof:s,type:a,key:d,ref:l!==void 0?l:null,props:u}}return Lr.Fragment=t,Lr.jsx=i,Lr.jsxs=i,Lr}var xx;function qk(){return xx||(xx=1,_d.exports=Dk()),_d.exports}var o=qk(),Ld={exports:{}},Ie={};var yx;function Bk(){if(yx)return Ie;yx=1;var s=Symbol.for("react.transitional.element"),t=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),u=Symbol.for("react.consumer"),d=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),p=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),y=Symbol.iterator;function w(T){return T===null||typeof T!="object"?null:(T=y&&T[y]||T["@@iterator"],typeof T=="function"?T:null)}var k={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},j=Object.assign,S={};function A(T,z,F){this.props=T,this.context=z,this.refs=S,this.updater=F||k}A.prototype.isReactComponent={},A.prototype.setState=function(T,z){if(typeof T!="object"&&typeof T!="function"&&T!=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,T,z,"setState")},A.prototype.forceUpdate=function(T){this.updater.enqueueForceUpdate(this,T,"forceUpdate")};function R(){}R.prototype=A.prototype;function q(T,z,F){this.props=T,this.context=z,this.refs=S,this.updater=F||k}var O=q.prototype=new R;O.constructor=q,j(O,A.prototype),O.isPureReactComponent=!0;var L=Array.isArray,B={H:null,A:null,T:null,S:null,V:null},_=Object.prototype.hasOwnProperty;function Q(T,z,F,J,le,ne){return F=ne.ref,{$$typeof:s,type:T,key:z,ref:F!==void 0?F:null,props:ne}}function C(T,z){return Q(T.type,z,void 0,void 0,void 0,T.props)}function Y(T){return typeof T=="object"&&T!==null&&T.$$typeof===s}function H(T){var z={"=":"=0",":":"=2"};return"$"+T.replace(/[=:]/g,function(F){return z[F]})}var fe=/\/+/g;function ee(T,z){return typeof T=="object"&&T!==null&&T.key!=null?H(""+T.key):z.toString(36)}function xe(){}function re(T){switch(T.status){case"fulfilled":return T.value;case"rejected":throw T.reason;default:switch(typeof T.status=="string"?T.then(xe,xe):(T.status="pending",T.then(function(z){T.status==="pending"&&(T.status="fulfilled",T.value=z)},function(z){T.status==="pending"&&(T.status="rejected",T.reason=z)})),T.status){case"fulfilled":return T.value;case"rejected":throw T.reason}}throw T}function de(T,z,F,J,le){var ne=typeof T;(ne==="undefined"||ne==="boolean")&&(T=null);var ce=!1;if(T===null)ce=!0;else switch(ne){case"bigint":case"string":case"number":ce=!0;break;case"object":switch(T.$$typeof){case s:case t:ce=!0;break;case x:return ce=T._init,de(ce(T._payload),z,F,J,le)}}if(ce)return le=le(T),ce=J===""?"."+ee(T,0):J,L(le)?(F="",ce!=null&&(F=ce.replace(fe,"$&/")+"/"),de(le,z,F,"",function(Me){return Me})):le!=null&&(Y(le)&&(le=C(le,F+(le.key==null||T&&T.key===le.key?"":(""+le.key).replace(fe,"$&/")+"/")+ce)),z.push(le)),1;ce=0;var ve=J===""?".":J+":";if(L(T))for(var Re=0;Re<T.length;Re++)J=T[Re],ne=ve+ee(J,Re),ce+=de(J,z,F,ne,le);else if(Re=w(T),typeof Re=="function")for(T=Re.call(T),Re=0;!(J=T.next()).done;)J=J.value,ne=ve+ee(J,Re++),ce+=de(J,z,F,ne,le);else if(ne==="object"){if(typeof T.then=="function")return de(re(T),z,F,J,le);throw z=String(T),Error("Objects are not valid as a React child (found: "+(z==="[object Object]"?"object with keys {"+Object.keys(T).join(", ")+"}":z)+"). If you meant to render a collection of children, use an array instead.")}return ce}function U(T,z,F){if(T==null)return T;var J=[],le=0;return de(T,J,"","",function(ne){return z.call(F,ne,le++)}),J}function Z(T){if(T._status===-1){var z=T._result;z=z(),z.then(function(F){(T._status===0||T._status===-1)&&(T._status=1,T._result=F)},function(F){(T._status===0||T._status===-1)&&(T._status=2,T._result=F)}),T._status===-1&&(T._status=0,T._result=z)}if(T._status===1)return T._result.default;throw T._result}var oe=typeof reportError=="function"?reportError:function(T){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var z=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof T=="object"&&T!==null&&typeof T.message=="string"?String(T.message):String(T),error:T});if(!window.dispatchEvent(z))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",T);return}console.error(T)};function ge(){}return Ie.Children={map:U,forEach:function(T,z,F){U(T,function(){z.apply(this,arguments)},F)},count:function(T){var z=0;return U(T,function(){z++}),z},toArray:function(T){return U(T,function(z){return z})||[]},only:function(T){if(!Y(T))throw Error("React.Children.only expected to receive a single React element child.");return T}},Ie.Component=A,Ie.Fragment=i,Ie.Profiler=l,Ie.PureComponent=q,Ie.StrictMode=a,Ie.Suspense=m,Ie.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=B,Ie.__COMPILER_RUNTIME={__proto__:null,c:function(T){return B.H.useMemoCache(T)}},Ie.cache=function(T){return function(){return T.apply(null,arguments)}},Ie.cloneElement=function(T,z,F){if(T==null)throw Error("The argument must be a React element, but you passed "+T+".");var J=j({},T.props),le=T.key,ne=void 0;if(z!=null)for(ce in z.ref!==void 0&&(ne=void 0),z.key!==void 0&&(le=""+z.key),z)!_.call(z,ce)||ce==="key"||ce==="__self"||ce==="__source"||ce==="ref"&&z.ref===void 0||(J[ce]=z[ce]);var ce=arguments.length-2;if(ce===1)J.children=F;else if(1<ce){for(var ve=Array(ce),Re=0;Re<ce;Re++)ve[Re]=arguments[Re+2];J.children=ve}return Q(T.type,le,void 0,void 0,ne,J)},Ie.createContext=function(T){return T={$$typeof:d,_currentValue:T,_currentValue2:T,_threadCount:0,Provider:null,Consumer:null},T.Provider=T,T.Consumer={$$typeof:u,_context:T},T},Ie.createElement=function(T,z,F){var J,le={},ne=null;if(z!=null)for(J in z.key!==void 0&&(ne=""+z.key),z)_.call(z,J)&&J!=="key"&&J!=="__self"&&J!=="__source"&&(le[J]=z[J]);var ce=arguments.length-2;if(ce===1)le.children=F;else if(1<ce){for(var ve=Array(ce),Re=0;Re<ce;Re++)ve[Re]=arguments[Re+2];le.children=ve}if(T&&T.defaultProps)for(J in ce=T.defaultProps,ce)le[J]===void 0&&(le[J]=ce[J]);return Q(T,ne,void 0,void 0,null,le)},Ie.createRef=function(){return{current:null}},Ie.forwardRef=function(T){return{$$typeof:h,render:T}},Ie.isValidElement=Y,Ie.lazy=function(T){return{$$typeof:x,_payload:{_status:-1,_result:T},_init:Z}},Ie.memo=function(T,z){return{$$typeof:p,type:T,compare:z===void 0?null:z}},Ie.startTransition=function(T){var z=B.T,F={};B.T=F;try{var J=T(),le=B.S;le!==null&&le(F,J),typeof J=="object"&&J!==null&&typeof J.then=="function"&&J.then(ge,oe)}catch(ne){oe(ne)}finally{B.T=z}},Ie.unstable_useCacheRefresh=function(){return B.H.useCacheRefresh()},Ie.use=function(T){return B.H.use(T)},Ie.useActionState=function(T,z,F){return B.H.useActionState(T,z,F)},Ie.useCallback=function(T,z){return B.H.useCallback(T,z)},Ie.useContext=function(T){return B.H.useContext(T)},Ie.useDebugValue=function(){},Ie.useDeferredValue=function(T,z){return B.H.useDeferredValue(T,z)},Ie.useEffect=function(T,z,F){var J=B.H;if(typeof F=="function")throw Error("useEffect CRUD overload is not enabled in this build of React.");return J.useEffect(T,z)},Ie.useId=function(){return B.H.useId()},Ie.useImperativeHandle=function(T,z,F){return B.H.useImperativeHandle(T,z,F)},Ie.useInsertionEffect=function(T,z){return B.H.useInsertionEffect(T,z)},Ie.useLayoutEffect=function(T,z){return B.H.useLayoutEffect(T,z)},Ie.useMemo=function(T,z){return B.H.useMemo(T,z)},Ie.useOptimistic=function(T,z){return B.H.useOptimistic(T,z)},Ie.useReducer=function(T,z,F){return B.H.useReducer(T,z,F)},Ie.useRef=function(T){return B.H.useRef(T)},Ie.useState=function(T){return B.H.useState(T)},Ie.useSyncExternalStore=function(T,z,F){return B.H.useSyncExternalStore(T,z,F)},Ie.useTransition=function(){return B.H.useTransition()},Ie.version="19.1.0",Ie}var bx;function Vf(){return bx||(bx=1,Ld.exports=Bk()),Ld.exports}var b=Vf();const $k=Ok(b),Uk=Lk({__proto__:null,default:$k},[b]);var Od={exports:{}},Or={},Dd={exports:{}},qd={};var vx;function Hk(){return vx||(vx=1,(function(s){function t(U,Z){var oe=U.length;U.push(Z);e:for(;0<oe;){var ge=oe-1>>>1,T=U[ge];if(0<l(T,Z))U[ge]=Z,U[oe]=T,oe=ge;else break e}}function i(U){return U.length===0?null:U[0]}function a(U){if(U.length===0)return null;var Z=U[0],oe=U.pop();if(oe!==Z){U[0]=oe;e:for(var ge=0,T=U.length,z=T>>>1;ge<z;){var F=2*(ge+1)-1,J=U[F],le=F+1,ne=U[le];if(0>l(J,oe))le<T&&0>l(ne,J)?(U[ge]=ne,U[le]=oe,ge=le):(U[ge]=J,U[F]=oe,ge=F);else if(le<T&&0>l(ne,oe))U[ge]=ne,U[le]=oe,ge=le;else break e}}return Z}function l(U,Z){var oe=U.sortIndex-Z.sortIndex;return oe!==0?oe:U.id-Z.id}if(s.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var u=performance;s.unstable_now=function(){return u.now()}}else{var d=Date,h=d.now();s.unstable_now=function(){return d.now()-h}}var m=[],p=[],x=1,y=null,w=3,k=!1,j=!1,S=!1,A=!1,R=typeof setTimeout=="function"?setTimeout:null,q=typeof clearTimeout=="function"?clearTimeout:null,O=typeof setImmediate<"u"?setImmediate:null;function L(U){for(var Z=i(p);Z!==null;){if(Z.callback===null)a(p);else if(Z.startTime<=U)a(p),Z.sortIndex=Z.expirationTime,t(m,Z);else break;Z=i(p)}}function B(U){if(S=!1,L(U),!j)if(i(m)!==null)j=!0,_||(_=!0,ee());else{var Z=i(p);Z!==null&&de(B,Z.startTime-U)}}var _=!1,Q=-1,C=5,Y=-1;function H(){return A?!0:!(s.unstable_now()-Y<C)}function fe(){if(A=!1,_){var U=s.unstable_now();Y=U;var Z=!0;try{e:{j=!1,S&&(S=!1,q(Q),Q=-1),k=!0;var oe=w;try{t:{for(L(U),y=i(m);y!==null&&!(y.expirationTime>U&&H());){var ge=y.callback;if(typeof ge=="function"){y.callback=null,w=y.priorityLevel;var T=ge(y.expirationTime<=U);if(U=s.unstable_now(),typeof T=="function"){y.callback=T,L(U),Z=!0;break t}y===i(m)&&a(m),L(U)}else a(m);y=i(m)}if(y!==null)Z=!0;else{var z=i(p);z!==null&&de(B,z.startTime-U),Z=!1}}break e}finally{y=null,w=oe,k=!1}Z=void 0}}finally{Z?ee():_=!1}}}var ee;if(typeof O=="function")ee=function(){O(fe)};else if(typeof MessageChannel<"u"){var xe=new MessageChannel,re=xe.port2;xe.port1.onmessage=fe,ee=function(){re.postMessage(null)}}else ee=function(){R(fe,0)};function de(U,Z){Q=R(function(){U(s.unstable_now())},Z)}s.unstable_IdlePriority=5,s.unstable_ImmediatePriority=1,s.unstable_LowPriority=4,s.unstable_NormalPriority=3,s.unstable_Profiling=null,s.unstable_UserBlockingPriority=2,s.unstable_cancelCallback=function(U){U.callback=null},s.unstable_forceFrameRate=function(U){0>U||125<U?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):C=0<U?Math.floor(1e3/U):5},s.unstable_getCurrentPriorityLevel=function(){return w},s.unstable_next=function(U){switch(w){case 1:case 2:case 3:var Z=3;break;default:Z=w}var oe=w;w=Z;try{return U()}finally{w=oe}},s.unstable_requestPaint=function(){A=!0},s.unstable_runWithPriority=function(U,Z){switch(U){case 1:case 2:case 3:case 4:case 5:break;default:U=3}var oe=w;w=U;try{return Z()}finally{w=oe}},s.unstable_scheduleCallback=function(U,Z,oe){var ge=s.unstable_now();switch(typeof oe=="object"&&oe!==null?(oe=oe.delay,oe=typeof oe=="number"&&0<oe?ge+oe:ge):oe=ge,U){case 1:var T=-1;break;case 2:T=250;break;case 5:T=1073741823;break;case 4:T=1e4;break;default:T=5e3}return T=oe+T,U={id:x++,callback:Z,priorityLevel:U,startTime:oe,expirationTime:T,sortIndex:-1},oe>ge?(U.sortIndex=oe,t(p,U),i(m)===null&&U===i(p)&&(S?(q(Q),Q=-1):S=!0,de(B,oe-ge))):(U.sortIndex=T,t(m,U),j||k||(j=!0,_||(_=!0,ee()))),U},s.unstable_shouldYield=H,s.unstable_wrapCallback=function(U){var Z=w;return function(){var oe=w;w=Z;try{return U.apply(this,arguments)}finally{w=oe}}}})(qd)),qd}var wx;function Ik(){return wx||(wx=1,Dd.exports=Hk()),Dd.exports}var Bd={exports:{}},Pt={};var kx;function Gk(){if(kx)return Pt;kx=1;var s=Vf();function t(m){var p="https://react.dev/errors/"+m;if(1<arguments.length){p+="?args[]="+encodeURIComponent(arguments[1]);for(var x=2;x<arguments.length;x++)p+="&args[]="+encodeURIComponent(arguments[x])}return"Minified React error #"+m+"; visit "+p+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function i(){}var a={d:{f:i,r:function(){throw Error(t(522))},D:i,C:i,L:i,m:i,X:i,S:i,M:i},p:0,findDOMNode:null},l=Symbol.for("react.portal");function u(m,p,x){var y=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:l,key:y==null?null:""+y,children:m,containerInfo:p,implementation:x}}var d=s.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function h(m,p){if(m==="font")return"";if(typeof p=="string")return p==="use-credentials"?p:""}return Pt.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=a,Pt.createPortal=function(m,p){var x=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!p||p.nodeType!==1&&p.nodeType!==9&&p.nodeType!==11)throw Error(t(299));return u(m,p,null,x)},Pt.flushSync=function(m){var p=d.T,x=a.p;try{if(d.T=null,a.p=2,m)return m()}finally{d.T=p,a.p=x,a.d.f()}},Pt.preconnect=function(m,p){typeof m=="string"&&(p?(p=p.crossOrigin,p=typeof p=="string"?p==="use-credentials"?p:"":void 0):p=null,a.d.C(m,p))},Pt.prefetchDNS=function(m){typeof m=="string"&&a.d.D(m)},Pt.preinit=function(m,p){if(typeof m=="string"&&p&&typeof p.as=="string"){var x=p.as,y=h(x,p.crossOrigin),w=typeof p.integrity=="string"?p.integrity:void 0,k=typeof p.fetchPriority=="string"?p.fetchPriority:void 0;x==="style"?a.d.S(m,typeof p.precedence=="string"?p.precedence:void 0,{crossOrigin:y,integrity:w,fetchPriority:k}):x==="script"&&a.d.X(m,{crossOrigin:y,integrity:w,fetchPriority:k,nonce:typeof p.nonce=="string"?p.nonce:void 0})}},Pt.preinitModule=function(m,p){if(typeof m=="string")if(typeof p=="object"&&p!==null){if(p.as==null||p.as==="script"){var x=h(p.as,p.crossOrigin);a.d.M(m,{crossOrigin:x,integrity:typeof p.integrity=="string"?p.integrity:void 0,nonce:typeof p.nonce=="string"?p.nonce:void 0})}}else p==null&&a.d.M(m)},Pt.preload=function(m,p){if(typeof m=="string"&&typeof p=="object"&&p!==null&&typeof p.as=="string"){var x=p.as,y=h(x,p.crossOrigin);a.d.L(m,x,{crossOrigin:y,integrity:typeof p.integrity=="string"?p.integrity:void 0,nonce:typeof p.nonce=="string"?p.nonce:void 0,type:typeof p.type=="string"?p.type:void 0,fetchPriority:typeof p.fetchPriority=="string"?p.fetchPriority:void 0,referrerPolicy:typeof p.referrerPolicy=="string"?p.referrerPolicy:void 0,imageSrcSet:typeof p.imageSrcSet=="string"?p.imageSrcSet:void 0,imageSizes:typeof p.imageSizes=="string"?p.imageSizes:void 0,media:typeof p.media=="string"?p.media:void 0})}},Pt.preloadModule=function(m,p){if(typeof m=="string")if(p){var x=h(p.as,p.crossOrigin);a.d.m(m,{as:typeof p.as=="string"&&p.as!=="script"?p.as:void 0,crossOrigin:x,integrity:typeof p.integrity=="string"?p.integrity:void 0})}else a.d.m(m)},Pt.requestFormReset=function(m){a.d.r(m)},Pt.unstable_batchedUpdates=function(m,p){return m(p)},Pt.useFormState=function(m,p,x){return d.H.useFormState(m,p,x)},Pt.useFormStatus=function(){return d.H.useHostTransitionStatus()},Pt.version="19.1.0",Pt}var jx;function Yk(){if(jx)return Bd.exports;jx=1;function s(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(s)}catch(t){console.error(t)}}return s(),Bd.exports=Gk(),Bd.exports}var Sx;function Vk(){if(Sx)return Or;Sx=1;var s=Ik(),t=Vf(),i=Yk();function a(e){var n="https://react.dev/errors/"+e;if(1<arguments.length){n+="?args[]="+encodeURIComponent(arguments[1]);for(var r=2;r<arguments.length;r++)n+="&args[]="+encodeURIComponent(arguments[r])}return"Minified React error #"+e+"; visit "+n+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function l(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function u(e){var n=e,r=e;if(e.alternate)for(;n.return;)n=n.return;else{e=n;do n=e,(n.flags&4098)!==0&&(r=n.return),e=n.return;while(e)}return n.tag===3?r:null}function d(e){if(e.tag===13){var n=e.memoizedState;if(n===null&&(e=e.alternate,e!==null&&(n=e.memoizedState)),n!==null)return n.dehydrated}return null}function h(e){if(u(e)!==e)throw Error(a(188))}function m(e){var n=e.alternate;if(!n){if(n=u(e),n===null)throw Error(a(188));return n!==e?null:e}for(var r=e,c=n;;){var f=r.return;if(f===null)break;var g=f.alternate;if(g===null){if(c=f.return,c!==null){r=c;continue}break}if(f.child===g.child){for(g=f.child;g;){if(g===r)return h(f),e;if(g===c)return h(f),n;g=g.sibling}throw Error(a(188))}if(r.return!==c.return)r=f,c=g;else{for(var v=!1,N=f.child;N;){if(N===r){v=!0,r=f,c=g;break}if(N===c){v=!0,c=f,r=g;break}N=N.sibling}if(!v){for(N=g.child;N;){if(N===r){v=!0,r=g,c=f;break}if(N===c){v=!0,c=g,r=f;break}N=N.sibling}if(!v)throw Error(a(189))}}if(r.alternate!==c)throw Error(a(190))}if(r.tag!==3)throw Error(a(188));return r.stateNode.current===r?e:n}function p(e){var n=e.tag;if(n===5||n===26||n===27||n===6)return e;for(e=e.child;e!==null;){if(n=p(e),n!==null)return n;e=e.sibling}return null}var x=Object.assign,y=Symbol.for("react.element"),w=Symbol.for("react.transitional.element"),k=Symbol.for("react.portal"),j=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),A=Symbol.for("react.profiler"),R=Symbol.for("react.provider"),q=Symbol.for("react.consumer"),O=Symbol.for("react.context"),L=Symbol.for("react.forward_ref"),B=Symbol.for("react.suspense"),_=Symbol.for("react.suspense_list"),Q=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),Y=Symbol.for("react.activity"),H=Symbol.for("react.memo_cache_sentinel"),fe=Symbol.iterator;function ee(e){return e===null||typeof e!="object"?null:(e=fe&&e[fe]||e["@@iterator"],typeof e=="function"?e:null)}var xe=Symbol.for("react.client.reference");function re(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===xe?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case j:return"Fragment";case A:return"Profiler";case S:return"StrictMode";case B:return"Suspense";case _:return"SuspenseList";case Y:return"Activity"}if(typeof e=="object")switch(e.$$typeof){case k:return"Portal";case O:return(e.displayName||"Context")+".Provider";case q:return(e._context.displayName||"Context")+".Consumer";case L:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Q:return n=e.displayName||null,n!==null?n:re(e.type)||"Memo";case C:n=e._payload,e=e._init;try{return re(e(n))}catch{}}return null}var de=Array.isArray,U=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Z=i.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,oe={pending:!1,data:null,method:null,action:null},ge=[],T=-1;function z(e){return{current:e}}function F(e){0>T||(e.current=ge[T],ge[T]=null,T--)}function J(e,n){T++,ge[T]=e.current,e.current=n}var le=z(null),ne=z(null),ce=z(null),ve=z(null);function Re(e,n){switch(J(ce,n),J(ne,e),J(le,null),n.nodeType){case 9:case 11:e=(e=n.documentElement)&&(e=e.namespaceURI)?Yg(e):0;break;default:if(e=n.tagName,n=n.namespaceURI)n=Yg(n),e=Vg(n,e);else switch(e){case"svg":e=1;break;case"math":e=2;break;default:e=0}}F(le),J(le,e)}function Me(){F(le),F(ne),F(ce)}function Qe(e){e.memoizedState!==null&&J(ve,e);var n=le.current,r=Vg(n,e.type);n!==r&&(J(ne,e),J(le,r))}function Ue(e){ne.current===e&&(F(le),F(ne)),ve.current===e&&(F(ve),Er._currentValue=oe)}var et=Object.prototype.hasOwnProperty,Fe=s.unstable_scheduleCallback,be=s.unstable_cancelCallback,ye=s.unstable_shouldYield,Ae=s.unstable_requestPaint,Ne=s.unstable_now,Ht=s.unstable_getCurrentPriorityLevel,cn=s.unstable_ImmediatePriority,ze=s.unstable_UserBlockingPriority,ut=s.unstable_NormalPriority,At=s.unstable_LowPriority,Rt=s.unstable_IdlePriority,In=s.log,kn=s.unstable_setDisableYieldValue,Qt=null,Je=null;function jt(e){if(typeof In=="function"&&kn(e),Je&&typeof Je.setStrictMode=="function")try{Je.setStrictMode(Qt,e)}catch{}}var St=Math.clz32?Math.clz32:js,un=Math.log,Gn=Math.LN2;function js(e){return e>>>=0,e===0?32:31-(un(e)/Gn|0)|0}var dn=256,fn=4194304;function Ct(e){var n=e&42;if(n!==0)return n;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194048;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function jn(e,n,r){var c=e.pendingLanes;if(c===0)return 0;var f=0,g=e.suspendedLanes,v=e.pingedLanes;e=e.warmLanes;var N=c&134217727;return N!==0?(c=N&~g,c!==0?f=Ct(c):(v&=N,v!==0?f=Ct(v):r||(r=N&~e,r!==0&&(f=Ct(r))))):(N=c&~g,N!==0?f=Ct(N):v!==0?f=Ct(v):r||(r=c&~e,r!==0&&(f=Ct(r)))),f===0?0:n!==0&&n!==f&&(n&g)===0&&(g=f&-f,r=n&-n,g>=r||g===32&&(r&4194048)!==0)?n:f}function E(e,n){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&n)===0}function V(e,n){switch(e){case 1:case 2:case 4:case 8:case 64:return n+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function ue(){var e=dn;return dn<<=1,(dn&4194048)===0&&(dn=256),e}function he(){var e=fn;return fn<<=1,(fn&62914560)===0&&(fn=4194304),e}function pe(e){for(var n=[],r=0;31>r;r++)n.push(e);return n}function $e(e,n){e.pendingLanes|=n,n!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function We(e,n,r,c,f,g){var v=e.pendingLanes;e.pendingLanes=r,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=r,e.entangledLanes&=r,e.errorRecoveryDisabledLanes&=r,e.shellSuspendCounter=0;var N=e.entanglements,M=e.expirationTimes,K=e.hiddenUpdates;for(r=v&~r;0<r;){var te=31-St(r),ae=1<<te;N[te]=0,M[te]=-1;var X=K[te];if(X!==null)for(K[te]=null,te=0;te<X.length;te++){var P=X[te];P!==null&&(P.lane&=-536870913)}r&=~ae}c!==0&&ft(e,c,0),g!==0&&f===0&&e.tag!==0&&(e.suspendedLanes|=g&~(v&~n))}function ft(e,n,r){e.pendingLanes|=n,e.suspendedLanes&=~n;var c=31-St(n);e.entangledLanes|=n,e.entanglements[c]=e.entanglements[c]|1073741824|r&4194090}function W(e,n){var r=e.entangledLanes|=n;for(e=e.entanglements;r;){var c=31-St(r),f=1<<c;f&n|e[c]&n&&(e[c]|=n),r&=~f}}function me(e){switch(e){case 2:e=1;break;case 8:e=4;break;case 32:e=16;break;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:e=128;break;case 268435456:e=134217728;break;default:e=0}return e}function ht(e){return e&=-e,2<e?8<e?(e&134217727)!==0?32:268435456:8:2}function Wt(){var e=Z.p;return e!==0?e:(e=window.event,e===void 0?32:ux(e.type))}function mt(e,n){var r=Z.p;try{return Z.p=e,n()}finally{Z.p=r}}var bt=Math.random().toString(36).slice(2),gt="__reactFiber$"+bt,Et="__reactProps$"+bt,Sn="__reactContainer$"+bt,Nc="__reactEvents$"+bt,Sv="__reactListeners$"+bt,Nv="__reactHandles$"+bt,Rh="__reactResources$"+bt,Ua="__reactMarker$"+bt;function Tc(e){delete e[gt],delete e[Et],delete e[Nc],delete e[Sv],delete e[Nv]}function Ii(e){var n=e[gt];if(n)return n;for(var r=e.parentNode;r;){if(n=r[Sn]||r[gt]){if(r=n.alternate,n.child!==null||r!==null&&r.child!==null)for(e=Pg(e);e!==null;){if(r=e[gt])return r;e=Pg(e)}return n}e=r,r=e.parentNode}return null}function Gi(e){if(e=e[gt]||e[Sn]){var n=e.tag;if(n===5||n===6||n===13||n===26||n===27||n===3)return e}return null}function Ha(e){var n=e.tag;if(n===5||n===26||n===27||n===6)return e.stateNode;throw Error(a(33))}function Yi(e){var n=e[Rh];return n||(n=e[Rh]={hoistableStyles:new Map,hoistableScripts:new Map}),n}function qt(e){e[Ua]=!0}var _h=new Set,Lh={};function ri(e,n){Vi(e,n),Vi(e+"Capture",n)}function Vi(e,n){for(Lh[e]=n,e=0;e<n.length;e++)_h.add(n[e])}var Tv=RegExp("^[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$"),Oh={},Dh={};function Av(e){return et.call(Dh,e)?!0:et.call(Oh,e)?!1:Tv.test(e)?Dh[e]=!0:(Oh[e]=!0,!1)}function mo(e,n,r){if(Av(n))if(r===null)e.removeAttribute(n);else{switch(typeof r){case"undefined":case"function":case"symbol":e.removeAttribute(n);return;case"boolean":var c=n.toLowerCase().slice(0,5);if(c!=="data-"&&c!=="aria-"){e.removeAttribute(n);return}}e.setAttribute(n,""+r)}}function po(e,n,r){if(r===null)e.removeAttribute(n);else{switch(typeof r){case"undefined":case"function":case"symbol":case"boolean":e.removeAttribute(n);return}e.setAttribute(n,""+r)}}function es(e,n,r,c){if(c===null)e.removeAttribute(r);else{switch(typeof c){case"undefined":case"function":case"symbol":case"boolean":e.removeAttribute(r);return}e.setAttributeNS(n,r,""+c)}}var Ac,qh;function Ki(e){if(Ac===void 0)try{throw Error()}catch(r){var n=r.stack.trim().match(/\n( *(at )?)/);Ac=n&&n[1]||"",qh=-1<r.stack.indexOf(`
3
3
  at`)?" (<anonymous>)":-1<r.stack.indexOf("@")?"@unknown:0:0":""}return`
4
4
  `+Ac+e+qh}var Cc=!1;function Ec(e,n){if(!e||Cc)return"";Cc=!0;var r=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var c={DetermineComponentFrameRoot:function(){try{if(n){var ae=function(){throw Error()};if(Object.defineProperty(ae.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ae,[])}catch(P){var X=P}Reflect.construct(e,[],ae)}else{try{ae.call()}catch(P){X=P}e.call(ae.prototype)}}else{try{throw Error()}catch(P){X=P}(ae=e())&&typeof ae.catch=="function"&&ae.catch(function(){})}}catch(P){if(P&&X&&typeof P.stack=="string")return[P.stack,X.stack]}return[null,null]}};c.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var f=Object.getOwnPropertyDescriptor(c.DetermineComponentFrameRoot,"name");f&&f.configurable&&Object.defineProperty(c.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var g=c.DetermineComponentFrameRoot(),v=g[0],N=g[1];if(v&&N){var M=v.split(`
@@ -11,11 +11,11 @@ Error generating stack: `+r.message+`
11
11
  `).length;return s.endsWith(`
12
12
  `)?t-1:t}const S2=s=>/\.(md|markdown|mdx)$/i.test(s),N2=0,Vr=1,Mx=Object.freeze({unsupportedData:4003,tooLarge:4009}),T2=250,A2=123;function xf(s){const t=/^([a-z][a-z0-9+.-]*:\/\/)(?:[^/?#\\]*@)?([^/?#\\@]*)([^?#]*)/i.exec(String(s));return t?`${t[1]}${t[2]}${t[3]}`:"<websocket>"}function zx(s,t){const a=((s instanceof Error?s.message:String(s??"")).split(String(t)).join(xf(t))||"WebSocket error").replace(/[a-z][a-z0-9+.-]*:\/\/[^\s'"<>]+/gi,u=>xf(u)),l=new Error(a);return s instanceof Error&&s.name&&(l.name=s.name),l}function C2(s){let t=s;for(;no(t)>A2;)t=t.slice(0,-1);return t}function _l(s,t,i){if(!(s.readyState!==N2&&s.readyState!==Vr)){try{t===void 0?s.close():s.close(t,C2(i??""));return}catch{}try{s.close()}catch{}}}function kb(s){typeof s.addEventListener=="function"&&s.addEventListener("error",()=>{})}function _a(s,t,i){if(typeof s.addEventListener=="function")return s.addEventListener(t,i),()=>s.removeEventListener?.(t,i);const a=`on${t}`,l=s[a];return s[a]=u=>{l?.(u),i(u)},()=>{s[a]=l??null}}const jb=s=>{const t=s?.error instanceof Error&&s.error.message||typeof s?.message=="string"&&s.message||"WebSocket error";return s?.error instanceof Error&&s.error.message?s.error:new Error(t)};function E2(s,{maxFrame:t=mf,maxBufferedBytes:i=4*mf}={}){if(s.readyState!==Vr)throw new st("WebSocket is not open",{reason:"disconnected"});kb(s);try{s.binaryType="arraybuffer"}catch{}const a=new Set,l=new Set;let u;const d=[];let h,m;const p=y=>{if(u)return;u=y,m!==void 0&&clearTimeout(m);for(const k of d.splice(0))k();a.clear();const w=[...l];l.clear();for(const k of w)k(y)},x=(y,w)=>{const k=new st(y,{reason:"protocol"});_l(s,w,y),p({error:k})};return d.push(_a(s,"message",y=>{if(u)return;const w=y?.data;if(typeof w!="string")return x("Binary WebSocket messages are not ALP frames",Mx.unsupportedData);if(no(w)>t)return x(`ALP frame exceeds ${t} bytes`,Mx.tooLarge);for(const k of w.includes(`
13
13
  `)?w.split(`
14
- `):[w]){if(u)return;if(k.trim())for(const j of[...a])j(k)}})),d.push(_a(s,"close",y=>p({error:h,code:typeof y?.code=="number"?y.code:void 0,reason:typeof y?.reason=="string"&&y.reason?y.reason:void 0}))),d.push(_a(s,"error",y=>{h||(h=jb(y),m=setTimeout(()=>p({error:h}),T2),_l(s))})),{get state(){return u||s.readyState!==Vr?"closed":"open"},send(y){if(u||s.readyState!==Vr)throw new st("WebSocket is not open",{reason:"send_failed"});if((s.bufferedAmount??0)+no(y)>i)throw new st(`WebSocket send buffer is over ${i} bytes`,{reason:"send_failed"});s.send(y)},onMessage(y){return u?()=>!1:(a.add(y),()=>a.delete(y))},onClose(y){return u?()=>!1:(l.add(y),()=>l.delete(y))},close(){_l(s,1e3,"client closed"),p({code:1e3,reason:"client closed"})}}}function M2(s,{WebSocket:t,protocols:i,createSocket:a,signal:l,timeoutMs:u=15e3,...d}={}){const h=xf(s);let m;try{m=pf(u)}catch(y){return Promise.reject(y)}if(l?.aborted)return Promise.reject(new st(`Connecting to ${h} was aborted`,{reason:"aborted",cause:l.reason}));const p=t??globalThis.WebSocket;if(!a&&typeof p!="function")return Promise.reject(new TypeError("No WebSocket implementation: pass options.WebSocket or options.createSocket"));let x;try{x=a?a(s,i):i===void 0?new p(s):new p(s,i)}catch(y){return Promise.reject(new st(`Could not connect to ${h}`,{reason:"disconnected",cause:zx(y,s)}))}return kb(x),new Promise((y,w)=>{const k=[];let j;const S=()=>{for(const O of k.splice(0))O();j!==void 0&&clearTimeout(j),l?.removeEventListener("abort",R)},A=O=>{S(),_l(x),w(O)},R=()=>A(new st(`Connecting to ${h} was aborted`,{reason:"aborted",cause:l?.reason})),q=()=>{S();try{y(E2(x,d))}catch(O){w(O)}};if(x.readyState===Vr)return q();k.push(_a(x,"open",q)),k.push(_a(x,"error",O=>A(new st(`Could not connect to ${h}`,{reason:"disconnected",cause:zx(jb(O),s)})))),k.push(_a(x,"close",O=>A(new st(`Could not connect to ${h}`,{reason:"disconnected",data:{code:O?.code,reason:O?.reason||void 0}})))),l?.addEventListener("abort",R,{once:!0}),m!==void 0&&(j=setTimeout(()=>A(new st(`Connecting to ${h} timed out after ${u} ms`,{reason:"timeout"})),m))})}const z2=new Set(["localhost","127.0.0.1"]);function Sb(s){let t;try{t=new URL(String(s).trim())}catch{throw new Ke("Enter the gateway address, such as https://alp.example.com or http://127.0.0.1:7434.")}if(t.username||t.password||t.search||t.hash)throw new Ke("Use a gateway address without a user name, password, query or fragment.");if(t.protocol!=="https:"&&!(t.protocol==="http:"&&z2.has(t.hostname)))throw new Ke("Use https, or http only on this machine (127.0.0.1 or localhost, for example through an SSH tunnel).");return`${t.origin}${t.pathname.replace(/\/+$/,"")}`}const Nl=s=>Array.isArray(s)&&s.every(t=>typeof t=="string");function R2(s){if(!s||typeof s!="object")return;const{websocket:t,subprotocols:i,principal:a}=s;if(t!=="/v1/ws"||!Nl(i)||!i.includes("alp.v1")||!a||typeof a.id!="string"||!Nl(a.permissions)||!Nl(a.workspaces)||a.modes!==void 0&&!Nl(a.modes))return;const l={id:a.id,...typeof a.label=="string"?{label:a.label}:{},permissions:[...a.permissions],workspaces:[...a.workspaces],...Array.isArray(a.workspaceRoots)?{workspaceRoots:a.workspaceRoots.filter(u=>u&&typeof u.path=="string"&&typeof u.canonical=="string").map(u=>({path:u.path,canonical:u.canonical}))}:{},...a.modes?{modes:[...a.modes]}:{}};return{websocket:t,subprotocols:i,principal:l}}async function _2(s){try{const t=await s.json();return typeof t?.error=="string"?t.error:void 0}catch{return}}function L2(s,t){const i=new AbortController,a=setTimeout(()=>i.abort(new Ai("The gateway did not answer in time.")),t),l=()=>i.abort(s?.reason);return s?.aborted?l():s?.addEventListener("abort",l,{once:!0}),{signal:i.signal,done(){clearTimeout(a),s?.removeEventListener("abort",l)}}}async function O2({url:s,token:t,signal:i,timeoutMs:a=15e3,fetch:l=globalThis.fetch.bind(globalThis),WebSocket:u}){const d=Sb(s);if(!t||/\s/.test(t))throw new Ra("Enter the access token printed by alp-gateway credential create.");const h=L2(i,a);let m;try{m=await l(`${d}/v1/tickets`,{method:"POST",credentials:"omit",cache:"no-store",redirect:"error",referrerPolicy:"no-referrer",headers:{authorization:`Bearer ${t}`},signal:h.signal})}catch(p){throw h.done(),i?.aborted?i.reason??p:h.signal.reason instanceof Ai?h.signal.reason:new Ai("Cannot reach the gateway. Check that it is running at this address and that it allows this page's origin (alp-gateway serve --origin).")}try{if(m.status===401)throw new Ra;if(m.status===403){const w=await _2(m);throw new Ke(w==="tls_required"?"The gateway only accepts this connection over HTTPS.":"The gateway does not allow this page's origin. Start it with --origin set to this page's address.")}if(m.status===421)throw new Ke("The gateway does not know this host name. Add it with alp-gateway serve --public-host.");if(m.status===429)throw new Ai("The gateway is limiting requests from this address. Wait a moment.");if(m.status!==201)throw new Ai(`The gateway is not ready (HTTP ${m.status}).`);const p=R2(await m.json().catch(()=>{}));if(!p)throw new Ke("The gateway answered with an unexpected ticket. Check that the address points to an ALP gateway.");const x=`${d.replace(/^http/,"ws")}${p.websocket}`;return{transport:await M2(x,{protocols:p.subprotocols,signal:h.signal,timeoutMs:a,...u?{WebSocket:u}:{}}).catch(w=>{throw i?.aborted?i.reason??w:new Ai("The gateway accepted the token but the live connection failed. Retrying may help.")}),principal:p.principal}}finally{h.done()}}function Ll(s,t){return!s||!t?void 0:(s.workspaceRoots?.length?s.workspaceRoots:s.workspaces.map(a=>({path:a,canonical:a}))).find(a=>a.path===t||a.canonical===t)}function Te(s,t){return s?s.permissions.includes(t)?!0:t.endsWith(".read")&&s.permissions.includes(t.replace(/\.read$/,".write")):!1}const Pf="alp-web:link-token",D2=/^alpgw1\.[a-f0-9]{16}\.[A-Za-z0-9_-]{43}$/,q2="This link's access token is no longer valid. Run `alp web` again to open ALP with a new link.",B2="This page is not on this machine's loopback address, so it did not use the access token in its link. Open the address `alp web` printed.",$2="The access token in this link is incomplete or damaged. Run `alp web` again, or copy its whole address.",U2=new Set(["127.0.0.1","localhost"]),Nb=s=>typeof s=="string"&&D2.test(s);function H2(s){const t=String(s??"").replace(/^#/,"");if(!t)return;const i=new URLSearchParams(t);if(!i.has("token"))return;const a=i.get("token");return Nb(a)?{token:a}:{malformed:!0}}const Tb=s=>s.protocol==="http:"&&U2.has(s.hostname);function I2(s){let t;try{t=s?.getItem(Pf)}catch{return}if(t!=null){if(Nb(t))return t;Kr(s)}}function Kr(s){try{s?.removeItem(Pf)}catch{}}function Ab({location:s,history:t,storage:i}){const a=H2(s.hash);a&&t.replaceState(t.state,"",`${s.pathname}${s.search}`);const l=Tb(s);if(a&&("malformed"in a||!l))return Kr(i),{error:"malformed"in a?$2:B2};if(a){try{i?.setItem(Pf,a.token)}catch{}return{url:s.origin,token:a.token}}if(!l)return;const u=I2(i);return u?{url:s.origin,token:u}:void 0}const G2="http://127.0.0.1:7434",Cb=({location:s,dev:t=!1})=>!t&&Tb(s);function Y2({location:s,remembered:t,dev:i=!1}){return t||(Cb({location:s,dev:i})?s.origin:G2)}function sc(s=16){const t=new Uint8Array(Math.ceil(s/2));return globalThis.crypto.getRandomValues(t),Array.from(t,i=>i.toString(16).padStart(2,"0")).join("").slice(0,s)}const V2=()=>`web_${sc(16)}`,Tl=()=>`web-msg-${sc(20)}`,K2=()=>`web-task-${sc(16)}`,Qf=()=>`web-conv-${sc(16)}`,F2="Files in the workspace are not changed or restored: only the conversation goes back.",X2="Files are not copied: the fork works on the current files of where it runs.",yf={runtime_unsupported:"This session runs on a runtime that cannot fork or rewind its conversation.",not_persistent:"This session keeps no native conversation to fork or rewind.",not_root:"Only a main conversation can be forked or rewound; an agent's work belongs to its requester."},Al=Object.freeze({session_busy:"The session or one of its agents is still working. Wait until everything is idle, then try again.",stale_generation:"The conversation changed since this view loaded. It was reloaded; check it and try again.",turn_not_found:"That message is no longer part of this conversation. It was reloaded; try again.",turn_in_progress:"A turn is still running. Wait until it ends, then try again.",empty_prefix:"Nothing comes before the first message. Start a new session instead.",boundary_unmapped:"The agent's runtime cannot go back to exactly this point (that turn was not started by ALP). Choose another message.",runtime_unsupported:yf.runtime_unsupported,native_refused:"The agent's runtime refused it. Nothing changed.",outcome_unknown:"The host cannot tell whether it happened. Check the session list and this conversation before trying again; a new attempt is a new request.",key_conflict:"That request id was already used for something else. Try again.",branch_not_found:"That branch is no longer kept on the host.",not_root:yf.not_root,outside_workspace:"That workspace is not granted to your access token.",attachment_forbidden:"This conversation holds an attachment your access token may not use.",request_conflict:"A session with that id already exists.",persistence_failed:"The host could not finish saving it. Trying again finishes it.",invalid_params:"The host did not accept this request for this session. Reload the page and try again; if it keeps happening, this app and the host may run different versions of ALP."}),P2=s=>typeof s?.data?.reason=="string"?s.data.reason:void 0;function ei(s){const t=s,i=P2(t),a=typeof t?.code=="number"?t.code:void 0,l=Be(s),u=l.sent!=="yes"&&i!=="outcome_unknown",d=i==="stale_generation"||i==="turn_not_found";if(i==="persistence_failed")return{message:Al.persistence_failed,reason:i,code:a,retrySame:!0,reload:!1};if(a===1003&&i==="grant")return{message:`Your access token cannot do this (it needs ${typeof t?.data?.permission=="string"?t.data.permission:"session.write"}).`,reason:i,code:a,retrySame:!1,reload:!1};if(a===1003&&i==="mode"){const h=Array.isArray(t?.data?.modes)?t.data.modes.filter(m=>typeof m=="string"):[];return{message:`Your access token cannot drive this conversation in its mode${h.length?` (it may use ${h.join(", ")})`:""}. Ask the host owner for a token with that mode.`,reason:i,code:a,retrySame:!1,reload:!1}}if(i&&Al[i])return{message:Al[i],reason:i,code:a,retrySame:!1,reload:d};if(u){const h=l.sent==="no"?" Trying again is safe.":" It may have happened: trying again sends the same request, which the host answers only once.";return{message:`${l.message}${l.terminal?"":h}`,...i?{reason:i}:{},code:a,retrySame:!l.terminal,reload:!1}}return a===-32601?{message:"This host does not offer it. Update ALP on the host.",code:a,retrySame:!1,reload:!1}:a===-32602?{message:Al.invalid_params,...i?{reason:i}:{},code:a,retrySame:!1,reload:!1}:{message:s instanceof Error&&s.message?s.message:"Something went wrong.",...i?{reason:i}:{},code:a,retrySame:!1,reload:d}}function Q2({capabilities:s,canRead:t,canWrite:i,summary:a,busy:l=!1,generation:u,online:d=!0,driveBlock:h}){const m=a?.conversation,p=(k=void 0)=>({shown:!1,...k?{reason:k}:{}}),x=m?.reason?yf[m.reason]??`Not available here (${m.reason}).`:void 0,y=s.includes("session.history")&&!!u,w=k=>s.includes(`session.${k}`)?!m||m[k]!==!0?p(x):!i||k==="fork"&&!t?p("Your access token cannot change this conversation (it needs session.write)."):h?p(h):y?d?k==="rewind"&&l?{shown:!0,reason:"Wait until main and its agents are idle."}:{shown:!0}:{shown:!0,reason:"Reconnecting…"}:p("This host does not keep a history generation for this view."):p();return{fork:w("fork"),rewind:w("rewind")}}const W2="Restart the agent's process on the same conversation and settings, for example after a new sign-in. Its messages, history and files stay.",Fr=Object.freeze({session_busy:"The agent or one of its agents is still working. Wait until everything is idle, then reload.",session_closed:"The session is closed. Send it a message to open it again on its conversation.",no_history:"The agent has no conversation to keep yet. Send it a message first, or start a new session.",native_refused:"The agent could not be restarted on its conversation. The session was closed with its conversation kept; send it a message to open it again.",runtime_unsupported:"This session runs on a runtime the host cannot reload.",not_root:"Only the main agent of a session can be reloaded."});function Z2(s){const t=ei(s),i=t.reason?Fr[t.reason]:void 0;return i?{...t,message:i}:t}const J2="Main writes a checkpoint of its work, then its context is compacted (or a fresh conversation starts from the checkpoint). Its session, history and files stay; while it is busy, this waits for the end of its turn.",Wf=Object.freeze({session_busy:"The session is not open. Send it a message to open it, then compact it.",session_closed:"The session is closed. Send it a message to open it, then compact it.",runtime_unsupported:"Only the main agent of a session can be compacted.",not_root:"Only the main agent of a session can be compacted."});function ej(s){return s==="deferred"?"Compaction will start when the main agent finishes its current turn.":s==="running"?"The main agent is already compacting its context.":"Compacting the main agent's context: it writes a checkpoint first."}function tj(s){const t=ei(s),i=t.reason?Wf[t.reason]:void 0;return i?{...t,message:i}:t}function nj({capabilities:s,canRead:t,canWrite:i,summary:a,root:l,closed:u=!1,busy:d=!1,generation:h,online:m=!0,driveBlock:p}){const x=j=>({shown:!0,enabled:!1,reason:j}),y=s.includes("session.resumeCommand")?t?m?{shown:!0,enabled:!0}:x("Reconnecting…"):x("Your access token cannot read this session."):{shown:!1,enabled:!1},w=()=>{if(!s.includes("session.reload"))return{shown:!1,enabled:!1};if(!l)return x(Fr.not_root);const j=a?.conversation;return j?.reload!==!0?x(j?.reason==="not_persistent"?"This session keeps no native conversation to reload.":Fr.runtime_unsupported):i?p?x(p):u?x(Fr.session_closed):!s.includes("session.history")||!h?x("The conversation is still loading."):m?d?x("Wait until main and its agents are idle."):{shown:!0,enabled:!0}:x("Reconnecting…"):x("Your access token cannot reload agents (it needs session.write).")},k=()=>l?i?p?x(p):u?x(Wf.session_closed):m?{shown:!0,enabled:!0}:x("Reconnecting…"):x("Your access token cannot compact agents (it needs session.write)."):{shown:!1,enabled:!1};return{reload:w(),compact:k(),resume:y}}function sj(s,t={}){const i=new Map,a=s.turnOrder??[];for(const l of s.entries){if(l.sessionId!==s.rootId)continue;const u=l.item;if(u.kind!=="user_message"||typeof u.clientMessageId!="string")continue;const d=s.prompts[u.clientMessageId];if(!d||d.state!=="accepted"||d.result!=="turn"||!d.turnId)continue;const h=a.indexOf(d.turnId);h<0||i.set(l.key,{turnId:d.turnId,index:h,later:a.length-h,rewindable:h>0||!!t.hasOlder,ended:s.turns[d.turnId]==="ended",text:typeof u.text=="string"?u.text:""})}return i}function Zf(s){return s?.kind!=="notice"||typeof s.id!="string"?null:s.id.startsWith("rewind:")&&s.id.length>7?{kind:"rewind",branchId:s.id.slice(7)}:s.id.startsWith("fork:")&&s.id.length>5?{kind:"fork",sessionId:s.id.slice(5)}:null}const ij=s=>`${s} later turn${s===1?"":"s"}`,aj=s=>`${s} turn${s===1?"":"s"}`;function rj(s,t,i){const a=t?.find(u=>u.branchId===i)?.turns;if(typeof a=="number")return a;const l=/(\d+) later turn/.exec(String(s?.text??""));return l?Number(l[1]):void 0}const Il=Object.freeze({capability:"This host does not offer Git changes. Update ALP on the host.",registry:"This host does not list its workspaces, so Git changes cannot be shown. Update ALP on the host.",projectRead:"This access token cannot read Git status (needs project.read).",filesRead:"This access token cannot read file contents, so diffs are hidden (needs files.read).",workspace:"Choose a workspace to see its changes.",unregistered:"This workspace is not registered on the host, so its Git changes cannot be shown. The host owner can add it as a project.",loading:"Loading workspaces…"}),Gl=Object.freeze({not_repository:"Not a git repository",unknown_ref:"The base branch is not known in this repository.",invalid_compare:"The host refused this comparison. Pick Uncommitted or a branch name Git accepts.",stale_snapshot:"The checkout changed since this list was loaded. It was loaded again from the start.",invalid_cursor:"The rest of this list is no longer available. It was loaded again from the start.",git_unavailable:"Git is not available on the host.",git_failed:"Git failed on the host. Try again; the host's logs may say why.",blocked_path:"This file is never shown remotely: secrets, keys, .git and ALP configuration are blocked.",invalid_path:"That is not a valid path in this workspace."}),Eb=Object.freeze([{id:"uncommitted",label:"Uncommitted"},{id:"base",label:"Committed"},{id:"staged",label:"Staged"},{id:"unstaged",label:"Unstaged"}]),Rx=Object.freeze({modified:"Modified",added:"New",deleted:"Deleted",renamed:"Renamed",copied:"Copied",typechange:"Type changed",untracked:"Untracked",conflicted:"Conflicted"}),oj=Object.freeze({modified:"M",added:"A",deleted:"D",renamed:"R",copied:"C",typechange:"T",untracked:"U",conflicted:"!"}),Mb=Object.freeze({binary:"Binary file",too_large:"Diff too large to display",withheld:"Content withheld: it looks like it holds a private key.",symlink:"Symbolic link: its target is not shown.",submodule:"Submodule: its content is not shown."});class ys extends Error{constructor(t){super(t.message),this.name="GitAccessError",this.failure=t,this.reason=t.reason}}function _i(s){if(s instanceof ys)return s.failure;const t=Be(s);if(t.code===1003&&t.reason==="grant"){const a=s?.data?.permission;return a==="files.read"?{...t,message:Il.filesRead}:a==="project.read"?{...t,message:Il.projectRead}:t}const i=t.reason?Gl[t.reason]:void 0;return i?{...t,message:i}:t}function lj(s){const t=_i(s);return t.code===1004&&t.reason==="stale_snapshot"||t.code===-32602&&t.reason==="invalid_cursor"}function Jf(s){const t=s.workspace;if(!t)return;const i=Ll(s.principal??void 0,t),a=new Set([t,...i?[i.path,i.canonical]:[]]);return s.registry.workspaces.filter(l=>a.has(l.directory)&&!l.archivedAt).sort((l,u)=>+!!u.pinnedAt-+!!l.pinnedAt||String(l.createdAt).localeCompare(String(u.createdAt))||l.id.localeCompare(u.id))[0]}function Gd(s){const t=l=>({status:!1,reason:l,message:Il[l]});if(!s.workspace)return t("workspace");if(!s.connection.capabilities.includes("workspace.git"))return t("capability");if(!Te(s.principal??void 0,"project.read"))return t("projectRead");if(!s.connection.capabilities.includes("workspace.registry"))return t("registry");const i=Jf(s);if(!i)return t(s.registry.loading?"loading":"unregistered");const a=Te(s.principal??void 0,"files.read");return{status:!0,workspaceId:i.id,content:a,...a?{}:{contentMessage:Il.filesRead}}}function cj(s){const t=typeof s=="string"&&s?Js(s):void 0;return t&&!$i(t)?t:void 0}function uj({mode:s,baseRef:t,ignoreWhitespace:i}){const a=Eb.some(l=>l.id===s)?s:"uncommitted";return{mode:a,...a==="base"&&t?{baseRef:t}:{},...i?{ignoreWhitespace:!0}:{}}}function _x(s,t){const i=Array.isArray(t?.files)?t.files:[],a=Number.isSafeInteger(t?.hiddenCount)&&t.hiddenCount>0?t.hiddenCount:0,l=s&&s.snapshot===t.snapshot?s:void 0;return{compare:t.compare,snapshot:t.snapshot,files:l?[...l.files,...i]:[...i],hiddenCount:(l?.hiddenCount??0)+a,truncated:t.truncated===!0,...typeof t.nextCursor=="string"&&t.nextCursor?{nextCursor:t.nextCursor}:{}}}function dj(s){const t=[];for(const i of Array.isArray(s?.hunks)?s.hunks:[]){t.push({type:"hunk",text:`@@ -${i.oldStart},${i.oldCount} +${i.newStart},${i.newCount} @@${i.context?` ${i.context}`:""}`});let a=i.oldStart,l=i.newStart;for(const u of Array.isArray(i.lines)?i.lines:[]){const d=u.noNewline===!0?{noNewline:!0}:{};u.type==="add"?t.push({type:"add",text:u.content,newLine:l++,...d}):u.type==="remove"?t.push({type:"remove",text:u.content,oldLine:a++,...d}):t.push({type:"context",text:u.content,oldLine:a++,newLine:l++,...d})}}return t}function fj(s){let t=0,i=0;for(const a of s)t+=a.additions||0,i+=a.deletions||0;return{additions:t,deletions:i}}function Lx(s){if(!Number.isFinite(s)||s<1e3)return String(Math.max(0,Math.floor(s||0)));const t=s/1e3;return`${t>=10?Math.round(t):Math.round(t*10)/10}k`}function Ox(s){const i=[s.branch??(s.detached&&s.head?`Detached at ${s.head.slice(0,7)}`:s.head?s.head.slice(0,7):"No commits yet")];if(s.upstream){const{ref:a,ahead:l,behind:u}=s.upstream;i.push(`${a}${l||u?` (${[l?`↑${l}`:"",u?`↓${u}`:""].filter(Boolean).join(" ")})`:""}`)}return i.join(" · ")}function hj(s){return s?s.replace(/^refs\/(heads|remotes)\//,"").trim():"base"}const zb=Object.freeze(["image/png","image/jpeg","image/gif","image/webp"]),Mi=Object.freeze({maxCount:4,maxBytes:2*1024*1024,maxTotalBytes:2.5*1024*1024});function mj(s,t=!0){const i={maxCount:0,maxBytes:0,maxTotalBytes:0};if(!t)return i;if(s===void 0)return{...Mi};if(!s||typeof s!="object"||Array.isArray(s))return i;const a=s;if(!["maxCount","maxBytes","maxTotalBytes"].every(u=>Number.isSafeInteger(a[u])&&a[u]>=0))return i;const l=Math.min(Mi.maxTotalBytes,a.maxTotalBytes);return{maxCount:Math.min(Mi.maxCount,a.maxCount),maxBytes:Math.min(Mi.maxBytes,l,a.maxBytes),maxTotalBytes:l}}const Li=s=>s>=1024*1024?`${(s/1024/1024).toFixed(1).replace(/\.0$/,"")} MB`:`${Math.max(1,Math.round(s/1024))} KB`;function Rb(s){const t=String(s?.type??"").split(";",1)[0].trim().toLowerCase(),i=t==="image/jpg"?"image/jpeg":t;return zb.includes(i)?i:null}function Dx(s){if(!s)return[];const t=Array.from(s.files??[]);return t.length?t:Array.from(s.items??[]).filter(i=>i?.kind==="file").map(i=>i.getAsFile?.()).filter(i=>!!i)}function pj(s){let t="";for(let i=0;i<s.length;i+=32768)t+=String.fromCharCode(...s.subarray(i,i+32768));return btoa(t)}let gj=0;function _b(s,t,i,a,l=Mi){const u=s.reduce((d,h)=>d+h.size,0);return i?!l.maxCount||!l.maxBytes||!l.maxTotalBytes?"This connection takes no images.":s.length>=l.maxCount?`A message carries at most ${l.maxCount} images.`:a>l.maxBytes?`${t} is ${Li(a)}; an image is at most ${Li(l.maxBytes)}.`:u+a>l.maxTotalBytes?`The images of a message are at most ${Li(l.maxTotalBytes)} together.`:null:`${t} is not a PNG, JPEG, GIF or WebP image.`}async function xj(s,t,i=Mi){const a=[];let l=null;for(const u of Array.from(t)){const d=String(u.name||"image"),h=Rb(u),m=_b([...s,...a],d,h,u.size,i);if(m||!h){l??=m;continue}let p;try{p=pj(new Uint8Array(await u.arrayBuffer()))}catch{l??=`Could not read ${d}.`;continue}a.push({id:`image-${++gj}`,type:"image",mimeType:h,data:p,name:d,size:u.size})}return{added:a,error:l}}function Xr(s,t,i=Mi){const a=[...s];let l=null;for(const u of t){const d=_b(a,u.name,u.mimeType,u.size,i);if(d){l??=d;continue}a.push(u)}return{attachments:a,error:l}}function yj(s,t=[]){return[...s.trim()||!t.length?[{type:"text",text:s}]:[],...t.map(i=>({type:"image",mimeType:i.mimeType,data:i.data,...i.name?{name:i.name.slice(0,255)}:{}}))]}const Lb=s=>`data:${s.mimeType};base64,${s.data}`,Ps=Object.freeze({maxObjectBytes:0,maxPerPrompt:0,maxPromptBytes:0,maxChunkBytes:0}),qx=["maxObjectBytes","maxPerPrompt","maxPromptBytes","maxChunkBytes"];function bj(s,t){if(!t||!s||typeof s!="object"||Array.isArray(s))return{...Ps};const i=s;if(!qx.every(h=>Number.isSafeInteger(i[h])&&i[h]>=0))return{...Ps};const[a,l,u,d]=qx.map(h=>i[h]);return!l||!u||!d?{...Ps}:{maxObjectBytes:Math.min(a,u),maxPerPrompt:l,maxPromptBytes:u,maxChunkBytes:d}}const Ob=s=>s<1024?`${s} B`:Li(s),Db=s=>!!s&&s.maxPerPrompt>0&&s.maxPromptBytes>0&&s.maxChunkBytes>0;function vj({capable:s,permitted:t,writable:i,limits:a,session:l,known:u=!0}){if(!s)return"The host behind this gateway does not store files.";if(!i)return"Your access token cannot send messages.";if(!t)return"Your access token cannot upload files (it needs attachments.write).";if(!Db(a))return"This connection takes no files.";if(!u)return null;const d=l?.promptAttachments;if(!Array.isArray(d)||!d.length){const h=typeof l?.agent=="string"?l.agent:"This agent",m=typeof l?.runtime=="string"?l.runtime:"a runtime";return`${h} runs on ${m} here, which cannot read attached files.`}return null}function wj(s){const t=String(s??"").normalize("NFC").replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}/\\]/gu,"").trim();let i="",a=0;for(const l of t){const u=new TextEncoder().encode(l).length;if(a+u>255)break;i+=l,a+=u}return i.trim()||"file"}const kj=/^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/;function jj(s){const t=String(s?.type??"").split(";",1)[0].trim().toLowerCase();return kj.test(t)?t:"application/octet-stream"}function qb(s,t,i,a){const l=s.reduce((u,d)=>u+d.size,0);return Db(a)?s.length>=a.maxPerPrompt?`A message carries at most ${a.maxPerPrompt} files.`:i>a.maxObjectBytes?`${t} is ${Li(i)}; a file is at most ${Li(a.maxObjectBytes)}.`:l+i>a.maxPromptBytes?`The files of a message are at most ${Li(a.maxPromptBytes)} together.`:null:"This connection takes no files."}let Sj=0;async function Nj(s,t,i){const a=[];let l=null;for(const u of Array.from(t)){const d=wj(u.name),h=qb([...s,...a],d,u.size,i);if(h){l??=h;continue}let m;try{m=new Uint8Array(await u.arrayBuffer())}catch{l??=`Could not read ${d}.`;continue}a.push({id:`file-${++Sj}`,type:"file",name:d,mimeType:jj(u),size:m.length,data:m})}return{added:a,error:l}}function Ol(s,t,i){const a=[...s];let l=null;for(const u of t){const d=qb(a,u.name,u.size,i);if(d){l??=d;continue}a.push(u)}return{attachments:a,error:l}}const Bx=(s,t,i=0)=>`${s}:file-${t}${i?`.${i}`:""}`;async function Tj(s,{sessionId:t,file:i,requestId:a,digest:l}){try{const u=await s.begin({sessionId:t,name:i.name,size:i.data.length,mimeType:i.mimeType,sha256:await l(i.data),requestId:a});return u?.state!=="uploading"||typeof u.uploadId!="string"?!1:(await s.abort(u.uploadId),!0)}catch{return!1}}function Aj(s,t=[],i=[]){const a=yj(s,t);if(!i.length)return a;if(i.some(l=>typeof l.attachmentId!="string"))throw new Error("A file of this message is not uploaded yet.");return[...s.trim()?[{type:"text",text:s}]:[],...t.map(l=>({type:"image",mimeType:l.mimeType,data:l.data,...l.name?{name:l.name.slice(0,255)}:{}})),...i.map(l=>({type:"attachment",attachmentId:l.attachmentId}))]}function Cj(s){return Array.isArray(s)?s.filter(t=>t&&typeof t=="object"&&typeof t.attachmentId=="string"&&typeof t.name=="string"&&Number.isSafeInteger(t.size)&&t.size>=0).map(t=>({attachmentId:t.attachmentId,name:t.name,size:t.size})):[]}function bs(s){return{rootId:s,cursor:0,entries:[],positions:{},sessions:{},order:[],running:{},closed:{},questions:{},prompts:{},turns:{},turnOrder:[],historyUnavailable:!1,reset:0}}function Yd(s,t){const i=s.positions[t.key];if(i!==void 0){const a=s.entries.slice();return a[i]=t,{...s,entries:a}}return{...s,entries:[...s.entries,t],positions:{...s.positions,[t.key]:s.entries.length}}}const Ea=(s,t)=>{if(!(t in s))return s;const i={...s};return delete i[t],i};function $x(s,t){if(typeof t!="string"||!t)return s;const i=s.turnOrder??[];return i.includes(t)?s:{...s,turnOrder:[...i,t]}}function zi(s,t){if(!t||typeof t!="object"||!t.event||typeof t.sessionId!="string")return s;const i=typeof t.cursor=="number";if(i&&t.cursor<=s.cursor)return s;let a=i?{...s,cursor:t.cursor}:s;const l=t.sessionId,u=typeof t.ts=="string"?t.ts:"",d=t.event;d.type==="item"&&!a.sessions[l]&&(a={...a,sessions:{...a.sessions,[l]:{id:l}},order:a.order.includes(l)?a.order:[...a.order,l]});const h=()=>`${l}:${d.type}:${t.cursor??`${t.epoch}:${t.seq}`}`;switch(d.type){case"session.opened":case"session.updated":{const m=d.session&&typeof d.session=="object"?d.session:{},p=a.sessions[l];return a={...a,sessions:{...a.sessions,[l]:{...p,...m,id:l,...d.type==="session.opened"?{status:m.busy?"running":"idle"}:{}}},order:a.order.includes(l)?a.order:[...a.order,l]},d.type==="session.opened"&&(a={...a,closed:Ea(a.closed,l)}),a}case"session.closed":{const m=a.sessions[l];return{...a,closed:{...a.closed,[l]:!0},running:Ea(a.running,l),questions:Object.fromEntries(Object.entries(a.questions).filter(([,p])=>p.sessionId!==l)),sessions:m?{...a.sessions,[l]:{...m,status:"closed",busy:!1}}:a.sessions}}case"session.failed":return Yd(a,{key:h(),sessionId:l,ts:u,item:{kind:"session_event",id:h(),level:"error",text:d.error?.message?`The session failed: ${d.error.message}`:"The session failed."}});case"prompt.accepted":{if(typeof d.clientMessageId!="string")return a;const m=d.result==="turn"||d.result==="steer"?d.result:void 0;return a={...a,prompts:{...a.prompts,[d.clientMessageId]:{state:"accepted",...typeof d.turnId=="string"?{turnId:d.turnId}:{},...m?{result:m}:{}}}},m==="turn"&&l===a.rootId?$x(a,d.turnId):a}case"prompt.failed":return typeof d.clientMessageId=="string"?{...a,prompts:{...a.prompts,[d.clientMessageId]:{state:"failed",...d.error?.code?{errorCode:d.error.code}:{},...d.error?.message?{error:d.error.message}:{}}}}:a;case"turn.started":{l===a.rootId&&(a=$x(a,d.turnId));const m=a.sessions[l],p=a.turns[d.turnId]==="ended"?a.turns:{...a.turns,[String(d.turnId)]:"running"};return{...a,turns:p,running:{...a.running,[l]:String(d.turnId)},...m?{sessions:{...a.sessions,[l]:{...m,status:"running",busy:!0}}}:{}}}case"turn.ended":{const m=a.sessions[l];return a={...a,running:Ea(a.running,l),turns:{...a.turns,[String(d.turnId)]:"ended"},...m&&m.status!=="closed"?{sessions:{...a.sessions,[l]:{...m,status:"idle"}}}:{}},(d.state==="failed"||d.state==="canceled")&&(a=Yd(a,{key:h(),sessionId:l,ts:u,item:{kind:"turn_end",id:h(),state:d.state,...d.error?.message?{error:d.error.message}:{}}})),a}case"item":{const m=d.item;return!m||typeof m!="object"||typeof m.id!="string"||typeof m.kind!="string"||!["user_message","assistant_message","notice","tool_call","todo","compaction"].includes(m.kind)?a:Yd(a,{key:`${l}:${m.id}`,sessionId:l,ts:u,item:m})}case"usage":{const m=a.sessions[l];return!d.usage||typeof d.usage!="object"||Array.isArray(d.usage)?a:{...a,sessions:{...a.sessions,[l]:{...m,id:l,usage:d.usage}}}}case"question":{const m=d.question;return!m||typeof m.id!="string"?a:{...a,questions:{...a.questions,[m.id]:m}}}case"question.resolved":return typeof d.questionId=="string"?{...a,questions:Ea(a.questions,d.questionId)}:a;default:return a}}function Ux(s,t,i){let a=t.reset?{...bs(s.rootId),reset:s.reset+1}:{...s,questions:{}};const l=i.filter(p=>typeof p?.cursor=="number").sort((p,x)=>p.cursor-x.cursor),u=i.filter(p=>typeof p?.cursor!="number"),d=a.cursor;for(const p of l)a=zi(a,p);for(const p of u)a=zi(a,p);const h=t.session,m=a.rootId;if(h&&(h.id===void 0||h.id===m)){const p=a.sessions[m];a={...a,sessions:{...a.sessions,[m]:{...p,...h,id:m}},order:a.order.includes(m)?a.order:[m,...a.order]},h.status==="closed"?a={...a,closed:{...a.closed,[m]:!0},running:Ea(a.running,m)}:h.status==="idle"&&!h.busy&&(a={...a,running:Ea(a.running,m)})}return t.reset&&(a={...a,historyUnavailable:a.cursor===d}),a}function Bb(s){return(s.order.includes(s.rootId)?s.order:[s.rootId,...s.order]).map(i=>({id:i,session:s.sessions[i],running:i in s.running,closed:!!s.closed[i]}))}function Ej(s,t){return s.entries.filter(i=>i.sessionId===t)}function Hx(s,t){const i=s.prompts[t];if(!i)return!1;if(i.state==="failed")return i.errorCode!=="outcome_unknown";const a=Object.values(s.running);if(!i.turnId)return a.length===0;const l=s.turns[i.turnId];return l==="ended"||l==="running"&&!a.includes(i.turnId)}function Ix(s){const t=new Set;for(const i of s.entries)i.item.kind==="user_message"&&typeof i.item.clientMessageId=="string"&&t.add(i.item.clientMessageId);return t}function bf(s,t){return s.oversized?{sessionId:t,epoch:"history",seq:s.cursor,cursor:s.cursor,ts:"",event:{type:"item",item:{kind:"notice",id:`oversized:${s.cursor}`,level:"warning",text:`History event ${s.cursor} is too large to display (${s.oversized.bytes} bytes).`}}}:s}function Mj(s,t){let i=bs(s.rootId);for(const d of t)i=zi(i,bf(d,s.rootId));const a=i.entries.slice(),l={...i.positions};for(const d of s.entries){const h=l[d.key];h!==void 0?a[h]=d:(l[d.key]=a.length,a.push(d))}const u={...i.sessions};for(const[d,h]of Object.entries(s.sessions))u[d]={...u[d],...h};return{...s,entries:a,positions:l,sessions:u,order:[...new Set([...i.order,...s.order])],prompts:{...i.prompts,...s.prompts},turns:{...i.turns,...s.turns},turnOrder:[...new Set([...i.turnOrder,...s.turnOrder??[]])]}}const zj={codex:"Codex",claude:"Claude",acp:"ACP",antigravity:"Antigravity"},Rj={"read-only":"Read only","workspace-write":"Workspace write","full-access":"Full access"},$b=s=>s==="custom"?"Custom":s,on=s=>typeof s=="string"&&s.trim()?s:void 0;function Gx(s){if(!Array.isArray(s))return[];const t=new Map;for(const i of s){const a=on(i?.id);if(!a||t.has(a))continue;const l=Array.isArray(i.efforts)?[...new Set(i.efforts.filter(d=>!!on(d)))]:[],u=on(i.effort);t.set(a,{id:a,label:on(i.label)??a,efforts:l,...u&&l.includes(u)?{effort:u}:{}})}return[...t.values()]}function Xs(s){if(s.replace(/[\s_-]+/g,"").toLowerCase()==="xhigh")return"Extra high";const i=s.replace(/[_-]+/g," ").replace(/\s+/g," ").trim();return i?i.charAt(0).toUpperCase()+i.slice(1).toLowerCase():s}function Ub(s,t,i){if(t)return s.find(l=>l.id===t);if(!i?.model)return;const a=i.runtime?`${i.runtime}:${i.model}`:i.model;return s.find(l=>l.id===a)??s.find(l=>l.id===i.model)}function Hb(s){return(s?.efforts??[]).map(t=>({id:t,label:Xs(t)}))}function _j(s,t){return t&&s?.efforts.includes(t)?t:void 0}function Yx(s,t){const i=t.team&&s.teams.some(d=>d.id===t.team)?t.team:void 0,a=t.mode&&s.modes.some(d=>d.id===t.mode)?t.mode:s.defaultMode??s.modes[0]?.id,l=t.model?s.models.find(d=>d.id===t.model):void 0,u=t.thinkingByModel?.[l?.id??"default"];return{...i?{team:i}:{},...a?{mode:a}:{},...l?{model:l.id}:{},...u&&(!l||l.efforts.includes(u))?{thinking:u}:{}}}function Vx(s,t,{persist:i=!1}={}){return{cwd:s,...i?{persist:!0}:{},...t.team?{workflow:t.team}:{},...t.mode?{mode:t.mode}:{},...t.model?{model:t.model}:{},...t.thinking?{thinking:t.thinking}:{}}}function Lj(s){const t=s?.preview;if(!t||typeof t!="object")return;const i=on(t.team),a=on(t.agent);return!i||!a?void 0:{teams:Array.isArray(t.teams)?t.teams.filter(u=>on(u?.id)).map(u=>({id:u.id,label:on(u.label)??u.id,...on(u.description)?{description:u.description}:{}})):[],team:i,agent:a,...on(t.teamLabel)?{teamLabel:t.teamLabel}:{},runtime:on(t.runtime)??"",model:on(t.model)??"",mode:on(t.mode)??"",thinking:on(t.thinking)??""}}function Oj(s,t=[]){const i=Ub(t,void 0,s),a=[{key:"team",label:"Team",value:s.teamLabel??s.teams.find(l=>l.id===s.team)?.label??$b(s.team)},{key:"agent",label:"Agent",value:s.agent}];return s.runtime&&a.push({key:"runtime",label:"Runtime",value:zj[s.runtime]??s.runtime}),s.model&&a.push({key:"model",label:"Model",value:i?.label??s.model}),s.thinking&&a.push({key:"thinking",label:"Thinking",value:Xs(s.thinking)}),s.mode&&a.push({key:"mode",label:"Permissions",value:Rj[s.mode]??s.mode}),a}function Ib(s){return JSON.stringify([typeof s?.workflow=="string"?s.workflow:"",typeof s?.model=="string"?s.model:""])}function Kx(s,t){if(!(!t||s.some(i=>i.id===t.team)))return{id:t.team,label:t.teamLabel??$b(t.team)}}function Dj(s,t){return t&&!s.some(i=>i.id===t.id)?[t,...s]:s}function qj({chosen:s,previewTeam:t,previewSettled:i,previewError:a,previewBlocked:l,previewNeedsRead:u,teams:d,teamsKnown:h,teamsUnavailable:m}){return s?{team:s}:t?{team:t}:i?d.length?{team:d[0].id}:h?{}:{wait:Bj({previewError:a,previewBlocked:l,previewNeedsRead:u,teamsUnavailable:m}),stuck:!0}:{wait:"Checking what would run…"}}function Bj({previewError:s,previewBlocked:t,previewNeedsRead:i,teamsUnavailable:a}){const l=a?.reason==="capability"?"this host does not list teams (no team capability)":a?.reason==="permission"?"your access token cannot list teams (it lacks project.read)":a?.reason==="failed"?`the team list failed${a.message?` (${Vd(a.message)})`:""}`:"the team list is not available",u=t?`the preview is not available${s?` (${Vd(s)})`:""}`:`the preview failed${s?` (${Vd(s)})`:""}`,d=[];(a?.reason==="failed"||!t)&&d.push("use Retry in the preview to ask again");const h=[];a?.reason==="permission"&&h.push("project.read"),t&&i&&h.push("session.read"),h.length&&d.push(`reconnect with a token that has ${h.join(" or ")}`),d.length||d.push("connect to a host that lists teams or previews sessions");const m=d.join(", or ");return`Cannot tell which team would run: ${l}, and ${u}. To start, ${m}.`}function Vd(s){return String(s).trim().replace(/[.。]+$/,"")}function $j(s,t,i){return String(t??"").trim()?`${s} Your first message was not sent; it is back in the New session box${i?` of ${i}`:""}.`:s}async function Uj(s,t,i,{mounted:a,describe:l,nameOf:u}){const d=s.startOrigin();try{return await s.createSession(t)}catch(h){throw a()||(i.trim()&&s.keepUnsentDraft(i,d),s.notify("error",$j(l(h).message,i,d.workspace?u(d.workspace):void 0))),h}}const Gb="session.configure.live",Ma=Object.freeze({session_busy:"The session or one of its agents is working. Wait until everything is idle, then try again.",session_closed:"The session is closed. Send it a message to open it, then change its configuration.",not_root:"Only the main agent of a session can be changed; an agent keeps the team and model it started with.",not_persistent:"This session is not kept, so it cannot continue its conversation with a new configuration.",runtime_unsupported:"The host cannot change this session's model or team while it runs. Start a new session instead.",runtime_mismatch:"A session keeps its runtime. To use another runtime's model, start a new session with it.",agent_mismatch:"That team runs another main agent. Start a new session with that team.",permission_escalation:"The change would give the session more permissions or new commands than it has. Start a new session for it.",team_not_found:"The host defines no such team for this project.",invalid_params:"The host does not offer this model or thinking for this session.",native_refused:"The agent's runtime did not take the new configuration. The session keeps its own.",stale_generation:"The conversation changed since this view loaded. It was reloaded; try again.",key_conflict:"That request id was already used for something else. Try again.",outcome_unknown:"The host cannot tell whether the change happened. Check the session before trying again.",persistence_failed:"The host could not store the change. Check the session before trying again.",turn_in_progress:"A turn of this conversation has not ended. Try again when it has."}),Yb=new Set(["runtime_mismatch","agent_mismatch","permission_escalation","runtime_unsupported"]);function Fx(s){const t=ei(s),a=s?.data?.action==="session.create",l=t.reason?Ma[t.reason]:void 0,u=t.reason==="grant"?t.message:l??t.message;return{...t,message:u,newSession:a||!!t.reason&&Yb.has(t.reason)}}const Hj=s=>/^([a-z]+)[:/]/.exec(s)?.[1];function Ij(s,t){const i=t.runtime,a=i?s.filter(u=>Hj(u.id)===i):[],l=t.model?a.find(u=>u.id===`${i}:${t.model}`)??a.find(u=>u.id===t.model):void 0;return{same:a,current:l,others:s.length-a.length}}function Gj({capabilities:s,canWrite:t,canTeam:i,summary:a,closed:l=!1,busy:u=!1,configuring:d=!1,generation:h,online:m=!0,driveBlock:p}){const x=A=>({enabled:!1,reason:A});if(!s.includes(Gb)){const A="Set when the session started: this host cannot change it on a running session.";return{shown:!1,reason:A,model:x(A),thinking:x(A),team:x(A)}}const y=a?.conversation,k=(()=>{if(y?.configure!==!0)return y?.reason==="not_persistent"?Ma.not_persistent:y?.reason==="not_root"?Ma.not_root:Ma.runtime_unsupported;if(!t)return"Your access token cannot change this session (it needs session.write).";if(p)return p;if(l)return Ma.session_closed;if(!s.includes("session.history")||!h)return"The conversation is still loading.";if(!m)return"Reconnecting…";if(d)return"Applying the last change…";if(u)return"Wait until main and its agents are idle."})(),j=k?x(k):{enabled:!0},S=k?x(k):i?{enabled:!0}:x("Your access token cannot change the team (it needs session.team.write).");return{shown:!0,model:j,thinking:j,team:S}}function Yj(s,t){if(!t)return s;const i=s?.workflow&&typeof s.workflow=="object"?s.workflow:{};return{...s,model:t.model,thinking:t.thinking,mode:t.mode,runtime:t.runtime,workflow:{...i,mode:t.team,supervisor:t.supervisor,...typeof t.maxPeers=="number"?{maxPeers:t.maxPeers}:{}},teamLabel:t.teamLabel??s?.teamLabel??(t.team==="custom"?void 0:t.team)}}function Vj(s,t,i){const a=s.effective,u=`${a.teamLabel??a.team} · main runs ${i??a.model}${a.thinking?` · ${t(a.thinking)}`:""}`;return s.status==="unchanged"?`Nothing to change: ${u}.`:`Changed: ${u}.${s.restarted?" The agent restarted on the same conversation.":""}`}const eh="alp-web:preferences",vf=1,Kj=["interrupt","steer","queue"],Fj=["enter","mod-enter"],Xj=["system","light","dark","zinc","midnight","claude","ghostty","pureBlack"],Pj=["full","collapseToolCalls","collapseTurns"],Qj=["github","catppuccin","dracula","tokyo-night","one","nord","gruvbox","solarized"],On=Object.freeze({uiFontSize:[10,21,14],contentFontSize:[10,21,15],codeFontSize:[9,22,12],contentMaxWidth:[600,4e3,820],terminalScrollback:[0,1e6,1e4]}),Wj=200,Vb=Object.freeze({header:["new-session","history","search"],footer:["tasks"]}),Kb=new Set(["tasks"]),so=s=>Vb[s].map(t=>({id:t,visible:!Kb.has(t)})),Fb=Object.freeze({grouping:"project",sort:"created",titleSource:"title",rowItems:Object.freeze({branch:!1,project:!1,host:!0,labels:!0}),trailing:"timestamp",projectFilters:[]}),Zj=64;function Xx(s){const t=qi(s)?s:{},i=qi(t.rowItems)?t.rowItems:{},a=Fb;return{grouping:t.grouping==="status"?"status":"project",sort:t.sort==="lastPrompt"?"lastPrompt":"created",titleSource:t.titleSource==="branch"?"branch":"title",rowItems:Object.fromEntries(Object.entries(a.rowItems).map(([l,u])=>[l,typeof i[l]=="boolean"?i[l]:u])),trailing:t.trailing==="none"?"none":"timestamp",projectFilters:[...new Set(Array.isArray(t.projectFilters)?t.projectFilters.filter(l=>typeof l=="string"&&l&&l.length<=4096):[])].slice(0,Zj)}}const Kd=Object.freeze({sendBehavior:"steer",sendShortcut:"enter",theme:"system",uiFontFamily:"",monoFontFamily:"",uiFontSize:14,contentFontSize:15,codeFontSize:12,contentMaxWidth:null,syntaxTheme:"one",chatDisplay:"collapseTurns",chatOutline:!0,terminalScrollback:1e4,sidebar:Object.freeze({header:so("header"),footer:so("footer")}),sidebarDisplay:Fb,newSession:Object.freeze({})});function Br(s,[t,i,a]){return typeof s=="number"&&Number.isFinite(s)?Math.min(i,Math.max(t,Math.round(s))):a}function Px(s){if(typeof s!="string")return"";const t=s.trim();return t.length<=Wj&&!/[;{}<>\\()]/.test(t)?t:""}function Qx(s,t){const i=Vb[t],a=[];for(const l of Array.isArray(s)?s:[])qi(l)&&i.includes(l.id)&&!a.some(u=>u.id===l.id)&&a.push({id:l.id,visible:typeof l.visible=="boolean"?l.visible:!Kb.has(l.id)});for(const l of so(t))a.some(u=>u.id===l.id)||a.push(l);return a}const Jj=200,eS=64,qi=s=>!!s&&typeof s=="object"&&!Array.isArray(s),Fd=s=>typeof s=="string"&&s.trim()&&s.length<=Jj?s:void 0;function Xb(s){if(!qi(s))return{};const t=s,i={};for(const a of["team","mode","model"]){const l=Fd(t[a]);l&&(i[a]=l)}if(qi(t.thinkingByModel)){const a={};for(const[l,u]of Object.entries(t.thinkingByModel).slice(0,eS)){const d=Fd(u);Fd(l)&&d&&!Object.hasOwn(Object.prototype,l)&&(a[l]=d)}Object.keys(a).length&&(i.thinkingByModel=a)}return i}function Oi(s){const t=()=>({...Kd,sidebar:{header:so("header"),footer:so("footer")},sidebarDisplay:Xx(null),newSession:{}});if(typeof s!="string"||!s)return t();let i;try{i=JSON.parse(s)}catch{return t()}if(!qi(i)||i.v!==vf)return t();const a=(u,d)=>u.includes(i[d])?i[d]:Kd[d],l=qi(i.sidebar)?i.sidebar:{};return{sendBehavior:a(Kj,"sendBehavior"),sendShortcut:a(Fj,"sendShortcut"),theme:a(Xj,"theme"),uiFontFamily:Px(i.uiFontFamily),monoFontFamily:Px(i.monoFontFamily),uiFontSize:Br(i.uiFontSize,On.uiFontSize),contentFontSize:Br(i.contentFontSize,On.contentFontSize),codeFontSize:Br(i.codeFontSize,On.codeFontSize),contentMaxWidth:typeof i.contentMaxWidth=="number"&&Number.isFinite(i.contentMaxWidth)?Br(i.contentMaxWidth,On.contentMaxWidth):null,syntaxTheme:a(Qj,"syntaxTheme"),chatDisplay:a(Pj,"chatDisplay"),chatOutline:typeof i.chatOutline=="boolean"?i.chatOutline:Kd.chatOutline,terminalScrollback:Br(i.terminalScrollback,On.terminalScrollback),sidebar:{header:Qx(l.header,"header"),footer:Qx(l.footer,"footer")},sidebarDisplay:Xx(i.sidebarDisplay),newSession:Xb(i.newSession)}}const tS=["sendBehavior","sendShortcut","theme","uiFontFamily","monoFontFamily","uiFontSize","contentFontSize","codeFontSize","contentMaxWidth","syntaxTheme","chatDisplay","chatOutline","terminalScrollback","sidebar","sidebarDisplay","newSession"];function nS(s){const t=Oi(JSON.stringify({...s,v:vf}));return JSON.stringify({v:vf,...Object.fromEntries(tS.map(i=>[i,t[i]]))})}function Wx(s){if(!s)return Oi(null);try{return Oi(s.getItem(eh))}catch{return Oi(null)}}function sS(s,t){if(!s)return!1;try{return s.setItem(eh,nS(t)),!0}catch{return!1}}function iS(s,t){const i={...s.thinkingByModel??{}},a=t.model||"default";return t.thinking?i[a]=t.thinking:delete i[a],Xb({team:t.team,mode:t.mode,model:t.model,thinkingByModel:i})}const io=Object.freeze({capability:"The host has not allowed remote terminals (its owner runs: alp terminal allow --yes)",permission:"Your access token cannot open terminals (it needs terminal.exec)",workspace:"Open a workspace to use a terminal.",registry:"This host does not list its workspaces, so it cannot open a terminal here. Update ALP on the host.",loading:"Loading the host's workspaces…",unregistered:"This workspace is not in the host's workspace list, so a terminal cannot open here.",offline:"Not connected to the host."}),VC="This shell runs on the daemon host as the account that runs alpd. The workspace is not a sandbox: the shell can read and write anything that account can, and use the network.",aS=Object.freeze({"root-only":"Limited protection on this Linux host: closing the terminal may not stop background processes.",none:"Process cleanup is not guaranteed on Windows: closing the terminal may not stop background processes."});function KC(s){return s==="root-only"||s==="none"?aS[s]:void 0}const FC="Runs on the daemon host as the account that runs alpd · the workspace is not a sandbox",Zx={terminal_disabled:io.capability,terminal_unsupported:"Terminals are not available on the daemon host (its terminal owner did not load).",terminal_limit:"Too many terminals are open on the host. Close one and try again.",input_too_large:"That input was too large for the terminal."},rS={closed:"closed",idle:"ended after being idle",lifetime:"reached its maximum lifetime",detached:"nobody reattached in time",revoked:"access was revoked",disabled:"the host turned terminals off",shutdown:"the host stopped"};function XC(s){const t=[];return Number.isSafeInteger(s.exitCode)&&t.push(`code ${s.exitCode}`),Number.isSafeInteger(s.signal)&&s.signal&&t.push(`signal ${s.signal}`),s.reason&&s.reason!=="exited"&&t.push(rS[s.reason]??s.reason),t.length?`Process exited (${t.join(" / ")})`:"Process exited"}const Jx=(s,t)=>{const i=t-s+1;return`\r
14
+ `):[w]){if(u)return;if(k.trim())for(const j of[...a])j(k)}})),d.push(_a(s,"close",y=>p({error:h,code:typeof y?.code=="number"?y.code:void 0,reason:typeof y?.reason=="string"&&y.reason?y.reason:void 0}))),d.push(_a(s,"error",y=>{h||(h=jb(y),m=setTimeout(()=>p({error:h}),T2),_l(s))})),{get state(){return u||s.readyState!==Vr?"closed":"open"},send(y){if(u||s.readyState!==Vr)throw new st("WebSocket is not open",{reason:"send_failed"});if((s.bufferedAmount??0)+no(y)>i)throw new st(`WebSocket send buffer is over ${i} bytes`,{reason:"send_failed"});s.send(y)},onMessage(y){return u?()=>!1:(a.add(y),()=>a.delete(y))},onClose(y){return u?()=>!1:(l.add(y),()=>l.delete(y))},close(){_l(s,1e3,"client closed"),p({code:1e3,reason:"client closed"})}}}function M2(s,{WebSocket:t,protocols:i,createSocket:a,signal:l,timeoutMs:u=15e3,...d}={}){const h=xf(s);let m;try{m=pf(u)}catch(y){return Promise.reject(y)}if(l?.aborted)return Promise.reject(new st(`Connecting to ${h} was aborted`,{reason:"aborted",cause:l.reason}));const p=t??globalThis.WebSocket;if(!a&&typeof p!="function")return Promise.reject(new TypeError("No WebSocket implementation: pass options.WebSocket or options.createSocket"));let x;try{x=a?a(s,i):i===void 0?new p(s):new p(s,i)}catch(y){return Promise.reject(new st(`Could not connect to ${h}`,{reason:"disconnected",cause:zx(y,s)}))}return kb(x),new Promise((y,w)=>{const k=[];let j;const S=()=>{for(const O of k.splice(0))O();j!==void 0&&clearTimeout(j),l?.removeEventListener("abort",R)},A=O=>{S(),_l(x),w(O)},R=()=>A(new st(`Connecting to ${h} was aborted`,{reason:"aborted",cause:l?.reason})),q=()=>{S();try{y(E2(x,d))}catch(O){w(O)}};if(x.readyState===Vr)return q();k.push(_a(x,"open",q)),k.push(_a(x,"error",O=>A(new st(`Could not connect to ${h}`,{reason:"disconnected",cause:zx(jb(O),s)})))),k.push(_a(x,"close",O=>A(new st(`Could not connect to ${h}`,{reason:"disconnected",data:{code:O?.code,reason:O?.reason||void 0}})))),l?.addEventListener("abort",R,{once:!0}),m!==void 0&&(j=setTimeout(()=>A(new st(`Connecting to ${h} timed out after ${u} ms`,{reason:"timeout"})),m))})}const z2=new Set(["localhost","127.0.0.1"]);function Sb(s){let t;try{t=new URL(String(s).trim())}catch{throw new Ke("Enter the gateway address, such as https://alp.example.com or http://127.0.0.1:7434.")}if(t.username||t.password||t.search||t.hash)throw new Ke("Use a gateway address without a user name, password, query or fragment.");if(t.protocol!=="https:"&&!(t.protocol==="http:"&&z2.has(t.hostname)))throw new Ke("Use https, or http only on this machine (127.0.0.1 or localhost, for example through an SSH tunnel).");return`${t.origin}${t.pathname.replace(/\/+$/,"")}`}const Nl=s=>Array.isArray(s)&&s.every(t=>typeof t=="string");function R2(s){if(!s||typeof s!="object")return;const{websocket:t,subprotocols:i,principal:a}=s;if(t!=="/v1/ws"||!Nl(i)||!i.includes("alp.v1")||!a||typeof a.id!="string"||!Nl(a.permissions)||!Nl(a.workspaces)||a.modes!==void 0&&!Nl(a.modes))return;const l={id:a.id,...typeof a.label=="string"?{label:a.label}:{},permissions:[...a.permissions],workspaces:[...a.workspaces],...Array.isArray(a.workspaceRoots)?{workspaceRoots:a.workspaceRoots.filter(u=>u&&typeof u.path=="string"&&typeof u.canonical=="string").map(u=>({path:u.path,canonical:u.canonical}))}:{},...a.modes?{modes:[...a.modes]}:{}};return{websocket:t,subprotocols:i,principal:l}}async function _2(s){try{const t=await s.json();return typeof t?.error=="string"?t.error:void 0}catch{return}}function L2(s,t){const i=new AbortController,a=setTimeout(()=>i.abort(new Ai("The gateway did not answer in time.")),t),l=()=>i.abort(s?.reason);return s?.aborted?l():s?.addEventListener("abort",l,{once:!0}),{signal:i.signal,done(){clearTimeout(a),s?.removeEventListener("abort",l)}}}async function O2({url:s,token:t,signal:i,timeoutMs:a=15e3,fetch:l=globalThis.fetch.bind(globalThis),WebSocket:u}){const d=Sb(s);if(!t||/\s/.test(t))throw new Ra("Enter the access token printed by alp-gateway credential create.");const h=L2(i,a);let m;try{m=await l(`${d}/v1/tickets`,{method:"POST",credentials:"omit",cache:"no-store",redirect:"error",referrerPolicy:"no-referrer",headers:{authorization:`Bearer ${t}`},signal:h.signal})}catch(p){throw h.done(),i?.aborted?i.reason??p:h.signal.reason instanceof Ai?h.signal.reason:new Ai("Cannot reach the gateway. Check that it is running at this address and that it allows this page's origin (alp-gateway serve --origin).")}try{if(m.status===401)throw new Ra;if(m.status===403){const w=await _2(m);throw new Ke(w==="tls_required"?"The gateway only accepts this connection over HTTPS.":"The gateway does not allow this page's origin. Start it with --origin set to this page's address.")}if(m.status===421)throw new Ke("The gateway does not know this host name. Add it with alp-gateway serve --public-host.");if(m.status===429)throw new Ai("The gateway is limiting requests from this address. Wait a moment.");if(m.status!==201)throw new Ai(`The gateway is not ready (HTTP ${m.status}).`);const p=R2(await m.json().catch(()=>{}));if(!p)throw new Ke("The gateway answered with an unexpected ticket. Check that the address points to an ALP gateway.");const x=`${d.replace(/^http/,"ws")}${p.websocket}`;return{transport:await M2(x,{protocols:p.subprotocols,signal:h.signal,timeoutMs:a,...u?{WebSocket:u}:{}}).catch(w=>{throw i?.aborted?i.reason??w:new Ai("The gateway accepted the token but the live connection failed. Retrying may help.")}),principal:p.principal}}finally{h.done()}}function Ll(s,t){return!s||!t?void 0:(s.workspaceRoots?.length?s.workspaceRoots:s.workspaces.map(a=>({path:a,canonical:a}))).find(a=>a.path===t||a.canonical===t)}function Te(s,t){return s?s.permissions.includes(t)?!0:t.endsWith(".read")&&s.permissions.includes(t.replace(/\.read$/,".write")):!1}const Pf="alp-web:link-token",D2=/^alpgw1\.[a-f0-9]{16}\.[A-Za-z0-9_-]{43}$/,q2="This link's access token is no longer valid. Run `alp dashboard` again to open ALP with a new link.",B2="This page is not on this machine's loopback address, so it did not use the access token in its link. Open the address `alp dashboard` printed.",$2="The access token in this link is incomplete or damaged. Run `alp dashboard` again, or copy its whole address.",U2=new Set(["127.0.0.1","localhost"]),Nb=s=>typeof s=="string"&&D2.test(s);function H2(s){const t=String(s??"").replace(/^#/,"");if(!t)return;const i=new URLSearchParams(t);if(!i.has("token"))return;const a=i.get("token");return Nb(a)?{token:a}:{malformed:!0}}const Tb=s=>s.protocol==="http:"&&U2.has(s.hostname);function I2(s){let t;try{t=s?.getItem(Pf)}catch{return}if(t!=null){if(Nb(t))return t;Kr(s)}}function Kr(s){try{s?.removeItem(Pf)}catch{}}function Ab({location:s,history:t,storage:i}){const a=H2(s.hash);a&&t.replaceState(t.state,"",`${s.pathname}${s.search}`);const l=Tb(s);if(a&&("malformed"in a||!l))return Kr(i),{error:"malformed"in a?$2:B2};if(a){try{i?.setItem(Pf,a.token)}catch{}return{url:s.origin,token:a.token}}if(!l)return;const u=I2(i);return u?{url:s.origin,token:u}:void 0}const G2="http://127.0.0.1:7434",Cb=({location:s,dev:t=!1})=>!t&&Tb(s);function Y2({location:s,remembered:t,dev:i=!1}){return t||(Cb({location:s,dev:i})?s.origin:G2)}function sc(s=16){const t=new Uint8Array(Math.ceil(s/2));return globalThis.crypto.getRandomValues(t),Array.from(t,i=>i.toString(16).padStart(2,"0")).join("").slice(0,s)}const V2=()=>`web_${sc(16)}`,Tl=()=>`web-msg-${sc(20)}`,K2=()=>`web-task-${sc(16)}`,Qf=()=>`web-conv-${sc(16)}`,F2="Files in the workspace are not changed or restored: only the conversation goes back.",X2="Files are not copied: the fork works on the current files of where it runs.",yf={runtime_unsupported:"This session runs on a runtime that cannot fork or rewind its conversation.",not_persistent:"This session keeps no native conversation to fork or rewind.",not_root:"Only a main conversation can be forked or rewound; an agent's work belongs to its requester."},Al=Object.freeze({session_busy:"The session or one of its agents is still working. Wait until everything is idle, then try again.",stale_generation:"The conversation changed since this view loaded. It was reloaded; check it and try again.",turn_not_found:"That message is no longer part of this conversation. It was reloaded; try again.",turn_in_progress:"A turn is still running. Wait until it ends, then try again.",empty_prefix:"Nothing comes before the first message. Start a new session instead.",boundary_unmapped:"The agent's runtime cannot go back to exactly this point (that turn was not started by ALP). Choose another message.",runtime_unsupported:yf.runtime_unsupported,native_refused:"The agent's runtime refused it. Nothing changed.",outcome_unknown:"The host cannot tell whether it happened. Check the session list and this conversation before trying again; a new attempt is a new request.",key_conflict:"That request id was already used for something else. Try again.",branch_not_found:"That branch is no longer kept on the host.",not_root:yf.not_root,outside_workspace:"That workspace is not granted to your access token.",attachment_forbidden:"This conversation holds an attachment your access token may not use.",request_conflict:"A session with that id already exists.",persistence_failed:"The host could not finish saving it. Trying again finishes it.",invalid_params:"The host did not accept this request for this session. Reload the page and try again; if it keeps happening, this app and the host may run different versions of ALP."}),P2=s=>typeof s?.data?.reason=="string"?s.data.reason:void 0;function ei(s){const t=s,i=P2(t),a=typeof t?.code=="number"?t.code:void 0,l=Be(s),u=l.sent!=="yes"&&i!=="outcome_unknown",d=i==="stale_generation"||i==="turn_not_found";if(i==="persistence_failed")return{message:Al.persistence_failed,reason:i,code:a,retrySame:!0,reload:!1};if(a===1003&&i==="grant")return{message:`Your access token cannot do this (it needs ${typeof t?.data?.permission=="string"?t.data.permission:"session.write"}).`,reason:i,code:a,retrySame:!1,reload:!1};if(a===1003&&i==="mode"){const h=Array.isArray(t?.data?.modes)?t.data.modes.filter(m=>typeof m=="string"):[];return{message:`Your access token cannot drive this conversation in its mode${h.length?` (it may use ${h.join(", ")})`:""}. Ask the host owner for a token with that mode.`,reason:i,code:a,retrySame:!1,reload:!1}}if(i&&Al[i])return{message:Al[i],reason:i,code:a,retrySame:!1,reload:d};if(u){const h=l.sent==="no"?" Trying again is safe.":" It may have happened: trying again sends the same request, which the host answers only once.";return{message:`${l.message}${l.terminal?"":h}`,...i?{reason:i}:{},code:a,retrySame:!l.terminal,reload:!1}}return a===-32601?{message:"This host does not offer it. Update ALP on the host.",code:a,retrySame:!1,reload:!1}:a===-32602?{message:Al.invalid_params,...i?{reason:i}:{},code:a,retrySame:!1,reload:!1}:{message:s instanceof Error&&s.message?s.message:"Something went wrong.",...i?{reason:i}:{},code:a,retrySame:!1,reload:d}}function Q2({capabilities:s,canRead:t,canWrite:i,summary:a,busy:l=!1,generation:u,online:d=!0,driveBlock:h}){const m=a?.conversation,p=(k=void 0)=>({shown:!1,...k?{reason:k}:{}}),x=m?.reason?yf[m.reason]??`Not available here (${m.reason}).`:void 0,y=s.includes("session.history")&&!!u,w=k=>s.includes(`session.${k}`)?!m||m[k]!==!0?p(x):!i||k==="fork"&&!t?p("Your access token cannot change this conversation (it needs session.write)."):h?p(h):y?d?k==="rewind"&&l?{shown:!0,reason:"Wait until main and its agents are idle."}:{shown:!0}:{shown:!0,reason:"Reconnecting…"}:p("This host does not keep a history generation for this view."):p();return{fork:w("fork"),rewind:w("rewind")}}const W2="Restart the agent's process on the same conversation and settings, for example after a new sign-in. Its messages, history and files stay.",Fr=Object.freeze({session_busy:"The agent or one of its agents is still working. Wait until everything is idle, then reload.",session_closed:"The session is closed. Send it a message to open it again on its conversation.",no_history:"The agent has no conversation to keep yet. Send it a message first, or start a new session.",native_refused:"The agent could not be restarted on its conversation. The session was closed with its conversation kept; send it a message to open it again.",runtime_unsupported:"This session runs on a runtime the host cannot reload.",not_root:"Only the main agent of a session can be reloaded."});function Z2(s){const t=ei(s),i=t.reason?Fr[t.reason]:void 0;return i?{...t,message:i}:t}const J2="Main writes a checkpoint of its work, then its context is compacted (or a fresh conversation starts from the checkpoint). Its session, history and files stay; while it is busy, this waits for the end of its turn.",Wf=Object.freeze({session_busy:"The session is not open. Send it a message to open it, then compact it.",session_closed:"The session is closed. Send it a message to open it, then compact it.",runtime_unsupported:"Only the main agent of a session can be compacted.",not_root:"Only the main agent of a session can be compacted."});function ej(s){return s==="deferred"?"Compaction will start when the main agent finishes its current turn.":s==="running"?"The main agent is already compacting its context.":"Compacting the main agent's context: it writes a checkpoint first."}function tj(s){const t=ei(s),i=t.reason?Wf[t.reason]:void 0;return i?{...t,message:i}:t}function nj({capabilities:s,canRead:t,canWrite:i,summary:a,root:l,closed:u=!1,busy:d=!1,generation:h,online:m=!0,driveBlock:p}){const x=j=>({shown:!0,enabled:!1,reason:j}),y=s.includes("session.resumeCommand")?t?m?{shown:!0,enabled:!0}:x("Reconnecting…"):x("Your access token cannot read this session."):{shown:!1,enabled:!1},w=()=>{if(!s.includes("session.reload"))return{shown:!1,enabled:!1};if(!l)return x(Fr.not_root);const j=a?.conversation;return j?.reload!==!0?x(j?.reason==="not_persistent"?"This session keeps no native conversation to reload.":Fr.runtime_unsupported):i?p?x(p):u?x(Fr.session_closed):!s.includes("session.history")||!h?x("The conversation is still loading."):m?d?x("Wait until main and its agents are idle."):{shown:!0,enabled:!0}:x("Reconnecting…"):x("Your access token cannot reload agents (it needs session.write).")},k=()=>l?i?p?x(p):u?x(Wf.session_closed):m?{shown:!0,enabled:!0}:x("Reconnecting…"):x("Your access token cannot compact agents (it needs session.write)."):{shown:!1,enabled:!1};return{reload:w(),compact:k(),resume:y}}function sj(s,t={}){const i=new Map,a=s.turnOrder??[];for(const l of s.entries){if(l.sessionId!==s.rootId)continue;const u=l.item;if(u.kind!=="user_message"||typeof u.clientMessageId!="string")continue;const d=s.prompts[u.clientMessageId];if(!d||d.state!=="accepted"||d.result!=="turn"||!d.turnId)continue;const h=a.indexOf(d.turnId);h<0||i.set(l.key,{turnId:d.turnId,index:h,later:a.length-h,rewindable:h>0||!!t.hasOlder,ended:s.turns[d.turnId]==="ended",text:typeof u.text=="string"?u.text:""})}return i}function Zf(s){return s?.kind!=="notice"||typeof s.id!="string"?null:s.id.startsWith("rewind:")&&s.id.length>7?{kind:"rewind",branchId:s.id.slice(7)}:s.id.startsWith("fork:")&&s.id.length>5?{kind:"fork",sessionId:s.id.slice(5)}:null}const ij=s=>`${s} later turn${s===1?"":"s"}`,aj=s=>`${s} turn${s===1?"":"s"}`;function rj(s,t,i){const a=t?.find(u=>u.branchId===i)?.turns;if(typeof a=="number")return a;const l=/(\d+) later turn/.exec(String(s?.text??""));return l?Number(l[1]):void 0}const Il=Object.freeze({capability:"This host does not offer Git changes. Update ALP on the host.",registry:"This host does not list its workspaces, so Git changes cannot be shown. Update ALP on the host.",projectRead:"This access token cannot read Git status (needs project.read).",filesRead:"This access token cannot read file contents, so diffs are hidden (needs files.read).",workspace:"Choose a workspace to see its changes.",unregistered:"This workspace is not registered on the host, so its Git changes cannot be shown. The host owner can add it as a project.",loading:"Loading workspaces…"}),Gl=Object.freeze({not_repository:"Not a git repository",unknown_ref:"The base branch is not known in this repository.",invalid_compare:"The host refused this comparison. Pick Uncommitted or a branch name Git accepts.",stale_snapshot:"The checkout changed since this list was loaded. It was loaded again from the start.",invalid_cursor:"The rest of this list is no longer available. It was loaded again from the start.",git_unavailable:"Git is not available on the host.",git_failed:"Git failed on the host. Try again; the host's logs may say why.",blocked_path:"This file is never shown remotely: secrets, keys, .git and ALP configuration are blocked.",invalid_path:"That is not a valid path in this workspace."}),Eb=Object.freeze([{id:"uncommitted",label:"Uncommitted"},{id:"base",label:"Committed"},{id:"staged",label:"Staged"},{id:"unstaged",label:"Unstaged"}]),Rx=Object.freeze({modified:"Modified",added:"New",deleted:"Deleted",renamed:"Renamed",copied:"Copied",typechange:"Type changed",untracked:"Untracked",conflicted:"Conflicted"}),oj=Object.freeze({modified:"M",added:"A",deleted:"D",renamed:"R",copied:"C",typechange:"T",untracked:"U",conflicted:"!"}),Mb=Object.freeze({binary:"Binary file",too_large:"Diff too large to display",withheld:"Content withheld: it looks like it holds a private key.",symlink:"Symbolic link: its target is not shown.",submodule:"Submodule: its content is not shown."});class ys extends Error{constructor(t){super(t.message),this.name="GitAccessError",this.failure=t,this.reason=t.reason}}function _i(s){if(s instanceof ys)return s.failure;const t=Be(s);if(t.code===1003&&t.reason==="grant"){const a=s?.data?.permission;return a==="files.read"?{...t,message:Il.filesRead}:a==="project.read"?{...t,message:Il.projectRead}:t}const i=t.reason?Gl[t.reason]:void 0;return i?{...t,message:i}:t}function lj(s){const t=_i(s);return t.code===1004&&t.reason==="stale_snapshot"||t.code===-32602&&t.reason==="invalid_cursor"}function Jf(s){const t=s.workspace;if(!t)return;const i=Ll(s.principal??void 0,t),a=new Set([t,...i?[i.path,i.canonical]:[]]);return s.registry.workspaces.filter(l=>a.has(l.directory)&&!l.archivedAt).sort((l,u)=>+!!u.pinnedAt-+!!l.pinnedAt||String(l.createdAt).localeCompare(String(u.createdAt))||l.id.localeCompare(u.id))[0]}function Gd(s){const t=l=>({status:!1,reason:l,message:Il[l]});if(!s.workspace)return t("workspace");if(!s.connection.capabilities.includes("workspace.git"))return t("capability");if(!Te(s.principal??void 0,"project.read"))return t("projectRead");if(!s.connection.capabilities.includes("workspace.registry"))return t("registry");const i=Jf(s);if(!i)return t(s.registry.loading?"loading":"unregistered");const a=Te(s.principal??void 0,"files.read");return{status:!0,workspaceId:i.id,content:a,...a?{}:{contentMessage:Il.filesRead}}}function cj(s){const t=typeof s=="string"&&s?Js(s):void 0;return t&&!$i(t)?t:void 0}function uj({mode:s,baseRef:t,ignoreWhitespace:i}){const a=Eb.some(l=>l.id===s)?s:"uncommitted";return{mode:a,...a==="base"&&t?{baseRef:t}:{},...i?{ignoreWhitespace:!0}:{}}}function _x(s,t){const i=Array.isArray(t?.files)?t.files:[],a=Number.isSafeInteger(t?.hiddenCount)&&t.hiddenCount>0?t.hiddenCount:0,l=s&&s.snapshot===t.snapshot?s:void 0;return{compare:t.compare,snapshot:t.snapshot,files:l?[...l.files,...i]:[...i],hiddenCount:(l?.hiddenCount??0)+a,truncated:t.truncated===!0,...typeof t.nextCursor=="string"&&t.nextCursor?{nextCursor:t.nextCursor}:{}}}function dj(s){const t=[];for(const i of Array.isArray(s?.hunks)?s.hunks:[]){t.push({type:"hunk",text:`@@ -${i.oldStart},${i.oldCount} +${i.newStart},${i.newCount} @@${i.context?` ${i.context}`:""}`});let a=i.oldStart,l=i.newStart;for(const u of Array.isArray(i.lines)?i.lines:[]){const d=u.noNewline===!0?{noNewline:!0}:{};u.type==="add"?t.push({type:"add",text:u.content,newLine:l++,...d}):u.type==="remove"?t.push({type:"remove",text:u.content,oldLine:a++,...d}):t.push({type:"context",text:u.content,oldLine:a++,newLine:l++,...d})}}return t}function fj(s){let t=0,i=0;for(const a of s)t+=a.additions||0,i+=a.deletions||0;return{additions:t,deletions:i}}function Lx(s){if(!Number.isFinite(s)||s<1e3)return String(Math.max(0,Math.floor(s||0)));const t=s/1e3;return`${t>=10?Math.round(t):Math.round(t*10)/10}k`}function Ox(s){const i=[s.branch??(s.detached&&s.head?`Detached at ${s.head.slice(0,7)}`:s.head?s.head.slice(0,7):"No commits yet")];if(s.upstream){const{ref:a,ahead:l,behind:u}=s.upstream;i.push(`${a}${l||u?` (${[l?`↑${l}`:"",u?`↓${u}`:""].filter(Boolean).join(" ")})`:""}`)}return i.join(" · ")}function hj(s){return s?s.replace(/^refs\/(heads|remotes)\//,"").trim():"base"}const zb=Object.freeze(["image/png","image/jpeg","image/gif","image/webp"]),Mi=Object.freeze({maxCount:4,maxBytes:2*1024*1024,maxTotalBytes:2.5*1024*1024});function mj(s,t=!0){const i={maxCount:0,maxBytes:0,maxTotalBytes:0};if(!t)return i;if(s===void 0)return{...Mi};if(!s||typeof s!="object"||Array.isArray(s))return i;const a=s;if(!["maxCount","maxBytes","maxTotalBytes"].every(u=>Number.isSafeInteger(a[u])&&a[u]>=0))return i;const l=Math.min(Mi.maxTotalBytes,a.maxTotalBytes);return{maxCount:Math.min(Mi.maxCount,a.maxCount),maxBytes:Math.min(Mi.maxBytes,l,a.maxBytes),maxTotalBytes:l}}const Li=s=>s>=1024*1024?`${(s/1024/1024).toFixed(1).replace(/\.0$/,"")} MB`:`${Math.max(1,Math.round(s/1024))} KB`;function Rb(s){const t=String(s?.type??"").split(";",1)[0].trim().toLowerCase(),i=t==="image/jpg"?"image/jpeg":t;return zb.includes(i)?i:null}function Dx(s){if(!s)return[];const t=Array.from(s.files??[]);return t.length?t:Array.from(s.items??[]).filter(i=>i?.kind==="file").map(i=>i.getAsFile?.()).filter(i=>!!i)}function pj(s){let t="";for(let i=0;i<s.length;i+=32768)t+=String.fromCharCode(...s.subarray(i,i+32768));return btoa(t)}let gj=0;function _b(s,t,i,a,l=Mi){const u=s.reduce((d,h)=>d+h.size,0);return i?!l.maxCount||!l.maxBytes||!l.maxTotalBytes?"This connection takes no images.":s.length>=l.maxCount?`A message carries at most ${l.maxCount} images.`:a>l.maxBytes?`${t} is ${Li(a)}; an image is at most ${Li(l.maxBytes)}.`:u+a>l.maxTotalBytes?`The images of a message are at most ${Li(l.maxTotalBytes)} together.`:null:`${t} is not a PNG, JPEG, GIF or WebP image.`}async function xj(s,t,i=Mi){const a=[];let l=null;for(const u of Array.from(t)){const d=String(u.name||"image"),h=Rb(u),m=_b([...s,...a],d,h,u.size,i);if(m||!h){l??=m;continue}let p;try{p=pj(new Uint8Array(await u.arrayBuffer()))}catch{l??=`Could not read ${d}.`;continue}a.push({id:`image-${++gj}`,type:"image",mimeType:h,data:p,name:d,size:u.size})}return{added:a,error:l}}function Xr(s,t,i=Mi){const a=[...s];let l=null;for(const u of t){const d=_b(a,u.name,u.mimeType,u.size,i);if(d){l??=d;continue}a.push(u)}return{attachments:a,error:l}}function yj(s,t=[]){return[...s.trim()||!t.length?[{type:"text",text:s}]:[],...t.map(i=>({type:"image",mimeType:i.mimeType,data:i.data,...i.name?{name:i.name.slice(0,255)}:{}}))]}const Lb=s=>`data:${s.mimeType};base64,${s.data}`,Ps=Object.freeze({maxObjectBytes:0,maxPerPrompt:0,maxPromptBytes:0,maxChunkBytes:0}),qx=["maxObjectBytes","maxPerPrompt","maxPromptBytes","maxChunkBytes"];function bj(s,t){if(!t||!s||typeof s!="object"||Array.isArray(s))return{...Ps};const i=s;if(!qx.every(h=>Number.isSafeInteger(i[h])&&i[h]>=0))return{...Ps};const[a,l,u,d]=qx.map(h=>i[h]);return!l||!u||!d?{...Ps}:{maxObjectBytes:Math.min(a,u),maxPerPrompt:l,maxPromptBytes:u,maxChunkBytes:d}}const Ob=s=>s<1024?`${s} B`:Li(s),Db=s=>!!s&&s.maxPerPrompt>0&&s.maxPromptBytes>0&&s.maxChunkBytes>0;function vj({capable:s,permitted:t,writable:i,limits:a,session:l,known:u=!0}){if(!s)return"The host behind this gateway does not store files.";if(!i)return"Your access token cannot send messages.";if(!t)return"Your access token cannot upload files (it needs attachments.write).";if(!Db(a))return"This connection takes no files.";if(!u)return null;const d=l?.promptAttachments;if(!Array.isArray(d)||!d.length){const h=typeof l?.agent=="string"?l.agent:"This agent",m=typeof l?.runtime=="string"?l.runtime:"a runtime";return`${h} runs on ${m} here, which cannot read attached files.`}return null}function wj(s){const t=String(s??"").normalize("NFC").replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}/\\]/gu,"").trim();let i="",a=0;for(const l of t){const u=new TextEncoder().encode(l).length;if(a+u>255)break;i+=l,a+=u}return i.trim()||"file"}const kj=/^[a-z0-9][a-z0-9!#$&^_.+-]{0,126}\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}$/;function jj(s){const t=String(s?.type??"").split(";",1)[0].trim().toLowerCase();return kj.test(t)?t:"application/octet-stream"}function qb(s,t,i,a){const l=s.reduce((u,d)=>u+d.size,0);return Db(a)?s.length>=a.maxPerPrompt?`A message carries at most ${a.maxPerPrompt} files.`:i>a.maxObjectBytes?`${t} is ${Li(i)}; a file is at most ${Li(a.maxObjectBytes)}.`:l+i>a.maxPromptBytes?`The files of a message are at most ${Li(a.maxPromptBytes)} together.`:null:"This connection takes no files."}let Sj=0;async function Nj(s,t,i){const a=[];let l=null;for(const u of Array.from(t)){const d=wj(u.name),h=qb([...s,...a],d,u.size,i);if(h){l??=h;continue}let m;try{m=new Uint8Array(await u.arrayBuffer())}catch{l??=`Could not read ${d}.`;continue}a.push({id:`file-${++Sj}`,type:"file",name:d,mimeType:jj(u),size:m.length,data:m})}return{added:a,error:l}}function Ol(s,t,i){const a=[...s];let l=null;for(const u of t){const d=qb(a,u.name,u.size,i);if(d){l??=d;continue}a.push(u)}return{attachments:a,error:l}}const Bx=(s,t,i=0)=>`${s}:file-${t}${i?`.${i}`:""}`;async function Tj(s,{sessionId:t,file:i,requestId:a,digest:l}){try{const u=await s.begin({sessionId:t,name:i.name,size:i.data.length,mimeType:i.mimeType,sha256:await l(i.data),requestId:a});return u?.state!=="uploading"||typeof u.uploadId!="string"?!1:(await s.abort(u.uploadId),!0)}catch{return!1}}function Aj(s,t=[],i=[]){const a=yj(s,t);if(!i.length)return a;if(i.some(l=>typeof l.attachmentId!="string"))throw new Error("A file of this message is not uploaded yet.");return[...s.trim()?[{type:"text",text:s}]:[],...t.map(l=>({type:"image",mimeType:l.mimeType,data:l.data,...l.name?{name:l.name.slice(0,255)}:{}})),...i.map(l=>({type:"attachment",attachmentId:l.attachmentId}))]}function Cj(s){return Array.isArray(s)?s.filter(t=>t&&typeof t=="object"&&typeof t.attachmentId=="string"&&typeof t.name=="string"&&Number.isSafeInteger(t.size)&&t.size>=0).map(t=>({attachmentId:t.attachmentId,name:t.name,size:t.size})):[]}function bs(s){return{rootId:s,cursor:0,entries:[],positions:{},sessions:{},order:[],running:{},closed:{},questions:{},prompts:{},turns:{},turnOrder:[],historyUnavailable:!1,reset:0}}function Yd(s,t){const i=s.positions[t.key];if(i!==void 0){const a=s.entries.slice();return a[i]=t,{...s,entries:a}}return{...s,entries:[...s.entries,t],positions:{...s.positions,[t.key]:s.entries.length}}}const Ea=(s,t)=>{if(!(t in s))return s;const i={...s};return delete i[t],i};function $x(s,t){if(typeof t!="string"||!t)return s;const i=s.turnOrder??[];return i.includes(t)?s:{...s,turnOrder:[...i,t]}}function zi(s,t){if(!t||typeof t!="object"||!t.event||typeof t.sessionId!="string")return s;const i=typeof t.cursor=="number";if(i&&t.cursor<=s.cursor)return s;let a=i?{...s,cursor:t.cursor}:s;const l=t.sessionId,u=typeof t.ts=="string"?t.ts:"",d=t.event;d.type==="item"&&!a.sessions[l]&&(a={...a,sessions:{...a.sessions,[l]:{id:l}},order:a.order.includes(l)?a.order:[...a.order,l]});const h=()=>`${l}:${d.type}:${t.cursor??`${t.epoch}:${t.seq}`}`;switch(d.type){case"session.opened":case"session.updated":{const m=d.session&&typeof d.session=="object"?d.session:{},p=a.sessions[l];return a={...a,sessions:{...a.sessions,[l]:{...p,...m,id:l,...d.type==="session.opened"?{status:m.busy?"running":"idle"}:{}}},order:a.order.includes(l)?a.order:[...a.order,l]},d.type==="session.opened"&&(a={...a,closed:Ea(a.closed,l)}),a}case"session.closed":{const m=a.sessions[l];return{...a,closed:{...a.closed,[l]:!0},running:Ea(a.running,l),questions:Object.fromEntries(Object.entries(a.questions).filter(([,p])=>p.sessionId!==l)),sessions:m?{...a.sessions,[l]:{...m,status:"closed",busy:!1}}:a.sessions}}case"session.failed":return Yd(a,{key:h(),sessionId:l,ts:u,item:{kind:"session_event",id:h(),level:"error",text:d.error?.message?`The session failed: ${d.error.message}`:"The session failed."}});case"prompt.accepted":{if(typeof d.clientMessageId!="string")return a;const m=d.result==="turn"||d.result==="steer"?d.result:void 0;return a={...a,prompts:{...a.prompts,[d.clientMessageId]:{state:"accepted",...typeof d.turnId=="string"?{turnId:d.turnId}:{},...m?{result:m}:{}}}},m==="turn"&&l===a.rootId?$x(a,d.turnId):a}case"prompt.failed":return typeof d.clientMessageId=="string"?{...a,prompts:{...a.prompts,[d.clientMessageId]:{state:"failed",...d.error?.code?{errorCode:d.error.code}:{},...d.error?.message?{error:d.error.message}:{}}}}:a;case"turn.started":{l===a.rootId&&(a=$x(a,d.turnId));const m=a.sessions[l],p=a.turns[d.turnId]==="ended"?a.turns:{...a.turns,[String(d.turnId)]:"running"};return{...a,turns:p,running:{...a.running,[l]:String(d.turnId)},...m?{sessions:{...a.sessions,[l]:{...m,status:"running",busy:!0}}}:{}}}case"turn.ended":{const m=a.sessions[l];return a={...a,running:Ea(a.running,l),turns:{...a.turns,[String(d.turnId)]:"ended"},...m&&m.status!=="closed"?{sessions:{...a.sessions,[l]:{...m,status:"idle"}}}:{}},(d.state==="failed"||d.state==="canceled")&&(a=Yd(a,{key:h(),sessionId:l,ts:u,item:{kind:"turn_end",id:h(),state:d.state,...d.error?.message?{error:d.error.message}:{}}})),a}case"item":{const m=d.item;return!m||typeof m!="object"||typeof m.id!="string"||typeof m.kind!="string"||!["user_message","assistant_message","notice","tool_call","todo","compaction"].includes(m.kind)?a:Yd(a,{key:`${l}:${m.id}`,sessionId:l,ts:u,item:m})}case"usage":{const m=a.sessions[l];return!d.usage||typeof d.usage!="object"||Array.isArray(d.usage)?a:{...a,sessions:{...a.sessions,[l]:{...m,id:l,usage:d.usage}}}}case"question":{const m=d.question;return!m||typeof m.id!="string"?a:{...a,questions:{...a.questions,[m.id]:m}}}case"question.resolved":return typeof d.questionId=="string"?{...a,questions:Ea(a.questions,d.questionId)}:a;default:return a}}function Ux(s,t,i){let a=t.reset?{...bs(s.rootId),reset:s.reset+1}:{...s,questions:{}};const l=i.filter(p=>typeof p?.cursor=="number").sort((p,x)=>p.cursor-x.cursor),u=i.filter(p=>typeof p?.cursor!="number"),d=a.cursor;for(const p of l)a=zi(a,p);for(const p of u)a=zi(a,p);const h=t.session,m=a.rootId;if(h&&(h.id===void 0||h.id===m)){const p=a.sessions[m];a={...a,sessions:{...a.sessions,[m]:{...p,...h,id:m}},order:a.order.includes(m)?a.order:[m,...a.order]},h.status==="closed"?a={...a,closed:{...a.closed,[m]:!0},running:Ea(a.running,m)}:h.status==="idle"&&!h.busy&&(a={...a,running:Ea(a.running,m)})}return t.reset&&(a={...a,historyUnavailable:a.cursor===d}),a}function Bb(s){return(s.order.includes(s.rootId)?s.order:[s.rootId,...s.order]).map(i=>({id:i,session:s.sessions[i],running:i in s.running,closed:!!s.closed[i]}))}function Ej(s,t){return s.entries.filter(i=>i.sessionId===t)}function Hx(s,t){const i=s.prompts[t];if(!i)return!1;if(i.state==="failed")return i.errorCode!=="outcome_unknown";const a=Object.values(s.running);if(!i.turnId)return a.length===0;const l=s.turns[i.turnId];return l==="ended"||l==="running"&&!a.includes(i.turnId)}function Ix(s){const t=new Set;for(const i of s.entries)i.item.kind==="user_message"&&typeof i.item.clientMessageId=="string"&&t.add(i.item.clientMessageId);return t}function bf(s,t){return s.oversized?{sessionId:t,epoch:"history",seq:s.cursor,cursor:s.cursor,ts:"",event:{type:"item",item:{kind:"notice",id:`oversized:${s.cursor}`,level:"warning",text:`History event ${s.cursor} is too large to display (${s.oversized.bytes} bytes).`}}}:s}function Mj(s,t){let i=bs(s.rootId);for(const d of t)i=zi(i,bf(d,s.rootId));const a=i.entries.slice(),l={...i.positions};for(const d of s.entries){const h=l[d.key];h!==void 0?a[h]=d:(l[d.key]=a.length,a.push(d))}const u={...i.sessions};for(const[d,h]of Object.entries(s.sessions))u[d]={...u[d],...h};return{...s,entries:a,positions:l,sessions:u,order:[...new Set([...i.order,...s.order])],prompts:{...i.prompts,...s.prompts},turns:{...i.turns,...s.turns},turnOrder:[...new Set([...i.turnOrder,...s.turnOrder??[]])]}}const zj={codex:"Codex",claude:"Claude",acp:"ACP",antigravity:"Antigravity"},Rj={"read-only":"Read only","workspace-write":"Workspace write","full-access":"Full access"},$b=s=>s==="custom"?"Custom":s,on=s=>typeof s=="string"&&s.trim()?s:void 0;function Gx(s){if(!Array.isArray(s))return[];const t=new Map;for(const i of s){const a=on(i?.id);if(!a||t.has(a))continue;const l=Array.isArray(i.efforts)?[...new Set(i.efforts.filter(d=>!!on(d)))]:[],u=on(i.effort);t.set(a,{id:a,label:on(i.label)??a,efforts:l,...u&&l.includes(u)?{effort:u}:{}})}return[...t.values()]}function Xs(s){if(s.replace(/[\s_-]+/g,"").toLowerCase()==="xhigh")return"Extra high";const i=s.replace(/[_-]+/g," ").replace(/\s+/g," ").trim();return i?i.charAt(0).toUpperCase()+i.slice(1).toLowerCase():s}function Ub(s,t,i){if(t)return s.find(l=>l.id===t);if(!i?.model)return;const a=i.runtime?`${i.runtime}:${i.model}`:i.model;return s.find(l=>l.id===a)??s.find(l=>l.id===i.model)}function Hb(s){return(s?.efforts??[]).map(t=>({id:t,label:Xs(t)}))}function _j(s,t){return t&&s?.efforts.includes(t)?t:void 0}function Yx(s,t){const i=t.team&&s.teams.some(d=>d.id===t.team)?t.team:void 0,a=t.mode&&s.modes.some(d=>d.id===t.mode)?t.mode:s.defaultMode??s.modes[0]?.id,l=t.model?s.models.find(d=>d.id===t.model):void 0,u=t.thinkingByModel?.[l?.id??"default"];return{...i?{team:i}:{},...a?{mode:a}:{},...l?{model:l.id}:{},...u&&(!l||l.efforts.includes(u))?{thinking:u}:{}}}function Vx(s,t,{persist:i=!1}={}){return{cwd:s,...i?{persist:!0}:{},...t.team?{workflow:t.team}:{},...t.mode?{mode:t.mode}:{},...t.model?{model:t.model}:{},...t.thinking?{thinking:t.thinking}:{}}}function Lj(s){const t=s?.preview;if(!t||typeof t!="object")return;const i=on(t.team),a=on(t.agent);return!i||!a?void 0:{teams:Array.isArray(t.teams)?t.teams.filter(u=>on(u?.id)).map(u=>({id:u.id,label:on(u.label)??u.id,...on(u.description)?{description:u.description}:{}})):[],team:i,agent:a,...on(t.teamLabel)?{teamLabel:t.teamLabel}:{},runtime:on(t.runtime)??"",model:on(t.model)??"",mode:on(t.mode)??"",thinking:on(t.thinking)??""}}function Oj(s,t=[]){const i=Ub(t,void 0,s),a=[{key:"team",label:"Team",value:s.teamLabel??s.teams.find(l=>l.id===s.team)?.label??$b(s.team)},{key:"agent",label:"Agent",value:s.agent}];return s.runtime&&a.push({key:"runtime",label:"Runtime",value:zj[s.runtime]??s.runtime}),s.model&&a.push({key:"model",label:"Model",value:i?.label??s.model}),s.thinking&&a.push({key:"thinking",label:"Thinking",value:Xs(s.thinking)}),s.mode&&a.push({key:"mode",label:"Permissions",value:Rj[s.mode]??s.mode}),a}function Ib(s){return JSON.stringify([typeof s?.workflow=="string"?s.workflow:"",typeof s?.model=="string"?s.model:""])}function Kx(s,t){if(!(!t||s.some(i=>i.id===t.team)))return{id:t.team,label:t.teamLabel??$b(t.team)}}function Dj(s,t){return t&&!s.some(i=>i.id===t.id)?[t,...s]:s}function qj({chosen:s,previewTeam:t,previewSettled:i,previewError:a,previewBlocked:l,previewNeedsRead:u,teams:d,teamsKnown:h,teamsUnavailable:m}){return s?{team:s}:t?{team:t}:i?d.length?{team:d[0].id}:h?{}:{wait:Bj({previewError:a,previewBlocked:l,previewNeedsRead:u,teamsUnavailable:m}),stuck:!0}:{wait:"Checking what would run…"}}function Bj({previewError:s,previewBlocked:t,previewNeedsRead:i,teamsUnavailable:a}){const l=a?.reason==="capability"?"this host does not list teams (no team capability)":a?.reason==="permission"?"your access token cannot list teams (it lacks project.read)":a?.reason==="failed"?`the team list failed${a.message?` (${Vd(a.message)})`:""}`:"the team list is not available",u=t?`the preview is not available${s?` (${Vd(s)})`:""}`:`the preview failed${s?` (${Vd(s)})`:""}`,d=[];(a?.reason==="failed"||!t)&&d.push("use Retry in the preview to ask again");const h=[];a?.reason==="permission"&&h.push("project.read"),t&&i&&h.push("session.read"),h.length&&d.push(`reconnect with a token that has ${h.join(" or ")}`),d.length||d.push("connect to a host that lists teams or previews sessions");const m=d.join(", or ");return`Cannot tell which team would run: ${l}, and ${u}. To start, ${m}.`}function Vd(s){return String(s).trim().replace(/[.。]+$/,"")}function $j(s,t,i){return String(t??"").trim()?`${s} Your first message was not sent; it is back in the New session box${i?` of ${i}`:""}.`:s}async function Uj(s,t,i,{mounted:a,describe:l,nameOf:u}){const d=s.startOrigin();try{return await s.createSession(t)}catch(h){throw a()||(i.trim()&&s.keepUnsentDraft(i,d),s.notify("error",$j(l(h).message,i,d.workspace?u(d.workspace):void 0))),h}}const Gb="session.configure.live",Ma=Object.freeze({session_busy:"The session or one of its agents is working. Wait until everything is idle, then try again.",session_closed:"The session is closed. Send it a message to open it, then change its configuration.",not_root:"Only the main agent of a session can be changed; an agent keeps the team and model it started with.",not_persistent:"This session is not kept, so it cannot continue its conversation with a new configuration.",runtime_unsupported:"The host cannot change this session's model or team while it runs. Start a new session instead.",runtime_mismatch:"A session keeps its runtime. To use another runtime's model, start a new session with it.",agent_mismatch:"That team runs another main agent. Start a new session with that team.",permission_escalation:"The change would give the session more permissions or new commands than it has. Start a new session for it.",team_not_found:"The host defines no such team for this project.",invalid_params:"The host does not offer this model or thinking for this session.",native_refused:"The agent's runtime did not take the new configuration. The session keeps its own.",stale_generation:"The conversation changed since this view loaded. It was reloaded; try again.",key_conflict:"That request id was already used for something else. Try again.",outcome_unknown:"The host cannot tell whether the change happened. Check the session before trying again.",persistence_failed:"The host could not store the change. Check the session before trying again.",turn_in_progress:"A turn of this conversation has not ended. Try again when it has."}),Yb=new Set(["runtime_mismatch","agent_mismatch","permission_escalation","runtime_unsupported"]);function Fx(s){const t=ei(s),a=s?.data?.action==="session.create",l=t.reason?Ma[t.reason]:void 0,u=t.reason==="grant"?t.message:l??t.message;return{...t,message:u,newSession:a||!!t.reason&&Yb.has(t.reason)}}const Hj=s=>/^([a-z]+)[:/]/.exec(s)?.[1];function Ij(s,t){const i=t.runtime,a=i?s.filter(u=>Hj(u.id)===i):[],l=t.model?a.find(u=>u.id===`${i}:${t.model}`)??a.find(u=>u.id===t.model):void 0;return{same:a,current:l,others:s.length-a.length}}function Gj({capabilities:s,canWrite:t,canTeam:i,summary:a,closed:l=!1,busy:u=!1,configuring:d=!1,generation:h,online:m=!0,driveBlock:p}){const x=A=>({enabled:!1,reason:A});if(!s.includes(Gb)){const A="Set when the session started: this host cannot change it on a running session.";return{shown:!1,reason:A,model:x(A),thinking:x(A),team:x(A)}}const y=a?.conversation,k=(()=>{if(y?.configure!==!0)return y?.reason==="not_persistent"?Ma.not_persistent:y?.reason==="not_root"?Ma.not_root:Ma.runtime_unsupported;if(!t)return"Your access token cannot change this session (it needs session.write).";if(p)return p;if(l)return Ma.session_closed;if(!s.includes("session.history")||!h)return"The conversation is still loading.";if(!m)return"Reconnecting…";if(d)return"Applying the last change…";if(u)return"Wait until main and its agents are idle."})(),j=k?x(k):{enabled:!0},S=k?x(k):i?{enabled:!0}:x("Your access token cannot change the team (it needs session.team.write).");return{shown:!0,model:j,thinking:j,team:S}}function Yj(s,t){if(!t)return s;const i=s?.workflow&&typeof s.workflow=="object"?s.workflow:{};return{...s,model:t.model,thinking:t.thinking,mode:t.mode,runtime:t.runtime,workflow:{...i,mode:t.team,supervisor:t.supervisor,...typeof t.maxPeers=="number"?{maxPeers:t.maxPeers}:{}},teamLabel:t.teamLabel??s?.teamLabel??(t.team==="custom"?void 0:t.team)}}function Vj(s,t,i){const a=s.effective,u=`${a.teamLabel??a.team} · main runs ${i??a.model}${a.thinking?` · ${t(a.thinking)}`:""}`;return s.status==="unchanged"?`Nothing to change: ${u}.`:`Changed: ${u}.${s.restarted?" The agent restarted on the same conversation.":""}`}const eh="alp-web:preferences",vf=1,Kj=["interrupt","steer","queue"],Fj=["enter","mod-enter"],Xj=["system","light","dark","zinc","midnight","claude","ghostty","pureBlack"],Pj=["full","collapseToolCalls","collapseTurns"],Qj=["github","catppuccin","dracula","tokyo-night","one","nord","gruvbox","solarized"],On=Object.freeze({uiFontSize:[10,21,14],contentFontSize:[10,21,15],codeFontSize:[9,22,12],contentMaxWidth:[600,4e3,820],terminalScrollback:[0,1e6,1e4]}),Wj=200,Vb=Object.freeze({header:["new-session","history","search"],footer:["tasks"]}),Kb=new Set(["tasks"]),so=s=>Vb[s].map(t=>({id:t,visible:!Kb.has(t)})),Fb=Object.freeze({grouping:"project",sort:"created",titleSource:"title",rowItems:Object.freeze({branch:!1,project:!1,host:!0,labels:!0}),trailing:"timestamp",projectFilters:[]}),Zj=64;function Xx(s){const t=qi(s)?s:{},i=qi(t.rowItems)?t.rowItems:{},a=Fb;return{grouping:t.grouping==="status"?"status":"project",sort:t.sort==="lastPrompt"?"lastPrompt":"created",titleSource:t.titleSource==="branch"?"branch":"title",rowItems:Object.fromEntries(Object.entries(a.rowItems).map(([l,u])=>[l,typeof i[l]=="boolean"?i[l]:u])),trailing:t.trailing==="none"?"none":"timestamp",projectFilters:[...new Set(Array.isArray(t.projectFilters)?t.projectFilters.filter(l=>typeof l=="string"&&l&&l.length<=4096):[])].slice(0,Zj)}}const Kd=Object.freeze({sendBehavior:"steer",sendShortcut:"enter",theme:"system",uiFontFamily:"",monoFontFamily:"",uiFontSize:14,contentFontSize:15,codeFontSize:12,contentMaxWidth:null,syntaxTheme:"one",chatDisplay:"collapseTurns",chatOutline:!0,terminalScrollback:1e4,sidebar:Object.freeze({header:so("header"),footer:so("footer")}),sidebarDisplay:Fb,newSession:Object.freeze({})});function Br(s,[t,i,a]){return typeof s=="number"&&Number.isFinite(s)?Math.min(i,Math.max(t,Math.round(s))):a}function Px(s){if(typeof s!="string")return"";const t=s.trim();return t.length<=Wj&&!/[;{}<>\\()]/.test(t)?t:""}function Qx(s,t){const i=Vb[t],a=[];for(const l of Array.isArray(s)?s:[])qi(l)&&i.includes(l.id)&&!a.some(u=>u.id===l.id)&&a.push({id:l.id,visible:typeof l.visible=="boolean"?l.visible:!Kb.has(l.id)});for(const l of so(t))a.some(u=>u.id===l.id)||a.push(l);return a}const Jj=200,eS=64,qi=s=>!!s&&typeof s=="object"&&!Array.isArray(s),Fd=s=>typeof s=="string"&&s.trim()&&s.length<=Jj?s:void 0;function Xb(s){if(!qi(s))return{};const t=s,i={};for(const a of["team","mode","model"]){const l=Fd(t[a]);l&&(i[a]=l)}if(qi(t.thinkingByModel)){const a={};for(const[l,u]of Object.entries(t.thinkingByModel).slice(0,eS)){const d=Fd(u);Fd(l)&&d&&!Object.hasOwn(Object.prototype,l)&&(a[l]=d)}Object.keys(a).length&&(i.thinkingByModel=a)}return i}function Oi(s){const t=()=>({...Kd,sidebar:{header:so("header"),footer:so("footer")},sidebarDisplay:Xx(null),newSession:{}});if(typeof s!="string"||!s)return t();let i;try{i=JSON.parse(s)}catch{return t()}if(!qi(i)||i.v!==vf)return t();const a=(u,d)=>u.includes(i[d])?i[d]:Kd[d],l=qi(i.sidebar)?i.sidebar:{};return{sendBehavior:a(Kj,"sendBehavior"),sendShortcut:a(Fj,"sendShortcut"),theme:a(Xj,"theme"),uiFontFamily:Px(i.uiFontFamily),monoFontFamily:Px(i.monoFontFamily),uiFontSize:Br(i.uiFontSize,On.uiFontSize),contentFontSize:Br(i.contentFontSize,On.contentFontSize),codeFontSize:Br(i.codeFontSize,On.codeFontSize),contentMaxWidth:typeof i.contentMaxWidth=="number"&&Number.isFinite(i.contentMaxWidth)?Br(i.contentMaxWidth,On.contentMaxWidth):null,syntaxTheme:a(Qj,"syntaxTheme"),chatDisplay:a(Pj,"chatDisplay"),chatOutline:typeof i.chatOutline=="boolean"?i.chatOutline:Kd.chatOutline,terminalScrollback:Br(i.terminalScrollback,On.terminalScrollback),sidebar:{header:Qx(l.header,"header"),footer:Qx(l.footer,"footer")},sidebarDisplay:Xx(i.sidebarDisplay),newSession:Xb(i.newSession)}}const tS=["sendBehavior","sendShortcut","theme","uiFontFamily","monoFontFamily","uiFontSize","contentFontSize","codeFontSize","contentMaxWidth","syntaxTheme","chatDisplay","chatOutline","terminalScrollback","sidebar","sidebarDisplay","newSession"];function nS(s){const t=Oi(JSON.stringify({...s,v:vf}));return JSON.stringify({v:vf,...Object.fromEntries(tS.map(i=>[i,t[i]]))})}function Wx(s){if(!s)return Oi(null);try{return Oi(s.getItem(eh))}catch{return Oi(null)}}function sS(s,t){if(!s)return!1;try{return s.setItem(eh,nS(t)),!0}catch{return!1}}function iS(s,t){const i={...s.thinkingByModel??{}},a=t.model||"default";return t.thinking?i[a]=t.thinking:delete i[a],Xb({team:t.team,mode:t.mode,model:t.model,thinkingByModel:i})}const io=Object.freeze({capability:"The host has not allowed remote terminals (its owner runs: alp terminal allow --yes)",permission:"Your access token cannot open terminals (it needs terminal.exec)",workspace:"Open a workspace to use a terminal.",registry:"This host does not list its workspaces, so it cannot open a terminal here. Update ALP on the host.",loading:"Loading the host's workspaces…",unregistered:"This workspace is not in the host's workspace list, so a terminal cannot open here.",offline:"Not connected to the host."}),VC="This shell runs on the daemon host as the account that runs alpd. The workspace is not a sandbox: the shell can read and write anything that account can, and use the network.",aS=Object.freeze({"root-only":"Limited protection on this Linux host: closing the terminal may not stop background processes.",none:"Process cleanup is not guaranteed on Windows: closing the terminal may not stop background processes."});function KC(s){return s==="root-only"||s==="none"?aS[s]:void 0}const FC="Runs on the daemon host as the account that runs alpd · the workspace is not a sandbox",Zx={terminal_disabled:io.capability,terminal_unsupported:"Terminals are not available on the daemon host (its terminal owner did not load).",terminal_limit:"Too many terminals are open on the host. Close one and try again.",input_too_large:"That input was too large for the terminal."},rS={closed:"closed",idle:"ended after being idle",lifetime:"reached its maximum lifetime",detached:"nobody reattached in time",revoked:"access was revoked",disabled:"the host turned terminals off",shutdown:"the host stopped"};function XC(s){const t=[];return Number.isSafeInteger(s.exitCode)&&t.push(`code ${s.exitCode}`),Number.isSafeInteger(s.signal)&&s.signal&&t.push(`signal ${s.signal}`),s.reason&&s.reason!=="exited"&&t.push(rS[s.reason]??s.reason),t.length?`Process exited (${t.join(" / ")})`:"Process exited"}const Jx=(s,t)=>{const i=t-s+1;return`\r
15
15
  \x1B[2m[output lost: ${i} output ${i===1?"event":"events"} (#${s}${i>1?`–${t}`:""}) are no longer kept by the host]\x1B[0m\r
16
16
  `};function wf(s){const t=s&&typeof s=="object"?s:{},i=a=>{const l=t[a];return Number.isSafeInteger(l)&&l>=1?Math.min(l,Ci[a]):Ci[a]};return{maxPerPrincipal:i("maxPerPrincipal"),maxPerDaemon:i("maxPerDaemon"),maxInputBytes:i("maxInputBytes"),maxOutputFrameBytes:i("maxOutputFrameBytes"),replayBytes:i("replayBytes"),idleMs:i("idleMs"),maxLifetimeMs:i("maxLifetimeMs"),reconnectMs:i("reconnectMs")}}function Pb(s){const t=[];if(!s.workspace)t.push("workspace");else if(s.connection.phase!=="open"&&!s.connection.capabilities.length)t.push("offline");else if(s.connection.capabilities.includes("terminal")||t.push("capability"),Te(s.principal??void 0,"terminal.exec")||t.push("permission"),!t.length)if(!s.connection.capabilities.includes("workspace.registry"))t.push("registry");else{const i=Jf(s);if(i)return{ok:!0,workspaceId:i.id};t.push(s.registry.loading?"loading":"unregistered")}return{ok:!1,reasons:t,messages:t.map(i=>io[i])}}function oS(s,t){let i=0,a=0;for(;a<s.length;){const l=s.codePointAt(a)??0,u=l<128?1:l<2048?2:l<65536?3:4;if(i+u>t)break;i+=u,a+=l>65535?2:1}return[s.slice(0,a),s.slice(a)]}function ey(s,t){const i=(a,l,u)=>Math.min(u,Math.max(l,Number.isFinite(a)?Math.floor(a):l));return{cols:i(s,Ci.minCols,Ci.maxCols),rows:i(t,Ci.minRows,Ci.maxRows)}}const ty=s=>s?.protection==="root-only"||s?.protection==="none"?s.protection:void 0;class lS{#e={status:"idle"};#j=new Set;#p=new Set;#n=[];#i=0;#m=0;#o=null;#f=0;#a=null;#s="";#g=!1;#c;#y;#v={cols:80,rows:24};#w=null;#b=!0;#d;constructor(t){this.#d={limits:wf(void 0),inputDelayMs:5,resizeDelayMs:120,maxHistoryChars:Ci.replayBytes,newRequestId:()=>globalThis.crypto.randomUUID(),...t}}get workspaceId(){return this.#d.workspaceId}getState(){return this.#e}get lastSeq(){return this.#m}subscribe(t){return this.#j.add(t),()=>{this.#j.delete(t)}}onOutput(t){return this.#p.add(t),()=>{this.#p.delete(t)}}history(){return this.#n.join("")}get accepting(){return this.#e.status==="running"}#h(t){this.#e={...this.#e,...t};for(const i of[...this.#j])i()}#k(t){if(t){for(this.#n.push(t),this.#i+=t.length;this.#i>this.#d.maxHistoryChars&&this.#n.length>1;)this.#i-=this.#n.shift().length;for(const i of[...this.#p])i(t)}}#S(){const{storage:t,storageKey:i}=this.#d;try{const a=t&&i?t.getItem(i):null;return Sl(a)?a:void 0}catch{return}}#C(t){const{storage:i,storageKey:a}=this.#d;if(!(!i||!a))try{t?i.setItem(a,t):i.removeItem(a)}catch{}}start(t,i){if(this.#e.status!=="idle")return;t!==void 0&&i!==void 0&&(this.#v=ey(t,i));const a=this.#d.initialTerminalId,l=this.#S()??(Sl(a)?a:void 0);l?(this.#C(l),this.#h({terminalId:l}),this.#E(0,!0)):this.#z()}restart(){const{status:t,terminalId:i}=this.#e;["exited","gone","failed","closed"].includes(t)&&(i&&t==="exited"&&this.#d.request("terminal.close",{terminalId:i}).catch(()=>{}),this.#C(void 0),this.#M(),this.#k("\x1Bc"),this.#n=[],this.#i=0,this.#e={status:"idle"},this.#z())}#M(){this.#f+=1,this.#m=0,this.#o=null,this.#s="",this.#w=null,this.#a=null}async#z(){const t=++this.#f;this.#a??=this.#d.newRequestId(),this.#h({status:"starting",error:void 0});let i;try{i=await this.#d.request("terminal.create",{workspaceId:this.#d.workspaceId,cols:this.#v.cols,rows:this.#v.rows,requestId:this.#a})}catch(l){if(t!==this.#f)return;if(Be(l).sent!=="yes"){this.#h({status:"reconnecting"}),this.#b&&this.#U();return}this.#a=null,this.#h({status:"failed",error:Xd(l)});return}if(t!==this.#f){const l=i?.terminal?.terminalId;if(this.#e.status==="closed"&&Sl(l))try{await this.#d.request("terminal.close",{terminalId:l})}catch{}return}const a=i?.terminal?.terminalId;if(!Sl(a)){this.#a=null,this.#h({status:"failed",error:"The host sent something this app does not understand."});return}this.#a=null,this.#w={cols:i.terminal.cols,rows:i.terminal.rows},this.#C(a),this.#h({terminalId:a,protection:ty(i.terminal)}),await this.#E(0,!1)}#U(){setTimeout(()=>{this.#b&&this.#e.status==="reconnecting"&&this.connected()},1e3)}async#E(t,i){const a=this.#e.terminalId,l=++this.#f;this.#o=[],this.#h({status:"attaching",error:void 0});let u;try{u=await this.#d.request("terminal.attach",{terminalId:a,...t>0?{after:t}:{}})}catch(p){if(l!==this.#f)return;this.#o=null;const x=Be(p);if(x.sent!=="yes"){this.#h({status:"reconnecting"}),this.#b&&this.#U();return}if(x.code===1001){if(this.#C(void 0),i&&!this.#m){this.#h({terminalId:void 0}),this.#z();return}this.#h({status:"gone",error:"This terminal has ended and the host no longer keeps it."});return}this.#h({status:"failed",error:Xd(p)});return}if(l!==this.#f)return;const d=this.#o??[];this.#o=null;const h=u?.gap;h&&Number.isSafeInteger(h.fromSeq)&&Number.isSafeInteger(h.toSeq)&&h.toSeq>=h.fromSeq&&h.toSeq>this.#m&&(this.#k(Jx(Math.max(h.fromSeq,this.#m+1),h.toSeq)),this.#m=h.toSeq);const m=u?.terminal;m&&Number.isSafeInteger(m.cols)&&(this.#w??={cols:m.cols,rows:m.rows}),this.#h({status:"running",protection:ty(m)??this.#e.protection});for(const p of d)this.#T(p);this.#e.status==="running"&&m?.state==="exited"&&this.#h({status:"exited",exit:{exitCode:m.exitCode??null,signal:m.signal??null,reason:m.endReason??"exited"}}),this.#e.status==="running"&&this.#D(0)}event(t){if(!(!t||t.terminalId!==this.#e.terminalId)){if(this.#o){this.#o.push(t);return}this.#T(t)}}#T(t){if(t.type==="detached"){if(t.reason==="slow_consumer"){this.#b?this.#E(this.#m,!1):this.#h({status:"reconnecting"});return}this.#f+=1,this.#s="",this.#h({status:"replaced"});return}!Number.isSafeInteger(t.seq)||t.seq<=this.#m||(t.seq>this.#m+1&&this.#k(Jx(this.#m+1,t.seq-1)),this.#m=t.seq,t.type==="output"&&typeof t.data=="string"?this.#k(t.data):t.type==="exit"&&(this.#s="",this.#h({status:"exited",exit:{exitCode:t.exitCode??null,signal:t.signal??null,reason:typeof t.reason=="string"?t.reason:"exited"}})))}input(t){return!this.accepting||typeof t!="string"||!t?!1:(this.#s+=t,!this.#g&&this.#c===void 0&&(this.#c=setTimeout(()=>{this.#c=void 0,this.#l()},this.#d.inputDelayMs)),!0)}async#l(){if(this.#g||!this.#s||!this.accepting)return;const[t,i]=oS(this.#s,this.#d.limits.maxInputBytes);if(!t){this.#s="";return}this.#s=i,this.#g=!0;const a=this.#e.terminalId;try{await this.#d.request("terminal.input",{terminalId:a,data:t})}catch(l){const u=Be(l);if(this.#s="",u.reason!=="terminal_exited"&&u.reason!=="not_attached"){const d=u.sent==="yes"?`Input was not delivered: ${Xd(l)}`:"The last input may not have reached the shell (the connection dropped). It is not sent again.";this.#h({lost:d}),this.#k(`\r
17
17
  \x1B[2m[${d}]\x1B[0m\r
18
- `)}}finally{this.#g=!1}this.#s&&this.#l()}resize(t,i){this.#v=ey(t,i),this.#D(this.#d.resizeDelayMs)}#D(t){this.#y!==void 0&&clearTimeout(this.#y),this.#y=setTimeout(()=>{this.#y=void 0,this.#H()},t)}async#H(){if(!this.accepting)return;const t=this.#v;if(!(this.#w&&this.#w.cols===t.cols&&this.#w.rows===t.rows))try{const i=await this.#d.request("terminal.resize",{terminalId:this.#e.terminalId,cols:t.cols,rows:t.rows});this.#w={cols:Number(i?.cols??t.cols),rows:Number(i?.rows??t.rows)}}catch{this.#w=null}}reattach(){this.#e.status!=="replaced"||!this.#e.terminalId||this.#E(this.#m,!1)}connected(){this.#b=!0;const{status:t,terminalId:i}=this.#e;t!=="reconnecting"&&t!=="attaching"&&t!=="starting"&&t!=="running"||(this.#w=null,i?this.#E(this.#m,!1):this.#a&&this.#z())}disconnected(){this.#b=!1,this.#f+=1,this.#o=null,this.#s&&(this.#s="",this.#h({lost:"Input typed while the connection dropped was not sent."})),["running","attaching","starting"].includes(this.#e.status)&&this.#h({status:"reconnecting"})}async close(){const{terminalId:t,status:i}=this.#e;if(this.dispose(),this.#C(void 0),this.#h({status:"closed"}),!(!t||i==="gone"||i==="closed"))try{await this.#d.request("terminal.close",{terminalId:t})}catch{}}#I(){this.#f+=1,this.#c!==void 0&&clearTimeout(this.#c),this.#y!==void 0&&clearTimeout(this.#y),this.#c=this.#y=void 0,this.#s=""}dispose(){this.#I(),this.#p.clear()}dismissLost(){this.#e.lost&&this.#h({lost:void 0})}}function Xd(s){const t=Be(s);return t.reason&&Zx[t.reason]?Zx[t.reason]:t.code===1003&&t.reason==="grant"?io.permission:t.code===1003&&t.reason==="outside_workspace"?"This workspace is not granted to your access token.":t.message}const cS=["attach.after","prompt.receipts"],ny={name:"alp-web",version:"0.10.0"},sy="Stop is waiting for this message’s outcome.",uS=15e3,dS=200,iy={"read-only":"Read only","workspace-write":"Workspace write","full-access":"Full access"};function ic(s,t){const i=s.tree,a=i&&i.rootId===t?Object.keys(i.projection.questions).length>0:!1;return i&&i.rootId===t&&i.status==="attached"?a:a||(s.attention[t]??0)>0}function ao(s,t){return s.turnAttention[t]?.reason}function Pd(s){if(!s||s.reason!=="finished"&&s.reason!=="error"||typeof s.at!="string")return;const t=Date.parse(s.at),i=s.reason==="error"&&typeof s.message=="string"&&s.message.trim()?s.message:void 0;return{reason:s.reason,at:Number.isFinite(t)?t:Date.now(),hostAt:s.at,...typeof s.turnId=="string"?{turnId:s.turnId}:{},...i?{message:i}:{}}}function fS(s){const t=Object.entries(s.turnAttention).filter(([i])=>s.tree?.rootId===i||s.sessions.list.some(a=>a.id===i&&!a.archived));return t.length===Object.keys(s.turnAttention).length?s.turnAttention:Object.fromEntries(t)}const ay="This access token cannot list files (needs project.read).",kf="This access token cannot read files (needs files.read).",Qb="This host does not offer file reading. Update ALP on the host.",Wb=100;function hS(s){if(typeof s!="string")return;const t=s.trim();return t&&t.length<=253&&!/[\p{Cc}\p{Cf}]/u.test(t)?t:void 0}function ry(s,t){const i=(Array.isArray(s?.sessions)?s.sessions:[]).filter(a=>a&&typeof a.id=="string"&&!a.parentId);return t?i.sort((a,l)=>String(l.updatedAt??l.createdAt??"").localeCompare(String(a.updatedAt??a.createdAt??""))):i}function mS(){try{return globalThis.sessionStorage??void 0}catch{return}}function rn(s=""){return{connection:{phase:"idle",gateway:s,attempt:0,capabilities:[]},principal:null,workspace:null,catalog:{status:"idle",teams:[],modes:[],models:[]},sessions:{status:"idle",list:[]},registry:{workspaces:[],revision:0},terminalDirectory:{items:[],mode:"idle"},history:{status:"idle",list:[],query:""},attention:{},turnAttention:{},selected:null,focus:null,tree:null,prompts:[],queued:[],busy:{},tasks:{status:"idle",visible:!1,rows:[],unreadable:0,creates:[],busy:{}},settings:{status:"idle",models:[]},notice:null,preferences:Oi(null)}}class $r extends Error{constructor(){super("The message was discarded."),this.name="DiscardedError"}}class oy extends Error{constructor(t,i,a){super(i.message),this.name="UploadError",this.fileName=t,this.failure=i,this.dropped=a}}class pS{#e;#j=new Set;#p=!1;#n;#i=null;#m="";#o=new Map;#f=new Map;#a=null;#s=null;#g=new Map;#c=new Map;#y=new Map;#v=new Map;#w=new Map;#b=new Map;#d=new Map;#h=new WeakMap;#k(t,i){const a=(this.#h.get(t)??Promise.resolve()).then(i);return this.#h.set(t,a.catch(()=>{})),a}#S=new WeakSet;#C=!1;#M=null;#z=new Set;#U=0;#E=!1;#T=null;#l={};#D={};#H=new Map;#I;#ae;#re;#N=null;#X=null;#P=null;#q=new Map;#Oe=0;#G=0;#xe={visible:!0,focused:!0};#tt=0;#R=new Map;#Y=new Map;#B;constructor(t={}){this.#n={open:O2,reconnecting:Cx,backoff:{initialMs:500,maxMs:15e3},stableMs:5e3,requestTimeoutMs:3e4,createTimeoutMs:12e4,taskPollMs:5e3,sessionPollMs:15e3,attentionPollMs:5e3,attentionWatchPollMs:6e4,historyPageSize:dS,releaseTimeoutMs:5e3,busyUnseenMs:uS,...t},this.#e={...rn(),preferences:Wx(t.storage)}}getState(){return this.#e}subscribe(t){return this.#j.add(t),()=>{this.#j.delete(t)}}#t(t){const i=typeof t=="function"?t(this.#e):t;this.#e={...this.#e,...i},this.#nt(),this.#e.queued.length&&this.#Tt()}#nt(){this.#p||(this.#p=!0,queueMicrotask(()=>{this.#p=!1;for(const t of[...this.#j])t()}))}#u(t,i,a){this.#t({notice:{id:++this.#tt,level:t,text:i,...a?.action?{action:a.action}:{}}})}dismissNotice(){this.#t({notice:null})}notify(t,i){this.#u(t,i)}#r(){const t=this.#i?.alp;if(!t||t.state!=="open"||!t.client)throw new Ke(this.#e.connection.phase==="reconnecting"?"Reconnecting to the host. Try again in a moment.":"Not connected to a host.");return t.client}connect({url:t,token:i,link:a=!1}){this.#oe(),a||Kr(this.#n.linkStorage);let l;try{l=Sb(t)}catch(k){this.#t({connection:{...this.#e.connection,phase:"failed",gateway:String(t),error:Be(k)}});return}const u=String(i??"").trim();if(!u){this.#t({connection:{...this.#e.connection,phase:"failed",gateway:l,error:Be(new Ra("Enter an access token."))}});return}this.#m=u,this.#e={...rn(l),preferences:this.#e.preferences},this.#t({connection:{phase:"connecting",gateway:l,attempt:1,capabilities:[],...a?{link:!0}:{}}});const d={opened:!1,...a?{link:!0}:{}};this.#i=d;const{open:h,reconnecting:m,backoff:p,stableMs:x,requestTimeoutMs:y}=this.#n,w=m({connect:async({signal:k})=>{const{transport:j,principal:S}=await h({url:l,token:this.#m,signal:k});if(this.#i!==d)throw j.close(),new Error("This connection was replaced.");return d.principal=S,j},onConnect:(k,j)=>this.#it(d,k,j.signal),onDisconnect:()=>{if(this.#i===d){this.#B?.close(!1),this.#B=void 0;for(const k of this.#R.values())k.disconnected();this.#s=null,this.#g.clear(),this.#a=null;for(const k of this.#o.values())k.attaching=null}},shouldRetry:k=>!Be(k).terminal,backoff:p,stableMs:x,client:{timeoutMs:y}});d.alp=w,w.onEvent(k=>{this.#i===d&&this.#dt(k)&&this.#ft(k)}),w.onNotification((k,j)=>{if(this.#i===d){if(k==="catalog.updated"){this.#et();return}if(k==="terminal.event")for(const S of this.#R.values())S.event(j)}}),w.onState((k,j)=>{this.#i===d&&this.#st(d,k,j)})}showError(t){this.#oe(),this.#t({connection:{...rn(this.#e.connection.gateway).connection,phase:"failed",error:{message:t,sent:"no",terminal:!0}}})}disconnect({keepTerminals:t=!1,keepLink:i=!1}={}){i||Kr(this.#n.linkStorage),this.#oe({keepTerminals:t})}#oe({keepTerminals:t=!1}={}){const i=this.#i;this.#i=null,this.#m="",this.#ye(),this.#o.clear(),this.#c.clear(),this.#f.clear(),this.#K.clear(),this.#se.clear(),this.#F.clear(),this.#ne.clear(),this.#g.clear();const a=[...this.#x.values()];this.#x.clear();for(const u of a)clearTimeout(u.retry),u.observer?.stop(),u.done();this.#O.clear(),this.#ge.clear(),this.#$!==void 0&&(clearTimeout(this.#$),this.#$=void 0),this.#a=null,this.#s=null,this.#M=null,this.#U+=1,this.#l={},this.#N=null;const l=this.#ct(t?null:i);if(i?.alp){const u=i.alp;l?l.then(()=>u.stop()):u.stop()}i&&this.#t({...rn(this.#e.connection.gateway),preferences:this.#e.preferences})}#st(t,i,a){const l=this.#e.connection;if(i==="open"){t.opened=!0,this.#t({connection:{...l,phase:"open",attempt:0,error:void 0}}),this.#rt();return}if(i==="connecting"){this.#t({connection:{...l,phase:t.opened?"reconnecting":"connecting",attempt:t.alp?.attempt??l.attempt}});return}if(i==="waiting"){if(!t.opened&&!t.link)return this.#De(a??new Error("Could not connect."));if(!t.opened){this.#t({connection:{...l,phase:"connecting",error:a?Be(a):void 0}});return}this.#ye(),this.#t({connection:{...l,phase:"reconnecting",error:a?Be(a):void 0}});return}i==="stopped"&&a&&this.#De(a)}#De(t){const i=this.#e.connection.gateway;let a=Be(t);this.#i?.link&&t instanceof Ra&&(Kr(this.#n.linkStorage),a={...a,message:q2}),this.#oe(),this.#t({connection:{...rn(i).connection,phase:"failed",error:a}})}async#it(t,i,a){const l=await Ax(i,ny,{signal:a,timeoutMs:15e3});if(this.#i!==t)throw new Error("This connection was replaced.");const u=Array.isArray(l?.capabilities)?l.capabilities.filter(m=>typeof m=="string"):[],d=cS.filter(m=>!u.includes(m));if(d.length)throw new Ke(`The host behind this gateway is too old for this app (it lacks ${d.join(", ")}). Update ALP on the host.`);this.#at(t.principal,u,typeof l?.daemonVersion=="string"?l.daemonVersion:void 0,hS(l?.hostname),mj(l?.promptImageLimits,u.includes("prompt.images")),bj(l?.attachmentLimits,u.includes("attachments")),u.includes("terminal")?wf(l?.terminalLimits):void 0),this.#s=null,this.#a=null;const h=this.#e.selected;if(h&&h!==this.#T&&!this.#o.get(h)?.gone){this.#_(h).failed=null;try{if(await this.#ue(i,h,a),this.#i!==t||a.aborted)throw new Error("This connection was replaced.");this.#s={client:i,root:h}}catch(m){if(this.#i!==t||a.aborted||!Ud(m))throw m;this.#$e(h,m)}}}#at(t,i,a,l,u,d={...Ps},h=void 0){this.#D={};const m=this.#e.workspace,p=m&&Ll(t,m)?m:t.workspaces[0]??null,x=JSON.stringify(t)!==JSON.stringify(this.#e.principal);p!==m&&(this.#l={},this.#N=null),this.#t(y=>({principal:t,registry:x?rn().registry:{...y.registry,loading:!1},connection:{...y.connection,capabilities:i,...a?{daemonVersion:a}:{},hostname:l,promptImageLimits:u,attachmentLimits:d,terminalLimits:h},...p!==y.workspace?{workspace:p,selected:null,focus:null,tree:null,sessions:rn().sessions,history:rn().history,attention:{},turnAttention:{},tasks:{...rn().tasks,visible:y.tasks.visible}}:{},...x||p!==y.workspace?{catalog:rn().catalog}:{}}))}#rt(){this.#lt();for(const t of this.#R.values())t.connected();this.#V(),this.#kt();for(const[t,i]of this.#x)i.attempts=0,i.exhausted=!1,this.#A(t);this.refreshRegistry(),this.#e.workspace&&(this.refreshSessions(),this.refreshAttention(),this.#e.history.status!=="idle"&&this.loadHistory({quiet:!0}),this.#e.catalog.status!=="ready"&&this.#Te(),this.#e.tasks.visible&&this.refreshTasks()),this.#ot()}#ot(){this.#ye(),this.#ae=setInterval(()=>{this.#e.workspace&&this.#e.connection.phase==="open"&&this.refreshSessions({quiet:!0})},this.#n.sessionPollMs);const t=this.hasCapability("question.watch")?this.#n.attentionWatchPollMs:this.#n.attentionPollMs;this.#re=setInterval(()=>{this.#e.workspace&&this.#e.connection.phase==="open"&&this.refreshAttention()},t),this.#I=setInterval(()=>{this.#e.tasks.visible&&this.#e.workspace&&this.#e.connection.phase==="open"&&this.refreshTasks({quiet:!0})},this.#n.taskPollMs)}#ye(){this.#ae!==void 0&&clearInterval(this.#ae),this.#I!==void 0&&clearInterval(this.#I),this.#re!==void 0&&clearInterval(this.#re),this.#ae=this.#I=this.#re=void 0}hasCapability(t){return this.#e.connection.capabilities.includes(t)}terminalGate(){return Pb(this.#e)}#lt(){this.#B?.close(),this.#B=void 0;const t=this.#i;!t||!this.hasCapability("terminal")||!Te(this.#e.principal??void 0,"terminal.exec")||(this.#B=h2(this.#r(),{capabilities:this.#e.connection.capabilities,onMode:i=>{this.#i===t&&this.#t(a=>({terminalDirectory:{...a.terminalDirectory,mode:i}}))},onSnapshot:i=>{this.#i===t&&this.#t(a=>({terminalDirectory:{...a.terminalDirectory,items:i,error:void 0}}))},onError:i=>{this.#i===t&&this.#t(a=>({terminalDirectory:{...a.terminalDirectory,error:Be(i).message}}))}}))}openListedTerminal(t,i){const a=this.terminalTabs(t),l=a.tabs.find(h=>h.session.getState().terminalId===i);if(l){this.selectTerminal(t,l.key);return}if(!this.#e.terminalDirectory.items.some(h=>h.terminalId===i&&h.workspaceId===t&&h.state==="running")||a.tabs.length>=32)return;const u=globalThis.crypto.randomUUID(),d=this.#be(t,u,a.storage,a.storageKey,i);a.tabs=[...a.tabs,{key:u,session:d}],a.active=u,this.#Q(t)}terminal(t){let i=this.#Y.get(t)??this.terminalTabs(t);return i.tabs.length||(this.addTerminal(t),i=this.terminalTabs(t)),(i.tabs.find(a=>a.key===i.active)??i.tabs[0]).session}terminalTabs(t){const i=this.terminalGate();if(!i.ok||i.workspaceId!==t)throw new Ke(i.ok?"That workspace is not the open one.":i.messages.join(" "));let a=this.#Y.get(t);if(a)return a;const l=this.#n.terminalStorage===void 0?mS():this.#n.terminalStorage??void 0,u=`alp-web.terminal|${this.#e.connection.gateway}|${this.#e.principal?.id??""}|${t}`;let d=["default"],h="default";try{const m=JSON.parse(l?.getItem(`${u}|tabs`)??"null");m?.v===1&&Array.isArray(m.keys)&&m.keys.length<=32&&m.keys.every(p=>typeof p=="string"&&/^(default|[a-zA-Z0-9-]{1,64})$/.test(p))&&new Set(m.keys).size===m.keys.length&&(d=m.keys,h=d.includes(m.active)?m.active:d[0]??null)}catch{}return a={tabs:d.map(m=>({key:m,session:this.#be(t,m,l,u)})),active:h,storage:l,storageKey:u},this.#Y.set(t,a),a}#be(t,i,a,l,u){const d=new lS({workspaceId:t,...u?{initialTerminalId:u}:{},request:(h,m)=>this.#r().request(h,m,{timeoutMs:this.#n.requestTimeoutMs}),limits:this.#e.connection.terminalLimits??wf(void 0),...a?{storage:a,storageKey:i==="default"?l:`${l}|${i}`}:{},...this.#n.terminalOptions});return this.#R.set(JSON.stringify([t,i]),d),d}#Q(t){const i=this.#Y.get(t);if(i){try{i.storage?.setItem(`${i.storageKey}|tabs`,JSON.stringify({v:1,keys:i.tabs.map(a=>a.key),active:i.active}))}catch{}this.#t({})}}addTerminal(t){const i=this.terminalTabs(t);if(i.tabs.length>=32)return i.active;const a=globalThis.crypto.randomUUID();return i.tabs=[...i.tabs,{key:a,session:this.#be(t,a,i.storage,i.storageKey)}],i.active=a,this.#Q(t),a}selectTerminal(t,i){const a=this.terminalTabs(t);a.tabs.some(l=>l.key===i)&&(a.active=i,this.#Q(t))}closeTerminalTab(t,i){const a=this.terminalTabs(t),l=a.tabs.findIndex(d=>d.key===i);if(l<0)return Promise.resolve();const u=a.tabs[l];return a.tabs=a.tabs.filter(d=>d.key!==i),a.active===i&&(a.active=a.tabs[Math.min(l,a.tabs.length-1)]?.key??null),this.#R.delete(JSON.stringify([t,i])),this.#Q(t),u.session.close()}closeTerminal(t=Jf(this.#e)?.id){const i=t?this.#Y.get(t):void 0;if(!t||!i)return Promise.resolve();const a=i.tabs;i.tabs=[],i.active=null;for(const l of a)this.#R.delete(JSON.stringify([t,l.key]));return this.#Q(t),Promise.allSettled(a.map(l=>l.session.close()))}#ct(t){this.#B?.close(),this.#B=void 0;const i=t?.alp?.state==="open"?t.alp.client:void 0,a=[];for(const l of this.#R.values()){const{terminalId:u,status:d}=l.getState();l.dispose(),i&&u&&d!=="gone"&&d!=="closed"&&a.push(i.request("terminal.close",{terminalId:u},{timeoutMs:1e3}).catch(()=>{}))}return this.#R.clear(),this.#Y.clear(),a.length?Promise.allSettled(a):void 0}#_(t){let i=this.#o.get(t);return i||(i={projection:bs(t),attaching:null,gone:null,failed:null},this.#o.set(t,i),this.#f.set(t,t)),i}#W(t){for(const i of t.order)this.#f.set(i,t.rootId);return t}#ut(t){const i=t?.sessionId;if(typeof i!="string")return;let a=this.#f.get(i);if(!a){const l=t.event?.type==="session.opened"?t.event.session?.parentId:void 0;a=typeof l=="string"&&this.#f.get(l)||void 0,a&&this.#f.set(i,a)}return a===this.#a?a:void 0}#dt(t){const i=t?.event;if(i?.type==="question"){const a=i.question?.id,l=i.question?.rootId;return typeof a=="string"&&typeof l=="string"&&this.#X?.events.push({id:a,root:l}),this.#N&&typeof a=="string"&&typeof l=="string"&&this.#N.get(a)!==l&&(this.#N.set(a,l),this.#ve()),t.cursor!==void 0||!!this.#a&&l===this.#a}if(i?.type==="attention"&&t.cursor===void 0)return typeof t.sessionId=="string"&&(this.#P&&this.#P.push([t.sessionId,i.attention??null]),this.#ht(t.sessionId,i.attention)),!1;if(i?.type==="turn.ended"&&t.cursor===void 0){if(typeof t.sessionId=="string"){const a=t.sessionId;this.#e.sessions.list.some(l=>l.id===a&&(l.status==="running"||l.busy))&&this.#t(l=>({sessions:{...l.sessions,list:l.sessions.list.map(u=>u.id===a?{...u,busy:!1,...u.status==="running"?{status:"idle"}:{}}:u)}})),this.#qe(a,i)}return!1}if(i?.type==="question.resolved"){if(typeof i.questionId=="string"&&this.#X?.events.push({id:i.questionId}),this.#N?.delete(i.questionId)&&this.#ve(),t.cursor!==void 0)return!0;const a=this.#a?this.#o.get(this.#a):void 0;return a?Object.hasOwn(a.projection.questions,i.questionId)||!!a.attaching?.buffer.some(l=>l.event?.type==="question"&&l.event.question?.id===i.questionId):!1}return!0}#ve(){if(!this.#N)return;const t={};for(const i of this.#N.values())t[i]=(t[i]??0)+1;JSON.stringify(t)!==JSON.stringify(this.#e.attention)&&this.#t({attention:t})}#ft(t){const i=this.#ut(t);if(!i)return;const a=this.#o.get(i);if(!a)return;if(t.event?.type==="history.reset"&&t.sessionId===i){this.#Be(i,t.event.generation);return}if(a.attaching){a.attaching.buffer.push(t);return}a.projection=this.#W(zi(a.projection,t)),this.#L(i);const l=t.event?.type;t.sessionId===i&&l==="turn.ended"?this.#qe(i,t.event):t.sessionId===i&&l==="turn.started"&&(this.#q.delete(i),this.#Z(i))}get#le(){return this.hasCapability("session.attention")&&this.hasCapability("question.watch")}#ht(t,i){this.#q.delete(t);const a=Pd(i);if(!a){this.#Z(t);return}if(this.#ce(t)){this.#Z(t),this.#we(t,a);return}this.#e.history.list.some(l=>l.id===t&&l.archived)||this.#e.turnAttention[t]?.hostAt!==a.hostAt&&this.#t(l=>({turnAttention:{...l.turnAttention,[t]:a}}))}#we(t,i){if(!this.#le||this.#e.connection.phase!=="open")return;const a={},l=this.#l;this.#q.set(t,a);const u=()=>{this.#q.get(t)===a&&(this.#q.delete(t),!(l!==this.#l||this.#e.turnAttention[t])&&(this.#e.history.list.some(d=>d.id===t&&d.archived)||this.#t(d=>({turnAttention:{...d.turnAttention,[t]:i}}))))};try{this.#r().request("session.attention.clear",{sessionId:t,...i.hostAt?{at:i.hostAt}:{}}).then(()=>{this.#q.get(t)===a&&this.#q.delete(t)},u)}catch{u()}}#Z(t){this.#e.turnAttention[t]&&this.#t(i=>{const{[t]:a,...l}=i.turnAttention;return{turnAttention:l}})}#qe(t,i){if(this.#le)return;const a=i?.state==="completed"?"finished":i?.state==="failed"?"error":void 0;if(!a){this.#Z(t);return}if(this.#ce(t)||this.#e.history.list.some(d=>d.id===t&&d.archived))return;const l=typeof i?.error?.message=="string"&&i.error.message.trim()?i.error.message:void 0,u={reason:a,at:Date.now(),...typeof i?.turnId=="string"?{turnId:i.turnId}:{},...a==="error"&&l?{message:l}:{}};this.#t(d=>({turnAttention:{...d.turnAttention,[t]:u}}))}#ce(t){const i=this.#e.focus??this.#e.selected;return this.#xe.visible&&this.#xe.focused&&(i===t||this.#e.selected===t)}setPresence({visible:t,focused:i}){this.#xe={visible:!!t,focused:!!i};const a=this.#e.focus??this.#e.selected;a&&this.#ce(a)&&this.clearAttention(a)}clearAttention(t){const i=t?this.#e.turnAttention[t]:void 0;!t||!i||(this.#Z(t),this.#we(t,i))}async#ue(t,i,a,l=0){const u=this.#_(i),d={buffer:[]};u.attaching=d,this.#a=i;const h=this.#y.get(i)??0;this.#e.selected===i&&this.#t(m=>({tree:{rootId:i,status:"attaching",projection:u.projection,...m.tree?.rootId===i&&m.tree.error?{}:{}}}));try{if(this.hasCapability("session.history")&&!this.#c.has(i)){const y=await t.request("session.history",{sessionId:i},{timeoutMs:this.#n.requestTimeoutMs,...a?{signal:a}:{}});if(u.attaching!==d)return;u.projection=bs(i);for(const w of y.items)u.projection=zi(u.projection,bf(w,i));this.#W(u.projection),u.projection={...u.projection,cursor:y.tipCursor},this.#c.set(i,{generation:y.generation,olderCursor:y.olderCursor,hasOlder:y.hasOlder})}const m=u.projection.cursor,p=this.#c.get(i),x=await t.request("session.attach",{sessionId:i,...p?{after:m,generation:p.generation}:m>0?{after:m}:{}},{timeoutMs:this.#n.requestTimeoutMs,...a?{signal:a}:{}});if(u.attaching!==d)return;u.attaching=null,u.gone=null,u.failed=null,this.#ke(i,u,x,d.buffer),(this.#y.get(i)??0)!==h&&this.#c.get(i)?.generation!==this.#v.get(i)&&(this.#c.delete(i),queueMicrotask(()=>{this.#je(t,i)}))}catch(m){if(u.attaching!==d)throw m;if(m?.data?.reason==="stale_cursor"&&l<1&&this.#c.has(i))return this.#c.delete(i),u.projection=bs(i),u.attaching===d&&(u.attaching=null),this.#ue(t,i,a,l+1);throw u.attaching===d&&(u.attaching=null),t===this.#i?.alp?.client&&this.#a===i&&(this.#a=null),m}}#ke(t,i,a,l){i.projection=this.#W(Ux(i.projection,a??{},l)),a?.reset&&!i.projection.historyUnavailable&&this.#u("info","The host restarted this conversation's history; it was loaded again from the beginning."),this.#L(t,"attached")}#Be(t,i){if(typeof i!="string"||!i||this.#c.get(t)?.generation===i||this.#v.get(t)===i)return;this.#v.set(t,i),this.#y.set(t,(this.#y.get(t)??0)+1),this.#c.delete(t);const a=this.#o.get(t);a&&this.#We(t,a.projection);const l=this.#s?.root===t?this.#s.client:void 0;a&&l&&!a.attaching&&this.#je(l,t)}#je(t,i){return this.#k(t,()=>this.#mt(t,i))}async#mt(t,i){if(!(t!==this.#i?.alp?.client||this.#e.selected!==i)&&!(this.#s?.client!==t||this.#s.root!==i)){this.#c.delete(i);try{await this.#ue(t,i)}catch(a){this.#Ne(t,i,a)}}}async loadOlder(){const t=this.#e.selected;if(!t)return;const i=this.#c.get(t),a=this.#o.get(t),l=this.#s?.root===t?this.#s.client:null;if(!i?.hasOlder||i.loading||!a||!l)return;const u={...i,loading:!0,error:void 0};this.#c.set(t,u),this.#L(t);try{const d=await l.request("session.history",{sessionId:t,before:i.olderCursor},{timeoutMs:this.#n.requestTimeoutMs});if(this.#c.get(t)!==u)return;if(d.generation!==i.generation)throw new Error("History changed; reconnect to refresh it.");a.projection=this.#W(Mj(a.projection,d.items)),this.#c.set(t,{generation:d.generation,olderCursor:d.olderCursor,hasOlder:d.hasOlder})}catch(d){this.#c.get(t)===u&&this.#c.set(t,{...i,error:Be(d).message})}this.#L(t)}#$e(t,i){const a=this.#_(t);a.gone=Be(i),a.attaching=null,this.#a===t&&(this.#a=null),this.#e.selected===t&&this.#t({tree:{rootId:t,status:"gone",error:a.gone,projection:a.projection}})}#L(t,i){if(this.#e.selected!==t){this.#A(t);return}const a=this.#o.get(t);if(!a)return;const l=Ix(a.projection),u=a.projection.prompts;for(const h of this.#O.get(t)??[]){const m=u[h];(m?.state==="failed"&&m.errorCode!=="outcome_unknown"||m?.turnId&&a.projection.turns[m.turnId]==="ended")&&this.#O.get(t)?.delete(h)}let d=this.#e.prompts.filter(h=>h.rootId!==t||!l.has(h.id));d=d.map(h=>{const m=u[h.id];if(h.rootId!==t||m?.state!=="failed")return h;const p=m.errorCode==="outcome_unknown",x=p?"unknown":"failed";if(h.status===x)return h;const y=p?"The host cannot tell whether the agent took the message":"The agent did not take the message";return{...h,status:x,error:m.error?`${y}: ${m.error}`:`${y}.`,retrySameId:!1}}),this.#t(h=>({tree:{rootId:t,status:i??(h.tree?.rootId===t?h.tree.status:"attached"),projection:a.projection,...this.#c.has(t)?{older:this.#c.get(t)}:{},...i==="attached"?{}:h.tree?.rootId===t&&h.tree.error?{error:h.tree.error}:{}},...d.length!==h.prompts.length||d.some((m,p)=>m!==h.prompts[p])?{prompts:d}:{},sessions:this.#Ue(h.sessions,t,a.projection),busy:{...h.busy,interrupt:this.#x.has(t)&&!this.#x.get(t)?.exhausted}})),this.#A(t)}#Ue(t,i,a){const l=t.list.findIndex(p=>p.id===i);if(l<0)return t;const u=t.list[l],d=a.sessions[i],h=a.closed[i]?"closed":i in a.running?"running":d?.status==="closed"||u.status==="closed"&&!d?"closed":"idle";if(u.status===h&&(!d?.title||d.title===u.title))return t;const m=t.list.slice();return m[l]={...u,status:h,...d?.title?{title:d.title}:{}},{...t,list:m}}async#V(){const t=this.#i?.alp?.client;if(t){if(this.#S.has(t)){this.#E=!0;return}this.#S.add(t);try{for(;;){this.#E=!1;const i=await this.#k(t,()=>this.#pt(t));if(t!==this.#i?.alp?.client||!i&&!this.#E)break}}finally{this.#S.delete(t)}}}async#pt(t){if(this.#i?.alp?.state!=="open"||t!==this.#i.alp.client)return!1;const i=this.#e.selected;this.#s&&this.#s.client!==t&&(this.#s=null);const a=this.#s;if(a&&a.root!==i)return this.#s=null,this.#a===a.root&&(this.#a=null),await this.#J(a),!0;if(!i||i===this.#T||this.#s?.root===i)return!1;const l=this.#_(i);if(l.gone)return this.#t({tree:{rootId:i,status:"gone",error:l.gone,projection:l.projection}}),!1;if(l.failed)return this.#t({tree:{rootId:i,status:"error",error:l.failed,projection:l.projection}}),!1;const u=this.#g.get(i);try{return this.#g.delete(i),this.#s={client:t,root:i},await this.#ue(t,i),t!==this.#i?.alp?.client?!0:(this.#s={client:t,root:i},this.#e.selected!==i)}catch(d){return u&&t===this.#i?.alp?.client&&(this.#s?.client===t&&this.#s.root===i&&(this.#s=null),await this.#J(u)),this.#Ne(t,i,d),!1}}async#J(t){const i=this.#x.get(t.root)?.observer;i&&i.state!=="stopped"?(this.#g.set(t.root,t),i.ready().catch(()=>{}).then(()=>this.#Se(t.root,t))):(this.#g.delete(t.root),await t.client.request("session.release",{sessionId:t.root},{timeoutMs:this.#n.releaseTimeoutMs}).catch(()=>{}))}#Se(t,i){const a=this.#g.get(t);!a||i&&a!==i||this.#k(a.client,async()=>{this.#g.get(t)===a&&(this.#g.delete(t),this.#i?.alp?.client===a.client&&(this.#s?.client===a.client&&this.#s.root===t||await a.client.request("session.release",{sessionId:t},{timeoutMs:this.#n.releaseTimeoutMs}).catch(()=>{})))})}#Ne(t,i,a){if(t!==this.#i?.alp?.client)return;if(Ud(a)){this.#$e(i,a);return}const l=this.#_(i);l.failed=Be(a),this.#e.selected===i&&this.#t({tree:{rootId:i,status:"error",error:l.failed,projection:l.projection}})}retryAttach(){const t=this.#e.selected;if(!t)return;const i=this.#o.get(t);i&&(i.gone=null,i.failed=null);const a=this.#i?.alp?.client;a&&this.#k(a,async()=>{const l=this.#s;l?.client===a&&l.root===t&&(this.#s=null,this.#a===t&&(this.#a=null),await this.#J(l))}).finally(()=>this.#V())}selectWorkspace(t){const i=this.#e.principal,a=t&&(Ll(i??void 0,t)||this.#e.registry.workspaces.some(l=>l.managedWorktree&&l.directory===t))?t:null;a!==this.#e.workspace&&(this.#l={},this.#N=null,this.#t(l=>({workspace:a,selected:null,focus:null,tree:null,sessions:rn().sessions,history:rn().history,attention:{},turnAttention:{},catalog:rn().catalog,tasks:{...rn().tasks,visible:l.tasks.visible}})),this.#V(),a&&this.#e.connection.phase==="open"&&(this.refreshSessions(),this.refreshAttention(),this.#Te(),this.#e.tasks.visible&&this.refreshTasks()))}async refreshRegistry(){if(!this.hasCapability("workspace.registry")||!Te(this.#e.principal??void 0,"project.read")||this.#e.registry.loading)return;const t=this.#D,i=this.#i;this.#t(a=>({registry:{...a.registry,loading:!0}}));try{const a=[];let l,u=0;do{const d=await this.#r().request("workspace.list",{limit:500,...l?{cursor:l}:{}});a.push(...d.workspaces),u=d.revision,l=d.nextCursor}while(l);t===this.#D&&i===this.#i&&this.#t({registry:{workspaces:a,revision:u}})}catch(a){t===this.#D&&i===this.#i&&this.#t(l=>({registry:{...l.registry,loading:!1,error:a instanceof Error?a.message:String(a)}}))}}async pinWorkspace(t,i){if(!Te(this.#e.principal??void 0,"workspace.write")){this.#u("error","Ask the host owner to add workspace.write to your credential to change shared pins.");return}const a=()=>this.#r().request("workspace.update",{workspaceId:t,pinned:i,ifRevision:this.#e.registry.revision,requestId:globalThis.crypto.randomUUID()});try{try{await a()}catch(l){if(l?.data?.reason!=="stale_revision")throw l;await this.refreshRegistry(),await a()}await this.refreshRegistry()}catch(l){this.#u("error",`Pin was not saved. ${l instanceof Error?l.message:String(l)} Refresh and try again.`),await this.refreshRegistry()}}async renameWorkspace(t,i){if(!Te(this.#e.principal??void 0,"workspace.write"))return this.#u("error","Ask the host owner to add workspace.write to your credential to rename shared workspaces."),!1;try{return await this.#r().request("workspace.update",{workspaceId:t,title:i.trim()||null,ifRevision:this.#e.registry.revision,requestId:globalThis.crypto.randomUUID()}),await this.refreshRegistry(),!0}catch(a){return this.#u("error",`Name was not saved. ${a instanceof Error?a.message:String(a)} Refresh and try again.`),await this.refreshRegistry(),!1}}async worktreeOptions(t){return(await this.#r().request("workspace.worktree.options",{workspaceId:t})).mappingIds}async mutateWorktree(t,i,a){if(!this.hasCapability("workspace.worktree")||!Te(this.#e.principal??void 0,"workspace.manage"))return!1;const l=t+":"+i+":"+(a??"");let u=this.#H.get(l);u||(u={workspaceId:i,...a?{mappingId:a}:{},ifRevision:this.#e.registry.revision,requestId:globalThis.crypto.randomUUID()},this.#H.set(l,u));try{return await this.#r().request("workspace.worktree."+t,u),this.#H.delete(l),await this.refreshRegistry(),!0}catch(d){return d?.data?.reason==="stale_revision"&&this.#H.delete(l),this.#u("error",`Worktree ${t} was not confirmed. ${d instanceof Error?d.message:String(d)} Retry the same operation to reconcile its outcome.`),await this.refreshRegistry(),!1}}async registerProject(t){if(!Te(this.#e.principal??void 0,"workspace.write")){this.#u("error","Ask the host owner to add workspace.write to your credential. To add another directory, the owner must grant it locally first.");return}try{await this.#r().request("project.register",{directory:t,ifRevision:this.#e.registry.revision,requestId:globalThis.crypto.randomUUID()}),await this.refreshRegistry()}catch(i){this.#u("error",`Project was not added. ${i instanceof Error?i.message:String(i)} Refresh and try again.`),await this.refreshRegistry()}}async listWorkspaceSessions(t){if(!Te(this.#e.principal??void 0,"session.read")||this.#e.connection.phase!=="open")return{};const i=this.#r(),a=await Promise.all(t.map(async l=>{try{const u=await i.request("session.list",{projectRoot:l,rootsOnly:!0,includeClosed:!0});return[l,(Array.isArray(u?.sessions)?u.sessions:[]).filter(d=>d&&typeof d.id=="string"&&!d.parentId&&!d.archived)]}catch{return null}}));return Object.fromEntries(a.filter(Boolean))}async refreshSessions({quiet:t=!1}={}){this.refreshRegistry();const i=this.#e.workspace;if(!i)return;const a=this.#l;t||this.#t(u=>({sessions:{...u.sessions,status:u.sessions.list.length?u.sessions.status:"loading",error:void 0}}));const l=Date.now();try{const d=await this.#r().request("session.list",{projectRoot:i,rootsOnly:!0,includeClosed:!0});if(a!==this.#l)return;const h=(Array.isArray(d?.sessions)?d.sessions:[]).filter(m=>m&&typeof m.id=="string"&&!m.parentId&&!m.archived).sort((m,p)=>String(p.updatedAt??p.createdAt??"").localeCompare(String(m.updatedAt??m.createdAt??"")));this.#t(m=>{let p={status:"ready",list:h};for(const[j,S]of this.#o)p=this.#Ue(p,j,S.projection);const x=m.selected&&!h.some(j=>j.id===m.selected)?m.sessions.list.find(j=>j.id===m.selected):void 0,w=this.#le?[]:Object.keys(m.turnAttention).filter(j=>m.turnAttention[j].at<l&&h.some(S=>S.id===j&&(S.status==="running"||S.busy))),k=w.length?Object.fromEntries(Object.entries(m.turnAttention).filter(([j])=>!w.includes(j))):m.turnAttention;return{sessions:x?{...p,list:[x,...p.list]}:p,turnAttention:k}})}catch(u){if(a!==this.#l)return;t||this.#t(d=>({sessions:{...d.sessions,status:"error",error:Be(u)}}))}}async refreshAttention(){const t=this.#e.workspace;if(!t||!Te(this.#e.principal??void 0,"session.read"))return;const i=this.#l,a=++this.#Oe,l=this.hasCapability("question.watch"),u=l?{read:a,events:[]}:null;this.#X=u;const d=this.#le,h=d?[]:null;this.#P=h;try{const m=l&&this.hasCapability("question.watch.turns"),p=await this.#r().request(l?"question.watch":"question.list",{projectRoot:t,...m?{turns:!0}:{},...d?{attention:!0}:{}});if(i!==this.#l||a!==this.#Oe)return;d&&Array.isArray(p?.attention)&&this.#gt(p.attention,h??[]);const x=new Map;for(const y of Array.isArray(p?.questions)?p.questions:[])typeof y?.id=="string"&&typeof y.rootId=="string"&&x.set(y.id,y.rootId);for(const y of u?.events??[])y.root?x.set(y.id,y.root):x.delete(y.id);this.#N=x,this.#ve(),l||(this.#N=null)}catch{}finally{this.#X===u&&(this.#X=null),this.#P===h&&(this.#P=null)}}#gt(t,i){const a=new Map;for(const u of t)typeof u?.sessionId=="string"&&Pd(u.attention)&&a.set(u.sessionId,u.attention);for(const[u,d]of i)a.set(u,d);const l={};for(const[u,d]of a){const h=Pd(d);if(!h||this.#e.history.list.some(p=>p.id===u&&p.archived))continue;if(this.#ce(u)){this.#we(u,h);continue}const m=this.#e.turnAttention[u];l[u]=m?.hostAt===h.hostAt?m:h}JSON.stringify(l)!==JSON.stringify(this.#e.turnAttention)&&this.#t({turnAttention:l})}get historyPaged(){return this.hasCapability("session.list.page")}async loadHistory({quiet:t=!1,query:i=this.#e.history.query}={}){const a=this.#e.workspace;if(!a)return;const l=this.#l,u=++this.#G,d=this.historyPaged,h=i.trim();t||this.#t(m=>({history:{...m.history,status:"loading",error:void 0,query:i}}));try{const m=await this.#r().request("session.list",{projectRoot:a,rootsOnly:!0,includeClosed:!0,includeArchived:!0,...d?{limit:this.#n.historyPageSize,...h?{query:h}:{}}:{}});if(l!==this.#l||u!==this.#G)return;const p=d&&typeof m?.nextCursor=="string"?m.nextCursor:void 0;this.#t({history:{status:"ready",list:ry(m,!d),query:i,...p?{nextCursor:p}:{}}})}catch(m){if(l!==this.#l||u!==this.#G)return;(!t||this.#e.history.status!=="ready")&&this.#t(p=>({history:{...p.history,status:"error",error:Be(m),query:i}}))}}async loadMoreHistory(){const t=this.#e.workspace,{status:i,nextCursor:a,query:l,more:u}=this.#e.history;if(!t||i!=="ready"||!a||u==="loading")return;const d=this.#l,h=this.#G,m=l.trim();this.#t(p=>({history:{...p.history,more:"loading"}}));try{const p=await this.#r().request("session.list",{projectRoot:t,rootsOnly:!0,includeClosed:!0,includeArchived:!0,limit:this.#n.historyPageSize,cursor:a,...m?{query:m}:{}});if(d!==this.#l)return;if(h!==this.#G){this.#He();return}const x=typeof p?.nextCursor=="string"?p.nextCursor:void 0;this.#t(y=>{const w=new Set(y.history.list.map(A=>A.id)),{more:k,nextCursor:j,...S}=y.history;return{history:{...S,list:[...S.list,...ry(p,!1).filter(A=>!w.has(A.id))],...x?{nextCursor:x}:{}}}})}catch{if(d!==this.#l)return;if(h!==this.#G){this.#He();return}this.#t(p=>({history:{...p.history,more:"error"}}))}}#He(){if(this.#e.history.more!=="loading")return;const{more:t,...i}=this.#e.history;this.#t({history:i})}get filesSearchable(){return this.hasCapability("workspace.files")}async searchWorkspaceFiles({query:t="",limit:i=Wb}={}){const a=this.#e.workspace;if(!a)throw new Ke("Choose a workspace first.");if(!this.filesSearchable)throw new Ke("The host does not offer file search. Update ALP on the host.");if(!Te(this.#e.principal??void 0,"project.read"))throw new Ke(ay);let l;try{l=await this.#r().request("workspace.files.search",{projectRoot:a,query:String(t).slice(0,200),limit:i})}catch(d){throw Be(d).code===1003?new Ke(ay):d}return{files:(Array.isArray(l?.files)?l.files:[]).filter(d=>d&&typeof d.path=="string"&&d.path).map(d=>({path:String(d.path)})),truncated:l?.truncated===!0}}get filesReadable(){return this.hasCapability("workspace.files.read")}get canReadFiles(){return Te(this.#e.principal??void 0,"files.read")}#Ie(t,i){const a=(d,h,m=!1)=>new Ei({message:d,reason:h,sent:"no",terminal:m}),l=this.#e.workspace;if(!l)throw a("Choose a workspace first.","workspace");if(!this.filesReadable)throw a(Qb,"capability",!0);if(!this.canReadFiles)throw a(kf,"grant",!0);if(t===void 0||t===""){if(i)throw a(Ir.invalid_path,"invalid_path");return{workspace:l,path:void 0}}const u=Js(t);if(!u)throw a(Ir.invalid_path,"invalid_path");if($i(u))throw a(Ir.blocked_path,"blocked_path");return{workspace:l,path:u}}#Ge(t){const i=g2(t);return i.code===1003&&i.reason==="grant"?new Ei({...i,message:kf}):new Ei(i)}async listWorkspaceFiles({path:t,includeIgnored:i=!1}={}){const a=this.#Ie(t,!1);let l;try{l=await this.#r().request("workspace.files.list",{projectRoot:a.workspace,...a.path?{path:a.path}:{},...i?{includeIgnored:!0}:{}})}catch(u){throw this.#Ge(u)}return x2(l,a.path??"")}async readWorkspaceFile({path:t,includeIgnored:i=!1}){const a=this.#Ie(t,!0);let l;try{l=await this.#r().request("workspace.files.read",{projectRoot:a.workspace,path:a.path,...i?{includeIgnored:!0}:{}})}catch(d){throw this.#Ge(d)}const u=typeof l?.content=="string"?l.content:void 0;if(u===void 0||u.length>Hl.maxReadBytes)throw new Ei({message:u===void 0?"The host sent something this app does not understand.":Ir.too_large,...u===void 0?{}:{reason:"too_large"},sent:"yes",terminal:!1});return{path:a.path,content:u,size:typeof l?.size=="number"&&Number.isFinite(l.size)?l.size:u.length,...typeof l?.modifiedAt=="string"?{modifiedAt:l.modifiedAt}:{}}}get gitAccess(){return Gd(this.#e)}async gitStatus(){const t=Gd(this.#e);if(!t.status)throw new ys({message:t.message,reason:t.reason,sent:"no",terminal:t.reason!=="loading"});let i;try{i=await this.#r().request("workspace.git.status",{workspaceId:t.workspaceId})}catch(a){throw new ys(_i(a))}if(!i||typeof i!="object"||typeof i.state!="string"||!Array.isArray(i.files))throw new ys({message:"The host sent something this app does not understand.",sent:"yes",terminal:!1});return i}async gitDiff({compare:t,path:i,cursor:a}){const l=Gd(this.#e);if(!l.status)throw new ys({message:l.message,reason:l.reason,sent:"no",terminal:l.reason!=="loading"});if(!l.content)throw new ys({message:l.contentMessage,reason:"grant",sent:"no",terminal:!0});const u=i===void 0?void 0:cj(i);if(i!==void 0&&!u){const h=Js(i)?"blocked_path":"invalid_path";throw new ys({message:Gl[h],reason:h,sent:"no",terminal:!1})}let d;try{d=await this.#r().request("workspace.git.diff",{workspaceId:l.workspaceId,compare:uj(t),...u?{path:u}:{},...a?{cursor:a}:{}})}catch(h){throw new ys(_i(h))}if(!d||typeof d!="object"||typeof d.snapshot!="string"||!Array.isArray(d.files))throw new ys({message:"The host sent something this app does not understand.",sent:"yes",terminal:!1});return d}isArchived(t){return t?!!this.#e.history.list.find(i=>i.id===t)?.archived&&!this.#e.sessions.list.some(i=>i.id===t):!1}async#Te(){const t=this.#e.workspace,i=this.#e.principal;if(!t||!i)return;const a=this.#l;this.#t(l=>({catalog:{...l.catalog,status:"loading",error:void 0}}));try{const l=this.#r(),[u,d,h]=await Promise.all([this.#Ye(l,i,t),Te(i,"session.read")?l.request("catalog.get",{}).catch(()=>{}):void 0,this.hasCapability("library")&&Te(i,"session.read")?l.request("library.models",{}).catch(()=>{}):void 0]);if(a!==this.#l)return;const m=i.modes,x=(Array.isArray(d?.modes)&&d.modes.length?d.modes:Object.keys(iy).map(k=>({id:k}))).filter(k=>typeof k?.id=="string"&&(!m||m.includes(k.id))).map(k=>({id:k.id,label:typeof k.label=="string"?k.label:iy[k.id]??k.id,...typeof k.description=="string"?{description:k.description}:{}})),y=Gx(h?.models),w=x.some(k=>k.id==="full-access")?"full-access":x[0]?.id;this.#t({catalog:{status:"ready",...u,modes:x,models:y,...w?{defaultMode:w}:{}}})}catch(l){if(a!==this.#l)return;this.#t(u=>({catalog:{...u.catalog,status:"error",error:Be(l)}}))}}async#Ye(t,i,a){if(!this.hasCapability("team"))return{teams:[],teamsKnown:!1,teamsUnavailable:{reason:"capability"}};if(!Te(i,"project.read"))return{teams:[],teamsKnown:!1,teamsUnavailable:{reason:"permission"}};try{const l=await t.request("team.list",{projectRoot:a});return Array.isArray(l?.teams)?{teams:l.teams.filter(d=>typeof d?.id=="string"&&!d.error).map(d=>({id:d.id,label:typeof d.label=="string"?d.label:d.id,...typeof d.description=="string"?{description:d.description}:{}})),teamsKnown:!0}:{teams:[],teamsKnown:!1,teamsUnavailable:{reason:"failed",message:"The host answered team.list in a form this app does not read."}}}catch(l){return{teams:[],teamsKnown:!1,teamsUnavailable:{reason:"failed",message:Be(l).message}}}}startOrigin(){return{workspace:this.#e.workspace,connection:this.#U}}keepUnsentDraft(t,i){if(!t||!i?.workspace||i.connection!==this.#U)return;const a={workspace:i.workspace,text:String(t)};for(const l of this.#z)if(l(a)){this.#M=null;return}this.#M=a}takeUnsentDrafts(t){return this.#z.add(t),()=>{this.#z.delete(t)}}unsentDraft(){const t=this.#M;return t&&t.workspace===this.#e.workspace?t.text:""}clearUnsentDraft(t){(t===void 0||this.#M?.text===t)&&(this.#M=null)}async retryTeams(){const{workspace:t,principal:i,catalog:a}=this.#e;if(!t||!i||a.status!=="ready"||a.teamsUnavailable?.reason!=="failed"||this.#C)return;const l=this.#l;this.#C=!0;try{const u=await this.#Ye(this.#r(),i,t);if(l!==this.#l||this.#e.workspace!==t||this.#e.catalog.status!=="ready")return;this.#t(d=>({catalog:{...d.catalog,teams:u.teams,teamsKnown:u.teamsKnown,teamsUnavailable:u.teamsUnavailable}}))}catch{}finally{this.#C=!1}}selectSession(t){if(this.clearAttention(t),t===this.#e.selected)return;const i=t?this.#_(t):void 0;i&&(i.failed=null),this.#t({selected:t,focus:t,tree:t&&i?{rootId:t,status:i.gone?"gone":"detached",...i.gone?{error:i.gone}:{},projection:i.projection}:null}),this.#V()}focusSession(t){const i=this.#e.tree?.projection;!i||t!==i.rootId&&!i.sessions[t]||(this.clearAttention(t),this.#t({focus:t}))}async createSession({team:t,mode:i,model:a,thinking:l,title:u,prompt:d,files:h=[]}={}){const m=this.#e.workspace;if(!m)throw new Ke("Choose a workspace first.");if(this.#T||this.#e.busy.create)throw new Ke("A new session is already starting.");const p=this.#r(),x=V2(),y=this.#l;this.#T=x,this.#t(A=>({busy:{...A.busy,create:!0}}));const w=this.#_(x),k={id:x,projectRoot:m,status:"initializing",...u?{title:u}:{},createdAt:new Date().toISOString()};this.#t(A=>({selected:x,focus:x,tree:{rootId:x,status:"attaching",projection:w.projection},sessions:{...A.sessions,list:[k,...A.sessions.list.filter(R=>R.id!==x)]}}));const j=()=>y===this.#l&&p===this.#i?.alp?.client,S=()=>{if(!j())throw new Ke("The connection or workspace changed while starting the session.")};try{return await this.#k(p,async()=>{S();const A=this.#s;A&&A.client===p&&(this.#s=null,this.#a=null,await this.#J(A)),S();const R={buffer:[]};w.attaching=R,this.#a=x;const q={cwd:m,persist:!0,...t?{workflow:t}:{},...i?{mode:i}:{},...a?{model:a}:{},...l?{thinking:l}:{}};this.#s={client:p,root:x};try{await p.request("session.create",{sessionId:x,spec:q,history:"skip"},{timeoutMs:this.#n.createTimeoutMs}),S(),this.#s={client:p,root:x}}catch(O){if(!j())throw O;w.attaching=null;const L=Be(O);throw L.sent!=="unknown"?(this.#s?.client===p&&this.#s.root===x&&(this.#s=null,await this.#J({client:p,root:x})),j()&&(this.#o.delete(x),this.#c.delete(x),this.#f.delete(x),this.#a===x&&(this.#a=null),this.#t(B=>({...B.selected===x?{selected:null,focus:null,tree:null}:{},sessions:{...B.sessions,list:B.sessions.list.filter(_=>_.id!==x)}}))),O):(this.refreshSessions(),new wb(`${L.message} If the new session shows in the list, open it and send your message there; otherwise start again.`,x))}try{let O;if(this.hasCapability("session.history")){const B=await p.request("session.history",{sessionId:x,limit:1},{timeoutMs:this.#n.requestTimeoutMs});S(),O=B.generation,this.#c.set(x,{generation:O,hasOlder:!1})}const L=await p.request("session.attach",{sessionId:x,...O?{generation:O,after:0}:{}},{timeoutMs:this.#n.requestTimeoutMs});S(),w.attaching===R&&(w.attaching=null,w.failed=null,this.#ke(x,w,L,R.buffer))}catch(O){if(!j())throw O;w.attaching===R&&(w.attaching=null),this.#a===x&&(this.#a=null),this.#Ne(p,x,O)}return u?.trim()&&await this.renameSession(x,u.trim()).catch(()=>{}),S(),this.#Et({team:t,mode:i,model:a,thinking:l}),(d?.trim()||h.length)&&await this.sendPrompt(d??"",x,[],h,{keepRefused:!0}).catch(O=>this.#u("error",Be(O).message)),this.refreshSessions({quiet:!0}),x})}finally{this.#T===x&&(this.#T=null,this.#t(A=>({busy:{...A.busy,create:!1}}))),this.#V()}}async renameSession(t,i){const u=(await this.#r().request("session.rename",{sessionId:t,title:i}))?.session,d=m=>m.id===t?{...m,...u&&typeof u=="object"?u:{},title:i}:m;this.#t(m=>({sessions:{...m.sessions,list:m.sessions.list.map(d)},history:{...m.history,list:m.history.list.map(d)}}));const h=this.#o.get(t);h&&(h.projection={...h.projection,sessions:{...h.projection.sessions,[t]:{...h.projection.sessions[t],id:t,title:i}}},this.#L(t))}async archiveSession(t){const i=this.#r(),a=this.#l;if(await i.request("session.archive",{sessionId:t,archived:!0}),a!==this.#l)return;this.#e.selected===t&&this.selectSession(null);const{[t]:l,...u}=this.#e.attention,{[t]:d,...h}=this.#e.turnAttention;this.#t(m=>({turnAttention:h,sessions:{...m.sessions,list:m.sessions.list.filter(p=>p.id!==t)},history:{...m.history,list:m.history.list.map(p=>p.id===t?{...p,archived:!0}:p)},attention:u}))}async restoreSession(t){const i=this.#r(),a=this.#l,l=await i.request("session.archive",{sessionId:t,archived:!1});if(a!==this.#l)return;const u=l?.session&&typeof l.session=="object"?l.session:void 0;this.#t(d=>{const m={...d.history.list.find(p=>p.id===t)??{},...u??{},id:t,archived:!1};return{history:{...d.history,list:d.history.list.map(p=>p.id===t?m:p)},sessions:{...d.sessions,list:d.sessions.list.some(p=>p.id===t)?d.sessions.list:[m,...d.sessions.list]}}}),this.refreshSessions({quiet:!0})}#de(t){const i=this.#e.sessions.list.find(l=>l.id===t)??this.#e.history.list.find(l=>l.id===t),a=this.#o.get(t)?.projection.sessions[t];return{...i??{},...a??{},...a?.conversation?{}:i?.conversation?{conversation:i.conversation}:{}}}conversationGate(t=this.#e.tree?.rootId){const{principal:i,connection:a}=this.#e,l=t?this.#o.get(t):void 0,u=!!t&&!!l&&(this.rootBusy(t)||Object.keys(l.projection.running).length>0||Object.keys(l.projection.questions).length>0);return Q2({capabilities:a.capabilities,canRead:Te(i??void 0,"session.read"),canWrite:Te(i??void 0,"session.write"),summary:t?this.#de(t):null,busy:u,generation:t?this.#c.get(t)?.generation??null:null,online:a.phase==="open",driveBlock:t&&t===this.#e.tree?.rootId?this.driveBlock():void 0})}agentControls(t){const{principal:i,connection:a}=this.#e,l=this.#e.tree?.rootId,u=l?this.#o.get(l):void 0,d=!!l&&t===l,h=d&&!!u&&(this.rootBusy(l)||Object.keys(u.projection.running).length>0||Object.keys(u.projection.questions).length>0);return nj({capabilities:a.capabilities,canRead:Te(i??void 0,"session.read"),canWrite:Te(i??void 0,"session.write"),summary:d?this.#de(l):null,root:d,closed:d&&!!u?.projection.closed[l],busy:h,generation:d?this.#c.get(l)?.generation??null:null,online:a.phase==="open",driveBlock:d?this.driveBlock():void 0})}#ee=new Map;async listCommands(t){if(!this.#e.connection.capabilities.includes("session.commands"))return this.#ee.get(t)??[];try{const i=await this.#r().request("session.commands",{sessionId:t}),a=Array.isArray(i?.commands)?i.commands.filter(l=>typeof l?.name=="string"&&l.name):[];return(a.length||!this.#ee.has(t))&&this.#ee.set(t,a),this.#ee.get(t)??[]}catch{return this.#ee.get(t)??[]}}async copyResumeCommand(t,i){try{const a=await this.#r().request("session.resumeCommand",{sessionId:t});if(typeof a?.display!="string"||!a.display)throw new Ke("The host answered no command.");return await i(a.display),this.#u("info",`Copied the resume command: ${a.display}`),a}catch(a){this.#u("error",`Could not copy the resume command: ${Be(a).message}`);return}}async reloadAgent({sessionId:t,requestId:i}){const{root:a,generation:l,client:u}=this.#fe();if(t!==a)throw new Ke(Fr.not_root);this.#u("info","Reloading the agent…");try{const d=await u.request("session.reload",{sessionId:a,requestId:i,ifGeneration:l},{timeoutMs:this.#n.createTimeoutMs});return this.#Ae(d.session),this.refreshSessions({quiet:!0}),this.#u("info","Reloaded the agent: it restarted on the same conversation."),d}catch(d){throw this.#he(a,d),this.#u("error",Z2(d).message),d}}async compactAgent({sessionId:t}){const i=this.#e.tree?.rootId;if(!i||t!==i)throw new Ke(Wf.not_root);try{const a=await this.#r().request("session.compact",{sessionId:i});return this.#u("info",ej(a?.status)),a}catch(a){throw this.#u("error",tj(a).message),a}}rootSummary(t=this.#e.tree?.rootId){return t?this.#de(t):{}}historyGeneration(t){return this.#c.get(t)?.generation}#Ae(t){if(!t||typeof t.id!="string")return;const i=t.id,a=u=>u.id===i?{...u,...t}:u;this.#t(u=>({sessions:{...u.sessions,list:u.sessions.list.map(a)},history:{...u.history,list:u.history.list.map(a)}}));const l=this.#o.get(i);l&&(l.projection={...l.projection,sessions:{...l.projection.sessions,[i]:{...l.projection.sessions[i],...t,id:i}}},this.#L(i))}#fe(){const t=this.#e.tree?.rootId??this.#e.selected;if(!t)throw new Ke("Open a session first.");const i=this.#c.get(t)?.generation;if(!i)throw new Ke("The conversation is still loading. Try again in a moment.");return{root:t,generation:i,client:this.#r()}}#he(t,i){if(!ei(i).reload)return;const a=this.#s?.root===t?this.#s.client:void 0;this.#c.delete(t),a&&this.#je(a,t)}async rewindConversation({beforeTurnId:t,requestId:i}){const{root:a,generation:l,client:u}=this.#fe();try{const d=await u.request("session.rewind",{sessionId:a,requestId:i,ifGeneration:l,beforeTurnId:t},{timeoutMs:this.#n.createTimeoutMs});return this.#Ae(d.session),this.#Be(a,d.generation),this.refreshSessions({quiet:!0}),d}catch(d){throw this.#he(a,d),d}}async forkConversation({requestId:t,boundary:i,branchId:a,workspaceId:l,directory:u,title:d}){const{root:h,generation:m,client:p}=this.#fe();let x;try{x=await p.request("session.fork",{sessionId:h,requestId:t,ifGeneration:m,...i?{boundary:i}:{},...a?{branchId:a}:{},...l?{workspaceId:l}:{},...d?.trim()?{title:d.trim()}:{}},{timeoutMs:this.#n.createTimeoutMs})}catch(y){throw this.#he(h,y),y}return this.#xt(x.session,u),x}#xt(t,i){const a=t?.id;typeof a=="string"&&(i&&i!==this.#e.workspace&&this.selectWorkspace(i),this.#t(l=>({sessions:{...l.sessions,list:[t,...l.sessions.list.filter(u=>u.id!==a)]}})),this.selectSession(a),this.refreshSessions({quiet:!0}))}worktreeForkSource(){const{workspace:t,principal:i,registry:a}=this.#e;if(!t||!this.hasCapability("workspace.worktree")||!this.hasCapability("workspace.registry")||!Te(i??void 0,"workspace.manage"))return null;const l=i?.workspaceRoots?.find(u=>u.path===t)?.canonical;return a.workspaces.find(u=>!u.managedWorktree&&!u.archivedAt&&(u.directory===t||u.directory===l))??null}async forkIntoWorktree({requestId:t,worktreeKey:i=t,mappingId:a,boundary:l,branchId:u,title:d}){const h=this.worktreeForkSource();if(!h)throw new Ke("Worktrees are not available for this workspace.");const m=this.#d.get(t)??i;this.#d.set(t,m);try{let p=this.#w.get(m);if(!p){let y=this.#b.get(m);y||(y={workspaceId:h.id,mappingId:a,ifRevision:this.#e.registry.revision,requestId:`${m}:worktree`},this.#b.set(m,y));let w;try{w=await this.#r().request("workspace.worktree.create",y,{timeoutMs:this.#n.createTimeoutMs})}catch(k){throw(k?.data?.reason==="stale_revision"||Be(k).sent==="yes")&&this.#b.delete(m),k}p={id:w.workspace.id,directory:w.workspace.directory},this.#w.set(m,p),this.#b.delete(m),await this.refreshRegistry()}const x=await this.forkConversation({requestId:t,boundary:l,branchId:u,workspaceId:p.id,directory:p.directory,title:d});return this.#d.delete(t),x}catch(p){throw ei(p).retrySame||this.#d.delete(t),p}}async worktreeForkDestinations(){const t=this.worktreeForkSource();return t?this.worktreeOptions(t.id):[]}driveBlock(){const{principal:t,tree:i}=this.#e;if(!t)return"Not connected.";if(!Te(t,"session.write"))return"Your access token can view sessions but not send messages.";if(!i)return;const a=t.modes;if(a){const l=Bb(i.projection).find(u=>u.session?.mode&&!a.includes(u.session.mode));if(l)return`Your access token can only drive sessions in ${a.join(", ")} mode; this conversation runs in ${l.session?.mode}.`}}#yt(t,i){return this.#k(t,async()=>{if(!(t!==this.#i?.alp?.client||this.#e.selected!==i))try{await this.#bt(t,i)}finally{this.#V()}})}async#bt(t,i){const a=this.#_(i),l=a.projection.sessions[i],u=this.#e.sessions.list.find(y=>y.id===i);if(!(a.projection.closed[i]||l?.status==="closed"||!l&&u?.status==="closed"))return;const h=l?.projectRoot??u?.projectRoot??this.#e.workspace??"",m=Ll(this.#e.principal??void 0,h)?.path??this.#e.workspace??h,p=l?.mode??u?.mode,x={buffer:[]};a.attaching=x,this.#a=i;try{if(await t.request("session.create",{sessionId:i,spec:{cwd:m,...p?{mode:p}:{}},resume:!0,history:"skip"},{timeoutMs:this.#n.createTimeoutMs}),t!==this.#i?.alp?.client)return;if(this.#s={client:t,root:i},this.hasCapability("session.history")&&!this.#c.has(i)){const j=await t.request("session.history",{sessionId:i},{timeoutMs:this.#n.requestTimeoutMs});if(a.attaching!==x)return;a.projection=bs(i);for(const S of j.items)a.projection=zi(a.projection,bf(S,i));this.#W(a.projection),a.projection={...a.projection,cursor:j.tipCursor},this.#c.set(i,{generation:j.generation,olderCursor:j.olderCursor,hasOlder:j.hasOlder})}const y=a.projection.cursor,w=this.#c.get(i),k=await t.request("session.attach",{sessionId:i,...w?{after:y,generation:w.generation}:y>0?{after:y}:{}},{timeoutMs:this.#n.requestTimeoutMs});a.attaching===x&&(a.attaching=null,this.#ke(i,a,k,x.buffer))}catch(y){throw a.attaching===x&&(a.attaching=null),y}}async sendPrompt(t,i=this.#e.selected,a=[],l=[],{keepRefused:u=!1}={}){const d=String(t??"");if(!i||!d.trim()&&!a.length&&!l.length)return;const h=this.driveBlock();if(h)throw new Ke(h);const m=Xr([],a,this.#e.connection.promptImageLimits);if(m.error)throw new Ke(m.error);const p=l.length?this.#Ve(i,l):null;if(p&&!u)throw new Ke(p);const x=Tl(),y={id:x,rootId:i,text:d,...a.length?{images:a}:{},...l.length?{files:l.map(w=>({...w,received:0,error:void 0})),uploadKey:x}:{},delivery:this.rootBusy(i)?"steer":"auto",status:"sending",retrySameId:!0,at:Date.now()};if(this.clearAttention(i),p){this.#t(w=>({prompts:[...w.prompts,{...y,status:"failed",error:p}]})),this.#Me(y);return}this.#t(w=>({prompts:[...w.prompts,y]})),this.#Me(y),await this.#Ke(y)}fileGate(t=this.#e.selected){const{connection:i,principal:a}=this.#e,l=t?this.#o.get(t)?.projection.sessions[t]??this.#e.sessions.list.find(u=>u.id===t):void 0;return vj({capable:i.capabilities.includes("attachments"),permitted:Te(a??void 0,"attachments.write"),writable:Te(a??void 0,"session.write"),limits:i.attachmentLimits,session:l,known:!!t})}#Ve(t,i){return this.fileGate(t)??Ol([],i,this.#e.connection.attachmentLimits??Ps).error}#vt(t,i){const a=this.#wt(t,i);this.#me.set(i.id,a);const l=()=>{this.#me.get(i.id)===a&&this.#me.delete(i.id)};return a.then(l,l),a}#me=new Map;#te(t){return this.#e.prompts.some(i=>i.id===t)}async#wt(t,i){const a=i.files??[],l=i.uploadKey??i.id,u=this.#e.connection.attachmentLimits??Ps,d=(p,x)=>this.#t(y=>({prompts:y.prompts.map(w=>w.id===i.id&&w.files?{...w,files:w.files.map((k,j)=>j===p?{...k,...x}:k)}:w)})),h=$d(t),m=[...a];for(const[p,x]of a.entries())if(!x.attachmentId){if(!this.#te(i.id))throw new $r;d(p,{error:void 0,received:x.received??0,started:!0});try{const y=await h.upload({sessionId:i.rootId,name:x.name,mimeType:x.mimeType,data:x.data,requestId:Bx(l,p,x.attempt),maxChunkBytes:u.maxChunkBytes,onProgress:w=>{if(!this.#te(i.id))throw new $r;d(p,{received:w})}});if(typeof y?.attachmentId!="string")throw new Error(`The host did not answer an attachment for ${x.name}.`);m[p]={...x,attachmentId:y.attachmentId,received:x.size,error:void 0},d(p,{attachmentId:y.attachmentId,received:x.size,error:void 0})}catch(y){if(y instanceof $r||!this.#te(i.id))throw new $r;const w=Be(y);throw d(p,{error:w.message}),new oy(x.name,w,Ff(y)&&["closed","disconnected","send_failed"].includes(y.reason))}}return m}#kt(){for(const t of this.#e.prompts)t.status!=="failed"||!t.resumeUpload||t.resumeUpload>3||this.retryPrompt(t.id,{resume:!0}).catch(()=>{})}async#Ke(t){const i=t.rootId,a=this.#ne.get(i),l=(async()=>{a&&await a.catch(()=>{});const u=this.#e.prompts.find(h=>h.id===t.id);if(!u||u.status!=="sending")return;const d=this.rootBusy(i,t.id)?"steer":"auto";d!==u.delivery&&this.#t(h=>({prompts:h.prompts.map(m=>m.id===t.id?{...m,delivery:d}:m)})),await this.#Fe({...u,delivery:d})})();this.#ne.set(i,l);try{await l}finally{this.#ne.get(i)===l&&this.#ne.delete(i)}}#ne=new Map;rootBusy(t=this.#e.selected,i){if(!t)return!1;const a=this.#o.get(t);if(a&&t in a.projection.running||this.#x.has(t))return!0;for(const u of this.#O.get(t)??[]){if(u===i)continue;const d=a?.projection.prompts[u];if(!this.#F.has(u)&&(!d||d.errorCode==="outcome_unknown"))return!0}if(this.#e.prompts.some(u=>u.rootId===t&&u.id!==i&&u.status==="unknown")||this.#e.prompts.some(u=>u.rootId===t&&u.id!==i&&u.status==="sending"&&!u.accepted&&this.#ge.has(u.id)))return!0;const l=this.#K.get(t);if(!l||!a)return!1;for(const[u]of l){if(u===i)continue;const d=a.projection.prompts[u];if(!(d?.state==="failed"||!d&&!this.#F.has(u)||(!d?.turnId||!a.projection.turns[d.turnId])&&Date.now()-(this.#se.get(u)??0)>this.#Qe)&&(!d||!Hx(a.projection,u)))return!0}return!1}async configureMode(t){const i=this.#e.selected;if(!i||!t)return;const a=this.#e.principal?.modes,l=this.driveBlock()??(a&&!a.includes(t)?`Your access token can only use ${a.join(", ")} mode.`:void 0);if(l){this.#u("error",l);return}if(!this.#e.busy.mode){this.#t(u=>({busy:{...u.busy,mode:!0}}));try{const u=await this.#r().request("session.configure",{sessionId:i,mode:t},{timeoutMs:this.#n.requestTimeoutMs}),d=this.#o.get(i),h=typeof u?.session?.mode=="string"?u.session.mode:t;d&&(d.projection={...d.projection,sessions:{...d.projection.sessions,[i]:{...d.projection.sessions[i],id:i,mode:h}}},this.#L(i)),this.#t(m=>({sessions:{...m.sessions,list:m.sessions.list.map(p=>p.id===i?{...p,mode:h}:p)}}))}catch(u){this.#u("error",Be(u).message)}finally{this.#t(u=>({busy:{...u.busy,mode:!1}}))}}}liveConfigure(){const{principal:t,connection:i,busy:a}=this.#e,l=this.#e.tree?.rootId,u=l?this.#o.get(l):void 0,d=!!l&&!!u&&(this.rootBusy(l)||Object.keys(u.projection.running).length>0||Object.keys(u.projection.questions).length>0);return Gj({capabilities:i.capabilities,canWrite:Te(t??void 0,"session.write"),canTeam:Te(t??void 0,"session.team.write"),summary:l?this.#de(l):null,closed:!!l&&!!u?.projection.closed[l],busy:d,configuring:!!a.configure||!!a.mode,generation:l?this.#c.get(l)?.generation??null:null,online:i.phase==="open",driveBlock:l?this.driveBlock():void 0})}async previewConfigure(t={}){const i=this.#e.tree?.rootId;if(!i||!this.hasCapability(Gb)||!Te(this.#e.principal??void 0,"session.read"))return;const a=await this.#r().request("session.configure.preview",{sessionId:i,...t},{timeoutMs:this.#n.requestTimeoutMs});return a?.preview&&typeof a.preview=="object"?a.preview:void 0}#pe;async configureLive(t){const i=this.#e.tree?.rootId,a=Object.fromEntries(Object.entries(t).filter(([h,m])=>["model","thinking","team"].includes(h)&&typeof m=="string"&&m));if(!i||!Object.keys(a).length||this.#e.busy.configure)return;const l=this.liveConfigure(),u=a.team?l.team:a.model?l.model:l.thinking;if(!l.shown||!u.enabled){this.#u("error",u.reason??l.reason??"This change is not available now.");return}this.#t(h=>({busy:{...h.busy,configure:!0}}));const d=JSON.stringify([i,a]);try{if(a.team){const w=await this.previewConfigure(a).catch(()=>{});if(w&&!w.allowed){const k=w.reason??"runtime_unsupported";this.#u("error",Ma[k]??w.message??"The host would not take this change.",Yb.has(k)?{action:"new-session"}:void 0);return}}const{generation:h,client:m}=this.#fe(),p=this.#pe?.key===d?this.#pe.requestId:Qf();this.#pe=void 0;let x;try{x=await m.request("session.configure",{sessionId:i,...a,requestId:p,ifGeneration:h},{timeoutMs:this.#n.createTimeoutMs})}catch(w){const k=Fx(w);k.retrySame&&(this.#pe={key:d,requestId:p}),this.#he(i,w),this.#u("error",k.message,k.newSession?{action:"new-session"}:void 0);return}const y=x?.configured;if(this.#Ae(Yj(x.session,y?.effective)),this.refreshSessions({quiet:!0}),y){const w=this.#e.catalog.models.find(k=>k.id===`${y.effective.runtime}:${y.effective.model}`)?.label;this.#u("info",Vj(y,Xs,w))}return x}catch(h){this.#u("error",Fx(h).message);return}finally{this.#t(h=>({busy:{...h.busy,configure:!1}}))}}async#Fe(t){const i=a=>this.#t(l=>({prompts:l.prompts.map(u=>u.id===t.id?{...u,...a}:u)}));this.#ge.add(t.id);try{const a=this.#r();!(this.#T===t.rootId&&this.#s?.client===a&&this.#s.root===t.rootId)&&this.#e.selected===t.rootId&&await this.#yt(a,t.rootId);const u=Xr([],t.images??[],this.#e.connection.promptImageLimits);if(u.error)throw new Ke(u.error);let d=t.files??[];if(d.length){const p=this.#Ve(t.rootId,d);if(p)throw new Ke(p);if(d=await this.#vt(a,t),!this.#te(t.id))return}if(!this.#te(t.id))return;i({submitted:!0});let h=this.#O.get(t.rootId);h||this.#O.set(t.rootId,h=new Set),h.add(t.id);const m=await a.request("session.prompt",{sessionId:t.rootId,clientMessageId:t.id,delivery:t.delivery,content:Aj(t.text,t.images,d)},{timeoutMs:this.#n.requestTimeoutMs});if(m?.outcome==="unknown"){i({status:"unknown",error:"The host cannot tell whether the agent took the message.",retrySameId:!1});return}if(m?.outcome==="failed"){this.#_e(t.rootId,t.id),i({status:"failed",error:m.error?.message?`The agent did not take the message: ${m.error.message}`:"The agent did not take the message.",retrySameId:!1});return}this.#F.add(t.id),this.#Nt(),this.#Xe(t)?this.#Ce(t.id):i({accepted:!0})}catch(a){if(this.#Xe(t))return this.#Ce(t.id);if(a instanceof $r)return;if(a instanceof oy){const u=a.dropped,d=this.#e.prompts.find(h=>h.id===t.id)?.resumeUpload??0;i({status:"failed",error:`Could not upload ${a.fileName}: ${a.failure.message}${u?" The upload continues when the connection is back.":""}`,retrySameId:!0,resumeUpload:u?d+1:0});return}const l=Be(a);t.files?.length&&(l.reason==="attachment_unavailable"||l.code===1001)&&await this.#jt(t,a),l.sent==="no"?i({status:"failed",error:l.message,retrySameId:!0}):l.sent==="yes"&&l.reason!=="outcome_unknown"?i({status:"failed",error:l.message,retrySameId:!1}):i({status:"unknown",error:l.message,retrySameId:l.reason!=="outcome_unknown"})}finally{this.#ge.delete(t.id),this.#e.prompts.find(l=>l.id===t.id)?.status==="failed"?this.#_e(t.rootId,t.id):this.#A(t.rootId)}}async#jt(t,i){const a=i?.data,u=(this.#e.prompts.find(h=>h.id===t.id)?.files??[]).filter(h=>typeof h.attachmentId=="string");let d;if(a?.reason==="attachment_unavailable"){const h=u.filter(m=>m.attachmentId===a?.attachmentId);d=new Set((h.length?h:u).map(m=>m.attachmentId))}else{let h;try{h=$d(this.#r())}catch{return}const m=await Promise.all(u.map(p=>h.get(p.attachmentId).then(()=>!1,x=>Be(x).code===1001)));d=new Set(u.filter((p,x)=>m[x]).map(p=>p.attachmentId))}d.size&&this.#t(h=>({prompts:h.prompts.map(m=>m.id===t.id&&m.files?{...m,files:m.files.map(p=>p.attachmentId&&d.has(p.attachmentId)?{...p,attachmentId:void 0,received:0,started:!1,attempt:(p.attempt??0)+1}:p)}:m)}))}#ge=new Set;#Xe(t){const i=this.#o.get(t.rootId);return!!i&&Ix(i.projection).has(t.id)}#Ce(t){this.#t(i=>({prompts:i.prompts.filter(a=>a.id!==t)}))}async retryPrompt(t,{resume:i=!1}={}){const a=this.#e.prompts.find(d=>d.id===t);if(!a||a.status==="sending")return;const l=i?a.resumeUpload:0,u=a.retrySameId?{...a,status:"sending",error:void 0,accepted:!1,resumeUpload:l}:{...a,id:Tl(),delivery:this.rootBusy(a.rootId,a.id)?"steer":"auto",status:"sending",error:void 0,retrySameId:!0,accepted:!1,resumeUpload:l,...a.files?.length?{uploadKey:a.uploadKey??a.id}:{}};if(this.#t(d=>({prompts:d.prompts.map(h=>h.id===t?u:h)})),u.id===a.id)return this.#Fe(u);this.#Pe(a.rootId,a.id),this.#Me(u),await this.#Ke(u)}#Pe(t,i){this.#K.get(t)?.delete(i),this.#se.delete(i),this.#F.delete(i)}discardPrompt(t){const i=this.#e.prompts.find(a=>a.id===t);i&&this.#Pe(i.rootId,t),this.#Ce(t),i&&this.#St(i)}#St(t){const i=(t.files??[]).map((u,d)=>({file:u,slot:d})).filter(({file:u})=>u.started&&!u.attachmentId);if(!i.length)return;const a=t.uploadKey??t.id,l=this.#me.get(t.id)??Promise.resolve();this.#Ee=this.#Ee.then(()=>l.catch(()=>{})).then(async()=>{let u;try{u=this.#r()}catch{return}const d=$d(u);for(const{file:h,slot:m}of i)await Tj(d,{sessionId:t.rootId,file:h,requestId:Bx(a,m,h.attempt),digest:vb})})}#Ee=Promise.resolve();abandonedUploads(){return this.#Ee}#K=new Map;#Me(t){let i=this.#K.get(t.rootId);i||this.#K.set(t.rootId,i=new Map),i.set(t.id,this.#o.get(t.rootId)?.projection.reset??0),this.#se.set(t.id,Date.now())}#se=new Map;#F=new Set;#$;get#Qe(){return this.#n.busyUnseenMs}#Nt(){this.#$!==void 0&&clearTimeout(this.#$),this.#$=setTimeout(()=>{this.#$=void 0,this.#i&&this.#t(t=>({busy:{...t.busy}}))},this.#Qe+100)}#We(t,i){const a=this.#K.get(t);if(!a)return!0;for(const[l,u]of a){const d=i.historyUnavailable&&i.reset>u&&Object.keys(i.running).length===0;(Hx(i,l)||d)&&(a.delete(l),this.#se.delete(l),this.#F.delete(l))}return a.size===0}queuePrompt(t){const i=this.#e.selected,a=String(t??"");if(!i||!a.trim())return;const l=this.driveBlock();if(l)throw new Ke(l);this.#t(u=>({queued:[...u.queued,{id:Tl(),rootId:i,text:a}]}))}interruptAndSend(t){const i=this.#e.selected,a=String(t??"");if(!i||!a.trim())return;const l=this.driveBlock();if(l)throw new Ke(l);this.#t(u=>({queued:[{id:Tl(),rootId:i,text:a},...u.queued]})),this.interrupt()}editQueued(t){const i=this.#e.queued.find(a=>a.id===t);return i?(this.#t(a=>({queued:a.queued.filter(l=>l.id!==t)})),i.text):null}async sendQueuedNow(t){const i=this.#e.queued.find(a=>a.id===t);!i||i.rootId!==this.#e.selected||(this.#t(a=>({queued:a.queued.filter(l=>l.id!==t)})),await this.sendPrompt(i.text))}#ze=!1;#Tt(){this.#ze||(this.#ze=!0,queueMicrotask(()=>{this.#ze=!1,this.#At()}))}#At(){const{selected:t,tree:i,connection:a,prompts:l,queued:u}=this.#e;if(!t||a.phase!=="open"||!i||i.rootId!==t||i.status!=="attached"||t in i.projection.running||l.some(h=>h.rootId===t)||!this.#We(t,i.projection)||this.driveBlock())return;const d=u.find(h=>h.rootId===t);d&&this.sendQueuedNow(d.id).catch(()=>{})}#O=new Map;#x=new Map;async interrupt(){const t=this.#e.selected;if(!t)return;const i=this.#x.get(t);if(i)return i.attempts=0,i.exhausted=!1,i.observer?.state==="stopped"&&this.#Ze(t,i),this.#A(t),i.promise;if(!this.hasCapability("session.interrupt.turn")){this.#u("error","This host cannot safely stop a specific turn. Upgrade the host to use Stop.");return}const a=this.#o.get(t)?.projection,l=a?.running[t],u=l?void 0:[...new Set([...this.#O.get(t)??[],...this.#e.prompts.filter(x=>x.rootId===t&&x.status!=="failed").map(x=>x.id)])].find(x=>{const y=a?.prompts[x];return!y||y.state==="failed"&&y.errorCode==="outcome_unknown"||y.state==="accepted"&&(!y.turnId||a?.turns[y.turnId]!=="ended")});if(!l&&!u)return;const d=this.#e.prompts.find(x=>x.id===u);if(d&&!d.submitted){this.discardPrompt(d.id),this.#u("info","Message canceled before sending.");return}let h=()=>{};const m=new Promise(x=>{h=()=>x(void 0)}),p={...l?{turnId:l}:{messageId:u},done:h,promise:m};return this.#x.set(t,p),this.#Ze(t,p),this.#t(x=>({busy:{...x.busy,interrupt:!0}})),l||this.#u("info",sy),this.#A(t),m}#Ze(t,i){const a=this.#i,l=this.#e.principal?.id,{open:u,backoff:d,stableMs:h,requestTimeoutMs:m}=this.#n,p=this.#e.connection.gateway,x=this.#m;let y=null,w=!1;i.observed??=this.#o.get(t)?.projection??bs(t);const k=()=>this.#i===a&&this.#x.get(t)===i,j=Cx({connect:async({signal:S})=>{const A=await u({url:p,token:x,signal:S});if(!k())throw A.transport.close(),new Ke("This Stop is no longer waiting.");if(A.principal.id!==l||!Te(A.principal,"session.read")||!Te(A.principal,"session.write"))throw A.transport.close(),new Ra("Stop access changed. Reconnect with the original access before trying again.");return A.transport},onConnect:async(S,{signal:A})=>{const R=await Ax(S,ny,{signal:A,timeoutMs:m}),q=Array.isArray(R.capabilities)?R.capabilities:[];if(!q.includes("session.interrupt.turn")||!q.includes("attach.after"))throw new Ke("This host cannot safely observe and stop a specific turn.");y=[];const O=await S.request("session.attach",{sessionId:t,after:i.observed?.cursor??0},{signal:A,timeoutMs:m});k()&&(i.observed=Ux(i.observed??bs(t),O,y),i.observed={...i.observed,cursor:Math.max(i.observed.cursor,O.cursor??0)},y=null,this.#A(t))},onDisconnect:()=>{y=null},shouldRetry:S=>!Be(S).terminal&&!Ud(S),backoff:d,stableMs:h,client:{timeoutMs:m}});i.observer=j,j.onEvent(S=>{if(!(!k()||S.sessionId!==t)){if(y){y.push(S);return}i.observed=zi(i.observed??bs(t),S),this.#A(t)}}),j.onState((S,A)=>{k()&&(S==="open"?(w&&(i.attempts=0,i.exhausted=!1),w=!0,this.#A(t)):S==="stopped"&&(this.#Se(t),i.exhausted=!0,this.#e.selected===t&&this.#t(R=>({busy:{...R.busy,interrupt:!1}})),this.#u("error",`Stop is unresolved: ${Be(A).message}`)))})}#Re(t){const i=this.#x.get(t);i&&(this.#x.delete(t),this.#Se(t),clearTimeout(i.retry),i.observer?.stop(),i.done(),this.#e.notice?.text===sy&&this.#t({notice:null}),this.#e.selected===t&&this.#t(a=>({busy:{...a.busy,interrupt:!1}})))}#_e(t,i){this.#O.get(t)?.delete(i),this.#x.get(t)?.messageId===i&&(this.#u("info","The agent did not take that message. There is no turn to stop."),this.#Re(t))}#A(t){const i=this.#x.get(t);if(!i)return;const a=this.#o.get(t)?.projection,l=[i.observed,a].filter(m=>!!m).sort((m,p)=>(p?.cursor??0)-(m?.cursor??0)),u=i.messageId?l.map(m=>m?.prompts[i.messageId]).find(Boolean):void 0;if(u?.state==="failed"&&u.errorCode!=="outcome_unknown"){this.#_e(t,i.messageId);return}if(!i.turnId&&u?.state==="accepted"&&u.turnId&&(i.turnId=u.turnId),i.turnId&&l.some(m=>m?.turns[i.turnId]==="ended")){this.#Re(t);return}const d=i.observer?.state==="open"?i.observer.client:void 0,h=d??(this.#e.connection.phase==="open"?this.#i?.alp?.client:void 0);if(!(!i.turnId||i.sending||i.exhausted||i.observer?.state==="stopped"||!h)){if(!d&&!this.hasCapability("session.interrupt.turn")){i.warned||(i.warned=!0,this.#u("error","Stop is still waiting: this host cannot safely stop a specific turn."));return}clearTimeout(i.retry),i.sending=!0,i.attempts=(i.attempts??0)+1,this.#e.selected===t&&this.#t(m=>({busy:{...m.busy,interrupt:!0}})),h.request("session.interrupt",{sessionId:t,turnId:i.turnId},{timeoutMs:this.#n.requestTimeoutMs}).then(m=>{this.#x.get(t)===i&&typeof m?.interrupted=="boolean"&&this.#Re(t)},m=>{this.#x.get(t)===i&&this.#u("error",`Stop is still waiting for this turn's outcome: ${Be(m).message}`)}).finally(()=>{i.sending=!1,this.#x.get(t)===i&&((i.attempts??0)<3?i.retry=setTimeout(()=>this.#A(t),250):(i.exhausted=!0,this.#e.selected===t&&this.#t(m=>({busy:{...m.busy,interrupt:!1}})),this.#u("error","Stop is unresolved. Try Stop again to check this same turn.")))})}}async answerQuestion(t,{text:i,dismiss:a=!1}){const l=`question:${t}`;this.#t(u=>({busy:{...u.busy,[l]:!0}}));try{await this.#r().request("question.answer",a?{questionId:t,dismiss:!0,reason:"Declined in ALP web"}:{questionId:t,text:String(i??"")});const u=this.#e.selected,d=u?this.#o.get(u):void 0;if(d&&u&&d.projection.questions[t]){const h={...d.projection.questions};delete h[t],d.projection={...d.projection,questions:h},this.#L(u)}this.refreshAttention()}catch(u){const d=Be(u);this.#u("error",d.code===1001?"That question is no longer waiting for an answer.":d.message)}finally{this.#t(u=>({busy:{...u.busy,[l]:!1}}))}}setTasksVisible(t){this.#Le=Math.max(0,this.#Le+(t?1:-1));const i=this.#Le>0;this.#e.tasks.visible!==i&&(this.#t(a=>({tasks:{...a.tasks,visible:i}})),i&&this.refreshTasks())}#Le=0;tasksBlock(){const{principal:t}=this.#e;if(!t)return"Not connected.";if(!this.hasCapability("task"))return"This host does not offer tasks.";if(!Te(t,"project.read"))return"Your access token cannot read this workspace's tasks."}async refreshTasks({quiet:t=!1}={}){const i=this.#e.workspace;if(!i||this.tasksBlock())return;const a=this.#l;t||this.#t(l=>({tasks:{...l.tasks,status:l.tasks.rows.length?l.tasks.status:"loading",error:void 0}}));try{const l=await this.#r().request("task.list",{projectRoot:i});if(a!==this.#l||t&&l?.revision&&l.revision===this.#e.tasks.revision)return;const u=Array.isArray(l?.tasks)?l.tasks:[];this.#t(d=>({tasks:{...d.tasks,status:"ready",rows:u,revision:l?.revision,unreadable:Array.isArray(l?.unreadable)?l.unreadable.length:0,error:void 0,creates:this.#Ct(d.tasks.creates,u)}}))}catch(l){if(a!==this.#l)return;(!t||this.#e.tasks.status!=="ready")&&this.#t(u=>({tasks:{...u.tasks,status:"error",error:Be(l)}}))}}#Ct(t,i){return t.map(a=>{if(a.status!=="unknown")return a;const l=i.find(u=>u.title===a.title&&u.status!=="closed");return l?{...a,match:l.id}:{...a,match:void 0}})}async createTask({title:t,priority:i=2}){const a=this.#e.workspace,l=String(t??"").trim();if(!a||!l)return;const u={requestId:K2(),title:l,priority:i,status:"creating"};this.#t(d=>({tasks:{...d.tasks,creates:[...d.tasks.creates,u],message:void 0}})),await this.#Je(u)}async#Je(t){const i=this.#e.workspace,a=this.#l,l=u=>this.#t(d=>({tasks:{...d.tasks,creates:u?d.tasks.creates.map(h=>h.requestId===t.requestId?{...h,...u}:h):d.tasks.creates.filter(h=>h.requestId!==t.requestId)}}));try{const u=await this.#r().request("task.create",{projectRoot:i,title:t.title,priority:t.priority,requestId:t.requestId});if(a!==this.#l)return;l(null),this.#t(d=>({tasks:{...d.tasks,message:{level:"info",text:u?.duplicate?`Task ${u.id} already existed for this request.`:`Created task ${u?.id??""}.`}}})),await this.refreshTasks({quiet:!1})}catch(u){if(a!==this.#l)return;const d=Be(u);d.sent==="unknown"||d.code===1e3?(l({status:"unknown",error:`${d.message} The list was read again: check it before creating this task again.`}),await this.refreshTasks()):l({status:"failed",error:d.message})}}async retryTaskCreate(t){const i=this.#e.tasks.creates.find(l=>l.requestId===t);if(!i||i.status==="creating")return;const a={...i,status:"creating",error:void 0,match:void 0};this.#t(l=>({tasks:{...l.tasks,creates:l.tasks.creates.map(u=>u.requestId===t?a:u)}})),await this.#Je(a)}dismissTaskCreate(t){this.#t(i=>({tasks:{...i.tasks,creates:i.tasks.creates.filter(a=>a.requestId!==t)}}))}async changeTask(t,i){const a=this.#e.workspace;if(!a||!t?.id)return;const l=this.#l;this.#t(u=>({tasks:{...u.tasks,busy:{...u.tasks.busy,[t.id]:!0},message:void 0}}));try{const u=this.#r();"gate"in i?await u.request("task.gate.resolve",{projectRoot:a,id:t.id,gate:i.gate,channel:"web",...i.choice?{choice:i.choice}:{},...i.reject?{reject:!0}:{},ifRev:t.rev}):await u.request("task.update",{projectRoot:a,id:t.id,action:i.action,...i.action==="close"?{note:"Closed in ALP web"}:{},ifRev:t.rev})}catch(u){if(l!==this.#l)return;const d=Be(u);this.#t(h=>({tasks:{...h.tasks,message:{level:"error",text:d.sent==="unknown"?`${d.message} The list was read again.`:d.message}}}))}finally{l===this.#l&&(this.#t(u=>({tasks:{...u.tasks,busy:{...u.tasks.busy,[t.id]:!1}}})),await this.refreshTasks())}}setSendBehavior(t){this.#ie({sendBehavior:t})}setTheme(t){this.#ie({theme:t})}updatePreferences(t){this.#ie(t)}#ie(t){const i=Oi(JSON.stringify({...this.#e.preferences,...t,v:1}));this.#t({preferences:i}),sS(this.#n.storage,i)}#Et(t){this.#ie({newSession:iS(this.#e.preferences.newSession,t)})}resetPreferences(){this.#ie(Oi(null))}reloadPreferences(){const t=Wx(this.#n.storage);JSON.stringify(t)!==JSON.stringify(this.#e.preferences)&&this.#t({preferences:t})}previewBlock(){const{principal:t,workspace:i}=this.#e;if(!t)return"Not connected.";if(!Te(t,"session.read"))return"Your access token cannot read sessions, so the host cannot say what would run.";if(!i)return"Choose a workspace first."}async previewSession(t,{signal:i}={}){const a=this.previewBlock();if(a)throw new Ke(a);const l=await this.#r().request("session.preview",{spec:{...t,cwd:this.#e.workspace}},{timeoutMs:this.#n.requestTimeoutMs,...i?{signal:i}:{}}),u=Lj(l);if(!u)throw new Ke("The host answered the preview in a form this app does not read.");return u}libraryBlock(){const{principal:t,workspace:i}=this.#e;if(!t)return"Not connected.";if(!this.hasCapability("library"))return"This host does not offer its library.";if(!Te(t,"project.read"))return"Your access token cannot read this workspace's configuration.";if(!i)return"Choose a workspace first."}async listLibrary(t){const i=this.libraryBlock();if(i)throw new Ke(i);const a=await this.#r().request("library.list",{kind:t,projectRoot:this.#e.workspace},{timeoutMs:this.#n.requestTimeoutMs});return(Array.isArray(a?.entries)?a.entries:[]).filter(l=>l&&typeof l.name=="string")}async getLibraryEntry(t,i){const a=this.libraryBlock();if(a)throw new Ke(a);const l=await this.#r().request("library.get",{kind:t,name:i,projectRoot:this.#e.workspace},{timeoutMs:this.#n.requestTimeoutMs});if(!l||typeof l!="object"||!l.content||typeof l.content!="object"||Array.isArray(l.content))throw new Ke("The host answered library.get in a form this app does not read.");const u=d=>Array.isArray(d)?d.filter(h=>typeof h=="string"):[];return{kind:typeof l.kind=="string"?l.kind:t,name:typeof l.name=="string"?l.name:i,source:typeof l.source=="string"?l.source:"unknown",...typeof l.overrides=="string"?{overrides:l.overrides}:{},content:l.content,...typeof l.revision=="string"||l.revision===null?{revision:l.revision}:{},usedBy:u(l.usedBy),...Array.isArray(l.librarySkills)?{librarySkills:u(l.librarySkills)}:{},secrets:u(l.secrets)}}libraryWriteBlock(t){const i=this.libraryBlock();return i||(Te(this.#e.principal??void 0,"library.write")?this.hasCapability("library.project.write")?["agents","skills"].includes(t)?null:"Executable and administrative configuration is edited on the host.":"Update the host to support safe project instruction editing.":"This token does not grant library.write.")}async writeLibrary(t,i,a){const l=this.libraryWriteBlock(i);if(l)throw new Ke(l);return this.#r().request(`library.${t}`,{...a,kind:i,scope:"project",projectRoot:this.#e.workspace},{timeoutMs:this.#n.requestTimeoutMs})}#et(){this.#e.catalog.status==="ready"&&this.#Te(),this.#e.settings.status==="ready"&&this.loadSettings()}async refreshModels(){!this.#e.principal||!Te(this.#e.principal,"session.read")||!this.hasCapability("catalog.live")||(await this.#r().request("catalog.refresh",{},{timeoutMs:Math.max(this.#n.requestTimeoutMs??0,6e4)}),this.#et())}async loadSettings(){const t=this.#e.principal;if(!t)return;const i=this.#l;this.#t(a=>({settings:{...a.settings,status:"loading",error:void 0}}));try{const a=this.#r(),[l,u]=await Promise.all([this.hasCapability("settings.language")&&Te(t,"session.read")?a.request("settings.language.get",{}).catch(()=>{}):void 0,this.hasCapability("library")&&Te(t,"session.read")?a.request("library.models",{}).catch(()=>{}):void 0]);if(i!==this.#l)return;this.#t({settings:{status:"ready",...l&&typeof l.applies=="string"?{language:l}:{},models:Gx(u?.models)}})}catch(a){if(i!==this.#l)return;this.#t(l=>({settings:{...l.settings,status:"error",error:Be(a)}}))}}}const gS=s=>s.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Zb=(...s)=>s.filter((t,i,a)=>!!t&&t.trim()!==""&&a.indexOf(t)===i).join(" ").trim();var xS={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const yS=b.forwardRef(({color:s="currentColor",size:t=24,strokeWidth:i=2,absoluteStrokeWidth:a,className:l="",children:u,iconNode:d,...h},m)=>b.createElement("svg",{ref:m,...xS,width:t,height:t,stroke:s,strokeWidth:a?Number(i)*24/Number(t):i,className:Zb("lucide",l),...h},[...d.map(([p,x])=>b.createElement(p,x)),...Array.isArray(u)?u:[u]]));const ie=(s,t)=>{const i=b.forwardRef(({className:a,...l},u)=>b.createElement(yS,{ref:u,iconNode:t,className:Zb(`lucide-${gS(s)}`,a),...l}));return i.displayName=`${s}`,i};const ac=ie("Archive",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]);const bS=ie("ArrowDownUp",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"m21 8-4-4-4 4",key:"1c9v7m"}],["path",{d:"M17 4v16",key:"7dpous"}]]);const vS=ie("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);const wS=ie("ArrowLeftRight",[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]]);const Jb=ie("ArrowLeftToLine",[["path",{d:"M3 19V5",key:"rwsyhb"}],["path",{d:"m13 6-6 6 6 6",key:"1yhaz7"}],["path",{d:"M7 12h14",key:"uoisry"}]]);const th=ie("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const e0=ie("ArrowRightToLine",[["path",{d:"M17 12H3",key:"8awo09"}],["path",{d:"m11 18 6-6-6-6",key:"8c2y43"}],["path",{d:"M21 5v14",key:"nzette"}]]);const Dl=ie("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);const rc=ie("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const kS=ie("Blocks",[["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["path",{d:"M10 21V8a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-5a1 1 0 0 0-1-1H3",key:"1fpvtg"}]]);const jS=ie("BookOpen",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]]);const Oa=ie("Bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]);const SS=ie("Boxes",[["path",{d:"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",key:"lc1i9w"}],["path",{d:"m7 16.5-4.74-2.85",key:"1o9zyk"}],["path",{d:"m7 16.5 5-3",key:"va8pkn"}],["path",{d:"M7 16.5v5.17",key:"jnp8gn"}],["path",{d:"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",key:"8zsnat"}],["path",{d:"m17 16.5-5-3",key:"8arw3v"}],["path",{d:"m17 16.5 4.74-2.85",key:"8rfmw"}],["path",{d:"M17 16.5v5.17",key:"k6z78m"}],["path",{d:"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",key:"1xygjf"}],["path",{d:"M12 8 7.26 5.15",key:"1vbdud"}],["path",{d:"m12 8 4.74-2.85",key:"3rx089"}],["path",{d:"M12 13.5V8",key:"1io7kd"}]]);const Pr=ie("Brain",[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z",key:"ep3f8r"}],["path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4",key:"1p4c4q"}],["path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375",key:"tmeiqw"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M19.938 10.5a4 4 0 0 1 .585.396",key:"1qfode"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M19.967 17.484A4 4 0 0 1 18 18",key:"159ez6"}]]);const NS=ie("CheckCheck",[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]);const oc=ie("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);const Qn=ie("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);const nh=ie("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);const Jn=ie("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const si=ie("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);const lc=ie("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const t0=ie("CircleDashed",[["path",{d:"M10.1 2.182a10 10 0 0 1 3.8 0",key:"5ilxe3"}],["path",{d:"M13.9 21.818a10 10 0 0 1-3.8 0",key:"11zvb9"}],["path",{d:"M17.609 3.721a10 10 0 0 1 2.69 2.7",key:"1iw5b2"}],["path",{d:"M2.182 13.9a10 10 0 0 1 0-3.8",key:"c0bmvh"}],["path",{d:"M20.279 17.609a10 10 0 0 1-2.7 2.69",key:"1ruxm7"}],["path",{d:"M21.818 10.1a10 10 0 0 1 0 3.8",key:"qkgqxc"}],["path",{d:"M3.721 6.391a10 10 0 0 1 2.7-2.69",key:"1mcia2"}],["path",{d:"M6.391 20.279a10 10 0 0 1-2.69-2.7",key:"1fvljs"}]]);const n0=ie("CircleDot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]);const TS=ie("CircleGauge",[["path",{d:"M15.6 2.7a10 10 0 1 0 5.7 5.7",key:"1e0p6d"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M13.4 10.6 19 5",key:"1kr7tw"}]]);const AS=ie("CircleHelp",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const s0=ie("CircleSlash",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"9",x2:"15",y1:"15",y2:"9",key:"1dfufj"}]]);const CS=ie("Circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);const ES=ie("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const MS=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const i0=ie("Columns2",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]]);const zS=ie("Columns3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);const a0=ie("CopyX",[["line",{x1:"12",x2:"18",y1:"12",y2:"18",key:"1rg63v"}],["line",{x1:"12",x2:"18",y1:"18",y2:"12",key:"ebkxgr"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);const ws=ie("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);const jf=ie("Cpu",[["rect",{width:"16",height:"16",x:"4",y:"4",rx:"2",key:"14l7u7"}],["rect",{width:"6",height:"6",x:"9",y:"9",rx:"1",key:"5aljv4"}],["path",{d:"M15 2v2",key:"13l42r"}],["path",{d:"M15 20v2",key:"15mkzm"}],["path",{d:"M2 15h2",key:"1gxd5l"}],["path",{d:"M2 9h2",key:"1bbxkp"}],["path",{d:"M20 15h2",key:"19e6y8"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M9 2v2",key:"165o2o"}],["path",{d:"M9 20v2",key:"i2bqo8"}]]);const RS=ie("Crosshair",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]]);const _S=ie("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);const sh=ie("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);const LS=ie("EyeOff",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);const lo=ie("Eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const OS=ie("FileCode",[["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}]]);const Sf=ie("FileDiff",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]]);const ih=ie("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);const r0=ie("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);const ah=ie("Files",[["path",{d:"M20 7h-3a2 2 0 0 1-2-2V2",key:"x099mo"}],["path",{d:"M9 18a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h7l4 4v10a2 2 0 0 1-2 2Z",key:"18t6ie"}],["path",{d:"M3 7.6v12.8A1.6 1.6 0 0 0 4.6 22h9.8",key:"1nja0z"}]]);const DS=ie("FolderCog",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["path",{d:"M10.3 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v3.3",key:"1k8050"}],["path",{d:"m21.7 19.4-.9-.3",key:"1qgwi9"}],["path",{d:"m15.2 16.9-.9-.3",key:"1t7mvx"}],["path",{d:"m16.6 21.7.3-.9",key:"1j67ps"}],["path",{d:"m19.1 15.2.3-.9",key:"18r7jp"}],["path",{d:"m19.6 21.7-.4-1",key:"z2vh2"}],["path",{d:"m16.8 15.3-.4-1",key:"1ei7r6"}],["path",{d:"m14.3 19.6 1-.4",key:"11sv9r"}],["path",{d:"m20.7 16.8 1-.4",key:"19m87a"}]]);const ly=ie("FolderGit2",[["path",{d:"M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5",key:"1w6njk"}],["circle",{cx:"13",cy:"12",r:"2",key:"1j92g6"}],["path",{d:"M18 19c-2.8 0-5-2.2-5-5v8",key:"pkpw2h"}],["circle",{cx:"20",cy:"19",r:"2",key:"1obnsp"}]]);const qS=ie("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);const cy=ie("FolderPlus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);const Da=ie("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);const BS=ie("Gauge",[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]]);const Qs=ie("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);const $S=ie("GitCompareArrows",[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]);const o0=ie("GitFork",[["circle",{cx:"12",cy:"18",r:"3",key:"1mpf1b"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9",key:"1uq4wg"}],["path",{d:"M12 12v3",key:"158kv8"}]]);const l0=ie("Hand",[["path",{d:"M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2",key:"1fvzgz"}],["path",{d:"M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2",key:"1kc0my"}],["path",{d:"M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8",key:"10h0bg"}],["path",{d:"M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15",key:"1s1gnw"}]]);const cc=ie("History",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]);const US=ie("Image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);const rh=ie("Info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]);const HS=ie("KeyRound",[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]]);const IS=ie("Keyboard",[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]]);const oh=ie("ListChecks",[["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);const Bi=ie("ListTodo",[["rect",{x:"3",y:"5",width:"6",height:"6",rx:"1",key:"1defrl"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);const GS=ie("ListTree",[["path",{d:"M21 12h-8",key:"1bmf0i"}],["path",{d:"M21 6H8",key:"1pqkrb"}],["path",{d:"M21 18h-8",key:"1tm79t"}],["path",{d:"M3 6v4c0 1.1.9 2 2 2h3",key:"1ywdgy"}],["path",{d:"M3 10v6c0 1.1.9 2 2 2h3",key:"2wc746"}]]);const YS=ie("List",[["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 18h.01",key:"1tta3j"}],["path",{d:"M3 6h.01",key:"1rqtza"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 18h13",key:"1lx6n3"}],["path",{d:"M8 6h13",key:"ik3vkj"}]]);const uc=ie("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);const qa=ie("Lock",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]);const VS=ie("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);const KS=ie("Maximize",[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]);const uy=ie("MessageSquarePlus",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M12 7v6",key:"lw1j43"}],["path",{d:"M9 10h6",key:"9gxzsh"}]]);const FS=ie("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);const XS=ie("Mic",[["path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z",key:"131961"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);const PS=ie("Minimize",[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]]);const c0=ie("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);const QS=ie("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);const WS=ie("PanelBottom",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 15h18",key:"5xshup"}]]);const $a=ie("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);const lh=ie("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);const ZS=ie("PanelTop",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}]]);const Ui=ie("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);const JS=ie("PinOff",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]);const u0=ie("Pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);const eN=ie("PlugZap",[["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m18 3-4 4h6l-4 4",key:"16psg9"}]]);const tN=ie("Plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]]);const ks=ie("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);const co=ie("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);const uo=ie("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);const nN=ie("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]);const d0=ie("Rows2",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 12h18",key:"1i2n21"}]]);const sN=ie("Scissors",[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]);const ti=ie("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);const Qr=ie("Server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]);const iN=ie("Settings2",[["path",{d:"M20 7h-9",key:"3s1dr2"}],["path",{d:"M14 17H5",key:"gfn3mx"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]);const ch=ie("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const f0=ie("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const dc=ie("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const aN=ie("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]);const rN=ie("Shrink",[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]]);const oN=ie("Smartphone",[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]]);const lN=ie("Space",[["path",{d:"M22 17v1c0 .5-.5 1-1 1H3c-.5 0-1-.5-1-1v-1",key:"lt2kga"}]]);const cN=ie("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const fc=ie("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);const hc=ie("SquareTerminal",[["path",{d:"m7 11 2-2-2-2",key:"1lz0vl"}],["path",{d:"M11 13h4",key:"1p7l4v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}]]);const uN=ie("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);const dN=ie("Stethoscope",[["path",{d:"M11 2v2",key:"1539x4"}],["path",{d:"M5 2v2",key:"1yf1q8"}],["path",{d:"M5 3H4a2 2 0 0 0-2 2v4a6 6 0 0 0 12 0V5a2 2 0 0 0-2-2h-1",key:"rb5t3r"}],["path",{d:"M8 15a6 6 0 0 0 12 0v-3",key:"x18d4x"}],["circle",{cx:"20",cy:"10",r:"2",key:"ts1r5v"}]]);const h0=ie("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);const uh=ie("Target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);const fN=ie("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);const m0=ie("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const hN=ie("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);const p0=ie("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]);const Yl=ie("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);const mN=ie("Webhook",[["path",{d:"M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2",key:"q3hayz"}],["path",{d:"m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06",key:"1go1hn"}],["path",{d:"m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8",key:"qlwsc0"}]]);const pN=ie("WifiOff",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);const g0=ie("Wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",key:"cbrjhi"}]]);const en=ie("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);var gN=Object.defineProperty,dh=(s,t)=>gN(s,"name",{value:t,configurable:!0});function Nf(s,t){if(typeof s=="function")return s(t);s!=null&&(s.current=t)}dh(Nf,"setRef");function x0(...s){return t=>{let i=!1;const a=s.map(l=>{const u=Nf(l,t);return!i&&typeof u=="function"&&(i=!0),u});if(i)return()=>{for(let l=0;l<a.length;l++){const u=a[l];typeof u=="function"?u():Nf(s[l],null)}}}}dh(x0,"composeRefs");function y0(...s){return b.useCallback(x0(...s),s)}dh(y0,"useComposedRefs");var xN=Object.defineProperty,wn=(s,t)=>xN(s,"name",{value:t,configurable:!0});function b0(s){const t=b.forwardRef((i,a)=>{let{children:l,...u}=i,d=null,h=!1;const m=[];l=N0(l),b.Children.forEach(l,w=>{if(j0(w)){h=!0;const k=w;let j="child"in k.props?k.props.child:k.props.children;for(;fh(j)&&typeof Vl=="function";)j=Vl(j._payload);d=vN(k,j),m.push(d?.props?.children)}else m.push(w)}),d?d=b.cloneElement(d,void 0,m):!h&&b.Children.count(l)===1&&b.isValidElement(l)&&(d=l);const p=d?k0(d):void 0,x=y0(a,p);if(!d){if(l||l===0)throw new Error(h?jN(s):kN(s));return l}const y=w0(u,d.props??{});return d.type!==b.Fragment&&(y.ref=a?x:p),b.cloneElement(d,y)});return t.displayName=`${s}.Slot`,t}wn(b0,"createSlot");var yN=b0("Slot"),v0=Symbol.for("radix.slottable");function bN(s){const t=wn(i=>"child"in i?i.children(i.child):i.children,"Slottable");return t.displayName=`${s}.Slottable`,t.__radixId=v0,t}wn(bN,"createSlottable");var vN=wn((s,t)=>"child"in s.props?b.isValidElement(t)?b.cloneElement(t,void 0,s.props.children(t.props.children)):null:b.isValidElement(t)?t:null,"getSlottableElementFromSlottable");function w0(s,t){const i={...t};for(const a in t){const l=s[a],u=t[a];/^on[A-Z]/.test(a)?l&&u?i[a]=(...h)=>{const m=u(...h);return l(...h),m}:l&&(i[a]=l):a==="style"?i[a]={...l,...u}:a==="className"?i[a]=[l,u].filter(Boolean).join(" "):a==="aria-describedby"&&(i[a]=T0(u,l))}return{...s,...i}}wn(w0,"mergeProps");function k0(s){let t=Object.getOwnPropertyDescriptor(s.props,"ref")?.get,i=t&&"isReactWarning"in t&&t.isReactWarning;return i?s.ref:(t=Object.getOwnPropertyDescriptor(s,"ref")?.get,i=t&&"isReactWarning"in t&&t.isReactWarning,i?s.props.ref:s.props.ref||s.ref)}wn(k0,"getElementRef");function j0(s){return b.isValidElement(s)&&typeof s.type=="function"&&"__radixId"in s.type&&s.type.__radixId===v0}wn(j0,"isSlottable");var wN=Symbol.for("react.lazy");function fh(s){return s!=null&&typeof s=="object"&&"$$typeof"in s&&s.$$typeof===wN&&"_payload"in s&&S0(s._payload)}wn(fh,"isLazyComponent");function S0(s){return typeof s=="object"&&s!==null&&"then"in s}wn(S0,"isPromiseLike");function N0(s){let t=s;for(;fh(t)&&typeof Vl=="function";)t=Vl(t._payload);return t}wn(N0,"useUnwrappedLazy");function T0(...s){const t=new Set;for(const i of s)if(typeof i=="string")for(const a of String(i).trim().split(/\s+/))a&&t.add(a);return t.size>0?Array.from(t).join(" "):void 0}wn(T0,"concatAriaDescribedby");var kN=wn(s=>`${s} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),jN=wn(s=>`${s} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Vl=Uk[" use ".trim().toString()];function A0(s){var t,i,a="";if(typeof s=="string"||typeof s=="number")a+=s;else if(typeof s=="object")if(Array.isArray(s)){var l=s.length;for(t=0;t<l;t++)s[t]&&(i=A0(s[t]))&&(a&&(a+=" "),a+=i)}else for(i in s)s[i]&&(a&&(a+=" "),a+=i);return a}function C0(){for(var s,t,i=0,a="",l=arguments.length;i<l;i++)(s=arguments[i])&&(t=A0(s))&&(a&&(a+=" "),a+=t);return a}const dy=s=>typeof s=="boolean"?`${s}`:s===0?"0":s,fy=C0,SN=(s,t)=>i=>{var a;if(t?.variants==null)return fy(s,i?.class,i?.className);const{variants:l,defaultVariants:u}=t,d=Object.keys(l).map(p=>{const x=i?.[p],y=u?.[p];if(x===null)return null;const w=dy(x)||dy(y);return l[p][w]}),h=i&&Object.entries(i).reduce((p,x)=>{let[y,w]=x;return w===void 0||(p[y]=w),p},{}),m=t==null||(a=t.compoundVariants)===null||a===void 0?void 0:a.reduce((p,x)=>{let{class:y,className:w,...k}=x;return Object.entries(k).every(j=>{let[S,A]=j;return Array.isArray(A)?A.includes({...u,...h}[S]):{...u,...h}[S]===A})?[...p,y,w]:p},[]);return fy(s,d,m,i?.class,i?.className)},NN=(s,t)=>{const i=new Array(s.length+t.length);for(let a=0;a<s.length;a++)i[a]=s[a];for(let a=0;a<t.length;a++)i[s.length+a]=t[a];return i},TN=(s,t)=>({classGroupId:s,validator:t}),E0=(s=new Map,t=null,i)=>({nextPart:s,validators:t,classGroupId:i}),Kl="-",hy=[],AN="arbitrary..",CN=s=>{const t=MN(s),{conflictingClassGroups:i,conflictingClassGroupModifiers:a}=s;return{getClassGroupId:d=>{if(d.startsWith("[")&&d.endsWith("]"))return EN(d);const h=d.split(Kl),m=h[0]===""&&h.length>1?1:0;return M0(h,m,t)},getConflictingClassGroupIds:(d,h)=>{if(h){const m=a[d],p=i[d];return m?p?NN(p,m):m:p||hy}return i[d]||hy}}},M0=(s,t,i)=>{if(s.length-t===0)return i.classGroupId;const l=s[t],u=i.nextPart.get(l);if(u){const p=M0(s,t+1,u);if(p)return p}const d=i.validators;if(d===null)return;const h=t===0?s.join(Kl):s.slice(t).join(Kl),m=d.length;for(let p=0;p<m;p++){const x=d[p];if(x.validator(h))return x.classGroupId}},EN=s=>s.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const t=s.slice(1,-1),i=t.indexOf(":"),a=t.slice(0,i);return a?AN+a:void 0})(),MN=s=>{const{theme:t,classGroups:i}=s;return zN(i,t)},zN=(s,t)=>{const i=E0();for(const a in s){const l=s[a];hh(l,i,a,t)}return i},hh=(s,t,i,a)=>{const l=s.length;for(let u=0;u<l;u++){const d=s[u];RN(d,t,i,a)}},RN=(s,t,i,a)=>{if(typeof s=="string"){_N(s,t,i);return}if(typeof s=="function"){LN(s,t,i,a);return}ON(s,t,i,a)},_N=(s,t,i)=>{const a=s===""?t:z0(t,s);a.classGroupId=i},LN=(s,t,i,a)=>{if(DN(s)){hh(s(a),t,i,a);return}t.validators===null&&(t.validators=[]),t.validators.push(TN(i,s))},ON=(s,t,i,a)=>{const l=Object.entries(s),u=l.length;for(let d=0;d<u;d++){const[h,m]=l[d];hh(m,z0(t,h),i,a)}},z0=(s,t)=>{let i=s;const a=t.split(Kl),l=a.length;for(let u=0;u<l;u++){const d=a[u];let h=i.nextPart.get(d);h||(h=E0(),i.nextPart.set(d,h)),i=h}return i},DN=s=>"isThemeGetter"in s&&s.isThemeGetter===!0,qN=s=>{if(s<1)return{get:()=>{},set:()=>{}};let t=0,i=Object.create(null),a=Object.create(null);const l=(u,d)=>{i[u]=d,t++,t>s&&(t=0,a=i,i=Object.create(null))};return{get(u){let d=i[u];if(d!==void 0)return d;if((d=a[u])!==void 0)return l(u,d),d},set(u,d){u in i?i[u]=d:l(u,d)}}},Tf="!",my=":",BN=[],py=(s,t,i,a,l)=>({modifiers:s,hasImportantModifier:t,baseClassName:i,maybePostfixModifierPosition:a,isExternal:l}),$N=s=>{const{prefix:t,experimentalParseClassName:i}=s;let a=l=>{const u=[];let d=0,h=0,m=0,p;const x=l.length;for(let S=0;S<x;S++){const A=l[S];if(d===0&&h===0){if(A===my){u.push(l.slice(m,S)),m=S+1;continue}if(A==="/"){p=S;continue}}A==="["?d++:A==="]"?d--:A==="("?h++:A===")"&&h--}const y=u.length===0?l:l.slice(m);let w=y,k=!1;y.endsWith(Tf)?(w=y.slice(0,-1),k=!0):y.startsWith(Tf)&&(w=y.slice(1),k=!0);const j=p&&p>m?p-m:void 0;return py(u,k,w,j)};if(t){const l=t+my,u=a;a=d=>d.startsWith(l)?u(d.slice(l.length)):py(BN,!1,d,void 0,!0)}if(i){const l=a;a=u=>i({className:u,parseClassName:l})}return a},UN=s=>{const t=new Map;return s.orderSensitiveModifiers.forEach((i,a)=>{t.set(i,1e6+a)}),i=>{const a=[];let l=[];for(let u=0;u<i.length;u++){const d=i[u],h=d[0]==="[",m=t.has(d);h||m?(l.length>0&&(l.sort(),a.push(...l),l=[]),a.push(d)):l.push(d)}return l.length>0&&(l.sort(),a.push(...l)),a}},HN=s=>({cache:qN(s.cacheSize),parseClassName:$N(s),sortModifiers:UN(s),postfixLookupClassGroupIds:IN(s),...CN(s)}),IN=s=>{const t=Object.create(null),i=s.postfixLookupClassGroups;if(i)for(let a=0;a<i.length;a++)t[i[a]]=!0;return t},GN=/\s+/,YN=(s,t)=>{const{parseClassName:i,getClassGroupId:a,getConflictingClassGroupIds:l,sortModifiers:u,postfixLookupClassGroupIds:d}=t,h=[],m=s.trim().split(GN);let p="";for(let x=m.length-1;x>=0;x-=1){const y=m[x],{isExternal:w,modifiers:k,hasImportantModifier:j,baseClassName:S,maybePostfixModifierPosition:A}=i(y);if(w){p=y+(p.length>0?" "+p:p);continue}let R=!!A,q;if(R){const Q=S.substring(0,A);q=a(Q);const C=q&&d[q]?a(S):void 0;C&&C!==q&&(q=C,R=!1)}else q=a(S);if(!q){if(!R){p=y+(p.length>0?" "+p:p);continue}if(q=a(S),!q){p=y+(p.length>0?" "+p:p);continue}R=!1}const O=k.length===0?"":k.length===1?k[0]:u(k).join(":"),L=j?O+Tf:O,B=L+q;if(h.indexOf(B)>-1)continue;h.push(B);const _=l(q,R);for(let Q=0;Q<_.length;++Q){const C=_[Q];h.push(L+C)}p=y+(p.length>0?" "+p:p)}return p},VN=(...s)=>{let t=0,i,a,l="";for(;t<s.length;)(i=s[t++])&&(a=R0(i))&&(l&&(l+=" "),l+=a);return l},R0=s=>{if(typeof s=="string")return s;let t,i="";for(let a=0;a<s.length;a++)s[a]&&(t=R0(s[a]))&&(i&&(i+=" "),i+=t);return i},KN=(s,...t)=>{let i,a,l,u;const d=m=>{const p=t.reduce((x,y)=>y(x),s());return i=HN(p),a=i.cache.get,l=i.cache.set,u=h,h(m)},h=m=>{const p=a(m);if(p)return p;const x=YN(m,i);return l(m,x),x};return u=d,(...m)=>u(VN(...m))},FN=[],Ot=s=>{const t=i=>i[s]||FN;return t.isThemeGetter=!0,t.themeKey=s,t},_0=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,L0=/^\((?:(\w[\w-]*):)?(.+)\)$/i,XN=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,PN=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,QN=/\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$/,WN=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix|color|light-dark)\(.+\)$/,ZN=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,JN=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Ks=s=>XN.test(s),Ye=s=>!!s&&!Number.isNaN(Number(s)),Pn=s=>!!s&&Number.isInteger(Number(s)),Qd=s=>s.endsWith("%")&&Ye(s.slice(0,-1)),ps=s=>PN.test(s),O0=()=>!0,e3=s=>QN.test(s)&&!WN.test(s),mh=()=>!1,t3=s=>ZN.test(s),n3=s=>JN.test(s),s3=s=>!ke(s)&&!je(s),i3=s=>s.startsWith("@container")&&(s[10]==="/"&&s[11]!==void 0||s[11]==="s"&&s[16]!==void 0&&s.startsWith("-size/",10)||s[11]==="n"&&s[18]!==void 0&&s.startsWith("-normal/",10)),a3=s=>ii(s,B0,mh),ke=s=>_0.test(s),Si=s=>ii(s,$0,e3),gy=s=>ii(s,h3,Ye),r3=s=>ii(s,H0,O0),o3=s=>ii(s,U0,mh),xy=s=>ii(s,D0,mh),l3=s=>ii(s,q0,n3),Cl=s=>ii(s,I0,t3),je=s=>L0.test(s),Ur=s=>Hi(s,$0),c3=s=>Hi(s,U0),yy=s=>Hi(s,D0),u3=s=>Hi(s,B0),d3=s=>Hi(s,q0),El=s=>Hi(s,I0,!0),f3=s=>Hi(s,H0,!0),ii=(s,t,i)=>{const a=_0.exec(s);return a?a[1]?t(a[1]):i(a[2]):!1},Hi=(s,t,i=!1)=>{const a=L0.exec(s);return a?a[1]?t(a[1]):i:!1},D0=s=>s==="position"||s==="percentage",q0=s=>s==="image"||s==="url",B0=s=>s==="length"||s==="size"||s==="bg-size",$0=s=>s==="length",h3=s=>s==="number",U0=s=>s==="family-name",H0=s=>s==="number"||s==="weight",I0=s=>s==="shadow",m3=()=>{const s=Ot("color"),t=Ot("font"),i=Ot("text"),a=Ot("font-weight"),l=Ot("tracking"),u=Ot("leading"),d=Ot("breakpoint"),h=Ot("container"),m=Ot("spacing"),p=Ot("radius"),x=Ot("shadow"),y=Ot("inset-shadow"),w=Ot("text-shadow"),k=Ot("drop-shadow"),j=Ot("blur"),S=Ot("perspective"),A=Ot("aspect"),R=Ot("ease"),q=Ot("animate"),O=()=>["auto","avoid","all","avoid-page","page","left","right","column"],L=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],B=()=>[...L(),je,ke],_=()=>["auto","hidden","clip","visible","scroll"],Q=()=>["auto","contain","none"],C=()=>[je,ke,m],Y=()=>[Ks,"full","auto",...C()],H=()=>[Pn,"none","subgrid",je,ke],fe=()=>["auto",{span:["full",Pn,je,ke]},Pn,je,ke],ee=()=>[Pn,"auto",je,ke],xe=()=>["auto","min","max","fr",je,ke],re=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],de=()=>["start","end","center","stretch","center-safe","end-safe"],U=()=>["auto",...C()],Z=()=>[Ks,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...C()],oe=()=>[h,Ks,"screen","full","dvw","lvw","svw","min","max","fit",...C()],ge=()=>[Ks,"screen","full","lh","dvh","lvh","svh","min","max","fit",...C()],T=()=>[s,je,ke],z=()=>[...L(),yy,xy,{position:[je,ke]}],F=()=>["no-repeat",{repeat:["","x","y","space","round"]}],J=()=>["auto","cover","contain",u3,a3,{size:[je,ke]}],le=()=>[Qd,Ur,Si],ne=()=>["","none","full",p,je,ke],ce=()=>["",Ye,Ur,Si],ve=()=>["solid","dashed","dotted","double"],Re=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],Me=()=>[Ye,Qd,yy,xy],Qe=()=>["","none",j,je,ke],Ue=()=>["none",Ye,je,ke],et=()=>["none",Ye,je,ke],Fe=()=>[Ye,je,ke],be=()=>[Ks,"full",...C()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[ps],breakpoint:[ps],color:[O0],container:[ps],"drop-shadow":[ps],ease:["in","out","in-out"],font:[s3],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[ps],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[ps],shadow:[ps],spacing:["px",Ye],text:[ps],"text-shadow":[ps],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",Ks,ke,je,A]}],container:["container"],"container-type":[{"@container":["","normal","size",je,ke]}],"container-named":[i3],columns:[{columns:[Ye,"auto",ke,je,h]}],"break-after":[{"break-after":O()}],"break-before":[{"break-before":O()}],"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:B()}],overflow:[{overflow:_()}],"overflow-x":[{"overflow-x":_()}],"overflow-y":[{"overflow-y":_()}],overscroll:[{overscroll:Q()}],"overscroll-x":[{"overscroll-x":Q()}],"overscroll-y":[{"overscroll-y":Q()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:Y()}],"inset-x":[{"inset-x":Y()}],"inset-y":[{"inset-y":Y()}],start:[{"inset-s":Y(),start:Y()}],end:[{"inset-e":Y(),end:Y()}],"inset-bs":[{"inset-bs":Y()}],"inset-be":[{"inset-be":Y()}],top:[{top:Y()}],right:[{right:Y()}],bottom:[{bottom:Y()}],left:[{left:Y()}],visibility:["visible","invisible","collapse"],z:[{z:[Pn,"auto",je,ke]}],basis:[{basis:[Ks,"full","auto",h,...C()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[Ye,Ks,"auto","initial","none",ke]}],grow:[{grow:["",Ye,je,ke]}],shrink:[{shrink:["",Ye,je,ke]}],order:[{order:[Pn,"first","last","none",je,ke]}],"grid-cols":[{"grid-cols":H()}],"col-start-end":[{col:fe()}],"col-start":[{"col-start":ee()}],"col-end":[{"col-end":ee()}],"grid-rows":[{"grid-rows":H()}],"row-start-end":[{row:fe()}],"row-start":[{"row-start":ee()}],"row-end":[{"row-end":ee()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":xe()}],"auto-rows":[{"auto-rows":xe()}],gap:[{gap:C()}],"gap-x":[{"gap-x":C()}],"gap-y":[{"gap-y":C()}],"justify-content":[{justify:[...re(),"normal"]}],"justify-items":[{"justify-items":[...de(),"normal"]}],"justify-self":[{"justify-self":["auto",...de()]}],"align-content":[{content:["normal",...re()]}],"align-items":[{items:[...de(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...de(),{baseline:["","last"]}]}],"place-content":[{"place-content":re()}],"place-items":[{"place-items":[...de(),"baseline"]}],"place-self":[{"place-self":["auto",...de()]}],p:[{p:C()}],px:[{px:C()}],py:[{py:C()}],ps:[{ps:C()}],pe:[{pe:C()}],pbs:[{pbs:C()}],pbe:[{pbe:C()}],pt:[{pt:C()}],pr:[{pr:C()}],pb:[{pb:C()}],pl:[{pl:C()}],m:[{m:U()}],mx:[{mx:U()}],my:[{my:U()}],ms:[{ms:U()}],me:[{me:U()}],mbs:[{mbs:U()}],mbe:[{mbe:U()}],mt:[{mt:U()}],mr:[{mr:U()}],mb:[{mb:U()}],ml:[{ml:U()}],"space-x":[{"space-x":C()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":C()}],"space-y-reverse":["space-y-reverse"],size:[{size:Z()}],"inline-size":[{inline:["auto",...oe()]}],"min-inline-size":[{"min-inline":["auto",...oe()]}],"max-inline-size":[{"max-inline":["none",...oe()]}],"block-size":[{block:["auto",...ge()]}],"min-block-size":[{"min-block":["auto",...ge()]}],"max-block-size":[{"max-block":["none",...ge()]}],w:[{w:[h,"screen",...Z()]}],"min-w":[{"min-w":[h,"screen","none",...Z()]}],"max-w":[{"max-w":[h,"screen","none","prose",{screen:[d]},...Z()]}],h:[{h:["screen","lh",...Z()]}],"min-h":[{"min-h":["screen","lh","none",...Z()]}],"max-h":[{"max-h":["screen","lh","none",...Z()]}],"font-size":[{text:["base",i,Ur,Si]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[a,f3,r3]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",Qd,ke]}],"font-family":[{font:[c3,o3,t]}],"font-features":[{"font-features":[ke]}],"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:[l,je,ke]}],"line-clamp":[{"line-clamp":[Ye,"none",je,gy]}],leading:[{leading:["none",u,...C()]}],"list-image":[{"list-image":["none",je,ke]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",je,ke]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:T()}],"text-color":[{text:T()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...ve(),"wavy"]}],"text-decoration-thickness":[{decoration:[Ye,"from-font","auto",je,Si]}],"text-decoration-color":[{decoration:T()}],"underline-offset":[{"underline-offset":[Ye,"auto",je,ke]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:C()}],"tab-size":[{tab:[Pn,je,ke]}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",je,ke]}],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",je,ke]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:z()}],"bg-repeat":[{bg:F()}],"bg-size":[{bg:J()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},Pn,je,ke],radial:["",je,ke],conic:["",Pn,je,ke]},d3,l3]}],"bg-color":[{bg:T()}],"gradient-from-pos":[{from:le()}],"gradient-via-pos":[{via:le()}],"gradient-to-pos":[{to:le()}],"gradient-from":[{from:T()}],"gradient-via":[{via:T()}],"gradient-to":[{to:T()}],rounded:[{rounded:ne()}],"rounded-s":[{"rounded-s":ne()}],"rounded-e":[{"rounded-e":ne()}],"rounded-t":[{"rounded-t":ne()}],"rounded-r":[{"rounded-r":ne()}],"rounded-b":[{"rounded-b":ne()}],"rounded-l":[{"rounded-l":ne()}],"rounded-ss":[{"rounded-ss":ne()}],"rounded-se":[{"rounded-se":ne()}],"rounded-ee":[{"rounded-ee":ne()}],"rounded-es":[{"rounded-es":ne()}],"rounded-tl":[{"rounded-tl":ne()}],"rounded-tr":[{"rounded-tr":ne()}],"rounded-br":[{"rounded-br":ne()}],"rounded-bl":[{"rounded-bl":ne()}],"border-w":[{border:ce()}],"border-w-x":[{"border-x":ce()}],"border-w-y":[{"border-y":ce()}],"border-w-s":[{"border-s":ce()}],"border-w-e":[{"border-e":ce()}],"border-w-bs":[{"border-bs":ce()}],"border-w-be":[{"border-be":ce()}],"border-w-t":[{"border-t":ce()}],"border-w-r":[{"border-r":ce()}],"border-w-b":[{"border-b":ce()}],"border-w-l":[{"border-l":ce()}],"divide-x":[{"divide-x":ce()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":ce()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...ve(),"hidden","none"]}],"divide-style":[{divide:[...ve(),"hidden","none"]}],"border-color":[{border:T()}],"border-color-x":[{"border-x":T()}],"border-color-y":[{"border-y":T()}],"border-color-s":[{"border-s":T()}],"border-color-e":[{"border-e":T()}],"border-color-bs":[{"border-bs":T()}],"border-color-be":[{"border-be":T()}],"border-color-t":[{"border-t":T()}],"border-color-r":[{"border-r":T()}],"border-color-b":[{"border-b":T()}],"border-color-l":[{"border-l":T()}],"divide-color":[{divide:T()}],"outline-style":[{outline:[...ve(),"none","hidden"]}],"outline-offset":[{"outline-offset":[Ye,je,ke]}],"outline-w":[{outline:["",Ye,Ur,Si]}],"outline-color":[{outline:T()}],shadow:[{shadow:["","inner","none",x,El,Cl]}],"shadow-color":[{shadow:T()}],"inset-shadow":[{"inset-shadow":["none",y,El,Cl]}],"inset-shadow-color":[{"inset-shadow":T()}],"ring-w":[{ring:ce()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:T()}],"ring-offset-w":[{"ring-offset":[Ye,Si]}],"ring-offset-color":[{"ring-offset":T()}],"inset-ring-w":[{"inset-ring":ce()}],"inset-ring-color":[{"inset-ring":T()}],"text-shadow":[{"text-shadow":["none",w,El,Cl]}],"text-shadow-color":[{"text-shadow":T()}],opacity:[{opacity:[Ye,je,ke]}],"mix-blend":[{"mix-blend":[...Re(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":Re()}],"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":[Ye]}],"mask-image-linear-from-pos":[{"mask-linear-from":Me()}],"mask-image-linear-to-pos":[{"mask-linear-to":Me()}],"mask-image-linear-from-color":[{"mask-linear-from":T()}],"mask-image-linear-to-color":[{"mask-linear-to":T()}],"mask-image-t-from-pos":[{"mask-t-from":Me()}],"mask-image-t-to-pos":[{"mask-t-to":Me()}],"mask-image-t-from-color":[{"mask-t-from":T()}],"mask-image-t-to-color":[{"mask-t-to":T()}],"mask-image-r-from-pos":[{"mask-r-from":Me()}],"mask-image-r-to-pos":[{"mask-r-to":Me()}],"mask-image-r-from-color":[{"mask-r-from":T()}],"mask-image-r-to-color":[{"mask-r-to":T()}],"mask-image-b-from-pos":[{"mask-b-from":Me()}],"mask-image-b-to-pos":[{"mask-b-to":Me()}],"mask-image-b-from-color":[{"mask-b-from":T()}],"mask-image-b-to-color":[{"mask-b-to":T()}],"mask-image-l-from-pos":[{"mask-l-from":Me()}],"mask-image-l-to-pos":[{"mask-l-to":Me()}],"mask-image-l-from-color":[{"mask-l-from":T()}],"mask-image-l-to-color":[{"mask-l-to":T()}],"mask-image-x-from-pos":[{"mask-x-from":Me()}],"mask-image-x-to-pos":[{"mask-x-to":Me()}],"mask-image-x-from-color":[{"mask-x-from":T()}],"mask-image-x-to-color":[{"mask-x-to":T()}],"mask-image-y-from-pos":[{"mask-y-from":Me()}],"mask-image-y-to-pos":[{"mask-y-to":Me()}],"mask-image-y-from-color":[{"mask-y-from":T()}],"mask-image-y-to-color":[{"mask-y-to":T()}],"mask-image-radial":[{"mask-radial":[je,ke]}],"mask-image-radial-from-pos":[{"mask-radial-from":Me()}],"mask-image-radial-to-pos":[{"mask-radial-to":Me()}],"mask-image-radial-from-color":[{"mask-radial-from":T()}],"mask-image-radial-to-color":[{"mask-radial-to":T()}],"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":L()}],"mask-image-conic-pos":[{"mask-conic":[Ye]}],"mask-image-conic-from-pos":[{"mask-conic-from":Me()}],"mask-image-conic-to-pos":[{"mask-conic-to":Me()}],"mask-image-conic-from-color":[{"mask-conic-from":T()}],"mask-image-conic-to-color":[{"mask-conic-to":T()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:z()}],"mask-repeat":[{mask:F()}],"mask-size":[{mask:J()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",je,ke]}],filter:[{filter:["","none",je,ke]}],blur:[{blur:Qe()}],brightness:[{brightness:[Ye,je,ke]}],contrast:[{contrast:[Ye,je,ke]}],"drop-shadow":[{"drop-shadow":["","none",k,El,Cl]}],"drop-shadow-color":[{"drop-shadow":T()}],grayscale:[{grayscale:["",Ye,je,ke]}],"hue-rotate":[{"hue-rotate":[Ye,je,ke]}],invert:[{invert:["",Ye,je,ke]}],saturate:[{saturate:[Ye,je,ke]}],sepia:[{sepia:["",Ye,je,ke]}],"backdrop-filter":[{"backdrop-filter":["","none",je,ke]}],"backdrop-blur":[{"backdrop-blur":Qe()}],"backdrop-brightness":[{"backdrop-brightness":[Ye,je,ke]}],"backdrop-contrast":[{"backdrop-contrast":[Ye,je,ke]}],"backdrop-grayscale":[{"backdrop-grayscale":["",Ye,je,ke]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[Ye,je,ke]}],"backdrop-invert":[{"backdrop-invert":["",Ye,je,ke]}],"backdrop-opacity":[{"backdrop-opacity":[Ye,je,ke]}],"backdrop-saturate":[{"backdrop-saturate":[Ye,je,ke]}],"backdrop-sepia":[{"backdrop-sepia":["",Ye,je,ke]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":C()}],"border-spacing-x":[{"border-spacing-x":C()}],"border-spacing-y":[{"border-spacing-y":C()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",je,ke]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[Ye,"initial",je,ke]}],ease:[{ease:["linear","initial",R,je,ke]}],delay:[{delay:[Ye,je,ke]}],animate:[{animate:["none",q,je,ke]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[S,je,ke]}],"perspective-origin":[{"perspective-origin":B()}],rotate:[{rotate:Ue()}],"rotate-x":[{"rotate-x":Ue()}],"rotate-y":[{"rotate-y":Ue()}],"rotate-z":[{"rotate-z":Ue()}],scale:[{scale:et()}],"scale-x":[{"scale-x":et()}],"scale-y":[{"scale-y":et()}],"scale-z":[{"scale-z":et()}],"scale-3d":["scale-3d"],skew:[{skew:Fe()}],"skew-x":[{"skew-x":Fe()}],"skew-y":[{"skew-y":Fe()}],transform:[{transform:[je,ke,"","none","gpu","cpu"]}],"transform-origin":[{origin:B()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:be()}],"translate-x":[{"translate-x":be()}],"translate-y":[{"translate-y":be()}],"translate-z":[{"translate-z":be()}],"translate-none":["translate-none"],zoom:[{zoom:[Pn,je,ke]}],accent:[{accent:T()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:T()}],"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",je,ke]}],"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":T()}],"scrollbar-track-color":[{"scrollbar-track":T()}],"scrollbar-gutter":[{"scrollbar-gutter":["auto","stable","both"]}],"scrollbar-w":[{scrollbar:["auto","thin","none"]}],"scroll-m":[{"scroll-m":C()}],"scroll-mx":[{"scroll-mx":C()}],"scroll-my":[{"scroll-my":C()}],"scroll-ms":[{"scroll-ms":C()}],"scroll-me":[{"scroll-me":C()}],"scroll-mbs":[{"scroll-mbs":C()}],"scroll-mbe":[{"scroll-mbe":C()}],"scroll-mt":[{"scroll-mt":C()}],"scroll-mr":[{"scroll-mr":C()}],"scroll-mb":[{"scroll-mb":C()}],"scroll-ml":[{"scroll-ml":C()}],"scroll-p":[{"scroll-p":C()}],"scroll-px":[{"scroll-px":C()}],"scroll-py":[{"scroll-py":C()}],"scroll-ps":[{"scroll-ps":C()}],"scroll-pe":[{"scroll-pe":C()}],"scroll-pbs":[{"scroll-pbs":C()}],"scroll-pbe":[{"scroll-pbe":C()}],"scroll-pt":[{"scroll-pt":C()}],"scroll-pr":[{"scroll-pr":C()}],"scroll-pb":[{"scroll-pb":C()}],"scroll-pl":[{"scroll-pl":C()}],"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",je,ke]}],fill:[{fill:["none",...T()]}],"stroke-w":[{stroke:[Ye,Ur,Si,gy]}],stroke:[{stroke:["none",...T()]}],"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":["start","end","right","left"],"inset-y":["inset-bs","inset-be","top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["ps","pe","pr","pl"],py:["pbs","pbe","pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["ms","me","mr","ml"],my:["mbs","mbe","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-s","border-w-e","border-w-r","border-w-l"],"border-w-y":["border-w-bs","border-w-be","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-s","border-color-e","border-color-r","border-color-l"],"border-color-y":["border-color-bs","border-color-be","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-ms","scroll-me","scroll-mr","scroll-ml"],"scroll-my":["scroll-mbs","scroll-mbe","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-ps","scroll-pe","scroll-pr","scroll-pl"],"scroll-py":["scroll-pbs","scroll-pbe","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"]}},p3=KN(m3);function I(...s){return p3(C0(s))}const g3=SN("inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-45 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",secondary:"bg-secondary text-secondary-foreground border border-border hover:bg-accent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground",destructive:"bg-destructive/15 text-destructive border border-destructive/40 hover:bg-destructive/25",link:"text-highlight underline-offset-4 hover:underline"},size:{default:"h-9 px-4",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 px-5",icon:"size-9","icon-sm":"size-7 rounded-md"}},defaultVariants:{variant:"default",size:"default"}});function we({className:s,variant:t,size:i,asChild:a=!1,type:l,...u}){const d=a?yN:"button";return o.jsx(d,{"data-slot":"button",type:a?void 0:l??"button",className:I(g3({variant:t,size:i}),s),...u})}const G0="w-full min-w-0 rounded-md border border-input bg-background/60 px-3 text-sm text-foreground placeholder:text-muted-foreground/80 outline-none transition-colors focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive";function Zn({className:s,type:t="text",...i}){return o.jsx("input",{"data-slot":"input",type:t,className:I(G0,"h-9",s),...i})}function ph({className:s,children:t,...i}){return o.jsx("select",{"data-slot":"select",className:I(G0,"h-9 appearance-none pr-8",s),style:{backgroundImage:`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2395a39a' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")`,backgroundPosition:"right 0.6rem center",backgroundSize:"16px",backgroundRepeat:"no-repeat"},...i,children:t})}function ro({className:s,...t}){return o.jsx("label",{"data-slot":"label",className:I("text-xs font-medium text-muted-foreground",s),...t})}function Ft({className:s,label:t}){return o.jsxs("span",{role:"status",className:I("inline-flex items-center gap-2 text-muted-foreground",s),children:[o.jsx(uc,{"aria-hidden":!0,className:"size-4 animate-spin"}),t?o.jsx("span",{children:t}):o.jsx("span",{className:"sr-only",children:"Loading"})]})}const Y0=b.createContext(null);function x3({controller:s,children:t}){return o.jsx(Y0.Provider,{value:s,children:t})}function Oe(){const s=b.useContext(Y0);if(!s)throw new Error("useController outside ControllerProvider");return s}function Ee(){const s=Oe();return b.useSyncExternalStore(b.useCallback(t=>s.subscribe(t),[s]),()=>s.getState())}function V0(s){const[t,i]=b.useState(!1),[a,l]=b.useState(null);return{run:b.useCallback(async(...d)=>{i(!0),l(null);try{return await s(...d),!0}catch(h){return l(h instanceof Error?h.message:String(h)),!1}finally{i(!1)}},[s]),pending:t,error:a,clearError:()=>l(null)}}const y3="M1196 972L1193 1004L1180 1053L1163 1087L1141 1117L1114 1143L1079 1166L1052 1178L1011 1189L970 1193L284 1193L217 1183L158 1156L113 1117L89 1084L68 1036L59 988L58 284L62 246L72 208L86 177L108 145L132 120L168 94L197 80L237 68L284 63L970 63L1030 71L1086 94L1123 121L1160 164L1182 208L1193 252L1196 285Z",b3="M717 377L693 495L641 803L566 803L566 801L644 371L717 371ZM594 443L531 803L462 803L469 764L447 780L424 792L402 800L371 806L345 807L309 803L278 794L256 784L238 773L216 755L202 740L184 714L170 684L163 659L160 637L160 607L164 582L171 559L180 539L196 514L231 479L250 466L280 451L313 441L345 437L377 438L405 443L431 452L463 469L483 484L509 511L522 439L589 438L594 439ZM1092 639L1086 671L1077 696L1067 715L1047 742L1031 758L1001 780L967 796L937 804L908 807L872 805L832 795L804 782L779 765L759 747L737 887L669 888L665 887L665 880L737 439L803 439L797 478L809 468L836 452L857 444L885 438L915 437L941 440L974 449L996 459L1031 483L1050 502L1071 533L1083 561L1089 584L1092 604ZM223 616L223 639L227 661L236 683L249 702L262 715L282 729L307 740L335 746L369 746L385 743L403 737L431 721L455 698L466 682L478 654L482 633L482 609L477 583L465 556L454 541L436 524L409 508L384 500L362 497L336 498L314 503L289 514L271 526L254 542L239 563L228 589ZM772 613L772 640L775 657L784 681L798 702L812 716L829 728L859 741L885 746L918 746L934 743L952 737L984 718L1004 698L1015 682L1027 654L1031 631L1031 610L1026 583L1015 558L1002 540L978 519L958 508L933 500L912 497L886 498L863 503L838 514L820 526L803 542L785 568L777 588Z";function K0({className:s}){return o.jsxs("svg",{viewBox:"0 0 1254 1254","aria-hidden":!0,className:I("shrink-0",s),children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:"alp-logo-tile",x1:"180",y1:"120",x2:"1080",y2:"1160",gradientUnits:"userSpaceOnUse",children:[o.jsx("stop",{stopColor:"#1d1e20"}),o.jsx("stop",{offset:"1",stopColor:"#111214"})]})}),o.jsx("path",{fill:"url(#alp-logo-tile)",d:y3}),o.jsx("path",{fill:"#fff",fillRule:"evenodd",d:b3})]})}const F0="alp-web:gateway",X0=!1;function v3(){let s=null;try{s=window.localStorage.getItem(F0)}catch{}return Y2({location:window.location,remembered:s,dev:X0})}function w3(){const s=Oe(),{connection:t}=Ee();return o.jsx("main",{className:"flex min-h-full items-center justify-center bg-[radial-gradient(ellipse_at_top,_var(--glow)_0%,_var(--background)_55%)] px-4 py-10",children:o.jsxs("div",{className:"w-full max-w-md space-y-4","data-testid":"link-connecting",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(K0,{className:"size-10"}),o.jsxs("div",{children:[o.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"ALP"}),o.jsx("p",{className:"text-sm text-muted-foreground",children:"Opening ALP on this machine"})]})]}),o.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[o.jsx(Ft,{label:"Connecting…"}),t.attempt>1?o.jsxs("span",{children:["Waiting for alp web (attempt ",t.attempt,")"]}):null]}),t.error?o.jsx("p",{className:"text-sm text-muted-foreground",children:t.error.message}):null,o.jsx(we,{size:"sm",variant:"ghost",onClick:()=>s.disconnect(),children:"Use another access token"})]})})}function k3(){const s=Oe(),{connection:t}=Ee(),[i,a]=b.useState(()=>t.gateway||v3()),[l,u]=b.useState(""),d=t.phase==="connecting",h=t.phase==="failed"?t.error:void 0;if(d&&t.link)return o.jsx(w3,{});const m=p=>{p.preventDefault();try{window.localStorage.setItem(F0,i.trim())}catch{}s.connect({url:i,token:l})};return o.jsx("main",{className:"flex min-h-full items-center justify-center bg-[radial-gradient(ellipse_at_top,_var(--glow)_0%,_var(--background)_55%)] px-4 py-10",children:o.jsxs("div",{className:"w-full max-w-md",children:[o.jsxs("div",{className:"mb-8 flex items-center gap-3",children:[o.jsx(K0,{className:"size-10"}),o.jsxs("div",{children:[o.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"ALP"}),o.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect to your agents on an ALP host"})]})]}),o.jsxs("form",{onSubmit:m,className:"space-y-5 rounded-xl border border-border bg-card/80 p-6 shadow-xl shadow-[var(--shadow)] backdrop-blur","aria-describedby":h?"connect-error":void 0,children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx(ro,{htmlFor:"gateway",children:"Gateway address"}),o.jsx(Zn,{id:"gateway",name:"gateway",inputMode:"url",autoComplete:"url",spellCheck:!1,value:i,onChange:p=>a(p.target.value),placeholder:"https://alp.example.com",required:!0,disabled:d})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx(ro,{htmlFor:"token",children:"Access token"}),o.jsx(Zn,{id:"token",name:"token",type:"password",autoComplete:"off",spellCheck:!1,value:l,onChange:p=>u(p.target.value),placeholder:"alpgw1.…",required:!0,disabled:d}),o.jsxs("p",{className:"flex items-start gap-1.5 text-xs text-muted-foreground",children:[o.jsx(dc,{"aria-hidden":!0,className:"mt-0.5 size-3.5 shrink-0 text-highlight"}),"Kept in this tab's memory only. Reloading or disconnecting forgets it."]})]}),h?o.jsx("div",{id:"connect-error",role:"alert",className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:h.message}):null,o.jsx(we,{type:"submit",className:"w-full",disabled:d||!i.trim()||!l.trim(),children:d?o.jsx(Ft,{className:"text-primary-foreground",label:"Connecting…"}):o.jsxs(o.Fragment,{children:[o.jsx(eN,{"aria-hidden":!0})," Connect"]})})]}),o.jsxs("details",{className:"mt-5 rounded-lg border border-border/70 bg-card/40 px-4 py-3 text-sm text-muted-foreground",children:[o.jsxs("summary",{className:"flex cursor-pointer items-center gap-2 font-medium text-foreground/90",children:[o.jsx(HS,{"aria-hidden":!0,className:"size-4"})," Getting a token"]}),o.jsxs("div",{className:"mt-3 space-y-2",children:[Cb({location:window.location,dev:X0})?o.jsxs(o.Fragment,{children:[o.jsxs("p",{children:["On this machine, run ",o.jsx("code",{className:"font-mono",children:"alp web"}),": it opens this page with a link that signs you in. ",o.jsx("code",{className:"font-mono",children:"alp web --print"})," prints the link instead, and ",o.jsx("code",{className:"font-mono",children:"alp web rotate"})," replaces its token, signing out every open page."]}),o.jsx("p",{children:"To use a standalone gateway instead, create a token for the workspaces you want to open, then start the gateway with this page's address as an allowed origin:"})]}):o.jsx("p",{children:"On the ALP host, create a token for the workspaces you want to open here, then start the gateway with this page's address as an allowed origin:"}),o.jsx("pre",{className:"overflow-x-auto rounded-md bg-background px-3 py-2 font-mono text-xs text-foreground/90",children:`alp-gateway credential create --label web \\
18
+ `)}}finally{this.#g=!1}this.#s&&this.#l()}resize(t,i){this.#v=ey(t,i),this.#D(this.#d.resizeDelayMs)}#D(t){this.#y!==void 0&&clearTimeout(this.#y),this.#y=setTimeout(()=>{this.#y=void 0,this.#H()},t)}async#H(){if(!this.accepting)return;const t=this.#v;if(!(this.#w&&this.#w.cols===t.cols&&this.#w.rows===t.rows))try{const i=await this.#d.request("terminal.resize",{terminalId:this.#e.terminalId,cols:t.cols,rows:t.rows});this.#w={cols:Number(i?.cols??t.cols),rows:Number(i?.rows??t.rows)}}catch{this.#w=null}}reattach(){this.#e.status!=="replaced"||!this.#e.terminalId||this.#E(this.#m,!1)}connected(){this.#b=!0;const{status:t,terminalId:i}=this.#e;t!=="reconnecting"&&t!=="attaching"&&t!=="starting"&&t!=="running"||(this.#w=null,i?this.#E(this.#m,!1):this.#a&&this.#z())}disconnected(){this.#b=!1,this.#f+=1,this.#o=null,this.#s&&(this.#s="",this.#h({lost:"Input typed while the connection dropped was not sent."})),["running","attaching","starting"].includes(this.#e.status)&&this.#h({status:"reconnecting"})}async close(){const{terminalId:t,status:i}=this.#e;if(this.dispose(),this.#C(void 0),this.#h({status:"closed"}),!(!t||i==="gone"||i==="closed"))try{await this.#d.request("terminal.close",{terminalId:t})}catch{}}#I(){this.#f+=1,this.#c!==void 0&&clearTimeout(this.#c),this.#y!==void 0&&clearTimeout(this.#y),this.#c=this.#y=void 0,this.#s=""}dispose(){this.#I(),this.#p.clear()}dismissLost(){this.#e.lost&&this.#h({lost:void 0})}}function Xd(s){const t=Be(s);return t.reason&&Zx[t.reason]?Zx[t.reason]:t.code===1003&&t.reason==="grant"?io.permission:t.code===1003&&t.reason==="outside_workspace"?"This workspace is not granted to your access token.":t.message}const cS=["attach.after","prompt.receipts"],ny={name:"alp-web",version:"0.10.0"},sy="Stop is waiting for this message’s outcome.",uS=15e3,dS=200,iy={"read-only":"Read only","workspace-write":"Workspace write","full-access":"Full access"};function ic(s,t){const i=s.tree,a=i&&i.rootId===t?Object.keys(i.projection.questions).length>0:!1;return i&&i.rootId===t&&i.status==="attached"?a:a||(s.attention[t]??0)>0}function ao(s,t){return s.turnAttention[t]?.reason}function Pd(s){if(!s||s.reason!=="finished"&&s.reason!=="error"||typeof s.at!="string")return;const t=Date.parse(s.at),i=s.reason==="error"&&typeof s.message=="string"&&s.message.trim()?s.message:void 0;return{reason:s.reason,at:Number.isFinite(t)?t:Date.now(),hostAt:s.at,...typeof s.turnId=="string"?{turnId:s.turnId}:{},...i?{message:i}:{}}}function fS(s){const t=Object.entries(s.turnAttention).filter(([i])=>s.tree?.rootId===i||s.sessions.list.some(a=>a.id===i&&!a.archived));return t.length===Object.keys(s.turnAttention).length?s.turnAttention:Object.fromEntries(t)}const ay="This access token cannot list files (needs project.read).",kf="This access token cannot read files (needs files.read).",Qb="This host does not offer file reading. Update ALP on the host.",Wb=100;function hS(s){if(typeof s!="string")return;const t=s.trim();return t&&t.length<=253&&!/[\p{Cc}\p{Cf}]/u.test(t)?t:void 0}function ry(s,t){const i=(Array.isArray(s?.sessions)?s.sessions:[]).filter(a=>a&&typeof a.id=="string"&&!a.parentId);return t?i.sort((a,l)=>String(l.updatedAt??l.createdAt??"").localeCompare(String(a.updatedAt??a.createdAt??""))):i}function mS(){try{return globalThis.sessionStorage??void 0}catch{return}}function rn(s=""){return{connection:{phase:"idle",gateway:s,attempt:0,capabilities:[]},principal:null,workspace:null,catalog:{status:"idle",teams:[],modes:[],models:[]},sessions:{status:"idle",list:[]},registry:{workspaces:[],revision:0},terminalDirectory:{items:[],mode:"idle"},history:{status:"idle",list:[],query:""},attention:{},turnAttention:{},selected:null,focus:null,tree:null,prompts:[],queued:[],busy:{},tasks:{status:"idle",visible:!1,rows:[],unreadable:0,creates:[],busy:{}},settings:{status:"idle",models:[]},notice:null,preferences:Oi(null)}}class $r extends Error{constructor(){super("The message was discarded."),this.name="DiscardedError"}}class oy extends Error{constructor(t,i,a){super(i.message),this.name="UploadError",this.fileName=t,this.failure=i,this.dropped=a}}class pS{#e;#j=new Set;#p=!1;#n;#i=null;#m="";#o=new Map;#f=new Map;#a=null;#s=null;#g=new Map;#c=new Map;#y=new Map;#v=new Map;#w=new Map;#b=new Map;#d=new Map;#h=new WeakMap;#k(t,i){const a=(this.#h.get(t)??Promise.resolve()).then(i);return this.#h.set(t,a.catch(()=>{})),a}#S=new WeakSet;#C=!1;#M=null;#z=new Set;#U=0;#E=!1;#T=null;#l={};#D={};#H=new Map;#I;#ae;#re;#N=null;#X=null;#P=null;#q=new Map;#Oe=0;#G=0;#xe={visible:!0,focused:!0};#tt=0;#R=new Map;#Y=new Map;#B;constructor(t={}){this.#n={open:O2,reconnecting:Cx,backoff:{initialMs:500,maxMs:15e3},stableMs:5e3,requestTimeoutMs:3e4,createTimeoutMs:12e4,taskPollMs:5e3,sessionPollMs:15e3,attentionPollMs:5e3,attentionWatchPollMs:6e4,historyPageSize:dS,releaseTimeoutMs:5e3,busyUnseenMs:uS,...t},this.#e={...rn(),preferences:Wx(t.storage)}}getState(){return this.#e}subscribe(t){return this.#j.add(t),()=>{this.#j.delete(t)}}#t(t){const i=typeof t=="function"?t(this.#e):t;this.#e={...this.#e,...i},this.#nt(),this.#e.queued.length&&this.#Tt()}#nt(){this.#p||(this.#p=!0,queueMicrotask(()=>{this.#p=!1;for(const t of[...this.#j])t()}))}#u(t,i,a){this.#t({notice:{id:++this.#tt,level:t,text:i,...a?.action?{action:a.action}:{}}})}dismissNotice(){this.#t({notice:null})}notify(t,i){this.#u(t,i)}#r(){const t=this.#i?.alp;if(!t||t.state!=="open"||!t.client)throw new Ke(this.#e.connection.phase==="reconnecting"?"Reconnecting to the host. Try again in a moment.":"Not connected to a host.");return t.client}connect({url:t,token:i,link:a=!1}){this.#oe(),a||Kr(this.#n.linkStorage);let l;try{l=Sb(t)}catch(k){this.#t({connection:{...this.#e.connection,phase:"failed",gateway:String(t),error:Be(k)}});return}const u=String(i??"").trim();if(!u){this.#t({connection:{...this.#e.connection,phase:"failed",gateway:l,error:Be(new Ra("Enter an access token."))}});return}this.#m=u,this.#e={...rn(l),preferences:this.#e.preferences},this.#t({connection:{phase:"connecting",gateway:l,attempt:1,capabilities:[],...a?{link:!0}:{}}});const d={opened:!1,...a?{link:!0}:{}};this.#i=d;const{open:h,reconnecting:m,backoff:p,stableMs:x,requestTimeoutMs:y}=this.#n,w=m({connect:async({signal:k})=>{const{transport:j,principal:S}=await h({url:l,token:this.#m,signal:k});if(this.#i!==d)throw j.close(),new Error("This connection was replaced.");return d.principal=S,j},onConnect:(k,j)=>this.#it(d,k,j.signal),onDisconnect:()=>{if(this.#i===d){this.#B?.close(!1),this.#B=void 0;for(const k of this.#R.values())k.disconnected();this.#s=null,this.#g.clear(),this.#a=null;for(const k of this.#o.values())k.attaching=null}},shouldRetry:k=>!Be(k).terminal,backoff:p,stableMs:x,client:{timeoutMs:y}});d.alp=w,w.onEvent(k=>{this.#i===d&&this.#dt(k)&&this.#ft(k)}),w.onNotification((k,j)=>{if(this.#i===d){if(k==="catalog.updated"){this.#et();return}if(k==="terminal.event")for(const S of this.#R.values())S.event(j)}}),w.onState((k,j)=>{this.#i===d&&this.#st(d,k,j)})}showError(t){this.#oe(),this.#t({connection:{...rn(this.#e.connection.gateway).connection,phase:"failed",error:{message:t,sent:"no",terminal:!0}}})}disconnect({keepTerminals:t=!1,keepLink:i=!1}={}){i||Kr(this.#n.linkStorage),this.#oe({keepTerminals:t})}#oe({keepTerminals:t=!1}={}){const i=this.#i;this.#i=null,this.#m="",this.#ye(),this.#o.clear(),this.#c.clear(),this.#f.clear(),this.#K.clear(),this.#se.clear(),this.#F.clear(),this.#ne.clear(),this.#g.clear();const a=[...this.#x.values()];this.#x.clear();for(const u of a)clearTimeout(u.retry),u.observer?.stop(),u.done();this.#O.clear(),this.#ge.clear(),this.#$!==void 0&&(clearTimeout(this.#$),this.#$=void 0),this.#a=null,this.#s=null,this.#M=null,this.#U+=1,this.#l={},this.#N=null;const l=this.#ct(t?null:i);if(i?.alp){const u=i.alp;l?l.then(()=>u.stop()):u.stop()}i&&this.#t({...rn(this.#e.connection.gateway),preferences:this.#e.preferences})}#st(t,i,a){const l=this.#e.connection;if(i==="open"){t.opened=!0,this.#t({connection:{...l,phase:"open",attempt:0,error:void 0}}),this.#rt();return}if(i==="connecting"){this.#t({connection:{...l,phase:t.opened?"reconnecting":"connecting",attempt:t.alp?.attempt??l.attempt}});return}if(i==="waiting"){if(!t.opened&&!t.link)return this.#De(a??new Error("Could not connect."));if(!t.opened){this.#t({connection:{...l,phase:"connecting",error:a?Be(a):void 0}});return}this.#ye(),this.#t({connection:{...l,phase:"reconnecting",error:a?Be(a):void 0}});return}i==="stopped"&&a&&this.#De(a)}#De(t){const i=this.#e.connection.gateway;let a=Be(t);this.#i?.link&&t instanceof Ra&&(Kr(this.#n.linkStorage),a={...a,message:q2}),this.#oe(),this.#t({connection:{...rn(i).connection,phase:"failed",error:a}})}async#it(t,i,a){const l=await Ax(i,ny,{signal:a,timeoutMs:15e3});if(this.#i!==t)throw new Error("This connection was replaced.");const u=Array.isArray(l?.capabilities)?l.capabilities.filter(m=>typeof m=="string"):[],d=cS.filter(m=>!u.includes(m));if(d.length)throw new Ke(`The host behind this gateway is too old for this app (it lacks ${d.join(", ")}). Update ALP on the host.`);this.#at(t.principal,u,typeof l?.daemonVersion=="string"?l.daemonVersion:void 0,hS(l?.hostname),mj(l?.promptImageLimits,u.includes("prompt.images")),bj(l?.attachmentLimits,u.includes("attachments")),u.includes("terminal")?wf(l?.terminalLimits):void 0),this.#s=null,this.#a=null;const h=this.#e.selected;if(h&&h!==this.#T&&!this.#o.get(h)?.gone){this.#_(h).failed=null;try{if(await this.#ue(i,h,a),this.#i!==t||a.aborted)throw new Error("This connection was replaced.");this.#s={client:i,root:h}}catch(m){if(this.#i!==t||a.aborted||!Ud(m))throw m;this.#$e(h,m)}}}#at(t,i,a,l,u,d={...Ps},h=void 0){this.#D={};const m=this.#e.workspace,p=m&&Ll(t,m)?m:t.workspaces[0]??null,x=JSON.stringify(t)!==JSON.stringify(this.#e.principal);p!==m&&(this.#l={},this.#N=null),this.#t(y=>({principal:t,registry:x?rn().registry:{...y.registry,loading:!1},connection:{...y.connection,capabilities:i,...a?{daemonVersion:a}:{},hostname:l,promptImageLimits:u,attachmentLimits:d,terminalLimits:h},...p!==y.workspace?{workspace:p,selected:null,focus:null,tree:null,sessions:rn().sessions,history:rn().history,attention:{},turnAttention:{},tasks:{...rn().tasks,visible:y.tasks.visible}}:{},...x||p!==y.workspace?{catalog:rn().catalog}:{}}))}#rt(){this.#lt();for(const t of this.#R.values())t.connected();this.#V(),this.#kt();for(const[t,i]of this.#x)i.attempts=0,i.exhausted=!1,this.#A(t);this.refreshRegistry(),this.#e.workspace&&(this.refreshSessions(),this.refreshAttention(),this.#e.history.status!=="idle"&&this.loadHistory({quiet:!0}),this.#e.catalog.status!=="ready"&&this.#Te(),this.#e.tasks.visible&&this.refreshTasks()),this.#ot()}#ot(){this.#ye(),this.#ae=setInterval(()=>{this.#e.workspace&&this.#e.connection.phase==="open"&&this.refreshSessions({quiet:!0})},this.#n.sessionPollMs);const t=this.hasCapability("question.watch")?this.#n.attentionWatchPollMs:this.#n.attentionPollMs;this.#re=setInterval(()=>{this.#e.workspace&&this.#e.connection.phase==="open"&&this.refreshAttention()},t),this.#I=setInterval(()=>{this.#e.tasks.visible&&this.#e.workspace&&this.#e.connection.phase==="open"&&this.refreshTasks({quiet:!0})},this.#n.taskPollMs)}#ye(){this.#ae!==void 0&&clearInterval(this.#ae),this.#I!==void 0&&clearInterval(this.#I),this.#re!==void 0&&clearInterval(this.#re),this.#ae=this.#I=this.#re=void 0}hasCapability(t){return this.#e.connection.capabilities.includes(t)}terminalGate(){return Pb(this.#e)}#lt(){this.#B?.close(),this.#B=void 0;const t=this.#i;!t||!this.hasCapability("terminal")||!Te(this.#e.principal??void 0,"terminal.exec")||(this.#B=h2(this.#r(),{capabilities:this.#e.connection.capabilities,onMode:i=>{this.#i===t&&this.#t(a=>({terminalDirectory:{...a.terminalDirectory,mode:i}}))},onSnapshot:i=>{this.#i===t&&this.#t(a=>({terminalDirectory:{...a.terminalDirectory,items:i,error:void 0}}))},onError:i=>{this.#i===t&&this.#t(a=>({terminalDirectory:{...a.terminalDirectory,error:Be(i).message}}))}}))}openListedTerminal(t,i){const a=this.terminalTabs(t),l=a.tabs.find(h=>h.session.getState().terminalId===i);if(l){this.selectTerminal(t,l.key);return}if(!this.#e.terminalDirectory.items.some(h=>h.terminalId===i&&h.workspaceId===t&&h.state==="running")||a.tabs.length>=32)return;const u=globalThis.crypto.randomUUID(),d=this.#be(t,u,a.storage,a.storageKey,i);a.tabs=[...a.tabs,{key:u,session:d}],a.active=u,this.#Q(t)}terminal(t){let i=this.#Y.get(t)??this.terminalTabs(t);return i.tabs.length||(this.addTerminal(t),i=this.terminalTabs(t)),(i.tabs.find(a=>a.key===i.active)??i.tabs[0]).session}terminalTabs(t){const i=this.terminalGate();if(!i.ok||i.workspaceId!==t)throw new Ke(i.ok?"That workspace is not the open one.":i.messages.join(" "));let a=this.#Y.get(t);if(a)return a;const l=this.#n.terminalStorage===void 0?mS():this.#n.terminalStorage??void 0,u=`alp-web.terminal|${this.#e.connection.gateway}|${this.#e.principal?.id??""}|${t}`;let d=["default"],h="default";try{const m=JSON.parse(l?.getItem(`${u}|tabs`)??"null");m?.v===1&&Array.isArray(m.keys)&&m.keys.length<=32&&m.keys.every(p=>typeof p=="string"&&/^(default|[a-zA-Z0-9-]{1,64})$/.test(p))&&new Set(m.keys).size===m.keys.length&&(d=m.keys,h=d.includes(m.active)?m.active:d[0]??null)}catch{}return a={tabs:d.map(m=>({key:m,session:this.#be(t,m,l,u)})),active:h,storage:l,storageKey:u},this.#Y.set(t,a),a}#be(t,i,a,l,u){const d=new lS({workspaceId:t,...u?{initialTerminalId:u}:{},request:(h,m)=>this.#r().request(h,m,{timeoutMs:this.#n.requestTimeoutMs}),limits:this.#e.connection.terminalLimits??wf(void 0),...a?{storage:a,storageKey:i==="default"?l:`${l}|${i}`}:{},...this.#n.terminalOptions});return this.#R.set(JSON.stringify([t,i]),d),d}#Q(t){const i=this.#Y.get(t);if(i){try{i.storage?.setItem(`${i.storageKey}|tabs`,JSON.stringify({v:1,keys:i.tabs.map(a=>a.key),active:i.active}))}catch{}this.#t({})}}addTerminal(t){const i=this.terminalTabs(t);if(i.tabs.length>=32)return i.active;const a=globalThis.crypto.randomUUID();return i.tabs=[...i.tabs,{key:a,session:this.#be(t,a,i.storage,i.storageKey)}],i.active=a,this.#Q(t),a}selectTerminal(t,i){const a=this.terminalTabs(t);a.tabs.some(l=>l.key===i)&&(a.active=i,this.#Q(t))}closeTerminalTab(t,i){const a=this.terminalTabs(t),l=a.tabs.findIndex(d=>d.key===i);if(l<0)return Promise.resolve();const u=a.tabs[l];return a.tabs=a.tabs.filter(d=>d.key!==i),a.active===i&&(a.active=a.tabs[Math.min(l,a.tabs.length-1)]?.key??null),this.#R.delete(JSON.stringify([t,i])),this.#Q(t),u.session.close()}closeTerminal(t=Jf(this.#e)?.id){const i=t?this.#Y.get(t):void 0;if(!t||!i)return Promise.resolve();const a=i.tabs;i.tabs=[],i.active=null;for(const l of a)this.#R.delete(JSON.stringify([t,l.key]));return this.#Q(t),Promise.allSettled(a.map(l=>l.session.close()))}#ct(t){this.#B?.close(),this.#B=void 0;const i=t?.alp?.state==="open"?t.alp.client:void 0,a=[];for(const l of this.#R.values()){const{terminalId:u,status:d}=l.getState();l.dispose(),i&&u&&d!=="gone"&&d!=="closed"&&a.push(i.request("terminal.close",{terminalId:u},{timeoutMs:1e3}).catch(()=>{}))}return this.#R.clear(),this.#Y.clear(),a.length?Promise.allSettled(a):void 0}#_(t){let i=this.#o.get(t);return i||(i={projection:bs(t),attaching:null,gone:null,failed:null},this.#o.set(t,i),this.#f.set(t,t)),i}#W(t){for(const i of t.order)this.#f.set(i,t.rootId);return t}#ut(t){const i=t?.sessionId;if(typeof i!="string")return;let a=this.#f.get(i);if(!a){const l=t.event?.type==="session.opened"?t.event.session?.parentId:void 0;a=typeof l=="string"&&this.#f.get(l)||void 0,a&&this.#f.set(i,a)}return a===this.#a?a:void 0}#dt(t){const i=t?.event;if(i?.type==="question"){const a=i.question?.id,l=i.question?.rootId;return typeof a=="string"&&typeof l=="string"&&this.#X?.events.push({id:a,root:l}),this.#N&&typeof a=="string"&&typeof l=="string"&&this.#N.get(a)!==l&&(this.#N.set(a,l),this.#ve()),t.cursor!==void 0||!!this.#a&&l===this.#a}if(i?.type==="attention"&&t.cursor===void 0)return typeof t.sessionId=="string"&&(this.#P&&this.#P.push([t.sessionId,i.attention??null]),this.#ht(t.sessionId,i.attention)),!1;if(i?.type==="turn.ended"&&t.cursor===void 0){if(typeof t.sessionId=="string"){const a=t.sessionId;this.#e.sessions.list.some(l=>l.id===a&&(l.status==="running"||l.busy))&&this.#t(l=>({sessions:{...l.sessions,list:l.sessions.list.map(u=>u.id===a?{...u,busy:!1,...u.status==="running"?{status:"idle"}:{}}:u)}})),this.#qe(a,i)}return!1}if(i?.type==="question.resolved"){if(typeof i.questionId=="string"&&this.#X?.events.push({id:i.questionId}),this.#N?.delete(i.questionId)&&this.#ve(),t.cursor!==void 0)return!0;const a=this.#a?this.#o.get(this.#a):void 0;return a?Object.hasOwn(a.projection.questions,i.questionId)||!!a.attaching?.buffer.some(l=>l.event?.type==="question"&&l.event.question?.id===i.questionId):!1}return!0}#ve(){if(!this.#N)return;const t={};for(const i of this.#N.values())t[i]=(t[i]??0)+1;JSON.stringify(t)!==JSON.stringify(this.#e.attention)&&this.#t({attention:t})}#ft(t){const i=this.#ut(t);if(!i)return;const a=this.#o.get(i);if(!a)return;if(t.event?.type==="history.reset"&&t.sessionId===i){this.#Be(i,t.event.generation);return}if(a.attaching){a.attaching.buffer.push(t);return}a.projection=this.#W(zi(a.projection,t)),this.#L(i);const l=t.event?.type;t.sessionId===i&&l==="turn.ended"?this.#qe(i,t.event):t.sessionId===i&&l==="turn.started"&&(this.#q.delete(i),this.#Z(i))}get#le(){return this.hasCapability("session.attention")&&this.hasCapability("question.watch")}#ht(t,i){this.#q.delete(t);const a=Pd(i);if(!a){this.#Z(t);return}if(this.#ce(t)){this.#Z(t),this.#we(t,a);return}this.#e.history.list.some(l=>l.id===t&&l.archived)||this.#e.turnAttention[t]?.hostAt!==a.hostAt&&this.#t(l=>({turnAttention:{...l.turnAttention,[t]:a}}))}#we(t,i){if(!this.#le||this.#e.connection.phase!=="open")return;const a={},l=this.#l;this.#q.set(t,a);const u=()=>{this.#q.get(t)===a&&(this.#q.delete(t),!(l!==this.#l||this.#e.turnAttention[t])&&(this.#e.history.list.some(d=>d.id===t&&d.archived)||this.#t(d=>({turnAttention:{...d.turnAttention,[t]:i}}))))};try{this.#r().request("session.attention.clear",{sessionId:t,...i.hostAt?{at:i.hostAt}:{}}).then(()=>{this.#q.get(t)===a&&this.#q.delete(t)},u)}catch{u()}}#Z(t){this.#e.turnAttention[t]&&this.#t(i=>{const{[t]:a,...l}=i.turnAttention;return{turnAttention:l}})}#qe(t,i){if(this.#le)return;const a=i?.state==="completed"?"finished":i?.state==="failed"?"error":void 0;if(!a){this.#Z(t);return}if(this.#ce(t)||this.#e.history.list.some(d=>d.id===t&&d.archived))return;const l=typeof i?.error?.message=="string"&&i.error.message.trim()?i.error.message:void 0,u={reason:a,at:Date.now(),...typeof i?.turnId=="string"?{turnId:i.turnId}:{},...a==="error"&&l?{message:l}:{}};this.#t(d=>({turnAttention:{...d.turnAttention,[t]:u}}))}#ce(t){const i=this.#e.focus??this.#e.selected;return this.#xe.visible&&this.#xe.focused&&(i===t||this.#e.selected===t)}setPresence({visible:t,focused:i}){this.#xe={visible:!!t,focused:!!i};const a=this.#e.focus??this.#e.selected;a&&this.#ce(a)&&this.clearAttention(a)}clearAttention(t){const i=t?this.#e.turnAttention[t]:void 0;!t||!i||(this.#Z(t),this.#we(t,i))}async#ue(t,i,a,l=0){const u=this.#_(i),d={buffer:[]};u.attaching=d,this.#a=i;const h=this.#y.get(i)??0;this.#e.selected===i&&this.#t(m=>({tree:{rootId:i,status:"attaching",projection:u.projection,...m.tree?.rootId===i&&m.tree.error?{}:{}}}));try{if(this.hasCapability("session.history")&&!this.#c.has(i)){const y=await t.request("session.history",{sessionId:i},{timeoutMs:this.#n.requestTimeoutMs,...a?{signal:a}:{}});if(u.attaching!==d)return;u.projection=bs(i);for(const w of y.items)u.projection=zi(u.projection,bf(w,i));this.#W(u.projection),u.projection={...u.projection,cursor:y.tipCursor},this.#c.set(i,{generation:y.generation,olderCursor:y.olderCursor,hasOlder:y.hasOlder})}const m=u.projection.cursor,p=this.#c.get(i),x=await t.request("session.attach",{sessionId:i,...p?{after:m,generation:p.generation}:m>0?{after:m}:{}},{timeoutMs:this.#n.requestTimeoutMs,...a?{signal:a}:{}});if(u.attaching!==d)return;u.attaching=null,u.gone=null,u.failed=null,this.#ke(i,u,x,d.buffer),(this.#y.get(i)??0)!==h&&this.#c.get(i)?.generation!==this.#v.get(i)&&(this.#c.delete(i),queueMicrotask(()=>{this.#je(t,i)}))}catch(m){if(u.attaching!==d)throw m;if(m?.data?.reason==="stale_cursor"&&l<1&&this.#c.has(i))return this.#c.delete(i),u.projection=bs(i),u.attaching===d&&(u.attaching=null),this.#ue(t,i,a,l+1);throw u.attaching===d&&(u.attaching=null),t===this.#i?.alp?.client&&this.#a===i&&(this.#a=null),m}}#ke(t,i,a,l){i.projection=this.#W(Ux(i.projection,a??{},l)),a?.reset&&!i.projection.historyUnavailable&&this.#u("info","The host restarted this conversation's history; it was loaded again from the beginning."),this.#L(t,"attached")}#Be(t,i){if(typeof i!="string"||!i||this.#c.get(t)?.generation===i||this.#v.get(t)===i)return;this.#v.set(t,i),this.#y.set(t,(this.#y.get(t)??0)+1),this.#c.delete(t);const a=this.#o.get(t);a&&this.#We(t,a.projection);const l=this.#s?.root===t?this.#s.client:void 0;a&&l&&!a.attaching&&this.#je(l,t)}#je(t,i){return this.#k(t,()=>this.#mt(t,i))}async#mt(t,i){if(!(t!==this.#i?.alp?.client||this.#e.selected!==i)&&!(this.#s?.client!==t||this.#s.root!==i)){this.#c.delete(i);try{await this.#ue(t,i)}catch(a){this.#Ne(t,i,a)}}}async loadOlder(){const t=this.#e.selected;if(!t)return;const i=this.#c.get(t),a=this.#o.get(t),l=this.#s?.root===t?this.#s.client:null;if(!i?.hasOlder||i.loading||!a||!l)return;const u={...i,loading:!0,error:void 0};this.#c.set(t,u),this.#L(t);try{const d=await l.request("session.history",{sessionId:t,before:i.olderCursor},{timeoutMs:this.#n.requestTimeoutMs});if(this.#c.get(t)!==u)return;if(d.generation!==i.generation)throw new Error("History changed; reconnect to refresh it.");a.projection=this.#W(Mj(a.projection,d.items)),this.#c.set(t,{generation:d.generation,olderCursor:d.olderCursor,hasOlder:d.hasOlder})}catch(d){this.#c.get(t)===u&&this.#c.set(t,{...i,error:Be(d).message})}this.#L(t)}#$e(t,i){const a=this.#_(t);a.gone=Be(i),a.attaching=null,this.#a===t&&(this.#a=null),this.#e.selected===t&&this.#t({tree:{rootId:t,status:"gone",error:a.gone,projection:a.projection}})}#L(t,i){if(this.#e.selected!==t){this.#A(t);return}const a=this.#o.get(t);if(!a)return;const l=Ix(a.projection),u=a.projection.prompts;for(const h of this.#O.get(t)??[]){const m=u[h];(m?.state==="failed"&&m.errorCode!=="outcome_unknown"||m?.turnId&&a.projection.turns[m.turnId]==="ended")&&this.#O.get(t)?.delete(h)}let d=this.#e.prompts.filter(h=>h.rootId!==t||!l.has(h.id));d=d.map(h=>{const m=u[h.id];if(h.rootId!==t||m?.state!=="failed")return h;const p=m.errorCode==="outcome_unknown",x=p?"unknown":"failed";if(h.status===x)return h;const y=p?"The host cannot tell whether the agent took the message":"The agent did not take the message";return{...h,status:x,error:m.error?`${y}: ${m.error}`:`${y}.`,retrySameId:!1}}),this.#t(h=>({tree:{rootId:t,status:i??(h.tree?.rootId===t?h.tree.status:"attached"),projection:a.projection,...this.#c.has(t)?{older:this.#c.get(t)}:{},...i==="attached"?{}:h.tree?.rootId===t&&h.tree.error?{error:h.tree.error}:{}},...d.length!==h.prompts.length||d.some((m,p)=>m!==h.prompts[p])?{prompts:d}:{},sessions:this.#Ue(h.sessions,t,a.projection),busy:{...h.busy,interrupt:this.#x.has(t)&&!this.#x.get(t)?.exhausted}})),this.#A(t)}#Ue(t,i,a){const l=t.list.findIndex(p=>p.id===i);if(l<0)return t;const u=t.list[l],d=a.sessions[i],h=a.closed[i]?"closed":i in a.running?"running":d?.status==="closed"||u.status==="closed"&&!d?"closed":"idle";if(u.status===h&&(!d?.title||d.title===u.title))return t;const m=t.list.slice();return m[l]={...u,status:h,...d?.title?{title:d.title}:{}},{...t,list:m}}async#V(){const t=this.#i?.alp?.client;if(t){if(this.#S.has(t)){this.#E=!0;return}this.#S.add(t);try{for(;;){this.#E=!1;const i=await this.#k(t,()=>this.#pt(t));if(t!==this.#i?.alp?.client||!i&&!this.#E)break}}finally{this.#S.delete(t)}}}async#pt(t){if(this.#i?.alp?.state!=="open"||t!==this.#i.alp.client)return!1;const i=this.#e.selected;this.#s&&this.#s.client!==t&&(this.#s=null);const a=this.#s;if(a&&a.root!==i)return this.#s=null,this.#a===a.root&&(this.#a=null),await this.#J(a),!0;if(!i||i===this.#T||this.#s?.root===i)return!1;const l=this.#_(i);if(l.gone)return this.#t({tree:{rootId:i,status:"gone",error:l.gone,projection:l.projection}}),!1;if(l.failed)return this.#t({tree:{rootId:i,status:"error",error:l.failed,projection:l.projection}}),!1;const u=this.#g.get(i);try{return this.#g.delete(i),this.#s={client:t,root:i},await this.#ue(t,i),t!==this.#i?.alp?.client?!0:(this.#s={client:t,root:i},this.#e.selected!==i)}catch(d){return u&&t===this.#i?.alp?.client&&(this.#s?.client===t&&this.#s.root===i&&(this.#s=null),await this.#J(u)),this.#Ne(t,i,d),!1}}async#J(t){const i=this.#x.get(t.root)?.observer;i&&i.state!=="stopped"?(this.#g.set(t.root,t),i.ready().catch(()=>{}).then(()=>this.#Se(t.root,t))):(this.#g.delete(t.root),await t.client.request("session.release",{sessionId:t.root},{timeoutMs:this.#n.releaseTimeoutMs}).catch(()=>{}))}#Se(t,i){const a=this.#g.get(t);!a||i&&a!==i||this.#k(a.client,async()=>{this.#g.get(t)===a&&(this.#g.delete(t),this.#i?.alp?.client===a.client&&(this.#s?.client===a.client&&this.#s.root===t||await a.client.request("session.release",{sessionId:t},{timeoutMs:this.#n.releaseTimeoutMs}).catch(()=>{})))})}#Ne(t,i,a){if(t!==this.#i?.alp?.client)return;if(Ud(a)){this.#$e(i,a);return}const l=this.#_(i);l.failed=Be(a),this.#e.selected===i&&this.#t({tree:{rootId:i,status:"error",error:l.failed,projection:l.projection}})}retryAttach(){const t=this.#e.selected;if(!t)return;const i=this.#o.get(t);i&&(i.gone=null,i.failed=null);const a=this.#i?.alp?.client;a&&this.#k(a,async()=>{const l=this.#s;l?.client===a&&l.root===t&&(this.#s=null,this.#a===t&&(this.#a=null),await this.#J(l))}).finally(()=>this.#V())}selectWorkspace(t){const i=this.#e.principal,a=t&&(Ll(i??void 0,t)||this.#e.registry.workspaces.some(l=>l.managedWorktree&&l.directory===t))?t:null;a!==this.#e.workspace&&(this.#l={},this.#N=null,this.#t(l=>({workspace:a,selected:null,focus:null,tree:null,sessions:rn().sessions,history:rn().history,attention:{},turnAttention:{},catalog:rn().catalog,tasks:{...rn().tasks,visible:l.tasks.visible}})),this.#V(),a&&this.#e.connection.phase==="open"&&(this.refreshSessions(),this.refreshAttention(),this.#Te(),this.#e.tasks.visible&&this.refreshTasks()))}async refreshRegistry(){if(!this.hasCapability("workspace.registry")||!Te(this.#e.principal??void 0,"project.read")||this.#e.registry.loading)return;const t=this.#D,i=this.#i;this.#t(a=>({registry:{...a.registry,loading:!0}}));try{const a=[];let l,u=0;do{const d=await this.#r().request("workspace.list",{limit:500,...l?{cursor:l}:{}});a.push(...d.workspaces),u=d.revision,l=d.nextCursor}while(l);t===this.#D&&i===this.#i&&this.#t({registry:{workspaces:a,revision:u}})}catch(a){t===this.#D&&i===this.#i&&this.#t(l=>({registry:{...l.registry,loading:!1,error:a instanceof Error?a.message:String(a)}}))}}async pinWorkspace(t,i){if(!Te(this.#e.principal??void 0,"workspace.write")){this.#u("error","Ask the host owner to add workspace.write to your credential to change shared pins.");return}const a=()=>this.#r().request("workspace.update",{workspaceId:t,pinned:i,ifRevision:this.#e.registry.revision,requestId:globalThis.crypto.randomUUID()});try{try{await a()}catch(l){if(l?.data?.reason!=="stale_revision")throw l;await this.refreshRegistry(),await a()}await this.refreshRegistry()}catch(l){this.#u("error",`Pin was not saved. ${l instanceof Error?l.message:String(l)} Refresh and try again.`),await this.refreshRegistry()}}async renameWorkspace(t,i){if(!Te(this.#e.principal??void 0,"workspace.write"))return this.#u("error","Ask the host owner to add workspace.write to your credential to rename shared workspaces."),!1;try{return await this.#r().request("workspace.update",{workspaceId:t,title:i.trim()||null,ifRevision:this.#e.registry.revision,requestId:globalThis.crypto.randomUUID()}),await this.refreshRegistry(),!0}catch(a){return this.#u("error",`Name was not saved. ${a instanceof Error?a.message:String(a)} Refresh and try again.`),await this.refreshRegistry(),!1}}async worktreeOptions(t){return(await this.#r().request("workspace.worktree.options",{workspaceId:t})).mappingIds}async mutateWorktree(t,i,a){if(!this.hasCapability("workspace.worktree")||!Te(this.#e.principal??void 0,"workspace.manage"))return!1;const l=t+":"+i+":"+(a??"");let u=this.#H.get(l);u||(u={workspaceId:i,...a?{mappingId:a}:{},ifRevision:this.#e.registry.revision,requestId:globalThis.crypto.randomUUID()},this.#H.set(l,u));try{return await this.#r().request("workspace.worktree."+t,u),this.#H.delete(l),await this.refreshRegistry(),!0}catch(d){return d?.data?.reason==="stale_revision"&&this.#H.delete(l),this.#u("error",`Worktree ${t} was not confirmed. ${d instanceof Error?d.message:String(d)} Retry the same operation to reconcile its outcome.`),await this.refreshRegistry(),!1}}async registerProject(t){if(!Te(this.#e.principal??void 0,"workspace.write")){this.#u("error","Ask the host owner to add workspace.write to your credential. To add another directory, the owner must grant it locally first.");return}try{await this.#r().request("project.register",{directory:t,ifRevision:this.#e.registry.revision,requestId:globalThis.crypto.randomUUID()}),await this.refreshRegistry()}catch(i){this.#u("error",`Project was not added. ${i instanceof Error?i.message:String(i)} Refresh and try again.`),await this.refreshRegistry()}}async listWorkspaceSessions(t){if(!Te(this.#e.principal??void 0,"session.read")||this.#e.connection.phase!=="open")return{};const i=this.#r(),a=await Promise.all(t.map(async l=>{try{const u=await i.request("session.list",{projectRoot:l,rootsOnly:!0,includeClosed:!0});return[l,(Array.isArray(u?.sessions)?u.sessions:[]).filter(d=>d&&typeof d.id=="string"&&!d.parentId&&!d.archived)]}catch{return null}}));return Object.fromEntries(a.filter(Boolean))}async refreshSessions({quiet:t=!1}={}){this.refreshRegistry();const i=this.#e.workspace;if(!i)return;const a=this.#l;t||this.#t(u=>({sessions:{...u.sessions,status:u.sessions.list.length?u.sessions.status:"loading",error:void 0}}));const l=Date.now();try{const d=await this.#r().request("session.list",{projectRoot:i,rootsOnly:!0,includeClosed:!0});if(a!==this.#l)return;const h=(Array.isArray(d?.sessions)?d.sessions:[]).filter(m=>m&&typeof m.id=="string"&&!m.parentId&&!m.archived).sort((m,p)=>String(p.updatedAt??p.createdAt??"").localeCompare(String(m.updatedAt??m.createdAt??"")));this.#t(m=>{let p={status:"ready",list:h};for(const[j,S]of this.#o)p=this.#Ue(p,j,S.projection);const x=m.selected&&!h.some(j=>j.id===m.selected)?m.sessions.list.find(j=>j.id===m.selected):void 0,w=this.#le?[]:Object.keys(m.turnAttention).filter(j=>m.turnAttention[j].at<l&&h.some(S=>S.id===j&&(S.status==="running"||S.busy))),k=w.length?Object.fromEntries(Object.entries(m.turnAttention).filter(([j])=>!w.includes(j))):m.turnAttention;return{sessions:x?{...p,list:[x,...p.list]}:p,turnAttention:k}})}catch(u){if(a!==this.#l)return;t||this.#t(d=>({sessions:{...d.sessions,status:"error",error:Be(u)}}))}}async refreshAttention(){const t=this.#e.workspace;if(!t||!Te(this.#e.principal??void 0,"session.read"))return;const i=this.#l,a=++this.#Oe,l=this.hasCapability("question.watch"),u=l?{read:a,events:[]}:null;this.#X=u;const d=this.#le,h=d?[]:null;this.#P=h;try{const m=l&&this.hasCapability("question.watch.turns"),p=await this.#r().request(l?"question.watch":"question.list",{projectRoot:t,...m?{turns:!0}:{},...d?{attention:!0}:{}});if(i!==this.#l||a!==this.#Oe)return;d&&Array.isArray(p?.attention)&&this.#gt(p.attention,h??[]);const x=new Map;for(const y of Array.isArray(p?.questions)?p.questions:[])typeof y?.id=="string"&&typeof y.rootId=="string"&&x.set(y.id,y.rootId);for(const y of u?.events??[])y.root?x.set(y.id,y.root):x.delete(y.id);this.#N=x,this.#ve(),l||(this.#N=null)}catch{}finally{this.#X===u&&(this.#X=null),this.#P===h&&(this.#P=null)}}#gt(t,i){const a=new Map;for(const u of t)typeof u?.sessionId=="string"&&Pd(u.attention)&&a.set(u.sessionId,u.attention);for(const[u,d]of i)a.set(u,d);const l={};for(const[u,d]of a){const h=Pd(d);if(!h||this.#e.history.list.some(p=>p.id===u&&p.archived))continue;if(this.#ce(u)){this.#we(u,h);continue}const m=this.#e.turnAttention[u];l[u]=m?.hostAt===h.hostAt?m:h}JSON.stringify(l)!==JSON.stringify(this.#e.turnAttention)&&this.#t({turnAttention:l})}get historyPaged(){return this.hasCapability("session.list.page")}async loadHistory({quiet:t=!1,query:i=this.#e.history.query}={}){const a=this.#e.workspace;if(!a)return;const l=this.#l,u=++this.#G,d=this.historyPaged,h=i.trim();t||this.#t(m=>({history:{...m.history,status:"loading",error:void 0,query:i}}));try{const m=await this.#r().request("session.list",{projectRoot:a,rootsOnly:!0,includeClosed:!0,includeArchived:!0,...d?{limit:this.#n.historyPageSize,...h?{query:h}:{}}:{}});if(l!==this.#l||u!==this.#G)return;const p=d&&typeof m?.nextCursor=="string"?m.nextCursor:void 0;this.#t({history:{status:"ready",list:ry(m,!d),query:i,...p?{nextCursor:p}:{}}})}catch(m){if(l!==this.#l||u!==this.#G)return;(!t||this.#e.history.status!=="ready")&&this.#t(p=>({history:{...p.history,status:"error",error:Be(m),query:i}}))}}async loadMoreHistory(){const t=this.#e.workspace,{status:i,nextCursor:a,query:l,more:u}=this.#e.history;if(!t||i!=="ready"||!a||u==="loading")return;const d=this.#l,h=this.#G,m=l.trim();this.#t(p=>({history:{...p.history,more:"loading"}}));try{const p=await this.#r().request("session.list",{projectRoot:t,rootsOnly:!0,includeClosed:!0,includeArchived:!0,limit:this.#n.historyPageSize,cursor:a,...m?{query:m}:{}});if(d!==this.#l)return;if(h!==this.#G){this.#He();return}const x=typeof p?.nextCursor=="string"?p.nextCursor:void 0;this.#t(y=>{const w=new Set(y.history.list.map(A=>A.id)),{more:k,nextCursor:j,...S}=y.history;return{history:{...S,list:[...S.list,...ry(p,!1).filter(A=>!w.has(A.id))],...x?{nextCursor:x}:{}}}})}catch{if(d!==this.#l)return;if(h!==this.#G){this.#He();return}this.#t(p=>({history:{...p.history,more:"error"}}))}}#He(){if(this.#e.history.more!=="loading")return;const{more:t,...i}=this.#e.history;this.#t({history:i})}get filesSearchable(){return this.hasCapability("workspace.files")}async searchWorkspaceFiles({query:t="",limit:i=Wb}={}){const a=this.#e.workspace;if(!a)throw new Ke("Choose a workspace first.");if(!this.filesSearchable)throw new Ke("The host does not offer file search. Update ALP on the host.");if(!Te(this.#e.principal??void 0,"project.read"))throw new Ke(ay);let l;try{l=await this.#r().request("workspace.files.search",{projectRoot:a,query:String(t).slice(0,200),limit:i})}catch(d){throw Be(d).code===1003?new Ke(ay):d}return{files:(Array.isArray(l?.files)?l.files:[]).filter(d=>d&&typeof d.path=="string"&&d.path).map(d=>({path:String(d.path)})),truncated:l?.truncated===!0}}get filesReadable(){return this.hasCapability("workspace.files.read")}get canReadFiles(){return Te(this.#e.principal??void 0,"files.read")}#Ie(t,i){const a=(d,h,m=!1)=>new Ei({message:d,reason:h,sent:"no",terminal:m}),l=this.#e.workspace;if(!l)throw a("Choose a workspace first.","workspace");if(!this.filesReadable)throw a(Qb,"capability",!0);if(!this.canReadFiles)throw a(kf,"grant",!0);if(t===void 0||t===""){if(i)throw a(Ir.invalid_path,"invalid_path");return{workspace:l,path:void 0}}const u=Js(t);if(!u)throw a(Ir.invalid_path,"invalid_path");if($i(u))throw a(Ir.blocked_path,"blocked_path");return{workspace:l,path:u}}#Ge(t){const i=g2(t);return i.code===1003&&i.reason==="grant"?new Ei({...i,message:kf}):new Ei(i)}async listWorkspaceFiles({path:t,includeIgnored:i=!1}={}){const a=this.#Ie(t,!1);let l;try{l=await this.#r().request("workspace.files.list",{projectRoot:a.workspace,...a.path?{path:a.path}:{},...i?{includeIgnored:!0}:{}})}catch(u){throw this.#Ge(u)}return x2(l,a.path??"")}async readWorkspaceFile({path:t,includeIgnored:i=!1}){const a=this.#Ie(t,!0);let l;try{l=await this.#r().request("workspace.files.read",{projectRoot:a.workspace,path:a.path,...i?{includeIgnored:!0}:{}})}catch(d){throw this.#Ge(d)}const u=typeof l?.content=="string"?l.content:void 0;if(u===void 0||u.length>Hl.maxReadBytes)throw new Ei({message:u===void 0?"The host sent something this app does not understand.":Ir.too_large,...u===void 0?{}:{reason:"too_large"},sent:"yes",terminal:!1});return{path:a.path,content:u,size:typeof l?.size=="number"&&Number.isFinite(l.size)?l.size:u.length,...typeof l?.modifiedAt=="string"?{modifiedAt:l.modifiedAt}:{}}}get gitAccess(){return Gd(this.#e)}async gitStatus(){const t=Gd(this.#e);if(!t.status)throw new ys({message:t.message,reason:t.reason,sent:"no",terminal:t.reason!=="loading"});let i;try{i=await this.#r().request("workspace.git.status",{workspaceId:t.workspaceId})}catch(a){throw new ys(_i(a))}if(!i||typeof i!="object"||typeof i.state!="string"||!Array.isArray(i.files))throw new ys({message:"The host sent something this app does not understand.",sent:"yes",terminal:!1});return i}async gitDiff({compare:t,path:i,cursor:a}){const l=Gd(this.#e);if(!l.status)throw new ys({message:l.message,reason:l.reason,sent:"no",terminal:l.reason!=="loading"});if(!l.content)throw new ys({message:l.contentMessage,reason:"grant",sent:"no",terminal:!0});const u=i===void 0?void 0:cj(i);if(i!==void 0&&!u){const h=Js(i)?"blocked_path":"invalid_path";throw new ys({message:Gl[h],reason:h,sent:"no",terminal:!1})}let d;try{d=await this.#r().request("workspace.git.diff",{workspaceId:l.workspaceId,compare:uj(t),...u?{path:u}:{},...a?{cursor:a}:{}})}catch(h){throw new ys(_i(h))}if(!d||typeof d!="object"||typeof d.snapshot!="string"||!Array.isArray(d.files))throw new ys({message:"The host sent something this app does not understand.",sent:"yes",terminal:!1});return d}isArchived(t){return t?!!this.#e.history.list.find(i=>i.id===t)?.archived&&!this.#e.sessions.list.some(i=>i.id===t):!1}async#Te(){const t=this.#e.workspace,i=this.#e.principal;if(!t||!i)return;const a=this.#l;this.#t(l=>({catalog:{...l.catalog,status:"loading",error:void 0}}));try{const l=this.#r(),[u,d,h]=await Promise.all([this.#Ye(l,i,t),Te(i,"session.read")?l.request("catalog.get",{}).catch(()=>{}):void 0,this.hasCapability("library")&&Te(i,"session.read")?l.request("library.models",{}).catch(()=>{}):void 0]);if(a!==this.#l)return;const m=i.modes,x=(Array.isArray(d?.modes)&&d.modes.length?d.modes:Object.keys(iy).map(k=>({id:k}))).filter(k=>typeof k?.id=="string"&&(!m||m.includes(k.id))).map(k=>({id:k.id,label:typeof k.label=="string"?k.label:iy[k.id]??k.id,...typeof k.description=="string"?{description:k.description}:{}})),y=Gx(h?.models),w=x.some(k=>k.id==="full-access")?"full-access":x[0]?.id;this.#t({catalog:{status:"ready",...u,modes:x,models:y,...w?{defaultMode:w}:{}}})}catch(l){if(a!==this.#l)return;this.#t(u=>({catalog:{...u.catalog,status:"error",error:Be(l)}}))}}async#Ye(t,i,a){if(!this.hasCapability("team"))return{teams:[],teamsKnown:!1,teamsUnavailable:{reason:"capability"}};if(!Te(i,"project.read"))return{teams:[],teamsKnown:!1,teamsUnavailable:{reason:"permission"}};try{const l=await t.request("team.list",{projectRoot:a});return Array.isArray(l?.teams)?{teams:l.teams.filter(d=>typeof d?.id=="string"&&!d.error).map(d=>({id:d.id,label:typeof d.label=="string"?d.label:d.id,...typeof d.description=="string"?{description:d.description}:{}})),teamsKnown:!0}:{teams:[],teamsKnown:!1,teamsUnavailable:{reason:"failed",message:"The host answered team.list in a form this app does not read."}}}catch(l){return{teams:[],teamsKnown:!1,teamsUnavailable:{reason:"failed",message:Be(l).message}}}}startOrigin(){return{workspace:this.#e.workspace,connection:this.#U}}keepUnsentDraft(t,i){if(!t||!i?.workspace||i.connection!==this.#U)return;const a={workspace:i.workspace,text:String(t)};for(const l of this.#z)if(l(a)){this.#M=null;return}this.#M=a}takeUnsentDrafts(t){return this.#z.add(t),()=>{this.#z.delete(t)}}unsentDraft(){const t=this.#M;return t&&t.workspace===this.#e.workspace?t.text:""}clearUnsentDraft(t){(t===void 0||this.#M?.text===t)&&(this.#M=null)}async retryTeams(){const{workspace:t,principal:i,catalog:a}=this.#e;if(!t||!i||a.status!=="ready"||a.teamsUnavailable?.reason!=="failed"||this.#C)return;const l=this.#l;this.#C=!0;try{const u=await this.#Ye(this.#r(),i,t);if(l!==this.#l||this.#e.workspace!==t||this.#e.catalog.status!=="ready")return;this.#t(d=>({catalog:{...d.catalog,teams:u.teams,teamsKnown:u.teamsKnown,teamsUnavailable:u.teamsUnavailable}}))}catch{}finally{this.#C=!1}}selectSession(t){if(this.clearAttention(t),t===this.#e.selected)return;const i=t?this.#_(t):void 0;i&&(i.failed=null),this.#t({selected:t,focus:t,tree:t&&i?{rootId:t,status:i.gone?"gone":"detached",...i.gone?{error:i.gone}:{},projection:i.projection}:null}),this.#V()}focusSession(t){const i=this.#e.tree?.projection;!i||t!==i.rootId&&!i.sessions[t]||(this.clearAttention(t),this.#t({focus:t}))}async createSession({team:t,mode:i,model:a,thinking:l,title:u,prompt:d,files:h=[]}={}){const m=this.#e.workspace;if(!m)throw new Ke("Choose a workspace first.");if(this.#T||this.#e.busy.create)throw new Ke("A new session is already starting.");const p=this.#r(),x=V2(),y=this.#l;this.#T=x,this.#t(A=>({busy:{...A.busy,create:!0}}));const w=this.#_(x),k={id:x,projectRoot:m,status:"initializing",...u?{title:u}:{},createdAt:new Date().toISOString()};this.#t(A=>({selected:x,focus:x,tree:{rootId:x,status:"attaching",projection:w.projection},sessions:{...A.sessions,list:[k,...A.sessions.list.filter(R=>R.id!==x)]}}));const j=()=>y===this.#l&&p===this.#i?.alp?.client,S=()=>{if(!j())throw new Ke("The connection or workspace changed while starting the session.")};try{return await this.#k(p,async()=>{S();const A=this.#s;A&&A.client===p&&(this.#s=null,this.#a=null,await this.#J(A)),S();const R={buffer:[]};w.attaching=R,this.#a=x;const q={cwd:m,persist:!0,...t?{workflow:t}:{},...i?{mode:i}:{},...a?{model:a}:{},...l?{thinking:l}:{}};this.#s={client:p,root:x};try{await p.request("session.create",{sessionId:x,spec:q,history:"skip"},{timeoutMs:this.#n.createTimeoutMs}),S(),this.#s={client:p,root:x}}catch(O){if(!j())throw O;w.attaching=null;const L=Be(O);throw L.sent!=="unknown"?(this.#s?.client===p&&this.#s.root===x&&(this.#s=null,await this.#J({client:p,root:x})),j()&&(this.#o.delete(x),this.#c.delete(x),this.#f.delete(x),this.#a===x&&(this.#a=null),this.#t(B=>({...B.selected===x?{selected:null,focus:null,tree:null}:{},sessions:{...B.sessions,list:B.sessions.list.filter(_=>_.id!==x)}}))),O):(this.refreshSessions(),new wb(`${L.message} If the new session shows in the list, open it and send your message there; otherwise start again.`,x))}try{let O;if(this.hasCapability("session.history")){const B=await p.request("session.history",{sessionId:x,limit:1},{timeoutMs:this.#n.requestTimeoutMs});S(),O=B.generation,this.#c.set(x,{generation:O,hasOlder:!1})}const L=await p.request("session.attach",{sessionId:x,...O?{generation:O,after:0}:{}},{timeoutMs:this.#n.requestTimeoutMs});S(),w.attaching===R&&(w.attaching=null,w.failed=null,this.#ke(x,w,L,R.buffer))}catch(O){if(!j())throw O;w.attaching===R&&(w.attaching=null),this.#a===x&&(this.#a=null),this.#Ne(p,x,O)}return u?.trim()&&await this.renameSession(x,u.trim()).catch(()=>{}),S(),this.#Et({team:t,mode:i,model:a,thinking:l}),(d?.trim()||h.length)&&await this.sendPrompt(d??"",x,[],h,{keepRefused:!0}).catch(O=>this.#u("error",Be(O).message)),this.refreshSessions({quiet:!0}),x})}finally{this.#T===x&&(this.#T=null,this.#t(A=>({busy:{...A.busy,create:!1}}))),this.#V()}}async renameSession(t,i){const u=(await this.#r().request("session.rename",{sessionId:t,title:i}))?.session,d=m=>m.id===t?{...m,...u&&typeof u=="object"?u:{},title:i}:m;this.#t(m=>({sessions:{...m.sessions,list:m.sessions.list.map(d)},history:{...m.history,list:m.history.list.map(d)}}));const h=this.#o.get(t);h&&(h.projection={...h.projection,sessions:{...h.projection.sessions,[t]:{...h.projection.sessions[t],id:t,title:i}}},this.#L(t))}async archiveSession(t){const i=this.#r(),a=this.#l;if(await i.request("session.archive",{sessionId:t,archived:!0}),a!==this.#l)return;this.#e.selected===t&&this.selectSession(null);const{[t]:l,...u}=this.#e.attention,{[t]:d,...h}=this.#e.turnAttention;this.#t(m=>({turnAttention:h,sessions:{...m.sessions,list:m.sessions.list.filter(p=>p.id!==t)},history:{...m.history,list:m.history.list.map(p=>p.id===t?{...p,archived:!0}:p)},attention:u}))}async restoreSession(t){const i=this.#r(),a=this.#l,l=await i.request("session.archive",{sessionId:t,archived:!1});if(a!==this.#l)return;const u=l?.session&&typeof l.session=="object"?l.session:void 0;this.#t(d=>{const m={...d.history.list.find(p=>p.id===t)??{},...u??{},id:t,archived:!1};return{history:{...d.history,list:d.history.list.map(p=>p.id===t?m:p)},sessions:{...d.sessions,list:d.sessions.list.some(p=>p.id===t)?d.sessions.list:[m,...d.sessions.list]}}}),this.refreshSessions({quiet:!0})}#de(t){const i=this.#e.sessions.list.find(l=>l.id===t)??this.#e.history.list.find(l=>l.id===t),a=this.#o.get(t)?.projection.sessions[t];return{...i??{},...a??{},...a?.conversation?{}:i?.conversation?{conversation:i.conversation}:{}}}conversationGate(t=this.#e.tree?.rootId){const{principal:i,connection:a}=this.#e,l=t?this.#o.get(t):void 0,u=!!t&&!!l&&(this.rootBusy(t)||Object.keys(l.projection.running).length>0||Object.keys(l.projection.questions).length>0);return Q2({capabilities:a.capabilities,canRead:Te(i??void 0,"session.read"),canWrite:Te(i??void 0,"session.write"),summary:t?this.#de(t):null,busy:u,generation:t?this.#c.get(t)?.generation??null:null,online:a.phase==="open",driveBlock:t&&t===this.#e.tree?.rootId?this.driveBlock():void 0})}agentControls(t){const{principal:i,connection:a}=this.#e,l=this.#e.tree?.rootId,u=l?this.#o.get(l):void 0,d=!!l&&t===l,h=d&&!!u&&(this.rootBusy(l)||Object.keys(u.projection.running).length>0||Object.keys(u.projection.questions).length>0);return nj({capabilities:a.capabilities,canRead:Te(i??void 0,"session.read"),canWrite:Te(i??void 0,"session.write"),summary:d?this.#de(l):null,root:d,closed:d&&!!u?.projection.closed[l],busy:h,generation:d?this.#c.get(l)?.generation??null:null,online:a.phase==="open",driveBlock:d?this.driveBlock():void 0})}#ee=new Map;async listCommands(t){if(!this.#e.connection.capabilities.includes("session.commands"))return this.#ee.get(t)??[];try{const i=await this.#r().request("session.commands",{sessionId:t}),a=Array.isArray(i?.commands)?i.commands.filter(l=>typeof l?.name=="string"&&l.name):[];return(a.length||!this.#ee.has(t))&&this.#ee.set(t,a),this.#ee.get(t)??[]}catch{return this.#ee.get(t)??[]}}async copyResumeCommand(t,i){try{const a=await this.#r().request("session.resumeCommand",{sessionId:t});if(typeof a?.display!="string"||!a.display)throw new Ke("The host answered no command.");return await i(a.display),this.#u("info",`Copied the resume command: ${a.display}`),a}catch(a){this.#u("error",`Could not copy the resume command: ${Be(a).message}`);return}}async reloadAgent({sessionId:t,requestId:i}){const{root:a,generation:l,client:u}=this.#fe();if(t!==a)throw new Ke(Fr.not_root);this.#u("info","Reloading the agent…");try{const d=await u.request("session.reload",{sessionId:a,requestId:i,ifGeneration:l},{timeoutMs:this.#n.createTimeoutMs});return this.#Ae(d.session),this.refreshSessions({quiet:!0}),this.#u("info","Reloaded the agent: it restarted on the same conversation."),d}catch(d){throw this.#he(a,d),this.#u("error",Z2(d).message),d}}async compactAgent({sessionId:t}){const i=this.#e.tree?.rootId;if(!i||t!==i)throw new Ke(Wf.not_root);try{const a=await this.#r().request("session.compact",{sessionId:i});return this.#u("info",ej(a?.status)),a}catch(a){throw this.#u("error",tj(a).message),a}}rootSummary(t=this.#e.tree?.rootId){return t?this.#de(t):{}}historyGeneration(t){return this.#c.get(t)?.generation}#Ae(t){if(!t||typeof t.id!="string")return;const i=t.id,a=u=>u.id===i?{...u,...t}:u;this.#t(u=>({sessions:{...u.sessions,list:u.sessions.list.map(a)},history:{...u.history,list:u.history.list.map(a)}}));const l=this.#o.get(i);l&&(l.projection={...l.projection,sessions:{...l.projection.sessions,[i]:{...l.projection.sessions[i],...t,id:i}}},this.#L(i))}#fe(){const t=this.#e.tree?.rootId??this.#e.selected;if(!t)throw new Ke("Open a session first.");const i=this.#c.get(t)?.generation;if(!i)throw new Ke("The conversation is still loading. Try again in a moment.");return{root:t,generation:i,client:this.#r()}}#he(t,i){if(!ei(i).reload)return;const a=this.#s?.root===t?this.#s.client:void 0;this.#c.delete(t),a&&this.#je(a,t)}async rewindConversation({beforeTurnId:t,requestId:i}){const{root:a,generation:l,client:u}=this.#fe();try{const d=await u.request("session.rewind",{sessionId:a,requestId:i,ifGeneration:l,beforeTurnId:t},{timeoutMs:this.#n.createTimeoutMs});return this.#Ae(d.session),this.#Be(a,d.generation),this.refreshSessions({quiet:!0}),d}catch(d){throw this.#he(a,d),d}}async forkConversation({requestId:t,boundary:i,branchId:a,workspaceId:l,directory:u,title:d}){const{root:h,generation:m,client:p}=this.#fe();let x;try{x=await p.request("session.fork",{sessionId:h,requestId:t,ifGeneration:m,...i?{boundary:i}:{},...a?{branchId:a}:{},...l?{workspaceId:l}:{},...d?.trim()?{title:d.trim()}:{}},{timeoutMs:this.#n.createTimeoutMs})}catch(y){throw this.#he(h,y),y}return this.#xt(x.session,u),x}#xt(t,i){const a=t?.id;typeof a=="string"&&(i&&i!==this.#e.workspace&&this.selectWorkspace(i),this.#t(l=>({sessions:{...l.sessions,list:[t,...l.sessions.list.filter(u=>u.id!==a)]}})),this.selectSession(a),this.refreshSessions({quiet:!0}))}worktreeForkSource(){const{workspace:t,principal:i,registry:a}=this.#e;if(!t||!this.hasCapability("workspace.worktree")||!this.hasCapability("workspace.registry")||!Te(i??void 0,"workspace.manage"))return null;const l=i?.workspaceRoots?.find(u=>u.path===t)?.canonical;return a.workspaces.find(u=>!u.managedWorktree&&!u.archivedAt&&(u.directory===t||u.directory===l))??null}async forkIntoWorktree({requestId:t,worktreeKey:i=t,mappingId:a,boundary:l,branchId:u,title:d}){const h=this.worktreeForkSource();if(!h)throw new Ke("Worktrees are not available for this workspace.");const m=this.#d.get(t)??i;this.#d.set(t,m);try{let p=this.#w.get(m);if(!p){let y=this.#b.get(m);y||(y={workspaceId:h.id,mappingId:a,ifRevision:this.#e.registry.revision,requestId:`${m}:worktree`},this.#b.set(m,y));let w;try{w=await this.#r().request("workspace.worktree.create",y,{timeoutMs:this.#n.createTimeoutMs})}catch(k){throw(k?.data?.reason==="stale_revision"||Be(k).sent==="yes")&&this.#b.delete(m),k}p={id:w.workspace.id,directory:w.workspace.directory},this.#w.set(m,p),this.#b.delete(m),await this.refreshRegistry()}const x=await this.forkConversation({requestId:t,boundary:l,branchId:u,workspaceId:p.id,directory:p.directory,title:d});return this.#d.delete(t),x}catch(p){throw ei(p).retrySame||this.#d.delete(t),p}}async worktreeForkDestinations(){const t=this.worktreeForkSource();return t?this.worktreeOptions(t.id):[]}driveBlock(){const{principal:t,tree:i}=this.#e;if(!t)return"Not connected.";if(!Te(t,"session.write"))return"Your access token can view sessions but not send messages.";if(!i)return;const a=t.modes;if(a){const l=Bb(i.projection).find(u=>u.session?.mode&&!a.includes(u.session.mode));if(l)return`Your access token can only drive sessions in ${a.join(", ")} mode; this conversation runs in ${l.session?.mode}.`}}#yt(t,i){return this.#k(t,async()=>{if(!(t!==this.#i?.alp?.client||this.#e.selected!==i))try{await this.#bt(t,i)}finally{this.#V()}})}async#bt(t,i){const a=this.#_(i),l=a.projection.sessions[i],u=this.#e.sessions.list.find(y=>y.id===i);if(!(a.projection.closed[i]||l?.status==="closed"||!l&&u?.status==="closed"))return;const h=l?.projectRoot??u?.projectRoot??this.#e.workspace??"",m=Ll(this.#e.principal??void 0,h)?.path??this.#e.workspace??h,p=l?.mode??u?.mode,x={buffer:[]};a.attaching=x,this.#a=i;try{if(await t.request("session.create",{sessionId:i,spec:{cwd:m,...p?{mode:p}:{}},resume:!0,history:"skip"},{timeoutMs:this.#n.createTimeoutMs}),t!==this.#i?.alp?.client)return;if(this.#s={client:t,root:i},this.hasCapability("session.history")&&!this.#c.has(i)){const j=await t.request("session.history",{sessionId:i},{timeoutMs:this.#n.requestTimeoutMs});if(a.attaching!==x)return;a.projection=bs(i);for(const S of j.items)a.projection=zi(a.projection,bf(S,i));this.#W(a.projection),a.projection={...a.projection,cursor:j.tipCursor},this.#c.set(i,{generation:j.generation,olderCursor:j.olderCursor,hasOlder:j.hasOlder})}const y=a.projection.cursor,w=this.#c.get(i),k=await t.request("session.attach",{sessionId:i,...w?{after:y,generation:w.generation}:y>0?{after:y}:{}},{timeoutMs:this.#n.requestTimeoutMs});a.attaching===x&&(a.attaching=null,this.#ke(i,a,k,x.buffer))}catch(y){throw a.attaching===x&&(a.attaching=null),y}}async sendPrompt(t,i=this.#e.selected,a=[],l=[],{keepRefused:u=!1}={}){const d=String(t??"");if(!i||!d.trim()&&!a.length&&!l.length)return;const h=this.driveBlock();if(h)throw new Ke(h);const m=Xr([],a,this.#e.connection.promptImageLimits);if(m.error)throw new Ke(m.error);const p=l.length?this.#Ve(i,l):null;if(p&&!u)throw new Ke(p);const x=Tl(),y={id:x,rootId:i,text:d,...a.length?{images:a}:{},...l.length?{files:l.map(w=>({...w,received:0,error:void 0})),uploadKey:x}:{},delivery:this.rootBusy(i)?"steer":"auto",status:"sending",retrySameId:!0,at:Date.now()};if(this.clearAttention(i),p){this.#t(w=>({prompts:[...w.prompts,{...y,status:"failed",error:p}]})),this.#Me(y);return}this.#t(w=>({prompts:[...w.prompts,y]})),this.#Me(y),await this.#Ke(y)}fileGate(t=this.#e.selected){const{connection:i,principal:a}=this.#e,l=t?this.#o.get(t)?.projection.sessions[t]??this.#e.sessions.list.find(u=>u.id===t):void 0;return vj({capable:i.capabilities.includes("attachments"),permitted:Te(a??void 0,"attachments.write"),writable:Te(a??void 0,"session.write"),limits:i.attachmentLimits,session:l,known:!!t})}#Ve(t,i){return this.fileGate(t)??Ol([],i,this.#e.connection.attachmentLimits??Ps).error}#vt(t,i){const a=this.#wt(t,i);this.#me.set(i.id,a);const l=()=>{this.#me.get(i.id)===a&&this.#me.delete(i.id)};return a.then(l,l),a}#me=new Map;#te(t){return this.#e.prompts.some(i=>i.id===t)}async#wt(t,i){const a=i.files??[],l=i.uploadKey??i.id,u=this.#e.connection.attachmentLimits??Ps,d=(p,x)=>this.#t(y=>({prompts:y.prompts.map(w=>w.id===i.id&&w.files?{...w,files:w.files.map((k,j)=>j===p?{...k,...x}:k)}:w)})),h=$d(t),m=[...a];for(const[p,x]of a.entries())if(!x.attachmentId){if(!this.#te(i.id))throw new $r;d(p,{error:void 0,received:x.received??0,started:!0});try{const y=await h.upload({sessionId:i.rootId,name:x.name,mimeType:x.mimeType,data:x.data,requestId:Bx(l,p,x.attempt),maxChunkBytes:u.maxChunkBytes,onProgress:w=>{if(!this.#te(i.id))throw new $r;d(p,{received:w})}});if(typeof y?.attachmentId!="string")throw new Error(`The host did not answer an attachment for ${x.name}.`);m[p]={...x,attachmentId:y.attachmentId,received:x.size,error:void 0},d(p,{attachmentId:y.attachmentId,received:x.size,error:void 0})}catch(y){if(y instanceof $r||!this.#te(i.id))throw new $r;const w=Be(y);throw d(p,{error:w.message}),new oy(x.name,w,Ff(y)&&["closed","disconnected","send_failed"].includes(y.reason))}}return m}#kt(){for(const t of this.#e.prompts)t.status!=="failed"||!t.resumeUpload||t.resumeUpload>3||this.retryPrompt(t.id,{resume:!0}).catch(()=>{})}async#Ke(t){const i=t.rootId,a=this.#ne.get(i),l=(async()=>{a&&await a.catch(()=>{});const u=this.#e.prompts.find(h=>h.id===t.id);if(!u||u.status!=="sending")return;const d=this.rootBusy(i,t.id)?"steer":"auto";d!==u.delivery&&this.#t(h=>({prompts:h.prompts.map(m=>m.id===t.id?{...m,delivery:d}:m)})),await this.#Fe({...u,delivery:d})})();this.#ne.set(i,l);try{await l}finally{this.#ne.get(i)===l&&this.#ne.delete(i)}}#ne=new Map;rootBusy(t=this.#e.selected,i){if(!t)return!1;const a=this.#o.get(t);if(a&&t in a.projection.running||this.#x.has(t))return!0;for(const u of this.#O.get(t)??[]){if(u===i)continue;const d=a?.projection.prompts[u];if(!this.#F.has(u)&&(!d||d.errorCode==="outcome_unknown"))return!0}if(this.#e.prompts.some(u=>u.rootId===t&&u.id!==i&&u.status==="unknown")||this.#e.prompts.some(u=>u.rootId===t&&u.id!==i&&u.status==="sending"&&!u.accepted&&this.#ge.has(u.id)))return!0;const l=this.#K.get(t);if(!l||!a)return!1;for(const[u]of l){if(u===i)continue;const d=a.projection.prompts[u];if(!(d?.state==="failed"||!d&&!this.#F.has(u)||(!d?.turnId||!a.projection.turns[d.turnId])&&Date.now()-(this.#se.get(u)??0)>this.#Qe)&&(!d||!Hx(a.projection,u)))return!0}return!1}async configureMode(t){const i=this.#e.selected;if(!i||!t)return;const a=this.#e.principal?.modes,l=this.driveBlock()??(a&&!a.includes(t)?`Your access token can only use ${a.join(", ")} mode.`:void 0);if(l){this.#u("error",l);return}if(!this.#e.busy.mode){this.#t(u=>({busy:{...u.busy,mode:!0}}));try{const u=await this.#r().request("session.configure",{sessionId:i,mode:t},{timeoutMs:this.#n.requestTimeoutMs}),d=this.#o.get(i),h=typeof u?.session?.mode=="string"?u.session.mode:t;d&&(d.projection={...d.projection,sessions:{...d.projection.sessions,[i]:{...d.projection.sessions[i],id:i,mode:h}}},this.#L(i)),this.#t(m=>({sessions:{...m.sessions,list:m.sessions.list.map(p=>p.id===i?{...p,mode:h}:p)}}))}catch(u){this.#u("error",Be(u).message)}finally{this.#t(u=>({busy:{...u.busy,mode:!1}}))}}}liveConfigure(){const{principal:t,connection:i,busy:a}=this.#e,l=this.#e.tree?.rootId,u=l?this.#o.get(l):void 0,d=!!l&&!!u&&(this.rootBusy(l)||Object.keys(u.projection.running).length>0||Object.keys(u.projection.questions).length>0);return Gj({capabilities:i.capabilities,canWrite:Te(t??void 0,"session.write"),canTeam:Te(t??void 0,"session.team.write"),summary:l?this.#de(l):null,closed:!!l&&!!u?.projection.closed[l],busy:d,configuring:!!a.configure||!!a.mode,generation:l?this.#c.get(l)?.generation??null:null,online:i.phase==="open",driveBlock:l?this.driveBlock():void 0})}async previewConfigure(t={}){const i=this.#e.tree?.rootId;if(!i||!this.hasCapability(Gb)||!Te(this.#e.principal??void 0,"session.read"))return;const a=await this.#r().request("session.configure.preview",{sessionId:i,...t},{timeoutMs:this.#n.requestTimeoutMs});return a?.preview&&typeof a.preview=="object"?a.preview:void 0}#pe;async configureLive(t){const i=this.#e.tree?.rootId,a=Object.fromEntries(Object.entries(t).filter(([h,m])=>["model","thinking","team"].includes(h)&&typeof m=="string"&&m));if(!i||!Object.keys(a).length||this.#e.busy.configure)return;const l=this.liveConfigure(),u=a.team?l.team:a.model?l.model:l.thinking;if(!l.shown||!u.enabled){this.#u("error",u.reason??l.reason??"This change is not available now.");return}this.#t(h=>({busy:{...h.busy,configure:!0}}));const d=JSON.stringify([i,a]);try{if(a.team){const w=await this.previewConfigure(a).catch(()=>{});if(w&&!w.allowed){const k=w.reason??"runtime_unsupported";this.#u("error",Ma[k]??w.message??"The host would not take this change.",Yb.has(k)?{action:"new-session"}:void 0);return}}const{generation:h,client:m}=this.#fe(),p=this.#pe?.key===d?this.#pe.requestId:Qf();this.#pe=void 0;let x;try{x=await m.request("session.configure",{sessionId:i,...a,requestId:p,ifGeneration:h},{timeoutMs:this.#n.createTimeoutMs})}catch(w){const k=Fx(w);k.retrySame&&(this.#pe={key:d,requestId:p}),this.#he(i,w),this.#u("error",k.message,k.newSession?{action:"new-session"}:void 0);return}const y=x?.configured;if(this.#Ae(Yj(x.session,y?.effective)),this.refreshSessions({quiet:!0}),y){const w=this.#e.catalog.models.find(k=>k.id===`${y.effective.runtime}:${y.effective.model}`)?.label;this.#u("info",Vj(y,Xs,w))}return x}catch(h){this.#u("error",Fx(h).message);return}finally{this.#t(h=>({busy:{...h.busy,configure:!1}}))}}async#Fe(t){const i=a=>this.#t(l=>({prompts:l.prompts.map(u=>u.id===t.id?{...u,...a}:u)}));this.#ge.add(t.id);try{const a=this.#r();!(this.#T===t.rootId&&this.#s?.client===a&&this.#s.root===t.rootId)&&this.#e.selected===t.rootId&&await this.#yt(a,t.rootId);const u=Xr([],t.images??[],this.#e.connection.promptImageLimits);if(u.error)throw new Ke(u.error);let d=t.files??[];if(d.length){const p=this.#Ve(t.rootId,d);if(p)throw new Ke(p);if(d=await this.#vt(a,t),!this.#te(t.id))return}if(!this.#te(t.id))return;i({submitted:!0});let h=this.#O.get(t.rootId);h||this.#O.set(t.rootId,h=new Set),h.add(t.id);const m=await a.request("session.prompt",{sessionId:t.rootId,clientMessageId:t.id,delivery:t.delivery,content:Aj(t.text,t.images,d)},{timeoutMs:this.#n.requestTimeoutMs});if(m?.outcome==="unknown"){i({status:"unknown",error:"The host cannot tell whether the agent took the message.",retrySameId:!1});return}if(m?.outcome==="failed"){this.#_e(t.rootId,t.id),i({status:"failed",error:m.error?.message?`The agent did not take the message: ${m.error.message}`:"The agent did not take the message.",retrySameId:!1});return}this.#F.add(t.id),this.#Nt(),this.#Xe(t)?this.#Ce(t.id):i({accepted:!0})}catch(a){if(this.#Xe(t))return this.#Ce(t.id);if(a instanceof $r)return;if(a instanceof oy){const u=a.dropped,d=this.#e.prompts.find(h=>h.id===t.id)?.resumeUpload??0;i({status:"failed",error:`Could not upload ${a.fileName}: ${a.failure.message}${u?" The upload continues when the connection is back.":""}`,retrySameId:!0,resumeUpload:u?d+1:0});return}const l=Be(a);t.files?.length&&(l.reason==="attachment_unavailable"||l.code===1001)&&await this.#jt(t,a),l.sent==="no"?i({status:"failed",error:l.message,retrySameId:!0}):l.sent==="yes"&&l.reason!=="outcome_unknown"?i({status:"failed",error:l.message,retrySameId:!1}):i({status:"unknown",error:l.message,retrySameId:l.reason!=="outcome_unknown"})}finally{this.#ge.delete(t.id),this.#e.prompts.find(l=>l.id===t.id)?.status==="failed"?this.#_e(t.rootId,t.id):this.#A(t.rootId)}}async#jt(t,i){const a=i?.data,u=(this.#e.prompts.find(h=>h.id===t.id)?.files??[]).filter(h=>typeof h.attachmentId=="string");let d;if(a?.reason==="attachment_unavailable"){const h=u.filter(m=>m.attachmentId===a?.attachmentId);d=new Set((h.length?h:u).map(m=>m.attachmentId))}else{let h;try{h=$d(this.#r())}catch{return}const m=await Promise.all(u.map(p=>h.get(p.attachmentId).then(()=>!1,x=>Be(x).code===1001)));d=new Set(u.filter((p,x)=>m[x]).map(p=>p.attachmentId))}d.size&&this.#t(h=>({prompts:h.prompts.map(m=>m.id===t.id&&m.files?{...m,files:m.files.map(p=>p.attachmentId&&d.has(p.attachmentId)?{...p,attachmentId:void 0,received:0,started:!1,attempt:(p.attempt??0)+1}:p)}:m)}))}#ge=new Set;#Xe(t){const i=this.#o.get(t.rootId);return!!i&&Ix(i.projection).has(t.id)}#Ce(t){this.#t(i=>({prompts:i.prompts.filter(a=>a.id!==t)}))}async retryPrompt(t,{resume:i=!1}={}){const a=this.#e.prompts.find(d=>d.id===t);if(!a||a.status==="sending")return;const l=i?a.resumeUpload:0,u=a.retrySameId?{...a,status:"sending",error:void 0,accepted:!1,resumeUpload:l}:{...a,id:Tl(),delivery:this.rootBusy(a.rootId,a.id)?"steer":"auto",status:"sending",error:void 0,retrySameId:!0,accepted:!1,resumeUpload:l,...a.files?.length?{uploadKey:a.uploadKey??a.id}:{}};if(this.#t(d=>({prompts:d.prompts.map(h=>h.id===t?u:h)})),u.id===a.id)return this.#Fe(u);this.#Pe(a.rootId,a.id),this.#Me(u),await this.#Ke(u)}#Pe(t,i){this.#K.get(t)?.delete(i),this.#se.delete(i),this.#F.delete(i)}discardPrompt(t){const i=this.#e.prompts.find(a=>a.id===t);i&&this.#Pe(i.rootId,t),this.#Ce(t),i&&this.#St(i)}#St(t){const i=(t.files??[]).map((u,d)=>({file:u,slot:d})).filter(({file:u})=>u.started&&!u.attachmentId);if(!i.length)return;const a=t.uploadKey??t.id,l=this.#me.get(t.id)??Promise.resolve();this.#Ee=this.#Ee.then(()=>l.catch(()=>{})).then(async()=>{let u;try{u=this.#r()}catch{return}const d=$d(u);for(const{file:h,slot:m}of i)await Tj(d,{sessionId:t.rootId,file:h,requestId:Bx(a,m,h.attempt),digest:vb})})}#Ee=Promise.resolve();abandonedUploads(){return this.#Ee}#K=new Map;#Me(t){let i=this.#K.get(t.rootId);i||this.#K.set(t.rootId,i=new Map),i.set(t.id,this.#o.get(t.rootId)?.projection.reset??0),this.#se.set(t.id,Date.now())}#se=new Map;#F=new Set;#$;get#Qe(){return this.#n.busyUnseenMs}#Nt(){this.#$!==void 0&&clearTimeout(this.#$),this.#$=setTimeout(()=>{this.#$=void 0,this.#i&&this.#t(t=>({busy:{...t.busy}}))},this.#Qe+100)}#We(t,i){const a=this.#K.get(t);if(!a)return!0;for(const[l,u]of a){const d=i.historyUnavailable&&i.reset>u&&Object.keys(i.running).length===0;(Hx(i,l)||d)&&(a.delete(l),this.#se.delete(l),this.#F.delete(l))}return a.size===0}queuePrompt(t){const i=this.#e.selected,a=String(t??"");if(!i||!a.trim())return;const l=this.driveBlock();if(l)throw new Ke(l);this.#t(u=>({queued:[...u.queued,{id:Tl(),rootId:i,text:a}]}))}interruptAndSend(t){const i=this.#e.selected,a=String(t??"");if(!i||!a.trim())return;const l=this.driveBlock();if(l)throw new Ke(l);this.#t(u=>({queued:[{id:Tl(),rootId:i,text:a},...u.queued]})),this.interrupt()}editQueued(t){const i=this.#e.queued.find(a=>a.id===t);return i?(this.#t(a=>({queued:a.queued.filter(l=>l.id!==t)})),i.text):null}async sendQueuedNow(t){const i=this.#e.queued.find(a=>a.id===t);!i||i.rootId!==this.#e.selected||(this.#t(a=>({queued:a.queued.filter(l=>l.id!==t)})),await this.sendPrompt(i.text))}#ze=!1;#Tt(){this.#ze||(this.#ze=!0,queueMicrotask(()=>{this.#ze=!1,this.#At()}))}#At(){const{selected:t,tree:i,connection:a,prompts:l,queued:u}=this.#e;if(!t||a.phase!=="open"||!i||i.rootId!==t||i.status!=="attached"||t in i.projection.running||l.some(h=>h.rootId===t)||!this.#We(t,i.projection)||this.driveBlock())return;const d=u.find(h=>h.rootId===t);d&&this.sendQueuedNow(d.id).catch(()=>{})}#O=new Map;#x=new Map;async interrupt(){const t=this.#e.selected;if(!t)return;const i=this.#x.get(t);if(i)return i.attempts=0,i.exhausted=!1,i.observer?.state==="stopped"&&this.#Ze(t,i),this.#A(t),i.promise;if(!this.hasCapability("session.interrupt.turn")){this.#u("error","This host cannot safely stop a specific turn. Upgrade the host to use Stop.");return}const a=this.#o.get(t)?.projection,l=a?.running[t],u=l?void 0:[...new Set([...this.#O.get(t)??[],...this.#e.prompts.filter(x=>x.rootId===t&&x.status!=="failed").map(x=>x.id)])].find(x=>{const y=a?.prompts[x];return!y||y.state==="failed"&&y.errorCode==="outcome_unknown"||y.state==="accepted"&&(!y.turnId||a?.turns[y.turnId]!=="ended")});if(!l&&!u)return;const d=this.#e.prompts.find(x=>x.id===u);if(d&&!d.submitted){this.discardPrompt(d.id),this.#u("info","Message canceled before sending.");return}let h=()=>{};const m=new Promise(x=>{h=()=>x(void 0)}),p={...l?{turnId:l}:{messageId:u},done:h,promise:m};return this.#x.set(t,p),this.#Ze(t,p),this.#t(x=>({busy:{...x.busy,interrupt:!0}})),l||this.#u("info",sy),this.#A(t),m}#Ze(t,i){const a=this.#i,l=this.#e.principal?.id,{open:u,backoff:d,stableMs:h,requestTimeoutMs:m}=this.#n,p=this.#e.connection.gateway,x=this.#m;let y=null,w=!1;i.observed??=this.#o.get(t)?.projection??bs(t);const k=()=>this.#i===a&&this.#x.get(t)===i,j=Cx({connect:async({signal:S})=>{const A=await u({url:p,token:x,signal:S});if(!k())throw A.transport.close(),new Ke("This Stop is no longer waiting.");if(A.principal.id!==l||!Te(A.principal,"session.read")||!Te(A.principal,"session.write"))throw A.transport.close(),new Ra("Stop access changed. Reconnect with the original access before trying again.");return A.transport},onConnect:async(S,{signal:A})=>{const R=await Ax(S,ny,{signal:A,timeoutMs:m}),q=Array.isArray(R.capabilities)?R.capabilities:[];if(!q.includes("session.interrupt.turn")||!q.includes("attach.after"))throw new Ke("This host cannot safely observe and stop a specific turn.");y=[];const O=await S.request("session.attach",{sessionId:t,after:i.observed?.cursor??0},{signal:A,timeoutMs:m});k()&&(i.observed=Ux(i.observed??bs(t),O,y),i.observed={...i.observed,cursor:Math.max(i.observed.cursor,O.cursor??0)},y=null,this.#A(t))},onDisconnect:()=>{y=null},shouldRetry:S=>!Be(S).terminal&&!Ud(S),backoff:d,stableMs:h,client:{timeoutMs:m}});i.observer=j,j.onEvent(S=>{if(!(!k()||S.sessionId!==t)){if(y){y.push(S);return}i.observed=zi(i.observed??bs(t),S),this.#A(t)}}),j.onState((S,A)=>{k()&&(S==="open"?(w&&(i.attempts=0,i.exhausted=!1),w=!0,this.#A(t)):S==="stopped"&&(this.#Se(t),i.exhausted=!0,this.#e.selected===t&&this.#t(R=>({busy:{...R.busy,interrupt:!1}})),this.#u("error",`Stop is unresolved: ${Be(A).message}`)))})}#Re(t){const i=this.#x.get(t);i&&(this.#x.delete(t),this.#Se(t),clearTimeout(i.retry),i.observer?.stop(),i.done(),this.#e.notice?.text===sy&&this.#t({notice:null}),this.#e.selected===t&&this.#t(a=>({busy:{...a.busy,interrupt:!1}})))}#_e(t,i){this.#O.get(t)?.delete(i),this.#x.get(t)?.messageId===i&&(this.#u("info","The agent did not take that message. There is no turn to stop."),this.#Re(t))}#A(t){const i=this.#x.get(t);if(!i)return;const a=this.#o.get(t)?.projection,l=[i.observed,a].filter(m=>!!m).sort((m,p)=>(p?.cursor??0)-(m?.cursor??0)),u=i.messageId?l.map(m=>m?.prompts[i.messageId]).find(Boolean):void 0;if(u?.state==="failed"&&u.errorCode!=="outcome_unknown"){this.#_e(t,i.messageId);return}if(!i.turnId&&u?.state==="accepted"&&u.turnId&&(i.turnId=u.turnId),i.turnId&&l.some(m=>m?.turns[i.turnId]==="ended")){this.#Re(t);return}const d=i.observer?.state==="open"?i.observer.client:void 0,h=d??(this.#e.connection.phase==="open"?this.#i?.alp?.client:void 0);if(!(!i.turnId||i.sending||i.exhausted||i.observer?.state==="stopped"||!h)){if(!d&&!this.hasCapability("session.interrupt.turn")){i.warned||(i.warned=!0,this.#u("error","Stop is still waiting: this host cannot safely stop a specific turn."));return}clearTimeout(i.retry),i.sending=!0,i.attempts=(i.attempts??0)+1,this.#e.selected===t&&this.#t(m=>({busy:{...m.busy,interrupt:!0}})),h.request("session.interrupt",{sessionId:t,turnId:i.turnId},{timeoutMs:this.#n.requestTimeoutMs}).then(m=>{this.#x.get(t)===i&&typeof m?.interrupted=="boolean"&&this.#Re(t)},m=>{this.#x.get(t)===i&&this.#u("error",`Stop is still waiting for this turn's outcome: ${Be(m).message}`)}).finally(()=>{i.sending=!1,this.#x.get(t)===i&&((i.attempts??0)<3?i.retry=setTimeout(()=>this.#A(t),250):(i.exhausted=!0,this.#e.selected===t&&this.#t(m=>({busy:{...m.busy,interrupt:!1}})),this.#u("error","Stop is unresolved. Try Stop again to check this same turn.")))})}}async answerQuestion(t,{text:i,dismiss:a=!1}){const l=`question:${t}`;this.#t(u=>({busy:{...u.busy,[l]:!0}}));try{await this.#r().request("question.answer",a?{questionId:t,dismiss:!0,reason:"Declined in ALP web"}:{questionId:t,text:String(i??"")});const u=this.#e.selected,d=u?this.#o.get(u):void 0;if(d&&u&&d.projection.questions[t]){const h={...d.projection.questions};delete h[t],d.projection={...d.projection,questions:h},this.#L(u)}this.refreshAttention()}catch(u){const d=Be(u);this.#u("error",d.code===1001?"That question is no longer waiting for an answer.":d.message)}finally{this.#t(u=>({busy:{...u.busy,[l]:!1}}))}}setTasksVisible(t){this.#Le=Math.max(0,this.#Le+(t?1:-1));const i=this.#Le>0;this.#e.tasks.visible!==i&&(this.#t(a=>({tasks:{...a.tasks,visible:i}})),i&&this.refreshTasks())}#Le=0;tasksBlock(){const{principal:t}=this.#e;if(!t)return"Not connected.";if(!this.hasCapability("task"))return"This host does not offer tasks.";if(!Te(t,"project.read"))return"Your access token cannot read this workspace's tasks."}async refreshTasks({quiet:t=!1}={}){const i=this.#e.workspace;if(!i||this.tasksBlock())return;const a=this.#l;t||this.#t(l=>({tasks:{...l.tasks,status:l.tasks.rows.length?l.tasks.status:"loading",error:void 0}}));try{const l=await this.#r().request("task.list",{projectRoot:i});if(a!==this.#l||t&&l?.revision&&l.revision===this.#e.tasks.revision)return;const u=Array.isArray(l?.tasks)?l.tasks:[];this.#t(d=>({tasks:{...d.tasks,status:"ready",rows:u,revision:l?.revision,unreadable:Array.isArray(l?.unreadable)?l.unreadable.length:0,error:void 0,creates:this.#Ct(d.tasks.creates,u)}}))}catch(l){if(a!==this.#l)return;(!t||this.#e.tasks.status!=="ready")&&this.#t(u=>({tasks:{...u.tasks,status:"error",error:Be(l)}}))}}#Ct(t,i){return t.map(a=>{if(a.status!=="unknown")return a;const l=i.find(u=>u.title===a.title&&u.status!=="closed");return l?{...a,match:l.id}:{...a,match:void 0}})}async createTask({title:t,priority:i=2}){const a=this.#e.workspace,l=String(t??"").trim();if(!a||!l)return;const u={requestId:K2(),title:l,priority:i,status:"creating"};this.#t(d=>({tasks:{...d.tasks,creates:[...d.tasks.creates,u],message:void 0}})),await this.#Je(u)}async#Je(t){const i=this.#e.workspace,a=this.#l,l=u=>this.#t(d=>({tasks:{...d.tasks,creates:u?d.tasks.creates.map(h=>h.requestId===t.requestId?{...h,...u}:h):d.tasks.creates.filter(h=>h.requestId!==t.requestId)}}));try{const u=await this.#r().request("task.create",{projectRoot:i,title:t.title,priority:t.priority,requestId:t.requestId});if(a!==this.#l)return;l(null),this.#t(d=>({tasks:{...d.tasks,message:{level:"info",text:u?.duplicate?`Task ${u.id} already existed for this request.`:`Created task ${u?.id??""}.`}}})),await this.refreshTasks({quiet:!1})}catch(u){if(a!==this.#l)return;const d=Be(u);d.sent==="unknown"||d.code===1e3?(l({status:"unknown",error:`${d.message} The list was read again: check it before creating this task again.`}),await this.refreshTasks()):l({status:"failed",error:d.message})}}async retryTaskCreate(t){const i=this.#e.tasks.creates.find(l=>l.requestId===t);if(!i||i.status==="creating")return;const a={...i,status:"creating",error:void 0,match:void 0};this.#t(l=>({tasks:{...l.tasks,creates:l.tasks.creates.map(u=>u.requestId===t?a:u)}})),await this.#Je(a)}dismissTaskCreate(t){this.#t(i=>({tasks:{...i.tasks,creates:i.tasks.creates.filter(a=>a.requestId!==t)}}))}async changeTask(t,i){const a=this.#e.workspace;if(!a||!t?.id)return;const l=this.#l;this.#t(u=>({tasks:{...u.tasks,busy:{...u.tasks.busy,[t.id]:!0},message:void 0}}));try{const u=this.#r();"gate"in i?await u.request("task.gate.resolve",{projectRoot:a,id:t.id,gate:i.gate,channel:"web",...i.choice?{choice:i.choice}:{},...i.reject?{reject:!0}:{},ifRev:t.rev}):await u.request("task.update",{projectRoot:a,id:t.id,action:i.action,...i.action==="close"?{note:"Closed in ALP web"}:{},ifRev:t.rev})}catch(u){if(l!==this.#l)return;const d=Be(u);this.#t(h=>({tasks:{...h.tasks,message:{level:"error",text:d.sent==="unknown"?`${d.message} The list was read again.`:d.message}}}))}finally{l===this.#l&&(this.#t(u=>({tasks:{...u.tasks,busy:{...u.tasks.busy,[t.id]:!1}}})),await this.refreshTasks())}}setSendBehavior(t){this.#ie({sendBehavior:t})}setTheme(t){this.#ie({theme:t})}updatePreferences(t){this.#ie(t)}#ie(t){const i=Oi(JSON.stringify({...this.#e.preferences,...t,v:1}));this.#t({preferences:i}),sS(this.#n.storage,i)}#Et(t){this.#ie({newSession:iS(this.#e.preferences.newSession,t)})}resetPreferences(){this.#ie(Oi(null))}reloadPreferences(){const t=Wx(this.#n.storage);JSON.stringify(t)!==JSON.stringify(this.#e.preferences)&&this.#t({preferences:t})}previewBlock(){const{principal:t,workspace:i}=this.#e;if(!t)return"Not connected.";if(!Te(t,"session.read"))return"Your access token cannot read sessions, so the host cannot say what would run.";if(!i)return"Choose a workspace first."}async previewSession(t,{signal:i}={}){const a=this.previewBlock();if(a)throw new Ke(a);const l=await this.#r().request("session.preview",{spec:{...t,cwd:this.#e.workspace}},{timeoutMs:this.#n.requestTimeoutMs,...i?{signal:i}:{}}),u=Lj(l);if(!u)throw new Ke("The host answered the preview in a form this app does not read.");return u}libraryBlock(){const{principal:t,workspace:i}=this.#e;if(!t)return"Not connected.";if(!this.hasCapability("library"))return"This host does not offer its library.";if(!Te(t,"project.read"))return"Your access token cannot read this workspace's configuration.";if(!i)return"Choose a workspace first."}async listLibrary(t){const i=this.libraryBlock();if(i)throw new Ke(i);const a=await this.#r().request("library.list",{kind:t,projectRoot:this.#e.workspace},{timeoutMs:this.#n.requestTimeoutMs});return(Array.isArray(a?.entries)?a.entries:[]).filter(l=>l&&typeof l.name=="string")}async getLibraryEntry(t,i){const a=this.libraryBlock();if(a)throw new Ke(a);const l=await this.#r().request("library.get",{kind:t,name:i,projectRoot:this.#e.workspace},{timeoutMs:this.#n.requestTimeoutMs});if(!l||typeof l!="object"||!l.content||typeof l.content!="object"||Array.isArray(l.content))throw new Ke("The host answered library.get in a form this app does not read.");const u=d=>Array.isArray(d)?d.filter(h=>typeof h=="string"):[];return{kind:typeof l.kind=="string"?l.kind:t,name:typeof l.name=="string"?l.name:i,source:typeof l.source=="string"?l.source:"unknown",...typeof l.overrides=="string"?{overrides:l.overrides}:{},content:l.content,...typeof l.revision=="string"||l.revision===null?{revision:l.revision}:{},usedBy:u(l.usedBy),...Array.isArray(l.librarySkills)?{librarySkills:u(l.librarySkills)}:{},secrets:u(l.secrets)}}libraryWriteBlock(t){const i=this.libraryBlock();return i||(Te(this.#e.principal??void 0,"library.write")?this.hasCapability("library.project.write")?["agents","skills"].includes(t)?null:"Executable and administrative configuration is edited on the host.":"Update the host to support safe project instruction editing.":"This token does not grant library.write.")}async writeLibrary(t,i,a){const l=this.libraryWriteBlock(i);if(l)throw new Ke(l);return this.#r().request(`library.${t}`,{...a,kind:i,scope:"project",projectRoot:this.#e.workspace},{timeoutMs:this.#n.requestTimeoutMs})}#et(){this.#e.catalog.status==="ready"&&this.#Te(),this.#e.settings.status==="ready"&&this.loadSettings()}async refreshModels(){!this.#e.principal||!Te(this.#e.principal,"session.read")||!this.hasCapability("catalog.live")||(await this.#r().request("catalog.refresh",{},{timeoutMs:Math.max(this.#n.requestTimeoutMs??0,6e4)}),this.#et())}async loadSettings(){const t=this.#e.principal;if(!t)return;const i=this.#l;this.#t(a=>({settings:{...a.settings,status:"loading",error:void 0}}));try{const a=this.#r(),[l,u]=await Promise.all([this.hasCapability("settings.language")&&Te(t,"session.read")?a.request("settings.language.get",{}).catch(()=>{}):void 0,this.hasCapability("library")&&Te(t,"session.read")?a.request("library.models",{}).catch(()=>{}):void 0]);if(i!==this.#l)return;this.#t({settings:{status:"ready",...l&&typeof l.applies=="string"?{language:l}:{},models:Gx(u?.models)}})}catch(a){if(i!==this.#l)return;this.#t(l=>({settings:{...l.settings,status:"error",error:Be(a)}}))}}}const gS=s=>s.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Zb=(...s)=>s.filter((t,i,a)=>!!t&&t.trim()!==""&&a.indexOf(t)===i).join(" ").trim();var xS={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const yS=b.forwardRef(({color:s="currentColor",size:t=24,strokeWidth:i=2,absoluteStrokeWidth:a,className:l="",children:u,iconNode:d,...h},m)=>b.createElement("svg",{ref:m,...xS,width:t,height:t,stroke:s,strokeWidth:a?Number(i)*24/Number(t):i,className:Zb("lucide",l),...h},[...d.map(([p,x])=>b.createElement(p,x)),...Array.isArray(u)?u:[u]]));const ie=(s,t)=>{const i=b.forwardRef(({className:a,...l},u)=>b.createElement(yS,{ref:u,iconNode:t,className:Zb(`lucide-${gS(s)}`,a),...l}));return i.displayName=`${s}`,i};const ac=ie("Archive",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]);const bS=ie("ArrowDownUp",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"m21 8-4-4-4 4",key:"1c9v7m"}],["path",{d:"M17 4v16",key:"7dpous"}]]);const vS=ie("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);const wS=ie("ArrowLeftRight",[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]]);const Jb=ie("ArrowLeftToLine",[["path",{d:"M3 19V5",key:"rwsyhb"}],["path",{d:"m13 6-6 6 6 6",key:"1yhaz7"}],["path",{d:"M7 12h14",key:"uoisry"}]]);const th=ie("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const e0=ie("ArrowRightToLine",[["path",{d:"M17 12H3",key:"8awo09"}],["path",{d:"m11 18 6-6-6-6",key:"8c2y43"}],["path",{d:"M21 5v14",key:"nzette"}]]);const Dl=ie("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);const rc=ie("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);const kS=ie("Blocks",[["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["path",{d:"M10 21V8a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-5a1 1 0 0 0-1-1H3",key:"1fpvtg"}]]);const jS=ie("BookOpen",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]]);const Oa=ie("Bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]);const SS=ie("Boxes",[["path",{d:"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",key:"lc1i9w"}],["path",{d:"m7 16.5-4.74-2.85",key:"1o9zyk"}],["path",{d:"m7 16.5 5-3",key:"va8pkn"}],["path",{d:"M7 16.5v5.17",key:"jnp8gn"}],["path",{d:"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",key:"8zsnat"}],["path",{d:"m17 16.5-5-3",key:"8arw3v"}],["path",{d:"m17 16.5 4.74-2.85",key:"8rfmw"}],["path",{d:"M17 16.5v5.17",key:"k6z78m"}],["path",{d:"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",key:"1xygjf"}],["path",{d:"M12 8 7.26 5.15",key:"1vbdud"}],["path",{d:"m12 8 4.74-2.85",key:"3rx089"}],["path",{d:"M12 13.5V8",key:"1io7kd"}]]);const Pr=ie("Brain",[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z",key:"ep3f8r"}],["path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4",key:"1p4c4q"}],["path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375",key:"tmeiqw"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M19.938 10.5a4 4 0 0 1 .585.396",key:"1qfode"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M19.967 17.484A4 4 0 0 1 18 18",key:"159ez6"}]]);const NS=ie("CheckCheck",[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]);const oc=ie("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);const Qn=ie("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);const nh=ie("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);const Jn=ie("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);const si=ie("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);const lc=ie("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const t0=ie("CircleDashed",[["path",{d:"M10.1 2.182a10 10 0 0 1 3.8 0",key:"5ilxe3"}],["path",{d:"M13.9 21.818a10 10 0 0 1-3.8 0",key:"11zvb9"}],["path",{d:"M17.609 3.721a10 10 0 0 1 2.69 2.7",key:"1iw5b2"}],["path",{d:"M2.182 13.9a10 10 0 0 1 0-3.8",key:"c0bmvh"}],["path",{d:"M20.279 17.609a10 10 0 0 1-2.7 2.69",key:"1ruxm7"}],["path",{d:"M21.818 10.1a10 10 0 0 1 0 3.8",key:"qkgqxc"}],["path",{d:"M3.721 6.391a10 10 0 0 1 2.7-2.69",key:"1mcia2"}],["path",{d:"M6.391 20.279a10 10 0 0 1-2.69-2.7",key:"1fvljs"}]]);const n0=ie("CircleDot",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}]]);const TS=ie("CircleGauge",[["path",{d:"M15.6 2.7a10 10 0 1 0 5.7 5.7",key:"1e0p6d"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M13.4 10.6 19 5",key:"1kr7tw"}]]);const AS=ie("CircleHelp",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const s0=ie("CircleSlash",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"9",x2:"15",y1:"15",y2:"9",key:"1dfufj"}]]);const CS=ie("Circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);const ES=ie("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);const MS=ie("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);const i0=ie("Columns2",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]]);const zS=ie("Columns3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);const a0=ie("CopyX",[["line",{x1:"12",x2:"18",y1:"12",y2:"18",key:"1rg63v"}],["line",{x1:"12",x2:"18",y1:"18",y2:"12",key:"ebkxgr"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);const ws=ie("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);const jf=ie("Cpu",[["rect",{width:"16",height:"16",x:"4",y:"4",rx:"2",key:"14l7u7"}],["rect",{width:"6",height:"6",x:"9",y:"9",rx:"1",key:"5aljv4"}],["path",{d:"M15 2v2",key:"13l42r"}],["path",{d:"M15 20v2",key:"15mkzm"}],["path",{d:"M2 15h2",key:"1gxd5l"}],["path",{d:"M2 9h2",key:"1bbxkp"}],["path",{d:"M20 15h2",key:"19e6y8"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M9 2v2",key:"165o2o"}],["path",{d:"M9 20v2",key:"i2bqo8"}]]);const RS=ie("Crosshair",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]]);const _S=ie("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);const sh=ie("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);const LS=ie("EyeOff",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);const lo=ie("Eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const OS=ie("FileCode",[["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z",key:"1mlx9k"}]]);const Sf=ie("FileDiff",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M9 10h6",key:"9gxzsh"}],["path",{d:"M12 13V7",key:"h0r20n"}],["path",{d:"M9 17h6",key:"r8uit2"}]]);const ih=ie("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);const r0=ie("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);const ah=ie("Files",[["path",{d:"M20 7h-3a2 2 0 0 1-2-2V2",key:"x099mo"}],["path",{d:"M9 18a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h7l4 4v10a2 2 0 0 1-2 2Z",key:"18t6ie"}],["path",{d:"M3 7.6v12.8A1.6 1.6 0 0 0 4.6 22h9.8",key:"1nja0z"}]]);const DS=ie("FolderCog",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["path",{d:"M10.3 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v3.3",key:"1k8050"}],["path",{d:"m21.7 19.4-.9-.3",key:"1qgwi9"}],["path",{d:"m15.2 16.9-.9-.3",key:"1t7mvx"}],["path",{d:"m16.6 21.7.3-.9",key:"1j67ps"}],["path",{d:"m19.1 15.2.3-.9",key:"18r7jp"}],["path",{d:"m19.6 21.7-.4-1",key:"z2vh2"}],["path",{d:"m16.8 15.3-.4-1",key:"1ei7r6"}],["path",{d:"m14.3 19.6 1-.4",key:"11sv9r"}],["path",{d:"m20.7 16.8 1-.4",key:"19m87a"}]]);const ly=ie("FolderGit2",[["path",{d:"M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5",key:"1w6njk"}],["circle",{cx:"13",cy:"12",r:"2",key:"1j92g6"}],["path",{d:"M18 19c-2.8 0-5-2.2-5-5v8",key:"pkpw2h"}],["circle",{cx:"20",cy:"19",r:"2",key:"1obnsp"}]]);const qS=ie("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);const cy=ie("FolderPlus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);const Da=ie("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);const BS=ie("Gauge",[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]]);const Qs=ie("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);const $S=ie("GitCompareArrows",[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]);const o0=ie("GitFork",[["circle",{cx:"12",cy:"18",r:"3",key:"1mpf1b"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9",key:"1uq4wg"}],["path",{d:"M12 12v3",key:"158kv8"}]]);const l0=ie("Hand",[["path",{d:"M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2",key:"1fvzgz"}],["path",{d:"M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2",key:"1kc0my"}],["path",{d:"M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8",key:"10h0bg"}],["path",{d:"M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15",key:"1s1gnw"}]]);const cc=ie("History",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]);const US=ie("Image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]);const rh=ie("Info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]);const HS=ie("KeyRound",[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]]);const IS=ie("Keyboard",[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]]);const oh=ie("ListChecks",[["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);const Bi=ie("ListTodo",[["rect",{x:"3",y:"5",width:"6",height:"6",rx:"1",key:"1defrl"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);const GS=ie("ListTree",[["path",{d:"M21 12h-8",key:"1bmf0i"}],["path",{d:"M21 6H8",key:"1pqkrb"}],["path",{d:"M21 18h-8",key:"1tm79t"}],["path",{d:"M3 6v4c0 1.1.9 2 2 2h3",key:"1ywdgy"}],["path",{d:"M3 10v6c0 1.1.9 2 2 2h3",key:"2wc746"}]]);const YS=ie("List",[["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 18h.01",key:"1tta3j"}],["path",{d:"M3 6h.01",key:"1rqtza"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 18h13",key:"1lx6n3"}],["path",{d:"M8 6h13",key:"ik3vkj"}]]);const uc=ie("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);const qa=ie("Lock",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]);const VS=ie("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);const KS=ie("Maximize",[["path",{d:"M8 3H5a2 2 0 0 0-2 2v3",key:"1dcmit"}],["path",{d:"M21 8V5a2 2 0 0 0-2-2h-3",key:"1e4gt3"}],["path",{d:"M3 16v3a2 2 0 0 0 2 2h3",key:"wsl5sc"}],["path",{d:"M16 21h3a2 2 0 0 0 2-2v-3",key:"18trek"}]]);const uy=ie("MessageSquarePlus",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M12 7v6",key:"lw1j43"}],["path",{d:"M9 10h6",key:"9gxzsh"}]]);const FS=ie("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);const XS=ie("Mic",[["path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z",key:"131961"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);const PS=ie("Minimize",[["path",{d:"M8 3v3a2 2 0 0 1-2 2H3",key:"hohbtr"}],["path",{d:"M21 8h-3a2 2 0 0 1-2-2V3",key:"5jw1f3"}],["path",{d:"M3 16h3a2 2 0 0 1 2 2v3",key:"198tvr"}],["path",{d:"M16 21v-3a2 2 0 0 1 2-2h3",key:"ph8mxp"}]]);const c0=ie("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);const QS=ie("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);const WS=ie("PanelBottom",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 15h18",key:"5xshup"}]]);const $a=ie("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);const lh=ie("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);const ZS=ie("PanelTop",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}]]);const Ui=ie("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);const JS=ie("PinOff",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]);const u0=ie("Pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);const eN=ie("PlugZap",[["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m18 3-4 4h6l-4 4",key:"16psg9"}]]);const tN=ie("Plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]]);const ks=ie("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);const co=ie("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);const uo=ie("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);const nN=ie("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]);const d0=ie("Rows2",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 12h18",key:"1i2n21"}]]);const sN=ie("Scissors",[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]);const ti=ie("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);const Qr=ie("Server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]);const iN=ie("Settings2",[["path",{d:"M20 7h-9",key:"3s1dr2"}],["path",{d:"M14 17H5",key:"gfn3mx"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]);const ch=ie("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);const f0=ie("ShieldAlert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);const dc=ie("ShieldCheck",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const aN=ie("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]);const rN=ie("Shrink",[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]]);const oN=ie("Smartphone",[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]]);const lN=ie("Space",[["path",{d:"M22 17v1c0 .5-.5 1-1 1H3c-.5 0-1-.5-1-1v-1",key:"lt2kga"}]]);const cN=ie("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);const fc=ie("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);const hc=ie("SquareTerminal",[["path",{d:"m7 11 2-2-2-2",key:"1lz0vl"}],["path",{d:"M11 13h4",key:"1p7l4v"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}]]);const uN=ie("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);const dN=ie("Stethoscope",[["path",{d:"M11 2v2",key:"1539x4"}],["path",{d:"M5 2v2",key:"1yf1q8"}],["path",{d:"M5 3H4a2 2 0 0 0-2 2v4a6 6 0 0 0 12 0V5a2 2 0 0 0-2-2h-1",key:"rb5t3r"}],["path",{d:"M8 15a6 6 0 0 0 12 0v-3",key:"x18d4x"}],["circle",{cx:"20",cy:"10",r:"2",key:"ts1r5v"}]]);const h0=ie("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);const uh=ie("Target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);const fN=ie("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);const m0=ie("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);const hN=ie("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);const p0=ie("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]);const Yl=ie("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);const mN=ie("Webhook",[["path",{d:"M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2",key:"q3hayz"}],["path",{d:"m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06",key:"1go1hn"}],["path",{d:"m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8",key:"qlwsc0"}]]);const pN=ie("WifiOff",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);const g0=ie("Wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",key:"cbrjhi"}]]);const en=ie("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);var gN=Object.defineProperty,dh=(s,t)=>gN(s,"name",{value:t,configurable:!0});function Nf(s,t){if(typeof s=="function")return s(t);s!=null&&(s.current=t)}dh(Nf,"setRef");function x0(...s){return t=>{let i=!1;const a=s.map(l=>{const u=Nf(l,t);return!i&&typeof u=="function"&&(i=!0),u});if(i)return()=>{for(let l=0;l<a.length;l++){const u=a[l];typeof u=="function"?u():Nf(s[l],null)}}}}dh(x0,"composeRefs");function y0(...s){return b.useCallback(x0(...s),s)}dh(y0,"useComposedRefs");var xN=Object.defineProperty,wn=(s,t)=>xN(s,"name",{value:t,configurable:!0});function b0(s){const t=b.forwardRef((i,a)=>{let{children:l,...u}=i,d=null,h=!1;const m=[];l=N0(l),b.Children.forEach(l,w=>{if(j0(w)){h=!0;const k=w;let j="child"in k.props?k.props.child:k.props.children;for(;fh(j)&&typeof Vl=="function";)j=Vl(j._payload);d=vN(k,j),m.push(d?.props?.children)}else m.push(w)}),d?d=b.cloneElement(d,void 0,m):!h&&b.Children.count(l)===1&&b.isValidElement(l)&&(d=l);const p=d?k0(d):void 0,x=y0(a,p);if(!d){if(l||l===0)throw new Error(h?jN(s):kN(s));return l}const y=w0(u,d.props??{});return d.type!==b.Fragment&&(y.ref=a?x:p),b.cloneElement(d,y)});return t.displayName=`${s}.Slot`,t}wn(b0,"createSlot");var yN=b0("Slot"),v0=Symbol.for("radix.slottable");function bN(s){const t=wn(i=>"child"in i?i.children(i.child):i.children,"Slottable");return t.displayName=`${s}.Slottable`,t.__radixId=v0,t}wn(bN,"createSlottable");var vN=wn((s,t)=>"child"in s.props?b.isValidElement(t)?b.cloneElement(t,void 0,s.props.children(t.props.children)):null:b.isValidElement(t)?t:null,"getSlottableElementFromSlottable");function w0(s,t){const i={...t};for(const a in t){const l=s[a],u=t[a];/^on[A-Z]/.test(a)?l&&u?i[a]=(...h)=>{const m=u(...h);return l(...h),m}:l&&(i[a]=l):a==="style"?i[a]={...l,...u}:a==="className"?i[a]=[l,u].filter(Boolean).join(" "):a==="aria-describedby"&&(i[a]=T0(u,l))}return{...s,...i}}wn(w0,"mergeProps");function k0(s){let t=Object.getOwnPropertyDescriptor(s.props,"ref")?.get,i=t&&"isReactWarning"in t&&t.isReactWarning;return i?s.ref:(t=Object.getOwnPropertyDescriptor(s,"ref")?.get,i=t&&"isReactWarning"in t&&t.isReactWarning,i?s.props.ref:s.props.ref||s.ref)}wn(k0,"getElementRef");function j0(s){return b.isValidElement(s)&&typeof s.type=="function"&&"__radixId"in s.type&&s.type.__radixId===v0}wn(j0,"isSlottable");var wN=Symbol.for("react.lazy");function fh(s){return s!=null&&typeof s=="object"&&"$$typeof"in s&&s.$$typeof===wN&&"_payload"in s&&S0(s._payload)}wn(fh,"isLazyComponent");function S0(s){return typeof s=="object"&&s!==null&&"then"in s}wn(S0,"isPromiseLike");function N0(s){let t=s;for(;fh(t)&&typeof Vl=="function";)t=Vl(t._payload);return t}wn(N0,"useUnwrappedLazy");function T0(...s){const t=new Set;for(const i of s)if(typeof i=="string")for(const a of String(i).trim().split(/\s+/))a&&t.add(a);return t.size>0?Array.from(t).join(" "):void 0}wn(T0,"concatAriaDescribedby");var kN=wn(s=>`${s} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),jN=wn(s=>`${s} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Vl=Uk[" use ".trim().toString()];function A0(s){var t,i,a="";if(typeof s=="string"||typeof s=="number")a+=s;else if(typeof s=="object")if(Array.isArray(s)){var l=s.length;for(t=0;t<l;t++)s[t]&&(i=A0(s[t]))&&(a&&(a+=" "),a+=i)}else for(i in s)s[i]&&(a&&(a+=" "),a+=i);return a}function C0(){for(var s,t,i=0,a="",l=arguments.length;i<l;i++)(s=arguments[i])&&(t=A0(s))&&(a&&(a+=" "),a+=t);return a}const dy=s=>typeof s=="boolean"?`${s}`:s===0?"0":s,fy=C0,SN=(s,t)=>i=>{var a;if(t?.variants==null)return fy(s,i?.class,i?.className);const{variants:l,defaultVariants:u}=t,d=Object.keys(l).map(p=>{const x=i?.[p],y=u?.[p];if(x===null)return null;const w=dy(x)||dy(y);return l[p][w]}),h=i&&Object.entries(i).reduce((p,x)=>{let[y,w]=x;return w===void 0||(p[y]=w),p},{}),m=t==null||(a=t.compoundVariants)===null||a===void 0?void 0:a.reduce((p,x)=>{let{class:y,className:w,...k}=x;return Object.entries(k).every(j=>{let[S,A]=j;return Array.isArray(A)?A.includes({...u,...h}[S]):{...u,...h}[S]===A})?[...p,y,w]:p},[]);return fy(s,d,m,i?.class,i?.className)},NN=(s,t)=>{const i=new Array(s.length+t.length);for(let a=0;a<s.length;a++)i[a]=s[a];for(let a=0;a<t.length;a++)i[s.length+a]=t[a];return i},TN=(s,t)=>({classGroupId:s,validator:t}),E0=(s=new Map,t=null,i)=>({nextPart:s,validators:t,classGroupId:i}),Kl="-",hy=[],AN="arbitrary..",CN=s=>{const t=MN(s),{conflictingClassGroups:i,conflictingClassGroupModifiers:a}=s;return{getClassGroupId:d=>{if(d.startsWith("[")&&d.endsWith("]"))return EN(d);const h=d.split(Kl),m=h[0]===""&&h.length>1?1:0;return M0(h,m,t)},getConflictingClassGroupIds:(d,h)=>{if(h){const m=a[d],p=i[d];return m?p?NN(p,m):m:p||hy}return i[d]||hy}}},M0=(s,t,i)=>{if(s.length-t===0)return i.classGroupId;const l=s[t],u=i.nextPart.get(l);if(u){const p=M0(s,t+1,u);if(p)return p}const d=i.validators;if(d===null)return;const h=t===0?s.join(Kl):s.slice(t).join(Kl),m=d.length;for(let p=0;p<m;p++){const x=d[p];if(x.validator(h))return x.classGroupId}},EN=s=>s.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const t=s.slice(1,-1),i=t.indexOf(":"),a=t.slice(0,i);return a?AN+a:void 0})(),MN=s=>{const{theme:t,classGroups:i}=s;return zN(i,t)},zN=(s,t)=>{const i=E0();for(const a in s){const l=s[a];hh(l,i,a,t)}return i},hh=(s,t,i,a)=>{const l=s.length;for(let u=0;u<l;u++){const d=s[u];RN(d,t,i,a)}},RN=(s,t,i,a)=>{if(typeof s=="string"){_N(s,t,i);return}if(typeof s=="function"){LN(s,t,i,a);return}ON(s,t,i,a)},_N=(s,t,i)=>{const a=s===""?t:z0(t,s);a.classGroupId=i},LN=(s,t,i,a)=>{if(DN(s)){hh(s(a),t,i,a);return}t.validators===null&&(t.validators=[]),t.validators.push(TN(i,s))},ON=(s,t,i,a)=>{const l=Object.entries(s),u=l.length;for(let d=0;d<u;d++){const[h,m]=l[d];hh(m,z0(t,h),i,a)}},z0=(s,t)=>{let i=s;const a=t.split(Kl),l=a.length;for(let u=0;u<l;u++){const d=a[u];let h=i.nextPart.get(d);h||(h=E0(),i.nextPart.set(d,h)),i=h}return i},DN=s=>"isThemeGetter"in s&&s.isThemeGetter===!0,qN=s=>{if(s<1)return{get:()=>{},set:()=>{}};let t=0,i=Object.create(null),a=Object.create(null);const l=(u,d)=>{i[u]=d,t++,t>s&&(t=0,a=i,i=Object.create(null))};return{get(u){let d=i[u];if(d!==void 0)return d;if((d=a[u])!==void 0)return l(u,d),d},set(u,d){u in i?i[u]=d:l(u,d)}}},Tf="!",my=":",BN=[],py=(s,t,i,a,l)=>({modifiers:s,hasImportantModifier:t,baseClassName:i,maybePostfixModifierPosition:a,isExternal:l}),$N=s=>{const{prefix:t,experimentalParseClassName:i}=s;let a=l=>{const u=[];let d=0,h=0,m=0,p;const x=l.length;for(let S=0;S<x;S++){const A=l[S];if(d===0&&h===0){if(A===my){u.push(l.slice(m,S)),m=S+1;continue}if(A==="/"){p=S;continue}}A==="["?d++:A==="]"?d--:A==="("?h++:A===")"&&h--}const y=u.length===0?l:l.slice(m);let w=y,k=!1;y.endsWith(Tf)?(w=y.slice(0,-1),k=!0):y.startsWith(Tf)&&(w=y.slice(1),k=!0);const j=p&&p>m?p-m:void 0;return py(u,k,w,j)};if(t){const l=t+my,u=a;a=d=>d.startsWith(l)?u(d.slice(l.length)):py(BN,!1,d,void 0,!0)}if(i){const l=a;a=u=>i({className:u,parseClassName:l})}return a},UN=s=>{const t=new Map;return s.orderSensitiveModifiers.forEach((i,a)=>{t.set(i,1e6+a)}),i=>{const a=[];let l=[];for(let u=0;u<i.length;u++){const d=i[u],h=d[0]==="[",m=t.has(d);h||m?(l.length>0&&(l.sort(),a.push(...l),l=[]),a.push(d)):l.push(d)}return l.length>0&&(l.sort(),a.push(...l)),a}},HN=s=>({cache:qN(s.cacheSize),parseClassName:$N(s),sortModifiers:UN(s),postfixLookupClassGroupIds:IN(s),...CN(s)}),IN=s=>{const t=Object.create(null),i=s.postfixLookupClassGroups;if(i)for(let a=0;a<i.length;a++)t[i[a]]=!0;return t},GN=/\s+/,YN=(s,t)=>{const{parseClassName:i,getClassGroupId:a,getConflictingClassGroupIds:l,sortModifiers:u,postfixLookupClassGroupIds:d}=t,h=[],m=s.trim().split(GN);let p="";for(let x=m.length-1;x>=0;x-=1){const y=m[x],{isExternal:w,modifiers:k,hasImportantModifier:j,baseClassName:S,maybePostfixModifierPosition:A}=i(y);if(w){p=y+(p.length>0?" "+p:p);continue}let R=!!A,q;if(R){const Q=S.substring(0,A);q=a(Q);const C=q&&d[q]?a(S):void 0;C&&C!==q&&(q=C,R=!1)}else q=a(S);if(!q){if(!R){p=y+(p.length>0?" "+p:p);continue}if(q=a(S),!q){p=y+(p.length>0?" "+p:p);continue}R=!1}const O=k.length===0?"":k.length===1?k[0]:u(k).join(":"),L=j?O+Tf:O,B=L+q;if(h.indexOf(B)>-1)continue;h.push(B);const _=l(q,R);for(let Q=0;Q<_.length;++Q){const C=_[Q];h.push(L+C)}p=y+(p.length>0?" "+p:p)}return p},VN=(...s)=>{let t=0,i,a,l="";for(;t<s.length;)(i=s[t++])&&(a=R0(i))&&(l&&(l+=" "),l+=a);return l},R0=s=>{if(typeof s=="string")return s;let t,i="";for(let a=0;a<s.length;a++)s[a]&&(t=R0(s[a]))&&(i&&(i+=" "),i+=t);return i},KN=(s,...t)=>{let i,a,l,u;const d=m=>{const p=t.reduce((x,y)=>y(x),s());return i=HN(p),a=i.cache.get,l=i.cache.set,u=h,h(m)},h=m=>{const p=a(m);if(p)return p;const x=YN(m,i);return l(m,x),x};return u=d,(...m)=>u(VN(...m))},FN=[],Ot=s=>{const t=i=>i[s]||FN;return t.isThemeGetter=!0,t.themeKey=s,t},_0=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,L0=/^\((?:(\w[\w-]*):)?(.+)\)$/i,XN=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,PN=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,QN=/\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$/,WN=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix|color|light-dark)\(.+\)$/,ZN=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,JN=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Ks=s=>XN.test(s),Ye=s=>!!s&&!Number.isNaN(Number(s)),Pn=s=>!!s&&Number.isInteger(Number(s)),Qd=s=>s.endsWith("%")&&Ye(s.slice(0,-1)),ps=s=>PN.test(s),O0=()=>!0,e3=s=>QN.test(s)&&!WN.test(s),mh=()=>!1,t3=s=>ZN.test(s),n3=s=>JN.test(s),s3=s=>!ke(s)&&!je(s),i3=s=>s.startsWith("@container")&&(s[10]==="/"&&s[11]!==void 0||s[11]==="s"&&s[16]!==void 0&&s.startsWith("-size/",10)||s[11]==="n"&&s[18]!==void 0&&s.startsWith("-normal/",10)),a3=s=>ii(s,B0,mh),ke=s=>_0.test(s),Si=s=>ii(s,$0,e3),gy=s=>ii(s,h3,Ye),r3=s=>ii(s,H0,O0),o3=s=>ii(s,U0,mh),xy=s=>ii(s,D0,mh),l3=s=>ii(s,q0,n3),Cl=s=>ii(s,I0,t3),je=s=>L0.test(s),Ur=s=>Hi(s,$0),c3=s=>Hi(s,U0),yy=s=>Hi(s,D0),u3=s=>Hi(s,B0),d3=s=>Hi(s,q0),El=s=>Hi(s,I0,!0),f3=s=>Hi(s,H0,!0),ii=(s,t,i)=>{const a=_0.exec(s);return a?a[1]?t(a[1]):i(a[2]):!1},Hi=(s,t,i=!1)=>{const a=L0.exec(s);return a?a[1]?t(a[1]):i:!1},D0=s=>s==="position"||s==="percentage",q0=s=>s==="image"||s==="url",B0=s=>s==="length"||s==="size"||s==="bg-size",$0=s=>s==="length",h3=s=>s==="number",U0=s=>s==="family-name",H0=s=>s==="number"||s==="weight",I0=s=>s==="shadow",m3=()=>{const s=Ot("color"),t=Ot("font"),i=Ot("text"),a=Ot("font-weight"),l=Ot("tracking"),u=Ot("leading"),d=Ot("breakpoint"),h=Ot("container"),m=Ot("spacing"),p=Ot("radius"),x=Ot("shadow"),y=Ot("inset-shadow"),w=Ot("text-shadow"),k=Ot("drop-shadow"),j=Ot("blur"),S=Ot("perspective"),A=Ot("aspect"),R=Ot("ease"),q=Ot("animate"),O=()=>["auto","avoid","all","avoid-page","page","left","right","column"],L=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],B=()=>[...L(),je,ke],_=()=>["auto","hidden","clip","visible","scroll"],Q=()=>["auto","contain","none"],C=()=>[je,ke,m],Y=()=>[Ks,"full","auto",...C()],H=()=>[Pn,"none","subgrid",je,ke],fe=()=>["auto",{span:["full",Pn,je,ke]},Pn,je,ke],ee=()=>[Pn,"auto",je,ke],xe=()=>["auto","min","max","fr",je,ke],re=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],de=()=>["start","end","center","stretch","center-safe","end-safe"],U=()=>["auto",...C()],Z=()=>[Ks,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...C()],oe=()=>[h,Ks,"screen","full","dvw","lvw","svw","min","max","fit",...C()],ge=()=>[Ks,"screen","full","lh","dvh","lvh","svh","min","max","fit",...C()],T=()=>[s,je,ke],z=()=>[...L(),yy,xy,{position:[je,ke]}],F=()=>["no-repeat",{repeat:["","x","y","space","round"]}],J=()=>["auto","cover","contain",u3,a3,{size:[je,ke]}],le=()=>[Qd,Ur,Si],ne=()=>["","none","full",p,je,ke],ce=()=>["",Ye,Ur,Si],ve=()=>["solid","dashed","dotted","double"],Re=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],Me=()=>[Ye,Qd,yy,xy],Qe=()=>["","none",j,je,ke],Ue=()=>["none",Ye,je,ke],et=()=>["none",Ye,je,ke],Fe=()=>[Ye,je,ke],be=()=>[Ks,"full",...C()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[ps],breakpoint:[ps],color:[O0],container:[ps],"drop-shadow":[ps],ease:["in","out","in-out"],font:[s3],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[ps],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[ps],shadow:[ps],spacing:["px",Ye],text:[ps],"text-shadow":[ps],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",Ks,ke,je,A]}],container:["container"],"container-type":[{"@container":["","normal","size",je,ke]}],"container-named":[i3],columns:[{columns:[Ye,"auto",ke,je,h]}],"break-after":[{"break-after":O()}],"break-before":[{"break-before":O()}],"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:B()}],overflow:[{overflow:_()}],"overflow-x":[{"overflow-x":_()}],"overflow-y":[{"overflow-y":_()}],overscroll:[{overscroll:Q()}],"overscroll-x":[{"overscroll-x":Q()}],"overscroll-y":[{"overscroll-y":Q()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:Y()}],"inset-x":[{"inset-x":Y()}],"inset-y":[{"inset-y":Y()}],start:[{"inset-s":Y(),start:Y()}],end:[{"inset-e":Y(),end:Y()}],"inset-bs":[{"inset-bs":Y()}],"inset-be":[{"inset-be":Y()}],top:[{top:Y()}],right:[{right:Y()}],bottom:[{bottom:Y()}],left:[{left:Y()}],visibility:["visible","invisible","collapse"],z:[{z:[Pn,"auto",je,ke]}],basis:[{basis:[Ks,"full","auto",h,...C()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[Ye,Ks,"auto","initial","none",ke]}],grow:[{grow:["",Ye,je,ke]}],shrink:[{shrink:["",Ye,je,ke]}],order:[{order:[Pn,"first","last","none",je,ke]}],"grid-cols":[{"grid-cols":H()}],"col-start-end":[{col:fe()}],"col-start":[{"col-start":ee()}],"col-end":[{"col-end":ee()}],"grid-rows":[{"grid-rows":H()}],"row-start-end":[{row:fe()}],"row-start":[{"row-start":ee()}],"row-end":[{"row-end":ee()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":xe()}],"auto-rows":[{"auto-rows":xe()}],gap:[{gap:C()}],"gap-x":[{"gap-x":C()}],"gap-y":[{"gap-y":C()}],"justify-content":[{justify:[...re(),"normal"]}],"justify-items":[{"justify-items":[...de(),"normal"]}],"justify-self":[{"justify-self":["auto",...de()]}],"align-content":[{content:["normal",...re()]}],"align-items":[{items:[...de(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...de(),{baseline:["","last"]}]}],"place-content":[{"place-content":re()}],"place-items":[{"place-items":[...de(),"baseline"]}],"place-self":[{"place-self":["auto",...de()]}],p:[{p:C()}],px:[{px:C()}],py:[{py:C()}],ps:[{ps:C()}],pe:[{pe:C()}],pbs:[{pbs:C()}],pbe:[{pbe:C()}],pt:[{pt:C()}],pr:[{pr:C()}],pb:[{pb:C()}],pl:[{pl:C()}],m:[{m:U()}],mx:[{mx:U()}],my:[{my:U()}],ms:[{ms:U()}],me:[{me:U()}],mbs:[{mbs:U()}],mbe:[{mbe:U()}],mt:[{mt:U()}],mr:[{mr:U()}],mb:[{mb:U()}],ml:[{ml:U()}],"space-x":[{"space-x":C()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":C()}],"space-y-reverse":["space-y-reverse"],size:[{size:Z()}],"inline-size":[{inline:["auto",...oe()]}],"min-inline-size":[{"min-inline":["auto",...oe()]}],"max-inline-size":[{"max-inline":["none",...oe()]}],"block-size":[{block:["auto",...ge()]}],"min-block-size":[{"min-block":["auto",...ge()]}],"max-block-size":[{"max-block":["none",...ge()]}],w:[{w:[h,"screen",...Z()]}],"min-w":[{"min-w":[h,"screen","none",...Z()]}],"max-w":[{"max-w":[h,"screen","none","prose",{screen:[d]},...Z()]}],h:[{h:["screen","lh",...Z()]}],"min-h":[{"min-h":["screen","lh","none",...Z()]}],"max-h":[{"max-h":["screen","lh","none",...Z()]}],"font-size":[{text:["base",i,Ur,Si]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[a,f3,r3]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",Qd,ke]}],"font-family":[{font:[c3,o3,t]}],"font-features":[{"font-features":[ke]}],"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:[l,je,ke]}],"line-clamp":[{"line-clamp":[Ye,"none",je,gy]}],leading:[{leading:["none",u,...C()]}],"list-image":[{"list-image":["none",je,ke]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",je,ke]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:T()}],"text-color":[{text:T()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...ve(),"wavy"]}],"text-decoration-thickness":[{decoration:[Ye,"from-font","auto",je,Si]}],"text-decoration-color":[{decoration:T()}],"underline-offset":[{"underline-offset":[Ye,"auto",je,ke]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:C()}],"tab-size":[{tab:[Pn,je,ke]}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",je,ke]}],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",je,ke]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:z()}],"bg-repeat":[{bg:F()}],"bg-size":[{bg:J()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},Pn,je,ke],radial:["",je,ke],conic:["",Pn,je,ke]},d3,l3]}],"bg-color":[{bg:T()}],"gradient-from-pos":[{from:le()}],"gradient-via-pos":[{via:le()}],"gradient-to-pos":[{to:le()}],"gradient-from":[{from:T()}],"gradient-via":[{via:T()}],"gradient-to":[{to:T()}],rounded:[{rounded:ne()}],"rounded-s":[{"rounded-s":ne()}],"rounded-e":[{"rounded-e":ne()}],"rounded-t":[{"rounded-t":ne()}],"rounded-r":[{"rounded-r":ne()}],"rounded-b":[{"rounded-b":ne()}],"rounded-l":[{"rounded-l":ne()}],"rounded-ss":[{"rounded-ss":ne()}],"rounded-se":[{"rounded-se":ne()}],"rounded-ee":[{"rounded-ee":ne()}],"rounded-es":[{"rounded-es":ne()}],"rounded-tl":[{"rounded-tl":ne()}],"rounded-tr":[{"rounded-tr":ne()}],"rounded-br":[{"rounded-br":ne()}],"rounded-bl":[{"rounded-bl":ne()}],"border-w":[{border:ce()}],"border-w-x":[{"border-x":ce()}],"border-w-y":[{"border-y":ce()}],"border-w-s":[{"border-s":ce()}],"border-w-e":[{"border-e":ce()}],"border-w-bs":[{"border-bs":ce()}],"border-w-be":[{"border-be":ce()}],"border-w-t":[{"border-t":ce()}],"border-w-r":[{"border-r":ce()}],"border-w-b":[{"border-b":ce()}],"border-w-l":[{"border-l":ce()}],"divide-x":[{"divide-x":ce()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":ce()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...ve(),"hidden","none"]}],"divide-style":[{divide:[...ve(),"hidden","none"]}],"border-color":[{border:T()}],"border-color-x":[{"border-x":T()}],"border-color-y":[{"border-y":T()}],"border-color-s":[{"border-s":T()}],"border-color-e":[{"border-e":T()}],"border-color-bs":[{"border-bs":T()}],"border-color-be":[{"border-be":T()}],"border-color-t":[{"border-t":T()}],"border-color-r":[{"border-r":T()}],"border-color-b":[{"border-b":T()}],"border-color-l":[{"border-l":T()}],"divide-color":[{divide:T()}],"outline-style":[{outline:[...ve(),"none","hidden"]}],"outline-offset":[{"outline-offset":[Ye,je,ke]}],"outline-w":[{outline:["",Ye,Ur,Si]}],"outline-color":[{outline:T()}],shadow:[{shadow:["","inner","none",x,El,Cl]}],"shadow-color":[{shadow:T()}],"inset-shadow":[{"inset-shadow":["none",y,El,Cl]}],"inset-shadow-color":[{"inset-shadow":T()}],"ring-w":[{ring:ce()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:T()}],"ring-offset-w":[{"ring-offset":[Ye,Si]}],"ring-offset-color":[{"ring-offset":T()}],"inset-ring-w":[{"inset-ring":ce()}],"inset-ring-color":[{"inset-ring":T()}],"text-shadow":[{"text-shadow":["none",w,El,Cl]}],"text-shadow-color":[{"text-shadow":T()}],opacity:[{opacity:[Ye,je,ke]}],"mix-blend":[{"mix-blend":[...Re(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":Re()}],"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":[Ye]}],"mask-image-linear-from-pos":[{"mask-linear-from":Me()}],"mask-image-linear-to-pos":[{"mask-linear-to":Me()}],"mask-image-linear-from-color":[{"mask-linear-from":T()}],"mask-image-linear-to-color":[{"mask-linear-to":T()}],"mask-image-t-from-pos":[{"mask-t-from":Me()}],"mask-image-t-to-pos":[{"mask-t-to":Me()}],"mask-image-t-from-color":[{"mask-t-from":T()}],"mask-image-t-to-color":[{"mask-t-to":T()}],"mask-image-r-from-pos":[{"mask-r-from":Me()}],"mask-image-r-to-pos":[{"mask-r-to":Me()}],"mask-image-r-from-color":[{"mask-r-from":T()}],"mask-image-r-to-color":[{"mask-r-to":T()}],"mask-image-b-from-pos":[{"mask-b-from":Me()}],"mask-image-b-to-pos":[{"mask-b-to":Me()}],"mask-image-b-from-color":[{"mask-b-from":T()}],"mask-image-b-to-color":[{"mask-b-to":T()}],"mask-image-l-from-pos":[{"mask-l-from":Me()}],"mask-image-l-to-pos":[{"mask-l-to":Me()}],"mask-image-l-from-color":[{"mask-l-from":T()}],"mask-image-l-to-color":[{"mask-l-to":T()}],"mask-image-x-from-pos":[{"mask-x-from":Me()}],"mask-image-x-to-pos":[{"mask-x-to":Me()}],"mask-image-x-from-color":[{"mask-x-from":T()}],"mask-image-x-to-color":[{"mask-x-to":T()}],"mask-image-y-from-pos":[{"mask-y-from":Me()}],"mask-image-y-to-pos":[{"mask-y-to":Me()}],"mask-image-y-from-color":[{"mask-y-from":T()}],"mask-image-y-to-color":[{"mask-y-to":T()}],"mask-image-radial":[{"mask-radial":[je,ke]}],"mask-image-radial-from-pos":[{"mask-radial-from":Me()}],"mask-image-radial-to-pos":[{"mask-radial-to":Me()}],"mask-image-radial-from-color":[{"mask-radial-from":T()}],"mask-image-radial-to-color":[{"mask-radial-to":T()}],"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":L()}],"mask-image-conic-pos":[{"mask-conic":[Ye]}],"mask-image-conic-from-pos":[{"mask-conic-from":Me()}],"mask-image-conic-to-pos":[{"mask-conic-to":Me()}],"mask-image-conic-from-color":[{"mask-conic-from":T()}],"mask-image-conic-to-color":[{"mask-conic-to":T()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:z()}],"mask-repeat":[{mask:F()}],"mask-size":[{mask:J()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",je,ke]}],filter:[{filter:["","none",je,ke]}],blur:[{blur:Qe()}],brightness:[{brightness:[Ye,je,ke]}],contrast:[{contrast:[Ye,je,ke]}],"drop-shadow":[{"drop-shadow":["","none",k,El,Cl]}],"drop-shadow-color":[{"drop-shadow":T()}],grayscale:[{grayscale:["",Ye,je,ke]}],"hue-rotate":[{"hue-rotate":[Ye,je,ke]}],invert:[{invert:["",Ye,je,ke]}],saturate:[{saturate:[Ye,je,ke]}],sepia:[{sepia:["",Ye,je,ke]}],"backdrop-filter":[{"backdrop-filter":["","none",je,ke]}],"backdrop-blur":[{"backdrop-blur":Qe()}],"backdrop-brightness":[{"backdrop-brightness":[Ye,je,ke]}],"backdrop-contrast":[{"backdrop-contrast":[Ye,je,ke]}],"backdrop-grayscale":[{"backdrop-grayscale":["",Ye,je,ke]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[Ye,je,ke]}],"backdrop-invert":[{"backdrop-invert":["",Ye,je,ke]}],"backdrop-opacity":[{"backdrop-opacity":[Ye,je,ke]}],"backdrop-saturate":[{"backdrop-saturate":[Ye,je,ke]}],"backdrop-sepia":[{"backdrop-sepia":["",Ye,je,ke]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":C()}],"border-spacing-x":[{"border-spacing-x":C()}],"border-spacing-y":[{"border-spacing-y":C()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",je,ke]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[Ye,"initial",je,ke]}],ease:[{ease:["linear","initial",R,je,ke]}],delay:[{delay:[Ye,je,ke]}],animate:[{animate:["none",q,je,ke]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[S,je,ke]}],"perspective-origin":[{"perspective-origin":B()}],rotate:[{rotate:Ue()}],"rotate-x":[{"rotate-x":Ue()}],"rotate-y":[{"rotate-y":Ue()}],"rotate-z":[{"rotate-z":Ue()}],scale:[{scale:et()}],"scale-x":[{"scale-x":et()}],"scale-y":[{"scale-y":et()}],"scale-z":[{"scale-z":et()}],"scale-3d":["scale-3d"],skew:[{skew:Fe()}],"skew-x":[{"skew-x":Fe()}],"skew-y":[{"skew-y":Fe()}],transform:[{transform:[je,ke,"","none","gpu","cpu"]}],"transform-origin":[{origin:B()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:be()}],"translate-x":[{"translate-x":be()}],"translate-y":[{"translate-y":be()}],"translate-z":[{"translate-z":be()}],"translate-none":["translate-none"],zoom:[{zoom:[Pn,je,ke]}],accent:[{accent:T()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:T()}],"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",je,ke]}],"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":T()}],"scrollbar-track-color":[{"scrollbar-track":T()}],"scrollbar-gutter":[{"scrollbar-gutter":["auto","stable","both"]}],"scrollbar-w":[{scrollbar:["auto","thin","none"]}],"scroll-m":[{"scroll-m":C()}],"scroll-mx":[{"scroll-mx":C()}],"scroll-my":[{"scroll-my":C()}],"scroll-ms":[{"scroll-ms":C()}],"scroll-me":[{"scroll-me":C()}],"scroll-mbs":[{"scroll-mbs":C()}],"scroll-mbe":[{"scroll-mbe":C()}],"scroll-mt":[{"scroll-mt":C()}],"scroll-mr":[{"scroll-mr":C()}],"scroll-mb":[{"scroll-mb":C()}],"scroll-ml":[{"scroll-ml":C()}],"scroll-p":[{"scroll-p":C()}],"scroll-px":[{"scroll-px":C()}],"scroll-py":[{"scroll-py":C()}],"scroll-ps":[{"scroll-ps":C()}],"scroll-pe":[{"scroll-pe":C()}],"scroll-pbs":[{"scroll-pbs":C()}],"scroll-pbe":[{"scroll-pbe":C()}],"scroll-pt":[{"scroll-pt":C()}],"scroll-pr":[{"scroll-pr":C()}],"scroll-pb":[{"scroll-pb":C()}],"scroll-pl":[{"scroll-pl":C()}],"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",je,ke]}],fill:[{fill:["none",...T()]}],"stroke-w":[{stroke:[Ye,Ur,Si,gy]}],stroke:[{stroke:["none",...T()]}],"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":["start","end","right","left"],"inset-y":["inset-bs","inset-be","top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["ps","pe","pr","pl"],py:["pbs","pbe","pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["ms","me","mr","ml"],my:["mbs","mbe","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-s","border-w-e","border-w-r","border-w-l"],"border-w-y":["border-w-bs","border-w-be","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-s","border-color-e","border-color-r","border-color-l"],"border-color-y":["border-color-bs","border-color-be","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-ms","scroll-me","scroll-mr","scroll-ml"],"scroll-my":["scroll-mbs","scroll-mbe","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-ps","scroll-pe","scroll-pr","scroll-pl"],"scroll-py":["scroll-pbs","scroll-pbe","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"]}},p3=KN(m3);function I(...s){return p3(C0(s))}const g3=SN("inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-45 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",secondary:"bg-secondary text-secondary-foreground border border-border hover:bg-accent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground",destructive:"bg-destructive/15 text-destructive border border-destructive/40 hover:bg-destructive/25",link:"text-highlight underline-offset-4 hover:underline"},size:{default:"h-9 px-4",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 px-5",icon:"size-9","icon-sm":"size-7 rounded-md"}},defaultVariants:{variant:"default",size:"default"}});function we({className:s,variant:t,size:i,asChild:a=!1,type:l,...u}){const d=a?yN:"button";return o.jsx(d,{"data-slot":"button",type:a?void 0:l??"button",className:I(g3({variant:t,size:i}),s),...u})}const G0="w-full min-w-0 rounded-md border border-input bg-background/60 px-3 text-sm text-foreground placeholder:text-muted-foreground/80 outline-none transition-colors focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive";function Zn({className:s,type:t="text",...i}){return o.jsx("input",{"data-slot":"input",type:t,className:I(G0,"h-9",s),...i})}function ph({className:s,children:t,...i}){return o.jsx("select",{"data-slot":"select",className:I(G0,"h-9 appearance-none pr-8",s),style:{backgroundImage:`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2395a39a' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")`,backgroundPosition:"right 0.6rem center",backgroundSize:"16px",backgroundRepeat:"no-repeat"},...i,children:t})}function ro({className:s,...t}){return o.jsx("label",{"data-slot":"label",className:I("text-xs font-medium text-muted-foreground",s),...t})}function Ft({className:s,label:t}){return o.jsxs("span",{role:"status",className:I("inline-flex items-center gap-2 text-muted-foreground",s),children:[o.jsx(uc,{"aria-hidden":!0,className:"size-4 animate-spin"}),t?o.jsx("span",{children:t}):o.jsx("span",{className:"sr-only",children:"Loading"})]})}const Y0=b.createContext(null);function x3({controller:s,children:t}){return o.jsx(Y0.Provider,{value:s,children:t})}function Oe(){const s=b.useContext(Y0);if(!s)throw new Error("useController outside ControllerProvider");return s}function Ee(){const s=Oe();return b.useSyncExternalStore(b.useCallback(t=>s.subscribe(t),[s]),()=>s.getState())}function V0(s){const[t,i]=b.useState(!1),[a,l]=b.useState(null);return{run:b.useCallback(async(...d)=>{i(!0),l(null);try{return await s(...d),!0}catch(h){return l(h instanceof Error?h.message:String(h)),!1}finally{i(!1)}},[s]),pending:t,error:a,clearError:()=>l(null)}}const y3="M1196 972L1193 1004L1180 1053L1163 1087L1141 1117L1114 1143L1079 1166L1052 1178L1011 1189L970 1193L284 1193L217 1183L158 1156L113 1117L89 1084L68 1036L59 988L58 284L62 246L72 208L86 177L108 145L132 120L168 94L197 80L237 68L284 63L970 63L1030 71L1086 94L1123 121L1160 164L1182 208L1193 252L1196 285Z",b3="M717 377L693 495L641 803L566 803L566 801L644 371L717 371ZM594 443L531 803L462 803L469 764L447 780L424 792L402 800L371 806L345 807L309 803L278 794L256 784L238 773L216 755L202 740L184 714L170 684L163 659L160 637L160 607L164 582L171 559L180 539L196 514L231 479L250 466L280 451L313 441L345 437L377 438L405 443L431 452L463 469L483 484L509 511L522 439L589 438L594 439ZM1092 639L1086 671L1077 696L1067 715L1047 742L1031 758L1001 780L967 796L937 804L908 807L872 805L832 795L804 782L779 765L759 747L737 887L669 888L665 887L665 880L737 439L803 439L797 478L809 468L836 452L857 444L885 438L915 437L941 440L974 449L996 459L1031 483L1050 502L1071 533L1083 561L1089 584L1092 604ZM223 616L223 639L227 661L236 683L249 702L262 715L282 729L307 740L335 746L369 746L385 743L403 737L431 721L455 698L466 682L478 654L482 633L482 609L477 583L465 556L454 541L436 524L409 508L384 500L362 497L336 498L314 503L289 514L271 526L254 542L239 563L228 589ZM772 613L772 640L775 657L784 681L798 702L812 716L829 728L859 741L885 746L918 746L934 743L952 737L984 718L1004 698L1015 682L1027 654L1031 631L1031 610L1026 583L1015 558L1002 540L978 519L958 508L933 500L912 497L886 498L863 503L838 514L820 526L803 542L785 568L777 588Z";function K0({className:s}){return o.jsxs("svg",{viewBox:"0 0 1254 1254","aria-hidden":!0,className:I("shrink-0",s),children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:"alp-logo-tile",x1:"180",y1:"120",x2:"1080",y2:"1160",gradientUnits:"userSpaceOnUse",children:[o.jsx("stop",{stopColor:"#1d1e20"}),o.jsx("stop",{offset:"1",stopColor:"#111214"})]})}),o.jsx("path",{fill:"url(#alp-logo-tile)",d:y3}),o.jsx("path",{fill:"#fff",fillRule:"evenodd",d:b3})]})}const F0="alp-web:gateway",X0=!1;function v3(){let s=null;try{s=window.localStorage.getItem(F0)}catch{}return Y2({location:window.location,remembered:s,dev:X0})}function w3(){const s=Oe(),{connection:t}=Ee();return o.jsx("main",{className:"flex min-h-full items-center justify-center bg-[radial-gradient(ellipse_at_top,_var(--glow)_0%,_var(--background)_55%)] px-4 py-10",children:o.jsxs("div",{className:"w-full max-w-md space-y-4","data-testid":"link-connecting",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(K0,{className:"size-10"}),o.jsxs("div",{children:[o.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"ALP"}),o.jsx("p",{className:"text-sm text-muted-foreground",children:"Opening ALP on this machine"})]})]}),o.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[o.jsx(Ft,{label:"Connecting…"}),t.attempt>1?o.jsxs("span",{children:["Waiting for alp dashboard (attempt ",t.attempt,")"]}):null]}),t.error?o.jsx("p",{className:"text-sm text-muted-foreground",children:t.error.message}):null,o.jsx(we,{size:"sm",variant:"ghost",onClick:()=>s.disconnect(),children:"Use another access token"})]})})}function k3(){const s=Oe(),{connection:t}=Ee(),[i,a]=b.useState(()=>t.gateway||v3()),[l,u]=b.useState(""),d=t.phase==="connecting",h=t.phase==="failed"?t.error:void 0;if(d&&t.link)return o.jsx(w3,{});const m=p=>{p.preventDefault();try{window.localStorage.setItem(F0,i.trim())}catch{}s.connect({url:i,token:l})};return o.jsx("main",{className:"flex min-h-full items-center justify-center bg-[radial-gradient(ellipse_at_top,_var(--glow)_0%,_var(--background)_55%)] px-4 py-10",children:o.jsxs("div",{className:"w-full max-w-md",children:[o.jsxs("div",{className:"mb-8 flex items-center gap-3",children:[o.jsx(K0,{className:"size-10"}),o.jsxs("div",{children:[o.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"ALP"}),o.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect to your agents on an ALP host"})]})]}),o.jsxs("form",{onSubmit:m,className:"space-y-5 rounded-xl border border-border bg-card/80 p-6 shadow-xl shadow-[var(--shadow)] backdrop-blur","aria-describedby":h?"connect-error":void 0,children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx(ro,{htmlFor:"gateway",children:"Gateway address"}),o.jsx(Zn,{id:"gateway",name:"gateway",inputMode:"url",autoComplete:"url",spellCheck:!1,value:i,onChange:p=>a(p.target.value),placeholder:"https://alp.example.com",required:!0,disabled:d})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx(ro,{htmlFor:"token",children:"Access token"}),o.jsx(Zn,{id:"token",name:"token",type:"password",autoComplete:"off",spellCheck:!1,value:l,onChange:p=>u(p.target.value),placeholder:"alpgw1.…",required:!0,disabled:d}),o.jsxs("p",{className:"flex items-start gap-1.5 text-xs text-muted-foreground",children:[o.jsx(dc,{"aria-hidden":!0,className:"mt-0.5 size-3.5 shrink-0 text-highlight"}),"Kept in this tab's memory only. Reloading or disconnecting forgets it."]})]}),h?o.jsx("div",{id:"connect-error",role:"alert",className:"rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:h.message}):null,o.jsx(we,{type:"submit",className:"w-full",disabled:d||!i.trim()||!l.trim(),children:d?o.jsx(Ft,{className:"text-primary-foreground",label:"Connecting…"}):o.jsxs(o.Fragment,{children:[o.jsx(eN,{"aria-hidden":!0})," Connect"]})})]}),o.jsxs("details",{className:"mt-5 rounded-lg border border-border/70 bg-card/40 px-4 py-3 text-sm text-muted-foreground",children:[o.jsxs("summary",{className:"flex cursor-pointer items-center gap-2 font-medium text-foreground/90",children:[o.jsx(HS,{"aria-hidden":!0,className:"size-4"})," Getting a token"]}),o.jsxs("div",{className:"mt-3 space-y-2",children:[Cb({location:window.location,dev:X0})?o.jsxs(o.Fragment,{children:[o.jsxs("p",{children:["On this machine, run ",o.jsx("code",{className:"font-mono",children:"alp dashboard"}),": it opens this page with a link that signs you in. ",o.jsx("code",{className:"font-mono",children:"alp dashboard --print"})," prints the link instead, and ",o.jsx("code",{className:"font-mono",children:"alp dashboard rotate"})," replaces its token, signing out every open page."]}),o.jsx("p",{children:"To use a standalone gateway instead, create a token for the workspaces you want to open, then start the gateway with this page's address as an allowed origin:"})]}):o.jsx("p",{children:"On the ALP host, create a token for the workspaces you want to open here, then start the gateway with this page's address as an allowed origin:"}),o.jsx("pre",{className:"overflow-x-auto rounded-md bg-background px-3 py-2 font-mono text-xs text-foreground/90",children:`alp-gateway credential create --label web \\
19
19
  --workspace /path/to/project
20
20
  alp-gateway serve --origin ${typeof window>"u"?"http://127.0.0.1:7435":window.location.origin}`}),o.jsx("p",{children:"From another machine, use the host's HTTPS address, or an SSH tunnel to the gateway's port (127.0.0.1:7434 by default)."})]})]})]})})}function ai({open:s,onClose:t,title:i,description:a,children:l,className:u,footer:d}){const h=b.useRef(null),m=b.useId();return b.useEffect(()=>{const p=h.current;p&&(s&&!p.open&&p.showModal(),!s&&p.open&&p.close())},[s]),o.jsx("dialog",{ref:h,"aria-labelledby":m,onCancel:p=>{p.preventDefault(),t()},onClick:p=>{p.target===h.current&&t()},className:I("m-auto w-[min(92vw,32rem)] max-h-[88dvh] overflow-hidden rounded-xl border border-border bg-popover p-0 text-popover-foreground shadow-2xl shadow-[var(--shadow)]",u),children:s?o.jsxs("div",{className:"flex max-h-[88dvh] flex-col",children:[o.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-border px-5 py-4",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("h2",{id:m,className:"text-base font-semibold",children:i}),a?o.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:a}):null]}),o.jsx(we,{variant:"ghost",size:"icon-sm","aria-label":"Close",onClick:t,children:o.jsx(en,{})})]}),o.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4",children:l}),d?o.jsx("footer",{className:"flex flex-wrap justify-end gap-2 border-t border-border px-5 py-3",children:d}):null]}):null})}function Dt(s){const t=s.replace(/[\\/]+$/,"");return t.split(/[\\/]/).pop()||t||s}function Ri(s,t=Date.now()){if(!s)return"";const i=Date.parse(s);if(Number.isNaN(i))return"";const a=Math.max(0,Math.round((t-i)/1e3));if(a<45)return"just now";const l=Math.round(a/60);if(l<60)return`${l} min ago`;const u=Math.round(l/60);if(u<24)return`${u} h ago`;const d=Math.round(u/24);return d<7?`${d} d ago`:new Date(i).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function P0(s){if(!s)return"";const t=Date.parse(s);return Number.isNaN(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}const j3={"read-only":"Read only","workspace-write":"Workspace write","full-access":"Full access"},Fl=s=>s?j3[s]??s:"";function Wn(s,t){return s?.title?s.title:`Session ${(s?.id??t??"").replace(/^(web_|ses_)/,"").slice(0,6)}`}function S3(s,t=Date.now()){const i=Date.parse(s??"");if(!Number.isFinite(i))return"";const a=Math.max(0,t-i);if(a<6e4)return"now";if(a<36e5)return`${Math.floor(a/6e4)}m`;if(a<864e5)return`${Math.floor(a/36e5)}h`;if(a<7*864e5)return`${Math.floor(a/864e5)}d`;const l=new Date(i);return`${l.toLocaleDateString("en-US",{month:"short"})} ${l.getDate()}`}function N3({session:s,onClose:t}){const i=Oe(),[a,l]=b.useState(s?.title??""),[u,d]=b.useState(s);s!==u&&(d(s),l(s?.title??""));const h=V0(b.useCallback((m,p)=>i.renameSession(m,p),[i]));return b.useEffect(()=>{s&&h.clearError()},[s]),o.jsx(ai,{open:!!s,onClose:t,title:"Rename session",footer:o.jsxs(o.Fragment,{children:[o.jsx(we,{variant:"ghost",onClick:t,children:"Cancel"}),o.jsx(we,{type:"submit",form:"rename-session",disabled:h.pending||!a.trim(),children:"Save"})]}),children:o.jsxs("form",{id:"rename-session",className:"space-y-1.5",onSubmit:async m=>{m.preventDefault(),s&&await h.run(s.id,a.trim())&&t()},children:[o.jsx(ro,{htmlFor:"rename-title",children:"Title"}),o.jsx(Zn,{id:"rename-title",value:a,onChange:m=>l(m.target.value),maxLength:200,autoFocus:!0}),h.error?o.jsx("p",{role:"alert",className:"text-xs text-destructive",children:h.error}):null]})})}function T3({session:s,onClose:t}){const i=Oe(),a=V0(b.useCallback(l=>i.archiveSession(l),[i]));return b.useEffect(()=>{s&&a.clearError()},[s]),o.jsx(ai,{open:!!s,onClose:t,title:"Archive session?",description:o.jsxs(o.Fragment,{children:["“",Wn(s??void 0),"” stops and leaves the list. Its history stays on the host."]}),footer:o.jsxs(o.Fragment,{children:[o.jsx(we,{variant:"ghost",onClick:t,children:"Cancel"}),o.jsx(we,{variant:"destructive",disabled:a.pending,onClick:async()=>{s&&await a.run(s.id)&&t()},children:"Archive"})]}),children:a.error?o.jsx("p",{role:"alert",className:"text-xs text-destructive",children:a.error}):o.jsx("p",{className:"text-sm text-muted-foreground",children:"Running work in this session is stopped."})})}function Q0({version:s,connection:t,principal:i,preferences:a,browser:l={}}){const u=h=>h===void 0?"unknown":h?"yes":"no",d=h=>h?.length?[...h].sort().join(", "):"none";return[{title:"App",rows:[["Version",`ALP web v${s}`],["Theme",a.theme],["Content width",a.contentMaxWidth===null?"default":`${a.contentMaxWidth}px`],["Chat display",a.chatDisplay],["Default send",a.sendBehavior]]},{title:"Browser",rows:[["User agent",l.userAgent??"unknown"],["Language",l.language??"unknown"],["Online",u(l.online)],["Secure context",u(l.secure)],["Viewport",l.viewport??"unknown"],["Color scheme",l.colorScheme??"unknown"]]},{title:"Connection",rows:[["Gateway",t.gateway],["State",t.phase==="reconnecting"?`reconnecting (attempt ${t.attempt})`:t.phase],["Host",t.hostname??"unknown"],["ALP on the host",t.daemonVersion??"unknown"],["Capabilities",d(t.capabilities)]]},{title:"Access token",rows:[["Name",i?.label??"unknown"],["Id",i?.id??"unknown"],["Permissions",d(i?.permissions)],["Modes",i?.modes?d(i.modes):"any"],["Projects",String(i?.workspaces?.length??0)]]}]}function A3(s){const t=[`ALP web diagnostics, ${(s.now??new Date).toISOString()}`];for(const i of Q0(s)){t.push("",`## ${i.title}`);for(const[a,l]of i.rows)t.push(`${a}: ${l}`)}return t.join(`
21
21
  `)}const C3="modulepreload",E3=function(s){return"/"+s},by={},W0=function(t,i,a){let l=Promise.resolve();if(i&&i.length>0){let m=function(p){return Promise.all(p.map(x=>Promise.resolve(x).then(y=>({status:"fulfilled",value:y}),y=>({status:"rejected",reason:y}))))};document.getElementsByTagName("link");const d=document.querySelector("meta[property=csp-nonce]"),h=d?.nonce||d?.getAttribute("nonce");l=m(i.map(p=>{if(p=E3(p),p in by)return;by[p]=!0;const x=p.endsWith(".css"),y=x?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${p}"]${y}`))return;const w=document.createElement("link");if(w.rel=x?"stylesheet":C3,x||(w.as="script"),w.crossOrigin="",w.href=p,h&&w.setAttribute("nonce",h),document.head.appendChild(w),x)return new Promise((k,j)=>{w.addEventListener("load",k),w.addEventListener("error",()=>j(new Error(`Unable to preload CSS for ${p}`)))})}))}function u(d){const h=new Event("vite:preloadError",{cancelable:!0});if(h.payload=d,window.dispatchEvent(h),!h.defaultPrevented)throw d}return l.then(d=>{for(const h of d||[])h.status==="rejected"&&u(h.reason);return t().catch(u)})},M3={keyword:"#ff7b72",comment:"#8b949e",string:"#a5d6ff",number:"#79c0ff",literal:"#79c0ff",function:"#d2a8ff",definition:"#d2a8ff",class:"#ffa657",type:"#ff7b72",tag:"#7ee787",attribute:"#79c0ff",property:"#79c0ff",variable:"#c9d1d9",operator:"#79c0ff",punctuation:"#c9d1d9",regexp:"#a5d6ff",escape:"#79c0ff",meta:"#8b949e",heading:"#79c0ff",link:"#a5d6ff"},z3={keyword:"#cf222e",comment:"#6e7781",string:"#0a3069",number:"#0550ae",literal:"#0550ae",function:"#8250df",definition:"#8250df",class:"#953800",type:"#cf222e",tag:"#116329",attribute:"#0550ae",property:"#0550ae",variable:"#24292f",operator:"#0550ae",punctuation:"#24292f",regexp:"#0a3069",escape:"#0550ae",meta:"#6e7781",heading:"#0550ae",link:"#0a3069"},R3=[{id:"github",label:"GitHub"},{id:"catppuccin",label:"Catppuccin"},{id:"dracula",label:"Dracula"},{id:"tokyo-night",label:"Tokyo Night"},{id:"one",label:"One"},{id:"nord",label:"Nord"},{id:"gruvbox",label:"Gruvbox"},{id:"solarized",label:"Solarized"}];function Ni(s){return{keyword:s.keyword,comment:s.comment,string:s.string,number:s.number,literal:s.number,function:s.function,definition:s.function,class:s.type,type:s.type,tag:s.tag,attribute:s.attribute,property:s.attribute,variable:s.base,operator:s.operator,punctuation:s.base,regexp:s.string,escape:s.number,meta:s.comment,heading:s.function,link:s.string}}const _3={base:"#4c4f69",keyword:"#8839ef",comment:"#8c8fa1",string:"#40a02b",number:"#fe640b",function:"#1e66f5",type:"#df8e1d",tag:"#8839ef",attribute:"#df8e1d",operator:"#04a5e5"},L3={base:"#cdd6f4",keyword:"#cba6f7",comment:"#9399b2",string:"#a6e3a1",number:"#fab387",function:"#89b4fa",type:"#f9e2af",tag:"#cba6f7",attribute:"#f9e2af",operator:"#89dceb"},O3={base:"#f8f8f2",keyword:"#ff79c6",comment:"#6272a4",string:"#f1fa8c",number:"#bd93f9",function:"#50fa7b",type:"#8be9fd",tag:"#ff79c6",attribute:"#50fa7b",operator:"#ff79c6"},D3={base:"#3760bf",keyword:"#9854f1",comment:"#848cb5",string:"#587539",number:"#b15c00",function:"#2e7de9",type:"#007197",tag:"#f52a65",attribute:"#8c6c3e",operator:"#006a83"},q3={base:"#c0caf5",keyword:"#bb9af7",comment:"#565f89",string:"#9ece6a",number:"#ff9e64",function:"#7aa2f7",type:"#2ac3de",tag:"#f7768e",attribute:"#e0af68",operator:"#89ddff"},B3={base:"#383a42",keyword:"#a626a4",comment:"#a0a1a7",string:"#50a14f",number:"#986801",function:"#4078f2",type:"#c18401",tag:"#e45649",attribute:"#986801",operator:"#0184bc"},$3={base:"#abb2bf",keyword:"#c678dd",comment:"#5c6370",string:"#98c379",number:"#d19a66",function:"#61afef",type:"#e5c07b",tag:"#e06c75",attribute:"#d19a66",operator:"#56b6c2"},U3={base:"#2e3440",keyword:"#5e81ac",comment:"#6b7280",string:"#4f6f3a",number:"#8f5e91",function:"#2e6f8e",type:"#3b7f87",tag:"#5e81ac",attribute:"#8f5e91",operator:"#5e81ac"},H3={base:"#d8dee9",keyword:"#81a1c1",comment:"#616e88",string:"#a3be8c",number:"#b48ead",function:"#88c0d0",type:"#8fbcbb",tag:"#81a1c1",attribute:"#8fbcbb",operator:"#81a1c1"},I3={base:"#3c3836",keyword:"#9d0006",comment:"#928374",string:"#79740e",number:"#8f3f71",function:"#427b58",type:"#b57614",tag:"#076678",attribute:"#b57614",operator:"#af3a03"},G3={base:"#ebdbb2",keyword:"#fb4934",comment:"#928374",string:"#b8bb26",number:"#d3869b",function:"#8ec07c",type:"#fabd2f",tag:"#83a598",attribute:"#fabd2f",operator:"#fe8019"},Y3={base:"#657b83",keyword:"#859900",comment:"#93a1a1",string:"#2aa198",number:"#d33682",function:"#268bd2",type:"#b58900",tag:"#268bd2",attribute:"#b58900",operator:"#859900"},V3={base:"#839496",keyword:"#859900",comment:"#586e75",string:"#2aa198",number:"#d33682",function:"#268bd2",type:"#b58900",tag:"#268bd2",attribute:"#b58900",operator:"#859900"};function K3(s,t){const i=t==="dark";switch(s){case"github":return i?M3:z3;case"catppuccin":return Ni(i?L3:_3);case"dracula":return Ni(O3);case"tokyo-night":return Ni(i?q3:D3);case"one":return Ni(i?$3:B3);case"nord":return Ni(i?H3:U3);case"gruvbox":return Ni(i?G3:I3);case"solarized":return Ni(i?V3:Y3)}}const vy={typescript:"ts",javascript:"js",python:"py",rust:"rs",golang:"go","c++":"cpp",csharp:"cs","c#":"cs",objc:"m","objective-c":"m",markdown:"md",elixir:"ex"};function F3(s){const t=s?.trim().split(/\s+/)[0]?.toLowerCase().replace(/^\./,"");return t?`code.${Object.hasOwn(vy,t)?vy[t]:t}`:null}const X3=R3.map(s=>({value:s.id,label:s.label}));let Af=null,wy=null;const Cf=new Set;function P3(){return wy??=W0(()=>import("./highlighter-BnicKQ_d.js"),[]).then(s=>{Af=s;for(const t of Cf)t();return s}),wy}function Q3(){const[,s]=b.useReducer(t=>t+1,0);return b.useEffect(()=>{if(!Af)return Cf.add(s),P3(),()=>{Cf.delete(s)}},[]),Af}const W3=768*1024;function mc(s,t){const i=Q3();return b.useMemo(()=>{if(!i||!t||s.length>W3||!i.isLanguageSupported(t))return null;try{return i.highlightCode(s,t)}catch{return null}},[i,s,t])}function pc({tokens:s}){return b.createElement(b.Fragment,null,s.map((t,i)=>t.style?b.createElement("span",{key:i,style:{color:`var(--syntax-${t.style})`}},t.text):t.text))}const Z3=["keyword","comment","string","number","literal","function","definition","class","type","tag","attribute","property","variable","operator","punctuation","regexp","escape","meta","heading","link"];function J3(s,t){const i=K3(s,t),a=document.documentElement.style;for(const l of Z3)a.setProperty(`--syntax-${l}`,i[l])}const Wd=[{value:"light",label:"Light",group:"primary",swatch:"#ffffff"},{value:"dark",label:"Dark",group:"primary",swatch:"#2D8B62"},{value:"system",label:"System",group:"primary"},{value:"zinc",label:"Zinc",group:"variant",swatch:"#808080"},{value:"midnight",label:"Midnight",group:"variant",swatch:"#4A6BA8"},{value:"claude",label:"Claude",group:"variant",swatch:"#D97757"},{value:"ghostty",label:"Ghostty",group:"variant",swatch:"#8caaee"},{value:"pureBlack",label:"Pure black",group:"variant",swatch:"#000000"}],ky={light:"#ffffff",dark:"#181b1a",zinc:"#18181b",midnight:"#161820",claude:"#1f1f1e",ghostty:"#282c34",pureBlack:"#000000"};function e4(s,t="one"){const i=document.documentElement,a=typeof window.matchMedia=="function"?window.matchMedia("(prefers-color-scheme: light)"):null,l=()=>{const u=s==="system"?a?.matches?"light":"dark":s,d=u==="light"?"light":"dark";i.dataset.theme=u,i.classList.toggle("dark",d==="dark"),i.style.colorScheme=d,document.querySelector('meta[name="color-scheme"]')?.setAttribute("content",d),document.querySelector('meta[name="theme-color"]')?.setAttribute("content",ky[u]??ky.dark),J3(t,d)};return l(),s!=="system"||!a?()=>{}:(a.addEventListener("change",l),()=>a.removeEventListener("change",l))}const Z0='"Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',J0='"JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace';function e1(s){return s.contentMaxWidth??On.contentMaxWidth[2]}function t4(s){const t=document.documentElement.style;t.setProperty("--app-font-sans",s.uiFontFamily||Z0),t.setProperty("--app-font-mono",s.monoFontFamily||J0),t.setProperty("--ui-scale",String(s.uiFontSize/On.uiFontSize[2])),t.setProperty("--content-font-size",`${s.contentFontSize}px`),t.setProperty("--code-font-size",`${s.codeFontSize}px`),t.setProperty("--content-width",`${e1(s)}px`)}const n4={red:"#dc2626",green:"#16a34a",yellow:"#ca8a04",blue:"#2563eb",magenta:"#9333ea",cyan:"#0891b2",white:"#ffffff",brightRed:"#ef4444",brightGreen:"#22c55e",brightYellow:"#f59e0b",brightBlue:"#3b82f6",brightMagenta:"#a855f7",brightCyan:"#06b6d4",brightWhite:"#fafafa"},s4={red:"#e07070",green:"#5dba80",yellow:"#d4a44a",blue:"#6a9de0",magenta:"#b07ad0",cyan:"#4aabb8",white:"#d4d4d8",brightRed:"#e89090",brightGreen:"#7ecf9a",brightYellow:"#e0be6e",brightBlue:"#8ab4e8",brightMagenta:"#c49ae0",brightCyan:"#6ec2cc",brightWhite:"#f0f0f2"};function PC(){const s=document.documentElement,t=getComputedStyle(s),i=d=>t.getPropertyValue(d).trim(),a=s.dataset.theme==="light",l=i("--background"),u=i("--foreground");return{background:l,foreground:u,cursor:u,cursorAccent:l,selectionBackground:a?"rgba(0, 0, 0, 0.15)":"rgba(255, 255, 255, 0.2)",selectionForeground:u,black:i("--terminal-black"),brightBlack:i("--terminal-bright-black"),...a?n4:s4}}function t1({checked:s,onCheckedChange:t,className:i,...a}){return o.jsx("button",{type:"button",role:"switch","aria-checked":s,onClick:()=>t(!s),"data-slot":"switch",className:I("relative inline-flex h-5 w-9 shrink-0 items-center rounded-full border border-transparent transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s?"bg-primary":"bg-input",i),...a,children:o.jsx("span",{"aria-hidden":!0,className:I("pointer-events-none block size-4 rounded-full bg-white shadow transition-transform",s?"translate-x-4":"translate-x-0.5")})})}const Ef=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,n1=s=>s.replace(/\t/g," ").match(/^ */)[0].length,jy=s=>s.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(t=>t.trim());function s1(s,t,i){const a=Ef.exec(s[t]),l=/\d/.test(a[2]),u=[];let d=t;for(;d<s.length;){const h=s[d],m=Ef.exec(h),p=n1(h);if(m&&p===i&&/\d/.test(m[2])===l){u.push({text:m[3],children:[]}),d++;continue}if(m&&p>i&&u.length){const x=s1(s,d,p);u.at(-1).children.push(x.block),d=x.next;continue}if(!m&&h.trim()&&p>i&&u.length){const x=u.at(-1);if(x.children.length)break;x.text+=` ${h.trim()}`,d++;continue}break}return{block:{kind:"list",ordered:l,start:l&&Number.parseInt(a[2],10)||1,items:u},next:d}}function i4(s){const t=s.replace(/\r\n?/g,`
@@ -26,7 +26,7 @@ alp-gateway serve --origin ${typeof window>"u"?"http://127.0.0.1:7435":window.lo
26
26
  ${p[1]}`:i.push({kind:"quote",text:p[1]});continue}if(!d.trim()){l();continue}a.push(d)}return l(),i}const i1=String.raw`(?!\))[^()\s]{0,2048}(?:\([^()\s]{0,2048}\)[^()\s]{0,2048})?`,a1=String.raw`[^[\]\n]{1,1000}`,a4=new RegExp(["(`[^`\\n]{1,1000}`)",String.raw`(\*\*[^*\n]{1,1000}?\*\*|__[^_\n]{1,1000}?__)`,String.raw`(~~[^~\n]{1,1000}?~~)`,String.raw`(\[${a1}\]\(${i1}\))`,String.raw`((?:https?:\/\/|mailto:)[^\s<>()]{0,2048}[^\s<>().,;:!?'"`+"`"+String.raw`*])`,String.raw`(\*[^*\s][^*\n]{0,1000}?\*|(?<![\w])_[^_\s][^_\n]{0,1000}?_(?![\w]))`].join("|")),r4=new RegExp(String.raw`^\[(${a1})\]\((${i1})\)$`);function o4(s){const t=r4.exec(s);return t?{text:t[1],href:t[2]}:void 0}const gc=b.createContext(null),l4="cursor-pointer text-highlight underline-offset-2 hover:underline focus-visible:underline outline-none";function Sy({target:s,links:t,children:i,title:a}){return o.jsx("button",{type:"button",className:I("inline break-words text-left [overflow-wrap:anywhere]",l4),title:a,"data-testid":"chat-file-link","data-path":s.path,onClick:()=>t.open(s),children:o.jsx(gc.Provider,{value:null,children:i})})}const r1=s=>/^(https?:\/\/|mailto:)/i.test(s)?s:void 0;function Ny({href:s,children:t}){const i=r1(s);return i?o.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:"break-words text-highlight [overflow-wrap:anywhere] hover:underline",children:o.jsx(gc.Provider,{value:null,children:t})}):o.jsx(o.Fragment,{children:t})}function Un({text:s}){const t=b.useContext(gc),i=[];let a=s,l=0;for(;a;){const u=a4.exec(a);if(!u){i.push(a);break}u.index&&i.push(a.slice(0,u.index));const[d,h,m,p,x,y,w]=u;if(h){const k=h.slice(1,-1),j=t?.resolve(k,"code"),S=o.jsx("code",{className:I("rounded-md bg-muted px-1 py-0.5 font-mono text-(length:--code-font-size)",j?"text-highlight":"text-foreground"),children:k});i.push(j&&t?o.jsx(Sy,{target:j,links:t,title:`Open ${j.path}${j.line?`:${j.line}`:""}`,children:S},l++):o.jsx(b.Fragment,{children:S},l++))}else if(m)i.push(o.jsx("strong",{className:"font-semibold text-foreground",children:o.jsx(Un,{text:m.slice(2,-2)})},l++));else if(p)i.push(o.jsx("s",{className:"text-muted-foreground",children:o.jsx(Un,{text:p.slice(2,-2)})},l++));else if(x){const k=o4(x),j=!k||r1(k.href)?void 0:t?.resolve(k.href,"href");k?i.push(j&&t?o.jsx(Sy,{target:j,links:t,title:`Open ${j.path}${j.line?`:${j.line}`:""}`,children:o.jsx(Un,{text:k.text})},l++):o.jsx(Ny,{href:k.href,children:o.jsx(Un,{text:k.text})},l++)):i.push(x)}else y?i.push(o.jsx(Ny,{href:y,children:y},l++)):w&&i.push(o.jsx("em",{className:"italic",children:o.jsx(Un,{text:w.slice(1,-1)})},l++));a=a.slice(u.index+d.length)}return o.jsx(o.Fragment,{children:i})}const c4=["","mt-6 mb-3 border-b border-border pb-2 text-[1.867em] leading-[1.286] font-bold","mt-6 mb-3 border-b border-border pb-2 text-[1.6em] leading-[1.292] font-bold","mt-4 mb-2 text-[1.4em] leading-[1.333] font-semibold","mt-4 mb-2 text-[1.267em] leading-[1.316] font-semibold","mt-3 mb-1 text-[1.133em] leading-[1.294] font-semibold","mt-3 mb-1 text-[1.133em] leading-[1.294] font-semibold uppercase tracking-[0.5px] text-muted-foreground"];function o1({blocks:s,nested:t}){return o.jsx(o.Fragment,{children:s.map((i,a)=>{const l=s[a+1];switch(i.kind){case"code":return o.jsx(u4,{text:i.text,lang:i.lang},a);case"heading":{const u=`h${Math.min(i.level+1,6)}`;return o.jsx(u,{className:I("text-foreground first:mt-0",c4[i.level]),children:o.jsx(Un,{text:i.text})},a)}case"list":{const u=i.ordered?"ol":"ul",d=t?"mb-0":l?l.kind==="list"?"mb-2":"mb-4":"mb-0";return o.jsx(u,{className:I("mt-1 pl-2.5",d),...i.ordered&&i.start!==1?{start:i.start}:{},children:i.items.map((h,m)=>o.jsxs("li",{className:"mb-1 flex items-start",children:[o.jsx("span",{"aria-hidden":!0,className:I("mr-1 shrink-0 select-none text-muted-foreground",i.ordered&&"min-w-3"),children:i.ordered?`${i.start+m}.`:"•"}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx(Un,{text:h.text}),h.children.length?o.jsx(o1,{blocks:h.children,nested:!0}):null]})]},m))},a)}case"quote":return o.jsx("blockquote",{className:"my-3 whitespace-pre-wrap rounded-r-md border-l-4 border-muted bg-card px-4 py-3 text-foreground/80",children:o.jsx(Un,{text:i.text})},a);case"table":return o.jsx("div",{className:"my-3 overflow-x-auto rounded-md border border-border",children:o.jsxs("table",{className:"w-full border-collapse text-left",children:[o.jsx("thead",{className:"bg-muted",children:o.jsx("tr",{children:i.head.map((u,d)=>o.jsx("th",{className:"border-b border-r border-border p-2 font-semibold last:border-r-0",children:o.jsx(Un,{text:u})},d))})}),o.jsx("tbody",{children:i.rows.map((u,d)=>o.jsx("tr",{className:"border-b border-border last:border-b-0",children:i.head.map((h,m)=>o.jsx("td",{className:"border-r border-border p-2 align-top last:border-r-0",children:o.jsx(Un,{text:u[m]??""})},m))},d))})]})},a);case"rule":return o.jsx("hr",{className:"my-2.5 border-0 border-t border-border"},a);default:return o.jsx("p",{className:I("whitespace-pre-wrap",t?"mb-0":"mb-3"),children:o.jsx(Un,{text:i.text})},a)}})})}function u4({text:s,lang:t}){const i=mc(s,F3(t));return o.jsx("pre",{className:"my-3 overflow-x-auto rounded-md border border-border bg-muted p-3 font-mono text-(length:--code-font-size) leading-[1.5] text-foreground","data-language":t||void 0,children:o.jsx("code",{children:i?i.map((a,l)=>o.jsxs(b.Fragment,{children:[l?`
27
27
  `:null,o.jsx(pc,{tokens:a})]},l)):s})})}function fo({text:s,className:t}){const i=b.useMemo(()=>i4(s),[s]);return o.jsx("div",{className:I("min-w-0 break-words text-(length:--content-font-size) leading-[1.4] text-foreground [overflow-wrap:anywhere]",t),children:o.jsx(o1,{blocks:i})})}const Xl="‹hidden on the host›",d4=new Set(["instructions","body","houseRules"]),f4={instructions:"AGENT.md",config:"agent.json",body:"SKILL.md",server:"Server",hook:"Hook",team:"team.json",houseRules:"HOUSE_RULES.md",provider:"Provider"},Ty=s=>s!==null&&typeof s=="object"&&!Array.isArray(s)&&Object.keys(s).length===1&&s.$secret==="keep";function h4(s){const t=[];for(const[i,a]of Object.entries(s??{})){const l=f4[i]??i;if(d4.has(i)&&typeof a=="string"){t.push({key:i,label:l,kind:"text",text:a});continue}if(a===void 0)continue;const u=Ty(a)?Xl:JSON.stringify(a,(d,h)=>Ty(h)?Xl:h,2);t.push({key:i,label:l,kind:"json",text:u})}return t}const Ml={none:"/favicon.svg",running:"/favicon-running.svg",attention:"/favicon-attention.svg"},Ay=220;function m4({status:s,waiting:t=!1,reason:i}){return t?"needs_input":s==="error"||i==="error"?"failed":s==="running"||s==="initializing"?"running":i==="finished"?"attention":"done"}function p4(s,t=!1){return s.includes("running")?"running":t||s.includes("needs_input")||s.includes("attention")?"attention":"none"}function g4({root:s,name:t,reason:i,message:a}){const l=i==="error"?(a?l1(a):"")||"Encountered an error.":"Finished working.";return{title:i==="finished"?"Agent finished":"Agent needs attention",body:`${t}: ${l}`,tag:`alp-${i}-${s}`}}function x4(s,t){return Object.entries(t).filter(([i,a])=>a.at!==s[i]?.at).map(([i])=>i)}function l1(s){const t=s.replace(/```[\s\S]*?```/g," ").replace(/[`*_>#~[\]]/g,"").replace(/\s+/g," ").trim();return t.length>Ay?`${t.slice(0,Ay-3).trimEnd()}...`:t}function y4(s,t){return Object.entries(t).filter(([i,a])=>a>0&&a>(s[i]??0)).map(([i])=>i)}const Cy=(s,t)=>s.visible&&s.focused&&s.shown===t,c1="fixed z-50 max-h-[min(60vh,28rem)] min-w-40 max-w-[min(92vw,26rem)] overflow-y-auto rounded-lg border border-border bg-popover p-1 shadow-xl shadow-[var(--shadow)]";function Mf({items:s,close:t,openPage:i}){return o.jsx(o.Fragment,{children:s.map(a=>o.jsxs(b.Fragment,{children:[a.group?o.jsx("div",{role:"separator",className:"-mx-1 my-1 h-px bg-border"}):null,o.jsxs("button",{type:"button",role:a.checked===void 0?"menuitem":a.keepOpen?"menuitemcheckbox":"menuitemradio","aria-checked":a.checked,disabled:a.disabled,title:a.title,"data-testid":a.testId,"aria-haspopup":a.page?"menu":void 0,onClick:l=>{if(l.stopPropagation(),a.page&&i){i(a.page);return}a.keepOpen||t(),a.onSelect()},className:I("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm outline-none hover:bg-accent focus-visible:bg-accent disabled:opacity-45 [&_svg]:size-3.5",a.destructive?"text-destructive":"text-foreground"),children:[a.icon,o.jsx("span",{className:"min-w-0 flex-1 truncate",children:a.label}),a.indicator?o.jsx("span",{"aria-label":"On",className:"size-1.5 shrink-0 rounded-full bg-highlight"}):null,a.hint?o.jsx("span",{className:"ml-3 font-mono text-xs text-muted-foreground",children:a.hint}):null,a.value?o.jsx("span",{className:"ml-3 max-w-[50%] truncate text-xs text-muted-foreground",children:a.value}):null,a.page?o.jsx(Jn,{"aria-hidden":!0,className:"text-muted-foreground"}):null,a.checked?o.jsx(oc,{"aria-hidden":!0,className:"ml-2 text-foreground"}):null]})]},a.id??a.label))})}function u1(s,t){return i=>{const a=Array.from(s.current?.querySelectorAll('[role^="menuitem"]:not([disabled])')??[]),l=a.indexOf(document.activeElement);i.key==="Escape"?(i.preventDefault(),i.stopPropagation(),t()):i.key==="ArrowDown"?(i.preventDefault(),a[(l+1)%a.length]?.focus()):i.key==="ArrowUp"?(i.preventDefault(),a[(l-1+a.length)%a.length]?.focus()):i.key==="Home"?(i.preventDefault(),a[0]?.focus()):i.key==="End"?(i.preventDefault(),a.at(-1)?.focus()):i.key==="Tab"&&t(!1)}}function d1({label:s,at:t,items:i,onClose:a,testId:l,fallbackFocus:u}){const d=b.useRef(null),[h,m]=b.useState({visibility:"hidden"}),p=b.useRef(null),x=b.useCallback((y=!0)=>{if(a(),!y)return;const w=p.current;w?.focus(),setTimeout(()=>{w&&!w.isConnected&&u?.()?.focus()},0)},[a,u]);return b.useLayoutEffect(()=>{if(!t)return;p.current=document.activeElement;const y=d.current?.offsetWidth??0,w=d.current?.offsetHeight??0;m({left:Math.max(8,Math.min(t.x,window.innerWidth-y-8)),top:Math.max(8,Math.min(t.y,window.innerHeight-w-8))})},[t]),b.useLayoutEffect(()=>{t&&h.visibility!=="hidden"&&d.current?.querySelector('[role^="menuitem"]:not([disabled])')?.focus()},[h]),b.useEffect(()=>{if(!t)return;const y=()=>x(!1),w=k=>{d.current?.contains(k.target)||x(!1)};return window.addEventListener("resize",y),window.addEventListener("scroll",y,!0),window.addEventListener("blur",y),document.addEventListener("pointerdown",w,!0),()=>{window.removeEventListener("resize",y),window.removeEventListener("scroll",y,!0),window.removeEventListener("blur",y),document.removeEventListener("pointerdown",w,!0)}},[t,x]),t?o.jsx("div",{ref:d,role:"menu","aria-label":s,"data-testid":l,onKeyDown:u1(d,x),onContextMenu:y=>y.preventDefault(),style:h,className:c1,children:o.jsx(Mf,{items:i,close:()=>x()})}):null}function Kt({label:s,title:t,trigger:i,triggerClassName:a,items:l,pages:u,width:d,align:h="end",onOpenChange:m,disabled:p,openRequest:x,onOpenRequestHandled:y,testId:w}){const[k,j]=b.useState(!1),[S,A]=b.useState(null),[R,q]=b.useState({}),O=b.useRef(null),L=b.useRef(null),B=b.useId(),_=b.useCallback(ee=>{j(ee),ee||A(null),m?.(ee)},[m]);b.useEffect(()=>{x&&(p||_(!0),y?.())},[x]);const Q=()=>Array.from(L.current?.querySelectorAll('[role^="menuitem"]:not([disabled])')??[]);b.useLayoutEffect(()=>{if(!k||!O.current)return;const ee=O.current.getBoundingClientRect(),xe=L.current?.offsetHeight??0,re=ee.bottom+4+xe<=window.innerHeight-8;q({top:re?ee.bottom+4:Math.max(8,ee.top-4-xe),...h==="end"?{right:Math.max(8,window.innerWidth-ee.right)}:{left:Math.max(8,ee.left)}})},[k,h]),b.useEffect(()=>{k&&Q()[0]?.focus()},[k,S]),b.useEffect(()=>{if(!k)return;const ee=()=>_(!1),xe=de=>{de.target instanceof Node&&de.target.contains(O.current)&&_(!1)};window.addEventListener("resize",ee),window.addEventListener("scroll",xe,!0);const re=de=>{!L.current?.contains(de.target)&&!O.current?.contains(de.target)&&_(!1)};return document.addEventListener("pointerdown",re),()=>{document.removeEventListener("pointerdown",re),window.removeEventListener("resize",ee),window.removeEventListener("scroll",xe,!0)}},[k,_]);const C=(ee=!0)=>{_(!1),ee&&O.current?.focus()},Y=S?u?.[S]:void 0,H=u1(L,C),fe=ee=>{if(Y&&(ee.key==="Escape"||ee.key==="ArrowLeft")){ee.preventDefault(),ee.stopPropagation(),A(null);return}H(ee)};return o.jsxs(o.Fragment,{children:[o.jsx("button",{ref:O,type:"button","aria-label":s,title:t??s,disabled:p,"aria-haspopup":"menu","aria-expanded":k,"aria-controls":k?B:void 0,"data-testid":w,onClick:ee=>{ee.stopPropagation(),_(!k)},onKeyDown:ee=>{ee.key==="ArrowDown"&&!k&&(ee.preventDefault(),_(!0))},className:a,children:i}),k?o.jsx("div",{ref:L,id:B,role:"menu","aria-label":Y?Y.title:s,onKeyDown:fe,style:d?{...R,width:d}:R,className:c1,"data-page":S??void 0,children:Y?o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",role:"menuitem",onClick:ee=>{ee.stopPropagation(),A(null)},"aria-label":`Back from ${Y.title}`,className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent [&_svg]:size-3.5",children:[o.jsx(nh,{"aria-hidden":!0}),Y.title]}),o.jsx("div",{role:"separator",className:"-mx-1 my-1 h-px bg-border"}),o.jsx(Mf,{items:Y.items,close:()=>C()})]}):o.jsx(Mf,{items:l,close:()=>C(),openPage:u?A:void 0})}):null]})}const b4=[{id:"general",title:"General"},{id:"workspaces",title:"Projects & Workspaces"},{id:"tabs-panes",title:"Tabs & Panes"},{id:"layout",title:"Layout"},{id:"agent-input",title:"Agent Input"}],xc=[{action:"command-center.toggle",combo:"Mod+K",section:"general",label:"Toggle command center"},{action:"command-center.files",combo:"Mod+P",section:"general",label:"Search files"},{action:"shortcuts.toggle",combo:"Shift+?",section:"general",label:"Show keyboard shortcuts",scope:"other",note:"Available when focus is not in a text field."},{action:"settings.toggle",combo:"Mod+,",section:"general",label:"Toggle settings"},{action:"session.new",combo:"Mod+N",section:"workspaces",label:"New session"},{action:"session.archive",combo:"Mod+Shift+Backspace",section:"workspaces",label:"Archive session"},{action:"session.index",combo:"Alt+Digit",section:"workspaces",label:"Jump to session",display:["alt","1-9"]},{action:"session.relative",combo:"Alt+[",delta:-1,section:"workspaces",label:"Previous session"},{action:"session.relative",combo:"Alt+]",delta:1,section:"workspaces",label:"Next session"},{action:"tab.menu",combo:"Mod+T",section:"tabs-panes",label:"New tab"},{action:"tab.agent",combo:"Mod+Shift+A",section:"tabs-panes",label:"New agent"},{action:"tab.changes",combo:"Mod+Shift+G",section:"tabs-panes",label:"Changes"},{action:"tab.files",combo:"Mod+Shift+E",section:"tabs-panes",label:"Files"},{action:"tab.terminal",combo:"Mod+Shift+T",section:"tabs-panes",label:"New terminal"},{action:"tab.close",combo:"Alt+Shift+W",section:"tabs-panes",label:"Close current tab"},{action:"tab.index",combo:"Alt+Shift+Digit",section:"tabs-panes",label:"Jump to tab",display:["alt","shift","1-9"]},{action:"tab.relative",combo:"Alt+Shift+[",delta:-1,section:"tabs-panes",label:"Previous tab"},{action:"tab.relative",combo:"Alt+Shift+]",delta:1,section:"tabs-panes",label:"Next tab"},{action:"pane.split.right",combo:"Cmd+\\",section:"tabs-panes",label:"Split pane right",mac:!0},{action:"pane.split.down",combo:"Cmd+Shift+\\",section:"tabs-panes",label:"Split pane down",mac:!0},{action:"pane.focus.left",combo:"Cmd+Shift+ArrowLeft",section:"tabs-panes",label:"Focus pane left",mac:!0,scope:"other"},{action:"pane.focus.right",combo:"Cmd+Shift+ArrowRight",section:"tabs-panes",label:"Focus pane right",mac:!0,scope:"other"},{action:"pane.focus.up",combo:"Cmd+Shift+ArrowUp",section:"tabs-panes",label:"Focus pane up",mac:!0,scope:"other"},{action:"pane.focus.down",combo:"Cmd+Shift+ArrowDown",section:"tabs-panes",label:"Focus pane down",mac:!0,scope:"other"},{action:"pane.move.left",combo:"Cmd+Alt+Shift+ArrowLeft",section:"tabs-panes",label:"Move tab left",mac:!0},{action:"pane.move.right",combo:"Cmd+Alt+Shift+ArrowRight",section:"tabs-panes",label:"Move tab right",mac:!0},{action:"pane.move.up",combo:"Cmd+Alt+Shift+ArrowUp",section:"tabs-panes",label:"Move tab up",mac:!0},{action:"pane.move.down",combo:"Cmd+Alt+Shift+ArrowDown",section:"tabs-panes",label:"Move tab down",mac:!0},{action:"pane.close",combo:"Cmd+Shift+W",section:"tabs-panes",label:"Close pane",mac:!0,note:"Some browsers keep this key to close the window."},{action:"sidebar.left",combo:"Mod+B",section:"layout",label:"Toggle left sidebar"},{action:"sidebar.right",combo:"Mod+E",section:"layout",label:"Toggle Explorer sidebar"},{action:"sidebar.right",combo:"Ctrl+`"},{action:"sidebar.both",combo:"Mod+.",section:"layout",label:"Toggle both sidebars"},{action:"composer.focus",combo:"Mod+L",section:"agent-input",label:"Focus message input",handledElsewhere:!0},{action:"composer.mode",combo:"Shift+Tab",section:"agent-input",label:"Cycle agent mode",handledElsewhere:!0},{action:"agent.interrupt",combo:"Escape",section:"agent-input",label:"Interrupt agent",handledElsewhere:!0}],Ey={"[":"BracketLeft","]":"BracketRight",",":"Comma",".":"Period","`":"Backquote","?":"Slash","\\":"Backslash"};function f1(s,t){const i=s.split("+"),a=i.pop()??"",l={meta:!1,ctrl:!1,alt:!1,shift:!1};for(const u of i)u==="Mod"?l[t?"meta":"ctrl"]=!0:u==="Cmd"?l.meta=!0:u==="Ctrl"?l.ctrl=!0:u==="Alt"?l.alt=!0:u==="Shift"&&(l.shift=!0);return{key:a,mods:l}}function v4(s,{mac:t,editable:i=!1,bindings:a=xc}){for(const l of a){if(l.handledElsewhere||l.mac&&!t||l.scope==="other"&&i)continue;const{key:u,mods:d}=f1(l.combo,t);if(!(s.metaKey!==d.meta||s.ctrlKey!==d.ctrl||s.altKey!==d.alt||s.shiftKey!==d.shift)){if(u==="Digit"){const h=/^Digit([1-9])$/.exec(s.code);if(h)return{binding:l,index:Number(h[1])};continue}if(u.length===1&&/[A-Za-z]/.test(u)?s.code===`Key${u.toUpperCase()}`:Ey[u]&&s.code===Ey[u]||s.key===u)return{binding:l}}}return null}function gh(s,t){if(s.display)return s.display;const{key:i,mods:a}=f1(s.combo,t),l=[];return a.ctrl&&l.push("ctrl"),a.meta&&l.push("mod"),a.alt&&l.push("alt"),a.shift&&i!=="?"&&l.push("shift"),l.push(i),l}const w4={Backspace:"⌫",Enter:"⏎",Escape:"Esc",Space:"␣",ArrowLeft:"←",ArrowRight:"→",ArrowUp:"↑",ArrowDown:"↓"};function xh(s,t){const i=l=>w4[l]??(l.length===1?l.toUpperCase():l);if(t){const l=["ctrl","alt","shift","mod"],u={ctrl:"⌃",alt:"⌥",shift:"⇧",mod:"⌘"};return l.filter(d=>s.includes(d)).map(d=>u[d]).join("")+s.filter(d=>!l.includes(d)).map(i).join("")}const a={mod:"Ctrl",ctrl:"Ctrl",alt:"Alt",shift:"Shift"};return s.map(l=>a[l]??i(l)).join("+")}function Pl(s,t){const i=xc.find(a=>a.action===s&&a.label&&(!a.mac||t));return i?xh(gh(i,t),t):""}function k4(s,t=""){const i=t.trim().toLowerCase();return b4.map(a=>({...a,rows:xc.filter(l=>l.section===a.id&&l.label&&(!l.mac||s)).map(l=>({id:`${l.action}:${l.combo}`,label:l.label,keys:xh(gh(l,s),s),...l.note?{note:l.note}:{}})).filter(l=>!i||l.label.toLowerCase().includes(i)||l.keys.toLowerCase().includes(i))})).filter(a=>a.rows.length)}function h1(s){const t=s;if(!t||typeof t.closest!="function")return!1;if(t.isContentEditable)return!0;const i=String(t.tagName??"").toLowerCase();return i==="textarea"||i==="select"?!0:i!=="input"?!1:!["button","checkbox","radio","submit","reset","range","color","file"].includes(String(t.type??"").toLowerCase())}function ho(){const s=globalThis.navigator;return/Mac|iPhone|iPad/.test(String(s?.platform||s?.userAgent||""))}const j4=[["needs_input","Needs input"],["failed","Failed"],["attention","Ready to review"],["running","Working"],["done","Done"]],S4=7,My=s=>{const t=Date.parse(s??"");return Number.isFinite(t)?t:0};function zy(s,t){const i=a=>My(t==="lastPrompt"?a.updatedAt??a.createdAt:a.createdAt);return[...s].sort((a,l)=>i(l)-i(a)||a.id.localeCompare(l.id))}function N4(s,t,i){const a=s.filter((l,u)=>u<S4||i(l)!=="done");return{visible:t?[...s]:a,canToggle:a.length<s.length}}function T4(s,t){return j4.map(([i,a])=>({bucket:i,label:a,sessions:s.filter(l=>t(l)===i)})).filter(i=>i.sessions.length>0)}function m1(s,t){return s.filter(i=>t.includes(i))}function A4(s,t){const i=m1(t,s);return i.length?s.filter(a=>i.includes(a)):[...s]}function p1(){return o.jsxs("span",{"aria-hidden":!0,className:"relative flex size-[14px] items-center justify-center",children:[o.jsx("span",{className:"absolute inset-[1px] rounded-full border-[1.5px] border-dot-running opacity-30"}),o.jsx("span",{className:"absolute inset-[1px] animate-spin rounded-full border-[1.5px] border-transparent border-t-dot-running opacity-90 [animation-duration:900ms]"}),o.jsx("span",{className:"size-1.5 rounded-full bg-dot-running"})]})}function yh({bucket:s}){const t=s==="running"?"Running":s==="needs_input"?"Waiting for your answer":s==="failed"?"Failed":s==="attention"?"Finished":"Idle";return o.jsxs("span",{className:"flex h-5 w-4 shrink-0 items-center justify-center",title:t,"data-status":s,children:[s==="running"?o.jsx(p1,{}):s==="needs_input"?o.jsx(si,{"aria-hidden":!0,className:"size-3 fill-dot-warning text-sidebar"}):o.jsx("span",{"aria-hidden":!0,className:I("size-1.5 rounded-full",s==="failed"?"bg-dot-danger":s==="attention"?"bg-dot-success":"bg-extra-muted opacity-30")}),o.jsx("span",{className:"sr-only",children:t})]})}function C4({workspaceId:s,managed:t,online:i,open:a,onClose:l}){const u=Oe(),[d,h]=b.useState(!1),m=R=>{l()},[p,x]=b.useState([]),[y,w]=b.useState(""),[k,j]=b.useState(""),S=async()=>{if(j(""),!t){h(!0);try{const R=await u.worktreeOptions(s);x(R),w(R[0]??"")}catch(R){j(R instanceof Error?R.message:String(R))}finally{h(!1)}}},A=async()=>{h(!0);try{await u.mutateWorktree(t?"remove":"create",s,t?void 0:y)?(m(!1),j("")):j("The operation is not confirmed. Retry to reconcile.")}finally{h(!1)}};return b.useEffect(()=>{a&&S()},[a]),o.jsxs(ai,{open:a,onClose:()=>{d||m()},title:t?"Remove managed worktree":"Create managed worktree",children:[o.jsx("p",{children:t?"Delete this checkout’s files. Its Git branch remains. Saved sessions, active work, claims, leases, results and dirty files prevent removal.":"Create a clean checkout from the current committed HEAD in a host-approved destination."}),t?null:p.length?o.jsxs("label",{className:"mt-2 block",children:["Destination",o.jsx("select",{"aria-label":"Worktree destination",className:"mt-1 w-full rounded border border-border bg-background p-1",value:y,onChange:R=>w(R.target.value),children:p.map(R=>o.jsx("option",{children:R},R))})]}):o.jsx("p",{className:"mt-2",children:d?"Loading destinations…":"Ask the host owner to configure a destination mapping and grant its ID to this credential."}),k?o.jsx("p",{role:"alert",className:"mt-2",children:k}):null,o.jsxs("div",{className:"mt-3 flex gap-3",children:[o.jsx("button",{type:"button",disabled:d||!i||!t&&!y,onClick:()=>{A()},children:d?"Working…":t?"Delete checkout files":"Create checkout"}),o.jsx("button",{type:"button",disabled:d,onClick:()=>m(),children:"Cancel"})]})]})}const Ry=["#7a6aa8","#3d7ea6","#388068","#a4673a","#b05c80","#6a70b8","#368080","#b06260","#8f7838","#5179b0"];function E4(s){let t=0;for(const i of s)t=t*31+i.charCodeAt(0)>>>0;return Ry[t%Ry.length]}const Dn="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",Ql="hover:bg-sidebar-hover active:bg-secondary",M4="https://github.com/phucanh08/alp/issues/new",z4="https://github.com/phucanh08/alp/releases";function ql({icon:s,label:t,onClick:i,disabled:a,title:l,active:u,shortcut:d,testId:h}){return o.jsx("div",{className:"px-2",children:o.jsxs("button",{type:"button",onClick:i,disabled:a,title:l,"aria-current":u?"page":void 0,"data-testid":h,className:I("group flex min-h-9 w-full items-center gap-2 rounded-lg px-2 py-1 md:min-h-7 text-left text-sm text-muted-foreground hover:text-foreground disabled:pointer-events-none disabled:opacity-45",Ql,u&&"bg-sidebar-hover text-foreground",Dn),children:[o.jsx(s,{"aria-hidden":!0,className:"size-[18px] shrink-0 md:size-3.5"}),o.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),d?o.jsx("kbd",{"aria-hidden":!0,className:"hidden rounded-md bg-secondary/50 px-1 py-px font-sans text-[length:calc(11px*var(--ui-scale))] leading-4 text-muted-foreground md:group-hover:inline",children:d}):null]})})}function R4({query:s,onQuery:t,open:i,onOpen:a,onClose:l,focusRequest:u,shortcut:d}){const h=b.useRef(null);return b.useEffect(()=>{i&&h.current?.focus()},[i,u]),i?o.jsx("div",{className:"px-2",children:o.jsxs("div",{className:"flex min-h-9 w-full items-center gap-2 rounded-lg bg-sidebar-hover px-2 py-1 md:min-h-7 focus-within:ring-1 focus-within:ring-border",children:[o.jsx(ti,{"aria-hidden":!0,className:"size-[18px] shrink-0 text-foreground md:size-3.5"}),o.jsx("input",{ref:h,type:"search",value:s,onChange:m=>t(m.target.value),"aria-label":"Search sessions",placeholder:"Search sessions…",onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),l())},onBlur:()=>{s.trim()||l()},className:"min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:hidden"}),o.jsx("button",{type:"button","aria-label":"Clear search",title:"Clear search",onMouseDown:m=>m.preventDefault(),onClick:l,className:I("-mr-1 flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-secondary hover:text-foreground",Dn),children:o.jsx(en,{"aria-hidden":!0,className:"size-3.5"})})]})}):o.jsx(ql,{icon:ti,label:"Search",onClick:a,shortcut:d})}function bh(s,t,i){return m4({status:s.status,waiting:t,reason:i})}function Zd({title:s,children:t,testId:i}){return o.jsxs("div",{className:"flex min-h-11 items-center justify-between gap-2 pl-2 pr-1 md:min-h-9","data-testid":i,children:[o.jsx("h2",{className:"select-none text-xs text-muted-foreground",children:s}),t]})}function _4({session:s,title:t,meta:i,trailing:a,bucket:l,selected:u,canWrite:d,onSelect:h,onRename:m,onArchive:p}){const[x,y]=b.useState(!1),w=s.status==="closed"?"Closed":`Updated ${Ri(s.updatedAt??s.createdAt)}`;return o.jsxs("li",{className:I("group relative mb-0.5 rounded-lg",u?"bg-sidebar-selected":"hover:bg-sidebar-hover active:bg-secondary",x&&!u&&"bg-sidebar-hover"),children:[o.jsxs("button",{type:"button",onClick:h,"aria-current":u?"true":void 0,"data-testid":"session-row",title:`${t} · ${w}`,className:I("flex min-h-11 w-full min-w-0 items-start gap-2 rounded-lg py-2 pl-4 pr-3 text-left md:min-h-9",d&&"max-md:pr-8",Dn),children:[o.jsx(yh,{bucket:l}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("span",{className:I("min-w-0 flex-1 truncate text-sm leading-5 text-foreground",u||x?"opacity-100":"opacity-[0.76] group-hover:opacity-100"),children:t}),a?o.jsx("span",{className:I("shrink-0 text-xs text-muted-foreground tabular-nums",d&&"md:group-hover:invisible",x&&"invisible"),"data-testid":"sidebar-workspace-timestamp",children:a}):null]}),i.length?o.jsx("span",{className:"mt-0.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 text-xs text-muted-foreground","data-testid":"sidebar-row-meta",children:i.map(k=>o.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1","data-meta":k.key,children:[o.jsx(k.icon,{"aria-hidden":!0,className:"size-3 shrink-0"}),o.jsx("span",{className:"truncate",children:k.text})]},k.key))}):null]})]}),d?o.jsxs("div",{className:I("absolute right-[5px] top-[13px] flex opacity-100 md:top-[9px] md:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100",x&&"opacity-100"),children:[o.jsx("span",{"aria-hidden":!0,className:I("pointer-events-none absolute inset-y-0 right-full hidden w-6 bg-linear-to-r md:block from-transparent",u?"to-sidebar-selected":"to-sidebar-hover")}),o.jsx(Kt,{label:`Actions for ${t}`,onOpenChange:y,trigger:o.jsx(_S,{"aria-hidden":!0,className:"size-3.5"}),triggerClassName:I("flex size-[18px] items-center justify-center rounded text-muted-foreground hover:bg-secondary hover:text-foreground",u?"bg-sidebar-selected":"bg-sidebar-hover",Dn),items:[{label:"Rename",icon:o.jsx(Ui,{"aria-hidden":!0}),onSelect:m},{label:"Archive",icon:o.jsx(ac,{"aria-hidden":!0}),onSelect:p,destructive:!0}]})]}):null]})}function L4({path:s,name:t,worktree:i,expanded:a,canWrite:l,actions:u,onToggle:d,onNewSession:h}){const[m,p]=b.useState(!1);return o.jsxs("div",{className:I("group relative mb-1 flex min-h-11 items-center rounded-lg md:min-h-9",Ql,m&&"bg-sidebar-hover"),children:[o.jsxs("button",{type:"button",onClick:d,"aria-expanded":a,title:s,"data-testid":"project-row","data-workspace":s,className:I("flex min-h-11 min-w-0 flex-1 items-center gap-2 rounded-lg p-2 pr-16 text-left md:min-h-9",Dn),children:[o.jsxs("span",{"aria-hidden":!0,className:"flex h-5 w-4 shrink-0 items-center justify-center",children:[i?o.jsx(Qs,{className:"size-3.5 text-muted-foreground group-hover:hidden group-focus-within:hidden"}):o.jsx("span",{className:"flex size-4 items-center justify-center rounded-[4px] text-[length:calc(9px*var(--ui-scale))] font-medium leading-none text-white group-hover:hidden group-focus-within:hidden",style:{backgroundColor:E4(s)},children:t.slice(0,1).toUpperCase()}),o.jsx("span",{className:I("hidden size-3.5 text-muted-foreground group-hover:block group-focus-within:block transition-transform",a?"rotate-90":""),children:"›"})]}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-muted-foreground",children:t})]}),o.jsxs("div",{className:I("absolute right-1.5 flex items-center gap-0.5 md:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100",m&&"opacity-100"),children:[u.length?o.jsx(Kt,{label:`Project actions for ${t}`,title:"Project actions",onOpenChange:p,testId:"project-actions",trigger:o.jsx(sh,{"aria-hidden":!0,className:"size-[15px]"}),items:u,triggerClassName:I("flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-secondary hover:text-foreground",Dn)}):null,l?o.jsx("button",{type:"button",onClick:h,"aria-label":`Start a session in ${t}`,title:`New session in ${t}`,className:I("flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-secondary hover:text-foreground",Dn),children:o.jsx(ks,{"aria-hidden":!0,className:"size-[15px]"})}):null]})]})}const zf=I("relative flex size-11 items-center justify-center rounded-md text-muted-foreground hover:text-foreground md:size-7 [&_svg]:size-5 md:[&_svg]:size-4",Dn);function Jd({label:s,title:t,onClick:i,children:a,testId:l}){return o.jsx("button",{type:"button","aria-label":s,title:t??s,onClick:i,"data-testid":l,className:zf,children:a})}function O4({display:s,projects:t,onChange:i}){const a=m1(s.projectFilters,t),l=h=>i({projectFilters:a.includes(h)?a.filter(m=>m!==h):[...a,h]}),u={grouping:{title:"Grouping",items:[{label:"Project",icon:o.jsx(Da,{"aria-hidden":!0}),checked:s.grouping==="project",onSelect:()=>i({grouping:"project"}),testId:"sidebar-grouping-project"},{label:"Status",icon:o.jsx(t0,{"aria-hidden":!0}),checked:s.grouping==="status",onSelect:()=>i({grouping:"status"}),testId:"sidebar-grouping-status"}]},sort:{title:"Sort",items:[{label:"Created",checked:s.sort==="created",onSelect:()=>i({sort:"created"}),testId:"sidebar-sort-created"},{label:"Last prompt",checked:s.sort==="lastPrompt",onSelect:()=>i({sort:"lastPrompt"}),testId:"sidebar-sort-lastPrompt"}]},titleSource:{title:"Title",items:[{label:"Title",icon:o.jsx(hN,{"aria-hidden":!0}),checked:s.titleSource==="title",onSelect:()=>i({titleSource:"title"}),testId:"sidebar-workspace-title-source-title"},{label:"Branch name",icon:o.jsx(Qs,{"aria-hidden":!0}),checked:s.titleSource==="branch",onSelect:()=>i({titleSource:"branch"}),testId:"sidebar-workspace-title-source-branch"}]},show:{title:"Show",items:[...[["branch","Branch",Qs],["project","Project",Da],["host","Host",Qr],["labels","Labels",h0]].map(([h,m,p])=>({label:m,icon:o.jsx(p,{"aria-hidden":!0}),checked:s.rowItems[h],keepOpen:!0,testId:`sidebar-row-item-${h}`,onSelect:()=>i({rowItems:{...s.rowItems,[h]:!s.rowItems[h]}})})),{label:"Last activity",icon:o.jsx(ES,{"aria-hidden":!0}),checked:s.trailing==="timestamp",keepOpen:!0,group:!0,testId:"sidebar-workspace-trailing-timestamp",onSelect:()=>i({trailing:s.trailing==="timestamp"?"none":"timestamp"})}]},projectFilter:{title:"Project",items:[{label:"All projects",checked:a.length===0,keepOpen:!0,onSelect:()=>i({projectFilters:[]}),testId:"sidebar-project-filter-all"},...t.map((h,m)=>({id:h,label:Dt(h),title:h,checked:a.includes(h),keepOpen:!0,group:m===0,onSelect:()=>l(h),testId:"sidebar-project-filter-item"}))]}},d=[{label:"Grouping",page:"grouping",value:s.grouping==="project"?"Project":"Status",onSelect:()=>{},testId:"sidebar-display-grouping"},...s.grouping==="project"?[{label:"Sort",page:"sort",value:s.sort==="created"?"Created":"Last prompt",onSelect:()=>{},testId:"sidebar-display-sort"}]:[],{label:"Title",page:"titleSource",value:s.titleSource==="title"?"Title":"Branch name",onSelect:()=>{},testId:"sidebar-display-title-source"},{label:"Show",page:"show",onSelect:()=>{},testId:"sidebar-display-show"},...t.length>1?[{label:"Project",page:"projectFilter",indicator:a.length>0,group:!0,onSelect:()=>{},testId:"sidebar-display-project-filter"}]:[]];return o.jsx(Kt,{label:"Display preferences",align:"end",width:232,items:d,pages:u,testId:"sidebar-display-preferences-menu",trigger:o.jsx(iN,{"aria-hidden":!0,className:"size-3.5"}),triggerClassName:I("flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-sidebar-hover hover:text-foreground",Dn)})}function D4({open:s,onClose:t,unregistered:i}){const a=Oe(),{principal:l,connection:u,registry:d}=Ee(),[h,m]=b.useState("");b.useEffect(()=>{s&&m(i[0]??"")},[s]);const p=Te(l??void 0,"workspace.write"),x=u.capabilities.includes("workspace.registry"),y=async()=>{h&&(await a.registerProject(h),t())};return o.jsx(ai,{open:s,onClose:t,title:"Add project",description:"A project is a directory the host owner granted to this access token. Adding it puts it in the host's shared workspace list. For another directory, the owner grants it first (alp-gateway credential create --workspace).",footer:x&&p&&i.length?o.jsxs(o.Fragment,{children:[o.jsx(we,{variant:"ghost",onClick:t,children:"Cancel"}),o.jsx(we,{disabled:!h||u.phase!=="open"||!!d.loading,onClick:()=>{y()},children:"Register project"})]}):o.jsx(we,{variant:"secondary",onClick:t,children:"Close"}),children:x?p?i.length?o.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[o.jsx("span",{className:"text-xs text-muted-foreground",children:"Existing granted directory"}),o.jsx("select",{"aria-label":"Existing granted directory",value:h,onChange:w=>m(w.target.value),className:"w-full rounded-md border border-input bg-background p-2 text-sm",children:i.map(w=>o.jsx("option",{value:w,children:w},w))})]}):o.jsx("p",{className:"text-sm text-muted-foreground",children:"Every directory this token grants is already a project."}):o.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"Ask the host owner to add workspace.write to your credential."}):o.jsx("p",{className:"text-sm text-muted-foreground",children:"This host does not list its workspaces. Update ALP on the host."})})}function q4({row:s,onClose:t}){const i=Oe(),[a,l]=b.useState("");b.useEffect(()=>{l(s?.title??"")},[s]);const u=async()=>{s&&await i.renameWorkspace(s.id,a)&&t()};return o.jsx(ai,{open:!!s,onClose:t,title:"Rename workspace",footer:o.jsxs(o.Fragment,{children:[o.jsx(we,{variant:"ghost",onClick:t,children:"Cancel"}),o.jsx(we,{onClick:()=>{u()},children:"Rename"})]}),children:o.jsx("form",{onSubmit:d=>{d.preventDefault(),u()},children:o.jsx(Zn,{"aria-label":"Workspace name",value:a,maxLength:200,placeholder:s?Dt(s.directory):"",onChange:d=>l(d.target.value),autoFocus:!0})})})}function B4({onNewSession:s,onRename:t,onArchive:i,onSettings:a,onShortcuts:l,onNavigate:u,onClose:d,onHistory:h,historyOpen:m,onTasks:p,tasksOpen:x,onOpenSession:y,searchRequest:w,onSearchRequestHandled:k}){const j=Oe(),S=Ee(),{principal:A,workspace:R,sessions:q,selected:O,connection:L,preferences:B}=S,_=B.sidebarDisplay,Q=b.useMemo(()=>ho(),[]),[C,Y]=b.useState(!1),[H,fe]=b.useState(!1),[ee,xe]=b.useState(""),[re,de]=b.useState({}),[U,Z]=b.useState(!1),[oe,ge]=b.useState(null),[T,z]=b.useState(null),F=Te(A??void 0,"session.write"),J=Te(A??void 0,"workspace.write"),le=L.capabilities.includes("workspace.worktree")&&Te(A??void 0,"workspace.manage"),ne=L.phase==="open",ce=S.registry,ve=E=>ce.workspaces.filter(V=>!V.archivedAt&&(V.directory===E||A?.workspaceRoots?.some(ue=>ue.path===E&&ue.canonical===V.directory))).sort((V,ue)=>V.createdAt.localeCompare(ue.createdAt)||V.id.localeCompare(ue.id)),Re=[...new Set([...A?.workspaces??[],...ce.workspaces.filter(E=>E.managedWorktree&&!E.archivedAt).map(E=>E.directory)])],Me=A4(Re,_.projectFilters),Qe=Me.filter(E=>!!ve(E)[0]?.pinnedAt),Ue=Me.filter(E=>!Qe.includes(E)),et=(A?.workspaces??[]).filter(E=>!ve(E).length),Fe=ee.trim().toLowerCase(),be=E=>!Fe||Wn(E).toLowerCase().includes(Fe),[ye,Ae]=b.useState({}),Ne=Re.filter(E=>E!==R).join(`
28
28
  `);b.useEffect(()=>{if(_.grouping!=="status"||!ne)return;let E=!0;const V=()=>{j.listWorkspaceSessions(Ne?Ne.split(`
29
- `):[]).then(he=>{E&&Ae(he)})};V();const ue=setInterval(V,15e3);return()=>{E=!1,clearInterval(ue)}},[j,_.grouping,ne,Ne]);const Ht=E=>j.updatePreferences({sidebarDisplay:{..._,...E}}),cn=E=>{if(E===R){Y(V=>!V);return}Y(!1),j.selectWorkspace(E)},ze=E=>{E!==R&&(Y(!1),j.selectWorkspace(E)),s(),u()},ut=(E,V)=>{E!==R&&j.selectWorkspace(E),j.selectSession(V),y(),u()},At=()=>{xe(""),fe(!1)},[Rt,In]=b.useState(0);b.useEffect(()=>{w&&(fe(!0),Y(!1),In(E=>E+1),k?.())},[w]);const kn=L.hostname??L.gateway.replace(/^https?:\/\//,""),Qt=(E,V)=>{navigator.clipboard?.writeText(E).then(()=>j.notify("info",`${V} copied`),()=>j.notify("error",`Could not copy the ${V.toLowerCase()}.`))},Je=E=>ve(E)[0],jt=E=>Je(E)?.title||Dt(E),St=(E,V)=>{const ue=Je(E),he=ue?.branch||void 0,pe=[];return _.rowItems.branch&&he&&pe.push({key:"branch",icon:Qs,text:he}),_.rowItems.project&&pe.push({key:"project",icon:Da,text:jt(E)}),_.rowItems.host&&pe.push({key:"host",icon:Qr,text:kn}),_.rowItems.labels&&ue?.labels.length&&pe.push({key:"labels",icon:h0,text:ue.labels.join(", ")}),{title:_.titleSource==="branch"&&he?he:Wn(V),meta:pe,trailing:_.trailing==="timestamp"?S3(V.updatedAt??V.createdAt):""}},un=E=>bh(E,ic(S,E.id),ao(S,E.id)),Gn=(E,V)=>{const ue=St(E,V);return o.jsx(_4,{session:V,title:ue.title,meta:ue.meta,trailing:ue.trailing,selected:V.id===O&&!m,canWrite:F,bucket:un(V),onSelect:()=>ut(E,V.id),onRename:()=>t(V),onArchive:()=>i(V)},V.id)},js=E=>{const V=Je(E),ue=[];if(V){const he=J?void 0:"Ask the host owner for workspace.write to change shared pins and names.";ue.push({label:V.pinnedAt?"Unpin":"Pin to top",icon:V.pinnedAt?o.jsx(JS,{"aria-hidden":!0}):o.jsx(u0,{"aria-hidden":!0}),disabled:!J||!ne,title:he,onSelect:()=>{j.pinWorkspace(V.id,!V.pinnedAt)},testId:V.pinnedAt?"project-unpin":"project-pin"},{label:"Rename workspace",icon:o.jsx(Ui,{"aria-hidden":!0}),disabled:!J||!ne,title:he,onSelect:()=>ge(V),testId:"project-rename"})}else L.capabilities.includes("workspace.registry")&&J&&(A?.workspaces??[]).includes(E)&&ue.push({label:"Add to projects",icon:o.jsx(cy,{"aria-hidden":!0}),disabled:!ne,onSelect:()=>{j.registerProject(E)},testId:"project-register"});return ue.push({label:"Copy path",icon:o.jsx(ws,{"aria-hidden":!0}),group:ue.length>0,onSelect:()=>Qt(E,"Path"),testId:"project-copy-path"}),V?.branch&&ue.push({label:"Copy branch name",icon:o.jsx(Qs,{"aria-hidden":!0}),onSelect:()=>Qt(V.branch,"Branch name"),testId:"project-copy-branch"}),V&&le&&ue.push({label:V.managedWorktree?"Remove worktree":"Create worktree",icon:o.jsx(Qs,{"aria-hidden":!0}),group:!0,disabled:!ne,onSelect:()=>z({row:V}),testId:V.managedWorktree?"project-remove-worktree":"project-create-worktree"}),ue.push({label:"Open project settings",icon:o.jsx(DS,{"aria-hidden":!0}),group:!0,onSelect:()=>a("projects"),testId:"project-settings"}),ue},dn=E=>{const V=E===R&&(!C||!!Fe),ue=Je(E),he=zy(q.list.filter(be),_.sort),pe=N4(he,!!re[E]||!!Fe,un);return o.jsxs("div",{className:I(V&&"pb-3"),"data-testid":"sidebar-project","data-path":E,"data-workspace-id":ue?.id,"data-pinned":ue?.pinnedAt?"true":void 0,"data-branch":ue?.branch??void 0,"data-worktree":ue?.managedWorktree?"true":void 0,children:[o.jsx(L4,{path:E,name:jt(E),worktree:!!ue?.managedWorktree,expanded:V,canWrite:F&&ne,actions:js(E),onToggle:()=>cn(E),onNewSession:()=>ze(E)}),V?o.jsxs("div",{children:[q.status==="loading"&&!q.list.length?o.jsx("div",{className:"py-2 pl-4",children:o.jsx(Ft,{label:"Loading sessions…",className:"text-xs"})}):null,q.status==="error"?o.jsxs("div",{className:"mx-1 mb-1 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive",role:"alert",children:[q.error?.message," ",o.jsx("button",{type:"button",className:"text-highlight underline-offset-4 hover:underline",onClick:()=>{j.refreshSessions()},children:"Try again"})]}):null,q.status==="ready"&&!q.list.length?F&&ne?o.jsxs("button",{type:"button",onClick:()=>ze(E),"aria-label":`Start a session in ${jt(E)}`,className:I("group mb-0.5 flex min-h-11 w-full items-center md:min-h-9 gap-2 rounded-lg py-2 pl-4 pr-3 text-left text-sm text-muted-foreground hover:text-foreground",Ql,Dn),children:[o.jsx("span",{className:"flex h-5 w-4 shrink-0 items-center justify-center",children:o.jsx(ks,{"aria-hidden":!0,className:"size-3.5"})}),o.jsx("span",{className:"truncate",children:"New session"})]}):o.jsx("p",{className:"flex min-h-9 items-center py-2 pl-10 pr-3 text-sm text-muted-foreground",children:"No sessions yet"}):null,Fe&&q.list.length&&!he.length?o.jsxs("p",{className:"flex min-h-9 items-center py-2 pl-10 pr-3 text-sm text-muted-foreground",children:["No sessions match “",ee.trim(),"”"]}):null,o.jsx("ul",{children:pe.visible.map($e=>Gn(E,$e))}),pe.canToggle||re[E]?o.jsx("button",{type:"button",onClick:()=>de($e=>({...$e,[E]:!$e[E]})),"data-testid":"sidebar-show-more",className:I("flex min-h-9 w-full items-center rounded-lg py-1 pl-10 pr-3 text-left text-xs text-muted-foreground hover:text-foreground",Ql,Dn),children:re[E]?"Show less":"Show more"}):null]}):null]},E)},fn=()=>{const E=[...R?q.list.map(he=>({path:R,session:he})):[],...Object.entries(ye).filter(([he])=>Me.includes(he)&&he!==R).flatMap(([he,pe])=>pe.map($e=>({path:he,session:$e})))].filter(he=>Me.includes(he.path)&&be(he.session)),V=zy(E.map(he=>he.session),"lastPrompt").map(he=>E.find(pe=>pe.session===he)),ue=T4(V.map(he=>he.session),un);return ue.length?ue.map(he=>o.jsxs("div",{"data-testid":`sidebar-status-${he.bucket}`,children:[o.jsx(Zd,{title:he.label}),o.jsx("ul",{children:he.sessions.map(pe=>{const $e=V.find(We=>We.session===pe);return Gn($e.path,pe)})})]},he.bucket)):o.jsx("p",{className:"px-2 py-3 text-sm text-muted-foreground",children:Fe?`No sessions match “${ee.trim()}”`:"No sessions yet"})},Ct=E=>{switch(E){case"new-session":return o.jsx(ql,{icon:ks,label:"New session",onClick:()=>{s(),u()},disabled:!R||!F||!ne,title:F?void 0:"Your access token cannot start sessions.",shortcut:Pl("session.new",Q)});case"history":return o.jsx(ql,{icon:cc,label:"History",onClick:()=>{h(),u()},active:m,disabled:!R,testId:"sidebar-history"});case"search":return o.jsx(R4,{query:ee,onQuery:xe,open:H,onOpen:()=>{fe(!0),Y(!1)},onClose:At,focusRequest:Rt});case"tasks":return o.jsx(ql,{icon:oh,label:"Tasks",onClick:()=>{p?.(),u()},active:x,disabled:!R||!p,testId:"sidebar-tasks"})}},jn=B.sidebar.footer.filter(E=>E.visible);return o.jsxs("nav",{"aria-label":"Workspaces and sessions",className:"relative flex h-full min-h-0 flex-col bg-sidebar",children:[o.jsx("div",{className:"flex shrink-0 flex-col gap-0.5 border-b border-border pb-1.5 pt-2",children:B.sidebar.header.filter(E=>E.visible).map(E=>o.jsx(b.Fragment,{children:Ct(E.id)},E.id))}),d?o.jsx("button",{type:"button","aria-label":"Close sessions",onClick:d,className:I("absolute right-[9.5px] top-3 z-10 flex size-8 items-center justify-center rounded-lg bg-sidebar text-muted-foreground hover:text-foreground",Dn),children:o.jsx(en,{"aria-hidden":!0,className:"size-4"})}):null,o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-4 pt-0.5",children:[_.grouping==="project"&&Qe.length?o.jsxs("div",{"data-testid":"sidebar-pinned",children:[o.jsx(Zd,{title:"Pinned",testId:"sidebar-pinned-header"}),Qe.map(dn)]}):null,o.jsx(Zd,{title:"Workspaces",children:o.jsx(O4,{display:_,projects:Re,onChange:Ht})}),ce.error?o.jsxs("p",{role:"alert",className:"px-2 pb-2 text-xs text-destructive",children:[ce.error," ",o.jsx("button",{type:"button",className:"underline",onClick:()=>{j.refreshRegistry()},children:"Retry"})]}):null,Re.length?_.grouping==="status"?fn():Ue.map(dn):o.jsxs("div",{className:"mt-1 px-2 py-3 text-sm","data-testid":"sidebar-no-projects",children:[o.jsx("p",{className:"text-foreground",children:"No projects yet"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"This access token grants no workspace. The host owner adds one with alp-gateway credential create --workspace."})]})]}),jn.length?o.jsx("div",{className:"flex shrink-0 flex-col gap-0.5 border-t border-border py-1.5","data-testid":"sidebar-footer-items",children:jn.map(E=>o.jsx(b.Fragment,{children:Ct(E.id)},E.id))}):null,o.jsxs("div",{className:"flex shrink-0 items-center border-t border-border px-2 py-1.5","data-testid":"sidebar-footer-bottom-line",children:[o.jsx(Jd,{label:"Add project",onClick:()=>Z(!0),testId:"sidebar-add-project",children:o.jsx(cy,{"aria-hidden":!0})}),o.jsx(Jd,{label:"Usage",onClick:()=>a("usage"),testId:"sidebar-usage-icon",children:o.jsx(TS,{"aria-hidden":!0})}),o.jsx(Kt,{label:"Hosts",title:`${A?.label??"Access token"} · ${kn}${ne?"":" · reconnecting"}`,align:"start",testId:"sidebar-hosts-trigger",trigger:o.jsxs(o.Fragment,{children:[o.jsx(Qr,{"aria-hidden":!0,className:"!size-[19px] md:!size-[15px]"}),o.jsx("span",{"aria-hidden":!0,className:I("absolute bottom-[11px] right-[11px] size-1.5 md:bottom-[5px] md:right-[5px] rounded-full ring-2 ring-sidebar",ne?"bg-dot-success":"bg-dot-warning")})]}),triggerClassName:zf,items:[{label:kn,icon:o.jsx(Qr,{"aria-hidden":!0}),hint:ne?"Online":"Reconnecting",onSelect:()=>a("host"),testId:"sidebar-host-option"},{label:"Connections",icon:o.jsx(c0,{"aria-hidden":!0}),onSelect:()=>a("connections")},{label:"Disconnect",icon:o.jsx(VS,{"aria-hidden":!0}),destructive:!0,group:!0,onSelect:()=>j.disconnect(),testId:"sidebar-disconnect"}]}),o.jsx("span",{className:"flex-1"}),o.jsx(Kt,{label:"Help and support",align:"start",testId:"sidebar-help-trigger",trigger:o.jsx(AS,{"aria-hidden":!0}),triggerClassName:zf,items:[{label:"Run diagnostics",onSelect:()=>a("diagnostics")},...l?[{label:"Keyboard shortcuts",hint:Pl("shortcuts.toggle",Q)||void 0,onSelect:l}]:[],{label:"Report an issue",group:!0,onSelect:()=>{window.open(M4,"_blank","noopener,noreferrer")}},{label:"What's new",onSelect:()=>{window.open(z4,"_blank","noopener,noreferrer")}}]}),o.jsx(Jd,{label:"Settings",onClick:()=>a(),testId:"sidebar-settings",children:o.jsx(ch,{"aria-hidden":!0})})]}),o.jsx(D4,{open:U,onClose:()=>Z(!1),unregistered:et}),o.jsx(q4,{row:oe,onClose:()=>ge(null)}),T?o.jsx(C4,{workspaceId:T.row.id,managed:!!T.row.managedWorktree,online:ne,open:!0,onClose:()=>z(null)}):null]})}const $4=6e3,Wr=()=>typeof window<"u"&&"Notification"in window;function U4(){const[s,t]=b.useState(()=>Wr()?Notification.permission:"unsupported");b.useEffect(()=>{if(!Wr())return;const a=()=>t(Notification.permission);return window.addEventListener("focus",a),document.addEventListener("visibilitychange",a),()=>{window.removeEventListener("focus",a),document.removeEventListener("visibilitychange",a)}},[]);const i=b.useCallback(async()=>{if(Wr())try{t(await Notification.requestPermission())}catch{t(Notification.permission)}},[]);return{permission:s,request:i}}function H4({onOpenSession:s}){const t=Ee(),i=Oe(),{workspace:a,sessions:l,tree:u,attention:d,selected:h,focus:m}=t,p=b.useMemo(()=>fS(t),[t.turnAttention,l,u]);b.useEffect(()=>{const O=()=>i.setPresence({visible:document.visibilityState==="visible",focused:document.hasFocus()});return O(),window.addEventListener("focus",O),window.addEventListener("blur",O),document.addEventListener("visibilitychange",O),()=>{window.removeEventListener("focus",O),window.removeEventListener("blur",O),document.removeEventListener("visibilitychange",O)}},[i]);const x=p4(l.list.map(O=>bh(O,ic(t,O.id),ao(t,O.id))),Object.keys(p).length>0);b.useEffect(()=>{let O=document.querySelector('link[rel="icon"]');O||(O=document.createElement("link"),O.rel="icon",document.head.append(O)),O.type="image/svg+xml",O.href=Ml[x],O.dataset.status=x},[x]),b.useEffect(()=>()=>{const O=document.querySelector('link[rel="icon"]');O&&(O.href=Ml.none,O.dataset.status="none")},[]);const y=u?.rootId,w=y?l.list.find(O=>O.id===y):void 0,k=y?Wn({id:y,title:u?.projection.sessions[y]?.title??w?.title}):a?Dt(a):"ALP";b.useEffect(()=>(document.title=k,()=>{document.title="ALP"}),[k]);const j=b.useRef({attention:d,live:{}}),S=b.useMemo(()=>{const O=j.current;O.attention!==d&&(O.live={}),O.attention=d;const L={...d};for(const[B,_]of Object.entries(O.live))L[B]=Math.max(L[B]??0,_);if(u){const B=Object.keys(u.projection.questions).length;L[u.rootId]=u.status==="attached"?B:Math.max(B,d[u.rootId]??0),u.status==="attached"&&(O.live[u.rootId]=B)}return L},[d,u]),A=b.useRef({workspace:null,since:Date.now(),counts:{}}),R=b.useRef(s);R.current=s,b.useEffect(()=>{const O=A.current;if(O.workspace!==a){A.current={workspace:a,since:Date.now(),counts:S};return}const L=y4(O.counts,S);if(O.counts=S,!L.length||!Wr()||Notification.permission!=="granted")return;const B=Date.now()-O.since<$4,_={visible:document.visibilityState==="visible",focused:document.hasFocus(),shown:m??h};for(const Q of L){const Y=(u?.rootId===Q?Object.values(u.projection.questions):[]).sort((fe,ee)=>(Date.parse(ee.askedAt??"")||0)-(Date.parse(fe.askedAt??"")||0))[0];if(B&&!(Y&&(Date.parse(Y.askedAt??"")||0)>=O.since)||Cy(_,Q)||Y?.sessionId&&Cy(_,Y.sessionId))continue;const H=Wn(l.list.find(fe=>fe.id===Q)??{id:Q,title:u?.rootId===Q?u.projection.sessions[Q]?.title:void 0});try{const fe=new Notification("Agent needs attention",{body:`${H}: ${Y?.body?l1(Y.body):"Waiting for your answer."}`,tag:`alp-question-${Q}`,icon:Ml.attention});fe.onclick=()=>{window.focus(),R.current(Q),fe.close()}}catch{}}},[S,a,u,l,h,m]);const q=b.useRef({workspace:a,entries:p});b.useEffect(()=>{const O=q.current,L=O.workspace===a?x4(O.entries,p):[];if(q.current={workspace:a,entries:p},!(!L.length||!Wr()||Notification.permission!=="granted"))for(const B of L){const _=p[B];if(!_)continue;const Q=Wn(l.list.find(fe=>fe.id===B)??{id:B,title:u?.rootId===B?u.projection.sessions[B]?.title:void 0}),{title:C,body:Y,tag:H}=g4({root:B,name:Q,reason:_.reason,message:_.message});try{const fe=new Notification(C,{body:Y,tag:H,icon:Ml.attention});fe.onclick=()=>{window.focus(),R.current(B),fe.close()}}catch{}}},[p,a,l,u])}const g1=[{id:"general",label:"General",icon:ch},{id:"appearance",label:"Appearance",icon:QS},{id:"sidebar",label:"Sidebar",icon:$a},{id:"chat",label:"Chat",icon:FS},{id:"terminal",label:"Terminal",icon:hc},{id:"editor",label:"Editor",icon:MS},{id:"files",label:"Files",icon:ah},{id:"diagnostics",label:"Diagnostics",icon:dN},{id:"about",label:"About",icon:rh}],x1=[{id:"host",label:"Overview",icon:Qr},{id:"projects",label:"Projects",icon:ly},{id:"connections",label:"Connections",icon:c0},{id:"pair-device",label:"Pair device",icon:oN},{id:"alp-templates",label:"Templates",icon:Yl},{id:"alp-agents",label:"Agents",icon:Oa},{id:"alp-skills",label:"Skills",icon:jS},{id:"alp-hooks",label:"Hooks",icon:mN},{id:"alp-mcp",label:"MCP servers",icon:tN},{id:"metadata",label:"Metadata",icon:cN},{id:"voice",label:"Voice",icon:XS},{id:"workspaces",label:"Workspaces",icon:ly},{id:"providers",label:"Providers",icon:SS},{id:"usage",label:"Usage",icon:BS},{id:"terminals",label:"Terminals",icon:hc},{id:"plugins",label:"Plugins",icon:kS}],I4=Object.fromEntries([...g1,...x1].map(s=>[s.id,s.label])),G4={"new-session":{label:"New session",icon:ks},history:{label:"History",icon:cc},search:{label:"Search",icon:ti},tasks:{label:"Tasks",icon:oh}},Y4="Readable **content** and `code` preview.\n\n```ts\n// The highlight theme, code font and code size\nexport function greet(name: string): string {\n return `Hello, ${name}!`;\n}\n```";function V4(){return o.jsx("section",{className:"mb-6 rounded-lg border border-border bg-background p-4","aria-label":"Live preview of content typography, syntax theme, and code font","data-testid":"appearance-preview",children:o.jsx(fo,{text:Y4})})}const yc="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset";function rt({title:s,action:t,children:i}){return o.jsxs("section",{className:"mb-6",children:[s||t?o.jsxs("div",{className:"mb-3 ml-1 flex items-center justify-between gap-2",children:[s?o.jsx("h3",{className:"text-xs font-normal text-muted-foreground",children:s}):o.jsx("span",{}),t]}):null,o.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card",children:i})]})}function He({title:s,hint:t,children:i,first:a}){return o.jsxs("div",{className:I("flex flex-wrap items-center justify-between gap-3 p-4",!a&&"border-t border-border"),children:[o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"text-sm text-foreground",children:s}),t?o.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:t}):null]}),i!==void 0?o.jsx("div",{className:"min-w-0 max-w-full text-sm text-muted-foreground",children:i}):null]})}function ln({what:s,why:t}){return o.jsx(rt,{children:o.jsxs("div",{className:"flex items-start gap-3 p-4",role:"note",children:[o.jsx(rc,{"aria-hidden":!0,className:"mt-0.5 size-4 shrink-0 text-muted-foreground"}),o.jsxs("div",{children:[o.jsxs("p",{className:"text-sm",children:[s," is not available in this beta"]}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t})]})]})})}function La({label:s,value:t,options:i,onChange:a}){return o.jsx(ph,{"aria-label":s,value:t,onChange:l=>a?.(l.target.value),disabled:!a,className:"h-8 w-auto rounded-lg border-border bg-transparent pl-3 text-sm text-foreground disabled:cursor-default disabled:opacity-100",children:i.map(l=>o.jsx("option",{value:l.value,children:l.label},l.value))})}function K4(){const{permission:s,request:t}=U4(),i=s==="unsupported"?"This browser cannot show notifications.":s==="denied"?"Blocked in this browser. Allow notifications for this site in the browser settings to get them.":s==="granted"?"On: a notification when a session waits for your answer while you are elsewhere. The tab icon shows it too.":"Get a notification when a session waits for your answer while you are elsewhere. The browser asks first.";return o.jsx(He,{title:"Notifications",hint:i,children:s==="default"?o.jsx(we,{size:"sm",variant:"secondary",onClick:()=>{t()},children:"Enable"}):o.jsx("span",{className:"text-sm text-muted-foreground","data-testid":"notification-permission",children:s==="granted"?"Allowed":s==="denied"?"Blocked":"Unavailable"})})}function F4(s,t,i){return t==="mod-enter"?s==="interrupt"?`When the agent is running, ${i}+Enter interrupts. Enter inserts a new line.`:s==="queue"?`When the agent is running, ${i}+Enter queues. Enter inserts a new line.`:`When the agent is running, ${i}+Enter steers the active turn. Enter inserts a new line.`:s==="interrupt"?"When the agent is running, Enter interrupts. Command/Ctrl+Enter queues.":s==="queue"?"When the agent is running, Enter queues. Command/Ctrl+Enter submits.":"When the agent is running, Enter steers the active turn. Command/Ctrl+Enter queues."}const _y=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent)?"⌘":"Ctrl";function X4({mobile:s}){const t=Oe(),{preferences:i}=Ee();return o.jsxs(o.Fragment,{children:[o.jsx(rt,{title:"General",children:o.jsx(He,{first:!0,title:"Language",hint:"App language. This beta speaks English; the agents' language is a host setting (Host › Overview).",children:o.jsx(La,{label:"Language",value:"system",options:[{value:"system",label:"System"}]})})}),o.jsxs(rt,{title:"Sending",children:[s?null:o.jsx(He,{first:!0,title:"Send shortcut",children:o.jsx(La,{label:"Send shortcut",value:i.sendShortcut,onChange:a=>t.updatePreferences({sendShortcut:a}),options:[{value:"enter",label:"Enter"},{value:"mod-enter",label:`${_y}+Enter`}]})}),o.jsx(He,{first:s,title:"Default send",hint:F4(i.sendBehavior,s?"enter":i.sendShortcut,_y),children:o.jsx(La,{label:"Default send",value:i.sendBehavior,onChange:a=>t.setSendBehavior(a),options:[{value:"interrupt",label:"Interrupt"},{value:"steer",label:"Steer"},{value:"queue",label:"Queue"}]})})]}),o.jsxs(rt,{title:"This browser",children:[o.jsx(He,{first:!0,title:"Saved settings",hint:"Every App setting and your last New session choices (team, model, thinking, permissions) stay in this browser. The access token never does.",children:o.jsx(we,{size:"sm",variant:"secondary",onClick:()=>t.resetPreferences(),children:"Reset"})}),o.jsx(K4,{})]})]})}function Zr({label:s,value:t,placeholder:i,numeric:a,limits:l,width:u="w-28",onCommit:d}){const[h,m]=b.useState(t);b.useEffect(()=>m(t),[t]);const p=()=>{if(!a||!l){h.trim()!==t?d(h.trim()):m(t);return}const x=Number.parseInt(h,10);if(!Number.isFinite(x)){m(t);return}const y=String(Math.min(l[1],Math.max(l[0],x)));m(y),y!==t&&d(y)};return o.jsx(Zn,{"aria-label":s,value:h,placeholder:i,inputMode:a?"numeric":void 0,onChange:x=>m(a?x.target.value.replace(/[^\d]/g,""):x.target.value),onBlur:p,onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),p())},onFocus:x=>x.target.select(),className:I("h-8",u,a&&"text-right tabular-nums")})}function ef({title:s,hint:t,label:i,value:a,limits:l,onCommit:u}){return o.jsx(He,{title:s,hint:t,children:o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx(Zr,{label:i,value:String(a),numeric:!0,limits:l,width:"w-16",onCommit:d=>u(Number(d))}),o.jsx("span",{className:"text-xs",children:"px"})]})})}function P4(){const s=Oe(),{preferences:t}=Ee(),i=Wd.find(a=>a.value===t.theme)?.swatch;return o.jsxs(o.Fragment,{children:[o.jsx(rt,{title:"Theme",children:o.jsx(He,{first:!0,title:"Theme",children:o.jsxs("span",{className:"flex items-center gap-2",children:[i?o.jsx("span",{"aria-hidden":!0,className:"size-3 rounded-full border border-border",style:{backgroundColor:i},"data-testid":"theme-swatch"}):null,o.jsxs(ph,{"aria-label":"Theme",value:t.theme,onChange:a=>s.setTheme(a.target.value),className:"h-8 w-auto rounded-lg border-border bg-transparent pl-3 text-sm text-foreground",children:[Wd.filter(a=>a.group==="primary").map(a=>o.jsx("option",{value:a.value,children:a.label},a.value)),o.jsx("option",{disabled:!0,children:"──────"}),Wd.filter(a=>a.group==="variant").map(a=>o.jsx("option",{value:a.value,children:a.label},a.value))]})]})})}),o.jsxs(rt,{title:"Fonts",children:[o.jsx(He,{first:!0,title:"Interface font",hint:"Used across the app. Leave empty for the system default",children:o.jsx(Zr,{label:"Interface font family",value:t.uiFontFamily,placeholder:Z0,width:"w-64 max-w-full",onCommit:a=>s.updatePreferences({uiFontFamily:a})})}),o.jsx(ef,{title:"Interface size",hint:"Used for navigation, controls, and labels",label:"Interface font size",value:t.uiFontSize,limits:On.uiFontSize,onCommit:a=>s.updatePreferences({uiFontSize:a})}),o.jsx(ef,{title:"Content size",hint:"Used for chat text and rendered Markdown",label:"Content font size",value:t.contentFontSize,limits:On.contentFontSize,onCommit:a=>s.updatePreferences({contentFontSize:a})}),o.jsx(He,{title:"Code font",hint:"Used in code, diffs, and the terminal output. Leave empty for the system default",children:o.jsx(Zr,{label:"Code font family",value:t.monoFontFamily,placeholder:J0,width:"w-64 max-w-full",onCommit:a=>s.updatePreferences({monoFontFamily:a})})}),o.jsx(ef,{title:"Code size",hint:"Used for code, diffs, and terminal output",label:"Code font size",value:t.codeFontSize,limits:On.codeFontSize,onCommit:a=>s.updatePreferences({codeFontSize:a})})]}),o.jsx(rt,{title:"Layout",children:o.jsx(He,{first:!0,title:"Content width",hint:"Max width of chat and Markdown files on wide screens",children:o.jsxs("span",{className:"flex items-center gap-2",children:[t.contentMaxWidth!==null?o.jsx(we,{size:"sm",variant:"ghost","aria-label":"Reset content width to default",onClick:()=>s.updatePreferences({contentMaxWidth:null}),children:"Reset"}):null,o.jsx(Zr,{label:"Content width in pixels",value:String(e1(t)),numeric:!0,limits:On.contentMaxWidth,width:"w-20",onCommit:a=>s.updatePreferences({contentMaxWidth:Number(a)})}),o.jsx("span",{className:"text-xs",children:"px"})]})})}),o.jsx(rt,{title:"Syntax",children:o.jsx(He,{first:!0,title:"Highlight theme",hint:"Colors for code, independent of the app theme",children:o.jsx(La,{label:"Highlight theme",value:t.syntaxTheme,onChange:a=>s.updatePreferences({syntaxTheme:a}),options:X3})})}),o.jsx(V4,{})]})}function Q4(){const s=Oe(),{preferences:t}=Ee(),i=(u,d)=>s.updatePreferences({sidebar:{...t.sidebar,[u]:d}}),a=(u,d,h)=>{const m=[...t.sidebar[u]];[m[d],m[d+h]]=[m[d+h],m[d]],i(u,m)},l=(u,d,h)=>o.jsxs(rt,{title:d,children:[o.jsx("p",{className:"px-4 pt-3 text-xs text-muted-foreground",children:h}),t.sidebar[u].map((m,p,x)=>{const y=G4[m.id];return o.jsxs("div",{className:I("flex items-center gap-2 p-4",p>0&&"border-t border-border"),"data-testid":`sidebar-nav-item-${m.id}`,children:[o.jsx(y.icon,{"aria-hidden":!0,strokeWidth:1.75,className:"size-4 shrink-0 text-muted-foreground"}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-foreground",children:y.label}),o.jsx(we,{size:"icon",variant:"ghost",className:"size-7","aria-label":`Move ${y.label} up`,disabled:p===0,onClick:()=>a(u,p,-1),children:o.jsx(Dl,{"aria-hidden":!0})}),o.jsx(we,{size:"icon",variant:"ghost",className:"size-7","aria-label":`Move ${y.label} down`,disabled:p===x.length-1,onClick:()=>a(u,p,1),children:o.jsx(vS,{"aria-hidden":!0})}),o.jsx(t1,{checked:m.visible,"aria-label":y.label,onCheckedChange:w=>i(u,x.map(k=>k.id===m.id?{...k,visible:w}:k))})]},m.id)})]});return o.jsxs(o.Fragment,{children:[l("header","Header","Choose which items appear at the top of the sidebar and in what order"),l("footer","Footer","Choose which rows appear at the bottom of the sidebar and in what order. The host and Settings row always shows")]})}function W4(){const s=Oe(),{preferences:t}=Ee();return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:"Detail level",children:[o.jsx(He,{first:!0,title:"Chat display",hint:"How much of an agent's work the chat shows",children:o.jsx(La,{label:"Chat display",value:t.chatDisplay,onChange:i=>s.updatePreferences({chatDisplay:i}),options:[{value:"full",label:"Full"},{value:"collapseToolCalls",label:"Collapse tool calls"},{value:"collapseTurns",label:"Collapse turns"}]})}),o.jsx(He,{title:"Chat outline",hint:"Show an outline for jumping between prompts",children:o.jsx(t1,{checked:t.chatOutline,"aria-label":"Chat outline",onCheckedChange:i=>s.updatePreferences({chatOutline:i})})})]}),o.jsx(ln,{what:"Always expand reasoning",why:"ALP's hosts do not send the agents' reasoning, so there is nothing to expand."})]})}function Z4(){const s=Oe(),{preferences:t}=Ee();return o.jsx(rt,{title:"Terminal",children:o.jsx(He,{first:!0,title:"Terminal scrollback",hint:"Lines kept in the built-in terminal buffer",children:o.jsx(Zr,{label:"Terminal scrollback lines",value:String(t.terminalScrollback),numeric:!0,limits:On.terminalScrollback,onCommit:i=>s.updatePreferences({terminalScrollback:Number(i)})})})})}function J4(){return o.jsx(rt,{title:"Files",children:o.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground","data-testid":"file-panel-settings-empty",children:"File panels appear here when a plugin adds one"})})}function eT(){const s=typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: light)").matches;return{userAgent:navigator.userAgent,language:navigator.language,online:navigator.onLine,secure:window.isSecureContext,viewport:`${window.innerWidth}×${window.innerHeight} @${window.devicePixelRatio}x`,colorScheme:s?"light":"dark"}}function tT(){const{connection:s,principal:t,preferences:i}=Ee(),[a,l]=b.useState(null),[u,d]=b.useState("idle"),h=()=>{d("idle"),l({version:"0.0.1-beta.8",connection:s,principal:t,preferences:i,browser:eT(),now:new Date})},m=async()=>{if(a)try{await navigator.clipboard.writeText(A3(a)),d("copied")}catch{d("failed")}};return o.jsxs(o.Fragment,{children:[o.jsx(rt,{title:"Diagnostics",children:o.jsx(He,{first:!0,title:"App diagnostic",hint:"Collect connection, host and browser details. Providers, logs and the daemon itself: run alp doctor on the host.",children:o.jsx(we,{size:"sm",variant:"secondary","data-testid":"settings-diagnostics-run",onClick:h,children:a?"Refresh":"Run"})})}),a?o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:`Diagnostic, ${a.now?.toLocaleTimeString()??""}`,action:o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs","data-testid":"settings-diagnostics-copy",onClick:()=>{m()},children:u==="copied"?"Copied":"Copy diagnostic"}),children:[u==="failed"?o.jsx("p",{role:"alert",className:"px-4 py-3 text-xs text-destructive",children:"Failed to copy diagnostic. Select the values below instead."}):null,o.jsx("p",{className:"px-4 py-3 text-xs text-muted-foreground",children:"It holds no access token, prompts or files."})]}),Q0(a).map(p=>o.jsx(rt,{title:p.title,children:p.rows.map(([x,y],w)=>o.jsx(He,{first:w===0,title:x,children:o.jsx("span",{className:"break-all font-mono text-xs","data-testid":`diagnostics-${x.toLowerCase().replace(/\W+/g,"-")}`,children:y})},x))},p.title))]}):null]})}function y1(s){return s.hostname??s.gateway.replace(/^https?:\/\//,"")}const Ly=s=>s?.trim().replace(/^v/i,"")||null,nT="https://github.com/phucanh08/alp/releases";function sT(){const{connection:s}=Ee(),t=y1(s),i=Ly(s.daemonVersion),a=s.phase!=="open",l=!!i&&i!==Ly("0.0.1-beta.8");return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:"About",children:[o.jsxs(He,{first:!0,title:"App version",hint:"This device",children:["v","0.0.1-beta.8"]}),o.jsx("a",{href:nT,target:"_blank",rel:"noopener noreferrer","data-testid":"settings-whats-new",className:I("block hover:bg-sidebar-hover",yc),children:o.jsx(He,{title:"What's new",hint:"Release notes for every version",children:o.jsx(Jn,{"aria-hidden":!0,className:"size-4"})})})]}),o.jsx(rt,{title:"Connected hosts",children:o.jsx(He,{first:!0,title:t,hint:a?"Offline":l?"Version differs from this device":"ALP on the host, through the gateway (ALP JSON-RPC v1)",children:o.jsx("span",{"data-testid":"connected-host-version",children:i?`v${i}`:"unknown"})})})]})}function iT(){const s=Oe(),{principal:t,connection:i,settings:a}=Ee(),[l,u]=b.useState(!1);b.useEffect(()=>{s.loadSettings()},[s]);const d=["session.read","session.write","project.read","project.write","workspace.write","workspace.manage","files.read","library.write","terminal.exec"];return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:"Host",children:[o.jsx(He,{first:!0,title:"Machine",hint:"The host's name, as it reports it.",children:i.hostname??"unknown"}),o.jsx(He,{title:"ALP",children:i.daemonVersion??"unknown"}),o.jsx(He,{title:"Gateway",children:o.jsx("span",{className:"break-all font-mono text-xs",children:i.gateway})}),o.jsx(He,{title:"Agents' language",hint:"Set on the host with alp; read only here.",children:a.status==="loading"?o.jsx(Ft,{label:"Loading…",className:"text-xs"}):a.language?`${a.language.applies}${a.language.language?"":" (default)"}`:"Not available"}),a.status==="error"?o.jsx("p",{role:"alert",className:"border-t border-border px-4 py-3 text-xs text-destructive",children:a.error?.message}):null]}),o.jsx(rt,{title:`Models new sessions can pick${a.models.length?` (${a.models.length})`:""}`,action:s.hasCapability("catalog.live")?o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs","data-testid":"settings-models-refresh",disabled:l,onClick:()=>{u(!0),s.refreshModels().catch(()=>{}).finally(()=>u(!1))},children:l?"Refreshing…":"Refresh"}):void 0,children:a.models.length?o.jsx("ul",{className:"max-h-72 divide-y divide-border overflow-y-auto",children:a.models.map(h=>o.jsxs("li",{className:"flex items-center justify-between gap-3 px-4 py-2 text-sm",children:[o.jsx("span",{className:"min-w-0 truncate",children:h.label}),o.jsx("span",{className:"shrink-0 font-mono text-[length:calc(11px*var(--ui-scale))] text-muted-foreground",children:h.id})]},h.id))}):o.jsx(He,{first:!0,title:a.status==="ready"?"None listed":"Loading…"})}),o.jsxs(rt,{title:"Access token",children:[o.jsxs(He,{first:!0,title:"Name",children:[t?.label??"—"," ",o.jsxs("span",{className:"font-mono text-xs",children:["(",t?.id,")"]})]}),o.jsx(He,{title:"Allows",children:o.jsx("span",{className:"flex flex-wrap justify-end gap-1",children:d.map(h=>{const m=Te(t??void 0,h);return o.jsxs("span",{className:I("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs [&_svg]:size-3",m?"bg-primary/15 text-highlight":"bg-secondary text-muted-foreground"),children:[m?o.jsx(lc,{"aria-hidden":!0}):o.jsx(rc,{"aria-hidden":!0}),h]},h)})})}),o.jsx(He,{title:"Modes",hint:"Permissions a session may run with.",children:t?.modes?t.modes.map(Fl).join(", "):"Any"})]})]})}function aT(){const{principal:s,registry:t}=Ee();return b.useCallback(i=>t.workspaces.filter(a=>!a.archivedAt&&(a.directory===i||s?.workspaceRoots?.some(l=>l.path===i&&l.canonical===a.directory))),[s,t])}function b1(s,t){if(!s)return"This host does not list its workspaces. Update ALP on the host.";if(!Te(t??void 0,"project.read"))return"Your access token cannot read the host's workspace list (it needs project.read)."}function rT(){const s=Oe(),{principal:t,workspace:i,registry:a,connection:l}=Ee(),u=aT(),[d,h]=b.useState(""),m=t?.workspaces??[],p=b1(s.hasCapability("workspace.registry"),t);b.useEffect(()=>{p||s.refreshRegistry()},[s,p]);const x=p?[]:m.filter(k=>!u(k).length),y=Te(t??void 0,"workspace.write"),w=l.phase==="open";return o.jsxs(o.Fragment,{children:[o.jsx(rt,{title:"Projects this token opens",children:m.length?m.map((k,j)=>o.jsx(He,{first:j===0,title:Dt(k),hint:o.jsx("span",{className:"break-all font-mono",children:k}),children:o.jsxs("span",{className:"flex items-center gap-2",children:[p?null:o.jsx("span",{className:"text-xs","data-testid":"project-registered",children:u(k).length?"Registered":"Not registered"}),k===i?o.jsx("span",{className:"text-highlight","data-testid":"project-current",children:"Current"}):o.jsx(we,{size:"sm",variant:"secondary",onClick:()=>s.selectWorkspace(k),children:"Open"})]})},k)):o.jsx(He,{first:!0,title:"No projects",hint:"This access token grants no workspace."})}),p?null:o.jsxs(rt,{title:"Register a project",children:[o.jsx(He,{first:!0,title:"Granted directory",hint:y?"Registering adds a granted directory to the host's shared workspace list, so terminals, Git and worktrees can use it. It changes no files.":"Ask the host owner to add workspace.write to your credential to register projects.",children:y&&x.length?o.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:k=>{k.preventDefault(),d&&s.registerProject(d).then(()=>h(""))},children:[o.jsx(La,{label:"Directory to register",value:d,onChange:h,options:[{value:"",label:"Choose a directory"},...x.map(k=>({value:k,label:Dt(k)}))]}),o.jsx(we,{size:"sm",type:"submit",disabled:!d||!w||a.loading,children:"Register"})]}):y?o.jsx("span",{className:"text-xs",children:"Every granted directory is registered"}):null}),a.error?o.jsx("p",{role:"alert",className:"border-t border-border px-4 py-3 text-xs text-destructive",children:a.error}):null]}),o.jsx(ln,{what:"Granting or removing projects",why:"The access token decides which projects you can open. The host owner grants them with alp-gateway credential create --workspace."})]})}function oT({row:s,first:t,writable:i,online:a,busy:l}){const u=Oe(),{workspace:d,principal:h}=Ee(),[m,p]=b.useState(!1),[x,y]=b.useState(s.title??""),w=s.title||Dt(s.directory),k=h?.workspaces?.some(A=>A===s.directory||h.workspaceRoots?.some(R=>R.path===A&&R.canonical===s.directory))||s.managedWorktree,j=h?.workspaceRoots?.find(A=>A.canonical===s.directory)?.path??s.directory,S=async()=>{await u.renameWorkspace(s.id,x)&&p(!1)};return o.jsxs("div",{className:I("flex flex-col gap-2 p-4",!t&&"border-t border-border"),"data-testid":"settings-workspace-row","data-workspace-id":s.id,children:[o.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex items-center gap-2 text-sm text-foreground",children:[o.jsx("span",{className:"truncate",children:w}),s.pinnedAt?o.jsx(u0,{"aria-label":"Pinned",className:"size-3 shrink-0 text-muted-foreground"}):null,s.managedWorktree?o.jsx("span",{className:"rounded-full bg-secondary px-2 py-0.5 text-[length:calc(11px*var(--ui-scale))] text-muted-foreground",children:"Worktree"}):null]}),o.jsx("div",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:s.directory}),s.branch!==void 0?o.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:s.branch||"Detached HEAD"}):null]}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx(we,{size:"sm",variant:"ghost","aria-pressed":!!s.pinnedAt,disabled:!i||!a||l,onClick:()=>{u.pinWorkspace(s.id,!s.pinnedAt)},"aria-label":`${s.pinnedAt?"Unpin":"Pin"} workspace ${w}`,children:s.pinnedAt?"Unpin":"Pin"}),o.jsx(we,{size:"sm",variant:"ghost",disabled:!i||!a||l,onClick:()=>{y(s.title??""),p(A=>!A)},"aria-label":`Rename workspace ${w}`,children:"Rename"}),k?j===d?o.jsx("span",{className:"text-xs text-highlight",children:"Open"}):o.jsx(we,{size:"sm",variant:"secondary",onClick:()=>u.selectWorkspace(j),children:"Open"}):null]})]}),m?o.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:A=>{A.preventDefault(),S()},children:[o.jsx(Zn,{"aria-label":`New name for ${w}`,value:x,maxLength:200,onChange:A=>y(A.target.value),placeholder:Dt(s.directory),className:"h-8 min-w-0 flex-1",autoFocus:!0}),o.jsx(we,{size:"sm",type:"submit",disabled:!a||l,children:"Save"}),o.jsx(we,{size:"sm",variant:"ghost",type:"button",onClick:()=>p(!1),children:"Cancel"})]}):null]})}function lT(){const s=Oe(),{principal:t,registry:i,connection:a}=Ee(),l=b1(s.hasCapability("workspace.registry"),t);if(b.useEffect(()=>{l||s.refreshRegistry()},[s,l]),l)return o.jsx(ln,{what:"Workspace settings",why:l});const u=Te(t??void 0,"workspace.write"),d=a.phase==="open",h=i.workspaces.filter(m=>!m.archivedAt).sort((m,p)=>+!!p.pinnedAt-+!!m.pinnedAt||(m.title||Dt(m.directory)).localeCompare(p.title||Dt(p.directory))||m.id.localeCompare(p.id));return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:`Shared with every client of this host${h.length?` (${h.length})`:""}`,action:o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs",disabled:i.loading||!d,onClick:()=>{s.refreshRegistry()},children:i.loading?"Refreshing…":"Refresh"}),children:[i.error?o.jsx("p",{role:"alert",className:"px-4 py-3 text-xs text-destructive",children:i.error}):null,h.length?h.map((m,p)=>o.jsx(oT,{row:m,first:p===0&&!i.error,writable:u,online:d,busy:!!i.loading},m.id)):o.jsx(He,{first:!i.error,title:i.loading?"Loading…":"No workspaces",hint:i.loading?void 0:"Register a granted directory under Host › Projects."})]}),u?null:o.jsx(rt,{children:o.jsx(He,{first:!0,title:"Read only",hint:"Pins and names are shared with every client of this host. Ask the host owner to add workspace.write to your credential to change them."})}),o.jsx(ln,{what:"Archiving workspaces, labels and placement",why:"The host's owner manages them with alp on the host."})]})}function cT({onNavigate:s}){const t=Ee(),i=t.connection.capabilities.includes("terminal"),a=Te(t.principal??void 0,"terminal.exec"),l=Pb(t),u=!l.ok&&l.reasons.includes("unregistered"),d=Te(t.principal??void 0,"workspace.write"),h=(m,p)=>o.jsxs("span",{className:I("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs [&_svg]:size-3",m?"bg-primary/15 text-highlight":"bg-secondary text-muted-foreground"),children:[m?o.jsx(lc,{"aria-hidden":!0}):o.jsx(rc,{"aria-hidden":!0}),p]});return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:"Remote terminals",children:[o.jsx(He,{first:!0,title:"Host",hint:i?"The host's owner allowed remote terminals.":io.capability,children:o.jsx("span",{"data-testid":"terminals-host",children:h(i,i?"Allowed":"Not allowed")})}),o.jsx(He,{title:"Access token",hint:a?"Your access token may open terminals (terminal.exec).":io.permission,children:o.jsx("span",{"data-testid":"terminals-token",children:h(a,a?"terminal.exec":"No terminal.exec")})}),o.jsx(He,{title:"This workspace",hint:l.ok?"A terminal can open here from the + menu (Terminal).":[...l.messages,u?d?"Register it under Host › Projects; the terminal opens once it is in the list.":"Registering it needs workspace.write: ask the host owner to register it, or to add workspace.write to your credential.":""].filter(Boolean).join(" "),children:o.jsxs("span",{className:"flex items-center gap-2",children:[u&&d?o.jsx(we,{size:"sm",variant:"secondary","data-testid":"terminals-register",onClick:()=>s("projects"),children:"Register in Projects"}):null,o.jsx("span",{"data-testid":"terminals-workspace",children:h(l.ok,l.ok?"Ready":"Not available")})]})})]}),o.jsx(ln,{what:"Changing the host's terminal switch",why:"Only the host's owner turns remote terminals on or off, on the host: alp terminal allow --yes, alp terminal deny, alp terminal status. Font and colors are under App › Terminal."})]})}function uT(){const s=Oe(),{connection:t}=Ee(),i=t.gateway.startsWith("https:");return o.jsxs(rt,{title:"This connection",children:[o.jsx(He,{first:!0,title:"Gateway",children:o.jsx("span",{className:"break-all font-mono text-xs",children:t.gateway})}),o.jsx(He,{title:"State",children:t.phase==="open"?"Connected":t.phase==="reconnecting"?`Reconnecting (attempt ${t.attempt})`:t.phase}),o.jsx(He,{title:"Transport",hint:i?"TLS to the gateway.":"Plain HTTP, allowed only on this machine (loopback or an SSH tunnel).",children:i?"HTTPS / WSS":"Loopback HTTP / WS"}),o.jsx(He,{title:"Access token",hint:"Kept in this tab's memory only. Disconnecting forgets it.",children:o.jsx(we,{size:"sm",variant:"destructive",onClick:()=>s.disconnect(),children:"Disconnect"})})]})}function dT({kind:s,name:t,onClose:i}){const a=Oe(),[l,u]=b.useState({status:"loading"});b.useEffect(()=>{let h=!0;return u({status:"loading"}),a.getLibraryEntry(s,t).then(m=>{h&&u({status:"ready",entry:m})},m=>{h&&u({status:"error",error:Be(m).message})}),()=>{h=!1}},[a,s,t]);const d=l.entry;return o.jsx(rt,{title:t,action:o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:i,children:"Close"}),children:o.jsxs("div",{"data-testid":"library-entry","aria-label":`${t} content`,role:"group",children:[l.status==="loading"?o.jsx("div",{className:"p-4",children:o.jsx(Ft,{label:"Loading…",className:"text-xs"})}):null,l.status==="error"?o.jsx("p",{role:"alert",className:"p-4 text-xs text-destructive",children:l.error}):null,d?o.jsxs(o.Fragment,{children:[o.jsx(He,{first:!0,title:"Source",hint:d.usedBy.length?`Used by ${d.usedBy.join(", ")}`:void 0,children:o.jsxs("span",{className:"text-xs",children:[d.source,d.overrides?` · overrides ${d.overrides}`:""]})}),d.librarySkills?.length?o.jsx(He,{title:"Skills the library gives it",children:d.librarySkills.join(", ")}):null,h4(d.content).map(h=>o.jsxs("div",{className:"border-t border-border p-4",children:[o.jsx("div",{className:"mb-2 font-mono text-xs text-muted-foreground",children:h.label}),o.jsx("pre",{className:"max-h-96 overflow-auto whitespace-pre-wrap break-words rounded-md bg-secondary p-3 font-mono text-xs text-foreground",children:h.text})]},h.key)),d.secrets.length?o.jsxs("p",{className:"border-t border-border px-4 py-3 text-xs text-muted-foreground",children:[d.secrets.length===1?"One value that can hold a secret is":`${d.secrets.length} values that can hold secrets are`," shown as ",Xl,": the gateway keeps them on the host."]}):null]}):null]})})}function fT({kind:s,selected:t,onChanged:i}){const a=Oe(),[l,u]=b.useState(""),[d,h]=b.useState(""),[m,p]=b.useState(""),[x,y]=b.useState(null),[w,k]=b.useState(!1),[j,S]=b.useState(!1),[A,R]=b.useState(null),[q,O]=b.useState(null);b.useEffect(()=>{let B=!0;return k(!1),R(null),O(null),h(""),t?a.getLibraryEntry(s,t).then(_=>{if(B){if(_.source!=="project"||_.overrides||_.secrets.length||_.revision===void 0){O("This entry holds configuration the host runs or values kept on the host, so it is read only here.");return}u(t),y(_.revision),p(JSON.stringify(_.content,null,2)),k(!0)}},_=>{B&&R(Be(_).message)}):(u(""),y(null),p(JSON.stringify(s==="skills"?{body:""}:{instructions:"",config:{description:""}},null,2)),k(!0)),()=>{B=!1}},[a,s,t]);const L=async B=>{S(!0),R(null);try{const _=B==="save"?{name:l,content:JSON.parse(m),revision:x}:B==="delete"?{name:l,revision:x}:{from:l,to:d},Q=await a.writeLibrary(B,s,_);B==="save"&&y(Q.revision),(B==="delete"||B==="rename")&&k(!1),i()}catch(_){R(Be(_).message)}finally{S(!1)}};return o.jsx(rt,{title:t?"Edit project instructions":"New project instructions",children:o.jsxs("div",{className:"flex flex-col gap-3 p-4",children:[o.jsx("p",{className:"text-xs text-muted-foreground",children:"Agents and skills only. Host entries, executable configuration, references and extra files cannot be changed here."}),A?o.jsx("p",{role:"alert",className:"text-xs text-destructive",children:A}):null,q?o.jsx("p",{role:"note",className:"text-xs text-muted-foreground",children:q}):null,w?o.jsxs(o.Fragment,{children:[o.jsx(Zn,{"aria-label":"Entry name",value:l,onChange:B=>u(B.target.value),disabled:j||!!t,placeholder:"Entry name"}),o.jsx("textarea",{"aria-label":"Instruction entry JSON",className:"min-h-48 rounded border border-border bg-background p-2 font-mono text-xs",value:m,onChange:B=>p(B.target.value),disabled:j}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx(we,{size:"sm",disabled:j||!l.trim(),onClick:()=>{L("save")},children:"Save project entry"}),t?o.jsx(we,{size:"sm",variant:"secondary",disabled:j,onClick:()=>{L("delete")},children:"Delete project entry"}):null]}),t?o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx(Zn,{"aria-label":"New entry name",value:d,onChange:B=>h(B.target.value),placeholder:"New name",disabled:j}),o.jsx(we,{size:"sm",variant:"secondary",disabled:j||!d.trim(),onClick:()=>{L("duplicate")},children:"Duplicate"}),o.jsx(we,{size:"sm",variant:"secondary",disabled:j||!d.trim(),onClick:()=>{L("rename")},children:"Rename"})]}):null]}):null]})})}function Ta({kind:s,noun:t}){const i=Oe(),{workspace:a}=Ee(),[l,u]=b.useState({status:"loading",entries:[]}),[d,h]=b.useState(null),m=i.libraryBlock(),p=b.useCallback(()=>{let w=!0;return u(k=>({...k,status:"loading",error:void 0})),i.listLibrary(s).then(k=>{w&&u({status:"ready",entries:k})},k=>{w&&u({status:"error",entries:[],error:Be(k).message})}),()=>{w=!1}},[i,s]);if(b.useEffect(()=>m?void 0:p(),[p,m,a]),b.useEffect(()=>{h(null)},[s,a]),m)return o.jsx(ln,{what:`Listing ${t}`,why:m});const x=d?l.entries.find(w=>w.name===d):void 0,y=x&&x.source==="project"&&!x.overrides?x.name:null;return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:a?`As ${Dt(a)} sees them`:void 0,action:o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>p(),children:"Refresh"}),children:[l.status==="loading"&&!l.entries.length?o.jsx("div",{className:"p-4",children:o.jsx(Ft,{label:"Loading…",className:"text-xs"})}):null,l.status==="error"?o.jsx("p",{role:"alert",className:"p-4 text-xs text-destructive",children:l.error}):null,l.status==="ready"&&!l.entries.length?o.jsx(He,{first:!0,title:`No ${t}`}):null,l.entries.map((w,k)=>o.jsx("button",{type:"button",onClick:()=>h(j=>j===w.name?null:w.name),"aria-expanded":d===w.name,"data-testid":`library-row-${w.name}`,className:I("block w-full text-left hover:bg-sidebar-hover",yc,d===w.name&&"bg-sidebar-hover"),children:o.jsx(He,{first:k===0,title:o.jsx("span",{className:"font-mono text-[length:calc(13px*var(--ui-scale))]",children:w.name}),hint:[w.description,w.usedBy?.length?`Used by ${w.usedBy.join(", ")}`:""].filter(Boolean).join(" · ")||void 0,children:o.jsxs("span",{className:"text-xs",children:[w.source,w.overrides?` · overrides ${w.overrides}`:""]})})},`${w.source}:${w.name}`))]}),i.libraryWriteBlock(s)?null:o.jsx(fT,{kind:s,selected:y,onChanged:()=>p()},`${s}:${a}:${y??"new"}`),d?o.jsx(dT,{kind:s,name:d,onClose:()=>h(null)}):null,i.libraryWriteBlock(s)?o.jsx(ln,{what:`Editing ${t}`,why:`${i.libraryWriteBlock(s)} Open an entry to read it. Values that can hold secrets (environment, headers, MCP URLs and arguments, hook commands) show as ${Xl}. Changes configure commands the host runs, so edit them on the host with alp.`}):null]})}function hT({page:s,mobile:t,onNavigate:i}){switch(s){case"general":return o.jsx(X4,{mobile:t});case"appearance":return o.jsx(P4,{});case"sidebar":return o.jsx(Q4,{});case"chat":return o.jsx(W4,{});case"terminal":return o.jsx(Z4,{});case"files":return o.jsx(J4,{});case"editor":return o.jsx(ln,{what:"Editor",why:"This app opens a workspace's files read only (the Files panel); changing them is the agents' work, or yours on the host."});case"diagnostics":return o.jsx(tT,{});case"about":return o.jsx(sT,{});case"host":return o.jsx(iT,{});case"projects":return o.jsx(rT,{});case"connections":return o.jsx(uT,{});case"alp-templates":return o.jsx(Ta,{kind:"teams",noun:"templates"});case"alp-agents":return o.jsx(Ta,{kind:"agents",noun:"agents"});case"alp-skills":return o.jsx(Ta,{kind:"skills",noun:"skills"});case"alp-hooks":return o.jsx(Ta,{kind:"hooks",noun:"hooks"});case"alp-mcp":return o.jsx(Ta,{kind:"mcp",noun:"MCP servers"});case"providers":return o.jsxs(o.Fragment,{children:[o.jsx(Ta,{kind:"providers",noun:"providers"}),o.jsx(ln,{what:"Adding, testing or diagnosing providers",why:"Tests run commands on the host; they are not offered remotely."})]});case"pair-device":return o.jsx(ln,{what:"Pairing a device",why:"This app is the remote client: open it on the other device and connect with an access token."});case"voice":return o.jsx(ln,{what:"Voice",why:"Paseo's dictation and voice mode turn speech into prompts with a speech provider set up on the host. ALP's agents take text, and its hosts have no speech provider to set up."});case"metadata":return o.jsx(ln,{what:"Metadata generation",why:"A host setting the gateway does not expose."});case"workspaces":return o.jsx(lT,{});case"usage":return o.jsx(ln,{what:"Usage and limits",why:"Account-wide on the host; check with alp usage there."});case"terminals":return o.jsx(cT,{onNavigate:i});case"plugins":return o.jsx(ln,{what:"Plugins",why:"Installing plugins changes the host; not offered remotely."})}}function Oy({page:s,label:t,icon:i,selected:a,onSelect:l,mobile:u}){return o.jsxs("button",{type:"button",onClick:()=>l(s),"aria-current":a?"page":void 0,"data-testid":`settings-${s}`,className:I("flex min-h-7 w-full items-center gap-2 rounded-lg px-2 py-1 text-left text-sm text-muted-foreground hover:bg-sidebar-hover hover:text-foreground",yc,a&&"bg-sidebar-hover text-foreground",u&&"min-h-10"),children:[o.jsx(i,{"aria-hidden":!0,strokeWidth:1.75,className:"size-4 shrink-0"}),o.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),u?o.jsx(Jn,{"aria-hidden":!0,className:"size-4 text-extra-muted"}):null]})}function Dy({page:s,onSelect:t,mobile:i}){const{connection:a}=Ee(),l=y1(a);return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-2",children:[o.jsx("p",{className:"px-2 py-1 text-sm text-extra-muted",children:"App"}),g1.map(u=>o.jsx(Oy,{page:u.id,label:u.label,icon:u.icon,selected:s===u.id,onSelect:t,mobile:i},u.id))]}),o.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-2",children:[o.jsx("p",{className:"px-2 py-1 text-sm text-extra-muted",children:"Host"}),o.jsxs("div",{className:"flex min-h-7 items-center gap-2 px-2 py-1 text-sm",title:a.gateway,"data-testid":"settings-host-label",children:[o.jsx("span",{className:"flex size-4 items-center justify-center",children:o.jsx("span",{className:I("size-2 rounded-full",a.phase==="open"?"bg-dot-success":"bg-dot-warning")})}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-foreground",children:l})]}),x1.map(u=>o.jsx(Oy,{page:u.id,label:u.label,icon:u.icon,selected:s===u.id,onSelect:t,mobile:i},u.id))]})]})}function mT({onClose:s,mobile:t,initialPage:i}){const[a,l]=b.useState(i??(t?null:"general"));b.useEffect(()=>{const h=m=>{m.key==="Escape"&&!(m.target instanceof HTMLElement&&m.target.closest('[role="menu"],dialog'))&&s()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[s]);const u=(h,m)=>o.jsx("div",{className:"flex h-14 shrink-0 items-center gap-2 border-b border-border px-2 md:h-9",children:o.jsxs("button",{type:"button",onClick:m,className:I("flex min-h-7 items-center gap-2 rounded-lg px-2 py-1 text-sm text-muted-foreground hover:bg-sidebar-hover hover:text-foreground",yc),children:[o.jsx(th,{"aria-hidden":!0,className:"size-4"}),h]})}),d=a?o.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:o.jsxs("div",{className:"mx-auto w-full max-w-[720px] p-4 pt-14",children:[o.jsx("h2",{className:"mb-6 ml-1 text-[length:calc(26px*var(--ui-scale))] font-semibold text-foreground","data-testid":"settings-detail-header-title",children:I4[a]}),o.jsx(hT,{page:a,mobile:t,onNavigate:l})]})}):null;return t?o.jsxs("div",{role:"region","aria-label":"Settings",className:"flex h-dvh flex-col bg-background",children:[a?u("Settings",()=>l(null)):u("Back",s),a?d:o.jsx("nav",{"aria-label":"Settings",className:"min-h-0 flex-1 overflow-y-auto",children:o.jsx(Dy,{page:null,onSelect:l,mobile:!0})})]}):o.jsxs("div",{role:"region","aria-label":"Settings",className:"flex h-dvh overflow-hidden bg-background",children:[o.jsxs("nav",{"aria-label":"Settings",className:"flex w-[320px] shrink-0 flex-col border-r border-border bg-sidebar","data-testid":"settings-sidebar",children:[u("Back",s),o.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:o.jsx(Dy,{page:a,onSelect:l,mobile:!1})})]}),o.jsx("main",{className:"flex min-w-0 flex-1 flex-col","data-testid":"settings-detail-pane",children:d})]})}const pT=[{key:"list",label:"List"},{key:"board",label:"Board"},{key:"epics",label:"Epics"}],gT=["open","ready","closed","all"],Wl=(s,t)=>s.priority-t.priority||s.id.localeCompare(t.id),v1=(s,t)=>(t.closed?.at??t.updatedAt??"").localeCompare(s.closed?.at??s.updatedAt??"")||s.id.localeCompare(t.id);function vh(s){return s.status==="closed"?"closed":s.approvals?.length?"approve":s.status==="review"?"review":s.status==="in_progress"?"progress":s.type==="epic"?s.progress?.done?"progress":"ready":s.ready?"ready":"blocked"}const qy={approve:"Needs approval",review:"In review",progress:"In progress",ready:"Ready",blocked:"Blocked",closed:"Closed"},w1=s=>!!s.ready&&s.status!=="closed";function xT(s){const t=s.filter(i=>i.status==="closed").length;return{open:s.length-t,ready:s.filter(w1).length,closed:t,all:s.length}}function yT(s,t,i=""){const a=i.trim().toLowerCase().split(/\s+/).filter(Boolean);return s.filter(l=>{if(t==="open"&&l.status==="closed"||t==="ready"&&!w1(l)||t==="closed"&&l.status!=="closed")return!1;if(!a.length)return!0;const u=[l.id,l.title,l.type??"",l.assignee??"",...l.labels??[]].join(" ").toLowerCase();return a.every(d=>u.includes(d))})}const bT=[{key:"approve",title:"Waiting for your approval"},{key:"review",title:"In review"},{key:"progress",title:"In progress"},{key:"ready",title:"Ready"},{key:"waiting",title:"Blocked or waiting"},{key:"epics",title:"Epics"},{key:"closed",title:"Closed"}];function vT(s){return s.status==="closed"?"closed":s.approvals?.length?"approve":s.status==="review"?"review":s.status==="in_progress"?"progress":s.type==="epic"?"epics":s.ready?"ready":"waiting"}function wT(s){return bT.map(t=>{const i=s.filter(a=>vT(a)===t.key);return{...t,tasks:i.sort(t.key==="closed"?v1:Wl)}}).filter(t=>t.tasks.length)}const kT=[{key:"approve",title:"Needs approval"},{key:"blocked",title:"Blocked"},{key:"ready",title:"Ready"},{key:"progress",title:"In progress"},{key:"review",title:"In review"},{key:"closed",title:"Closed"}];function jT(s){return kT.map(t=>({...t,tasks:s.filter(i=>i.type!=="epic"&&vh(i)===t.key).sort(t.key==="closed"?v1:Wl)})).filter(t=>t.tasks.length||t.key==="blocked"||t.key==="ready"||t.key==="progress")}function ST(s,t){return t.filter(i=>i.type==="epic"||i.progress).sort(Wl).map(i=>{const a=s.filter(d=>d.parent===i.id).sort(Wl),l=i.progress?.done??a.filter(d=>d.status==="closed").length,u=i.progress?.total??a.length;return{epic:i,children:a,done:l,total:u,percent:u?Math.round(l/u*100):0}})}function k1(s,t=Date.now()){const i=s?Date.parse(s):NaN;if(Number.isNaN(i))return"";const a=Math.max(0,Math.floor((t-i)/6e4));return a<60?`${a}m`:a<1440?`${Math.floor(a/60)}h`:a<1440*14?`${Math.floor(a/1440)}d`:`${Math.floor(a/10080)}w`}const oo="main",j1=5,Gr=.1,zl=.15,By=.4,NT=16,TT=1030,$y=()=>({root:{kind:"pane",id:oo},focused:oo,assign:{},actives:{}});function Vt(s){return s.kind==="pane"?[s.id]:s.children.flatMap(Vt)}function S1(s){return s.kind==="pane"?1:1+Math.max(...s.children.map(S1))}const N1=s=>s.kind==="pane"?[s.id]:[s.id,...s.children.flatMap(N1)];function Uy(s,t){const i=new Set(N1(s));let a=1;for(;i.has(`${t}-${a}`);)a+=1;return`${t}-${a}`}function Ti(s,t){const i=Vt(s.root),a=s.assign[t];return a&&i.includes(a)?a:i.includes(s.focused)?s.focused:i[0]}function AT(s,t,i){const a=Object.fromEntries(Vt(s.root).map(l=>[l,[]]));for(const l of t)a[Ti(s,i(l))].push(l);return a}function bc(s,t){if(s.kind==="pane")return s.id===t?[]:null;for(let i=0;i<s.children.length;i+=1){const a=bc(s.children[i],t);if(a)return[i,...a]}return null}const wh=(s,t)=>t.reduce((i,a)=>i.children[a],s);function Zl(s,t,i){if(!t.length)return i(s);const a=s,[l,...u]=t;return{...a,children:a.children.map((d,h)=>h===l?Zl(d,u,i):d)}}function Rf(s,{target:t,position:i,key:a}){const l=bc(s.root,t);if(!l)return null;const u=i==="left"||i==="right"?"horizontal":"vertical",d=i==="right"||i==="bottom",h=Uy(s.root,"pane"),m={kind:"pane",id:h},p=l.slice(0,-1),x=l.length?wh(s.root,p):null,y=l[l.length-1]??0;let w;if(x&&x.direction===u){const k=x.sizes[y]??0,j=d?y+1:y,S=x.sizes.slice();S.splice(j,0,k/2),S[y+(d?0:1)]=k/2;const A=x.children.slice();A.splice(j,0,m),w=Zl(s.root,p,()=>({...x,children:A,sizes:S}))}else{const k=Uy(s.root,"group");w=Zl(s.root,l,j=>({kind:"group",id:k,direction:u,children:d?[j,m]:[m,j],sizes:[.5,.5]}))}return S1(w)>j1?null:{...s,root:w,focused:h,assign:a?{...s.assign,[a]:h}:s.assign}}function T1(s,t){const i=bc(s,t);if(!i||!i.length)return null;for(let a=i.length-1;a>=0;a-=1){const l=wh(s,i.slice(0,a)),u=i[a];for(let d=u-1;d>=0;d-=1){const h=Vt(l.children[d]);if(h.length)return h[h.length-1]}for(let d=u+1;d<l.children.length;d+=1){const h=Vt(l.children[d]);if(h.length)return h[0]}}return null}function Hy(s,t){const i=bc(s.root,t);if(!i||!i.length)return null;const a=T1(s.root,t),l=i.slice(0,-1),u=wh(s.root,l),d=i[i.length-1],h=u.children.filter((j,S)=>S!==d),m=u.sizes.filter((j,S)=>S!==d),p=m.reduce((j,S)=>j+S,0)||1,x=Zl(s.root,l,()=>h.length===1?h[0]:{...u,children:h,sizes:m.map(j=>j/p)}),y=Object.fromEntries(Object.entries(s.assign).filter(([,j])=>j!==t)),w=Object.fromEntries(Object.entries(s.actives).filter(([j])=>j!==t)),k=s.focused===t?a??Vt(x)[0]:s.focused;return{root:x,focused:k,assign:y,actives:w}}function CT(s,t,i){return Vt(s.root).includes(i)?{...s,focused:i,assign:{...s.assign,[t]:i},actives:{...s.actives,[i]:t}}:s}function A1(s){const t=s.length;if(!t)return[];if(t===1)return[1];if(t*Gr>1)return s.map(()=>1/t);const i=s.map(m=>Number.isFinite(m)&&m>0?m:0),a=i.reduce((m,p)=>m+p,0),l=a>0?i.map(m=>m/a):i.map(()=>1/t),u=l.map(()=>0),d=new Set(l.map((m,p)=>p));let h=1;for(;d.size;){let m=0;for(const x of d)m+=l[x];if(m<=0){for(const x of d)u[x]=h/d.size;break}const p=[...d].filter(x=>l[x]/m*h<Gr);if(!p.length){for(const x of d)u[x]=l[x]/m*h;break}for(const x of p)u[x]=Gr,d.delete(x),h-=Gr}return u}function ET(s,t,i){const a=l=>l.kind==="pane"?l:l.id===t&&i.length===l.children.length?{...l,sizes:A1(i)}:{...l,children:l.children.map(a)};return{...s,root:a(s.root)}}function _f(s,t={left:0,top:0,right:1,bottom:1}){if(s.kind==="pane")return[{id:s.id,...t}];const i=[];let a=0;for(let l=0;l<s.children.length;l+=1){const u=s.sizes[l]??0;if(s.direction==="horizontal"){const d=t.right-t.left;i.push(..._f(s.children[l],{...t,left:t.left+d*a,right:t.left+d*(a+u)}))}else{const d=t.bottom-t.top;i.push(..._f(s.children[l],{...t,top:t.top+d*a,bottom:t.top+d*(a+u)}))}a+=u}return i}function Iy(s,t,i){const a=_f(s),l=a.find(p=>p.id===t);if(!l)return null;const u=i==="left"||i==="right",d=(p,x,y,w)=>x<y?y-x:w<p?p-w:0,h=(p,x,y,w)=>Math.max(0,Math.min(x,w)-Math.max(p,y)),m=a.filter(p=>p.id!==t).map(p=>{const x=i==="left"?l.left-p.right:i==="right"?p.left-l.right:i==="up"?l.top-p.bottom:p.top-l.bottom;if(x<-1e-6)return null;const[y,w,k,j]=u?[p.top,p.bottom,l.top,l.bottom]:[p.left,p.right,l.left,l.right],S=Math.abs(u?(p.top+p.bottom)/2-(l.top+l.bottom)/2:(p.left+p.right)/2-(l.left+l.right)/2);return{id:p.id,primary:x,secondary:d(y,w,k,j),overlap:h(y,w,k,j),center:S}}).filter(p=>!!p);return m.sort((p,x)=>p.primary-x.primary||p.secondary-x.secondary||x.overlap-p.overlap||p.center-x.center||String(p?.id).localeCompare(String(x?.id))),m[0]?.id??null}function MT({width:s,height:t,x:i,y:a}){const l=s*((1-By)/2),u=t*((1-By)/2);if(i>=l&&i<=s-l&&a>=u&&a<=t-u)return"center";if(i<=s*zl)return"left";if(i>=s-s*zl)return"right";if(a<=t*zl)return"top";if(a>=t-t*zl)return"bottom";const d=[["left",i],["right",s-i],["top",a],["bottom",t-a]];return d.sort((h,m)=>h[1]-m[1]),d[0][0]}const Lf=s=>!!s&&typeof s=="object"&&!Array.isArray(s),Bl=s=>typeof s=="string"&&!!s.trim()&&s.length<=TT;function C1(s,t,i){if(!Lf(s)||i>j1)return null;const a=s;if(!Bl(a.id)||t.has(a.id))return null;if(t.add(a.id),a.kind==="pane")return{kind:"pane",id:a.id};if(a.kind!=="group"||a.direction!=="horizontal"&&a.direction!=="vertical"||!Array.isArray(a.children)||!Array.isArray(a.sizes)||a.children.length!==a.sizes.length||a.children.length<2)return null;const l=[];for(const d of a.children){const h=C1(d,t,i+1);if(!h)return null;l.push(h)}const u=a.sizes.map(d=>typeof d=="number"&&Number.isFinite(d)&&d>0?d:0);return{kind:"group",id:a.id,direction:a.direction,children:l,sizes:A1(u)}}function zT(s){if(!Lf(s))return;const t=s,i=C1(t.root,new Set,1);if(!i||i.kind==="pane")return;const a=Vt(i);if(a.length>NT)return;const l=(m,p)=>{const x={};if(!Lf(m))return x;for(const[y,w]of Object.entries(m).slice(0,100))Bl(y)&&Bl(w)&&p(y,w)&&(x[y]=w);return x},u=l(t.assign,(m,p)=>a.includes(p)),d=l(t.actives,m=>a.includes(m)),h=Bl(t.focused)&&a.includes(t.focused)?t.focused:a[0];return{root:i,focused:h,assign:u,actives:d}}const E1="alp-web:layout",Of=1,RT=["changes","terminal","diff","files","agents","tasks"],M1=Object.freeze({initial:320,min:200,max:600}),z1=Object.freeze({initial:320,min:240,max:720}),_T=20,LT=50,R1=300,_1=1024,OT=_1+5,Df=s=>!!s&&typeof s=="object"&&!Array.isArray(s),L1=s=>typeof s=="string"&&s.trim()&&s.length<=R1?s:void 0,DT=s=>typeof s=="string"&&s.trim()&&s.length<=_1?s:void 0,Gy=s=>typeof s=="string"&&s.trim()&&s.length<=OT?s:void 0,Hr=(s,t=()=>!0,i=L1)=>Array.isArray(s)?[...new Set(s.map(i).filter(a=>!!a&&t(a)))].slice(0,LT):[];function Jl(s,t){if(!(typeof s!="number"||!Number.isFinite(s)))return Math.round(Math.min(t.max,Math.max(t.min,s)))}const qT=(s,t)=>`${s}
29
+ `):[]).then(he=>{E&&Ae(he)})};V();const ue=setInterval(V,15e3);return()=>{E=!1,clearInterval(ue)}},[j,_.grouping,ne,Ne]);const Ht=E=>j.updatePreferences({sidebarDisplay:{..._,...E}}),cn=E=>{if(E===R){Y(V=>!V);return}Y(!1),j.selectWorkspace(E)},ze=E=>{E!==R&&(Y(!1),j.selectWorkspace(E)),s(),u()},ut=(E,V)=>{E!==R&&j.selectWorkspace(E),j.selectSession(V),y(),u()},At=()=>{xe(""),fe(!1)},[Rt,In]=b.useState(0);b.useEffect(()=>{w&&(fe(!0),Y(!1),In(E=>E+1),k?.())},[w]);const kn=L.hostname??L.gateway.replace(/^https?:\/\//,""),Qt=(E,V)=>{navigator.clipboard?.writeText(E).then(()=>j.notify("info",`${V} copied`),()=>j.notify("error",`Could not copy the ${V.toLowerCase()}.`))},Je=E=>ve(E)[0],jt=E=>Je(E)?.title||Dt(E),St=(E,V)=>{const ue=Je(E),he=ue?.branch||void 0,pe=[];return _.rowItems.branch&&he&&pe.push({key:"branch",icon:Qs,text:he}),_.rowItems.project&&pe.push({key:"project",icon:Da,text:jt(E)}),_.rowItems.host&&pe.push({key:"host",icon:Qr,text:kn}),_.rowItems.labels&&ue?.labels.length&&pe.push({key:"labels",icon:h0,text:ue.labels.join(", ")}),{title:_.titleSource==="branch"&&he?he:Wn(V),meta:pe,trailing:_.trailing==="timestamp"?S3(V.updatedAt??V.createdAt):""}},un=E=>bh(E,ic(S,E.id),ao(S,E.id)),Gn=(E,V)=>{const ue=St(E,V);return o.jsx(_4,{session:V,title:ue.title,meta:ue.meta,trailing:ue.trailing,selected:V.id===O&&!m,canWrite:F,bucket:un(V),onSelect:()=>ut(E,V.id),onRename:()=>t(V),onArchive:()=>i(V)},V.id)},js=E=>{const V=Je(E),ue=[];if(V){const he=J?void 0:"Ask the host owner for workspace.write to change shared pins and names.";ue.push({label:V.pinnedAt?"Unpin":"Pin to top",icon:V.pinnedAt?o.jsx(JS,{"aria-hidden":!0}):o.jsx(u0,{"aria-hidden":!0}),disabled:!J||!ne,title:he,onSelect:()=>{j.pinWorkspace(V.id,!V.pinnedAt)},testId:V.pinnedAt?"project-unpin":"project-pin"},{label:"Rename workspace",icon:o.jsx(Ui,{"aria-hidden":!0}),disabled:!J||!ne,title:he,onSelect:()=>ge(V),testId:"project-rename"})}else L.capabilities.includes("workspace.registry")&&J&&(A?.workspaces??[]).includes(E)&&ue.push({label:"Add to projects",icon:o.jsx(cy,{"aria-hidden":!0}),disabled:!ne,onSelect:()=>{j.registerProject(E)},testId:"project-register"});return ue.push({label:"Copy path",icon:o.jsx(ws,{"aria-hidden":!0}),group:ue.length>0,onSelect:()=>Qt(E,"Path"),testId:"project-copy-path"}),V?.branch&&ue.push({label:"Copy branch name",icon:o.jsx(Qs,{"aria-hidden":!0}),onSelect:()=>Qt(V.branch,"Branch name"),testId:"project-copy-branch"}),V&&le&&ue.push({label:V.managedWorktree?"Remove worktree":"Create worktree",icon:o.jsx(Qs,{"aria-hidden":!0}),group:!0,disabled:!ne,onSelect:()=>z({row:V}),testId:V.managedWorktree?"project-remove-worktree":"project-create-worktree"}),ue.push({label:"Open project settings",icon:o.jsx(DS,{"aria-hidden":!0}),group:!0,onSelect:()=>a("projects"),testId:"project-settings"}),ue},dn=E=>{const V=E===R&&(!C||!!Fe),ue=Je(E),he=zy(q.list.filter(be),_.sort),pe=N4(he,!!re[E]||!!Fe,un);return o.jsxs("div",{className:I(V&&"pb-3"),"data-testid":"sidebar-project","data-path":E,"data-workspace-id":ue?.id,"data-pinned":ue?.pinnedAt?"true":void 0,"data-branch":ue?.branch??void 0,"data-worktree":ue?.managedWorktree?"true":void 0,children:[o.jsx(L4,{path:E,name:jt(E),worktree:!!ue?.managedWorktree,expanded:V,canWrite:F&&ne,actions:js(E),onToggle:()=>cn(E),onNewSession:()=>ze(E)}),V?o.jsxs("div",{children:[q.status==="loading"&&!q.list.length?o.jsx("div",{className:"py-2 pl-4",children:o.jsx(Ft,{label:"Loading sessions…",className:"text-xs"})}):null,q.status==="error"?o.jsxs("div",{className:"mx-1 mb-1 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-xs text-destructive",role:"alert",children:[q.error?.message," ",o.jsx("button",{type:"button",className:"text-highlight underline-offset-4 hover:underline",onClick:()=>{j.refreshSessions()},children:"Try again"})]}):null,q.status==="ready"&&!q.list.length?F&&ne?o.jsxs("button",{type:"button",onClick:()=>ze(E),"aria-label":`Start a session in ${jt(E)}`,className:I("group mb-0.5 flex min-h-11 w-full items-center md:min-h-9 gap-2 rounded-lg py-2 pl-4 pr-3 text-left text-sm text-muted-foreground hover:text-foreground",Ql,Dn),children:[o.jsx("span",{className:"flex h-5 w-4 shrink-0 items-center justify-center",children:o.jsx(ks,{"aria-hidden":!0,className:"size-3.5"})}),o.jsx("span",{className:"truncate",children:"New session"})]}):o.jsx("p",{className:"flex min-h-9 items-center py-2 pl-10 pr-3 text-sm text-muted-foreground",children:"No sessions yet"}):null,Fe&&q.list.length&&!he.length?o.jsxs("p",{className:"flex min-h-9 items-center py-2 pl-10 pr-3 text-sm text-muted-foreground",children:["No sessions match “",ee.trim(),"”"]}):null,o.jsx("ul",{children:pe.visible.map($e=>Gn(E,$e))}),pe.canToggle||re[E]?o.jsx("button",{type:"button",onClick:()=>de($e=>({...$e,[E]:!$e[E]})),"data-testid":"sidebar-show-more",className:I("flex min-h-9 w-full items-center rounded-lg py-1 pl-10 pr-3 text-left text-xs text-muted-foreground hover:text-foreground",Ql,Dn),children:re[E]?"Show less":"Show more"}):null]}):null]},E)},fn=()=>{const E=[...R?q.list.map(he=>({path:R,session:he})):[],...Object.entries(ye).filter(([he])=>Me.includes(he)&&he!==R).flatMap(([he,pe])=>pe.map($e=>({path:he,session:$e})))].filter(he=>Me.includes(he.path)&&be(he.session)),V=zy(E.map(he=>he.session),"lastPrompt").map(he=>E.find(pe=>pe.session===he)),ue=T4(V.map(he=>he.session),un);return ue.length?ue.map(he=>o.jsxs("div",{"data-testid":`sidebar-status-${he.bucket}`,children:[o.jsx(Zd,{title:he.label}),o.jsx("ul",{children:he.sessions.map(pe=>{const $e=V.find(We=>We.session===pe);return Gn($e.path,pe)})})]},he.bucket)):o.jsx("p",{className:"px-2 py-3 text-sm text-muted-foreground",children:Fe?`No sessions match “${ee.trim()}”`:"No sessions yet"})},Ct=E=>{switch(E){case"new-session":return o.jsx(ql,{icon:ks,label:"New session",onClick:()=>{s(),u()},disabled:!R||!F||!ne,title:F?void 0:"Your access token cannot start sessions.",shortcut:Pl("session.new",Q)});case"history":return o.jsx(ql,{icon:cc,label:"History",onClick:()=>{h(),u()},active:m,disabled:!R,testId:"sidebar-history"});case"search":return o.jsx(R4,{query:ee,onQuery:xe,open:H,onOpen:()=>{fe(!0),Y(!1)},onClose:At,focusRequest:Rt});case"tasks":return o.jsx(ql,{icon:oh,label:"Tasks",onClick:()=>{p?.(),u()},active:x,disabled:!R||!p,testId:"sidebar-tasks"})}},jn=B.sidebar.footer.filter(E=>E.visible);return o.jsxs("nav",{"aria-label":"Workspaces and sessions",className:"relative flex h-full min-h-0 flex-col bg-sidebar",children:[o.jsx("div",{className:"flex shrink-0 flex-col gap-0.5 border-b border-border pb-1.5 pt-2",children:B.sidebar.header.filter(E=>E.visible).map(E=>o.jsx(b.Fragment,{children:Ct(E.id)},E.id))}),d?o.jsx("button",{type:"button","aria-label":"Close sessions",onClick:d,className:I("absolute right-[9.5px] top-3 z-10 flex size-8 items-center justify-center rounded-lg bg-sidebar text-muted-foreground hover:text-foreground",Dn),children:o.jsx(en,{"aria-hidden":!0,className:"size-4"})}):null,o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-2 pb-4 pt-0.5",children:[_.grouping==="project"&&Qe.length?o.jsxs("div",{"data-testid":"sidebar-pinned",children:[o.jsx(Zd,{title:"Pinned",testId:"sidebar-pinned-header"}),Qe.map(dn)]}):null,o.jsx(Zd,{title:"Workspaces",children:o.jsx(O4,{display:_,projects:Re,onChange:Ht})}),ce.error?o.jsxs("p",{role:"alert",className:"px-2 pb-2 text-xs text-destructive",children:[ce.error," ",o.jsx("button",{type:"button",className:"underline",onClick:()=>{j.refreshRegistry()},children:"Retry"})]}):null,Re.length?_.grouping==="status"?fn():Ue.map(dn):o.jsxs("div",{className:"mt-1 px-2 py-3 text-sm","data-testid":"sidebar-no-projects",children:[o.jsx("p",{className:"text-foreground",children:"No projects yet"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"This access token grants no workspace. The host owner adds one with alp-gateway credential create --workspace."})]})]}),jn.length?o.jsx("div",{className:"flex shrink-0 flex-col gap-0.5 border-t border-border py-1.5","data-testid":"sidebar-footer-items",children:jn.map(E=>o.jsx(b.Fragment,{children:Ct(E.id)},E.id))}):null,o.jsxs("div",{className:"flex shrink-0 items-center border-t border-border px-2 py-1.5","data-testid":"sidebar-footer-bottom-line",children:[o.jsx(Jd,{label:"Add project",onClick:()=>Z(!0),testId:"sidebar-add-project",children:o.jsx(cy,{"aria-hidden":!0})}),o.jsx(Jd,{label:"Usage",onClick:()=>a("usage"),testId:"sidebar-usage-icon",children:o.jsx(TS,{"aria-hidden":!0})}),o.jsx(Kt,{label:"Hosts",title:`${A?.label??"Access token"} · ${kn}${ne?"":" · reconnecting"}`,align:"start",testId:"sidebar-hosts-trigger",trigger:o.jsxs(o.Fragment,{children:[o.jsx(Qr,{"aria-hidden":!0,className:"!size-[19px] md:!size-[15px]"}),o.jsx("span",{"aria-hidden":!0,className:I("absolute bottom-[11px] right-[11px] size-1.5 md:bottom-[5px] md:right-[5px] rounded-full ring-2 ring-sidebar",ne?"bg-dot-success":"bg-dot-warning")})]}),triggerClassName:zf,items:[{label:kn,icon:o.jsx(Qr,{"aria-hidden":!0}),hint:ne?"Online":"Reconnecting",onSelect:()=>a("host"),testId:"sidebar-host-option"},{label:"Connections",icon:o.jsx(c0,{"aria-hidden":!0}),onSelect:()=>a("connections")},{label:"Disconnect",icon:o.jsx(VS,{"aria-hidden":!0}),destructive:!0,group:!0,onSelect:()=>j.disconnect(),testId:"sidebar-disconnect"}]}),o.jsx("span",{className:"flex-1"}),o.jsx(Kt,{label:"Help and support",align:"start",testId:"sidebar-help-trigger",trigger:o.jsx(AS,{"aria-hidden":!0}),triggerClassName:zf,items:[{label:"Run diagnostics",onSelect:()=>a("diagnostics")},...l?[{label:"Keyboard shortcuts",hint:Pl("shortcuts.toggle",Q)||void 0,onSelect:l}]:[],{label:"Report an issue",group:!0,onSelect:()=>{window.open(M4,"_blank","noopener,noreferrer")}},{label:"What's new",onSelect:()=>{window.open(z4,"_blank","noopener,noreferrer")}}]}),o.jsx(Jd,{label:"Settings",onClick:()=>a(),testId:"sidebar-settings",children:o.jsx(ch,{"aria-hidden":!0})})]}),o.jsx(D4,{open:U,onClose:()=>Z(!1),unregistered:et}),o.jsx(q4,{row:oe,onClose:()=>ge(null)}),T?o.jsx(C4,{workspaceId:T.row.id,managed:!!T.row.managedWorktree,online:ne,open:!0,onClose:()=>z(null)}):null]})}const $4=6e3,Wr=()=>typeof window<"u"&&"Notification"in window;function U4(){const[s,t]=b.useState(()=>Wr()?Notification.permission:"unsupported");b.useEffect(()=>{if(!Wr())return;const a=()=>t(Notification.permission);return window.addEventListener("focus",a),document.addEventListener("visibilitychange",a),()=>{window.removeEventListener("focus",a),document.removeEventListener("visibilitychange",a)}},[]);const i=b.useCallback(async()=>{if(Wr())try{t(await Notification.requestPermission())}catch{t(Notification.permission)}},[]);return{permission:s,request:i}}function H4({onOpenSession:s}){const t=Ee(),i=Oe(),{workspace:a,sessions:l,tree:u,attention:d,selected:h,focus:m}=t,p=b.useMemo(()=>fS(t),[t.turnAttention,l,u]);b.useEffect(()=>{const O=()=>i.setPresence({visible:document.visibilityState==="visible",focused:document.hasFocus()});return O(),window.addEventListener("focus",O),window.addEventListener("blur",O),document.addEventListener("visibilitychange",O),()=>{window.removeEventListener("focus",O),window.removeEventListener("blur",O),document.removeEventListener("visibilitychange",O)}},[i]);const x=p4(l.list.map(O=>bh(O,ic(t,O.id),ao(t,O.id))),Object.keys(p).length>0);b.useEffect(()=>{let O=document.querySelector('link[rel="icon"]');O||(O=document.createElement("link"),O.rel="icon",document.head.append(O)),O.type="image/svg+xml",O.href=Ml[x],O.dataset.status=x},[x]),b.useEffect(()=>()=>{const O=document.querySelector('link[rel="icon"]');O&&(O.href=Ml.none,O.dataset.status="none")},[]);const y=u?.rootId,w=y?l.list.find(O=>O.id===y):void 0,k=y?Wn({id:y,title:u?.projection.sessions[y]?.title??w?.title}):a?Dt(a):"ALP";b.useEffect(()=>(document.title=k,()=>{document.title="ALP"}),[k]);const j=b.useRef({attention:d,live:{}}),S=b.useMemo(()=>{const O=j.current;O.attention!==d&&(O.live={}),O.attention=d;const L={...d};for(const[B,_]of Object.entries(O.live))L[B]=Math.max(L[B]??0,_);if(u){const B=Object.keys(u.projection.questions).length;L[u.rootId]=u.status==="attached"?B:Math.max(B,d[u.rootId]??0),u.status==="attached"&&(O.live[u.rootId]=B)}return L},[d,u]),A=b.useRef({workspace:null,since:Date.now(),counts:{}}),R=b.useRef(s);R.current=s,b.useEffect(()=>{const O=A.current;if(O.workspace!==a){A.current={workspace:a,since:Date.now(),counts:S};return}const L=y4(O.counts,S);if(O.counts=S,!L.length||!Wr()||Notification.permission!=="granted")return;const B=Date.now()-O.since<$4,_={visible:document.visibilityState==="visible",focused:document.hasFocus(),shown:m??h};for(const Q of L){const Y=(u?.rootId===Q?Object.values(u.projection.questions):[]).sort((fe,ee)=>(Date.parse(ee.askedAt??"")||0)-(Date.parse(fe.askedAt??"")||0))[0];if(B&&!(Y&&(Date.parse(Y.askedAt??"")||0)>=O.since)||Cy(_,Q)||Y?.sessionId&&Cy(_,Y.sessionId))continue;const H=Wn(l.list.find(fe=>fe.id===Q)??{id:Q,title:u?.rootId===Q?u.projection.sessions[Q]?.title:void 0});try{const fe=new Notification("Agent needs attention",{body:`${H}: ${Y?.body?l1(Y.body):"Waiting for your answer."}`,tag:`alp-question-${Q}`,icon:Ml.attention});fe.onclick=()=>{window.focus(),R.current(Q),fe.close()}}catch{}}},[S,a,u,l,h,m]);const q=b.useRef({workspace:a,entries:p});b.useEffect(()=>{const O=q.current,L=O.workspace===a?x4(O.entries,p):[];if(q.current={workspace:a,entries:p},!(!L.length||!Wr()||Notification.permission!=="granted"))for(const B of L){const _=p[B];if(!_)continue;const Q=Wn(l.list.find(fe=>fe.id===B)??{id:B,title:u?.rootId===B?u.projection.sessions[B]?.title:void 0}),{title:C,body:Y,tag:H}=g4({root:B,name:Q,reason:_.reason,message:_.message});try{const fe=new Notification(C,{body:Y,tag:H,icon:Ml.attention});fe.onclick=()=>{window.focus(),R.current(B),fe.close()}}catch{}}},[p,a,l,u])}const g1=[{id:"general",label:"General",icon:ch},{id:"appearance",label:"Appearance",icon:QS},{id:"sidebar",label:"Sidebar",icon:$a},{id:"chat",label:"Chat",icon:FS},{id:"terminal",label:"Terminal",icon:hc},{id:"editor",label:"Editor",icon:MS},{id:"files",label:"Files",icon:ah},{id:"diagnostics",label:"Diagnostics",icon:dN},{id:"about",label:"About",icon:rh}],x1=[{id:"host",label:"Overview",icon:Qr},{id:"projects",label:"Projects",icon:ly},{id:"connections",label:"Connections",icon:c0},{id:"pair-device",label:"Pair device",icon:oN},{id:"alp-templates",label:"Templates",icon:Yl},{id:"alp-agents",label:"Agents",icon:Oa},{id:"alp-skills",label:"Skills",icon:jS},{id:"alp-hooks",label:"Hooks",icon:mN},{id:"alp-mcp",label:"MCP servers",icon:tN},{id:"metadata",label:"Metadata",icon:cN},{id:"voice",label:"Voice",icon:XS},{id:"workspaces",label:"Workspaces",icon:ly},{id:"providers",label:"Providers",icon:SS},{id:"usage",label:"Usage",icon:BS},{id:"terminals",label:"Terminals",icon:hc},{id:"plugins",label:"Plugins",icon:kS}],I4=Object.fromEntries([...g1,...x1].map(s=>[s.id,s.label])),G4={"new-session":{label:"New session",icon:ks},history:{label:"History",icon:cc},search:{label:"Search",icon:ti},tasks:{label:"Tasks",icon:oh}},Y4="Readable **content** and `code` preview.\n\n```ts\n// The highlight theme, code font and code size\nexport function greet(name: string): string {\n return `Hello, ${name}!`;\n}\n```";function V4(){return o.jsx("section",{className:"mb-6 rounded-lg border border-border bg-background p-4","aria-label":"Live preview of content typography, syntax theme, and code font","data-testid":"appearance-preview",children:o.jsx(fo,{text:Y4})})}const yc="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset";function rt({title:s,action:t,children:i}){return o.jsxs("section",{className:"mb-6",children:[s||t?o.jsxs("div",{className:"mb-3 ml-1 flex items-center justify-between gap-2",children:[s?o.jsx("h3",{className:"text-xs font-normal text-muted-foreground",children:s}):o.jsx("span",{}),t]}):null,o.jsx("div",{className:"overflow-hidden rounded-lg border border-border bg-card",children:i})]})}function He({title:s,hint:t,children:i,first:a}){return o.jsxs("div",{className:I("flex flex-wrap items-center justify-between gap-3 p-4",!a&&"border-t border-border"),children:[o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"text-sm text-foreground",children:s}),t?o.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:t}):null]}),i!==void 0?o.jsx("div",{className:"min-w-0 max-w-full text-sm text-muted-foreground",children:i}):null]})}function ln({what:s,why:t}){return o.jsx(rt,{children:o.jsxs("div",{className:"flex items-start gap-3 p-4",role:"note",children:[o.jsx(rc,{"aria-hidden":!0,className:"mt-0.5 size-4 shrink-0 text-muted-foreground"}),o.jsxs("div",{children:[o.jsxs("p",{className:"text-sm",children:[s," is not available in this beta"]}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t})]})]})})}function La({label:s,value:t,options:i,onChange:a}){return o.jsx(ph,{"aria-label":s,value:t,onChange:l=>a?.(l.target.value),disabled:!a,className:"h-8 w-auto rounded-lg border-border bg-transparent pl-3 text-sm text-foreground disabled:cursor-default disabled:opacity-100",children:i.map(l=>o.jsx("option",{value:l.value,children:l.label},l.value))})}function K4(){const{permission:s,request:t}=U4(),i=s==="unsupported"?"This browser cannot show notifications.":s==="denied"?"Blocked in this browser. Allow notifications for this site in the browser settings to get them.":s==="granted"?"On: a notification when a session waits for your answer while you are elsewhere. The tab icon shows it too.":"Get a notification when a session waits for your answer while you are elsewhere. The browser asks first.";return o.jsx(He,{title:"Notifications",hint:i,children:s==="default"?o.jsx(we,{size:"sm",variant:"secondary",onClick:()=>{t()},children:"Enable"}):o.jsx("span",{className:"text-sm text-muted-foreground","data-testid":"notification-permission",children:s==="granted"?"Allowed":s==="denied"?"Blocked":"Unavailable"})})}function F4(s,t,i){return t==="mod-enter"?s==="interrupt"?`When the agent is running, ${i}+Enter interrupts. Enter inserts a new line.`:s==="queue"?`When the agent is running, ${i}+Enter queues. Enter inserts a new line.`:`When the agent is running, ${i}+Enter steers the active turn. Enter inserts a new line.`:s==="interrupt"?"When the agent is running, Enter interrupts. Command/Ctrl+Enter queues.":s==="queue"?"When the agent is running, Enter queues. Command/Ctrl+Enter submits.":"When the agent is running, Enter steers the active turn. Command/Ctrl+Enter queues."}const _y=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent)?"⌘":"Ctrl";function X4({mobile:s}){const t=Oe(),{preferences:i}=Ee();return o.jsxs(o.Fragment,{children:[o.jsx(rt,{title:"General",children:o.jsx(He,{first:!0,title:"Language",hint:"App language. This beta speaks English; the agents' language is a host setting (Host › Overview).",children:o.jsx(La,{label:"Language",value:"system",options:[{value:"system",label:"System"}]})})}),o.jsxs(rt,{title:"Sending",children:[s?null:o.jsx(He,{first:!0,title:"Send shortcut",children:o.jsx(La,{label:"Send shortcut",value:i.sendShortcut,onChange:a=>t.updatePreferences({sendShortcut:a}),options:[{value:"enter",label:"Enter"},{value:"mod-enter",label:`${_y}+Enter`}]})}),o.jsx(He,{first:s,title:"Default send",hint:F4(i.sendBehavior,s?"enter":i.sendShortcut,_y),children:o.jsx(La,{label:"Default send",value:i.sendBehavior,onChange:a=>t.setSendBehavior(a),options:[{value:"interrupt",label:"Interrupt"},{value:"steer",label:"Steer"},{value:"queue",label:"Queue"}]})})]}),o.jsxs(rt,{title:"This browser",children:[o.jsx(He,{first:!0,title:"Saved settings",hint:"Every App setting and your last New session choices (team, model, thinking, permissions) stay in this browser. The access token never does.",children:o.jsx(we,{size:"sm",variant:"secondary",onClick:()=>t.resetPreferences(),children:"Reset"})}),o.jsx(K4,{})]})]})}function Zr({label:s,value:t,placeholder:i,numeric:a,limits:l,width:u="w-28",onCommit:d}){const[h,m]=b.useState(t);b.useEffect(()=>m(t),[t]);const p=()=>{if(!a||!l){h.trim()!==t?d(h.trim()):m(t);return}const x=Number.parseInt(h,10);if(!Number.isFinite(x)){m(t);return}const y=String(Math.min(l[1],Math.max(l[0],x)));m(y),y!==t&&d(y)};return o.jsx(Zn,{"aria-label":s,value:h,placeholder:i,inputMode:a?"numeric":void 0,onChange:x=>m(a?x.target.value.replace(/[^\d]/g,""):x.target.value),onBlur:p,onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),p())},onFocus:x=>x.target.select(),className:I("h-8",u,a&&"text-right tabular-nums")})}function ef({title:s,hint:t,label:i,value:a,limits:l,onCommit:u}){return o.jsx(He,{title:s,hint:t,children:o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx(Zr,{label:i,value:String(a),numeric:!0,limits:l,width:"w-16",onCommit:d=>u(Number(d))}),o.jsx("span",{className:"text-xs",children:"px"})]})})}function P4(){const s=Oe(),{preferences:t}=Ee(),i=Wd.find(a=>a.value===t.theme)?.swatch;return o.jsxs(o.Fragment,{children:[o.jsx(rt,{title:"Theme",children:o.jsx(He,{first:!0,title:"Theme",children:o.jsxs("span",{className:"flex items-center gap-2",children:[i?o.jsx("span",{"aria-hidden":!0,className:"size-3 rounded-full border border-border",style:{backgroundColor:i},"data-testid":"theme-swatch"}):null,o.jsxs(ph,{"aria-label":"Theme",value:t.theme,onChange:a=>s.setTheme(a.target.value),className:"h-8 w-auto rounded-lg border-border bg-transparent pl-3 text-sm text-foreground",children:[Wd.filter(a=>a.group==="primary").map(a=>o.jsx("option",{value:a.value,children:a.label},a.value)),o.jsx("option",{disabled:!0,children:"──────"}),Wd.filter(a=>a.group==="variant").map(a=>o.jsx("option",{value:a.value,children:a.label},a.value))]})]})})}),o.jsxs(rt,{title:"Fonts",children:[o.jsx(He,{first:!0,title:"Interface font",hint:"Used across the app. Leave empty for the system default",children:o.jsx(Zr,{label:"Interface font family",value:t.uiFontFamily,placeholder:Z0,width:"w-64 max-w-full",onCommit:a=>s.updatePreferences({uiFontFamily:a})})}),o.jsx(ef,{title:"Interface size",hint:"Used for navigation, controls, and labels",label:"Interface font size",value:t.uiFontSize,limits:On.uiFontSize,onCommit:a=>s.updatePreferences({uiFontSize:a})}),o.jsx(ef,{title:"Content size",hint:"Used for chat text and rendered Markdown",label:"Content font size",value:t.contentFontSize,limits:On.contentFontSize,onCommit:a=>s.updatePreferences({contentFontSize:a})}),o.jsx(He,{title:"Code font",hint:"Used in code, diffs, and the terminal output. Leave empty for the system default",children:o.jsx(Zr,{label:"Code font family",value:t.monoFontFamily,placeholder:J0,width:"w-64 max-w-full",onCommit:a=>s.updatePreferences({monoFontFamily:a})})}),o.jsx(ef,{title:"Code size",hint:"Used for code, diffs, and terminal output",label:"Code font size",value:t.codeFontSize,limits:On.codeFontSize,onCommit:a=>s.updatePreferences({codeFontSize:a})})]}),o.jsx(rt,{title:"Layout",children:o.jsx(He,{first:!0,title:"Content width",hint:"Max width of chat and Markdown files on wide screens",children:o.jsxs("span",{className:"flex items-center gap-2",children:[t.contentMaxWidth!==null?o.jsx(we,{size:"sm",variant:"ghost","aria-label":"Reset content width to default",onClick:()=>s.updatePreferences({contentMaxWidth:null}),children:"Reset"}):null,o.jsx(Zr,{label:"Content width in pixels",value:String(e1(t)),numeric:!0,limits:On.contentMaxWidth,width:"w-20",onCommit:a=>s.updatePreferences({contentMaxWidth:Number(a)})}),o.jsx("span",{className:"text-xs",children:"px"})]})})}),o.jsx(rt,{title:"Syntax",children:o.jsx(He,{first:!0,title:"Highlight theme",hint:"Colors for code, independent of the app theme",children:o.jsx(La,{label:"Highlight theme",value:t.syntaxTheme,onChange:a=>s.updatePreferences({syntaxTheme:a}),options:X3})})}),o.jsx(V4,{})]})}function Q4(){const s=Oe(),{preferences:t}=Ee(),i=(u,d)=>s.updatePreferences({sidebar:{...t.sidebar,[u]:d}}),a=(u,d,h)=>{const m=[...t.sidebar[u]];[m[d],m[d+h]]=[m[d+h],m[d]],i(u,m)},l=(u,d,h)=>o.jsxs(rt,{title:d,children:[o.jsx("p",{className:"px-4 pt-3 text-xs text-muted-foreground",children:h}),t.sidebar[u].map((m,p,x)=>{const y=G4[m.id];return o.jsxs("div",{className:I("flex items-center gap-2 p-4",p>0&&"border-t border-border"),"data-testid":`sidebar-nav-item-${m.id}`,children:[o.jsx(y.icon,{"aria-hidden":!0,strokeWidth:1.75,className:"size-4 shrink-0 text-muted-foreground"}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-foreground",children:y.label}),o.jsx(we,{size:"icon",variant:"ghost",className:"size-7","aria-label":`Move ${y.label} up`,disabled:p===0,onClick:()=>a(u,p,-1),children:o.jsx(Dl,{"aria-hidden":!0})}),o.jsx(we,{size:"icon",variant:"ghost",className:"size-7","aria-label":`Move ${y.label} down`,disabled:p===x.length-1,onClick:()=>a(u,p,1),children:o.jsx(vS,{"aria-hidden":!0})}),o.jsx(t1,{checked:m.visible,"aria-label":y.label,onCheckedChange:w=>i(u,x.map(k=>k.id===m.id?{...k,visible:w}:k))})]},m.id)})]});return o.jsxs(o.Fragment,{children:[l("header","Header","Choose which items appear at the top of the sidebar and in what order"),l("footer","Footer","Choose which rows appear at the bottom of the sidebar and in what order. The host and Settings row always shows")]})}function W4(){const s=Oe(),{preferences:t}=Ee();return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:"Detail level",children:[o.jsx(He,{first:!0,title:"Chat display",hint:"How much of an agent's work the chat shows",children:o.jsx(La,{label:"Chat display",value:t.chatDisplay,onChange:i=>s.updatePreferences({chatDisplay:i}),options:[{value:"full",label:"Full"},{value:"collapseToolCalls",label:"Collapse tool calls"},{value:"collapseTurns",label:"Collapse turns"}]})}),o.jsx(He,{title:"Chat outline",hint:"Show an outline for jumping between prompts",children:o.jsx(t1,{checked:t.chatOutline,"aria-label":"Chat outline",onCheckedChange:i=>s.updatePreferences({chatOutline:i})})})]}),o.jsx(ln,{what:"Always expand reasoning",why:"ALP's hosts do not send the agents' reasoning, so there is nothing to expand."})]})}function Z4(){const s=Oe(),{preferences:t}=Ee();return o.jsx(rt,{title:"Terminal",children:o.jsx(He,{first:!0,title:"Terminal scrollback",hint:"Lines kept in the built-in terminal buffer",children:o.jsx(Zr,{label:"Terminal scrollback lines",value:String(t.terminalScrollback),numeric:!0,limits:On.terminalScrollback,onCommit:i=>s.updatePreferences({terminalScrollback:Number(i)})})})})}function J4(){return o.jsx(rt,{title:"Files",children:o.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground","data-testid":"file-panel-settings-empty",children:"File panels appear here when a plugin adds one"})})}function eT(){const s=typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: light)").matches;return{userAgent:navigator.userAgent,language:navigator.language,online:navigator.onLine,secure:window.isSecureContext,viewport:`${window.innerWidth}×${window.innerHeight} @${window.devicePixelRatio}x`,colorScheme:s?"light":"dark"}}function tT(){const{connection:s,principal:t,preferences:i}=Ee(),[a,l]=b.useState(null),[u,d]=b.useState("idle"),h=()=>{d("idle"),l({version:"0.0.1-beta.9",connection:s,principal:t,preferences:i,browser:eT(),now:new Date})},m=async()=>{if(a)try{await navigator.clipboard.writeText(A3(a)),d("copied")}catch{d("failed")}};return o.jsxs(o.Fragment,{children:[o.jsx(rt,{title:"Diagnostics",children:o.jsx(He,{first:!0,title:"App diagnostic",hint:"Collect connection, host and browser details. Providers, logs and the daemon itself: run alp doctor on the host.",children:o.jsx(we,{size:"sm",variant:"secondary","data-testid":"settings-diagnostics-run",onClick:h,children:a?"Refresh":"Run"})})}),a?o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:`Diagnostic, ${a.now?.toLocaleTimeString()??""}`,action:o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs","data-testid":"settings-diagnostics-copy",onClick:()=>{m()},children:u==="copied"?"Copied":"Copy diagnostic"}),children:[u==="failed"?o.jsx("p",{role:"alert",className:"px-4 py-3 text-xs text-destructive",children:"Failed to copy diagnostic. Select the values below instead."}):null,o.jsx("p",{className:"px-4 py-3 text-xs text-muted-foreground",children:"It holds no access token, prompts or files."})]}),Q0(a).map(p=>o.jsx(rt,{title:p.title,children:p.rows.map(([x,y],w)=>o.jsx(He,{first:w===0,title:x,children:o.jsx("span",{className:"break-all font-mono text-xs","data-testid":`diagnostics-${x.toLowerCase().replace(/\W+/g,"-")}`,children:y})},x))},p.title))]}):null]})}function y1(s){return s.hostname??s.gateway.replace(/^https?:\/\//,"")}const Ly=s=>s?.trim().replace(/^v/i,"")||null,nT="https://github.com/phucanh08/alp/releases";function sT(){const{connection:s}=Ee(),t=y1(s),i=Ly(s.daemonVersion),a=s.phase!=="open",l=!!i&&i!==Ly("0.0.1-beta.9");return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:"About",children:[o.jsxs(He,{first:!0,title:"App version",hint:"This device",children:["v","0.0.1-beta.9"]}),o.jsx("a",{href:nT,target:"_blank",rel:"noopener noreferrer","data-testid":"settings-whats-new",className:I("block hover:bg-sidebar-hover",yc),children:o.jsx(He,{title:"What's new",hint:"Release notes for every version",children:o.jsx(Jn,{"aria-hidden":!0,className:"size-4"})})})]}),o.jsx(rt,{title:"Connected hosts",children:o.jsx(He,{first:!0,title:t,hint:a?"Offline":l?"Version differs from this device":"ALP on the host, through the gateway (ALP JSON-RPC v1)",children:o.jsx("span",{"data-testid":"connected-host-version",children:i?`v${i}`:"unknown"})})})]})}function iT(){const s=Oe(),{principal:t,connection:i,settings:a}=Ee(),[l,u]=b.useState(!1);b.useEffect(()=>{s.loadSettings()},[s]);const d=["session.read","session.write","project.read","project.write","workspace.write","workspace.manage","files.read","library.write","terminal.exec"];return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:"Host",children:[o.jsx(He,{first:!0,title:"Machine",hint:"The host's name, as it reports it.",children:i.hostname??"unknown"}),o.jsx(He,{title:"ALP",children:i.daemonVersion??"unknown"}),o.jsx(He,{title:"Gateway",children:o.jsx("span",{className:"break-all font-mono text-xs",children:i.gateway})}),o.jsx(He,{title:"Agents' language",hint:"Set on the host with alp; read only here.",children:a.status==="loading"?o.jsx(Ft,{label:"Loading…",className:"text-xs"}):a.language?`${a.language.applies}${a.language.language?"":" (default)"}`:"Not available"}),a.status==="error"?o.jsx("p",{role:"alert",className:"border-t border-border px-4 py-3 text-xs text-destructive",children:a.error?.message}):null]}),o.jsx(rt,{title:`Models new sessions can pick${a.models.length?` (${a.models.length})`:""}`,action:s.hasCapability("catalog.live")?o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs","data-testid":"settings-models-refresh",disabled:l,onClick:()=>{u(!0),s.refreshModels().catch(()=>{}).finally(()=>u(!1))},children:l?"Refreshing…":"Refresh"}):void 0,children:a.models.length?o.jsx("ul",{className:"max-h-72 divide-y divide-border overflow-y-auto",children:a.models.map(h=>o.jsxs("li",{className:"flex items-center justify-between gap-3 px-4 py-2 text-sm",children:[o.jsx("span",{className:"min-w-0 truncate",children:h.label}),o.jsx("span",{className:"shrink-0 font-mono text-[length:calc(11px*var(--ui-scale))] text-muted-foreground",children:h.id})]},h.id))}):o.jsx(He,{first:!0,title:a.status==="ready"?"None listed":"Loading…"})}),o.jsxs(rt,{title:"Access token",children:[o.jsxs(He,{first:!0,title:"Name",children:[t?.label??"—"," ",o.jsxs("span",{className:"font-mono text-xs",children:["(",t?.id,")"]})]}),o.jsx(He,{title:"Allows",children:o.jsx("span",{className:"flex flex-wrap justify-end gap-1",children:d.map(h=>{const m=Te(t??void 0,h);return o.jsxs("span",{className:I("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs [&_svg]:size-3",m?"bg-primary/15 text-highlight":"bg-secondary text-muted-foreground"),children:[m?o.jsx(lc,{"aria-hidden":!0}):o.jsx(rc,{"aria-hidden":!0}),h]},h)})})}),o.jsx(He,{title:"Modes",hint:"Permissions a session may run with.",children:t?.modes?t.modes.map(Fl).join(", "):"Any"})]})]})}function aT(){const{principal:s,registry:t}=Ee();return b.useCallback(i=>t.workspaces.filter(a=>!a.archivedAt&&(a.directory===i||s?.workspaceRoots?.some(l=>l.path===i&&l.canonical===a.directory))),[s,t])}function b1(s,t){if(!s)return"This host does not list its workspaces. Update ALP on the host.";if(!Te(t??void 0,"project.read"))return"Your access token cannot read the host's workspace list (it needs project.read)."}function rT(){const s=Oe(),{principal:t,workspace:i,registry:a,connection:l}=Ee(),u=aT(),[d,h]=b.useState(""),m=t?.workspaces??[],p=b1(s.hasCapability("workspace.registry"),t);b.useEffect(()=>{p||s.refreshRegistry()},[s,p]);const x=p?[]:m.filter(k=>!u(k).length),y=Te(t??void 0,"workspace.write"),w=l.phase==="open";return o.jsxs(o.Fragment,{children:[o.jsx(rt,{title:"Projects this token opens",children:m.length?m.map((k,j)=>o.jsx(He,{first:j===0,title:Dt(k),hint:o.jsx("span",{className:"break-all font-mono",children:k}),children:o.jsxs("span",{className:"flex items-center gap-2",children:[p?null:o.jsx("span",{className:"text-xs","data-testid":"project-registered",children:u(k).length?"Registered":"Not registered"}),k===i?o.jsx("span",{className:"text-highlight","data-testid":"project-current",children:"Current"}):o.jsx(we,{size:"sm",variant:"secondary",onClick:()=>s.selectWorkspace(k),children:"Open"})]})},k)):o.jsx(He,{first:!0,title:"No projects",hint:"This access token grants no workspace."})}),p?null:o.jsxs(rt,{title:"Register a project",children:[o.jsx(He,{first:!0,title:"Granted directory",hint:y?"Registering adds a granted directory to the host's shared workspace list, so terminals, Git and worktrees can use it. It changes no files.":"Ask the host owner to add workspace.write to your credential to register projects.",children:y&&x.length?o.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:k=>{k.preventDefault(),d&&s.registerProject(d).then(()=>h(""))},children:[o.jsx(La,{label:"Directory to register",value:d,onChange:h,options:[{value:"",label:"Choose a directory"},...x.map(k=>({value:k,label:Dt(k)}))]}),o.jsx(we,{size:"sm",type:"submit",disabled:!d||!w||a.loading,children:"Register"})]}):y?o.jsx("span",{className:"text-xs",children:"Every granted directory is registered"}):null}),a.error?o.jsx("p",{role:"alert",className:"border-t border-border px-4 py-3 text-xs text-destructive",children:a.error}):null]}),o.jsx(ln,{what:"Granting or removing projects",why:"The access token decides which projects you can open. The host owner grants them with alp-gateway credential create --workspace."})]})}function oT({row:s,first:t,writable:i,online:a,busy:l}){const u=Oe(),{workspace:d,principal:h}=Ee(),[m,p]=b.useState(!1),[x,y]=b.useState(s.title??""),w=s.title||Dt(s.directory),k=h?.workspaces?.some(A=>A===s.directory||h.workspaceRoots?.some(R=>R.path===A&&R.canonical===s.directory))||s.managedWorktree,j=h?.workspaceRoots?.find(A=>A.canonical===s.directory)?.path??s.directory,S=async()=>{await u.renameWorkspace(s.id,x)&&p(!1)};return o.jsxs("div",{className:I("flex flex-col gap-2 p-4",!t&&"border-t border-border"),"data-testid":"settings-workspace-row","data-workspace-id":s.id,children:[o.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsxs("div",{className:"flex items-center gap-2 text-sm text-foreground",children:[o.jsx("span",{className:"truncate",children:w}),s.pinnedAt?o.jsx(u0,{"aria-label":"Pinned",className:"size-3 shrink-0 text-muted-foreground"}):null,s.managedWorktree?o.jsx("span",{className:"rounded-full bg-secondary px-2 py-0.5 text-[length:calc(11px*var(--ui-scale))] text-muted-foreground",children:"Worktree"}):null]}),o.jsx("div",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:s.directory}),s.branch!==void 0?o.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:s.branch||"Detached HEAD"}):null]}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx(we,{size:"sm",variant:"ghost","aria-pressed":!!s.pinnedAt,disabled:!i||!a||l,onClick:()=>{u.pinWorkspace(s.id,!s.pinnedAt)},"aria-label":`${s.pinnedAt?"Unpin":"Pin"} workspace ${w}`,children:s.pinnedAt?"Unpin":"Pin"}),o.jsx(we,{size:"sm",variant:"ghost",disabled:!i||!a||l,onClick:()=>{y(s.title??""),p(A=>!A)},"aria-label":`Rename workspace ${w}`,children:"Rename"}),k?j===d?o.jsx("span",{className:"text-xs text-highlight",children:"Open"}):o.jsx(we,{size:"sm",variant:"secondary",onClick:()=>u.selectWorkspace(j),children:"Open"}):null]})]}),m?o.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:A=>{A.preventDefault(),S()},children:[o.jsx(Zn,{"aria-label":`New name for ${w}`,value:x,maxLength:200,onChange:A=>y(A.target.value),placeholder:Dt(s.directory),className:"h-8 min-w-0 flex-1",autoFocus:!0}),o.jsx(we,{size:"sm",type:"submit",disabled:!a||l,children:"Save"}),o.jsx(we,{size:"sm",variant:"ghost",type:"button",onClick:()=>p(!1),children:"Cancel"})]}):null]})}function lT(){const s=Oe(),{principal:t,registry:i,connection:a}=Ee(),l=b1(s.hasCapability("workspace.registry"),t);if(b.useEffect(()=>{l||s.refreshRegistry()},[s,l]),l)return o.jsx(ln,{what:"Workspace settings",why:l});const u=Te(t??void 0,"workspace.write"),d=a.phase==="open",h=i.workspaces.filter(m=>!m.archivedAt).sort((m,p)=>+!!p.pinnedAt-+!!m.pinnedAt||(m.title||Dt(m.directory)).localeCompare(p.title||Dt(p.directory))||m.id.localeCompare(p.id));return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:`Shared with every client of this host${h.length?` (${h.length})`:""}`,action:o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs",disabled:i.loading||!d,onClick:()=>{s.refreshRegistry()},children:i.loading?"Refreshing…":"Refresh"}),children:[i.error?o.jsx("p",{role:"alert",className:"px-4 py-3 text-xs text-destructive",children:i.error}):null,h.length?h.map((m,p)=>o.jsx(oT,{row:m,first:p===0&&!i.error,writable:u,online:d,busy:!!i.loading},m.id)):o.jsx(He,{first:!i.error,title:i.loading?"Loading…":"No workspaces",hint:i.loading?void 0:"Register a granted directory under Host › Projects."})]}),u?null:o.jsx(rt,{children:o.jsx(He,{first:!0,title:"Read only",hint:"Pins and names are shared with every client of this host. Ask the host owner to add workspace.write to your credential to change them."})}),o.jsx(ln,{what:"Archiving workspaces, labels and placement",why:"The host's owner manages them with alp on the host."})]})}function cT({onNavigate:s}){const t=Ee(),i=t.connection.capabilities.includes("terminal"),a=Te(t.principal??void 0,"terminal.exec"),l=Pb(t),u=!l.ok&&l.reasons.includes("unregistered"),d=Te(t.principal??void 0,"workspace.write"),h=(m,p)=>o.jsxs("span",{className:I("inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs [&_svg]:size-3",m?"bg-primary/15 text-highlight":"bg-secondary text-muted-foreground"),children:[m?o.jsx(lc,{"aria-hidden":!0}):o.jsx(rc,{"aria-hidden":!0}),p]});return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:"Remote terminals",children:[o.jsx(He,{first:!0,title:"Host",hint:i?"The host's owner allowed remote terminals.":io.capability,children:o.jsx("span",{"data-testid":"terminals-host",children:h(i,i?"Allowed":"Not allowed")})}),o.jsx(He,{title:"Access token",hint:a?"Your access token may open terminals (terminal.exec).":io.permission,children:o.jsx("span",{"data-testid":"terminals-token",children:h(a,a?"terminal.exec":"No terminal.exec")})}),o.jsx(He,{title:"This workspace",hint:l.ok?"A terminal can open here from the + menu (Terminal).":[...l.messages,u?d?"Register it under Host › Projects; the terminal opens once it is in the list.":"Registering it needs workspace.write: ask the host owner to register it, or to add workspace.write to your credential.":""].filter(Boolean).join(" "),children:o.jsxs("span",{className:"flex items-center gap-2",children:[u&&d?o.jsx(we,{size:"sm",variant:"secondary","data-testid":"terminals-register",onClick:()=>s("projects"),children:"Register in Projects"}):null,o.jsx("span",{"data-testid":"terminals-workspace",children:h(l.ok,l.ok?"Ready":"Not available")})]})})]}),o.jsx(ln,{what:"Changing the host's terminal switch",why:"Only the host's owner turns remote terminals on or off, on the host: alp terminal allow --yes, alp terminal deny, alp terminal status. Font and colors are under App › Terminal."})]})}function uT(){const s=Oe(),{connection:t}=Ee(),i=t.gateway.startsWith("https:");return o.jsxs(rt,{title:"This connection",children:[o.jsx(He,{first:!0,title:"Gateway",children:o.jsx("span",{className:"break-all font-mono text-xs",children:t.gateway})}),o.jsx(He,{title:"State",children:t.phase==="open"?"Connected":t.phase==="reconnecting"?`Reconnecting (attempt ${t.attempt})`:t.phase}),o.jsx(He,{title:"Transport",hint:i?"TLS to the gateway.":"Plain HTTP, allowed only on this machine (loopback or an SSH tunnel).",children:i?"HTTPS / WSS":"Loopback HTTP / WS"}),o.jsx(He,{title:"Access token",hint:"Kept in this tab's memory only. Disconnecting forgets it.",children:o.jsx(we,{size:"sm",variant:"destructive",onClick:()=>s.disconnect(),children:"Disconnect"})})]})}function dT({kind:s,name:t,onClose:i}){const a=Oe(),[l,u]=b.useState({status:"loading"});b.useEffect(()=>{let h=!0;return u({status:"loading"}),a.getLibraryEntry(s,t).then(m=>{h&&u({status:"ready",entry:m})},m=>{h&&u({status:"error",error:Be(m).message})}),()=>{h=!1}},[a,s,t]);const d=l.entry;return o.jsx(rt,{title:t,action:o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:i,children:"Close"}),children:o.jsxs("div",{"data-testid":"library-entry","aria-label":`${t} content`,role:"group",children:[l.status==="loading"?o.jsx("div",{className:"p-4",children:o.jsx(Ft,{label:"Loading…",className:"text-xs"})}):null,l.status==="error"?o.jsx("p",{role:"alert",className:"p-4 text-xs text-destructive",children:l.error}):null,d?o.jsxs(o.Fragment,{children:[o.jsx(He,{first:!0,title:"Source",hint:d.usedBy.length?`Used by ${d.usedBy.join(", ")}`:void 0,children:o.jsxs("span",{className:"text-xs",children:[d.source,d.overrides?` · overrides ${d.overrides}`:""]})}),d.librarySkills?.length?o.jsx(He,{title:"Skills the library gives it",children:d.librarySkills.join(", ")}):null,h4(d.content).map(h=>o.jsxs("div",{className:"border-t border-border p-4",children:[o.jsx("div",{className:"mb-2 font-mono text-xs text-muted-foreground",children:h.label}),o.jsx("pre",{className:"max-h-96 overflow-auto whitespace-pre-wrap break-words rounded-md bg-secondary p-3 font-mono text-xs text-foreground",children:h.text})]},h.key)),d.secrets.length?o.jsxs("p",{className:"border-t border-border px-4 py-3 text-xs text-muted-foreground",children:[d.secrets.length===1?"One value that can hold a secret is":`${d.secrets.length} values that can hold secrets are`," shown as ",Xl,": the gateway keeps them on the host."]}):null]}):null]})})}function fT({kind:s,selected:t,onChanged:i}){const a=Oe(),[l,u]=b.useState(""),[d,h]=b.useState(""),[m,p]=b.useState(""),[x,y]=b.useState(null),[w,k]=b.useState(!1),[j,S]=b.useState(!1),[A,R]=b.useState(null),[q,O]=b.useState(null);b.useEffect(()=>{let B=!0;return k(!1),R(null),O(null),h(""),t?a.getLibraryEntry(s,t).then(_=>{if(B){if(_.source!=="project"||_.overrides||_.secrets.length||_.revision===void 0){O("This entry holds configuration the host runs or values kept on the host, so it is read only here.");return}u(t),y(_.revision),p(JSON.stringify(_.content,null,2)),k(!0)}},_=>{B&&R(Be(_).message)}):(u(""),y(null),p(JSON.stringify(s==="skills"?{body:""}:{instructions:"",config:{description:""}},null,2)),k(!0)),()=>{B=!1}},[a,s,t]);const L=async B=>{S(!0),R(null);try{const _=B==="save"?{name:l,content:JSON.parse(m),revision:x}:B==="delete"?{name:l,revision:x}:{from:l,to:d},Q=await a.writeLibrary(B,s,_);B==="save"&&y(Q.revision),(B==="delete"||B==="rename")&&k(!1),i()}catch(_){R(Be(_).message)}finally{S(!1)}};return o.jsx(rt,{title:t?"Edit project instructions":"New project instructions",children:o.jsxs("div",{className:"flex flex-col gap-3 p-4",children:[o.jsx("p",{className:"text-xs text-muted-foreground",children:"Agents and skills only. Host entries, executable configuration, references and extra files cannot be changed here."}),A?o.jsx("p",{role:"alert",className:"text-xs text-destructive",children:A}):null,q?o.jsx("p",{role:"note",className:"text-xs text-muted-foreground",children:q}):null,w?o.jsxs(o.Fragment,{children:[o.jsx(Zn,{"aria-label":"Entry name",value:l,onChange:B=>u(B.target.value),disabled:j||!!t,placeholder:"Entry name"}),o.jsx("textarea",{"aria-label":"Instruction entry JSON",className:"min-h-48 rounded border border-border bg-background p-2 font-mono text-xs",value:m,onChange:B=>p(B.target.value),disabled:j}),o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx(we,{size:"sm",disabled:j||!l.trim(),onClick:()=>{L("save")},children:"Save project entry"}),t?o.jsx(we,{size:"sm",variant:"secondary",disabled:j,onClick:()=>{L("delete")},children:"Delete project entry"}):null]}),t?o.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.jsx(Zn,{"aria-label":"New entry name",value:d,onChange:B=>h(B.target.value),placeholder:"New name",disabled:j}),o.jsx(we,{size:"sm",variant:"secondary",disabled:j||!d.trim(),onClick:()=>{L("duplicate")},children:"Duplicate"}),o.jsx(we,{size:"sm",variant:"secondary",disabled:j||!d.trim(),onClick:()=>{L("rename")},children:"Rename"})]}):null]}):null]})})}function Ta({kind:s,noun:t}){const i=Oe(),{workspace:a}=Ee(),[l,u]=b.useState({status:"loading",entries:[]}),[d,h]=b.useState(null),m=i.libraryBlock(),p=b.useCallback(()=>{let w=!0;return u(k=>({...k,status:"loading",error:void 0})),i.listLibrary(s).then(k=>{w&&u({status:"ready",entries:k})},k=>{w&&u({status:"error",entries:[],error:Be(k).message})}),()=>{w=!1}},[i,s]);if(b.useEffect(()=>m?void 0:p(),[p,m,a]),b.useEffect(()=>{h(null)},[s,a]),m)return o.jsx(ln,{what:`Listing ${t}`,why:m});const x=d?l.entries.find(w=>w.name===d):void 0,y=x&&x.source==="project"&&!x.overrides?x.name:null;return o.jsxs(o.Fragment,{children:[o.jsxs(rt,{title:a?`As ${Dt(a)} sees them`:void 0,action:o.jsx(we,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>p(),children:"Refresh"}),children:[l.status==="loading"&&!l.entries.length?o.jsx("div",{className:"p-4",children:o.jsx(Ft,{label:"Loading…",className:"text-xs"})}):null,l.status==="error"?o.jsx("p",{role:"alert",className:"p-4 text-xs text-destructive",children:l.error}):null,l.status==="ready"&&!l.entries.length?o.jsx(He,{first:!0,title:`No ${t}`}):null,l.entries.map((w,k)=>o.jsx("button",{type:"button",onClick:()=>h(j=>j===w.name?null:w.name),"aria-expanded":d===w.name,"data-testid":`library-row-${w.name}`,className:I("block w-full text-left hover:bg-sidebar-hover",yc,d===w.name&&"bg-sidebar-hover"),children:o.jsx(He,{first:k===0,title:o.jsx("span",{className:"font-mono text-[length:calc(13px*var(--ui-scale))]",children:w.name}),hint:[w.description,w.usedBy?.length?`Used by ${w.usedBy.join(", ")}`:""].filter(Boolean).join(" · ")||void 0,children:o.jsxs("span",{className:"text-xs",children:[w.source,w.overrides?` · overrides ${w.overrides}`:""]})})},`${w.source}:${w.name}`))]}),i.libraryWriteBlock(s)?null:o.jsx(fT,{kind:s,selected:y,onChanged:()=>p()},`${s}:${a}:${y??"new"}`),d?o.jsx(dT,{kind:s,name:d,onClose:()=>h(null)}):null,i.libraryWriteBlock(s)?o.jsx(ln,{what:`Editing ${t}`,why:`${i.libraryWriteBlock(s)} Open an entry to read it. Values that can hold secrets (environment, headers, MCP URLs and arguments, hook commands) show as ${Xl}. Changes configure commands the host runs, so edit them on the host with alp.`}):null]})}function hT({page:s,mobile:t,onNavigate:i}){switch(s){case"general":return o.jsx(X4,{mobile:t});case"appearance":return o.jsx(P4,{});case"sidebar":return o.jsx(Q4,{});case"chat":return o.jsx(W4,{});case"terminal":return o.jsx(Z4,{});case"files":return o.jsx(J4,{});case"editor":return o.jsx(ln,{what:"Editor",why:"This app opens a workspace's files read only (the Files panel); changing them is the agents' work, or yours on the host."});case"diagnostics":return o.jsx(tT,{});case"about":return o.jsx(sT,{});case"host":return o.jsx(iT,{});case"projects":return o.jsx(rT,{});case"connections":return o.jsx(uT,{});case"alp-templates":return o.jsx(Ta,{kind:"teams",noun:"templates"});case"alp-agents":return o.jsx(Ta,{kind:"agents",noun:"agents"});case"alp-skills":return o.jsx(Ta,{kind:"skills",noun:"skills"});case"alp-hooks":return o.jsx(Ta,{kind:"hooks",noun:"hooks"});case"alp-mcp":return o.jsx(Ta,{kind:"mcp",noun:"MCP servers"});case"providers":return o.jsxs(o.Fragment,{children:[o.jsx(Ta,{kind:"providers",noun:"providers"}),o.jsx(ln,{what:"Adding, testing or diagnosing providers",why:"Tests run commands on the host; they are not offered remotely."})]});case"pair-device":return o.jsx(ln,{what:"Pairing a device",why:"This app is the remote client: open it on the other device and connect with an access token."});case"voice":return o.jsx(ln,{what:"Voice",why:"Paseo's dictation and voice mode turn speech into prompts with a speech provider set up on the host. ALP's agents take text, and its hosts have no speech provider to set up."});case"metadata":return o.jsx(ln,{what:"Metadata generation",why:"A host setting the gateway does not expose."});case"workspaces":return o.jsx(lT,{});case"usage":return o.jsx(ln,{what:"Usage and limits",why:"Account-wide on the host; check with alp usage there."});case"terminals":return o.jsx(cT,{onNavigate:i});case"plugins":return o.jsx(ln,{what:"Plugins",why:"Installing plugins changes the host; not offered remotely."})}}function Oy({page:s,label:t,icon:i,selected:a,onSelect:l,mobile:u}){return o.jsxs("button",{type:"button",onClick:()=>l(s),"aria-current":a?"page":void 0,"data-testid":`settings-${s}`,className:I("flex min-h-7 w-full items-center gap-2 rounded-lg px-2 py-1 text-left text-sm text-muted-foreground hover:bg-sidebar-hover hover:text-foreground",yc,a&&"bg-sidebar-hover text-foreground",u&&"min-h-10"),children:[o.jsx(i,{"aria-hidden":!0,strokeWidth:1.75,className:"size-4 shrink-0"}),o.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),u?o.jsx(Jn,{"aria-hidden":!0,className:"size-4 text-extra-muted"}):null]})}function Dy({page:s,onSelect:t,mobile:i}){const{connection:a}=Ee(),l=y1(a);return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-2",children:[o.jsx("p",{className:"px-2 py-1 text-sm text-extra-muted",children:"App"}),g1.map(u=>o.jsx(Oy,{page:u.id,label:u.label,icon:u.icon,selected:s===u.id,onSelect:t,mobile:i},u.id))]}),o.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-2",children:[o.jsx("p",{className:"px-2 py-1 text-sm text-extra-muted",children:"Host"}),o.jsxs("div",{className:"flex min-h-7 items-center gap-2 px-2 py-1 text-sm",title:a.gateway,"data-testid":"settings-host-label",children:[o.jsx("span",{className:"flex size-4 items-center justify-center",children:o.jsx("span",{className:I("size-2 rounded-full",a.phase==="open"?"bg-dot-success":"bg-dot-warning")})}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-foreground",children:l})]}),x1.map(u=>o.jsx(Oy,{page:u.id,label:u.label,icon:u.icon,selected:s===u.id,onSelect:t,mobile:i},u.id))]})]})}function mT({onClose:s,mobile:t,initialPage:i}){const[a,l]=b.useState(i??(t?null:"general"));b.useEffect(()=>{const h=m=>{m.key==="Escape"&&!(m.target instanceof HTMLElement&&m.target.closest('[role="menu"],dialog'))&&s()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[s]);const u=(h,m)=>o.jsx("div",{className:"flex h-14 shrink-0 items-center gap-2 border-b border-border px-2 md:h-9",children:o.jsxs("button",{type:"button",onClick:m,className:I("flex min-h-7 items-center gap-2 rounded-lg px-2 py-1 text-sm text-muted-foreground hover:bg-sidebar-hover hover:text-foreground",yc),children:[o.jsx(th,{"aria-hidden":!0,className:"size-4"}),h]})}),d=a?o.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:o.jsxs("div",{className:"mx-auto w-full max-w-[720px] p-4 pt-14",children:[o.jsx("h2",{className:"mb-6 ml-1 text-[length:calc(26px*var(--ui-scale))] font-semibold text-foreground","data-testid":"settings-detail-header-title",children:I4[a]}),o.jsx(hT,{page:a,mobile:t,onNavigate:l})]})}):null;return t?o.jsxs("div",{role:"region","aria-label":"Settings",className:"flex h-dvh flex-col bg-background",children:[a?u("Settings",()=>l(null)):u("Back",s),a?d:o.jsx("nav",{"aria-label":"Settings",className:"min-h-0 flex-1 overflow-y-auto",children:o.jsx(Dy,{page:null,onSelect:l,mobile:!0})})]}):o.jsxs("div",{role:"region","aria-label":"Settings",className:"flex h-dvh overflow-hidden bg-background",children:[o.jsxs("nav",{"aria-label":"Settings",className:"flex w-[320px] shrink-0 flex-col border-r border-border bg-sidebar","data-testid":"settings-sidebar",children:[u("Back",s),o.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:o.jsx(Dy,{page:a,onSelect:l,mobile:!1})})]}),o.jsx("main",{className:"flex min-w-0 flex-1 flex-col","data-testid":"settings-detail-pane",children:d})]})}const pT=[{key:"list",label:"List"},{key:"board",label:"Board"},{key:"epics",label:"Epics"}],gT=["open","ready","closed","all"],Wl=(s,t)=>s.priority-t.priority||s.id.localeCompare(t.id),v1=(s,t)=>(t.closed?.at??t.updatedAt??"").localeCompare(s.closed?.at??s.updatedAt??"")||s.id.localeCompare(t.id);function vh(s){return s.status==="closed"?"closed":s.approvals?.length?"approve":s.status==="review"?"review":s.status==="in_progress"?"progress":s.type==="epic"?s.progress?.done?"progress":"ready":s.ready?"ready":"blocked"}const qy={approve:"Needs approval",review:"In review",progress:"In progress",ready:"Ready",blocked:"Blocked",closed:"Closed"},w1=s=>!!s.ready&&s.status!=="closed";function xT(s){const t=s.filter(i=>i.status==="closed").length;return{open:s.length-t,ready:s.filter(w1).length,closed:t,all:s.length}}function yT(s,t,i=""){const a=i.trim().toLowerCase().split(/\s+/).filter(Boolean);return s.filter(l=>{if(t==="open"&&l.status==="closed"||t==="ready"&&!w1(l)||t==="closed"&&l.status!=="closed")return!1;if(!a.length)return!0;const u=[l.id,l.title,l.type??"",l.assignee??"",...l.labels??[]].join(" ").toLowerCase();return a.every(d=>u.includes(d))})}const bT=[{key:"approve",title:"Waiting for your approval"},{key:"review",title:"In review"},{key:"progress",title:"In progress"},{key:"ready",title:"Ready"},{key:"waiting",title:"Blocked or waiting"},{key:"epics",title:"Epics"},{key:"closed",title:"Closed"}];function vT(s){return s.status==="closed"?"closed":s.approvals?.length?"approve":s.status==="review"?"review":s.status==="in_progress"?"progress":s.type==="epic"?"epics":s.ready?"ready":"waiting"}function wT(s){return bT.map(t=>{const i=s.filter(a=>vT(a)===t.key);return{...t,tasks:i.sort(t.key==="closed"?v1:Wl)}}).filter(t=>t.tasks.length)}const kT=[{key:"approve",title:"Needs approval"},{key:"blocked",title:"Blocked"},{key:"ready",title:"Ready"},{key:"progress",title:"In progress"},{key:"review",title:"In review"},{key:"closed",title:"Closed"}];function jT(s){return kT.map(t=>({...t,tasks:s.filter(i=>i.type!=="epic"&&vh(i)===t.key).sort(t.key==="closed"?v1:Wl)})).filter(t=>t.tasks.length||t.key==="blocked"||t.key==="ready"||t.key==="progress")}function ST(s,t){return t.filter(i=>i.type==="epic"||i.progress).sort(Wl).map(i=>{const a=s.filter(d=>d.parent===i.id).sort(Wl),l=i.progress?.done??a.filter(d=>d.status==="closed").length,u=i.progress?.total??a.length;return{epic:i,children:a,done:l,total:u,percent:u?Math.round(l/u*100):0}})}function k1(s,t=Date.now()){const i=s?Date.parse(s):NaN;if(Number.isNaN(i))return"";const a=Math.max(0,Math.floor((t-i)/6e4));return a<60?`${a}m`:a<1440?`${Math.floor(a/60)}h`:a<1440*14?`${Math.floor(a/1440)}d`:`${Math.floor(a/10080)}w`}const oo="main",j1=5,Gr=.1,zl=.15,By=.4,NT=16,TT=1030,$y=()=>({root:{kind:"pane",id:oo},focused:oo,assign:{},actives:{}});function Vt(s){return s.kind==="pane"?[s.id]:s.children.flatMap(Vt)}function S1(s){return s.kind==="pane"?1:1+Math.max(...s.children.map(S1))}const N1=s=>s.kind==="pane"?[s.id]:[s.id,...s.children.flatMap(N1)];function Uy(s,t){const i=new Set(N1(s));let a=1;for(;i.has(`${t}-${a}`);)a+=1;return`${t}-${a}`}function Ti(s,t){const i=Vt(s.root),a=s.assign[t];return a&&i.includes(a)?a:i.includes(s.focused)?s.focused:i[0]}function AT(s,t,i){const a=Object.fromEntries(Vt(s.root).map(l=>[l,[]]));for(const l of t)a[Ti(s,i(l))].push(l);return a}function bc(s,t){if(s.kind==="pane")return s.id===t?[]:null;for(let i=0;i<s.children.length;i+=1){const a=bc(s.children[i],t);if(a)return[i,...a]}return null}const wh=(s,t)=>t.reduce((i,a)=>i.children[a],s);function Zl(s,t,i){if(!t.length)return i(s);const a=s,[l,...u]=t;return{...a,children:a.children.map((d,h)=>h===l?Zl(d,u,i):d)}}function Rf(s,{target:t,position:i,key:a}){const l=bc(s.root,t);if(!l)return null;const u=i==="left"||i==="right"?"horizontal":"vertical",d=i==="right"||i==="bottom",h=Uy(s.root,"pane"),m={kind:"pane",id:h},p=l.slice(0,-1),x=l.length?wh(s.root,p):null,y=l[l.length-1]??0;let w;if(x&&x.direction===u){const k=x.sizes[y]??0,j=d?y+1:y,S=x.sizes.slice();S.splice(j,0,k/2),S[y+(d?0:1)]=k/2;const A=x.children.slice();A.splice(j,0,m),w=Zl(s.root,p,()=>({...x,children:A,sizes:S}))}else{const k=Uy(s.root,"group");w=Zl(s.root,l,j=>({kind:"group",id:k,direction:u,children:d?[j,m]:[m,j],sizes:[.5,.5]}))}return S1(w)>j1?null:{...s,root:w,focused:h,assign:a?{...s.assign,[a]:h}:s.assign}}function T1(s,t){const i=bc(s,t);if(!i||!i.length)return null;for(let a=i.length-1;a>=0;a-=1){const l=wh(s,i.slice(0,a)),u=i[a];for(let d=u-1;d>=0;d-=1){const h=Vt(l.children[d]);if(h.length)return h[h.length-1]}for(let d=u+1;d<l.children.length;d+=1){const h=Vt(l.children[d]);if(h.length)return h[0]}}return null}function Hy(s,t){const i=bc(s.root,t);if(!i||!i.length)return null;const a=T1(s.root,t),l=i.slice(0,-1),u=wh(s.root,l),d=i[i.length-1],h=u.children.filter((j,S)=>S!==d),m=u.sizes.filter((j,S)=>S!==d),p=m.reduce((j,S)=>j+S,0)||1,x=Zl(s.root,l,()=>h.length===1?h[0]:{...u,children:h,sizes:m.map(j=>j/p)}),y=Object.fromEntries(Object.entries(s.assign).filter(([,j])=>j!==t)),w=Object.fromEntries(Object.entries(s.actives).filter(([j])=>j!==t)),k=s.focused===t?a??Vt(x)[0]:s.focused;return{root:x,focused:k,assign:y,actives:w}}function CT(s,t,i){return Vt(s.root).includes(i)?{...s,focused:i,assign:{...s.assign,[t]:i},actives:{...s.actives,[i]:t}}:s}function A1(s){const t=s.length;if(!t)return[];if(t===1)return[1];if(t*Gr>1)return s.map(()=>1/t);const i=s.map(m=>Number.isFinite(m)&&m>0?m:0),a=i.reduce((m,p)=>m+p,0),l=a>0?i.map(m=>m/a):i.map(()=>1/t),u=l.map(()=>0),d=new Set(l.map((m,p)=>p));let h=1;for(;d.size;){let m=0;for(const x of d)m+=l[x];if(m<=0){for(const x of d)u[x]=h/d.size;break}const p=[...d].filter(x=>l[x]/m*h<Gr);if(!p.length){for(const x of d)u[x]=l[x]/m*h;break}for(const x of p)u[x]=Gr,d.delete(x),h-=Gr}return u}function ET(s,t,i){const a=l=>l.kind==="pane"?l:l.id===t&&i.length===l.children.length?{...l,sizes:A1(i)}:{...l,children:l.children.map(a)};return{...s,root:a(s.root)}}function _f(s,t={left:0,top:0,right:1,bottom:1}){if(s.kind==="pane")return[{id:s.id,...t}];const i=[];let a=0;for(let l=0;l<s.children.length;l+=1){const u=s.sizes[l]??0;if(s.direction==="horizontal"){const d=t.right-t.left;i.push(..._f(s.children[l],{...t,left:t.left+d*a,right:t.left+d*(a+u)}))}else{const d=t.bottom-t.top;i.push(..._f(s.children[l],{...t,top:t.top+d*a,bottom:t.top+d*(a+u)}))}a+=u}return i}function Iy(s,t,i){const a=_f(s),l=a.find(p=>p.id===t);if(!l)return null;const u=i==="left"||i==="right",d=(p,x,y,w)=>x<y?y-x:w<p?p-w:0,h=(p,x,y,w)=>Math.max(0,Math.min(x,w)-Math.max(p,y)),m=a.filter(p=>p.id!==t).map(p=>{const x=i==="left"?l.left-p.right:i==="right"?p.left-l.right:i==="up"?l.top-p.bottom:p.top-l.bottom;if(x<-1e-6)return null;const[y,w,k,j]=u?[p.top,p.bottom,l.top,l.bottom]:[p.left,p.right,l.left,l.right],S=Math.abs(u?(p.top+p.bottom)/2-(l.top+l.bottom)/2:(p.left+p.right)/2-(l.left+l.right)/2);return{id:p.id,primary:x,secondary:d(y,w,k,j),overlap:h(y,w,k,j),center:S}}).filter(p=>!!p);return m.sort((p,x)=>p.primary-x.primary||p.secondary-x.secondary||x.overlap-p.overlap||p.center-x.center||String(p?.id).localeCompare(String(x?.id))),m[0]?.id??null}function MT({width:s,height:t,x:i,y:a}){const l=s*((1-By)/2),u=t*((1-By)/2);if(i>=l&&i<=s-l&&a>=u&&a<=t-u)return"center";if(i<=s*zl)return"left";if(i>=s-s*zl)return"right";if(a<=t*zl)return"top";if(a>=t-t*zl)return"bottom";const d=[["left",i],["right",s-i],["top",a],["bottom",t-a]];return d.sort((h,m)=>h[1]-m[1]),d[0][0]}const Lf=s=>!!s&&typeof s=="object"&&!Array.isArray(s),Bl=s=>typeof s=="string"&&!!s.trim()&&s.length<=TT;function C1(s,t,i){if(!Lf(s)||i>j1)return null;const a=s;if(!Bl(a.id)||t.has(a.id))return null;if(t.add(a.id),a.kind==="pane")return{kind:"pane",id:a.id};if(a.kind!=="group"||a.direction!=="horizontal"&&a.direction!=="vertical"||!Array.isArray(a.children)||!Array.isArray(a.sizes)||a.children.length!==a.sizes.length||a.children.length<2)return null;const l=[];for(const d of a.children){const h=C1(d,t,i+1);if(!h)return null;l.push(h)}const u=a.sizes.map(d=>typeof d=="number"&&Number.isFinite(d)&&d>0?d:0);return{kind:"group",id:a.id,direction:a.direction,children:l,sizes:A1(u)}}function zT(s){if(!Lf(s))return;const t=s,i=C1(t.root,new Set,1);if(!i||i.kind==="pane")return;const a=Vt(i);if(a.length>NT)return;const l=(m,p)=>{const x={};if(!Lf(m))return x;for(const[y,w]of Object.entries(m).slice(0,100))Bl(y)&&Bl(w)&&p(y,w)&&(x[y]=w);return x},u=l(t.assign,(m,p)=>a.includes(p)),d=l(t.actives,m=>a.includes(m)),h=Bl(t.focused)&&a.includes(t.focused)?t.focused:a[0];return{root:i,focused:h,assign:u,actives:d}}const E1="alp-web:layout",Of=1,RT=["changes","terminal","diff","files","agents","tasks"],M1=Object.freeze({initial:320,min:200,max:600}),z1=Object.freeze({initial:320,min:240,max:720}),_T=20,LT=50,R1=300,_1=1024,OT=_1+5,Df=s=>!!s&&typeof s=="object"&&!Array.isArray(s),L1=s=>typeof s=="string"&&s.trim()&&s.length<=R1?s:void 0,DT=s=>typeof s=="string"&&s.trim()&&s.length<=_1?s:void 0,Gy=s=>typeof s=="string"&&s.trim()&&s.length<=OT?s:void 0,Hr=(s,t=()=>!0,i=L1)=>Array.isArray(s)?[...new Set(s.map(i).filter(a=>!!a&&t(a)))].slice(0,LT):[];function Jl(s,t){if(!(typeof s!="number"||!Number.isFinite(s)))return Math.round(Math.min(t.max,Math.max(t.min,s)))}const qT=(s,t)=>`${s}
30
30
  ${t}`;function BT(s){if(!Df(s))return;const t=s,i=L1(t.session),a=Gy(t.active),l=zT(t.panes),u=Hr(t.files,d=>Js(d)===d&&!$i(d),DT);return{...i?{session:i}:{},agents:i?Hr(t.agents,d=>d!==i):[],tasks:Hr(t.tasks),panels:Hr(t.panels,d=>RT.includes(d)),order:Hr(t.order,void 0,Gy),...u.length?{files:u}:{},...a?{active:a}:{},...l?{panes:l}:{},at:typeof t.at=="number"&&Number.isFinite(t.at)?t.at:0}}function O1(s){const t={workspaces:{}};if(typeof s!="string"||!s)return t;let i;try{i=JSON.parse(s)}catch{return t}if(!Df(i)||i.v!==Of)return t;const a={};if(Df(i.workspaces)){const d=Object.entries(i.workspaces).map(([h,m])=>[h,BT(m)]).filter(([h,m])=>h.length<=2*R1&&m).sort((h,m)=>(m[1]?.at??0)-(h[1]?.at??0)).slice(0,_T);for(const[h,m]of d)m&&(a[h]=m)}const l=Jl(i.sidebarWidth,M1),u=Jl(i.dockWidth,z1);return{...l?{sidebarWidth:l}:{},...u?{dockWidth:u}:{},workspaces:a}}function $T(s){const t=O1(JSON.stringify({...s,v:Of}));return JSON.stringify({v:Of,...t})}function kh(s){if(!s)return{workspaces:{}};try{return O1(s.getItem(E1))}catch{return{workspaces:{}}}}function D1(s,t){if(!s)return!1;try{return s.setItem(E1,$T(t(kh(s)))),!0}catch{return!1}}const UT=(s,t)=>s.workspaces[t];function q1(s,t,i){const a=new Map(i.map((l,u)=>[l,u]));return s.map((l,u)=>({tab:l,index:u,rank:a.get(t(l))??i.length+u})).sort((l,u)=>l.rank-u.rank).map(l=>l.tab)}function qf(s,t,i){if(s.indexOf(t)<0)return s;const l=s.filter(d=>d!==t),u=Math.max(0,Math.min(l.length,i));return[...l.slice(0,u),t,...l.slice(u)]}function ec(){try{return window.localStorage}catch{return}}const vn=s=>`${s.kind}:${s.id}`;function jh(s,t,i,a){const l=s.findIndex(d=>vn(d)===vn(t));if(l<0)return[];let u=i==="left"?s.slice(0,l):i==="right"?s.slice(l+1):s.filter((d,h)=>h!==l);return t.kind==="agent"&&t.id!==a&&(u=u.filter(d=>!(d.kind==="agent"&&d.id===a))),u}function Yy({tabs:s,active:t,selected:i,closing:a,keep:l}){const u=new Set(a.map(vn)),d=a.some(x=>x.kind==="agent"&&x.id===i),h=new Set(s.filter(x=>!u.has(vn(x))&&!(d&&x.kind==="agent")).map(vn)),m=!!t&&u.has(vn(t));let p=t&&!m?t:null;if(t&&m)if(l&&h.has(vn(l)))p=l;else{const x=s.findIndex(y=>vn(y)===vn(t));p=s.slice(x+1).find(y=>h.has(vn(y)))??s.slice(0,x).reverse().find(y=>h.has(vn(y)))??null}else p&&!h.has(vn(p))&&(p=s.find(x=>h.has(vn(x)))??null);return{closingRoot:d,next:p}}const tf=s=>s.kind==="draft"||s.kind==="launcher",nf={kind:"draft",id:"new"},qe=s=>`${s.kind}:${s.id}`,B1=b.createContext(null);function kt(){const s=b.useContext(B1);if(!s)throw new Error("useTabs outside TabsProvider");return s}const sf=s=>{if(!s)return null;const t=s.indexOf(":"),i=s.slice(0,t),a=s.slice(t+1);return a?i==="agent"||i==="task"?{kind:i,id:a}:i==="file"?Js(a)===a&&!$i(a)?{kind:i,id:a}:null:i==="panel"?{kind:i,id:a}:null:null};function HT({children:s}){const t=Oe(),{selected:i,focus:a,workspace:l,connection:u,sessions:d,tree:h}=Ee(),[m,p]=b.useState([]),[x,y]=b.useState([]),[w,k]=b.useState([]),[j,S]=b.useState({}),[A,R]=b.useState([]),[q,O]=b.useState(!1),[L,B]=b.useState([]),[_,Q]=b.useState(null),[C,Y]=b.useState([]),[H,fe]=b.useState($y),[ee,xe]=b.useState(null),re=l?qT(u.gateway,l):null,[de,U]=b.useState(null),Z=b.useRef(null),[oe,ge]=b.useState(!1),T=b.useCallback(()=>{Z.current=null,ge(!1)},[]),z=()=>{const E=Z.current;return new Set(E?[E.session,...E.agents].map(V=>`agent:${V}`):[])},F=b.useRef(null),J=b.useCallback(E=>{const V=t.getState().focus;t.focusSession(E);const ue=t.getState().focus;ue!==V&&(F.current=ue)},[t]);b.useEffect(()=>{const E=Z.current;E&&(i?E.session!==i:E.attempted)&&T(),p(i?[i]:[]),Q(V=>{if(V?.kind==="draft"&&t.getState().busy.create)return V;if(i&&E?.session===i&&E.active){const ue=sf(E.active);if(ue&&ue.kind!=="agent")return ue}return i&&E?.session===i&&!E.active&&V?.kind==="launcher"?V:i?{kind:"agent",id:i}:V&&V.kind!=="agent"?V:null})},[i,t,T]),b.useEffect(()=>{const E=re?UT(kh(ec()),re):void 0;y(E?.tasks??[]),k(E?.files??[]),S({}),R(E?.panels??[]),Y(E?.order??[]);const V=E?.panes??$y(),ue=new Set(Object.values(V.assign)),he=Vt(V.root).length>1?Vt(V.root).filter(We=>!ue.has(We)).map((We,ft)=>({pane:We,id:`n${ft+1}`})):[];fe(he.length?{...V,assign:{...V.assign,...Object.fromEntries(he.map(We=>[`launcher:${We.id}`,We.pane]))}}:V),xe(null),O(!1),B(he.map(We=>We.id));const pe=sf(E?.active);Z.current=E?.session?{session:E.session,agents:E.agents,active:E.active}:null,ge(!!E?.session);const $e=he.find(We=>We.pane===V.focused);Q(We=>pe&&pe.kind!=="agent"&&(pe.kind==="task"?E?.tasks.includes(pe.id):pe.kind==="file"?E?.files?.includes(pe.id):E?.panels.includes(pe.id))?pe:(We&&We.kind!=="agent"?null:We)??($e?{kind:"launcher",id:$e.id}:null)),U(re)},[re]),b.useEffect(()=>{const E=Z.current;!E||E.attempted||i||d.status!=="ready"||(_?.kind!=="draft"&&d.list.some(V=>V.id===E.session)?(E.attempted=!0,t.selectSession(E.session)):T())},[d,i,_,t,T]),b.useEffect(()=>{const E=Z.current;if(!E||!h||h.rootId!==i||E.session!==i)return;if(h.status==="gone"||h.status==="error"){T();return}if(h.status!=="attached")return;T();const V=E.agents.filter(he=>h.projection.sessions[he]);if(!V.length)return;p(he=>[...he,...V.filter(pe=>!he.includes(pe))]);const ue=sf(E.active);ue?.kind==="agent"&&V.includes(ue.id)&&(t.focusSession(ue.id),Q(ue))},[h,i,t,T]),b.useEffect(()=>{if(!(!a||!i)){if(p(E=>E.includes(a)?E:[...E,a]),F.current===a){F.current=null;return}Q(E=>E?.kind==="draft"&&t.getState().busy.create||E&&Z.current?.session===i&&a===i&&E.kind!=="agent"?E:{kind:"agent",id:a})}},[a,i,t]);const le=b.useMemo(()=>q1([...m.map(E=>({kind:"agent",id:E})),...x.map(E=>({kind:"task",id:E})),...w.map(E=>({kind:"file",id:E})),...A.map(E=>({kind:"panel",id:E})),...q?[nf]:[],...L.map(E=>({kind:"launcher",id:E}))],qe,C),[m,x,w,A,q,L,C]),ne=b.useMemo(()=>Vt(H.root),[H.root]),ce=b.useMemo(()=>AT(H,le,qe),[H,le]),ve=_?Ti(H,qe(_)):ne.includes(H.focused)?H.focused:ne[0],Re=ce[ve]??[],Me=b.useCallback(E=>{if(E===ve)return _;const V=ce[E]??[],ue=H.actives[E];return V.find(he=>qe(he)===ue)??V[0]??null},[ve,_,ce,H.actives]);b.useEffect(()=>{de===re&&fe(E=>{const V=new Set(le.map(qe)),ue=z(),he=Vt(E.root);let pe=!1;const $e={};for(const[W,me]of Object.entries(E.assign))(V.has(W)||ue.has(W))&&he.includes(me)?$e[W]=me:pe=!0;for(const W of V)$e[W]||($e[W]=ve,pe=!0);let We=E.actives;const ft=_?qe(_):null;return ft&&V.has(ft)&&We[ve]!==ft&&(We={...We,[ve]:ft},pe=!0),E.focused!==ve&&(pe=!0),pe?{...E,focused:ve,assign:$e,actives:We}:E})},[de,re,le,_,ve]),b.useEffect(()=>{if(de!==re||oe||ne.length<2)return;const E=ne.filter(V=>!(ce[V]??[]).length);E.length&&fe(V=>{let ue=V;for(const he of E)ue=Hy(ue,he)??ue;return ue})},[de,re,oe,ne,ce]),b.useEffect(()=>{ee&&(!ne.includes(ee)||ne.length<2)&&xe(null)},[ee,ne]),b.useEffect(()=>{if(!re||de!==re)return;const E=i??Z.current?.session,V=le.filter(pe=>!tf(pe)).map(qe),ue=new Set([...V,...z()]),he=ne.length>1?{root:H.root,focused:ve,assign:Object.fromEntries(Object.entries(H.assign).filter(([pe])=>ue.has(pe))),actives:Object.fromEntries(Object.entries(H.actives).filter(([,pe])=>ue.has(pe)))}:void 0;D1(ec(),pe=>({...pe,workspaces:{...pe.workspaces,[re]:{...E?{session:E}:{},agents:E?[...m.filter($e=>$e!==E),...Z.current?.agents??[]]:[],tasks:x,files:w,panels:A,order:V,..._&&!tf(_)?{active:qe(_)}:Z.current?.active?{active:Z.current.active}:{},...he?{panes:he}:{},at:Date.now()}}}))},[re,de,i,m,x,w,A,le,_,ne,H,ve]);const Qe=E=>{const V=Z.current;V&&!tf(E)&&(V.active=qe(E))},Ue=b.useCallback(E=>{E.kind==="agent"&&t.focusSession(E.id),Qe(E),Q(E)},[t]),et=b.useCallback((E,V)=>{const ue=!!t.getState().busy.create;let he=E;if(ue&&he.some(W=>W.kind==="draft")&&(t.notify("info","The new session is still starting. Its tab opens once it is ready."),he=he.filter(W=>W.kind!=="draft")),!he.length)return;const pe=new Set(he.map(qe));let $e=!1;const We={};for(const W of ne){const me=ce[W]??[],ht=W===ve?_:Me(W),Wt=Yy({tabs:me,active:ht,selected:i,closing:he,keep:V&&me.some(mt=>qe(mt)===qe(V))?V:void 0});$e||=Wt.closingRoot,We[W]=Wt.next}let ft=We[ve]??null;if(!ft&&ne.length>1){const W=T1(H.root,ve);ft=(W?We[W]:null)??ne.map(me=>We[me]).find(Boolean)??null}T(),p(W=>$e?[]:W.filter(me=>!pe.has(`agent:${me}`))),y(W=>W.filter(me=>!pe.has(`task:${me}`))),k(W=>W.filter(me=>!pe.has(`file:${me}`))),R(W=>W.filter(me=>!pe.has(`panel:${me}`))),pe.has("panel:terminal")&&t.closeTerminal(),pe.has(qe(nf))&&O(!1),B(W=>W.filter(me=>!pe.has(`launcher:${me}`))),fe(W=>({...W,actives:Object.fromEntries(ne.flatMap(me=>We[me]?[[me,qe(We[me])]]:[]))})),$e?t.selectSession(null):ft?.kind==="agent"?t.focusSession(ft.id):a&&pe.has(`agent:${a}`)&&i&&J(i),Q(ft)},[ne,ce,ve,_,Me,H.root,i,a,t,J,T]),Fe=b.useCallback(E=>et([E]),[et]),be=b.useCallback((E,V,ue)=>{const he=jh(ue??ce[Ti(H,qe(E))]??[],E,V,i);he.length&&et(he,E)},[ce,H,i,et]),ye=b.useCallback((E,V,ue)=>{const he=qe(E),pe=le.map(qe),$e=new Set((ce[V]??[]).map(qe));$e.delete(he);const We=qf([...pe.filter(mt=>$e.has(mt)),he],he,ue),ft=pe.filter(mt=>mt!==he),W=ft.flatMap((mt,bt)=>$e.has(mt)?[bt]:[]),me=W.length?W[W.length-1]+1:ft.length,ht=[...ft.slice(0,me),he,...ft.slice(me)];let Wt=0;return ht.map(mt=>mt===he||$e.has(mt)?We[Wt++]:mt)},[le,ce]),Ae=b.useCallback((E,V,ue)=>{Y(ue?qf(le.map(qe),qe(E),V):ye(E,Ti(H,qe(E)),V))},[le,ye,H]),Ne=b.useCallback(E=>{if(E===ve||!ne.includes(E))return;const V=Me(E);V?Ue(V):(fe(ue=>({...ue,focused:E})),Q(null))},[ve,ne,Me,Ue]),Ht=b.useCallback((E,V)=>{const ue=Ti(E,qe(V)),he=Me(ue);if(!he||qe(he)!==qe(V))return E;const pe=Yy({tabs:ce[ue]??[],active:V,selected:null,closing:[V]}).next,$e={...E.actives};return pe?$e[ue]=qe(pe):delete $e[ue],{...E,actives:$e}},[Me,ce]),cn=b.useCallback((E,V,ue)=>{if(!ne.includes(V))return;const he=(ce[V]??[]).filter(pe=>qe(pe)!==qe(E));Y(ye(E,V,ue??he.length)),fe(pe=>CT(Ht(pe,E),qe(E),V)),Ue(E)},[ne,ce,ye,Ht,Ue]),ze=b.useCallback((E,V,ue)=>{const he=Ti(H,qe(E));if(he===V&&(ce[he]??[]).length<2)return;const pe=Rf(Ht(H,E),{target:V,position:ue,key:qe(E)});pe&&(fe(pe),Ue(E))},[H,ce,Ht,Ue]),ut=!!l,At=b.useCallback((E,V=ve)=>{if(!ut)return;const ue=new Set(L);let he=1;for(;ue.has(`n${he}`);)he+=1;const pe={kind:"launcher",id:`n${he}`},$e=Rf(H,{target:V,position:E,key:qe(pe)});$e&&(fe($e),B(We=>[...We,pe.id]),Q(pe))},[ut,L,H,ve]),Rt=b.useCallback((E,V)=>{const ue=`launcher:${E}`,he=Ti(H,ue);fe(pe=>({...pe,focused:he})),B(pe=>pe.filter($e=>$e!==E)),V()},[H]),In=b.useCallback(E=>{if(ne.length<2||!ne.includes(E))return;const V=ce[E]??[];V.length?et(V):fe(ue=>Hy(ue,E)??ue)},[ne,ce,et]),kn=b.useCallback(E=>{const V=Iy(H.root,ve,E);return V?(Ne(V),!0):!1},[H.root,ve,Ne]),Qt=b.useCallback(E=>{const V=Iy(H.root,ve,E);return!V||!_?!1:(cn(_,V),!0)},[H.root,ve,_,cn]),Je=b.useCallback((E,V)=>fe(ue=>ET(ue,E,V)),[]),jt=b.useCallback(E=>xe(V=>V===E?null:E),[]),St=b.useCallback(E=>{y(V=>V.includes(E)?V:[...V,E]),Qe({kind:"task",id:E}),Q({kind:"task",id:E})},[]),un=b.useCallback((E,V)=>{const ue=Js(E);!ue||$i(ue)||(k(he=>he.includes(ue)?he:[...he,ue]),S(he=>({...he,[ue]:{...V?{line:V}:{},nonce:(he[ue]?.nonce??0)+1}})),Qe({kind:"file",id:ue}),Q({kind:"file",id:ue}))},[]),Gn=b.useCallback(E=>j[E],[j]),js=b.useCallback(E=>{t.focusSession(E),p(V=>V.includes(E)?V:[...V,E]),Qe({kind:"agent",id:E}),Q({kind:"agent",id:E})},[t]),dn=b.useCallback(E=>{R(V=>V.includes(E)?V:[...V,E]),Qe({kind:"panel",id:E}),Q({kind:"panel",id:E})},[]),fn=b.useCallback(()=>{O(!0),Q(nf)},[]),Ct=b.useCallback(E=>{O(!1),Q(V=>V?.kind!=="draft"?V:t.getState().selected===E?{kind:"agent",id:E}:null)},[t]),jn=b.useMemo(()=>({tabs:le,row:Re,active:_,panes:H,byPane:ce,focusedPane:ve,activeOf:Me,focusPane:Ne,splitEmpty:At,canSplitEmpty:ut,launch:Rt,splitWith:ze,moveTabToPane:cn,closePane:In,focusAdjacent:kn,moveTabAdjacent:Qt,resize:Je,maximized:ee,toggleMaximized:jt,activate:Ue,close:Fe,closeOthers:be,move:Ae,openTask:St,openFile:un,fileTarget:Gn,openAgent:js,openPanel:dn,openDraft:fn,finishDraft:Ct}),[le,Re,_,H,ce,ve,Me,Ne,At,ut,Rt,ze,cn,In,kn,Qt,Je,ee,jt,Ue,Fe,be,Ae,St,un,Gn,js,dn,fn,Ct]);return o.jsx(B1.Provider,{value:jn,children:s})}const Ws="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",IT=I("flex w-full min-w-0 items-start gap-2 rounded-lg py-2 pl-2 pr-3 text-left",Ws),GT=[0,1,2,3,4],YT={list:YS,board:zS,epics:uh},VT={approve:l0,review:lo,progress:uc,ready:lc,waiting:s0,epics:uh,closed:t0},KT={approve:"bg-dot-warning",review:"bg-dot-running",progress:"border-2 border-dot-warning",ready:"bg-dot-success",blocked:"bg-dot-danger",closed:"border-2 border-border"},FT={blocked:"border-l-dot-danger",ready:"border-l-dot-success",approve:"border-l-dot-warning"};function Sh({state:s}){return o.jsx("span",{role:"img","aria-label":qy[s],title:qy[s],className:I("inline-block size-[9px] shrink-0 rounded-full",KT[s])})}function $1({value:s}){return o.jsxs("span",{className:I("shrink-0 rounded border px-1 text-[length:calc(10.5px*var(--ui-scale))] font-semibold tabular-nums leading-4",s===0?"border-destructive text-destructive":s===1?"border-warning text-warning":"border-border text-muted-foreground"),children:["P",s]})}function U1({onPicked:s,onOpen:t,current:i}){const a=Oe(),{openTask:l,active:u}=kt(),d=C=>{(t??l)(C),s?.()},{tasks:h,principal:m,workspace:p}=Ee(),[x,y]=b.useState(""),[w,k]=b.useState(2),[j,S]=b.useState({view:"list",filter:"open",query:""}),A=a.tasksBlock(),R=Te(m??void 0,"project.write");b.useEffect(()=>(a.setTasksVisible(!0),()=>a.setTasksVisible(!1)),[a]);const q=h.rows,O=b.useMemo(()=>xT(q),[q]),L=b.useMemo(()=>yT(q,j.filter,j.query),[q,j.filter,j.query]);if(!p)return o.jsx("p",{className:"px-4 py-6 text-sm text-muted-foreground",children:"Choose a workspace to see its tasks."});if(A)return o.jsxs("p",{className:"flex items-start gap-2 px-4 py-6 text-sm text-muted-foreground",children:[o.jsx(qa,{"aria-hidden":!0,className:"mt-0.5 size-4 shrink-0"}),A]});const B=C=>t?i===C:u?.kind==="task"&&u.id===C,_=C=>S(Y=>({...Y,view:C})),Q=h.status==="ready"||q.length>0;return o.jsxs("div",{className:"@container flex min-h-0 flex-col gap-2 p-2","data-testid":"task-board","data-view":j.view,children:[o.jsxs("div",{className:"flex items-center gap-1.5 px-1 pt-1",children:[o.jsx("h2",{className:"text-sm font-semibold",children:"Tasks"}),Q?o.jsxs("span",{className:"text-xs text-muted-foreground","data-testid":"tasks-open-count",children:[O.open," open"]}):null,o.jsx("span",{className:"flex-1"}),o.jsx("div",{role:"group","aria-label":"Task view",className:"flex rounded-lg border border-border bg-card p-0.5",children:pT.map(C=>{const Y=YT[C.key],H=j.view===C.key;return o.jsxs("button",{type:"button","aria-pressed":H,title:C.label,onClick:()=>_(C.key),className:I("flex h-6 items-center gap-1 rounded-md px-1.5 text-xs",H?"bg-secondary font-semibold text-foreground":"text-muted-foreground hover:text-foreground",Ws),children:[o.jsx(Y,{"aria-hidden":!0,className:"size-3.5"}),o.jsx("span",{className:"sr-only @[340px]:not-sr-only",children:C.label})]},C.key)})}),o.jsx("button",{type:"button","aria-label":"Refresh tasks",title:"Refresh tasks",onClick:()=>{a.refreshTasks()},className:I("flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-sidebar-hover hover:text-foreground",Ws),children:o.jsx(co,{"aria-hidden":!0,className:I("size-3.5",h.status==="loading"&&"animate-spin")})})]}),o.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 px-1",children:[o.jsx("div",{role:"group","aria-label":"Task filter",className:"flex flex-wrap gap-1",children:gT.map(C=>{const Y=j.filter===C;return o.jsxs("button",{type:"button","aria-pressed":Y,onClick:()=>S(H=>({...H,filter:C})),"data-testid":`tasks-filter-${C}`,className:I("h-6 rounded-full border px-2.5 text-xs",Y?"border-foreground bg-foreground font-semibold text-background":"border-border text-foreground hover:bg-secondary",Ws),children:[C[0].toUpperCase()+C.slice(1)," ",o.jsx("span",{className:"text-[length:calc(11px*var(--ui-scale))] opacity-60",children:O[C]})]},C)})}),o.jsxs("label",{className:"flex h-7 min-w-[160px] flex-1 items-center gap-1.5 rounded-lg border border-border bg-card px-2 focus-within:border-ring",children:[o.jsx(ti,{"aria-hidden":!0,className:"size-3.5 shrink-0 text-muted-foreground"}),o.jsx("input",{type:"text",role:"searchbox",value:j.query,onChange:C=>S(Y=>({...Y,query:C.target.value})),"aria-label":"Filter tasks",placeholder:"Filter by id, title, label, agent",className:"min-w-0 flex-1 bg-transparent text-xs text-foreground outline-none placeholder:text-muted-foreground"})]})]}),R?o.jsxs("form",{className:"flex gap-1.5 px-1",onSubmit:C=>{C.preventDefault(),x.trim()&&(a.createTask({title:x,priority:w}),y(""))},children:[o.jsx(ro,{htmlFor:"task-title",className:"sr-only",children:"New task"}),o.jsx(Zn,{id:"task-title",value:x,onChange:C=>y(C.target.value),placeholder:"New task…",maxLength:200,className:"h-8 min-w-0 flex-1"}),o.jsx(ro,{htmlFor:"task-priority",className:"sr-only",children:"Priority"}),o.jsx(ph,{id:"task-priority",value:w,onChange:C=>k(Number(C.target.value)),className:"h-8 w-16 text-xs",children:GT.map(C=>o.jsxs("option",{value:C,children:["P",C]},C))}),o.jsx(we,{type:"submit",size:"icon-sm",className:"size-8","aria-label":"Add task",title:"Add task",disabled:!x.trim(),children:o.jsx(ks,{"aria-hidden":!0})})]}):o.jsx("p",{className:"px-2 text-xs text-muted-foreground",children:"Your access token can read tasks but not change them."}),h.creates.map(C=>o.jsx("div",{role:C.status==="creating"?"status":"alert",className:I("mx-1 rounded-lg border px-3 py-2 text-xs",C.status==="creating"?"border-border text-muted-foreground":C.status==="unknown"?"border-warning/40 bg-warning/5 text-warning":"border-destructive/40 bg-destructive/5 text-destructive"),children:C.status==="creating"?o.jsx(Ft,{label:`Creating “${C.title}”…`}):o.jsxs(o.Fragment,{children:[o.jsxs("p",{className:"mb-1.5 font-medium text-foreground",children:["“",C.title,"”"]}),o.jsx("p",{children:C.error}),C.match?o.jsxs("p",{className:"mt-1 text-foreground/90",children:["A task with this title is in the list (",C.match,"); it was probably created."]}):null,o.jsxs("div",{className:"mt-2 flex gap-2",children:[o.jsxs(we,{size:"sm",variant:"secondary",onClick:()=>{a.retryTaskCreate(C.requestId)},children:[o.jsx(uo,{"aria-hidden":!0})," Create again"]}),o.jsx(we,{size:"sm",variant:"ghost",onClick:()=>a.dismissTaskCreate(C.requestId),children:"Dismiss"})]})]})},C.requestId)),h.message?o.jsx("p",{role:h.message.level==="error"?"alert":"status",className:I("mx-1 rounded-md px-3 py-1.5 text-xs",h.message.level==="error"?"bg-destructive/10 text-destructive":"bg-primary/10 text-highlight"),children:h.message.text}):null,h.status==="loading"&&!q.length?o.jsx(Ft,{label:"Loading tasks…",className:"px-2 text-xs"}):null,h.status==="error"?o.jsx("p",{role:"alert",className:"mx-1 rounded-md bg-destructive/10 px-3 py-2 text-xs text-destructive",children:h.error?.message}):null,h.unreadable?o.jsxs("p",{className:"px-2 text-xs text-warning",children:[h.unreadable," task file(s) on the host could not be read."]}):null,h.status==="ready"&&!q.length?o.jsx(Bf,{text:"No tasks yet. Add one here, with alp task add, or ask main to plan the work."}):null,q.length&&!L.length?o.jsx(Bf,{text:j.query.trim()?"No tasks match.":j.filter==="open"?"All tasks are closed.":j.filter==="ready"?"No task is ready.":"No closed tasks."}):null,L.length&&j.view==="list"?o.jsx(XT,{tasks:L,isCurrent:B,onOpen:d,canWrite:R}):null,L.length&&j.view==="board"?o.jsx(PT,{tasks:L,isCurrent:B,onOpen:d}):null,L.length&&j.view==="epics"?o.jsx(QT,{all:q,shown:L,isCurrent:B,onOpen:d}):null]})}function Bf({text:s}){return o.jsx("p",{role:"status",className:"mx-1 rounded-lg border border-dashed border-border px-4 py-5 text-center text-xs text-muted-foreground",children:s})}function H1({task:s,isCurrent:t,onOpen:i,testId:a="task-row"}){const l=t(s.id),u=vh(s),d=s.blockedBy?.length?`after ${s.blockedBy.join(", ")}`:"",h=s.waits?.length&&!s.approvals?.length?`waits on ${s.waits.join("; ")}`:"";return o.jsx("div",{className:I("rounded-lg",l?"bg-sidebar-selected":"hover:bg-sidebar-hover"),"data-testid":a,children:o.jsxs("button",{type:"button",className:IT,onClick:()=>i(s.id),"aria-current":l?"true":void 0,title:s.title,children:[o.jsx("span",{className:"flex h-5 w-4 shrink-0 items-center justify-center",children:o.jsx(Sh,{state:u})}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:I("line-clamp-2 text-sm leading-5",s.status==="closed"?"text-muted-foreground line-through":"text-foreground/90"),children:s.title}),o.jsxs("span",{className:"mt-0.5 flex flex-wrap items-center gap-x-1.5 text-xs text-muted-foreground",children:[o.jsx("span",{className:"font-mono",children:s.id}),o.jsxs("span",{children:["P",s.priority]}),s.type&&s.type!=="task"?o.jsx("span",{children:s.type}):null,o.jsx("span",{children:String(s.status).replace("_"," ")}),s.assignee?o.jsxs("span",{children:["· @",s.assignee]}):null,s.progress?o.jsxs("span",{children:["· ",s.progress.done,"/",s.progress.total]}):null,s.approvals?.length?o.jsx("span",{className:"text-dot-warning",children:"· needs approval"}):null,d?o.jsxs("span",{className:"text-dot-danger",children:["· ",d]}):null,h?o.jsxs("span",{children:["· ",h]}):null,s.parent?o.jsxs("span",{children:["· in ",s.parent]}):null,(s.labels??[]).map(m=>o.jsxs("span",{className:"text-info",children:["#",m]},m)),o.jsx("span",{className:"ml-auto tabular-nums",children:k1(s.status==="closed"?s.closed?.at:s.updatedAt)})]})]})]})})}function XT({tasks:s,isCurrent:t,onOpen:i,canWrite:a}){const l=Oe(),{tasks:u}=Ee(),d=b.useMemo(()=>wT(s),[s]),[h,m]=b.useState({});return o.jsx("div",{className:"space-y-1","data-testid":"tasks-list-view",children:d.map(p=>{const x=h[p.key]??!1,y=VT[p.key]??CS;return o.jsxs("section",{"aria-label":p.title,"data-testid":`tasks-section-${p.key}`,children:[o.jsxs("button",{type:"button","aria-expanded":!x,onClick:()=>m(w=>({...w,[p.key]:!x})),className:I("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground hover:text-foreground",Ws),children:[x?o.jsx(Jn,{"aria-hidden":!0,className:"size-3.5"}):o.jsx(Qn,{"aria-hidden":!0,className:"size-3.5"}),o.jsx(y,{"aria-hidden":!0,className:"size-3.5"}),o.jsx("span",{className:"font-semibold",children:p.title}),o.jsx("span",{className:"tabular-nums opacity-70",children:p.tasks.length})]}),x?null:o.jsx("ul",{"aria-label":p.title,children:p.tasks.map(w=>o.jsxs("li",{className:"mb-0.5",children:[o.jsx(H1,{task:w,isCurrent:t,onOpen:i}),p.key==="approve"&&a?w.approvals.map(k=>o.jsxs("div",{className:"ml-8 mr-2 mb-1 flex items-center gap-2 rounded-md bg-warning/[0.06] px-2 py-1 text-xs",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",children:k.note||"Waiting for your approval"}),k.options?.length?k.options.map(j=>o.jsx(we,{size:"sm",className:"h-6 px-2 text-xs",disabled:!!u.busy[w.id],"aria-label":`Approve ${w.id}: ${j}`,onClick:()=>{l.changeTask(w,{gate:k.gate,choice:j})},children:j},j)):o.jsx(we,{size:"sm",className:"h-6 px-2 text-xs",disabled:!!u.busy[w.id],"aria-label":`Approve ${w.id}`,onClick:()=>{l.changeTask(w,{gate:k.gate})},children:"Approve"}),k.rejected?null:o.jsx(we,{size:"sm",variant:"secondary",className:"h-6 px-2 text-xs",disabled:!!u.busy[w.id],"aria-label":`Reject ${w.id}`,onClick:()=>{l.changeTask(w,{gate:k.gate,reject:!0})},children:"Reject"})]},k.gate)):null]},w.id))})]},p.key)})})}function PT({tasks:s,isCurrent:t,onOpen:i}){const a=b.useMemo(()=>jT(s),[s]);return o.jsx("div",{className:"flex items-start gap-2.5 overflow-x-auto px-1 pb-2","data-testid":"tasks-board-view",children:a.map(l=>o.jsxs("section",{"aria-label":l.title,"data-testid":`tasks-column-${l.key}`,className:"flex max-h-[640px] w-[248px] shrink-0 flex-col rounded-[10px] border border-border bg-card",children:[o.jsxs("h3",{className:"flex items-center gap-2 border-b border-border px-3 py-2 text-xs font-semibold",children:[o.jsx(Sh,{state:l.key}),o.jsx("span",{className:"flex-1",children:l.title}),o.jsx("span",{className:"font-normal tabular-nums text-muted-foreground",children:l.tasks.length})]}),o.jsxs("ul",{className:"min-h-0 space-y-2 overflow-y-auto p-2",children:[l.tasks.map(u=>{const d=t(u.id);return o.jsx("li",{children:o.jsxs("button",{type:"button",onClick:()=>i(u.id),"aria-current":d?"true":void 0,title:u.title,"data-testid":"task-card",className:I("flex w-full flex-col gap-1 rounded-lg border border-l-[3px] border-border bg-background p-2.5 text-left hover:border-muted-foreground",FT[l.key],d&&"bg-sidebar-selected",Ws),children:[o.jsxs("span",{className:"flex w-full items-center gap-1.5 text-xs text-muted-foreground",children:[o.jsx($1,{value:u.priority}),o.jsx("span",{className:"font-mono",children:u.id}),o.jsx("span",{className:"flex-1"}),o.jsx("span",{className:"tabular-nums",children:k1(l.key==="closed"?u.closed?.at:u.updatedAt)})]}),o.jsx("span",{className:I("line-clamp-3 text-[length:calc(13px*var(--ui-scale))] leading-[18px]",l.key==="closed"&&"text-muted-foreground"),children:u.title}),u.assignee?o.jsxs("span",{className:"truncate text-xs text-muted-foreground",children:["@",u.assignee]}):null,u.blockedBy?.length?o.jsxs("span",{className:"truncate text-xs text-dot-danger",children:["after ",u.blockedBy.join(", ")]}):null,u.labels?.length?o.jsx("span",{className:"flex flex-wrap gap-1.5 text-xs text-info",children:u.labels.map(h=>o.jsxs("span",{children:["#",h]},h))}):null]})},u.id)}),l.tasks.length?null:o.jsx("li",{className:"px-1 py-2 text-xs text-muted-foreground",children:"Nothing here"})]})]},l.key))})}function QT({all:s,shown:t,isCurrent:i,onOpen:a}){const l=b.useMemo(()=>ST(s,t),[s,t]),[u,d]=b.useState({});return l.length?o.jsx("ul",{className:"space-y-2 px-1","data-testid":"tasks-epics-view",children:l.map(({epic:h,children:m,done:p,total:x,percent:y})=>{const w=u[h.id]??h.status!=="closed",k=i(h.id);return o.jsxs("li",{className:"rounded-[10px] border border-border bg-card p-3","data-testid":"epic",children:[o.jsxs("button",{type:"button",onClick:()=>a(h.id),"aria-current":k?"true":void 0,title:h.title,className:I("flex w-full min-w-0 items-center gap-2 rounded-md text-left",k&&"text-highlight",Ws),children:[o.jsx(Sh,{state:vh(h)}),o.jsx(uh,{"aria-hidden":!0,className:"size-3.5 shrink-0 text-muted-foreground"}),o.jsx($1,{value:h.priority}),o.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:h.id}),o.jsx("span",{className:I("min-w-0 flex-1 truncate text-sm",h.status==="closed"&&"text-muted-foreground line-through"),children:h.title}),o.jsxs("span",{className:"shrink-0 font-mono text-xs text-muted-foreground","data-testid":"epic-progress",children:[p,"/",x]})]}),o.jsx("div",{role:"progressbar","aria-label":`${h.id} progress`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":y,className:"mt-2 h-1.5 overflow-hidden rounded-full bg-secondary",children:o.jsx("div",{className:"h-full rounded-full bg-dot-success",style:{width:`${y}%`}})}),m.length?o.jsxs("button",{type:"button","aria-expanded":w,onClick:()=>d(j=>({...j,[h.id]:!w})),className:I("mt-2 flex items-center gap-1 rounded-md text-xs text-muted-foreground hover:text-foreground",Ws),children:[w?o.jsx(Qn,{"aria-hidden":!0,className:"size-3"}):o.jsx(Jn,{"aria-hidden":!0,className:"size-3"}),m.length," ",m.length===1?"task":"tasks"]}):null,w&&m.length?o.jsx("ul",{className:"mt-1 border-l border-border pl-2","aria-label":`Tasks of ${h.id}`,children:m.map(j=>o.jsx("li",{children:o.jsx(H1,{task:j,isCurrent:i,onOpen:a,testId:"epic-task"})},j.id))}):null]},h.id)})}):o.jsx(Bf,{text:"No epics here. An epic is a task other tasks name as their parent."})}const I1="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",af=I("flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-secondary hover:text-foreground [&_svg]:size-4",I1);function rf({testId:s,children:t}){return o.jsxs("div",{className:"flex min-h-full flex-col items-center justify-center gap-2 p-6 text-center",role:"note","data-testid":s,children:[o.jsx(ah,{"aria-hidden":!0,strokeWidth:1.5,className:"size-6 text-extra-muted"}),t]})}function WT({onPicked:s}){const t=Oe(),{workspace:i,connection:a,principal:l}=Ee(),{openFile:u,active:d}=kt(),h=a.capabilities.includes("workspace.files.read"),m=Te(l??void 0,"files.read"),[p,x]=b.useState({}),[y,w]=b.useState([]),[k,j]=b.useState("name"),[S,A]=b.useState(!1),R=b.useRef(0),q=b.useCallback((H,fe)=>{const ee=R.current;x(xe=>({...xe,[H]:xe[H]?.status==="ready"?xe[H]:{status:"loading"}})),t.listWorkspaceFiles({...H?{path:H}:{},includeIgnored:fe}).then(xe=>{R.current===ee&&x(re=>({...re,[H]:{status:"ready",entries:xe.entries,truncated:xe.truncated}}))},xe=>{R.current===ee&&x(re=>({...re,[H]:{status:"error",error:xe instanceof Ei||xe instanceof Error?xe.message:"Could not list this folder."}}))})},[t]),O=`${a.gateway}
31
31
  ${i??""}`,L=b.useRef(O),B=b.useRef(y);if(B.current=y,b.useEffect(()=>{if(!h||!m||!i||a.phase!=="open")return;R.current+=1;const H=L.current===O;if(L.current=O,x({}),H||w([]),q("",S),H)for(const fe of B.current)q(fe,S)},[h,m,i,O,a.phase,S,q]),!h)return o.jsx(rf,{testId:"files-unavailable",children:o.jsx("p",{className:"max-w-[300px] text-sm text-muted-foreground",children:Qb})});if(!m)return o.jsxs(rf,{testId:"files-forbidden",children:[o.jsxs("p",{className:"flex max-w-[300px] items-start gap-2 text-sm text-foreground",children:[o.jsx(qa,{"aria-hidden":!0,className:"mt-0.5 size-4 shrink-0 text-muted-foreground"}),kf]}),o.jsxs("p",{className:"max-w-[300px] text-xs leading-5 text-muted-foreground",children:["File reading is never granted by default. The host owner can create a token that allows it: ",o.jsx("code",{className:"font-mono",children:"alp-gateway credential create --permission files.read"})," (with the other permissions it needs)."]})]});if(!i)return o.jsx(rf,{testId:"files-no-workspace",children:o.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose a workspace to browse its files."})});const _=w2(p,y,{sort:k,showHidden:S}),Q=H=>{const fe=!y.includes(H);w(ee=>v2(ee,H)),fe&&p[H]?.status!=="ready"&&q(H,S)},C=()=>{R.current+=1,x({}),q("",S);for(const H of y)q(H,S)},Y=d?.kind==="file"?d.id:void 0;return o.jsxs("div",{className:"flex min-h-full flex-col","data-testid":"files-panel",children:[o.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border px-2 py-1",children:[o.jsxs("span",{className:"min-w-0 flex-1 truncate px-1 text-xs text-muted-foreground",children:["Sorted by ",Id[k].toLowerCase()]}),o.jsx("button",{type:"button",className:af,onClick:()=>j(Ex),"aria-label":`Sort by ${Id[Ex(k)].toLowerCase()}`,title:`Sort: ${Id[k]}`,"data-testid":"files-sort","data-sort":k,children:o.jsx(bS,{"aria-hidden":!0})}),o.jsx("button",{type:"button",className:af,onClick:()=>A(H=>!H),"aria-pressed":S,"aria-label":"Show hidden files",title:S?"Hide hidden files":"Show hidden files","data-testid":"files-show-hidden",children:S?o.jsx(lo,{"aria-hidden":!0}):o.jsx(LS,{"aria-hidden":!0})}),o.jsx("button",{type:"button",className:af,onClick:C,"aria-label":"Refresh files",title:"Refresh","data-testid":"files-refresh",children:o.jsx(co,{"aria-hidden":!0})})]}),o.jsx("ul",{className:"py-1",role:"tree","aria-label":"Workspace files",children:_.map(H=>{const fe={paddingLeft:8+H.depth*14};if(H.kind==="status"){const U=H.status==="loading"?"Loading…":H.status==="empty"?H.path?"Empty folder":"No files to show":H.status==="truncated"?"Only the first 1000 entries are shown.":H.message??"Could not list this folder.";return o.jsxs("li",{role:"none",style:fe,className:I("py-1 pr-3 text-xs",H.status==="error"?"text-destructive":"text-muted-foreground"),"data-testid":`files-${H.status}`,children:[U,H.status==="error"?o.jsx("button",{type:"button",className:"ml-2 text-highlight hover:underline",onClick:()=>q(H.path,S),children:"Retry"}):null]},`status:${H.path}`)}const{entry:ee}=H,xe=ee.kind==="directory",re=!xe&&Y===ee.path,de=xe?H.open?qS:Da:r0;return o.jsx("li",{role:"treeitem","aria-expanded":xe?H.open:void 0,"aria-selected":re||void 0,children:o.jsxs("button",{type:"button",style:fe,title:ee.path,onClick:()=>{xe?Q(ee.path):(u(ee.path),s?.())},className:I("flex w-full min-w-0 items-center gap-1.5 py-1 pr-3 text-left text-[length:calc(13px*var(--ui-scale))]",re?"bg-sidebar-selected text-foreground":"text-foreground/85 hover:bg-sidebar-hover",I1),"data-testid":"files-entry","data-path":ee.path,"data-kind":ee.kind,children:[o.jsx(Jn,{"aria-hidden":!0,className:I("size-3.5 shrink-0 text-extra-muted transition-transform",!xe&&"invisible",H.open&&"rotate-90")}),o.jsx(de,{"aria-hidden":!0,className:"size-4 shrink-0 text-muted-foreground"}),o.jsx("span",{className:"truncate",children:ee.name})]})},ee.path)})})]})}const ZT=Object.freeze(["shell","read","edit","write","search","fetch","sub_agent","plan","plain_text","unknown"]),Hn=400,JT=1e6,Nh=s=>typeof s=="object"&&s!==null&&!Array.isArray(s),Ln=s=>typeof s=="string"?s:"",za=s=>s.split(`
32
32
  `).find(t=>t.trim())?.trim()??"";function G1(s){const t=Nh(s)?s.type:void 0;return typeof t=="string"&&ZT.includes(t)?t:"unknown"}function $l(s,t=[]){if(!s)return s;const i=s.replace(/\\/g,"/");for(const a of t){if(!a)continue;const l=a.replace(/\\/g,"/").replace(/\/+$/,"");if(l){if(i===l)return".";if(i.startsWith(`${l}/`))return i.slice(l.length+1)}}return s}function Vy(s){const t=String(s??"").trim();return t?/[:./]/.test(t)||t.includes("__")?t:t.replace(/[._-]+/g," ").split(" ").filter(Boolean).join(" ").toLowerCase().replace(/^./,i=>i.toUpperCase()):"Tool"}function e5(s){if(typeof s=="string")return za(s);if(Nh(s)){const t=Object.values(s).find(i=>typeof i=="string"&&i.trim());if(typeof t=="string")return za(t)}return""}const t5={shell:"terminal",read:"eye",edit:"pencil",write:"pencil",search:"search",fetch:"search",sub_agent:"bot",plan:"brain",plain_text:"wrench",unknown:"wrench"};function n5(s,t=[]){const i=typeof s?.name=="string"?s.name:"",a=G1(s?.detail),l=Nh(s?.detail)?s.detail:{},d=i.trim().toLowerCase()==="task"||i==="alp_delegate"?"bot":t5[a];switch(a){case"shell":return{kind:a,label:"Shell",secondary:za(Ln(l.command)),icon:d};case"read":return{kind:a,label:"Read",secondary:$l(Ln(l.filePath),t),icon:d};case"edit":return{kind:a,label:"Edit",secondary:$l(Ln(l.filePath),t),icon:d};case"write":return{kind:a,label:"Write",secondary:$l(Ln(l.filePath),t),icon:d};case"search":return{kind:a,label:"Search",secondary:za(Ln(l.query)),icon:d};case"fetch":return{kind:a,label:"Fetch",secondary:Ln(l.url),icon:d};case"sub_agent":return{kind:a,label:Ln(l.subAgentType).trim()||"Task",secondary:za(Ln(l.description)),icon:d};case"plan":return{kind:a,label:"Plan",secondary:"",icon:d};case"plain_text":return{kind:a,label:Vy(i),secondary:za(Ln(l.label)),icon:d};default:{if(i==="alp_delegate")return{kind:a,label:"Delegate",secondary:`to ${l.input?.agent??"an agent"}`,icon:d};const h=i.startsWith("alp_")?i.replace(/^alp_/,"").replace(/^\w/,m=>m.toUpperCase()):Vy(i);return{kind:a,label:h,secondary:e5(l.input),icon:d}}}}function tc(s){if(!s)return[];const t=s.replace(/\r\n?/g,`
@@ -40,7 +40,7 @@ ${w.ignoreWhitespace}
40
40
  ${m??""}
41
41
  ${p.at}`,j=u5(d&&!!y&&x,k,w),[S,A]=b.useState([]);b.useEffect(()=>A([]),[h,u.mode]);const R=b.useCallback(()=>{p.load()},[p.load]);d5(R,p.at,d&&l.status);const q=`${s}-panel`;if(!l.status)return o.jsx(Fy,{testId:`panel-unavailable-${s}`,reason:l.reason,children:l.reason==="projectRead"?o.jsxs("p",{className:"flex max-w-[300px] items-start gap-2 text-sm text-foreground",children:[o.jsx(qa,{"aria-hidden":!0,className:"mt-0.5 size-4 shrink-0 text-muted-foreground"}),l.message]}):o.jsx("p",{className:"max-w-[300px] text-sm text-muted-foreground",children:l.message})});const O=C=>o.jsx(g5,{mode:u.mode,setMode:Y=>Di.set({mode:Y}),content:!!y,ignoreWhitespace:u.ignoreWhitespace,totals:C,refreshing:p.loading||j.loading,onRefresh:R,testId:`${s}-toolbar`});if(!p.status)return o.jsxs("div",{className:"flex min-h-full flex-col","data-testid":q,children:[O(),p.error?o.jsxs("p",{className:"px-3 py-4 text-sm text-destructive",role:"alert","data-testid":"git-error",children:[p.error," ",o.jsx("button",{type:"button",className:"ml-1 text-highlight hover:underline",onClick:R,children:"Retry"})]}):o.jsx("p",{className:"px-3 py-4 text-sm text-muted-foreground","data-testid":"git-loading",children:"Checking repository..."})]});if(p.status.state!=="repository")return o.jsxs(Fy,{testId:"changes-not-git",reason:p.status.state,children:[o.jsx("p",{className:"max-w-[300px] text-sm text-muted-foreground",children:p.status.state==="unsupported"?"This workspace is inside a Git repository but is not its top level, so its changes are not shown.":"Not a git repository"}),o.jsx("button",{type:"button",className:"text-xs text-highlight hover:underline",onClick:R,children:"Refresh"})]});if(!y){const C=p.status.files;return o.jsxs("div",{className:"flex min-h-full flex-col","data-testid":q,"data-content":"none",children:[O(),o.jsx(Qy,{status:p.status,mode:"uncommitted"}),o.jsxs("p",{className:"flex items-start gap-1.5 px-3 py-2 text-xs text-muted-foreground","data-testid":"git-content-forbidden",children:[o.jsx(qa,{"aria-hidden":!0,className:"mt-0.5 size-3.5 shrink-0"}),l.contentMessage]}),C.length?o.jsx("ul",{"aria-label":"Changed files",children:C.map(Y=>o.jsx(p5,{file:Y},`${Y.oldPath??""}
42
42
  ${Y.path}`))}):o.jsx("p",{className:"px-3 py-4 text-sm text-muted-foreground","data-testid":"git-empty",children:"No changes to display"}),o.jsx(Py,{count:p.status.hiddenCount}),p.status.truncated?o.jsxs("p",{className:"px-3 py-2 text-xs text-muted-foreground","data-testid":"git-truncated",children:["Only the first ",C.length," changed files are shown."]}):null]})}const L=j.diff?.files??[],B=C=>s==="diff"||S.includes(C),_=C=>A(Y=>Y.includes(C)?Y.filter(H=>H!==C):[...Y,C]),Q=u.mode==="uncommitted"?"base":"uncommitted";return o.jsxs("div",{className:"flex min-h-full flex-col","data-testid":q,"data-content":"diff",children:[O(j.diff?fj(L):void 0),o.jsx(Qy,{status:p.status,mode:u.mode}),m?o.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-1 text-xs text-muted-foreground","data-testid":"git-focus",children:[o.jsx("span",{className:"min-w-0 flex-1 truncate",children:m}),o.jsx("button",{type:"button",className:"text-highlight hover:underline",onClick:()=>Ky(null),"data-testid":"git-focus-clear",children:"All files"})]}):null,j.notice?o.jsx("p",{className:"px-3 py-2 text-xs text-muted-foreground",role:"status","data-testid":"git-notice",children:j.notice}):null,j.error?o.jsxs("p",{className:"px-3 py-2 text-sm text-destructive",role:"alert","data-testid":"git-error",children:[j.error," ",o.jsx("button",{type:"button",className:"ml-1 text-highlight hover:underline",onClick:()=>j.load(),children:"Retry"})]}):null,j.loading&&!j.diff?o.jsx("p",{className:"px-3 py-4 text-sm text-muted-foreground","data-testid":"git-loading",children:"Loading changes…"}):null,j.diff&&!L.length&&!j.error?o.jsxs("div",{className:"flex flex-col items-center gap-2 px-3 py-6 text-center","data-testid":"git-empty",children:[o.jsx("p",{className:"text-sm text-muted-foreground",children:"No changes to display"}),!m&&!u.ignoreWhitespace?o.jsx("button",{type:"button",className:"text-xs text-highlight hover:underline",onClick:()=>Di.set({mode:Q}),"data-testid":"changes-empty-switch-mode",children:Q==="base"?"See committed changes":"See uncommitted changes"}):null]}):null,L.length?o.jsx("ul",{"aria-label":s==="diff"?"Diff":"Changed files",children:L.map(C=>o.jsx(m5,{file:C,open:B(C.path),onToggle:()=>_(C.path),onOpenDiff:s==="changes"&&t?()=>{Ky(C.path,h),t()}:void 0},`${C.oldPath??""}
43
- ${C.path}`))}):null,o.jsx(Py,{count:j.diff?.hiddenCount??0}),j.diff?.nextCursor?o.jsx("button",{type:"button",onClick:j.loadMore,disabled:j.more,className:I("mx-3 my-2 self-start rounded-md px-2 py-1 text-xs text-highlight hover:bg-secondary disabled:opacity-60",vc),"data-testid":"git-load-more",children:j.more?"Loading…":"Load more"}):j.diff?.truncated?o.jsx("p",{className:"px-3 py-2 text-xs text-muted-foreground","data-testid":"git-truncated",children:"Only some untracked files are shown: the host limits how many it reads."}):null]})}function x5({onOpenDiff:s}){return o.jsx(P1,{variant:"changes",onOpenDiff:s})}function y5(){return o.jsx(P1,{variant:"diff"})}const b5=b.lazy(()=>W0(()=>import("./TerminalPanel-BbYa_Xkd.js"),__vite__mapDeps([0,1])).then(s=>({default:s.TerminalPanel}))),ni={changes:{label:"Changes",icon:Sf},terminal:{label:"Terminal",icon:hc},diff:{label:"Diff",icon:Sf},files:{label:"Files",icon:ah},agents:{label:"Agents",icon:Oa},tasks:{label:"Tasks",icon:Bi}},v5="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",w5=I("flex w-full min-w-0 items-start gap-2 rounded-lg py-2 pl-2 pr-3 text-left",v5);function k5({onPicked:s}){const{openAgent:t,active:i}=kt(),{tree:a}=Ee();if(!a)return o.jsx("p",{className:"px-4 py-6 text-sm text-muted-foreground",children:"Open a session to see its agents."});const l=Bb(a.projection),u=new Set(Object.values(a.projection.questions).map(d=>d.sessionId));return o.jsx("ul",{className:"p-2","aria-label":"Agents in this session",children:l.map(d=>{const h=d.session,m=d.id===a.rootId,p=i?.kind==="agent"&&i.id===d.id,x=u.has(d.id)?"needs_input":d.running?"running":"done";return o.jsx("li",{className:I("mb-0.5 rounded-lg",p?"bg-sidebar-selected":"hover:bg-sidebar-hover",!m&&"ml-4"),children:o.jsxs("button",{type:"button",onClick:()=>{t(d.id),s?.()},"aria-current":p?"true":void 0,className:w5,"data-testid":"agent-row",children:[o.jsx(yh,{bucket:x}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx("span",{className:I("truncate text-sm leading-5",p?"text-foreground":"text-foreground/80"),children:h?.agent??(m?"main":"agent")}),o.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:d.closed?"closed":d.running?"working":"idle"})]}),o.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:[m?"main conversation":"assignment",Fl(h?.mode),h?.model].filter(Boolean).join(" · ")})]})]})},d.id)})})}function j5({kind:s}){const t=ni[s];return o.jsxs("div",{className:"flex min-h-full flex-col items-center justify-center gap-2 p-6 text-center",role:"note","data-testid":`panel-unavailable-${s}`,children:[o.jsx(t.icon,{"aria-hidden":!0,strokeWidth:1.5,className:"size-6 text-extra-muted"}),o.jsxs("p",{className:"text-sm text-foreground",children:[t.label," is not available in this beta"]}),o.jsx("p",{className:"max-w-[300px] text-xs leading-5 text-muted-foreground",children:t.unavailable})]})}function Q1({kind:s,onPicked:t}){const{openPanel:i}=kt();return s==="agents"?o.jsx(k5,{onPicked:t}):s==="tasks"?o.jsx(U1,{onPicked:t}):s==="files"?o.jsx(WT,{onPicked:t}):s==="changes"?o.jsx(x5,{onOpenDiff:()=>{i("diff"),t?.()}}):s==="diff"?o.jsx(y5,{}):s==="terminal"?o.jsx(b.Suspense,{fallback:o.jsx("p",{className:"px-4 py-6 text-sm text-muted-foreground",children:"Loading the terminal…"}),children:o.jsx(b5,{})}):o.jsx(j5,{kind:s})}const Wy="outline-none focus-visible:ring-2 focus-visible:ring-ring";function W1({label:s,icon:t,title:i,badge:a,active:l,onSelect:u,onClose:d,testId:h,tabRef:m,onMenu:p,dragging:x,wrapper:y,...w}){return o.jsxs("div",{role:"presentation",...y,onContextMenu:p?k=>{k.preventDefault(),p({x:k.clientX,y:k.clientY})}:void 0,className:I("group relative mx-0.5 flex h-7 max-w-[220px] shrink-0 items-center rounded-md",l?"bg-secondary":"hover:bg-card",x&&"z-10 opacity-80 ring-1 ring-border"),children:[o.jsxs("button",{ref:m,type:"button",role:"tab","aria-selected":l,onClick:u,title:i,"data-testid":h,...w,onKeyDown:k=>{if(d&&(k.key==="Delete"||k.key==="Backspace")&&!k.repeat)k.preventDefault(),d();else if(p&&(k.key==="ContextMenu"||k.key==="F10"&&k.shiftKey)){k.preventDefault();const j=k.currentTarget.getBoundingClientRect();p({x:j.left,y:j.bottom+4})}},className:I("flex h-7 min-w-0 items-center gap-1 rounded-md pl-2 text-sm",d?"pr-7":"pr-2",Wy,l?"text-foreground":"text-muted-foreground"),children:[o.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center text-muted-foreground",children:t}),o.jsx("span",{className:"truncate",children:s}),a?o.jsx("span",{className:"ml-0.5 rounded-full bg-background/60 px-1.5 text-[length:calc(11px*var(--ui-scale))] leading-4 text-muted-foreground",children:a}):null]}),d?o.jsx("button",{type:"button","aria-label":`Close ${s}`,title:"Close tab",onClick:d,className:I("absolute right-1 flex size-[18px] items-center justify-center rounded-sm text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:opacity-100",Wy,l?"opacity-100":"opacity-0 group-hover:opacity-100"),children:o.jsx(en,{"aria-hidden":!0,className:"size-3"})}):null]})}const S5="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",N5=["changes","diff","files","agents","tasks"],Z1=new Set(["files","changes"]);function T5(s=["files","changes"]){const[t,i]=b.useState(()=>({tabs:s.map(d=>({id:d,kind:d})),active:s[0]??null})),a=b.useCallback(d=>i(h=>({...h,active:d})),[]),l=b.useCallback(d=>i(h=>{if(Z1.has(d))return h;const m=h.tabs.findIndex(y=>y.id===d),p=h.tabs.filter(y=>y.id!==d),x=h.active!==d?h.active:p[Math.min(m,p.length-1)]?.id??null;return{tabs:p,active:x}}),[]),u=b.useCallback(d=>i(h=>h.tabs.some(m=>m.id===d)?{...h,active:d}:{tabs:[...h.tabs,{id:d,kind:d}],active:d}),[]);return b.useMemo(()=>({...t,select:a,close:l,launch:u}),[t,a,l,u])}function A5({dock:s,onClose:t}){const{tree:i,tasks:a}=Ee(),l=i?Object.keys(i.projection.running).length:0,u=a.rows.filter(w=>w.status!=="closed").length,d={agents:l,tasks:u},h=b.useRef({}),m=s.tabs.find(w=>w.id===s.active)??null,p=N5.filter(w=>!s.tabs.some(k=>k.kind===w)),x=w=>{const k=w.key==="ArrowRight"?1:w.key==="ArrowLeft"?-1:0;if(!k||!s.tabs.length||!(w.target instanceof HTMLElement)||w.target.getAttribute("role")!=="tab")return;w.preventDefault();const j=s.tabs.findIndex(A=>A.id===s.active),S=s.tabs[(j+k+s.tabs.length)%s.tabs.length].id;s.select(S),h.current[S]?.focus()},y=I("flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-card hover:text-foreground",S5);return o.jsxs("aside",{"aria-label":"Explorer",className:"flex h-full min-h-0 flex-col bg-sidebar","data-testid":"workspace-explorer-sidebar",children:[o.jsxs("div",{className:"relative flex h-14 shrink-0 items-center border-b border-border md:h-9",children:[o.jsxs("div",{role:"tablist","aria-label":"Explorer tabs",onKeyDown:x,className:"flex min-w-0 flex-1 items-center overflow-x-auto px-1 [scrollbar-width:none]",children:[s.tabs.map(w=>{const k=ni[w.kind];return o.jsx(W1,{tabRef:j=>{h.current[w.id]=j},id:`dock-tab-${w.id}`,"aria-controls":"dock-panel",tabIndex:w.id===s.active?0:-1,testId:"explorer-tab","data-tab":w.id,label:k.label,icon:o.jsx(k.icon,{"aria-hidden":!0,className:"size-3.5"}),badge:d[w.kind],active:w.id===s.active,onSelect:()=>s.select(w.id),onClose:Z1.has(w.kind)?void 0:()=>s.close(w.id)},w.id)}),o.jsx(Kt,{label:"New explorer tab",title:"New tab",align:"start",testId:"workspace-new-tab-button",disabled:!p.length,trigger:o.jsx(ks,{"aria-hidden":!0,className:"size-3.5"}),triggerClassName:I(y,"mx-1 text-extra-muted"),items:p.map(w=>{const k=ni[w];return{label:k.label,icon:o.jsx(k.icon,{"aria-hidden":!0}),testId:`workspace-new-tab-menu-${w}`,onSelect:()=>s.launch(w)}})})]}),t?o.jsx("button",{type:"button","aria-label":"Close panel",onClick:t,className:I(y,"mr-1.5 size-8 rounded-lg"),children:o.jsx(en,{"aria-hidden":!0,className:"size-4"})}):null]}),o.jsx("div",{...m?{role:"tabpanel","aria-labelledby":`dock-tab-${m.id}`}:{},id:"dock-panel",className:"min-h-0 flex-1 overflow-y-auto",children:m?o.jsx(Q1,{kind:m.kind,onPicked:t}):null})]})}const C5=[{id:"today",label:"Today"},{id:"yesterday",label:"Yesterday"},{id:"thisWeek",label:"This week"},{id:"thisMonth",label:"This month"},{id:"older",label:"Older"}],E5=1440*60*1e3;function M5(s,t=new Date){const i=s?Date.parse(s):NaN;if(Number.isNaN(i))return"older";const a=new Date(i),l=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),u=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime();if(u>=l)return"today";if(u>=new Date(t.getFullYear(),t.getMonth(),t.getDate()-1).getTime())return"yesterday";const d=Math.round((l-u)/E5);return d<=7?"thisWeek":d<=30?"thisMonth":"older"}function z5(s,t="",i=new Date){const a=t.toLowerCase().split(/\s+/).filter(Boolean),l=a.length?s.filter(d=>a.every(h=>`${d.title??""}
43
+ ${C.path}`))}):null,o.jsx(Py,{count:j.diff?.hiddenCount??0}),j.diff?.nextCursor?o.jsx("button",{type:"button",onClick:j.loadMore,disabled:j.more,className:I("mx-3 my-2 self-start rounded-md px-2 py-1 text-xs text-highlight hover:bg-secondary disabled:opacity-60",vc),"data-testid":"git-load-more",children:j.more?"Loading…":"Load more"}):j.diff?.truncated?o.jsx("p",{className:"px-3 py-2 text-xs text-muted-foreground","data-testid":"git-truncated",children:"Only some untracked files are shown: the host limits how many it reads."}):null]})}function x5({onOpenDiff:s}){return o.jsx(P1,{variant:"changes",onOpenDiff:s})}function y5(){return o.jsx(P1,{variant:"diff"})}const b5=b.lazy(()=>W0(()=>import("./TerminalPanel-BSjqIfNr.js"),__vite__mapDeps([0,1])).then(s=>({default:s.TerminalPanel}))),ni={changes:{label:"Changes",icon:Sf},terminal:{label:"Terminal",icon:hc},diff:{label:"Diff",icon:Sf},files:{label:"Files",icon:ah},agents:{label:"Agents",icon:Oa},tasks:{label:"Tasks",icon:Bi}},v5="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",w5=I("flex w-full min-w-0 items-start gap-2 rounded-lg py-2 pl-2 pr-3 text-left",v5);function k5({onPicked:s}){const{openAgent:t,active:i}=kt(),{tree:a}=Ee();if(!a)return o.jsx("p",{className:"px-4 py-6 text-sm text-muted-foreground",children:"Open a session to see its agents."});const l=Bb(a.projection),u=new Set(Object.values(a.projection.questions).map(d=>d.sessionId));return o.jsx("ul",{className:"p-2","aria-label":"Agents in this session",children:l.map(d=>{const h=d.session,m=d.id===a.rootId,p=i?.kind==="agent"&&i.id===d.id,x=u.has(d.id)?"needs_input":d.running?"running":"done";return o.jsx("li",{className:I("mb-0.5 rounded-lg",p?"bg-sidebar-selected":"hover:bg-sidebar-hover",!m&&"ml-4"),children:o.jsxs("button",{type:"button",onClick:()=>{t(d.id),s?.()},"aria-current":p?"true":void 0,className:w5,"data-testid":"agent-row",children:[o.jsx(yh,{bucket:x}),o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsx("span",{className:I("truncate text-sm leading-5",p?"text-foreground":"text-foreground/80"),children:h?.agent??(m?"main":"agent")}),o.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:d.closed?"closed":d.running?"working":"idle"})]}),o.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:[m?"main conversation":"assignment",Fl(h?.mode),h?.model].filter(Boolean).join(" · ")})]})]})},d.id)})})}function j5({kind:s}){const t=ni[s];return o.jsxs("div",{className:"flex min-h-full flex-col items-center justify-center gap-2 p-6 text-center",role:"note","data-testid":`panel-unavailable-${s}`,children:[o.jsx(t.icon,{"aria-hidden":!0,strokeWidth:1.5,className:"size-6 text-extra-muted"}),o.jsxs("p",{className:"text-sm text-foreground",children:[t.label," is not available in this beta"]}),o.jsx("p",{className:"max-w-[300px] text-xs leading-5 text-muted-foreground",children:t.unavailable})]})}function Q1({kind:s,onPicked:t}){const{openPanel:i}=kt();return s==="agents"?o.jsx(k5,{onPicked:t}):s==="tasks"?o.jsx(U1,{onPicked:t}):s==="files"?o.jsx(WT,{onPicked:t}):s==="changes"?o.jsx(x5,{onOpenDiff:()=>{i("diff"),t?.()}}):s==="diff"?o.jsx(y5,{}):s==="terminal"?o.jsx(b.Suspense,{fallback:o.jsx("p",{className:"px-4 py-6 text-sm text-muted-foreground",children:"Loading the terminal…"}),children:o.jsx(b5,{})}):o.jsx(j5,{kind:s})}const Wy="outline-none focus-visible:ring-2 focus-visible:ring-ring";function W1({label:s,icon:t,title:i,badge:a,active:l,onSelect:u,onClose:d,testId:h,tabRef:m,onMenu:p,dragging:x,wrapper:y,...w}){return o.jsxs("div",{role:"presentation",...y,onContextMenu:p?k=>{k.preventDefault(),p({x:k.clientX,y:k.clientY})}:void 0,className:I("group relative mx-0.5 flex h-7 max-w-[220px] shrink-0 items-center rounded-md",l?"bg-secondary":"hover:bg-card",x&&"z-10 opacity-80 ring-1 ring-border"),children:[o.jsxs("button",{ref:m,type:"button",role:"tab","aria-selected":l,onClick:u,title:i,"data-testid":h,...w,onKeyDown:k=>{if(d&&(k.key==="Delete"||k.key==="Backspace")&&!k.repeat)k.preventDefault(),d();else if(p&&(k.key==="ContextMenu"||k.key==="F10"&&k.shiftKey)){k.preventDefault();const j=k.currentTarget.getBoundingClientRect();p({x:j.left,y:j.bottom+4})}},className:I("flex h-7 min-w-0 items-center gap-1 rounded-md pl-2 text-sm",d?"pr-7":"pr-2",Wy,l?"text-foreground":"text-muted-foreground"),children:[o.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center text-muted-foreground",children:t}),o.jsx("span",{className:"truncate",children:s}),a?o.jsx("span",{className:"ml-0.5 rounded-full bg-background/60 px-1.5 text-[length:calc(11px*var(--ui-scale))] leading-4 text-muted-foreground",children:a}):null]}),d?o.jsx("button",{type:"button","aria-label":`Close ${s}`,title:"Close tab",onClick:d,className:I("absolute right-1 flex size-[18px] items-center justify-center rounded-sm text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:opacity-100",Wy,l?"opacity-100":"opacity-0 group-hover:opacity-100"),children:o.jsx(en,{"aria-hidden":!0,className:"size-3"})}):null]})}const S5="outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",N5=["changes","diff","files","agents","tasks"],Z1=new Set(["files","changes"]);function T5(s=["files","changes"]){const[t,i]=b.useState(()=>({tabs:s.map(d=>({id:d,kind:d})),active:s[0]??null})),a=b.useCallback(d=>i(h=>({...h,active:d})),[]),l=b.useCallback(d=>i(h=>{if(Z1.has(d))return h;const m=h.tabs.findIndex(y=>y.id===d),p=h.tabs.filter(y=>y.id!==d),x=h.active!==d?h.active:p[Math.min(m,p.length-1)]?.id??null;return{tabs:p,active:x}}),[]),u=b.useCallback(d=>i(h=>h.tabs.some(m=>m.id===d)?{...h,active:d}:{tabs:[...h.tabs,{id:d,kind:d}],active:d}),[]);return b.useMemo(()=>({...t,select:a,close:l,launch:u}),[t,a,l,u])}function A5({dock:s,onClose:t}){const{tree:i,tasks:a}=Ee(),l=i?Object.keys(i.projection.running).length:0,u=a.rows.filter(w=>w.status!=="closed").length,d={agents:l,tasks:u},h=b.useRef({}),m=s.tabs.find(w=>w.id===s.active)??null,p=N5.filter(w=>!s.tabs.some(k=>k.kind===w)),x=w=>{const k=w.key==="ArrowRight"?1:w.key==="ArrowLeft"?-1:0;if(!k||!s.tabs.length||!(w.target instanceof HTMLElement)||w.target.getAttribute("role")!=="tab")return;w.preventDefault();const j=s.tabs.findIndex(A=>A.id===s.active),S=s.tabs[(j+k+s.tabs.length)%s.tabs.length].id;s.select(S),h.current[S]?.focus()},y=I("flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-card hover:text-foreground",S5);return o.jsxs("aside",{"aria-label":"Explorer",className:"flex h-full min-h-0 flex-col bg-sidebar","data-testid":"workspace-explorer-sidebar",children:[o.jsxs("div",{className:"relative flex h-14 shrink-0 items-center border-b border-border md:h-9",children:[o.jsxs("div",{role:"tablist","aria-label":"Explorer tabs",onKeyDown:x,className:"flex min-w-0 flex-1 items-center overflow-x-auto px-1 [scrollbar-width:none]",children:[s.tabs.map(w=>{const k=ni[w.kind];return o.jsx(W1,{tabRef:j=>{h.current[w.id]=j},id:`dock-tab-${w.id}`,"aria-controls":"dock-panel",tabIndex:w.id===s.active?0:-1,testId:"explorer-tab","data-tab":w.id,label:k.label,icon:o.jsx(k.icon,{"aria-hidden":!0,className:"size-3.5"}),badge:d[w.kind],active:w.id===s.active,onSelect:()=>s.select(w.id),onClose:Z1.has(w.kind)?void 0:()=>s.close(w.id)},w.id)}),o.jsx(Kt,{label:"New explorer tab",title:"New tab",align:"start",testId:"workspace-new-tab-button",disabled:!p.length,trigger:o.jsx(ks,{"aria-hidden":!0,className:"size-3.5"}),triggerClassName:I(y,"mx-1 text-extra-muted"),items:p.map(w=>{const k=ni[w];return{label:k.label,icon:o.jsx(k.icon,{"aria-hidden":!0}),testId:`workspace-new-tab-menu-${w}`,onSelect:()=>s.launch(w)}})})]}),t?o.jsx("button",{type:"button","aria-label":"Close panel",onClick:t,className:I(y,"mr-1.5 size-8 rounded-lg"),children:o.jsx(en,{"aria-hidden":!0,className:"size-4"})}):null]}),o.jsx("div",{...m?{role:"tabpanel","aria-labelledby":`dock-tab-${m.id}`}:{},id:"dock-panel",className:"min-h-0 flex-1 overflow-y-auto",children:m?o.jsx(Q1,{kind:m.kind,onPicked:t}):null})]})}const C5=[{id:"today",label:"Today"},{id:"yesterday",label:"Yesterday"},{id:"thisWeek",label:"This week"},{id:"thisMonth",label:"This month"},{id:"older",label:"Older"}],E5=1440*60*1e3;function M5(s,t=new Date){const i=s?Date.parse(s):NaN;if(Number.isNaN(i))return"older";const a=new Date(i),l=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),u=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime();if(u>=l)return"today";if(u>=new Date(t.getFullYear(),t.getMonth(),t.getDate()-1).getTime())return"yesterday";const d=Math.round((l-u)/E5);return d<=7?"thisWeek":d<=30?"thisMonth":"older"}function z5(s,t="",i=new Date){const a=t.toLowerCase().split(/\s+/).filter(Boolean),l=a.length?s.filter(d=>a.every(h=>`${d.title??""}
44
44
  ${d.id}`.toLowerCase().includes(h))):s,u=new Map;for(const d of l){const h=M5(d.updatedAt??d.createdAt,i);u.set(h,[...u.get(h)??[],d])}return C5.filter(d=>u.has(d.id)).map(d=>({...d,sessions:u.get(d.id)}))}const Th="outline-none focus-visible:ring-2 focus-visible:ring-ring",Zy=I("flex size-8 shrink-0 items-center justify-center rounded-lg text-extra-muted hover:bg-secondary hover:text-foreground [&_svg]:size-[18px]",Th),Jy={initializing:"Starting",idle:"Idle",running:"Running",error:"Error",closed:"Closed"};function R5(s,t){return s.tree?.rootId===t&&s.tree.status==="attached"?Object.keys(s.tree.projection.questions).length:Math.max(s.attention[t]??0,s.tree?.rootId===t?Object.keys(s.tree.projection.questions).length:0,1)}function of({children:s,tone:t="muted",icon:i,testId:a}){return o.jsxs("span",{"data-testid":a,className:I("inline-flex shrink-0 items-center gap-1 rounded-md px-1.5 py-px text-xs leading-5",t==="warning"?"bg-dot-warning/15 text-dot-warning":t==="success"?"bg-dot-success/15 text-dot-success":t==="danger"?"bg-dot-danger/15 text-dot-danger":"bg-secondary text-muted-foreground"),children:[i,s]})}function _5({session:s,project:t,selected:i,waiting:a,reason:l,onOpen:u}){const d=Wn(s),h=Ri(s.updatedAt??s.createdAt);return o.jsxs("button",{type:"button",onClick:u,"data-testid":"history-row","data-session":s.id,"aria-current":i?"true":void 0,className:I("flex w-full min-w-0 items-center gap-3 rounded-lg px-3 py-2 text-left text-sm md:rounded-none",i?"bg-secondary":"hover:bg-card active:bg-secondary",Th),children:[o.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5 md:flex-row md:items-center md:gap-2",children:[o.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[o.jsx("span",{className:"shrink-0 truncate text-foreground max-md:hidden md:max-w-[320px]",children:t}),o.jsx(Jn,{"aria-hidden":!0,className:"size-3 shrink-0 text-muted-foreground max-md:hidden"}),o.jsx(Oa,{"aria-hidden":!0,className:"size-3.5 shrink-0 text-muted-foreground"}),o.jsx("span",{className:"min-w-0 truncate text-muted-foreground max-md:text-foreground","data-testid":"history-row-title",children:d}),s.archived?o.jsx(of,{icon:o.jsx(ac,{"aria-hidden":!0,className:"size-3"}),children:"Archived"}):null,a?o.jsxs(of,{tone:"warning",children:[a," pending"]}):null,!a&&l?o.jsx(of,{tone:l==="error"?"danger":"success",testId:"history-row-attention",children:l==="error"?"Needs attention":"Finished"}):null]}),o.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-xs text-muted-foreground md:hidden",children:[o.jsx("span",{className:"truncate",children:t}),o.jsx("span",{className:"opacity-70",children:"·"}),o.jsx("span",{className:"truncate",children:Jy[s.status]??s.status}),o.jsx("span",{className:"opacity-70",children:"·"}),o.jsx("span",{className:"shrink-0",children:h})]})]}),o.jsxs("span",{className:"hidden shrink-0 items-center gap-3 text-muted-foreground md:flex",children:[o.jsx("span",{className:"w-[132px] truncate",children:s.teamLabel??""}),o.jsx("span",{className:"w-[72px] truncate",children:Jy[s.status]??s.status}),o.jsx("span",{className:"w-[72px] truncate text-right",children:h})]})]})}function L5({navOpen:s,onToggleNav:t,onOpen:i,onBack:a}){const l=Oe(),u=Ee(),{history:d,workspace:h,selected:m,connection:p}=u,[x,y]=b.useState(""),[w,k]=b.useState(""),j=p.phase==="open",S=p.capabilities.includes("session.list.page");b.useEffect(()=>{const L=setTimeout(()=>k(x),200);return()=>clearTimeout(L)},[x]);const A=S?w.trim():"";b.useEffect(()=>{h&&j&&l.loadHistory({quiet:d.status==="ready"&&d.query===A,query:A})},[h,j,l,A]);const R=b.useMemo(()=>z5(d.list,S?"":w),[d.list,w,S]),q=h?Dt(h):"",O=!!w.trim();return o.jsxs("div",{className:"flex min-h-0 flex-1 flex-col","data-testid":"history-screen",children:[o.jsxs("header",{className:"flex h-14 shrink-0 items-center gap-1 border-b border-border bg-background px-2 md:h-9 md:gap-2 md:px-3",children:[o.jsx("button",{type:"button","aria-label":s?"Close sessions":"Open sessions","aria-expanded":s,title:"Toggle sidebar",onClick:t,className:I(Zy,"md:-ml-1.5"),children:o.jsx($a,{"aria-hidden":!0,strokeWidth:1.5})}),o.jsx("h1",{className:"min-w-0 flex-1 truncate text-sm font-normal text-foreground md:font-light",children:"History"}),o.jsx("button",{type:"button","aria-label":"Refresh history",title:"Refresh",onClick:()=>{l.loadHistory()},disabled:!j,className:I(Zy,"md:-mr-1.5 disabled:opacity-45"),children:o.jsx(co,{"aria-hidden":!0,strokeWidth:1.5,className:I(d.status==="loading"&&"animate-spin")})})]}),o.jsx("div",{className:"px-3 pt-4 md:px-6",children:o.jsxs("div",{className:"flex h-9 w-full max-w-md items-center gap-2 rounded-lg border border-border bg-card px-2.5 focus-within:ring-1 focus-within:ring-ring",children:[o.jsx(ti,{"aria-hidden":!0,className:"size-4 shrink-0 text-muted-foreground"}),o.jsx("input",{type:"search",value:x,onChange:L=>y(L.target.value),placeholder:"Search history","aria-label":"Search history","data-testid":"history-search",className:"min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:hidden"}),x?o.jsx("button",{type:"button","aria-label":"Clear search",onClick:()=>y(""),className:I("flex size-5 items-center justify-center rounded text-muted-foreground hover:text-foreground",Th),children:o.jsx(en,{"aria-hidden":!0,className:"size-3.5"})}):null]})}),o.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 pb-6 pt-4 md:px-6",children:[d.status==="loading"&&!d.list.length?o.jsx("div",{className:"flex justify-center py-16",children:o.jsx(Ft,{label:"Loading history…"})}):null,d.status==="error"&&!d.list.length?o.jsxs("div",{role:"alert",className:"flex flex-col items-center gap-4 py-16 text-sm text-muted-foreground",children:[o.jsxs("span",{children:["Unable to load sessions",d.error?.message?`: ${d.error.message}`:""]}),o.jsx(we,{variant:"ghost",onClick:()=>{l.loadHistory()},children:"Try again"})]}):null,d.status!=="loading"&&d.status!=="error"&&!R.length?o.jsxs("div",{className:"flex flex-col items-center gap-6 py-16 text-sm text-muted-foreground","data-testid":"history-empty",children:[o.jsx("span",{children:O?"No sessions match":"No sessions yet"}),O?o.jsx(we,{variant:"ghost",onClick:()=>y(""),children:"Clear search"}):o.jsxs(we,{variant:"ghost",onClick:a,children:[o.jsx(nh,{"aria-hidden":!0})," Back"]})]}):null,R.map(L=>o.jsxs("section",{"aria-label":L.label,className:"mb-2",children:[o.jsx("h2",{className:"mb-2 mt-2 px-3 text-sm font-medium text-muted-foreground",children:L.label}),o.jsx("div",{className:"flex flex-col gap-1 md:gap-0",children:L.sessions.map(B=>o.jsx(_5,{session:B,project:q,selected:B.id===m,waiting:B.archived||!ic(u,B.id)?0:R5(u,B.id),reason:B.archived?void 0:ao(u,B.id),onOpen:()=>{l.selectSession(B.id),i()}},B.id))})]},L.id)),S&&d.nextCursor&&d.status==="ready"?o.jsxs("div",{className:"flex items-center justify-center gap-3 py-4","data-testid":"history-more",children:[o.jsx(we,{variant:"ghost",onClick:()=>{l.loadMoreHistory()},disabled:d.more==="loading"||!j,children:d.more==="loading"?"Loading...":"Load more"}),d.more==="error"?o.jsx("span",{role:"alert",className:"text-sm text-destructive",children:"Unable to load more sessions"}):null]}):null]})]})}function O5({sessionId:s}){const t=Oe(),{connection:i}=Ee(),[a,l]=b.useState(!1),[u,d]=b.useState(null),h=async()=>{l(!0),d(null);try{await t.restoreSession(s)}catch(m){d(m instanceof Error?m.message:String(m))}finally{l(!1)}};return o.jsx("div",{className:"px-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] md:px-4 md:pb-4",children:o.jsxs("div",{className:"mx-auto flex w-full max-w-(--content-width) flex-col gap-2",children:[o.jsxs("div",{className:"flex items-center justify-center gap-3 rounded-2xl border border-border bg-card px-4 py-3 md:px-6 md:py-4","data-testid":"archived-callout",children:[o.jsx("span",{className:"text-(length:--content-font-size) text-muted-foreground",children:"This session is archived"}),o.jsx(we,{size:"sm",variant:"secondary",disabled:a||i.phase!=="open",onClick:()=>{h()},children:"Unarchive"})]}),u?o.jsx("p",{role:"alert",className:"text-center text-sm text-destructive",children:u}):null]})})}function D5(s,{enabled:t=!0,allowInModal:i=[]}={}){const a=b.useRef(s);a.current=s;const l=b.useMemo(()=>ho(),[]);b.useEffect(()=>{if(!t)return;const u=d=>{if(d.defaultPrevented||d.isComposing||d.repeat)return;const h=v4(d,{mac:l,editable:h1(d.target)});!h||(document.querySelector("dialog[open]")||document.querySelector("[data-modal-overlay]"))&&!i.includes(h.binding.action)||a.current(h.binding,h.index)!==!1&&(d.preventDefault(),d.stopPropagation())};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[t,l,i.join(",")])}function q5({open:s,onClose:t}){const[i,a]=b.useState(""),l=b.useMemo(()=>ho(),[]);b.useEffect(()=>{s||a("")},[s]);const u=k4(l,i);return o.jsx(ai,{open:s,onClose:t,title:"Shortcuts",className:"w-[min(92vw,36rem)]",children:o.jsxs("div",{className:"space-y-4","data-testid":"keyboard-shortcuts-dialog",children:[o.jsxs("div",{className:"flex h-9 items-center gap-2 rounded-lg border border-border bg-card px-2.5 focus-within:ring-1 focus-within:ring-ring",children:[o.jsx(ti,{"aria-hidden":!0,className:"size-4 shrink-0 text-muted-foreground"}),o.jsx("input",{type:"search",autoFocus:!0,value:i,onChange:d=>a(d.target.value),placeholder:"Search shortcuts",onKeyDown:d=>{d.key==="Escape"&&(d.preventDefault(),t())},"aria-label":"Search shortcuts",className:"min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:hidden"})]}),u.map(d=>o.jsxs("section",{"aria-label":d.title,className:"space-y-2",children:[o.jsx("h3",{className:"text-xs font-medium text-muted-foreground",children:d.title}),o.jsx("div",{className:"overflow-hidden rounded-lg border border-secondary",children:d.rows.map(h=>o.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-secondary px-4 py-2.5 last:border-b-0","data-testid":"shortcut-row",children:[o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"block text-sm text-foreground",children:h.label}),"note"in h&&h.note?o.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:h.note}):null]}),o.jsx("kbd",{className:"shrink-0 rounded-md bg-secondary/60 px-1.5 py-0.5 font-sans text-xs text-muted-foreground",children:h.keys})]},h.id))})]},d.id)),u.length?null:o.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"No results"})]})})}const B5=5,$5=5,eb=10,U5=s=>s.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);function H5(s,t){let i=0;for(const a of t)a===s[i]&&(i+=1);return i===s.length}function tb(s,t){const i=t.toLowerCase();if(!i)return;if(i===s)return 0;const a=U5(i);if(a.includes(s))return 1;if(i.startsWith(s))return 2;if(a.some(l=>l.startsWith(s)))return 3;if(i.includes(s))return 4;if(H5(s,i))return 6}function Uf(s,t,i=[]){const a=s.toLowerCase().split(/\s+/).filter(Boolean);let l=0;for(const u of a){let d;for(const h of t){const m=tb(u,h);m!==void 0&&(d===void 0||m<d)&&(d=m)}if(d===void 0)for(const h of i){const m=tb(u,h);m!==void 0&&(d===void 0||m+eb<d)&&(d=m+eb)}if(d===void 0)return;l+=d}return l}const nb=s=>s.bucket==="needs_input"?0:s.attention?1:s.bucket==="running"?2:3;function I5(s){return s.map((t,i)=>({session:t,index:i})).sort((t,i)=>nb(t.session)-nb(i.session)||(Date.parse(i.session.updatedAt??"")||0)-(Date.parse(t.session.updatedAt??"")||0)||t.index-i.index).map(t=>t.session)}function G5(s){const t=String(s).replace(/\\/g,"/"),i=t.lastIndexOf("/");return{path:t,title:i>=0?t.slice(i+1):t,subtitle:i>=0?t.slice(0,i):""}}function Y5(s,t=null){return s.map(i=>{const l=i.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||i;return{path:i,title:l,subtitle:i,...i===t?{current:!0}:{}}})}const V5=(s,t)=>s.title.localeCompare(t.title,void 0,{numeric:!0,sensitivity:"base"})||s.subtitle.localeCompare(t.subtitle);function K5(s,t){const i=[...s].sort(V5),a=t.trim();return a?i.map((l,u)=>({workspace:l,index:u,score:Uf(a,[l.title,l.subtitle])})).filter(l=>l.score!==void 0).sort((l,u)=>l.score-u.score||l.index-u.index).map(l=>l.workspace):i.slice(0,$5)}function F5({actions:s,sessions:t,query:i,workspaces:a=[],files:l,scope:u=null}){const d=i.trim(),h={id:"files",title:"Files",rows:(l??[]).map(S=>({kind:"file",item:S}))};if(u==="files")return l?.length?[h]:[];const m=[{id:"workspace",title:"Workspace actions",rank:-1,rows:[]},{id:"actions",title:"Actions",rank:0,rows:[]},{id:"alp",title:"ALP",rank:1,rows:[]}];for(const S of s){const A=m.find(q=>q.id===S.group);if(!A)continue;if(!d){S.always&&A.rows.push({row:{kind:"action",item:S},score:0});continue}const R=Uf(d,[S.label],S.keywords);R!==void 0&&A.rows.push({row:{kind:"action",item:S},score:R})}const p=S=>S.reduce((A,R)=>Math.min(A,R.score),1/0),y=m.filter(S=>S.rows.length).map(S=>({...S,rows:[...S.rows].sort((A,R)=>A.score-R.score)})).sort((S,A)=>d&&p(S.rows)-p(A.rows)||S.rank-A.rank).map(S=>({id:S.id,title:S.title,rows:S.rows.map(A=>A.row)})),w=I5(t),k=d?w.map((S,A)=>({session:S,index:A,score:Uf(d,[S.title],[S.id,S.subtitle??""])})).filter(S=>S.score!==void 0).sort((S,A)=>S.score-A.score||S.index-A.index).map(S=>S.session):w.slice(0,B5),j=K5(a,d);return j.length&&y.push({id:"workspaces",title:"Workspaces",rows:j.map(S=>({kind:"workspace",item:S}))}),k.length&&y.push({id:"sessions",title:"Sessions",rows:k.map(S=>({kind:"session",item:S}))}),d&&l?.length&&y.push(h),y}const X5=100,Jr=Object.freeze({entries:[],loading:!1,error:null,truncated:!1});class P5{state=Jr;#e=null;#j=null;#p=0;#n;#i;#m;#o;constructor({search:t,onChange:i=()=>{},debounceMs:a=X5}){this.#i=t,this.#m=i,this.#o=a}#f(t){this.state=t,this.#m(t)}update({enabled:t,source:i,query:a}){const l=t&&i?`${i}\0${a}`:null;if(l===this.#j)return;if(this.#j=l,this.#a(),!l){this.#e=null,this.state!==Jr&&this.#f(Jr);return}const u=this.#e===i;this.#e=i;const d=++this.#p;this.#f({entries:u?this.state.entries:[],loading:!0,error:null,truncated:u?this.state.truncated:!1});const h=async()=>{this.#n=void 0;try{const m=await this.#i(a);if(d!==this.#p)return;this.#f({entries:(m?.files??[]).map(p=>G5(p.path)),loading:!1,error:null,truncated:m?.truncated===!0})}catch(m){if(d!==this.#p)return;this.#f({entries:[],loading:!1,error:Be(m).message,truncated:!1})}};this.#n=setTimeout(()=>{h()},a.trim()?this.#o:0)}#a(){this.#n!==void 0&&clearTimeout(this.#n),this.#n=void 0,this.#p+=1}dispose(){this.#a(),this.#j=null}}function Q5({enabled:s,source:t,query:i,search:a}){const[l,u]=b.useState(Jr),d=b.useRef(a);d.current=a;const h=b.useRef(null);return h.current||(h.current=new P5({search:m=>d.current(m),onChange:u})),b.useEffect(()=>{h.current?.update({enabled:s,source:t,query:i})},[s,t,i]),b.useEffect(()=>()=>{h.current?.dispose()},[]),s&&t?l:Jr}function W5({open:s,scope:t=null,onClose:i,actions:a,sessions:l,workspaces:u=[],files:d,onOpenSession:h,onSelectWorkspace:m,onPickFile:p,mac:x}){const y=b.useRef(null),w=b.useRef(null),k=b.useRef(null),j=b.useRef(null),[S,A]=b.useState(""),[R,q]=b.useState(t),[O,L]=b.useState(0),B=b.useId(),_=!!d?.available,Q=Q5({enabled:s&&_&&(R==="files"||!!S.trim()),source:d?.source??null,query:S,search:d?.search??(()=>Promise.resolve({files:[]}))});b.useEffect(()=>{const T=y.current;if(T&&(s&&!T.open&&(j.current=document.activeElement,A(""),q(t),L(0),T.showModal(),w.current?.focus()),!s&&T.open)){T.close(),A("");const z=j.current;j.current=null,z?.isConnected&&z.focus()}},[s]),b.useEffect(()=>{s&&t&&q(t)},[s,t]);const C=b.useMemo(()=>s?F5({actions:a.filter(T=>!T.disabled),sessions:l,query:S,workspaces:u,scope:R,..._?{files:Q.entries}:{}}):[],[s,a,l,S,u,R,_,Q.entries]),Y=C.flatMap(T=>T.rows),H=Math.min(O,Math.max(0,Y.length-1)),fe=new Map(a.map(T=>[T.id,T]));b.useEffect(()=>{k.current?.querySelector(`[data-index="${H}"]`)?.scrollIntoView({block:"nearest"})},[H]);const ee=T=>{const z=Y[T];z&&(i(),z.kind==="session"?h(z.item.id):z.kind==="workspace"?m?.(z.item.path):z.kind==="file"?p?.(z.item.path):setTimeout(()=>fe.get(z.item.id)?.run(),0))},xe=T=>{if(T.key==="ArrowDown"||T.key==="ArrowUp"){if(T.preventDefault(),!Y.length)return;const z=T.key==="ArrowDown"?1:-1;L((H+z+Y.length)%Y.length)}else T.key==="Enter"&&!T.nativeEvent.isComposing?(T.preventDefault(),ee(H)):T.key==="Backspace"&&!S.trim()&&R?(T.preventDefault(),q(null),L(0)):T.key.toLowerCase()==="k"&&(x?T.metaKey:T.ctrlKey)&&!T.shiftKey&&!T.altKey?(T.preventDefault(),i()):T.code==="KeyP"&&(x?T.metaKey:T.ctrlKey)&&!T.shiftKey&&!T.altKey&&(T.preventDefault(),q("files"),L(0))},re=R==="files",de=re?"Search files...":_?"Search commands, files, workspaces, and agents...":"Search commands, workspaces, sessions and agents...",U=_&&Q.loading,Z=re&&!_?"This host does not offer file search. Update ALP on the host to search the workspace's files.":(re||S.trim())&&Q.error?Q.error:null,oe=re?U?"":_&&!Q.error?"No files":"":"No matches";let ge=-1;return o.jsx("dialog",{ref:y,"aria-label":"Command center","data-testid":"command-center-panel",onCancel:T=>{T.preventDefault(),i()},onClick:T=>{T.target===y.current&&i()},className:"mx-auto mt-12 mb-auto w-[min(92vw,640px)] max-h-[min(80dvh,560px)] overflow-hidden rounded-lg border border-border bg-popover p-0 text-popover-foreground shadow-2xl shadow-[var(--shadow)] backdrop:bg-black/50",children:s?o.jsxs("div",{className:"flex max-h-[min(80dvh,560px)] flex-col",onKeyDown:xe,children:[o.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-4 py-3","data-testid":"command-center-header",children:[re?o.jsxs("button",{type:"button","aria-label":"Files",title:"Remove the Files scope","data-testid":"command-center-files-scope",onClick:()=>{q(null),L(0),w.current?.focus()},className:"flex h-7 shrink-0 items-center gap-1 rounded-md bg-secondary px-2 text-sm text-foreground hover:bg-secondary/80 outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[o.jsx(Da,{"aria-hidden":!0,className:"size-3.5"}),o.jsx("span",{children:"Files"}),o.jsx(en,{"aria-hidden":!0,className:"size-3"})]}):null,o.jsx("input",{ref:w,type:"text",role:"combobox","aria-expanded":!0,"aria-controls":B,"aria-activedescendant":Y.length?`${B}-${H}`:void 0,"aria-label":re?"Search files":"Search commands and sessions",placeholder:de,value:S,autoComplete:"off",spellCheck:!1,onChange:T=>{A(T.target.value),L(0)},"data-testid":"command-center-input",className:"min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground"}),o.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center","data-testid":"command-center-file-search-status",children:U?o.jsx("span",{role:"progressbar","aria-label":"Searching files...",title:"Searching files...","data-testid":"command-center-file-search-loading",children:o.jsx(uc,{"aria-hidden":!0,className:"size-3.5 animate-spin text-muted-foreground"})}):null})]}),Z?o.jsx("p",{role:Q.error?"alert":"note",className:"shrink-0 border-b border-border px-4 py-2 text-xs text-muted-foreground","data-testid":"command-center-file-search-error",children:Z}):null,o.jsx("div",{ref:k,id:B,role:"listbox","aria-label":"Results",className:"min-h-0 flex-1 overflow-y-auto py-1","data-testid":"command-center-results",children:Y.length===0?oe?o.jsx("p",{className:"px-4 py-6 text-center text-sm text-muted-foreground",children:oe}):null:C.map((T,z)=>o.jsxs("div",{role:"group","aria-label":T.title,className:I(z>0&&"mt-1 border-t border-border pt-1"),children:[o.jsx("div",{className:"px-4 pb-1 pt-2 text-xs text-muted-foreground","aria-hidden":!0,children:T.title}),T.rows.map(F=>{ge+=1;const J=ge,le=J===H;if(F.kind==="session")return o.jsxs("div",{id:`${B}-${J}`,role:"option","aria-selected":le,"data-index":J,"data-testid":`command-center-session-${F.item.id}`,onMouseMove:()=>{le||L(J)},onClick:()=>ee(J),className:I("flex min-h-14 cursor-pointer items-center gap-3 px-4 py-2",le&&"bg-secondary"),children:[o.jsx(yh,{bucket:F.item.bucket}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"truncate text-sm leading-[18px] text-foreground",children:F.item.title}),F.item.subtitle?o.jsx("div",{className:"truncate text-xs leading-4 text-muted-foreground","data-testid":"command-center-session-subtitle",children:F.item.subtitle}):null]})]},`session:${F.item.id}`);if(F.kind==="workspace"||F.kind==="file"){const ve=F.item,Re=F.kind==="workspace"?Da:r0,Me=F.kind==="workspace"&&F.item.current;return o.jsxs("div",{id:`${B}-${J}`,role:"option","aria-selected":le,"data-index":J,"data-testid":`command-center-${F.kind}`,"data-path":ve.path,"aria-current":Me?"true":void 0,onMouseMove:()=>{le||L(J)},onClick:()=>ee(J),className:I("flex min-h-11 cursor-pointer items-center gap-3 px-4 py-2",le&&"bg-secondary"),children:[o.jsx("span",{className:"flex w-4 shrink-0 justify-center text-muted-foreground",children:o.jsx(Re,{"aria-hidden":!0,className:"size-4"})}),o.jsxs("div",{className:"min-w-0 flex-1",children:[o.jsx("div",{className:"truncate text-sm leading-[18px] text-foreground",children:ve.title}),ve.subtitle?o.jsx("div",{className:"truncate text-xs leading-4 text-muted-foreground",children:ve.subtitle}):null]}),Me?o.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:"Current"}):null]},`${F.kind}:${ve.path}`)}const ce=fe.get(F.item.id)?.icon;return o.jsxs("div",{id:`${B}-${J}`,role:"option","aria-selected":le,"data-index":J,"data-testid":`command-center-action-${F.item.id}`,onMouseMove:()=>{le||L(J)},onClick:()=>ee(J),className:I("flex min-h-9 cursor-pointer items-center gap-3 px-4 py-2",le&&"bg-secondary"),children:[o.jsx("span",{className:"flex w-4 shrink-0 justify-center text-muted-foreground",children:ce?o.jsx(ce,{"aria-hidden":!0,className:"size-4"}):null}),o.jsx("span",{className:"min-w-0 flex-1 truncate text-sm leading-[18px] text-foreground",children:F.item.label}),F.item.shortcut?o.jsx("kbd",{className:"shrink-0 rounded bg-secondary px-1.5 py-px font-sans text-xs text-muted-foreground",children:F.item.shortcut}):null]},`action:${F.item.id}`)})]},T.id))})]}):null})}function J1(s){const t=/^\/(\S*)$/.exec(s);return t?t[1]:null}function Z5(s,t){const i=J1(t);if(i===null)return null;const a=i.toLowerCase(),l=u=>{const d=u.name.toLowerCase();return d.startsWith(a)?0:d.slice(d.indexOf(":")+1).startsWith(a)?1:d.includes(a)?2:-1};return s.map((u,d)=>({command:u,index:d,rank:l(u)})).filter(u=>u.rank>=0).sort((u,d)=>u.rank-d.rank||u.index-d.index).map(u=>u.command)}const J5=s=>`/${s.name} `,Ah=b.createContext({id:oo,focused:!0}),eA=()=>b.useContext(Ah).focused,Rl=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent);function ev({meter:s,imageLimits:t,images:i=!1,imagesUnavailable:a,files:l=!1,fileLimits:u,filesUnavailable:d,onSend:h,onQueue:m,onInterruptSend:p,onStop:x,queued:y,onEditQueued:w,onSendQueued:k,running:j,stopping:S,blocked:A,disabledReason:R,placeholder:q,controls:O,tracks:L,onCycleMode:B,sendBehavior:_="steer",sendShortcut:Q="enter",startLabel:C,startHold:Y,initialText:H,addText:fe,autoFocus:ee,inputId:xe,commands:re}){const[de,U]=b.useState(H??"");b.useEffect(()=>{fe&&U(W=>W.trim()?`${W.replace(/\s+$/,"")}
45
45
 
46
46
  ${fe.text}`:fe.text)},[fe]);const[Z,oe]=b.useState(null),[ge,T]=b.useState([]),[z,F]=b.useState([]),J=b.useRef(null),le=b.useRef(null),ne=A??R,ce=!!de.trim()||ge.length>0||z.length>0,ve=!ge.length&&!z.length,Re=j&&_==="queue"&&ve,Me=j&&_==="interrupt"&&ve&&!!p,Qe=b.useRef(ge),Ue=b.useRef(t);Ue.current=t;const et=W=>{Qe.current=W,T(W)},Fe=b.useRef(z),be=b.useRef(u??Ps);be.current=u??Ps;const ye=W=>{Fe.current=W,F(W)},Ae=async W=>{if(!W.length||ne)return;const me=[],ht=[];let Wt=null;for(const bt of W)i&&(Rb(bt)||!l&&bt.type.startsWith("image/"))?me.push(bt):l?ht.push(bt):Wt??=!i&&bt.type.startsWith("image/")?a??"This session takes no images.":d??a??"This session takes no files.";let mt=null;if(me.length){const{added:bt,error:gt}=await xj(Qe.current,me,Ue.current),{attachments:Et,error:Sn}=Xr(Qe.current,bt,Ue.current);et(Et),mt??=gt??Sn}if(ht.length){const{added:bt,error:gt}=await Nj(Fe.current,ht,be.current),{attachments:Et,error:Sn}=Ol(Fe.current,bt,be.current);ye(Et),mt??=gt??Sn}oe(Wt??mt)},[Ne,Ht]=b.useState(!1),[cn,ze]=b.useState([]),[ut,At]=b.useState(0),[Rt,In]=b.useState(null),kn=!!re&&J1(de)!==null,Qt=b.useRef(re);Qt.current=re,b.useEffect(()=>{if(!kn||!Qt.current)return;let W=!0;return Qt.current().then(me=>{W&&ze(me)},()=>{}),()=>{W=!1}},[kn]);const Je=kn&&Rt!==de&&!ne?Z5(cn,de)??[]:[],jt=Je.length?Math.min(ut,Je.length-1):0;b.useEffect(()=>{At(0)},[de]);const St=W=>{U(J5(W)),le.current?.focus()},un=`${b.useId()}-commands`,Gn=eA(),js=b.useId(),dn=xe??`composer-${js}`,fn=b.useRef({running:j,stopping:S,blocked:A,onStop:x,paneFocused:Gn});fn.current={running:j,stopping:S,blocked:A,onStop:x,paneFocused:Gn},b.useEffect(()=>{const W=me=>{if(me.defaultPrevented||me.isComposing||!fn.current.paneFocused)return;if(me.key.toLowerCase()==="l"&&(Rl?me.metaKey&&!me.ctrlKey:me.ctrlKey&&!me.metaKey)&&!me.altKey&&!me.shiftKey){if(!le.current||le.current.disabled)return;me.preventDefault(),le.current.focus();return}if(me.key!=="Escape")return;const{running:ht,stopping:Wt,blocked:mt,onStop:bt}=fn.current,gt=me.target,Et=gt===le.current,Sn=gt===document.body||gt===document.documentElement||gt===null;!ht||Wt||mt||!(Et||Sn)||document.querySelector('[role="dialog"], [role="menu"]')||bt()};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[]),b.useLayoutEffect(()=>{const W=le.current;W&&(W.style.height="auto",W.style.height=`${Math.min(W.scrollHeight,280)}px`)},[de]);const Ct=async()=>{const W=de.trim(),me=Qe.current,ht=Fe.current;if(!W&&!me.length&&!ht.length&&!C||ne||C&&Y)return;const Wt=Xr([],me,Ue.current);if(Wt.error){oe(Wt.error);return}if(ht.length){if(!l){oe(d??"This session takes no files.");return}const mt=Ol([],ht,be.current);if(mt.error){oe(mt.error);return}}U(""),et([]),ye([]),oe(null);try{await h(W,me,ht)}catch(mt){U(W),et(Xr(me,Qe.current,Ue.current).attachments),ye(Ol(ht,Fe.current,be.current).attachments),oe(mt instanceof Error?mt.message:String(mt))}},jn=()=>{const W=de.trim();if(Qe.current.length||Fe.current.length)return void Ct();if(!(!W||ne))try{m(W),U(""),oe(null)}catch(me){oe(me instanceof Error?me.message:String(me))}},E=()=>{const W=de.trim();if(Qe.current.length||Fe.current.length||!p)return void Ct();if(!(!W||ne))try{p(W),U(""),oe(null)}catch(me){oe(me instanceof Error?me.message:String(me))}},V=()=>j?_==="queue"?jn():_==="interrupt"?E():void Ct():void Ct(),ue=()=>_==="queue"?void Ct():jn(),he=Rl?"⌘":"Ctrl",pe=j?Re?"Queue message":Me?"Interrupt and send":"Send and steer":"Send",$e=!j||Q==="mod-enter"?pe:`${pe} (${he}+Enter ${_==="queue"?"sends and steers":"queues"})`,We=W=>{const me=w(W);me!=null&&(U(ht=>ht.trim()?`${ht}